{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink/sparkline",
  "title": "Sparkline",
  "description": "Inline Unicode braille sparkline chart",
  "dependencies": [
    "ink"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/ink/accessibility.json",
    "https://termcn.dev/r/ink/use-theme.json",
    "https://termcn.dev/r/ink/use-unicode.json"
  ],
  "files": [
    {
      "path": "registry/ui/sparkline.tsx",
      "content": "import { Box, Text } from \"ink\";\n\nimport { useTheme } from \"@/hooks/use-theme\";\nimport { useUnicode } from \"@/hooks/use-unicode\";\nimport { summarizeSeries } from \"@/lib/accessibility\";\n\nexport interface SparklineProps {\n  data: number[];\n  width?: number;\n  color?: string;\n  label?: string;\n  accessibleSummary?: string;\n  \"aria-label\"?: string;\n}\n\nconst BRAILLE_LEVELS = [\"⣀\", \"⣄\", \"⣤\", \"⣦\", \"⣶\", \"⣷\", \"⣿\", \"⣿\"];\nconst ASCII_LEVELS = [\".\", \":\", \"-\", \"=\", \"+\", \"*\", \"#\", \"@\"];\n\nconst normalize = (data: number[], levels: number): number[] => {\n  if (data.length === 0) {\n    return [];\n  }\n  const min = Math.min(...data);\n  const max = Math.max(...data);\n  const range = max - min;\n  if (range === 0) {\n    return data.map(() => Math.floor(levels / 2));\n  }\n  return data.map((v) => Math.round(((v - min) / range) * (levels - 1)));\n};\n\nexport const Sparkline = ({\n  data,\n  width = 20,\n  color,\n  label,\n  accessibleSummary,\n  \"aria-label\": ariaLabel,\n}: SparklineProps) => {\n  const theme = useTheme();\n  const unicode = useUnicode();\n  const resolvedColor = color ?? theme.colors.primary;\n  const levelsForOutput = unicode ? BRAILLE_LEVELS : ASCII_LEVELS;\n\n  if (data.length === 0) {\n    return (\n      <Box>\n        {label && <Text color={theme.colors.mutedForeground}>{label} </Text>}\n        <Text color={theme.colors.mutedForeground}>{\"-\".repeat(width)}</Text>\n      </Box>\n    );\n  }\n\n  const sampled =\n    data.length > width\n      ? Array.from(\n          { length: width },\n          (_, i) => data[Math.round((i / (width - 1)) * (data.length - 1))] ?? 0\n        )\n      : data;\n\n  const levels = normalize(sampled, levelsForOutput.length);\n  const sparkStr = levels\n    .map((level) => levelsForOutput[level] ?? levelsForOutput[0])\n    .join(\"\");\n\n  return (\n    <Box\n      flexDirection=\"row\"\n      gap={1}\n      aria-label={\n        ariaLabel ??\n        accessibleSummary ??\n        summarizeSeries(\n          label ?? \"Sparkline\",\n          data.map((value, index) => ({ label: String(index + 1), value }))\n        )\n      }\n    >\n      {label && <Text color={theme.colors.mutedForeground}>{label}</Text>}\n      <Text color={resolvedColor}>{sparkStr}</Text>\n    </Box>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "charts"
  ],
  "type": "registry:ui"
}