What problem does it solve?
It solves the challenge of building creative, browser-based text layouts (like word-games, ASCII-style typography, and text-as-geometry) without relying on DOM layout tricks or expensive reflows.
Core Features & Use Cases
- Deterministic text measurement and line layout: uses DOM-free multiline measurement to compute line breaks, per-line widths, and grapheme positions for the exact font metrics you specify.
- Flow around moving obstacles: routes text row-by-row around a variable-width corridor so paragraphs can wrap around sprites, shapes, or projected ASCII masks.
- Creative primitive for custom rendering: returns geometry data so you can draw with canvas (or other coordinate systems) and apply kinetic typography, per-glyph effects, and generative compositions.
Use it when the user wants a “pretext demo,” text that flows around an orb/shape, text-as-collision/gameplay geometry, kinetic typography, or single-file HTML generative artwork using real prose (not lorem ipsum).
Quick Start
Create a single self-contained HTML file that imports @chenglou/pretext, prepares the user’s text with the exact canvas font string, then uses layoutNextLineRange to stream line segments around the obstacle each frame.