@chenglou/pretext and re-exported from the package’s main entry point.
PreparedText
PreparedText
An opaque handle returned by
prepare(). Pass it to layout().PreparedText is intentionally opaque — its internal structure is not part of the public API. Do not attempt to read or construct it directly. Obtain one from prepare() and pass it to layout().If you need access to the underlying segment strings (for custom rendering), use prepareWithSegments() instead, which returns PreparedTextWithSegments.PreparedTextWithSegments
PreparedTextWithSegments
Extends
PreparedText with an exposed segments array. Returned by prepareWithSegments(). Pass to layoutWithLines(), walkLineRanges(), or layoutNextLine().The segment strings produced during the prepare phase, aligned with Pretext’s internal parallel arrays. For example,
['hello', ' ', 'world']. Use these to reconstruct or render individual line fragments when building a custom renderer.Treat
PreparedTextWithSegments as an escape hatch for experiments and custom rendering. For pure height measurement, prefer the opaque PreparedText from prepare().PrepareOptions
PrepareOptions
Optional configuration passed as the third argument to
prepare() and prepareWithSegments().Controls whitespace handling during text analysis.
LayoutResult
LayoutResult
Returned by
layout(). Contains the computed line count and total block height.The number of wrapped lines produced at the given
maxWidth. For example, 3.Total block height in pixels. Equal to
lineCount * lineHeight, where lineHeight is the value passed to layout(). For example, 57.LayoutCursor
LayoutCursor
A position within a Pass a line’s
PreparedTextWithSegments handle, expressed as a segment index and a grapheme index within that segment. Used as start and end on LayoutLine and LayoutLineRange.Index into the
segments array of the PreparedTextWithSegments handle.Grapheme index within the segment at
segmentIndex. 0 at segment boundaries; non-zero only when a word was broken mid-grapheme by overflow-wrap: break-word.end cursor as the start argument to the next layoutNextLine() call to stream lines one at a time.LayoutLine
LayoutLine
A single laid-out line, including its rendered text, measured width, and start/end cursors. Appears in the
lines array of LayoutLinesResult and is returned by layoutNextLine().The full rendered text content of this line. For example,
'hello world'. Trailing whitespace is not included; a trailing visible hyphen is included when a soft hyphen was chosen as the break point.The measured rendered width of this line in pixels. For example,
87.5. Trailing whitespace does not contribute to width.Inclusive start position of this line in the prepared segment stream.
Exclusive end position of this line. Pass as
start to the next layoutNextLine() call.LayoutLineRange
LayoutLineRange
Like A common pattern is to use
LayoutLine but without the text field. Produced by walkLineRanges(). Useful when you need line geometry (widths and cursors) without paying the cost of building line text strings.The measured rendered width of this line in pixels. For example,
87.5.Inclusive start position of this line in the prepared segment stream.
Exclusive end position of this line.
walkLineRanges() to binary-search for a satisfying container width, then call layoutWithLines() once with that width to get the full LayoutLine objects:LayoutLinesResult
LayoutLinesResult
Extends
LayoutResult with a lines array. Returned by layoutWithLines().The number of wrapped lines produced at the given
maxWidth.Total block height in pixels. Equal to
lineCount * lineHeight.One
LayoutLine per wrapped line, in document order. Each entry contains the rendered text string, measured width, and start/end cursors.