{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "score-gauge",
  "title": "Score Gauge",
  "author": "VenusUI",
  "description": "A speedometer-style gauge whose needle sweeps to a score, with colored rating bands.",
  "files": [
    {
      "path": "registry/default/ui/score-gauge.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface GaugeBand {\n  /** Upper bound of the band (inclusive). */\n  upTo: number\n  label: string\n  /** Any CSS color. */\n  color: string\n}\n\ninterface ScoreGaugeProps extends React.ComponentProps<\"div\"> {\n  value: number\n  min?: number\n  max?: number\n  /** Accessible name and caption, e.g. \"Credit score\". */\n  label: string\n  /** Colored ranges from `min` to `max`. Defaults to credit-score bands. */\n  bands?: GaugeBand[]\n  /** Small text under the rating, e.g. \"Updated 2 Nov\". */\n  caption?: string\n}\n\nconst CREDIT_BANDS: GaugeBand[] = [\n  { upTo: 579, label: \"Poor\", color: \"#ef4444\" },\n  { upTo: 669, label: \"Fair\", color: \"#f97316\" },\n  { upTo: 739, label: \"Good\", color: \"#eab308\" },\n  { upTo: 799, label: \"Very good\", color: \"#84cc16\" },\n  { upTo: 850, label: \"Excellent\", color: \"#22c55e\" },\n]\n\nconst START = 160 // degrees, measured clockwise from 3 o'clock\nconst SWEEP = 220\nconst CX = 100\nconst CY = 100\nconst R = 78\n\nconst point = (angle: number, r = R) => {\n  const a = (angle * Math.PI) / 180\n  return [CX + r * Math.cos(a), CY + r * Math.sin(a)] as const\n}\n\nfunction arc(from: number, to: number) {\n  const [x1, y1] = point(from)\n  const [x2, y2] = point(to)\n  return `M ${x1.toFixed(2)} ${y1.toFixed(2)} A ${R} ${R} 0 ${to - from > 180 ? 1 : 0} 1 ${x2.toFixed(2)} ${y2.toFixed(2)}`\n}\n\n/**\n * A speedometer-style gauge. When it scrolls into view the needle sweeps to\n * the value and the number counts up. It's a `meter` with the value and\n * rating as text; with reduced motion it shows the value immediately.\n */\nfunction ScoreGauge({ value, min = 300, max = 850, label, bands = CREDIT_BANDS, caption, className, ...props }: ScoreGaugeProps) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [shown, setShown] = React.useState(min)\n  const clamped = Math.min(max, Math.max(min, value))\n  const band = bands.find((b) => clamped <= b.upTo) ?? bands[bands.length - 1]\n\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el) return\n    let frame = 0\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n    const observer = new IntersectionObserver(([entry]) => {\n      if (!entry?.isIntersecting) return\n      observer.disconnect()\n      if (reduced) {\n        setShown(clamped)\n        return\n      }\n      const start = performance.now()\n      const duration = 1400\n      const step = (now: number) => {\n        const t = Math.min(1, (now - start) / duration)\n        const eased = 1 - (1 - t) ** 3\n        setShown(min + (clamped - min) * eased)\n        if (t < 1) frame = requestAnimationFrame(step)\n      }\n      frame = requestAnimationFrame(step)\n    }, { threshold: 0.4 })\n    observer.observe(el)\n    return () => {\n      observer.disconnect()\n      cancelAnimationFrame(frame)\n    }\n  }, [clamped, min])\n\n  const angleOf = (v: number) => START + ((v - min) / (max - min)) * SWEEP\n  const needle = angleOf(shown)\n\n  return (\n    <div\n      ref={ref}\n      role=\"meter\"\n      aria-label={label}\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={clamped}\n      aria-valuetext={`${clamped}, ${band.label}`}\n      data-slot=\"score-gauge\"\n      className={cn(\"relative w-full max-w-xs\", className)}\n      {...props}\n    >\n      <svg viewBox=\"0 0 200 150\" aria-hidden=\"true\" className=\"w-full overflow-visible\">\n        {/* Track */}\n        <path d={arc(START, START + SWEEP)} fill=\"none\" stroke=\"currentColor\" strokeOpacity={0.08} strokeWidth={16} strokeLinecap=\"round\" />\n        {/* Bands */}\n        {bands.map((b, i) => {\n          const a = angleOf(i === 0 ? min : bands[i - 1].upTo) + 1.2\n          const z = angleOf(Math.min(b.upTo, max)) - 1.2\n          return <path key={b.label} d={arc(a, z)} fill=\"none\" stroke={b.color} strokeWidth={10} strokeLinecap=\"round\" opacity={0.9} />\n        })}\n        {/* Ticks */}\n        {Array.from({ length: 12 }, (_, i) => {\n          const a = START + (i / 11) * SWEEP\n          const [x1, y1] = point(a, R - 15)\n          const [x2, y2] = point(a, R - 20)\n          return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} stroke=\"currentColor\" strokeOpacity={0.3} strokeWidth={1.5} strokeLinecap=\"round\" />\n        })}\n        {/* Needle */}\n        <g style={{ transform: `rotate(${needle}deg)`, transformOrigin: `${CX}px ${CY}px` }}>\n          <path d={`M ${CX} ${CY - 4} L ${CX + R - 18} ${CY} L ${CX} ${CY + 4} Z`} fill=\"currentColor\" />\n        </g>\n        <circle cx={CX} cy={CY} r={9} fill=\"currentColor\" />\n        <circle cx={CX} cy={CY} r={4} fill={band.color} />\n        <text x={point(START, R + 2)[0]} y={point(START, R)[1] + 18} textAnchor=\"middle\" className=\"fill-current text-[9px] opacity-50\">\n          {min}\n        </text>\n        <text x={point(START + SWEEP, R + 2)[0]} y={point(START + SWEEP, R)[1] + 18} textAnchor=\"middle\" className=\"fill-current text-[9px] opacity-50\">\n          {max}\n        </text>\n      </svg>\n      <div className=\"-mt-6 text-center\">\n        <p aria-hidden=\"true\" className=\"text-[10px] font-medium tracking-[0.2em] text-muted-foreground uppercase\">\n          {label}\n        </p>\n        <p className=\"text-4xl font-semibold tracking-tight tabular-nums\">{Math.round(shown)}</p>\n        {/* Band colors (lime, yellow…) are too light for text, so the color goes on a dot. */}\n        <p className=\"inline-flex items-center gap-1.5 text-sm font-medium\">\n          <span aria-hidden=\"true\" className=\"size-2 rounded-full\" style={{ backgroundColor: band.color }} />\n          {band.label}\n        </p>\n        {caption ? <p className=\"mt-0.5 text-xs text-muted-foreground\">{caption}</p> : null}\n      </div>\n    </div>\n  )\n}\n\nexport { ScoreGauge }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.1"
  },
  "categories": [
    "data-display"
  ],
  "type": "registry:ui"
}