MANIFESTO

"I have crawled through the depths of hell to bring you this foundational piece of UI engineering."

Pretext is more than a library; it is a declaration of independence for web developers to escape the shackles of DOM-based layout.

The Problem

The Overlooked DOM Tax

In the age of AI, text measurement has become the final barrier to fluid and dynamic innovation.

The Interleaving Death Loop

Every time you call getBoundingClientRect(), the browser is forced into a synchronous reflow. In large-scale UIs, this Read/Write Interleaving is the most expensive operation on the web, killing 120fps performance.

The Pretext Solution

Decouple layout from the browser's render loop. By using Pure Arithmetic in memory to compute typography, performance is boosted by 500x — bringing layout back to arithmetic.

I have crawled through the depths of hell to bring you, for the foreseeable years, one of the more important foundational pieces of UI engineering.
CL
Cheng Lou
React · ReasonML · ReScript · Midjourney
The Creator

Back from the Depths

Cheng Lou is a veteran of the front-end ecosystem — a core contributor to React, the creator of ReasonML and ReScript, and later an engineer at Midjourney.

This time, he returned with something different: not a framework or a compiler, but a fundamental rethinking of how browsers handle text.

🤖
AI-Calibrated for Weeks

The algorithm was calibrated by having Claude Code and Codex measure the browser's ground truth at every significant container width, running for weeks — until pixel-perfect accuracy was achieved.

📦
Few KBs. Zero DOM.

The engine is tiny, supports Korean mixed with RTL Arabic, handles platform-specific Emoji quirks, and works with Canvas, WebGL, and even XR environments.

Unlocking the "Unsolvable"

Bypassing the Status Quo

120fps Virtualization

Occlusion of hundreds of thousands of text boxes — each a different height — without touching the DOM. A single linear traversal replaces the entire measurement stack. Masonry. Infinite scrolls. All simplified.

🤖

Deterministic AI UIs

When interfaces are synthesized on-the-fly by AI agents, you can't afford reflow bottlenecks. Pure arithmetic layout means AI can compute interfaces deterministically, not by guess-and-check CSS.

📰

Responsive Magazines

True multi-column layouts, as precise as print — yet dynamic. Drag a handle and watch the text reflow in real time across columns. A problem CSS Regions promised to solve and never did.

💬

Shrinkwrapped Bubbles

Chat bubbles that automatically hug their content width with mathematical precision — no CSS tricks, no fixed widths, no measurement hacks.

👾

Variable ASCII Art

Every character's position is calculated mathematically. Even ASCII art achieves the elegance of proportional fonts at 120fps — because it's just arithmetic now.

📐

Auto-Growing Inputs

Auto-growing text areas, accordions, multi-line centering, pure Canvas multiline — all the CSS riddles that kept senior devs up at night, now reduced to a boring footnote.

A Win for Arithmetic

This is not just a speed lead, but a leap in engineering philosophy.

  • Cold/Hot Path Separation: Analysis and calculation are perfectly decoupled.
  • Script Aware: Effortless mixed layout for Arabic, CJK, and Thai.
  • Emoji Precision: Automatic correction of browser-level Canvas discrepancies.
Native DOM Layout
~50.0ms
Pretext Layout
0.1ms
Live Demos

See It In Action

Interactive playgrounds that showcase what becomes possible when text layout is pure math.

Get Started

Zero Dependencies.
One Install.

A few KBs of pure TypeScript. No native modules, no WASM bundles, no DOM required — works in the browser, Canvas, WebGL, and even server-side.

terminal
npm install @chenglou/pretext
# or
bun install @chenglou/pretext
core-api.ts
import { prepare, layout } from '@chenglou/pretext';

// Step 1: Analyze text once (cold path)
const handle = prepare(text, '16px Inter');

// Step 2: Layout at any width, instantly (hot path)
const results = layout(handle, containerWidth, lineHeight);
// → { lines, totalHeight, totalWidth }
Community

The Internet Reacts

What the front-end world said when Pretext dropped.

★★★★★

"The masonry virtualization at 120fps with varying heights is insane. Text measurement has been the silent killer of smooth custom UIs for years."

— Developer on X
★★★★★

"bypassing DOM measurement is load-bearing infrastructure for the AI-generated UI era — when the interface itself is synthesized on the fly, you can't afford reflow bottlenecks."

— Developer on X
★★★★★

"everyone spent a decade arguing CSS-in-JS vs utility classes while this man just said 'what if no CSS at all' — this is what happens when someone actually solves problems."

— Developer on X
★★★★★

"solving the problem CSS pretended didn't exist for 25 years. Everyone's thought about this. He just actually did it."

— Developer on X
★★★★★

"if you can measure and lay out text without the DOM, you can render UI anywhere — canvas, WebGL, native. The browser layout engine stops being the bottleneck. That's not a library. That's a paradigm escape."

— Developer on X
★★★★★

"My wife has a fashion website and has always wanted a magazine layout. I converted one of her articles and she is very excited."

— Early adopter on X

"Stop begging the DOM for layout dimensions. Now, you command them."