{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"photo-wake","type":"registry:ui","title":"Photo Wake","description":"Photos pop in along the cursor path, then drift, shrink and fade away.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/photo-wake.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PhotoWakeProps {\n  /** Image URLs, spawned in order. */\n  images: string[];\n  children?: ReactNode;\n  /** Px the cursor travels between spawns. */\n  threshold?: number;\n  /** Image width in px (height follows the image aspect ratio). */\n  size?: number;\n  /** Lifetime of each image in ms. */\n  duration?: number;\n  /** Max random tilt in degrees. */\n  rotation?: number;\n  className?: string;\n}\n\nexport function PhotoWake({\n  images,\n  children,\n  threshold = 60,\n  size = 150,\n  duration = 1100,\n  rotation = 10,\n  className,\n}: PhotoWakeProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const layer = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = root.current!;\n    const box = layer.current!;\n    if (!images.length) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Warm the cache so the first pass of the trail does not pop in empty.\n    images.forEach((s) => (new Image().src = s));\n    let last: { x: number; y: number } | null = null;\n    let idx = 0;\n    let z = 1;\n\n    const spawn = (x: number, y: number, dx: number, dy: number) => {\n      const img = document.createElement(\"img\");\n      img.src = images[idx++ % images.length];\n      img.alt = \"\";\n      img.draggable = false;\n      const rot = (Math.random() * 2 - 1) * rotation;\n      Object.assign(img.style, {\n        position: \"absolute\",\n        left: `${x}px`,\n        top: `${y}px`,\n        width: `${size}px`,\n        borderRadius: \"14px\",\n        boxShadow: \"0 18px 40px -12px rgba(0,0,0,.55)\",\n        zIndex: String(z++),\n        pointerEvents: \"none\",\n        willChange: \"transform, opacity\",\n      });\n      box.appendChild(img);\n      const len = Math.hypot(dx, dy) || 1;\n      const drift = `${(dx / len) * 40}px, ${(dy / len) * 40}px`;\n      const at = (t: string, s: number, r = rot) => `translate(-50%, -50%) translate(${t}) rotate(${r}deg) scale(${s})`;\n      const frames: Keyframe[] = reduced\n        ? [{ opacity: 1, transform: at(\"0,0\", 1) }, { opacity: 0, transform: at(\"0,0\", 1) }]\n        : [\n            { opacity: 0, transform: at(\"0,0\", 0.4, 0) },\n            { opacity: 1, transform: at(\"0,0\", 1.04), offset: 0.14, easing: \"cubic-bezier(.2,.8,.2,1)\" },\n            { opacity: 1, transform: at(\"0,0\", 1), offset: 0.55 },\n            { opacity: 0, transform: at(drift, 0.7) },\n          ];\n      img.animate(frames, { duration, easing: \"ease-in\", fill: \"forwards\" }).finished.then(\n        () => img.remove(),\n        () => img.remove(),\n      );\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      const x = e.clientX - r.left;\n      const y = e.clientY - r.top;\n      if (!last) {\n        last = { x, y };\n        return;\n      }\n      const dx = x - last.x;\n      const dy = y - last.y;\n      if (Math.hypot(dx, dy) >= threshold) {\n        spawn(x, y, dx, dy);\n        last = { x, y };\n      }\n    };\n    const onLeave = () => (last = null);\n\n    el.addEventListener(\"pointermove\", onMove, { passive: true });\n    el.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      box.replaceChildren();\n    };\n  }, [images, threshold, size, duration, rotation]);\n\n  return (\n    <div ref={root} className={cn(\"relative overflow-hidden\", className)}>\n      <div ref={layer} aria-hidden className=\"pointer-events-none absolute inset-0\" />\n      {children}\n    </div>\n  );\n}\n"}]}