{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-stack-expand",
  "type": "registry:component",
  "title": "Card Stack Expand",
  "description": "Notification cards stacked with depth. Hover, focus or the Expand button spreads them into a list, and each card dismisses with a swipe or its close button. New cards drop in from the top.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "stack",
    "notifications",
    "cards",
    "swipe",
    "dismiss",
    "expand"
  ],
  "docs": "https://hyperblur.dev/effects/card-stack-expand",
  "files": [
    {
      "path": "registry/hyperblur/card-stack-expand.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/card-stack-expand.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface StackNotification {\n  id: string;\n  title: string;\n  body?: string;\n  time?: string;\n  color?: string;\n  mark?: string;\n}\n\nexport interface CardStackExpandProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  items?: StackNotification[];\n  defaultItems?: StackNotification[];\n  onChange?: (items: StackNotification[]) => void;\n  incoming?: StackNotification[];\n  title?: string;\n  max?: number;\n  cardHeight?: number;\n  gap?: number;\n  autoPeek?: number;\n  reserveSpace?: boolean;\n  accent?: string;\n}\n\nconst seed: StackNotification[] = [\n  { id: \"s1\", title: \"Deploy finished\", body: \"web-app is live on production\", time: \"now\", color: \"#2f7bff\", mark: \"D\" },\n  { id: \"s2\", title: \"Maya commented\", body: \"Can we ship the new pricing page?\", time: \"4m\", color: \"#e5584f\", mark: \"M\" },\n  { id: \"s3\", title: \"Invoice paid\", body: \"Northwind sent $1,240.00\", time: \"1h\", color: \"#2fa56b\", mark: \"$\" },\n  { id: \"s4\", title: \"Weekly digest\", body: \"12 merged pull requests this week\", time: \"2h\", color: \"#9a6bff\", mark: \"W\" },\n];\n\nconst pool: StackNotification[] = [\n  { id: \"p1\", title: \"New signup\", body: \"ana@fernhill.example joined Team\", time: \"now\", color: \"#f0a22e\", mark: \"N\" },\n  { id: \"p2\", title: \"Build warning\", body: \"Bundle grew by 14 kB on /pricing\", time: \"now\", color: \"#e5584f\", mark: \"!\" },\n  { id: \"p3\", title: \"Review requested\", body: \"Tomas asked for your review\", time: \"now\", color: \"#2f7bff\", mark: \"R\" },\n  { id: \"p4\", title: \"Backup complete\", body: \"Nightly snapshot stored, 2.4 GB\", time: \"now\", color: \"#2fa56b\", mark: \"B\" },\n];\n\nconst css = `\n.hb-za4 {\n  --hb-za4-c: #2f7bff;\n  --hb-za4-h: 52px;\n  --hb-za4-g: 8px;\n  --hb-za4-p: 9px;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-za4 *, .hb-za4 *::before, .hb-za4 *::after { box-sizing: border-box; }\n.hb-za4-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }\n.hb-za4-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-za4-count {\n  min-width: 20px;\n  padding: 1px 6px;\n  font-size: 11px;\n  font-weight: 600;\n  line-height: 16px;\n  text-align: center;\n  color: #ededed;\n  background: #262626;\n  border-radius: 999px;\n  font-variant-numeric: tabular-nums;\n}\n.hb-za4-tools { display: flex; gap: 6px; }\n.hb-za4-tool {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  height: 26px;\n  margin: 0;\n  padding: 0 10px;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 500;\n  color: #d4d4d4;\n  background: #171717;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;\n}\n.hb-za4-tool:hover { background: #202020; border-color: #3a3a3a; }\n.hb-za4-tool:active { transform: scale(0.96); }\n.hb-za4-tool:focus-visible { outline: 2px solid var(--hb-za4-c); outline-offset: 2px; }\n.hb-za4-tool svg { width: 12px; height: 12px; }\n.hb-za4-stack {\n  position: relative;\n  height: var(--hb-za4-sh);\n  list-style: none;\n  margin: 0;\n  padding: 0;\n  transition: height 0.5s cubic-bezier(0.22, 0.9, 0.24, 1);\n}\n.hb-za4-item {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 0;\n  height: var(--hb-za4-h);\n  z-index: calc(100 - var(--hb-za4-k));\n  transform-origin: 50% 100%;\n  transform: translateY(calc(var(--hb-za4-k) * var(--hb-za4-p))) scale(calc(1 - var(--hb-za4-k) * 0.05));\n  transition: transform 0.5s cubic-bezier(0.22, 0.9, 0.24, 1), opacity 0.35s ease;\n}\n.hb-za4[data-open=\"true\"] .hb-za4-item {\n  transform: translateY(calc(var(--hb-za4-k) * (var(--hb-za4-h) + var(--hb-za4-g)))) scale(1);\n}\n.hb-za4-item[data-hide=\"true\"] { opacity: 0; pointer-events: none; }\n.hb-za4-card {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 100%;\n  padding: 0 8px 0 10px;\n  overflow: hidden;\n  background: #151515;\n  border: 1px solid #2a2a2a;\n  border-radius: 12px;\n  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);\n  transform: translateX(var(--hb-za4-dx, 0px));\n  transition: transform 0.35s cubic-bezier(0.22, 0.9, 0.24, 1), opacity 0.3s ease;\n  animation: hb-za4-in 0.5s cubic-bezier(0.22, 0.9, 0.24, 1) backwards;\n  touch-action: pan-y;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-za4-item[data-drag=\"true\"] .hb-za4-card { transition: none; }\n.hb-za4-item[data-leaving=\"true\"] .hb-za4-card { transform: translateX(calc(var(--hb-za4-dir, 1) * 115%)); opacity: 0; }\n.hb-za4-item[data-leaving=\"true\"] { pointer-events: none; }\n.hb-za4[data-open=\"true\"] .hb-za4-card { cursor: grab; }\n.hb-za4-body, .hb-za4-mark, .hb-za4-meta { transition: opacity 0.3s ease; }\n.hb-za4[data-open=\"false\"] .hb-za4-item:not([data-top=\"true\"]) .hb-za4-card > * { opacity: 0; }\n.hb-za4-mark {\n  display: grid;\n  flex: 0 0 auto;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  font-size: 13px;\n  font-weight: 700;\n  color: #ffffff;\n  border-radius: 9px;\n}\n.hb-za4-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }\n.hb-za4-body b { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-za4-body span { font-size: 12px; color: #9a9a9a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-za4-meta { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; }\n.hb-za4-time { font-size: 11px; color: #707070; font-variant-numeric: tabular-nums; }\n.hb-za4-x {\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  margin: 0;\n  padding: 0;\n  color: #8f8f8f;\n  background: transparent;\n  border: 0;\n  border-radius: 8px;\n  cursor: pointer;\n  transition: background 0.2s ease, color 0.2s ease;\n}\n.hb-za4-x:hover { background: #262626; color: #ededed; }\n.hb-za4-x:focus-visible { outline: 2px solid var(--hb-za4-c); outline-offset: 1px; }\n.hb-za4-x svg { width: 12px; height: 12px; }\n.hb-za4-empty {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  height: var(--hb-za4-h);\n  font-size: 12px;\n  color: #8f8f8f;\n  border: 1px dashed #2a2a2a;\n  border-radius: 12px;\n  animation: hb-za4-in 0.5s cubic-bezier(0.22, 0.9, 0.24, 1) backwards;\n}\n.hb-za4-empty svg { width: 14px; height: 14px; color: var(--hb-za4-c); }\n@keyframes hb-za4-in {\n  from { opacity: 0; transform: translateY(-18px) scale(0.94); }\n  to { opacity: 1; transform: translateY(0) scale(1); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-za4-stack, .hb-za4-item, .hb-za4-card, .hb-za4-body, .hb-za4-mark, .hb-za4-meta, .hb-za4-tool { transition: none; }\n  .hb-za4-card, .hb-za4-empty { animation: none; }\n}\n`;\n\nexport function CardStackExpand({\n  items,\n  defaultItems,\n  onChange,\n  incoming,\n  title = \"Notifications\",\n  max = 4,\n  cardHeight = 52,\n  gap = 8,\n  autoPeek = 0,\n  reserveSpace = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  onKeyDown,\n  ...rest\n}: CardStackExpandProps) {\n  const controlled = items !== undefined;\n  const [inner, setInner] = React.useState<StackNotification[]>(defaultItems ?? seed);\n  const list = controlled ? items : inner;\n  const queue = incoming && incoming.length ? incoming : pool;\n  const [leaving, setLeaving] = React.useState<Record<string, number>>({});\n  const [hover, setHover] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const [pinned, setPinned] = React.useState(false);\n  const [peek, setPeek] = React.useState(false);\n  const [drag, setDrag] = React.useState<{ id: string; dx: number } | null>(null);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const timers = React.useRef<number[]>([]);\n  const counter = React.useRef(0);\n  const down = React.useRef<{ id: string; x: number; pid: number; moved: boolean } | null>(null);\n  const latest = React.useRef({ list, onChange, controlled });\n  const stackId = React.useId();\n\n  React.useEffect(() => {\n    latest.current = { list, onChange, controlled };\n  }, [list, onChange, controlled]);\n\n  React.useEffect(() => {\n    const ids = timers.current;\n    return () => ids.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const open = hover || focused || pinned || peek;\n  const interacting = hover || focused || pinned;\n\n  React.useEffect(() => {\n    if (!autoPeek || interacting) return;\n    let id = 0;\n    function wait() {\n      id = window.setTimeout(() => {\n        setPeek(true);\n        id = window.setTimeout(() => {\n          setPeek(false);\n          wait();\n        }, 2000);\n      }, autoPeek);\n    }\n    wait();\n    return () => {\n      window.clearTimeout(id);\n      setPeek(false);\n    };\n  }, [autoPeek, interacting]);\n\n  React.useEffect(() => {\n    if (!pinned) return;\n    function away(e: PointerEvent) {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setPinned(false);\n    }\n    document.addEventListener(\"pointerdown\", away);\n    return () => document.removeEventListener(\"pointerdown\", away);\n  }, [pinned]);\n\n  function commit(next: StackNotification[]) {\n    if (!latest.current.controlled) setInner(next);\n    latest.current.onChange?.(next);\n  }\n\n  function dismiss(id: string, dir: number) {\n    setLeaving((prev) => (prev[id] ? prev : { ...prev, [id]: dir }));\n    const t = window.setTimeout(() => {\n      commit(latest.current.list.filter((n) => n.id !== id));\n      setLeaving((prev) => {\n        const copy = { ...prev };\n        delete copy[id];\n        return copy;\n      });\n    }, 340);\n    timers.current.push(t);\n  }\n\n  function add() {\n    const base = queue[counter.current % queue.length];\n    counter.current += 1;\n    const fresh = { ...base, id: `${base.id}-${counter.current}` };\n    commit([fresh, ...latest.current.list]);\n  }\n\n  const live = list.filter((n) => !leaving[n.id]);\n  const shown = Math.max(1, Math.min(live.length, open ? max : 3));\n  const collapsedHeight = cardHeight + Math.min(Math.max(live.length - 1, 0), 2) * 9;\n  const expandedCount = Math.max(1, Math.min(live.length, max));\n  const expandedHeight = expandedCount * cardHeight + (expandedCount - 1) * gap;\n  const stackHeight = reserveSpace\n    ? Math.max(expandedHeight, collapsedHeight)\n    : open\n      ? expandedHeight\n      : collapsedHeight;\n\n  const vars = {\n    \"--hb-za4-c\": accent,\n    \"--hb-za4-h\": `${cardHeight}px`,\n    \"--hb-za4-g\": `${gap}px`,\n    \"--hb-za4-sh\": `${stackHeight}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  const orders: number[] = [];\n  let running = 0;\n  list.forEach((n) => {\n    orders.push(running);\n    if (!leaving[n.id]) running += 1;\n  });\n\n  function pointerDown(e: React.PointerEvent<HTMLElement>, id: string) {\n    if (!open || (e.pointerType === \"mouse\" && e.button !== 0)) return;\n    if ((e.target as HTMLElement).closest(\"button\")) return;\n    down.current = { id, x: e.clientX, pid: e.pointerId, moved: false };\n  }\n\n  function pointerMove(e: React.PointerEvent<HTMLElement>) {\n    const d = down.current;\n    if (!d || d.pid !== e.pointerId) return;\n    const dx = e.clientX - d.x;\n    if (!d.moved && Math.abs(dx) < 5) return;\n    if (!d.moved) e.currentTarget.setPointerCapture(e.pointerId);\n    d.moved = true;\n    setDrag({ id: d.id, dx });\n  }\n\n  function pointerUp(e: React.PointerEvent<HTMLElement>) {\n    const d = down.current;\n    if (!d || d.pid !== e.pointerId) return;\n    down.current = null;\n    const dx = drag?.dx ?? 0;\n    setDrag(null);\n    if (Math.abs(dx) > 80) dismiss(d.id, dx > 0 ? 1 : -1);\n  }\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-za4 ${className}`}\n      style={vars}\n      data-open={open}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        if (e.pointerType === \"mouse\") setHover(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        if (e.pointerType === \"mouse\") setHover(false);\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        setFocused(true);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (e.key === \"Escape\") {\n          setPinned(false);\n          setHover(false);\n          setFocused(false);\n          (document.activeElement as HTMLElement | null)?.blur();\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-card-stack-expand\" precedence=\"default\">{css}</style>\n      <div className=\"hb-za4-head\">\n        <div className=\"hb-za4-title\">\n          <span>{title}</span>\n          <span className=\"hb-za4-count\" aria-label={`${live.length} notifications`}>{live.length}</span>\n        </div>\n        <div className=\"hb-za4-tools\">\n          <button type=\"button\" className=\"hb-za4-tool\" onClick={add}>\n            <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n              <path d=\"M6 2v8M2 6h8\" />\n            </svg>\n            New\n          </button>\n          <button\n            type=\"button\"\n            className=\"hb-za4-tool\"\n            aria-expanded={open}\n            aria-controls={stackId}\n            onClick={() => setPinned((v) => !v)}\n          >\n            {open ? \"Collapse\" : \"Expand\"}\n          </button>\n        </div>\n      </div>\n      {live.length === 0 ? (\n        <div className=\"hb-za4-empty\">\n          <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"m2.5 7.5 3 3 6-6.5\" />\n          </svg>\n          You are all caught up\n        </div>\n      ) : null}\n      <ul\n        id={stackId}\n        className=\"hb-za4-stack\"\n        style={live.length === 0 ? { display: \"none\" } : undefined}\n        onClick={() => {\n          if (!open) setPinned(true);\n        }}\n      >\n        {list.map((n, idx) => {\n          const isLeaving = Boolean(leaving[n.id]);\n          const k = orders[idx];\n          const hidden = isLeaving ? false : k >= shown;\n          const dragging = drag?.id === n.id;\n          const itemStyle = {\n            \"--hb-za4-k\": k,\n            \"--hb-za4-dir\": leaving[n.id] ?? 1,\n            \"--hb-za4-dx\": dragging ? `${drag.dx.toFixed(1)}px` : \"0px\",\n          } as React.CSSProperties;\n          return (\n            <li\n              key={n.id}\n              className=\"hb-za4-item\"\n              style={itemStyle}\n              data-top={k === 0}\n              data-hide={hidden}\n              data-drag={dragging}\n              data-leaving={isLeaving}\n              aria-hidden={hidden || (!open && k > 0) ? true : undefined}\n              onPointerDown={(e) => pointerDown(e, n.id)}\n              onPointerMove={pointerMove}\n              onPointerUp={pointerUp}\n              onPointerCancel={pointerUp}\n            >\n              <div className=\"hb-za4-card\">\n                <span className=\"hb-za4-mark\" style={{ background: n.color ?? accent }} aria-hidden=\"true\">\n                  {n.mark ?? n.title.charAt(0)}\n                </span>\n                <div className=\"hb-za4-body\">\n                  <b>{n.title}</b>\n                  {n.body ? <span>{n.body}</span> : null}\n                </div>\n                <div className=\"hb-za4-meta\">\n                  {n.time ? <span className=\"hb-za4-time\">{n.time}</span> : null}\n                  <button\n                    type=\"button\"\n                    className=\"hb-za4-x\"\n                    aria-label={`Dismiss ${n.title}`}\n                    tabIndex={open && !hidden ? 0 : -1}\n                    onClick={(e) => {\n                      e.stopPropagation();\n                      dismiss(n.id, 1);\n                    }}\n                  >\n                    <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                      <path d=\"m2.5 2.5 7 7M9.5 2.5l-7 7\" />\n                    </svg>\n                  </button>\n                </div>\n              </div>\n            </li>\n          );\n        })}\n      </ul>\n    </div>\n  );\n}\n"
    }
  ]
}