Dom-Free Text Height Estimation In The Browser
Sources: 1 • Confidence: Medium • Updated: 2026-04-12 10:21
Key takeaways
- Pretext can calculate the height of line-wrapped paragraph text without rendering it in the DOM.
- Pretext's prepare() tokenizes text into segments (including soft hyphens, non-Latin sequences, and emoji), measures segments using an off-screen canvas, and caches results.
- Cheng Lou has stated that Pretext's behavior was iteratively refined over weeks using Claude Code and Codex with browser ground truth at significant container widths.
- Pretext is described as achieving much faster text measurement than DOM render-and-measure by using multiple optimization tricks.
- Pretext testing compared estimates to browser ground truth by rendering the full text of The Great Gatsby across multiple browsers, and later expanded to public-domain corpora in multiple languages including Thai, Chinese, Korean, Japanese, Arabic.
Sections
Dom-Free Text Height Estimation In The Browser
- Pretext can calculate the height of line-wrapped paragraph text without rendering it in the DOM.
- Pretext's prepare() tokenizes text into segments (including soft hyphens, non-Latin sequences, and emoji), measures segments using an off-screen canvas, and caches results.
- Pretext's layout() emulates browser word-wrapping to compute wrapped line count at a given width and derive resulting height.
Api Architecture Enabling Reuse Across Repeated Layout Queries
- Pretext's prepare() tokenizes text into segments (including soft hyphens, non-Latin sequences, and emoji), measures segments using an off-screen canvas, and caches results.
- Pretext's layout() emulates browser word-wrapping to compute wrapped line count at a given width and derive resulting height.
- Pretext splits computation into a single prepare() step followed by multiple layout() calls.
Llm-Assisted Implementation And Refinement Loop Tied To Browser Outputs
- Cheng Lou has stated that Pretext's behavior was iteratively refined over weeks using Claude Code and Codex with browser ground truth at significant container widths.
- An interactive artifact was built with Claude to visualize a simplified version of Pretext to aid understanding.
Performance And Footprint Claims As Decision-Relevant But Unverified Properties
- Pretext is described as achieving much faster text measurement than DOM render-and-measure by using multiple optimization tricks.
- Cheng Lou has stated that the Pretext engine is only a few kilobytes, accounts for browser quirks, and supports complex multilingual scenarios including mixed Korean and right-to-left Arabic and platform-specific emojis.
Validation Strategy: Corpus-Based Ground Truth Across Browsers And Languages
- Pretext testing compared estimates to browser ground truth by rendering the full text of The Great Gatsby across multiple browsers, and later expanded to public-domain corpora in multiple languages including Thai, Chinese, Korean, Japanese, Arabic.
Unknowns
- What is the measured accuracy of estimated heights versus DOM ground truth across browsers, fonts, and scripts (including worst-case and tail errors)?
- What are the actual performance characteristics (throughput/latency) compared to DOM measurement under defined workloads, including cold-cache vs warm-cache and low-end devices?
- What is the verified production bundle size of Pretext (after typical bundler/minifier settings), and what optional features or language support affect that size?
- How does Pretext handle font loading and late style changes (e.g., font substitution, variable fonts), and what cache invalidation mechanisms exist?
- Which specific browser versions/engines are covered by the ground-truth tests, and how often are tests rerun or updated to track engine changes?