{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-volume-knob",
  "type": "registry:component",
  "title": "Volume Knob",
  "description": "A knurled hardware knob inside a 270 degree ring of LED segments. Drag up or down to turn it, hold Shift for fine control, scroll while focused, and double click to mute.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "knob",
    "dial",
    "volume",
    "audio",
    "slider",
    "micro"
  ],
  "docs": "https://hyperblur.dev/effects/micro-volume-knob",
  "files": [
    {
      "path": "registry/hyperblur/micro-volume-knob.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-volume-knob.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MicroVolumeKnobProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n  value?: number;\n  defaultValue?: number;\n  min?: number;\n  max?: number;\n  step?: number;\n  segments?: number;\n  size?: number;\n  label?: string;\n  accent?: string;\n  muted?: boolean;\n  defaultMuted?: boolean;\n  disabled?: boolean;\n  onChange?: (value: number) => void;\n  onMutedChange?: (muted: boolean) => void;\n}\n\nconst css = `\n.hb-wf4 {\n  --hb-wf4-c: #2f7bff;\n  --hb-wf4-s: 128px;\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 6px;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.hb-wf4 *, .hb-wf4 *::before, .hb-wf4 *::after { box-sizing: border-box; }\n.hb-wf4[data-disabled=\"true\"] { opacity: 0.45; pointer-events: none; }\n.hb-wf4-dial {\n  position: relative;\n  width: var(--hb-wf4-s);\n  height: var(--hb-wf4-s);\n  border-radius: 50%;\n  outline: none;\n  cursor: ns-resize;\n  touch-action: none;\n}\n.hb-wf4-dial:focus-visible .hb-wf4-cap { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wf4-c), 0 10px 22px -6px rgba(0,0,0,0.9); }\n.hb-wf4-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }\n.hb-wf4-seg { stroke: #232323; stroke-width: 3.2; stroke-linecap: round; transition: stroke 0.12s ease, opacity 0.2s ease; }\n.hb-wf4-seg[data-lit=\"true\"] { stroke: var(--hb-wf4-c); }\n.hb-wf4-seg[data-peak=\"true\"] { stroke: #ffffff; filter: drop-shadow(0 0 3px var(--hb-wf4-c)); }\n.hb-wf4[data-muted=\"true\"] .hb-wf4-seg[data-lit=\"true\"] { stroke: #3a3a3a; filter: none; }\n.hb-wf4-tk { fill: #555; font-family: var(--font-mono), ui-monospace, monospace; font-size: 7px; letter-spacing: 0.06em; }\n.hb-wf4-well {\n  position: absolute;\n  inset: 17%;\n  border-radius: 50%;\n  background: #050505;\n  box-shadow: inset 0 2px 6px rgba(0,0,0,0.9), 0 1px 0 rgba(255,255,255,0.05);\n}\n.hb-wf4-cap {\n  position: absolute;\n  inset: 20%;\n  border-radius: 50%;\n  background:\n    radial-gradient(circle at 50% 50%, #262626 0%, #1b1b1b 54%, transparent 55%),\n    repeating-conic-gradient(from 0deg, #2e2e2e 0deg 4deg, #161616 4deg 8deg);\n  box-shadow: 0 10px 22px -6px rgba(0,0,0,0.9), inset 0 1px 0 rgba(255,255,255,0.1);\n  transition: transform 0.32s cubic-bezier(0.25, 1.4, 0.45, 1), box-shadow 0.2s ease;\n}\n.hb-wf4[data-drag=\"true\"] .hb-wf4-cap { transition: none; }\n.hb-wf4-cap::before {\n  content: \"\";\n  position: absolute;\n  inset: 22%;\n  border-radius: 50%;\n  background: radial-gradient(circle at 40% 30%, #3a3a3a 0%, #1e1e1e 60%, #151515 100%);\n  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.12);\n}\n.hb-wf4-ind {\n  position: absolute;\n  left: 50%;\n  top: 7%;\n  width: 3px;\n  height: 22%;\n  margin-left: -1.5px;\n  border-radius: 2px;\n  background: var(--hb-wf4-c);\n  box-shadow: 0 0 6px var(--hb-wf4-c);\n}\n.hb-wf4[data-muted=\"true\"] .hb-wf4-ind { background: #5a5a5a; box-shadow: none; }\n.hb-wf4-ro {\n  display: flex;\n  align-items: baseline;\n  gap: 6px;\n  font-family: var(--font-mono), ui-monospace, monospace;\n  font-variant-numeric: tabular-nums;\n}\n.hb-wf4-v { font-size: 15px; font-weight: 600; min-width: 3ch; text-align: right; }\n.hb-wf4-l { font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: #777; }\n.hb-wf4[data-muted=\"true\"] .hb-wf4-v { color: #ff6a5a; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wf4-cap, .hb-wf4-seg { transition: none; }\n}\n`;\n\nconst sweep = 270;\n\nexport function MicroVolumeKnob({\n  value,\n  defaultValue = 62,\n  min = 0,\n  max = 100,\n  step = 1,\n  segments = 23,\n  size = 128,\n  label = \"Volume\",\n  accent = \"#2f7bff\",\n  muted,\n  defaultMuted = false,\n  disabled = false,\n  onChange,\n  onMutedChange,\n  className = \"\",\n  style,\n  ...rest\n}: MicroVolumeKnobProps) {\n  const [inner, setInner] = React.useState(defaultValue);\n  const [innerMuted, setInnerMuted] = React.useState(defaultMuted);\n  const v = value ?? inner;\n  const m = muted ?? innerMuted;\n  const [dragging, setDragging] = React.useState(false);\n  const dialRef = React.useRef<HTMLDivElement>(null);\n  const drag = React.useRef({ y: 0, base: 0 });\n  const api = React.useRef({ v, min, max, step, value, onChange });\n\n  React.useEffect(() => {\n    api.current = { v, min, max, step, value, onChange };\n  });\n\n  const commit = React.useCallback((raw: number) => {\n    const a = api.current;\n    const snapped = Math.round(raw / a.step) * a.step;\n    const next = Math.min(a.max, Math.max(a.min, Number(snapped.toFixed(4))));\n    if (next === a.v) return;\n    a.v = next;\n    if (a.value === undefined) setInner(next);\n    a.onChange?.(next);\n  }, []);\n\n  const toggleMute = () => {\n    const next = !m;\n    if (muted === undefined) setInnerMuted(next);\n    onMutedChange?.(next);\n  };\n\n  React.useEffect(() => {\n    const el = dialRef.current;\n    if (!el) return;\n    const onWheel = (e: WheelEvent) => {\n      if (document.activeElement !== el) return;\n      e.preventDefault();\n      const a = api.current;\n      commit(a.v - Math.sign(e.deltaY) * a.step * (e.shiftKey ? 1 : 2));\n    };\n    el.addEventListener(\"wheel\", onWheel, { passive: false });\n    return () => el.removeEventListener(\"wheel\", onWheel);\n  }, [commit]);\n\n  const p = (v - min) / (max - min || 1);\n  const angle = -sweep / 2 + sweep * p;\n  const lit = Math.round(p * (segments - 1));\n  const segs = Array.from({ length: segments }, (_, i) => {\n    const a = ((-sweep / 2 + (sweep * i) / (segments - 1)) * Math.PI) / 180;\n    const r1 = 55;\n    const r2 = i % 5 === 0 ? 62 : 60;\n    return {\n      x1: (64 + r1 * Math.sin(a)).toFixed(2),\n      y1: (64 - r1 * Math.cos(a)).toFixed(2),\n      x2: (64 + r2 * Math.sin(a)).toFixed(2),\n      y2: (64 - r2 * Math.cos(a)).toFixed(2),\n      on: p > 0 && i <= lit,\n      peak: p > 0 && i === lit,\n    };\n  });\n\n  return (\n    <div\n      className={`hb-wf4 ${className}`}\n      data-drag={dragging}\n      data-muted={m}\n      data-disabled={disabled}\n      style={{ ...style, [\"--hb-wf4-c\" as string]: accent, [\"--hb-wf4-s\" as string]: `${size}px` }}\n      {...rest}\n    >\n      <style href=\"hb-micro-volume-knob\" precedence=\"default\">\n        {css}\n      </style>\n      <div\n        ref={dialRef}\n        className=\"hb-wf4-dial\"\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={m ? `Muted, ${v}` : `${v}`}\n        aria-disabled={disabled || undefined}\n        onPointerDown={(e) => {\n          if (disabled) return;\n          e.currentTarget.setPointerCapture(e.pointerId);\n          e.currentTarget.focus();\n          drag.current = { y: e.clientY, base: v };\n          setDragging(true);\n        }}\n        onPointerMove={(e) => {\n          if (!dragging) return;\n          const range = max - min;\n          const k = e.shiftKey ? 0.25 : 1;\n          commit(drag.current.base + ((drag.current.y - e.clientY) / 160) * range * k);\n        }}\n        onPointerUp={() => setDragging(false)}\n        onPointerCancel={() => setDragging(false)}\n        onDoubleClick={toggleMute}\n        onKeyDown={(e) => {\n          const big = (max - min) / 10;\n          if (e.key === \"ArrowUp\" || e.key === \"ArrowRight\") {\n            e.preventDefault();\n            commit(v + step);\n          } else if (e.key === \"ArrowDown\" || e.key === \"ArrowLeft\") {\n            e.preventDefault();\n            commit(v - step);\n          } else if (e.key === \"PageUp\") {\n            e.preventDefault();\n            commit(v + big);\n          } else if (e.key === \"PageDown\") {\n            e.preventDefault();\n            commit(v - big);\n          } else if (e.key === \"Home\") {\n            e.preventDefault();\n            commit(min);\n          } else if (e.key === \"End\") {\n            e.preventDefault();\n            commit(max);\n          } else if (e.key === \"m\" || e.key === \"M\") {\n            e.preventDefault();\n            toggleMute();\n          }\n        }}\n      >\n        <svg className=\"hb-wf4-svg\" viewBox=\"0 0 128 128\" aria-hidden=\"true\">\n          {segs.map((s, i) => (\n            <line key={i} className=\"hb-wf4-seg\" data-lit={s.on} data-peak={s.peak} x1={s.x1} y1={s.y1} x2={s.x2} y2={s.y2} />\n          ))}\n          <text className=\"hb-wf4-tk\" x=\"22\" y=\"122\" textAnchor=\"middle\">MIN</text>\n          <text className=\"hb-wf4-tk\" x=\"106\" y=\"122\" textAnchor=\"middle\">MAX</text>\n        </svg>\n        <span className=\"hb-wf4-well\" aria-hidden=\"true\" />\n        <span className=\"hb-wf4-cap\" aria-hidden=\"true\" style={{ transform: `rotate(${angle.toFixed(2)}deg)` }}>\n          <span className=\"hb-wf4-ind\" />\n        </span>\n      </div>\n      <div className=\"hb-wf4-ro\" aria-hidden=\"true\">\n        <span className=\"hb-wf4-v\">{m ? \"MUTE\" : v}</span>\n        <span className=\"hb-wf4-l\">{label}</span>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}