pretext

Create browser demos with DOM-free text measurement and canvas layout using @chenglou/pretext.

1|Updated Aug 6, 2026
One-click install
npx skills add https://github.com/agtktID/indagis-agent --skill pretext-agtktid
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/agtktID/indagis-agent/tree/main/skills/creative/pretext
Command: npx skills add https://github.com/agtktID/indagis-agent --skill pretext-agtktid

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Measuring multiline text in the browser normally requires DOM reads like getBoundingClientRect, which cause reflow thrash and make animated text layouts impractical. This Skill uses the @chenglou/pretext library to compute line breaks, per-line widths, and per-grapheme positions purely via canvas measurement, enabling text effects that CSS cannot produce. ## Core Features & Use Cases - Variable-width text flow: Stream lines around moving obstacles (sprites, ASCII logos, wire shapes) using layoutNextLineRange with per-row width functions at 60fps. - Text-as-geometry demos: Build games where bricks or obstacles are measured words, shatter typography into per-glyph particles, and drive kinetic type with per-line transforms. - Multiline shrink-wrap and measurement: Compute exact box heights and tightest container widths without touching the DOM, for virtualized lists and masonry layouts. - Use Case: A user asks for a hero section where a paragraph parts around a draggable glowing orb. The Skill starts from the hello-orb-flow.html template, swaps in real prose, tunes the palette and font, and delivers a single self-contained HTML file. ## Quick Start Ask the agent to build a pretext demo where text flows around a moving shape, and it will generate a self-contained HTML file you can open with python3 -m http.server.

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 pretext's layoutNextLineRange with a per-row width function that returns the corridor width at each y position. Call it in a loop each frame, skipping rows too narrow to fit a line, so paragraphs reflow around the obstacle at 60fps without DOM reads.

What is @chenglou/pretext used for?▼

Pretext is a 15KB zero-dependency TypeScript library that measures multiline text via canvas, returning line breaks, per-line widths, and grapheme positions for a given text, font, and width. It enables layouts and text effects that CSS cannot produce.

Does pretext work with emoji and CJK characters?▼

Yes, but you must split text with Intl.Segmenter using grapheme granularity rather than String.split, which breaks emoji and combining marks into separate characters. Intl.Segmenter is built into every modern browser.

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

The canvas ctx.font string must exactly match the rendered CSS font, including weight and family. If a web font fails to load, CSS falls back to another family and measurements drift by 5-20%, so always preload fonts explicitly.

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, since the library is intentionally narrow. Also use dedicated tools for image-to-ASCII conversion or canvas art with no text role.

How do I keep pretext demos running at 60fps?▼

Call prepare or prepareWithSegments only once per text and font pair, then rerun only the cheap layout functions on resize or per frame. Set ctx.font once per frame rather than per fillText call, since changing canvas font state is slow.