Communitygithub.com

diamotion

>- Turns a static technical diagram (screenshot, or PDF page + figure number) plus its explanatory text into a step-by-step animated diagram that a reader with mild ADHD can grasp quickly. The AI authors a compact, theme-agnostic diagram.json (or decoupled static.json + story.json) using original-faithful layout or ELK auto-layout; a zero-dependency Web Component player (<dg-player>) renders it with any CSS theme. Use whenever the user shares a diagram / figure and asks to animate it, visualize it step by step, or make it easier to understand.

What is diamotion?

diamotion is a Claude Code agent skill that >- Turns a static technical diagram (screenshot, or PDF page + figure number) plus its explanatory text into a step-by-step animated diagram that a reader with mild ADHD can grasp quickly. The AI authors a compact, theme-agnostic diagram.json (or decoupled static.json + story.json) using original-faithful layout or ELK auto-layout; a zero-dependency Web Component player (<dg-player>) renders it with any CSS theme. Use whenever the user shares a diagram / figure and asks to animate it, visualize it step by step, or make it easier to understand.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Coder-Chouchou/diamotion/tree/HEAD/skills/diamotion

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

DiaMotion Skill v3.6

Tool Home: The root of your local diamotion clone (denoted <diamotion> below; run CLI commands from <diamotion> or set $DIAMOTION_HOME). Read <diamotion>/README.md (or README.zh-CN.md) for setup (npm install, Node ≥ 24, Edge/Chrome, optional Python + Pillow/PyMuPDF) and the --dg-* theme contract. Schema: <diamotion>/schema/diagram.schema.json. Reference examples (all passing tools/check.mjs with 0 errors / 0 warnings):

  • examples/ualink-fig-1-2/ — Topology / Hierarchical Block Diagram
  • examples/ualink-fig-1-3-stack/ — Layered Protocol Stack
  • examples/ualink-dl-fsm/ — State Machine (FSM)
  • examples/ualink-dl-fsm-route3/ — Two-stage decoupled static.json + story-trace.json (trace + regions + badges + trail: "auto")
  • examples/ualink-flit-flow/ — Flowchart / Decision Logic
  • examples/ualink-chiplet-credits/ — Nested Pipeline & Credit Loops

Two goals (nothing else matters)

  1. The reader understands the figure fast. One idea per step. Show cause and effect with motion. Keep text short and anchored on the diagram.
  2. The output is original-faithful and theme-agnostic. Author semantic data only: no HTML, CSS, JS, colors, or fonts. When an original figure exists, mirror its spatial layout and clean wiring via "layout": "faithful"; themes style --dg-* CSS variables.

Hard rules

  • Never hand-write a per-diagram HTML/SVG/JS page. Author diagram.json (or static.json + story.json) and build/verify it with tools/check.mjs.
  • Original-faithful layout when a reference figure exists (faithful). Set "layout": "faithful" (or { "engine": "faithful", "pad": 24, "groupPad": 24 }) and omit "canvas". Place nodes on a clean grid mirroring original.png's exact rows, columns, symmetry, aspect ratio, vertical pipeline strips (vertical: true), orthogonal rails, smooth curved FSM/cable arcs (curve: true), and dashed interface dividers (style: "guide"). Let layout.mjs auto-size omitted w/h, recursively wrap nested group.contains, auto-place omitted link/attached labels, and normalize tight bounds (negative rail coordinates are allowed during authoring).
  • ELK auto-layout for text-only diagrams (elk). When creating a diagram from text alone without a source figure, set "layout": { "engine": "elk", ... } and omit node/group x/y/w/h and link points.
  • Preserve all original elements; add helpful ones freely. Always populate "sourceItems": [...] with every visible label/element from original.png so lint verifies nothing is silently dropped. You may freely add auxiliary explanatory nodes/groups/links styled normally with kinds.
  • Zero colors or fonts in data. Express meaning only via kinds ({ "ualink": { "slot": 1, "name": "UALink" } } using slots 1..6 or "neutral"). lint always rejects raw style keys (color, fill, stroke, bg, background, backgroundColor, font, fontFamily, css, theme, and style on non-links).
  • Do not edit player/ or themes/ for one diagram. If a capability is genuinely missing, extend the toolkit generically, run npm run build:player && npm run verify, and document it in schema/diagram.schema.json and the READMEs.
  • Strict grounding & accuracy. When sourceText is present:
    • Every quote is verified verbatim by lint (hyphenation-aware; supports … / [...] ellipses).
    • Every non-overview step must have either a verified quote OR an explicit non-verbatim tag matching 推断|非原文|示意|假设|通用知识 (e.g. "tag": "推断 · 非原文").
    • At least 50% (ceil((steps - 1) * 0.5)) of main-scene non-overview steps must carry verified verbatim quotes.
    • Keep modal verbs exact (shall ≠ may). Never invent fields, numbers, or behavior. Name unlabeled connections honestly (e.g. "原文未命名").

Workflow

  1. Prepare inputs in a working folder (e.g., diagrams/<slug>/, or a user-specified path):

    • From a PDF:
      python tools/crop_figure.py <spec.pdf> --page N --figure "x-y" --out <dir> [--pages-text a-b] [--clip x0,y0,x1,y1]
      
      Writes original.png and source.txt. For vector PDFs, optionally also extract exact normalized geometry anchors:
      python tools/pdf_geom.py <spec.pdf> --page N --figure "x-y" -o <dir>/raw_geometry.json [--canvas-w 1100] [--clip x0,y0,x1,y1]
      
      Always visually inspect original.png; if anything is clipped or stray prose leaked in, re-run with --clip. Include adjacent pages via --pages-text when the explanation spans pages.
    • From a screenshot: save it as <dir>/original.png and any accompanying text as <dir>/source.txt.
    • Two-stage decoupled workflow (Route 3, recommended when reusing one figure across multiple stories):
      1. Author <dir>/static.json (elements, kinds, layout, sourceItems, glossary, original, sourceText — no scenes) and lock geometry + compare.png via: node tools/check.mjs <dir>/static.json --static
      2. Author one or more <dir>/story-*.json files referencing "base": "./static.json" (plus optional "overlayElements": [...] and "scenes": [...]) and verify each with: node tools/check.mjs <dir>/story-*.json Single-file diagram.json remains 100% supported.
  2. Understand before authoring. Answer for yourself:

    • What single question does the figure answer? That becomes summary (≤ 40 visual chars; vlen: CJK = 1, ASCII = 0.5).
    • What is the complete inventory of visible elements/labels in original.png? Put every one into sourceItems.
    • What is the exact spatial structure of original.png? Identify rows/columns, symmetry axes, vertical strips, nested containers, orthogonal channel rails, curved FSM/cable arcs, timing waveforms, and dashed interface dividers.
    • What are the 3–10 steps? Order: overview → one idea per step → takeaway.
  3. Author theme-agnostic diagram.json (or static.json + story.json).

    • Root metadata: "$schema", "version": 1, "id", "title", "source", "summary", "original": "original.png", "sourceText": "source.txt", "sourceItems": [...], "glossary": { ... }.
    • Root layout:
      • With original.png (primary): "layout": "faithful" or { "engine": "faithful", "pad": 24, "groupPad": 24 } and omit "canvas" (auto-computed and normalized so top-left starts at pad; negative rail coordinates like x: -40 are fine). Optional "fontSize": 15 (default 16).
      • Text-only (no original.png): "layout": { "engine": "elk", "direction": "DOWN"|"RIGHT"|"UP"|"LEFT", "routing": "ORTHOGONAL"|"POLYLINE", "nodeGap": 40, "layerGap": 64, "groupPad": 24, "edgeGap": 22, "pad": 24, "wrapping": "OFF"|"SINGLE_EDGE"|"MULTI_EDGE", "aspectRatio": 1.6 }, omitting x/y/w/h and link points.
    • Rich inline text: use _{...} for subscript and ^{...} for superscript (e.g. T_{HS-PREPARE}, 2^{16}, D_{0}) in any node/group/link/label/wave text or step caption; bare _/^ and \_{/\^{ remain literal.
    • Elements:
      • node (default type): id, x, y (required in faithful; omit in elk), optional w, h (auto-sized when omitted; set explicitly for aligned uniform rows/columns/strips), label (\n for multi-line), optional sub, kind, shape: box | round | pill | circle | diamond | chip | tag | mux | cylinder | hexagon | xor | dot | brace, orient (right|left|down|up for mux/hexagon/cylinder/brace), sharp: true, dashed: true, double: true, stack: true, vertical: true + verticalDir: "up"|"down", inset, minW/minH.
      • group: type: "group", label, optional kind, border ("dashed"|"solid"|"none"), fill ("none"|"tint"), labelPos (top-left|bottom-left|top|bottom|top-right|bottom-right|top-outside|bottom-outside), contains: [childIds...], pad, optional x, y, w, h, minW/minH.
      • wave: type: "wave", declarative protocol timing track at (x, y), optional h, kind, optional left-rail label & size, and segments: [{ type, w, label?, from?, to?, cycles?, highlight? }] where type is high | low | mid | data | clk | x | gap | ramp.
      • link: type: "link", from, to ("id", "id.side", or "id.side:frac", shape-aware on pill, circle, xor, dot, diamond, hexagon, mux), optional points or explicit route, curve: true, style: "line"|"bus"|"guide"|"block", z: "auto"|"top", dashed, arrow (none|end|start|both), label, labelPos, labelAt + labelOffset, labelRotate: true, labelBg: true.
      • label: type: "label", text, anchor (start|middle|end), strong, size, optional attach: "<id>" (inherits focus/dim/hidden across multi-hop attach chains).
    • glossary: map every acronym/key term to a concise plain explanation (also matches e.kind and newline-normalized labels).
  4. Design steps for ADHD readers (strict budgets enforced as errors by lint):

    • Step count: 3–10 steps per scene.
    • Main scene step 1: overview with no focus — frame what the figure shows and what to watch for.
    • Middle steps: one idea per step, focus ≤ 6 ids. Link endpoints and group members stay undimmed automatically; context expands group members recursively. Opt into 3-tier visual memory via "trail": "auto" on a scene or per-step "visited": [ids]. Every scene needs ≥ 1 focused step.
    • Motion for causality:
      • tokens: [{ via: [linkIds…], from?, text?, tone?: "accent"|"ok"|"danger"|"kind", after?: idx, once?: true, repeat?: N, dur?, delay?, reverse? }] — smooth travelling badges with semantic tones, synchronized relay chains (after), and finite settling (once/repeat).
      • flow: ["lnk1", { "id": "lnk2", "reverse": true }] — continuous forward or reverse dashed flow.
      • trace: ["lnk1", { "id": "lnk2", "reverse": true }] — single-pass stroke draw-in along a link (sweeps once and settles visibly without disturbing dashed wires; respects mark: "danger" | "ok").
      • set: { id: "new label" } — dynamic value/state update with persistent .is-changed accent tint + bold label.
      • mark: { id: "danger" | "ok" | "off" } — semantic error, success, or disabled state.
      • show / hide — appearing or disappearing elements.
    • Story-layer overlays (regions & badges — ideal for decoupled story.json):
      • regions: [{ of: [elementIds…], tone?: "accent"|"ok"|"danger"|"kind", kind?, pad?: 8, dashed?: false }] (max 3 per step): draws a soft translucent box below L-groups around the union bounding box of any static elements (e.g. timing windows between vertical guide lines or a slice of register cells).
      • badges: [{ at: "id", text?: "1", corner?: "tl"|"tr"|"bl"|"br", tone?: "accent"|"ok"|"danger"|"kind" }] (max 6 per step, text ≤ 2 visual chars, auto-numbers 1..N): circular reading-order stamps with 4-corner collision avoidance.
    • Notes: at most 2 notes per step, each text ≤ 12 visual chars; auto-placed collision-free across all 4 sides.
    • Captions: title ≤ 18 visual chars (state a takeaway, not a bare noun); say ≤ 70 visual chars (1–2 crisp spoken sentences, at most 2 **bold** pairs).
    • Second scene: add only when a contrast or alternate branch genuinely clarifies why; tag non-verbatim scenarios.
  5. Verify and iterate with one command (run from <diamotion>):

    node tools/check.mjs <dir>/diagram.json [--themes paper,midnight] [--out <dir>] [--loose] [--static] [--no-shots] [--no-compare]
    

    check.mjs runs 4 stages in sequence and writes <dir>/check-report.json:

    1. lint — structure, forbidden style keys, sourceItems, strict ADHD budgets, static shape geometry, and verbatim quotes.
    2. layout + build — faithful / elk / manual resolution → <dir>/index.html.
    3. audit + shots — single headless Edge/Chrome via CDP audits live Shadow DOM across every theme × scene × step (.err, JS/console errors, shape text overflow, group label overflow, note/badge clipping & overlaps, leader crossings, text–text overlaps, viewBox clipping, .wrap overflow) and captures <dir>/shots/*.png.
    4. compare — builds side-by-side <dir>/compare.png (Original | Redraw).

    Loop until RESULT: PASS (exit 0, 0 errors/0 warnings), AND visually inspect <dir>/compare.png plus rendered shots in BOTH paper and midnight!

  6. Deliver.

    • Link <dir>/index.html (offline, with theme switcher & zoom/pan UI), <dir>/diagram.json (or static.json + story.json), and <dir>/compare.png.
    • Keep the summary short: what the steps cover, any non-verbatim inferred steps, and confirmation that check.mjs passed.

Embedding for other layers

Use <dg-player src="resolved.json"> (dumped via node tools/layout.mjs or build.mjs --resolved) or inline <script type="application/json">. Set --dg-* CSS custom properties on any ancestor to re-theme. Use chrome="none" for a bare diagram, zoomIn() / setZoom() / resetZoom() for viewport inspection, and listen to the dg-step event to sync narration or video.

Related Skills