pretext
/pretext
Use for advanced web text measurement and layout with @chenglou/pretext: virtualized lists with variable-height text, shrinkwrapped chat bubbles, responsive multiline text, auto-growing textareas, dev-time label overflow checks, Canvas/SVG/WebGL text, and avoiding DOM reflow from getBoundingClientRect/offsetHeight. This is text-layout engineering/performance, not visual design polish.
- Author
- radustefandumitru ↗
- Repository
- overdrive ↗
- Licence
- Apache-2.0
- Last repository change
- 09.07.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 09.07.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Use for advanced web text measurement and layout with @chenglou/pretext: virtualized lists with variable-height text, shrinkwrapped chat bubbles, responsive multiline text, auto-growing textareas, dev-time label overflow checks, Canvas/SVG/WebGL text, and avoiding DOM reflow from getBoundingClientRect/offsetHeight. This is text-layout engineering/performance, not visual design polish.
Original author description
Use for advanced web text measurement and layout with @chenglou/pretext: virtualized lists with variable-height text, shrinkwrapped chat bubbles, responsive multiline text, auto-growing textareas, dev-time label overflow checks, Canvas/SVG/WebGL text, and avoiding DOM reflow from getBoundingClientRect/offsetHeight. This is text-layout engineering/performance, not visual design polish.
How it works
- What This Skill Does
- Before Implementing
- Implementation Pattern
- Verification
- Caveats
- Attribution
SKILL.md preview
---
name: pretext
description: Use for advanced web text measurement and layout with @chenglou/pretext: virtualized lists with variable-height text, shrinkwrapped chat bubbles, responsive multiline text, auto-growing textareas, dev-time label overflow checks, Canvas/SVG/WebGL text, and avoiding DOM reflow from getBoundingClientRect/offsetHeight. This is text-layout engineering/performance, not visual design polish.
---
# Pretext Text Layout
Use this skill when the hard part is measuring or laying out text accurately without forcing browser layout reflow. Do not use it for ordinary typography taste, brand direction, or visual polish; route those to the frontend/design skills.
## What This Skill Does
`@chenglou/pretext` is a pure TypeScript text measurement and layout library. It helps agents replace repeated DOM measurement loops with deterministic text layout calls when building:
- Virtualized feeds, logs, comments, or chat lists with variable-height rows.
- Chat/message bubbles that shrinkwrap text without layout thrash.
- Auto-growing textareas or editor previews.
- Responsive/magazine/multi-column text layout experiments.
- Dev-time checks such as "does this label overflow at this width?"
- Canvas, SVG, WebGL, or custom-rendered text where the browser DOM is not doing layout.
## Before Implementing
1. Confirm the project is a JavaScript/TypeScript web project and inspect its package manager.
2. If the package is not installed, ask or state the dependency change before adding it:
```bash
npm install @chenglou/pretext
```
Use the project's existing package manager when it is not npm.
3. Match measurement inputs to rendered CSS: font family, font size, line height, letter spacing, available width, white-space behavior, and locale.
4. Ensure relevant web fonts are loaded before relying on measured output in the browser.
## Implementation Pattern
Use `prepare` for repeated layout of the same text/font inputs, then call `layout` whenever width or wrapping constraints change.
```ts
import { layout, prepare } from '@chenglou/pretext';
const prepared = prepare({
text: message.body,
font: '16px Inter',
lineHeight: 22,
whiteSpace: 'pre-wrap',
});
const box = layout(prepared, {
width: availableWidth,
});
```
For virtualization, keep prepared handles or cached layout metadata near the row model. Recompute only when the text, font metrics, or available width changes. Use the resulting height/line information to feed the virtualizer instead of mounting hidden DOM nodes.
For lower-level control, use APIs such as `prepareWithSegments`, `layoutWithLines`, `measureLineStats`, `walkLineRanges`, `layoutNextLineRange`, and `materializeLineRange` when the component needs custom segmentation, incremental line layout, or manual rendering.
For rich inline text, inspect `@chenglou/pretext/rich-inline` and keep spans/segments explicit rather than trying to infer style from rendered DOM.
## Verification
- Compare a few representative strings against the rendered browser result, including long words, emoji, mixed scripts, newlines, and narrow widths.
- Test resize behavior and font-loading timing.
- Check that the implementation reduces layout reads such as `getBoundingClientRect`, `offsetHeight`, and hidden measurement nodes.
- For virtualized lists, verify scroll position stability when data loads or widths change.
## Caveats
- Pretext is not a full CSS layout engine. It is for text measurement/layout, not arbitrary flex/grid/block layout.
- Browser font rendering, fallback fonts, and international text can still create differences; verify visually when precision matters.
- Do not add global tooling or Overdrive installer setup for this. It is a normal per-project app dependency.
## Attribution
This skill is original Overdrive guidance for using Cheng Lou's MIT-licensed `@chenglou/pretext` library.
- GitHub: https://github.com/chenglou/pretext
- npm package: `@chenglou/pretext`
- Creator credit: Cheng Lou / @_chenglou
Files in this package (2)
- SKILL.md 4 KB
- agents/openai.yaml 1 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · radustefandumitru/overdrive | 100 | Apache-2.0 |
| mateaix/mateclaw | 100 | Apache-2.0 |
| yaniv-golan/pretext-skill | 100 | MIT |
| akillness/jeo-skills | 95 | MIT |
Database snapshot: 13.11.2026 · package version f53ccc993d96 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100frontend-responsive
Use when a ticket requires a layout to work across screen sizes — mobile/tablet/desktop, fluid typography, breakpoint or container-query behaviour, zoom and reflow, or fixing overflow and touch-target issues. Invoke for "make X responsive", "fix the mobile layout", "support…