Pretext: TypeScript library for multiline text measurement and layout
TL;DR AI
2 min readKey summary
Pretext is a TypeScript library that measures and layouts multiline text using canvas measureText.
It uses prepare(text, font) to segment text and cache word widths and layout(prepared, maxWidth, lineHeight) to compute lines and height with arithmetic.
The library performs one DOM calibration per font for emoji correction and reports about 0.0002ms per text on resize.
Source code is available on GitHub at chenglou/pretext.


