{
  "name": "donut-chart",
  "type": "ui:component",
  "title": "DonutChart",
  "description": "Zero-dependency SVG donut chart with center KPI total and percentage legend.",
  "dependencies": [],
  "registryDependencies": [
    "theme"
  ],
  "files": [
    {
      "path": "src/ui/donut-chart.tsx",
      "target": "src/ui/donut-chart.tsx",
      "sha256": "f0d1401e8a47cce7a8ebc2bdd28ca50e62ac195ca51e01c6bc9ecd640110693b",
      "content": "import './theme.css';\nimport { scope } from '@fierst/aster';\n\nconst dcScope = scope`\n  :scope {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    gap: 1.25rem;\n    font-family: var(--aster-font-sans);\n  }\n  .dc-ring { position: relative; display: inline-grid; place-items: center; flex-shrink: 0; }\n  svg { transform: rotate(-90deg); display: block; }\n  .dc-center { position: absolute; text-align: center; line-height: 1.2; }\n  .dc-total { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--aster-on-surface); display: block; }\n  .dc-sub { font-size: 0.72rem; color: var(--aster-on-surface-muted); }\n  .dc-legend { display: grid; gap: 0.45rem; flex: 1; min-width: 150px; }\n  .dc-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; font-size: 0.82rem; }\n  .dc-left { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--aster-on-surface); }\n  .dc-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }\n  .dc-num { font-family: var(--aster-font-mono); color: var(--aster-on-surface-muted); }\n`;\n\nconst PALETTE = [\n  'var(--aster-primary)',\n  'var(--aster-success)',\n  'var(--aster-warning)',\n  'var(--aster-danger)',\n  'var(--aster-border-strong)',\n];\n\nexport interface DonutSlice {\n  label: string;\n  value: number;\n  color?: string;\n}\n\nexport function DonutChart({\n  data,\n  size = 136,\n  strokeWidth = 18,\n  centerLabel = 'Total',\n  class: extraClass,\n}: {\n  data: readonly DonutSlice[];\n  size?: number;\n  strokeWidth?: number;\n  centerLabel?: string;\n  class?: string;\n}) {\n  const amount = (value: number) => (Number.isFinite(value) ? Math.max(0, value) : 0);\n  const total = data.reduce((sum, slice) => sum + amount(slice.value), 0);\n  const fraction = (value: number) => (total ? amount(value) / total : 0);\n  const r = (size - strokeWidth) / 2;\n  const circ = 2 * Math.PI * r;\n  let offset = 0;\n\n  return (\n    <div class={[dcScope, extraClass].filter(Boolean).join(' ')}>\n      <div class=\"dc-ring\" style={{ width: `${size}px`, height: `${size}px` }}>\n        <svg\n          width={size}\n          height={size}\n          viewBox={`0 0 ${size} ${size}`}\n          role=\"img\"\n          aria-label={centerLabel}\n        >\n          <circle\n            cx={size / 2}\n            cy={size / 2}\n            r={r}\n            fill=\"none\"\n            stroke=\"var(--aster-surface-muted)\"\n            stroke-width={strokeWidth}\n          />\n          {data.map((slice, idx) => {\n            const frac = fraction(slice.value);\n            const seg = frac * circ;\n            const dashOffset = -offset;\n            offset += seg;\n            const color = slice.color ?? PALETTE[idx % PALETTE.length];\n            return (\n              <circle\n                key={slice.label}\n                cx={size / 2}\n                cy={size / 2}\n                r={r}\n                fill=\"none\"\n                stroke={color}\n                stroke-width={strokeWidth}\n                stroke-dasharray={`${seg} ${circ - seg}`}\n                stroke-dashoffset={dashOffset}\n              />\n            );\n          })}\n        </svg>\n        <div class=\"dc-center\">\n          <span class=\"dc-total\">{total.toLocaleString()}</span>\n          <span class=\"dc-sub\">{centerLabel}</span>\n        </div>\n      </div>\n\n      <div class=\"dc-legend\">\n        {data.map((slice, idx) => (\n          <div key={slice.label} class=\"dc-row\">\n            <span class=\"dc-left\">\n              <span\n                class=\"dc-swatch\"\n                style={{ background: slice.color ?? PALETTE[idx % PALETTE.length] }}\n              />\n              <span>{slice.label}</span>\n            </span>\n            <span class=\"dc-num\">{Math.round(fraction(slice.value) * 100)}%</span>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}
