{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"helix-cards","type":"registry:ui","title":"Helix Cards","description":"Cards wound around an endless 3D helix that keeps turning, and spins faster when you scroll or drag.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/helix-cards.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface HelixCardsProps {\n  images: string[];\n  /** Cards on the spiral; images repeat to fill it. */\n  count?: number;\n  /** Spiral radius in px. */\n  radius?: number;\n  /** Degrees between neighbouring cards. */\n  step?: number;\n  /** Vertical px between neighbouring cards. */\n  pitch?: number;\n  /** Card width in px. */\n  cardWidth?: number;\n  /** Idle rotation in cards per second (negative spins the other way). */\n  speed?: number;\n  className?: string;\n}\n\nexport function HelixCards({\n  images,\n  count = 30,\n  radius = 300,\n  step = 30,\n  pitch = 30,\n  cardWidth = 150,\n  speed = 0.8,\n  className,\n}: HelixCardsProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const cardRefs = useRef<(HTMLDivElement | null)[]>([]);\n  const n = Math.max(images.length, Math.round(count));\n  const cfg = useRef({ radius, step, pitch, speed, cardWidth });\n  useEffect(() => {\n    cfg.current = { radius, step, pitch, speed, cardWidth };\n  }, [radius, step, pitch, speed, cardWidth]);\n\n  useEffect(() => {\n    const root = rootRef.current!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let offset = 0;\n    let vel = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let drag: { x: number; y: number; t: number } | null = null;\n\n    const render = () => {\n      const { radius: R, step: st, pitch: pt, cardWidth: cw } = cfg.current;\n      const h = root.clientHeight;\n      const edge = h / 2 + cw * 0.35;\n      for (let i = 0; i < n; i++) {\n        const el = cardRefs.current[i];\n        if (!el) continue;\n        const s = ((((i + offset) % n) + n) % n) - n / 2; // wrapped slot, -n/2..n/2\n        const a = (s * st * Math.PI) / 180;\n        const x = Math.sin(a) * R;\n        const z = Math.cos(a) * R;\n        const y = -s * pt;\n        const fade = Math.max(0, Math.min(1, (edge - Math.abs(y)) / (cw * 0.6)));\n        const facing = (Math.cos(a) + 1) / 2; // 1 = facing viewer, 0 = far side\n        el.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateY(${(a * 180) / Math.PI}deg)`;\n        el.style.opacity = String(fade * (0.25 + facing * 0.75));\n        el.style.filter = `brightness(${(0.35 + facing * 0.65).toFixed(2)})`;\n        el.style.zIndex = String(Math.round(z) + 1000);\n        el.style.visibility = fade <= 0 ? \"hidden\" : \"visible\";\n      }\n    };\n\n    const tick = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      if (!drag) {\n        offset += (vel + (reduced ? 0 : cfg.current.speed)) * dt;\n        vel *= Math.exp(-dt * 2);\n      }\n      render();\n      raf = visible ? requestAnimationFrame(tick) : 0;\n    };\n    const start = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(tick);\n    };\n\n    const unit = () => cfg.current.pitch * 1.6; // px of drag per card\n    const onWheel = (e: WheelEvent) => {\n      e.preventDefault();\n      const d = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;\n      vel = Math.max(-30, Math.min(30, vel + (d * (e.deltaMode === 1 ? 16 : 1)) / 60));\n    };\n    const onDown = (e: PointerEvent) => {\n      root.setPointerCapture(e.pointerId);\n      drag = { x: e.clientX, y: e.clientY, t: performance.now() };\n      vel = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      if (!drag) return;\n      const now = performance.now();\n      // Dragging left or up winds the spiral forward.\n      const d = (drag.x - e.clientX + (drag.y - e.clientY)) / unit();\n      offset += d;\n      vel = (d / Math.max(1, now - drag.t)) * 1000 * 0.6;\n      drag = { x: e.clientX, y: e.clientY, t: now };\n    };\n    const onUp = () => {\n      drag = null;\n    };\n    const onKey = (e: KeyboardEvent) => {\n      const d = e.key === \"ArrowUp\" || e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowDown\" || e.key === \"ArrowLeft\" ? -1 : 0;\n      if (!d) return;\n      e.preventDefault();\n      vel += d * 4;\n    };\n\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(root);\n    root.addEventListener(\"wheel\", onWheel, { passive: false });\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"pointercancel\", onUp);\n    root.addEventListener(\"keydown\", onKey);\n    render();\n    start();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      root.removeEventListener(\"wheel\", onWheel);\n      root.removeEventListener(\"pointerdown\", onDown);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"pointercancel\", onUp);\n      root.removeEventListener(\"keydown\", onKey);\n    };\n  }, [n]);\n\n  const cardHeight = cardWidth * 0.68;\n\n  return (\n    <div\n      ref={rootRef}\n      tabIndex={0}\n      role=\"region\"\n      aria-roledescription=\"spiral gallery\"\n      aria-label=\"Spiral gallery. Scroll, drag or use the arrow keys to spin.\"\n      className={cn(\n        \"relative h-full w-full cursor-grab touch-none select-none overflow-hidden outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring active:cursor-grabbing\",\n        className,\n      )}\n      style={{ perspective: 1400 }}\n    >\n      <div className=\"absolute left-1/2 top-1/2\" style={{ transformStyle: \"preserve-3d\", transform: \"rotateX(-8deg) rotateZ(-6deg)\" }}>\n        {Array.from({ length: n }, (_, i) => (\n          <div\n            key={i}\n            ref={(el) => {\n              cardRefs.current[i] = el;\n            }}\n            className=\"absolute overflow-hidden rounded-xl bg-muted shadow-[0_20px_40px_-12px_rgba(0,0,0,.6)] ring-1 ring-white/10 will-change-transform\"\n            style={{ width: cardWidth, height: cardHeight, left: -cardWidth / 2, top: -cardHeight / 2, visibility: \"hidden\" }}\n          >\n            {/* eslint-disable-next-line @next/next/no-img-element */}\n            <img src={images[i % images.length]} alt=\"\" draggable={false} className=\"size-full object-cover\" />\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"}]}