{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "basic-carousel",
  "title": "Basic Carousel",
  "description": "A plain, dependable carousel: drag or swipe between slides, arrows and dots, one to four slides in view, looping, and optional autoplay whose progress fills the active dot and pauses whenever someone hovers, focuses or drags.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/basic-carousel/basic-carousel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, animate, useMotionValue, useReducedMotion, type PanInfo } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface CarouselSlide {\n  src: string;\n  alt: string;\n  title?: string;\n  description?: string;\n}\n\nexport interface BasicCarouselProps {\n  /** Image slides. Pass children instead for your own slide content. */\n  slides?: CarouselSlide[];\n  children?: React.ReactNode;\n  /** How many slides show at once (1–4). */\n  slidesPerView?: number;\n  /** Space between slides, in px. */\n  gap?: number;\n  /** After the last slide, go back to the first (and the other way). */\n  loop?: boolean;\n  /** Move on by itself; pauses while hovered, focused, dragged or off-screen. */\n  autoplay?: boolean;\n  /** Milliseconds per slide when autoplaying. */\n  interval?: number;\n  showArrows?: boolean;\n  showDots?: boolean;\n  /** Slide shape, e.g. \"16 / 10\" or \"1 / 1\". */\n  aspectRatio?: string;\n  index?: number;\n  defaultIndex?: number;\n  onIndexChange?: (index: number) => void;\n  /** Accessible name for the carousel. */\n  label?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", dot: \"rgba(245,244,241,0.22)\", dotOn: \"#F5F4F1\", btn: \"rgba(10,10,10,0.55)\", btnBorder: \"rgba(255,255,255,0.18)\", btnText: \"#F5F4F1\", focus: \"rgba(245,244,241,0.85)\", slideBg: \"#151515\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", dot: \"rgba(10,10,10,0.18)\", dotOn: \"#0A0A0A\", btn: \"rgba(255,255,255,0.8)\", btnBorder: \"rgba(10,10,10,0.12)\", btnText: \"#0A0A0A\", focus: \"rgba(10,10,10,0.85)\", slideBg: \"#EDEDEB\" },\n};\n\nconst DEFAULT_SLIDES: CarouselSlide[] = [\n  { src: \"/demo/34.webp\", alt: \"Cyclist in motion blur\", title: \"Road Cycling\", description: \"Tempo ride · 42 km · Zone 3\" },\n  { src: \"/demo/31.webp\", alt: \"Sprinter mid-stride\", title: \"Track Sprints\", description: \"8 × 200 m · 90 s rest\" },\n  { src: \"/demo/12.webp\", alt: \"Skier carving down a slope\", title: \"Alpine Skiing\", description: \"Carving drills · 3 runs\" },\n  { src: \"/demo/28.webp\", alt: \"Rower on still water\", title: \"Rowing\", description: \"Steady state · 45 min\" },\n  { src: \"/demo/33.webp\", alt: \"Swimmer doing freestyle\", title: \"Open Water\", description: \"Freestyle · 1,500 m\" },\n];\n\nexport function BasicCarousel({\n  slides = DEFAULT_SLIDES,\n  children,\n  slidesPerView = 1,\n  gap = 12,\n  loop = true,\n  autoplay = false,\n  interval = 4000,\n  showArrows = true,\n  showDots = true,\n  aspectRatio = \"16 / 10\",\n  index,\n  defaultIndex = 0,\n  onIndexChange,\n  label = \"Carousel\",\n  theme = \"dark\",\n  className,\n}: BasicCarouselProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const [width, setWidth] = React.useState(0);\n  const [internal, setInternal] = React.useState(defaultIndex);\n  const [paused, setPaused] = React.useState(false);\n  const [dragging, setDragging] = React.useState(false);\n  const x = useMotionValue(0);\n\n  const items = children ? React.Children.toArray(children) : slides;\n  const count = items.length;\n  const perView = Math.max(1, Math.min(4, Math.round(slidesPerView), count));\n  const last = Math.max(0, count - perView);\n  const current = Math.min(index ?? internal, last);\n  const slideW = width ? (width - gap * (perView - 1)) / perView : 0;\n  const step = slideW + gap;\n\n  const go = React.useCallback(\n    (i: number) => {\n      const next = i < 0 ? (loop ? last : 0) : i > last ? (loop ? 0 : last) : i;\n      if (index === undefined) setInternal(next);\n      onIndexChange?.(next);\n    },\n    [index, last, loop, onIndexChange],\n  );\n\n  React.useLayoutEffect(() => {\n    const el = viewportRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setWidth(el.clientWidth));\n    ro.observe(el);\n    setWidth(el.clientWidth);\n    return () => ro.disconnect();\n  }, []);\n\n  // Slide the track to the current slide (jump there on resize so it never drifts).\n  const lastWidth = React.useRef(0);\n  React.useEffect(() => {\n    if (!step) return;\n    const target = -current * step;\n    if (lastWidth.current !== width || reduce) x.set(target);\n    else animate(x, target, { type: \"spring\", stiffness: 300, damping: 36 });\n    lastWidth.current = width;\n  }, [current, step, width, reduce, x]);\n\n  // Autoplay: a timer per slide, restarted on every change and held while paused.\n  const running = autoplay && !paused && !dragging && count > perView;\n  React.useEffect(() => {\n    if (!running) return;\n    const id = window.setTimeout(() => go(current + 1), interval);\n    return () => window.clearTimeout(id);\n  }, [running, current, interval, go]);\n\n  React.useEffect(() => {\n    const onVis = () => setPaused(document.hidden);\n    document.addEventListener(\"visibilitychange\", onVis);\n    return () => document.removeEventListener(\"visibilitychange\", onVis);\n  }, []);\n\n  const onDragEnd = (_: unknown, info: PanInfo) => {\n    setDragging(false);\n    const moved = -info.offset.x / (step || 1);\n    const flick = Math.abs(info.velocity.x) > 400 ? -Math.sign(info.velocity.x) : 0;\n    const by = Math.abs(moved) > 0.2 ? Math.sign(moved) * Math.max(1, Math.round(Math.abs(moved))) : flick;\n    const target = Math.max(0, Math.min(last, current + by));\n    if (target === current) animate(x, -current * step, { type: \"spring\", stiffness: 300, damping: 36 });\n    else go(target);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      go(current - 1);\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      go(current + 1);\n    }\n  };\n\n  const pages = last + 1;\n  const canPrev = loop || current > 0;\n  const canNext = loop || current < last;\n\n  const arrow = (dir: -1 | 1) => (\n    <button\n      type=\"button\"\n      aria-label={dir < 0 ? \"Previous slide\" : \"Next slide\"}\n      aria-controls={`${uid}-track`}\n      disabled={dir < 0 ? !canPrev : !canNext}\n      onClick={() => go(current + dir)}\n      className=\"absolute top-1/2 z-10 flex -translate-y-1/2 cursor-pointer items-center justify-center rounded-full backdrop-blur-md transition-[opacity,transform] duration-200 outline-none hover:scale-105 focus-visible:ring-2 disabled:cursor-default disabled:opacity-0\"\n      style={{ [dir < 0 ? \"left\" : \"right\"]: 12, width: 38, height: 38, background: p.btn, border: `1px solid ${p.btnBorder}`, color: p.btnText, [\"--tw-ring-color\" as string]: p.focus }}\n    >\n      <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        <path d={dir < 0 ? \"m15 6-6 6 6 6\" : \"m9 6 6 6-6 6\"} />\n      </svg>\n    </button>\n  );\n\n  return (\n    <section\n      aria-roledescription=\"carousel\"\n      aria-label={label}\n      className={cn(\"flex w-full flex-col\", className)}\n      style={{ gap: 14, fontFamily: \"Inter, sans-serif\" }}\n      onMouseEnter={() => setPaused(true)}\n      onMouseLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={(e) => !e.currentTarget.contains(e.relatedTarget as Node) && setPaused(false)}\n      onKeyDown={onKeyDown}\n    >\n      <div className=\"relative\">\n        <div ref={viewportRef} className=\"overflow-hidden rounded-2xl\">\n          <motion.div\n            id={`${uid}-track`}\n            className=\"flex touch-pan-y\"\n            style={{ x, gap, cursor: count > perView ? (dragging ? \"grabbing\" : \"grab\") : undefined }}\n            drag={count > perView ? \"x\" : false}\n            dragConstraints={{ left: -last * step, right: 0 }}\n            dragElastic={0.12}\n            dragMomentum={false}\n            onDragStart={() => setDragging(true)}\n            onDragEnd={onDragEnd}\n            aria-live={running ? \"off\" : \"polite\"}\n          >\n            {items.map((item, i) => {\n              const visible = i >= current && i < current + perView;\n              const slide = !children ? (item as CarouselSlide) : null;\n              return (\n                <div\n                  key={i}\n                  role=\"group\"\n                  aria-roledescription=\"slide\"\n                  aria-label={`${i + 1} of ${count}`}\n                  aria-hidden={!visible}\n                  inert={!visible}\n                  className=\"relative shrink-0 overflow-hidden rounded-2xl select-none\"\n                  style={{ width: slideW || `calc((100% - ${gap * (perView - 1)}px) / ${perView})`, aspectRatio, background: p.slideBg }}\n                >\n                  {slide ? (\n                    <>\n                      {/* eslint-disable-next-line @next/next/no-img-element */}\n                      <img src={slide.src} alt={slide.alt} draggable={false} loading={i < perView + 1 ? \"eager\" : \"lazy\"} className=\"h-full w-full object-cover\" />\n                      {(slide.title || slide.description) && (\n                        <div className=\"absolute inset-x-0 bottom-0 flex flex-col\" style={{ gap: 2, padding: \"40px 18px 16px\", background: \"linear-gradient(to top, rgba(0,0,0,0.7), transparent)\" }}>\n                          {slide.title && <span className=\"text-[16px] font-semibold tracking-[-0.01em] text-white\">{slide.title}</span>}\n                          {slide.description && <span className=\"text-[13px] text-white/70\">{slide.description}</span>}\n                        </div>\n                      )}\n                    </>\n                  ) : (\n                    (item as React.ReactNode)\n                  )}\n                </div>\n              );\n            })}\n          </motion.div>\n        </div>\n        {showArrows && count > perView && (\n          <>\n            {arrow(-1)}\n            {arrow(1)}\n          </>\n        )}\n      </div>\n\n      {showDots && pages > 1 && (\n        <div className=\"flex items-center justify-center\" style={{ gap: 6 }} role=\"group\" aria-label=\"Choose slide\">\n          {Array.from({ length: pages }, (_, i) => {\n            const on = i === current;\n            return (\n              <button\n                key={i}\n                type=\"button\"\n                aria-label={`Go to slide ${i + 1}`}\n                aria-current={on ? \"true\" : undefined}\n                onClick={() => go(i)}\n                className=\"flex cursor-pointer items-center justify-center border-none bg-transparent p-0 outline-none focus-visible:ring-2\"\n                style={{ height: 16, borderRadius: 99, [\"--tw-ring-color\" as string]: p.focus }}\n              >\n                <motion.span className=\"relative block overflow-hidden rounded-full\" initial={false} animate={{ width: on ? 26 : 7 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 34 }} style={{ height: 7, background: p.dot }}>\n                  {on && (\n                    <motion.span\n                      key={`${current}-${running}`}\n                      className=\"absolute inset-y-0 left-0 block rounded-full\"\n                      style={{ background: p.dotOn }}\n                      initial={{ width: running ? \"0%\" : \"100%\" }}\n                      animate={{ width: \"100%\" }}\n                      transition={running ? { duration: interval / 1000, ease: \"linear\" } : { duration: 0 }}\n                    />\n                  )}\n                </motion.span>\n              </button>\n            );\n          })}\n        </div>\n      )}\n    </section>\n  );\n}\n\nexport default BasicCarousel;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}