{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "area-chart",
  "title": "Area Chart",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-react/components/charts/area-chart/AreaChart.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport ReactECharts from 'echarts-for-react/lib/core'\nimport { cn } from '@/lib/utils'\nimport { ChartFrame, EChart, echartsCoreModule, heightToStyle } from '../shared'\nimport { useChartTheme, mergeOptionBlock, toRgba, gaugeThresholds } from '../useChartTheme'\n\n// AreaChart\n// ─────────────────────────────────────────────────────────────────────────\n\nexport interface AreaChartProps {\n  data: Record<string, any>[]\n  xField?: string\n  yField?: string | string[]\n  height?: number | string\n  option?: any\n  className?: string\n}\n\nexport const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>(\n  ({ data, xField = 'x', yField = 'y', height = 300, option, className }, ref) => {\n    const theme = useChartTheme()\n\n    const mergedOption = React.useMemo(() => {\n      const fields = Array.isArray(yField) ? yField : [yField]\n      const xData = data.map((d) => d[xField])\n\n      const series = fields.map((field, i) => ({\n        name: field,\n        type: 'line',\n        smooth: true,\n        symbol: 'none',\n        areaStyle: { opacity: 0.15 },\n        lineStyle: { width: 2 },\n        itemStyle: { color: theme.colors[i % theme.colors.length] },\n        data: data.map((d) => d[field]),\n      }))\n\n      const userOption: any = option ?? {}\n      const {\n        series: userSeries,\n        xAxis: userXAxis,\n        yAxis: userYAxis,\n        grid: userGrid,\n        tooltip: userTooltip,\n        legend: userLegend,\n        ...userRest\n      } = userOption\n      const mergedSeries = Array.isArray(userSeries) ? series.map((s, i) => ({ ...s, ...(userSeries[i] ?? {}) })) : series\n\n      const baseLegend: any =\n        fields.length > 1\n          ? {\n              bottom: 0,\n              icon: 'circle',\n              itemWidth: 8,\n              itemHeight: 8,\n              textStyle: { fontSize: 11, color: theme.textColor },\n            }\n          : { show: false }\n\n      return {\n        color: theme.colors,\n        grid: mergeOptionBlock(\n          { left: 16, right: 16, top: 24, bottom: fields.length > 1 ? 32 : 24, containLabel: true },\n          userGrid,\n        ),\n        tooltip: mergeOptionBlock(\n          {\n            trigger: 'axis',\n            backgroundColor: theme.tooltipBg,\n            borderColor: theme.tooltipBorder,\n            textStyle: { color: theme.tooltipText, fontSize: 12 },\n          },\n          userTooltip,\n        ),\n        legend: userLegend?.show === false ? undefined : mergeOptionBlock(baseLegend, userLegend),\n        xAxis: mergeOptionBlock(\n          {\n            type: 'category',\n            data: xData,\n            axisLine: { lineStyle: { color: theme.axisColor } },\n            axisLabel: { color: theme.textColor, fontSize: 11 },\n            axisTick: { show: false },\n          },\n          userXAxis,\n        ),\n        yAxis: mergeOptionBlock(\n          {\n            type: 'value',\n            splitLine: { lineStyle: { color: theme.splitLineColor } },\n            axisLabel: { color: theme.textColor, fontSize: 11 },\n            axisLine: { show: false },\n            axisTick: { show: false },\n          },\n          userYAxis,\n        ),\n        series: mergedSeries,\n        ...userRest,\n      }\n    }, [data, xField, yField, option, theme])\n\n    return (\n      <ChartFrame ref={ref} height={height} className={className}>\n        <EChart option={mergedOption} />\n      </ChartFrame>\n    )\n  },\n)\nAreaChart.displayName = 'AreaChart'\n",
      "type": "registry:ui",
      "target": "~/components/ui/charts/area-chart/AreaChart.tsx"
    },
    {
      "path": "packages/registry-react/components/charts/area-chart/index.ts",
      "content": "export { AreaChart, type AreaChartProps } from './AreaChart'\n",
      "type": "registry:ui",
      "target": "~/components/ui/charts/area-chart/index.ts"
    },
    {
      "path": "packages/registry-react/components/charts/useChartTheme.ts",
      "content": "'use client'\n\nimport { useEffect, useState } from 'react'\n\n// Chart palette is driven by Tailwind v4 CSS variables (`--chart-1`..`--chart-5`,\n// `--muted-foreground`, `--border`, `--popover`, etc.) so dark/light flips\n// happen automatically when the consumer toggles their theme class. The\n// values resolve at runtime via `getComputedStyle`, so they pick up whatever\n// the consumer set in their own `tailwind.css` -- no fork required.\n//\n// We bump a module-level `themeKey` whenever `<html>` class/style changes (the\n// typical shadcn dark-mode pivot) and notify subscribed `useChartTheme()`\n// consumers so every chart re-resolves its colors and ECharts re-paints.\n\nlet themeKey = 0\nconst listeners = new Set<() => void>()\n\nfunction bump() {\n  themeKey++\n  listeners.forEach((l) => l())\n}\n\nif (typeof window !== 'undefined') {\n  // Bump once on the first paint so post-hydration getComputedStyle reads\n  // the *resolved* CSS values (during SSR-built bundles the very first\n  // read returns the fallbacks below).\n  requestAnimationFrame(bump)\n  new MutationObserver(bump).observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: ['class', 'style', 'data-theme'],\n  })\n}\n\n// Lazy canvas context used to normalize any CSS color string (including\n// `oklch(...)`, `oklab(...)`, `color(display-p3 ...)`) into a hex / rgba\n// string ECharts' canvas renderer can consume. Without this, code that\n// does `color + '40'` (8-digit hex alpha trick) produces invalid color\n// strings like `oklch(...)40` and the canvas API throws.\nlet _hexCanvas: CanvasRenderingContext2D | null = null\nfunction toHex(cssColor: string): string {\n  if (typeof document === 'undefined') return cssColor\n  if (!_hexCanvas) {\n    _hexCanvas = document.createElement('canvas').getContext('2d')\n  }\n  if (!_hexCanvas) return cssColor\n  // Reset, then assign; the browser normalizes whatever it accepted into\n  // the canonical hex/rgba form when read back.\n  _hexCanvas.fillStyle = '#000'\n  _hexCanvas.fillStyle = cssColor\n  return _hexCanvas.fillStyle as string\n}\n\n// Convert any CSS color (hex, rgb, oklch, color()) + alpha 0..1 to a\n// canvas-safe rgba(r,g,b,a). `colorString + '40'` (8-digit hex alpha)\n// only works when `colorString` is `#rrggbb`; once tokens resolve to\n// oklch() post-hydration the gradient stops break and the canvas paint\n// throws every frame. Stay defensive and always return rgba.\nexport function toRgba(cssColor: string, alpha: number): string {\n  if (typeof document === 'undefined') return cssColor\n  if (!_hexCanvas) {\n    _hexCanvas = document.createElement('canvas').getContext('2d')\n  }\n  if (!_hexCanvas) return cssColor\n  _hexCanvas.fillStyle = '#000'\n  _hexCanvas.fillStyle = cssColor\n  const normalized = _hexCanvas.fillStyle as string\n  if (normalized.startsWith('#') && normalized.length === 7) {\n    const r = parseInt(normalized.slice(1, 3), 16)\n    const g = parseInt(normalized.slice(3, 5), 16)\n    const b = parseInt(normalized.slice(5, 7), 16)\n    return `rgba(${r},${g},${b},${alpha})`\n  }\n  if (normalized.startsWith('rgba(')) {\n    return normalized.replace(/,\\s*[\\d.]+\\s*\\)$/, `,${alpha})`)\n  }\n  if (normalized.startsWith('rgb(')) {\n    return normalized.replace(/^rgb\\(/, 'rgba(').replace(/\\)$/, `,${alpha})`)\n  }\n  // Canvas refused to parse this color -- ship the original string and\n  // let ECharts complain (better than crashing the paint loop).\n  return cssColor\n}\n\nfunction resolveVar(name: string, fallback: string): string {\n  if (typeof window === 'undefined') return fallback\n  const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim()\n  if (!v) return fallback\n  return toHex(v)\n}\n\n// SSR / pre-hydration fallback palette. Hex values picked to roughly\n// match the shadcn Neutral defaults in `tailwind.css` so the first paint\n// doesn't flicker.\nconst CHART_FALLBACK = ['#f59e0b', '#14b8a6', '#3b82f6', '#f97316', '#eab308']\n\n/** The resolved chart theme tokens. All values are canvas-safe hex/rgba. */\nexport interface ChartTheme {\n  colors: string[]\n  textColor: string\n  axisColor: string\n  splitLineColor: string\n  tooltipBg: string\n  tooltipBorder: string\n  tooltipText: string\n}\n\nfunction resolveTheme(): ChartTheme {\n  return {\n    colors: Array.from({ length: 5 }, (_, i) => resolveVar(`--chart-${i + 1}`, CHART_FALLBACK[i]!)),\n    textColor: resolveVar('--muted-foreground', '#888888'),\n    axisColor: resolveVar('--border', '#e5e5e5'),\n    splitLineColor: resolveVar('--border', '#f0f0f0'),\n    tooltipBg: resolveVar('--popover', 'rgba(255,255,255,0.96)'),\n    tooltipBorder: resolveVar('--border', '#e5e5e5'),\n    tooltipText: resolveVar('--popover-foreground', '#333333'),\n  }\n}\n\n/**\n * Subscribe to the theme-token palette. Re-resolves (and re-renders the\n * consuming chart) whenever the consumer flips their dark-mode class on\n * `<html>`. The first client render resolves the real CSS values; SSR /\n * pre-hydration returns the fallback palette above.\n */\nexport function useChartTheme(): ChartTheme {\n  const [, setTick] = useState(themeKey)\n  const [theme, setTheme] = useState<ChartTheme>(() => resolveTheme())\n\n  useEffect(() => {\n    const update = () => {\n      setTick(themeKey)\n      setTheme(resolveTheme())\n    }\n    listeners.add(update)\n    // Resolve once on mount so the first client paint reads the real CSS\n    // values instead of the SSR fallbacks.\n    update()\n    return () => {\n      listeners.delete(update)\n    }\n  }, [])\n\n  return theme\n}\n\n// Two-level deep merge for ECharts option blocks (xAxis, yAxis, grid,\n// tooltip, legend, singleAxis, parallel, etc.). The top-level keys merge\n// shallowly, but one nested level (axisLabel, axisLine, splitLine, etc.)\n// merges shallowly too so a consumer passing `xAxis: { axisLabel: { fontSize: 9 } }`\n// doesn't blow away the wrapper's `color` + base font defaults on the same\n// axisLabel block. Arrays + primitives replace outright.\n//\n// This is the merge strategy the chart wrappers use to fold `option`\n// onto their computed base option without forcing consumers to spell out\n// every default they want to preserve.\nexport function mergeOptionBlock<T extends Record<string, any>>(base: T, user: Partial<T> | undefined): T {\n  if (!user) return base\n  const out: any = { ...base }\n  for (const k of Object.keys(user)) {\n    const bv = (base as any)[k]\n    const uv = (user as any)[k]\n    if (\n      bv != null &&\n      uv != null &&\n      typeof bv === 'object' &&\n      typeof uv === 'object' &&\n      !Array.isArray(bv) &&\n      !Array.isArray(uv)\n    ) {\n      out[k] = { ...bv, ...uv }\n    } else {\n      out[k] = uv\n    }\n  }\n  return out\n}\n\n// Default gauge stoplight: teal (safe) -> amber (warning) -> red (danger).\n// Pulled off saturated green and onto teal so the gauge ties back to the\n// dashboard palette; red is kept as the universal \"limit reached\" cue.\n// GaugeChart consumes this via its `thresholds` prop default; consumers\n// pass their own array to override. Static because gauges have semantic\n// meaning (green safe / red danger) that we deliberately don't theme-flip.\nexport const gaugeThresholds: [number, string][] = [\n  [0.6, '#14b8a6'],\n  [0.85, '#f59e0b'],\n  [1, '#dc2626'],\n]\n",
      "type": "registry:ui",
      "target": "~/components/ui/charts/useChartTheme.ts"
    },
    {
      "path": "packages/registry-react/components/charts/shared.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport * as echartsCore from 'echarts/core'\nimport { use } from 'echarts/core'\nimport { CanvasRenderer } from 'echarts/renderers'\nimport {\n  LineChart as EChartsLineChart,\n  BarChart as EChartsBarChart,\n  PieChart as EChartsPieChart,\n  ScatterChart as EChartsScatterChart,\n  RadarChart as EChartsRadarChart,\n  GaugeChart as EChartsGaugeChart,\n  HeatmapChart as EChartsHeatmap,\n  TreemapChart as EChartsTreemapChart,\n  FunnelChart as EChartsFunnelChart,\n  BoxplotChart as EChartsBoxplotChart,\n  CandlestickChart as EChartsCandlestickChart,\n  GraphChart as EChartsGraphChart,\n  ParallelChart as EChartsParallelChart,\n  SankeyChart as EChartsSankeyChart,\n  SunburstChart as EChartsSunburstChart,\n  ThemeRiverChart,\n  TreeChart as EChartsTreeChart,\n} from 'echarts/charts'\nimport {\n  GridComponent,\n  TooltipComponent,\n  LegendComponent,\n  RadarComponent,\n  VisualMapComponent,\n  CalendarComponent,\n  DataZoomComponent,\n  ParallelComponent,\n  SingleAxisComponent,\n} from 'echarts/components'\nimport ReactECharts from 'echarts-for-react/lib/core'\nimport { cn } from '@/lib/utils'\n\nexport function heightToStyle(height: number | string): string {\n  return /^\\d+$/.test(String(height)) ? `${height}px` : String(height)\n}\n\ninterface ChartFrameProps {\n  height: number | string\n  className?: string\n  /** Apply the accessible role/tabindex/focus-ring chrome. Some chart\n   *  wrappers ship a bare `w-full` frame -- pass `false` for those. */\n  focusable?: boolean\n}\n\n/** Shared `<div>` wrapper around the ECharts canvas. */\nexport const ChartFrame = React.forwardRef<HTMLDivElement, ChartFrameProps & { children: React.ReactNode }>(\n  ({ height, className, focusable = true, children }, ref) => (\n    <div\n      ref={ref}\n      role={focusable ? 'img' : undefined}\n      tabIndex={focusable ? 0 : undefined}\n      style={{ height: heightToStyle(height) }}\n      className={\n        focusable\n          ? cn('focus-visible:ring-ring w-full focus-visible:ring-2 focus-visible:outline-none', className)\n          : cn('w-full', className)\n      }\n    >\n      {children}\n    </div>\n  ),\n)\nChartFrame.displayName = 'ChartFrame'\n\n/** ECharts canvas filling its parent frame. */\nexport function EChart({ option }: { option: any }) {\n  return (\n    <ReactECharts\n      echarts={echartsCore as any}\n      option={option}\n      notMerge\n      lazyUpdate\n      style={{ width: '100%', height: '100%' }}\n    />\n  )\n}\n\nexport const echartsCoreModule = echartsCore\n\n// Register every chart type the wrappers need once at module load.\nuse([\n  CanvasRenderer,\n  EChartsLineChart,\n  EChartsBarChart,\n  EChartsPieChart,\n  EChartsScatterChart,\n  EChartsRadarChart,\n  EChartsGaugeChart,\n  EChartsHeatmap,\n  EChartsTreemapChart,\n  EChartsFunnelChart,\n  EChartsBoxplotChart,\n  EChartsCandlestickChart,\n  EChartsGraphChart,\n  EChartsParallelChart,\n  EChartsSankeyChart,\n  EChartsSunburstChart,\n  ThemeRiverChart,\n  EChartsTreeChart,\n  GridComponent,\n  TooltipComponent,\n  LegendComponent,\n  RadarComponent,\n  VisualMapComponent,\n  CalendarComponent,\n  DataZoomComponent,\n  ParallelComponent,\n  SingleAxisComponent,\n])",
      "type": "registry:ui",
      "target": "~/components/ui/charts/shared.tsx"
    }
  ],
  "dependencies": [
    "echarts",
    "echarts-for-react"
  ],
  "devDependencies": [],
  "registryDependencies": [],
  "description": "React mirror of @uipkge/area-chart — see the Vue registry item for the canonical description.",
  "categories": [
    "chart"
  ]
}