{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "knob",
  "title": "Knob",
  "description": "A rotary dial for picking a value in a range, like a mixer control: drag up or down, scroll or use the keyboard, with a 270° progress ring and a sliding thumb, or a physical-looking knob with an indicator and ticks that light up as it turns.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/knob/knob.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface KnobProps {\n  value?: number;\n  defaultValue?: number;\n  onValueChange?: (value: number) => void;\n  min?: number;\n  max?: number;\n  step?: number;\n  label?: string;\n  /** Text after the number, e.g. \"%\" or \" dB\". */\n  unit?: string;\n  /** Format the centre readout yourself. */\n  format?: (value: number) => string;\n  /** ring: a progress arc. dial: a physical-looking knob with an indicator and ticks. */\n  variant?: \"ring\" | \"dial\";\n  size?: number;\n  /** Arc colour. */\n  color?: string;\n  disabled?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", track: \"rgba(255,255,255,0.1)\", arc: \"#F5F4F1\", knob: \"#1A1A1A\", knobEdge: \"rgba(255,255,255,0.14)\", tick: \"rgba(255,255,255,0.22)\", tickOn: \"#F5F4F1\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", track: \"rgba(10,10,10,0.1)\", arc: \"#0A0A0A\", knob: \"#FFFFFF\", knobEdge: \"rgba(10,10,10,0.14)\", tick: \"rgba(10,10,10,0.2)\", tickOn: \"#0A0A0A\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst START = 135; // degrees, measured clockwise from 3 o'clock\nconst SWEEP = 270;\n\n// Rounded so the server and the browser print identical coordinates (Math.cos can differ in the last digit).\nconst r3 = (n: number) => Math.round(n * 1000) / 1000;\nconst polar = (cx: number, cy: number, r: number, deg: number) => {\n  const a = (deg * Math.PI) / 180;\n  return [r3(cx + r * Math.cos(a)), r3(cy + r * Math.sin(a))];\n};\nconst arcPath = (cx: number, cy: number, r: number, a0: number, a1: number) => {\n  const [x0, y0] = polar(cx, cy, r, a0);\n  const [x1, y1] = polar(cx, cy, r, a1);\n  return `M ${x0} ${y0} A ${r} ${r} 0 ${a1 - a0 > 180 ? 1 : 0} 1 ${x1} ${y1}`;\n};\n\nexport function Knob({ value, defaultValue = 50, onValueChange, min = 0, max = 100, step = 1, label = \"Volume\", unit = \"%\", format, variant = \"ring\", size = 128, color, disabled = false, theme = \"dark\", className }: KnobProps) {\n  const p = PALETTES[theme];\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultValue);\n  const v = value ?? internal;\n  const frac = (v - min) / (max - min);\n  const shown = useSpring(frac, { stiffness: 380, damping: 34 });\n  React.useEffect(() => {\n    if (reduce) shown.jump(frac);\n    else shown.set(frac);\n  }, [frac, shown, reduce]);\n  const [active, setActive] = React.useState(false);\n  const drag = React.useRef<{ y: number; start: number } | null>(null);\n\n  const clamp = (n: number) => Math.min(max, Math.max(min, Math.round(n / step) * step));\n  const set = React.useCallback(\n    (n: number) => {\n      const c = clamp(Number(n.toFixed(6)));\n      if (value === undefined) setInternal(c);\n      onValueChange?.(c);\n    },\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [value, onValueChange, min, max, step],\n  );\n\n  const c = size / 2;\n  const r = size / 2 - 10;\n  const arcLen = (Math.PI * 2 * r * SWEEP) / 360;\n  const dash = useTransform(shown, (f) => `${Math.max(0.001, f) * arcLen} ${arcLen}`);\n  const angle = useTransform(shown, (f) => START + f * SWEEP);\n  const thumbX = useTransform(angle, (a) => polar(c, c, r, a)[0]);\n  const thumbY = useTransform(angle, (a) => polar(c, c, r, a)[1]);\n  // The dial's indicator: a short line from near the rim towards the centre, following the angle.\n  const indX1 = useTransform(angle, (a) => polar(c, c, r - 12, a)[0]);\n  const indY1 = useTransform(angle, (a) => polar(c, c, r - 12, a)[1]);\n  const indX2 = useTransform(angle, (a) => polar(c, c, r - 26, a)[0]);\n  const indY2 = useTransform(angle, (a) => polar(c, c, r - 26, a)[1]);\n  const arc = color ?? p.arc;\n  const readout = format ? format(v) : `${Number.isInteger(step) ? Math.round(v) : v.toFixed(1)}${unit}`;\n  const ticks = 21;\n\n  return (\n    <div className={cn(\"flex flex-col items-center select-none\", className)} style={{ gap: 10, fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      <div\n        role=\"slider\"\n        tabIndex={disabled ? -1 : 0}\n        aria-label={label}\n        aria-valuemin={min}\n        aria-valuemax={max}\n        aria-valuenow={v}\n        aria-valuetext={readout}\n        aria-disabled={disabled || undefined}\n        className=\"relative cursor-ns-resize rounded-full outline-none focus-visible:ring-2\"\n        style={{ width: size, height: size, touchAction: \"none\", [\"--tw-ring-color\" as string]: p.focus }}\n        onPointerDown={(e) => {\n          if (disabled) return;\n          (e.target as Element).setPointerCapture?.(e.pointerId);\n          drag.current = { y: e.clientY, start: v };\n          setActive(true);\n        }}\n        onPointerMove={(e) => {\n          if (!drag.current) return;\n          // Up increases; 200px of travel covers the whole range (Shift for fine control).\n          const range = max - min;\n          const delta = ((drag.current.y - e.clientY) / (e.shiftKey ? 800 : 200)) * range;\n          set(drag.current.start + delta);\n        }}\n        onPointerUp={() => {\n          drag.current = null;\n          setActive(false);\n        }}\n        onPointerCancel={() => {\n          drag.current = null;\n          setActive(false);\n        }}\n        onWheel={(e) => {\n          if (disabled) return;\n          set(v + (e.deltaY < 0 ? step : -step) * (e.shiftKey ? 10 : 1));\n        }}\n        onKeyDown={(e) => {\n          if (disabled) return;\n          const big = (max - min) / 10;\n          const map: Record<string, number> = { ArrowUp: v + step, ArrowRight: v + step, ArrowDown: v - step, ArrowLeft: v - step, PageUp: v + big, PageDown: v - big, Home: min, End: max };\n          if (e.key in map) {\n            e.preventDefault();\n            set(map[e.key]);\n          }\n        }}\n      >\n        <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"block overflow-visible\" aria-hidden=\"true\">\n          {variant === \"dial\" &&\n            Array.from({ length: ticks }, (_, i) => {\n              const a = START + (i / (ticks - 1)) * SWEEP;\n              const [x0, y0] = polar(c, c, r + 2, a);\n              const [x1, y1] = polar(c, c, r + (i % 5 === 0 ? 8 : 5), a);\n              return <line key={i} x1={x0} y1={y0} x2={x1} y2={y1} stroke={i / (ticks - 1) <= frac + 1e-6 ? p.tickOn : p.tick} strokeWidth={i % 5 === 0 ? 1.6 : 1.1} strokeLinecap=\"round\" style={{ transition: \"stroke 0.15s ease\" }} />;\n            })}\n          {variant === \"ring\" && (\n            <>\n              <path d={arcPath(c, c, r, START, START + SWEEP)} fill=\"none\" stroke={p.track} strokeWidth={6} strokeLinecap=\"round\" />\n              <motion.path d={arcPath(c, c, r, START, START + SWEEP)} fill=\"none\" stroke={arc} strokeWidth={6} strokeLinecap=\"round\" style={{ strokeDasharray: dash }} />\n              <motion.circle r={active ? 8 : 6.5} cx={thumbX} cy={thumbY} fill={arc} stroke={p.knob} strokeWidth={3} style={{ transition: \"r 0.15s ease\" }} />\n            </>\n          )}\n          {variant === \"dial\" && (\n            <>\n              <circle cx={c} cy={c} r={r - 8} fill={p.knob} stroke={p.knobEdge} strokeWidth={1} />\n              <circle cx={c} cy={c} r={r - 14} fill=\"none\" stroke={p.knobEdge} strokeWidth={1} opacity={0.6} />\n              <motion.line x1={indX1} y1={indY1} x2={indX2} y2={indY2} stroke={arc} strokeWidth={3} strokeLinecap=\"round\" />\n            </>\n          )}\n        </svg>\n        {variant === \"ring\" && (\n          <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center\">\n            <motion.span className=\"font-semibold tracking-[-0.02em] tabular-nums\" style={{ fontSize: size * 0.19, color: p.text }} animate={{ scale: active && !reduce ? 1.06 : 1 }}>\n              {readout}\n            </motion.span>\n          </div>\n        )}\n      </div>\n      {/* The dial's face carries the indicator, so its value sits underneath. */}\n      {variant === \"dial\" && (\n        <motion.span className=\"font-semibold tracking-[-0.02em] tabular-nums\" style={{ fontSize: size * 0.15, color: p.text, marginTop: -4 }} animate={{ scale: active && !reduce ? 1.06 : 1 }}>\n          {readout}\n        </motion.span>\n      )}\n      <span className=\"text-[12.5px] font-medium tracking-wide uppercase\" style={{ color: p.muted }}>\n        {label}\n      </span>\n    </div>\n  );\n}\n\nexport default Knob;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}