{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroller",
  "type": "registry:ui",
  "title": "Scroller",
  "description": "A row (or column) of items that glides past on a loop: logos of the organisations you work with, short quotes, headlines. The items are real content, so the component treats them that way first and as motion second.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "marketing",
    "effect"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/scroller.tsx",
      "target": "components/ui/effects/scroller.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport { PauseIcon, PlayIcon } from 'lucide-react';\n\n// @interlace/scroller v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/scroller\n// What changed since: https://ds.interlace.tools/c/scroller#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — Scroller\n *\n * A row (or column) of items that glides past on a loop: logos of the\n * organisations you work with, short quotes, headlines. The items are real\n * content, so the component treats them that way first and as motion second.\n *\n * ## Content first\n *\n * - The items render once, as a list, on the server. A second copy is added\n *   for the seamless loop, and that copy is `aria-hidden` and `inert`, so a\n *   screen reader hears each item once and Tab visits each link once.\n * - A visible Pause button sits next to the strip, as WCAG 2.2.2 asks for\n *   anything that moves for more than five seconds. Hovering the strip or\n *   moving focus into it also pauses it.\n * - Under `prefers-reduced-motion: reduce` nothing moves: the clone is not\n *   rendered, the button is not shown (it would control nothing), and the\n *   strip becomes an ordinary scrollable row, so every item stays reachable.\n *\n * ## Motion\n *\n * One Web Animations API animation on the track, from 0 to minus the width\n * of one copy. No keyframes to add to a stylesheet. The animation pauses\n * when the strip leaves the viewport or the tab is hidden.\n *\n * ## Composition\n *\n *   Scroller                           (section-like div — data-slot=\"scroller\")\n *     ├─ viewport                      (overflow + edge fade)\n *     │   └─ track                     (animated)\n *     │       ├─ ul                    (the items, each child in an li)\n *     │       └─ ul clone              (aria-hidden, inert; motion only)\n *     └─ pause button                  (data-slot=\"scroller-control\")\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `div` props                                          |\n * | R6   | data-slot per part      | scroller / -track / -list / -item / -control          |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R8   | Enums, not booleans     | `direction`, `gap`, `edges`                           |\n * | R19  | Tokens only             | control uses `--background`, `--border`, `--ring`     |\n * | R25  | Client component        | animation and pause state                             |\n * | R26  | A11y                    | list semantics, one copy announced, visible pause     |\n */\n\nimport * as React from 'react';\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nconst GAP = { sm: 'gap-4', md: 'gap-8', lg: 'gap-16' } as const;\nconst GAP_PAD = {\n  sm: { x: 'pr-4', y: 'pb-4' },\n  md: { x: 'pr-8', y: 'pb-8' },\n  lg: { x: 'pr-16', y: 'pb-16' },\n} as const;\n\nconst FADE = {\n  x: '[mask-image:linear-gradient(to_right,transparent,black_8%,black_92%,transparent)]',\n  y: '[mask-image:linear-gradient(to_bottom,transparent,black_8%,black_92%,transparent)]',\n} as const;\n\nexport interface ScrollerProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {\n  /** The items. Each child becomes one list item. */\n  children: React.ReactNode;\n  /** Which way the items travel. @default 'left' */\n  direction?: 'left' | 'right' | 'up' | 'down';\n  /** Seconds for one full copy to pass. @default 40 */\n  duration?: number;\n  /** Space between items. @default 'md' */\n  gap?: keyof typeof GAP;\n  /** Fade the items out at the edges, or cut them off square. @default 'fade' */\n  edges?: 'fade' | 'none';\n  /** Pause while the pointer is over the strip. @default true */\n  pauseOnHover?: boolean;\n  /** Accessible name of the strip, read before the items. */\n  label?: string;\n  /** Text of the pause button. @default 'Pause' */\n  pauseLabel?: string;\n  /** Text of the play button. @default 'Play' */\n  playLabel?: string;\n}\n\nexport function Scroller({\n  children,\n  direction = 'left',\n  duration = 40,\n  gap = 'md',\n  edges = 'fade',\n  pauseOnHover = true,\n  label,\n  pauseLabel = 'Pause',\n  playLabel = 'Play',\n  className,\n  ...props\n}: ScrollerProps) {\n  const reduced = useReducedMotion();\n  const axis = direction === 'up' || direction === 'down' ? 'y' : 'x';\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const firstRef = React.useRef<HTMLUListElement>(null);\n  const [paused, setPaused] = React.useState(false);\n  const [held, setHeld] = React.useState(false);\n\n  const items = React.Children.toArray(children);\n  const moving = !reduced;\n\n  const animationRef = React.useRef<Animation | null>(null);\n  const stateRef = React.useRef({ paused: false, held: false });\n\n  /** Play or pause the loop from the pause button, hover/focus and visibility. Reads refs only, so it is stable. */\n  const sync = React.useCallback(() => {\n    const animation = animationRef.current;\n    const track = trackRef.current;\n    if (!animation || !track) return;\n    const state = stateRef.current;\n    if (state.paused || state.held || track.dataset.offscreen === 'true') animation.pause();\n    else animation.play();\n  }, []);\n\n  React.useEffect(() => {\n    const track = trackRef.current;\n    const first = firstRef.current;\n    if (!moving || !track || !first || typeof track.animate !== 'function') return;\n\n    let animation: Animation | null = null;\n    const start = () => {\n      animation?.cancel();\n      const size = axis === 'x' ? first.offsetWidth : first.offsetHeight;\n      const prop = axis === 'x' ? 'translateX' : 'translateY';\n      const forward = direction === 'left' || direction === 'up';\n      const frames = [\n        { transform: `${prop}(${forward ? 0 : -size}px)` },\n        { transform: `${prop}(${forward ? -size : 0}px)` },\n      ];\n      animation = track.animate(frames, { duration: duration * 1000, iterations: Infinity });\n      animationRef.current = animation;\n      sync();\n    };\n    start();\n\n    const ro = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(start);\n    ro?.observe(first);\n    const io =\n      typeof IntersectionObserver === 'undefined'\n        ? null\n        : new IntersectionObserver(([entry]) => {\n            track.dataset.offscreen = entry?.isIntersecting ? 'false' : 'true';\n            sync();\n          });\n    io?.observe(track);\n\n    return () => {\n      ro?.disconnect();\n      io?.disconnect();\n      animation?.cancel();\n      animationRef.current = null;\n    };\n  }, [moving, axis, direction, duration, items.length, sync]);\n\n  React.useEffect(() => {\n    stateRef.current = { paused, held };\n    sync();\n  }, [paused, held, sync]);\n\n  const vertical = axis === 'y';\n  const list = (clone: boolean) => (\n    <ul\n      ref={clone ? undefined : firstRef}\n      data-slot=\"scroller-list\"\n      aria-hidden={clone || undefined}\n      inert={clone || undefined}\n      className={cn(\n        'flex shrink-0 list-none p-0',\n        vertical ? 'flex-col' : 'flex-row items-center',\n        GAP[gap],\n        GAP_PAD[gap][axis],\n      )}\n    >\n      {items.map((item, i) => (\n        <li key={React.isValidElement(item) && item.key !== null ? item.key : i} data-slot=\"scroller-item\" className=\"shrink-0\">\n          {item}\n        </li>\n      ))}\n    </ul>\n  );\n\n  return (\n    <div\n      role={label ? 'region' : undefined}\n      aria-label={label}\n      data-slot=\"scroller\"\n      data-direction={direction}\n      className={cn('relative flex items-start gap-2', vertical ? 'flex-row' : 'flex-col sm:flex-row sm:items-center', className)}\n      {...props}\n    >\n      <div\n        data-slot=\"scroller-viewport\"\n        className={cn(\n          'min-w-0 flex-1',\n          moving ? 'overflow-hidden' : vertical ? 'overflow-y-auto' : 'overflow-x-auto',\n          edges === 'fade' && FADE[axis],\n        )}\n        onPointerEnter={pauseOnHover ? () => setHeld(true) : undefined}\n        onPointerLeave={pauseOnHover ? () => setHeld(false) : undefined}\n        onFocus={() => setHeld(true)}\n        onBlur={(e) => {\n          if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setHeld(false);\n        }}\n      >\n        <div\n          ref={trackRef}\n          data-slot=\"scroller-track\"\n          className={cn('flex w-max', vertical ? 'flex-col' : 'flex-row')}\n        >\n          {list(false)}\n          {moving ? list(true) : null}\n        </div>\n      </div>\n      {moving ? (\n        <button\n          type=\"button\"\n          data-slot=\"scroller-control\"\n          aria-pressed={paused}\n          aria-label={paused ? playLabel : pauseLabel}\n          onClick={() => setPaused((p) => !p)}\n          className=\"border-border bg-background text-foreground hover:bg-muted focus-visible:ring-ring inline-flex min-h-11 shrink-0 items-center gap-1.5 rounded-md border px-3 text-sm font-medium focus-visible:ring-[3px] focus-visible:outline-hidden\"\n        >\n          {paused ? <PlayIcon aria-hidden className=\"size-4\" /> : <PauseIcon aria-hidden className=\"size-4\" />}\n          {paused ? playLabel : pauseLabel}\n        </button>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/scroller\n\nInstalled to `components/ui/effects/scroller.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/scroller';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/scroller\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
