{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "figure-trace",
  "title": "Trace Figure",
  "author": "zyx1121 (https://github.com/zyx1121)",
  "description": "A run replayed one event a press: who sent what, and the line to take from it, with the record growing on screen.",
  "registryDependencies": [
    "https://ui.zyx.tw/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/zyx/components/figure-trace.tsx",
      "content": "\"use client\"\n\nimport { useState } from \"react\"\n\nimport { cn } from \"../lib/utils\"\n\nimport { FIGURE_LABELS, type FigureLabels, type Trace } from \"../lib/figures\"\n\n/**\n * A run replayed by the reader, one event a press. Events that have happened\n * stay on screen and the newest is lit, so the record is seen growing. Every\n * event keeps its place from the start: nothing below moves.\n */\nexport function TraceFigure({\n  trace,\n  className,\n  shown: driven,\n  labels,\n}: {\n  trace: Trace\n  className?: string\n  labels?: Partial<FigureLabels>\n  /**\n   * How many events a scrolling page has shown (components/scrolly.tsx).\n   * Set, the figure has no button and no line: the page has them.\n   */\n  shown?: number\n}) {\n  const words = { ...FIGURE_LABELS, ...labels }\n  const { events } = trace\n  const [pressed, setShown] = useState(1)\n  const shown = driven ?? pressed\n  const last = shown === events.length\n  const own = driven === undefined\n\n  return (\n    <figure\n      className={cn(\n        \"max-w-2xl border-t border-b border-border py-5\",\n        className\n      )}\n    >\n      {own && (\n        <div className=\"flex items-baseline gap-x-5\">\n          <button\n            type=\"button\"\n            onClick={() => setShown(last ? 1 : shown + 1)}\n            className={cn(\n              \"-my-2.5 cursor-pointer py-2.5 outline-offset-4 focus-visible:outline-2\",\n              \"bg-(--mark)/20 text-(--mark)\"\n            )}\n          >\n            {last ? words.again : words.next}\n          </button>\n          <span className=\"text-muted-foreground tabular-nums\">\n            {shown} / {events.length}\n          </span>\n        </div>\n      )}\n\n      <ol\n        aria-label={trace.alt}\n        className={cn(\"flex flex-col gap-y-5\", own && \"mt-8\")}\n      >\n        {events.map(({ from, lines }, index) => {\n          const current = index === shown - 1\n          return (\n            <li\n              key={index}\n              aria-hidden={index >= shown}\n              className={cn(\n                \"flex gap-x-3\",\n                \"motion-safe:transition-colors motion-safe:duration-state\",\n                index >= shown && \"invisible\",\n                current ? \"text-foreground\" : \"text-muted-foreground\"\n              )}\n            >\n              <span className={cn(\"w-18 shrink-0\", current && \"text-(--mark)\")}>\n                {from}\n              </span>\n              <span className=\"min-w-0 flex-1 wrap-anywhere whitespace-pre-wrap\">\n                {lines.join(\"\\n\")}\n              </span>\n            </li>\n          )\n        })}\n      </ol>\n\n      {/* Every event's line shares one cell, so the tallest sets the height. */}\n      {own && (\n        <figcaption aria-live=\"polite\" className=\"mt-8 grid\">\n          {events.map(({ text }, index) => (\n            <p\n              key={index}\n              aria-hidden={index !== shown - 1}\n              className={cn(\n                \"col-start-1 row-start-1 text-pretty\",\n                index !== shown - 1 && \"invisible\"\n              )}\n            >\n              {text}\n            </p>\n          ))}\n        </figcaption>\n      )}\n    </figure>\n  )\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/zyx/lib/figures.ts",
      "content": "/**\n * The figures a reader operates in an article: a drawing read part by part,\n * a choice, a quiz, a replayed run and a dial. Each is plain data, so an\n * article can keep its figures in JSON.\n */\n\n/**\n * A drawing in box-drawing characters, set as text so it is as legible as\n * the page around it. `wide` fits 66 cells (the narrowest column from the sm\n * breakpoint up); `narrow` fits 30 cells, for phones. ASCII and box-drawing\n * characters only, so every glyph keeps one cell.\n */\nexport type Diagram = {\n  kind: \"diagram\"\n  wide: string[]\n  /** Left out, phones get the wide drawing and scroll it sideways. */\n  narrow?: string[]\n  /**\n   * Pseudo code: set from the column's left edge instead of its middle, and\n   * a step lights whole lines.\n   */\n  code?: boolean\n  alt: string\n  /**\n   * The drawing read one part at a time. Each step lights the words in\n   * `lit` wherever they stand in the drawing (wide and narrow alike) and\n   * shows `text` under it. The figure plays through its steps by itself and\n   * holds on the one a reader picks.\n   */\n  steps?: { label: string; lit: string[]; text: string }[]\n}\n\n/**\n * A figure the reader operates (figure-lesson.tsx): `ask` names\n * the one choice, and each state is what one answer leads to. A state is a\n * few titled blocks of rows, with the line to take from it under them.\n */\nexport type Lesson = {\n  kind: \"lesson\"\n  ask: string\n  /** Two blocks stand side by side from the sm breakpoint up. */\n  side?: boolean\n  states: {\n    label: string\n    blocks: {\n      title: string\n      /** The rows are steps in order, so each takes its number. */\n      numbered?: boolean\n      rows: {\n        text: string\n        /** A count or a version, set at the row's right edge. */\n        value?: string\n        /** `mark` is what this state adds, `dim` what it removes. */\n        tone?: \"mark\" | \"dim\" | \"quiet\"\n      }[]\n    }[]\n    text: string\n  }[]\n}\n\n/**\n * A question the reader answers before the text does\n * (figure-quiz.tsx). Every item takes the same options; picking\n * one shows which is right, and the line that says why.\n */\nexport type Quiz = {\n  kind: \"quiz\"\n  ask: string\n  options: string[]\n  items: {\n    text: string\n    /** The index of the right option. */\n    answer: number\n    why: string\n  }[]\n}\n\n/**\n * A run replayed one event at a time (figure-trace.tsx): who\n * spoke, what was sent, and the line to take from it. Events stay on screen,\n * so the reader watches the record grow.\n */\nexport type Trace = {\n  kind: \"trace\"\n  alt: string\n  events: {\n    /** The sender, in Latin capitals: USER, MODEL, TOOL. */\n    from: string\n    /** What was sent, as written on the wire. Long lines wrap. */\n    lines: string[]\n    text: string\n  }[]\n}\n\n/**\n * A quantity the reader moves (figure-dial.tsx): each stop\n * redraws the same bars, so the eye follows what grows and what does not.\n */\nexport type Dial = {\n  kind: \"dial\"\n  ask: string\n  /** Cells in a full bar: 20 or fewer, so a phone holds it. */\n  scale: number\n  stops: {\n    label: string\n    /** The same bars at every stop, in the same order. */\n    bars: {\n      label: string\n      cells: number\n      value?: string\n      tone?: \"mark\" | \"quiet\"\n    }[]\n    text: string\n  }[]\n}\n\nexport type Figure = Diagram | Lesson | Quiz | Trace | Dial\n\n/** The words on the figures' buttons and marks, so a page can set its language. */\nexport type FigureLabels = {\n  next: string\n  again: string\n  play: string\n  stop: string\n  /** Before the line that says why, on a right pick and on a wrong one. */\n  right: string\n  wrong: string\n}\n\nexport const FIGURE_LABELS: FigureLabels = {\n  next: \"Next\",\n  again: \"Again\",\n  play: \"Play\",\n  stop: \"Pause\",\n  right: \"Right: \",\n  wrong: \"Not quite: \",\n}\n",
      "type": "registry:lib"
    }
  ],
  "meta": {
    "useWhen": "A run of messages, such as an agent's tool calls, replayed step by step.",
    "notFor": "Logs to search; use table.",
    "related": [
      "scrolly",
      "figure-diagram"
    ]
  },
  "docs": "Use when: A run of messages, such as an agent's tool calls, replayed step by step.\nNot for: Logs to search; use table.\nGuide: https://ui.zyx.tw/figure-trace.md",
  "categories": [
    "figure",
    "motion"
  ],
  "type": "registry:component"
}