Pretext.js is a high-performance, pure JavaScript/TypeScript text layout engine that measures and lays out multiline text without touching the DOM. It uses the browser Canvas font engine (measureText) during a single prepare() pass to capture real glyph metrics, caches results, and then computes line breaks and heights purely with arithmetic in layout() — meaning zero getBoundingClientRect calls, zero forced synchronous reflows, and extremely fast repeated layout calculations. Key features include TypeScript-native API, multilingual/script-aware segmentation (CJK, Arabic, Hebrew, Thai, Hindi, Korean), reusable prepared handles for multiple widths, no runtime dependencies, and production-ready performance for virtual scrolling, chat UIs, editors, and other text-heavy interfaces.

