{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-sticky-stack",
  "type": "registry:component",
  "title": "Scroll Sticky Stack",
  "description": "Cards that stick to the top and pile on each other. Each card shrinks and dims a little as the next one slides over it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "sticky",
    "stack",
    "cards",
    "layers",
    "process"
  ],
  "docs": "https://hyperblur.dev/effects/scroll-sticky-stack",
  "files": [
    {
      "path": "registry/hyperblur/scroll-sticky-stack.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/scroll-sticky-stack.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ScrollStackCard {\n  title: string;\n  text: string;\n  tag?: string;\n  stat?: string;\n  from?: string;\n  to?: string;\n}\n\nexport interface ScrollStickyStackProps extends React.HTMLAttributes<HTMLDivElement> {\n  cards?: ScrollStackCard[];\n  top?: number;\n  gap?: number;\n  cardHeight?: number;\n  minScale?: number;\n  scroller?: React.RefObject<HTMLElement | null> | HTMLElement | null;\n  height?: number | string;\n  autoplay?: boolean;\n  accent?: string;\n}\n\ntype Scroller = React.RefObject<HTMLElement | null> | HTMLElement | null;\n\ninterface Frame {\n  sc: HTMLElement | null;\n  top: number;\n  vh: number;\n}\n\nconst defaultCards: ScrollStackCard[] = [\n  {\n    title: \"Discover\",\n    text: \"Interviews, audits and a clear brief before any pixel moves.\",\n    tag: \"Week 1\",\n    stat: \"12 interviews\",\n    from: \"#1e3a8a\",\n    to: \"#0f172a\",\n  },\n  {\n    title: \"Design\",\n    text: \"Flows, type and a component library the whole team shares.\",\n    tag: \"Weeks 2-4\",\n    stat: \"48 components\",\n    from: \"#6d28d9\",\n    to: \"#1e1b4b\",\n  },\n  {\n    title: \"Build\",\n    text: \"Small slices behind flags, tested on real devices.\",\n    tag: \"Weeks 5-9\",\n    stat: \"31 releases\",\n    from: \"#0f766e\",\n    to: \"#042f2e\",\n  },\n  {\n    title: \"Launch\",\n    text: \"A calm rollout with monitoring, docs and a clean handover.\",\n    tag: \"Week 10\",\n    stat: \"99.98% uptime\",\n    from: \"#b45309\",\n    to: \"#291304\",\n  },\n];\n\nconst css = `\n.hb-qm8 {\n  --hb-qm8-a: #2f7bff;\n  --hb-qm8-u: 100vh;\n  --hb-qm8-ch: 0.62;\n  --hb-qm8-top: 16px;\n  --hb-qm8-gap: 14px;\n  position: relative;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-qm8, .hb-qm8 * { box-sizing: border-box; }\n.hb-qm8-vp {\n  position: relative;\n  overflow-x: hidden;\n  overflow-y: auto;\n  overflow-anchor: none;\n  scrollbar-width: thin;\n  scrollbar-color: #2e2e2e transparent;\n  outline: none;\n}\n.hb-qm8-vp:focus-visible { outline: 2px solid var(--hb-qm8-a); outline-offset: -2px; }\n.hb-qm8-list { padding: 0 1em calc(var(--hb-qm8-u) * 0.14); }\n.hb-qm8-card {\n  --hb-qm8-s: 1;\n  --hb-qm8-d: 0;\n  position: sticky;\n  top: calc(var(--hb-qm8-top) + var(--hb-qm8-i) * var(--hb-qm8-gap));\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  height: calc(var(--hb-qm8-u) * var(--hb-qm8-ch));\n  min-height: 7.5em;\n  margin-bottom: calc(var(--hb-qm8-u) * 0.3);\n  padding: 1em 1.1em;\n  overflow: hidden;\n  border: 1px solid rgba(255, 255, 255, 0.12);\n  border-radius: 1.1em;\n  background: linear-gradient(150deg, var(--hb-qm8-f), var(--hb-qm8-t));\n  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.4);\n  transform: scale(var(--hb-qm8-s));\n  transform-origin: 50% 0;\n  will-change: transform;\n}\n.hb-qm8-card:last-child { margin-bottom: 0; }\n.hb-qm8-card::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: radial-gradient(80% 90% at 10% 0%, rgba(255, 255, 255, 0.2), transparent 60%);\n  pointer-events: none;\n}\n.hb-qm8-card::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: #000;\n  opacity: var(--hb-qm8-d);\n  pointer-events: none;\n}\n.hb-qm8-row {\n  position: relative;\n  z-index: 1;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 0.8em;\n}\n.hb-qm8-tag {\n  padding: 0.22em 0.7em;\n  border-radius: 999px;\n  background: rgba(10, 10, 10, 0.4);\n  font-size: 0.68em;\n  font-weight: 600;\n  letter-spacing: 0.05em;\n  color: #fff;\n}\n.hb-qm8-idx {\n  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n  font-size: 0.72em;\n  letter-spacing: 0.08em;\n  color: rgba(255, 255, 255, 0.6);\n}\n.hb-qm8-main { position: relative; z-index: 1; }\n.hb-qm8-title {\n  margin: 0;\n  font-size: 1.65em;\n  font-weight: 600;\n  line-height: 1.05;\n  letter-spacing: -0.02em;\n  color: #fff;\n}\n.hb-qm8-text {\n  max-width: 42ch;\n  margin: 0.4em 0 0;\n  font-size: 0.82em;\n  line-height: 1.45;\n  color: rgba(255, 255, 255, 0.72);\n}\n.hb-qm8-stat {\n  position: relative;\n  z-index: 1;\n  font-size: 0.72em;\n  font-weight: 600;\n  letter-spacing: 0.03em;\n  color: rgba(255, 255, 255, 0.86);\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qm8-card { transform: none; will-change: auto; }\n}\n`;\n\nfunction clamp(n: number) {\n  return Math.min(1, Math.max(0, n));\n}\n\nfunction pick(scroller: Scroller | undefined): HTMLElement | null {\n  if (!scroller) return null;\n  return \"current\" in scroller ? scroller.current : scroller;\n}\n\nfunction useScrollFrame(\n  rootRef: React.RefObject<HTMLElement | null>,\n  viewportRef: React.RefObject<HTMLElement | null>,\n  scroller: Scroller | undefined,\n  own: boolean,\n  unit: string,\n  onFrame: (frame: Frame) => void,\n) {\n  const latest = React.useRef(onFrame);\n\n  React.useEffect(() => {\n    latest.current = onFrame;\n  });\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const sc = own ? viewportRef.current : pick(scroller);\n    const host: HTMLElement | Window = sc ?? window;\n    const run = () => {\n      const top = sc ? sc.getBoundingClientRect().top : 0;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      if (sc && !own) root.style.setProperty(unit, `${vh}px`);\n      latest.current({ sc, top, vh });\n    };\n    host.addEventListener(\"scroll\", run, { passive: true });\n    window.addEventListener(\"resize\", run);\n    const ro = new ResizeObserver(run);\n    ro.observe(root);\n    if (sc) ro.observe(sc);\n    return () => {\n      host.removeEventListener(\"scroll\", run);\n      window.removeEventListener(\"resize\", run);\n      ro.disconnect();\n    };\n  }, [rootRef, viewportRef, scroller, own, unit]);\n}\n\nfunction useAutoScroll(viewportRef: React.RefObject<HTMLElement | null>, active: boolean) {\n  React.useEffect(() => {\n    const el = viewportRef.current;\n    if (!el || !active) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      el.scrollTop = (el.scrollHeight - el.clientHeight) * 0.45;\n      return;\n    }\n    let raf = 0;\n    let last = 0;\n    let pos = 0;\n    let dir = 1;\n    let hold = 700;\n    let idle = 0;\n    const touch = () => {\n      idle = performance.now() + 3200;\n    };\n    const tick = (now: number) => {\n      raf = requestAnimationFrame(tick);\n      const dt = Math.min(now - last, 50);\n      last = now;\n      const max = el.scrollHeight - el.clientHeight;\n      if (max <= 0) return;\n      if (now < idle) {\n        pos = el.scrollTop / max;\n        return;\n      }\n      if (hold > 0) {\n        hold -= dt;\n        return;\n      }\n      pos += (dir * dt) / 9000;\n      if (pos >= 1) {\n        pos = 1;\n        dir = -1;\n        hold = 900;\n      } else if (pos <= 0) {\n        pos = 0;\n        dir = 1;\n        hold = 900;\n      }\n      el.scrollTop = pos * max;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      if (entry.isIntersecting) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(tick);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    const events = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n    for (const name of events) el.addEventListener(name, touch, { passive: true });\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      for (const name of events) el.removeEventListener(name, touch);\n    };\n  }, [viewportRef, active]);\n}\n\nexport function ScrollStickyStack({\n  cards = defaultCards,\n  top = 16,\n  gap = 14,\n  cardHeight = 0.62,\n  minScale = 0.94,\n  scroller,\n  height,\n  autoplay = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: ScrollStickyStackProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const listRef = React.useRef<HTMLDivElement>(null);\n  const own = height !== undefined;\n  const n = cards.length;\n  const per = 1 - Math.min(1, Math.max(0.6, minScale));\n\n  useAutoScroll(viewportRef, own && autoplay);\n  useScrollFrame(rootRef, viewportRef, scroller, own, \"--hb-qm8-u\", ({ top: vTop }) => {\n    const list = listRef.current;\n    if (!list) return;\n    const els = list.children;\n    const arrive: number[] = [0];\n    for (let j = 1; j < els.length; j++) {\n      const prev = els[j - 1] as HTMLElement;\n      const next = els[j] as HTMLElement;\n      const startY = vTop + top + (j - 1) * gap + prev.offsetHeight;\n      const stuckY = vTop + top + j * gap;\n      const q = clamp((startY - next.getBoundingClientRect().top) / Math.max(1, startY - stuckY));\n      arrive.push(q);\n    }\n    for (let i = 0; i < els.length; i++) {\n      let sum = 0;\n      for (let j = i + 1; j < els.length; j++) sum += arrive[j];\n      const el = els[i] as HTMLElement;\n      el.style.setProperty(\"--hb-qm8-s\", (1 - per * sum).toFixed(4));\n      el.style.setProperty(\"--hb-qm8-d\", Math.min(0.5, sum * 0.16).toFixed(4));\n    }\n  });\n\n  const body = (\n    <div ref={listRef} className=\"hb-qm8-list\">\n      {cards.map((card, i) => (\n        <article\n          key={i}\n          className=\"hb-qm8-card\"\n          style={\n            {\n              \"--hb-qm8-i\": i,\n              \"--hb-qm8-f\": card.from ?? \"#1e3a8a\",\n              \"--hb-qm8-t\": card.to ?? \"#0f172a\",\n            } as React.CSSProperties\n          }\n        >\n          <div className=\"hb-qm8-row\">\n            {card.tag ? <span className=\"hb-qm8-tag\">{card.tag}</span> : <span />}\n            <span className=\"hb-qm8-idx\">\n              {String(i + 1).padStart(2, \"0\")} / {String(n).padStart(2, \"0\")}\n            </span>\n          </div>\n          <div className=\"hb-qm8-main\">\n            <h3 className=\"hb-qm8-title\">{card.title}</h3>\n            <p className=\"hb-qm8-text\">{card.text}</p>\n          </div>\n          {card.stat ? <span className=\"hb-qm8-stat\">{card.stat}</span> : <span />}\n        </article>\n      ))}\n    </div>\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-qm8 ${className}`.trim()}\n      style={\n        {\n          \"--hb-qm8-a\": accent,\n          \"--hb-qm8-top\": `${top}px`,\n          \"--hb-qm8-gap\": `${gap}px`,\n          \"--hb-qm8-ch\": Math.min(1, Math.max(0.2, cardHeight)),\n          ...(own ? { \"--hb-qm8-u\": typeof height === \"number\" ? `${height}px` : height } : null),\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-scroll-sticky-stack\" precedence=\"default\">\n        {css}\n      </style>\n      {own ? (\n        <div\n          ref={viewportRef}\n          className=\"hb-qm8-vp\"\n          style={{ height }}\n          tabIndex={0}\n          role=\"region\"\n          aria-label=\"Scrollable content\"\n        >\n          {body}\n        </div>\n      ) : (\n        body\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}