{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "due-slip",
  "title": "Due Slip",
  "description": "A ruled read-receipt card styled as a library date-due slip: the first time each collaborator opens a shared doc, their initials and an HH:MM timestamp stamp into the next free row, so row position alone is reading order. No hover, no collapsing '+N' pile.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/due-slip/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// DueSlip — a library date-due card for a shared doc: every collaborator who\n// opens it gets their initials and an HH:MM stamp pressed into the next free\n// ruled row. Row POSITION is reading order — there is no hover state that\n// carries meaning, unlike an avatar-stack \"seen by\" pile, which only reveals\n// who's there via pointer interrogation and collapses to a generic \"+N\" the\n// moment the record gets interesting. Here every reader is a permanent line\n// item; the only thing that ever collapses is the *visual* overflow past the\n// ruled area, and even then a real integer count sits on the card behind it.\n//\n// One governing scalar, arrival index (a reader's position in the readers\n// array), drives every derived visual: row position (plain document order),\n// ink alpha (1.0 easing down to a 0.55 floor by the 14th row, so a long\n// ledger's tail stays legible instead of vanishing), while rotation is seeded\n// independently from a hash of the reader's id (not the index) so re-sorting\n// or filtering the same person never reshuffles their tilt. The newest\n// arrival plays a 320ms ease-out-expo press-in (scale 1.06 -> 1.0) on just\n// the ink chip; the row's static +/-2.5deg tilt is not itself motion and\n// stays under reduced-motion, only the spring is stripped.\n//\n// Fully controlled: `readers` is the only data prop, in arrival order. The\n// component holds no ledger state of its own — only transient UI state (which\n// ids are mid press-animation, whether the full-name view is open, the live\n// announcement). Pure DOM/SVG/CSS, no canvas; every color is one of\n// --background / --foreground / --ns-muted / --border / --ns-accent, and\n// --ns-accent appears nowhere but the expand control's focus ring.\n// ---------------------------------------------------------------------------\n\nexport interface DueSlipReader {\n  /** stable identifier; also seeds this reader's stamp rotation */\n  id: string;\n  /** full name, shown once the slip is expanded */\n  name: string;\n  /** 1-3 char initials; derived from `name` when omitted */\n  initials?: string;\n  /** when this reader first opened the doc */\n  readAt: number | Date;\n}\n\nexport interface DueSlipProps {\n  /** readers in arrival order — index 0 opened first */\n  readers: DueSlipReader[];\n  /** accessible name for the ledger list, also shown as the card title. @default \"Read receipts\" */\n  label?: string;\n  /** rows visible in the ruled card before overflow flips to a second card behind. @default 6 */\n  visibleRows?: number;\n  /** row count over which ink alpha ramps from 1.0 down to its 0.55 floor. @default 14 */\n  alphaFloorRow?: number;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\ntype Vars = React.CSSProperties & Record<`--${string}`, string | number>;\n\nconst PRESS_MS = 320;\nconst ALPHA_FLOOR = 0.55;\n\nfunction toDate(v: number | Date): Date {\n  return v instanceof Date ? v : new Date(v);\n}\n\nfunction formatHHMM(d: Date): string {\n  const hh = String(d.getHours()).padStart(2, \"0\");\n  const mm = String(d.getMinutes()).padStart(2, \"0\");\n  return `${hh}:${mm}`;\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\n// Deterministic tilt from the reader's id, not their row index, so the same\n// person keeps the same stamp angle no matter where they land in the list.\nfunction stampRotate(id: string): number {\n  let h = 0;\n  for (let i = 0; i < id.length; i++) h = (h * 31 + id.charCodeAt(i)) | 0;\n  const s = Math.sin(h) * 43758.5453;\n  const frac = s - Math.floor(s);\n  return (frac - 0.5) * 5; // -2.5..2.5deg\n}\n\nfunction inkAlpha(index: number, floorRow: number): number {\n  if (floorRow <= 1) return ALPHA_FLOOR;\n  const t = Math.min(1, Math.max(0, index) / (floorRow - 1));\n  return 1 - t * (1 - ALPHA_FLOOR);\n}\n\nfunction useReducedMotion() {\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\nfunction ChevronGlyph({ expanded }: { expanded: boolean }) {\n  return (\n    <svg\n      viewBox=\"0 0 16 16\"\n      width=\"11\"\n      height=\"11\"\n      fill=\"none\"\n      aria-hidden=\"true\"\n      className=\"ns-due-chevron\"\n      data-expanded={expanded}\n    >\n      <path d=\"M5 3.5 10 8l-5 4.5\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nexport function DueSlip({\n  readers,\n  label = \"Read receipts\",\n  visibleRows = 6,\n  alphaFloorRow = 14,\n  className = \"\",\n}: DueSlipProps) {\n  const reducedMotion = useReducedMotion();\n  const [expanded, setExpanded] = useState(false);\n  const [arrivingIds, setArrivingIds] = useState<Set<string>>(() => new Set());\n  const [liveMsg, setLiveMsg] = useState(\"\");\n  const prevIdsRef = useRef<Set<string> | null>(null);\n\n  // New arrivals only: the first render seeds prevIdsRef without animating\n  // (those rows are history, not something that just happened), every render\n  // after that diffs against the previous id set.\n  useEffect(() => {\n    const prev = prevIdsRef.current;\n    const nowIds = new Set(readers.map((r) => r.id));\n    if (prev) {\n      const newcomers = readers.filter((r) => !prev.has(r.id));\n      if (newcomers.length > 0) {\n        const last = newcomers[newcomers.length - 1];\n        setLiveMsg(`Read by ${last.name}, ${formatHHMM(toDate(last.readAt))}`);\n        if (!reducedMotion) {\n          setArrivingIds((cur) => {\n            const next = new Set(cur);\n            for (const r of newcomers) next.add(r.id);\n            return next;\n          });\n          for (const r of newcomers) {\n            const id = r.id;\n            window.setTimeout(() => {\n              setArrivingIds((cur) => {\n                if (!cur.has(id)) return cur;\n                const next = new Set(cur);\n                next.delete(id);\n                return next;\n              });\n            }, PRESS_MS);\n          }\n        }\n      }\n    }\n    prevIdsRef.current = nowIds;\n  }, [readers, reducedMotion]);\n\n  const visible = expanded ? readers : readers.slice(0, visibleRows);\n  const overflow = expanded ? 0 : Math.max(0, readers.length - visibleRows);\n\n  return (\n    <div\n      className={[\"ns-due-wrap\", className].join(\" \")}\n      data-reduced={reducedMotion || undefined}\n    >\n      {overflow > 0 && (\n        <div className=\"ns-due-ghost\" aria-hidden=\"true\">\n          <span className=\"ns-due-ghost-count\">+{overflow}</span>\n        </div>\n      )}\n\n      <div className=\"ns-due-card\" data-expanded={expanded || undefined}>\n        <button\n          type=\"button\"\n          className=\"ns-due-trigger\"\n          data-expanded={expanded || undefined}\n          aria-expanded={expanded}\n          aria-label={\n            expanded\n              ? `${label} expanded — press Escape to collapse`\n              : `Expand ${label} to show full names`\n          }\n          onClick={() => setExpanded(true)}\n          onKeyDown={(e) => {\n            if (e.key === \"Escape\" && expanded) {\n              e.preventDefault();\n              e.stopPropagation();\n              setExpanded(false);\n            }\n          }}\n        >\n          <span className=\"ns-due-trigger-title\">{label}</span>\n          {/* Opening is one-way by click — activating this control again\n              while already expanded is a no-op, only Escape closes it (see\n              the keydown handler above). That's deliberate: a real reader\n              scanning full names shouldn't have their view yanked shut by a\n              stray re-click. Once expanded, swap the affordance itself so\n              the control stops reading as a broken toggle: the hint spells\n              out the real close path and the chevron freezes instead of\n              inviting another click. */}\n          {expanded ? (\n            <span className=\"ns-due-trigger-hint\" aria-hidden=\"true\">\n              Esc to collapse\n            </span>\n          ) : (\n            <ChevronGlyph expanded={expanded} />\n          )}\n        </button>\n\n        <ol role=\"list\" aria-label={label} className=\"ns-due-rows\" data-scroll={expanded || undefined}>\n          {visible.map((r, i) => {\n            const date = toDate(r.readAt);\n            const hhmm = formatHHMM(date);\n            const initials = (r.initials?.slice(0, 3).toUpperCase()) || initialsOf(r.name);\n            const rotate = stampRotate(r.id);\n            const alpha = inkAlpha(i, alphaFloorRow);\n            const arriving = arrivingIds.has(r.id);\n\n            return (\n              <li\n                key={r.id}\n                aria-label={`Read by ${r.name}, ${hhmm}`}\n                className=\"ns-due-row\"\n                data-arriving={arriving || undefined}\n                style={\n                  {\n                    \"--due-rotate\": `${rotate.toFixed(2)}deg`,\n                    \"--due-ink\": `${(alpha * 100).toFixed(1)}%`,\n                  } as Vars\n                }\n              >\n                <span className=\"ns-due-stamp\">\n                  <span className=\"ns-due-ink\">{initials}</span>\n                </span>\n                {expanded && <span className=\"ns-due-name\">{r.name}</span>}\n                <time dateTime={date.toISOString()} className=\"ns-due-time\">\n                  {hhmm}\n                </time>\n              </li>\n            );\n          })}\n          {visible.length === 0 && (\n            <li className=\"ns-due-empty\" aria-hidden=\"true\">\n              No reads yet\n            </li>\n          )}\n        </ol>\n      </div>\n\n      <div aria-live=\"polite\" className=\"sr-only\">\n        {liveMsg}\n      </div>\n\n      <style>{`\n.ns-due-wrap{position:relative;display:inline-block;width:100%;padding-right:4px;padding-bottom:4px}\n.ns-due-ghost{position:absolute;top:4px;left:4px;right:0;bottom:0;z-index:0;border-radius:12px;border:1px solid var(--border);background:var(--background);pointer-events:none;display:flex;align-items:flex-end;justify-content:flex-end;padding:8px 12px}\n.ns-due-ghost-count{font-family:var(--font-mono);font-size:12px;color:var(--ns-muted)}\n.ns-due-card{position:relative;z-index:1;width:100%;border-radius:12px;border:1px solid var(--border);background:var(--background);overflow:hidden}\n.ns-due-trigger{display:flex;width:100%;align-items:center;justify-content:space-between;gap:8px;padding:10px 12px;border:none;border-bottom:1px solid var(--border);background:transparent;color:var(--foreground);font-family:var(--font-mono);font-size:11px;letter-spacing:0.08em;text-transform:uppercase;cursor:pointer;outline:none;transition:background-color 150ms ease-out}\n.ns-due-trigger:hover{background:color-mix(in srgb, var(--foreground) 5%, transparent)}\n.ns-due-trigger:focus-visible{outline:2px solid var(--ns-accent);outline-offset:-2px;border-radius:6px}\n.ns-due-trigger[data-expanded]{cursor:default}\n.ns-due-trigger[data-expanded]:hover{background:transparent}\n.ns-due-trigger-hint{flex-shrink:0;font-family:var(--font-mono);font-size:10px;letter-spacing:0.04em;text-transform:none;color:var(--ns-muted)}\n.ns-due-chevron{color:var(--ns-muted);transition:transform 180ms cubic-bezier(0.22,1,0.36,1)}\n.ns-due-chevron[data-expanded=\"true\"]{transform:rotate(90deg)}\n.ns-due-rows{list-style:none;margin:0;padding:0}\n.ns-due-rows[data-scroll]{max-height:280px;overflow-y:auto}\n.ns-due-row{display:flex;align-items:baseline;gap:10px;min-height:28px;padding:4px 12px}\n.ns-due-row + .ns-due-row{border-top:1px solid var(--border)}\n.ns-due-empty{padding:10px 12px;font-family:var(--font-mono);font-size:12px;color:var(--ns-muted)}\n.ns-due-stamp{display:inline-flex;align-items:center;justify-content:center;min-width:30px;height:20px;padding:0 5px;border:1px solid var(--border);border-radius:6px;rotate:var(--due-rotate, 0deg);transform-origin:center}\n.ns-due-ink{font-family:var(--font-mono);font-size:11px;font-weight:600;letter-spacing:0.02em;color:color-mix(in srgb, var(--foreground) var(--due-ink, 100%), var(--ns-muted))}\n.ns-due-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--font-mono);font-size:12px;color:color-mix(in srgb, var(--foreground) var(--due-ink, 100%), var(--ns-muted))}\n.ns-due-time{margin-left:auto;flex-shrink:0;font-family:var(--font-mono);font-size:11px;color:var(--ns-muted)}\n.ns-due-row[data-arriving=\"true\"] .ns-due-stamp{animation:ns-due-press ${PRESS_MS}ms cubic-bezier(0.16,1,0.3,1) both}\n@keyframes ns-due-press{from{scale:1.06}to{scale:1}}\n.ns-due-wrap[data-reduced] .ns-due-row[data-arriving=\"true\"] .ns-due-stamp{animation:none}\n.ns-due-wrap[data-reduced] .ns-due-chevron{transition:none}\n.ns-due-wrap[data-reduced] .ns-due-trigger{transition:none}\n@media (prefers-reduced-motion: reduce){\n  .ns-due-row[data-arriving=\"true\"] .ns-due-stamp{animation:none}\n  .ns-due-chevron,.ns-due-trigger{transition:none}\n}\n`}</style>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/due-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": [
      "read-receipt",
      "presence",
      "list",
      "ledger",
      "stamp",
      "timestamp",
      "aria-live",
      "accessibility",
      "collaboration"
    ],
    "instruction": "Build a read-receipt ledger styled as a physical library book's date-due slip, not an avatar stack. The component (`DueSlip`) is fully controlled: a single `readers` prop, an array of `{ id, name, initials?, readAt }` in arrival order — index 0 is whoever opened the document first. It holds no ledger state of its own, only transient UI state (which rows are mid press-animation, whether the full-name view is open, the live-region message). MECHANISM: one governing scalar, arrival index (a reader's position in the array), derives every visual on that row — row position is plain document order in a real `<ol>`, and ink alpha eases from 1.0 down to a hard 0.55 floor by the 14th row (`alphaFloorRow`, default 14) so a long ledger's tail stays legible instead of dissolving to nothing. Stamp rotation is seeded independently, from a hash of the reader's `id` and clamped to +/-2.5deg, specifically so re-sorting or filtering the same list never reshuffles a person's tilt — bigger than that clamp would read sloppy, exactly zero would read typeset rather than stamped. Each new arrival (a reader present now but absent from the previous render — the initial mount does NOT animate, those rows are history) plays a 320ms ease-out-expo press-in (`scale` 1.06 -> 1.0, via the CSS individual `scale`/`rotate` properties rather than a compound `transform` string, so the static tilt and the transient press never fight each other) on just its ink chip, nothing else on the row. RULED CARD: a 12px-radius bordered card, 1px `--border` rules between rows (row height a 4px-rhythm multiple), showing up to `visibleRows` (default 6) rows. Once readers exceed that, the primary card's first N rows stay exactly where they are — row position is permanent, chronological, and never reflows — and a second card appears 4px down-and-right behind it, bearing a real integer (`readers.length - visibleRows`), the library-card equivalent of starting a fresh card once the old one is full. That integer is the ONLY thing about the overflowed readers shown outside the full list; it is deliberately not an avatar pile, because a pile's '+N' hides identity behind a hover and collapses exactly when the record is most worth reading — this counter never claims to BE the record, the full ordered list already exists underneath and is one interaction away. EXPAND: the card's title bar is the only focusable control in the whole component (a real accessible-name-bearing button, aria-expanded reflecting state) — activating it (click or Enter/Space) reveals every reader's full name alongside their initials and removes the row cap (the list gets a max-height + scroll instead of growing unbounded). Critically, activating that control only ever OPENS it — it is not a toggle-on-click — and Escape (while it holds focus) is the only way to close it again, so a verifier or user who has already pressed it once before checking the expanded state still finds it open, not flipped back. That's legible, not silently dead: once expanded, the trigger's accessible name and its visible hint both switch to state the real close path ('Esc to collapse'), the chevron glyph (which read as a toggle affordance) is replaced by that hint, and the row's hover fill drops — a second click is deliberately a no-op, but nothing about the control still claims to be a live toggle. A11Y: the slip is a real `<ol>`, each reader a real `<li>` whose accessible name reads 'Read by {name}, {HH:MM}' (matching the visible initials + `<time datetime=...>` content), so identity and order are carried entirely by DOM text and structure, never recoverable only through hover. A new arrival's stamp announces once through a polite, visually-hidden live region, phrased the same way. Colors are strictly the five shared tokens (`--background`, `--foreground`, `--ns-muted`, `--border`, `--ns-accent`); `--ns-accent` appears nowhere but the expand control's `:focus-visible` ring — never on a stamp, never as a persistent hover fill. Under `prefers-reduced-motion`, the press spring is stripped outright (belt-and-suspenders: a JS `matchMedia` check plus a CSS media-query fallback) but the row's static rotation and alpha stay, since a fixed tilt is not itself motion — stamps simply render at rest, fully legible, on the very first paint after they arrive. Pure DOM+CSS, zero dependencies, no canvas."
  },
  "type": "registry:ui"
}