computeLineBreaks()
Compute greedy single-column line breaks over prepared segments.
Import
Section titled “Import”import { computeLineBreaks } from "@graphrefly/ts/solutions/reactive-layout";Signature
Section titled “Signature”function computeLineBreaks( segments: readonly PreparedSegment[], maxWidth: number, opts: { readonly hyphenWidth?: number; readonly segmentAdapter?: SegmentAdapter } = {},): LineBreaksResultParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
segments | readonly PreparedSegment[] | Prepared segments from analyzeAndMeasure or a measurement provider. |
maxWidth | number | Maximum line width in pixels; non-finite or negative values produce no useful width budget. |
opts | { readonly hyphenWidth?: number; readonly segmentAdapter?: SegmentAdapter } | Optional hyphen width and segment adapter for grapheme-aware slicing. |
Returns
Section titled “Returns”A LineBreaksResult containing ordered layout lines and the line count.
Example
Section titled “Example”import { analyzeAndMeasure, computeLineBreaks } from "@graphrefly/ts/solutions/reactive-layout";
const segments = analyzeAndMeasure( "Hello world", "16px system-ui", { measureSegment: (segment) => ({ width: segment.length * 8 }) }, new Map(),);const lineBreaks = computeLineBreaks(segments, 64);Remarks
Section titled “Remarks”- Pure helper: This does not subscribe, schedule, or emit messages; reactive bundles call it from ordinary graph nodes.
Source
Section titled “Source”packages/ts/src/solutions/reactive-layout/line.ts