{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"bend-ribbon","type":"registry:ui","title":"Bend Ribbon","description":"An endless ribbon of images bent along an arc that you scroll, drag or arrow through, easing to a snap.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/bend-ribbon.tsx","type":"registry:ui","content":"\"use client\";\n/* eslint-disable @next/next/no-img-element */\n\nimport { useEffect, useRef, type KeyboardEvent } from \"react\";\n\nexport interface BendRibbonItem {\n  image: string;\n  text?: string;\n}\n\nexport interface BendRibbonProps {\n  items: BendRibbonItem[];\n  /** Card width in px. */\n  itemWidth?: number;\n  /** Card image height in px. */\n  itemHeight?: number;\n  /** Px between cards along the arc. */\n  gap?: number;\n  /** Curvature of the arc. 0 is flat, negative flips it into a bowl. */\n  bend?: number;\n  /** Wheel/drag multiplier. */\n  scrollSpeed?: number;\n  /** Easing towards the scroll target, 0-1 (lower = floatier). */\n  ease?: number;\n  /** Idle drift in px per second. 0 disables. */\n  autoScroll?: number;\n  /** Corner radius in px. */\n  radius?: number;\n  className?: string;\n}\n\nexport function BendRibbon({\n  items,\n  itemWidth = 240,\n  itemHeight = 300,\n  gap = 36,\n  bend = 2,\n  scrollSpeed = 1,\n  ease = 0.08,\n  autoScroll = 24,\n  radius = 16,\n  className,\n}: BendRibbonProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const cards = useRef<(HTMLDivElement | null)[]>([]);\n  const state = useRef({ cur: 0, target: 0, hover: false, drag: null as null | { x: number; t: number }, nudge: () => {} });\n  // Repeat short lists so the loop never shows a gap.\n  const repeat = Math.max(1, Math.ceil(10 / Math.max(1, items.length)));\n  const list = Array.from({ length: repeat }, () => items).flat();\n  const stride = itemWidth + gap;\n\n  useEffect(() => {\n    const el = root.current!;\n    const s = state.current;\n    const reduce = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const total = list.length * stride;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let snapTimer = 0;\n\n    const snap = () => {\n      s.target = Math.round(s.target / stride) * stride;\n    };\n\n    const layout = () => {\n      const w = el.clientWidth;\n      const R = bend === 0 ? Infinity : (w * 2) / Math.abs(bend);\n      const dir = Math.sign(bend) || 1;\n      for (let i = 0; i < cards.current.length; i++) {\n        const card = cards.current[i];\n        if (!card) continue;\n        const raw = i * stride - s.cur;\n        const u = ((((raw + total / 2) % total) + total) % total) - total / 2;\n        const a = u / R;\n        const x = R === Infinity ? u : R * Math.sin(a);\n        const y = R === Infinity ? 0 : dir * R * (1 - Math.cos(a));\n        const hidden = Math.abs(a) > 1.4 || Math.abs(x) > w / 2 + itemWidth;\n        card.style.transform = `translate3d(${x - itemWidth / 2}px, ${y}px, 0) rotate(${dir * a}rad)`;\n        card.style.visibility = hidden ? \"hidden\" : \"visible\";\n      }\n    };\n\n    const tick = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      if (!reduce && autoScroll && !s.hover && !s.drag) s.target += autoScroll * dt;\n      s.cur += (s.target - s.cur) * (reduce ? 1 : ease);\n      layout();\n      raf = visible ? requestAnimationFrame(tick) : 0;\n    };\n    const start = () => {\n      if (!raf && visible) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    };\n    s.nudge = start;\n\n    const io = new IntersectionObserver(([e]) => {\n      visible = e.isIntersecting;\n      start();\n    });\n    io.observe(el);\n\n    const onWheel = (e: WheelEvent) => {\n      e.preventDefault();\n      s.target += (Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY) * scrollSpeed * 0.6;\n      window.clearTimeout(snapTimer);\n      snapTimer = window.setTimeout(snap, 180);\n      start();\n    };\n    el.addEventListener(\"wheel\", onWheel, { passive: false });\n    layout();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearTimeout(snapTimer);\n      io.disconnect();\n      el.removeEventListener(\"wheel\", onWheel);\n    };\n  }, [list.length, stride, bend, scrollSpeed, ease, autoScroll, itemWidth]);\n\n  const onKey = (e: KeyboardEvent) => {\n    const s = state.current;\n    const dir = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : 0;\n    if (!dir) return;\n    e.preventDefault();\n    s.target = Math.round(s.target / stride + dir) * stride;\n    s.nudge();\n  };\n\n  return (\n    <div\n      ref={root}\n      role=\"region\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"Gallery. Drag, scroll or use arrow keys.\"\n      tabIndex={0}\n      onKeyDown={onKey}\n      onPointerEnter={() => (state.current.hover = true)}\n      onPointerLeave={() => (state.current.hover = false)}\n      onPointerDown={(e) => {\n        e.currentTarget.setPointerCapture(e.pointerId);\n        state.current.drag = { x: e.clientX, t: state.current.target };\n      }}\n      onPointerMove={(e) => {\n        const d = state.current.drag;\n        if (!d) return;\n        state.current.target = d.t - (e.clientX - d.x) * scrollSpeed * 1.4;\n        state.current.nudge();\n      }}\n      onPointerUp={() => {\n        const s = state.current;\n        s.drag = null;\n        s.target = Math.round(s.target / stride) * stride;\n      }}\n      onPointerCancel={() => (state.current.drag = null)}\n      className={`relative w-full cursor-grab select-none overflow-hidden outline-none focus-visible:ring-2 focus-visible:ring-ring active:cursor-grabbing ${className ?? \"\"}`}\n      style={{\n        height: itemHeight + 190,\n        touchAction: \"pan-y\",\n        maskImage: \"linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent)\",\n        WebkitMaskImage: \"linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent)\",\n      }}\n    >\n      {list.map((item, i) => (\n        <div\n          key={i}\n          ref={(el) => {\n            cards.current[i] = el;\n          }}\n          aria-hidden={i >= items.length || undefined}\n          className=\"absolute left-1/2 top-6 will-change-transform\"\n          style={{ width: itemWidth, transformOrigin: \"50% 50%\", visibility: \"hidden\" }}\n        >\n          <img\n            src={item.image}\n            alt={item.text ?? \"\"}\n            draggable={false}\n            className=\"pointer-events-none w-full bg-muted object-cover shadow-[0_20px_40px_-18px_rgba(0,0,0,.8)]\"\n            style={{ height: itemHeight, borderRadius: radius }}\n          />\n          {item.text && <p className=\"mt-4 text-center text-lg font-semibold tracking-tight text-foreground\">{item.text}</p>}\n        </div>\n      ))}\n    </div>\n  );\n}\n"}]}