{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel",
  "title": "Carousel",
  "description": "A row of slides the user swipes or steps through with Previous and Next buttons: recipe photos, a few featured cards.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/lib-announce",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-router-link",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-reduced-motion"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/carousel/carousel-styles.ts",
      "content": "export { buttonsClass, fillTemplate, nearestSlide, pageClass, pagerClass, rootClass, slideClass, slidesPerViewClass, viewportClass };\n\n// Class strings and helpers for Carousel, apart from the component so its file exports\n// only components (React Fast Refresh). Class strings are literal so the app's Tailwind\n// finds them when it compiles.\n\n/** The region. It takes focus only when both buttons become disabled under focus. @internal */\nconst rootClass =\n  \"grid min-w-0 gap-3 outline-ring outline-offset-4 focus-visible:outline-2 focus-visible:outline-solid\";\n\n/**\n * The scroller: native horizontal scrolling with mandatory snap points, so a swipe, a\n * trackpad, a wheel with Shift and the arrow keys all land on a slide. No `touch-action`\n * is set, so a vertical swipe that starts on the slides still scrolls the page, and\n * `overscroll-x-contain` keeps a horizontal swipe at the last slide from navigating back.\n * The scrollbar is hidden; the buttons and the keyboard move between slides.\n *\n * @internal\n * @claim \"The scroller: native horizontal scrolling with\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > snaps each slide to the start of a horizontal scroller that a keyboard can reach)\n * @claim \"The scroller: native horizontal scrolling with\" registry/ouro/components/ouro/carousel/carousel.touch.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.touch.test.tsx::moves to the next slide with a horizontal swipe and reports it once)\n * @claim \"No `touch-action` is set, so a\" registry/ouro/components/ouro/carousel/carousel.touch.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.touch.test.tsx::moves to the next slide with a horizontal swipe and reports it once)\n */\nconst viewportClass =\n  \"box-border flex min-w-0 gap-4 overflow-x-auto overflow-y-hidden overscroll-x-contain snap-x snap-mandatory \" +\n  \"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden rounded-ouro-lg \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"forced-colors:outline-1 forced-colors:outline-solid forced-colors:-outline-offset-1\";\n\n/** @internal */\nconst slideClass = \"box-border min-w-0 shrink-0 grow-0 basis-(--ouro-carousel-basis) snap-start\";\n\n/**\n * The slide width for each `slidesPerView`, with the 1rem gap between slides taken out. @internal\n *\n * @claim \"The slide width for each `slidesPerView`\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > shows two or three slides at a time with slidesPerView)\n * @claim \"The slide width for each `slidesPerView`\" registry/ouro/components/ouro/carousel/carousel-styles.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel-styles.ts, /calc\\(\\(100%-1rem\\)\\/2\\)/)\n */\nconst slidesPerViewClass = {\n  1: \"[--ouro-carousel-basis:100%]\",\n  2: \"[--ouro-carousel-basis:calc((100%-1rem)/2)]\",\n  3: \"[--ouro-carousel-basis:calc((100%-2rem)/3)]\",\n} as const;\n\n/** @internal */\nconst buttonsClass = \"flex items-center justify-end gap-2\";\n\n// The pager sits at the start of the buttons' row. Each page is a 24px link around its dot, 44px\n// on a coarse pointer so neighbouring targets never overlap; the current one is a longer dot in the primary colour,\n// so it differs by shape as well as colour, and takes the selection's colours under forced colours.\nconst pagerClass = \"me-auto flex flex-wrap items-center\";\nconst pageClass =\n  \"relative grid size-6 pointer-coarse:size-11 place-items-center rounded-full outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"after:block after:h-2 after:w-2 after:rounded-full after:bg-muted-foreground after:content-[''] \" +\n  \"aria-[current=true]:after:w-4 aria-[current=true]:after:bg-primary \" +\n  \"forced-colors:after:bg-[CanvasText] forced-colors:aria-[current=true]:after:bg-[Highlight]\";\n\n/**\n * Fills a label template: `{n}` is the 1-based slide number and `{total}` the slide count.\n *\n * @internal\n * @claim \"Fills a label template: `{n}` is\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel announcements > announces with the slideLabel template)\n * @claim \"Fills a label template: `{n}` is\" registry/ouro/components/ouro/carousel/carousel-styles.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel-styles.ts, /replaceAll\\(\"\\{n\\}\", String\\(n\\)\\)/)\n */\nfunction fillTemplate(template: string, n: number, total: number): string {\n  return template.replaceAll(\"{n}\", String(n)).replaceAll(\"{total}\", String(total));\n}\n\n/**\n * The index of the slide whose start edge is nearest the scroller's start edge, in either\n * reading direction.\n *\n * @internal\n */\nfunction nearestSlide(viewport: HTMLElement): number {\n  const rtl = getComputedStyle(viewport).direction === \"rtl\";\n  const box = viewport.getBoundingClientRect();\n  const edge = rtl ? box.right : box.left;\n  let best = 0;\n  let bestDistance = Infinity;\n  [...viewport.children].forEach((slide, index) => {\n    const rect = slide.getBoundingClientRect();\n    const distance = Math.abs((rtl ? rect.right : rect.left) - edge);\n    if (distance < bestDistance) {\n      best = index;\n      bestDistance = distance;\n    }\n  });\n  return best;\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/carousel/carousel-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/carousel/carousel.tsx",
      "content": "\"use client\";\n\nimport { Children, useEffect, useLayoutEffect, useRef, useState, type JSX, type ReactNode } from \"react\";\nimport { announce } from \"@/registry/ouro/lib/ouro/announce\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { RouterLink } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport {\n  buttonsClass,\n  fillTemplate,\n  nearestSlide,\n  pageClass,\n  pagerClass,\n  rootClass,\n  slideClass,\n  slidesPerViewClass,\n  viewportClass,\n} from \"@/registry/ouro/components/ouro/carousel/carousel-styles\";\n\n/** Props for {@link Carousel}. */\nexport interface CarouselProps {\n  /**\n   * Names the carousel for screen readers, such as \"Recipe photos\". It is always required.\n   *\n   * @claim \"It is always required\" registry/ouro/components/ouro/carousel/carousel.test-d.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel.test-d.ts, /expectTypeOf<\\{\\schildren:\\s\"Slides\"\\s\\}>\\(\\)\\.not\\.toExtend<CarouselProps>/)\n   */\n  label: string;\n  /**\n   * The slides: each child is one slide, so pass the images or cards themselves.\n   *\n   * @claim \"The slides: each child is one\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > is a named carousel region of slides named by their position)\n   */\n  children: ReactNode;\n  /** Next on the last slide goes back to the first, and Previous on the first goes to the last. */\n  loop?: boolean | undefined;\n  /** How many slides show at once. @default 1 */\n  slidesPerView?: 1 | 2 | 3 | (number & { 'Use 1, 2 or 3': never }) | undefined;\n  /**\n   * The slide to start on, counting from 0. The starting slide is not announced. @default 0\n   *\n   * @claim \"The slide to start on, counting\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel navigation > starts at defaultIndex without announcing it)\n   */\n  defaultIndex?: number | undefined;\n  /**\n   * The slide in view, counting from the first as `0`, for a carousel your app drives: from the\n   * address (`#slide-3`, so a slide has a link and Back and Forward step through the slides), a\n   * router's state, or another control. When it changes the carousel moves there, smoothly or at once\n   * with reduced motion, and announces the position, without calling `onIndexChange`. Set it\n   * from `onIndexChange` too, so a swipe or a button press moves it. Unset, the carousel keeps its own position, from `defaultIndex`.\n   *\n   * @claim \"When it changes the carousel moves\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel driven by the app > starts at index, moves when index changes and announces it, and reports the user's own moves)\n   */\n  index?: number | undefined;\n  /** Called with the index of the first visible slide when the user moves to another slide, once per change. */\n  onIndexChange?: ((index: number) => void) | undefined;\n  /**\n   * Shows a pager beside the buttons: a dot for each position, a link to the address this returns\n   * (`(index) => \"#slide-\" + (index + 1)`), named by `slideLabel`, with `aria-current=\"true\"` and a\n   * longer dot on the position in view. Following one changes the address, so drive the carousel\n   * with `index` from the address and it moves there.\n   *\n   * @claim \"a dot for each position, a link\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel driven by the app > shows a pager of links, one per position, with the one in view marked current)\n   */\n  pagerHref?: ((index: number) => string) | undefined;\n  /** With `pagerHref`, the pager's accessible name. @default \"Slides\" */\n  pagerLabel?: string | undefined;\n  /**\n   * Called at once with the slide a Previous or Next press is moving to, before the scroll gets\n   * there, and with null when the scroll settles: show that position straight away, so a counter\n   * never names the slide being left. `onIndexChange` still reports, and the carousel announces,\n   * only where the scroll settles.\n   *\n   * @claim \"Called at once with the slide\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel navigation > reports the slide a press is moving to at once, and null when the scroll settles)\n   */\n  onTargetChange?: ((index: number | null) => void) | undefined;\n  /** The Previous button's accessible name. @default \"Previous slide\" */\n  previousLabel?: string | undefined;\n  /** The Next button's accessible name. @default \"Next slide\" */\n  nextLabel?: string | undefined;\n  /**\n   * Names each slide and is announced when the position changes: `{n}` is the slide's\n   * number and `{total}` the number of slides. @default \"Slide {n} of {total}\"\n   * @claim \"Names each slide and is announced\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > is a named carousel region of slides named by their position)\n   * @claim \"Names each slide and is announced\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > names its buttons and slides with the labels it is given)\n   */\n  slideLabel?: string | undefined;\n  /** What a screen reader calls the carousel, after its label: \"Recipe photos, carousel\". @default \"carousel\" */\n  roleDescription?: string | undefined;\n  /**\n   * What a screen reader calls each slide, after its name: \"Slide 2 of 5, slide\". @default \"slide\"\n   *\n   * @claim \"What a screen reader calls each\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > is a named carousel region of slides named by their position)\n   */\n  slideRoleDescription?: string | undefined;\n  /** Layout only: width and margins (`max-w-xl`, `mx-auto`). Appearance classes warn in development. */\n  className?: string | undefined;\n\n  /** Not a prop. Ouro UI's Carousel is not Embla: `<Carousel loop>`. */\n  opts?: { 'Use <Carousel loop>; Carousel takes no Embla options': never };\n  /** Not a prop. Read the position with `onIndexChange`: `<Carousel onIndexChange={setIndex}>`. */\n  setApi?: { 'Use <Carousel onIndexChange={setIndex}>': never };\n  /**\n   * Not a prop. Carousel never moves on its own, so it takes no plugins.\n   *\n   * @claim \"Carousel never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test-d.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel.test-d.ts, /plugins:\\s\\[\\]\\s\\}>\\(\\)\\.not\\.toExtend<CarouselProps>/)\n   * @claim \"Carousel never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test-d.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel.test-d.ts, /autoplay:\\strue\\s\\}>\\(\\)\\.not\\.toExtend<CarouselProps>/)\n   */\n  plugins?: { 'Carousel never moves on its own; remove plugins': never };\n  /**\n   * Not a prop. Carousel never moves on its own: motion the user did not start is hard to read and to stop.\n   *\n   * @claim \"Carousel never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test-d.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel.test-d.ts, /autoplay:\\strue\\s\\}>\\(\\)\\.not\\.toExtend<CarouselProps>/)\n   */\n  autoplay?: { 'Carousel never moves on its own; remove autoplay': never };\n  /** Not a prop. Carousel scrolls horizontally; stack vertical content in a grid instead. */\n  orientation?: { 'Carousel scrolls horizontally; use a grid for a vertical list': never };\n}\n\nconst perViews = [1, 2, 3] as const;\n\nfunction ChevronIcon({ back }: { back?: boolean }): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className={cn(\"size-4 rtl:-scale-x-100\", back && \"-scale-x-100 rtl:scale-x-100\")}>\n      <path d=\"M6 3l5 5-5 5\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\n/**\n * A row of slides the user swipes or steps through with Previous and Next buttons:\n * recipe photos, a few featured cards. It is the browser's own scrolling with snap\n * points, so swiping, trackpads and arrow keys all work and a vertical swipe still\n * scrolls the page. Each child is a slide named \"Slide 2 of 5\", and moving to another\n * slide announces that position politely, once. It never moves on its own, and with\n * reduced motion the buttons jump instead of scrolling smoothly. With every slide in view\n * (one slide, or no more than `slidesPerView`) the buttons hide.\n *\n * An app that keeps the slide in the address passes `index` and `pagerHref`: a slide then has a\n * link, the pager's dots link to the slides, and Back and Forward step through them.\n *\n * Use a grid instead when every item should be visible at once, and `Tabs` when the\n * panels have names the user picks from.\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/carousel\n *\n * @example\n * <Carousel label=\"Recipe photos\">\n *   {photos.map((photo) => <img key={photo.id} src={photo.src} alt={photo.alt} />)}\n * </Carousel>\n * <Carousel label=\"Featured recipes\" slidesPerView={2} loop onIndexChange={setIndex}>\n *   {recipes.map((recipe) => <RecipeCard key={recipe.id} recipe={recipe} />)}\n * </Carousel>\n * // The slide lives in the address: #slide-3.\n * const hash = useSyncExternalStore(onHashChange, () => location.hash, () => \"\");\n * const slide = Math.max(0, Number(hash.replace(\"#slide-\", \"\")) - 1 || 0);\n * <Carousel\n *   label=\"Overview\"\n *   index={slide}\n *   onIndexChange={(index) => history.replaceState(null, \"\", `#slide-${index + 1}`)}\n *   pagerHref={(index) => `#slide-${index + 1}`}\n * >\n *   {slides}\n * </Carousel>\n * @claim \"An app that keeps the slide\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel driven by the app > follows the address when a pager link is followed, and when the address goes back)\n * @claim \"It is the browser's own scrolling\" registry/ouro/components/ouro/carousel/carousel.touch.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.touch.test.tsx::lets a vertical swipe that starts on the slides scroll the page)\n * @claim \"It is the browser's own scrolling\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > snaps each slide to the start of a horizontal scroller that a keyboard can reach)\n * @claim \"Each child is a slide named\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel structure > snaps each slide to the start of a horizontal scroller that a keyboard can reach)\n * @claim \"It never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel motion > jumps instantly with reduced motion)\n * @claim \"With every slide in view\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel navigation > hides the buttons when every slide is in view)\n * @claim \"It never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test.tsx verify:testExists(registry/ouro/components/ouro/carousel/carousel.test.tsx::Carousel motion > scrolls smoothly when motion is allowed)\n * @claim \"It never moves on its own\" registry/ouro/components/ouro/carousel/carousel.test-d.ts verify:fileLine(registry/ouro/components/ouro/carousel/carousel.test-d.ts, /autoplay:\\strue\\s\\}>\\(\\)\\.not\\.toExtend<CarouselProps>/)\n */\nexport function Carousel(props: CarouselProps): JSX.Element {\n  const {\n    label,\n    children,\n    loop = false,\n    slidesPerView: perViewProp = 1,\n    defaultIndex = 0,\n    index: indexProp,\n    onIndexChange,\n    pagerHref,\n    pagerLabel = \"Slides\",\n    onTargetChange,\n    previousLabel = \"Previous slide\",\n    nextLabel = \"Next slide\",\n    slideLabel = \"Slide {n} of {total}\",\n    roleDescription = \"carousel\",\n    slideRoleDescription = \"slide\",\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    opts,\n    setApi,\n    plugins,\n    autoplay,\n    orientation,\n  } = props;\n\n  const slides = Children.toArray(children);\n  const total = slides.length;\n  // A slidesPerView that is not one of Ouro UI's (a type error) warns and shows one slide.\n  const perView = perViews.includes(perViewProp as 1 | 2 | 3) ? (perViewProp as 1 | 2 | 3) : 1;\n  const lastIndex = Math.max(0, total - perView);\n\n  useAppearanceClassNameCheck(\n    \"Carousel\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; style the slides you pass in`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Carousel\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !label && [\"label is required; it names the carousel for screen readers\", '<Carousel label=\"Recipe photos\">'],\n          total === 0 && [\n            \"there are no slides\",\n            '<Carousel label=\"Recipe photos\">{photos.map((photo) => <img key={photo.id} src={photo.src} alt={photo.alt} />)}</Carousel>',\n          ],\n          perView !== perViewProp && [`slidesPerView={${String(perViewProp)}} is not supported; use 1, 2, 3`, \"<Carousel slidesPerView={3}>\"],\n          total > 0 && defaultIndex > lastIndex && [`defaultIndex={${defaultIndex}} is past the last slide (${lastIndex})`, `<Carousel defaultIndex={${lastIndex}}>`],\n          (indexProp ?? 0) > lastIndex && [`index={${String(indexProp)}} is past the last slide (${lastIndex})`, `<Carousel index={${lastIndex}}>`],\n          opts !== undefined && [\"opts is not a prop\", \"<Carousel loop>\"],\n          setApi !== undefined && [\"setApi is not a prop\", \"<Carousel onIndexChange={setIndex}>\"],\n          plugins !== undefined && [\"plugins is not a prop; Carousel never moves on its own\", '<Carousel label=\"Recipe photos\">'],\n          autoplay !== undefined && [\"autoplay is not a prop; Carousel never moves on its own\", '<Carousel label=\"Recipe photos\">'],\n          orientation !== undefined && [\"orientation is not a prop; Carousel scrolls horizontally\", '<div className=\"grid gap-4\">…</div>'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // The app's index, when it drives the carousel, within the slides.\n  const controlled = indexProp === undefined ? undefined : Math.min(Math.max(0, indexProp), lastIndex);\n  const startIndex = controlled ?? Math.min(Math.max(0, defaultIndex), lastIndex);\n  const [index, setIndex] = useState(startIndex);\n  const current = Math.min(index, lastIndex);\n  // The settled index, and the slide a button press is heading to before the scroll settles.\n  const settled = useRef(startIndex);\n  const heading = useRef<number | undefined>(undefined);\n  const rootRef = useRef<HTMLElement>(null);\n  const viewportRef = useRef<HTMLDivElement>(null);\n  const previousRef = useRef<HTMLButtonElement>(null);\n  const nextRef = useRef<HTMLButtonElement>(null);\n  // What had focus when the position settled: a re-render may disable it or make it inert.\n  const focused = useRef<Element | null>(null);\n  // The latest props for the scroll listener, which is attached once.\n  // Stryker disable next-line ObjectLiteral: the layout effect below sets it before anything reads it.\n  const latest = useRef({ onIndexChange, onTargetChange, slideLabel, total, lastIndex, loop, controlled });\n  useLayoutEffect(() => {\n    latest.current = { onIndexChange, onTargetChange, slideLabel, total, lastIndex, loop, controlled };\n  });\n\n  const scrollToSlide = (target: number, behavior: ScrollBehavior) => {\n    const viewport = viewportRef.current!;\n    const slide = viewport.children[target]!;\n    const rtl = getComputedStyle(viewport).direction === \"rtl\";\n    const box = viewport.getBoundingClientRect();\n    const rect = slide.getBoundingClientRect();\n    // The rects include any transform the carousel is drawn in (a Lightbox viewer starts at 90%), so\n    // the distance is taken back to layout pixels, the units scrollLeft uses.\n    const scale = viewport.offsetWidth > 0 ? box.width / viewport.offsetWidth : 1;\n    viewport.scrollTo({ left: viewport.scrollLeft + ((rtl ? rect.right - box.right : rect.left - box.left) / scale), behavior });\n  };\n\n  // Start on defaultIndex. The server renders the first slide in view.\n  useLayoutEffect(() => {\n    if (startIndex > 0) scrollToSlide(startIndex, \"instant\");\n    // Only on mount: defaultIndex is the starting slide.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  // The position follows the scroll, however it moved: a button, a swipe, a key. It\n  // settles when scrolling ends, so each change is reported and announced once, not for\n  // every slide passed on the way. Where `scrollend` is missing, a pause stands in for it,\n  // but not while a finger is down: a finger held still mid-swipe has not chosen a slide.\n  // A pause is not proof the scroll is over (a busy page delays scroll events past it), so\n  // it settles only when the position then holds still for two frames and, after a button\n  // press, has reached the slide the press is heading to.\n  useEffect(() => {\n    const viewport = viewportRef.current!;\n    const fallback = !(\"onscrollend\" in HTMLElement.prototype);\n    let timer: ReturnType<typeof setTimeout> | undefined;\n    let frame: number | undefined;\n    let touching = false;\n    const stopWaiting = () => {\n      clearTimeout(timer);\n      if (frame !== undefined) cancelAnimationFrame(frame);\n      frame = undefined;\n    };\n    const settle = () => {\n      stopWaiting();\n      heading.current = undefined;\n      const { onIndexChange, onTargetChange, slideLabel, total, lastIndex, controlled } = latest.current;\n      onTargetChange?.(null);\n      const next = Math.min(nearestSlide(viewport), lastIndex);\n      if (next === settled.current) return;\n      focused.current = document.activeElement;\n      settled.current = next;\n      setIndex(next);\n      // A move to the app's own index is the app's, so it is not reported back.\n      if (next !== controlled) onIndexChange?.(next);\n      announce(fillTemplate(slideLabel, next + 1, total));\n    };\n    // After a pause: settle if the position holds for two frames, else keep waiting. A press's\n    // target not reached once the scroll has stopped (the user scrolled elsewhere) is dropped,\n    // so the next pause settles wherever the scroll is.\n    const check = () => {\n      const left = viewport.scrollLeft;\n      frame = requestAnimationFrame(() => {\n        frame = requestAnimationFrame(() => {\n          frame = undefined;\n          if (viewport.scrollLeft !== left) return wait();\n          const target = heading.current;\n          if (target !== undefined && Math.min(nearestSlide(viewport), latest.current.lastIndex) !== target) {\n            heading.current = undefined;\n            return wait();\n          }\n          settle();\n        });\n      });\n    };\n    const wait = () => {\n      stopWaiting();\n      if (!touching) timer = setTimeout(check, 150);\n    };\n    const onTouchStart = () => {\n      touching = true;\n      stopWaiting();\n    };\n    const onTouchEnd = (event: TouchEvent) => {\n      touching = event.touches.length > 0;\n      wait();\n    };\n    if (fallback) {\n      viewport.addEventListener(\"scroll\", wait, { passive: true });\n      viewport.addEventListener(\"touchstart\", onTouchStart, { passive: true });\n      viewport.addEventListener(\"touchend\", onTouchEnd, { passive: true });\n      viewport.addEventListener(\"touchcancel\", onTouchEnd, { passive: true });\n    } else viewport.addEventListener(\"scrollend\", settle);\n    return () => {\n      stopWaiting();\n      viewport.removeEventListener(\"scroll\", wait);\n      viewport.removeEventListener(\"touchstart\", onTouchStart);\n      viewport.removeEventListener(\"touchend\", onTouchEnd);\n      viewport.removeEventListener(\"touchcancel\", onTouchEnd);\n      viewport.removeEventListener(\"scrollend\", settle);\n    };\n  }, []);\n\n  // Focus never falls to the page. A button disabled under focus hands it to the other\n  // button, or to the carousel when both are disabled; focus inside a slide that left\n  // the view (now inert) moves to the scroller. Runs before the browser drops the focus.\n  useLayoutEffect(() => {\n    const had = focused.current ?? document.activeElement!;\n    focused.current = null;\n    if (document.activeElement !== had && document.activeElement !== document.body) return;\n    const previous = previousRef.current!;\n    const next = nextRef.current!;\n    const button = had === previous ? next : had === next ? previous : undefined;\n    if (button && (had as HTMLButtonElement).disabled) (button.disabled ? rootRef.current! : button).focus();\n    else if (had.closest(\"[inert]\") && viewportRef.current!.contains(had)) viewportRef.current!.focus();\n  });\n\n  const reduced = useReducedMotion();\n  // The app moved its index (the address changed, Back or Forward): go there. A move the\n  // carousel reported itself is already where the scroll is, or heading there.\n  useEffect(() => {\n    if (controlled === undefined || controlled === (heading.current ?? settled.current)) return;\n    heading.current = controlled;\n    latest.current.onTargetChange?.(controlled);\n    scrollToSlide(controlled, reduced ? \"instant\" : \"smooth\");\n    // Only when the app's index changes: a new motion setting moves nothing.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [controlled]);\n  // The pager marks where the app says the carousel is, so a followed link is marked at once.\n  const shown = controlled ?? current;\n\n  const go = (step: 1 | -1) => {\n    // scrollend updates the ref before React commits the rendered index.\n    const from = heading.current ?? Math.min(settled.current, lastIndex);\n    // A native scrollend press can precede React disabling the boundary button.\n    const requested = from + step;\n    if (!loop && (requested < 0 || requested > lastIndex)) return;\n    const target = requested > lastIndex ? 0 : requested < 0 ? lastIndex : requested;\n    heading.current = target;\n    latest.current.onTargetChange?.(target);\n    scrollToSlide(target, reduced ? \"instant\" : \"smooth\");\n  };\n\n  return (\n    <section\n      ref={rootRef}\n      data-ouro=\"carousel\"\n      aria-roledescription={roleDescription}\n      aria-label={label}\n      tabIndex={-1}\n      className={cn(rootClass, className)}\n    >\n      <div data-ouro-carousel-viewport=\"\" data-ouro-control=\"carousel\" data-ouro-part=\"viewport\" ref={viewportRef} tabIndex={0} className={cn(viewportClass, slidesPerViewClass[perView])}>\n        {slides.map((slide, position) => (\n          <div\n            key={position}\n            data-ouro-carousel-slide=\"\"\n            role=\"group\"\n            aria-roledescription={slideRoleDescription}\n            aria-label={fillTemplate(slideLabel, position + 1, total)}\n            // Slides out of view are inert, so Tab and a screen reader's reading order skip them.\n            inert={position < current || position >= current + perView}\n            className={slideClass}\n          >\n            {slide}\n          </div>\n        ))}\n      </div>\n      {/* With every slide in view there is nowhere to step. The buttons stay in the page, so a\n          keyboard handler that presses them still finds them. */}\n      <div data-ouro-carousel-buttons=\"\" className={cn(buttonsClass, lastIndex === 0 && \"hidden\")}>\n        {pagerHref && (\n          <nav aria-label={pagerLabel} className={pagerClass}>\n            {Array.from({ length: lastIndex + 1 }, (_, position) => (\n              <RouterLink\n                key={position}\n                href={pagerHref(position)}\n                aria-current={position === shown ? \"true\" : undefined}\n                data-ouro-control=\"carousel\"\n                data-ouro-part=\"page\"\n                className={pageClass}\n              >\n                <span className=\"sr-only\">{fillTemplate(slideLabel, position + 1, total)}</span>\n              </RouterLink>\n            ))}\n          </nav>\n        )}\n        <Button\n          ref={previousRef}\n          variant=\"outline\"\n          tone=\"secondary\"\n          size=\"sm\"\n          aria-label={previousLabel}\n          data-ouro-control=\"carousel\"\n          data-ouro-part=\"previous\"\n          disabled={total === 0 || (!loop && current === 0)}\n          onClick={() => go(-1)}\n        >\n          <ChevronIcon back />\n        </Button>\n        <Button\n          ref={nextRef}\n          variant=\"outline\"\n          tone=\"secondary\"\n          size=\"sm\"\n          aria-label={nextLabel}\n          data-ouro-control=\"carousel\"\n          data-ouro-part=\"next\"\n          disabled={total === 0 || (!loop && current === lastIndex)}\n          onClick={() => go(1)}\n        >\n          <ChevronIcon />\n        </Button>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/carousel/carousel.tsx"
    }
  ],
  "docs": "A row of slides the user swipes or steps through with Previous and Next buttons: recipe photos, a few featured cards. Import: import { Carousel } from \"@/components/ouro/carousel/carousel\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/carousel.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}