Pretext

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Developers can now compute line-wrapped text heights entirely in JavaScript without expensive DOM measurement, unlocking faster dynamic text layouts and effects in browser apps.

Read this as

Pretext is a free browser library from Cheng Lou, the programmer who created the React animation library react-motion. It answers a tricky question: how tall will a paragraph of text be after the browser wraps it into lines? Normally you have to actually display the text and measure it, which is slow. Pretext instead measures words once using a hidden canvas, then does the line-wrapping math in memory, allowing applications to add live text effects and layouts without lag.

Pretext, an open-source library from former React core developer Cheng Lou, removes a performance bottleneck: measuring wrapped text heights previously required costly rendering to the page's structure. Teams building editors, document tools, or animation-heavy interfaces gain faster text layout with no licensing cost since it is on GitHub. Adoption risk is low, though accuracy was validated only against browser rendering of test documents rather than a formal benchmark. No pricing or support terms are stated.

Pretext (github.com/chenglou/pretext) splits text into segments, handling soft hyphens, non-Latin scripts and emoji, measures each with an off-screen canvas in a one-time prepare() call, caches results, then layout() emulates browser word-wrapping to compute line counts and heights at a given width. Validation rendered the full Great Gatsby across multiple browsers, later extended to Thai, Chinese, Korean, Japanese and Arabic corpora. No specific speedup figures are published in the article.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

Pretext Cheng Lou react-motion React Claude Great Gatsby

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading