@automattic/charts 4.14.0 → 4.15.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 (46) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/TOKENS.md +1 -1
  3. package/dist/index.cjs +1249 -325
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.css +31 -0
  6. package/dist/index.d.cts +41 -7
  7. package/dist/index.d.ts +41 -7
  8. package/dist/index.js +964 -325
  9. package/dist/index.js.map +1 -1
  10. package/package.json +9 -8
  11. package/src/charts/area-chart/area-chart.tsx +29 -20
  12. package/src/charts/area-chart/types.ts +3 -1
  13. package/src/charts/bar-chart/bar-chart.module.scss +38 -0
  14. package/src/charts/bar-chart/bar-chart.tsx +159 -56
  15. package/src/charts/bar-chart/private/band-tooltip.tsx +40 -5
  16. package/src/charts/bar-chart/private/bar-layer.tsx +66 -13
  17. package/src/charts/bar-chart/private/category.ts +25 -0
  18. package/src/charts/bar-chart/private/comparison-bars-geometry.ts +13 -1
  19. package/src/charts/bar-chart/private/index.ts +3 -1
  20. package/src/charts/bar-chart/private/selected-bar-ring.tsx +17 -6
  21. package/src/charts/bar-chart/private/stack-layout.ts +99 -0
  22. package/src/charts/bar-chart/private/stacked-bar-series.tsx +145 -0
  23. package/src/charts/bar-chart/private/test/stack-layout.test.ts +81 -0
  24. package/src/charts/bar-chart/private/test/value-domain.test.ts +10 -0
  25. package/src/charts/bar-chart/private/use-bar-chart-options.ts +35 -11
  26. package/src/charts/bar-chart/private/{use-overlap-slots.ts → use-bar-slots.ts} +36 -38
  27. package/src/charts/bar-chart/private/use-bar-stops.ts +19 -19
  28. package/src/charts/bar-chart/private/value-domain.ts +10 -8
  29. package/src/charts/bar-chart/test/bar-chart-stacked.test.tsx +546 -0
  30. package/src/charts/bar-chart/test/bar-chart.test.tsx +75 -0
  31. package/src/charts/bar-chart/test/use-bar-legend-items.test.tsx +18 -0
  32. package/src/charts/bar-chart/types.ts +3 -1
  33. package/src/charts/bar-chart/use-bar-colors.ts +12 -0
  34. package/src/charts/bar-chart/use-bar-legend-items.ts +4 -2
  35. package/src/charts/bar-list-chart/bar-list-chart.tsx +2 -0
  36. package/src/charts/line-chart/line-chart.tsx +55 -26
  37. package/src/charts/line-chart/test/line-chart.test.tsx +86 -0
  38. package/src/charts/line-chart/types.ts +3 -1
  39. package/src/charts/private/test/compact-when-short.test.tsx +170 -0
  40. package/src/charts/private/test/tick-decimals.test.tsx +95 -0
  41. package/src/charts/private/tick-decimals.tsx +132 -0
  42. package/src/charts/private/use-compact-when-short.ts +18 -0
  43. package/src/providers/chart-context/themes.ts +4 -0
  44. package/src/types.ts +35 -2
  45. package/src/charts/private/test/whole-number-ticks.test.tsx +0 -57
  46. package/src/charts/private/whole-number-ticks.tsx +0 -79
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ import { bisector } from "@visx/vendor/d3-array";
25
25
  import { PatternCircles, PatternHexagons, PatternLines, PatternWaves } from "@visx/pattern";
26
26
  import { Chart } from "react-google-charts";
27
27
  import DOMPurify from "dompurify";
28
+ import { __assign } from "tslib";
28
29
  import { Icon, chevronRight } from "@wordpress/icons";
29
30
  import { arc, pie } from "@visx/shape";
30
31
  // \0rolldown/runtime.js
@@ -1280,6 +1281,15 @@ const defaultTheme = {
1280
1281
  },
1281
1282
  strokeWidth: 1.5
1282
1283
  },
1284
+ compactWhenShort: {
1285
+ below: 140,
1286
+ margin: {
1287
+ top: 2,
1288
+ right: 2,
1289
+ bottom: 2,
1290
+ left: 2
1291
+ }
1292
+ },
1283
1293
  heatmapChart: {
1284
1294
  compactCellGap: 2,
1285
1295
  compactCellSize: 11,
@@ -3555,6 +3565,89 @@ const getAllHiddenMessage = (interactive, itemType) => {
3555
3565
  if (interactive) return _x("All series are hidden. Click legend items to show data.", "chart empty state: interactive series", "jetpack-charts");
3556
3566
  return _x("All series are hidden.", "chart empty state: series", "jetpack-charts");
3557
3567
  };
3568
+ // src/charts/private/tick-decimals.tsx
3569
+ /**
3570
+ * Whether every reading in the series is a whole number.
3571
+ *
3572
+ * @param series - The series visx renders.
3573
+ * @return True when at least one reading exists and none has a fraction.
3574
+ */
3575
+ const hasOnlyWholeNumbers = (series) => {
3576
+ let sawReading = false;
3577
+ for (const { data } of series) for (const point of data) {
3578
+ const value = point?.value;
3579
+ if (!isReading(value)) continue;
3580
+ if (!Number.isInteger(value)) return false;
3581
+ sawReading = true;
3582
+ }
3583
+ return sawReading;
3584
+ };
3585
+ const EPSILON = 1e-12;
3586
+ const tolerance = (scaled) => EPSILON * Math.max(1, Math.abs(scaled));
3587
+ const isValidDecimals = (decimals) => Number.isInteger(decimals) && decimals >= 0;
3588
+ const isOnDecimals = (value, decimals) => {
3589
+ const scaled = value * 10 ** decimals;
3590
+ return Math.abs(scaled - Math.round(scaled)) < tolerance(scaled);
3591
+ };
3592
+ /**
3593
+ * The scale's ticks with those finer than `decimals` places dropped.
3594
+ *
3595
+ * d3 steps by 1, 2 or 5 times a power of ten, so every multiple of 10^-decimals inside the domain is one of its ticks.
3596
+ *
3597
+ * @param scale - The value scale visx built.
3598
+ * @param count - Ticks to ask the scale for; undefined uses the scale's own default, as visx does.
3599
+ * @param decimals - Decimal places a tick may carry; 0 keeps whole numbers.
3600
+ * @return The kept ticks, or undefined when visx's own ticks need no change.
3601
+ */
3602
+ const getTickDecimalValues = (scale, count, decimals = 0) => {
3603
+ const ticks = scale?.ticks?.(count);
3604
+ if (!ticks?.every((tick) => typeof tick === "number")) return;
3605
+ const kept = ticks.filter((tick) => isOnDecimals(tick, decimals));
3606
+ return kept.length > 1 && kept.length < ticks.length ? kept : void 0;
3607
+ };
3608
+ /**
3609
+ * A value domain widened to the nearest `decimals` steps when fewer than two fit inside it, so the axis shows at least two ticks.
3610
+ *
3611
+ * @param domain - The domain the chart would scale to.
3612
+ * @param decimals - The axis's `tickDecimals`.
3613
+ * @return The widened domain, or undefined when `domain` needs no change.
3614
+ */
3615
+ const getTickDecimalsDomain = (domain, decimals) => {
3616
+ if (!domain || !isValidDecimals(decimals)) return;
3617
+ const scale = 10 ** decimals;
3618
+ const low = domain[0] * scale;
3619
+ const high = domain[1] * scale;
3620
+ if (Math.floor(high + tolerance(high)) - Math.ceil(low - tolerance(low)) >= 1) return;
3621
+ const floor = Math.floor(low + tolerance(low));
3622
+ const ceil = Math.max(Math.ceil(high - tolerance(high)), floor + 1);
3623
+ return [floor / scale, ceil / scale];
3624
+ };
3625
+ /**
3626
+ * The decimals a value axis's ticks are held to: 0 for whole-number data, else the caller's `tickDecimals`.
3627
+ *
3628
+ * @param hasWholeNumberValues - Whether every plotted value is a whole number.
3629
+ * @param tickDecimals - The axis's `tickDecimals`.
3630
+ * @return Decimal places, or undefined to keep visx's ticks.
3631
+ */
3632
+ const getTickDecimals = (hasWholeNumberValues, tickDecimals) => {
3633
+ if (hasWholeNumberValues) return 0;
3634
+ return isValidDecimals(tickDecimals) ? tickDecimals : void 0;
3635
+ };
3636
+ /**
3637
+ * Hands its children the chart's value-scale ticks, held to `decimals` places.
3638
+ *
3639
+ * @param props - Component props.
3640
+ * @param props.axis - Which scale carries the values.
3641
+ * @param props.numTicks - Ticks to ask the scale for.
3642
+ * @param props.decimals - Decimal places a tick may carry, or undefined to keep visx's ticks.
3643
+ * @param props.children - Renders the axis and grid with the tick values.
3644
+ * @return The rendered children.
3645
+ */
3646
+ const TickDecimals = ({ axis, numTicks, decimals, children }) => {
3647
+ const { xScale, yScale } = useContext(DataContext);
3648
+ const tickValues = decimals === void 0 ? void 0 : getTickDecimalValues(axis === "x" ? xScale : yScale, numTicks, decimals);
3649
+ return /* @__PURE__ */ jsx(Fragment$1, { children: children(tickValues) });
3650
+ };
3558
3651
  // src/charts/private/time-axis.ts
3559
3652
  const X_TICK_WIDTH = 60;
3560
3653
  const getCurveType = (type, smoothing) => {
@@ -3847,52 +3940,24 @@ const buildTimeAxisOptions = ({ dataSorted, width, axisOptions, scaleDomain, zoo
3847
3940
  ...numTicks === void 0 ? {} : { numTicks }
3848
3941
  };
3849
3942
  };
3850
- // src/charts/private/whole-number-ticks.tsx
3851
- /**
3852
- * Whether every reading in the series is a whole number.
3853
- *
3854
- * @param series - The series visx renders.
3855
- * @return True when at least one reading exists and none has a fraction.
3856
- */
3857
- const hasOnlyWholeNumbers = (series) => {
3858
- let sawReading = false;
3859
- for (const { data } of series) for (const point of data) {
3860
- const value = point?.value;
3861
- if (!isReading(value)) continue;
3862
- if (!Number.isInteger(value)) return false;
3863
- sawReading = true;
3864
- }
3865
- return sawReading;
3866
- };
3943
+ // src/charts/private/use-compact-when-short.ts
3867
3944
  /**
3868
- * The scale's ticks with the fractional ones dropped.
3945
+ * Whether a `compactWhenShort` chart is compact, and the margin it then defaults to.
3869
3946
  *
3870
- * d3 steps by 1, 2 or 5 times a power of ten, so every whole number inside the domain is one of its ticks.
3947
+ * Reads the height the chart was given, not the measured plot area: that grows once the legend
3948
+ * is hidden and would flip the chart straight back. A zero height is unmeasured, not short.
3871
3949
  *
3872
- * @param scale - The value scale visx built.
3873
- * @param count - Ticks to ask the scale for; undefined uses the scale's own default, as visx does.
3874
- * @return Whole-number ticks, or undefined when visx's own ticks need no change.
3875
- */
3876
- const getWholeNumberTickValues = (scale, count) => {
3877
- const ticks = scale?.ticks?.(count);
3878
- if (!ticks?.every((tick) => typeof tick === "number")) return;
3879
- const whole = ticks.filter((tick) => Number.isInteger(tick));
3880
- return whole.length > 1 && whole.length < ticks.length ? whole : void 0;
3881
- };
3882
- /**
3883
- * Hands its children the whole-number ticks of the chart's value scale.
3884
- *
3885
- * @param props - Component props.
3886
- * @param props.axis - Which scale carries the values.
3887
- * @param props.numTicks - Ticks to ask the scale for.
3888
- * @param props.enabled - Whether the plotted values are all whole numbers and the caller pinned neither the ticks nor the value domain.
3889
- * @param props.children - Renders the axis and grid with the tick values.
3890
- * @return The rendered children.
3950
+ * @param enabled - The chart's `compactWhenShort` prop.
3951
+ * @param height - The height the chart was given.
3952
+ * @return Whether the chart is compact, and the compact margin when it is.
3891
3953
  */
3892
- const WholeNumberTicks = ({ axis, numTicks, enabled, children }) => {
3893
- const { xScale, yScale } = useContext(DataContext);
3894
- const tickValues = enabled ? getWholeNumberTickValues(axis === "x" ? xScale : yScale, numTicks) : void 0;
3895
- return /* @__PURE__ */ jsx(Fragment$1, { children: children(tickValues) });
3954
+ const useCompactWhenShort = (enabled, height) => {
3955
+ const { compactWhenShort } = useGlobalChartsTheme();
3956
+ const isCompact = enabled && (height ?? 0) > 0 && height < compactWhenShort.below;
3957
+ return {
3958
+ isCompact,
3959
+ compactMargin: isCompact ? compactWhenShort.margin : void 0
3960
+ };
3896
3961
  };
3897
3962
  // src/charts/private/with-responsive/with-responsive.module.scss
3898
3963
  var with_responsive_module_default = {
@@ -4779,7 +4844,7 @@ const LineChartScalesRef = ({ chartRef, width, height, margin }) => {
4779
4844
  ]);
4780
4845
  return null;
4781
4846
  };
4782
- const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, renderGlyph = defaultRenderGlyph, glyphStyle = {}, withLegendGlyph = false, withGradientFill = false, smoothing = true, curveType, renderTooltip = renderDefaultTooltip, tooltipPlacement, tooltipStyle, withStartGlyphs = false, withEndGlyphs = false, animation, options = {}, onPointerDown = void 0, onPointerUp = void 0, onPointerMove = void 0, onPointerOut = void 0, onDatumActivate = void 0, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md" }, ref) => {
4847
+ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, renderGlyph = defaultRenderGlyph, glyphStyle = {}, withLegendGlyph = false, withGradientFill = false, smoothing = true, curveType, renderTooltip = renderDefaultTooltip, tooltipPlacement, tooltipStyle, withStartGlyphs = false, withEndGlyphs = false, animation, options = {}, onPointerDown = void 0, onPointerUp = void 0, onPointerMove = void 0, onPointerOut = void 0, onDatumActivate = void 0, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md", compactWhenShort = false }, ref) => {
4783
4848
  const legendInteractive = legend.interactive ?? false;
4784
4849
  const legendCollapseGroups = legend.collapseGroups ?? false;
4785
4850
  const legendComparisonItem = legend.comparisonItem ?? false;
@@ -4806,6 +4871,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
4806
4871
  }
4807
4872
  });
4808
4873
  const { legendChildren, nonLegendChildren } = useChartChildren(children, "LineChart");
4874
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort, height);
4809
4875
  const [measuredChartHeight, setMeasuredChartHeight] = useState();
4810
4876
  const handleContentHeightChange = useCallback((contentHeight) => {
4811
4877
  setMeasuredChartHeight(contentHeight > 0 ? contentHeight : height);
@@ -4894,25 +4960,34 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
4894
4960
  return min <= max ? [min, max] : void 0;
4895
4961
  }, [dataSorted, isSeriesVisible]);
4896
4962
  const hasWholeNumberValues = useMemo(() => hasOnlyWholeNumbers(visibleSeries), [visibleSeries]);
4963
+ const isLogScale = options?.yScale?.type === "log";
4964
+ const callerTickDecimals = isLogScale ? void 0 : options?.axis?.y?.tickDecimals;
4965
+ const yTickDecimals = getTickDecimals(hasWholeNumberValues, callerTickDecimals);
4897
4966
  const chartOptions = useMemo(() => {
4898
- const fallbackYDomain = getFallbackYDomain(visibleReadingExtent, options?.yScale?.type === "log");
4967
+ const fallbackYDomain = getFallbackYDomain(visibleReadingExtent, isLogScale);
4968
+ const { tickDecimals, ...yAxisOptions } = options?.axis?.y ?? {};
4969
+ const tickDecimalsDomain = isLogScale || tickDecimals === void 0 || options?.yScale?.domain || yAxisOptions.tickValues ? void 0 : getTickDecimalsDomain(yDomain ?? fallbackYDomain ?? visibleReadingExtent, yTickDecimals);
4899
4970
  return {
4900
4971
  axis: {
4901
- x: buildTimeAxisOptions({
4902
- dataSorted,
4903
- width,
4904
- axisOptions: options?.axis?.x,
4905
- scaleDomain: options?.xScale?.domain,
4906
- zoomDomain: zoom.domain,
4907
- formatting,
4908
- isSeriesRendered: (series) => isSeriesVisible(series.label)
4909
- }),
4972
+ x: {
4973
+ ...buildTimeAxisOptions({
4974
+ dataSorted,
4975
+ width,
4976
+ axisOptions: options?.axis?.x,
4977
+ scaleDomain: options?.xScale?.domain,
4978
+ zoomDomain: zoom.domain,
4979
+ formatting,
4980
+ isSeriesRendered: (series) => isSeriesVisible(series.label)
4981
+ }),
4982
+ ...isCompact && { display: false }
4983
+ },
4910
4984
  y: {
4911
4985
  orientation: "left",
4912
4986
  numTicks: 4,
4913
4987
  tickFormat: formatNumberCompact,
4914
4988
  display: true,
4915
- ...options?.axis?.y
4989
+ ...yAxisOptions,
4990
+ ...isCompact && { display: false }
4916
4991
  }
4917
4992
  },
4918
4993
  xScale: {
@@ -4926,6 +5001,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
4926
5001
  zero: false,
4927
5002
  ...fallbackYDomain ? { domain: fallbackYDomain } : {},
4928
5003
  ...yDomain ? { domain: yDomain } : {},
5004
+ ...tickDecimalsDomain ? { domain: tickDecimalsDomain } : {},
4929
5005
  ...options?.yScale
4930
5006
  }
4931
5007
  };
@@ -4936,8 +5012,11 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
4936
5012
  zoom.domain,
4937
5013
  yDomain,
4938
5014
  visibleReadingExtent,
5015
+ isLogScale,
5016
+ yTickDecimals,
4939
5017
  formatting,
4940
- isSeriesVisible
5018
+ isSeriesVisible,
5019
+ isCompact
4941
5020
  ]);
4942
5021
  const bucketInfo = useMemo(() => getBucketInfo(visibleSeries, options?.axis?.x?.tickResolution), [visibleSeries, options?.axis?.x?.tickResolution]);
4943
5022
  const tooltipRenderGlyph = useMemo(() => {
@@ -5012,7 +5091,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5012
5091
  className: clsx("line-chart", line_chart_module_default["line-chart"]),
5013
5092
  children: error
5014
5093
  });
5015
- const legendElement = showLegend && /* @__PURE__ */ jsx(Legend, {
5094
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ jsx(Legend, {
5016
5095
  orientation: legend.orientation ?? "horizontal",
5017
5096
  alignment: legend.alignment ?? "center",
5018
5097
  position: legendPosition,
@@ -5036,7 +5115,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5036
5115
  children: /* @__PURE__ */ jsx(ChartLayout, {
5037
5116
  legendPosition,
5038
5117
  legendElement,
5039
- legendChildren,
5118
+ legendChildren: isCompact ? [] : legendChildren,
5040
5119
  gap,
5041
5120
  className: clsx("line-chart", line_chart_module_default["line-chart"], { [line_chart_module_default["line-chart--animated"]]: animation && !prefersReducedMotion }, className),
5042
5121
  style: {
@@ -5064,6 +5143,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5064
5143
  height: chartHeight,
5065
5144
  margin: {
5066
5145
  ...defaultMargin,
5146
+ ...compactMargin,
5067
5147
  ...margin
5068
5148
  },
5069
5149
  xScale: chartOptions.xScale,
@@ -5071,12 +5151,12 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5071
5151
  onPointerOut,
5072
5152
  children: [
5073
5153
  /* @__PURE__ */ jsx(NearestPointerEvents, { ...zoom.handlers }),
5074
- /* @__PURE__ */ jsx(WholeNumberTicks, {
5154
+ /* @__PURE__ */ jsx(TickDecimals, {
5075
5155
  axis: "y",
5076
5156
  numTicks: chartOptions.axis.y.numTicks,
5077
- enabled: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain,
5157
+ decimals: !chartOptions.axis.y.tickValues && !options?.yScale?.domain ? yTickDecimals : void 0,
5078
5158
  children: (tickValues) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
5079
- !allSeriesHidden && gridVisibility !== "none" && /* @__PURE__ */ jsx(Grid, {
5159
+ !allSeriesHidden && gridVisibility !== "none" && !isCompact && /* @__PURE__ */ jsx(Grid, {
5080
5160
  columns: false,
5081
5161
  numTicks: chartOptions.axis.y.numTicks,
5082
5162
  tickValues: tickValues ?? chartOptions.axis.y.tickValues
@@ -5093,7 +5173,7 @@ const LineChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5093
5173
  y: chartHeight / 2,
5094
5174
  width,
5095
5175
  height: chartHeight,
5096
- children: getAllHiddenMessage(legendInteractive, "series")
5176
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
5097
5177
  }) : null,
5098
5178
  /* @__PURE__ */ jsx(ZoomClip, {
5099
5179
  active: zoomable && !!zoom.domain,
@@ -5295,7 +5375,7 @@ const HoverGlyphs = ({ visibleSeries, stacked, stackOffset, getElementStyles, st
5295
5375
  });
5296
5376
  };
5297
5377
  // src/charts/area-chart/area-chart.tsx
5298
- const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, stacked = true, stackOffset = "none", smoothing = true, curveType, fillOpacity, withStroke, renderTooltip = renderDefaultTooltip, animation, options = {}, onPointerDown, onPointerUp, onPointerMove, onPointerOut, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md" }, ref) => {
5378
+ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = true, withTooltipCrosshairs, showLegend = false, legend = {}, stacked = true, stackOffset = "none", smoothing = true, curveType, fillOpacity, withStroke, renderTooltip = renderDefaultTooltip, animation, options = {}, onPointerDown, onPointerUp, onPointerMove, onPointerOut, zoomable = false, rescaleYOnVisibilityChange = true, defaultHiddenSeries, children, gridVisibility, gap = "md", compactWhenShort = false }, ref) => {
5299
5379
  const legendInteractive = legend.interactive ?? false;
5300
5380
  const legendShape = legend.shape ?? "rect";
5301
5381
  const legendPosition = legend.position ?? "bottom";
@@ -5318,6 +5398,7 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5318
5398
  }
5319
5399
  });
5320
5400
  const { legendChildren, nonLegendChildren } = useChartChildren(children, "AreaChart");
5401
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort, height);
5321
5402
  const [measuredChartHeight, setMeasuredChartHeight] = useState();
5322
5403
  const handleContentHeightChange = useCallback((contentHeight) => {
5323
5404
  setMeasuredChartHeight(contentHeight > 0 ? contentHeight : height);
@@ -5397,20 +5478,24 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5397
5478
  const chartOptions = useMemo(() => {
5398
5479
  return {
5399
5480
  axis: {
5400
- x: buildTimeAxisOptions({
5401
- dataSorted,
5402
- width,
5403
- axisOptions: options?.axis?.x,
5404
- scaleDomain: options?.xScale?.domain,
5405
- zoomDomain: zoom.domain,
5406
- formatting
5407
- }),
5481
+ x: {
5482
+ ...buildTimeAxisOptions({
5483
+ dataSorted,
5484
+ width,
5485
+ axisOptions: options?.axis?.x,
5486
+ scaleDomain: options?.xScale?.domain,
5487
+ zoomDomain: zoom.domain,
5488
+ formatting
5489
+ }),
5490
+ ...isCompact && { display: false }
5491
+ },
5408
5492
  y: {
5409
5493
  orientation: "left",
5410
5494
  numTicks: 4,
5411
5495
  tickFormat: formatNumberCompact,
5412
5496
  display: true,
5413
- ...options?.axis?.y
5497
+ ...options?.axis?.y,
5498
+ ...isCompact && { display: false }
5414
5499
  }
5415
5500
  },
5416
5501
  xScale: {
@@ -5433,7 +5518,8 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5433
5518
  stacked,
5434
5519
  fixedYDomain,
5435
5520
  zoom.domain,
5436
- formatting
5521
+ formatting,
5522
+ isCompact
5437
5523
  ]);
5438
5524
  const defaultMargin = useChartMargin(height, chartOptions, dataSorted, theme);
5439
5525
  const error = validateData$3(dataSorted);
@@ -5513,7 +5599,7 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5513
5599
  className: clsx("area-chart", area_chart_module_default["area-chart"]),
5514
5600
  children: error
5515
5601
  });
5516
- const legendElement = showLegend && /* @__PURE__ */ jsx(Legend, {
5602
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ jsx(Legend, {
5517
5603
  orientation: legend.orientation ?? "horizontal",
5518
5604
  alignment: legend.alignment ?? "center",
5519
5605
  position: legendPosition,
@@ -5561,7 +5647,7 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5561
5647
  children: /* @__PURE__ */ jsx(ChartLayout, {
5562
5648
  legendPosition,
5563
5649
  legendElement,
5564
- legendChildren,
5650
+ legendChildren: isCompact ? [] : legendChildren,
5565
5651
  gap,
5566
5652
  className: clsx("area-chart", area_chart_module_default["area-chart"], { [area_chart_module_default["area-chart--animated"]]: animationEnabled }, className),
5567
5653
  style: {
@@ -5589,6 +5675,7 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5589
5675
  height: chartHeight,
5590
5676
  margin: {
5591
5677
  ...defaultMargin,
5678
+ ...compactMargin,
5592
5679
  ...margin
5593
5680
  },
5594
5681
  xScale: chartOptions.xScale,
@@ -5599,12 +5686,12 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5599
5686
  onPointerOut,
5600
5687
  pointerEventsDataKey: "nearest",
5601
5688
  children: [
5602
- /* @__PURE__ */ jsx(WholeNumberTicks, {
5689
+ /* @__PURE__ */ jsx(TickDecimals, {
5603
5690
  axis: "y",
5604
5691
  numTicks: chartOptions.axis.y.numTicks,
5605
- enabled: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain,
5692
+ decimals: hasWholeNumberValues && !chartOptions.axis.y.tickValues && !options?.yScale?.domain ? 0 : void 0,
5606
5693
  children: (tickValues) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
5607
- !allSeriesHidden && gridVisibility !== "none" && /* @__PURE__ */ jsx(Grid, {
5694
+ !allSeriesHidden && gridVisibility !== "none" && !isCompact && /* @__PURE__ */ jsx(Grid, {
5608
5695
  columns: false,
5609
5696
  numTicks: chartOptions.axis.y.numTicks,
5610
5697
  tickValues: tickValues ?? chartOptions.axis.y.tickValues
@@ -5621,7 +5708,7 @@ const AreaChartInternal = forwardRef(({ data, ariaLabel, chartId: providedChartI
5621
5708
  y: chartHeight / 2,
5622
5709
  width,
5623
5710
  height: chartHeight,
5624
- children: getAllHiddenMessage(legendInteractive, "series")
5711
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
5625
5712
  }) : null,
5626
5713
  /* @__PURE__ */ jsxs(ZoomClip, {
5627
5714
  active: zoomable,
@@ -5684,9 +5771,145 @@ var bar_chart_module_default = {
5684
5771
  "bar-chart": "a8ccharts-97yN9W-bar-chart",
5685
5772
  "bar-chart--animated": "a8ccharts-97yN9W-bar-chart--animated",
5686
5773
  "bar-chart--animated-horizontal": "a8ccharts-97yN9W-bar-chart--animated-horizontal",
5774
+ "bar-chart--stacked": "a8ccharts-97yN9W-bar-chart--stacked",
5687
5775
  "rise": "a8ccharts-97yN9W-rise",
5688
5776
  "stretch": "a8ccharts-97yN9W-stretch"
5689
5777
  };
5778
+ // src/charts/bar-chart/private/category.ts
5779
+ /**
5780
+ * Whether two data points sit at the same category: the same label, or the same date.
5781
+ *
5782
+ * @param point - A data point.
5783
+ * @param category - The data point naming the category.
5784
+ * @return Whether `point` is at `category`.
5785
+ */
5786
+ function isSameCategory(point, category) {
5787
+ return category.label ? point.label === category.label : !!category.date && !!point.date && point.date.getTime() === category.date.getTime();
5788
+ }
5789
+ /**
5790
+ * The category a data point sits at, as a key two points share when `isSameCategory` holds.
5791
+ *
5792
+ * @param point - A data point.
5793
+ * @return The category key.
5794
+ */
5795
+ function categoryKey(point) {
5796
+ return point.label ? `label:${point.label}` : `date:${point.date?.getTime()}`;
5797
+ }
5798
+ // src/charts/bar-chart/private/value-domain.ts
5799
+ /** Domain for a value axis that has nothing to scale, so its ticks still read 0 to 1. */
5800
+ const EMPTY_DOMAIN = [0, 1];
5801
+ /**
5802
+ * The value a bar is drawn at, preferring `visualValue` so a zero still shows a sliver.
5803
+ *
5804
+ * A missing reading is NaN, not null: `ComparisonBars` coerces the value with `Number()`,
5805
+ * which turns null into 0 and would draw a comparison shadow at the baseline.
5806
+ *
5807
+ * @param point - A data point handed to visx.
5808
+ * @return The bar value, or NaN when the bucket has no reading.
5809
+ */
5810
+ const getBarValue = (point) => {
5811
+ const enhanced = point;
5812
+ return (enhanced?.visualValue !== void 0 ? enhanced.visualValue : point?.value) ?? NaN;
5813
+ };
5814
+ /**
5815
+ * Whether visx renders a bar for a point.
5816
+ *
5817
+ * @param point - A data point handed to visx.
5818
+ * @return True when the point has a finite bar value.
5819
+ */
5820
+ const isBarRendered = (point) => Number.isFinite(getBarValue(point));
5821
+ /**
5822
+ * An explicit domain for the value scale, or null to let visx fit one to the data.
5823
+ *
5824
+ * Zero goes into the domain here rather than through the scale's `zero` flag: visx applies
5825
+ * `nice` before `zero`, which would leave the axis topping out at a raw maximum.
5826
+ *
5827
+ * @param data - Every series handed to the chart.
5828
+ * @param includeZero - Whether the domain must span zero.
5829
+ * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
5830
+ * @param tickDecimals - The value axis's `tickDecimals`.
5831
+ * @return Value domain, or null when visx should fit its own.
5832
+ */
5833
+ const getValueScaleDomain = (data, includeZero, isSeriesRendered, tickDecimals) => {
5834
+ let min = Infinity;
5835
+ let max = -Infinity;
5836
+ for (const series of data) {
5837
+ if (!isSeriesRendered(series)) continue;
5838
+ for (const point of series.data) {
5839
+ const value = getBarValue(point);
5840
+ if (!Number.isFinite(value)) continue;
5841
+ min = Math.min(min, value);
5842
+ max = Math.max(max, value);
5843
+ }
5844
+ }
5845
+ if (min === Infinity) return [...EMPTY_DOMAIN];
5846
+ let domain = null;
5847
+ if (min === max) domain = min === 0 ? [...EMPTY_DOMAIN] : [Math.min(0, min), Math.max(0, max)];
5848
+ else if (includeZero) domain = [Math.min(0, min), Math.max(0, max)];
5849
+ return getTickDecimalsDomain(domain ?? [min, max], tickDecimals) ?? domain;
5850
+ };
5851
+ // src/charts/bar-chart/private/stack-layout.ts
5852
+ /**
5853
+ * The series a layout draws: a stacked layout leaves comparison series out for now.
5854
+ *
5855
+ * @param series - The chart's series.
5856
+ * @param layout - The layout the bars are drawn in.
5857
+ * @return The drawn series.
5858
+ */
5859
+ function getDrawnSeries(series, layout) {
5860
+ return layout === "stacked" ? series.filter((item) => item.options?.type !== "comparison") : series;
5861
+ }
5862
+ /**
5863
+ * Stacks the series in order at each category: positives upward and negatives downward from zero.
5864
+ *
5865
+ * @param series - The series to stack, bottom first.
5866
+ * @return The stack layout.
5867
+ */
5868
+ function getStackLayout(series) {
5869
+ const segments = /* @__PURE__ */ new Map();
5870
+ const extents = /* @__PURE__ */ new Map();
5871
+ for (const { label, data } of series) {
5872
+ const byCategory = /* @__PURE__ */ new Map();
5873
+ segments.set(label, byCategory);
5874
+ for (const point of data) {
5875
+ const value = getBarValue(point);
5876
+ if (!Number.isFinite(value)) continue;
5877
+ const key = categoryKey(point);
5878
+ if (byCategory.has(key)) continue;
5879
+ const extent = extents.get(key) ?? [0, 0];
5880
+ const side = value < 0 ? 0 : 1;
5881
+ const start = extent[side];
5882
+ extent[side] = start + value;
5883
+ extents.set(key, extent);
5884
+ byCategory.set(key, {
5885
+ start,
5886
+ end: start + value
5887
+ });
5888
+ }
5889
+ }
5890
+ let extent = null;
5891
+ for (const [low, high] of extents.values()) extent = extent ? [Math.min(extent[0], low), Math.max(extent[1], high)] : [low, high];
5892
+ return {
5893
+ segmentOf: (key, datum) => segments.get(key)?.get(categoryKey(datum)),
5894
+ extentAt: (category) => {
5895
+ const [low, high] = extents.get(categoryKey(category)) ?? [0, 0];
5896
+ return [low, high];
5897
+ },
5898
+ extent
5899
+ };
5900
+ }
5901
+ /**
5902
+ * The value domain of a computed stack, falling back to an empty chart's domain.
5903
+ *
5904
+ * @param stack - The precomputed stack.
5905
+ * @param tickDecimals - The value axis precision, when set.
5906
+ * @return The extent widened for tick precision, or the empty chart domain.
5907
+ */
5908
+ function getStackedValueDomain(stack, tickDecimals) {
5909
+ const { extent } = stack;
5910
+ const domain = !extent || extent[0] === extent[1] ? [...EMPTY_DOMAIN] : extent;
5911
+ return getTickDecimalsDomain(domain, tickDecimals) ?? domain;
5912
+ }
5690
5913
  // src/charts/bar-chart/private/truncated-tick-component.tsx
5691
5914
  /**
5692
5915
  * Get the bandwidth of a scale
@@ -5801,57 +6024,6 @@ const createTruncatedTickComponent = (axis) => (props) => {
5801
6024
  */
5802
6025
  const TruncatedXTickComponent = createTruncatedTickComponent("x");
5803
6026
  const TruncatedYTickComponent = createTruncatedTickComponent("y");
5804
- // src/charts/bar-chart/private/value-domain.ts
5805
- /** Domain for a value axis that has nothing to scale, so its ticks still read 0 to 1. */
5806
- const EMPTY_DOMAIN = [0, 1];
5807
- /**
5808
- * The value a bar is drawn at, preferring `visualValue` so a zero still shows a sliver.
5809
- *
5810
- * A missing reading is NaN, not null: `ComparisonBars` coerces the value with `Number()`,
5811
- * which turns null into 0 and would draw a comparison shadow at the baseline.
5812
- *
5813
- * @param point - A data point handed to visx.
5814
- * @return The bar value, or NaN when the bucket has no reading.
5815
- */
5816
- const getBarValue = (point) => {
5817
- const enhanced = point;
5818
- return (enhanced?.visualValue !== void 0 ? enhanced.visualValue : point?.value) ?? NaN;
5819
- };
5820
- /**
5821
- * Whether visx renders a bar for a point.
5822
- *
5823
- * @param point - A data point handed to visx.
5824
- * @return True when the point has a finite bar value.
5825
- */
5826
- const isBarRendered = (point) => Number.isFinite(getBarValue(point));
5827
- /**
5828
- * An explicit domain for the value scale, or null to let visx fit one to the data.
5829
- *
5830
- * Zero goes into the domain here rather than through the scale's `zero` flag: visx applies
5831
- * `nice` before `zero`, which would leave the axis topping out at a raw maximum.
5832
- *
5833
- * @param data - Every series handed to the chart.
5834
- * @param includeZero - Whether the domain must span zero.
5835
- * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
5836
- * @return Value domain, or null when visx should fit its own.
5837
- */
5838
- const getValueScaleDomain = (data, includeZero, isSeriesRendered) => {
5839
- let min = Infinity;
5840
- let max = -Infinity;
5841
- for (const series of data) {
5842
- if (!isSeriesRendered(series)) continue;
5843
- for (const point of series.data) {
5844
- const value = getBarValue(point);
5845
- if (!Number.isFinite(value)) continue;
5846
- min = Math.min(min, value);
5847
- max = Math.max(max, value);
5848
- }
5849
- }
5850
- if (min === Infinity) return [...EMPTY_DOMAIN];
5851
- if (min === max) return min === 0 ? [...EMPTY_DOMAIN] : [Math.min(0, min), Math.max(0, max)];
5852
- if (includeZero) return [Math.min(0, min), Math.max(0, max)];
5853
- return null;
5854
- };
5855
6027
  // src/charts/bar-chart/private/use-bar-chart-options.ts
5856
6028
  /** Outer padding of the category band scale (space at the chart edges). */
5857
6029
  const BASE_BAND_PADDING = .2;
@@ -5940,14 +6112,18 @@ const getGroupPadding = (scale) => {
5940
6112
  * @param horizontal - Whether the chart is horizontal or vertical.
5941
6113
  * @param options - The options for the chart.
5942
6114
  * @param isSeriesRendered - Whether visx mounts a series, i.e. the legend shows it.
6115
+ * @param stack - The precomputed stack, when series share one bar.
5943
6116
  * @return The merged options for the chart.
5944
6117
  */
5945
- function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED) {
6118
+ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = ALL_RENDERED, stack) {
5946
6119
  const stableOptions = useDeepMemo(options);
5947
6120
  const formatting = useChartFormatting();
6121
+ const isStacked = !!stack;
5948
6122
  const axisConfig = useMemo(() => {
5949
- const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, ...xAxisOptions } = stableOptions.axis?.x || {};
5950
- const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, ...yAxisOptions } = stableOptions.axis?.y || {};
6123
+ const { labelOverflow: xLabelOverflow, tickResolution: xTickResolution, tickFormat: xTickFormat, tickDecimals: xTickDecimals, ...xAxisOptions } = stableOptions.axis?.x || {};
6124
+ const { labelOverflow: yLabelOverflow, tickResolution: yTickResolution, tickFormat: yTickFormat, tickDecimals: yTickDecimals, ...yAxisOptions } = stableOptions.axis?.y || {};
6125
+ const [valueAxisOptions, valueTickDecimals] = horizontal ? [xAxisOptions, xTickDecimals] : [yAxisOptions, yTickDecimals];
6126
+ const valueScaleType = isStacked ? "linear" : (horizontal ? stableOptions.xScale : stableOptions.yScale)?.type;
5951
6127
  return {
5952
6128
  xLabelOverflow,
5953
6129
  yLabelOverflow,
@@ -5955,9 +6131,14 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
5955
6131
  yTickFormat,
5956
6132
  xAxisOptions,
5957
6133
  yAxisOptions,
5958
- tickResolution: horizontal ? yTickResolution : xTickResolution
6134
+ tickResolution: horizontal ? yTickResolution : xTickResolution,
6135
+ valueTickDecimals: valueAxisOptions.tickValues || valueScaleType === "log" ? void 0 : valueTickDecimals
5959
6136
  };
5960
- }, [stableOptions, horizontal]);
6137
+ }, [
6138
+ stableOptions,
6139
+ horizontal,
6140
+ isStacked
6141
+ ]);
5961
6142
  const { tickResolution } = axisConfig;
5962
6143
  const defaultOptions = useMemo(() => {
5963
6144
  const bandScale = {
@@ -6012,17 +6193,21 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6012
6193
  const { xTickFormat: defaultXTickFormat, yTickFormat: defaultYTickFormat, tooltipLabelFormatter: defaultTooltipLabelFormatter, xAccessor, yAccessor, gridVisibility, xScale: baseXScale, yScale: baseYScale } = defaultOptions[horizontal ? "horizontal" : "vertical"];
6013
6194
  const valueScaleOptions = horizontal ? stableOptions.xScale : stableOptions.yScale;
6014
6195
  const includeZero = data.some((s) => s.options?.type === "comparison") || valueScaleOptions?.zero !== false;
6015
- const domain = valueScaleOptions?.domain ? null : getValueScaleDomain(data, includeZero, isSeriesRendered);
6016
- const valueScaleDomainOverride = domain ? { domain } : {};
6196
+ let domain = null;
6197
+ if (!valueScaleOptions?.domain) domain = stack ? getStackedValueDomain(stack, axisConfig.valueTickDecimals) : getValueScaleDomain(data, includeZero, isSeriesRendered, axisConfig.valueTickDecimals);
6198
+ const valueScaleOverride = {
6199
+ ...domain && { domain },
6200
+ ...stack && { type: "linear" }
6201
+ };
6017
6202
  const xScale = {
6018
6203
  ...baseXScale,
6019
6204
  ...stableOptions.xScale || {},
6020
- ...horizontal ? valueScaleDomainOverride : {}
6205
+ ...horizontal ? valueScaleOverride : {}
6021
6206
  };
6022
6207
  const yScale = {
6023
6208
  ...baseYScale,
6024
6209
  ...stableOptions.yScale || {},
6025
- ...!horizontal ? valueScaleDomainOverride : {}
6210
+ ...!horizontal ? valueScaleOverride : {}
6026
6211
  };
6027
6212
  const { xLabelOverflow, yLabelOverflow, xTickFormat, yTickFormat, xAxisOptions, yAxisOptions } = axisConfig;
6028
6213
  const dateAxisTickFormat = horizontal ? yTickFormat : xTickFormat;
@@ -6057,7 +6242,8 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6057
6242
  }
6058
6243
  },
6059
6244
  barGroup: { padding: getGroupPadding(horizontal ? yScale : xScale) },
6060
- tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter }
6245
+ tooltip: { labelFormatter: dateAxisTickFormat || defaultTooltipLabelFormatter },
6246
+ valueTickDecimals: axisConfig.valueTickDecimals
6061
6247
  };
6062
6248
  }, [
6063
6249
  defaultOptions,
@@ -6065,7 +6251,8 @@ function useBarChartOptions(data, horizontal, options = {}, isSeriesRendered = A
6065
6251
  stableOptions,
6066
6252
  horizontal,
6067
6253
  data,
6068
- isSeriesRendered
6254
+ isSeriesRendered,
6255
+ stack
6069
6256
  ]);
6070
6257
  }
6071
6258
  // src/charts/bar-chart/private/band-scale.ts
@@ -6097,6 +6284,17 @@ function getValueScaleBaseline(scale) {
6097
6284
  return Number.isFinite(maybeZero) ? Math.max(maybeZero, minOutput) : minOutput;
6098
6285
  }
6099
6286
  /**
6287
+ * A value's position on a continuous scale, held inside its range so a domain that leaves the value out cannot push a bar off the plot.
6288
+ *
6289
+ * @param {ValueScale} scale - The continuous value scale.
6290
+ * @param {number} value - The value to place.
6291
+ * @return {number} The position in pixels.
6292
+ */
6293
+ function getValueScalePosition(scale, value) {
6294
+ const [a, b] = scale.range().map((r) => Number(r) || 0);
6295
+ return Math.min(Math.max(scale(value), Math.min(a, b)), Math.max(a, b));
6296
+ }
6297
+ /**
6100
6298
  * Compute the rect that spans `valuePositions` along the value axis, centered on a slot and scaled by `widthFactor` across it.
6101
6299
  *
6102
6300
  * @param {object} params - Geometry inputs.
@@ -6293,13 +6491,13 @@ const SelectedBarRing = ({ chartId, selected, slotKeys, groupPadding, horizontal
6293
6491
  const slotOffset = groupScale(selected.slotKey);
6294
6492
  const bandPosition = Number(bandScale((horizontal ? yAccessor : xAccessor)(category)));
6295
6493
  if (slotOffset == null || !Number.isFinite(bandPosition)) return null;
6296
- const valuePositions = selected.data.map((datum) => Number(valueScale(Number((horizontal ? xAccessor : yAccessor)(datum)))));
6494
+ const valuePositions = selected.valueExtent ? selected.valueExtent.map((value) => getValueScalePosition(valueScale, value)) : [getValueScaleBaseline(valueScale), ...selected.data.map((datum) => Number(valueScale(Number((horizontal ? xAccessor : yAccessor)(datum)))))];
6297
6495
  const rect = computeSlotRect({
6298
6496
  horizontal,
6299
6497
  bandPosition,
6300
6498
  slotOffset,
6301
6499
  slotThickness: groupScale.bandwidth(),
6302
- valuePositions: [getValueScaleBaseline(valueScale), ...valuePositions],
6500
+ valuePositions,
6303
6501
  widthFactor: selected.thickness
6304
6502
  });
6305
6503
  return /* @__PURE__ */ jsx(SelectedRing, {
@@ -6309,13 +6507,107 @@ const SelectedBarRing = ({ chartId, selected, slotKeys, groupPadding, horizontal
6309
6507
  testId: "bar-chart-selected-ring"
6310
6508
  });
6311
6509
  };
6510
+ // src/charts/bar-chart/private/stacked-bar-series.tsx
6511
+ /**
6512
+ * The side a segment rounds when it ends its drawn stack: the far end of the positives or of the negatives.
6513
+ *
6514
+ * @param stack - The stack layout.
6515
+ * @param segment - The segment.
6516
+ * @param category - A datum at the segment's category.
6517
+ * @param horizontal - Whether the bars run horizontally.
6518
+ * @param clamp - Holds a value inside the value domain, where the bars are cut off.
6519
+ * @return The side to round, or undefined for a segment inside its stack or drawn with no length.
6520
+ */
6521
+ function getStackEnd(stack, segment, category, horizontal, clamp) {
6522
+ const [start, end] = [segment.start, segment.end].map(clamp);
6523
+ if (start === end) return;
6524
+ const extent = stack.extentAt(category).map(clamp);
6525
+ if (segment.end > 0 && end === extent[1]) return horizontal ? "right" : "top";
6526
+ if (segment.end < 0 && end === extent[0]) return horizontal ? "left" : "bottom";
6527
+ }
6528
+ const StackedBarSeries = ({ barClassName, slotKeys, slotKey, groupPadding, stack, ...props }) => {
6529
+ const { xScale, yScale, horizontal } = useContext(DataContext);
6530
+ const bandScale = horizontal ? yScale : xScale;
6531
+ const valueScale = horizontal ? xScale : yScale;
6532
+ const groupScale = useMemo(() => createGroupScale(slotKeys, bandScale?.bandwidth?.() ?? 0, groupPadding), [
6533
+ slotKeys,
6534
+ bandScale,
6535
+ groupPadding
6536
+ ]);
6537
+ const { dataKey, xAccessor, yAccessor } = props;
6538
+ const [domainStart, domainEnd] = (horizontal ? xScale : yScale)?.domain() ?? [-Infinity, Infinity];
6539
+ const domainMin = Math.min(Number(domainStart), Number(domainEnd));
6540
+ const domainMax = Math.max(Number(domainStart), Number(domainEnd));
6541
+ const clamp = useCallback((value) => Math.min(domainMax, Math.max(domainMin, value)), [domainMin, domainMax]);
6542
+ const stackEnd = useCallback((datum) => {
6543
+ const [low, high] = stack.extentAt(datum);
6544
+ return clamp(high > 0 ? high : low);
6545
+ }, [stack, clamp]);
6546
+ const renderGlyph = useCallback(({ datum, color }) => {
6547
+ const segment = stack.segmentOf(dataKey, datum);
6548
+ if (!segment || !bandScale?.bandwidth || !valueScale) return null;
6549
+ const rect = computeSlotRect({
6550
+ horizontal: !!horizontal,
6551
+ bandPosition: Number(bandScale((horizontal ? yAccessor : xAccessor)(datum))),
6552
+ slotOffset: groupScale(slotKey) ?? 0,
6553
+ slotThickness: groupScale.bandwidth(),
6554
+ valuePositions: [segment.start, segment.end].map((value) => getValueScalePosition(valueScale, value)),
6555
+ widthFactor: 1
6556
+ });
6557
+ return /* @__PURE__ */ jsx("rect", {
6558
+ ...rect,
6559
+ "data-stack-end": getStackEnd(stack, segment, datum, !!horizontal, clamp),
6560
+ className: clsx("visx-bar", barClassName?.(datum)),
6561
+ fill: color
6562
+ });
6563
+ }, [
6564
+ stack,
6565
+ clamp,
6566
+ dataKey,
6567
+ bandScale,
6568
+ valueScale,
6569
+ horizontal,
6570
+ groupScale,
6571
+ slotKey,
6572
+ xAccessor,
6573
+ yAccessor,
6574
+ barClassName
6575
+ ]);
6576
+ return /* @__PURE__ */ jsx(GlyphSeries, {
6577
+ ...props,
6578
+ xAccessor: horizontal ? stackEnd : xAccessor,
6579
+ yAccessor: horizontal ? yAccessor : stackEnd,
6580
+ enableEvents: false,
6581
+ renderGlyph
6582
+ });
6583
+ };
6312
6584
  // src/charts/bar-chart/private/bar-layer.tsx
6313
6585
  /**
6314
- * Draws the bars in front of any comparison shadows, slotted for an overlap layout and grouped by visx otherwise, then the selected bar's ring.
6586
+ * Wraps the stacked bars so the entrance animation grows them from the zero line.
6587
+ *
6588
+ * Reading the scales here, not in `BarLayer`, keeps the series' own data registration from re-rendering it in a loop.
6589
+ *
6590
+ * @param props - Component props.
6591
+ * @param props.horizontal - Whether the bars run horizontally.
6592
+ * @param props.children - The stacked series.
6593
+ * @return The group.
6594
+ */
6595
+ const StackedBarGroup = ({ horizontal, children }) => {
6596
+ const { xScale, yScale } = useContext(DataContext);
6597
+ const valueScale = horizontal ? xScale : yScale;
6598
+ const zero = valueScale ? getValueScalePosition(valueScale, 0) : 0;
6599
+ return /* @__PURE__ */ jsx("g", {
6600
+ className: "visx-bar-group",
6601
+ style: { transformOrigin: horizontal ? `${zero}px 0` : `0 ${zero}px` },
6602
+ children
6603
+ });
6604
+ };
6605
+ /**
6606
+ * Draws the bars in front of any comparison shadows, stacked or slotted in the layout's slots and grouped by visx otherwise, then the selected bar's ring.
6315
6607
  *
6316
6608
  * @param props - Component props.
6317
6609
  * @param props.chartId - The chart's id, which keeps the ring's clip path unique on a page with several charts.
6318
- * @param props.overlapSlots - The overlap layout, or undefined for a grouped one.
6610
+ * @param props.barSlots - The overlap or stacked slots, or undefined for a grouped layout.
6319
6611
  * @param props.selectedBar - The bar or slot the keyboard has selected.
6320
6612
  * @param props.primaryEntries - The visible primary series, for a grouped layout.
6321
6613
  * @param props.primaryKeys - Their labels, in group order.
@@ -6327,20 +6619,35 @@ const SelectedBarRing = ({ chartId, selected, slotKeys, groupPadding, horizontal
6327
6619
  * @param props.yAccessor - Reads a datum's y value.
6328
6620
  * @return The bars.
6329
6621
  */
6330
- const BarLayer = ({ chartId, overlapSlots, selectedBar, primaryEntries, primaryKeys, getBarBackground, barClassName, groupPadding, horizontal, xAccessor, yAccessor }) => {
6622
+ const BarLayer = ({ chartId, barSlots, selectedBar, primaryEntries, primaryKeys, getBarBackground, barClassName, groupPadding, horizontal, xAccessor, yAccessor }) => {
6331
6623
  let bars;
6332
- if (overlapSlots) bars = /* @__PURE__ */ jsx("g", {
6624
+ if (barSlots?.kind === "stacked") bars = /* @__PURE__ */ jsx(StackedBarGroup, {
6625
+ horizontal,
6626
+ children: barSlots.entries.map(({ series, index }) => /* @__PURE__ */ jsx(StackedBarSeries, {
6627
+ dataKey: series.label,
6628
+ data: series.data,
6629
+ xAccessor,
6630
+ yAccessor,
6631
+ colorAccessor: getBarBackground(index),
6632
+ barClassName,
6633
+ slotKeys: barSlots.slotKeys,
6634
+ slotKey: barSlots.slotOf(series.label),
6635
+ groupPadding,
6636
+ stack: barSlots.stack
6637
+ }, series.label))
6638
+ });
6639
+ else if (barSlots) bars = /* @__PURE__ */ jsx("g", {
6333
6640
  className: "visx-bar-group",
6334
- children: overlapSlots.entries.map(({ series, index }) => /* @__PURE__ */ jsx(SlottedBarSeries, {
6641
+ children: barSlots.entries.map(({ series, index }) => /* @__PURE__ */ jsx(SlottedBarSeries, {
6335
6642
  dataKey: series.label,
6336
6643
  data: series.data,
6337
6644
  xAccessor,
6338
6645
  yAccessor,
6339
6646
  colorAccessor: getBarBackground(index),
6340
6647
  barClassName,
6341
- slotKeys: overlapSlots.slotKeys,
6342
- slotKey: overlapSlots.slotOf(series.label),
6343
- thickness: overlapSlots.thicknessOf(series.label),
6648
+ slotKeys: barSlots.slotKeys,
6649
+ slotKey: barSlots.slotOf(series.label),
6650
+ thickness: barSlots.thicknessOf(series.label),
6344
6651
  groupPadding
6345
6652
  }, series.label))
6346
6653
  });
@@ -6370,7 +6677,7 @@ const BarLayer = ({ chartId, overlapSlots, selectedBar, primaryEntries, primaryK
6370
6677
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [bars, selectedBar && /* @__PURE__ */ jsx(SelectedBarRing, {
6371
6678
  chartId,
6372
6679
  selected: selectedBar,
6373
- slotKeys: overlapSlots?.slotKeys ?? primaryKeys,
6680
+ slotKeys: barSlots?.slotKeys ?? primaryKeys,
6374
6681
  groupPadding,
6375
6682
  horizontal,
6376
6683
  xAccessor,
@@ -6506,28 +6813,36 @@ function getOverlapBarColors(series, colors, slotColors, background) {
6506
6813
  });
6507
6814
  return barColors;
6508
6815
  }
6509
- // src/charts/bar-chart/private/use-overlap-slots.ts
6816
+ // src/charts/bar-chart/private/use-bar-slots.ts
6510
6817
  /**
6511
- * Whether two data points sit at the same category: the same label, or the same date.
6818
+ * Lays out the visible series in slots: overlap layers primaries and comparisons in two, stacked puts every primary in one.
6512
6819
  *
6513
- * @param point - A data point.
6514
- * @param category - The data point naming the category.
6515
- * @return Whether `point` is at `category`.
6516
- */
6517
- function isSameCategory(point, category) {
6518
- return category.label ? point.label === category.label : !!category.date && !!point.date && point.date.getTime() === category.date.getTime();
6519
- }
6520
- /**
6521
- * Lays out the visible series of an overlap layout in slots and layers.
6522
- *
6523
- * @param enabled - Whether the chart draws an overlap layout.
6820
+ * @param layout - How the chart places its series in a category.
6524
6821
  * @param seriesWithVisibility - Every series, with its index and whether it is visible.
6525
- * @return The layout, or undefined when the chart is not an overlap layout.
6822
+ * @return The slots, or undefined for a grouped layout.
6526
6823
  */
6527
- function useOverlapSlots(enabled, seriesWithVisibility) {
6824
+ function useBarSlots(layout, seriesWithVisibility) {
6528
6825
  return useMemo(() => {
6529
- if (!enabled) return;
6826
+ if (layout === "grouped") return;
6530
6827
  const visible = seriesWithVisibility.filter(({ isVisible }) => isVisible);
6828
+ if (layout === "stacked") {
6829
+ const entries = visible.map(({ series, index }) => ({
6830
+ series,
6831
+ index
6832
+ }));
6833
+ const slotKeys = [PRIMARY_SLOT];
6834
+ const slotOf = () => PRIMARY_SLOT;
6835
+ return {
6836
+ kind: "stacked",
6837
+ stack: getStackLayout(entries.map(({ series }) => series)),
6838
+ entries,
6839
+ keys: entries.map(({ series }) => series.label),
6840
+ slotKeys,
6841
+ slotOf,
6842
+ thicknessOf: () => 1,
6843
+ positions: getStopPositions(entries, slotKeys, slotOf)
6844
+ };
6845
+ }
6531
6846
  const placements = getOverlapPlacements(visible.map(({ series }) => series));
6532
6847
  const placed = visible.map(({ series, index }, position) => ({
6533
6848
  entry: {
@@ -6544,6 +6859,7 @@ function useOverlapSlots(enabled, seriesWithVisibility) {
6544
6859
  const showsComparisons = entries.some(({ series }) => slotOf(series.label) === COMPARISON_SLOT);
6545
6860
  const slotKeys = [...hasPrimaries ? [PRIMARY_SLOT] : [], ...showsComparisons ? [COMPARISON_SLOT] : []];
6546
6861
  return {
6862
+ kind: "overlap",
6547
6863
  entries,
6548
6864
  keys: entries.map(({ series }) => series.label),
6549
6865
  slotKeys,
@@ -6551,16 +6867,7 @@ function useOverlapSlots(enabled, seriesWithVisibility) {
6551
6867
  thicknessOf,
6552
6868
  positions: getStopPositions(entries, slotKeys, slotOf)
6553
6869
  };
6554
- }, [enabled, seriesWithVisibility]);
6555
- }
6556
- /**
6557
- * The category a data point sits at, as a key two points share when `isSameCategory` holds.
6558
- *
6559
- * @param point - A data point.
6560
- * @return The category key.
6561
- */
6562
- function categoryKey(point) {
6563
- return point.label ? `label:${point.label}` : `date:${point.date?.getTime()}`;
6870
+ }, [layout, seriesWithVisibility]);
6564
6871
  }
6565
6872
  /**
6566
6873
  * Lists a stop for every slot at every category that slot draws a bar at, category by category.
@@ -6619,7 +6926,7 @@ function membersAt(entries, category, stopKey) {
6619
6926
  /**
6620
6927
  * The slot a keyboard index selects, and every bar at its category.
6621
6928
  *
6622
- * @param slots - The overlap layout.
6929
+ * @param slots - The overlap or stacked slots.
6623
6930
  * @param selectedIndex - The keyboard index into `slots.positions`.
6624
6931
  * @return The selected slot, or undefined when nothing is selected or drawn there.
6625
6932
  */
@@ -6633,25 +6940,26 @@ function getSelectedSlot(slots, selectedIndex) {
6633
6940
  data: slotBars.map(({ datum }) => datum),
6634
6941
  slotKey,
6635
6942
  thickness: Math.max(...slotBars.map(({ key }) => slots.thicknessOf(key))),
6636
- members
6943
+ members,
6944
+ ...slots.kind === "stacked" && { valueExtent: slots.stack.extentAt(category) }
6637
6945
  };
6638
6946
  }
6639
6947
  // src/charts/bar-chart/private/use-bar-stops.ts
6640
6948
  /**
6641
- * Lays out the keyboard stops: one per slot and category in an overlap layout, else one per primary bar, series-major within each category.
6949
+ * Lays out the keyboard stops: one per slot and category in a slotted layout, else one per primary bar, series-major within each category.
6642
6950
  *
6643
- * @param overlapSlots - The overlap layout, or undefined for a grouped one.
6951
+ * @param barSlots - The overlap or stacked slots, or undefined for a grouped layout.
6644
6952
  * @param primaryEntries - The visible primary series.
6645
6953
  * @return The stops.
6646
6954
  */
6647
- function useBarStops(overlapSlots, primaryEntries) {
6648
- const series = useMemo(() => overlapSlots ? [] : primaryEntries.map((entry) => entry.series), [overlapSlots, primaryEntries]);
6955
+ function useBarStops(barSlots, primaryEntries) {
6956
+ const series = useMemo(() => barSlots ? [] : primaryEntries.map((entry) => entry.series), [barSlots, primaryEntries]);
6649
6957
  return {
6650
- count: overlapSlots?.positions.length ?? Math.max(0, ...series.map((item) => item.data.length)) * series.length,
6651
- key: useMemo(() => JSON.stringify(overlapSlots?.keys ?? series.map((item) => item.label)), [overlapSlots, series]),
6958
+ count: barSlots?.positions.length ?? Math.max(0, ...series.map((item) => item.data.length)) * series.length,
6959
+ key: useMemo(() => JSON.stringify(barSlots?.keys ?? series.map((item) => item.label)), [barSlots, series]),
6652
6960
  barAt: useCallback((stop) => {
6653
- if (overlapSlots) {
6654
- const position = overlapSlots.positions[stop];
6961
+ if (barSlots) {
6962
+ const position = barSlots.positions[stop];
6655
6963
  return position && {
6656
6964
  datum: position.datum,
6657
6965
  index: position.dataPointIndex,
@@ -6667,17 +6975,17 @@ function useBarStops(overlapSlots, primaryEntries) {
6667
6975
  index,
6668
6976
  key: item.label
6669
6977
  } : void 0;
6670
- }, [overlapSlots, series]),
6978
+ }, [barSlots, series]),
6671
6979
  stopOf: useCallback((seriesKey, dataPointIndex) => {
6672
- if (overlapSlots) {
6673
- const hovered = overlapSlots.entries.find((entry) => entry.series.label === seriesKey)?.series.data[dataPointIndex];
6674
- const slotKey = overlapSlots.slotOf(seriesKey);
6675
- const stop = hovered ? overlapSlots.positions.findIndex((position) => position.slotKey === slotKey && isSameCategory(position.datum, hovered)) : -1;
6980
+ if (barSlots) {
6981
+ const hovered = barSlots.entries.find((entry) => entry.series.label === seriesKey)?.series.data[dataPointIndex];
6982
+ const slotKey = barSlots.slotOf(seriesKey);
6983
+ const stop = hovered ? barSlots.positions.findIndex((position) => position.slotKey === slotKey && isSameCategory(position.datum, hovered)) : -1;
6676
6984
  return stop >= 0 ? stop : void 0;
6677
6985
  }
6678
6986
  const seriesIndex = series.findIndex((item) => item.label === seriesKey);
6679
6987
  return seriesIndex >= 0 ? dataPointIndex * series.length + seriesIndex : void 0;
6680
- }, [overlapSlots, series])
6988
+ }, [barSlots, series])
6681
6989
  };
6682
6990
  }
6683
6991
  /**
@@ -6832,10 +7140,23 @@ function nearestBandIndex(data, accessor, scale, position) {
6832
7140
  return nearest;
6833
7141
  }
6834
7142
  /**
7143
+ * How far a pointer sits from a stacked segment along the value axis.
7144
+ *
7145
+ * @param segment - The segment, or undefined when its series has no reading there.
7146
+ * @param scale - The value scale.
7147
+ * @param position - Pointer coordinate on the value axis.
7148
+ * @return 0 inside the segment, Infinity without one, otherwise the gap to its nearer end.
7149
+ */
7150
+ function distanceToSegment(segment, scale, position) {
7151
+ if (!segment) return Infinity;
7152
+ const [low, high] = [segment.start, segment.end].map((value) => getValueScalePosition(scale, value)).sort((a, b) => a - b);
7153
+ return Math.max(low - position, 0, position - high);
7154
+ }
7155
+ /**
6835
7156
  * Correct visx's range-based band inversion, which omits outer padding.
6836
7157
  * @param root0 - Registered series selection.
6837
7158
  * @param root0.keys - Visible series keys, back to front where bars overlap.
6838
- * @param root0.slots - Where series share slots: the slots of a category, in the order the band lays them out, and the slot each series sits in.
7159
+ * @param root0.slots - Where series share slots: the slots of a category, in the order the band lays them out, the slot each series sits in, and for a stack where each segment runs.
6839
7160
  * @param root0.groupPadding - Padding between grouped bars.
6840
7161
  * @param root0.withTooltips - Whether pointer events update the tooltip.
6841
7162
  * @param root0.onPointerDown - Receives the corrected pointer-down datum.
@@ -6847,6 +7168,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6847
7168
  const { xScale, yScale, dataRegistry, horizontal } = useContext(DataContext);
6848
7169
  const { showTooltip, hideTooltip, updateTooltip } = useContext(TooltipContext);
6849
7170
  const scale = horizontal ? yScale : xScale;
7171
+ const valueScale = horizontal ? xScale : yScale;
6850
7172
  const bandwidth = scale?.bandwidth?.() ?? 0;
6851
7173
  const groupScale = useMemo(() => createGroupScale(slots?.keys ?? keys, bandwidth, groupPadding), [
6852
7174
  slots,
@@ -6871,6 +7193,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6871
7193
  const start = band + Number(groupScale(slots ? slots.slotOf(key) : key));
6872
7194
  const end = start + groupScale.step();
6873
7195
  const distance = position >= start && position <= end ? 0 : Math.abs(position - (start + end) / 2);
7196
+ const valueDistance = slots?.stack && valueScale ? distanceToSegment(slots.stack.segmentOf(key, datum), valueScale, horizontal ? point.x : point.y) : 0;
6874
7197
  bands.push(band);
6875
7198
  selections.push({
6876
7199
  event: params.event,
@@ -6878,8 +7201,8 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6878
7201
  datum,
6879
7202
  index,
6880
7203
  svgPoint: point,
6881
- distanceX: horizontal ? 0 : distance,
6882
- distanceY: horizontal ? distance : 0
7204
+ distanceX: horizontal ? valueDistance : distance,
7205
+ distanceY: horizontal ? distance : valueDistance
6883
7206
  });
6884
7207
  }
6885
7208
  if (!slots) return selections;
@@ -6888,6 +7211,7 @@ function BandTooltip({ keys, slots, groupPadding, withTooltips, onPointerDown, o
6888
7211
  return selections.filter((_, index) => bands[index] === hoveredBand);
6889
7212
  }, [
6890
7213
  scale,
7214
+ valueScale,
6891
7215
  dataRegistry,
6892
7216
  horizontal,
6893
7217
  keys,
@@ -6981,6 +7305,16 @@ function useBarColors() {
6981
7305
  data,
6982
7306
  index
6983
7307
  }).color);
7308
+ if (layout === "stacked") {
7309
+ const drawn = getDrawnSeries(series, layout);
7310
+ return series.map((data, index) => {
7311
+ const drawnIndex = drawn.indexOf(data);
7312
+ return drawnIndex === -1 ? colors[index] : getElementStyles({
7313
+ data,
7314
+ index: drawnIndex
7315
+ }).color;
7316
+ });
7317
+ }
6984
7318
  if (layout !== "overlap") return comparisonOpacity === void 0 ? getGroupedBarColors(series, colors, backgroundColor) : colors;
6985
7319
  return getOverlapBarColors(series, colors, [getElementStyles({ index: 0 }).color, getElementStyles({ index: 1 }).color], backgroundColor);
6986
7320
  }, [
@@ -7029,13 +7363,14 @@ function forBarLayout(data, items, layout, seriesColors) {
7029
7363
  /**
7030
7364
  * Builds legend items that match `BarChart`'s bars in a layout, for a custom legend or a chart's own.
7031
7365
  *
7032
- * @param data - The series the chart draws.
7366
+ * @param allData - The chart's series; those the layout does not draw get no item.
7033
7367
  * @param options - The legend options, and the layout the bars are drawn in.
7034
7368
  * @param legendShape - The shape of the legend swatches.
7035
7369
  * @return The legend items.
7036
7370
  */
7037
- function useBarLegendItems(data, options = {}, legendShape) {
7371
+ function useBarLegendItems(allData, options = {}, legendShape) {
7038
7372
  const { layout } = options;
7373
+ const data = useMemo(() => getDrawnSeries(allData, layout), [allData, layout]);
7039
7374
  const getBarColors = useBarColors();
7040
7375
  const seriesColors = useMemo(() => layout ? getBarColors(data, { layout }) : void 0, [
7041
7376
  data,
@@ -7064,7 +7399,12 @@ const renderTooltipRow = (label, value) => /* @__PURE__ */ jsx("div", {
7064
7399
  className: bar_chart_module_default["bar-chart__tooltip-row"],
7065
7400
  children: sprintf(__("%1$s: %2$s", "jetpack-charts"), label, value)
7066
7401
  });
7067
- const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = false, showLegend = false, legend = {}, gridVisibility: gridVisibilityProp, renderTooltip, tooltipPlacement, tooltipAnchorTop, tooltipStyle, barClassName, options = {}, orientation = "vertical", layout = "grouped", withPatterns = false, showZeroValues = false, withBandHighlight = false, onBandHighlightChange, defaultHiddenSeries, animation, children, gap = "md", onPointerDown, onPointerUp, onDatumActivate }) => {
7402
+ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, height, className, margin, withTooltips = false, showLegend = false, legend = {}, gridVisibility: gridVisibilityProp, renderTooltip, tooltipPlacement, tooltipAnchorTop, tooltipStyle, barClassName, options = {}, orientation = "vertical", layout = "grouped", withPatterns = false, showZeroValues = false, withBandHighlight = false, onBandHighlightChange, defaultHiddenSeries, animation, children, gap = "md", compactWhenShort = false, onPointerDown, onPointerUp, onDatumActivate }) => {
7403
+ if (layout === "stacked" && showZeroValues) warnOnce("bar-chart-stacked-zero-values", "BarChart: showZeroValues has no effect in a stacked layout.");
7404
+ if (layout === "stacked" && data?.some((series) => series.options?.type === "comparison")) warnOnce("bar-chart-stacked-comparison", "BarChart: a stacked layout does not draw comparison series yet.");
7405
+ const valueScaleOptions = orientation === "horizontal" ? options.xScale : options.yScale;
7406
+ if (layout === "stacked" && valueScaleOptions?.type && valueScaleOptions.type !== "linear") warnOnce(`bar-chart-stacked-${valueScaleOptions.type}-scale`, `BarChart: a stacked layout draws on a linear value scale, so the ${valueScaleOptions.type} scale is ignored.`);
7407
+ if (layout === "stacked" && valueScaleOptions?.zero === false && !valueScaleOptions.domain) warnOnce("bar-chart-stacked-zero", "BarChart: every stack starts at zero, so zero: false has no effect in a stacked layout.");
7068
7408
  if (!withTooltips && (withBandHighlight || onBandHighlightChange)) warnOnce("bar-chart-band-highlight-without-tooltips", "BarChart: withBandHighlight and onBandHighlightChange require withTooltips.");
7069
7409
  const legendInteractive = legend.interactive ?? false;
7070
7410
  const legendCollapseGroups = legend.collapseGroups ?? false;
@@ -7072,13 +7412,15 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7072
7412
  const legendComparisonSeriesItems = legend.comparisonSeriesItems;
7073
7413
  const horizontal = orientation === "horizontal";
7074
7414
  const isOverlap = layout === "overlap";
7415
+ const isStacked = layout === "stacked";
7075
7416
  const chartId = useChartId(providedChartId);
7076
7417
  const hiddenSeries = useDefaultHiddenSeries(chartId, defaultHiddenSeries);
7077
7418
  const isSeriesVisible = useCallback((seriesLabel) => !hiddenSeries.has(seriesLabel), [hiddenSeries]);
7078
7419
  const theme = useXYChartTheme(data);
7079
- const dataSorted = useChartDataTransform(data);
7420
+ const transformedData = useChartDataTransform(data);
7421
+ const dataSorted = useMemo(() => getDrawnSeries(transformedData, layout), [layout, transformedData]);
7080
7422
  const dataWithVisibleZeros = useZeroValueDisplay(dataSorted, {
7081
- enabled: showZeroValues,
7423
+ enabled: showZeroValues && !isStacked,
7082
7424
  valueAxisLength: horizontal ? width : height
7083
7425
  });
7084
7426
  const legendItems = useBarLegendItems(dataSorted, useMemo(() => ({
@@ -7102,13 +7444,39 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7102
7444
  if (providerTheme.barChart?.barStyles?.comparison?.opacity !== void 0) warnOnce("bar-chart-comparison-opacity", "BarChart: theme.barChart.barStyles.comparison.opacity is deprecated. Comparison bars are opaque; leave it unset.");
7103
7445
  const isSeriesRendered = useCallback((series) => isSeriesVisible(series.label), [isSeriesVisible]);
7104
7446
  const hasWholeNumberValues = useMemo(() => hasOnlyWholeNumbers(dataSorted.filter(isSeriesRendered)), [dataSorted, isSeriesRendered]);
7105
- const chartOptions = useBarChartOptions(dataWithVisibleZeros, horizontal, options, isSeriesRendered);
7447
+ const { isCompact, compactMargin } = useCompactWhenShort(compactWhenShort && !horizontal, height);
7448
+ const resolvedOptions = useMemo(() => isCompact ? {
7449
+ ...options,
7450
+ axis: {
7451
+ ...options.axis,
7452
+ x: {
7453
+ ...options.axis?.x,
7454
+ display: false
7455
+ },
7456
+ y: {
7457
+ ...options.axis?.y,
7458
+ display: false
7459
+ }
7460
+ }
7461
+ } : options, [isCompact, options]);
7462
+ const seriesWithVisibility = useMemo(() => dataWithVisibleZeros.map((series, index) => ({
7463
+ series,
7464
+ index,
7465
+ isVisible: isSeriesRendered(series)
7466
+ })), [dataWithVisibleZeros, isSeriesRendered]);
7467
+ const allSeriesHidden = useMemo(() => {
7468
+ return seriesWithVisibility.every(({ isVisible }) => !isVisible);
7469
+ }, [seriesWithVisibility]);
7470
+ const primaryEntries = useMemo(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
7471
+ const barSlots = useBarSlots(layout, seriesWithVisibility);
7472
+ const chartOptions = useBarChartOptions(dataWithVisibleZeros, horizontal, resolvedOptions, isSeriesRendered, barSlots?.kind === "stacked" ? barSlots.stack : void 0);
7106
7473
  const valueAxis = horizontal ? chartOptions.axis.x : chartOptions.axis.y;
7107
7474
  const callerValueDomain = horizontal ? options.xScale?.domain : options.yScale?.domain;
7108
- const wholeNumberTicksProps = {
7475
+ const valueTickDecimals = getTickDecimals(hasWholeNumberValues, chartOptions.valueTickDecimals);
7476
+ const tickDecimalsProps = {
7109
7477
  axis: horizontal ? "x" : "y",
7110
7478
  numTicks: valueAxis.numTicks,
7111
- enabled: hasWholeNumberValues && !valueAxis.tickValues && !callerValueDomain
7479
+ decimals: !valueAxis.tickValues && !callerValueDomain ? valueTickDecimals : void 0
7112
7480
  };
7113
7481
  const defaultMargin = useChartMargin(height, chartOptions, dataSorted, theme, horizontal);
7114
7482
  const chartRef = useRef(null);
@@ -7119,18 +7487,8 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7119
7487
  }, [height]);
7120
7488
  const [selectedIndex, setSelectedIndex] = useState(void 0);
7121
7489
  const [isNavigating, setIsNavigating] = useState(false);
7122
- const seriesWithVisibility = useMemo(() => dataWithVisibleZeros.map((series, index) => ({
7123
- series,
7124
- index,
7125
- isVisible: isSeriesRendered(series)
7126
- })), [dataWithVisibleZeros, isSeriesRendered]);
7127
- const allSeriesHidden = useMemo(() => {
7128
- return seriesWithVisibility.every(({ isVisible }) => !isVisible);
7129
- }, [seriesWithVisibility]);
7130
- const primaryEntries = useMemo(() => seriesWithVisibility.filter(({ isVisible, series }) => isVisible && series.options?.type !== "comparison"), [seriesWithVisibility]);
7131
- const overlapSlots = useOverlapSlots(isOverlap, seriesWithVisibility);
7132
7490
  const primaryKeys = useMemo(() => primaryEntries.map(({ series }) => series.label), [primaryEntries]);
7133
- const stops = useBarStops(overlapSlots, primaryEntries);
7491
+ const stops = useBarStops(barSlots, primaryEntries);
7134
7492
  const { barAt, stopOf } = stops;
7135
7493
  const activateSelectedBar = useCallback((stop) => {
7136
7494
  const bar = barAt(stop);
@@ -7151,7 +7509,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7151
7509
  if (stop !== void 0) onChartPointerMove(stop);
7152
7510
  }, [stopOf, onChartPointerMove]);
7153
7511
  const comparisonEntries = useMemo(() => {
7154
- if (isOverlap) return [];
7512
+ if (barSlots) return [];
7155
7513
  const primaryByGroup = new Map(primaryEntries.map(({ series, index }) => [series.group, {
7156
7514
  label: series.label,
7157
7515
  index
@@ -7172,7 +7530,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7172
7530
  });
7173
7531
  return entries;
7174
7532
  }, [
7175
- isOverlap,
7533
+ barSlots,
7176
7534
  seriesWithVisibility,
7177
7535
  primaryEntries,
7178
7536
  primaryKeys
@@ -7238,6 +7596,32 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7238
7596
  })]
7239
7597
  });
7240
7598
  }, [chartOptions.tooltip, dataSorted]);
7599
+ const renderStackedTooltip = useCallback(({ tooltipData }) => {
7600
+ const nearestDatum = tooltipData?.nearestDatum?.datum;
7601
+ if (!nearestDatum || barSlots?.kind !== "stacked") return null;
7602
+ const datumByKey = tooltipData?.datumByKey ?? {};
7603
+ const categoryLabel = chartOptions.tooltip.labelFormatter(nearestDatum.label || (nearestDatum.date ? nearestDatum.date.getTime() : 0), 0, []);
7604
+ const rows = [...barSlots.entries].reverse().flatMap(({ series }) => {
7605
+ const datum = datumByKey[series.label]?.datum;
7606
+ return datum ? [{
7607
+ label: series.label,
7608
+ datum
7609
+ }] : [];
7610
+ });
7611
+ const readings = rows.filter(({ datum }) => isBarRendered(datum)).length;
7612
+ const [negative, positive] = barSlots.stack.extentAt(nearestDatum);
7613
+ return /* @__PURE__ */ jsxs("div", {
7614
+ className: bar_chart_module_default["bar-chart__tooltip"],
7615
+ children: [
7616
+ /* @__PURE__ */ jsx("div", {
7617
+ className: bar_chart_module_default["bar-chart__tooltip-header"],
7618
+ children: categoryLabel
7619
+ }),
7620
+ rows.map(({ label, datum }) => /* @__PURE__ */ jsx(Fragment, { children: renderTooltipRow(label, formatReading(datum.value)) }, label)),
7621
+ readings > 1 && renderTooltipRow(__("Total", "jetpack-charts"), formatReading(negative + positive))
7622
+ ]
7623
+ });
7624
+ }, [chartOptions.tooltip, barSlots]);
7241
7625
  const renderDefaultTooltip = useCallback(({ tooltipData }) => {
7242
7626
  const nearestDatum = tooltipData?.nearestDatum?.datum;
7243
7627
  if (!nearestDatum) return null;
@@ -7309,24 +7693,25 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7309
7693
  }
7310
7694
  `;
7311
7695
  }, [chartId]);
7312
- const overlapBandSlots = useMemo(() => overlapSlots && {
7313
- keys: overlapSlots.slotKeys,
7314
- slotOf: overlapSlots.slotOf
7315
- }, [overlapSlots]);
7316
- const selectedSlot = useMemo(() => getSelectedSlot(overlapSlots, selectedIndex), [overlapSlots, selectedIndex]);
7696
+ const barBandSlots = useMemo(() => barSlots && {
7697
+ keys: barSlots.slotKeys,
7698
+ slotOf: barSlots.slotOf,
7699
+ stack: barSlots.kind === "stacked" ? barSlots.stack : void 0
7700
+ }, [barSlots]);
7701
+ const selectedSlot = useMemo(() => getSelectedSlot(barSlots, selectedIndex), [barSlots, selectedIndex]);
7317
7702
  const selectedGroup = useMemo(() => {
7318
- const stop = overlapSlots || selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7703
+ const stop = barSlots || selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7319
7704
  if (!stop) return;
7320
7705
  return membersAt(primaryEntries, stop.datum, stop.key);
7321
7706
  }, [
7322
- overlapSlots,
7707
+ barSlots,
7323
7708
  selectedIndex,
7324
7709
  barAt,
7325
7710
  primaryEntries
7326
7711
  ]);
7327
7712
  const selectedMembers = selectedSlot?.members ?? selectedGroup;
7328
7713
  const selectedBar = useMemo(() => {
7329
- if (overlapSlots) return selectedSlot;
7714
+ if (barSlots) return selectedSlot;
7330
7715
  const bar = selectedIndex === void 0 ? void 0 : barAt(selectedIndex);
7331
7716
  return bar && isBarRendered(bar.datum) ? {
7332
7717
  data: [bar.datum],
@@ -7334,7 +7719,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7334
7719
  thickness: 1
7335
7720
  } : void 0;
7336
7721
  }, [
7337
- overlapSlots,
7722
+ barSlots,
7338
7723
  selectedSlot,
7339
7724
  selectedIndex,
7340
7725
  barAt
@@ -7357,9 +7742,9 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7357
7742
  className: clsx("bar-chart", bar_chart_module_default["bar-chart"]),
7358
7743
  children: error
7359
7744
  });
7360
- const gridVisibility = gridVisibilityProp ?? chartOptions.gridVisibility;
7745
+ const gridVisibility = isCompact ? "none" : gridVisibilityProp ?? chartOptions.gridVisibility;
7361
7746
  const legendPosition = legend.position ?? "bottom";
7362
- const legendElement = showLegend && /* @__PURE__ */ jsx(Legend, {
7747
+ const legendElement = showLegend && !isCompact && /* @__PURE__ */ jsx(Legend, {
7363
7748
  orientation: legend.orientation ?? "horizontal",
7364
7749
  position: legendPosition,
7365
7750
  alignment: legend.alignment ?? "center",
@@ -7382,9 +7767,12 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7382
7767
  children: /* @__PURE__ */ jsx(ChartLayout, {
7383
7768
  legendPosition,
7384
7769
  legendElement,
7385
- legendChildren,
7770
+ legendChildren: isCompact ? [] : legendChildren,
7386
7771
  gap,
7387
- className: clsx("bar-chart", bar_chart_module_default["bar-chart"], { [bar_chart_module_default[`bar-chart--animated${horizontal ? "-horizontal" : ""}`]]: animation && !prefersReducedMotion }, className),
7772
+ className: clsx("bar-chart", bar_chart_module_default["bar-chart"], {
7773
+ [bar_chart_module_default["bar-chart--stacked"]]: isStacked,
7774
+ [bar_chart_module_default[`bar-chart--animated${horizontal ? "-horizontal" : ""}`]]: animation && !prefersReducedMotion
7775
+ }, className),
7388
7776
  style: {
7389
7777
  width,
7390
7778
  height
@@ -7411,6 +7799,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7411
7799
  height: chartHeight,
7412
7800
  margin: {
7413
7801
  ...defaultMargin,
7802
+ ...compactMargin,
7414
7803
  ...margin
7415
7804
  },
7416
7805
  xScale,
@@ -7423,8 +7812,8 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7423
7812
  horizontal,
7424
7813
  onChange: onBandHighlightChange
7425
7814
  }),
7426
- !allSeriesHidden && /* @__PURE__ */ jsx(WholeNumberTicks, {
7427
- ...wholeNumberTicksProps,
7815
+ !allSeriesHidden && /* @__PURE__ */ jsx(TickDecimals, {
7816
+ ...tickDecimalsProps,
7428
7817
  children: (valueTicks) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Grid, {
7429
7818
  columns: gridVisibility.includes("y"),
7430
7819
  rows: false,
@@ -7443,7 +7832,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7443
7832
  y: chartHeight / 2,
7444
7833
  width,
7445
7834
  height: chartHeight,
7446
- children: getAllHiddenMessage(legendInteractive, "series")
7835
+ children: getAllHiddenMessage(legendInteractive && !isCompact, "series")
7447
7836
  }) : null,
7448
7837
  /* @__PURE__ */ jsx(ComparisonBars, {
7449
7838
  comparisonEntries,
@@ -7457,7 +7846,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7457
7846
  }),
7458
7847
  /* @__PURE__ */ jsx(BarLayer, {
7459
7848
  chartId,
7460
- overlapSlots,
7849
+ barSlots,
7461
7850
  selectedBar,
7462
7851
  primaryEntries,
7463
7852
  primaryKeys,
@@ -7469,16 +7858,16 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7469
7858
  yAccessor: chartOptions.accessors.yAccessor
7470
7859
  }),
7471
7860
  (withTooltips || onPointerDown || onPointerUp) && /* @__PURE__ */ jsx(BandTooltip, {
7472
- keys: overlapSlots?.keys ?? primaryKeys,
7473
- slots: overlapBandSlots,
7861
+ keys: barSlots?.keys ?? primaryKeys,
7862
+ slots: barBandSlots,
7474
7863
  groupPadding,
7475
7864
  withTooltips,
7476
7865
  onPointerDown,
7477
7866
  onPointerUp,
7478
7867
  onPointerMove: handlePointerMove
7479
7868
  }),
7480
- !allSeriesHidden && /* @__PURE__ */ jsx(WholeNumberTicks, {
7481
- ...wholeNumberTicksProps,
7869
+ !allSeriesHidden && /* @__PURE__ */ jsx(TickDecimals, {
7870
+ ...tickDecimalsProps,
7482
7871
  children: (valueTicks) => /* @__PURE__ */ jsxs(Fragment$1, { children: [chartOptions.axis.x.display !== false && /* @__PURE__ */ jsx(Axis, {
7483
7872
  ...chartOptions.axis.x,
7484
7873
  ...horizontal && valueTicks ? { tickValues: valueTicks } : {}
@@ -7495,7 +7884,7 @@ const BarChartInternal = ({ data, ariaLabel, chartId: providedChartId, width, he
7495
7884
  detectBounds: true,
7496
7885
  snapTooltipToDatumX: true,
7497
7886
  snapTooltipToDatumY: true,
7498
- renderTooltip: renderTooltip || (isOverlap ? renderOverlapTooltip : renderDefaultTooltip),
7887
+ renderTooltip: renderTooltip || isStacked && renderStackedTooltip || (isOverlap ? renderOverlapTooltip : renderDefaultTooltip),
7499
7888
  selectedIndex,
7500
7889
  tooltipRef,
7501
7890
  keyboardFocusedClassName: bar_chart_module_default["bar-chart__tooltip--keyboard-focused"],
@@ -9850,12 +10239,75 @@ function isPlainObject(o) {
9850
10239
  if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
9851
10240
  return true;
9852
10241
  }
9853
- // ../../../node_modules/.pnpm/@wordpress+warning@4.0.0/node_modules/@wordpress/warning/build-module/utils.mjs
9854
- var logged = /* @__PURE__ */ new Set();
9855
- // ../../../node_modules/.pnpm/@wordpress+warning@4.0.0/node_modules/@wordpress/warning/build-module/index.mjs
10242
+ // ../../../node_modules/.pnpm/lower-case@2.0.2/node_modules/lower-case/dist.es2015/index.js
10243
+ /**
10244
+ * Lower case as a function.
10245
+ */
10246
+ function lowerCase(str) {
10247
+ return str.toLowerCase();
10248
+ }
10249
+ // ../../../node_modules/.pnpm/no-case@3.0.4/node_modules/no-case/dist.es2015/index.js
10250
+ var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
10251
+ var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
10252
+ /**
10253
+ * Normalize the string into something other libraries can manipulate easier.
10254
+ */
10255
+ function noCase(input, options) {
10256
+ if (options === void 0) options = {};
10257
+ var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
10258
+ var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
10259
+ var start = 0;
10260
+ var end = result.length;
10261
+ while (result.charAt(start) === "\0") start++;
10262
+ while (result.charAt(end - 1) === "\0") end--;
10263
+ return result.slice(start, end).split("\0").map(transform).join(delimiter);
10264
+ }
10265
+ /**
10266
+ * Replace `re` in the input string with the replacement value.
10267
+ */
10268
+ function replace(input, re, value) {
10269
+ if (re instanceof RegExp) return input.replace(re, value);
10270
+ return re.reduce(function(input, re) {
10271
+ return input.replace(re, value);
10272
+ }, input);
10273
+ }
10274
+ // ../../../node_modules/.pnpm/dot-case@3.0.4/node_modules/dot-case/dist.es2015/index.js
10275
+ function dotCase(input, options) {
10276
+ if (options === void 0) options = {};
10277
+ return noCase(input, __assign({ delimiter: "." }, options));
10278
+ }
10279
+ // ../../../node_modules/.pnpm/param-case@3.0.4/node_modules/param-case/dist.es2015/index.js
10280
+ function paramCase(input, options) {
10281
+ if (options === void 0) options = {};
10282
+ return dotCase(input, __assign({ delimiter: "-" }, options));
10283
+ }
10284
+ // ../../../node_modules/.pnpm/@wordpress+warning@4.1.0/node_modules/@wordpress/warning/build-module/utils.mjs
10285
+ /**
10286
+ * Object map tracking messages which have been logged, for use in ensuring a
10287
+ * message is only logged once.
10288
+ */
10289
+ const logged = /* @__PURE__ */ new Set();
10290
+ // ../../../node_modules/.pnpm/@wordpress+warning@4.1.0/node_modules/@wordpress/warning/build-module/index.mjs
9856
10291
  function isDev() {
9857
10292
  return globalThis.SCRIPT_DEBUG === true;
9858
10293
  }
10294
+ /**
10295
+ * Shows a warning with `message` if environment is not `production`.
10296
+ *
10297
+ * @param message Message to show in the warning.
10298
+ *
10299
+ * @example
10300
+ * ```js
10301
+ * import warning from '@wordpress/warning';
10302
+ *
10303
+ * function MyComponent( props ) {
10304
+ * if ( ! props.title ) {
10305
+ * warning( '`props.title` was not passed' );
10306
+ * }
10307
+ * ...
10308
+ * }
10309
+ * ```
10310
+ */
9859
10311
  function warning(message) {
9860
10312
  if (!isDev()) return;
9861
10313
  if (logged.has(message)) return;
@@ -9911,7 +10363,15 @@ var require_es6 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
9911
10363
  return a !== a && b !== b;
9912
10364
  };
9913
10365
  }));
9914
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/hooks/use-update-effect.mjs
10366
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/utils/hooks/use-update-effect.mjs
10367
+ /**
10368
+ * A `React.useEffect` that will not run on the first render.
10369
+ * Source:
10370
+ * https://github.com/ariakit/ariakit/blob/main/packages/ariakit-react-core/src/utils/hooks.ts
10371
+ *
10372
+ * @param effect
10373
+ * @param deps
10374
+ */
9915
10375
  function useUpdateEffect(effect, deps) {
9916
10376
  const mountedRef = useRef$1(false);
9917
10377
  useEffect$1(() => {
@@ -9922,23 +10382,48 @@ function useUpdateEffect(effect, deps) {
9922
10382
  mountedRef.current = false;
9923
10383
  }, []);
9924
10384
  }
9925
- var use_update_effect_default = useUpdateEffect;
9926
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/context-system-provider.mjs
10385
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/context-system-provider.mjs
9927
10386
  var import_es6 = /* @__PURE__ */ __toESM(require_es6(), 1);
9928
- var ComponentsContext = createContext$1({});
10387
+ const ComponentsContext = createContext$1({});
9929
10388
  ComponentsContext.displayName = "ComponentsContext";
9930
- var useComponentsContext = () => useContext$1(ComponentsContext);
10389
+ const useComponentsContext = () => useContext$1(ComponentsContext);
10390
+ /**
10391
+ * Consolidates incoming ContextSystem values with a (potential) parent ContextSystem value.
10392
+ *
10393
+ * Note: This function will warn if it detects an un-memoized `value`
10394
+ *
10395
+ * @param {Object} props
10396
+ * @param {Record<string, any>} props.value
10397
+ * @return {Record<string, any>} The consolidated value.
10398
+ */
9931
10399
  function useContextSystemBridge({ value }) {
9932
10400
  const parentContext = useComponentsContext();
9933
10401
  const valueRef = useRef$1(value);
9934
- use_update_effect_default(() => {
10402
+ useUpdateEffect(() => {
9935
10403
  if ((0, import_es6.default)(valueRef.current, value) && valueRef.current !== value) warning(`Please memoize your context: ${JSON.stringify(value)}`);
9936
10404
  }, [value]);
9937
10405
  return useMemo$1(() => {
9938
10406
  return deepmerge(parentContext ?? {}, value ?? {}, { isMergeableObject: isPlainObject });
9939
10407
  }, [parentContext, value]);
9940
10408
  }
9941
- var BaseContextSystemProvider = ({ children, value }) => {
10409
+ /**
10410
+ * A Provider component that can modify props for connected components within
10411
+ * the Context system.
10412
+ *
10413
+ * @example
10414
+ * ```jsx
10415
+ * <ContextSystemProvider value={{ Button: { size: 'small' }}}>
10416
+ * <Button>...</Button>
10417
+ * </ContextSystemProvider>
10418
+ * ```
10419
+ *
10420
+ * @template {Record<string, any>} T
10421
+ * @param {Object} options
10422
+ * @param {React.ReactNode} options.children Children to render.
10423
+ * @param {T} options.value Props to render into connected components.
10424
+ * @return {React.JSX.Element} A Provider wrapped component.
10425
+ */
10426
+ const BaseContextSystemProvider = ({ children, value }) => {
9942
10427
  const contextValue = useContextSystemBridge({ value });
9943
10428
  return /* @__PURE__ */ jsx(ComponentsContext.Provider, {
9944
10429
  value: contextValue,
@@ -9946,10 +10431,14 @@ var BaseContextSystemProvider = ({ children, value }) => {
9946
10431
  });
9947
10432
  };
9948
10433
  memo(BaseContextSystemProvider);
9949
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/constants.mjs
9950
- var COMPONENT_NAMESPACE = "data-wp-component";
9951
- var CONNECTED_NAMESPACE = "data-wp-c16t";
9952
- var CONNECT_STATIC_NAMESPACE = "__contextSystemKey__";
10434
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/constants.mjs
10435
+ const COMPONENT_NAMESPACE = "data-wp-component";
10436
+ const CONNECTED_NAMESPACE = "data-wp-c16t";
10437
+ /**
10438
+ * Special key where the connected namespaces are stored.
10439
+ * This is attached to Context connected components as a static property.
10440
+ */
10441
+ const CONNECT_STATIC_NAMESPACE = "__contextSystemKey__";
9953
10442
  // ../../../node_modules/.pnpm/memize@2.1.1/node_modules/memize/dist/index.js
9954
10443
  /**
9955
10444
  * Memize options object.
@@ -10040,12 +10529,26 @@ function memize(fn, options) {
10040
10529
  };
10041
10530
  return memoized;
10042
10531
  }
10043
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/get-styled-class-name-from-key.mjs
10532
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/get-styled-class-name-from-key.mjs
10533
+ /**
10534
+ * Generates the connected component CSS className based on the namespace.
10535
+ *
10536
+ * @param namespace The name of the connected component.
10537
+ * @return The generated CSS className.
10538
+ */
10044
10539
  function getStyledClassName(namespace) {
10045
- return `components-${namespace.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[^A-Z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase()}`;
10540
+ return `components-${paramCase(namespace)}`;
10046
10541
  }
10047
- var getStyledClassNameFromKey = memize(getStyledClassName);
10048
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/context-connect.mjs
10542
+ const getStyledClassNameFromKey = memize(getStyledClassName);
10543
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/context-connect.mjs
10544
+ /**
10545
+ * Forwards ref (React.ForwardRef) and "Connects" (or registers) a component
10546
+ * within the Context system under a specified namespace.
10547
+ *
10548
+ * @param Component The component to register into the Context system.
10549
+ * @param namespace The namespace to register the component under.
10550
+ * @return The connected WordPressComponent
10551
+ */
10049
10552
  function contextConnect(Component, namespace) {
10050
10553
  return _contextConnect(Component, namespace, { forwardsRef: true });
10051
10554
  }
@@ -10053,6 +10556,9 @@ function _contextConnect(Component, namespace, options) {
10053
10556
  const WrappedComponent = options?.forwardsRef ? forwardRef$1(Component) : Component;
10054
10557
  if (typeof namespace === "undefined") warning("contextConnect: Please provide a namespace");
10055
10558
  let mergedNamespace = WrappedComponent["__contextSystemKey__"] || [namespace];
10559
+ /**
10560
+ * Consolidate (merge) namespaces before attaching it to the WrappedComponent.
10561
+ */
10056
10562
  if (Array.isArray(namespace)) mergedNamespace = [...mergedNamespace, ...namespace];
10057
10563
  if (typeof namespace === "string") mergedNamespace = [...mergedNamespace, namespace];
10058
10564
  return Object.assign(WrappedComponent, {
@@ -10061,14 +10567,45 @@ function _contextConnect(Component, namespace, options) {
10061
10567
  selector: `.${getStyledClassNameFromKey(namespace)}`
10062
10568
  });
10063
10569
  }
10064
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/utils.mjs
10570
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/utils.mjs
10571
+ /**
10572
+ * Creates a dedicated context namespace HTML attribute for components.
10573
+ * ns is short for "namespace"
10574
+ *
10575
+ * @example
10576
+ * ```jsx
10577
+ * <div {...ns('Container')} />
10578
+ * ```
10579
+ *
10580
+ * @param componentName The name for the component.
10581
+ * @return A props object with the namespaced HTML attribute.
10582
+ */
10065
10583
  function getNamespace(componentName) {
10066
10584
  return { [COMPONENT_NAMESPACE]: componentName };
10067
10585
  }
10586
+ /**
10587
+ * Creates a dedicated connected context namespace HTML attribute for components.
10588
+ * ns is short for "namespace"
10589
+ *
10590
+ * @example
10591
+ * ```jsx
10592
+ * <div {...cns()} />
10593
+ * ```
10594
+ *
10595
+ * @return A props object with the namespaced HTML attribute.
10596
+ */
10068
10597
  function getConnectedNamespace() {
10069
10598
  return { [CONNECTED_NAMESPACE]: true };
10070
10599
  }
10071
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/context/use-context-system.mjs
10600
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/context/use-context-system.mjs
10601
+ /**
10602
+ * Custom hook that derives registered props from the Context system.
10603
+ * These derived props are then consolidated with incoming component props.
10604
+ *
10605
+ * @param props Incoming props from the component.
10606
+ * @param namespace The namespace to register and to derive context props from.
10607
+ * @return The connected props.
10608
+ */
10072
10609
  function useContextSystem(props, namespace) {
10073
10610
  const contextSystemProps = useComponentsContext();
10074
10611
  if (typeof namespace === "undefined") warning("useContextSystem: Please provide a namespace");
@@ -10089,8 +10626,8 @@ function useContextSystem(props, namespace) {
10089
10626
  finalComponentProps.className = classes;
10090
10627
  return finalComponentProps;
10091
10628
  }
10092
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/visually-hidden/styles.mjs
10093
- var visuallyHidden = {
10629
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/visually-hidden/styles.mjs
10630
+ const visuallyHidden = {
10094
10631
  border: 0,
10095
10632
  clip: "rect(1px, 1px, 1px, 1px)",
10096
10633
  WebkitClipPath: "inset( 50% )",
@@ -10104,10 +10641,10 @@ var visuallyHidden = {
10104
10641
  wordWrap: "normal",
10105
10642
  wordBreak: "normal"
10106
10643
  };
10107
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/polymorphic-element.mjs
10108
- var customAttributeRegExp = /^(data|aria|x)-/i;
10109
- var eventHandlerRegExp = /^on[A-Z]/;
10110
- var svgElementNames = new Set(`animate animateMotion animateTransform circle clipPath defs desc ellipse
10644
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/utils/polymorphic-element.mjs
10645
+ const customAttributeRegExp = /^(data|aria|x)-/i;
10646
+ const eventHandlerRegExp = /^on[A-Z]/;
10647
+ const svgElementNames = new Set(`animate animateMotion animateTransform circle clipPath defs desc ellipse
10111
10648
  feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix
10112
10649
  feDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood
10113
10650
  feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode
@@ -10115,7 +10652,7 @@ var svgElementNames = new Set(`animate animateMotion animateTransform circle cli
10115
10652
  feTurbulence filter foreignObject g image line linearGradient marker mask
10116
10653
  metadata mpath path pattern polygon polyline radialGradient rect set stop svg
10117
10654
  switch symbol text textPath tspan use view`.split(/\s+/));
10118
- var baseElementProps = new Set(`children dangerouslySetInnerHTML key autoFocus defaultValue defaultChecked
10655
+ const baseElementProps = new Set(`children dangerouslySetInnerHTML key autoFocus defaultValue defaultChecked
10119
10656
  innerHTML suppressContentEditableWarning suppressHydrationWarning valueLink
10120
10657
  abbr accept acceptCharset accessKey action allow allowUserMedia
10121
10658
  allowPaymentRequest allowFullScreen allowTransparency alt async autoComplete
@@ -10136,7 +10673,7 @@ var baseElementProps = new Set(`children dangerouslySetInnerHTML key autoFocus d
10136
10673
  datatype inlist prefix property resource typeof vocab autoCapitalize
10137
10674
  autoCorrect autoSave color incremental fallback inert itemProp itemScope
10138
10675
  itemType itemID itemRef on option results security unselectable`.split(/\s+/));
10139
- var svgElementProps = new Set(`accentHeight accumulate additive alignmentBaseline allowReorder alphabetic
10676
+ const svgElementProps = new Set(`accentHeight accumulate additive alignmentBaseline allowReorder alphabetic
10140
10677
  amplitude arabicForm ascent attributeName attributeType autoReverse azimuth
10141
10678
  baseFrequency baselineShift baseProfile bbox begin bias by calcMode capHeight
10142
10679
  clip clipPathUnits clipPath clipRule colorInterpolation
@@ -10171,7 +10708,7 @@ var svgElementProps = new Set(`accentHeight accumulate additive alignmentBaselin
10171
10708
  xlinkActuate xlinkArcrole xlinkHref xlinkRole xlinkShow xlinkTitle xlinkType
10172
10709
  xmlBase xmlns xmlnsXlink xmlLang xmlSpace y y1 y2 yChannelSelector z
10173
10710
  zoomAndPan`.split(/\s+/));
10174
- var compatElementProps = /* @__PURE__ */ new Set([
10711
+ const compatElementProps = /* @__PURE__ */ new Set([
10175
10712
  "autofocus",
10176
10713
  "class",
10177
10714
  "for"
@@ -10192,19 +10729,39 @@ function UnforwardedPolymorphicElement({ as, ...props }, ref) {
10192
10729
  ...forwardedProps
10193
10730
  });
10194
10731
  }
10195
- var PolymorphicElement = forwardRef$1(UnforwardedPolymorphicElement);
10196
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/view/component.mjs
10732
+ /**
10733
+ * Internal utility for components that need Emotion-compatible `as` behavior
10734
+ * while rendering with plain React elements.
10735
+ */
10736
+ const PolymorphicElement = forwardRef$1(UnforwardedPolymorphicElement);
10737
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/view/component.mjs
10197
10738
  function UnforwardedView({ css, ...restProps }, ref) {
10198
10739
  return /* @__PURE__ */ jsx(PolymorphicElement, {
10199
10740
  ref,
10200
10741
  ...restProps
10201
10742
  });
10202
10743
  }
10203
- var component_default$2 = Object.assign(forwardRef$1(UnforwardedView), { selector: ".components-view" });
10204
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/visually-hidden/component.mjs
10744
+ /**
10745
+ * `View` is a core component that renders everything in the library.
10746
+ * It is the principle component in the entire library.
10747
+ *
10748
+ * ```jsx
10749
+ * import { View } from `@wordpress/components`;
10750
+ *
10751
+ * function Example() {
10752
+ * return (
10753
+ * <View>
10754
+ * Code is Poetry
10755
+ * </View>
10756
+ * );
10757
+ * }
10758
+ * ```
10759
+ */
10760
+ const View = Object.assign(forwardRef$1(UnforwardedView), { selector: ".components-view" });
10761
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/visually-hidden/component.mjs
10205
10762
  function UnconnectedVisuallyHidden(props, forwardedRef) {
10206
10763
  const { style: styleProp, ...contextProps } = useContextSystem(props, "VisuallyHidden");
10207
- return /* @__PURE__ */ jsx(component_default$2, {
10764
+ return /* @__PURE__ */ jsx(View, {
10208
10765
  ref: forwardedRef,
10209
10766
  ...contextProps,
10210
10767
  "data-visually-hidden": "",
@@ -10214,14 +10771,30 @@ function UnconnectedVisuallyHidden(props, forwardedRef) {
10214
10771
  }
10215
10772
  });
10216
10773
  }
10217
- var component_default$1 = contextConnect(UnconnectedVisuallyHidden, "VisuallyHidden");
10218
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/utils/use-responsive-value.mjs
10219
- var breakpoints = [
10774
+ /**
10775
+ * `VisuallyHidden` is a component used to render text intended to be visually
10776
+ * hidden, but will show for alternate devices, for example a screen reader.
10777
+ *
10778
+ * ```jsx
10779
+ * import { VisuallyHidden } from `@wordpress/components`;
10780
+ *
10781
+ * function Example() {
10782
+ * return (
10783
+ * <VisuallyHidden>
10784
+ * <label>Code is Poetry</label>
10785
+ * </VisuallyHidden>
10786
+ * );
10787
+ * }
10788
+ * ```
10789
+ */
10790
+ const VisuallyHidden$1 = contextConnect(UnconnectedVisuallyHidden, "VisuallyHidden");
10791
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/utils/use-responsive-value.mjs
10792
+ const breakpoints = [
10220
10793
  "40em",
10221
10794
  "52em",
10222
10795
  "64em"
10223
10796
  ];
10224
- var useBreakpointIndex = (options = {}) => {
10797
+ const useBreakpointIndex = (options = {}) => {
10225
10798
  const { defaultIndex = 0, enabled = true } = options;
10226
10799
  if (typeof defaultIndex !== "number") throw new TypeError(`Default breakpoint index should be a number. Got: ${defaultIndex}, ${typeof defaultIndex}`);
10227
10800
  else if (defaultIndex < 0 || defaultIndex > breakpoints.length - 1) throw new RangeError(`Default breakpoint index out of range. Theme has ${breakpoints.length} breakpoints, got index ${defaultIndex}`);
@@ -10253,8 +10826,8 @@ function useResponsiveValue(values, options = {}) {
10253
10826
  const array = values || [];
10254
10827
  return array[index >= array.length ? array.length - 1 : index];
10255
10828
  }
10256
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/utils.mjs
10257
- var ALIGNMENTS = {
10829
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/grid/utils.mjs
10830
+ const ALIGNMENTS = {
10258
10831
  bottom: {
10259
10832
  alignItems: "flex-end",
10260
10833
  justifyContent: "center"
@@ -10300,8 +10873,16 @@ var ALIGNMENTS = {
10300
10873
  function getAlignmentProps(alignment) {
10301
10874
  return alignment ? ALIGNMENTS[alignment] ?? {} : {};
10302
10875
  }
10303
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/hook.mjs
10304
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
10876
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/grid/hook.mjs
10877
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
10878
+ /**
10879
+ * Returns the shared style runtime registry.
10880
+ *
10881
+ * The registry is stored on `globalThis` so separately bundled copies of this
10882
+ * package can coordinate through the same document and style maps.
10883
+ *
10884
+ * @return The shared runtime registry.
10885
+ */
10305
10886
  function getRuntime() {
10306
10887
  const globalScope = globalThis;
10307
10888
  if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
@@ -10313,11 +10894,27 @@ function getRuntime() {
10313
10894
  if (typeof document !== "undefined") registerDocument(document);
10314
10895
  return globalScope.__wpStyleRuntime;
10315
10896
  }
10897
+ /**
10898
+ * Checks whether a document already contains a style tag for a hash.
10899
+ *
10900
+ * @param targetDocument Document to inspect.
10901
+ * @param hash Stable hash for the transformed CSS.
10902
+ *
10903
+ * @return Whether the style hash already exists in the document.
10904
+ */
10316
10905
  function documentContainsStyleHash(targetDocument, hash) {
10317
10906
  if (!targetDocument.head) return false;
10318
10907
  for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
10319
10908
  return false;
10320
10909
  }
10910
+ /**
10911
+ * Injects a registered style into a document, unless that document already
10912
+ * contains a style tag for the same hash.
10913
+ *
10914
+ * @param targetDocument Document to inject the style into.
10915
+ * @param hash Stable hash for the transformed CSS.
10916
+ * @param css CSS text to inject.
10917
+ */
10321
10918
  function injectStyle(targetDocument, hash, css) {
10322
10919
  if (!targetDocument.head) return;
10323
10920
  const runtime = getRuntime();
@@ -10337,6 +10934,17 @@ function injectStyle(targetDocument, hash, css) {
10337
10934
  targetDocument.head.appendChild(style);
10338
10935
  injectedStyles.add(hash);
10339
10936
  }
10937
+ /**
10938
+ * Registers a document as a style injection target.
10939
+ *
10940
+ * Existing registered styles are replayed into the document immediately.
10941
+ * Documents are reference-counted so multiple providers can safely register the
10942
+ * same document without one cleanup removing it while another registration is
10943
+ * still active.
10944
+ *
10945
+ * @param targetDocument Document to receive registered styles.
10946
+ * @return Cleanup function that unregisters this document registration.
10947
+ */
10340
10948
  function registerDocument(targetDocument) {
10341
10949
  const runtime = getRuntime();
10342
10950
  runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
@@ -10351,51 +10959,62 @@ function registerDocument(targetDocument) {
10351
10959
  runtime.documents.set(targetDocument, count - 1);
10352
10960
  };
10353
10961
  }
10962
+ /**
10963
+ * Registers a style and injects it into all registered documents.
10964
+ *
10965
+ * The hash is used as the deduplication key, so calling this repeatedly with
10966
+ * the same hash will not add duplicate style tags to a document.
10967
+ * Registered styles are retained for the lifetime of the page so they can be
10968
+ * replayed into documents that are registered later.
10969
+ *
10970
+ * @param hash Stable hash for the transformed CSS.
10971
+ * @param css CSS text to inject.
10972
+ */
10354
10973
  function registerStyle(hash, css) {
10355
10974
  const runtime = getRuntime();
10356
10975
  runtime.styles.set(hash, css);
10357
10976
  for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
10358
10977
  }
10359
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("79bac25858", "._631b7063b4047c89__grid{--wp-components-grid-align:initial;--wp-components-grid-justify:initial;--wp-components-grid-gap:initial;--wp-components-grid-template-columns:initial;--wp-components-grid-template-rows:initial;--wp-components-grid-row-gap:initial;--wp-components-grid-column-gap:initial;display:grid}._631b7063b4047c89__grid:not(:where(._51fa5e5688d538e7__row-gap-inherit,._3940112538797bb2__row-gap-initial,._9dc0e80dad95eb11__row-gap-unset,._964ec4132d3d0776__row-gap-revert,._9219888d7c4749d5__row-gap-revert-layer)){row-gap:var(--wp-components-grid-row-gap,calc(4px*var(--wp-components-grid-gap)))}._631b7063b4047c89__grid:not(:where(._149fd947497e8690__column-gap-inherit,.a018e74b0f04c517__column-gap-initial,.b1e45f9587eb70e5__column-gap-unset,._4da312511f64af94__column-gap-revert,.b51ead67217c210a__column-gap-revert-layer)){column-gap:var(--wp-components-grid-column-gap,calc(4px*var(--wp-components-grid-gap)))}._4cae76607d36422b__has-align:not(:where(._2c693b642b24e0d9__align-inherit,.fd4c5676ad7e83d4__align-initial,.c4c0cde44ab0ed21__align-unset,._8c23efb61db2f04e__align-revert,.c3adc4c41efa56d1__align-revert-layer)){align-items:var(--wp-components-grid-align)}._9bcd99517d001b4b__has-justify:not(:where(.a72d35ee0eda5e6b__justify-inherit,.d386403fd02ebc45__justify-initial,._7d60510a69e8ddf9__justify-unset,._857dfb6521d0cae3__justify-revert,._1537fff8402f1ca1__justify-revert-layer)){justify-content:var(--wp-components-grid-justify)}._983f7df07cd35a72__has-template-columns:not(:where(.df2216db1a717825__template-columns-inherit,._9016934ed273a0b8__template-columns-initial,._74966333f352d829__template-columns-unset,.b3ce45d005011688__template-columns-revert,._9ff0250b9bed5764__template-columns-revert-layer)){grid-template-columns:var(--wp-components-grid-template-columns)}._7e0fa0c081c20f6e__has-template-rows:not(:where(._10cfd24f62672d27__template-rows-inherit,.da1333be6b2af8c3__template-rows-initial,._919938d55c0cf234__template-rows-unset,.db40efe5796b7ffb__template-rows-revert,._1080cc5b99823c58__template-rows-revert-layer)){grid-template-rows:var(--wp-components-grid-template-rows)}.f4729d54fca65af1__is-inline{display:inline-grid;vertical-align:middle}._2c693b642b24e0d9__align-inherit{align-items:inherit}.fd4c5676ad7e83d4__align-initial{align-items:normal}.c4c0cde44ab0ed21__align-unset{align-items:unset}._8c23efb61db2f04e__align-revert{align-items:revert}.c3adc4c41efa56d1__align-revert-layer{align-items:revert-layer}.a72d35ee0eda5e6b__justify-inherit{justify-content:inherit}.d386403fd02ebc45__justify-initial{justify-content:normal}._7d60510a69e8ddf9__justify-unset{justify-content:unset}._857dfb6521d0cae3__justify-revert{justify-content:revert}._1537fff8402f1ca1__justify-revert-layer{justify-content:revert-layer}.df2216db1a717825__template-columns-inherit{grid-template-columns:inherit}._9016934ed273a0b8__template-columns-initial{grid-template-columns:none}._74966333f352d829__template-columns-unset{grid-template-columns:unset}.b3ce45d005011688__template-columns-revert{grid-template-columns:revert}._9ff0250b9bed5764__template-columns-revert-layer{grid-template-columns:revert-layer}._10cfd24f62672d27__template-rows-inherit{grid-template-rows:inherit}.da1333be6b2af8c3__template-rows-initial{grid-template-rows:none}._919938d55c0cf234__template-rows-unset{grid-template-rows:unset}.db40efe5796b7ffb__template-rows-revert{grid-template-rows:revert}._1080cc5b99823c58__template-rows-revert-layer{grid-template-rows:revert-layer}._51fa5e5688d538e7__row-gap-inherit{row-gap:inherit}._3940112538797bb2__row-gap-initial{row-gap:normal}._9dc0e80dad95eb11__row-gap-unset{row-gap:unset}._964ec4132d3d0776__row-gap-revert{row-gap:revert}._9219888d7c4749d5__row-gap-revert-layer{row-gap:revert-layer}._149fd947497e8690__column-gap-inherit{column-gap:inherit}.a018e74b0f04c517__column-gap-initial{column-gap:normal}.b1e45f9587eb70e5__column-gap-unset{column-gap:unset}._4da312511f64af94__column-gap-revert{column-gap:revert}.b51ead67217c210a__column-gap-revert-layer{column-gap:revert-layer}");
10978
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("b1a8e206b7", ".ad3e2e48d7abbecd__grid{--wp-components-grid-align:initial;--wp-components-grid-justify:initial;--wp-components-grid-gap:initial;--wp-components-grid-template-columns:initial;--wp-components-grid-template-rows:initial;--wp-components-grid-row-gap:initial;--wp-components-grid-column-gap:initial;display:grid}.ad3e2e48d7abbecd__grid:not(:where(._519ed3f6107b2f0e__row-gap-inherit,.cd62b95f8b7a55ca__row-gap-initial,._226744df7703790b__row-gap-unset,._372e9fe7fa60a162__row-gap-revert,.a788bb6771f557d4__row-gap-revert-layer)){row-gap:var(--wp-components-grid-row-gap,calc(4px*var(--wp-components-grid-gap)))}.ad3e2e48d7abbecd__grid:not(:where(.c811e15146756906__column-gap-inherit,._17d3c2ea7daf9367__column-gap-initial,._595e6195481b9016__column-gap-unset,.a3ecb3e47731c19e__column-gap-revert,._7c87cfbf3c22f476__column-gap-revert-layer)){column-gap:var(--wp-components-grid-column-gap,calc(4px*var(--wp-components-grid-gap)))}._25a972dc3223dff3__has-align:not(:where(._3cda38ca04ad4eb9__align-inherit,.f1d7342c52a8cb04__align-initial,._0d1a6c7ee990f351__align-unset,._57c7b85e7abf618b__align-revert,._82cb0c4950962787__align-revert-layer)){align-items:var(--wp-components-grid-align)}._801d1214723237b8__has-justify:not(:where(.b83c5dbf3264515b__justify-inherit,._5b7394b39d69670e__justify-initial,._3e7f0418752602e5__justify-unset,._5f937df46d7b2259__justify-revert,.bf2a4718a1ddba5c__justify-revert-layer)){justify-content:var(--wp-components-grid-justify)}._3c6ac9820776f1cb__has-template-columns:not(:where(._35faa4d32eedef32__template-columns-inherit,._8150cadb3f438833__template-columns-initial,.bcd5f2b096dec164__template-columns-unset,._48d047bc6fb687b8__template-columns-revert,._93f250669aa1a5a7__template-columns-revert-layer)){grid-template-columns:var(--wp-components-grid-template-columns)}.c2703b6b15e69b82__has-template-rows:not(:where(._3e9d5ffc53e4afc0__template-rows-inherit,._64bb5fbdf6d1038a__template-rows-initial,.f8f5df7043222325__template-rows-unset,._408aaf58100e60d5__template-rows-revert,.e0730d6abf0f3d2a__template-rows-revert-layer)){grid-template-rows:var(--wp-components-grid-template-rows)}._43af1cbfad3e73dd__is-inline{display:inline-grid;vertical-align:middle}._3cda38ca04ad4eb9__align-inherit{align-items:inherit}.f1d7342c52a8cb04__align-initial{align-items:normal}._0d1a6c7ee990f351__align-unset{align-items:unset}._57c7b85e7abf618b__align-revert{align-items:revert}._82cb0c4950962787__align-revert-layer{align-items:revert-layer}.b83c5dbf3264515b__justify-inherit{justify-content:inherit}._5b7394b39d69670e__justify-initial{justify-content:normal}._3e7f0418752602e5__justify-unset{justify-content:unset}._5f937df46d7b2259__justify-revert{justify-content:revert}.bf2a4718a1ddba5c__justify-revert-layer{justify-content:revert-layer}._35faa4d32eedef32__template-columns-inherit{grid-template-columns:inherit}._8150cadb3f438833__template-columns-initial{grid-template-columns:none}.bcd5f2b096dec164__template-columns-unset{grid-template-columns:unset}._48d047bc6fb687b8__template-columns-revert{grid-template-columns:revert}._93f250669aa1a5a7__template-columns-revert-layer{grid-template-columns:revert-layer}._3e9d5ffc53e4afc0__template-rows-inherit{grid-template-rows:inherit}._64bb5fbdf6d1038a__template-rows-initial{grid-template-rows:none}.f8f5df7043222325__template-rows-unset{grid-template-rows:unset}._408aaf58100e60d5__template-rows-revert{grid-template-rows:revert}.e0730d6abf0f3d2a__template-rows-revert-layer{grid-template-rows:revert-layer}._519ed3f6107b2f0e__row-gap-inherit{row-gap:inherit}.cd62b95f8b7a55ca__row-gap-initial{row-gap:normal}._226744df7703790b__row-gap-unset{row-gap:unset}._372e9fe7fa60a162__row-gap-revert{row-gap:revert}.a788bb6771f557d4__row-gap-revert-layer{row-gap:revert-layer}.c811e15146756906__column-gap-inherit{column-gap:inherit}._17d3c2ea7daf9367__column-gap-initial{column-gap:normal}._595e6195481b9016__column-gap-unset{column-gap:unset}.a3ecb3e47731c19e__column-gap-revert{column-gap:revert}._7c87cfbf3c22f476__column-gap-revert-layer{column-gap:revert-layer}");
10360
10979
  var style_module_default = {
10361
- "grid": "_631b7063b4047c89__grid",
10362
- "row-gap-inherit": "_51fa5e5688d538e7__row-gap-inherit",
10363
- "row-gap-initial": "_3940112538797bb2__row-gap-initial",
10364
- "row-gap-unset": "_9dc0e80dad95eb11__row-gap-unset",
10365
- "row-gap-revert": "_964ec4132d3d0776__row-gap-revert",
10366
- "row-gap-revert-layer": "_9219888d7c4749d5__row-gap-revert-layer",
10367
- "column-gap-inherit": "_149fd947497e8690__column-gap-inherit",
10368
- "column-gap-initial": "a018e74b0f04c517__column-gap-initial",
10369
- "column-gap-unset": "b1e45f9587eb70e5__column-gap-unset",
10370
- "column-gap-revert": "_4da312511f64af94__column-gap-revert",
10371
- "column-gap-revert-layer": "b51ead67217c210a__column-gap-revert-layer",
10372
- "has-align": "_4cae76607d36422b__has-align",
10373
- "align-inherit": "_2c693b642b24e0d9__align-inherit",
10374
- "align-initial": "fd4c5676ad7e83d4__align-initial",
10375
- "align-unset": "c4c0cde44ab0ed21__align-unset",
10376
- "align-revert": "_8c23efb61db2f04e__align-revert",
10377
- "align-revert-layer": "c3adc4c41efa56d1__align-revert-layer",
10378
- "has-justify": "_9bcd99517d001b4b__has-justify",
10379
- "justify-inherit": "a72d35ee0eda5e6b__justify-inherit",
10380
- "justify-initial": "d386403fd02ebc45__justify-initial",
10381
- "justify-unset": "_7d60510a69e8ddf9__justify-unset",
10382
- "justify-revert": "_857dfb6521d0cae3__justify-revert",
10383
- "justify-revert-layer": "_1537fff8402f1ca1__justify-revert-layer",
10384
- "has-template-columns": "_983f7df07cd35a72__has-template-columns",
10385
- "template-columns-inherit": "df2216db1a717825__template-columns-inherit",
10386
- "template-columns-initial": "_9016934ed273a0b8__template-columns-initial",
10387
- "template-columns-unset": "_74966333f352d829__template-columns-unset",
10388
- "template-columns-revert": "b3ce45d005011688__template-columns-revert",
10389
- "template-columns-revert-layer": "_9ff0250b9bed5764__template-columns-revert-layer",
10390
- "has-template-rows": "_7e0fa0c081c20f6e__has-template-rows",
10391
- "template-rows-inherit": "_10cfd24f62672d27__template-rows-inherit",
10392
- "template-rows-initial": "da1333be6b2af8c3__template-rows-initial",
10393
- "template-rows-unset": "_919938d55c0cf234__template-rows-unset",
10394
- "template-rows-revert": "db40efe5796b7ffb__template-rows-revert",
10395
- "template-rows-revert-layer": "_1080cc5b99823c58__template-rows-revert-layer",
10396
- "is-inline": "f4729d54fca65af1__is-inline"
10397
- };
10398
- var CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
10980
+ "grid": "ad3e2e48d7abbecd__grid",
10981
+ "row-gap-inherit": "_519ed3f6107b2f0e__row-gap-inherit",
10982
+ "row-gap-initial": "cd62b95f8b7a55ca__row-gap-initial",
10983
+ "row-gap-unset": "_226744df7703790b__row-gap-unset",
10984
+ "row-gap-revert": "_372e9fe7fa60a162__row-gap-revert",
10985
+ "row-gap-revert-layer": "a788bb6771f557d4__row-gap-revert-layer",
10986
+ "column-gap-inherit": "c811e15146756906__column-gap-inherit",
10987
+ "column-gap-initial": "_17d3c2ea7daf9367__column-gap-initial",
10988
+ "column-gap-unset": "_595e6195481b9016__column-gap-unset",
10989
+ "column-gap-revert": "a3ecb3e47731c19e__column-gap-revert",
10990
+ "column-gap-revert-layer": "_7c87cfbf3c22f476__column-gap-revert-layer",
10991
+ "has-align": "_25a972dc3223dff3__has-align",
10992
+ "align-inherit": "_3cda38ca04ad4eb9__align-inherit",
10993
+ "align-initial": "f1d7342c52a8cb04__align-initial",
10994
+ "align-unset": "_0d1a6c7ee990f351__align-unset",
10995
+ "align-revert": "_57c7b85e7abf618b__align-revert",
10996
+ "align-revert-layer": "_82cb0c4950962787__align-revert-layer",
10997
+ "has-justify": "_801d1214723237b8__has-justify",
10998
+ "justify-inherit": "b83c5dbf3264515b__justify-inherit",
10999
+ "justify-initial": "_5b7394b39d69670e__justify-initial",
11000
+ "justify-unset": "_3e7f0418752602e5__justify-unset",
11001
+ "justify-revert": "_5f937df46d7b2259__justify-revert",
11002
+ "justify-revert-layer": "bf2a4718a1ddba5c__justify-revert-layer",
11003
+ "has-template-columns": "_3c6ac9820776f1cb__has-template-columns",
11004
+ "template-columns-inherit": "_35faa4d32eedef32__template-columns-inherit",
11005
+ "template-columns-initial": "_8150cadb3f438833__template-columns-initial",
11006
+ "template-columns-unset": "bcd5f2b096dec164__template-columns-unset",
11007
+ "template-columns-revert": "_48d047bc6fb687b8__template-columns-revert",
11008
+ "template-columns-revert-layer": "_93f250669aa1a5a7__template-columns-revert-layer",
11009
+ "has-template-rows": "c2703b6b15e69b82__has-template-rows",
11010
+ "template-rows-inherit": "_3e9d5ffc53e4afc0__template-rows-inherit",
11011
+ "template-rows-initial": "_64bb5fbdf6d1038a__template-rows-initial",
11012
+ "template-rows-unset": "f8f5df7043222325__template-rows-unset",
11013
+ "template-rows-revert": "_408aaf58100e60d5__template-rows-revert",
11014
+ "template-rows-revert-layer": "e0730d6abf0f3d2a__template-rows-revert-layer",
11015
+ "is-inline": "_43af1cbfad3e73dd__is-inline"
11016
+ };
11017
+ const CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
10399
11018
  "inherit",
10400
11019
  "initial",
10401
11020
  "unset",
@@ -10444,15 +11063,35 @@ function useGrid(props) {
10444
11063
  }
10445
11064
  };
10446
11065
  }
10447
- // ../../../node_modules/.pnpm/@wordpress+components@43.0.0_@date-fns+tz@1.5.0_@types+react-dom@19.3.0_@types+react@19_401cb4bad47bd1f7b56615ff574f0485/node_modules/@wordpress/components/build-module/grid/component.mjs
11066
+ // ../../../node_modules/.pnpm/@wordpress+components@44.0.0_patch_hash=dd89cc780626599c6721f4e05e7091dd7b0aed577d8a667_94a1a77c56d75249398bc99af3f14fa5/node_modules/@wordpress/components/build-module/grid/component.mjs
10448
11067
  function UnconnectedGrid(props, forwardedRef) {
10449
11068
  const gridProps = useGrid(props);
10450
- return /* @__PURE__ */ jsx(component_default$2, {
11069
+ return /* @__PURE__ */ jsx(View, {
10451
11070
  ...gridProps,
10452
11071
  ref: forwardedRef
10453
11072
  });
10454
11073
  }
10455
- var component_default = contextConnect(UnconnectedGrid, "Grid");
11074
+ /**
11075
+ * `Grid` is a primitive layout component that can arrange content in a grid configuration.
11076
+ *
11077
+ * ```jsx
11078
+ * import {
11079
+ * __experimentalGrid as Grid,
11080
+ * __experimentalText as Text
11081
+ * } from `@wordpress/components`;
11082
+ *
11083
+ * function Example() {
11084
+ * return (
11085
+ * <Grid columns={ 3 }>
11086
+ * <Text>Code</Text>
11087
+ * <Text>is</Text>
11088
+ * <Text>Poetry</Text>
11089
+ * </Grid>
11090
+ * );
11091
+ * }
11092
+ * ```
11093
+ */
11094
+ const Grid$1 = contextConnect(UnconnectedGrid, "Grid");
10456
11095
  // src/charts/leaderboard-chart/hooks/use-fitted-row-count.ts
10457
11096
  /**
10458
11097
  * Fractional layout rounding can put a row's bottom a hair past the container's
@@ -10935,7 +11574,7 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
10935
11574
  }), allSeriesHidden ? /* @__PURE__ */ jsx("div", {
10936
11575
  className: leaderboard_chart_module_default.emptyState,
10937
11576
  children: getAllHiddenMessage(legendInteractive, "series")
10938
- }) : /* @__PURE__ */ jsx(component_default, {
11577
+ }) : /* @__PURE__ */ jsx(Grid$1, {
10939
11578
  role: "list",
10940
11579
  "aria-label": ariaLabel ?? __("Leaderboard chart", "jetpack-charts"),
10941
11580
  templateColumns,
@@ -10976,7 +11615,7 @@ const LeaderboardChartInternal = ({ data, chartId: providedChartId, width: propW
10976
11615
  children: [/* @__PURE__ */ jsx("span", {
10977
11616
  "aria-hidden": "true",
10978
11617
  children: "—"
10979
- }), /* @__PURE__ */ jsx(component_default$1, {
11618
+ }), /* @__PURE__ */ jsx(VisuallyHidden$1, {
10980
11619
  as: "span",
10981
11620
  children: hasPreviousPeriodValue ? __("Percentage change unavailable", "jetpack-charts") : __("No comparison data", "jetpack-charts")
10982
11621
  })]