Use Pretext to measure multiline text in browser environments without paying repeated DOM reflow costs in the hot path. Prefer it when text width changes often and you need stable height or per-line geometry from cached measurements.
OffscreenCanvas and no document, do not promise direct runtime support.prepare() plus layout() for height and line-count measurement.prepareWithSegments() plus layoutWithLines(), walkLineRanges(), or layoutNextLine() for custom rendering.font and line-height from the target element or design token source.document.fonts.ready before trusting measurements when web fonts are involved.(text, font, whiteSpace, locale) input.prepare() plus layout() when the user needs block height, resize performance, virtualization, scroll anchoring, or pre-measuring text before render.prepareWithSegments() plus rich line APIs when the user needs custom line drawing, canvas text, SVG text, shrink-wrap width discovery, or variable line widths.font and lineHeight aligned with the real UI; measurement errors usually come from mismatched inputs, not from the layout call itself.system-ui for accuracy-sensitive flows on macOS; prefer named fonts.prepare() as the expensive step and layout() as the hot path.{ whiteSpace: 'pre-wrap' } explicitly.prepare() on every resize.scripts/scaffold_browser_demo.py --out when you need a minimal browser starter wired to @chenglou/pretext.font, line-height, white-space mode, and UI markup to the real project after generation.references/browser-integration.md for the common browser setup pattern and a reusable measurement loop.references/usage-patterns.md when choosing between the simple and rich APIs.references/caveats.md before answering questions about accuracy, fonts, white-space, emoji, bidi behavior, or non-browser runtimes.references/project-examples.md for portable integration patterns you can adapt to any browser-based app or AI CLI workspace.共 1 个版本