{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "marquee",
  "title": "Marquee",
  "description": "Content scrolling in a seamless loop, pausing on focus and off screen, and draggable by the pointer.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/use-in-view",
    "@corsair-ui/use-media-query"
  ],
  "files": [
    {
      "path": "registry/default/ui/marquee.tsx",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useMemo,\n  useRef,\n  type ComponentProps,\n  type CSSProperties,\n  type DragEvent,\n  type MouseEvent,\n  type PointerEvent,\n  type Ref,\n} from \"react\";\n\nimport { useInView } from \"@/registry/default/hooks/use-in-view\";\nimport { useMediaQuery } from \"@/registry/default/hooks/use-media-query\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\n/** How far, in px, the pointer moves before a press becomes a drag, so taps and clicks on links still work. */\nconst DRAG_THRESHOLD = 5;\n\ninterface MarqueeProps extends Omit<ComponentProps<\"div\">, \"draggable\"> {\n  /** Which way the content travels. */\n  direction?: \"left\" | \"right\" | \"up\" | \"down\";\n  /** Seconds for the content to travel its own length. */\n  duration?: number;\n  /** Space between items, and between the end of the content and its next copy. Any CSS length. */\n  gap?: string;\n  /** Hold still while the pointer is over it. */\n  pauseOnHover?: boolean;\n  /**\n   * Hold it still from outside, for example while a dialog opened from it\n   * is up. It carries on from the same place once this is false again.\n   */\n  paused?: boolean;\n  /** Fade the content out at both edges. */\n  fade?: boolean;\n  /** How much of each edge the fade covers, in percent. */\n  fadeAmount?: number;\n  /**\n   * Copies of the content in the loop. Two are enough when the content is\n   * at least as long as the marquee; raise it for short content in a wide one.\n   */\n  repeat?: number;\n  /**\n   * Names the marquee for screen readers when `prefers-reduced-motion` turns\n   * it into a box you scroll by hand: it then becomes a focusable region, so\n   * keyboard users can scroll it too.\n   */\n  label?: string;\n  /**\n   * Let the pointer grab the loop and drag it either way; it carries on from\n   * where it is let go. A press that moves less than a few pixels is still a\n   * click, so links inside keep working. With `prefers-reduced-motion` the\n   * marquee is a scroll box instead, and this does nothing.\n   */\n  draggable?: boolean;\n}\n\n/** The loop's CSS animation on the track, where the browser supports looking it up. */\nfunction loopAnimation(track: HTMLElement | null) {\n  return track\n    ?.getAnimations?.()\n    .find((animation) => (animation as CSSAnimation).animationName?.startsWith(\"marquee\"));\n}\n\n/**\n * Content that scrolls in an endless loop: logos, quotes, ports of call.\n * It is one CSS animation of a transform. The copies that make the loop\n * seamless are hidden from screen readers and cannot take focus; the loop\n * stops while a link inside has keyboard focus, and pauses off screen.\n * With `prefers-reduced-motion` it holds still and scrolls by hand instead.\n * With `draggable`, the pointer can grab the loop: dragging seeks the same\n * CSS animation, so the loop stays seamless and there are no scroll listeners.\n *\n * @example\n * <Marquee pauseOnHover gap=\"3rem\">\n *   <span>Salvador</span>\n *   <span>Cartagena</span>\n *   <span>Havana</span>\n * </Marquee>\n */\nfunction Marquee({\n  direction = \"left\",\n  duration = 20,\n  gap = \"1rem\",\n  pauseOnHover = false,\n  paused = false,\n  fade = true,\n  fadeAmount = 10,\n  repeat = 2,\n  label = \"Scrolling content\",\n  draggable = false,\n  className,\n  style,\n  ref,\n  children,\n  onPointerDown,\n  onPointerMove,\n  onPointerUp,\n  onPointerCancel,\n  onClickCapture,\n  onDragStart,\n  ...props\n}: MarqueeProps) {\n  const [observe, inView] = useInView<HTMLDivElement>({ rootMargin: \"100px\" });\n  const reduced = useMediaQuery(\"(prefers-reduced-motion: reduce)\");\n  const root = useRef<HTMLDivElement>(null);\n  const mergedRef = useMemo(() => mergeRefs(ref, observe, root), [ref, observe]);\n  // A scroll box has to be reachable from the keyboard. Set on the element, and\n  // only while it is one, so the moving marquee stays out of the tab order.\n  useEffect(() => {\n    const element = root.current;\n    if (!element) return;\n    if (reduced) element.tabIndex = 0;\n    else element.removeAttribute(\"tabindex\");\n  }, [reduced]);\n\n  const vertical = direction === \"up\" || direction === \"down\";\n  const reversed = direction === \"right\" || direction === \"down\";\n  const copies = Math.max(2, Math.floor(repeat));\n\n  const track = useRef<HTMLDivElement>(null);\n  const drag = useRef<{ pointerId: number; start: number; last: number; moving: boolean }>(null);\n  // Set when a drag ends, so the click the browser fires after it does not follow a link.\n  const dragged = useRef(false);\n  const position = (event: PointerEvent<HTMLElement>) => (vertical ? event.clientY : event.clientX);\n\n  // Moves the loop by `distance` px by seeking its animation. Setting the\n  // time (rather than calling pause or play) keeps CSS in charge of pausing.\n  const seek = (distance: number) => {\n    const animation = loopAnimation(track.current);\n    if (!animation || !track.current) return;\n    const box = track.current.getBoundingClientRect();\n    const length = (vertical ? box.height : box.width) / copies;\n    const period = Number(animation.effect?.getComputedTiming().duration);\n    if (!length || !period) return;\n    // Forwards, the track moves towards the start as time runs; reversed, away from it.\n    const time =\n      Number(animation.currentTime ?? 0) + (distance / length) * period * (reversed ? 1 : -1);\n    animation.currentTime = ((time % period) + period) % period;\n  };\n\n  const endDrag = (event: PointerEvent<HTMLDivElement>, cancelled: boolean) => {\n    const current = drag.current;\n    if (!current || current.pointerId !== event.pointerId) return;\n    drag.current = null;\n    if (!current.moving) return;\n    if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n      event.currentTarget.releasePointerCapture(event.pointerId);\n    }\n    event.currentTarget.removeAttribute(\"data-dragging\");\n    dragged.current = !cancelled;\n  };\n\n  const dragHandlers = draggable\n    ? {\n        onPointerDown(event: PointerEvent<HTMLDivElement>) {\n          onPointerDown?.(event);\n          dragged.current = false;\n          if (event.defaultPrevented || event.button !== 0 || drag.current) return;\n          const start = position(event);\n          drag.current = { pointerId: event.pointerId, start, last: start, moving: false };\n        },\n        onPointerMove(event: PointerEvent<HTMLDivElement>) {\n          onPointerMove?.(event);\n          const current = drag.current;\n          if (!current || current.pointerId !== event.pointerId) return;\n          const now = position(event);\n          if (!current.moving) {\n            if (Math.abs(now - current.start) < DRAG_THRESHOLD) return;\n            // Only now, so a plain click still lands on the link under the pointer.\n            current.moving = true;\n            event.currentTarget.setPointerCapture(event.pointerId);\n            event.currentTarget.setAttribute(\"data-dragging\", \"true\");\n            // Pressing a link focuses it, and focus inside pauses the loop; a drag is not a visit.\n            const focused = document.activeElement;\n            if (focused instanceof HTMLElement && event.currentTarget.contains(focused)) {\n              focused.blur();\n            }\n          }\n          seek(now - current.last);\n          current.last = now;\n        },\n        onPointerUp(event: PointerEvent<HTMLDivElement>) {\n          onPointerUp?.(event);\n          endDrag(event, false);\n        },\n        onPointerCancel(event: PointerEvent<HTMLDivElement>) {\n          onPointerCancel?.(event);\n          endDrag(event, true);\n        },\n        onClickCapture(event: MouseEvent<HTMLDivElement>) {\n          onClickCapture?.(event);\n          if (!dragged.current) return;\n          dragged.current = false;\n          event.preventDefault();\n          event.stopPropagation();\n        },\n        // Links and images would otherwise start a native drag and steal the pointer.\n        onDragStart(event: DragEvent<HTMLDivElement>) {\n          onDragStart?.(event);\n          event.preventDefault();\n        },\n      }\n    : { onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onClickCapture, onDragStart };\n  const edge = Math.min(Math.max(fadeAmount, 0), 50);\n  const mask = fade\n    ? `linear-gradient(to ${vertical ? \"bottom\" : \"right\"}, transparent, #000 ${edge}%, #000 ${100 - edge}%, transparent)`\n    : undefined;\n\n  return (\n    <div\n      ref={mergedRef}\n      data-slot=\"marquee\"\n      data-direction={direction}\n      data-paused={paused ? \"\" : undefined}\n      data-draggable={draggable ? \"\" : undefined}\n      // Still, it scrolls by hand: a named region, focusable (set below) for the keyboard.\n      role={reduced ? \"region\" : undefined}\n      aria-label={reduced ? label : undefined}\n      className={cn(\n        \"group/marquee flex overflow-hidden motion-reduce:overflow-auto\",\n        vertical && \"flex-col\",\n        // Touch pans across the loop go to the drag; the page still scrolls the other way.\n        draggable && \"motion-safe:cursor-grab motion-safe:select-none\",\n        draggable && (vertical ? \"motion-safe:touch-pan-x\" : \"motion-safe:touch-pan-y\"),\n        draggable && \"data-[dragging=true]:cursor-grabbing\",\n        className\n      )}\n      style={\n        {\n          \"--marquee-gap\": gap,\n          \"--marquee-copies\": copies,\n          maskImage: mask,\n          WebkitMaskImage: mask,\n          ...style,\n        } as CSSProperties\n      }\n      {...props}\n      {...dragHandlers}\n    >\n      <div\n        ref={track}\n        data-slot=\"marquee-track\"\n        className={cn(\n          \"flex w-max shrink-0 group-focus-within/marquee:[animation-play-state:paused]\",\n          // Held while dragged; the drag moves it by seeking the animation.\n          \"group-data-[dragging=true]/marquee:[animation-play-state:paused]\",\n          vertical\n            ? \"motion-safe:animate-marquee-y h-max w-full flex-col\"\n            : \"motion-safe:animate-marquee-x\",\n          pauseOnHover && \"group-hover/marquee:[animation-play-state:paused]\"\n        )}\n        style={{\n          // Each loop moves the track by one copy of the content.\n          animationDuration: `${duration}s`,\n          animationDirection: reversed ? \"reverse\" : undefined,\n          // Inline only when held or off screen, so hover and focus can still pause it.\n          animationPlayState: paused || !inView ? \"paused\" : undefined,\n        }}\n      >\n        {Array.from({ length: copies }, (_, copy) => (\n          <div\n            key={copy}\n            data-slot=\"marquee-group\"\n            aria-hidden={copy > 0 ? true : undefined}\n            inert={copy > 0 ? true : undefined}\n            className={cn(\n              \"flex shrink-0 gap-[var(--marquee-gap)]\",\n              // Trailing space the size of the gap, so every copy is the same length and the loop has no seam.\n              vertical\n                ? \"flex-col pb-[var(--marquee-gap)]\"\n                : \"items-center pr-[var(--marquee-gap)]\",\n              copy > 0 && \"motion-reduce:hidden\"\n            )}\n          >\n            {children}\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n\nexport { Marquee, type MarqueeProps };\n",
      "type": "registry:ui"
    }
  ],
  "tailwind": {
    "config": {
      "theme": {
        "extend": {
          "keyframes": {
            "marquee-x": {
              "to": {
                "transform": "translate3d(calc(-100% / var(--marquee-copies)), 0, 0)"
              }
            },
            "marquee-y": {
              "to": {
                "transform": "translate3d(0, calc(-100% / var(--marquee-copies)), 0)"
              }
            }
          },
          "animation": {
            "marquee-x": "marquee-x 20s linear infinite",
            "marquee-y": "marquee-y 20s linear infinite"
          }
        }
      }
    }
  },
  "cssVars": {
    "theme": {
      "animate-marquee-x": "marquee-x 20s linear infinite",
      "animate-marquee-y": "marquee-y 20s linear infinite"
    }
  },
  "css": {
    "@keyframes marquee-x": {
      "to": {
        "transform": "translate3d(calc(-100% / var(--marquee-copies)), 0, 0)"
      }
    },
    "@keyframes marquee-y": {
      "to": {
        "transform": "translate3d(0, calc(-100% / var(--marquee-copies)), 0)"
      }
    }
  },
  "categories": [
    "motion"
  ],
  "type": "registry:ui"
}