frappe-ui 1.0.2 → 1.2.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 (194) hide show
  1. package/experimental/Calendar/CalendarEventRow.vue +0 -4
  2. package/experimental/Calendar/calendarUtils.ts +33 -21
  3. package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
  4. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  5. package/experimental/MultiEmailInput/types.ts +12 -3
  6. package/experimental/SpriteIcons/IconPicker.vue +2 -1
  7. package/experimental/Stepper/StepIndicator.vue +129 -0
  8. package/experimental/Stepper/Stepper.api.md +117 -0
  9. package/experimental/Stepper/Stepper.md +95 -0
  10. package/experimental/Stepper/Stepper.vue +82 -0
  11. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  12. package/experimental/Stepper/StepperVertical.vue +291 -0
  13. package/experimental/Stepper/index.ts +11 -0
  14. package/experimental/Stepper/resolve.ts +87 -0
  15. package/experimental/Stepper/types.ts +89 -0
  16. package/experimental.ts +2 -21
  17. package/package.json +1 -3
  18. package/src/charts/CalendarHeatmapChart.vue +353 -0
  19. package/src/charts/DonutChart.vue +34 -58
  20. package/src/charts/HeatmapChart.vue +26 -64
  21. package/src/charts/NumberCard.vue +62 -7
  22. package/src/charts/PercentageBarChart.vue +243 -0
  23. package/src/charts/SankeyChart.vue +14 -11
  24. package/src/charts/ScatterChart.vue +24 -20
  25. package/src/charts/axisChartCommon.ts +182 -18
  26. package/src/charts/axisFormat.ts +8 -3
  27. package/src/charts/calendarHeatmapOptions.ts +604 -0
  28. package/src/charts/colorMath.ts +26 -0
  29. package/src/charts/components/ChartContainer.vue +63 -53
  30. package/src/charts/components/ChartLegend.vue +216 -24
  31. package/src/charts/components/ChartScale.vue +85 -0
  32. package/src/charts/core/dataLabelFit.ts +45 -6
  33. package/src/charts/core/useAxisChart.ts +36 -19
  34. package/src/charts/core/useChart.ts +6 -1
  35. package/src/charts/core/usePlotKeyboard.ts +13 -2
  36. package/src/charts/docs/BarChart.md +11 -3
  37. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  38. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  39. package/src/charts/docs/ChartContainer.api.md +6 -0
  40. package/src/charts/docs/ChartLegend.api.md +1 -1
  41. package/src/charts/docs/ChartLegend.md +25 -3
  42. package/src/charts/docs/DonutChart.api.md +12 -0
  43. package/src/charts/docs/DonutChart.md +17 -0
  44. package/src/charts/docs/HeatmapChart.api.md +1 -1
  45. package/src/charts/docs/LineChart.md +5 -3
  46. package/src/charts/docs/NumberCard.api.md +6 -0
  47. package/src/charts/docs/NumberCard.md +6 -0
  48. package/src/charts/docs/Overview.md +13 -6
  49. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  50. package/src/charts/docs/PercentageBarChart.md +42 -0
  51. package/src/charts/docs/ScatterChart.md +2 -3
  52. package/src/charts/donutChartOptions.ts +22 -130
  53. package/src/charts/format.ts +4 -1
  54. package/src/charts/heatmapOptions.ts +17 -12
  55. package/src/charts/hiddenSeries.ts +8 -3
  56. package/src/charts/index.ts +12 -0
  57. package/src/charts/legendOverflow.ts +40 -0
  58. package/src/charts/numberCardFormat.ts +19 -13
  59. package/src/charts/referenceLines.ts +2 -1
  60. package/src/charts/scatterOptions.ts +16 -3
  61. package/src/charts/seriesData.ts +8 -3
  62. package/src/charts/slices.ts +228 -0
  63. package/src/charts/tokens.ts +99 -0
  64. package/src/charts/types.ts +318 -9
  65. package/src/components/Avatar/Avatar.md +27 -2
  66. package/src/components/Avatar/Avatar.vue +29 -12
  67. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
  68. package/src/components/Combobox/Combobox.vue +9 -2
  69. package/src/components/Combobox/ComboboxResults.vue +6 -1
  70. package/src/components/Combobox/utils.ts +2 -1
  71. package/src/components/DatePicker/DatePicker.md +7 -0
  72. package/src/components/DatePicker/DatePicker.vue +6 -0
  73. package/src/components/DatePicker/DateTimePicker.vue +6 -0
  74. package/src/components/DatePicker/composables.ts +18 -1
  75. package/src/components/DatePicker/utils.ts +53 -0
  76. package/src/components/Dialog/Dialog.md +3 -1
  77. package/src/components/Duration/Duration.api.md +16 -3
  78. package/src/components/Duration/Duration.md +21 -0
  79. package/src/components/Duration/Duration.vue +29 -8
  80. package/src/components/Duration/duration.ts +105 -44
  81. package/src/components/Duration/index.ts +1 -0
  82. package/src/components/Duration/types.ts +30 -1
  83. package/src/components/HoverCard/HoverCard.vue +21 -5
  84. package/src/components/Menu/utils.ts +3 -2
  85. package/src/components/MobileNav/MobileNavItem.vue +3 -22
  86. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  87. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  88. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  89. package/src/components/MultiSelect/types.ts +6 -0
  90. package/src/components/Select/Select.vue +4 -4
  91. package/src/components/Select/utils.ts +1 -0
  92. package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
  93. package/src/components/SettingsDialog/SettingsDialog.md +2 -1
  94. package/src/components/SettingsDialog/SettingsRow.vue +12 -2
  95. package/src/components/Sidebar/SidebarItem.vue +3 -33
  96. package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
  97. package/src/components/Switch/Switch.vue +3 -3
  98. package/src/components/Tooltip/Tooltip.vue +8 -0
  99. package/src/components/shared/deferredTrigger.ts +174 -0
  100. package/src/components/shared/navLink.ts +45 -0
  101. package/src/components/shared/selection/utils.ts +8 -1
  102. package/src/data-fetching/useCall/useCall.ts +25 -26
  103. package/src/data-fetching/useFrappeFetch.ts +48 -2
  104. package/src/data-fetching/useList/useList.ts +11 -3
  105. package/src/data-fetching/utils.ts +15 -1
  106. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  107. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  108. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  109. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  110. package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
  111. package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
  112. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
  113. package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
  114. package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
  115. package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
  116. package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
  117. package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
  118. package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
  119. package/src/molecules/editor/useEditor.ts +12 -6
  120. package/src/molecules/list/ListRow.vue +8 -1
  121. package/src/utils/dialog.ts +57 -16
  122. package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
  123. package/tailwind/content.js +1 -1
  124. package/tailwind/plugin.js +22 -0
  125. package/vite/README.md +5 -3
  126. package/vite/codeLanguages.js +41 -17
  127. package/vite/doctypeInterfaceGenerator.js +52 -39
  128. package/vitepress/index.node.ts +0 -2
  129. package/experimental/TextEditor/TextEditor.api.md +0 -161
  130. package/experimental/TextEditor/TextEditor.vue +0 -298
  131. package/experimental/TextEditor/classIcon.ts +0 -21
  132. package/experimental/TextEditor/commands.js +0 -344
  133. package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
  134. package/experimental/TextEditor/components/FontColor.vue +0 -153
  135. package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
  136. package/experimental/TextEditor/components/InsertImage.vue +0 -54
  137. package/experimental/TextEditor/components/InsertLink.vue +0 -13
  138. package/experimental/TextEditor/components/InsertVideo.vue +0 -14
  139. package/experimental/TextEditor/components/LinkPopup.vue +0 -99
  140. package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
  141. package/experimental/TextEditor/components/MentionList.vue +0 -95
  142. package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
  143. package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
  144. package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
  145. package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
  146. package/experimental/TextEditor/components/index.js +0 -0
  147. package/experimental/TextEditor/extensions/code-block.ts +0 -119
  148. package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
  149. package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
  150. package/experimental/TextEditor/extensions/color/index.ts +0 -2
  151. package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
  152. package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
  153. package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
  154. package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
  155. package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
  156. package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
  157. package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
  158. package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
  159. package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
  160. package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
  161. package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
  162. package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
  163. package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
  164. package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
  165. package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
  166. package/experimental/TextEditor/extensions/image/index.ts +0 -5
  167. package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
  168. package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
  169. package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
  170. package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
  171. package/experimental/TextEditor/extensions/link/index.ts +0 -1
  172. package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
  173. package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
  174. package/experimental/TextEditor/extensions/mention/index.ts +0 -1
  175. package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
  176. package/experimental/TextEditor/extensions/mention/style.css +0 -11
  177. package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
  178. package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
  179. package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
  180. package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
  181. package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
  182. package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
  183. package/experimental/TextEditor/extensions/tag/index.ts +0 -1
  184. package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
  185. package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
  186. package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
  187. package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
  188. package/experimental/TextEditor/extensions/video-extension.ts +0 -653
  189. package/experimental/TextEditor/hljs-github.css +0 -197
  190. package/experimental/TextEditor/index.ts +0 -21
  191. package/experimental/TextEditor/style.css +0 -190
  192. package/experimental/TextEditor/types.ts +0 -72
  193. package/experimental/TextEditor/utils.js +0 -11
  194. package/src/utils/url-validation.ts +0 -39
@@ -5,7 +5,9 @@ import {
5
5
  DATA_LABEL_FONT_SIZE,
6
6
  buildAxisGrid,
7
7
  buildValueAxis,
8
+ holdsWholeNumbers,
8
9
  toNumber,
10
+ referenceLineExtent,
9
11
  } from './axisChartCommon'
10
12
  import { formatLabel } from './format'
11
13
  import { CHART_FONT_FAMILY } from './measureText'
@@ -104,7 +106,8 @@ export function buildScatterSeries(
104
106
 
105
107
  return names.map((name, index) => ({
106
108
  name,
107
- label: formatLabel(name),
109
+ // A group's name is a value read from the data, which prints as given.
110
+ label: config.splitByColumn ? name : formatLabel(name),
108
111
  color: colors[index],
109
112
  points: grouped.get(name)!.map((point) => ({
110
113
  ...point,
@@ -196,11 +199,15 @@ export function buildScatterOption(
196
199
  isRTL,
197
200
  format: format?.x,
198
201
  name: config.xAxis?.title,
202
+ lines: referenceLineExtent(config.referenceLines, 'x', false),
203
+ integer: holdsWholeNumbers(config.data ?? [], [config.xColumn]),
199
204
  }),
200
205
  yAxis: valueAxis(config.yAxis, tokens, {
201
206
  horizontal: false,
202
207
  isRTL,
203
208
  format: format?.y,
209
+ lines: referenceLineExtent(config.referenceLines, 'y', false),
210
+ integer: holdsWholeNumbers(config.data ?? [], [config.yColumn]),
204
211
  }),
205
212
  series: [
206
213
  ...visible.map((entry) =>
@@ -334,9 +341,13 @@ function valueAxis(
334
341
  format?: ChartValueFormatter
335
342
  /** Axis title, for the axis that draws its own. */
336
343
  name?: string
344
+ /** The span its reference lines reach. */
345
+ lines?: { dataMin?: number; dataMax?: number }
346
+ /** Whether its column holds whole numbers only. */
347
+ integer: boolean
337
348
  },
338
349
  ) {
339
- const { horizontal, isRTL, format, name } = opts
350
+ const { horizontal, isRTL, format, name, lines, integer } = opts
340
351
 
341
352
  // Merged *under* the caller's own overrides, the way `applyAxisFormatters`
342
353
  // does it: an explicit `echartOptions` still wins over what v2 decided.
@@ -348,7 +359,7 @@ function valueAxis(
348
359
  boundaryGap: [AXIS_INSET, AXIS_INSET],
349
360
  ...(name
350
361
  ? {
351
- name: formatLabel(name),
362
+ name,
352
363
  nameLocation: 'end',
353
364
  nameGap: 8,
354
365
  nameTextStyle: {
@@ -368,5 +379,7 @@ function valueAxis(
368
379
  return buildValueAxis({ ...axis, echartOptions }, tokens, {
369
380
  horizontal,
370
381
  isRTL,
382
+ lines,
383
+ integer,
371
384
  })
372
385
  }
@@ -176,6 +176,9 @@ function buildSeries(
176
176
  // column that is no longer selected is expected, not an error.
177
177
  const style = props.seriesConfig?.[name]
178
178
  return {
179
+ // A `splitBy` name is a value read from the data, so it prints as given
180
+ // instead of going through `formatLabel`, which is for column keys.
181
+ ...(props.splitBy && axis === 'y' ? { label: name } : {}),
179
182
  // The collapsed tail has no column behind it, so its label comes from here
180
183
  // rather than from the data. Ahead of the style: a `seriesConfig` entry for
181
184
  // the reserved key renames and colors it like any other series.
@@ -334,10 +337,11 @@ function capSeries(pivoted: Pivoted, maxSeries?: number): Pivoted {
334
337
 
335
338
  /**
336
339
  * What each series is worth across the whole chart, which is what decides who
337
- * survives the cap. Magnitude rather than signed total: a series that runs
338
- * large and negative carries the chart as much as one that runs large.
340
+ * survives the cap and who keeps a place on an overflowing legend row.
341
+ * Magnitude rather than signed total: a series that runs large and negative
342
+ * carries the chart as much as one that runs large.
339
343
  */
340
- function seriesWeights(rows: Record<string, any>[], names: string[]) {
344
+ export function seriesWeights(rows: Record<string, any>[], names: string[]) {
341
345
  const weights: Record<string, number> = {}
342
346
  for (const name of names) weights[name] = 0
343
347
  for (const row of rows) {
@@ -356,6 +360,7 @@ function toValueAxis(
356
360
  title: options.title,
357
361
  min: options.min,
358
362
  max: options.max,
363
+ integer: options.integer,
359
364
  echartOptions: options.echartOptions,
360
365
  }
361
366
  }
@@ -0,0 +1,228 @@
1
+ import { toNumber } from './axisChartCommon'
2
+ import { formatPercent } from './format'
3
+ import { paletteColors, type ChartTokens } from './tokens'
4
+ import { OTHERS_KEY, OTHERS_LABEL } from './utils'
5
+ import type {
6
+ ChartLegendItem,
7
+ ChartPaletteName,
8
+ ChartTooltipItem,
9
+ ChartValueFormatter,
10
+ DonutChartConfig,
11
+ DonutSlice,
12
+ DonutSliceEvent,
13
+ } from './types'
14
+
15
+ // The ring and the bar cut the same rows into the same slices, so a breakdown
16
+ // keeps its names, its hidden slices and its pinned colors when it moves from
17
+ // one to the other. Plot, legend and tooltip all read the same `DonutSlice[]`,
18
+ // so they can't disagree about what a slice is worth.
19
+
20
+ export type SliceConfig = Pick<
21
+ DonutChartConfig,
22
+ | 'data'
23
+ | 'categoryColumn'
24
+ | 'valueColumn'
25
+ | 'maxSlices'
26
+ | 'order'
27
+ | 'palette'
28
+ | 'colors'
29
+ >
30
+
31
+ export type SliceContext = {
32
+ tokens: ChartTokens
33
+ /** Slice names the legend has switched off. Dropped from the plot. */
34
+ hiddenSlices?: string[]
35
+ }
36
+
37
+ export const DEFAULT_MAX_SLICES = 9
38
+ /** Below two there is nothing left to group into. */
39
+ const MIN_MAX_SLICES = 2
40
+
41
+ const SLICE_PALETTE: ChartPaletteName = 'categorical'
42
+
43
+ /**
44
+ * The slices of a breakdown, in drawing order. Hidden slices stay in the list —
45
+ * the legend still needs them, and dropping them would shift every color after.
46
+ */
47
+ export function buildSlices(
48
+ config: SliceConfig,
49
+ { tokens, hiddenSlices = [] }: SliceContext,
50
+ ): DonutSlice[] {
51
+ const grouped = groupRows(config)
52
+ const colors = paletteColors(
53
+ config.palette,
54
+ tokens,
55
+ grouped.length,
56
+ SLICE_PALETTE,
57
+ )
58
+
59
+ const visibleTotal = grouped.reduce(
60
+ (sum, slice) =>
61
+ hiddenSlices.includes(slice.name) ? sum : sum + slice.value,
62
+ 0,
63
+ )
64
+ const percents = roundShares(
65
+ grouped.map((slice) =>
66
+ hiddenSlices.includes(slice.name) || !visibleTotal
67
+ ? 0
68
+ : (slice.value / visibleTotal) * 100,
69
+ ),
70
+ )
71
+
72
+ return grouped.map((slice, index) => {
73
+ const hidden = hiddenSlices.includes(slice.name)
74
+ // Keyed by what the caller wrote, not by the unique name: `Others` is
75
+ // keyed by `OTHERS_KEY`, and a repeated category shares its pin.
76
+ const key = slice.isOthers ? OTHERS_KEY : slice.label
77
+ return {
78
+ ...slice,
79
+ // A pinned slice still spends its palette slot, as a pinned series does,
80
+ // so pinning one never recolors the others.
81
+ color: config.colors?.[key] || colors[index],
82
+ hidden,
83
+ percent: percents[index],
84
+ }
85
+ })
86
+ }
87
+
88
+ /**
89
+ * Whole points that add up to 100. Rounded one at a time, three equal shares
90
+ * print 99% between them and six print 102%. Largest remainder: every share
91
+ * takes its floor, and the points still missing go to the biggest fractions,
92
+ * the bigger slice first on a tie. A share under 1 keeps its true size so it
93
+ * prints `<1%`, not `0%`.
94
+ */
95
+ function roundShares(percents: number[]): number[] {
96
+ const floors = percents.map(Math.floor)
97
+ const missing =
98
+ Math.round(percents.reduce((sum, percent) => sum + percent, 0)) -
99
+ floors.reduce((sum, floor) => sum + floor, 0)
100
+ const rounded = [...floors]
101
+ percents
102
+ .map((percent, index) => ({ index, remainder: percent - floors[index] }))
103
+ .sort(
104
+ (a, b) =>
105
+ b.remainder - a.remainder || percents[b.index] - percents[a.index],
106
+ )
107
+ .slice(0, missing)
108
+ .forEach(({ index }) => rounded[index]++)
109
+ return rounded.map((share, index) =>
110
+ percents[index] > 0 && percents[index] < 1 ? percents[index] : share,
111
+ )
112
+ }
113
+
114
+ /** The slices with a mark on the plot: a zero slice has no arc and no block. */
115
+ export function drawnSlices(slices: DonutSlice[]): DonutSlice[] {
116
+ return slices.filter((slice) => !slice.hidden && slice.value > 0)
117
+ }
118
+
119
+ export function sliceEvent(slice: DonutSlice): DonutSliceEvent {
120
+ return {
121
+ name: slice.name,
122
+ label: slice.label,
123
+ value: slice.value,
124
+ percent: slice.percent,
125
+ rows: slice.rows,
126
+ }
127
+ }
128
+
129
+ export function sliceLegendItems(
130
+ slices: DonutSlice[],
131
+ format: ChartValueFormatter,
132
+ ): ChartLegendItem[] {
133
+ return slices.map((slice) => ({
134
+ name: slice.name,
135
+ label: slice.label,
136
+ color: slice.color,
137
+ hidden: slice.hidden,
138
+ // A hidden slice has no share of the visible total, so it shows none.
139
+ hint: slice.hidden ? undefined : formatPercent(slice.percent),
140
+ weight: slice.value,
141
+ formattedValue: format(slice.value),
142
+ }))
143
+ }
144
+
145
+ export function sliceTooltipItem(
146
+ slice: DonutSlice,
147
+ format: ChartValueFormatter,
148
+ ): ChartTooltipItem {
149
+ return {
150
+ name: slice.name,
151
+ label: slice.label,
152
+ color: slice.color,
153
+ value: slice.value,
154
+ formattedValue: format(slice.value),
155
+ percent: slice.percent,
156
+ kind: 'series',
157
+ }
158
+ }
159
+
160
+ type UnsizedSlice = Omit<DonutSlice, 'color' | 'hidden' | 'percent'>
161
+
162
+ function groupRows(config: SliceConfig): UnsizedSlice[] {
163
+ const rows = config.data ?? []
164
+
165
+ const entries = rows
166
+ .map((row) => ({ row, value: toNumber(row[config.valueColumn]) }))
167
+ // A breakdown reads as parts of a whole, and a negative part has nothing
168
+ // to draw.
169
+ .filter(
170
+ (entry): entry is { row: Record<string, any>; value: number } =>
171
+ entry.value !== null && entry.value >= 0,
172
+ )
173
+ const bySize = [...entries].sort((a, b) => b.value - a.value)
174
+
175
+ const max = Math.max(MIN_MAX_SLICES, config.maxSlices ?? DEFAULT_MAX_SLICES)
176
+ // One of the slots goes to "Others" itself.
177
+ const keep = entries.length > max ? max - 1 : entries.length
178
+ // The largest are kept whatever the drawing order, so the cap holds.
179
+ const kept = new Set(bySize.slice(0, keep))
180
+ const ordered = config.order === 'rows' ? entries : bySize
181
+
182
+ const seen = new Set<string>()
183
+ const slices: UnsizedSlice[] = ordered
184
+ .filter((entry) => kept.has(entry))
185
+ .map((entry) => {
186
+ const label = categoryLabel(entry.row[config.categoryColumn])
187
+ return {
188
+ name: uniqueName(label, seen),
189
+ label,
190
+ value: entry.value,
191
+ rows: [entry.row],
192
+ isOthers: false,
193
+ }
194
+ })
195
+
196
+ const overflow = ordered.filter((entry) => !kept.has(entry))
197
+ if (!overflow.length) return slices
198
+
199
+ return [
200
+ ...slices,
201
+ {
202
+ name: OTHERS_KEY,
203
+ label: OTHERS_LABEL,
204
+ value: overflow.reduce((sum, entry) => sum + entry.value, 0),
205
+ rows: overflow.map((entry) => entry.row),
206
+ isOthers: true,
207
+ },
208
+ ]
209
+ }
210
+
211
+ function categoryLabel(value: any) {
212
+ return value === null || value === undefined || value === ''
213
+ ? '(Blank)'
214
+ : String(value)
215
+ }
216
+
217
+ /**
218
+ * Two rows can carry the same category value, and a slice is addressed by name
219
+ * — so a repeat would highlight and hide both at once. The label keeps the raw
220
+ * value; only the identity is made unique.
221
+ */
222
+ function uniqueName(label: string, seen: Set<string>) {
223
+ let name = label
224
+ let suffix = 2
225
+ while (seen.has(name)) name = `${label} (${suffix++})`
226
+ seen.add(name)
227
+ return name
228
+ }
@@ -3,6 +3,7 @@ import {
3
3
  getResolvedColorScheme,
4
4
  type ResolvedColorScheme,
5
5
  } from '../composables/useColorScheme'
6
+ import { oklchCssToSrgb } from './colorMath'
6
7
  import { documentAttributes } from './utils'
7
8
  import type { ChartPalette, ChartPaletteName } from './types'
8
9
 
@@ -251,6 +252,87 @@ export function resolveChartTokens(el?: HTMLElement | null): ChartTokens {
251
252
  }
252
253
  }
253
254
 
255
+ /**
256
+ * `value` with every `var(--name)` in its strings swapped for what `el`
257
+ * computes for that name, so a caller's own colors reach echarts as concrete
258
+ * values, the way the tokens above do. An `oklch()` value comes back as sRGB:
259
+ * echarts cannot parse it, and a color it cannot parse paints nothing once it
260
+ * derives a hover color from it. Read off `el` rather than the document
261
+ * root, so a variable defined on a card or inside a shadow root resolves. A name
262
+ * `el` does not define takes the fallback, else stays as written. Walks arrays
263
+ * and plain objects, and returns the parts it changed nothing in as they were.
264
+ */
265
+ export function resolveCssVariables<T>(value: T, el?: Element | null): T {
266
+ if (!el || typeof getComputedStyle !== 'function') return value
267
+ let styles: CSSStyleDeclaration | undefined
268
+ const read = (name: string) =>
269
+ (styles ??= getComputedStyle(el)).getPropertyValue(name).trim()
270
+
271
+ return mapStrings(value, (text) =>
272
+ text.includes('var(') ? substituteVariables(text, read) : text,
273
+ )
274
+ }
275
+
276
+ /**
277
+ * `text` with each `var(--name)` swapped for `read(name)`, else for its
278
+ * fallback, which is substituted the same way. A fallback can hold parentheses
279
+ * of its own, `rgb(…)` or another `var(…)`, so its end is found by counting
280
+ * them.
281
+ */
282
+ function substituteVariables(
283
+ text: string,
284
+ read: (name: string) => string,
285
+ ): string {
286
+ const head = /var\(\s*(--[\w-]+)\s*([,)])/g
287
+ let out = ''
288
+ let copied = 0
289
+ for (let match; (match = head.exec(text)); ) {
290
+ let end = match.index + match[0].length
291
+ let fallback = ''
292
+ if (match[2] === ',') {
293
+ const close = closingParen(text, end)
294
+ if (close === -1) break
295
+ fallback = substituteVariables(text.slice(end, close), read).trim()
296
+ end = close + 1
297
+ }
298
+ const value = read(match[1]) || fallback
299
+ out +=
300
+ text.slice(copied, match.index) +
301
+ (value ? (oklchCssToSrgb(value) ?? value) : text.slice(match.index, end))
302
+ copied = head.lastIndex = end
303
+ }
304
+ return out + text.slice(copied)
305
+ }
306
+
307
+ /** Where the `)` closing a parenthesis opened just before `from` is, or -1. */
308
+ function closingParen(text: string, from: number) {
309
+ let depth = 1
310
+ for (let i = from; i < text.length; i++) {
311
+ if (text[i] === '(') depth++
312
+ else if (text[i] === ')' && --depth === 0) return i
313
+ }
314
+ return -1
315
+ }
316
+
317
+ function mapStrings(value: any, map: (text: string) => string): any {
318
+ if (typeof value === 'string') return map(value)
319
+ if (Array.isArray(value)) {
320
+ const next = value.map((item) => mapStrings(item, map))
321
+ return next.some((item, index) => item !== value[index]) ? next : value
322
+ }
323
+ if (!value || typeof value !== 'object') return value
324
+ const prototype = Object.getPrototypeOf(value)
325
+ // A `Date` on a time axis, an echarts graphic: not ours to rebuild.
326
+ if (prototype !== Object.prototype && prototype !== null) return value
327
+ let next: Record<string, any> | undefined
328
+ for (const key of Object.keys(value)) {
329
+ const mapped = mapStrings(value[key], map)
330
+ if (mapped === value[key]) continue
331
+ next = { ...(next ?? value), [key]: mapped }
332
+ }
333
+ return next ?? value
334
+ }
335
+
254
336
  export function pickSeriesColor(ramp: string[], index: number) {
255
337
  if (!ramp.length) return FALLBACK_CATEGORICAL.light[0]
256
338
  return ramp[index % ramp.length]
@@ -440,6 +522,23 @@ function hexLuminance(color: string): number | null {
440
522
  * folded in here — palette precedence lives in `resolveSeriesColors`, so there
441
523
  * is one place to read it.
442
524
  */
525
+ /**
526
+ * `config` with every `var(--…)` outside its rows resolved against `el`, so
527
+ * the option builders blend, shade and contrast concrete colors. Rows are data,
528
+ * not colors, and the largest part of a config to walk. Re-resolves when the
529
+ * theme flips.
530
+ */
531
+ export function useResolvedConfig<C extends { data?: unknown }>(
532
+ config: () => C,
533
+ el: Ref<HTMLElement | undefined>,
534
+ ): ComputedRef<C> {
535
+ return computed(() => {
536
+ documentAttributes()
537
+ const { data, ...rest } = config()
538
+ return { ...resolveCssVariables(rest, el.value), data } as C
539
+ })
540
+ }
541
+
443
542
  export function useChartTokens(el: Ref<HTMLElement | undefined>): {
444
543
  tokens: ComputedRef<ChartTokens>
445
544
  } {