pretext
Build creative browser demos with DOM-free text layout.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- pretext
- metadata
- { "tags": [ "creative-coding", "typography", "pretext", "ascii-art", "canvas", "generative", "text-layout", "kinetic-typography" ], "related_skills": [ "p5js", "architecture-diagram" ] }
- description
- Build creative browser demos with DOM-free text layout.
- when-to-use
- Use when the user wants a pretext creative demo — text flowing around a moving shape, ASCII-art effects using real words, text-as-geometry games, kinetic typography, multiline shrink-wrap UI, or per-glyph physics.
- argument-hint
- <pattern> [output.html]
02 资源文件 6
- 参考文档references/community-demos.md848 B
- 参考文档references/patterns.md10.2 KB
- 参考文档references/pitfalls.md3.9 KB
- 参考文档references/stack-and-use-cases.md3.4 KB
- 参考文档templates/donut-orbit.html52.0 KB
- 参考文档templates/hello-orb-flow.html3.4 KB
03 SKILL.md 正文
Pretext Creative Demos
@chenglou/pretext is a 15KB
zero-dependency TypeScript library by Cheng Lou (React core, ReasonML,
Midjourney) for DOM-free multiline text measurement and layout: given
(text, font, width), it returns line breaks, per-line widths, per-grapheme
positions, and total height via canvas measurement, no reflow. It is a creative
primitive: reflow paragraphs around a moving sprite at 60fps, build games whose
level geometry is real words, shatter text into particles, or pack
shrink-wrapped multiline UI with zero getBoundingClientRect thrash.
This skill makes cool demos with it — the kind people post to X. The
community demo corpus is at pretext.cool and chenglou.me/pretext.
Global rules
- Creative standard. Pretext returns numbers; you draw the thing. Don't
ship a "hello world" demo — the
hello-orb-flow.htmltemplate is the starting point; every delivered demo adds intentional color, motion, composition, and one visual detail the user didn't ask for. Dark backgrounds with considered palettes (amber-on-black, editorial white-on-charcoal, risograph pastels). Proportional fonts are the point — lean into "not monospaced". Use real source text, never lorem ipsum. First-paint excellence: no loading states, no blank frames. - Scope. Use pretext only when the demo needs to know line breaks before
rendering. Don't use for static CSS/HTML layouts, rich text editors, image →
text (use
ascii-art/ascii-videoskills), or canvas generative art with no text role (usep5js). - Stack. Single self-contained HTML file per demo, no build step:
@chenglou/pretextvia esm.sh CDN, Canvas 2D for rendering,Intl.Segmenterfor grapheme splits, raw DOM events for interaction. Details:references/stack-and-use-cases.md. - API invariants. Call
prepare()/prepareWithSegments()once per text+font pair and cache the handle; setctx.fontonce per frame; keep theprepare()font string exactly in sync with the rendered CSS; useIntl.Segmenterfor grapheme splits. Pitfalls + verification:references/pitfalls.md.
Routing
| Step | Reference | Purpose |
|---|---|---|
| API & use cases | references/stack-and-use-cases.md |
The two use cases (measure-only vs measure+render), streaming variable-width flow, helpers, pinned CDN import. |
| Pick a pattern | references/patterns.md |
Community demo patterns and which pretext API each uses. Pick one, riff on it — don't invent a new category unless asked. |
| Pitfalls & verification | references/pitfalls.md |
Performance notes, 8 common pitfalls, 10-item verification checklist. |
| Starters | templates/hello-orb-flow.html, templates/donut-orbit.html |
Working starters: reflow around a moving orb; measured ASCII logo obstacles with draggable wire shapes. |
| Inspiration | references/community-demos.md |
Clone-worthy community demos and the official playground gallery. |
04 同仓库更多 Skills
github-workflow
Umbrella for GitHub auth, repo management, issues, PRs, Mergify, and releases. Subsumes github-auth and repo-manager.
brave-automation
baa CLI: Brave profiles, Google sessions, credentials.
aes
AES docs, layers, rule fixes, and legacy migration.
popular-web-designs
54 real design systems (Stripe, Linear, Vercel) as HTML/CSS.
p5js
p5.js sketches: gen art, shaders, interactive, 3D.
design-md
Author/validate/export Google's DESIGN.md design-token spec files.