pretext-text-measurement — Claude Code skill: setup and features
Calculates multiline text dimensions and line breaking in JavaScript without touching DOM layout properties or triggering reflow.
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a claude-codeWhat pretext-text-measurement does
This skill guides coding agents on using @chenglou/pretext for estimating typography bounds in client-side code. Instead of querying properties like offsetHeight or calling getBoundingClientRect, which force browser layout recalculation, it processes string dimensions through cached font metrics.
The workflow separates preparation from placement. An initial call to prepare normalizes spaces and samples segment lengths via canvas context, while repeated calls to layout perform lightweight math during container resizes. That makes it suitable for canvas text rendering and virtual list row heights.
Running the resulting implementation requires adding @chenglou/pretext to your project dependencies.
What it helps with
- Determine paragraph height without touching DOM nodes
- Break text into lines for HTML canvas drawing
- Pre-calculate row heights for virtualized scrolling lists
- Flow text around floated graphics with dynamic line widths
Example prompts for the agent
- Show how to compute textarea height without reflow using pretext
- Generate code to split a paragraph into canvas lines with prepareWithSegments
- Measure row heights for a virtualized list using pretext layout
How to install pretext-text-measurement
1Skills CLI (Vercel)
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a claude-code2Manually: put the files in place
~/.claude/skills/pretext-text-measurement/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/pretext-text-measurement/
1Skills CLI (Vercel)
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a codex2Manually: put the files in place
.agents/skills/pretext-text-measurement/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a cursor2Manually: put the files in place
.cursor/skills/pretext-text-measurement/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install reason-machines/trending-skills pretext-text-measurement2Manually: put the files in place
.github/skills/pretext-text-measurement/SKILL.md1Skills CLI (Vercel)
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a gemini-cli2Platform CLI
gemini skills install https://github.com/reason-machines/trending-skills --path skills/pretext-text-measurementManually: put the files in place
.devin/skills/pretext-text-measurement/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about pretext-text-measurement
How do I install pretext-text-measurement in Claude Code?
Run npx skills add reason-machines/trending-skills --skill pretext-text-measurement -a claude-code. The skill definition will be added under ~/.claude/skills/pretext-text-measurement/SKILL.md.
What is pretext-text-measurement used for?
It instructs agents to measure text bounds and wrap lines using @chenglou/pretext without reading DOM layout properties. This keeps resizing operations fast and avoids layout reflows.
Does pretext require DOM elements to measure text?
It runs without DOM elements by measuring glyph metrics once and computing line breaks through pure arithmetic. You must install the @chenglou/pretext package in your project for the code to run.