{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "clock-card",
  "title": "Clock Card Rack",
  "description": "A catch-up digest as a punch-clock card rack: one bordered card per collaborator, unread bursts holding the card proud of a shared top datum by up to 6px until a real 'Mark caught up' button settles it flush.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/clock-card/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// ClockCardRack — the \"what happened while I was away\" digest, built as a\n// punch-clock card rack: one radius-12 bordered card per collaborator, each\n// holding their own work bursts as real punched rows (\"edited section 2 —\n// 14:10 to 14:32\"). No interleaved anonymous feed — every row lives on its\n// author's card, so the rhythm of one person's morning reads at a glance\n// instead of needing per-line avatar decoding.\n//\n// Time is the only governing scalar. It drives three things, never set\n// independently: (1) row order inside a card — latest punch first; (2) rack\n// order across cards — the card with the most recent punch anywhere on it\n// sits on top, recomputed on every render, never a stored index; (3) how\n// PROUD an unread card sits. Every card shares one top datum (the hairline\n// at the head of the rack) and cards holding unread bursts float up to 6px\n// above their flush resting position — `2px + 1px per 12 unread hours`,\n// clamped at 6px so a two-week vacation's backlog can't shove a card off the\n// rack the way an unclamped scalar would. The clamp is the point: proudness\n// reads as \"there is unread work here\", not \"here is how much\".\n//\n// Marking a card read is a real per-card \"Mark caught up\" button, never a\n// passive read-on-view — settle is a pure transform transition (300ms\n// ease-out-expo) off the offset above, so it costs no layout. A brand new\n// punch row plays a single vertical clip reveal on the render it first\n// appears (detected by diffing burst ids against the previous commit in a\n// layout effect, so the reveal starts on the very first paint rather than\n// flashing open then replaying) — like a card dropped into the slot.\n//\n// Fully controlled: `collaborators` is the only model, rows carry their own\n// `unread` flag, the rack derives every sort/offset from it and holds no\n// copy of the model itself. \"Mark caught up\" is reported via a callback,\n// the caller flips the flags. Local state is transient UI only: which\n// burst ids are still mid-reveal-animation and the aria-live announcement\n// text. Colors are CSS custom properties only (--background, --foreground,\n// --ns-muted, --border, --ns-accent via the bg-ns-accent/text-white utility\n// pair already standard across this registry's buttons) — never a literal —\n// so both themes render correctly. Differs from memory-ledger-decay\n// (patina-ledger): that component ages a record by tarnishing its ink on a\n// color ramp; this one never recolors anything for unread state — unread is\n// a physical position along a datum line, settled by a button, not a decay\n// curve read off elapsed time. Pure DOM + CSS + real <time> elements, no\n// canvas. prefers-reduced-motion swaps the proud/flush states directly with\n// no 300ms settle and skips the row-reveal animation entirely; nothing\n// becomes unreachable, it just stops moving.\n// ---------------------------------------------------------------------------\n\nexport interface ClockCardBurst {\n  /** stable id, unique within its collaborator */\n  id: string;\n  /** what happened, e.g. \"edited section 2\" */\n  section: string;\n  /** ISO datetime the burst started */\n  start: string;\n  /** ISO datetime the burst ended */\n  end: string;\n  /** unread bursts hold their card proud of the rack. default false */\n  unread?: boolean;\n}\n\nexport interface ClockCardCollaborator {\n  /** stable id */\n  id: string;\n  /** person's name — becomes the card's accessible name */\n  name: string;\n  /** work bursts for this person, any order — the component sorts them */\n  bursts: ClockCardBurst[];\n}\n\nexport interface ClockCardRackProps {\n  /** one card per collaborator — fully controlled, the rack derives everything else */\n  collaborators: ClockCardCollaborator[];\n  /** fires when a card's \"Mark caught up\" button is pressed; caller clears that card's unread flags */\n  onMarkCaughtUp?: (collaboratorId: string) => void;\n  /** accessible name for the rack region. default \"Catch-up digest\" */\n  ariaLabel?: string;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst MAX_PROUD_PX = 6;\nconst BASE_PROUD_PX = 2;\nconst HOUR_MS = 3_600_000;\n\nfunction safeTime(iso: string): number {\n  const t = Date.parse(iso);\n  return Number.isFinite(t) ? t : 0;\n}\n\nfunction formatClock(iso: string): string {\n  const t = safeTime(iso);\n  if (!t) return \"--:--\";\n  return new Date(t).toLocaleTimeString(undefined, {\n    hour: \"2-digit\",\n    minute: \"2-digit\",\n    hour12: false,\n  });\n}\n\nfunction proudOffsetPx(bursts: ClockCardBurst[]): number {\n  let unreadHours = 0;\n  let unreadCount = 0;\n  for (const b of bursts) {\n    if (!b.unread) continue;\n    unreadCount++;\n    unreadHours += Math.max(0, safeTime(b.end) - safeTime(b.start)) / HOUR_MS;\n  }\n  if (unreadCount === 0) return 0;\n  return Math.min(MAX_PROUD_PX, BASE_PROUD_PX + unreadHours / 12);\n}\n\nfunction latestPunch(bursts: ClockCardBurst[]): number {\n  let latest = -Infinity;\n  for (const b of bursts) latest = Math.max(latest, safeTime(b.end));\n  return latest;\n}\n\nexport function ClockCardRack({\n  collaborators,\n  onMarkCaughtUp,\n  ariaLabel = \"Catch-up digest\",\n  className = \"\",\n}: ClockCardRackProps) {\n  const uid = useId();\n  const [reducedMotion, setReducedMotion] = useState(false);\n  const [enteringIds, setEnteringIds] = useState<Set<string>>(() => new Set());\n  const [liveMsg, setLiveMsg] = useState(\"\");\n  const seenIdsRef = useRef<Set<string> | null>(null);\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const update = () => setReducedMotion(mq.matches);\n    update();\n    mq.addEventListener(\"change\", update);\n    return () => mq.removeEventListener(\"change\", update);\n  }, []);\n\n  // Detect brand-new burst rows synchronously before paint, so the very\n  // first frame already renders them clipped-closed rather than flashing\n  // open once, then replaying closed->open a frame later.\n  useLayoutEffect(() => {\n    const allIds = new Set<string>();\n    for (const c of collaborators) for (const b of c.bursts) allIds.add(b.id);\n\n    const seen = seenIdsRef.current;\n    if (seen === null) {\n      // first mount: nothing \"enters\", it's just the initial render\n      seenIdsRef.current = allIds;\n      return;\n    }\n\n    const fresh = new Set<string>();\n    for (const id of allIds) if (!seen.has(id)) fresh.add(id);\n    seenIdsRef.current = allIds;\n\n    if (fresh.size === 0 || reducedMotion) return;\n    setEnteringIds((prev) => new Set([...prev, ...fresh]));\n    const t = window.setTimeout(() => {\n      setEnteringIds((prev) => {\n        const next = new Set(prev);\n        for (const id of fresh) next.delete(id);\n        return next;\n      });\n    }, 360);\n    return () => window.clearTimeout(t);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [collaborators, reducedMotion]);\n\n  const sorted = [...collaborators].sort(\n    (a, b) => latestPunch(b.bursts) - latestPunch(a.bursts)\n  );\n\n  function markCaughtUp(c: ClockCardCollaborator) {\n    onMarkCaughtUp?.(c.id);\n    setLiveMsg(`Caught up with ${c.name}`);\n  }\n\n  return (\n    <div\n      role=\"region\"\n      aria-label={ariaLabel}\n      className={[\"ns-clockcard-rack\", className].join(\" \")}\n    >\n      <style>{`\n.ns-clockcard-datum{height:1px;background:var(--border);margin-bottom:10px}\n.ns-clockcard-slots{display:flex;flex-direction:column;gap:10px;padding-top:${MAX_PROUD_PX}px}\n.ns-clockcard-card{border-radius:12px;border:1px solid var(--border);background:var(--background);transform:translateY(calc(-1 * var(--nsc-offset, 0px)));transition:transform 300ms cubic-bezier(.16,1,.3,1)}\n.ns-clockcard-head{display:flex;align-items:baseline;gap:8px;padding:10px 12px;border-bottom:1px solid var(--border)}\n.ns-clockcard-name{margin:0;font-size:13px;font-weight:600;color:var(--foreground)}\n.ns-clockcard-count{font-family:var(--font-mono, ui-monospace, monospace);font-size:11px;color:var(--ns-muted)}\n.ns-clockcard-caughtup{margin-left:auto;flex-shrink:0;border-radius:6px;background:var(--ns-accent);color:var(--background);font-size:11px;font-weight:500;padding:5px 10px;transition:opacity 150ms ease-out}\n.ns-clockcard-caughtup:hover:not(:disabled){opacity:0.82}\n.ns-clockcard-caughtup:focus-visible{outline:2px solid var(--ns-accent);outline-offset:2px}\n.ns-clockcard-caughtup:disabled{opacity:0.4;pointer-events:none;cursor:not-allowed}\n.ns-clockcard-rows{list-style:none;margin:0;padding:0}\n.ns-clockcard-row{overflow:hidden}\n.ns-clockcard-row + .ns-clockcard-row{border-top:1px solid var(--border)}\n.ns-clockcard-row-clip{padding:7px 12px;display:flex;flex-wrap:wrap;align-items:baseline;gap:6px 8px}\n.ns-clockcard-row[data-entering=\"true\"] .ns-clockcard-row-clip{animation:ns-clockcard-reveal 340ms cubic-bezier(.16,1,.3,1) both}\n@keyframes ns-clockcard-reveal{from{clip-path:inset(0 0 100% 0);opacity:0}to{clip-path:inset(0 0 0% 0);opacity:1}}\n.ns-clockcard-section{font-size:12.5px;color:var(--foreground);min-width:0}\n.ns-clockcard-times{font-family:var(--font-mono, ui-monospace, monospace);font-size:11.5px;color:var(--ns-muted);white-space:nowrap;margin-left:auto}\n.ns-clockcard-empty{padding:10px 12px;font-size:12px;color:var(--ns-muted)}\n@media (prefers-reduced-motion: reduce){\n  .ns-clockcard-card{transition:none!important}\n  .ns-clockcard-row[data-entering=\"true\"] .ns-clockcard-row-clip{animation:none!important}\n  .ns-clockcard-caughtup{transition:none!important}\n}\n`}</style>\n\n      <div aria-hidden=\"true\" className=\"ns-clockcard-datum\" />\n\n      <div className=\"ns-clockcard-slots\">\n        {sorted.map((c) => {\n          const bursts = [...c.bursts].sort(\n            (a, b) => safeTime(b.start) - safeTime(a.start)\n          );\n          const unreadCount = bursts.filter((b) => b.unread).length;\n          const offset = proudOffsetPx(bursts);\n          const headingId = `${uid}-${c.id}-name`;\n          const countText =\n            unreadCount > 0\n              ? `${unreadCount} unread burst${unreadCount === 1 ? \"\" : \"s\"}`\n              : \"Caught up\";\n\n          return (\n            <section\n              key={c.id}\n              aria-labelledby={headingId}\n              data-proud={unreadCount > 0}\n              className=\"ns-clockcard-card\"\n              style={{ \"--nsc-offset\": `${offset}px` } as React.CSSProperties}\n            >\n              <header className=\"ns-clockcard-head\">\n                <h3 id={headingId} className=\"ns-clockcard-name\">\n                  {c.name}\n                </h3>\n                <span className=\"ns-clockcard-count\">{countText}</span>\n                <button\n                  type=\"button\"\n                  onClick={() => markCaughtUp(c)}\n                  disabled={unreadCount === 0}\n                  aria-label={`Mark ${c.name} caught up`}\n                  className=\"ns-clockcard-caughtup\"\n                >\n                  Mark caught up\n                </button>\n              </header>\n\n              {bursts.length === 0 ? (\n                <p className=\"ns-clockcard-empty\">No activity yet.</p>\n              ) : (\n                <ul role=\"list\" className=\"ns-clockcard-rows\">\n                  {bursts.map((b) => (\n                    <li\n                      key={b.id}\n                      data-entering={enteringIds.has(b.id)}\n                      className=\"ns-clockcard-row\"\n                    >\n                      <div className=\"ns-clockcard-row-clip\">\n                        <span className=\"ns-clockcard-section\">{b.section}</span>\n                        <span className=\"ns-clockcard-times\">\n                          <time dateTime={b.start}>{formatClock(b.start)}</time>\n                          {\" – \"}\n                          <time dateTime={b.end}>{formatClock(b.end)}</time>\n                        </span>\n                      </div>\n                    </li>\n                  ))}\n                </ul>\n              )}\n            </section>\n          );\n        })}\n      </div>\n\n      <div aria-live=\"polite\" className=\"sr-only\">\n        {liveMsg}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/clock-card.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": [
      "digest",
      "activity",
      "feed",
      "rack",
      "card",
      "time",
      "mono",
      "aria-live",
      "accessibility",
      "collaboration"
    ],
    "instruction": "A punch-clock card rack for a 'what happened while I was away' digest: one radius-12 bordered card per collaborator (rounded-xl border border-border bg-background), stacked in a rail under one shared hairline datum. Every entry is a time-punched row rendered on its author's own card ('edited section 2 — 14:10 to 14:32', real <time dateTime> elements, Geist Mono) — the interleaved anonymous feed pattern is structurally impossible here, not just avoided by convention, because rows only ever exist inside a collaborator's own <ul>. Time is the single governing scalar and nothing else is: it sorts rows within a card (latest punch first), sorts cards across the rack (the card whose most recent burst end-time is newest sits on top, recomputed fresh every render from `Math.max` over each card's bursts, never a stored index — so the rack keeps itself sorted for free as new punches land), and sets how far a card sits proud of the shared top datum when it holds unread work: `2px + 1px per 12 cumulative unread hours` (summed duration of that card's unread bursts), clamped at 6px so a two-week backlog cannot eject a card off the physical range the rack renders in — the clamp is what keeps 'proud' legible as a binary-ish 'there is unread work here' signal rather than a magnitude gauge. A card with zero unread bursts sits at exactly 0 offset (flush), never at the clamped floor. Settling is a single CSS custom property (--nsc-offset) driving `transform: translateY()`, transitioned 300ms cubic-bezier(.16,1,.3,1) (ease-out-expo) — a pure transform, no layout is touched, so marking a card caught up costs one composited animation. Reading is opt-in and explicit: each card has a real, per-card 'Mark caught up' button (disabled once nothing is unread, guarded with disabled:pointer-events-none so the disabled state never fires its own hover style) that reports via `onMarkCaughtUp(collaboratorId)` — the component holds no model of its own, `collaborators` is the only prop and every derived value (row order, rack order, proud offset, unread count) is recomputed from it on every render, so the caller flipping `unread` flags is the only way state changes. Completion is announced through a polite aria-live region reading 'Caught up with <name>'. A brand new punch row (a burst id not present in the previous commit, detected by diffing id sets against a ref updated inside a layout effect so the diff runs and the new row already renders clipped-shut on the very first paint, never flashing open and then replaying) plays a single 340ms clip-path reveal, like a card being dropped into its slot — a genuinely new punch, not merely 'this data changed'. A11y: each card is a `<section aria-labelledby>` pointing at a real `<h3>` holding the person's name, with a plain-text unread count immediately after it ('4 unread bursts' / 'Caught up') so the state is legible without inferring anything from a color or a pixel offset; rows are `<li>` inside a `<ul>`, each holding two real `<time dateTime>` elements, never a styled `<span>` standing in for one; rack re-sorting is a pure reorder of `<section>` elements keyed by collaborator id, so React moves the existing DOM nodes rather than remounting them and focus survives a re-sort for free. Props: `collaborators` (`{id, name, bursts: {id, section, start, end, unread?}[]}[]`), `onMarkCaughtUp`, `ariaLabel` (default 'Catch-up digest'), `className`. prefers-reduced-motion drops the 300ms settle transition and the row-reveal animation entirely — proud/flush and new/existing rows just render in their resting state directly, every control stays fully operable. Pure DOM + CSS + inline `<time>` — no canvas, no SVG. Demo: three collaborators at different proud depths (one two-burst backlog, one single fresh punch, one already caught up) plus a 'Simulate new punch' control that appends a new unread burst and shows the reveal-and-possible-resort together."
  },
  "type": "registry:ui"
}