gridsmith-ui 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +8 -6
  2. package/dist/MentionList-CoNBRFGR.d.ts +8 -0
  3. package/dist/charts.d.ts +42 -1
  4. package/dist/charts.js +320 -89
  5. package/dist/charts.js.map +1 -1
  6. package/dist/chat.js +5 -4
  7. package/dist/chat.js.map +1 -1
  8. package/dist/{chunk-6XAU44U4.js → chunk-CYN5O567.js} +10 -23
  9. package/dist/chunk-CYN5O567.js.map +1 -0
  10. package/dist/{chunk-SBTBMAIU.js → chunk-EX64MN2U.js} +6 -6
  11. package/dist/{chunk-SBTBMAIU.js.map → chunk-EX64MN2U.js.map} +1 -1
  12. package/dist/chunk-HP7WUZPK.js +80 -0
  13. package/dist/chunk-HP7WUZPK.js.map +1 -0
  14. package/dist/{chunk-4LDYR7QP.js → chunk-HXVXJUGV.js} +53 -13
  15. package/dist/chunk-HXVXJUGV.js.map +1 -0
  16. package/dist/{chunk-MV7JXWXK.js → chunk-KWLNEH53.js} +8 -7
  17. package/dist/chunk-KWLNEH53.js.map +1 -0
  18. package/dist/{chunk-CXMV7SXJ.js → chunk-MD2EFMES.js} +5 -77
  19. package/dist/chunk-MD2EFMES.js.map +1 -0
  20. package/dist/{chunk-SVP2IG4S.js → chunk-MYIJNVTK.js} +7 -7
  21. package/dist/chunk-MYIJNVTK.js.map +1 -0
  22. package/dist/{chunk-IVCVNAXG.js → chunk-OTCEJN64.js} +3 -3
  23. package/dist/{chunk-IVCVNAXG.js.map → chunk-OTCEJN64.js.map} +1 -1
  24. package/dist/{chunk-2PWGJ4PK.js → chunk-QM4SJKWV.js} +11 -6
  25. package/dist/chunk-QM4SJKWV.js.map +1 -0
  26. package/dist/chunk-RWKCAKN3.js +209 -0
  27. package/dist/chunk-RWKCAKN3.js.map +1 -0
  28. package/dist/{chunk-2YSEME33.js → chunk-SFY2KMHG.js} +63 -6
  29. package/dist/chunk-SFY2KMHG.js.map +1 -0
  30. package/dist/{chunk-NCIZQYXQ.js → chunk-X2HEV7FB.js} +33 -3
  31. package/dist/chunk-X2HEV7FB.js.map +1 -0
  32. package/dist/{chunk-JXANCXK6.js → chunk-ZI3OQDET.js} +18 -4
  33. package/dist/chunk-ZI3OQDET.js.map +1 -0
  34. package/dist/{chunk-7TOJ4G7S.js → chunk-ZYVXV4WC.js} +14 -9
  35. package/dist/chunk-ZYVXV4WC.js.map +1 -0
  36. package/dist/data-grid.d.ts +1 -1
  37. package/dist/data-grid.js +13 -12
  38. package/dist/data-grid.js.map +1 -1
  39. package/dist/editor-mentions.d.ts +30 -0
  40. package/dist/editor-mentions.js +160 -0
  41. package/dist/editor-mentions.js.map +1 -0
  42. package/dist/editor.d.ts +23 -3
  43. package/dist/editor.js +58 -9
  44. package/dist/editor.js.map +1 -1
  45. package/dist/{feather-2JFSFLXN.js → feather-VFWLAILO.js} +12 -3
  46. package/dist/feather-VFWLAILO.js.map +1 -0
  47. package/dist/{heroicons-4AQ4YBVG.js → heroicons-H3Z7DFCF.js} +22 -7
  48. package/dist/heroicons-H3Z7DFCF.js.map +1 -0
  49. package/dist/icons.d.ts +11 -4
  50. package/dist/icons.js +1 -1
  51. package/dist/index.d.ts +202 -31
  52. package/dist/index.js +1473 -1181
  53. package/dist/index.js.map +1 -1
  54. package/dist/kanban.js +8 -8
  55. package/dist/kanban.js.map +1 -1
  56. package/dist/{lucide-RZC2FEMS.js → lucide-MR32KM4G.js} +12 -3
  57. package/dist/lucide-MR32KM4G.js.map +1 -0
  58. package/dist/{phosphor-CEN25FLM.js → phosphor-ABQQL5N5.js} +12 -3
  59. package/dist/phosphor-ABQQL5N5.js.map +1 -0
  60. package/dist/resizable.js +8 -8
  61. package/dist/roots.css +28 -0
  62. package/dist/{tabler-YXXC7Y6B.js → tabler-ANUSY4D2.js} +12 -3
  63. package/dist/tabler-ANUSY4D2.js.map +1 -0
  64. package/dist/tokens.css +6 -0
  65. package/dist/{use-pagination-DiJo0aW5.d.ts → use-pagination-BnKOnBdz.d.ts} +3 -0
  66. package/dist/virtualized.d.ts +1 -1
  67. package/dist/virtualized.js +7 -6
  68. package/dist/virtualized.js.map +1 -1
  69. package/dist-static/tokens.css +6 -0
  70. package/package.json +29 -21
  71. package/dist/chunk-2PWGJ4PK.js.map +0 -1
  72. package/dist/chunk-2YSEME33.js.map +0 -1
  73. package/dist/chunk-4LDYR7QP.js.map +0 -1
  74. package/dist/chunk-6XAU44U4.js.map +0 -1
  75. package/dist/chunk-7TOJ4G7S.js.map +0 -1
  76. package/dist/chunk-CXMV7SXJ.js.map +0 -1
  77. package/dist/chunk-JXANCXK6.js.map +0 -1
  78. package/dist/chunk-MV7JXWXK.js.map +0 -1
  79. package/dist/chunk-NCIZQYXQ.js.map +0 -1
  80. package/dist/chunk-SVP2IG4S.js.map +0 -1
  81. package/dist/chunk-WOVYHFUD.js +0 -50
  82. package/dist/chunk-WOVYHFUD.js.map +0 -1
  83. package/dist/feather-2JFSFLXN.js.map +0 -1
  84. package/dist/heroicons-4AQ4YBVG.js.map +0 -1
  85. package/dist/lucide-RZC2FEMS.js.map +0 -1
  86. package/dist/phosphor-CEN25FLM.js.map +0 -1
  87. package/dist/tabler-YXXC7Y6B.js.map +0 -1
package/dist/charts.js CHANGED
@@ -1,8 +1,8 @@
1
- import { TITLE_TEXT, Skeleton } from './chunk-NCIZQYXQ.js';
1
+ import { formatLocale, TITLE_TEXT, Skeleton } from './chunk-X2HEV7FB.js';
2
2
  import { mergeRefs } from './chunk-7Q46JXSK.js';
3
3
  import { cn, GLASS_SURFACE } from './chunk-M2QRNBDQ.js';
4
4
  import { createContext, forwardRef, useContext, useRef, useState, useMemo, useLayoutEffect, useEffect, useId, useSyncExternalStore, Children, isValidElement } from 'react';
5
- import { ResponsiveContainer, BarChart as BarChart$1, CartesianGrid, XAxis, YAxis, Tooltip, Bar, LineChart as LineChart$1, Line, AreaChart as AreaChart$1, Area, PieChart as PieChart$1, Pie, Cell, ComposedChart, ScatterChart as ScatterChart$1, ZAxis, Scatter, RadarChart as RadarChart$1, PolarGrid, PolarAngleAxis, PolarRadiusAxis, Radar, RadialBarChart as RadialBarChart$1, RadialBar, FunnelChart as FunnelChart$1, Funnel, LabelList, Treemap, Sankey, Text, Legend, Rectangle } from 'recharts';
5
+ import { ResponsiveContainer, BarChart as BarChart$1, CartesianGrid, XAxis, YAxis, Tooltip, Bar, LineChart as LineChart$1, Line, AreaChart as AreaChart$1, Area, PieChart as PieChart$1, Pie, Cell, ComposedChart, ScatterChart as ScatterChart$1, ZAxis, Scatter, RadarChart as RadarChart$1, PolarGrid, PolarAngleAxis, PolarRadiusAxis, Radar, RadialBarChart as RadialBarChart$1, RadialBar, FunnelChart as FunnelChart$1, Funnel, LabelList, Treemap, Sankey, Text, Legend, getNiceTickValues, Rectangle } from 'recharts';
6
6
  import { createPortal } from 'react-dom';
7
7
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
8
 
@@ -441,6 +441,7 @@ var ChartWrapper = forwardRef(function ChartWrapper2({
441
441
  axisTitle,
442
442
  className,
443
443
  children,
444
+ formatValue,
444
445
  "aria-label": ariaLabel
445
446
  }, ref) {
446
447
  const container = useContext(ChartContainerContext);
@@ -448,7 +449,7 @@ var ChartWrapper = forwardRef(function ChartWrapper2({
448
449
  const plotRef = useRef(null);
449
450
  const [legend, setLegend] = useState(null);
450
451
  const [live, setLive] = useState(null);
451
- const frame = useMemo(() => ({ legend, live }), [legend, live]);
452
+ const frame = useMemo(() => ({ legend, live, formatValue }), [legend, live, formatValue]);
452
453
  const [drawn, setDrawn] = useState(null);
453
454
  useLayoutEffect(() => {
454
455
  const plot = plotRef.current;
@@ -522,12 +523,82 @@ var ChartWrapper = forwardRef(function ChartWrapper2({
522
523
  }
523
524
  );
524
525
  });
526
+ var TICK_COUNT = 5;
527
+ var TIME_UNITS = [["hour", 36e5], ["minute", 6e4], ["second", 1e3], ["millisecond", 1]];
528
+ var BYTE_UNITS = [["petabyte", 1e15], ["terabyte", 1e12], ["gigabyte", 1e9], ["megabyte", 1e6], ["kilobyte", 1e3], ["byte", 1]];
529
+ var MAX_FRACTION = 10;
530
+ function exact(format, maxDigits = MAX_FRACTION) {
531
+ for (let digits = 0; digits < maxDigits; digits++) {
532
+ const label = format(digits);
533
+ if (label === format(digits + 6)) return label;
534
+ }
535
+ return format(maxDigits);
536
+ }
537
+ var unitFormat = (unit, value) => (digits) => new Intl.NumberFormat(formatLocale(), { style: "unit", unit, unitDisplay: "short", maximumFractionDigits: digits }).format(value);
538
+ var unitsOf = (format) => format === "bytes" ? BYTE_UNITS : TIME_UNITS;
539
+ function unitReached(units, value) {
540
+ return units.find(([, size]) => Math.abs(value) >= size) ?? units[units.length - 1];
541
+ }
542
+ function axisUnit(units, ticks) {
543
+ const largest = Math.max(0, ...ticks.map(Math.abs));
544
+ const exactIn = (size) => ticks.every((t) => Math.abs(t / size * 100 - Math.round(t / size * 100)) < 1e-6);
545
+ return units.find(([, size]) => largest / size >= 1 && exactIn(size)) ?? units[units.length - 1];
546
+ }
547
+ function valueAxisTicks(values) {
548
+ const finite = values.filter(Number.isFinite);
549
+ if (!finite.length) return [];
550
+ const lo = Math.min(0, ...finite);
551
+ const hi = Math.max(0, ...finite);
552
+ if (lo === hi) return [lo];
553
+ return getNiceTickValues([lo, hi], TICK_COUNT, true).map(Number);
554
+ }
555
+ function axisTickFormatter(values, format = "number") {
556
+ if (typeof format === "function") return format;
557
+ if (format === "percent") return (value) => exact((d) => new Intl.NumberFormat(formatLocale(), { style: "percent", maximumFractionDigits: d }).format(value / 100));
558
+ if (format === "milliseconds" || format === "bytes") {
559
+ const [unit, size] = axisUnit(unitsOf(format), valueAxisTicks(values));
560
+ return (value) => exact(unitFormat(unit, value / size));
561
+ }
562
+ const compact = (value) => exact((d) => new Intl.NumberFormat(formatLocale(), { notation: "compact", maximumFractionDigits: d }).format(value));
563
+ const plain = (value) => exact((d) => new Intl.NumberFormat(formatLocale(), { maximumFractionDigits: d }).format(value));
564
+ const largest = Math.max(0, ...values.filter(Number.isFinite).map(Math.abs));
565
+ return largest >= COMPACT_FROM ? compact : plain;
566
+ }
567
+ var COMPACT_FROM = 1e4;
568
+ function fullValueFormatter(format = "number") {
569
+ if (typeof format === "function") return format;
570
+ if (format === "number") return (value) => value.toLocaleString(formatLocale());
571
+ if (format === "percent") return (value) => exact((d) => new Intl.NumberFormat(formatLocale(), { style: "percent", maximumFractionDigits: d }).format(value / 100), 4);
572
+ return (value) => {
573
+ const [unit, size] = unitReached(unitsOf(format), value);
574
+ return exact(unitFormat(unit, value / size), 4);
575
+ };
576
+ }
577
+ function axisExtent(data, series) {
578
+ return data.flatMap((row) => {
579
+ const own = [];
580
+ const up = /* @__PURE__ */ new Map();
581
+ const down = /* @__PURE__ */ new Map();
582
+ for (const s of series) {
583
+ const raw = row[s.dataKey];
584
+ const v = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
585
+ if (!Number.isFinite(v)) continue;
586
+ if (s.stack == null) own.push(v);
587
+ else if (v >= 0) up.set(s.stack, (up.get(s.stack) ?? 0) + v);
588
+ else down.set(s.stack, (down.get(s.stack) ?? 0) + v);
589
+ }
590
+ return [...own, ...up.values(), ...down.values()];
591
+ });
592
+ }
593
+ function seriesValues(data, keys, stacked = false) {
594
+ return axisExtent(data, keys.map((dataKey) => ({ dataKey, stack: stacked ? "stack" : null })));
595
+ }
525
596
  var hasLabel = (label) => label != null && label !== "" && typeof label !== "number";
526
597
  var entryName = (entry, label) => !hasLabel(label) && typeof entry.payload?.name === "string" && entry.payload.name || entry.name;
527
- var entryValue = (entry) => typeof entry.value === "number" ? entry.value.toLocaleString() : entry.value;
528
- function tooltipAnnouncement(label, payload) {
598
+ var entryValue = (entry, format) => typeof entry.value === "number" ? format ? format(entry.value, entry.dataKey) : entry.value.toLocaleString(formatLocale()) : entry.value;
599
+ function tooltipAnnouncement(label, payload, format) {
529
600
  if (!payload?.length) return "";
530
- const values = payload.map((entry) => `${entryName(entry, label)} ${entryValue(entry)}`).join(", ");
601
+ const values = payload.map((entry) => `${entryName(entry, label)} ${entryValue(entry, format)}`).join(", ");
531
602
  return hasLabel(label) ? `${String(label)}: ${values}` : values;
532
603
  }
533
604
  function ChartTooltipContent({ active, payload, label }) {
@@ -535,7 +606,7 @@ function ChartTooltipContent({ active, payload, label }) {
535
606
  const borderSubtle = useResolvedToken("--ds-border-subtle");
536
607
  const textPrimary = useResolvedToken("--ds-text-primary");
537
608
  const textSecondary = useResolvedToken("--ds-text-secondary");
538
- const { live } = useContext(ChartFrameContext);
609
+ const { live, formatValue } = useContext(ChartFrameContext);
539
610
  const on = !!active && !!payload?.length;
540
611
  const showLabel = hasLabel(label);
541
612
  const box = on ? /* @__PURE__ */ jsxs(
@@ -563,7 +634,7 @@ function ChartTooltipContent({ active, payload, label }) {
563
634
  entryName(entry, label),
564
635
  ":"
565
636
  ] }),
566
- /* @__PURE__ */ jsx("span", { className: "tabular-nums", style: { color: textPrimary }, children: entryValue(entry) })
637
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums", style: { color: textPrimary }, children: entryValue(entry, formatValue) })
567
638
  ] }, i);
568
639
  })
569
640
  ]
@@ -572,7 +643,7 @@ function ChartTooltipContent({ active, payload, label }) {
572
643
  if (live) {
573
644
  return /* @__PURE__ */ jsxs(Fragment, { children: [
574
645
  box,
575
- createPortal(on ? tooltipAnnouncement(label, payload) : "", live)
646
+ createPortal(on ? tooltipAnnouncement(label, payload, formatValue) : "", live)
576
647
  ] });
577
648
  }
578
649
  return /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", children: box });
@@ -691,13 +762,10 @@ function useAxisMeasure(ref, enabled = true) {
691
762
  }, [ref, enabled]);
692
763
  return state;
693
764
  }
694
- function valueAxisWidth(values, measure) {
695
- const finite = values.filter(Number.isFinite);
696
- const max = finite.length ? Math.max(...finite.map(Math.abs)) : 0;
697
- const magnitude = max > 0 ? 10 ** Math.floor(Math.log10(max)) : 1;
698
- const top = Math.ceil(max / magnitude) * magnitude;
699
- const negative = finite.some((v) => v < 0) ? "-" : "";
700
- return Math.ceil(measure(`${negative}${top}`)) + 8;
765
+ function valueAxisWidth(values, measure, format = String) {
766
+ const ticks = valueAxisTicks(values);
767
+ if (!ticks.length) return Math.ceil(measure(format(0))) + 8;
768
+ return Math.ceil(Math.max(...ticks.map((t) => measure(format(t))))) + 8;
701
769
  }
702
770
  var SWITCH_HYSTERESIS = 32;
703
771
  function useSidewaysSwitch(enabled, names, m, axisWidth, sideMargins) {
@@ -795,18 +863,7 @@ function barShape(bars, index, stacked, radius, horizontal = false) {
795
863
  return Shape;
796
864
  }
797
865
  function valueExtent(data, bars, stacked) {
798
- return data.flatMap((row) => {
799
- const own = [];
800
- const stacks = /* @__PURE__ */ new Map();
801
- for (const bar of bars) {
802
- const v = Number(row[bar.dataKey]);
803
- if (!Number.isFinite(v)) continue;
804
- const stack = barStackOf(bar, stacked);
805
- if (stack == null) own.push(v);
806
- else stacks.set(stack, (stacks.get(stack) ?? 0) + v);
807
- }
808
- return [...own, ...stacks.values()];
809
- });
866
+ return axisExtent(data, bars.map((bar) => ({ dataKey: bar.dataKey, stack: barStackOf(bar, stacked) ?? null })));
810
867
  }
811
868
  var titleLine = (px) => Math.ceil(px * 1.5) + 4;
812
869
  var TITLE_LINE_CSS = "calc(1.5 * var(--ds-font-size-xs) + 4px)";
@@ -824,6 +881,7 @@ var BarChart = markChart(forwardRef(function BarChart2({
824
881
  showLegend,
825
882
  xAxisLabel,
826
883
  yAxisLabel,
884
+ valueFormat,
827
885
  animated,
828
886
  "aria-label": ariaLabel,
829
887
  className
@@ -833,9 +891,12 @@ var BarChart = markChart(forwardRef(function BarChart2({
833
891
  const kind = categoryKind2 ?? categoryKind((data ?? []).map((d) => d[xAxisKey]));
834
892
  const names = kind === "names";
835
893
  const measured = useAxisMeasure(wrapperRef, (data?.length ?? 0) > 0);
894
+ const values = useMemo(() => valueExtent(data ?? [], bars, stacked), [data, bars, stacked]);
895
+ const tickFormat = useMemo(() => axisTickFormatter(values, valueFormat), [values, valueFormat]);
896
+ const fullFormat = useMemo(() => fullValueFormatter(valueFormat), [valueFormat]);
836
897
  const axisWidth = useMemo(
837
- () => measured.measure ? valueAxisWidth(valueExtent(data ?? [], bars, stacked), measured.measure) : 0,
838
- [measured.measure, data, bars, stacked]
898
+ () => measured.measure ? valueAxisWidth(values, measured.measure, tickFormat) : 0,
899
+ [measured.measure, values, tickFormat]
839
900
  );
840
901
  const turned = useSidewaysSwitch(horizontal === void 0 && names, labels, measured, axisWidth, 8);
841
902
  const sideways = horizontal ?? turned;
@@ -879,6 +940,7 @@ var BarChart = markChart(forwardRef(function BarChart2({
879
940
  categoryAxis: sideways ? "y" : "x",
880
941
  sideways,
881
942
  axisTitle: topTitle,
943
+ formatValue: fullFormat,
882
944
  className,
883
945
  "aria-label": ariaLabel,
884
946
  children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
@@ -892,7 +954,7 @@ var BarChart = markChart(forwardRef(function BarChart2({
892
954
  children: [
893
955
  showGrid && /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: gridStroke, vertical: !sideways, horizontal: true }),
894
956
  sideways ? /* @__PURE__ */ jsxs(Fragment, { children: [
895
- /* @__PURE__ */ jsx(XAxis, { type: "number", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto", label: bottomLabel }),
957
+ /* @__PURE__ */ jsx(XAxis, { type: "number", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto", label: bottomLabel, tickFormatter: tickFormat }),
896
958
  /* @__PURE__ */ jsx(
897
959
  YAxis,
898
960
  {
@@ -921,7 +983,7 @@ var BarChart = markChart(forwardRef(function BarChart2({
921
983
  label: bottomLabel
922
984
  }
923
985
  ),
924
- /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false })
986
+ /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false, tickFormatter: tickFormat })
925
987
  ] }),
926
988
  showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}), cursor: { fill: "var(--ds-bg-muted)", opacity: 0.5 } }),
927
989
  legendVisible && /* @__PURE__ */ jsx(ChartLegend, { order: bars.map((b) => b.dataKey) }),
@@ -959,11 +1021,15 @@ var LineChart = markChart(forwardRef(function LineChart2({
959
1021
  showLegend,
960
1022
  xAxisLabel,
961
1023
  yAxisLabel,
1024
+ valueFormat,
962
1025
  animated,
963
1026
  "aria-label": ariaLabel,
964
1027
  className
965
1028
  }, ref) {
966
1029
  const wrapperRef = useRef(null);
1030
+ const values = useMemo(() => seriesValues(data ?? [], lines.map((s) => s.dataKey), false), [data, lines]);
1031
+ const tickFormat = useMemo(() => axisTickFormatter(values, valueFormat), [values, valueFormat]);
1032
+ const fullFormat = useMemo(() => fullValueFormatter(valueFormat), [valueFormat]);
967
1033
  const xTicks = useCategoryTicks(data, xAxisKey, wrapperRef, xAxisInterval, "scale");
968
1034
  const measured = useAxisMeasure(wrapperRef, !!yAxisLabel && (data?.length ?? 0) > 0);
969
1035
  const colors = useChartColors(lines.length, false);
@@ -985,6 +1051,7 @@ var LineChart = markChart(forwardRef(function LineChart2({
985
1051
  categories: data.length,
986
1052
  categoryAxis: "x",
987
1053
  axisTitle: yAxisLabel,
1054
+ formatValue: fullFormat,
988
1055
  className,
989
1056
  "aria-label": ariaLabel,
990
1057
  children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(LineChart$1, { data, margin: { top, right: xTicks.endMargin, bottom: 4, left: 4 }, accessibilityLayer: true, children: [
@@ -1003,7 +1070,7 @@ var LineChart = markChart(forwardRef(function LineChart2({
1003
1070
  label: xAxisLabel ? { value: xAxisLabel, position: "insideBottom", offset: -2, style: axisLabelStyle } : void 0
1004
1071
  }
1005
1072
  ),
1006
- /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false }),
1073
+ /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false, tickFormatter: tickFormat }),
1007
1074
  showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
1008
1075
  legendVisible && /* @__PURE__ */ jsx(ChartLegend, { order: lines.map((l) => l.dataKey) }),
1009
1076
  lines.map((line, i) => /* @__PURE__ */ jsx(
@@ -1039,11 +1106,15 @@ var AreaChart = markChart(forwardRef(function AreaChart2({
1039
1106
  gradient = true,
1040
1107
  xAxisLabel,
1041
1108
  yAxisLabel,
1109
+ valueFormat,
1042
1110
  animated,
1043
1111
  "aria-label": ariaLabel,
1044
1112
  className
1045
1113
  }, ref) {
1046
1114
  const wrapperRef = useRef(null);
1115
+ const values = useMemo(() => seriesValues(data ?? [], areas.map((s) => s.dataKey), stacked), [data, areas, stacked]);
1116
+ const tickFormat = useMemo(() => axisTickFormatter(values, valueFormat), [values, valueFormat]);
1117
+ const fullFormat = useMemo(() => fullValueFormatter(valueFormat), [valueFormat]);
1047
1118
  const xTicks = useCategoryTicks(data, xAxisKey, wrapperRef, xAxisInterval, "scale");
1048
1119
  const measured = useAxisMeasure(wrapperRef, !!yAxisLabel && (data?.length ?? 0) > 0);
1049
1120
  const instanceId = useId();
@@ -1067,6 +1138,7 @@ var AreaChart = markChart(forwardRef(function AreaChart2({
1067
1138
  categories: data.length,
1068
1139
  categoryAxis: "x",
1069
1140
  axisTitle: yAxisLabel,
1141
+ formatValue: fullFormat,
1070
1142
  className,
1071
1143
  "aria-label": ariaLabel,
1072
1144
  children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(AreaChart$1, { data, margin: { top, right: xTicks.endMargin, bottom: 4, left: 4 }, accessibilityLayer: true, children: [
@@ -1089,7 +1161,7 @@ var AreaChart = markChart(forwardRef(function AreaChart2({
1089
1161
  label: xAxisLabel ? { value: xAxisLabel, position: "insideBottom", offset: -2, style: axisLabelStyle } : void 0
1090
1162
  }
1091
1163
  ),
1092
- /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false }),
1164
+ /* @__PURE__ */ jsx(YAxis, { width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false, tickFormatter: tickFormat }),
1093
1165
  showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
1094
1166
  legendVisible && /* @__PURE__ */ jsx(ChartLegend, { order: areas.map((a) => a.dataKey) }),
1095
1167
  areas.map((area, i) => /* @__PURE__ */ jsx(
@@ -1164,6 +1236,8 @@ var CompositeChart = markChart(forwardRef(function CompositeChart2({
1164
1236
  showLegend = true,
1165
1237
  xAxisLabel,
1166
1238
  yAxisLabel,
1239
+ valueFormat,
1240
+ lineValueFormat = valueFormat,
1167
1241
  animated,
1168
1242
  "aria-label": ariaLabel,
1169
1243
  className
@@ -1173,23 +1247,26 @@ var CompositeChart = markChart(forwardRef(function CompositeChart2({
1173
1247
  const kind = categoryKind2 ?? categoryKind((data ?? []).map((d) => d[xAxisKey]));
1174
1248
  const names = kind === "names";
1175
1249
  const measured = useAxisMeasure(wrapperRef, (data?.length ?? 0) > 0);
1250
+ const [values, lineValues] = useMemo(() => {
1251
+ const values2 = axisExtent(data ?? [], [
1252
+ ...bars.map((bar) => ({ dataKey: bar.dataKey, stack: barStackOf(bar, stacked) ?? null })),
1253
+ ...dualAxis ? [] : lines.map((l) => ({ dataKey: l.dataKey, stack: null }))
1254
+ ]);
1255
+ const lineValues2 = (data ?? []).flatMap((row) => lines.map((l) => Number(row[l.dataKey])));
1256
+ return [values2, lineValues2];
1257
+ }, [data, bars, lines, stacked, dualAxis]);
1258
+ const tickFormat = useMemo(() => axisTickFormatter(values, valueFormat), [values, valueFormat]);
1259
+ const lineTickFormat = useMemo(() => axisTickFormatter(lineValues, lineValueFormat), [lineValues, lineValueFormat]);
1260
+ const fullFormat = useMemo(() => {
1261
+ const bar = fullValueFormatter(valueFormat);
1262
+ const line = fullValueFormatter(dualAxis ? lineValueFormat : valueFormat);
1263
+ const lineKeys = new Set(lines.map((l) => l.dataKey));
1264
+ return (value, dataKey) => dataKey && lineKeys.has(dataKey) ? line(value) : bar(value);
1265
+ }, [valueFormat, lineValueFormat, dualAxis, lines]);
1176
1266
  const axisWidth = useMemo(() => {
1177
1267
  if (!measured.measure) return 0;
1178
- const values = (data ?? []).flatMap((row) => {
1179
- const stacks = /* @__PURE__ */ new Map();
1180
- const own = [];
1181
- for (const bar of bars) {
1182
- const v = Number(row[bar.dataKey]);
1183
- if (!Number.isFinite(v)) continue;
1184
- const stack = barStackOf(bar, stacked);
1185
- if (stack == null) own.push(v);
1186
- else stacks.set(stack, (stacks.get(stack) ?? 0) + v);
1187
- }
1188
- return [...own, ...stacks.values(), ...dualAxis ? [] : lines.map((l) => Number(row[l.dataKey]))];
1189
- });
1190
- const lineValues = (data ?? []).flatMap((row) => lines.map((l) => Number(row[l.dataKey])));
1191
- return valueAxisWidth(values, measured.measure) + (dualAxis ? valueAxisWidth(lineValues, measured.measure) : 0);
1192
- }, [measured.measure, data, bars, lines, stacked, dualAxis]);
1268
+ return valueAxisWidth(values, measured.measure, tickFormat) + (dualAxis ? valueAxisWidth(lineValues, measured.measure, lineTickFormat) : 0);
1269
+ }, [measured.measure, values, lineValues, tickFormat, lineTickFormat, dualAxis]);
1193
1270
  const turned = useSidewaysSwitch(horizontal === void 0 && names, labels, measured, axisWidth, 8);
1194
1271
  const sideways = horizontal ?? turned;
1195
1272
  const xTicks = useCategoryTicks(data, xAxisKey, wrapperRef, xAxisInterval, sideways ? "names" : kind);
@@ -1233,6 +1310,7 @@ var CompositeChart = markChart(forwardRef(function CompositeChart2({
1233
1310
  categoryAxis: sideways ? "y" : "x",
1234
1311
  sideways,
1235
1312
  axisTitle: topTitle,
1313
+ formatValue: fullFormat,
1236
1314
  className,
1237
1315
  "aria-label": ariaLabel,
1238
1316
  children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
@@ -1246,8 +1324,8 @@ var CompositeChart = markChart(forwardRef(function CompositeChart2({
1246
1324
  children: [
1247
1325
  showGrid && /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: gridStroke, vertical: !sideways, horizontal: true }),
1248
1326
  sideways ? /* @__PURE__ */ jsxs(Fragment, { children: [
1249
- /* @__PURE__ */ jsx(XAxis, { xAxisId: "left", type: "number", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto", label: bottomLabel }),
1250
- dualAxis && /* @__PURE__ */ jsx(XAxis, { xAxisId: "right", type: "number", orientation: "top", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto" }),
1327
+ /* @__PURE__ */ jsx(XAxis, { xAxisId: "left", type: "number", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto", label: bottomLabel, tickFormatter: tickFormat }),
1328
+ dualAxis && /* @__PURE__ */ jsx(XAxis, { xAxisId: "right", type: "number", orientation: "top", ...axisStyle.tick, axisLine: false, tickLine: false, height: "auto", tickFormatter: lineTickFormat }),
1251
1329
  /* @__PURE__ */ jsx(
1252
1330
  YAxis,
1253
1331
  {
@@ -1276,8 +1354,8 @@ var CompositeChart = markChart(forwardRef(function CompositeChart2({
1276
1354
  label: bottomLabel
1277
1355
  }
1278
1356
  ),
1279
- /* @__PURE__ */ jsx(YAxis, { yAxisId: "left", width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false }),
1280
- dualAxis && /* @__PURE__ */ jsx(YAxis, { yAxisId: "right", orientation: "right", width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false })
1357
+ /* @__PURE__ */ jsx(YAxis, { yAxisId: "left", width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false, tickFormatter: tickFormat }),
1358
+ dualAxis && /* @__PURE__ */ jsx(YAxis, { yAxisId: "right", orientation: "right", width: "auto", ...axisStyle.tick, axisLine: false, tickLine: false, tickFormatter: lineTickFormat })
1281
1359
  ] }),
1282
1360
  showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) }),
1283
1361
  showLegend && /* @__PURE__ */ jsx(ChartLegend, { order: [...bars.map((b) => b.dataKey), ...lines.map((l) => l.dataKey)] }),
@@ -1326,11 +1404,23 @@ var ScatterChart = markChart(forwardRef(function ScatterChart2({
1326
1404
  showGrid = true,
1327
1405
  showTooltip = true,
1328
1406
  showLegend,
1407
+ valueFormat,
1408
+ xValueFormat,
1329
1409
  animated,
1330
1410
  "aria-label": ariaLabel,
1331
1411
  className
1332
1412
  }, ref) {
1333
1413
  const wrapperRef = useRef(null);
1414
+ const [xTickFormat, yTickFormat, fullFormat] = useMemo(() => {
1415
+ const points = (data ?? []).flatMap((s) => s.points);
1416
+ const x = fullValueFormatter(xValueFormat);
1417
+ const y = fullValueFormatter(valueFormat);
1418
+ return [
1419
+ axisTickFormatter(points.map((p) => p.x), xValueFormat),
1420
+ axisTickFormatter(points.map((p) => p.y), valueFormat),
1421
+ (value, dataKey) => dataKey === "x" ? x(value) : dataKey === "y" ? y(value) : value.toLocaleString(formatLocale())
1422
+ ];
1423
+ }, [data, valueFormat, xValueFormat]);
1334
1424
  const measured = useAxisMeasure(wrapperRef, !!yLabel && (data?.length ?? 0) > 0);
1335
1425
  const colors = useChartColors(data.length, false);
1336
1426
  const gridStroke = useGridStroke();
@@ -1347,6 +1437,7 @@ var ScatterChart = markChart(forwardRef(function ScatterChart2({
1347
1437
  size: { model: "ratio" },
1348
1438
  chart: "scatter",
1349
1439
  axisTitle: yLabel,
1440
+ formatValue: fullFormat,
1350
1441
  className,
1351
1442
  "aria-label": ariaLabel,
1352
1443
  children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(
@@ -1365,6 +1456,7 @@ var ScatterChart = markChart(forwardRef(function ScatterChart2({
1365
1456
  ...axisStyle.tick,
1366
1457
  axisLine: false,
1367
1458
  tickLine: false,
1459
+ tickFormatter: xTickFormat,
1368
1460
  label: xLabel ? { value: xLabel, position: "bottom", offset: 0, style: { ...axisLabelStyle, textAnchor: "middle" } } : void 0
1369
1461
  }
1370
1462
  ),
@@ -1377,7 +1469,8 @@ var ScatterChart = markChart(forwardRef(function ScatterChart2({
1377
1469
  width: "auto",
1378
1470
  ...axisStyle.tick,
1379
1471
  axisLine: false,
1380
- tickLine: false
1472
+ tickLine: false,
1473
+ tickFormatter: yTickFormat
1381
1474
  }
1382
1475
  ),
1383
1476
  /* @__PURE__ */ jsx(ZAxis, { type: "number", dataKey: "z", range: [40, 400] }),
@@ -1409,6 +1502,7 @@ var RadarChart = markChart(forwardRef(function RadarChart2({
1409
1502
  showTooltip = true,
1410
1503
  showLegend,
1411
1504
  animated,
1505
+ valueFormat = "number",
1412
1506
  "aria-label": ariaLabel,
1413
1507
  className
1414
1508
  }, ref) {
@@ -1416,8 +1510,11 @@ var RadarChart = markChart(forwardRef(function RadarChart2({
1416
1510
  const softColors = useChartColors(dataKeys.length, true);
1417
1511
  const isAnimated = useChartAnimation(animated);
1418
1512
  const legendVisible = showLegend ?? dataKeys.length >= 2;
1513
+ const values = useMemo(() => seriesValues(data ?? [], dataKeys.map((dk) => dk.key)), [data, dataKeys]);
1514
+ const tickFormat = useMemo(() => axisTickFormatter(values, valueFormat), [values, valueFormat]);
1515
+ const fullFormat = useMemo(() => fullValueFormatter(valueFormat), [valueFormat]);
1419
1516
  if (!data?.length) return null;
1420
- return /* @__PURE__ */ jsx(ChartWrapper, { ref, height, size: { model: "square" }, chart: "radar", className, "aria-label": ariaLabel, children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(RadarChart$1, { data, cx: "50%", cy: "50%", outerRadius: "75%", accessibilityLayer: true, children: [
1517
+ return /* @__PURE__ */ jsx(ChartWrapper, { ref, height, size: { model: "square" }, chart: "radar", className, "aria-label": ariaLabel, formatValue: fullFormat, children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsxs(RadarChart$1, { data, cx: "50%", cy: "50%", outerRadius: "75%", accessibilityLayer: true, children: [
1421
1518
  /* @__PURE__ */ jsx(PolarGrid, { stroke: "var(--ds-border-subtle)" }),
1422
1519
  /* @__PURE__ */ jsx(
1423
1520
  PolarAngleAxis,
@@ -1430,6 +1527,7 @@ var RadarChart = markChart(forwardRef(function RadarChart2({
1430
1527
  PolarRadiusAxis,
1431
1528
  {
1432
1529
  tick: { fontSize: "var(--ds-font-size-xs)", fontFamily: "var(--ds-font-sans)", fill: "var(--ds-text-muted)" },
1530
+ tickFormatter: tickFormat,
1433
1531
  axisLine: false
1434
1532
  }
1435
1533
  ),
@@ -1527,19 +1625,139 @@ var FunnelChart = markChart(forwardRef(function FunnelChart2({
1527
1625
  showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) })
1528
1626
  ] }) }) });
1529
1627
  }));
1530
- function contrastColor(hex) {
1531
- const c = hex.replace("#", "");
1532
- if (c.length < 6) return "#ffffff";
1533
- const r = parseInt(c.substring(0, 2), 16);
1534
- const g = parseInt(c.substring(2, 4), 16);
1535
- const b = parseInt(c.substring(4, 6), 16);
1628
+
1629
+ // ../../showcase/src/lib/token-algorithms.ts
1630
+ function oklchCss(colour) {
1631
+ return `oklch(${colour.L.toFixed(3)} ${colour.C.toFixed(4)} ${colour.H})`;
1632
+ }
1633
+ function parseOklch(value) {
1634
+ const m = value.trim().match(/^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*(?:\/\s*[\d.%]+\s*)?\)$/i);
1635
+ if (!m) return null;
1636
+ const L = m[2] ? parseFloat(m[1]) / 100 : parseFloat(m[1]);
1637
+ return { L, C: parseFloat(m[3]), H: parseFloat(m[4]) };
1638
+ }
1639
+ function oklchToLinearSrgb({ L, C, H }) {
1640
+ const h = H * Math.PI / 180;
1641
+ const a = C * Math.cos(h);
1642
+ const b = C * Math.sin(h);
1643
+ const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
1644
+ const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
1645
+ const s_ = L - 0.0894841775 * a - 1.291485548 * b;
1646
+ const l = l_ * l_ * l_;
1647
+ const m = m_ * m_ * m_;
1648
+ const s = s_ * s_ * s_;
1649
+ return [
1650
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
1651
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
1652
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
1653
+ ];
1654
+ }
1655
+ function oklchToLinearSrgbClamped(colour) {
1656
+ return oklchToLinearSrgb(colour).map((v) => Math.min(1, Math.max(0, v)));
1657
+ }
1658
+ var gammaEncode = (v) => v <= 31308e-7 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
1659
+ var gammaDecode = (v) => v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
1660
+ function oklchToSrgb(colour) {
1661
+ return oklchToLinearSrgbClamped(colour).map(gammaEncode);
1662
+ }
1663
+ var ROUNDING_WINDOW = 0.25;
1664
+ function srgbLuminanceRange(encoded) {
1665
+ let lo = 0;
1666
+ let hi = 0;
1667
+ encoded.forEach((v, i) => {
1668
+ const x = Math.min(1, Math.max(0, v)) * 255;
1669
+ const below = Math.floor(x);
1670
+ const [a, b] = Math.abs(x - below - 0.5) <= ROUNDING_WINDOW ? [below, Math.min(255, below + 1)] : [Math.round(x), Math.round(x)];
1671
+ const weight = [0.2126, 0.7152, 0.0722][i];
1672
+ lo += weight * gammaDecode(a / 255);
1673
+ hi += weight * gammaDecode(b / 255);
1674
+ });
1675
+ return [lo, hi];
1676
+ }
1677
+ function luminanceRange(colour) {
1678
+ return srgbLuminanceRange(oklchToSrgb(colour));
1679
+ }
1680
+ function worstContrastOf([t0, t1], [f0, f1]) {
1681
+ if (t0 <= f1 && f0 <= t1) return 1;
1682
+ return t0 > f1 ? contrastRatio(t0, f1) : contrastRatio(t1, f0);
1683
+ }
1684
+ function contrastRatio(lumA, lumB) {
1685
+ const lighter = Math.max(lumA, lumB);
1686
+ const darker = Math.min(lumA, lumB);
1687
+ return (lighter + 0.05) / (darker + 0.05);
1688
+ }
1689
+ var WCAG_AA_TEXT = 4.5;
1690
+ var ON_FILL_WHITE = "oklch(1 0 0)";
1691
+ var ON_FILL_DARK = "var(--ds-neutral-950)";
1692
+ var DARK_TEXT_CANDIDATE = { L: 0.13, C: 2e-3, H: 0 };
1693
+ var ON_FILL_TINT_CHROMA = 0.1;
1694
+ var ON_FILL_TINT_TARGET = 5;
1695
+ var TINT_L_MAX = 0.45;
1696
+ var TINT_L_MIN = 0.1;
1697
+ var TINT_L_STEP = 0.01;
1698
+ var WHITE_RANGE = [1, 1];
1699
+ var DARK_RANGE = luminanceRange(DARK_TEXT_CANDIDATE);
1700
+ function minContrast(text, fills) {
1701
+ let min = Infinity;
1702
+ for (const f of fills) min = Math.min(min, worstContrastOf(text, luminanceRange(f)));
1703
+ return min;
1704
+ }
1705
+ function onFillDarkTint(fill, ...moreFills) {
1706
+ const fills = [fill, ...moreFills];
1707
+ const H = fill.H;
1708
+ const chroma = Math.min(ON_FILL_TINT_CHROMA, fill.C);
1709
+ for (const target of [ON_FILL_TINT_TARGET, WCAG_AA_TEXT]) {
1710
+ for (const C of [chroma, chroma / 2, chroma / 4]) {
1711
+ for (let L = TINT_L_MAX; L >= TINT_L_MIN - 1e-9; L -= TINT_L_STEP) {
1712
+ const candidate = { L: +L.toFixed(2), C: +C.toFixed(4), H };
1713
+ if (minContrast(luminanceRange(candidate), fills) >= target) return candidate;
1714
+ }
1715
+ }
1716
+ }
1717
+ return null;
1718
+ }
1719
+ function onFillTextValue(fill, ...moreFills) {
1720
+ const fills = [fill, ...moreFills];
1721
+ const whiteMin = minContrast(WHITE_RANGE, fills);
1722
+ if (whiteMin >= WCAG_AA_TEXT) return ON_FILL_WHITE;
1723
+ const tint = onFillDarkTint(fill, ...moreFills);
1724
+ if (tint) return oklchCss(tint);
1725
+ return minContrast(DARK_RANGE, fills) >= whiteMin ? ON_FILL_DARK : ON_FILL_WHITE;
1726
+ }
1727
+ var LABEL_INSET = 4;
1728
+ function treemapLabelLines(width, height, metrics) {
1729
+ if (width - 2 * LABEL_INSET < metrics.fontSize * 3) return 0;
1730
+ return Math.max(0, Math.floor((height - 2 * LABEL_INSET) / metrics.lineHeight));
1731
+ }
1732
+ var computedColors = /* @__PURE__ */ new Map();
1733
+ function computedColor(css) {
1734
+ if (typeof document === "undefined") return css;
1735
+ let value = computedColors.get(css);
1736
+ if (value === void 0) {
1737
+ const probe = document.createElement("span");
1738
+ probe.style.color = css;
1739
+ document.body.appendChild(probe);
1740
+ value = getComputedStyle(probe).color;
1741
+ probe.remove();
1742
+ computedColors.set(css, value);
1743
+ }
1744
+ return value;
1745
+ }
1746
+ function labelColorOn(fill) {
1747
+ const parsed = parseOklch(fill) ?? parseOklch(computedColor(fill));
1748
+ return parsed ? onFillTextValue(parsed) : contrastColor(computedColor(fill));
1749
+ }
1750
+ function contrastColor(color) {
1751
+ const rgb = /^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/.exec(color);
1752
+ const c = color.replace("#", "");
1753
+ const [r, g, b] = rgb ? [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])] : c.length >= 6 ? [parseInt(c.substring(0, 2), 16), parseInt(c.substring(2, 4), 16), parseInt(c.substring(4, 6), 16)] : [0, 0, 0];
1536
1754
  const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
1537
1755
  return luminance > 0.55 ? "#1f2937" : "#ffffff";
1538
1756
  }
1539
- function TreemapContent({ x = 0, y = 0, width = 0, height: h = 0, name, depth, colors, radius, index = 0 }) {
1757
+ function TreemapContent({ x = 0, y = 0, width = 0, height: h = 0, name, depth, colors, radius, index = 0, metrics }) {
1540
1758
  const fill = colors[index % colors.length];
1541
- const showLabel = width > 40 && h > 20;
1542
- const labelColor = contrastColor(fill);
1759
+ const lines = metrics && name ? treemapLabelLines(width, h, metrics) : 0;
1760
+ const labelColor = labelColorOn(fill);
1543
1761
  return /* @__PURE__ */ jsxs("g", { children: [
1544
1762
  /* @__PURE__ */ jsx(
1545
1763
  "rect",
@@ -1555,21 +1773,15 @@ function TreemapContent({ x = 0, y = 0, width = 0, height: h = 0, name, depth, c
1555
1773
  style: { opacity: depth === 1 ? 1 : 0.85 }
1556
1774
  }
1557
1775
  ),
1558
- showLabel && /* @__PURE__ */ jsx(
1559
- "text",
1776
+ lines > 0 && /* @__PURE__ */ jsx("foreignObject", { x, y, width, height: h, style: { pointerEvents: "none" }, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center overflow-hidden text-center", style: { padding: LABEL_INSET }, children: /* @__PURE__ */ jsx(
1777
+ "span",
1560
1778
  {
1561
- x: x + width / 2,
1562
- y: y + h / 2,
1563
- textAnchor: "middle",
1564
- dominantBaseline: "central",
1565
- fill: labelColor,
1566
- stroke: "none",
1567
- fontSize: "var(--ds-font-size-xs)",
1568
- fontFamily: "var(--ds-font-sans)",
1569
- style: { pointerEvents: "none" },
1779
+ "data-treemap-label": "",
1780
+ className: LABEL_TEXT,
1781
+ style: { color: labelColor, display: "-webkit-box", WebkitBoxOrient: "vertical", WebkitLineClamp: lines, overflow: "hidden", overflowWrap: "anywhere", hyphens: "auto" },
1570
1782
  children: name
1571
1783
  }
1572
- )
1784
+ ) }) })
1573
1785
  ] });
1574
1786
  }
1575
1787
  function addFillToNodes(nodes, colors, counter = { i: 0 }) {
@@ -1582,6 +1794,21 @@ function addFillToNodes(nodes, colors, counter = { i: 0 }) {
1582
1794
  return { ...node, fill };
1583
1795
  });
1584
1796
  }
1797
+ var LABEL_TEXT = "text-xs leading-tight font-[family-name:var(--ds-font-sans)]";
1798
+ function useLabelMetrics() {
1799
+ const probe = useRef(null);
1800
+ const [metrics, setMetrics] = useState(null);
1801
+ useLayoutEffect(() => {
1802
+ const el = probe.current;
1803
+ if (!el) return;
1804
+ const cs = getComputedStyle(el);
1805
+ const fontSize = parseFloat(cs.fontSize);
1806
+ const lineHeight = parseFloat(cs.lineHeight) || el.getBoundingClientRect().height;
1807
+ if (!(fontSize > 0) || !(lineHeight > 0)) return;
1808
+ if (!metrics || metrics.fontSize !== fontSize || metrics.lineHeight !== lineHeight) setMetrics({ fontSize, lineHeight });
1809
+ });
1810
+ return [probe, metrics];
1811
+ }
1585
1812
  var TreemapChart = markChart(forwardRef(function TreemapChart2({
1586
1813
  data,
1587
1814
  height = "auto",
@@ -1593,21 +1820,25 @@ var TreemapChart = markChart(forwardRef(function TreemapChart2({
1593
1820
  const colors = useChartColors(6, false);
1594
1821
  const isAnimated = useChartAnimation(animated);
1595
1822
  const radius = useRadius();
1823
+ const [probe, metrics] = useLabelMetrics();
1596
1824
  const chartData = addFillToNodes(data, colors);
1597
1825
  if (!data?.length) return null;
1598
- return /* @__PURE__ */ jsx(ChartWrapper, { ref, height, size: { model: "ratio" }, chart: "treemap", className, "aria-label": ariaLabel, children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsx(
1599
- Treemap,
1600
- {
1601
- data: chartData,
1602
- dataKey: "value",
1603
- nameKey: "name",
1604
- aspectRatio: 4 / 3,
1605
- stroke: "var(--ds-bg-surface)",
1606
- isAnimationActive: isAnimated,
1607
- content: /* @__PURE__ */ jsx(TreemapContent, { colors, radius }),
1608
- children: showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) })
1609
- }
1610
- ) }) });
1826
+ return /* @__PURE__ */ jsxs(ChartWrapper, { ref, height, size: { model: "ratio" }, chart: "treemap", className, "aria-label": ariaLabel, children: [
1827
+ /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: /* @__PURE__ */ jsx(
1828
+ Treemap,
1829
+ {
1830
+ data: chartData,
1831
+ dataKey: "value",
1832
+ nameKey: "name",
1833
+ aspectRatio: 4 / 3,
1834
+ stroke: "var(--ds-bg-surface)",
1835
+ isAnimationActive: isAnimated,
1836
+ content: /* @__PURE__ */ jsx(TreemapContent, { colors, radius, metrics }),
1837
+ children: showTooltip && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, {}) })
1838
+ }
1839
+ ) }),
1840
+ /* @__PURE__ */ jsx("span", { ref: probe, "aria-hidden": true, className: LABEL_TEXT, style: { position: "absolute", visibility: "hidden", pointerEvents: "none" }, children: "M" })
1841
+ ] });
1611
1842
  }));
1612
1843
  var SankeyChart = markChart(forwardRef(function SankeyChart2({
1613
1844
  data,