{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-infinite-slider",
  "title": "Infinite slider",
  "description": "A slider component that loops infinitely through its content.",
  "dependencies": [
    "motion",
    "react-use-measure"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/infinite-slider.tsx",
      "content": "'use client';\nimport { cn } from '@/lib/utils';\nimport {\n  useMotionValue,\n  animate,\n  motion,\n  useReducedMotion,\n} from 'motion/react';\nimport { useState, useEffect } from 'react';\nimport useMeasure from 'react-use-measure';\n\nexport type InfiniteSliderProps = {\n  children: React.ReactNode;\n  gap?: number;\n  speed?: number;\n  speedOnHover?: number;\n  direction?: 'horizontal' | 'vertical';\n  reverse?: boolean;\n  className?: string;\n};\n\nexport function InfiniteSlider({\n  children,\n  gap = 16,\n  speed = 100,\n  speedOnHover,\n  direction = 'horizontal',\n  reverse = false,\n  className,\n}: InfiniteSliderProps) {\n  const [currentSpeed, setCurrentSpeed] = useState(speed);\n  const [ref, { width, height }] = useMeasure();\n  const translation = useMotionValue(0);\n  const [isTransitioning, setIsTransitioning] = useState(false);\n  const [key, setKey] = useState(0);\n  const prefersReducedMotion = useReducedMotion();\n\n  useEffect(() => {\n    let controls;\n    const size = direction === 'horizontal' ? width : height;\n    const contentSize = size + gap;\n    const from = reverse ? -contentSize / 2 : 0;\n    const to = reverse ? 0 : -contentSize / 2;\n\n    if (prefersReducedMotion) {\n      translation.jump(from);\n      return;\n    }\n\n    const isPaused = currentSpeed <= 0;\n    if (isPaused) {\n      return;\n    }\n\n    const distanceToTravel = Math.abs(to - from);\n    const duration = distanceToTravel / currentSpeed;\n\n    if (isTransitioning) {\n      const remainingDistance = Math.abs(translation.get() - to);\n      const transitionDuration = remainingDistance / currentSpeed;\n\n      controls = animate(translation, [translation.get(), to], {\n        ease: 'linear',\n        duration: transitionDuration,\n        onComplete: () => {\n          setIsTransitioning(false);\n          setKey((prevKey) => prevKey + 1);\n        },\n      });\n    } else {\n      controls = animate(translation, [from, to], {\n        ease: 'linear',\n        duration: duration,\n        repeat: Infinity,\n        repeatType: 'loop',\n        repeatDelay: 0,\n        onRepeat: () => {\n          translation.set(from);\n        },\n      });\n    }\n\n    return controls?.stop;\n  }, [\n    key,\n    translation,\n    currentSpeed,\n    width,\n    height,\n    gap,\n    isTransitioning,\n    direction,\n    reverse,\n    prefersReducedMotion,\n  ]);\n\n  function slowDown() {\n    if (speedOnHover === undefined) {\n      return;\n    }\n    setIsTransitioning(true);\n    setCurrentSpeed(speedOnHover);\n  }\n\n  function resume() {\n    if (speedOnHover === undefined) {\n      return;\n    }\n    setIsTransitioning(true);\n    setCurrentSpeed(speed);\n  }\n\n  return (\n    <div className={cn('overflow-hidden', className)}>\n      <motion.div\n        className='flex w-max'\n        style={{\n          ...(direction === 'horizontal'\n            ? { x: translation }\n            : { y: translation }),\n          gap: `${gap}px`,\n          flexDirection: direction === 'horizontal' ? 'row' : 'column',\n        }}\n        ref={ref}\n        onHoverStart={slowDown}\n        onHoverEnd={resume}\n        onFocus={slowDown}\n        onBlur={resume}\n      >\n        {children}\n        {children}\n      </motion.div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/infinite-slider.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}