{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meter",
  "title": "Meter",
  "description": "A meter for a value within a known range: bar, semicircle gauge or segmented variants with threshold zones, animated counting numbers and proper meter semantics.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/meter/meter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, animate, useMotionValue, useMotionValueEvent } 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 type MeterVariant = \"bar\" | \"gauge\" | \"segments\";\nexport type MeterSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface MeterProps {\n  value?: number;\n  min?: number;\n  max?: number;\n  low?: number;\n  high?: number;\n  /** \"up\": high values are good (score, battery). \"down\": high values are bad (disk usage, load). */\n  goodDirection?: \"up\" | \"down\";\n  variant?: MeterVariant;\n  segments?: number;\n  label?: string;\n  description?: string;\n  unit?: string;\n  showValue?: boolean;\n  formatValue?: (value: number) => string;\n  size?: MeterSize;\n  theme?: \"dark\" | \"light\";\n  width?: number | string;\n  className?: string;\n}\n\nconst ZONES = {\n  bad: { dark: \"#FF7A6B\", light: \"#E5484D\" },\n  mid: { dark: \"#F2A841\", light: \"#B7791F\" },\n  good: { dark: \"#87FFE3\", light: \"#0F9F7F\" },\n  neutral: { dark: \"#F5F4F1\", light: \"#0A0A0A\" },\n};\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", track: \"rgba(255,255,255,0.09)\", tick: \"rgba(255,255,255,0.35)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", track: \"rgba(10,10,10,0.09)\", tick: \"rgba(10,10,10,0.35)\" },\n};\n\nconst SIZES: Record<MeterSize, { font: number; bar: number; big: number; seg: number }> = {\n  sm: { font: 13, bar: 6, big: 26, seg: 14 },\n  md: { font: 14.5, bar: 10, big: 34, seg: 20 },\n  lg: { font: 16, bar: 14, big: 44, seg: 28 },\n};\n\nconst SPRING = { type: \"spring\", stiffness: 140, damping: 22 } as const;\n\nexport function Meter({\n  value = 0,\n  min = 0,\n  max = 100,\n  low,\n  high,\n  goodDirection = \"up\",\n  variant = \"bar\",\n  segments = 12,\n  label,\n  description,\n  unit,\n  showValue = true,\n  formatValue,\n  size = \"md\",\n  theme = \"dark\",\n  width,\n  className,\n}: MeterProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const clamped = Math.min(max, Math.max(min, value));\n  const frac = max === min ? 0 : (clamped - min) / (max - min);\n\n  const zone = (() => {\n    if (low === undefined && high === undefined) return \"neutral\" as const;\n    const lo = low ?? min;\n    const hi = high ?? max;\n    const band = clamped < lo ? \"low\" : clamped > hi ? \"high\" : \"mid\";\n    if (band === \"mid\") return \"mid\" as const;\n    const highIsGood = goodDirection === \"up\";\n    return (band === \"high\") === highIsGood ? (\"good\" as const) : (\"bad\" as const);\n  })();\n  const color = ZONES[zone][theme];\n\n  const mv = useMotionValue(min);\n  const [shown, setShown] = React.useState(min);\n  useMotionValueEvent(mv, \"change\", (v) => setShown(v));\n  React.useEffect(() => {\n    const controls = animate(mv, clamped, { type: \"spring\", stiffness: 110, damping: 20 });\n    return () => controls.stop();\n  }, [clamped, mv]);\n\n  const decimals = Number.isInteger(value) && Number.isInteger(min) && Number.isInteger(max) ? 0 : 1;\n  const text = formatValue ? formatValue(shown) : `${shown.toFixed(decimals)}${unit ?? \"\"}`;\n  const finalText = formatValue ? formatValue(clamped) : `${clamped.toFixed(decimals)}${unit ?? \"\"}`;\n  const pos = (v: number) => (max === min ? 0 : ((v - min) / (max - min)) * 100);\n\n  const header = (label || (showValue && variant !== \"gauge\")) && (\n    <div className=\"flex items-baseline justify-between\" style={{ gap: 12 }}>\n      {label ? (\n        <span id={`${uid}-label`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </span>\n      ) : (\n        <span />\n      )}\n      {showValue && variant !== \"gauge\" && (\n        <span aria-hidden=\"true\" className=\"font-semibold tabular-nums\" style={{ color: p.text, fontSize: s.font }}>\n          {text}\n        </span>\n      )}\n    </div>\n  );\n\n  return (\n    <div\n      role=\"meter\"\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={clamped}\n      aria-valuetext={finalText}\n      aria-labelledby={label ? `${uid}-label` : undefined}\n      aria-label={label ? undefined : \"Meter\"}\n      className={cn(\"inline-flex flex-col\", className)}\n      style={{ gap: 10, width: width ?? (variant === \"gauge\" ? 240 : 320), maxWidth: \"100%\", fontFamily: \"Inter, sans-serif\" }}\n    >\n      {variant !== \"gauge\" && header}\n\n      {variant === \"bar\" && (\n        <div className=\"relative\" style={{ height: s.bar }}>\n          <div className=\"absolute inset-0 overflow-hidden\" style={{ borderRadius: s.bar, background: p.track }}>\n            <motion.div initial={{ width: \"0%\" }} animate={{ width: `${frac * 100}%` }} transition={SPRING} style={{ height: \"100%\", borderRadius: s.bar, background: color, transition: \"background 0.3s ease\" }} />\n          </div>\n          {[low, high].map((t, i) =>\n            t !== undefined && t > min && t < max ? (\n              <span key={i} aria-hidden=\"true\" className=\"absolute\" style={{ left: `${pos(t)}%`, top: -3, bottom: -3, width: 2, marginLeft: -1, borderRadius: 2, background: p.tick, mixBlendMode: theme === \"dark\" ? \"screen\" : \"multiply\", opacity: 0.6 }} />\n            ) : null,\n          )}\n        </div>\n      )}\n\n      {variant === \"segments\" && (\n        <div className=\"flex\" style={{ gap: 4 }} aria-hidden=\"true\">\n          {Array.from({ length: segments }).map((_, i) => {\n            const lit = i < Math.round(frac * segments);\n            return (\n              <motion.span\n                key={i}\n                className=\"flex-1\"\n                initial={{ opacity: 0.4, scaleY: 0.6 }}\n                animate={{ opacity: 1, scaleY: lit ? 1 : 0.75, backgroundColor: lit ? color : p.track }}\n                transition={{ type: \"spring\", stiffness: 380, damping: 26, delay: i * 0.025 }}\n                style={{ height: s.seg, borderRadius: Math.min(6, s.seg / 3), transformOrigin: \"bottom\" }}\n              />\n            );\n          })}\n        </div>\n      )}\n\n      {variant === \"gauge\" && (\n        <div className=\"relative w-full\" style={{ aspectRatio: \"200 / 118\" }}>\n          <svg viewBox=\"0 0 200 118\" className=\"absolute inset-0 h-full w-full\" fill=\"none\" aria-hidden=\"true\">\n            <path d=\"M20 100 A80 80 0 0 1 180 100\" stroke={p.track} strokeWidth={14} strokeLinecap=\"round\" />\n            <motion.path d=\"M20 100 A80 80 0 0 1 180 100\" stroke={color} strokeWidth={14} strokeLinecap=\"round\" initial={{ pathLength: 0 }} animate={{ pathLength: Math.max(frac, 0.001) }} transition={SPRING} style={{ transition: \"stroke 0.3s ease\" }} />\n          </svg>\n          <div className=\"absolute inset-x-0 bottom-0 flex flex-col items-center\" style={{ gap: 2 }}>\n            {showValue && (\n              <span aria-hidden=\"true\" className=\"font-semibold leading-none tracking-[-0.03em] tabular-nums\" style={{ color: p.text, fontSize: s.big }}>\n                {text}\n              </span>\n            )}\n            {label && (\n              <span id={`${uid}-label`} className=\"font-medium\" style={{ color: p.muted, fontSize: s.font - 1.5 }}>\n                {label}\n              </span>\n            )}\n          </div>\n        </div>\n      )}\n\n      {description && (\n        <span style={{ color: p.muted, fontSize: s.font - 1.5, lineHeight: 1.4, textAlign: variant === \"gauge\" ? \"center\" : undefined }}>{description}</span>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}