跳到正文
cccskills
免费在 GitHub 公开中文介绍

pretext

预先计算文字位置,用单个HTML文件制作动态浏览器演示。可让段落绕开移动图形、点击后文字散开、用单词搭建游戏,或让卡片紧贴多行文本。

原文查看原文说明

Build creative browser demos with DOM-free text layout.

AI 评分90分/ 100查看安装方法

适用场景

  • 让文字绕开移动图形
  • 制作点击后文字散开的效果
  • 用单词或文字制作游戏
  • 制作紧贴多行文本的卡片

中文介绍

功能

pretext用于制作以文字为主体的动态浏览器演示。它通过@chenglou/pretext在绘制前计算换行位置、每行宽度和每个字符的坐标,让段落绕开移动图形,或让文字在点击后散开。也适用于以单词为方块的游戏,以及紧贴多行文本的卡片。基本结构采用Canvas 2D和单个HTML文件,无需构建。

适用场景

适合在网页中加入由文字本身构成的视觉效果,或尝试能响应操作的动态排版。可以从附带模板出发,具体确定文本、字体、配色、运动效果和操作方式。

使用示例

  • “制作一个演示,让文字绕开可以拖动的球体。”
  • “让这首诗的文字在点击后散开。”
  • “用单词作为方块制作游戏,放在单个HTML文件中。”

注意事项

通过esm.sh加载库。测量与绘制时的字体设置必须一致。不适合普通静态布局或通用富文本编辑。此技能采用MIT许可证。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

客观评估

AI 仅根据 SKILL.md 的内容,从 4 个方面进行了评估。星标数和热度不计入评估。

指令清晰度能否看出何时使用、做什么
A良好明确用于动态文字表现和文字游戏,并排除静态布局。
步骤具体性步骤、输入输出和示例是否具体
A良好提供单个HTML的结构、API代码示例及不同效果的实现模式。
安全性发送数据、删除文件、执行命令等是否有说明
B部分不足从esm.sh加载代码并固定版本,但未提供所获取代码的验证步骤。
安装难易度所需工具和 API 密钥是否少且有说明
A良好采用无需构建的单个HTML文件,并提供从CDN导入的示例。

总分按每项 A=25 分、B=15 分、C=5 分相加。 由 AI(OpenAI Codex)于 2026年10月20日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(4)

  • SKILL.md13.7 KB
  • references/patterns.md10.2 KB
  • templates/donut-orbit.html52.0 KB
  • templates/hello-orb-flow.html3.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Pretext Creative Demos

Overview

@chenglou/pretext is a 15KB zero-dependency TypeScript library by Cheng Lou (React core, ReasonML, Midjourney) for DOM-free multiline text measurement and layout. It does one thing: given (text, font, width), return the line breaks, per-line widths, per-grapheme positions, and total height — all via canvas measurement, no reflow.

That sounds like plumbing. It is not. Because it is fast and geometric, it is a creative primitive: you can reflow paragraphs around a moving sprite at 60fps, build games whose level geometry is made of real words, drive ASCII logos through prose, shatter text into particles with exact per-grapheme starting positions, or pack shrink-wrapped multiline UI without any getBoundingClientRect thrash.

This skill exists so Hermes can make cool demos with it — the kind people post to X. See pretext.cool and chenglou.me/pretext for the community demo corpus.

When to Use

Use when the user asks for:

  • A "pretext demo" / "cool pretext thing" / "text-as-X"
  • Text flowing around a moving shape (hero sections, editorial layouts, animated long-form pages)
  • ASCII-art effects using real words or prose, not monospace rasters
  • Games where the playfield / obstacles / bricks are made of text (Tetris-from-letters, Breakout-of-prose)
  • Kinetic typography with per-glyph physics (shatter, scatter, flock, flow)
  • Typographic generative art, especially with non-Latin scripts or mixed scripts
  • Multiline "shrink-wrap" UI (smallest container width that still fits the text)
  • Anything that would require knowing line breaks before rendering

Don't use for:

  • Static SVG/HTML pages where CSS already solves layout — just use CSS
  • Rich text editors, general inline formatting engines (pretext is intentionally narrow)
  • Image → text (use ascii-art / ascii-video skills)
  • Pure canvas generative art with no text role — use p5js

Creative Standard

This is visual art rendered in a browser. Pretext returns numbers; you draw the thing.

  • Don't ship a "hello world" demo. The hello-orb-flow.html template is the starting point. Every delivered demo must add intentional color, motion, composition, and one visual detail the user didn't ask for but will appreciate.
  • Dark backgrounds, warm cores, considered palette. Classic amber-on-black (CRT / terminal) works, but so do cold-white-on-charcoal (editorial) and desaturated pastels (risograph). Pick one and commit.
  • Proportional fonts are the point. Pretext's whole vibe is "not monospaced" — lean into it. Use Iowan Old Style, Inter, JetBrains Mono, Helvetica Neue, or a variable font. Never default sans.
  • Real source/text, not lorem ipsum. The corpus should mean something. Short manifestos, poetry, real source code, a found text, the library's own README — never lorem ipsum.
  • First-paint excellence. No loading states, no blank frames. The demo must look shippable the instant it opens.

Stack

Single self-contained HTML file per demo. No build step.

LayerToolPurpose
Core@chenglou/pretext via esm.sh CDNText measurement + line layout
RenderHTML5 Canvas 2DGlyph rendering, per-frame composition
SegmentationIntl.Segmenter (built-in)Grapheme splitting for emoji / CJK / combining marks
InteractionRaw DOM eventsMouse / touch / wheel — no framework
<script type="module">
import {
  prepare, layout,                   // use-case 1: simple height
  prepareWithSegments, layoutWithLines,  // use-case 2a: fixed-width lines
  layoutNextLineRange, materializeLineRange, // use-case 2b: streaming / variable width
  measureLineStats, walkLineRanges,  // stats without string allocation
} from "https://esm.sh/@chenglou/pretext@0.0.6";
</script>

Pin the version. @0.0.6 at time of writing — check npm for the latest if demo behavior is off.

The Two Use Cases

Almost everything reduces to one of these two shapes. Learn both.

Use-case 1 — measure, then render with CSS/DOM

const prepared = prepare(text, "16px Inter");
const { height, lineCount } = layout(prepared, 320, 20);

You still let the browser draw the text. Pretext just tells you how tall the box will be at a given width, without a DOM read. Use for:

  • Virtualized lists where rows contain wrapping text
  • Masonry with precise card heights
  • "Does this label fit?" dev-time checks
  • Preventing layout shift when remote text loads

Keep font and letterSpacing exactly in sync with your CSS. The canvas ctx.font format (e.g. "16px Inter", "500 17px 'JetBrains Mono'") must match the rendered CSS, or measurements drift.

Use-case 2 — measure and render yourself

const prepared = prepareWithSegments(text, FONT);
const { lines } = layoutWithLines(prepared, 320, 26);
for (let i = 0; i < lines.length; i++) {
  ctx.fillText(lines[i].text, 0, i * 26);
}

This is where the creative work lives. You own the drawing, so you can:

  • Render to canvas, SVG, WebGL, or any coordinate system
  • Substitute per-glyph transforms (rotation, jitter, scale, opacity)
  • Use line metadata (width, grapheme positions) as geometry

For variable-width-per-line flow (text around a shape, text in a donut band, text in a non-rectangular column):

let cursor = { segmentIndex: 0, graphemeIndex: 0 };
let y = 0;
while (true) {
  const lineWidth = widthAtY(y);  // your function: how wide is the corridor at this y?
  const range = layoutNextLineRange(prepared, cursor, lineWidth);
  if (!range) break;
  const line = materializeLineRange(prepared, range);
  ctx.fillText(line.text, leftEdgeAtY(y), y);
  cursor = range.end;
  y += lineHeight;
}

This is the most important pattern in the whole library. It's what unlocks "text flowing around a dragged sprite" — the demo that went viral on X.

Helpers worth knowing

  • measureLineStats(prepared, maxWidth) → { lineCount, maxLineWidth } — the widest line, i.e. multiline shrink-wrap width.
  • walkLineRanges(prepared, maxWidth, callback) — iterate lines without allocating strings. Use for stats/physics over graphemes when you don't need the characters.
  • @chenglou/pretext/rich-inline — the same system but for paragraphs mixing fonts / chips / mentions. Import from the subpath.

Demo Recipe Patterns

The community corpus (see references/patterns.md) clusters into a handful of strong patterns. Pick one and riff — don't invent a new category unless asked.

PatternKey APIExample idea
Reflow around obstaclelayoutNextLineRange + per-row width functionEditorial paragraph that parts around a dragged cursor sprite
Text-as-geometry gamelayoutWithLines + per-line collision rectsBreakout where each brick is a measured word
Shatter / particleswalkLineRanges → per-grapheme (x,y) → physicsSentence that explodes into letters on click
ASCII obstacle typographylayoutNextLineRange + measured per-row obstacle spansBitmap ASCII logo, shape morphs, and draggable wire objects that make text open around their actual geometry
Editorial multi-columnlayoutNextLineRange per column + shared cursorAnimated magazine spread with pull quotes
Kinetic typelayoutWithLines + per-line transform over timeStar Wars crawl, wave, bounce, glitch
Multiline shrink-wrapmeasureLineStatsQuote card that auto-sizes to its tightest container

See templates/donut-orbit.html and templates/hello-orb-flow.html for working single-file starters.

Workflow

  1. Pick a pattern from the table above based on the user's brief.
  2. Start from a template:
    • templates/hello-orb-flow.html — text reflowing around a moving orb (reflow-around-obstacle pattern)
    • templates/donut-orbit.html — advanced example: measured ASCII logo obstacles, draggable wire sphere/cube, morphing shape fields, selectable DOM text, and dev-only controls
    • write_file to a new .html in ~/.hermes/cache/scratch/ or the user's workspace.
  3. Swap the corpus for something intentional to the brief. Real prose, 10-100 sentences, no lorem.
  4. Tune the aesthetic — font, palette, composition, interaction. This is the work; don't skip it.
  5. Verify locally:
    cd <dir-with-html> && python -m http.server 8765
    # then open http://localhost:8765/<file>.html
    
  6. Check the console — pretext will throw if prepareWithSegments is called with a bad font string; Intl.Segmenter is available in every modern browser.
  7. Show the user the file path, not just the code — they want to open it.

Performance Notes

  • prepare() / prepareWithSegments() is the expensive call. Do it once per text+font pair. Cache the handle.
  • On resize, only rerun layout() / layoutWithLines() — never re-prepare.
  • For per-frame animations where text doesn't change but geometry does, layoutNextLineRange in a tight loop is cheap enough to do every frame at 60fps for normal-length paragraphs.
  • When rendering ASCII masks per frame, keep a cell buffer (Uint8Array/typed arrays), derive measured per-row obstacle spans from the cells or projected geometry, merge spans, then feed those spans into layoutNextLineRange before drawing text.
  • Keep visual animation and layout animation coupled. If a sphere morphs into a cube, tween both the rendered cell buffer and the obstacle spans with the same value; otherwise the demo looks painted-on instead of physically reflowed.
  • For fades, prefer layer opacity over changing glyph intensity or obstacle scale. Put transient ASCII sprites on their own canvas and fade the canvas with CSS/GSAP opacity so geometry does not appear to shrink.
  • Canvas ctx.font setting is surprisingly slow; set it once per frame if font doesn't vary, not per fillText call.

Common Pitfalls

  1. Drifting CSS/canvas font strings. ctx.font = "16px Inter" measured, but CSS says font-family: Inter, sans-serif; font-size: 16px. Fine if Inter loads. If Inter 404s, CSS falls back to sans-serif and measurements drift by 5-20%. Always preload the font or use a web-safe family.

  2. Re-preparing inside the animation loop. Only layout* is cheap. Re-calling prepare every frame will tank perf. Keep the prepared handle in module scope.

  3. Forgetting Intl.Segmenter for grapheme splits. Emoji, combining marks, CJK — "é".split("") gives you two chars. Use new Intl.Segmenter(undefined, { granularity: "grapheme" }) when sampling individual visible glyphs.

  4. break: 'never' chips without extraWidth. In rich-inline, if you use break: 'never' for an atomic chip/mention, you must also supply extraWidth for the pill padding — otherwise chip chrome overflows the container.

  5. Using @chenglou/pretext from unpkg with TypeScript-only entry. Use esm.sh — it compiles the TS exports to browser-ready ESM automatically. unpkg will 404 or serve raw TS.

  6. Monospace fallbacks silently erasing the whole point. Users seeing monospace-looking output often have a CSS font-family that fell through to monospace. Verify the actual rendered font via DevTools.

  7. Skipping rows vs adjusting width when flowing around a shape. If the corridor on this row is too narrow to fit a line, skip the row (y += lineHeight; continue;) rather than passing a tiny maxWidth to layoutNextLineRange — pretext will return one-grapheme lines that look broken.

  8. Shipping a cold demo. The default first-paint looks tutorial-grade. Add: vignette, subtle scanline, idle auto-motion, one carefully chosen interactive response (drag, hover, scroll, click). Without these, "cool pretext demo" lands as "intern repro of the README."

Verification Checklist

  • Demo is a single self-contained .html file — opens by double-click or python -m http.server
  • @chenglou/pretext imported via esm.sh with pinned version
  • Corpus is real prose, not lorem ipsum, and matches the demo's concept
  • Font string passed to prepare matches the CSS font exactly
  • prepare() / prepareWithSegments() called once, not per frame
  • Dark background + considered palette — not the default white canvas
  • At least one interactive response (drag / hover / scroll / click) or idle auto-motion
  • Tested locally with python -m http.server and confirmed no console errors
  • 60fps on a mid-tier laptop (or graceful degradation documented)
  • One "extra mile" detail the user didn't ask for

Reference: Community Demos

Clone these for inspiration / patterns (all MIT-ish, linked from pretext.cool):

  • Pretext Breaker — breakout with word-bricks — github.com/rinesh/pretext-breaker
  • Tetris × Pretext — github.com/shinichimochizuki/tetris-pretext
  • Dragon animation — github.com/qtakmalay/PreTextExperiments
  • Somnai editorial engine — github.com/somnai-dreams/pretext-demos
  • Bad Apple!! ASCII — github.com/frmlinn/bad-apple-pretext
  • Drag-sprite reflow — github.com/dokobot/pretext-demo
  • Alarmy editorial clock — github.com/SmisLee/alarmy-pretext-demo

Official playground: chenglou.me/pretext — accordion, bubbles, dynamic-layout, editorial-engine, justification-comparison, masonry, markdown-chat, rich-note.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

1password

免费有简介AI 评分 100分

通过1Password CLI,将保存的密码和API密钥用于命令及配置模板,完成安装、认证、秘密值读取,并通过环境变量向命令传递凭据。

  • 安装并配置1Password CLI
  • 使用已保存的API密钥运行命令
  • 向配置模板填入秘密值
NousResearch/hermes-agent25.5万2026年10月19日 更新

3-statement-model

免费有简介AI 评分 90分

创建用公式联动利润表、资产负债表和现金流量表的 Excel 模型,分阶段填入历史实际数据与预测假设,比较不同情景,并检查三张报表之间的一致性。

  • 向财务模板填入历史实际数据
  • 建立三张财务报表联动的预测
  • 比较基准、乐观和悲观情景
NousResearch/hermes-agent25.5万2026年10月19日 更新

accelerate

免费有简介AI 评分 80分

以少量修改让现有PyTorch训练代码适用于多GPU或多台机器,指导混合精度、节省内存的DeepSpeed与FSDP配置,以及训练启动方法。

  • 将单GPU训练迁移至多GPU
  • 配置混合精度训练
  • 通过DeepSpeed或FSDP节省内存
NousResearch/hermes-agent25.5万2026年10月19日 更新

actual-setup

免费有简介AI 评分 100分

帮助配置Hermes,通过Actual Computer在自己的设备上运行AI模型。支持加密中继与本地连接,涵盖模型选择、响应测试,以及请求报错或空响应的排查。

  • 使用Actual密钥连接Hermes
  • 在本地设备上运行模型
  • 查找、下载并加载本地模型
NousResearch/hermes-agent25.5万2026年10月19日 更新

adversarial-ux-test

免费有简介AI 评分 80分

扮演不擅长技术、容易不满的用户测试应用,发现难懂的操作和导致放弃使用的障碍。将实际可改进的问题与个人抱怨分开,整理截图、修复建议和任务单。

  • 在发布或演示前检查易用性
  • 检查新用户的使用体验
  • 查找注册和付费流程中的障碍
NousResearch/hermes-agent25.5万2026年10月19日 更新

agent-merge-conflict-arbiter

免费有简介AI 评分 100分

从中立立场解决两个智能体分别修改代码产生的Git冲突,对照双方差异和意图,记录每处冲突的取舍理由,并通过构建或测试验证合并结果。

  • 解决两个智能体的分支冲突
  • 整合并行工作树中的修改
  • 核对冲突设计决策的理由
NousResearch/hermes-agent25.5万2026年10月19日 更新

查看 NousResearch 的全部技能

报告此技能的问题