{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-pin-steps",
  "type": "registry:component",
  "title": "Scroll Pin Steps",
  "description": "A pinned stage that swaps its content step by step as you scroll, with clickable step dots and a progress line.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "pinned",
    "sticky",
    "steps",
    "storytelling",
    "stepper"
  ],
  "docs": "https://hyperblur.dev/effects/scroll-pin-steps",
  "files": [
    {
      "path": "registry/hyperblur/scroll-pin-steps.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/scroll-pin-steps.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ScrollPinStep {\n  title: string;\n  text: string;\n  visual?: React.ReactNode;\n}\n\nexport interface ScrollPinStepsProps extends React.HTMLAttributes<HTMLDivElement> {\n  steps?: ScrollPinStep[];\n  scroller?: React.RefObject<HTMLElement | null> | HTMLElement | null;\n  height?: number | string;\n  autoplay?: boolean;\n  accent?: string;\n  stepLength?: number;\n  onStepChange?: (index: number) => void;\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 defaultSteps: ScrollPinStep[] = [\n  {\n    title: \"Capture\",\n    text: \"Drop in notes, links and files from anywhere. Everything lands in one inbox.\",\n  },\n  {\n    title: \"Organize\",\n    text: \"Smart folders sort the pile by project, person and date without any tagging.\",\n  },\n  {\n    title: \"Share\",\n    text: \"Send a live page to the team. Edits sync for everyone as they happen.\",\n  },\n  {\n    title: \"Review\",\n    text: \"A weekly digest shows what moved forward and what is still stuck.\",\n  },\n];\n\nconst icons = [\n  \"M12 2.5 3 7.5l9 5 9-5-9-5ZM3 12l9 5 9-5M3 16.5l9 5 9-5\",\n  \"M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12L13 2Z\",\n  \"M18 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM6 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM18 22a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM8.6 13.5l6.8 4M15.4 6.5l-6.8 4\",\n  \"M4 12.5 9.5 18 20 6.5\",\n];\n\nconst css = `\n.hb-qm3 {\n  --hb-qm3-a: #2f7bff;\n  --hb-qm3-p: 0;\n  --hb-qm3-u: 100vh;\n  position: relative;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-qm3, .hb-qm3 * { box-sizing: border-box; }\n.hb-qm3-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-qm3-vp:focus-visible { outline: 2px solid var(--hb-qm3-a); outline-offset: -2px; }\n.hb-qm3-track { position: relative; width: 100%; }\n.hb-qm3-stage {\n  position: sticky;\n  top: 0;\n  height: var(--hb-qm3-u);\n  overflow: hidden;\n  container-type: inline-size;\n  background: var(--hb-qm3-bg, #0a0a0a);\n}\n.hb-qm3-body {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) auto;\n  align-items: center;\n  column-gap: 1.3em;\n  height: 100%;\n  padding: 1.4em 1.5em 3em;\n}\n.hb-qm3-copy { display: grid; min-width: 0; }\n.hb-qm3-item {\n  grid-area: 1 / 1;\n  align-self: center;\n  opacity: 0;\n  transform: translate3d(0, 16px, 0);\n  transition: opacity 0.45s ease, transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);\n  pointer-events: none;\n}\n.hb-qm3-item[data-state=\"past\"] { transform: translate3d(0, -16px, 0); }\n.hb-qm3-item[data-state=\"on\"] { opacity: 1; transform: none; pointer-events: auto; }\n.hb-qm3-num {\n  display: block;\n  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n  font-size: 0.72em;\n  font-weight: 600;\n  letter-spacing: 0.08em;\n  line-height: 1;\n  color: color-mix(in srgb, var(--hb-qm3-a) 70%, #fff);\n}\n.hb-qm3-title {\n  margin: 0.55em 0 0.4em;\n  font-size: 1.75em;\n  font-weight: 600;\n  line-height: 1.08;\n  letter-spacing: -0.02em;\n  color: #f4f4f4;\n}\n.hb-qm3-text {\n  max-width: 32ch;\n  margin: 0;\n  font-size: 0.9em;\n  line-height: 1.5;\n  color: #a1a1a1;\n}\n.hb-qm3-art {\n  display: grid;\n  width: clamp(5.5em, 34cqw, 16em);\n  aspect-ratio: 1;\n}\n.hb-qm3-panel {\n  grid-area: 1 / 1;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 0.95em;\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 1.1em;\n  background: radial-gradient(120% 100% at 30% 0%, color-mix(in srgb, var(--hb-qm3-a) 26%, #111111) 0%, #0f0f0f 70%);\n  opacity: 0;\n  transform: scale(0.9) translate3d(0, 10px, 0);\n  transition: opacity 0.45s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-qm3-panel[data-on=\"true\"] { opacity: 1; transform: none; }\n.hb-qm3-plate {\n  display: grid;\n  place-items: center;\n  width: 3.4em;\n  height: 3.4em;\n  border: 1px solid color-mix(in srgb, var(--hb-qm3-a) 45%, #262626);\n  border-radius: 1em;\n  background: color-mix(in srgb, var(--hb-qm3-a) 22%, #141414);\n  filter: hue-rotate(var(--hb-qm3-h, 0deg));\n}\n.hb-qm3-plate svg {\n  width: 1.7em;\n  height: 1.7em;\n  fill: none;\n  stroke: color-mix(in srgb, var(--hb-qm3-a) 60%, #fff);\n  stroke-width: 1.7;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qm3-bars { display: grid; gap: 0.38em; width: 62%; }\n.hb-qm3-bars i {\n  display: block;\n  height: 0.3em;\n  border-radius: 999px;\n  background: rgba(255, 255, 255, 0.12);\n}\n.hb-qm3-bars i:first-child { background: color-mix(in srgb, var(--hb-qm3-a) 55%, transparent); }\n.hb-qm3-dots {\n  position: absolute;\n  left: 1.7em;\n  bottom: 1.15em;\n  z-index: 2;\n  display: flex;\n  align-items: center;\n  gap: 0.45em;\n}\n.hb-qm3-dot {\n  position: relative;\n  appearance: none;\n  width: 0.45em;\n  height: 0.45em;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 999px;\n  background: #3a3a3a;\n  cursor: pointer;\n  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.3s ease;\n}\n.hb-qm3-dot::after { content: \"\"; position: absolute; inset: -0.7em -0.3em; }\n.hb-qm3-dot[aria-current=\"step\"] { width: 1.7em; background: var(--hb-qm3-a); }\n.hb-qm3-dot:focus-visible { outline: 2px solid var(--hb-qm3-a); outline-offset: 3px; }\n.hb-qm3-line {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  height: 2px;\n  background: rgba(255, 255, 255, 0.06);\n}\n.hb-qm3-line::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: var(--hb-qm3-a);\n  transform: scaleX(var(--hb-qm3-p));\n  transform-origin: left center;\n}\n@container (max-width: 260px) {\n  .hb-qm3-body { grid-template-columns: minmax(0, 1fr); }\n  .hb-qm3-art { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qm3-item, .hb-qm3-panel, .hb-qm3-dot { transition: none; }\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 ScrollPinSteps({\n  steps = defaultSteps,\n  scroller,\n  height,\n  autoplay = false,\n  accent = \"#2f7bff\",\n  stepLength = 0.9,\n  onStepChange,\n  className = \"\",\n  style,\n  ...rest\n}: ScrollPinStepsProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const lastStep = React.useRef(0);\n  const changeRef = React.useRef(onStepChange);\n  const [active, setActive] = React.useState(0);\n  const own = height !== undefined;\n  const n = Math.max(1, steps.length);\n\n  React.useEffect(() => {\n    changeRef.current = onStepChange;\n  });\n\n  useAutoScroll(viewportRef, own && autoplay);\n  useScrollFrame(rootRef, viewportRef, scroller, own, \"--hb-qm3-u\", ({ top, vh }) => {\n    const track = trackRef.current;\n    if (!track) return;\n    const rect = track.getBoundingClientRect();\n    const span = rect.height - vh;\n    const p = span > 0 ? clamp((top - rect.top) / span) : 0;\n    rootRef.current?.style.setProperty(\"--hb-qm3-p\", p.toFixed(4));\n    const idx = Math.min(n - 1, Math.floor(p * n));\n    if (idx !== lastStep.current) {\n      lastStep.current = idx;\n      setActive(idx);\n      changeRef.current?.(idx);\n    }\n  });\n\n  const goTo = (i: number) => {\n    const track = trackRef.current;\n    if (!track) return;\n    const sc = own ? viewportRef.current : pick(scroller);\n    const vh = sc ? sc.clientHeight : window.innerHeight;\n    const top = sc ? sc.getBoundingClientRect().top : 0;\n    const rect = track.getBoundingClientRect();\n    const span = rect.height - vh;\n    const base = (sc ? sc.scrollTop : window.scrollY) + rect.top - top;\n    const target = base + span * ((i + 0.5) / n);\n    const behavior: ScrollBehavior = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n      ? \"auto\"\n      : \"smooth\";\n    if (sc) sc.scrollTo({ top: target, behavior });\n    else window.scrollTo({ top: target, behavior });\n  };\n\n  const pad = (v: number) => String(v).padStart(2, \"0\");\n\n  const body = (\n    <div\n      ref={trackRef}\n      className=\"hb-qm3-track\"\n      style={{ height: `calc(var(--hb-qm3-u) * ${(1 + n * stepLength).toFixed(3)})` }}\n    >\n      <div className=\"hb-qm3-stage\">\n        <div className=\"hb-qm3-body\">\n          <div className=\"hb-qm3-copy\">\n            {steps.map((step, i) => (\n              <div\n                key={i}\n                className=\"hb-qm3-item\"\n                data-state={i === active ? \"on\" : i < active ? \"past\" : \"next\"}\n                aria-hidden={i === active ? undefined : true}\n              >\n                <span className=\"hb-qm3-num\">\n                  {pad(i + 1)} / {pad(n)}\n                </span>\n                <h3 className=\"hb-qm3-title\">{step.title}</h3>\n                <p className=\"hb-qm3-text\">{step.text}</p>\n              </div>\n            ))}\n          </div>\n          <div className=\"hb-qm3-art\" aria-hidden=\"true\">\n            {steps.map((step, i) => (\n              <div key={i} className=\"hb-qm3-panel\" data-on={i === active}>\n                {step.visual ?? (\n                  <>\n                    <div className=\"hb-qm3-plate\" style={{ \"--hb-qm3-h\": `${i * 34}deg` } as React.CSSProperties}>\n                      <svg viewBox=\"0 0 24 24\">\n                        <path d={icons[i % icons.length]} />\n                      </svg>\n                    </div>\n                    <div className=\"hb-qm3-bars\">\n                      <i style={{ width: `${46 + ((i * 17) % 40)}%` }} />\n                      <i style={{ width: `${82 - ((i * 13) % 30)}%` }} />\n                      <i style={{ width: `${56 + ((i * 23) % 36)}%` }} />\n                    </div>\n                  </>\n                )}\n              </div>\n            ))}\n          </div>\n        </div>\n        <div className=\"hb-qm3-dots\">\n          {steps.map((step, i) => (\n            <button\n              key={i}\n              type=\"button\"\n              className=\"hb-qm3-dot\"\n              aria-label={`Step ${i + 1}: ${step.title}`}\n              aria-current={i === active ? \"step\" : undefined}\n              onClick={() => goTo(i)}\n            />\n          ))}\n        </div>\n        <div className=\"hb-qm3-line\" aria-hidden=\"true\" />\n      </div>\n    </div>\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-qm3 ${className}`.trim()}\n      style={\n        {\n          \"--hb-qm3-a\": accent,\n          ...(own ? { \"--hb-qm3-u\": typeof height === \"number\" ? `${height}px` : height } : null),\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-scroll-pin-steps\" precedence=\"default\">\n        {css}\n      </style>\n      {own ? (\n        <div\n          ref={viewportRef}\n          className=\"hb-qm3-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"
    }
  ]
}