{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gauge-meter",
  "type": "registry:component",
  "title": "Gauge Meter",
  "description": "A semicircular gauge with colored zones, tick marks, an animated needle and a large readout that counts to the value.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "charts",
    "gauge",
    "meter",
    "speedometer",
    "score",
    "kpi",
    "needle"
  ],
  "docs": "https://hyperblur.dev/effects/gauge-meter",
  "files": [
    {
      "path": "registry/hyperblur/gauge-meter.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/gauge-meter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface GaugeZone {\n  to: number;\n  color: string;\n  label?: string;\n}\n\nexport interface GaugeMeterProps extends React.HTMLAttributes<HTMLDivElement> {\n  value?: number;\n  min?: number;\n  max?: number;\n  zones?: GaugeZone[];\n  label?: string;\n  unit?: string;\n  decimals?: number;\n  ticks?: number;\n  showMinMax?: boolean;\n  needleColor?: string;\n  size?: number | string;\n  valueFormatter?: (n: number) => string;\n  animate?: boolean;\n}\n\nconst DEFAULT_ZONES: GaugeZone[] = [\n  { to: 40, color: \"#fb7185\", label: \"Low\" },\n  { to: 70, color: \"#fbbf24\", label: \"Fair\" },\n  { to: 100, color: \"#34d399\", label: \"Great\" },\n];\n\nconst css = `\n.hb-gau { display: block; min-width: 0; max-width: 100%; box-sizing: border-box; color: #ededed; font-family: inherit; }\n.hb-gau *, .hb-gau *::before, .hb-gau *::after { box-sizing: border-box; }\n.hb-gau-svg { display: block; width: 100%; height: auto; overflow: visible; }\n.hb-gau-track { fill: none; stroke: #1c1c1c; stroke-width: 12; }\n.hb-gau-zone {\n  fill: none;\n  stroke-width: 12;\n  stroke-dasharray: 1;\n  stroke-dashoffset: 0;\n  animation: hb-gau-sweep .9s cubic-bezier(.22, .8, .24, 1) backwards;\n  animation-delay: calc(var(--hb-gau-z, 0) * 160ms);\n  transition: opacity .25s ease, stroke-width .2s ease;\n}\n.hb-gau-zone[data-on=\"false\"] { opacity: .32; }\n.hb-gau-tick { stroke: #3a3a3a; stroke-width: 1; }\n.hb-gau-tick[data-major=\"true\"] { stroke: #5a5a5a; stroke-width: 1.4; }\n.hb-gau-needle {\n  transition: transform 1.1s cubic-bezier(.22, .8, .24, 1);\n}\n.hb-gau-hub { fill: #0a0a0a; stroke-width: 2.5; }\n.hb-gau-num {\n  fill: #ededed;\n  font-size: 28px;\n  font-weight: 600;\n  letter-spacing: -.02em;\n  font-family: var(--font-grotesk, ui-sans-serif, system-ui, sans-serif);\n  font-variant-numeric: tabular-nums;\n}\n.hb-gau-unit { fill: #8f8f8f; font-size: 13px; font-weight: 500; letter-spacing: 0; }\n.hb-gau-lab { fill: #8f8f8f; font-size: 11px; font-family: inherit; }\n.hb-gau-edge {\n  fill: #6b6b6b;\n  font-size: 10px;\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-variant-numeric: tabular-nums;\n}\n.hb-gau[data-animate=\"false\"] .hb-gau-zone { animation: none; }\n@keyframes hb-gau-sweep {\n  from { stroke-dashoffset: 1; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-gau-zone { animation: none !important; }\n  .hb-gau-zone, .hb-gau-needle { transition: none !important; }\n}\n`;\n\nconst CX = 100;\nconst CY = 98;\nconst R = 80;\n\nfunction f(n: number) {\n  return n.toFixed(2);\n}\n\nfunction pointAt(frac: number, r: number): [number, number] {\n  const t = Math.PI * (1 - frac);\n  return [CX + r * Math.cos(t), CY - r * Math.sin(t)];\n}\n\nfunction arc(a: number, b: number) {\n  const [x0, y0] = pointAt(a, R);\n  const [x1, y1] = pointAt(b, R);\n  return `M${f(x0)},${f(y0)}A${R},${R} 0 0 1 ${f(x1)},${f(y1)}`;\n}\n\nfunction useAnimatedValue(target: number, from: number, animate: boolean) {\n  const [shown, setShown] = React.useState(from);\n  const ref = React.useRef(from);\n  React.useEffect(() => {\n    if (!animate) return;\n    const reduce =\n      typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const duration = reduce ? 0 : 1100;\n    const start = ref.current;\n    const t0 = performance.now();\n    let id = 0;\n    const tick = (now: number) => {\n      const p = duration === 0 ? 1 : Math.min(1, (now - t0) / duration);\n      const e = 1 - Math.pow(1 - p, 3);\n      const v = start + (target - start) * e;\n      ref.current = v;\n      setShown(v);\n      if (p < 1) id = requestAnimationFrame(tick);\n    };\n    id = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(id);\n  }, [target, animate]);\n  return animate ? shown : target;\n}\n\nexport function GaugeMeter({\n  value = 72,\n  min = 0,\n  max = 100,\n  zones = DEFAULT_ZONES,\n  label,\n  unit = \"\",\n  decimals = 0,\n  ticks = 11,\n  showMinMax = true,\n  needleColor = \"#ededed\",\n  size = \"100%\",\n  valueFormatter,\n  animate = true,\n  className = \"\",\n  style,\n  ...rest\n}: GaugeMeterProps) {\n  const span = max > min ? max - min : 1;\n  const clamped = Math.min(max, Math.max(min, Number.isFinite(value) ? value : min));\n  const shown = useAnimatedValue(clamped, min, animate);\n\n  const [mounted, setMounted] = React.useState(!animate);\n  React.useEffect(() => {\n    if (!animate) return;\n    const a = requestAnimationFrame(() => setMounted(true));\n    return () => cancelAnimationFrame(a);\n  }, [animate]);\n\n  const sorted = [...zones].sort((a, b) => a.to - b.to);\n  const segs = sorted.map((z, i) => {\n    const from = i === 0 ? min : sorted[i - 1].to;\n    const a = Math.min(1, Math.max(0, (from - min) / span));\n    const b = Math.min(1, Math.max(0, (z.to - min) / span));\n    return { ...z, i, a, b };\n  });\n  const current = segs.find((s) => clamped <= s.to && clamped >= min + s.a * span) ?? segs[segs.length - 1];\n  const activeIdx = current ? current.i : -1;\n\n  const frac = (clamped - min) / span;\n  const deg = mounted ? -90 + frac * 180 : -90;\n  const fmt = valueFormatter ?? ((n: number) => n.toFixed(Math.max(0, decimals)));\n  const sub = label ?? current?.label ?? \"\";\n  const tickCount = Math.max(0, Math.round(ticks));\n\n  const text = `Gauge: ${fmt(clamped)}${unit} on a scale from ${fmt(min)} to ${fmt(max)}${\n    current?.label ? `, ${current.label}` : \"\"\n  }${label ? `, ${label}` : \"\"}.`;\n\n  return (\n    <div\n      className={`hb-gau ${className}`}\n      data-animate={animate ? \"true\" : \"false\"}\n      style={{ width: size, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-gauge-meter\" precedence=\"default\">{css}</style>\n      <svg className=\"hb-gau-svg\" viewBox=\"0 0 200 152\" role=\"img\" aria-label={text}>\n        <path className=\"hb-gau-track\" d={arc(0, 1)} />\n        {segs.map((s) => {\n          const gap = segs.length > 1 ? 0.006 : 0;\n          const a = s.a + (s.i === 0 ? 0 : gap);\n          const b = s.b - (s.i === segs.length - 1 ? 0 : gap);\n          if (b <= a) return null;\n          return (\n            <path\n              key={s.i}\n              className=\"hb-gau-zone\"\n              data-on={s.i === activeIdx ? \"true\" : \"false\"}\n              d={arc(a, b)}\n              pathLength={1}\n              stroke={s.color}\n              style={{ [\"--hb-gau-z\" as string]: s.i }}\n            />\n          );\n        })}\n        {Array.from({ length: tickCount }, (_, k) => {\n          const t = tickCount > 1 ? k / (tickCount - 1) : 0;\n          const major = k % 5 === 0 || k === tickCount - 1;\n          const [x0, y0] = pointAt(t, R - 13);\n          const [x1, y1] = pointAt(t, R - (major ? 20 : 17));\n          return (\n            <line\n              key={k}\n              className=\"hb-gau-tick\"\n              data-major={major ? \"true\" : \"false\"}\n              x1={f(x0)}\n              y1={f(y0)}\n              x2={f(x1)}\n              y2={f(y1)}\n            />\n          );\n        })}\n        <g\n          className=\"hb-gau-needle\"\n          style={{ transform: `rotate(${deg.toFixed(2)}deg)`, transformOrigin: `${CX}px ${CY}px` }}\n        >\n          <path\n            d={`M${CX - 3.5},${CY}L${CX},${CY - (R - 24)}L${CX + 3.5},${CY}Z`}\n            fill={needleColor}\n          />\n          <circle className=\"hb-gau-hub\" cx={CX} cy={CY} r={6} stroke={needleColor} />\n        </g>\n        <text className=\"hb-gau-num\" x={CX} y={CY + 33} textAnchor=\"middle\">\n          {fmt(shown)}\n          {unit ? (\n            <tspan className=\"hb-gau-unit\" dx={2}>\n              {unit}\n            </tspan>\n          ) : null}\n        </text>\n        {sub ? (\n          <text className=\"hb-gau-lab\" x={CX} y={CY + 49} textAnchor=\"middle\">\n            {sub}\n          </text>\n        ) : null}\n        {showMinMax ? (\n          <>\n            <text className=\"hb-gau-edge\" x={CX - R} y={CY + 16} textAnchor=\"middle\">\n              {fmt(min)}\n            </text>\n            <text className=\"hb-gau-edge\" x={CX + R} y={CY + 16} textAnchor=\"middle\">\n              {fmt(max)}\n            </text>\n          </>\n        ) : null}\n      </svg>\n    </div>\n  );\n}\n"
    }
  ]
}