Pretext is a JavaScript/TypeScript library that measures multiline text and computes layout without using the DOM, leveraging canvas‑based measurement for speed and accuracy.
Highlights
Avoids DOM reflows by measuring text with the browser's font engine via canvas.
Provides prepare() for one‑time normalization and segment measurement.
layout() performs fast arithmetic on cached widths for hot‑path calculations.
Full language, emoji, and mixed‑bidi support including whitespace handling options.
npm installable package with live demos and benchmark data.
auto-generated
chenglou · via GitHub
Context
Audience
Front end developers and UI engineers who need accurate, high performance text measurement and custom layout without triggering browser reflows
DomainWeb Front End Development
Formatopen source GitHub repository with npm package
Accessfree open source code with online documentation