{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sparkline",
  "title": "Sparkline",
  "description": "Inline SVG trend line for a KPI tile.",
  "dependencies": [
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/components/sparkline.tsx",
      "content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Inline trend line for a KPI tile — hand-rolled rather than charted. A\n   sparkline is a normalise and a join, and an overview screen carries four to\n   eight of them inline; a charting runtime would weigh more than everything it\n   draws here and would have to load before the number it sits next to.\n\n   Every shape paints with currentColor, so the tone stays on the semantic token\n   utilities and no stroke or fill colour is ever written into this file.\n\n   `fill` inherits, so the root settles it once per variant: the area and the\n   bars are filled shapes, a bare line is not. The stroke drawn on top of an\n   area re-states `fill-none` for itself — it is the one child that must not\n   inherit what its own variant just switched on. */\nconst sparklineVariants = cva(\"block size-full overflow-visible\", {\n  variants: {\n    tone: {\n      selected: \"text-selected\",\n      success: \"text-success\",\n      warning: \"text-warning\",\n      destructive: \"text-destructive\",\n      info: \"text-info\",\n      muted: \"text-muted-foreground\",\n      \"chart-1\": \"text-chart-1\",\n      \"chart-2\": \"text-chart-2\",\n      \"chart-3\": \"text-chart-3\",\n      \"chart-4\": \"text-chart-4\",\n      \"chart-5\": \"text-chart-5\",\n    },\n    variant: {\n      line: \"fill-none\",\n      area: \"fill-current\",\n      bar: \"fill-current\",\n    },\n  },\n  defaultVariants: {\n    tone: \"selected\",\n    variant: \"line\",\n  },\n})\n\n/* Share of each bar's slot given up to the gap. Kept as a fraction rather than\n   a width in pixels because the slot stretches with the box — a fixed gap would\n   swallow the bars in a narrow tile and vanish in a wide one. */\nconst BAR_GAP = 0.28\n\ntype SparklineTone = NonNullable<VariantProps<typeof sparklineVariants>[\"tone\"]>\n\ntype SparklineVariant = NonNullable<VariantProps<typeof sparklineVariants>[\"variant\"]>\n\ntype SparklineProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** The series, oldest reading first. */\n  data: number[]\n  /** Intrinsic box in px. `style` is spread last, so a consumer can override it. */\n  width?: number\n  height?: number\n  /** Screen px, held at that weight however the box stretches. */\n  strokeWidth?: number\n  tone?: SparklineTone\n  variant?: SparklineVariant\n  /**\n   * Announced in place of the graphic. Pass it only when the spark is the sole\n   * representation of the data — beside a visible number it is a second telling\n   * of the same fact, which is noise in a screen reader rather than help.\n   */\n  srLabel?: string\n}\n\nfunction Sparkline({\n  data,\n  width = 96,\n  height = 32,\n  strokeWidth = 2,\n  tone = \"selected\",\n  variant = \"line\",\n  srLabel,\n  className,\n  style,\n  ...props\n}: SparklineProps) {\n  /* One NaN poisons the coordinate string it lands in and the renderer discards\n     the whole path, so a single bad reading would cost the entire spark rather\n     than only itself. Dropping it keeps the rest legible: with no axis and no\n     labels there is no position for the reader to be misled about. */\n  const series = data.filter((n) => Number.isFinite(n))\n  if (series.length === 0) return null\n\n  const min = Math.min(...series)\n  const max = Math.max(...series)\n  const range = max - min\n  /* A flat series has no range to divide by. Half height is the honest picture —\n     pinning it to the floor or the ceiling would claim a low or a high that the\n     data never sets. */\n  const norm = (n: number) => (range > 0 ? (n - min) / range : 0.5)\n\n  /* Half a stroke of headroom top and bottom so the extremes sit inside the box\n     instead of painting over the row above. Measured in plot units, so it\n     tracks whatever the box stretches to. Bars carry no stroke and need none. */\n  const inset = variant === \"bar\" ? 0 : strokeWidth / 2\n  const plot = Math.max(height - inset * 2, 0)\n  const yOf = (n: number) => (inset + (1 - norm(n)) * plot).toFixed(2)\n\n  /* A line joins readings, so its box counts the gaps between them; bars own a\n     slot each, so theirs counts the readings. */\n  const span = Math.max(series.length - 1, 1)\n  const viewBox =\n    variant === \"bar\" ? `0 0 ${series.length} ${height}` : `0 0 ${span} ${height}`\n\n  const vertices = series.map((n, index) => `${index},${yOf(n)}`)\n  /* A one-point polyline paints nothing at all. Repeating the reading at the far\n     edge draws the flat line a single sample actually describes. */\n  if (vertices.length === 1) vertices.push(`${span},${yOf(series[0])}`)\n  const line = vertices.join(\" \")\n  /* Down to the floor at the last reading, back along it, closed by the polygon\n     itself — the fill belongs to the box, not to the range the series happens\n     to cover. */\n  const area = `0,${height} ${line} ${span},${height}`\n\n  return (\n    <div\n      data-slot=\"sparkline\"\n      data-tone={tone}\n      data-variant={variant}\n      className={cn(\"inline-flex shrink-0\", className)}\n      style={{ width, height, ...style }}\n      {...props}\n    >\n      {/* The plot stretches to its box rather than keeping the ratio the data\n          implies, which is the whole point of a spark: it fills the strip it is\n          given. That leaves x in index units that scale with the container, so\n          half of each end cap hangs past the first and last reading by an amount\n          no viewBox inset can express — the box lets it show rather than\n          shearing the ends flat. */}\n      <svg\n        viewBox={viewBox}\n        preserveAspectRatio=\"none\"\n        aria-hidden=\"true\"\n        className={cn(sparklineVariants({ tone, variant }))}\n      >\n        {variant === \"bar\"\n          ? series.map((n, index) => {\n              /* A zero-height rect paints nothing, so the series' own minimum\n                 would drop out of the chart entirely. Floor it at the weight the\n                 line variant would have drawn there — present, and still\n                 unmistakably the smallest. */\n              const barHeight = Math.max(norm(n) * height, strokeWidth)\n\n              return (\n                <rect\n                  key={index}\n                  data-slot=\"sparkline-bar\"\n                  x={index + BAR_GAP / 2}\n                  y={height - barHeight}\n                  width={1 - BAR_GAP}\n                  height={barHeight}\n                />\n              )\n            })\n          : null}\n\n        {variant === \"area\" ? (\n          <polygon data-slot=\"sparkline-area\" points={area} className=\"opacity-15\" />\n        ) : null}\n\n        {variant === \"line\" || variant === \"area\" ? (\n          <polyline\n            data-slot=\"sparkline-line\"\n            points={line}\n            className=\"fill-none\"\n            stroke=\"currentColor\"\n            strokeWidth={strokeWidth}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            /* Without this the non-uniform stretch above would scale the stroke\n               with the box and the line would come out heavier on one axis than\n               the other — a 2px spark reading as 2×6 in a wide tile. */\n            vectorEffect=\"non-scaling-stroke\"\n          />\n        ) : null}\n      </svg>\n\n      {srLabel ? <span className=\"sr-only\">{srLabel}</span> : null}\n    </div>\n  )\n}\n\nexport { Sparkline, sparklineVariants }\nexport type { SparklineProps, SparklineTone, SparklineVariant }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}