Skip to content

vyaz-monorepo / core/src / groupLinesByParagraph

Function: groupLinesByParagraph()

groupLinesByParagraph(lines): ParagraphGroup[]

Defined in: core/src/utils/groupLinesByParagraph.ts:47

Group lines by pIdx (paragraph index).

Collects all lines with the same pIdx into one group, even if they are not consecutive in the array (multi-column layout may interleave lines of different paragraphs across columns).

Returns groups sorted by pIdx in document order. Lines without a valid pIdx (e.g. pIdx === undefined) are grouped as index -1.

Parameters

lines

Line[]

— flat array of lines from layoutTextFrame

Returns

ParagraphGroup[]

groups of lines grouped by paragraph

Example

ts
const result = layoutTextFrame(frame);
const groups = groupLinesByParagraph(result.lines);
// groups[0].lines  → all lines for paragraph 0 (across all columns)
// groups[0].pIdx   → 0

Released under the MIT License.