What problem does it solve?
Pretext lets you create creative browser demos where text layout must be measured precisely before rendering, enabling effects like reflow around moving obstacles and text-as-geometry visuals without DOM-based layout thrashing.
Core Features & Use Cases
- DOM-free multiline text measurement: Compute line breaks, widths, grapheme positions, and total height from (text, font, width) to eliminate layout shift.
- Two key workflows: Use measurement only (DOM/CSS rendering) or measure-and-render yourself (canvas/WebGL/SVG with per-glyph transforms).
- Creative demo patterns: Flow text around obstacles with
layoutNextLineRange, animate kinetic typography, build text-based games, shatter typography into particles, and derive obstacle spans from ASCII/raster masks.
- No build step demos: Produce single-file HTML demos that import
@chenglou/pretext via a CDN.
Quick Start
Use the pretext templates to generate a single-file HTML demo (for example, templates/hello-orb-flow.html) that imports @chenglou/[email protected] and flows a paragraph around a moving orb.