pretext

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

5|2|Updated May 26, 2026
One-click install
npx skills add https://github.com/perasyudha/Nyxora --skill pretext-perasyudha
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/perasyudha/Nyxora/tree/main/packages/core/playbooks/creative/pretext
Command: npx skills add https://github.com/perasyudha/Nyxora --skill pretext-perasyudha

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building browser demos where text flows around moving shapes, forms game geometry, or shatters into particles requires knowing line breaks before rendering, which CSS and the DOM cannot provide without expensive reflows. ## Core Features & Use Cases - Variable-width text reflow: Uses layoutNextLineRange to flow paragraphs around dragged sprites, ASCII logos, and morphing wire shapes at 60fps. - Text-as-geometry demos: Builds Breakout-style games with word-bricks, per-grapheme shatter physics, kinetic typography, and multiline shrink-wrap cards. - Ready-made templates and patterns: Ships two working single-file HTML starters plus a patterns reference covering seven reusable demo recipes. - Use Case: A user asks for a cool demo where an editorial paragraph parts around a draggable glowing orb; the skill produces a self-contained HTML file using pretext via esm.sh with a tuned dark palette and real prose. ## Quick Start Ask the agent to build a pretext demo where text flows around a draggable orb, and it will write a single 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 materializeLineRange to get each line's text and draw it with canvas fillText, skipping rows too narrow to fit a line.

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 without triggering DOM reflow.

How do I import pretext in a browser HTML file?

Import from https://esm.sh/@chenglou/[email protected] inside a script type=module tag, since esm.sh compiles the TypeScript exports to browser-ready ESM. Avoid unpkg, which may 404 or serve raw TypeScript.

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 solves layout, rich text editors, or general inline formatting engines, since the library is intentionally narrow. It also does not handle image-to-text conversion or non-text generative art.

How do I split text into graphemes for per-letter animation?

Use Intl.Segmenter with granularity set to grapheme, which correctly handles emoji, combining marks, and CJK characters. Plain string split breaks multi-codepoint characters into invalid fragments.