{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "routing-slip",
  "title": "Routing Slip",
  "description": "A multi-party approval ledger styled as an interoffice routing slip: names print in fixed routed order, signing presses an ink chop beside your name, and signing out of turn lands visibly skewed with a written note rather than being hidden or blocked.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/routing-slip/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// RouteSlip — a multi-party approval ledger styled as an interoffice routing\n// slip, not an avatar-stack \"seen by\" row. Approver rows render in fixed\n// ROUTED order and never reorder themselves; that order is set once from the\n// `approvers` prop and is the spine every other visual hangs off. Signing is\n// a real, irreversible action scoped to `currentApproverId`'s own row — no\n// other row ever renders a Sign control. What distinguishes this from a\n// checkmark list is that signing out of turn is explicitly PERMITTED: a\n// signature is flagged \"out of turn\" whenever, at final state, some earlier\n// -routed approver's slot is still empty or was filled later than this one\n// (computed purely from routed index + signed timestamp, not from the order\n// clicks happened to arrive in). An in-turn chop settles at a plain 3deg\n// tilt; an out-of-turn chop lands with an 8deg skew on top of that tilt —\n// large enough to read as irregular at a glance, small enough to stay\n// legible — and the row also carries a plain-text \"out of turn\" note, so the\n// distinction never depends on noticing the skew.\n//\n// One governing scalar — signed count over `quorum` — derives the progress\n// line, Publish's aria-disabled state + written reason, and the crawling\n// underline under whichever unsigned row is currently \"Now\" (the first gap\n// in routed order, independent of who's allowed to fill it). `quorum` can be\n// less than the full roster: publish can unblock before every name is\n// stamped, which is a different claim than \"everyone signed.\"\n//\n// Pure DOM + CSS: a real <table> (approver / role / status / time columns,\n// <caption>, <th scope=\"col\">), a polite aria-live region announcing\n// \"{n} of {total} signed; waiting on {role}\", and every color drawn from\n// --background / --foreground / --ns-muted / --border / --ns-accent.\n// --ns-accent appears nowhere but the enabled Sign/Publish buttons' own\n// hover/focus/active states — never on a chop, never as a fill elsewhere.\n// ---------------------------------------------------------------------------\n\nexport interface RouteSlipApprover {\n  /** stable identifier */\n  id: string;\n  /** printed name */\n  name: string;\n  /** short role/team label, e.g. \"Legal\" — this is what Publish's reason and\n   * the aria-live announcement name when this approver is next */\n  role: string;\n}\n\nexport interface RouteSlipSignature {\n  approverId: string;\n  /** when this approver actually signed */\n  at: number | Date;\n}\n\nexport interface RouteSlipProps {\n  /** the approver chain in ROUTED order — fixed row order, index 0 is first\n   * in sequence. This order never changes regardless of actual signing order. */\n  approvers: RouteSlipApprover[];\n  /** seed one or more approvers as already signed, in whatever order they\n   * actually signed (not necessarily routed order) — out-of-turn flags are\n   * derived from this at every render */\n  initialSignatures?: RouteSlipSignature[];\n  /** signatures required before Publish unblocks. Clamped to\n   * [1, approvers.length]. @default approvers.length */\n  quorum?: number;\n  /** the approver whose row gets a real Sign button — every other row is\n   * read-only regardless of signed state */\n  currentApproverId?: string;\n  /** label for the document being routed, shown as the card title and in\n   * the table's accessible caption */\n  docLabel?: string;\n  /** called once per successful sign, with the approver id and timestamp */\n  onSign?: (approverId: string, at: number) => void;\n  /** called once, when Publish is activated at or above quorum */\n  onPublish?: () => void;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\ntype Sig = { approverId: string; at: number };\n\nconst CHOP_MS = 260;\n\nfunction toMs(v: number | Date): number {\n  return typeof v === \"number\" ? v : v.getTime();\n}\n\nfunction initialsOf(name: string): string {\n  const parts = name.trim().split(/\\s+/).filter(Boolean);\n  if (parts.length === 0) return \"?\";\n  if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();\n  return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();\n}\n\nfunction useReducedMotion(): boolean {\n  const [reduced, setReduced] = useState(false);\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    setReduced(mq.matches);\n    const onChange = () => setReduced(mq.matches);\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n  return reduced;\n}\n\n// A wall-clock stamp is the one thing here that can legitimately differ\n// between the server render and the client one (locale/timezone), same\n// reasoning as approval-inline-diff's TimeStamp — suppressHydrationWarning\n// is correct, not a bug being papered over.\nfunction TimeStamp({ ts }: { ts: number }) {\n  const label = new Date(ts).toLocaleTimeString(undefined, {\n    hour: \"numeric\",\n    minute: \"2-digit\",\n    second: \"2-digit\",\n  });\n  return <span suppressHydrationWarning>{label}</span>;\n}\n\nexport function RouteSlip({\n  approvers,\n  initialSignatures,\n  quorum,\n  currentApproverId,\n  docLabel = \"Routing slip\",\n  onSign,\n  onPublish,\n  className = \"\",\n}: RouteSlipProps) {\n  const uid = useId().replace(/:/g, \"\");\n  const captionId = `rs-caption-${uid}`;\n  const reasonId = `rs-reason-${uid}`;\n\n  const reducedMotion = useReducedMotion();\n\n  const [signatures, setSignatures] = useState<Sig[]>(() =>\n    (initialSignatures ?? []).map((s) => ({ approverId: s.approverId, at: toMs(s.at) }))\n  );\n  const [published, setPublished] = useState(false);\n  const [arrivingId, setArrivingId] = useState<string | null>(null);\n  const [announce, setAnnounce] = useState(\"\");\n  const arriveTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const prevSignedCount = useRef(signatures.length);\n  const prevPublished = useRef(false);\n\n  useEffect(() => () => clearTimeout(arriveTimer.current), []);\n\n  const quorumN = useMemo(() => {\n    const total = approvers.length || 1;\n    const raw = quorum ?? total;\n    return Math.min(total, Math.max(1, raw));\n  }, [quorum, approvers.length]);\n\n  const signedMap = useMemo(() => {\n    const m = new Map<string, number>();\n    for (const s of signatures) m.set(s.approverId, s.at);\n    return m;\n  }, [signatures]);\n\n  // Out-of-turn is derived from final state alone: approver i is out of turn\n  // if some earlier-routed approver j<i is still unsigned, or signed later\n  // than i did. Row 0 can never be out of turn — there is no one earlier to\n  // have skipped ahead of.\n  const outOfTurn = useMemo(() => {\n    const flags = new Array<boolean>(approvers.length).fill(false);\n    for (let i = 0; i < approvers.length; i++) {\n      const at = signedMap.get(approvers[i].id);\n      if (at === undefined) continue;\n      for (let j = 0; j < i; j++) {\n        const otherAt = signedMap.get(approvers[j].id);\n        if (otherAt === undefined || otherAt > at) {\n          flags[i] = true;\n          break;\n        }\n      }\n    }\n    return flags;\n  }, [approvers, signedMap]);\n\n  const nextIndex = useMemo(\n    () => approvers.findIndex((a) => !signedMap.has(a.id)),\n    [approvers, signedMap]\n  );\n  const nextApprover = nextIndex >= 0 ? approvers[nextIndex] : null;\n\n  const signedCount = signatures.length;\n  const quorumMet = signedCount >= quorumN;\n  const total = approvers.length;\n\n  // Announce only on genuine transitions (new sign / publish), never on the\n  // initial seeded mount — matches due-slip's newcomer-only announce pattern.\n  useEffect(() => {\n    if (signedCount > prevSignedCount.current) {\n      const msg = nextApprover\n        ? `${signedCount} of ${total} signed; waiting on ${nextApprover.role}.`\n        : `${signedCount} of ${total} signed; all signed.`;\n      setAnnounce(quorumMet ? `${msg} Publish unlocked.` : msg);\n    }\n    prevSignedCount.current = signedCount;\n  }, [signedCount, total, nextApprover, quorumMet]);\n\n  useEffect(() => {\n    if (published && !prevPublished.current) setAnnounce(\"Published.\");\n    prevPublished.current = published;\n  }, [published]);\n\n  function handleSign() {\n    if (!currentApproverId || published) return;\n    if (signedMap.has(currentApproverId)) return;\n    const at = Date.now();\n    setSignatures((prev) => [...prev, { approverId: currentApproverId, at }]);\n    onSign?.(currentApproverId, at);\n    if (!reducedMotion) {\n      setArrivingId(currentApproverId);\n      clearTimeout(arriveTimer.current);\n      arriveTimer.current = setTimeout(() => setArrivingId(null), CHOP_MS);\n    }\n  }\n\n  function handlePublish() {\n    if (published || !quorumMet) return;\n    setPublished(true);\n    onPublish?.();\n  }\n\n  const remaining = Math.max(0, quorumN - signedCount);\n  let reasonText: string;\n  if (published) {\n    reasonText = \"Published.\";\n  } else if (quorumMet) {\n    reasonText = \"Quorum met — ready to publish.\";\n  } else if (nextApprover) {\n    reasonText = `Publish disabled — needs ${remaining} more signature${\n      remaining === 1 ? \"\" : \"s\"\n    }, waiting on ${nextApprover.role}.`;\n  } else {\n    reasonText = \"Publish disabled — awaiting signatures.\";\n  }\n\n  const publishDisabled = !quorumMet || published;\n\n  return (\n    <div className={`w-full max-w-xl rounded-md border border-border bg-background ${className}`}>\n      <style>{CSS}</style>\n      <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n        {announce}\n      </span>\n\n      <div className=\"flex items-center justify-between gap-3 border-b border-border px-4 py-3\">\n        <div className=\"min-w-0\">\n          <p className=\"truncate text-sm font-medium text-foreground\">{docLabel}</p>\n          <p className=\"font-mono text-[11px] text-ns-muted\">\n            Quorum {quorumN} of {total}\n          </p>\n        </div>\n        <p className=\"shrink-0 font-mono text-xs tabular-nums text-ns-muted\">\n          {signedCount} of {total} signed\n        </p>\n      </div>\n\n      <div className=\"overflow-x-auto\">\n        <table className=\"w-full border-collapse text-sm\">\n          <caption id={captionId} className=\"sr-only\">\n            Approver routing slip for {docLabel}, in routed order\n          </caption>\n          <thead>\n            <tr className=\"border-b border-border\">\n              <th scope=\"col\" className=\"px-4 py-2 text-left font-mono text-[10px] uppercase tracking-wide text-ns-muted\">\n                Approver\n              </th>\n              <th scope=\"col\" className=\"px-3 py-2 text-left font-mono text-[10px] uppercase tracking-wide text-ns-muted\">\n                Role\n              </th>\n              <th scope=\"col\" className=\"px-3 py-2 text-left font-mono text-[10px] uppercase tracking-wide text-ns-muted\">\n                Status\n              </th>\n              <th scope=\"col\" className=\"px-4 py-2 text-right font-mono text-[10px] uppercase tracking-wide text-ns-muted\">\n                Time\n              </th>\n            </tr>\n          </thead>\n          <tbody>\n            {approvers.map((a, i) => {\n              const at = signedMap.get(a.id);\n              const isSigned = at !== undefined;\n              const isNext = !isSigned && i === nextIndex;\n              const isOutOfTurn = isSigned && outOfTurn[i];\n              const showSign = a.id === currentApproverId && !isSigned && !published;\n              const arriving = arrivingId === a.id;\n\n              return (\n                <tr key={a.id} className=\"border-b border-border last:border-b-0\">\n                  <td className=\"px-4 py-3 align-top\">\n                    <div className=\"flex items-center gap-2.5\">\n                      <span className=\"text-foreground\">{a.name}</span>\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"ns-rs-box\"\n                        data-signed={isSigned || undefined}\n                        data-out-of-turn={isOutOfTurn || undefined}\n                        data-arriving={arriving || undefined}\n                      >\n                        {isSigned ? initialsOf(a.name) : null}\n                      </span>\n                    </div>\n                    {isOutOfTurn && (\n                      <p\n                        data-slip-out-of-turn\n                        className=\"mt-1 font-mono text-[10px] uppercase tracking-wide text-ns-muted\"\n                      >\n                        out of turn\n                      </p>\n                    )}\n                  </td>\n                  <td className=\"px-3 py-3 align-top text-ns-muted\">{a.role}</td>\n                  <td className=\"px-3 py-3 align-top\">\n                    {isSigned ? (\n                      <span className=\"font-mono text-xs text-foreground\">Signed</span>\n                    ) : showSign ? (\n                      <button\n                        type=\"button\"\n                        data-slip-sign\n                        onClick={handleSign}\n                        className=\"ns-rs-btn\"\n                      >\n                        Sign as {a.name}\n                      </button>\n                    ) : isNext ? (\n                      <span className=\"ns-rs-now\">Now</span>\n                    ) : (\n                      <span className=\"font-mono text-xs text-ns-muted\">Awaiting</span>\n                    )}\n                  </td>\n                  <td className=\"px-4 py-3 align-top text-right\">\n                    {isSigned ? (\n                      <time\n                        dateTime={new Date(at as number).toISOString()}\n                        suppressHydrationWarning\n                        className=\"font-mono text-xs tabular-nums text-ns-muted\"\n                      >\n                        <TimeStamp ts={at as number} />\n                      </time>\n                    ) : (\n                      <span aria-hidden=\"true\" className=\"font-mono text-xs text-ns-muted\">\n                        —\n                      </span>\n                    )}\n                  </td>\n                </tr>\n              );\n            })}\n          </tbody>\n        </table>\n      </div>\n\n      <div className=\"border-t border-border px-4 py-3\">\n        <button\n          type=\"button\"\n          data-slip-publish\n          aria-disabled={publishDisabled}\n          aria-describedby={reasonId}\n          data-disabled={publishDisabled || undefined}\n          onClick={handlePublish}\n          className=\"ns-rs-btn w-full py-2 text-xs uppercase tracking-wide\"\n        >\n          {published ? \"Published\" : \"Publish\"}\n        </button>\n        <p id={reasonId} className=\"mt-2 font-mono text-[11px] text-ns-muted\">\n          {reasonText}\n        </p>\n      </div>\n    </div>\n  );\n}\n\nconst CSS = `\n.ns-rs-box{\n  position: relative;\n  display: inline-flex;\n  min-width: 42px;\n  height: 26px;\n  align-items: center;\n  justify-content: center;\n  padding: 0 6px;\n  border: 1px dashed var(--border);\n  border-radius: 6px;\n  font-family: var(--font-mono);\n  font-size: 11px;\n  font-weight: 600;\n  letter-spacing: 0.02em;\n  color: var(--foreground);\n  transform-origin: center;\n}\n.ns-rs-box[data-signed]{\n  border-style: solid;\n  border-color: var(--foreground);\n  transform: rotate(3deg);\n}\n.ns-rs-box[data-out-of-turn]{\n  transform: rotate(2deg) skewX(8deg);\n}\n.ns-rs-box[data-arriving]{\n  animation: ns-rs-chop-in ${CHOP_MS}ms cubic-bezier(0.16,1,0.3,1) both;\n}\n.ns-rs-box[data-arriving][data-out-of-turn]{\n  animation-name: ns-rs-chop-in-skew;\n}\n@keyframes ns-rs-chop-in{\n  from{ transform: scale(1.15) rotate(0deg); opacity: 0.45; }\n  to{ transform: scale(1) rotate(3deg); opacity: 1; }\n}\n@keyframes ns-rs-chop-in-skew{\n  from{ transform: scale(1.15) rotate(0deg) skewX(0deg); opacity: 0.45; }\n  to{ transform: scale(1) rotate(2deg) skewX(8deg); opacity: 1; }\n}\n\n.ns-rs-now{\n  display: inline-block;\n  font-family: var(--font-mono);\n  font-size: 11px;\n  text-transform: uppercase;\n  letter-spacing: 0.08em;\n  color: var(--foreground);\n  padding-bottom: 3px;\n  background-image: repeating-linear-gradient(90deg, var(--foreground) 0 5px, transparent 5px 10px);\n  background-position: 0 100%;\n  background-repeat: repeat-x;\n  background-size: 20px 1px;\n  animation: ns-rs-crawl 900ms linear infinite;\n}\n@keyframes ns-rs-crawl{\n  to{ background-position: -20px 100%; }\n}\n\n.ns-rs-btn{\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 6px;\n  border: 1px solid var(--border);\n  border-radius: 6px;\n  background: var(--background);\n  color: var(--foreground);\n  font-family: var(--font-mono);\n  font-size: 11px;\n  padding: 4px 10px;\n  cursor: pointer;\n  transition: background-color 150ms ease-out, border-color 150ms ease-out;\n}\n.ns-rs-btn:hover{\n  border-color: var(--ns-accent);\n  background: color-mix(in srgb, var(--ns-accent) 10%, var(--background));\n}\n.ns-rs-btn:active{\n  background: color-mix(in srgb, var(--ns-accent) 18%, var(--background));\n}\n.ns-rs-btn:focus-visible{\n  outline: 2px solid var(--ns-accent);\n  outline-offset: 2px;\n}\n.ns-rs-btn[data-disabled=\"true\"]{\n  color: var(--ns-muted);\n  cursor: not-allowed;\n}\n.ns-rs-btn[data-disabled=\"true\"]:hover,\n.ns-rs-btn[data-disabled=\"true\"]:active{\n  border-color: var(--border);\n  background: var(--background);\n}\n.ns-rs-btn[data-disabled=\"true\"]:focus-visible{\n  outline: 2px solid var(--foreground);\n  outline-offset: 2px;\n}\n\n@media (prefers-reduced-motion: reduce){\n  .ns-rs-box[data-arriving]{ animation: none; }\n  .ns-rs-now{ animation: none; }\n  .ns-rs-btn{ transition: none; }\n}\n`;\n",
      "type": "registry:ui",
      "target": "components/ui/routing-slip.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff"
    },
    "dark": {
      "ns-muted": "#8f8f8f"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "approval",
      "sign-off",
      "quorum",
      "table",
      "ledger",
      "workflow",
      "confirmation",
      "aria-live",
      "accessibility"
    ],
    "instruction": "Build RouteSlip, a controlled-once approval ledger for a fixed chain of approvers. Props: `approvers` (an array of `{id, name, role}` in ROUTED order — index 0 signs first in sequence; this array's order is the row order and never changes, regardless of who actually signs when), `initialSignatures` (optional array of `{approverId, at}` seeding already-signed rows before mount, in whatever order they actually happened), `quorum` (signatures required before Publish unblocks, clamped to [1, approvers.length], default approvers.length — this can be LESS than the full roster, which is a deliberately different claim from \"everyone must sign\"), `currentApproverId` (the one approver whose row gets a real, clickable Sign button — every other row is read-only text regardless of its own signed state, because this is one person's view of a shared slip, not an admin panel that can sign on anyone's behalf), `docLabel`, and `onSign`/`onPublish` callbacks. Signing and publishing are each one-shot and irreversible: once `currentApproverId` has a timestamp there is no unsign path, and once Publish fires there is no unpublish path — the same terminal-state discipline as approval-inline-diff's decided guard. MECHANISM: the component renders a real `<table>` with a `<caption>` (sr-only) and four `<th scope=\"col\">` columns — Approver, Role, Status, Time — one `<tr>` per approver in fixed routed order. The Approver cell prints the name followed by a small stamp box (1px dashed `--border`, ~42x26px). Before that approver signs the box is empty. The moment `currentApproverId` signs (Sign is a real `<button>`, present ONLY on that one row, reading \"Sign as {name}\"), the box fills with their initials in Geist Mono and plays a 260ms ease-out-expo press-in: `scale(1.15)` to `scale(1)` while settling into a `rotate(3deg)` tilt — a stamped, not typeset, mark. OUT OF TURN is the component's actual payload and is computed purely from final state, never from click order: approver i (by routed index) is out of turn if any earlier-routed approver j<i is still unsigned, or signed with a LATER timestamp than i's. Row 0 can never be out of turn — there is no one earlier to have skipped ahead of. A flagged chop's settle transform becomes `rotate(2deg) skewX(8deg)` instead of the plain 3deg tilt — noticeably irregular at a glance, still legible — and the row additionally renders a plain-text \"out of turn\" note beneath the name, so the distinction is carried by real text, not only by the skew. This is deliberately NOT a checkmark/avatar-overlay list: two approvers can both show \"Signed\" with identical green-free, color-free status text while only one of their stamps carries the skew, because a checkmark row has no way to encode routed-vs-actual order at all. GOVERNING SCALAR: signed count over quorum drives three derived surfaces — the header's \"{n} of {total} signed\" progress line (against the full roster, independent of quorum), the Status cell's \"Now\" label on the first unsigned row in routed order (independent of who `currentApproverId` is — \"Now\" can land on a row nobody present is allowed to sign), rendered with a crawling dashed underline (a `repeating-linear-gradient` sweeping via `background-position`, `--foreground`-only, never `--ns-accent`), and Publish's gating. Publish is a real `<button>` carrying `aria-disabled` (never the native `disabled` attribute, so it stays focusable and its reason stays reachable) plus `aria-describedby` pointing at a visible paragraph with the actual written reason, e.g. \"Publish disabled — needs 1 more signature, waiting on Release Mgmt.\" once quorum is met the reason reads \"Quorum met — ready to publish.\" and the button both loses `aria-disabled` and gains the enabled accent styling. A11Y: a polite `aria-live` region (sr-only, separate from the visible reason paragraph) announces on every genuine transition — never on the initial seeded mount, only on a sign or publish that happens in-session — phrased \"{n} of {total} signed; waiting on {role}.\" (naming the blocking approver's ROLE, matching the brief's own example almost verbatim) or \"...; all signed.\" once nobody remains, with \"Publish unlocked.\" appended the moment quorum is crossed, and a final \"Published.\" once Publish fires. Every signed row's timestamp is a real `<time datetime=...>` element. COLOR: strictly `--background` / `--foreground` / `--ns-muted` / `--border` / `--ns-accent`. `--ns-accent` appears nowhere but the Sign and Publish buttons' own hover/focus-visible/active states (border tint + a `color-mix(in srgb, var(--ns-accent) …%, var(--background))` wash, never a hex/rgb literal) — never on a chop, never as a persistent fill, and Publish's disabled variant overrides hover/active back to `--border`/`--background` and swaps its focus ring to `--foreground` so accent reads as an enabled-only signal exactly as specified. Under `prefers-reduced-motion`, the press-in keyframe and the \"Now\" underline's crawl animation are both stripped via a CSS media query (belt-and-suspenders alongside the JS `matchMedia` check that gates whether the press-in class is applied at all) — the final tilt/skew and the dashed underline still render at rest, fully legible on first paint, since a fixed tilt is not itself motion. Pure DOM and CSS, zero dependencies, no canvas or SVG."
  },
  "type": "registry:ui"
}