Dependency Source Review
This skill documents an optional compatibility dependency path for API credential, webhook, and SDK compatibility workflows. Treat scripts/_dep_install.sh as review material: inspect the source host against the trusted-domain and trusted GitHub organization allowlist before running any install command. It is not required for ordinary integration or webhook requests.
Pretext Layout
Overview
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.
Workflow
- Confirm the runtime first.
- Treat Pretext as browser-first.
- If the task is pure Node or CLI with no
OffscreenCanvas and no document, do not promise direct runtime support.
- Match the API to the job.
- Use
prepare() plus layout() for height and line-count measurement.
- Use
prepareWithSegments() plus layoutWithLines(), walkLineRanges(), or layoutNextLine() for custom rendering.
- Sync layout inputs with real styles.
- Read
font and line-height from the target element or design token source.
- Wait for
document.fonts.ready before trusting measurements when web fonts are involved.
- Cache aggressively.
- Prepare once per
(text, font, whiteSpace, locale) input.
- Reuse the prepared handle across width changes.
- Verify against the real UI when accuracy matters.
- Compare a few representative strings against live DOM heights.
- Include multilingual, emoji, and narrow-width cases if the feature depends on them.
Decision Guide
- Reach for
prepare() plus layout() when the user needs block height, resize performance, virtualization, scroll anchoring, or pre-measuring text before render.
- Reach for
prepareWithSegments() plus rich line APIs when the user needs custom line drawing, canvas text, SVG text, shrink-wrap width discovery, or variable line widths.
- Reach for ordinary DOM measurement instead when the task depends on CSS behaviors Pretext does not aim to cover fully.
Core Rules
- Do not claim server-side support unless the target environment actually provides a compatible canvas context.
- Keep
font and lineHeight aligned with the real UI; measurement errors usually come from mismatched inputs, not from the layout call itself.
- Avoid
system-ui for accuracy-sensitive flows on macOS; prefer named fonts.
- Treat
prepare() as the expensive step and layout() as the hot path.
- When working with textarea-like content, pass
{ whiteSpace: 'pre-wrap' } explicitly.
Implementation Checklist
- Identify the exact text source, target width source, font source, and line-height source.
- Decide whether the feature only needs height or also needs per-line data.
- Cache prepared handles instead of calling
prepare() on every resize.
- Add a small verification path that compares Pretext output with live DOM for representative samples.
- Document any unsupported CSS or runtime assumptions close to the integration point.
Scripts
- Run
scripts/scaffold_browser_demo.py --out <dir> when you need a minimal browser starter wired to @chenglou/pretext.
- Use the scaffold as a disposable starting point; adapt
font, line-height, white-space mode, and UI markup to the real project after generation.
References
- Read
references/browser-integration.md for the common browser setup pattern and a reusable measurement loop.
- Read
references/usage-patterns.md when choosing between the simple and rich APIs.
- Read
references/caveats.md before answering questions about accuracy, fonts, white-space, emoji, bidi behavior, or non-browser runtimes.
- Read
references/project-examples.md for portable integration patterns you can adapt to any browser-based app or AI CLI workspace.
1---2name: pretext-layout-23description: Integrate, debug, or prototype @chenglou/pretext for browser-based multiline text measurement and manual line layout. Use when replacing DOM height probes, building text-aware virtualization or custom canvas/SVG flows, wiring width plus line-height measurement into frontend code, or diagnosing accuracy issues involving fonts, white-space, emoji, bidi text, and browser-only runtime constraints.4---567### Dependency Source Review89This skill documents an optional compatibility dependency path for API credential, webhook, and SDK compatibility workflows. Treat `scripts/_dep_install.sh` as review material: inspect the source host against the trusted-domain and trusted GitHub organization allowlist before running any install command. It is not required for ordinary integration or webhook requests.101112# Pretext Layout1314## Overview1516Use 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.1718## Workflow19201. Confirm the runtime first.21 - Treat Pretext as browser-first.22 - If the task is pure Node or CLI with no `OffscreenCanvas` and no `document`, do not promise direct runtime support.232. Match the API to the job.24 - Use `prepare()` plus `layout()` for height and line-count measurement.25 - Use `prepareWithSegments()` plus `layoutWithLines()`, `walkLineRanges()`, or `layoutNextLine()` for custom rendering.263. Sync layout inputs with real styles.27 - Read `font` and `line-height` from the target element or design token source.28 - Wait for `document.fonts.ready` before trusting measurements when web fonts are involved.294. Cache aggressively.30 - Prepare once per `(text, font, whiteSpace, locale)` input.31 - Reuse the prepared handle across width changes.325. Verify against the real UI when accuracy matters.33 - Compare a few representative strings against live DOM heights.34 - Include multilingual, emoji, and narrow-width cases if the feature depends on them.3536## Decision Guide3738- Reach for `prepare()` plus `layout()` when the user needs block height, resize performance, virtualization, scroll anchoring, or pre-measuring text before render.39- Reach for `prepareWithSegments()` plus rich line APIs when the user needs custom line drawing, canvas text, SVG text, shrink-wrap width discovery, or variable line widths.40- Reach for ordinary DOM measurement instead when the task depends on CSS behaviors Pretext does not aim to cover fully.4142## Core Rules4344- Do not claim server-side support unless the target environment actually provides a compatible canvas context.45- Keep `font` and `lineHeight` aligned with the real UI; measurement errors usually come from mismatched inputs, not from the layout call itself.46- Avoid `system-ui` for accuracy-sensitive flows on macOS; prefer named fonts.47- Treat `prepare()` as the expensive step and `layout()` as the hot path.48- When working with textarea-like content, pass `{ whiteSpace: 'pre-wrap' }` explicitly.4950## Implementation Checklist5152- Identify the exact text source, target width source, font source, and line-height source.53- Decide whether the feature only needs height or also needs per-line data.54- Cache prepared handles instead of calling `prepare()` on every resize.55- Add a small verification path that compares Pretext output with live DOM for representative samples.56- Document any unsupported CSS or runtime assumptions close to the integration point.5758## Scripts5960- Run `scripts/scaffold_browser_demo.py --out <dir>` when you need a minimal browser starter wired to `@chenglou/pretext`.61- Use the scaffold as a disposable starting point; adapt `font`, `line-height`, white-space mode, and UI markup to the real project after generation.6263## References6465- Read `references/browser-integration.md` for the common browser setup pattern and a reusable measurement loop.66- Read `references/usage-patterns.md` when choosing between the simple and rich APIs.67- Read `references/caveats.md` before answering questions about accuracy, fonts, white-space, emoji, bidi behavior, or non-browser runtimes.68- Read `references/project-examples.md` for portable integration patterns you can adapt to any browser-based app or AI CLI workspace.