{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"logo-marquee","type":"registry:ui","title":"Logo Marquee","description":"An endless row of logos with faded edges that slows to a stop on hover.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/logo-marquee.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { animate, motion, useAnimationFrame, useMotionValue, useReducedMotion } from \"motion/react\";\nimport { useEffect, useRef, useState, type ReactNode } from \"react\";\n\ntype LogoMarqueeProps = {\n  items: ReactNode[];\n  /** Scroll speed in pixels per second. */\n  speed?: number;\n  direction?: \"left\" | \"right\";\n  /** Ease to a stop while the pointer or keyboard focus is on the row. */\n  pauseOnHover?: boolean;\n  /** Space between items, in pixels. */\n  gap?: number;\n  /** Fade the row out at both edges. */\n  fade?: boolean;\n  className?: string;\n};\n\nconst EDGE_FADE = \"linear-gradient(to right, transparent, #000 12%, #000 88%, transparent)\";\n\n/** An endless row of logos or any other items, with faded edges and a pause on hover. */\nexport function LogoMarquee({\n  items,\n  speed = 40,\n  direction = \"left\",\n  pauseOnHover = true,\n  gap = 48,\n  fade = true,\n  className = \"\",\n}: LogoMarqueeProps) {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLDivElement>(null);\n  const setRef = useRef<HTMLUListElement>(null);\n  const [setWidth, setSetWidth] = useState(0);\n  const [copies, setCopies] = useState(2);\n  const x = useMotionValue(0);\n  // 1 is full speed, 0 is stopped. Animated so hover slows the row down instead of freezing it.\n  const pace = useMotionValue(1);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const set = setRef.current;\n    if (!root || !set) return;\n    const observer = new ResizeObserver(() => {\n      const width = set.offsetWidth;\n      setSetWidth(width);\n      // Enough copies to cover the row while one of them is scrolled out of view.\n      setCopies(width > 0 ? Math.max(2, Math.ceil(root.offsetWidth / width) + 1) : 2);\n    });\n    observer.observe(root);\n    observer.observe(set);\n    return () => observer.disconnect();\n  }, [reduce]);\n\n  useAnimationFrame((_, delta) => {\n    if (reduce || setWidth <= 0) return;\n    const step = (direction === \"left\" ? -1 : 1) * speed * pace.get() * (Math.min(delta, 64) / 1000);\n    // Keep x within one set width, so the loop never runs out of copies.\n    const next = x.get() + step;\n    x.set((((next % setWidth) + setWidth) % setWidth) - setWidth);\n  });\n\n  function setPaused(paused: boolean) {\n    if (!pauseOnHover) return;\n    animate(pace, paused ? 0 : 1, { duration: paused ? 0.35 : 0.6, ease: \"easeOut\" });\n  }\n\n  const mask = fade ? EDGE_FADE : undefined;\n\n  if (reduce) {\n    // No scrolling: show every item once, wrapped and centered.\n    return (\n      <div ref={rootRef} className={`relative ${className}`}>\n        <ul ref={setRef} className=\"flex flex-wrap items-center justify-center\" style={{ gap }}>\n          {items.map((item, i) => (\n            <li key={i} className=\"shrink-0\">\n              {item}\n            </li>\n          ))}\n        </ul>\n      </div>\n    );\n  }\n\n  return (\n    <div\n      ref={rootRef}\n      className={`relative overflow-hidden ${className}`}\n      style={{ maskImage: mask, WebkitMaskImage: mask }}\n      onPointerEnter={() => setPaused(true)}\n      onPointerLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setPaused(false);\n      }}\n    >\n      <motion.div className=\"flex w-max will-change-transform\" style={{ x }}>\n        {Array.from({ length: copies }, (_, copy) => (\n          // Only the first copy is read by screen readers and reachable by keyboard.\n          <ul\n            key={copy}\n            ref={copy === 0 ? setRef : undefined}\n            aria-hidden={copy > 0 ? true : undefined}\n            inert={copy > 0}\n            className=\"flex shrink-0 items-center\"\n            style={{ gap, paddingRight: gap }}\n          >\n            {items.map((item, i) => (\n              <li key={i} className=\"shrink-0\">\n                {item}\n              </li>\n            ))}\n          </ul>\n        ))}\n      </motion.div>\n    </div>\n  );\n}\n"}]}