Zero-DOM-reflow text measurement and layout. Pure JavaScript that outperforms browser layout APIs by avoiding expensive reflows.
| Method | Time (500 texts) | Triggers Reflow | Status |
|---|---|---|---|
| DOM Layout (getBoundingClientRect) | ~19,000ms | Yes β 500 reflows | Slow |
| PreText prepare() | ~19ms | No β canvas measureText | Fast |
| PreText layout() | ~0.09ms | No β pure arithmetic | Instant |
PreText is 1000x faster by avoiding DOM reflow
Chinese, Japanese, Korean with proper line breaking and width measurement
Mixed left-to-right and right-to-left text (Arabic, Hebrew) handled correctly
Full emoji support and modern Unicode grapheme clusters
Know exact heights before rendering. No guesstimates needed.
Render text to non-DOM targets with precise line breaks.
Verify UI constraints at dev time without browser testing.
Masonry, text around images, JS-driven flexbox implementations.
Pre-calculate heights before new text loads to re-anchor scroll.
Find minimum container width that fits multiline text.