icon of Pretext.js

Pretext.js

Pure JS/TypeScript text layout engine that measures text with Canvas and computes layouts without any DOM reads or reflows.

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.

Use cases for Pretext.js

  • People exploring AI Code tools use Pretext.js when comparing options in that category.
  • People exploring AI Text tools use Pretext.js when comparing options in that category.
  • Pretext.js is often considered alongside other AI Coding tools in this directory.
  • Pretext.js is often considered alongside other AI Chat tools in this directory.
  • Pretext.js is often considered alongside other For Learning tools in this directory.

Frequently asked questions about Pretext.js