@Cool approach too. Did quick validation with
#ClaudeCode too.
# Why Pretext’s Approach is Brilliant
The web has a dirty secret: nobody knows how tall text is until they render it.
Every UI framework — React, Vue, Svelte — eventually hits the same wall. You need to know how much space text will occupy *before* you show it. Virtualized lists need row heights. Chat apps need bubble sizes. Masonry layouts need card dimensions. And the browser’s only answer is: “Render it into the DOM, force a synchronous layout reflow, read the measurement back, then do what you actually wanted to do.”
This is like weighing a letter by building a post office first.
Cheng Lou’s Pretext sidesteps the entire problem. It uses `canvas.measureText()` to get word widths — the same font engine the browser uses internally — then implements line-breaking and height calculation as pure arithmetic. The result: `prepare()` measures once (~1ms), and `layout()` answers “how tall is this text at width X?” in 0.0002ms. No DOM. No reflow. No render cycle. Just math.
This matters because **layout reflow is the single most expensive operation in the browser**. Every `getBoundingClientRect()` call forces the engine to recalculate the position and size of every affected element. In a grid with 200K rows, or a chat with 10K messages, or a dashboard with 500 cards, this cost is catastrophic. Developers work around it with fixed heights (ugly), estimated heights (inaccurate), or render-measure-hide cycles (flickery). Pretext eliminates the workaround by eliminating the problem.
The deeper insight is architectural: **measurement and rendering are two different concerns that the DOM has fused together**. Pretext separates them. Once you have accurate text height without rendering, everything downstream gets simpler — virtual scrolling becomes trivial, resize handling becomes instant, server-side layout becomes possible, and AI-generated UIs can verify their own layouts without a browser.
It’s 29KB, handles CJK/Arabic/Devanagari/emoji, and the hot path is literally free. The approach is brilliant because it’s obvious in retrospect — canvas has always been able to measure text — but nobody thought to build a complete line-breaking engine on top of it until now.