
Pretext Text Measurement
Pure JavaScript and TypeScript library for DOM-free multiline text measurement, wrapping, and layout.
- skills.sh installs
- 649
- GitHub stars
- 98
- last updated
- Jul 14, 2026
Own this skill? Claim it
What it does
- Covers paragraph height, manual line layout, shrinkwrap widths, variable-width flow around images, and rich inline text with mixed fonts
- Provides
prepare()/layout()for one-time analysis and cheap per-resize arithmetic, pluslayoutWithLines,measureLineStats, andlayoutNextLineRangefor line-level control - Avoids
getBoundingClientRectandoffsetHeightreflows by measuring text through the browser's canvas font engine as ground truth - Designed for canvas rendering, virtualized list row heights, and preventing layout shift when dynamic text loads
Install
$ npx -y skills add reason-machines/trending-skills --skill pretext-text-measurement -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Pretext Text Measurement & Layout
Skill by ara.so — Daily 2026 Skills collection.
Pretext is a pure JavaScript/TypeScript library for fast, accurate, DOM-free multiline text measurement and layout. It avoids getBoundingClientRect and offsetHeight (which trigger expensive layout reflows) by implementing its own measurement logic using the browser's font engine as ground truth.
Installation
npm install @chenglou/pretext
Core Concepts
prepare()/prepareWithSegments()— one-time analysis: normalize whitespace, segment text, measure via canvas. Cache and reuse this result.layout()/layoutWithLines()etc. — cheap hot path: pure arithmetic over cached widths. Call this on every resize, notprepare().- Font string format — same as
CanvasRenderingContext2D.font, e.g.'16px Inter','700 18px "Helvetica Neue"'.
Use Case 1: Measure Paragraph Height (No DOM)
import { prepare, layout } from '@chenglou/pretext'
// One-time per unique (text, font) combination
const prepared = prepare('AGI 春天到了. بدأت الرحلة 🚀', '16px Inter')
Details
- Repository
- github.com/reason-machines/trending-skills
- Categories
- Frontend & UI Code, Animation & Motion
- First seen
- May 16, 2026
More from reason-machines/trending-skills
All 163- Claude Code Source Recovery648
- Sheets Terminal Spreadsheet646
- Omnivoice Tts627
- Metatron Pentest Assistant602
- Tong Jincheng Relationship Skill595
- Awesome Design Md Jp594
- Parlor On Device Ai588
- Paper2code Arxiv Implementation585
- Free Code Claude Cli584
- Fieldtheory Cli Bookmarks582
- Tong Jincheng Interpersonal Skill574
- Claude Code Source Study569
- Cabinet Ai Knowledge Base562
- Binance Futures Signal Bot554
- Karpathytalk Community553
- X Mentor Skill Nuwa552
- Clawgod Claude Code Patch551
- Gemma Gem Browser Ai548
- Claude Skill App Onboarding Questionnaire539
- Gemma Tuner Multimodal537
- Tailslayer Dram Hedged Reads537
- Bluehammer Vulnerability Poc527
- Alayarenderer Generative World522
- Llm Wiki Skill516
Similar to Pretext Text Measurement
More Frontend & UI Code
better-typographySkilljakubkrehel/skills43.3K installsOpinionated typography skill covering type scales, font loading, line-height, wrapping, truncation, and underlines in web interfaces.
typographySkillpetekp/agent-skills529 installsProfessional type scale, pairing, spacing, and font-loading guidance for readable, hierarchical interfaces.
better-layoutSkilljakubkrehel/skills38.8K installsStructural guidance that tests a layout against resizing, translation and RTL mirroring before it ships.
layout-analyzerSkillclaude-office-skills/skills4.8K installsSurya-based layout analysis that detects text blocks, tables, figures, and reading order in documents.
Mcp Accessibility ScannerMCP serverjustasmonkev59 starsRuns axe-core accessibility scans on live pages, with keyboard, screen-reader and text-spacing audits via a browser.
MicrochartsMCP serverganapativs209 starsWord-sized React charts with generated alt text, rendered as self-contained SVG for AI-driven use.