{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stat-card",
  "type": "registry:component",
  "title": "Stat Card",
  "description": "KPI card with a counting value, a green or red delta pill, a caption and an embedded sparkline.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "charts",
    "kpi",
    "stat",
    "metric",
    "card",
    "dashboard",
    "analytics"
  ],
  "docs": "https://hyperblur.dev/effects/stat-card",
  "files": [
    {
      "path": "registry/hyperblur/stat-card.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/stat-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface StatCardProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  label: string;\n  value: string | number;\n  delta?: number;\n  caption?: string;\n  data?: number[];\n  color?: string;\n  prefix?: string;\n  suffix?: string;\n  decimals?: number;\n  locale?: string;\n}\n\nconst css = `\n.hb-stc {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  gap: 10px;\n  min-width: 0;\n  padding: 16px;\n  border-radius: 14px;\n  border: 1px solid #262626;\n  background: #111111;\n  color: #ededed;\n  overflow: hidden;\n}\n.hb-stc-label { font-size: 12px; font-weight: 500; line-height: 1.2; color: #8f8f8f; letter-spacing: .01em; }\n.hb-stc-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; }\n.hb-stc-value {\n  font-family: var(--font-grotesk, ui-sans-serif, system-ui, sans-serif);\n  font-size: 30px;\n  font-weight: 600;\n  line-height: 1.1;\n  letter-spacing: -.02em;\n  font-variant-numeric: tabular-nums;\n  white-space: pre;\n}\n.hb-stc-delta {\n  display: inline-flex;\n  align-items: center;\n  gap: 3px;\n  padding: 2px 7px 2px 5px;\n  border-radius: 999px;\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 11px;\n  font-weight: 500;\n  line-height: 1.4;\n  font-variant-numeric: tabular-nums;\n  color: var(--hb-stc-tone);\n  background: color-mix(in srgb, var(--hb-stc-tone) 14%, transparent);\n}\n.hb-stc-delta svg { display: block; width: 10px; height: 10px; }\n.hb-stc-caption { font-size: 12px; line-height: 1.3; color: #8f8f8f; }\n.hb-stc-spark { margin-top: auto; position: relative; width: 100%; line-height: 0; }\n.hb-stc-svg { display: block; width: 100%; overflow: visible; }\n.hb-stc-line {\n  fill: none;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  stroke-dasharray: 1;\n  stroke-dashoffset: 0;\n  transition: stroke-dashoffset 1.1s cubic-bezier(.22, .8, .24, 1), opacity .15s ease;\n}\n.hb-stc-area { transition: opacity .7s ease .35s; }\n.hb-stc-dot { transition: opacity .3s ease .95s; }\n.hb-stc[data-ready=\"false\"] .hb-stc-line { stroke-dashoffset: 1; opacity: 0; }\n.hb-stc[data-ready=\"false\"] .hb-stc-area,\n.hb-stc[data-ready=\"false\"] .hb-stc-dot { opacity: 0; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-stc-line, .hb-stc-area, .hb-stc-dot { transition: none !important; }\n  .hb-stc[data-ready=\"false\"] .hb-stc-line { stroke-dashoffset: 0 !important; opacity: 1 !important; }\n  .hb-stc[data-ready=\"false\"] .hb-stc-area,\n  .hb-stc[data-ready=\"false\"] .hb-stc-dot { opacity: 1 !important; }\n}\n`;\n\nfunction r(n: number) {\n  return Math.round(n * 100) / 100;\n}\n\nfunction monotone(pts: [number, number][]) {\n  const n = pts.length;\n  if (n < 2) return \"\";\n  const m: number[] = [];\n  for (let i = 0; i < n - 1; i++) {\n    const dx = pts[i + 1][0] - pts[i][0];\n    m.push(dx === 0 ? 0 : (pts[i + 1][1] - pts[i][1]) / dx);\n  }\n  const t: number[] = new Array(n).fill(0);\n  t[0] = m[0];\n  t[n - 1] = m[n - 2];\n  for (let i = 1; i < n - 1; i++) {\n    t[i] = m[i - 1] * m[i] <= 0 ? 0 : (2 * m[i - 1] * m[i]) / (m[i - 1] + m[i]);\n  }\n  let d = `M${r(pts[0][0])},${r(pts[0][1])}`;\n  for (let i = 0; i < n - 1; i++) {\n    const dx = (pts[i + 1][0] - pts[i][0]) / 3;\n    d += `C${r(pts[i][0] + dx)},${r(pts[i][1] + t[i] * dx)} ${r(pts[i + 1][0] - dx)},${r(pts[i + 1][1] - t[i + 1] * dx)} ${r(pts[i + 1][0])},${r(pts[i + 1][1])}`;\n  }\n  return d;\n}\n\nfunction ease(t: number) {\n  return 1 - Math.pow(1 - t, 3);\n}\n\nconst SPARK_H = 40;\n\nexport function StatCard({\n  label,\n  value,\n  delta,\n  caption,\n  data,\n  color = \"#2f7bff\",\n  prefix = \"\",\n  suffix = \"\",\n  decimals = 0,\n  locale = \"en-US\",\n  className = \"\",\n  style,\n  ...rest\n}: StatCardProps) {\n  const [ready, setReady] = React.useState(false);\n  const [counted, setCounted] = React.useState<number | null>(null);\n  const [width, setWidth] = React.useState(280);\n  const sparkRef = React.useRef<HTMLDivElement>(null);\n  const uid = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n\n  const format = React.useMemo(() => {\n    const nf = new Intl.NumberFormat(locale, {\n      minimumFractionDigits: decimals,\n      maximumFractionDigits: decimals,\n    });\n    return (n: number) => `${prefix}${nf.format(n)}${suffix}`;\n  }, [locale, decimals, prefix, suffix]);\n\n  React.useEffect(() => {\n    let a = 0;\n    let b = 0;\n    a = requestAnimationFrame(() => {\n      b = requestAnimationFrame(() => setReady(true));\n    });\n    return () => {\n      cancelAnimationFrame(a);\n      cancelAnimationFrame(b);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    const el = sparkRef.current;\n    if (!el || typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver((entries) => {\n      const w = Math.round(entries[0].contentRect.width);\n      if (w > 0) setWidth(w);\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [data]);\n\n  React.useEffect(() => {\n    if (typeof value !== \"number\" || !Number.isFinite(value)) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let raf = 0;\n    const duration = 1200;\n    const begin = requestAnimationFrame((start) => {\n      const tick = (now: number) => {\n        const t = Math.min((now - start) / duration, 1);\n        if (t >= 1) {\n          setCounted(null);\n          return;\n        }\n        setCounted(value * ease(t));\n        raf = requestAnimationFrame(tick);\n      };\n      setCounted(0);\n      raf = requestAnimationFrame(tick);\n    });\n    return () => {\n      cancelAnimationFrame(begin);\n      cancelAnimationFrame(raf);\n    };\n  }, [value]);\n\n  const shown = typeof value === \"number\" ? format(counted ?? value) : `${prefix}${value}${suffix}`;\n  const finalText = typeof value === \"number\" ? format(value) : `${prefix}${value}${suffix}`;\n\n  const vals = (data ?? []).filter((v) => Number.isFinite(v));\n  const dotR = 3.5;\n  const pad = dotR + 1;\n  const min = vals.length ? Math.min(...vals) : 0;\n  const max = vals.length ? Math.max(...vals) : 0;\n  const span = max - min;\n  const innerW = Math.max(1, width - pad * 2);\n  const innerH = SPARK_H - pad * 2;\n  const pts: [number, number][] = vals.map((v, i) => [\n    pad + (i / Math.max(1, vals.length - 1)) * innerW,\n    span === 0 ? SPARK_H / 2 : pad + (1 - (v - min) / span) * innerH,\n  ]);\n  const line = monotone(pts);\n  const last = pts[pts.length - 1];\n  const first = pts[0];\n  const area = line ? `${line}L${r(last[0])},${SPARK_H}L${r(first[0])},${SPARK_H}Z` : \"\";\n\n  const deltaTone = delta === undefined || delta === 0 ? \"#8f8f8f\" : delta > 0 ? \"#22c55e\" : \"#ef4444\";\n  const deltaText =\n    delta === undefined\n      ? \"\"\n      : `${new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(Math.abs(delta))}%`;\n  const deltaWord = delta === undefined ? \"\" : delta > 0 ? \"up\" : delta < 0 ? \"down\" : \"flat\";\n\n  const summary = [\n    `${label}: ${finalText}`,\n    delta === undefined ? \"\" : `${deltaWord} ${deltaText}`,\n    caption ?? \"\",\n  ]\n    .filter(Boolean)\n    .join(\", \");\n\n  return (\n    <div\n      className={`hb-stc ${className}`}\n      data-ready={ready ? \"true\" : \"false\"}\n      role=\"group\"\n      aria-label={summary}\n      style={{ [\"--hb-stc-tone\" as string]: deltaTone, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-stat-card\" precedence=\"default\">{css}</style>\n      <div className=\"hb-stc-label\" aria-hidden=\"true\">{label}</div>\n      <div className=\"hb-stc-row\" aria-hidden=\"true\">\n        <span className=\"hb-stc-value\">{shown}</span>\n        {delta !== undefined ? (\n          <span className=\"hb-stc-delta\">\n            {delta !== 0 ? (\n              <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                {delta > 0 ? <path d=\"M5 8.5V1.8M2 4.6 5 1.6l3 3\" /> : <path d=\"M5 1.5v6.7M2 5.4l3 3 3-3\" />}\n              </svg>\n            ) : null}\n            {deltaText}\n          </span>\n        ) : null}\n        {caption ? <span className=\"hb-stc-caption\">{caption}</span> : null}\n      </div>\n      {vals.length > 1 ? (\n        <div className=\"hb-stc-spark\" ref={sparkRef} style={{ height: SPARK_H }}>\n          <svg\n            className=\"hb-stc-svg\"\n            viewBox={`0 0 ${width} ${SPARK_H}`}\n            width={width}\n            height={SPARK_H}\n            aria-hidden=\"true\"\n          >\n            <defs>\n              <linearGradient id={`hb-stc-${uid}`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                <stop offset=\"0%\" stopColor={color} stopOpacity=\"0.32\" />\n                <stop offset=\"100%\" stopColor={color} stopOpacity=\"0\" />\n              </linearGradient>\n            </defs>\n            <path className=\"hb-stc-area\" d={area} fill={`url(#hb-stc-${uid})`} />\n            <path className=\"hb-stc-line\" d={line} pathLength={1} stroke={color} strokeWidth={2} />\n            <g className=\"hb-stc-dot\">\n              <circle cx={last[0]} cy={last[1]} r={dotR * 2} fill={color} opacity=\"0.18\" />\n              <circle cx={last[0]} cy={last[1]} r={dotR} fill={color} stroke=\"#111111\" strokeWidth=\"1.5\" />\n            </g>\n          </svg>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}