{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-infinite-spiral",
  "type": "registry:component",
  "title": "Gallery Infinite Spiral",
  "description": "Images laid out along a spiral that drifts forever, growing and brightening as they leave the center. Drag, scroll or use the arrow keys to move along it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "gallery",
    "spiral",
    "infinite",
    "drag",
    "scroll",
    "images"
  ],
  "docs": "https://hyperblur.dev/effects/gallery-infinite-spiral",
  "files": [
    {
      "path": "registry/hyperblur/gallery-infinite-spiral.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/gallery-infinite-spiral.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SpiralImage {\n  src?: string;\n  label?: string;\n  alt?: string;\n}\n\nexport interface GalleryInfiniteSpiralProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  images?: SpiralImage[];\n  drift?: number;\n  turns?: number;\n  wheel?: boolean;\n  accent?: string;\n  itemRatio?: number;\n  label?: string;\n}\n\nconst defaultImages: SpiralImage[] = [\n  { label: \"Dune\" },\n  { label: \"Fjord\" },\n  { label: \"Lagoon\" },\n  { label: \"Summit\" },\n  { label: \"Meadow\" },\n  { label: \"Canyon\" },\n  { label: \"Glacier\" },\n  { label: \"Harbor\" },\n  { label: \"Savanna\" },\n  { label: \"Tundra\" },\n  { label: \"Orchard\" },\n  { label: \"Mesa\" },\n];\n\nconst css = `\n.hb-qu1 {\n  --hb-qu1-a: #2f7bff;\n  --hb-qu1-r: 0.78;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 180px;\n  overflow: hidden;\n  container-type: size;\n  font-family: inherit;\n  color: #ededed;\n  background:\n    radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--hb-qu1-a) 22%, transparent) 0%, transparent 38%),\n    #0a0a0a;\n  cursor: grab;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: pan-y;\n}\n.hb-qu1 *, .hb-qu1 *::before, .hb-qu1 *::after { box-sizing: border-box; }\n.hb-qu1[data-drag=\"true\"] { cursor: grabbing; }\n.hb-qu1:focus-visible { outline: 2px solid var(--hb-qu1-a); outline-offset: -2px; }\n.hb-qu1-guide {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  pointer-events: none;\n}\n.hb-qu1-guide path {\n  fill: none;\n  stroke: color-mix(in srgb, var(--hb-qu1-a) 45%, transparent);\n  stroke-width: 1;\n  stroke-dasharray: 2 5;\n  vector-effect: non-scaling-stroke;\n}\n.hb-qu1-item {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  height: 40cqh;\n  width: calc(40cqh * var(--hb-qu1-r));\n  overflow: hidden;\n  border-radius: 10px;\n  background: #111111;\n  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.1);\n  will-change: transform, opacity;\n}\n.hb-qu1-img {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  object-fit: cover;\n  background-size: cover;\n  background-position: center;\n  pointer-events: none;\n  -webkit-user-drag: none;\n}\n.hb-qu1-art { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }\n.hb-qu1-cap {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  padding: 16px 8px 6px;\n  font-size: 11px;\n  font-weight: 600;\n  line-height: 1;\n  letter-spacing: 0.02em;\n  color: #ffffff;\n  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);\n  pointer-events: none;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qu1-item { will-change: auto; }\n}\n`;\n\nfunction hash(n: number) {\n  let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);\n  h ^= h >>> 13;\n  h = Math.imul(h, 0xc2b2ae35);\n  h ^= h >>> 16;\n  return h >>> 0;\n}\n\nfunction sceneBackground(i: number) {\n  const h = (i * 47 + 196) % 360;\n  const h2 = (h + 48) % 360;\n  return `linear-gradient(165deg, hsl(${h} 70% 56%) 0%, hsl(${h2} 78% 46%) 55%, hsl(${(h2 + 40) % 360} 60% 22%) 100%)`;\n}\n\nfunction Scene({ index }: { index: number }) {\n  const a = hash(index);\n  const b = hash(index + 101);\n  const sunX = 20 + (a % 60);\n  const sunY = 18 + (b % 18);\n  const p1 = 52 + (a % 14);\n  const p2 = 34 + (b % 14);\n  const peak1 = 30 + (a % 40);\n  const peak2 = 50 + (b % 40);\n  const hue = (index * 47 + 196) % 360;\n  return (\n    <svg className=\"hb-qu1-art\" viewBox=\"0 0 100 130\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n      <circle cx={sunX} cy={sunY} r=\"9\" fill={`hsl(${(hue + 30) % 360} 95% 88%)`} opacity=\"0.9\" />\n      <polygon\n        points={`0,130 0,${p1} ${peak1},${p1 - 22} 100,${p1 + 6} 100,130`}\n        fill={`hsl(${hue} 55% 28%)`}\n        opacity=\"0.78\"\n      />\n      <polygon\n        points={`0,130 0,${p2 + 50} ${peak2},${p2 + 20} 100,${p2 + 54} 100,130`}\n        fill={`hsl(${hue} 50% 14%)`}\n        opacity=\"0.9\"\n      />\n    </svg>\n  );\n}\n\nfunction place(i: number, n: number, t: number, turns: number) {\n  const d = ((((i - t) % n) + n) % n) / n;\n  const rho = 0.04 + 0.96 * Math.pow(1 - d, 0.85);\n  const th = -1.2 + d * turns * Math.PI * 2;\n  const x = 36 * rho * Math.cos(th);\n  const y = 30 * rho * Math.sin(th);\n  const s = 0.16 + 0.84 * Math.pow(1 - d, 1.15);\n  const fadeIn = Math.min(1, d / 0.08);\n  const fadeOut = Math.min(1, (1 - d) / 0.08);\n  const o = (1 - 0.8 * Math.pow(d, 1.4)) * fadeIn * fadeOut;\n  return {\n    transform: `translate(calc(-50% + ${x.toFixed(3)}cqw), calc(-50% + ${y.toFixed(3)}cqh)) scale(${s.toFixed(4)})`,\n    opacity: o.toFixed(3),\n    zIndex: Math.round((1 - d) * 100),\n  };\n}\n\nfunction guidePath(turns: number) {\n  const pts: string[] = [];\n  for (let k = 0; k <= 80; k++) {\n    const d = k / 80;\n    const rho = 0.04 + 0.96 * Math.pow(1 - d, 0.85);\n    const th = -1.2 + d * turns * Math.PI * 2;\n    const x = 50 + 36 * rho * Math.cos(th);\n    const y = 50 + 30 * rho * Math.sin(th);\n    pts.push(`${k === 0 ? \"M\" : \"L\"}${x.toFixed(2)} ${y.toFixed(2)}`);\n  }\n  return pts.join(\" \");\n}\n\nexport function GalleryInfiniteSpiral({\n  images = defaultImages,\n  drift = 0.3,\n  turns = 1.5,\n  wheel = true,\n  accent = \"#2f7bff\",\n  itemRatio = 0.78,\n  label = \"Spiral gallery\",\n  className = \"\",\n  style,\n  ...rest\n}: GalleryInfiniteSpiralProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const itemEls = React.useRef<(HTMLDivElement | null)[]>([]);\n  const pos = React.useRef(0);\n  const n = images.length;\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root || n === 0) return;\n    const els = itemEls.current;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const s = {\n      vx: 0,\n      pending: 0,\n      gain: reduce ? 0 : 1,\n      hover: false,\n      focus: false,\n      drag: false,\n      lastX: 0,\n      lastT: 0,\n      v: 0,\n      prev: 0,\n      raf: 0,\n      running: false,\n    };\n\n    function apply() {\n      for (let i = 0; i < n; i++) {\n        const el = els[i];\n        if (!el) continue;\n        const p = place(i, n, pos.current, turns);\n        el.style.transform = p.transform;\n        el.style.opacity = p.opacity;\n        el.style.zIndex = String(p.zIndex);\n      }\n    }\n\n    function tick(now: number) {\n      const dt = Math.min(0.05, Math.max(0, (now - s.prev) / 1000));\n      s.prev = now;\n      const target = s.hover || s.focus || s.drag ? 0 : 1;\n      s.gain += (target - s.gain) * (1 - Math.exp(-dt * 4));\n      if (!s.drag) {\n        pos.current += (s.vx + drift * s.gain) * dt;\n        s.vx *= Math.exp(-dt * 2.6);\n        const mv = s.pending * (1 - Math.exp(-dt * 9));\n        pos.current += mv;\n        s.pending -= mv;\n      }\n      pos.current = ((pos.current % n) + n) % n;\n      apply();\n      s.raf = requestAnimationFrame(tick);\n    }\n\n    function start() {\n      if (s.running || reduce) return;\n      s.running = true;\n      s.prev = performance.now();\n      s.raf = requestAnimationFrame(tick);\n    }\n\n    function stop() {\n      s.running = false;\n      cancelAnimationFrame(s.raf);\n    }\n\n    function nudge(by: number) {\n      if (reduce) {\n        pos.current += by;\n        apply();\n      } else {\n        s.pending += by;\n      }\n    }\n\n    function pxPerItem() {\n      return Math.max(48, root!.clientWidth * 0.2);\n    }\n\n    function onDown(e: PointerEvent) {\n      if (e.pointerType === \"mouse\" && e.button !== 0) return;\n      s.drag = true;\n      s.v = 0;\n      s.vx = 0;\n      s.lastX = e.clientX;\n      s.lastT = e.timeStamp;\n      root!.dataset.drag = \"true\";\n      root!.setPointerCapture(e.pointerId);\n    }\n\n    function onMove(e: PointerEvent) {\n      if (!s.drag) return;\n      const dx = e.clientX - s.lastX;\n      const dtm = Math.max(0.001, (e.timeStamp - s.lastT) / 1000);\n      const step = -dx / pxPerItem();\n      pos.current += step;\n      s.v = s.v * 0.7 + (step / dtm) * 0.3;\n      s.lastX = e.clientX;\n      s.lastT = e.timeStamp;\n      if (reduce) apply();\n    }\n\n    function onUp(e: PointerEvent) {\n      if (!s.drag) return;\n      s.drag = false;\n      root!.dataset.drag = \"false\";\n      if (root!.hasPointerCapture(e.pointerId)) root!.releasePointerCapture(e.pointerId);\n      if (!reduce) s.vx = Math.max(-6, Math.min(6, s.v));\n    }\n\n    function onWheel(e: WheelEvent) {\n      e.preventDefault();\n      nudge(Math.max(-3, Math.min(3, e.deltaY / 140)));\n    }\n\n    function onKey(e: KeyboardEvent) {\n      if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n        e.preventDefault();\n        nudge(1);\n      } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n        e.preventDefault();\n        nudge(-1);\n      }\n    }\n\n    function onEnter(e: PointerEvent) {\n      if (e.pointerType === \"mouse\") s.hover = true;\n    }\n    function onLeave() {\n      s.hover = false;\n    }\n    function onFocusIn() {\n      s.focus = true;\n    }\n    function onFocusOut() {\n      s.focus = false;\n    }\n\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"pointercancel\", onUp);\n    root.addEventListener(\"pointerenter\", onEnter);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"focusin\", onFocusIn);\n    root.addEventListener(\"focusout\", onFocusOut);\n    root.addEventListener(\"keydown\", onKey);\n    if (wheel) root.addEventListener(\"wheel\", onWheel, { passive: false });\n\n    apply();\n    const io = new IntersectionObserver((entries) => {\n      for (const entry of entries) {\n        if (entry.isIntersecting) start();\n        else stop();\n      }\n    });\n    io.observe(root);\n\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointerdown\", onDown);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"pointercancel\", onUp);\n      root.removeEventListener(\"pointerenter\", onEnter);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n      root.removeEventListener(\"keydown\", onKey);\n      if (wheel) root.removeEventListener(\"wheel\", onWheel);\n    };\n  }, [n, turns, drift, wheel]);\n\n  const vars = {\n    \"--hb-qu1-a\": accent,\n    \"--hb-qu1-r\": String(itemRatio),\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-gallery-infinite-spiral\" precedence=\"default\">{css}</style>\n      <div\n        ref={rootRef}\n        role=\"group\"\n        aria-roledescription=\"spiral gallery\"\n        aria-label={label}\n        tabIndex={0}\n        data-drag=\"false\"\n        className={`hb-qu1 ${className}`}\n        style={vars}\n        {...rest}\n      >\n        <svg className=\"hb-qu1-guide\" viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" aria-hidden=\"true\">\n          <path d={guidePath(turns)} />\n        </svg>\n        {images.map((img, i) => {\n          const p = place(i, n, 0, turns);\n          return (\n            <div\n              key={i}\n              ref={(el) => {\n                itemEls.current[i] = el;\n              }}\n              className=\"hb-qu1-item\"\n              role=\"img\"\n              aria-label={img.alt ?? img.label ?? `Image ${i + 1}`}\n              style={{ transform: p.transform, opacity: p.opacity, zIndex: p.zIndex }}\n            >\n              {img.src ? (\n                <div className=\"hb-qu1-img\" style={{ backgroundImage: `url(\"${img.src}\")` }} />\n              ) : (\n                <>\n                  <div className=\"hb-qu1-img\" style={{ background: sceneBackground(i) }} />\n                  <Scene index={i} />\n                </>\n              )}\n              {img.label ? <div className=\"hb-qu1-cap\">{img.label}</div> : null}\n            </div>\n          );\n        })}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}