{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel-depth",
  "type": "registry:component",
  "title": "Carousel Depth",
  "description": "A carousel in perspective: the active card is large and sharp while its neighbors turn away, shrink and dim. Supports drag, arrows, dots, keyboard and autoplay that pauses on hover.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "carousel",
    "3d",
    "depth",
    "slider",
    "autoplay",
    "cards"
  ],
  "docs": "https://hyperblur.dev/effects/carousel-depth",
  "files": [
    {
      "path": "registry/hyperblur/carousel-depth.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/carousel-depth.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DepthImage {\n  src?: string;\n  title?: string;\n  caption?: string;\n}\n\nexport interface CarouselDepthProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"onChange\" | \"defaultValue\"> {\n  images?: DepthImage[];\n  value?: number;\n  defaultValue?: number;\n  onChange?: (index: number) => void;\n  autoplay?: boolean;\n  interval?: number;\n  loop?: boolean;\n  accent?: string;\n  label?: string;\n}\n\nconst defaultImages: DepthImage[] = [\n  { title: \"Aurora Basin\", caption: \"Iceland\" },\n  { title: \"Terracotta Row\", caption: \"Marrakech\" },\n  { title: \"Night Ferry\", caption: \"Hong Kong\" },\n  { title: \"Salt Flats\", caption: \"Bolivia\" },\n  { title: \"Cedar Hollow\", caption: \"Oregon\" },\n  { title: \"Glass Tower\", caption: \"Singapore\" },\n  { title: \"Blue Hour\", caption: \"Lisbon\" },\n];\n\nconst css = `\n.hb-qu2 {\n  --hb-qu2-a: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  min-height: 180px;\n  overflow: hidden;\n  container-type: size;\n  perspective: 900px;\n  font-family: inherit;\n  color: #ededed;\n  background:\n    radial-gradient(ellipse at 50% 55%, color-mix(in srgb, var(--hb-qu2-a) 18%, transparent) 0%, transparent 60%),\n    #0a0a0a;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: pan-y;\n}\n.hb-qu2 *, .hb-qu2 *::before, .hb-qu2 *::after { box-sizing: border-box; }\n.hb-qu2:focus-visible { outline: 2px solid var(--hb-qu2-a); outline-offset: -2px; }\n.hb-qu2-slide {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  height: 74cqh;\n  width: calc(74cqh * 0.8);\n  overflow: hidden;\n  border-radius: 14px;\n  background: #111111;\n  cursor: pointer;\n  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.1);\n  will-change: transform, opacity;\n}\n.hb-qu2-slide[data-active=\"true\"] {\n  cursor: default;\n  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px color-mix(in srgb, var(--hb-qu2-a) 55%, transparent);\n}\n.hb-qu2[data-drag=\"true\"] .hb-qu2-slide { cursor: grabbing; }\n.hb-qu2-img {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  background-size: cover;\n  background-position: center;\n  pointer-events: none;\n}\n.hb-qu2-art { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }\n.hb-qu2-cap {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  padding: 26px 11px 10px;\n  background: linear-gradient(to top, rgba(0, 0, 0, 0.78), transparent);\n  pointer-events: none;\n}\n.hb-qu2-title {\n  display: block;\n  font-size: 13px;\n  font-weight: 650;\n  line-height: 1.2;\n  color: #ffffff;\n}\n.hb-qu2-sub {\n  display: block;\n  margin-top: 2px;\n  font-size: 10px;\n  line-height: 1.2;\n  letter-spacing: 0.06em;\n  text-transform: uppercase;\n  color: rgba(255, 255, 255, 0.68);\n}\n.hb-qu2-arrow {\n  position: absolute;\n  top: 50%;\n  z-index: 200;\n  display: grid;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  margin: -15px 0 0;\n  padding: 0;\n  color: #ededed;\n  background: rgba(17, 17, 17, 0.8);\n  border: 1px solid #262626;\n  border-radius: 999px;\n  cursor: pointer;\n  backdrop-filter: blur(6px);\n  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;\n}\n.hb-qu2-arrow[data-dir=\"prev\"] { left: 8px; }\n.hb-qu2-arrow[data-dir=\"next\"] { right: 8px; }\n.hb-qu2-arrow:hover:not(:disabled) { background: #171717; border-color: var(--hb-qu2-a); }\n.hb-qu2-arrow:active:not(:disabled) { transform: scale(0.92); }\n.hb-qu2-arrow:disabled { opacity: 0.35; cursor: default; }\n.hb-qu2-arrow:focus-visible, .hb-qu2-dot:focus-visible { outline: 2px solid var(--hb-qu2-a); outline-offset: 2px; }\n.hb-qu2-dots {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 6px;\n  z-index: 200;\n  display: flex;\n  justify-content: center;\n  gap: 0;\n}\n.hb-qu2-dot {\n  display: grid;\n  place-items: center;\n  width: 16px;\n  height: 16px;\n  margin: 0;\n  padding: 0;\n  background: none;\n  border: 0;\n  cursor: pointer;\n}\n.hb-qu2-dot::before {\n  content: \"\";\n  width: 6px;\n  height: 6px;\n  border-radius: 999px;\n  background: rgba(255, 255, 255, 0.28);\n  transition: width 0.3s ease, background 0.3s ease;\n}\n.hb-qu2-dot[aria-current=\"true\"]::before { width: 16px; background: var(--hb-qu2-a); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qu2-slide { will-change: auto; }\n  .hb-qu2-arrow, .hb-qu2-dot::before { transition: none; }\n}\n`;\n\nfunction hash(n: number) {\n  let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);\n  h ^= h >>> 13;\n  h = Math.imul(h, 0xc2b2ae35);\n  h ^= h >>> 16;\n  return h >>> 0;\n}\n\ninterface Api {\n  moveTo: (t: number, notify: boolean) => void;\n  go: (i: number, notify: boolean) => void;\n  step: (d: number) => void;\n  drag: (p: number) => void;\n  release: (v: number) => void;\n}\n\nconst noop = () => undefined;\n\nfunction mod(a: number, n: number) {\n  return ((a % n) + n) % n;\n}\n\nfunction Scene({ index }: { index: number }) {\n  const hue = (index * 53 + 12) % 360;\n  const a = hash(index + 7);\n  const b = hash(index + 211);\n  const sunX = 18 + (a % 64);\n  const sunY = 16 + (b % 20);\n  const m1 = 56 + (a % 12);\n  const m2 = 70 + (b % 10);\n  return (\n    <>\n      <div\n        className=\"hb-qu2-img\"\n        style={{\n          background: `linear-gradient(170deg, hsl(${hue} 72% 58%) 0%, hsl(${(hue + 46) % 360} 76% 44%) 58%, hsl(${(hue + 80) % 360} 58% 20%) 100%)`,\n        }}\n      />\n      <svg className=\"hb-qu2-art\" viewBox=\"0 0 100 125\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <circle cx={sunX} cy={sunY} r=\"10\" fill={`hsl(${(hue + 28) % 360} 95% 90%)`} opacity=\"0.9\" />\n        <polygon\n          points={`0,125 0,${m1} ${30 + (a % 36)},${m1 - 26} 100,${m1 + 4} 100,125`}\n          fill={`hsl(${hue} 52% 26%)`}\n          opacity=\"0.8\"\n        />\n        <polygon\n          points={`0,125 0,${m2 + 6} ${44 + (b % 36)},${m2 - 10} 100,${m2 + 8} 100,125`}\n          fill={`hsl(${hue} 48% 13%)`}\n          opacity=\"0.92\"\n        />\n      </svg>\n    </>\n  );\n}\n\nfunction slideStyle(o: number) {\n  const a = Math.abs(o);\n  const sign = o < 0 ? -1 : 1;\n  const x = sign * (a < 1 ? 30 * a : 30 + (a - 1) * 19);\n  const scale = 1 - 0.1 * Math.min(a, 2.2);\n  const ry = -Math.max(-1.5, Math.min(1.5, o)) * 40;\n  const z = -Math.min(a, 2) * 70;\n  const br = 1 - 0.5 * Math.min(a, 1.3);\n  const op = a <= 1.4 ? 1 : Math.max(0, 1 - (a - 1.4) / 0.9);\n  return {\n    transform: `translate(-50%, -50%) translateX(${x.toFixed(3)}cqw) translateZ(${z.toFixed(2)}px) rotateY(${ry.toFixed(2)}deg) scale(${scale.toFixed(4)})`,\n    filter: `brightness(${br.toFixed(3)})`,\n    opacity: op.toFixed(3),\n    zIndex: Math.round(100 - a * 10),\n    pointerEvents: (op <= 0.01 ? \"none\" : \"auto\") as React.CSSProperties[\"pointerEvents\"],\n  };\n}\n\nexport function CarouselDepth({\n  images = defaultImages,\n  value,\n  defaultValue = 0,\n  onChange,\n  autoplay = true,\n  interval = 3200,\n  loop = true,\n  accent = \"#2f7bff\",\n  label = \"Image carousel\",\n  className = \"\",\n  style,\n  ...rest\n}: CarouselDepthProps) {\n  const n = images.length;\n  const wrap = loop && n >= 6;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue);\n  const index = Math.max(0, Math.min(Math.max(0, n - 1), controlled ? value : inner));\n  const [pos, setPos] = React.useState(index);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const posRef = React.useRef(index);\n  const targetRef = React.useRef(index);\n  const raf = React.useRef(0);\n  const flags = React.useRef({ hover: false, focus: false, drag: false, visible: true });\n  const api = React.useRef<Api>({\n    moveTo: noop,\n    go: noop,\n    step: noop,\n    drag: noop,\n    release: noop,\n  });\n\n  React.useEffect(() => {\n    function kick() {\n      if (raf.current) return;\n      let prev = performance.now();\n      const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n      const step = (now: number) => {\n        const dt = Math.min(0.05, Math.max(0, (now - prev) / 1000));\n        prev = now;\n        const diff = targetRef.current - posRef.current;\n        if (reduce || Math.abs(diff) < 0.002) {\n          posRef.current = targetRef.current;\n          raf.current = 0;\n          setPos(posRef.current);\n          return;\n        }\n        posRef.current += diff * (1 - Math.exp(-dt * 8));\n        setPos(posRef.current);\n        raf.current = requestAnimationFrame(step);\n      };\n      raf.current = requestAnimationFrame(step);\n    }\n\n    function moveTo(t: number, notify: boolean) {\n      const tgt = wrap ? t : Math.max(0, Math.min(n - 1, t));\n      targetRef.current = tgt;\n      kick();\n      const ni = wrap ? mod(tgt, n) : tgt;\n      if (!controlled) setInner(ni);\n      if (notify) onChange?.(ni);\n    }\n\n    function go(i: number, notify: boolean) {\n      const cur = Math.round(posRef.current);\n      if (wrap) {\n        let diff = i - mod(cur, n);\n        if (diff > n / 2) diff -= n;\n        if (diff < -n / 2) diff += n;\n        moveTo(cur + diff, notify);\n      } else {\n        moveTo(i, notify);\n      }\n    }\n\n    api.current = {\n      moveTo,\n      go,\n      step: (d: number) => moveTo(Math.round(posRef.current) + d, true),\n      drag: (p: number) => {\n        posRef.current = wrap ? p : Math.max(-0.5, Math.min(n - 0.5, p));\n        setPos(posRef.current);\n      },\n      release: (v: number) => {\n        const base = Math.round(posRef.current - v * 0.18);\n        const cur = Math.round(posRef.current);\n        moveTo(Math.max(cur - 2, Math.min(cur + 2, base)), true);\n      },\n    };\n  });\n\n  React.useEffect(() => {\n    const cur = targetRef.current;\n    const curIdx = wrap ? mod(cur, n) : cur;\n    if (curIdx !== index) api.current.go(index, false);\n  }, [index, wrap, n]);\n\n  React.useEffect(() => {\n    return () => cancelAnimationFrame(raf.current);\n  }, []);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const f = flags.current;\n    const g = { id: -1, active: false, startX: 0, startPos: 0, lastX: 0, lastT: 0, v: 0, step: 100 };\n\n    function onDown(e: PointerEvent) {\n      if (e.pointerType === \"mouse\" && e.button !== 0) return;\n      if ((e.target as Element).closest(\"button\")) return;\n      g.id = e.pointerId;\n      g.active = false;\n      g.startX = e.clientX;\n      g.startPos = posRef.current;\n      g.lastX = e.clientX;\n      g.lastT = e.timeStamp;\n      g.v = 0;\n      g.step = Math.max(60, root!.clientWidth * 0.3);\n    }\n\n    function onMove(e: PointerEvent) {\n      if (e.pointerId !== g.id) return;\n      const dx = e.clientX - g.startX;\n      if (!g.active) {\n        if (Math.abs(dx) < 6) return;\n        g.active = true;\n        f.drag = true;\n        cancelAnimationFrame(raf.current);\n        raf.current = 0;\n        root!.dataset.drag = \"true\";\n        root!.setPointerCapture(e.pointerId);\n      }\n      const dtm = Math.max(0.001, (e.timeStamp - g.lastT) / 1000);\n      g.v = g.v * 0.6 + (-(e.clientX - g.lastX) / g.step / dtm) * 0.4;\n      g.lastX = e.clientX;\n      g.lastT = e.timeStamp;\n      api.current.drag(g.startPos - dx / g.step);\n    }\n\n    function onUp(e: PointerEvent) {\n      if (e.pointerId !== g.id) return;\n      g.id = -1;\n      if (!g.active) return;\n      g.active = false;\n      f.drag = false;\n      root!.dataset.drag = \"false\";\n      if (root!.hasPointerCapture(e.pointerId)) root!.releasePointerCapture(e.pointerId);\n      api.current.release(g.v);\n    }\n\n    function onKey(e: KeyboardEvent) {\n      if (e.key === \"ArrowRight\") {\n        e.preventDefault();\n        api.current.step(1);\n      } else if (e.key === \"ArrowLeft\") {\n        e.preventDefault();\n        api.current.step(-1);\n      } else if (e.key === \"Home\") {\n        e.preventDefault();\n        api.current.go(0, true);\n      } else if (e.key === \"End\") {\n        e.preventDefault();\n        api.current.go(n - 1, true);\n      }\n    }\n\n    function onEnter(e: PointerEvent) {\n      if (e.pointerType === \"mouse\") f.hover = true;\n    }\n    function onLeave() {\n      f.hover = false;\n    }\n    function onFocusIn() {\n      f.focus = true;\n    }\n    function onFocusOut() {\n      f.focus = false;\n    }\n\n    root.addEventListener(\"pointerdown\", onDown);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"pointercancel\", onUp);\n    root.addEventListener(\"pointerenter\", onEnter);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"focusin\", onFocusIn);\n    root.addEventListener(\"focusout\", onFocusOut);\n    root.addEventListener(\"keydown\", onKey);\n    const io = new IntersectionObserver((entries) => {\n      for (const entry of entries) f.visible = entry.isIntersecting;\n    });\n    io.observe(root);\n    return () => {\n      io.disconnect();\n      root.removeEventListener(\"pointerdown\", onDown);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"pointercancel\", onUp);\n      root.removeEventListener(\"pointerenter\", onEnter);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n      root.removeEventListener(\"keydown\", onKey);\n    };\n  }, [n]);\n\n  React.useEffect(() => {\n    if (!autoplay || n < 2) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const f = flags.current;\n    const id = window.setInterval(() => {\n      if (f.hover || f.focus || f.drag || !f.visible) return;\n      const cur = Math.round(posRef.current);\n      if (wrap) api.current.moveTo(cur + 1, true);\n      else api.current.go(mod(cur + 1, n), true);\n    }, Math.max(800, interval));\n    return () => window.clearInterval(id);\n  }, [autoplay, interval, n, wrap]);\n\n  const active = wrap ? mod(Math.round(pos), n) : Math.max(0, Math.min(n - 1, Math.round(pos)));\n  const vars = { \"--hb-qu2-a\": accent, ...style } as React.CSSProperties;\n  const atStart = !wrap && Math.round(pos) <= 0;\n  const atEnd = !wrap && Math.round(pos) >= n - 1;\n\n  return (\n    <>\n      <style href=\"hb-carousel-depth\" precedence=\"default\">{css}</style>\n      <div\n        ref={rootRef}\n        role=\"region\"\n        aria-roledescription=\"carousel\"\n        aria-label={label}\n        tabIndex={0}\n        data-drag=\"false\"\n        className={`hb-qu2 ${className}`}\n        style={vars}\n        {...rest}\n      >\n        {images.map((img, i) => {\n          let o = i - pos;\n          if (wrap) o -= n * Math.round(o / n);\n          const isActive = i === active;\n          return (\n            <div\n              key={i}\n              role=\"group\"\n              aria-roledescription=\"slide\"\n              aria-label={`${i + 1} of ${n}`}\n              aria-hidden={isActive ? undefined : true}\n              data-active={isActive}\n              className=\"hb-qu2-slide\"\n              style={slideStyle(o)}\n              onClick={() => {\n                if (!isActive) api.current.go(i, true);\n              }}\n            >\n              {img.src ? (\n                <div className=\"hb-qu2-img\" style={{ backgroundImage: `url(\"${img.src}\")` }} />\n              ) : (\n                <Scene index={i} />\n              )}\n              {img.title || img.caption ? (\n                <div className=\"hb-qu2-cap\">\n                  {img.title ? <span className=\"hb-qu2-title\">{img.title}</span> : null}\n                  {img.caption ? <span className=\"hb-qu2-sub\">{img.caption}</span> : null}\n                </div>\n              ) : null}\n            </div>\n          );\n        })}\n        <button\n          type=\"button\"\n          className=\"hb-qu2-arrow\"\n          data-dir=\"prev\"\n          aria-label=\"Previous slide\"\n          disabled={atStart}\n          onClick={() => api.current.step(-1)}\n        >\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M15 5l-7 7 7 7\" />\n          </svg>\n        </button>\n        <button\n          type=\"button\"\n          className=\"hb-qu2-arrow\"\n          data-dir=\"next\"\n          aria-label=\"Next slide\"\n          disabled={atEnd}\n          onClick={() => api.current.step(1)}\n        >\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M9 5l7 7-7 7\" />\n          </svg>\n        </button>\n        <div className=\"hb-qu2-dots\">\n          {images.map((_, i) => (\n            <button\n              key={i}\n              type=\"button\"\n              className=\"hb-qu2-dot\"\n              aria-label={`Go to slide ${i + 1}`}\n              aria-current={i === active}\n              onClick={() => api.current.go(i, true)}\n            />\n          ))}\n        </div>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}