Switch language한국어
Back to the list

Pretext: TypeScript library for multiline text measurement and layout

TL;DR AI

Key summary

2 min read
  1. Pretext is a TypeScript library that measures and layouts multiline text using canvas measureText.

  2. It uses prepare(text, font) to segment text and cache word widths and layout(prepared, maxWidth, lineHeight) to compute lines and height with arithmetic.

  3. The library performs one DOM calibration per font for emoji correction and reports about 0.0002ms per text on resize.

  4. Source code is available on GitHub at chenglou/pretext.

Read the original