Pretext
JavaScript and TypeScript library for measuring and laying out text
Worth exploring
Prepare text measurements once, then recalculate lines when the width changes.
- Why it works
- Reusing prepared measurements lets layout run again without remeasuring the same text and font.
- Watch out
- Prepare again when text, font, or options change to avoid using stale measurements.
What it is
It measures paragraphs without querying DOM layout and can render lines in DOM, Canvas, or SVG. Preparation caches measurements for layout calculations.
What it’s for
For chat developers who need to calculate message height before rendering.
Benefits
- Paragraph measurement without DOM layout
- Manual line layout




