@chenglou/pretext

Text layout
without the DOM.

Measure multiline text height using canvas.measureText — no layout reflow, no getBoundingClientRect. 100% accurate across all languages.

Dragon · Live Text Reflow

Text reflows around the dragon in real‑time at 60fps using layoutNextLine — zero DOM reads, pure arithmetic.

dragon
LINES 0REFLOW 0.0msDOM READS 0FPS 60

Sample Text

320px
font: 16px Georgia · line-height: 26px
Heightpx
Lines
prepare()ms
layout()ms

Usage

import { prepare, layout } from '@chenglou/pretext'

const prepared = prepare(
  "The quick brown fox jumps over the lazy dog. Typography…",
  '16px Georgia'
)

// Arithmetic calculation bypassing DOM representation and visual layouts
const { height, lineCount } = layout(prepared, 320, 26)
// → height: ?px  lineCount: ?