{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-chart",
  "type": "registry:ui",
  "title": "Share Chart",
  "description": "How a whole splits into parts, one bar per row: survey answers by group, a budget by department, time by activity. Each row is one 100% bar cut into segments, and every row shares one scale, so rows compare at a glance.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "data",
    "chart"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/skeleton.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/charts/share-chart.tsx",
      "target": "components/ui/charts/share-chart.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/share-chart v1.1.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/share-chart\n// What changed since: https://ds.interlace.tools/c/share-chart#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ShareChart\n *\n * How a whole splits into parts, one bar per row: survey answers by group,\n * a budget by department, time by activity. Each row is one 100% bar cut\n * into segments, and every row shares one scale, so rows compare at a\n * glance.\n *\n * ## Two layouts\n *\n *   - `stacked`: every bar starts at the same edge and runs to 100%. For\n *     parts that have no direction, such as answers to \"which do you use\".\n *   - `diverging`: for an ordered scale with two ends (strongly disagree to\n *     strongly agree). The categories before the middle go to the start of a\n *     shared zero line, the rest go to the end, and a `neutral` category\n *     straddles the line. The zero line sits in the same place on every row,\n *     so the reader compares both sides of every row against one mark. The\n *     total of each side is printed at its end of the bar.\n *\n * ## Shares, not raw numbers\n *\n * A row's values are divided by its total, which is the sum of its values\n * unless the row gives `total`. So counts and percentages both work, and a\n * row whose answers leave out \"no answer\" can set `total: 100` and keep that\n * gap honest instead of stretching the rest to fill it. `shareOf()` and\n * `shareLayout()` are exported and pure.\n *\n * ## Colour is never the only channel\n *\n * Stacked categories take the five chart hues in order, skipping any a\n * category names for itself, then neutral.\n * Diverging categories take two poles (`poles`, chart hues 1 and 3 by\n * default): the outer category of each side in the full tone, the inner ones\n * lighter towards the middle, and the neutral one grey. The legend names\n * every category in order; each row has a sentence with every share; a table\n * of every value sits behind the picture (`showTable` shows it). Segments are\n * parted by a 2px gap in the page colour, never by an outline.\n *\n * ## Pointing at a category\n *\n * Hovering a segment or a legend entry, or focusing a legend entry, dims the\n * other categories in every row and prints that category's share at the end\n * of each row. A click on a legend entry pins it (`aria-pressed`); a second\n * click lets go. All of it works from the keyboard through the legend.\n *\n * ## Motion\n *\n * The whole chart is in the server HTML. The first time it scrolls into\n * view, each bar grows out of its zero line once, in 400ms, the rows 150ms\n * apart in total. Under `prefers-reduced-motion` the bars are simply there.\n * It runs on the Web Animations API, so there are no keyframes to add.\n *\n * ## Container, not viewport\n *\n * Wide enough (28rem of its own box), each row is label, bar and totals on\n * one line, with the labels in one column. Narrower, the label sits above its\n * bar. In a right-to-left page the bars mirror: the start side is on the\n * right.\n *\n * ## MIN_VIEWPORT — 320\n *\n * ## Anatomy\n *\n *   <figure data-slot=\"share-chart\" data-layout=\"stacked|diverging\">\n *     <figcaption>{label}</figcaption>\n *     <div data-slot=\"share-chart-legend\"> <button aria-pressed /> × categories </div>\n *     <ul data-slot=\"share-chart-rows\">\n *       <li data-slot=\"share-chart-row\">\n *         <span data-slot=\"share-chart-row-label\" />\n *         <span data-slot=\"share-chart-start\" />            (diverging: start-side total)\n *         <svg data-slot=\"share-chart-bar\" aria-hidden>\n *           <rect data-slot=\"share-chart-segment\" /> × categories\n *         </svg>\n *         <span data-slot=\"share-chart-end\" />              (end-side total, or the pointed-at share)\n *         <span class=\"sr-only\">{row sentence}</span>\n *       </li>\n *     </ul>\n *     <div data-slot=\"share-chart-table\" />                 (sr-only unless showTable)\n *   </figure>\n *\n * | Rule | Concept                    | Where in this file                                         |\n * | ---- | -------------------------- | ---------------------------------------------------------- |\n * | R4   | Extends native el          | `React.ComponentProps<'figure'>`                            |\n * | R6   | data-slot on every part    | `share-chart` / `-row` / `-bar` / `-segment` / `-legend`     |\n * | R7   | className merged + ...rest | `cn(...)` + `{...props}`                                    |\n * | R8   | Enums, not booleans        | `layout`, `order`                                           |\n * | R13  | Ecosystem first            | no charting dep: `shareLayout` + SVG percentages            |\n * | R14  | Declares min viewport      | `data-min-viewport={String(MIN_VIEWPORT)}`                  |\n * | R18  | Tailwind only              | zero inline `style`; widths are SVG attributes, motion WAAPI |\n * | R19  | Tokens only                | `--chart-1..5`, `--muted-foreground`, mixed with `--background` |\n * | R23  | Loading reserves its box   | `loading` → `<Skeleton variant=\"chart\">`                    |\n * | R25  | Client component           | the reveal and the highlight run in the browser             |\n * | R26  | A11y                       | sentence per row + named legend + table                     |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { Skeleton } from '@/components/ui/skeleton';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nexport type ShareTone = 1 | 2 | 3 | 4 | 5 | 'neutral';\n\nexport type ShareCategory = {\n  /** What rows key their values by. */\n  id: string;\n  /** The category's name, as the legend and the table print it. */\n  label: string;\n  /** Its colour. @default stacked: the next of 1..5, then neutral; diverging: a shade of its side's pole */\n  tone?: ShareTone;\n};\n\nexport type ShareRow = {\n  /** The row's name, such as a group of respondents or a year. */\n  label: string;\n  /** A value per category id. Missing ids count as 0. */\n  values: Readonly<Record<string, number>>;\n  /** What the shares are of. @default the sum of the values */\n  total?: number;\n  /** A short line under the label, such as the sample size. */\n  note?: string;\n};\n\nexport type ShareLayoutKind = 'stacked' | 'diverging';\n\n/** Each tone at full strength, then two steps lighter towards the page. Written out so Tailwind sees them. */\nconst FILLS: Record<ShareTone, readonly [string, string, string]> = {\n  1: [\n    'fill-chart-1',\n    'fill-[color-mix(in_oklab,var(--chart-1),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--chart-1),var(--background)_60%)]',\n  ],\n  2: [\n    'fill-chart-2',\n    'fill-[color-mix(in_oklab,var(--chart-2),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--chart-2),var(--background)_60%)]',\n  ],\n  3: [\n    'fill-chart-3',\n    'fill-[color-mix(in_oklab,var(--chart-3),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--chart-3),var(--background)_60%)]',\n  ],\n  4: [\n    'fill-chart-4',\n    'fill-[color-mix(in_oklab,var(--chart-4),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--chart-4),var(--background)_60%)]',\n  ],\n  5: [\n    'fill-chart-5',\n    'fill-[color-mix(in_oklab,var(--chart-5),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--chart-5),var(--background)_60%)]',\n  ],\n  neutral: [\n    'fill-muted-foreground',\n    'fill-[color-mix(in_oklab,var(--muted-foreground),var(--background)_35%)]',\n    'fill-[color-mix(in_oklab,var(--muted-foreground),var(--background)_55%)]',\n  ],\n};\n\nconst STACK_ORDER: readonly ShareTone[] = [1, 2, 3, 4, 5];\n\n// ─────────────────────────────────────────────────────────────────\n// Pure geometry\n// ─────────────────────────────────────────────────────────────────\n\n/** Each category's share of the row, 0 to 1, in category order. Negative or non-finite values count as 0. */\nexport function shareOf(row: ShareRow, categories: readonly ShareCategory[]): number[] {\n  const raw = categories.map((c) => {\n    const v = row.values[c.id];\n    return typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : 0;\n  });\n  const sum = raw.reduce((a, b) => a + b, 0);\n  const total = row.total !== undefined && Number.isFinite(row.total) && row.total > 0 ? Math.max(row.total, sum) : sum;\n  return total > 0 ? raw.map((v) => v / total) : raw.map(() => 0);\n}\n\nexport type ShareSegment = {\n  /** Index into the categories. */\n  category: number;\n  /** Start along the bar, 0 to 1 of the shared scale. */\n  x: number;\n  /** Length, 0 to 1 of the shared scale. */\n  width: number;\n  /** The category's share of the row. */\n  share: number;\n};\n\nexport type ShareRowLayout = {\n  segments: ShareSegment[];\n  /** Diverging: the sum of the start side's shares, the neutral excluded. */\n  start: number;\n  /** Diverging: the sum of the end side's shares, the neutral excluded. Stacked: the sum of all shares. */\n  end: number;\n};\n\nexport type ShareLayout = {\n  rows: ShareRowLayout[];\n  /** Where the zero line sits, 0 to 1 of the bar. 0 when stacked. */\n  zero: number;\n};\n\n/**\n * Lay every row out on one shared scale.\n *\n * Stacked: the scale is 0 to 100% of a row. Diverging: categories before\n * `split` go to the start side, the category at `neutral` (if any) straddles\n * zero, and the rest go to the end side; the scale runs from the widest start\n * side to the widest end side across all rows, so the zero line is shared.\n */\nexport function shareLayout(\n  rows: readonly ShareRow[],\n  categories: readonly ShareCategory[],\n  layout: ShareLayoutKind,\n  options: { neutral?: number; split?: number } = {},\n): ShareLayout {\n  const shares = rows.map((row) => shareOf(row, categories));\n  if (layout === 'stacked') {\n    return {\n      zero: 0,\n      rows: shares.map((s) => {\n        let x = 0;\n        const segments = s.map((share, category) => {\n          const seg = { category, x, width: share, share };\n          x += share;\n          return seg;\n        });\n        return { segments, start: 0, end: x };\n      }),\n    };\n  }\n\n  const neutral = options.neutral !== undefined && options.neutral >= 0 ? options.neutral : -1;\n  const split = neutral >= 0 ? neutral : (options.split ?? Math.floor(categories.length / 2));\n  const endFrom = neutral >= 0 ? neutral + 1 : split;\n  const sides = shares.map((s) => {\n    const start = s.slice(0, split).reduce((a, b) => a + b, 0);\n    const end = s.slice(endFrom).reduce((a, b) => a + b, 0);\n    const middle = neutral >= 0 ? s[neutral]! : 0;\n    return { start, end, reach: start + middle / 2, beyond: end + middle / 2 };\n  });\n  const left = Math.max(0, ...sides.map((s) => s.reach));\n  const right = Math.max(0, ...sides.map((s) => s.beyond));\n  const span = left + right || 1;\n  return {\n    zero: left / span,\n    rows: shares.map((s, r) => {\n      let x = (left - sides[r]!.reach) / span;\n      const segments = s.map((share, category) => {\n        const seg = { category, x, width: share / span, share };\n        x += share / span;\n        return seg;\n      });\n      return { segments, start: sides[r]!.start, end: sides[r]!.end };\n    }),\n  };\n}\n\n/** The fill class of each category, in order. */\nexport function shareFills(\n  categories: readonly ShareCategory[],\n  layout: ShareLayoutKind,\n  options: { neutral?: number; split?: number; poles?: readonly [ShareTone, ShareTone] } = {},\n): string[] {\n  if (layout === 'stacked') {\n    // Auto tones skip every hue a category names, wherever it sits, so no two categories share a fill.\n    const named = new Set(categories.map((c) => c.tone));\n    const free = STACK_ORDER.filter((tone) => !named.has(tone));\n    let next = 0;\n    return categories.map((c) => FILLS[c.tone ?? free[next++] ?? 'neutral'][0]);\n  }\n  const [startPole, endPole] = options.poles ?? [1, 3];\n  const neutral = options.neutral !== undefined && options.neutral >= 0 ? options.neutral : -1;\n  const split = neutral >= 0 ? neutral : (options.split ?? Math.floor(categories.length / 2));\n  const endFrom = neutral >= 0 ? neutral + 1 : split;\n  const startCount = split;\n  const endCount = categories.length - endFrom;\n  return categories.map((c, i) => {\n    if (i === neutral) return FILLS[c.tone ?? 'neutral'][1];\n    if (i < split) {\n      // The outermost (index 0) is the strongest.\n      const step = Math.min(2, Math.round((i / Math.max(1, startCount - 1)) * Math.min(2, startCount - 1)));\n      return FILLS[c.tone ?? startPole][step]!;\n    }\n    // The outermost (the last) is the strongest.\n    const fromEdge = categories.length - 1 - i;\n    const step = Math.min(2, Math.round((fromEdge / Math.max(1, endCount - 1)) * Math.min(2, endCount - 1)));\n    return FILLS[c.tone ?? endPole][step]!;\n  });\n}\n\n/** Every fixed word in ShareChart. Pass only the ones to change. */\nexport interface ShareChartLabels {\n  /** Shown when there are no rows or categories. */\n  empty: string;\n  /** The legend's accessible name. */\n  categories: string;\n  /** The table's first column header, read by screen readers only. */\n  row: string;\n  /** The table caption, given the chart's label when it is a string. */\n  tableCaption: (label?: string) => string;\n  /** The sentence for one row, given its label and each category's formatted share. */\n  rowSentence: (row: string, shares: readonly { category: string; share: string }[]) => string;\n}\n\nconst LABELS: ShareChartLabels = {\n  empty: 'No answers to show yet.',\n  categories: 'Categories',\n  row: 'Row',\n  tableCaption: (label) => (label ? `${label}: shares by row` : 'Shares by row'),\n  rowSentence: (row, shares) => `${row}: ${shares.map((s) => `${s.category} ${s.share}`).join(', ')}.`,\n};\n\n/** One sentence for a row: its label, then every category's share. */\nexport function describeShareRow(\n  row: ShareRow,\n  categories: readonly ShareCategory[],\n  format: (share: number) => string,\n  sentence: ShareChartLabels['rowSentence'] = LABELS.rowSentence,\n): string {\n  const shares = shareOf(row, categories);\n  return sentence(\n    row.label,\n    categories.map((c, i) => ({ category: c.label, share: format(shares[i]!) })),\n  );\n}\n\n// ─────────────────────────────────────────────────────────────────\n// Component\n// ─────────────────────────────────────────────────────────────────\n\nconst GROW_MS = 400;\nconst SPREAD_MS = 150;\nconst EASE_ENTER = 'cubic-bezier(0.16, 1, 0.3, 1)';\n\n/** A bar's height, in px. A tall segmented bar never passes 28. */\nconst BAR_HEIGHT = 24;\n\nexport interface ShareChartProps extends Omit<React.ComponentProps<'figure'>, 'children'> {\n  /** The parts, in order. For `diverging`, from one end of the scale to the other. */\n  categories: readonly ShareCategory[];\n  /** One bar per row. */\n  rows: readonly ShareRow[];\n  /** `stacked` from one edge, or `diverging` around a shared zero line. @default 'stacked' */\n  layout?: ShareLayoutKind;\n  /** Diverging: the id of the middle category, which straddles the zero line. */\n  neutral?: string;\n  /** Diverging without a neutral: how many categories sit on the start side. @default half, rounded down */\n  split?: number;\n  /** Diverging: the tones of the start side and the end side. @default [1, 3] */\n  poles?: readonly [ShareTone, ShareTone];\n  /** Diverging: names for the start and end sides, printed above their totals. */\n  sideLabels?: readonly [string, string];\n  /** Keep the given row order, or sort by one category's share, largest first. @default 'given' */\n  order?: 'given' | 'descending';\n  /** The category `order=\"descending\"` sorts by. @default diverging: the end side's total; stacked: the first category */\n  sortBy?: string;\n  /** The chart's title. */\n  label?: React.ReactNode;\n  /** A BCP 47 locale for the percentages. @default the reader's */\n  locale?: string;\n  /** Decimal places on printed shares. @default 0 */\n  precision?: number;\n  /** Replace any fixed word: the empty note, the legend name, the table caption, the spoken rows. */\n  labels?: Partial<ShareChartLabels>;\n  /** Show the table of values, which otherwise is for screen readers only. */\n  showTable?: boolean;\n  /** Reserve the chart's box while the data loads. */\n  loading?: boolean;\n}\n\nexport const ShareChart = React.forwardRef<HTMLElement, ShareChartProps>(function ShareChart(\n  {\n    categories,\n    rows,\n    layout = 'stacked',\n    neutral,\n    split,\n    poles,\n    sideLabels,\n    order = 'given',\n    sortBy,\n    label,\n    locale,\n    precision = 0,\n    labels: labelsProp,\n    showTable = false,\n    loading = false,\n    className,\n    ...props\n  },\n  ref,\n) {\n  const reduced = useReducedMotion();\n  const labels = { ...LABELS, ...labelsProp };\n  const labelId = React.useId();\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const [hovered, setHovered] = React.useState<number | null>(null);\n  const [pinned, setPinned] = React.useState<number | null>(null);\n\n  const neutralIndex = neutral === undefined ? -1 : categories.findIndex((c) => c.id === neutral);\n  const geometryOptions = { neutral: neutralIndex, split };\n\n  const sorted = React.useMemo(() => {\n    if (order === 'given') return rows.map((row, index) => ({ row, index }));\n    const key = sortBy === undefined ? -1 : categories.findIndex((c) => c.id === sortBy);\n    const score = (row: ShareRow) => {\n      if (key >= 0) return shareOf(row, categories)[key]!;\n      if (layout === 'diverging') return shareLayout([row], categories, layout, geometryOptions).rows[0]!.end;\n      return shareOf(row, categories)[0] ?? 0;\n    };\n    return rows\n      .map((row, index) => ({ row, index, score: score(row) }))\n      .sort((a, b) => b.score - a.score || a.index - b.index);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [rows, categories, order, sortBy, layout, neutralIndex, split]);\n\n  const geometry = React.useMemo(\n    () => shareLayout(sorted.map((s) => s.row), categories, layout, geometryOptions),\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [sorted, categories, layout, neutralIndex, split],\n  );\n  const fills = React.useMemo(\n    () => shareFills(categories, layout, { ...geometryOptions, poles }),\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [categories, layout, neutralIndex, split, poles],\n  );\n\n  const percent = React.useMemo(\n    () =>\n      new Intl.NumberFormat(locale, {\n        style: 'percent',\n        minimumFractionDigits: precision,\n        maximumFractionDigits: precision,\n      }),\n    [locale, precision],\n  );\n  const format = (share: number) => percent.format(share);\n\n  // The first view grows each bar out of its zero line, once.\n  React.useLayoutEffect(() => {\n    const list = listRef.current;\n    if (!list || reduced || typeof IntersectionObserver === 'undefined') return;\n    const bars = Array.from(list.querySelectorAll<SVGGElement>('[data-slot=\"share-chart-grow\"]'));\n    if (typeof bars[0]!.animate !== 'function') return;\n    for (const bar of bars) bar.style.opacity = '0';\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((e) => e.isIntersecting)) return;\n        io.disconnect();\n        const last = Math.max(1, bars.length - 1);\n        bars.forEach((bar, i) => {\n          bar.style.opacity = '';\n          bar.style.transformOrigin = `${bar.getAttribute('data-origin')} 50%`;\n          bar.animate(\n            [\n              { transform: 'scaleX(0)', opacity: 0 },\n              { transform: 'scaleX(1)', opacity: 1 },\n            ],\n            { duration: GROW_MS, delay: (i / last) * SPREAD_MS, easing: EASE_ENTER, fill: 'backwards' },\n          );\n        });\n      },\n      { threshold: 0.25 },\n    );\n    io.observe(list);\n    return () => {\n      io.disconnect();\n      for (const bar of bars) {\n        bar.style.opacity = '';\n        for (const animation of bar.getAnimations()) animation.cancel();\n      }\n    };\n  }, [reduced, rows.length, categories.length, layout]);\n\n  if (loading) {\n    return (\n      <figure\n        ref={ref}\n        data-slot=\"share-chart\"\n        data-state=\"loading\"\n        data-min-viewport={String(MIN_VIEWPORT)}\n        aria-busy=\"true\"\n        className={cn('m-0 w-full', className)}\n        {...props}\n      >\n        <Skeleton variant=\"chart\" />\n      </figure>\n    );\n  }\n\n  if (rows.length === 0 || categories.length === 0) {\n    return (\n      <figure\n        ref={ref}\n        data-slot=\"share-chart\"\n        data-state=\"empty\"\n        data-min-viewport={String(MIN_VIEWPORT)}\n        className={cn('m-0 w-full rounded-xl border border-border p-6', className)}\n        {...props}\n      >\n        <p className=\"text-sm text-muted-foreground\">{labels.empty}</p>\n      </figure>\n    );\n  }\n\n  const diverging = layout === 'diverging';\n  // How many categories sit on the start side. Stacked has no start side.\n  const startSide = !diverging ? 0 : neutralIndex >= 0 ? neutralIndex : (split ?? Math.floor(categories.length / 2));\n  const active = hovered ?? pinned;\n  const zero = geometry.zero;\n  const pct = (n: number) => `${Number((n * 100).toFixed(3))}%`;\n\n  const point = (event: React.PointerEvent<SVGSVGElement>) => {\n    const category = (event.target as Element).getAttribute('data-category');\n    setHovered(category === null ? null : Number(category));\n  };\n\n  const NUMBER = 'text-foreground min-w-[4ch] shrink-0 text-ui-sm font-medium tabular-nums';\n\n  return (\n    <figure\n      ref={ref}\n      data-slot=\"share-chart\"\n      data-layout={layout}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      aria-labelledby={label ? labelId : undefined}\n      className={cn('@container/share m-0 flex w-full min-w-0 flex-col gap-4', className)}\n      {...props}\n    >\n      {label ? (\n        <figcaption id={labelId} data-slot=\"share-chart-label\" className=\"text-foreground text-ui-sm font-medium\">\n          {label}\n        </figcaption>\n      ) : null}\n\n      <ul\n        data-slot=\"share-chart-legend\"\n        aria-label={labels.categories}\n        className=\"m-0 flex list-none flex-wrap gap-x-4 gap-y-1 p-0 text-ui-sm\"\n      >\n        {categories.map((c, i) => (\n          <li key={c.id}>\n            <button\n              type=\"button\"\n              aria-pressed={pinned === i}\n              data-slot=\"share-chart-legend-item\"\n              data-active={active === i ? '' : undefined}\n              onPointerEnter={() => setHovered(i)}\n              onPointerLeave={() => setHovered(null)}\n              onFocus={() => setHovered(i)}\n              onBlur={() => setHovered(null)}\n              onClick={() => setPinned((current) => (current === i ? null : i))}\n              className={cn(\n                '-mx-1.5 flex min-h-target items-center gap-2 rounded-md px-1.5 py-0.5 text-start',\n                'hover:bg-muted data-[active]:bg-muted aria-pressed:bg-muted',\n                'focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:outline-hidden',\n              )}\n            >\n              <svg aria-hidden viewBox=\"0 0 12 12\" className=\"size-3 shrink-0\">\n                <rect width=\"12\" height=\"12\" rx=\"3\" className={fills[i]} />\n              </svg>\n              <span className=\"text-foreground\">{c.label}</span>\n            </button>\n          </li>\n        ))}\n      </ul>\n\n      <ul\n        ref={listRef}\n        data-slot=\"share-chart-rows\"\n        className={cn(\n          'm-0 grid list-none gap-y-3 p-0',\n          diverging ? 'grid-cols-[auto_minmax(0,1fr)_auto]' : 'grid-cols-[minmax(0,1fr)_auto]',\n          diverging\n            ? '@md/share:grid-cols-[minmax(6rem,14rem)_auto_minmax(0,1fr)_auto]'\n            : '@md/share:grid-cols-[minmax(6rem,14rem)_minmax(0,1fr)_auto]',\n        )}\n      >\n        {diverging && sideLabels ? (\n          <li aria-hidden className=\"col-span-full grid grid-cols-subgrid items-end gap-x-3 text-caption text-muted-foreground\">\n            <span className=\"col-span-full flex justify-between gap-3 @md/share:col-span-3 @md/share:col-start-2\">\n              <span>{sideLabels[0]}</span>\n              <span className=\"text-end\">{sideLabels[1]}</span>\n            </span>\n          </li>\n        ) : null}\n        {sorted.map(({ row, index }, r) => {\n          const placed = geometry.rows[r]!;\n          const sentence = describeShareRow(row, categories, format, labels.rowSentence);\n          // A pointed-at share replaces its side's total; the other side's number steps aside.\n          const shown = active === null ? null : format(placed.segments[active]!.share);\n          const onStart = active !== null && active < startSide;\n          const startText = active === null ? format(placed.start) : onStart ? shown : '';\n          const endText = active === null ? (diverging ? format(placed.end) : '') : onStart ? '' : shown;\n          return (\n            <li\n              key={`${row.label}-${index}`}\n              data-slot=\"share-chart-row\"\n              className=\"col-span-full grid grid-cols-subgrid items-center gap-x-3 gap-y-1\"\n            >\n              <span\n                data-slot=\"share-chart-row-label\"\n                aria-hidden\n                className=\"col-span-full flex min-w-0 flex-col @md/share:col-span-1\"\n              >\n                <span className=\"text-foreground text-ui-sm break-words\">{row.label}</span>\n                {row.note ? <span className=\"text-muted-foreground text-caption\">{row.note}</span> : null}\n              </span>\n              {diverging ? (\n                <span data-slot=\"share-chart-start\" aria-hidden className={cn(NUMBER, 'text-end')}>\n                  {startText}\n                </span>\n              ) : null}\n              <svg\n                data-slot=\"share-chart-bar\"\n                aria-hidden\n                width=\"100%\"\n                height={BAR_HEIGHT}\n                className=\"block h-6 w-full overflow-visible rtl:-scale-x-100\"\n                onPointerMove={point}\n                onPointerLeave={() => setHovered(null)}\n              >\n                <g data-slot=\"share-chart-grow\" data-origin={pct(zero)} className=\"[transform-box:view-box]\">\n                  {placed.segments.map((seg) =>\n                    seg.width > 0 ? (\n                      <rect\n                        key={seg.category}\n                        data-slot=\"share-chart-segment\"\n                        data-category={seg.category}\n                        x={pct(seg.x)}\n                        width={pct(seg.width)}\n                        y={0}\n                        height={BAR_HEIGHT}\n                        rx={4}\n                        strokeWidth={2}\n                        className={cn(\n                          'stroke-background motion-safe:transition-opacity motion-safe:duration-(--duration-fast)',\n                          fills[seg.category],\n                          active !== null && seg.category !== active && 'opacity-25',\n                        )}\n                      />\n                    ) : null,\n                  )}\n                </g>\n                {diverging ? (\n                  <line\n                    data-slot=\"share-chart-zero\"\n                    x1={pct(zero)}\n                    x2={pct(zero)}\n                    y1={-3}\n                    y2={BAR_HEIGHT + 3}\n                    strokeWidth={1.5}\n                    className=\"stroke-foreground\"\n                  />\n                ) : null}\n              </svg>\n              <span data-slot=\"share-chart-end\" aria-hidden className={NUMBER}>\n                {endText}\n              </span>\n              <span className=\"sr-only\">\n                {sentence}\n                {row.note ? ` ${row.note}.` : ''}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n\n      <div data-slot=\"share-chart-table\" className={cn(showTable ? 'overflow-x-auto' : 'sr-only')}>\n        <table className=\"w-full text-ui-sm tabular-nums\">\n          <caption className=\"text-muted-foreground pb-2 text-start text-caption\">\n            {labels.tableCaption(typeof label === 'string' ? label : undefined)}\n          </caption>\n          <thead>\n            <tr className=\"border-border border-b\">\n              <th scope=\"col\" className=\"py-1.5 pe-4 text-start font-medium\">\n                <span className=\"sr-only\">{labels.row}</span>\n              </th>\n              {categories.map((c) => (\n                <th key={c.id} scope=\"col\" className=\"py-1.5 pe-4 text-end font-medium last:pe-0\">\n                  {c.label}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {sorted.map(({ row, index }, r) => (\n              <tr key={`${row.label}-${index}`} className=\"border-border border-b\">\n                <th scope=\"row\" className=\"py-1.5 pe-4 text-start font-normal\">\n                  {row.label}\n                  {row.note ? <span className=\"text-muted-foreground block text-caption\">{row.note}</span> : null}\n                </th>\n                {geometry.rows[r]!.segments.map((seg) => (\n                  <td key={seg.category} className=\"py-1.5 pe-4 text-end last:pe-0\">\n                    {format(seg.share)}\n                  </td>\n                ))}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n    </figure>\n  );\n});\nShareChart.displayName = 'ShareChart';\n"
    }
  ],
  "meta": {
    "tier": "chart",
    "client": true,
    "minViewport": 320,
    "loading": true,
    "version": "1.1.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/share-chart\n\nInstalled to `components/ui/charts/share-chart.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/charts/share-chart';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/share-chart\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
