Skip to content
PACKAGES

computeLineBreaks()

Compute greedy single-column line breaks over prepared segments.

import { computeLineBreaks } from "@graphrefly/ts/solutions/reactive-layout";
function computeLineBreaks(
segments: readonly PreparedSegment[],
maxWidth: number,
opts: { readonly hyphenWidth?: number; readonly segmentAdapter?: SegmentAdapter } = {},
): LineBreaksResult
ParameterTypeDescription
segmentsreadonly PreparedSegment[]Prepared segments from analyzeAndMeasure or a measurement provider.
maxWidthnumberMaximum 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.

A LineBreaksResult containing ordered layout lines and the line count.

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);
  • Pure helper: This does not subscribe, schedule, or emit messages; reactive bundles call it from ordinary graph nodes.

packages/ts/src/solutions/reactive-layout/line.ts