pretext

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

6|1|Updated May 11, 2026
One-click install
npx skills add https://github.com/yakeworld/Synthos --skill pretext-yakeworld
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pretext
Source: https://github.com/yakeworld/Synthos/tree/main/skills/extended/external-automation/creative/web-code/pretext
Command: npx skills add https://github.com/yakeworld/Synthos --skill pretext-yakeworld

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building creative text-layout demos (text flowing around moving shapes, word-brick games, shattering typography) normally requires expensive DOM reflows or guesswork about line breaks. This Skill uses the @chenglou/pretext library to measure multiline text on canvas without touching the DOM, so line breaks, per-grapheme positions, and heights are known before rendering. ## Core Features & Use Cases - Reflow around obstacles: Stream lines with layoutNextLineRange and a per-row width function so prose parts around a draggable sprite or ASCII logo at 60fps. - Text-as-geometry and kinetic type: Use prepareWithSegments, walkLineRanges, and Intl.Segmenter to get per-grapheme coordinates for shatter/particle physics, word-brick Breakout, and animated editorial layouts. - Use Case: A user asks for a demo where a paragraph of real prose flows around a draggable glowing orb. The Skill starts from the hello-orb-flow.html template, swaps in meaningful corpus text, tunes the dark palette and proportional font, and delivers one self-contained HTML file verified via python3 -m http.server. ## Quick Start Ask the agent to build a pretext demo where a paragraph of real prose reflows around a draggable orb, delivered as a single self-contained 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 span at each y position. Call prepareWithSegments once, then recompute line ranges every frame as the shape moves; skip rows where the corridor is too narrow rather than passing a tiny maxWidth.

What is the @chenglou/pretext library 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, per-grapheme positions, and total height via canvas measurement, with no reflow.

Can I import @chenglou/pretext from unpkg in a browser?

No. unpkg serves the raw TypeScript entry, which 404s or fails to parse in browsers. Import from https://esm.sh/@chenglou/[email protected] instead, since esm.sh compiles the TS exports to browser-ready ESM, and pin the version.

Why do my pretext measurements not match the rendered text?

Measurement drift happens when the canvas font string differs from the rendered CSS font, often because a web font 404s and CSS falls back to another family. Preload the font and keep the ctx.font string exactly in sync with the CSS.

How do I split text into graphemes for emoji and CJK particle effects?

Use new Intl.Segmenter(undefined, { granularity: 'grapheme' }) to split text into visible glyphs. Plain string split breaks emoji, combining marks, and CJK into invalid fragments, which corrupts per-glyph physics and positioning.

When should I not use pretext for text layout?

Avoid pretext for static pages where CSS already handles layout, rich text editors, and general inline formatting engines, since the library is intentionally narrow. It fits cases needing line breaks or glyph positions known before rendering.