{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-image-trail",
  "type": "registry:component",
  "title": "Cursor Image Trail",
  "description": "Small photo tiles drop along the pointer path every few dozen pixels, then tilt, drift away and fade.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "image",
    "trail",
    "gallery",
    "portfolio",
    "photos"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-image-trail",
  "files": [
    {
      "path": "registry/hyperblur/cursor-image-trail.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-image-trail.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorImageTrailProps extends React.HTMLAttributes<HTMLDivElement> {\n  images?: string[];\n  size?: number;\n  spacing?: number;\n  duration?: number;\n  max?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi8 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qi8 *, .hb-qi8 *::before, .hb-qi8 *::after { box-sizing: border-box; }\n.hb-qi8-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n.hb-qi8-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }\n.hb-qi8-tile { position: absolute; left: 0; top: 0; opacity: 0; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.16); background-color: #171717; background-size: cover; background-position: center; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.7); will-change: transform, opacity; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qi8-layer { display: none; }\n}\n`;\n\nconst scenes = [\n  \"radial-gradient(circle at 70% 32%, #ffe3a3 0 9%, rgba(255,227,163,0) 10%), linear-gradient(180deg, #ff9a62 0%, #d4486b 52%, #2d1840 100%)\",\n  \"radial-gradient(120% 60% at 50% 100%, #0d4f6b 0%, rgba(13,79,107,0) 60%), linear-gradient(180deg, #9fd8f0 0%, #3a8fc2 48%, #0b2c4a 100%)\",\n  \"linear-gradient(160deg, rgba(0,0,0,0) 55%, #0e2a1a 56%), linear-gradient(200deg, rgba(0,0,0,0) 48%, #1b4a2c 49%), linear-gradient(180deg, #cfe8c4 0%, #6fa36a 100%)\",\n  \"radial-gradient(140% 70% at 20% 100%, #c98b4a 0%, rgba(201,139,74,0) 55%), linear-gradient(180deg, #f6d9a8 0%, #e2a35f 60%, #8a4f26 100%)\",\n  \"radial-gradient(80% 50% at 40% 30%, rgba(80,255,190,0.65) 0%, rgba(80,255,190,0) 70%), radial-gradient(60% 40% at 70% 45%, rgba(140,110,255,0.55) 0%, rgba(140,110,255,0) 70%), linear-gradient(180deg, #071226 0%, #0d1f3a 100%)\",\n  \"linear-gradient(0deg, #0b0f1c 0 22%, rgba(0,0,0,0) 22%), repeating-linear-gradient(90deg, #1b2440 0 9px, #ffcf6b 9px 11px, #1b2440 11px 18px), linear-gradient(180deg, #2a2f5c 0%, #ff7a59 100%)\",\n  \"radial-gradient(90% 60% at 50% 110%, #e8f6ff 0%, rgba(232,246,255,0) 60%), linear-gradient(180deg, #b9dcf2 0%, #6aa5cf 55%, #dff1fb 100%)\",\n  \"radial-gradient(circle at 30% 70%, #f2c6ff 0 14%, rgba(242,198,255,0) 15%), linear-gradient(180deg, #b79cff 0%, #7c5ad9 55%, #2c1d57 100%)\",\n];\n\nfunction hash(n: number) {\n  let x = (Math.imul(n | 0, 374761393) + 668265263) | 0;\n  x = Math.imul(x ^ (x >>> 13), 1274126177);\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967296;\n}\n\nexport function CursorImageTrail({\n  images,\n  size = 64,\n  spacing = 44,\n  duration = 950,\n  max = 14,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorImageTrailProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const layerRef = React.useRef<HTMLDivElement>(null);\n  const pool = Math.max(2, Math.min(40, Math.floor(max)));\n  const sources = images && images.length ? images.map((src) => `url(\"${src}\")`) : scenes;\n  const sourceKey = sources.join(\"\\n\");\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 list = sourceKey.split(\"\\n\");\n    const tiles = Array.from(layer.children) as HTMLElement[];\n    const anims: (Animation | null)[] = tiles.map(() => null);\n    const tw = size;\n    const th = size * 1.22;\n    let w = root.clientWidth;\n    let h = root.clientHeight;\n    let px = w / 2;\n    let py = h / 2;\n    let lx = 0;\n    let ly = 0;\n    let sx = 0;\n    let sy = 0;\n    let active = false;\n    let mix = 0;\n    let raf = 0;\n    let last = 0;\n    let t = 0;\n    let visible = true;\n    let serial = 0;\n    let primed = false;\n\n    const spawn = (x: number, y: number, mvx: number, mvy: number) => {\n      const el = tiles[serial % tiles.length];\n      if (!el) return;\n      anims[serial % tiles.length]?.cancel();\n      const src = list[serial % list.length];\n      el.style.backgroundImage = src;\n      el.style.width = `${tw}px`;\n      el.style.height = `${th.toFixed(1)}px`;\n      const r0 = (hash(serial * 3 + 1) - 0.5) * 24;\n      const r1 = r0 + (hash(serial * 3 + 2) - 0.5) * 30;\n      const m = Math.hypot(mvx, mvy) || 1;\n      const dx = (-mvx / m) * 22 + (hash(serial * 3 + 3) - 0.5) * 26;\n      const dy = (-mvy / m) * 22 - 26;\n      const x0 = x - tw / 2;\n      const y0 = y - th / 2;\n      const at = (ox: number, oy: number, s: number, r: number) =>\n        `translate3d(${(x0 + ox).toFixed(1)}px, ${(y0 + oy).toFixed(1)}px, 0) scale(${s}) rotate(${r.toFixed(1)}deg)`;\n      el.style.zIndex = String(serial % 1000);\n      anims[serial % tiles.length] = el.animate(\n        [\n          { transform: at(0, 0, 0.55, r0), opacity: 0 },\n          { transform: at(dx * 0.15, dy * 0.15, 1, r0), opacity: 1, offset: 0.18 },\n          { transform: at(dx * 0.55, dy * 0.55, 0.96, (r0 + r1) / 2), opacity: 0.9, offset: 0.55 },\n          { transform: at(dx, dy, 0.8, r1), opacity: 0 },\n        ],\n        { duration: Math.max(200, duration), easing: \"cubic-bezier(.2,.7,.3,1)\", fill: \"forwards\" },\n      );\n      serial++;\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      t += dt;\n      w = root.clientWidth;\n      h = root.clientHeight;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 4));\n      const ix = idle ? w * (0.5 + 0.36 * Math.sin(t * 0.75)) : px;\n      const iy = idle ? h * (0.5 + 0.22 * Math.sin(t * 1.5 + 0.4)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      if (!primed) {\n        primed = true;\n        lx = sx = tx;\n        ly = sy = ty;\n      }\n      const moved = Math.hypot(tx - sx, ty - sy);\n      if (moved >= spacing && (idle || active)) {\n        spawn(tx, ty, tx - lx, ty - ly);\n        sx = tx;\n        sy = ty;\n      }\n      lx = tx;\n      ly = ty;\n      raf = requestAnimationFrame(frame);\n    };\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\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? w / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      if (!active && !idle) {\n        sx = px;\n        sy = py;\n        lx = px;\n        ly = py;\n      }\n      active = true;\n    };\n    const onLeave = () => {\n      active = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointercancel\", 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\n    return () => {\n      stop();\n      io.disconnect();\n      anims.forEach((a) => a?.cancel());\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointercancel\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [sourceKey, size, spacing, duration, pool, idle]);\n\n  return (\n    <div ref={rootRef} className={`hb-qi8 ${className}`} style={style} {...rest}>\n      <style href=\"hb-cursor-image-trail\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qi8-content\">{children}</div>\n      <div ref={layerRef} className=\"hb-qi8-layer\" aria-hidden=\"true\">\n        {Array.from({ length: pool }, (_, i) => (\n          <span key={i} className=\"hb-qi8-tile\" />\n        ))}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}