{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"fog-deck","type":"registry:ui","title":"Fog Deck","description":"A looping carousel where cards recede into 3D depth and blur the further they sit from center. Drag, click, arrows or keys.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/fog-deck.tsx","type":"registry:ui","content":"\"use client\";\n/* eslint-disable @next/next/no-img-element */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform, type MotionValue } from \"motion/react\";\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\n\nexport interface FogDeckItem {\n  image: string;\n  title: string;\n  subtitle?: string;\n}\n\nexport interface FogDeckProps {\n  items: FogDeckItem[];\n  /** Card width in px. */\n  cardWidth?: number;\n  /** Card height in px. */\n  cardHeight?: number;\n  /** Horizontal px between card centers. */\n  spacing?: number;\n  /** Px each step pushes a card back in z. */\n  depth?: number;\n  /** Blur in px added per step from center. */\n  blur?: number;\n  /** Y rotation in degrees of side cards. */\n  rotate?: number;\n  /** Cards shown on each side. */\n  visible?: number;\n  autoplay?: boolean;\n  /** Ms between autoplay steps. */\n  autoplayDelay?: number;\n  className?: string;\n}\n\nconst spring = { type: \"spring\" as const, stiffness: 180, damping: 26 };\n\nexport function FogDeck({\n  items,\n  cardWidth = 250,\n  cardHeight = 330,\n  spacing = 170,\n  depth = 180,\n  blur = 3,\n  rotate = 18,\n  visible = 2,\n  autoplay = true,\n  autoplayDelay = 3500,\n  className,\n}: FogDeckProps) {\n  const n = items.length;\n  const pos = useMotionValue(0);\n  const [index, setIndex] = useState(0);\n  const drag = useRef<{ x: number; p: number; moved: boolean; t: number; vx: number; lx: number; card: number } | null>(null);\n  const hovered = useRef(false);\n  const reduce = useReducedMotion();\n  const mod = (v: number) => ((v % n) + n) % n;\n\n  const go = (target: number) => {\n    setIndex(mod(target));\n    animate(pos, target, reduce ? { duration: 0 } : spring);\n  };\n  const step = (dir: number) => go(Math.round(pos.get()) + dir);\n\n  // Autoplay reads the latest `go` via a ref so the interval never restarts.\n  const stepRef = useRef(step);\n  useEffect(() => {\n    stepRef.current = step;\n  });\n  useEffect(() => {\n    if (!autoplay || reduce) return;\n    const id = window.setInterval(() => !hovered.current && !drag.current && stepRef.current(1), autoplayDelay);\n    return () => window.clearInterval(id);\n  }, [autoplay, autoplayDelay, reduce]);\n\n  const active = items[index];\n\n  return (\n    <div\n      className={`flex w-full flex-col items-center gap-5 ${className ?? \"\"}`}\n      onPointerEnter={() => (hovered.current = true)}\n      onPointerLeave={() => (hovered.current = false)}\n    >\n      <div\n        role=\"region\"\n        aria-roledescription=\"carousel\"\n        aria-label=\"Depth carousel. Drag or use arrow keys.\"\n        tabIndex={0}\n        onKeyDown={(e) => {\n          if (e.key === \"ArrowRight\") step(1);\n          else if (e.key === \"ArrowLeft\") step(-1);\n          else return;\n          e.preventDefault();\n        }}\n        onPointerDown={(e) => {\n          const card = (e.target as HTMLElement).closest<HTMLElement>(\"[data-depth-index]\");\n          e.currentTarget.setPointerCapture(e.pointerId);\n          pos.stop();\n          drag.current = {\n            x: e.clientX,\n            p: pos.get(),\n            moved: false,\n            t: performance.now(),\n            vx: 0,\n            lx: e.clientX,\n            card: card ? Number(card.dataset.depthIndex) : -1,\n          };\n        }}\n        onPointerMove={(e) => {\n          const d = drag.current;\n          if (!d) return;\n          const now = performance.now();\n          d.vx = (e.clientX - d.lx) / Math.max(1, now - d.t);\n          d.t = now;\n          d.lx = e.clientX;\n          if (Math.abs(e.clientX - d.x) > 4) d.moved = true;\n          pos.set(d.p - (e.clientX - d.x) / spacing);\n        }}\n        onPointerUp={() => {\n          const d = drag.current;\n          drag.current = null;\n          if (!d) return;\n          // A tap on a side card brings it to the front.\n          if (!d.moved && d.card >= 0) {\n            let delta = mod(d.card - Math.round(pos.get()));\n            if (delta > n / 2) delta -= n;\n            go(Math.round(pos.get()) + delta);\n            return;\n          }\n          go(Math.round(pos.get() - d.vx * 3));\n        }}\n        onPointerCancel={() => {\n          drag.current = null;\n          go(Math.round(pos.get()));\n        }}\n        className=\"relative w-full cursor-grab touch-pan-y select-none rounded-3xl outline-none focus-visible:ring-2 focus-visible:ring-ring active:cursor-grabbing\"\n        style={{ height: cardHeight + 40, perspective: 1200 }}\n      >\n        {items.map((item, i) => (\n          <Card\n            key={item.title + i}\n            item={item}\n            i={i}\n            n={n}\n            pos={pos}\n            width={cardWidth}\n            height={cardHeight}\n            spacing={spacing}\n            depth={depth}\n            blur={blur}\n            rotate={rotate}\n            visible={visible}\n            current={i === index}\n          />\n        ))}\n      </div>\n\n      <div className=\"flex items-center gap-4\">\n        <button\n          type=\"button\"\n          aria-label=\"Previous\"\n          onClick={() => step(-1)}\n          className=\"grid size-10 place-items-center rounded-full border border-border bg-card text-foreground outline-none transition hover:bg-muted active:scale-90 focus-visible:ring-2 focus-visible:ring-ring\"\n        >\n          <ChevronLeft className=\"size-5\" aria-hidden />\n        </button>\n        <div className=\"w-44 text-center\" aria-live=\"polite\">\n          <motion.p key={index} initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} className=\"truncate font-semibold text-foreground\">\n            {active?.title}\n          </motion.p>\n          <p className=\"text-xs tabular-nums text-muted-foreground\">\n            {index + 1} / {n}\n          </p>\n        </div>\n        <button\n          type=\"button\"\n          aria-label=\"Next\"\n          onClick={() => step(1)}\n          className=\"grid size-10 place-items-center rounded-full border border-border bg-card text-foreground outline-none transition hover:bg-muted active:scale-90 focus-visible:ring-2 focus-visible:ring-ring\"\n        >\n          <ChevronRight className=\"size-5\" aria-hidden />\n        </button>\n      </div>\n    </div>\n  );\n}\n\ninterface CardProps {\n  item: FogDeckItem;\n  i: number;\n  n: number;\n  pos: MotionValue<number>;\n  width: number;\n  height: number;\n  spacing: number;\n  depth: number;\n  blur: number;\n  rotate: number;\n  visible: number;\n  current: boolean;\n}\n\nfunction Card({ item, i, n, pos, width, height, spacing, depth, blur, rotate, visible, current }: CardProps) {\n  // Signed distance from the front slot, wrapped so the ring loops.\n  const d = useTransform(pos, (p) => {\n    let v = (((i - p) % n) + n) % n;\n    if (v > n / 2) v -= n;\n    return v;\n  });\n  const transform = useTransform(d, (v) => {\n    const a = Math.abs(v);\n    const x = Math.sign(v) * spacing * (a - Math.max(0, a - 1) * 0.25);\n    return `translate3d(${x}px, 0, ${-a * depth}px) rotateY(${-Math.max(-1, Math.min(1, v)) * rotate}deg)`;\n  });\n  const filter = useTransform(d, (v) => `blur(${Math.abs(v) * blur}px) brightness(${1 - Math.min(Math.abs(v), 3) * 0.18})`);\n  const opacity = useTransform(d, (v) => Math.max(0, Math.min(1, visible + 0.6 - Math.abs(v))));\n  const zIndex = useTransform(d, (v) => 100 - Math.round(Math.abs(v) * 10));\n\n  return (\n    <motion.div\n      data-depth-index={i}\n      aria-hidden={!current}\n      className=\"absolute left-1/2 top-5 overflow-hidden rounded-2xl bg-muted shadow-[0_30px_60px_-25px_rgba(0,0,0,.9)]\"\n      style={{ width, height, marginLeft: -width / 2, transform, filter, opacity, zIndex }}\n    >\n      <img src={item.image} alt=\"\" draggable={false} className=\"pointer-events-none size-full object-cover\" />\n      <div className=\"pointer-events-none absolute inset-0 bg-gradient-to-t from-black/60 via-transparent to-transparent\" />\n      {item.subtitle && <p className=\"pointer-events-none absolute bottom-4 left-4 right-4 text-sm text-white/85\">{item.subtitle}</p>}\n    </motion.div>\n  );\n}\n"}]}