{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "analog-gauge",
  "type": "registry:component",
  "title": "Analog Gauge",
  "description": "An analog gauge whose needle swings and settles on its value, with a printed dial and a red zone.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Data"
  ],
  "docs": "Installed in components/furin/analog-gauge/. Docs, live controls and props table: https://furin.dev/components/analog-gauge/",
  "files": [
    {
      "path": "registry/analog-gauge/AnalogGauge.tsx",
      "content": "\"use client\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, PointerEvent } from \"react\";\nimport \"./AnalogGauge.css\";\n\nexport interface AnalogGaugeProps {\n  /** Valor que marca la aguja. */\n  value?: number;\n  /** Valor al inicio de la escala. */\n  min?: number;\n  /** Valor al final de la escala. */\n  max?: number;\n  /** Rótulo impreso en la carátula. */\n  label?: string;\n  /** Unidad impresa en la carátula. */\n  unit?: string;\n  /** Marcas grandes con número. */\n  ticks?: number;\n  /** Valor donde empieza la zona roja (usa el máximo para quitarla). */\n  redline?: number;\n  /** Diámetro del medidor, en px. */\n  size?: number;\n  /** Cuánto se pasa y oscila la aguja antes de asentarse (0 a 1). */\n  bounce?: number;\n  /** Color pintado en la punta de la aguja. */\n  accent?: string;\n  /** Cambia el valor solo cada pocos segundos (útil en demos). */\n  wander?: boolean;\n  /** Segundos entre cambios cuando wander está activo. */\n  interval?: number;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst BARRIDO = 240; // grados que recorre la aguja\nconst C = 200; // centro del lienzo SVG (viewBox 400)\nconst SUBDIV = 5;\n\nconst limitar = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));\nconst rad = (g: number) => (g * Math.PI) / 180;\nconst polar = (r: number, grados: number) => ({ x: C + r * Math.sin(rad(grados)), y: C - r * Math.cos(rad(grados)) });\n\n/** Medidor analógico: bisel cromado, carátula con marcas y números, aguja de acero con física de resorte (se pasa y se asienta) y cristal con reflejo. */\nexport function AnalogGauge({\n  value = 72,\n  min = 0,\n  max = 100,\n  label = \"Pressure\",\n  unit = \"PSI\",\n  ticks = 11,\n  redline = 85,\n  size = 320,\n  bounce = 0.55,\n  accent = \"#ff6a2a\",\n  wander = false,\n  interval = 2.8,\n  className = \"\",\n  style,\n}: AnalogGaugeProps) {\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const [auto, setAuto] = useState<number | null>(null);\n  const actual = limitar(auto ?? value, min, max);\n  const rango = max - min || 1;\n  const fraccion = (v: number) => limitar((v - min) / rango, 0, 1);\n\n  const raiz = useRef<HTMLDivElement>(null);\n  const agujaRef = useRef<SVGGElement>(null);\n  const sombraRef = useRef<SVGGElement>(null);\n  const fis = useRef({ f: 0, v: 0, meta: 0, raf: 0, t: 0, visible: true, quieto: false });\n  const zeta = useRef(0.5);\n  zeta.current = 0.9 - 0.7 * limitar(bounce, 0, 1);\n\n  const pintar = (f: number) => {\n    // f puede pasarse un poco de 0..1 por el rebote: la aguja gira libre, sin tope.\n    const g = (-BARRIDO / 2 + f * BARRIDO).toFixed(3);\n    agujaRef.current?.setAttribute(\"transform\", `rotate(${g} ${C} ${C})`);\n    sombraRef.current?.setAttribute(\"transform\", `rotate(${g} ${C} ${C})`);\n  };\n\n  const correr = () => {\n    const s = fis.current;\n    if (s.raf || !s.visible) return;\n    s.t = performance.now();\n    const paso = (ahora: number) => {\n      let dt = Math.min(0.04, Math.max(0, (ahora - s.t) / 1000));\n      s.t = ahora;\n      const w = 2 * Math.PI * 1.15;\n      while (dt > 0) {\n        const h = Math.min(dt, 1 / 240);\n        dt -= h;\n        s.v += (w * w * (s.meta - s.f) - 2 * zeta.current * w * s.v) * h;\n        s.f += s.v * h;\n      }\n      pintar(s.f);\n      if (Math.abs(s.f - s.meta) < 0.0004 && Math.abs(s.v) < 0.004) { s.f = s.meta; s.v = 0; s.raf = 0; pintar(s.f); return; }\n      if (!s.visible) { s.raf = 0; return; }\n      s.raf = requestAnimationFrame(paso);\n    };\n    s.raf = requestAnimationFrame(paso);\n  };\n\n  // Entrada: la aguja parte del mínimo y se asienta en su valor. Con movimiento reducido va directo.\n  useEffect(() => {\n    const s = fis.current;\n    s.quieto = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    s.meta = fraccion(actual);\n    if (s.quieto) { cancelAnimationFrame(s.raf); s.raf = 0; s.f = s.meta; s.v = 0; pintar(s.f); return; }\n    correr();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [actual, min, max]);\n\n  // Duerme fuera de pantalla.\n  useEffect(() => {\n    const el = raiz.current;\n    if (!el) return;\n    const io = new IntersectionObserver(([e]) => {\n      fis.current.visible = e.isIntersecting;\n      if (e.isIntersecting && Math.abs(fis.current.f - fis.current.meta) > 0.0004) correr();\n    });\n    io.observe(el);\n    return () => { io.disconnect(); cancelAnimationFrame(fis.current.raf); fis.current.raf = 0; };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  // Modo demo: nuevos valores al azar cada cierto tiempo, solo si se ve.\n  useEffect(() => {\n    if (!wander || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { setAuto(null); return; }\n    let id = 0;\n    let previo = fraccion(actual);\n    const siguiente = () => {\n      if (fis.current.visible) {\n        let n = previo;\n        for (let i = 0; i < 6 && Math.abs(n - previo) < 0.28; i++) n = 0.08 + Math.random() * 0.88;\n        previo = n;\n        setAuto(min + n * rango);\n      }\n      id = window.setTimeout(siguiente, Math.max(0.8, interval) * 1000);\n    };\n    id = window.setTimeout(siguiente, 1800);\n    return () => window.clearTimeout(id);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [wander, interval, min, max]);\n\n  const alMover = (e: PointerEvent<HTMLDivElement>) => {\n    const r = e.currentTarget.getBoundingClientRect();\n    e.currentTarget.style.setProperty(\"--fag-x\", limitar((e.clientX - r.left) / r.width, 0, 1).toFixed(3));\n    e.currentTarget.style.setProperty(\"--fag-y\", limitar((e.clientY - r.top) / r.height, 0, 1).toFixed(3));\n  };\n  const alSalir = (e: PointerEvent<HTMLDivElement>) => {\n    e.currentTarget.style.removeProperty(\"--fag-x\");\n    e.currentTarget.style.removeProperty(\"--fag-y\");\n  };\n\n  // Marcas: grandes con número y pequeñas entre ellas; las de la zona roja se pintan de rojo.\n  const segmentos = Math.max(2, ticks - 1);\n  const total = segmentos * SUBDIV;\n  const zonaRoja = redline < max;\n  const fRoja = fraccion(redline);\n  const marcas = Array.from({ length: total + 1 }, (_, m) => {\n    const f = m / total;\n    const grande = m % SUBDIV === 0;\n    const a = -BARRIDO / 2 + f * BARRIDO;\n    const p1 = polar(160, a);\n    const p2 = polar(grande ? 140 : 150, a);\n    return { ...p1, x2: p2.x, y2: p2.y, grande, roja: zonaRoja && f >= fRoja - 1e-6 };\n  });\n  const numeros = Array.from({ length: segmentos + 1 }, (_, i) => {\n    const f = i / segmentos;\n    const p = polar(116, -BARRIDO / 2 + f * BARRIDO);\n    const v = min + f * rango;\n    return { ...p, texto: String(Number(v.toFixed(1))), roja: zonaRoja && f >= fRoja - 1e-6 };\n  });\n  const arco = (() => {\n    if (!zonaRoja) return \"\";\n    const a0 = -BARRIDO / 2 + fRoja * BARRIDO;\n    const a1 = BARRIDO / 2;\n    const p0 = polar(166, a0);\n    const p1 = polar(166, a1);\n    return `M ${p0.x.toFixed(2)} ${p0.y.toFixed(2)} A 166 166 0 ${a1 - a0 > 180 ? 1 : 0} 1 ${p1.x.toFixed(2)} ${p1.y.toFixed(2)}`;\n  })();\n\n  const f0 = -BARRIDO / 2;\n  const aguja = \"M198.7 52 L192.6 200 L195.4 246 L204.6 246 L207.4 200 L201.3 52 Z\";\n  const vars = { \"--fag-size\": `${size}px`, \"--fag-accent\": accent } as CSSProperties;\n  return (\n    <div\n      ref={raiz}\n      className={`furin-analog-gauge ${className}`}\n      style={{ ...vars, ...style }}\n      role=\"meter\"\n      aria-label={label}\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={Number(actual.toFixed(2))}\n      aria-valuetext={`${Number(actual.toFixed(1))} ${unit}`}\n      onPointerMove={alMover}\n      onPointerLeave={alSalir}\n    >\n      <div className=\"furin-analog-gauge__bezel\" />\n      <div className=\"furin-analog-gauge__chamfer\" />\n      <div className=\"furin-analog-gauge__dial\" />\n      <svg className=\"furin-analog-gauge__svg\" viewBox=\"0 0 400 400\" aria-hidden=\"true\">\n        <defs>\n          <filter id={`${uid}b`} x=\"-60%\" y=\"-30%\" width=\"220%\" height=\"160%\"><feGaussianBlur stdDeviation=\"3.4\" /></filter>\n          <linearGradient id={`${uid}l`} x1=\"0\" x2=\"1\" y1=\"0\" y2=\"0\"><stop offset=\"0\" stopColor=\"#ffffff\" /><stop offset=\"0.55\" stopColor=\"#d3d8df\" /><stop offset=\"1\" stopColor=\"#9aa1ab\" /></linearGradient>\n          <linearGradient id={`${uid}r`} x1=\"0\" x2=\"1\" y1=\"0\" y2=\"0\"><stop offset=\"0\" stopColor=\"#8c939d\" /><stop offset=\"0.6\" stopColor=\"#525861\" /><stop offset=\"1\" stopColor=\"#2b2f36\" /></linearGradient>\n          <clipPath id={`${uid}t`}><rect x=\"150\" y=\"40\" width=\"100\" height=\"66\" /></clipPath>\n        </defs>\n        {arco ? <path d={arco} className=\"furin-analog-gauge__zone\" /> : null}\n        {marcas.map((m, i) => (\n          <line key={i} x1={m.x} y1={m.y} x2={m.x2} y2={m.y2} className={`furin-analog-gauge__tick${m.grande ? \" is-major\" : \"\"}${m.roja ? \" is-red\" : \"\"}`} />\n        ))}\n        {numeros.map((n, i) => (\n          <text key={i} x={n.x} y={n.y} textAnchor=\"middle\" dominantBaseline=\"central\" className={`furin-analog-gauge__num${n.roja ? \" is-red\" : \"\"}`}>{n.texto}</text>\n        ))}\n        <text x={C} y=\"262\" textAnchor=\"middle\" className=\"furin-analog-gauge__label\">{label}</text>\n        <text x={C} y=\"292\" textAnchor=\"middle\" className=\"furin-analog-gauge__unit\">{unit}</text>\n        <g transform=\"translate(7 11)\" opacity=\"0.65\">\n          <g ref={sombraRef} transform={`rotate(${f0} ${C} ${C})`} filter={`url(#${uid}b)`}><path d={aguja} fill=\"#000\" /></g>\n        </g>\n        <g ref={agujaRef} transform={`rotate(${f0} ${C} ${C})`}>\n          <path d=\"M200 52 L198.7 52 L192.6 200 L195.4 246 L200 246 Z\" fill={`url(#${uid}l)`} />\n          <path d=\"M200 52 L201.3 52 L207.4 200 L204.6 246 L200 246 Z\" fill={`url(#${uid}r)`} />\n          <g clipPath={`url(#${uid}t)`}>\n            <path d=\"M200 52 L198.7 52 L192.6 200 L200 200 Z\" className=\"furin-analog-gauge__tipL\" />\n            <path d=\"M200 52 L201.3 52 L207.4 200 L200 200 Z\" className=\"furin-analog-gauge__tipR\" />\n          </g>\n          <path d=\"M200 56 L200 244\" stroke=\"rgba(255,255,255,0.6)\" strokeWidth=\"0.8\" />\n        </g>\n      </svg>\n      <div className=\"furin-analog-gauge__hub\" />\n      <div className=\"furin-analog-gauge__glass\">\n        <span className=\"furin-analog-gauge__glare\" />\n        <span className=\"furin-analog-gauge__streak\" />\n      </div>\n    </div>\n  );\n}\n\nexport default AnalogGauge;\n",
      "type": "registry:component",
      "target": "components/furin/analog-gauge/AnalogGauge.tsx"
    },
    {
      "path": "registry/analog-gauge/AnalogGauge.css",
      "content": "@property --fag-x { syntax: \"<number>\"; inherits: true; initial-value: 0.5; }\n@property --fag-y { syntax: \"<number>\"; inherits: true; initial-value: 0.5; }\n\n.furin-analog-gauge {\n  --fag-size: 320px;\n  --fag-accent: #ff6a2a;\n  position: relative;\n  width: var(--fag-size);\n  height: var(--fag-size);\n  border-radius: 50%;\n  isolation: isolate;\n  transition: --fag-x 0.5s cubic-bezier(0.2, 0.75, 0.25, 1), --fag-y 0.5s cubic-bezier(0.2, 0.75, 0.25, 1);\n}\n\n/* Bisel cromado: reflejos de estudio en un cono y cepillado radial muy fino. */\n.furin-analog-gauge__bezel {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  background: conic-gradient(from 205deg, #70767f 0%, #f5f7f9 7%, #454b53 16%, #bcc2ca 26%, #fcfdfd 35%, #5a6068 46%, #9ca3ad 57%, #f6f8fa 67%, #4a5058 79%, #adb3bc 90%, #70767f 100%);\n  box-shadow:\n    0 0 0 1px rgba(0, 0, 0, 0.75),\n    0 6px 10px rgba(0, 0, 0, 0.55),\n    0 26px 36px -8px rgba(0, 0, 0, 0.85),\n    0 40px 60px -26px rgba(190, 205, 225, 0.22);\n}\n.furin-analog-gauge__bezel::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.07) 0deg 0.45deg, rgba(0, 0, 0, 0.08) 0.45deg 0.9deg);\n  mix-blend-mode: overlay;\n}\n/* Chaflán interior: el mismo cromo con la luz invertida. */\n.furin-analog-gauge__chamfer {\n  position: absolute;\n  inset: 3.6%;\n  border-radius: 50%;\n  background: conic-gradient(from 25deg, #2c3037 0%, #a9b0b9 9%, #20242a 20%, #7b828c 31%, #d9dee4 40%, #2a2e34 52%, #8d949e 63%, #cdd2d9 73%, #23272d 85%, #8a919b 94%, #2c3037 100%);\n  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 2px 3px rgba(255, 255, 255, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.18);\n}\n.furin-analog-gauge__dial {\n  position: absolute;\n  inset: 7.2%;\n  border-radius: 50%;\n  background:\n    repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.018) 0deg 1deg, rgba(0, 0, 0, 0) 1deg 2deg),\n    radial-gradient(circle at 50% 34%, #2a2e36 0%, #14161a 58%, #08090b 100%);\n  box-shadow:\n    inset 0 7px 16px rgba(0, 0, 0, 0.9),\n    inset 0 -2px 8px rgba(255, 255, 255, 0.04),\n    0 0 0 1px rgba(0, 0, 0, 0.8);\n}\n\n.furin-analog-gauge__svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }\n.furin-analog-gauge__tick { stroke: #c9ced6; stroke-width: 1.7; stroke-linecap: butt; }\n.furin-analog-gauge__tick.is-major { stroke: #f1f3f6; stroke-width: 3.4; }\n.furin-analog-gauge__tick.is-red { stroke: #ee4b50; }\n.furin-analog-gauge__zone { fill: none; stroke: #d93a3f; stroke-width: 6; opacity: 0.92; filter: drop-shadow(0 0 5px rgba(238, 75, 80, 0.55)); }\n.furin-analog-gauge__num { font: 600 18px / 1 \"Geist\", system-ui, -apple-system, \"Segoe UI\", sans-serif; fill: #eef0f3; font-variant-numeric: tabular-nums; }\n.furin-analog-gauge__num.is-red { fill: #ff7a7e; }\n.furin-analog-gauge__label { font: 600 12px / 1 ui-monospace, \"JetBrains Mono\", \"SF Mono\", Menlo, monospace; letter-spacing: 0.28em; text-transform: uppercase; fill: #8b929c; }\n.furin-analog-gauge__unit { font: 700 20px / 1 \"Geist\", system-ui, sans-serif; letter-spacing: 0.06em; fill: #eef0f3; }\n.furin-analog-gauge__tipL { fill: var(--fag-accent); }\n.furin-analog-gauge__tipR { fill: color-mix(in srgb, var(--fag-accent) 52%, #000); }\n\n/* Eje: casquillo de acero con la aguja pasando por debajo. */\n.furin-analog-gauge__hub {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: 11.5%;\n  height: 11.5%;\n  transform: translate(-50%, -50%);\n  border-radius: 50%;\n  background:\n    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0) 0 28%, rgba(0, 0, 0, 0.35) 30%, rgba(255, 255, 255, 0.35) 33%, rgba(255, 255, 255, 0) 38%),\n    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0) 42%),\n    conic-gradient(from 40deg, #f1f4f7, #7d848e, #fafbfc, #5b626b, #eef1f4, #8a919b, #f1f4f7);\n  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 5px 7px rgba(0, 0, 0, 0.6), inset 0 -3px 4px rgba(0, 0, 0, 0.3);\n}\n\n/* Cristal: reflejo curvo arriba, filo de luz abajo y una veta que se desplaza con el cursor. */\n.furin-analog-gauge__glass {\n  position: absolute;\n  inset: 7.2%;\n  border-radius: 50%;\n  overflow: hidden;\n  pointer-events: none;\n  background:\n    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, 0.07) 96%, rgba(255, 255, 255, 0.2) 100%),\n    radial-gradient(circle at 78% 104%, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0) 42%);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);\n}\n.furin-analog-gauge__glare {\n  position: absolute;\n  left: 9%;\n  right: 9%;\n  top: 3%;\n  height: 46%;\n  border-radius: 50% 50% 46% 46% / 62% 62% 38% 38%;\n  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.1) 55%, rgba(255, 255, 255, 0.015) 100%);\n  transform: translate(calc((var(--fag-x) - 0.5) * -16px), calc((var(--fag-y) - 0.5) * -10px));\n}\n.furin-analog-gauge__streak {\n  position: absolute;\n  top: -10%;\n  bottom: -10%;\n  width: 14%;\n  left: calc(8% + var(--fag-x) * 74%);\n  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));\n  transform: skewX(-18deg);\n  filter: blur(2px);\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .furin-analog-gauge { transition: none; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/analog-gauge/AnalogGauge.css"
    }
  ]
}
