{
  "$schema": "https://www.cooki-ui.design/schema/registry-item.json",
  "name": "3d-image-ring",
  "type": "registry:ui",
  "title": "3D Image Ring",
  "description": "Interactive cylindrical revolving image gallery with 3D perspective depth, drag inertia, and parallax tracking.",
  "category": "media",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/media/3d-image-ring/3d-image-ring.tsx",
      "type": "registry:ui",
      "target": "components/ui/3d-image-ring.tsx",
      "content": "import React, { useEffect, useRef, useState, useMemo } from \"react\";\nimport { motion, useMotionValue, easeOut, animate } from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ThreeDImageRingProps {\n  /** Array of image URLs to display in the ring */\n  images?: string[];\n  /** Container width in pixels (will be scaled) */\n  width?: number;\n  /** 3D perspective value */\n  perspective?: number;\n  /** Distance of images from center (z-depth) */\n  imageDistance?: number;\n  /** Initial rotation of the ring */\n  initialRotation?: number;\n  /** Animation duration for entrance */\n  animationDuration?: number;\n  /** Stagger delay between images */\n  staggerDelay?: number;\n  /** Hover opacity for non-hovered images */\n  hoverOpacity?: number;\n  /** Custom container className */\n  containerClassName?: string;\n  /** Custom ring className */\n  ringClassName?: string;\n  /** Custom image className */\n  imageClassName?: string;\n  /** Background color of the stage */\n  backgroundColor?: string;\n  /** Enable/disable drag functionality */\n  draggable?: boolean;\n  /** Breakpoint for mobile responsiveness */\n  mobileBreakpoint?: number;\n  /** Scale factor for mobile */\n  mobileScaleFactor?: number;\n  /** Power for the drag end inertia animation */\n  inertiaPower?: number;\n  /** Time constant for the drag end inertia animation */\n  inertiaTimeConstant?: number;\n  /** Multiplier for initial velocity when drag ends */\n  inertiaVelocityMultiplier?: number;\n}\n\nconst DEFAULT_IMAGES = [\n  \"https://images.unsplash.com/photo-1510812431401-41d2bd2722f3?q=80&w=1200&auto=format&fit=crop\",\n  \"https://images.unsplash.com/photo-1469474968028-56623f02e42e?q=80&w=1200&auto=format&fit=crop\",\n  \"https://images.unsplash.com/photo-1506744626753-1fa7604d459a?q=80&w=1200&auto=format&fit=crop\",\n  \"https://images.unsplash.com/photo-1470071131384-001b85755536?q=80&w=1200&auto=format&fit=crop\",\n  \"https://images.unsplash.com/photo-1472214103451-9374bd1c798e?q=80&w=1200&auto=format&fit=crop\",\n];\n\nexport function ThreeDImageRing({\n  images = DEFAULT_IMAGES,\n  width = 240,\n  perspective = 1600,\n  imageDistance = 360,\n  initialRotation = 180,\n  animationDuration = 1.2,\n  staggerDelay = 0.08,\n  hoverOpacity = 0.5,\n  containerClassName,\n  ringClassName,\n  imageClassName,\n  backgroundColor,\n  draggable = true,\n  mobileBreakpoint = 768,\n  mobileScaleFactor = 0.75,\n  inertiaPower = 0.8,\n  inertiaTimeConstant = 300,\n  inertiaVelocityMultiplier = 20,\n}: ThreeDImageRingProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const ringRef = useRef<HTMLDivElement>(null);\n\n  const rotationY = useMotionValue(initialRotation);\n  const startX = useRef<number>(0);\n  const currentRotationY = useRef<number>(initialRotation);\n  const isDragging = useRef<boolean>(false);\n  const velocity = useRef<number>(0);\n\n  const [currentScale, setCurrentScale] = useState(1);\n  const [showImages, setShowImages] = useState(false);\n\n  const angle = useMemo(() => 360 / Math.max(1, images.length), [images.length]);\n\n  const getBgPos = (imageIndex: number, currentRot: number, scale: number) => {\n    const scaledImageDistance = imageDistance * scale;\n    const effectiveRotation = currentRot - 180 - imageIndex * angle;\n    const parallaxOffset = (((effectiveRotation % 360) + 360) % 360) / 360;\n    return `${-(parallaxOffset * (scaledImageDistance / 1.5))}px 0px`;\n  };\n\n  useEffect(() => {\n    const unsubscribe = rotationY.on(\"change\", (latestRotation) => {\n      if (ringRef.current) {\n        Array.from(ringRef.current.children).forEach((imgElement, i) => {\n          (imgElement as HTMLElement).style.backgroundPosition = getBgPos(\n            i,\n            latestRotation,\n            currentScale\n          );\n        });\n      }\n      currentRotationY.current = latestRotation;\n    });\n    return () => unsubscribe();\n  }, [rotationY, images.length, imageDistance, currentScale, angle]);\n\n  useEffect(() => {\n    const handleResize = () => {\n      if (typeof window === \"undefined\") return;\n      const viewportWidth = window.innerWidth;\n      const newScale = viewportWidth <= mobileBreakpoint ? mobileScaleFactor : 1;\n      setCurrentScale(newScale);\n    };\n\n    window.addEventListener(\"resize\", handleResize);\n    handleResize();\n\n    return () => window.removeEventListener(\"resize\", handleResize);\n  }, [mobileBreakpoint, mobileScaleFactor]);\n\n  useEffect(() => {\n    setShowImages(true);\n  }, []);\n\n  const handleDragStart = (event: React.MouseEvent | React.TouchEvent) => {\n    if (!draggable) return;\n    isDragging.current = true;\n    const clientX = \"touches\" in event ? event.touches[0].clientX : event.clientX;\n    startX.current = clientX;\n    rotationY.stop();\n    velocity.current = 0;\n    if (ringRef.current) {\n      ringRef.current.style.cursor = \"grabbing\";\n    }\n    document.addEventListener(\"mousemove\", handleDrag);\n    document.addEventListener(\"mouseup\", handleDragEnd);\n    document.addEventListener(\"touchmove\", handleDrag);\n    document.addEventListener(\"touchend\", handleDragEnd);\n  };\n\n  const handleDrag = (event: MouseEvent | TouchEvent) => {\n    if (!draggable || !isDragging.current) return;\n    const clientX = \"touches\" in event ? event.touches[0].clientX : event.clientX;\n    const deltaX = clientX - startX.current;\n    velocity.current = -deltaX * 0.5;\n    rotationY.set(currentRotationY.current + velocity.current);\n    startX.current = clientX;\n  };\n\n  const handleDragEnd = () => {\n    isDragging.current = false;\n    if (ringRef.current) {\n      ringRef.current.style.cursor = \"grab\";\n      currentRotationY.current = rotationY.get();\n    }\n\n    document.removeEventListener(\"mousemove\", handleDrag);\n    document.removeEventListener(\"mouseup\", handleDragEnd);\n    document.removeEventListener(\"touchmove\", handleDrag);\n    document.removeEventListener(\"touchend\", handleDragEnd);\n\n    const initial = rotationY.get();\n    const velocityBoost = velocity.current * inertiaVelocityMultiplier;\n    const target = initial + velocityBoost;\n\n    animate(initial, target, {\n      type: \"inertia\",\n      velocity: velocityBoost,\n      power: inertiaPower,\n      timeConstant: inertiaTimeConstant,\n      restDelta: 0.5,\n      modifyTarget: (t) => Math.round(t / angle) * angle,\n      onUpdate: (latest) => {\n        rotationY.set(latest);\n      },\n    });\n\n    velocity.current = 0;\n  };\n\n  const imageVariants = {\n    hidden: { y: 150, opacity: 0 },\n    visible: { y: 0, opacity: 1 },\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\n        \"w-full h-full min-h-[360px] overflow-hidden select-none relative flex items-center justify-center\",\n        containerClassName\n      )}\n      style={{\n        backgroundColor,\n        transform: `scale(${currentScale})`,\n        transformOrigin: \"center center\",\n      }}\n      onMouseDown={draggable ? handleDragStart : undefined}\n      onTouchStart={draggable ? handleDragStart : undefined}\n    >\n      <div\n        style={{\n          perspective: `${perspective}px`,\n          width: `${width}px`,\n          height: `${width * 1.3}px`,\n          position: \"relative\",\n        }}\n      >\n        <motion.div\n          ref={ringRef}\n          className={cn(\"w-full h-full absolute inset-0\", ringClassName)}\n          style={{\n            transformStyle: \"preserve-3d\",\n            rotateY: rotationY,\n            cursor: draggable ? \"grab\" : \"default\",\n          }}\n        >\n          {showImages &&\n            images.map((imageUrl, index) => (\n              <motion.div\n                key={index}\n                className={cn(\n                  \"w-full h-full absolute rounded-2xl overflow-hidden shadow-2xl border border-white/20 dark:border-white/10\",\n                  imageClassName\n                )}\n                style={{\n                  transformStyle: \"preserve-3d\",\n                  backgroundImage: `url(${imageUrl})`,\n                  backgroundSize: \"cover\",\n                  backgroundRepeat: \"no-repeat\",\n                  backfaceVisibility: \"hidden\",\n                  willChange: \"transform\",\n                  rotateY: index * -angle,\n                  z: -imageDistance * currentScale,\n                  transformOrigin: `50% 50% ${imageDistance * currentScale}px`,\n                  backgroundPosition: getBgPos(\n                    index,\n                    currentRotationY.current,\n                    currentScale\n                  ),\n                }}\n                initial=\"hidden\"\n                animate=\"visible\"\n                variants={imageVariants}\n                custom={index}\n                transition={{\n                  delay: index * staggerDelay,\n                  duration: animationDuration,\n                  ease: easeOut,\n                }}\n                whileHover={{ opacity: 1, transition: { duration: 0.15 } }}\n                onHoverStart={() => {\n                  if (isDragging.current || !ringRef.current) return;\n                  Array.from(ringRef.current.children).forEach((imgEl, i) => {\n                    if (i !== index) {\n                      (imgEl as HTMLElement).style.opacity = `${hoverOpacity}`;\n                    }\n                  });\n                }}\n                onHoverEnd={() => {\n                  if (isDragging.current || !ringRef.current) return;\n                  Array.from(ringRef.current.children).forEach((imgEl) => {\n                    (imgEl as HTMLElement).style.opacity = \"1\";\n                  });\n                }}\n              />\n            ))}\n        </motion.div>\n      </div>\n    </div>\n  );\n}\n\nexport default ThreeDImageRing;\n"
    }
  ]
}