{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-photo-snake",
  "type": "registry:component",
  "title": "Photo Snake",
  "description": "A chain of instant-photo frames that follows the pointer like a snake: each frame chases the one ahead on a fixed link, leans into the motion and coils into a neat pile when the pointer rests.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "trail",
    "photos",
    "chain",
    "follow",
    "gallery"
  ],
  "docs": "https://hyperblur.dev/effects/hover-photo-snake",
  "files": [
    {
      "path": "registry/hyperblur/hover-photo-snake.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-photo-snake.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverPhotoSnakeFrame {\n  caption: string;\n  background?: string;\n}\n\nexport interface HoverPhotoSnakeProps extends React.HTMLAttributes<HTMLDivElement> {\n  frames?: HoverPhotoSnakeFrame[];\n  size?: number;\n  gap?: number;\n  follow?: number;\n  autoPlay?: boolean;\n  showCaptions?: boolean;\n}\n\nconst defaults: HoverPhotoSnakeFrame[] = [\n  { caption: \"Lisbon 06:12\", background: \"radial-gradient(circle at 68% 30%, #ffe6b0 0 10%, transparent 11%), linear-gradient(180deg, #ffb07a 0%, #e0607a 55%, #3b1e4a 100%)\" },\n  { caption: \"Faroe 09:40\", background: \"linear-gradient(165deg, transparent 58%, #1d3b2c 59%), linear-gradient(195deg, transparent 50%, #2f5a3f 51%), linear-gradient(180deg, #c9dde6 0%, #7da3b5 100%)\" },\n  { caption: \"Kyoto 17:05\", background: \"radial-gradient(70% 45% at 50% 100%, #2a1530 0%, transparent 70%), repeating-linear-gradient(90deg, transparent 0 14px, rgba(40,10,20,.55) 14px 16px), linear-gradient(180deg, #ff8f5a 0%, #c43d55 70%, #2a1530 100%)\" },\n  { caption: \"Atacama 22:30\", background: \"radial-gradient(1px 1px at 20% 30%, #fff, transparent), radial-gradient(1px 1px at 70% 20%, #fff, transparent), radial-gradient(1.5px 1.5px at 45% 55%, #fff, transparent), radial-gradient(80% 50% at 60% 40%, rgba(140,120,255,.45), transparent 70%), linear-gradient(180deg, #0a1030 0%, #1c2350 70%, #3a2a3f 100%)\" },\n  { caption: \"Reykjavik 01:14\", background: \"radial-gradient(90% 40% at 30% 35%, rgba(90,255,190,.7), transparent 70%), radial-gradient(60% 30% at 70% 25%, rgba(120,140,255,.55), transparent 70%), linear-gradient(180deg, #061428 0%, #0d2440 80%, #10161f 100%)\" },\n  { caption: \"Marrakesh 13:50\", background: \"linear-gradient(0deg, #b45a2c 0 26%, transparent 26%), repeating-linear-gradient(90deg, #d98a4f 0 18px, #c2703a 18px 20px), linear-gradient(180deg, #f6d6a4 0%, #e3a062 100%)\" },\n  { caption: \"Oslo 08:02\", background: \"linear-gradient(180deg, transparent 62%, #0f2a3a 62%), radial-gradient(circle at 30% 40%, #f1f5f8 0 18%, transparent 19%), linear-gradient(180deg, #a8c8de 0%, #e3eef5 100%)\" },\n];\n\nconst css = `\n.hb-wg2 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; touch-action: pan-y; }\n.hb-wg2 *, .hb-wg2 *::before, .hb-wg2 *::after { box-sizing: border-box; }\n.hb-wg2-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n.hb-wg2-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }\n.hb-wg2-frame { position: absolute; left: 0; top: 0; border-radius: 9px; padding: 3px 3px 15px; background: #f4f1ea; box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 14px 24px -10px rgba(0,0,0,.75), 0 2px 5px rgba(0,0,0,.45); will-change: transform, opacity; opacity: 0; }\n.hb-wg2-photo { width: 100%; height: 100%; border-radius: 6px; background-size: cover; background-position: center; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }\n.hb-wg2-cap { position: absolute; left: 5px; right: 5px; bottom: 2px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 7.5px; line-height: 12px; letter-spacing: .04em; color: #3b3a36; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg2-layer { display: none; }\n}\n`;\n\nexport function HoverPhotoSnake({\n  frames = defaults,\n  size = 58,\n  gap = 26,\n  follow = 0.22,\n  autoPlay = true,\n  showCaptions = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: HoverPhotoSnakeProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const layerRef = React.useRef<HTMLDivElement>(null);\n  const list = frames.length ? frames : defaults;\n  const n = list.length;\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const layer = layerRef.current;\n    if (!root || !layer) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const els = Array.from(layer.children) as HTMLElement[];\n    const pts = els.map(() => ({ x: root.clientWidth / 2, y: root.clientHeight / 2, r: 0 }));\n    let px = 0;\n    let py = 0;\n    let inside = false;\n    let mix = 0;\n    let t = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let shown = 0;\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      t += dt;\n      const w = root.clientWidth;\n      const h = root.clientHeight;\n      const ax = w * (0.5 + 0.34 * Math.sin(t * 0.8));\n      const ay = h * (0.5 + 0.26 * Math.sin(t * 1.6));\n      mix += ((inside ? 1 : 0) - mix) * (1 - Math.exp(-dt * 5));\n      const hx = ax + (px - ax) * mix;\n      const hy = ay + (py - ay) * mix;\n      const goal = inside || autoPlay ? 1 : 0;\n      shown += (goal - shown) * (1 - Math.exp(-dt * 6));\n      const k = 1 - Math.pow(1 - Math.min(0.9, Math.max(0.02, follow)), dt * 60);\n      pts.forEach((p, i) => {\n        const lx = i === 0 ? hx : pts[i - 1].x;\n        const ly = i === 0 ? hy : pts[i - 1].y;\n        let nx = p.x + (lx - p.x) * k;\n        let ny = p.y + (ly - p.y) * k;\n        if (i > 0) {\n          const dx = nx - lx;\n          const dy = ny - ly;\n          const d = Math.hypot(dx, dy);\n          const lim = gap;\n          if (d > lim) {\n            nx = lx + (dx / d) * lim;\n            ny = ly + (dy / d) * lim;\n          }\n        }\n        const vx = nx - p.x;\n        const vy = ny - p.y;\n        const speed = Math.hypot(vx, vy);\n        const goalR = Math.max(-28, Math.min(28, vx * 2.2)) + (i % 2 ? 4 : -4) * (1 - Math.min(1, speed / 3));\n        p.r += (goalR - p.r) * (1 - Math.exp(-dt * 8));\n        p.x = nx;\n        p.y = ny;\n        const scale = (1 - i * (0.5 / Math.max(1, els.length))) * (0.6 + 0.4 * shown);\n        const el = els[i];\n        el.style.transform = `translate3d(${(p.x - size / 2).toFixed(1)}px, ${(p.y - size * 0.62).toFixed(1)}px, 0) rotate(${p.r.toFixed(1)}deg) scale(${scale.toFixed(3)})`;\n        el.style.opacity = (shown * (1 - i * 0.06)).toFixed(3);\n      });\n      raf = requestAnimationFrame(frame);\n    };\n    const start = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? root.offsetWidth / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      inside = true;\n    };\n    const onLeave = () => {\n      inside = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") window.setTimeout(onLeave, 1200);\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    start();\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [n, size, gap, follow, autoPlay]);\n\n  return (\n    <div ref={rootRef} className={`hb-wg2 ${className}`} style={style} {...rest}>\n      <style href=\"hb-hover-photo-snake\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wg2-content\">{children}</div>\n      <div ref={layerRef} className=\"hb-wg2-layer\" aria-hidden=\"true\">\n        {list.map((f, i) => (\n          <div\n            key={i}\n            className=\"hb-wg2-frame\"\n            style={{ width: size, height: (size * 1.12 + 12).toFixed(1) + \"px\", zIndex: n - i, paddingBottom: showCaptions ? 15 : 3 }}\n          >\n            <div className=\"hb-wg2-photo\" style={{ background: f.background ?? defaults[i % defaults.length].background }} />\n            {showCaptions ? <span className=\"hb-wg2-cap\">{f.caption}</span> : null}\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}