{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-timeline-animation",
  "title": "Timeline animation",
  "description": "A vertical timeline whose line fills as the page scrolls, with entries that settle in once as they arrive.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/timeline-animation.tsx",
      "content": "'use client';\nimport {\n  motion,\n  type MotionValue,\n  useInView,\n  useScroll,\n  useTransform,\n  type Variants,\n} from 'motion/react';\nimport {\n  createContext,\n  type ReactNode,\n  type RefObject,\n  useContext,\n  useMemo,\n  useRef,\n} from 'react';\nimport { cn } from '@/lib/utils';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nconst EASE_OUT_STRONG = [0.23, 1, 0.32, 1] as const;\nconst SETTLE_DURATION = 0.3;\nconst SETTLE_DISTANCE = 8;\nconst SETTLE_MARGIN = '0px 0px -10% 0px';\n\ntype TimelineAnimationContextValue = {\n  containerRef?: RefObject<HTMLElement | null>;\n};\n\nconst TimelineAnimationContext = createContext<TimelineAnimationContextValue>(\n  {}\n);\n\nfunction fillOf(\n  prefersReducedMotion: boolean | null,\n  progress: MotionValue<number>\n) {\n  if (prefersReducedMotion) {\n    return 1;\n  }\n  return progress;\n}\n\nfunction reachedOpacityOf(progress: number): number {\n  if (progress > 0) {\n    return 1;\n  }\n  return 0;\n}\n\nfunction settleStateOf(isSettled: boolean) {\n  if (isSettled) {\n    return 'visible';\n  }\n  return 'hidden';\n}\n\nfunction settleVariantsOf(prefersReducedMotion: boolean | null): Variants {\n  if (prefersReducedMotion) {\n    return {\n      hidden: { opacity: 1, y: 0 },\n      visible: { opacity: 1, y: 0 },\n    };\n  }\n  return {\n    hidden: { opacity: 0, y: SETTLE_DISTANCE },\n    visible: { opacity: 1, y: 0 },\n  };\n}\n\nexport type TimelineAnimationProps = {\n  children: ReactNode;\n  className?: string;\n  containerRef?: RefObject<HTMLElement | null>;\n};\n\nexport function TimelineAnimation({\n  children,\n  className,\n  containerRef,\n}: TimelineAnimationProps) {\n  const value = useMemo(() => ({ containerRef }), [containerRef]);\n\n  return (\n    <TimelineAnimationContext value={value}>\n      <ol className={cn('flex flex-col', className)}>{children}</ol>\n    </TimelineAnimationContext>\n  );\n}\n\nexport type TimelineAnimationItemProps = {\n  children: ReactNode;\n  className?: string;\n};\n\nexport function TimelineAnimationItem({\n  children,\n  className,\n}: TimelineAnimationItemProps) {\n  const itemRef = useRef<HTMLLIElement>(null);\n  const segmentRef = useRef<HTMLSpanElement>(null);\n  const { containerRef } = useContext(TimelineAnimationContext);\n  const prefersReducedMotion = usePrefersReducedMotion();\n\n  const isInView = useInView(itemRef, {\n    root: containerRef,\n    once: true,\n    margin: SETTLE_MARGIN,\n  });\n  const prefersStill = Boolean(prefersReducedMotion);\n  const isSettled = isInView || prefersStill;\n  const settleState = settleStateOf(isSettled);\n  const settleVariants = settleVariantsOf(prefersReducedMotion);\n\n  // The segment runs from this dot to the next one, so its progress fills the line exactly\n  // where the middle of the scrolling area is.\n  const { scrollYProgress } = useScroll({\n    target: segmentRef,\n    container: containerRef,\n    offset: ['start center', 'end center'],\n  });\n  const reachedOpacity = useTransform(scrollYProgress, reachedOpacityOf);\n  const lineFill = fillOf(prefersReducedMotion, scrollYProgress);\n  const dotFill = fillOf(prefersReducedMotion, reachedOpacity);\n\n  return (\n    <li\n      ref={itemRef}\n      className={cn('group/item relative ps-8 pb-10 last:pb-0', className)}\n    >\n      <span\n        ref={segmentRef}\n        aria-hidden='true'\n        className='bg-border absolute start-[7.5px] top-2.5 -bottom-2.5 w-px group-last/item:invisible'\n      >\n        <motion.span\n          style={{ scaleY: lineFill }}\n          className='bg-primary absolute inset-0 origin-top'\n        />\n      </span>\n      <span\n        aria-hidden='true'\n        className='bg-muted absolute start-0 top-0.5 grid size-4 place-items-center rounded-full'\n      >\n        <span className='bg-foreground/15 col-start-1 row-start-1 size-1.5 rounded-full' />\n        <motion.span\n          style={{ opacity: dotFill }}\n          className='bg-primary col-start-1 row-start-1 size-1.5 rounded-full transition-opacity duration-200'\n        />\n      </span>\n      <motion.div\n        initial='hidden'\n        animate={settleState}\n        variants={settleVariants}\n        transition={{ duration: SETTLE_DURATION, ease: EASE_OUT_STRONG }}\n      >\n        {children}\n      </motion.div>\n    </li>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/timeline-animation.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}