pretext

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building text-driven visual demos in the browser normally requires DOM reflows and getBoundingClientRect calls that are too slow for 60fps animation. This Skill teaches how to use the @chenglou/pretext library to measure and lay out multiline text without touching the DOM, enabling effects like text reflowing around moving shapes, word-based games, and kinetic typography. ## Core Features & Use Cases - Variable-width text flow: Use layoutNextLineRange to stream lines around moving obstacles such as draggable orbs, ASCII logos, or morphing wire shapes. - Text-as-geometry demos: Build Breakout-style games with word bricks, shatter typography into per-grapheme particles, or drive ASCII art from real prose. - Measurement-only layouts: Compute multiline heights and shrink-wrap widths for virtualized lists, masonry grids, and quote cards without DOM reads. - Use Case: A user asks for a hero section where a paragraph parts around the cursor as it moves. The Skill provides a single-file HTML template using prepareWithSegments and per-row width functions to reflow text live at 60fps. ## Quick Start Ask the agent to build a pretext demo where a paragraph of real prose flows around a draggable glowing orb, saved as a single HTML file you can open in the browser.

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 subtracts the obstacle's horizontal span at each y position. Call prepareWithSegments once, then request each line's range inside the animation loop and draw with ctx.fillText.

What is @chenglou/pretext used for?▼

@chenglou/pretext is a 15KB zero-dependency TypeScript library for DOM-free multiline text measurement and layout. Given text, font, and width, it returns line breaks, per-line widths, and grapheme positions via canvas measurement without causing reflow.

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 invalid fragments. Intl.Segmenter is built into every modern browser.

Why do pretext measurements not match my rendered text?▼

Measurement drift happens when the canvas ctx.font string differs from the rendered CSS font, often because a web font failed to load and CSS fell back to another family. Preload the font and keep both font strings exactly in sync.

When should I not use pretext for text layout?▼

Avoid pretext for static pages where CSS already handles layout, rich text editors, or general inline formatting engines, since the library is intentionally narrow. Also use dedicated image-to-ASCII tools for image conversion rather than pretext.

Why is my pretext animation slow?▼

The common cause is calling prepare or prepareWithSegments inside the animation loop, which is the expensive operation. Cache the prepared handle in module scope and only rerun layout functions per frame; also set ctx.font once per frame rather than per fillText call.