{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dot-revolve",
  "type": "registry:ui",
  "title": "Dot Revolve",
  "description": "A small system of dots orbiting a centre, where a click changes the speed and direction.",
  "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/dot-revolve.tsx",
      "target": "components/prequelui/moments/dot-revolve.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport {\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  cn,\n  pointerScaleX,\n  surface,\n  useHydratedReducedMotion,\n  type MomentProps,\n} from \"./shared\";\n\nconst DOTS = Array.from({ length: 6 }, (_, index) => index);\nconst RADIUS = 42;\n\nfunction OrbitDot({\n  angle,\n  index,\n  speed,\n  reduce,\n}: {\n  angle: MotionValue<number>;\n  index: number;\n  speed: number;\n  reduce: boolean;\n}) {\n  const offset = (360 / DOTS.length) * index;\n  const x = useTransform(angle, (value) => {\n    return Math.cos(((value + offset) * Math.PI) / 180) * (RADIUS + index * 2);\n  });\n  const y = useTransform(angle, (value) => {\n    return Math.sin(((value + offset) * Math.PI) / 180) * (RADIUS + index * 2) * 0.72;\n  });\n  return (\n    <motion.span\n      aria-hidden=\"true\"\n      className=\"absolute left-1/2 top-1/2 rounded-full bg-white\"\n      style={{\n        x,\n        y,\n        width: 10 - index * 0.8,\n        height: 10 - index * 0.8,\n        marginLeft: -(10 - index * 0.8) / 2,\n        marginTop: -(10 - index * 0.8) / 2,\n        opacity: 1 - index * 0.1,\n      }}\n      animate={{ scale: reduce ? 1 : [1, 1.25, 1] }}\n      transition={{\n        duration: 2.4 - speed * 0.2,\n        repeat: reduce ? 0 : Infinity,\n        ease: \"easeInOut\",\n      }}\n    />\n  );\n}\n\nexport function DotRevolve({ className }: MomentProps) {\n  const angle = useMotionValue(0);\n  const direction = useRef(1);\n  const speedRef = useRef(1);\n  const [directionLabel, setDirectionLabel] = useState(\"CW\");\n  const [speedLabel, setSpeedLabel] = useState(1);\n  const [mounted, setMounted] = useState(false);\n  const reduce = useHydratedReducedMotion();\n  const dragging = useRef<{ x: number; speed: number; moved: boolean } | null>(null);\n  const dragged = useRef(false);\n\n  useEffect(() => setMounted(true), []);\n\n  useAnimationFrame((_, delta) => {\n    if (reduce) return;\n    angle.set(angle.get() + direction.current * speedRef.current * 42 * (delta / 1000));\n  });\n\n  const change = () => {\n    direction.current *= -1;\n    speedRef.current = speedRef.current === 1 ? 1.8 : 1;\n    setDirectionLabel(direction.current > 0 ? \"CW\" : \"CCW\");\n    setSpeedLabel(speedRef.current);\n  };\n\n  const key = (event: React.KeyboardEvent) => {\n    if (event.key === \"ArrowRight\") {\n      event.preventDefault();\n      speedRef.current = Math.min(3, speedRef.current + 0.3);\n      setSpeedLabel(Math.round(speedRef.current * 10) / 10);\n    }\n    if (event.key === \"ArrowLeft\") {\n      event.preventDefault();\n      speedRef.current = Math.max(0.2, speedRef.current - 0.3);\n      setSpeedLabel(Math.round(speedRef.current * 10) / 10);\n    }\n    if (event.key === \"Enter\" || event.key === \" \") {\n      event.preventDefault();\n      change();\n    }\n  };\n\n  return (\n    <div className={cn(surface, \"flex-col gap-2\", className)}>\n      <div\n        role=\"button\"\n        tabIndex={0}\n        aria-label={`Dot revolve, ${directionLabel} at ${speedLabel} times speed. Press Enter to change.`}\n        onClick={() => {\n          if (dragged.current) {\n            dragged.current = false;\n            return;\n          }\n          change();\n        }}\n        onKeyDown={key}\n        onPointerDown={(event) => {\n          event.currentTarget.setPointerCapture(event.pointerId);\n          dragging.current = {\n            x: event.clientX,\n            speed: speedRef.current,\n            moved: false,\n          };\n          dragged.current = false;\n        }}\n        onPointerMove={(event) => {\n          if (!dragging.current) return;\n          const raw = event.clientX - dragging.current.x;\n          if (Math.abs(raw) > 3) {\n            dragging.current.moved = true;\n            dragged.current = true;\n          }\n          const scale = pointerScaleX(event.currentTarget);\n          const delta = raw / (80 * (scale || 1));\n          speedRef.current = Math.max(0.2, Math.min(3, dragging.current.speed + delta));\n          setSpeedLabel(Math.round(speedRef.current * 10) / 10);\n        }}\n        onPointerUp={(event) => {\n          if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n            event.currentTarget.releasePointerCapture(event.pointerId);\n          }\n          dragging.current = null;\n        }}\n        onPointerCancel={(event) => {\n          if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n            event.currentTarget.releasePointerCapture(event.pointerId);\n          }\n          dragging.current = null;\n          dragged.current = false;\n        }}\n        className=\"relative flex size-[132px] cursor-grab touch-none items-center justify-center rounded-full border border-white/10 bg-[#111114] outline-none active:cursor-grabbing focus-visible:ring-2 focus-visible:ring-white/50\"\n      >\n        <span className=\"absolute size-[86px] rounded-full border border-dashed border-white/10\" />\n        {mounted ? (\n          DOTS.map((index) => (\n            <OrbitDot\n              key={index}\n              angle={angle}\n              index={index}\n              speed={speedLabel}\n              reduce={reduce}\n            />\n          ))\n        ) : (\n          <span aria-hidden=\"true\" className=\"absolute inset-0\">\n            {DOTS.map((index) => {\n              const offset = (360 / DOTS.length) * index;\n              const size = 10 - index * 0.8;\n              const x = (\n                Math.cos((offset * Math.PI) / 180) * (RADIUS + index * 2)\n              ).toFixed(3);\n              const y = (\n                Math.sin((offset * Math.PI) / 180) *\n                (RADIUS + index * 2) *\n                0.72\n              ).toFixed(3);\n              return (\n                <span\n                  key={index}\n                  className=\"absolute left-1/2 top-1/2 block rounded-full bg-white\"\n                  style={{\n                    width: `${size}px`,\n                    height: `${size}px`,\n                    marginLeft: `${-size / 2}px`,\n                    marginTop: `${-size / 2}px`,\n                    opacity: `${(1 - index * 0.1).toFixed(2)}`,\n                    transform: `translate(${x}px, ${y}px)`,\n                  }}\n                />\n              );\n            })}\n          </span>\n        )}\n        <span className=\"relative z-10 flex size-8 items-center justify-center rounded-full bg-white text-[13px] font-semibold text-black\">\n          {directionLabel}\n        </span>\n      </div>\n      <span\n        aria-live=\"polite\"\n        className=\"text-[13px] uppercase tracking-[0.18em] text-white/45\"\n      >\n        {speedLabel.toFixed(1)}× orbit · {directionLabel}\n      </span>\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"
    }
  ]
}
