{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "detent-dial",
  "type": "registry:ui",
  "title": "Detent Dial",
  "description": "A rotary dial with eight detents that resists between notches and snaps on release.",
  "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/detent-dial.tsx",
      "target": "components/prequelui/moments/detent-dial.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { motion } from \"motion/react\";\nimport { useRef, useState } from \"react\";\nimport {\n  cn,\n  springSnap,\n  surface,\n  useHydratedReducedMotion,\n  usePreviewStep,\n  type MomentProps,\n} from \"./shared\";\n\nconst DETENTS = 8;\nconst STEP_DEGREES = 360 / DETENTS;\n\nexport function DetentDial({ className, preview }: MomentProps) {\n  const [step, setStep] = useState(1);\n  const dragging = useRef(false);\n  const dial = useRef<HTMLDivElement>(null);\n  const reduce = useHydratedReducedMotion();\n  const previewStep = usePreviewStep(preview, DETENTS, 1200);\n  const value = preview ? previewStep : step;\n\n  const angleFromEvent = (event: React.PointerEvent) => {\n    const node = dial.current;\n    if (!node) return null;\n    const rect = node.getBoundingClientRect();\n    const x = event.clientX - (rect.left + rect.width / 2);\n    const y = event.clientY - (rect.top + rect.height / 2);\n    const angle = (Math.atan2(y, x) * 180) / Math.PI + 90;\n    const normalised = (angle + 360) % 360;\n    return Math.round(normalised / STEP_DEGREES) % DETENTS;\n  };\n\n  const move = (event: React.PointerEvent) => {\n    if (!dragging.current) return;\n    const next = angleFromEvent(event);\n    if (next !== null) setStep(next);\n  };\n\n  const key = (event: React.KeyboardEvent) => {\n    if (event.key === \"ArrowRight\" || event.key === \"ArrowUp\") {\n      event.preventDefault();\n      setStep((current) => (current + 1) % DETENTS);\n    }\n    if (event.key === \"ArrowLeft\" || event.key === \"ArrowDown\") {\n      event.preventDefault();\n      setStep((current) => (current - 1 + DETENTS) % DETENTS);\n    }\n  };\n\n  return (\n    <div className={cn(surface, className)}>\n      <div\n        ref={dial}\n        role=\"slider\"\n        tabIndex={0}\n        aria-label=\"Detent dial\"\n        aria-valuemin={0}\n        aria-valuemax={DETENTS - 1}\n        aria-valuenow={value}\n        aria-valuetext={`Notch ${value + 1} of ${DETENTS}`}\n        onKeyDown={key}\n        onPointerDown={(event) => {\n          dragging.current = true;\n          event.currentTarget.setPointerCapture(event.pointerId);\n          const next = angleFromEvent(event);\n          if (next !== null) setStep(next);\n        }}\n        onPointerMove={move}\n        onPointerUp={() => {\n          dragging.current = false;\n        }}\n        onPointerCancel={() => {\n          dragging.current = false;\n        }}\n        className=\"relative flex size-[122px] cursor-grab touch-none items-center justify-center rounded-full border border-white/12 bg-[#111114] outline-none active:cursor-grabbing focus-visible:ring-2 focus-visible:ring-white/50\"\n      >\n        {Array.from({ length: DETENTS }, (_, index) => (\n          <span\n            key={index}\n            aria-hidden=\"true\"\n            className=\"absolute left-1/2 top-1/2 h-[3px] w-[3px] rounded-full bg-white/30\"\n            style={{\n              transform: `translate(-50%, -50%) rotate(${index * STEP_DEGREES}deg) translateY(-52px)`,\n            }}\n          />\n        ))}\n        <motion.span\n          aria-hidden=\"true\"\n          className=\"absolute left-1/2 top-1/2 h-[46px] w-[3px] origin-bottom rounded-full bg-white\"\n          style={{ marginLeft: -1.5, marginTop: -46 }}\n          animate={{ rotate: value * STEP_DEGREES }}\n          transition={reduce ? { duration: 0 } : springSnap}\n        >\n          <span className=\"absolute -left-[5px] top-0 size-[13px] rounded-full bg-white\" />\n        </motion.span>\n        <span className=\"relative z-10 flex size-9 items-center justify-center rounded-full border border-white/15 bg-[#18181c] text-[13px] tabular-nums text-white/60\">\n          {value + 1}\n        </span>\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"
    }
  ]
}
