$ account chenglou
Pretext is a high-performance JavaScript/TypeScript library for text measurement and layout that operates entirely without DOM reflow. It accurately predicts line breaks, widths, and heights for any text, matching the behavior of Chrome (Blink), Firefox (Gecko), and Safari (WebKit) by porting each engine's line-breaking rules and embedding their ICU break tables. The library uses a two-phase architecture: a preparation phase that measures each character segment using Canvas `measureText()` and caches the results, followed by a pure-arithmetic layout phase that computes line breaks and positions with sub-millisecond performance. It supports plain text, rich inline spans (styled runs, atomic chips), and advanced features like letter spacing, soft hyphens, emoji handling, and CJK punctuation kerning. A comprehensive test harness records actual browser layouts of thousands of cases and scores predictions against them, with automated gates that block regressions. The repository also includes demos showing virtualized chat, editorial layouts with obstacles, justification comparison, and shrink-wrapping. While primarily an application/library, it contains significant data/research components—generated break tables from browser engines, multilingual corpora for testing, and offline invariants—making it a hybrid project with a strong research character in cross-browser text rendering.