{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "photo-trail-cursor",
  "title": "Photo Trail Cursor",
  "description": "An area where moving the pointer deals out photos along its path: each one pops in turned the way you were travelling, holds for a moment on top of the last, then sinks and fades, cycling through your set.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/photo-trail-cursor/photo-trail-cursor.tsx",
      "content": "\"use client\";\n/* eslint-disable @next/next/no-img-element -- Registry components work in any React app. */\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface PhotoTrailCursorProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  images?: string[];\n  /** Distance the pointer travels between photos, in px. */\n  spacing?: number;\n  /** Photo width in px; height follows each image's own shape via the aspect prop. */\n  width?: number;\n  /** Width / height of each photo. */\n  aspect?: number;\n  /** How long a photo stays before it's gone, in ms. */\n  life?: number;\n  /** Most degrees a photo is turned either way. */\n  tilt?: number;\n  radius?: number;\n}\n\nconst IMAGES = [\"/demo/19.webp\", \"/demo/38.webp\", \"/demo/2.webp\", \"/demo/108.webp\", \"/demo/39.webp\", \"/demo/43.webp\", \"/demo/26.webp\", \"/demo/5.webp\"];\nconst POOL = 14;\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function PhotoTrailCursor({ images = IMAGES, spacing = 90, width = 170, aspect = 4 / 5, life = 1100, tilt = 8, radius = 10, className, children, ...props }: PhotoTrailCursorProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const slots = React.useRef<(HTMLImageElement | null)[]>([]);\n  const state = React.useRef({ x: -1, y: -1, slot: 0, image: 0, z: 1 });\n\n  const onMove = (event: React.PointerEvent<HTMLDivElement>) => {\n    props.onPointerMove?.(event);\n    if (reduce || !images.length) return;\n    const r = event.currentTarget.getBoundingClientRect();\n    const scale = r.width / event.currentTarget.offsetWidth || 1;\n    const x = (event.clientX - r.left) / scale;\n    const y = (event.clientY - r.top) / scale;\n    const s = state.current;\n    const dx = x - s.x;\n    const dy = y - s.y;\n    if (s.x >= 0 && Math.hypot(dx, dy) < spacing) return;\n    const first = s.x < 0;\n    s.x = x;\n    s.y = y;\n    if (first) return;\n    const el = slots.current[s.slot];\n    s.slot = (s.slot + 1) % POOL;\n    if (!el) return;\n    el.src = images[s.image % images.length];\n    s.image += 1;\n    s.z += 1;\n    // Each photo lands angled the way the pointer was travelling, then sinks and fades.\n    const rot = Math.max(-tilt, Math.min(tilt, (dx / spacing) * tilt * 0.6 + (Math.random() - 0.5) * tilt));\n    el.style.zIndex = String(s.z);\n    el.style.left = `${x}px`;\n    el.style.top = `${y}px`;\n    el.getAnimations().forEach((a) => a.cancel());\n    el.animate(\n      [\n        { opacity: 0, transform: `translate(-50%, -50%) scale(0.6) rotate(${rot * 2}deg)` },\n        { opacity: 1, transform: `translate(-50%, -50%) scale(1) rotate(${rot}deg)`, offset: 0.18 },\n        { opacity: 1, transform: `translate(-50%, -50%) scale(1) rotate(${rot}deg)`, offset: 0.62 },\n        { opacity: 0, transform: `translate(-50%, calc(-50% + 30px)) scale(0.85) rotate(${rot}deg)` },\n      ],\n      { duration: life, easing: \"cubic-bezier(.2,.8,.2,1)\", fill: \"forwards\" },\n    );\n  };\n\n  return (\n    <div ref={rootRef} className={cn(\"relative isolate overflow-hidden\", className)} {...props} onPointerMove={onMove}>\n      {children}\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\">\n        {Array.from({ length: POOL }, (_, i) => (\n          <img\n            key={i}\n            ref={(el) => {\n              slots.current[i] = el;\n            }}\n            alt=\"\"\n            draggable={false}\n            className=\"absolute object-cover opacity-0 shadow-[0_18px_40px_-16px_rgba(0,0,0,.6)]\"\n            style={{ width, height: width / aspect, borderRadius: radius, transform: \"translate(-50%, -50%)\" }}\n          />\n        ))}\n      </div>\n      {/* Preload, so the first pass doesn't show blank frames. */}\n      <div aria-hidden=\"true\" className=\"hidden\">\n        {images.map((src) => (\n          <img key={src} src={src} alt=\"\" />\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}