{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sparkline",
  "type": "registry:component",
  "title": "Sparkline",
  "description": "A tiny smooth line with an optional area fill and a glowing end dot that draws in on mount.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "charts",
    "chart",
    "sparkline",
    "svg",
    "trend",
    "analytics"
  ],
  "docs": "https://hyperblur.dev/effects/sparkline",
  "files": [
    {
      "path": "registry/hyperblur/sparkline.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sparkline.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SparklineProps extends React.HTMLAttributes<HTMLDivElement> {\n  data: number[];\n  color?: string;\n  height?: number;\n  strokeWidth?: number;\n  fill?: boolean;\n  animate?: boolean;\n}\n\nconst css = `\n.hb-spark { position: relative; display: block; width: 100%; min-width: 0; line-height: 0; }\n.hb-spark-svg { display: block; width: 100%; overflow: visible; }\n.hb-spark-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-spark-area { transition: opacity .7s ease .35s; }\n.hb-spark-dot { transition: opacity .3s ease .95s; }\n.hb-spark[data-ready=\"false\"] .hb-spark-line { stroke-dashoffset: 1; opacity: 0; }\n.hb-spark[data-ready=\"false\"] .hb-spark-area,\n.hb-spark[data-ready=\"false\"] .hb-spark-dot { opacity: 0; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-spark-line, .hb-spark-area, .hb-spark-dot { transition: none !important; }\n  .hb-spark[data-ready=\"false\"] .hb-spark-line { stroke-dashoffset: 0 !important; opacity: 1 !important; }\n  .hb-spark[data-ready=\"false\"] .hb-spark-area,\n  .hb-spark[data-ready=\"false\"] .hb-spark-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 === 0) return \"\";\n  if (n === 1) return `M${r(pts[0][0])},${r(pts[0][1])}`;\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 useWidth(fallback: number) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const [width, setWidth] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.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  }, []);\n  return [ref, width] as const;\n}\n\nfunction useReady(animate: boolean) {\n  const [ready, setReady] = React.useState(!animate);\n  React.useEffect(() => {\n    if (!animate) return;\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  }, [animate]);\n  return animate ? ready : true;\n}\n\nexport function Sparkline({\n  data,\n  color = \"#2f7bff\",\n  height = 40,\n  strokeWidth = 2,\n  fill = true,\n  animate = true,\n  className = \"\",\n  style,\n  ...rest\n}: SparklineProps) {\n  const [ref, width] = useWidth(120);\n  const ready = useReady(animate);\n  const uid = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n\n  const vals = data.filter((v) => Number.isFinite(v));\n  const dotR = Math.max(3, strokeWidth * 1.4);\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 = Math.max(1, height - pad * 2);\n\n  const pts: [number, number][] = vals.map((v, i) => [\n    vals.length === 1 ? width / 2 : pad + (i / (vals.length - 1)) * innerW,\n    span === 0 ? height / 2 : pad + (1 - (v - min) / span) * innerH,\n  ]);\n\n  const line = monotone(pts);\n  const last = pts[pts.length - 1];\n  const first = pts[0];\n  const area =\n    pts.length > 1 ? `${line}L${r(last[0])},${height}L${r(first[0])},${height}Z` : \"\";\n  const label = vals.length\n    ? `Sparkline of ${vals.length} values, from ${vals[0]} to ${vals[vals.length - 1]}, low ${min}, high ${max}`\n    : \"Sparkline with no data\";\n\n  return (\n    <div\n      ref={ref}\n      className={`hb-spark ${className}`}\n      data-ready={ready ? \"true\" : \"false\"}\n      style={{ height, ...style }}\n      {...rest}\n    >\n      <style href=\"hb-sparkline\" precedence=\"default\">{css}</style>\n      <svg\n        className=\"hb-spark-svg\"\n        viewBox={`0 0 ${width} ${height}`}\n        width={width}\n        height={height}\n        role=\"img\"\n        aria-label={label}\n      >\n        <defs>\n          <linearGradient id={`hb-spark-${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        {fill && area ? (\n          <path className=\"hb-spark-area\" d={area} fill={`url(#hb-spark-${uid})`} />\n        ) : null}\n        {pts.length > 1 ? (\n          <path\n            className=\"hb-spark-line\"\n            d={line}\n            pathLength={1}\n            stroke={color}\n            strokeWidth={strokeWidth}\n          />\n        ) : null}\n        {last ? (\n          <g className=\"hb-spark-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        ) : null}\n      </svg>\n    </div>\n  );\n}\n"
    }
  ]
}