pretext

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

Updated Jul 10, 2026
One-click install
npx skills add https://github.com/AvaTar-ArTs/.Agent-skills --skill pretext-avatar-arts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/AvaTar-ArTs/.Agent-skills/tree/main/skills/creative/pretext
Command: npx skills add https://github.com/AvaTar-ArTs/.Agent-skills --skill pretext-avatar-arts

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building creative browser demos with text that flows around moving shapes, shatters into particles, or forms game geometry requires knowing line breaks before rendering, which standard CSS cannot provide. This Skill uses the @chenglou/pretext library to measure and lay out text without DOM reflow, enabling text-as-geometry effects at 60fps. ## Core Features & Use Cases - Variable-width text reflow: Streams lines around moving obstacles (orbs, ASCII logos, wire shapes) using layoutNextLineRange with per-row width functions. - Text-as-geometry games and kinetic typography: Builds Breakout-style word bricks, shatter/particle effects, and animated editorial layouts from measured line and grapheme positions. - Ready-made templates and patterns: Ships two working single-file HTML starters (hello-orb-flow, donut-orbit) plus a patterns reference covering seven demo recipes. - Use Case: A user asks for a demo where a paragraph parts around a draggable glowing orb; the Skill produces a self-contained HTML file using prepareWithSegments and layoutNextLineRange that runs at 60fps with no build step. ## Quick Start Ask the agent to create a pretext demo where text flows around a draggable orb, starting from the hello-orb-flow template and saving it as a single HTML file.

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 stream lines each frame, skipping rows where the corridor is too narrow.

What is @chenglou/pretext used for?

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, enabling text-as-geometry creative demos.

How do I import pretext in a browser without a build step?

Import from esm.sh with a pinned version, for example https://esm.sh/@chenglou/[email protected], inside a script type=module tag. Avoid unpkg, which can 404 or serve raw TypeScript that browsers cannot execute.

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 the font string 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 tools for image-to-ASCII conversion or non-text canvas art.

Why is my pretext animation slow or dropping frames?

The common cause is calling prepare or prepareWithSegments inside the animation loop; only layout functions are cheap enough per frame. Cache the prepared handle in module scope and set ctx.font once per frame rather than per fillText call.