Launch
PRETEXT.JS
Visit
Example Image

PRETEXT.JS

Text measurement that never touches the DOM.

Visit

Pretext.js is the official website for Pretext, a pure JavaScript/TypeScript text measurement and

layout engine created by Cheng Lou (chenglou), a former React core team member now at Midjourney.

The library solves a 30-year browser bottleneck: to know how tall a block of text will be,

developers have always had to render it in the DOM and ask the browser — a process that forces

expensive synchronous layout reflow.

Pretext eliminates this entirely with a two-phase architecture. The prepare() function measures

text once via Canvas and Intl.Segmenter, then the layout() function computes line breaks and

heights using pure arithmetic in ~0.0002ms — roughly 600× faster than traditional DOM measurement.

No reflow, no thrashing, no dependencies.

The website features an interactive playground where developers can experiment with Pretext in real

time, live examples demonstrating virtual scrolling, chat bubbles, multilingual content, and

accordion animations, and comprehensive documentation of the library's API. Pretext supports 12+

writing systems including CJK, Arabic, Hebrew, Thai, and mixed bidirectional text.

Pretext.js is MIT-licensed, weighs approximately 15KB, and works with any framework — React, Vue,

Svelte, or vanilla JavaScript. It is used in production at Midjourney to handle real-time AI text

streaming without layout shift.

Example Image
Example Image
Example Image
Example Image

Comments