Dom-Independent Text Height Measurement Via Wrapping Emulation
Sources: 1 • Confidence: Medium • Updated: 2026-03-30 03:31
Key takeaways
- Pretext can calculate the height of line-wrapped paragraph text without rendering it in the DOM.
- In Pretext, prepare() tokenizes text into segments handling soft hyphens, non-Latin sequences, and emoji, measures segments using an off-screen canvas, and caches the results.
- Cheng Lou says he used Claude Code and Codex with browser ground truth to iteratively measure and refine behavior at significant container widths over weeks.
- Pretext is a browser library created by Cheng Lou, a former React core developer and the creator of react-motion.
- Pretext testing compared its estimates to browser ground truth by rendering the full text of The Great Gatsby across multiple browsers and later expanded to public-domain corpora across many languages including Thai, Chinese, Korean, Japanese, and Arabic.
Sections
Dom-Independent Text Height Measurement Via Wrapping Emulation
- Pretext can calculate the height of line-wrapped paragraph text without rendering it in the DOM.
- In Pretext, layout() emulates browser word-wrapping to compute wrapped line count at a given width and derive the resulting height.
Prepare/Layout Pipeline With Canvas Measurement And Caching
- In Pretext, prepare() tokenizes text into segments handling soft hyphens, non-Latin sequences, and emoji, measures segments using an off-screen canvas, and caches the results.
- Pretext structures computation as a single prepare() step followed by multiple layout() calls.
Llm-Assisted Development Loop Tied To Ground Truth
- Cheng Lou says he used Claude Code and Codex with browser ground truth to iteratively measure and refine behavior at significant container widths over weeks.
- The author used Claude to build an interactive artifact visualizing a simplified version of Pretext.
Claims About Footprint And Handling Browser Quirks/Complex Scripts
- Pretext is a browser library created by Cheng Lou, a former React core developer and the creator of react-motion.
- Cheng Lou claims Pretext is only a few kilobytes, accounts for browser quirks, and supports complex multilingual scenarios including Korean mixed with right-to-left Arabic and platform-specific emojis.
Validation Approach Emphasizes Browser Ground Truth And Multilingual Corpora
- Pretext testing compared its estimates to browser ground truth by rendering the full text of The Great Gatsby across multiple browsers and later expanded to public-domain corpora across many languages including Thai, Chinese, Korean, Japanese, and Arabic.
Unknowns
- How accurate is the computed height versus actual DOM layout across a broad range of fonts, font-loading states, OS font stacks, and browser versions?
- What are the performance characteristics (latency, throughput, memory) for prepare() and layout() under realistic workloads (very long documents, frequent resizes, many concurrent paragraphs)?
- Which specific browser text-layout behaviors are emulated (and which are not), and how is parity maintained as browsers change wrapping/typography behavior over time?
- Is the “few kilobytes” size claim reproducible under typical production bundlers and configurations, and what features (e.g., multilingual edge cases) are included at that size?
- How generalizable and repeatable is the LLM-assisted, ground-truth-driven development loop for keeping behavior aligned with browsers (e.g., rerunning the process for new browser releases)?