GraphReFlyTS

API Reference

computeLineBreaks()

Compute greedy single-column line breaks over prepared segments.

Import

import { computeLineBreaks } from "@graphrefly/ts/solutions/reactive-layout";

Signature

function computeLineBreaks(
	segments: readonly PreparedSegment[],
	maxWidth: number,
	opts: { readonly hyphenWidth?: number; readonly segmentAdapter?: SegmentAdapter } = {},
): LineBreaksResult

Parameters

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.

Returns

A LineBreaksResult containing ordered layout lines and the line count.

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

  • Pure helper: This does not subscribe, schedule, or emit messages; reactive bundles call it from ordinary graph nodes.

Source

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