{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-sparkline",
  "title": "Sparkline",
  "description": "Micro-gráfico SVG ultra-leve para tabelas e cards com modos line, area e bar.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider",
    "@lema-ds/tokens"
  ],
  "files": [
    {
      "path": "components/ds/ds-sparkline.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\n\n// ── Variants ──\n\nexport const sparklineVariants = cva(\"overflow-visible\", {\n  variants: {\n    intent: {\n      primary: \"fill-primary stroke-primary text-primary\",\n      success: \"fill-success stroke-success text-success\",\n      destructive: \"fill-destructive stroke-destructive text-destructive\",\n      warning: \"fill-warning stroke-warning text-warning\",\n    },\n  },\n  defaultVariants: {\n    intent: \"primary\",\n  },\n})\n\n// ── Types ──\n\nexport interface SparklineProps\n  extends\n    React.SVGAttributes<SVGSVGElement>,\n    VariantProps<typeof sparklineVariants> {\n  /**\n   * Numeric series data array.\n   */\n  data: number[]\n  /**\n   * Sparkline type.\n   */\n  type?: \"line\" | \"area\" | \"bar\"\n  /**\n   * Line stroke thickness in pixels.\n   */\n  strokeWidth?: number\n  /**\n   * Shows a highlight circle at the latest (last) data point.\n   */\n  showLastPoint?: boolean\n  /**\n   * Height in pixels.\n   */\n  height?: number\n  /**\n   * Width in pixels or CSS percentage string.\n   */\n  width?: number | string\n  /**\n   * Loading skeleton indicator.\n   */\n  loading?: boolean\n  /**\n   * Locale for accessibility label formatting.\n   */\n  locale?: UILocale\n}\n\n// ── Component ──\n\nexport const Sparkline = React.forwardRef<SVGSVGElement, SparklineProps>(\n  (\n    {\n      data,\n      type = \"line\",\n      intent = \"primary\",\n      strokeWidth = 2,\n      showLastPoint = true,\n      height = 36,\n      width = \"100%\",\n      loading = false,\n      locale: localeProp,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const t = UI_I18N[locale].sparkline\n    const gradientId = React.useId()\n\n    if (loading) {\n      return (\n        <Skeleton\n          className={cn(\"rounded-sm\", className)}\n          style={{ height, width }}\n        />\n      )\n    }\n\n    if (!data || data.length === 0) {\n      return null\n    }\n\n    const viewBoxWidth = 100\n    const viewBoxHeight = height\n    const paddingY = 4\n    const paddingX = 4\n\n    const min = Math.min(...data)\n    const max = Math.max(...data)\n    const range = max - min || 1\n\n    const effectiveHeight = viewBoxHeight - paddingY * 2\n    const effectiveWidth = viewBoxWidth - paddingX * 2\n\n    // Compute coordinates\n    const points = data.map((val, idx) => {\n      const x =\n        data.length === 1\n          ? viewBoxWidth / 2\n          : paddingX + (idx / (data.length - 1)) * effectiveWidth\n      const y =\n        viewBoxHeight - paddingY - ((val - min) / range) * effectiveHeight\n      return { x, y, val }\n    })\n\n    const pathD = points.reduce((acc, pt, i) => {\n      return i === 0 ? `M ${pt.x} ${pt.y}` : `${acc} L ${pt.x} ${pt.y}`\n    }, \"\")\n\n    const areaD =\n      points.length > 0\n        ? `${pathD} L ${points[points.length - 1].x} ${viewBoxHeight} L ${points[0].x} ${viewBoxHeight} Z`\n        : \"\"\n\n    const lastPoint = points[points.length - 1]\n    const firstPoint = points[0]\n\n    const trendText = `${t.currentValue}: ${lastPoint.val} (${\n      lastPoint.val >= firstPoint.val ? \"+\" : \"\"\n    }${(lastPoint.val - firstPoint.val).toFixed(1)})`\n\n    return (\n      <svg\n        ref={ref}\n        viewBox={`0 0 ${viewBoxWidth} ${viewBoxHeight}`}\n        preserveAspectRatio=\"none\"\n        style={{ width, height }}\n        role=\"img\"\n        aria-label={trendText}\n        className={cn(sparklineVariants({ intent }), className)}\n        {...props}\n      >\n        <defs>\n          <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity=\"0.28\" />\n            <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity=\"0.0\" />\n          </linearGradient>\n        </defs>\n\n        {type === \"bar\" ? (\n          <g>\n            {points.map((pt, i) => {\n              const barWidth = Math.max(\n                2,\n                (effectiveWidth / data.length) * 0.65\n              )\n              const barHeight = Math.max(2, viewBoxHeight - pt.y - paddingY)\n              return (\n                <rect\n                  key={i}\n                  x={pt.x - barWidth / 2}\n                  y={pt.y}\n                  width={barWidth}\n                  height={barHeight}\n                  rx={1}\n                  className=\"fill-current opacity-80 transition-opacity hover:opacity-100\"\n                />\n              )\n            })}\n          </g>\n        ) : (\n          <>\n            {type === \"area\" && (\n              <path d={areaD} fill={`url(#${gradientId})`} stroke=\"none\" />\n            )}\n            <path\n              d={pathD}\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth={strokeWidth}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n            />\n            {showLastPoint && lastPoint && (\n              <circle\n                cx={lastPoint.x}\n                cy={lastPoint.y}\n                r={strokeWidth + 1}\n                className=\"fill-current\"\n              />\n            )}\n          </>\n        )}\n      </svg>\n    )\n  }\n)\n\nSparkline.displayName = \"Sparkline\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
