{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-deck-3d",
  "title": "Image Deck 3D",
  "description": "A single image split into a stacked deck of shape-clipped layers (rectangle, circle, hexagon, star, blob and more) that fans out on hover, with optional 3D cursor tilt, parallax, grayscale grading, and ambient idle rotation.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/image-deck-3d/image-deck-3d.tsx",
      "content": "\"use client\";\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 type ImageDeck3DShape = \"rectangle\" | \"circle\" | \"diamond\" | \"hexagon\" | \"triangle\" | \"pentagon\" | \"star\" | \"squircle\" | \"blob\";\n\nexport interface ImageDeck3DProps {\n  image: string;\n  alt?: string;\n  layerCount?: number;\n  shape?: ImageDeck3DShape;\n  enableColor?: boolean;\n  enableOpacity?: boolean;\n  enableParallax?: boolean;\n  enable3D?: boolean;\n  idleAnimation?: boolean;\n  radius?: number;\n  tilt?: number;\n  pan?: number;\n  depth?: number;\n  amplify?: number;\n  className?: string;\n}\n\nconst CLIP_PATHS: Record<ImageDeck3DShape, string> = {\n  rectangle: \"inset(0px round 0px)\",\n  circle: \"circle(45% at 50% 50%)\",\n  diamond: \"polygon(50% 0%, 14.1% 50%, 50% 100%, 85.9% 50%)\",\n  hexagon: \"polygon(25% 6.7%, 75% 6.7%, 100% 50%, 75% 93.3%, 25% 93.3%, 0% 50%)\",\n  triangle: \"polygon(50% 0%, 100% 100%, 0% 100%)\",\n  pentagon: \"polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%)\",\n  star: \"polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%)\",\n  squircle: \"none\",\n  blob: \"none\",\n};\n\nconst BORDER_RADII: Partial<Record<ImageDeck3DShape, string>> = {\n  squircle: \"32%\",\n  blob: \"62% 38% 34% 66% / 62% 32% 68% 38%\",\n};\n\nconst getBorderRadius = (s: ImageDeck3DShape) => BORDER_RADII[s];\nconst getClipPath = (s: ImageDeck3DShape, radius: number) => (s === \"rectangle\" ? `inset(0px round ${radius}px)` : CLIP_PATHS[s]);\n\nconst SCALE_INTERVAL = 0.06;\nconst OPACITY_INTERVAL = 0.05;\nconst OPACITY_FALLOFF = 0.1;\nconst SCALE_3D = 0.07;\n\nconst STAGGER_MS = 90;\nconst OPACITY_DURATION_MS = 700;\nconst TRANSFORM_DURATION_MS = 300;\nconst OPACITY_EASE = \"cubic-bezier(0.65, 0.05, 0.36, 1)\";\nconst TRANSFORM_EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\nconst FOLLOW_STRENGTH = 0.15;\n\nconst getScale = (i: number) => Math.max(1 - SCALE_INTERVAL * i, 0);\nconst getOpacity = (i: number, opacityOn: boolean) => (!opacityOn ? 1 : Math.max(1 - OPACITY_INTERVAL * i, 0.1));\nconst getFilterColor = (i: number, colorOn: boolean) => {\n  if (!colorOn) return \"\";\n  if (i === 0) return \"grayscale(1)\";\n  const t = Math.min(i * 0.15, 1);\n  return `grayscale(${1 - t}) saturate(${1 + t * 0.5})`;\n};\nconst get3DOpacity = (i: number, opacityOn: boolean) => {\n  const base = Math.max(1 - OPACITY_FALLOFF * i, 0.25);\n  return opacityOn ? Math.max(base - OPACITY_INTERVAL * i, 0.1) : base;\n};\nconst get3DScale = (i: number) => Math.max(1 - i * SCALE_3D, 0.35);\n\nexport function ImageDeck3D({\n  image,\n  alt = \"\",\n  layerCount = 10,\n  shape = \"rectangle\",\n  enableColor = false,\n  enableOpacity = false,\n  enableParallax = false,\n  enable3D = false,\n  idleAnimation = true,\n  radius = 0,\n  tilt = 45,\n  pan = 88,\n  depth = 36,\n  amplify = 54,\n  className,\n}: ImageDeck3DProps) {\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const stackRef = React.useRef<HTMLDivElement>(null);\n  const layerRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n\n  const [isHovered, setIsHovered] = React.useState(false);\n\n  const rectRef = React.useRef<DOMRect | null>(null);\n  const rafRef = React.useRef<number | null>(null);\n  const pendingRef = React.useRef<{ x: number; y: number } | null>(null);\n  const [inView, setInView] = React.useState(true);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    const update = () => {\n      rectRef.current = el.getBoundingClientRect();\n    };\n    update();\n    const ro = new ResizeObserver(update);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting), { threshold: 0.01 });\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(\n    () => () => {\n      if (rafRef.current != null) cancelAnimationFrame(rafRef.current);\n    },\n    [],\n  );\n\n  const idleRafRef = React.useRef<number | null>(null);\n  React.useEffect(() => {\n    const shouldRun = idleAnimation && enable3D && !isHovered && inView;\n\n    if (!shouldRun) {\n      if (idleRafRef.current != null) {\n        cancelAnimationFrame(idleRafRef.current);\n        idleRafRef.current = null;\n      }\n      return;\n    }\n\n    const amplitudeDeg = Math.min(tilt * 0.25, 10);\n    const start = performance.now();\n\n    const tick = (now: number) => {\n      const t = (now - start) / 1000;\n      if (stackRef.current) {\n        stackRef.current.style.setProperty(\"--ry\", `${Math.sin(t * 0.4) * amplitudeDeg}deg`);\n        stackRef.current.style.setProperty(\"--rx\", `${Math.cos(t * 0.3) * amplitudeDeg * 0.6}deg`);\n      }\n      idleRafRef.current = requestAnimationFrame(tick);\n    };\n    idleRafRef.current = requestAnimationFrame(tick);\n\n    return () => {\n      if (idleRafRef.current != null) {\n        cancelAnimationFrame(idleRafRef.current);\n        idleRafRef.current = null;\n      }\n    };\n  }, [idleAnimation, enable3D, isHovered, inView, tilt]);\n\n  const resetOffsets = React.useCallback(() => {\n    if (stackRef.current) {\n      stackRef.current.style.setProperty(\"--ry\", \"0deg\");\n      stackRef.current.style.setProperty(\"--rx\", \"0deg\");\n      stackRef.current.style.setProperty(\"--sx\", \"0px\");\n      stackRef.current.style.setProperty(\"--sy\", \"0px\");\n    }\n    layerRefs.current.forEach((el) => {\n      if (!el) return;\n      el.style.setProperty(\"--px\", \"0px\");\n      el.style.setProperty(\"--py\", \"0px\");\n    });\n  }, []);\n\n  const processMove = React.useCallback(() => {\n    rafRef.current = null;\n    const ev = pendingRef.current;\n    const rect = rectRef.current;\n    if (!ev || !rect) return;\n\n    const nx = ((ev.x - rect.left) / rect.width - 0.5) * 2;\n    const ny = ((ev.y - rect.top) / rect.height - 0.5) * 2;\n\n    if (enable3D && stackRef.current) {\n      const amplifyFactor = amplify / 100;\n      const tiltDeg = tilt * amplifyFactor;\n      const panPx = pan * amplifyFactor;\n      stackRef.current.style.setProperty(\"--ry\", `${nx * tiltDeg}deg`);\n      stackRef.current.style.setProperty(\"--rx\", `${-ny * tiltDeg}deg`);\n      stackRef.current.style.setProperty(\"--sx\", `${nx * panPx}px`);\n      stackRef.current.style.setProperty(\"--sy\", `${ny * panPx}px`);\n    } else if (enableParallax) {\n      layerRefs.current.forEach((el, i) => {\n        if (!el || i === 0) return;\n        const sv = 1 - SCALE_INTERVAL * i;\n        const mult = sv > 0 ? (1 - sv) * 3 + 0.2 : 1;\n        const x = nx * rect.width * FOLLOW_STRENGTH * mult;\n        const y = ny * rect.height * FOLLOW_STRENGTH * mult;\n        el.style.setProperty(\"--px\", `${x}px`);\n        el.style.setProperty(\"--py\", `${y}px`);\n      });\n    }\n  }, [enable3D, enableParallax, tilt, pan, amplify]);\n\n  const handleMouseMove = React.useCallback(\n    (e: React.MouseEvent) => {\n      if (!isHovered || (!enable3D && !enableParallax)) return;\n      pendingRef.current = { x: e.clientX, y: e.clientY };\n      if (rafRef.current == null) {\n        rafRef.current = requestAnimationFrame(processMove);\n      }\n    },\n    [isHovered, enable3D, enableParallax, processMove],\n  );\n\n  const handleMouseEnter = React.useCallback(() => {\n    rectRef.current = containerRef.current?.getBoundingClientRect() ?? null;\n    setIsHovered(true);\n  }, []);\n\n  const handleMouseLeave = React.useCallback(() => {\n    setIsHovered(false);\n    resetOffsets();\n  }, [resetOffsets]);\n\n  const layerStyles = React.useMemo(() => {\n    const styles: React.CSSProperties[] = [];\n    for (let i = 0; i < layerCount; i++) {\n      const delayMs = isHovered ? (layerCount - 1 - i) * STAGGER_MS : i * STAGGER_MS;\n\n      const scale = enable3D ? get3DScale(i) : isHovered ? getScale(i) : i === 0 ? 1 : 0.95;\n\n      const opacity = enable3D ? get3DOpacity(i, enableOpacity) : i === 0 ? 1 : isHovered ? getOpacity(i, enableOpacity) : 0;\n\n      const translateZ = enable3D ? i * depth : 0;\n      const filter = getFilterColor(i, enableColor) || \"none\";\n\n      styles.push({\n        transform: `translateZ(${translateZ}px) scale(${scale}) translate(var(--px, 0px), var(--py, 0px))`,\n        opacity,\n        filter,\n        transitionProperty: \"transform, opacity, filter\",\n        transitionDuration: `${TRANSFORM_DURATION_MS}ms, ${OPACITY_DURATION_MS}ms, ${OPACITY_DURATION_MS}ms`,\n        transitionTimingFunction: `${TRANSFORM_EASE}, ${OPACITY_EASE}, ${OPACITY_EASE}`,\n        transitionDelay: `0ms, ${delayMs}ms, ${delayMs}ms`,\n      } as React.CSSProperties);\n    }\n    return styles;\n  }, [layerCount, isHovered, enable3D, enableOpacity, enableColor, depth]);\n\n  return (\n    <div className={cn(\"relative h-full w-full\", className)}>\n      <div\n        ref={containerRef}\n        onMouseEnter={handleMouseEnter}\n        onMouseLeave={handleMouseLeave}\n        onMouseMove={handleMouseMove}\n        className=\"relative h-full w-full cursor-pointer border border-white/15\"\n        style={{\n          overflow: enable3D ? \"visible\" : \"hidden\",\n          borderRadius: radius,\n          perspective: enable3D ? 1600 : undefined,\n          perspectiveOrigin: \"50% 50%\",\n          isolation: enable3D ? \"isolate\" : undefined,\n        }}\n      >\n        <img src={image} alt={alt} className=\"sr-only\" />\n        <div\n          ref={stackRef}\n          aria-hidden=\"true\"\n          className=\"absolute inset-0\"\n          style={\n            {\n              transformStyle: enable3D ? \"preserve-3d\" : \"flat\",\n              transform: \"rotateY(var(--ry, 0deg)) rotateX(var(--rx, 0deg)) translate(var(--sx, 0px), var(--sy, 0px))\",\n              transition: \"transform 0.3s ease\",\n              willChange: \"transform\",\n            } as React.CSSProperties\n          }\n        >\n          {Array.from({ length: layerCount }).map((_, i) => (\n            <div\n              key={i}\n              ref={(el) => {\n                layerRefs.current[i] = el;\n              }}\n              style={\n                {\n                  position: \"absolute\",\n                  inset: 0,\n                  backgroundImage: `url(${JSON.stringify(image)})`,\n                  backgroundSize: \"cover\",\n                  backgroundPosition: \"center\",\n                  backgroundRepeat: \"no-repeat\",\n                  backfaceVisibility: \"hidden\",\n                  willChange: \"transform, opacity\",\n                  clipPath: getClipPath(i === 0 ? \"rectangle\" : shape, radius),\n                  borderRadius: getBorderRadius(i === 0 ? \"rectangle\" : shape),\n                  ...layerStyles[i],\n                } as React.CSSProperties\n              }\n            />\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}