{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "worm-dots",
  "type": "registry:ui",
  "title": "Worm Dots",
  "description": "A chain of dots that follows the pointer, each one a little later than the one before.",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/prequelui/moments/shared.tsx",
      "target": "components/prequelui/moments/shared.tsx",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport type { Transition } from \"motion/react\";\nimport { useHydratedReducedMotion } from \"@/lib/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport { cn, useHydratedReducedMotion };\n\nexport type MomentProps = {\n  className?: string;\n  preview?: boolean;\n};\n\nexport const springFast: Transition = { type: \"spring\", stiffness: 620, damping: 32 };\nexport const springSoft: Transition = { type: \"spring\", stiffness: 260, damping: 22 };\nexport const springBounce: Transition = { type: \"spring\", stiffness: 380, damping: 18 };\nexport const springHeavy: Transition = { type: \"spring\", stiffness: 200, damping: 26 };\nexport const springSnap: Transition = { type: \"spring\", stiffness: 700, damping: 38 };\n\nexport const tweenFast: Transition = { duration: 0.18, ease: [0.23, 1, 0.32, 1] };\nexport const tweenSoft: Transition = { duration: 0.32, ease: [0.23, 1, 0.32, 1] };\n\nexport const surface =\n  \"relative flex h-[150px] w-[230px] max-w-full select-none items-center justify-center text-foreground\";\n\nexport function usePreviewPulse(\n  preview: boolean | undefined,\n  duration = 900,\n  gap = 2500,\n) {\n  const [on, setOn] = useState(false);\n  const reduce = useHydratedReducedMotion();\n\n  useEffect(() => {\n    if (!preview || reduce) {\n      setOn(false);\n      return;\n    }\n    let close = 0;\n    let next = 0;\n    const run = () => {\n      setOn(true);\n      close = window.setTimeout(() => setOn(false), duration);\n      next = window.setTimeout(run, gap);\n    };\n    run();\n    return () => {\n      window.clearTimeout(close);\n      window.clearTimeout(next);\n    };\n  }, [preview, reduce, duration, gap]);\n\n  return on && !reduce;\n}\n\nexport function usePreviewStep(\n  preview: boolean | undefined,\n  steps: number,\n  interval = 1500,\n) {\n  const [step, setStep] = useState(0);\n  const reduce = useHydratedReducedMotion();\n\n  useEffect(() => {\n    if (!preview || reduce) return;\n    setStep(1);\n    const id = window.setInterval(\n      () => setStep((current) => (current + 1) % steps),\n      interval,\n    );\n    return () => window.clearInterval(id);\n  }, [preview, reduce, steps, interval]);\n\n  return reduce ? 0 : step;\n}\n\nexport function usePreviewPointer(\n  preview: boolean | undefined,\n  width = 220,\n  height = 120,\n) {\n  const [point, setPoint] = useState({ x: width / 2, y: height / 2 });\n  const reduce = useHydratedReducedMotion();\n\n  useEffect(() => {\n    if (!preview || reduce) return;\n    let frame = 0;\n    let start = 0;\n    const loop = (time: number) => {\n      if (!start) start = time;\n      const t = (time - start) / 1000;\n      const x = width / 2 + Math.cos(t * 1.4) * (width * 0.36);\n      const y = height / 2 + Math.sin(t * 2.1) * (height * 0.28);\n      setPoint({ x, y });\n      frame = requestAnimationFrame(loop);\n    };\n    frame = requestAnimationFrame(loop);\n    return () => cancelAnimationFrame(frame);\n  }, [preview, reduce, width, height]);\n\n  return [point, setPoint] as const;\n}\n\nexport function clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value));\n}\n\n/**\n * The docs stage zooms its children (CSS `zoom`), so a pointer event reports\n * positions in zoomed pixels while the component lays itself out unscaled.\n * Normalise the event back into the component's own coordinate space.\n */\nexport function localPoint(\n  event: { clientX: number; clientY: number },\n  node: HTMLElement,\n) {\n  const rect = node.getBoundingClientRect();\n  const scaleX = node.offsetWidth ? rect.width / node.offsetWidth : 1;\n  const scaleY = node.offsetHeight ? rect.height / node.offsetHeight : 1;\n  return {\n    x: (event.clientX - rect.left) / (scaleX || 1),\n    y: (event.clientY - rect.top) / (scaleY || 1),\n  };\n}\n\nexport function naturalWidth(node: HTMLElement) {\n  return node.offsetWidth || node.getBoundingClientRect().width;\n}\n\nexport function pointerScaleX(node: HTMLElement) {\n  const rect = node.getBoundingClientRect();\n  return node.offsetWidth ? rect.width / node.offsetWidth : 1;\n}\n"
    },
    {
      "path": "components/prequelui/moments/worm-dots.tsx",
      "target": "components/prequelui/moments/worm-dots.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { motion } from \"motion/react\";\nimport { useRef, useState } from \"react\";\nimport {\n  clamp,\n  cn,\n  localPoint,\n  surface,\n  useHydratedReducedMotion,\n  usePreviewPointer,\n  type MomentProps,\n} from \"./shared\";\n\nconst DOTS = Array.from({ length: 7 }, (_, index) => index);\nconst WIDTH = 190;\nconst HEIGHT = 58;\n\nexport function WormDots({ className, preview }: MomentProps) {\n  const [point, setPoint] = usePreviewPointer(preview, WIDTH, HEIGHT);\n  const [dir, setDir] = useState(1);\n  const lastX = useRef(WIDTH / 2);\n  const reduce = useHydratedReducedMotion();\n\n  const move = (event: React.PointerEvent<HTMLDivElement>) => {\n    const next = localPoint(event, event.currentTarget);\n    const direction = next.x >= lastX.current ? 1 : -1;\n    if (direction !== dir) setDir(direction);\n    lastX.current = next.x;\n    setPoint(next);\n  };\n\n  const key = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    if (![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)) {\n      return;\n    }\n    event.preventDefault();\n    const dx = event.key === \"ArrowRight\" ? 16 : event.key === \"ArrowLeft\" ? -16 : 0;\n    const dy = event.key === \"ArrowDown\" ? 10 : event.key === \"ArrowUp\" ? -10 : 0;\n    if (dx !== 0) {\n      const direction = dx > 0 ? 1 : -1;\n      if (direction !== dir) setDir(direction);\n    }\n    setPoint((current) => ({\n      x: clamp(current.x + dx, 7, WIDTH - 7),\n      y: clamp(current.y + dy, 12, HEIGHT - 12),\n    }));\n  };\n\n  const headX = clamp(point.x, 18, WIDTH - 18);\n  const headY = clamp(point.y, 14, HEIGHT - 14);\n\n  return (\n    <div\n      role=\"group\"\n      tabIndex={0}\n      aria-label=\"Worm dots, move the pointer or use arrow keys\"\n      onKeyDown={key}\n      className={cn(\n        surface,\n        \"overflow-hidden rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-white/50\",\n        className,\n      )}\n    >\n      <div\n        className=\"relative h-[58px] w-[190px] touch-none\"\n        onPointerMove={move}\n        onPointerLeave={() => {\n          lastX.current = WIDTH / 2;\n          setPoint({ x: WIDTH / 2, y: HEIGHT / 2 });\n        }}\n      >\n        {DOTS.map((index) => {\n          const size = 12 - index * 0.65;\n          const targetX =\n            (reduce ? 64 + index * 11 : headX - index * 12 * dir) - size / 2;\n          const targetY = (reduce ? HEIGHT / 2 : headY) - size / 2;\n          return (\n            <motion.span\n              key={index}\n              className=\"absolute left-0 top-0 rounded-full bg-white\"\n              style={{\n                width: size,\n                height: size,\n                opacity: 1 - index * 0.07,\n              }}\n              animate={{ x: targetX, y: targetY }}\n              transition={\n                reduce\n                  ? { duration: 0 }\n                  : {\n                      type: \"spring\",\n                      stiffness: 680 - index * 70,\n                      damping: 30 - index * 1.4,\n                      mass: 1,\n                    }\n              }\n            >\n              {index === 0 ? (\n                <>\n                  <span\n                    className=\"absolute top-[38%] size-[2px] rounded-full bg-black/70\"\n                    style={{ left: \"28%\" }}\n                  />\n                  <span\n                    className=\"absolute top-[38%] size-[2px] rounded-full bg-black/70\"\n                    style={{ right: \"28%\" }}\n                  />\n                </>\n              ) : null}\n            </motion.span>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"
    },
    {
      "path": "lib/use-reduced-motion.ts",
      "target": "lib/use-reduced-motion.ts",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useSyncExternalStore } from \"react\";\n\nconst subscribe = () => () => {};\n\nexport function useHydratedReducedMotion() {\n  const reduce = useReducedMotion() ?? false;\n  const mounted = useSyncExternalStore(\n    subscribe,\n    () => true,\n    () => false,\n  );\n  return mounted ? reduce : false;\n}\n"
    }
  ]
}
