{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel-3d-motion",
  "title": "Carousel 3D (Motion)",
  "author": "AlgorizeTech",
  "description": "A perspective carousel where cards rotate through depth, with drag and autoplay. Use it for portfolio and gallery sections that need presence.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/motion/ThreeDCarouselBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  AnimatePresence,\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n} from \"motion/react\";\nimport type { PanInfo } from \"motion/react\";\nimport { ChevronLeft, ChevronRight, Pause, Play } from \"lucide-react\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport interface CarouselItem {\n  id: string;\n  title: string;\n  category: string;\n  image: string;\n  description?: string;\n}\n\nexport interface ThreeDCarouselProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  items: CarouselItem[];\n  autoPlay?: boolean;\n  autoPlayInterval?: number;\n  /** Renders the previous / next and autoplay pause buttons. Defaults to `true`. */\n  showArrows?: boolean;\n  /** Renders the pagination dots under the deck. Defaults to `true`. */\n  showDots?: boolean;\n}\n\n// Sub-component for individual cards to cleanly manage 3D tilt hooks without loop issues\ninterface CarouselCardProps {\n  item: CarouselItem;\n  index: number;\n  activeIndex: number;\n  total: number;\n  onClick: () => void;\n  onDragEnd: (_: MouseEvent | TouchEvent, info: PanInfo) => void;\n}\n\nfunction CarouselCard({\n  item,\n  index,\n  activeIndex,\n  total,\n  onClick,\n  onDragEnd,\n}: CarouselCardProps) {\n  // Calculate circular distance offset for fanned 3D layout\n  let diff = (index - activeIndex) % total;\n  if (diff > Math.floor(total / 2)) diff -= total;\n  if (diff < -Math.floor(total / 2)) diff += total;\n\n  const offset = diff;\n  const isCenter = offset === 0;\n\n  // 3D Tilt Motion Values for interactive hover\n  const x = useMotionValue(0);\n  const y = useMotionValue(0);\n\n  const rotateX = useSpring(useTransform(y, [-150, 150], [14, -14]), {\n    stiffness: 300,\n    damping: 25,\n  });\n  const rotateY = useSpring(useTransform(x, [-150, 150], [-14, 14]), {\n    stiffness: 300,\n    damping: 25,\n  });\n\n  const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {\n    const rect = e.currentTarget.getBoundingClientRect();\n    const centerX = rect.left + rect.width / 2;\n    const centerY = rect.top + rect.height / 2;\n    x.set(e.clientX - centerX);\n    y.set(e.clientY - centerY);\n  };\n\n  const handleMouseLeave = () => {\n    x.set(0);\n    y.set(0);\n  };\n\n  // Do not render cards that are too far out of the fan view\n  if (Math.abs(offset) > 2) return null;\n\n  return (\n    <motion.div\n      onClick={onClick}\n      drag={isCenter ? \"x\" : false}\n      dragConstraints={{ left: 0, right: 0 }}\n      dragElastic={0.2}\n      onDragEnd={onDragEnd}\n      initial={false}\n      animate={{\n        x:\n          offset *\n          (typeof window !== \"undefined\" && window.innerWidth < 640\n            ? 120\n            : 220),\n        scale: isCenter ? 1 : Math.max(0.7, 1 - Math.abs(offset) * 0.15),\n        rotateY: offset * -22,\n        z: -Math.abs(offset) * 140,\n        zIndex: 30 - Math.abs(offset) * 10,\n        opacity: isCenter ? 1 : Math.max(0.3, 1 - Math.abs(offset) * 0.35),\n      }}\n      transition={{\n        type: \"spring\",\n        stiffness: 280,\n        damping: 28,\n      }}\n      className={cn(\n        \"absolute w-[280px] sm:w-[320px] md:w-[360px] h-[360px] sm:h-[400px] md:h-[420px] rounded-3xl\",\n        isCenter\n          ? \"cursor-grab active:cursor-grabbing z-30\"\n          : \"cursor-pointer z-10\",\n      )}\n    >\n      {/* Inner wrapper separates hover tilt transforms from outer fanned layout transforms */}\n      <motion.div\n        style={{ rotateX, rotateY }}\n        onMouseMove={handleMouseMove}\n        onMouseLeave={handleMouseLeave}\n        whileHover={{\n          scale: isCenter ? 1.02 : 1.05,\n          transition: { duration: 0.2 },\n        }}\n        className={cn(\n          \"w-full h-full rounded-3xl overflow-hidden shadow-2xl transition-shadow duration-300\",\n          \"bg-card border border-border\",\n          isCenter\n            ? \"shadow-primary/20 dark:shadow-primary/20 ring-2 ring-primary/30\"\n            : \"hover:border-primary/50 shadow-md\",\n        )}\n      >\n        {/* Image Background */}\n        <div className=\"relative w-full h-full overflow-hidden\">\n          <img\n            src={item.image}\n            alt={item.title}\n            loading=\"lazy\"\n            decoding=\"async\"\n            className=\"w-full h-full object-cover pointer-events-none transition-transform duration-700 hover:scale-105\"\n          />\n\n          {/* Theme Adaptive Overlay */}\n          <div className=\"absolute inset-0 bg-gradient-to-t from-black/90 via-black/30 to-transparent dark:from-black/95 dark:via-black/40 dark:to-transparent\" />\n\n          {/* Content Payload */}\n          <div className=\"absolute inset-x-0 bottom-0 p-6 flex flex-col justify-end pointer-events-none text-white\">\n            <span className=\"text-xs font-semibold uppercase tracking-wider px-3 py-1 rounded-full bg-primary/90 backdrop-blur-md w-fit mb-2 text-primary-foreground shadow-sm\">\n              {item.category}\n            </span>\n            <h3 className=\"text-xl md:text-2xl font-semibold tracking-tight mb-1 leading-snug\">\n              {item.title}\n            </h3>\n            {item.description && (\n              <p className=\"text-sm text-zinc-300 dark:text-zinc-400 line-clamp-2 leading-relaxed\">\n                {item.description}\n              </p>\n            )}\n          </div>\n        </div>\n      </motion.div>\n    </motion.div>\n  );\n}\n\nexport const ThreeDCarousel = React.forwardRef<\n  HTMLDivElement,\n  ThreeDCarouselProps\n>(\n  (\n    {\n      items,\n      autoPlay = true,\n      autoPlayInterval = 4000,\n      showArrows = true,\n      showDots = true,\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const [activeIndex, setActiveIndex] = useState(0);\n    const [isPlaying, setIsPlaying] = useState(autoPlay);\n    const [isHovered, setIsHovered] = useState(false);\n    const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n    const total = items.length;\n\n    const handleNext = useCallback(() => {\n      setActiveIndex((prev) => (prev + 1) % total);\n    }, [total]);\n\n    const handlePrev = useCallback(() => {\n      setActiveIndex((prev) => (prev - 1 + total) % total);\n    }, [total]);\n\n    // Keyboard Navigation\n    useEffect(() => {\n      const handleKeyDown = (e: KeyboardEvent) => {\n        if (e.key === \"ArrowLeft\") handlePrev();\n        if (e.key === \"ArrowRight\") handleNext();\n      };\n      window.addEventListener(\"keydown\", handleKeyDown);\n      return () => window.removeEventListener(\"keydown\", handleKeyDown);\n    }, [handleNext, handlePrev]);\n\n    // Auto-Play Timer\n    useEffect(() => {\n      if (isPlaying && !isHovered) {\n        timerRef.current = setInterval(handleNext, autoPlayInterval);\n      } else if (timerRef.current) {\n        clearInterval(timerRef.current);\n      }\n      return () => {\n        if (timerRef.current) clearInterval(timerRef.current);\n      };\n    }, [isPlaying, isHovered, handleNext, autoPlayInterval]);\n\n    // Drag / Swipe Interaction\n    const handleDragEnd = (_: MouseEvent | TouchEvent, info: PanInfo) => {\n      const threshold = 50;\n      if (info.offset.x < -threshold) {\n        handleNext();\n      } else if (info.offset.x > threshold) {\n        handlePrev();\n      }\n    };\n\n    return (\n      <div\n        ref={ref}\n        onMouseEnter={() => setIsHovered(true)}\n        onMouseLeave={() => setIsHovered(false)}\n        className={cn(\n          \"relative w-full h-[500px] md:h-[580px] flex flex-col items-center justify-center overflow-hidden select-none py-6\",\n          className,\n        )}\n        {...props}\n      >\n        {/* 3D Fanned Cards Container */}\n        <div className=\"relative w-full max-w-4xl h-[360px] md:h-[420px] flex items-center justify-center perspective-[1200px]\">\n          <AnimatePresence initial={false}>\n            {items.map((item, index) => (\n              <CarouselCard\n                key={item.id}\n                item={item}\n                index={index}\n                activeIndex={activeIndex}\n                total={total}\n                onClick={() => index !== activeIndex && setActiveIndex(index)}\n                onDragEnd={handleDragEnd}\n              />\n            ))}\n          </AnimatePresence>\n        </div>\n\n        {/* Navigation Controls Bar */}\n        {showArrows && (\n          <div className=\"flex items-center gap-4 mt-6 z-10\">\n            <button\n              onClick={handlePrev}\n              aria-label=\"Previous Slide\"\n              className=\"p-3 rounded-full bg-background border border-border text-foreground hover:bg-primary hover:text-primary-foreground hover:border-primary/30 hover:scale-105 active:scale-95 transition-all shadow-md\"\n            >\n              <ChevronLeft className=\"w-5 h-5\" />\n            </button>\n\n            {/* Auto-play Toggle Button */}\n            <button\n              onClick={() => setIsPlaying(!isPlaying)}\n              aria-label={isPlaying ? \"Pause Auto-play\" : \"Start Auto-play\"}\n              className=\"p-3 rounded-full bg-background border border-border text-foreground hover:bg-primary hover:text-primary-foreground hover:border-primary/30 hover:scale-105 active:scale-95 transition-all shadow-md\"\n            >\n              {isPlaying ? (\n                <Pause className=\"w-5 h-5\" />\n              ) : (\n                <Play className=\"w-5 h-5\" />\n              )}\n            </button>\n\n            <button\n              onClick={handleNext}\n              aria-label=\"Next Slide\"\n              className=\"p-3 rounded-full bg-background border border-border text-foreground hover:bg-primary hover:text-primary-foreground hover:border-primary/30 hover:scale-105 active:scale-95 transition-all shadow-md\"\n            >\n              <ChevronRight className=\"w-5 h-5\" />\n            </button>\n          </div>\n        )}\n\n        {/* Pagination Dots */}\n        {showDots && (\n          <div className=\"flex items-center gap-2 mt-4 z-10\">\n            {items.map((_, idx) => (\n              <button\n                key={idx}\n                onClick={() => setActiveIndex(idx)}\n                aria-label={`Go to slide ${idx + 1}`}\n                className={cn(\n                  \"h-1.5 rounded-full transition-all duration-300\",\n                  idx === activeIndex\n                    ? \"w-8 bg-primary\"\n                    : \"w-1.5 bg-muted hover:bg-primary/50\",\n                )}\n              />\n            ))}\n          </div>\n        )}\n      </div>\n    );\n  },\n);\n\nThreeDCarousel.displayName = \"ThreeDCarousel\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/ThreeDCarouselBlock.tsx"
    }
  ],
  "docs": "Motion build of `carousel-3d` — same props, markup and install path; install one or the other. Named exports: ThreeDCarousel, CarouselItem. `items` take { id, title, category, image, description? }. `autoPlay` with `autoPlayInterval` advances it; dragging pauses. Renders a plain <img>, so it works outside Next.js.",
  "categories": [
    "media",
    "marketing"
  ],
  "type": "registry:component"
}
