pretext

Generate single-file HTML demos using @chenglou/pretext for DOM-free text layout and kinetic typography.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill pretext-chensihakniroth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/Chensihakniroth/ANAKOT-AGENT/tree/main/skills/creative/pretext
Command: npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill pretext-chensihakniroth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @chenglou/pretext, gsap, lil-gui, and includes references (resource) components.

What problem does it solve? Measuring multiline text layout in the browser normally requires DOM reads and reflows, making effects like text flowing around moving shapes or per-glyph physics impractical at 60fps. This Skill uses @chenglou/pretext to compute line breaks, widths, and grapheme positions without touching the DOM, then renders the results on canvas. ## Core Features & Use Cases - Text reflow around obstacles: Stream lines with variable per-row widths so paragraphs part around dragged sprites, ASCII logos, or morphing wire shapes. - Text-as-geometry games and kinetic typography: Build Breakout-style word bricks, shatter sentences into per-glyph particles, or animate per-line transforms. - Multiline shrink-wrap and editorial layouts: Compute tightest container widths and flow text across multiple columns with a shared cursor. - Use Case: A user asks for a demo where a paragraph of real prose flows around a draggable glowing orb; the Skill produces a single self-contained HTML file using layoutNextLineRange with a per-row width function. ## Quick Start Ask the agent to create a pretext demo, for example: build a single-file HTML page where a paragraph of prose flows around a draggable orb using @chenglou/pretext.

Frequently Asked Questions about pretext

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make text flow around a moving shape in the browser?▼

Use @chenglou/pretext's layoutNextLineRange with a per-row width function that returns the corridor width at each y position. This lets paragraphs reflow around a dragged sprite or orb at 60fps without any DOM reflow.

What is @chenglou/pretext used for?▼

Pretext is a 15KB zero-dependency TypeScript library for DOM-free multiline text measurement. Given text, font, and width, it returns line breaks, per-line widths, and grapheme positions via canvas measurement, enabling creative text layout effects.

Does pretext work with emoji and CJK characters?▼

Yes, but you must use Intl.Segmenter with grapheme granularity when splitting text into individual glyphs. Splitting strings directly breaks emoji, combining marks, and CJK characters into invalid fragments.

Why do my pretext measurements not match the rendered text?▼

The canvas ctx.font string must exactly match the CSS font, and the web font must actually load. If the font 404s and CSS falls back to another family, measurements drift by 5-20 percent.

When should I not use pretext for text layout?▼

Avoid pretext for static pages where CSS already solves layout, rich text editors, or general inline formatting engines. It is intentionally narrow and only handles measurement and line breaking, not full text rendering.

Why is my pretext animation running slowly?▼

The most common cause is calling prepare or prepareWithSegments inside the animation loop. Prepare once per text and font pair, cache the handle, and only rerun layout functions per frame or on resize.