minerva-design 1.2.0 → 1.3.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 (256) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/charts/canvas.d.cts +4 -1
  3. package/dist/charts/canvas.d.ts +4 -1
  4. package/dist/charts/core.cjs +1 -1
  5. package/dist/charts/core.d.cts +5 -2
  6. package/dist/charts/core.d.ts +5 -2
  7. package/dist/charts/core.js +6 -4
  8. package/dist/charts/engine/canvas.cjs +1 -1
  9. package/dist/charts/engine/canvas.cjs.map +1 -1
  10. package/dist/charts/engine/canvas.js +65 -53
  11. package/dist/charts/engine/canvas.js.map +1 -1
  12. package/dist/charts/engine/chart.cjs +1 -2
  13. package/dist/charts/engine/chart.cjs.map +1 -1
  14. package/dist/charts/engine/chart.js +342 -323
  15. package/dist/charts/engine/chart.js.map +1 -1
  16. package/dist/charts/engine/color.cjs +1 -1
  17. package/dist/charts/engine/color.cjs.map +1 -1
  18. package/dist/charts/engine/color.d.cts +17 -0
  19. package/dist/charts/engine/color.d.ts +17 -0
  20. package/dist/charts/engine/color.js +27 -3
  21. package/dist/charts/engine/color.js.map +1 -1
  22. package/dist/charts/engine/controller.cjs +2 -2
  23. package/dist/charts/engine/controller.cjs.map +1 -1
  24. package/dist/charts/engine/controller.d.cts +6 -0
  25. package/dist/charts/engine/controller.d.ts +6 -0
  26. package/dist/charts/engine/controller.js +317 -253
  27. package/dist/charts/engine/controller.js.map +1 -1
  28. package/dist/charts/engine/curve.cjs +2 -0
  29. package/dist/charts/engine/curve.cjs.map +1 -0
  30. package/dist/charts/engine/curve.d.cts +15 -0
  31. package/dist/charts/engine/curve.d.ts +15 -0
  32. package/dist/charts/engine/curve.js +56 -0
  33. package/dist/charts/engine/curve.js.map +1 -0
  34. package/dist/charts/engine/data.cjs +1 -1
  35. package/dist/charts/engine/data.cjs.map +1 -1
  36. package/dist/charts/engine/data.d.cts +15 -2
  37. package/dist/charts/engine/data.d.ts +15 -2
  38. package/dist/charts/engine/data.js +98 -38
  39. package/dist/charts/engine/data.js.map +1 -1
  40. package/dist/charts/engine/dom.cjs +1 -1
  41. package/dist/charts/engine/dom.cjs.map +1 -1
  42. package/dist/charts/engine/dom.d.cts +5 -3
  43. package/dist/charts/engine/dom.d.ts +5 -3
  44. package/dist/charts/engine/dom.js +27 -22
  45. package/dist/charts/engine/dom.js.map +1 -1
  46. package/dist/charts/engine/items.cjs +1 -1
  47. package/dist/charts/engine/items.cjs.map +1 -1
  48. package/dist/charts/engine/items.js +132 -61
  49. package/dist/charts/engine/items.js.map +1 -1
  50. package/dist/charts/engine/model.cjs +1 -1
  51. package/dist/charts/engine/model.cjs.map +1 -1
  52. package/dist/charts/engine/model.d.cts +30 -3
  53. package/dist/charts/engine/model.d.ts +30 -3
  54. package/dist/charts/engine/model.js +225 -108
  55. package/dist/charts/engine/model.js.map +1 -1
  56. package/dist/charts/engine/overlay.cjs +1 -1
  57. package/dist/charts/engine/overlay.cjs.map +1 -1
  58. package/dist/charts/engine/overlay.d.cts +2 -0
  59. package/dist/charts/engine/overlay.d.ts +2 -0
  60. package/dist/charts/engine/overlay.js +16 -16
  61. package/dist/charts/engine/overlay.js.map +1 -1
  62. package/dist/charts/engine/presets.cjs +2 -2
  63. package/dist/charts/engine/presets.cjs.map +1 -1
  64. package/dist/charts/engine/presets.d.cts +71 -5
  65. package/dist/charts/engine/presets.d.ts +71 -5
  66. package/dist/charts/engine/presets.js +120 -33
  67. package/dist/charts/engine/presets.js.map +1 -1
  68. package/dist/charts/engine/renderers/canvas2d.cjs +1 -1
  69. package/dist/charts/engine/renderers/canvas2d.cjs.map +1 -1
  70. package/dist/charts/engine/renderers/canvas2d.js +149 -111
  71. package/dist/charts/engine/renderers/canvas2d.js.map +1 -1
  72. package/dist/charts/engine/renderers/range.cjs +1 -1
  73. package/dist/charts/engine/renderers/range.cjs.map +1 -1
  74. package/dist/charts/engine/renderers/range.js +4 -4
  75. package/dist/charts/engine/renderers/range.js.map +1 -1
  76. package/dist/charts/engine/renderers/shaders.cjs +37 -19
  77. package/dist/charts/engine/renderers/shaders.cjs.map +1 -1
  78. package/dist/charts/engine/renderers/shaders.d.cts +2 -2
  79. package/dist/charts/engine/renderers/shaders.d.ts +2 -2
  80. package/dist/charts/engine/renderers/shaders.js +37 -19
  81. package/dist/charts/engine/renderers/shaders.js.map +1 -1
  82. package/dist/charts/engine/renderers/types.cjs.map +1 -1
  83. package/dist/charts/engine/renderers/types.d.cts +11 -4
  84. package/dist/charts/engine/renderers/types.d.ts +11 -4
  85. package/dist/charts/engine/renderers/types.js.map +1 -1
  86. package/dist/charts/engine/renderers/webgl2.cjs +1 -1
  87. package/dist/charts/engine/renderers/webgl2.cjs.map +1 -1
  88. package/dist/charts/engine/renderers/webgl2.js +33 -12
  89. package/dist/charts/engine/renderers/webgl2.js.map +1 -1
  90. package/dist/charts/engine/renderers/webgpu.cjs +1 -1
  91. package/dist/charts/engine/renderers/webgpu.cjs.map +1 -1
  92. package/dist/charts/engine/renderers/webgpu.js +18 -15
  93. package/dist/charts/engine/renderers/webgpu.js.map +1 -1
  94. package/dist/charts/engine/scene.cjs +1 -1
  95. package/dist/charts/engine/scene.cjs.map +1 -1
  96. package/dist/charts/engine/scene.d.cts +19 -6
  97. package/dist/charts/engine/scene.d.ts +19 -6
  98. package/dist/charts/engine/scene.js +201 -89
  99. package/dist/charts/engine/scene.js.map +1 -1
  100. package/dist/charts/engine/shapes/canvas.cjs +2 -0
  101. package/dist/charts/engine/shapes/canvas.cjs.map +1 -0
  102. package/dist/charts/engine/shapes/canvas.d.cts +58 -0
  103. package/dist/charts/engine/shapes/canvas.d.ts +58 -0
  104. package/dist/charts/engine/shapes/canvas.js +159 -0
  105. package/dist/charts/engine/shapes/canvas.js.map +1 -0
  106. package/dist/charts/engine/shapes/chart.cjs +2 -0
  107. package/dist/charts/engine/shapes/chart.cjs.map +1 -0
  108. package/dist/charts/engine/shapes/chart.d.cts +6 -0
  109. package/dist/charts/engine/shapes/chart.d.ts +6 -0
  110. package/dist/charts/engine/shapes/chart.js +273 -0
  111. package/dist/charts/engine/shapes/chart.js.map +1 -0
  112. package/dist/charts/engine/shapes/draw.cjs +2 -0
  113. package/dist/charts/engine/shapes/draw.cjs.map +1 -0
  114. package/dist/charts/engine/shapes/draw.d.cts +20 -0
  115. package/dist/charts/engine/shapes/draw.d.ts +20 -0
  116. package/dist/charts/engine/shapes/draw.js +152 -0
  117. package/dist/charts/engine/shapes/draw.js.map +1 -0
  118. package/dist/charts/engine/shapes/funnel.cjs +2 -0
  119. package/dist/charts/engine/shapes/funnel.cjs.map +1 -0
  120. package/dist/charts/engine/shapes/funnel.d.cts +6 -0
  121. package/dist/charts/engine/shapes/funnel.d.ts +6 -0
  122. package/dist/charts/engine/shapes/funnel.js +149 -0
  123. package/dist/charts/engine/shapes/funnel.js.map +1 -0
  124. package/dist/charts/engine/shapes/gauge.cjs +2 -0
  125. package/dist/charts/engine/shapes/gauge.cjs.map +1 -0
  126. package/dist/charts/engine/shapes/gauge.d.cts +7 -0
  127. package/dist/charts/engine/shapes/gauge.d.ts +7 -0
  128. package/dist/charts/engine/shapes/gauge.js +173 -0
  129. package/dist/charts/engine/shapes/gauge.js.map +1 -0
  130. package/dist/charts/engine/shapes/hit.cjs +2 -0
  131. package/dist/charts/engine/shapes/hit.cjs.map +1 -0
  132. package/dist/charts/engine/shapes/hit.d.cts +28 -0
  133. package/dist/charts/engine/shapes/hit.d.ts +28 -0
  134. package/dist/charts/engine/shapes/hit.js +124 -0
  135. package/dist/charts/engine/shapes/hit.js.map +1 -0
  136. package/dist/charts/engine/shapes/index.d.cts +9 -0
  137. package/dist/charts/engine/shapes/index.d.ts +9 -0
  138. package/dist/charts/engine/shapes/layout.cjs +3 -0
  139. package/dist/charts/engine/shapes/layout.cjs.map +1 -0
  140. package/dist/charts/engine/shapes/layout.d.cts +88 -0
  141. package/dist/charts/engine/shapes/layout.d.ts +88 -0
  142. package/dist/charts/engine/shapes/layout.js +266 -0
  143. package/dist/charts/engine/shapes/layout.js.map +1 -0
  144. package/dist/charts/engine/shapes/pie.cjs +2 -0
  145. package/dist/charts/engine/shapes/pie.cjs.map +1 -0
  146. package/dist/charts/engine/shapes/pie.d.cts +20 -0
  147. package/dist/charts/engine/shapes/pie.d.ts +20 -0
  148. package/dist/charts/engine/shapes/pie.js +302 -0
  149. package/dist/charts/engine/shapes/pie.js.map +1 -0
  150. package/dist/charts/engine/shapes/radar.cjs +2 -0
  151. package/dist/charts/engine/shapes/radar.cjs.map +1 -0
  152. package/dist/charts/engine/shapes/radar.d.cts +8 -0
  153. package/dist/charts/engine/shapes/radar.d.ts +8 -0
  154. package/dist/charts/engine/shapes/radar.js +197 -0
  155. package/dist/charts/engine/shapes/radar.js.map +1 -0
  156. package/dist/charts/engine/shapes/runtime.cjs +2 -0
  157. package/dist/charts/engine/shapes/runtime.cjs.map +1 -0
  158. package/dist/charts/engine/shapes/runtime.d.cts +29 -0
  159. package/dist/charts/engine/shapes/runtime.d.ts +29 -0
  160. package/dist/charts/engine/shapes/runtime.js +97 -0
  161. package/dist/charts/engine/shapes/runtime.js.map +1 -0
  162. package/dist/charts/engine/shapes/scene.cjs +2 -0
  163. package/dist/charts/engine/shapes/scene.cjs.map +1 -0
  164. package/dist/charts/engine/shapes/scene.d.cts +257 -0
  165. package/dist/charts/engine/shapes/scene.d.ts +257 -0
  166. package/dist/charts/engine/shapes/scene.js +123 -0
  167. package/dist/charts/engine/shapes/scene.js.map +1 -0
  168. package/dist/charts/engine/shapes/treemap.cjs +2 -0
  169. package/dist/charts/engine/shapes/treemap.cjs.map +1 -0
  170. package/dist/charts/engine/shapes/treemap.d.cts +14 -0
  171. package/dist/charts/engine/shapes/treemap.d.ts +14 -0
  172. package/dist/charts/engine/shapes/treemap.js +213 -0
  173. package/dist/charts/engine/shapes/treemap.js.map +1 -0
  174. package/dist/charts/engine/shapes/types.d.cts +292 -0
  175. package/dist/charts/engine/shapes/types.d.ts +292 -0
  176. package/dist/charts/engine/signature.cjs +2 -0
  177. package/dist/charts/engine/signature.cjs.map +1 -0
  178. package/dist/charts/engine/signature.d.cts +9 -0
  179. package/dist/charts/engine/signature.d.ts +9 -0
  180. package/dist/charts/engine/signature.js +13 -0
  181. package/dist/charts/engine/signature.js.map +1 -0
  182. package/dist/charts/engine/theme.cjs +1 -1
  183. package/dist/charts/engine/theme.cjs.map +1 -1
  184. package/dist/charts/engine/theme.d.cts +10 -1
  185. package/dist/charts/engine/theme.d.ts +10 -1
  186. package/dist/charts/engine/theme.js +40 -16
  187. package/dist/charts/engine/theme.js.map +1 -1
  188. package/dist/charts/engine/types.d.cts +70 -9
  189. package/dist/charts/engine/types.d.ts +70 -9
  190. package/dist/charts/index.cjs +1 -1
  191. package/dist/charts/index.d.cts +4 -2
  192. package/dist/charts/index.d.ts +4 -2
  193. package/dist/charts/index.js +8 -5
  194. package/dist/charts/react/Chart.cjs +1 -1
  195. package/dist/charts/react/Chart.cjs.map +1 -1
  196. package/dist/charts/react/Chart.d.cts +8 -1
  197. package/dist/charts/react/Chart.d.ts +8 -1
  198. package/dist/charts/react/Chart.js +66 -47
  199. package/dist/charts/react/Chart.js.map +1 -1
  200. package/dist/charts/react/charts.cjs +1 -1
  201. package/dist/charts/react/charts.cjs.map +1 -1
  202. package/dist/charts/react/charts.d.cts +10 -2
  203. package/dist/charts/react/charts.d.ts +10 -2
  204. package/dist/charts/react/charts.js +174 -51
  205. package/dist/charts/react/charts.js.map +1 -1
  206. package/dist/charts/react/shapes.cjs +2 -0
  207. package/dist/charts/react/shapes.cjs.map +1 -0
  208. package/dist/charts/react/shapes.d.cts +255 -0
  209. package/dist/charts/react/shapes.d.ts +255 -0
  210. package/dist/charts/react/shapes.js +242 -0
  211. package/dist/charts/react/shapes.js.map +1 -0
  212. package/dist/charts/react/types.d.cts +73 -4
  213. package/dist/charts/react/types.d.ts +73 -4
  214. package/dist/native/charts/src/engine/color.cjs +1 -1
  215. package/dist/native/charts/src/engine/color.cjs.map +1 -1
  216. package/dist/native/charts/src/engine/color.js +12 -3
  217. package/dist/native/charts/src/engine/color.js.map +1 -1
  218. package/dist/native/charts/src/engine/controller.cjs +2 -2
  219. package/dist/native/charts/src/engine/controller.cjs.map +1 -1
  220. package/dist/native/charts/src/engine/controller.js +334 -270
  221. package/dist/native/charts/src/engine/controller.js.map +1 -1
  222. package/dist/native/charts/src/engine/curve.cjs +2 -0
  223. package/dist/native/charts/src/engine/curve.cjs.map +1 -0
  224. package/dist/native/charts/src/engine/curve.js +56 -0
  225. package/dist/native/charts/src/engine/curve.js.map +1 -0
  226. package/dist/native/charts/src/engine/data.cjs +1 -1
  227. package/dist/native/charts/src/engine/data.cjs.map +1 -1
  228. package/dist/native/charts/src/engine/data.js +98 -38
  229. package/dist/native/charts/src/engine/data.js.map +1 -1
  230. package/dist/native/charts/src/engine/model.cjs +1 -1
  231. package/dist/native/charts/src/engine/model.cjs.map +1 -1
  232. package/dist/native/charts/src/engine/model.js +229 -112
  233. package/dist/native/charts/src/engine/model.js.map +1 -1
  234. package/dist/native/charts/src/engine/overlay.cjs +1 -1
  235. package/dist/native/charts/src/engine/overlay.cjs.map +1 -1
  236. package/dist/native/charts/src/engine/overlay.js +16 -16
  237. package/dist/native/charts/src/engine/overlay.js.map +1 -1
  238. package/dist/native/charts/src/engine/presets.cjs +1 -1
  239. package/dist/native/charts/src/engine/presets.cjs.map +1 -1
  240. package/dist/native/charts/src/engine/presets.js +11 -4
  241. package/dist/native/charts/src/engine/presets.js.map +1 -1
  242. package/dist/native/charts/src/engine/scene.cjs +1 -1
  243. package/dist/native/charts/src/engine/scene.cjs.map +1 -1
  244. package/dist/native/charts/src/engine/scene.js +209 -97
  245. package/dist/native/charts/src/engine/scene.js.map +1 -1
  246. package/dist/native/charts/src/engine/theme.cjs.map +1 -1
  247. package/dist/native/charts/src/engine/theme.js.map +1 -1
  248. package/dist/native/components/Chart/scene.cjs +1 -1
  249. package/dist/native/components/Chart/scene.cjs.map +1 -1
  250. package/dist/native/components/Chart/scene.js +31 -19
  251. package/dist/native/components/Chart/scene.js.map +1 -1
  252. package/dist/native/source/components/Chart/scene.tsx +54 -20
  253. package/dist/taro/index.js +1059 -579
  254. package/dist/uni/charts-canvas.js +3 -1
  255. package/dist/weapp/controls.js +966 -225
  256. package/package.json +1 -1
@@ -0,0 +1,292 @@
1
+ import { ChartPadding } from '../types.js';
2
+ /** Kind of shape chart */
3
+ export type ShapeChartType = "pie" | "radar" | "gauge" | "funnel" | "treemap";
4
+ /** A named value (pie slice, funnel stage) */
5
+ export interface ShapeDatum {
6
+ /** Name shown in the legend, the labels and the tooltip */
7
+ name: string;
8
+ /** Value (negative values count as 0) */
9
+ value: number;
10
+ /** Color (any CSS color, `var(--x)` included); the palette when omitted */
11
+ color?: string;
12
+ }
13
+ /** Legend of a shape chart */
14
+ export interface ShapeLegendOptions {
15
+ /**
16
+ * Legend position
17
+ * @default "bottom"
18
+ */
19
+ position?: "top" | "bottom";
20
+ /**
21
+ * Clicking an item hides / shows its slice, stage or series
22
+ * @default true
23
+ */
24
+ toggle?: boolean;
25
+ }
26
+ /** What the pointer is over */
27
+ export interface ShapeHoverEvent {
28
+ /** Index of the slice / stage / series / leaf (treemap: in the flattened leaves) */
29
+ index: number;
30
+ /** Radar: index of the indicator closest to the pointer */
31
+ indicator?: number;
32
+ name: string;
33
+ value: number;
34
+ /** Share of the total, 0-1 (pie: of the visible total, funnel: of the first stage, treemap: of the root, gauge: of the range) */
35
+ percent: number;
36
+ /** Resolved CSS color of the mark */
37
+ color: string;
38
+ /** Treemap: names from the root to the leaf */
39
+ path?: string[];
40
+ }
41
+ /** Tooltip of a shape chart */
42
+ export interface ShapeTooltipOptions {
43
+ /** Renders the tooltip content (a string is set as text) */
44
+ render?: (event: ShapeHoverEvent) => string | Node | null;
45
+ }
46
+ /** Options shared by every shape chart */
47
+ export interface ShapeChartCommonOptions {
48
+ /** Colors of the marks without `color` (defaults to the `--chart-series-1..8` CSS variables, then the theme colors) */
49
+ palette?: readonly string[];
50
+ /** Legend; shown by default for pie, funnel and multi-series radar charts */
51
+ legend?: boolean | ShapeLegendOptions;
52
+ /** Tooltip; `false` disables it */
53
+ tooltip?: boolean | ShapeTooltipOptions;
54
+ /** Formats the values (labels, tooltip); compact numbers (1.2k, 3.4M) by default */
55
+ format?: (value: number) => string;
56
+ /**
57
+ * Formats the shares (labels, conversion rates, tooltip); `share` is 0-1
58
+ * @default one decimal, e.g. "40.0%"
59
+ */
60
+ percentFormat?: (share: number) => string;
61
+ /**
62
+ * Indexes of the hidden slices / stages / radar series / top-level treemap
63
+ * nodes. When set, the chart is controlled: this list wins over the legend
64
+ * state, and legend clicks (or `toggle()`) only emit the `toggle` event,
65
+ * whose `hiddenIndexes` should be passed back here.
66
+ */
67
+ hidden?: readonly number[];
68
+ /**
69
+ * Entry / update animation (skipped when the user prefers reduced motion)
70
+ * @default true
71
+ */
72
+ animation?: boolean;
73
+ /** Space around the drawing, in CSS pixels */
74
+ padding?: ChartPadding;
75
+ /** Accessible name of the chart */
76
+ ariaLabel?: string;
77
+ }
78
+ /** Pie / donut chart */
79
+ export interface PieChartOptions extends ShapeChartCommonOptions {
80
+ type: "pie";
81
+ data: readonly ShapeDatum[];
82
+ /**
83
+ * Inner radius as a fraction of the outer radius: 0 = pie, 0.6 = donut
84
+ * @default 0
85
+ */
86
+ innerRadius?: number;
87
+ /**
88
+ * Angle of the first slice, degrees clockwise from 12 o'clock
89
+ * @default 0
90
+ */
91
+ startAngle?: number;
92
+ /**
93
+ * Gap between the slices, in pixels
94
+ * @default 1 (pie), 2 (donut)
95
+ */
96
+ padAngle?: number;
97
+ /**
98
+ * Corner radius of the slices, in pixels
99
+ * @default 0 (pie), 4 (donut)
100
+ */
101
+ cornerRadius?: number;
102
+ /**
103
+ * Nightingale rose: the radius (instead of the angle) shows the value
104
+ * @default false
105
+ */
106
+ rose?: boolean;
107
+ /**
108
+ * Slice labels: `outside` with leader lines, `inside` the slices, or none
109
+ * @default "outside" (up to 12 slices), "none" otherwise
110
+ */
111
+ labels?: "outside" | "inside" | "none";
112
+ /** What a label shows: name, value, percent (combinable) */
113
+ labelContent?: readonly ("name" | "value" | "percent")[];
114
+ /** Big text in the hole of a donut (e.g. the total) */
115
+ centerValue?: string;
116
+ /** Small text under `centerValue` */
117
+ centerLabel?: string;
118
+ }
119
+ /** An axis of a radar chart */
120
+ export interface RadarIndicator {
121
+ name: string;
122
+ /** Value at the rim; the largest value of the series when omitted */
123
+ max?: number;
124
+ /**
125
+ * Value at the center
126
+ * @default 0
127
+ */
128
+ min?: number;
129
+ }
130
+ /** A polygon of a radar chart */
131
+ export interface RadarSeries {
132
+ name?: string;
133
+ /** One value per indicator */
134
+ values: readonly number[];
135
+ color?: string;
136
+ /**
137
+ * Fill opacity, 0-1
138
+ * @default 0.18
139
+ */
140
+ opacity?: number;
141
+ }
142
+ /** Radar (spider) chart */
143
+ export interface RadarChartOptions extends ShapeChartCommonOptions {
144
+ type: "radar";
145
+ indicators: readonly RadarIndicator[];
146
+ series: readonly RadarSeries[];
147
+ /**
148
+ * Grid shape
149
+ * @default "polygon"
150
+ */
151
+ shape?: "polygon" | "circle";
152
+ /**
153
+ * Number of grid rings
154
+ * @default 4
155
+ */
156
+ levels?: number;
157
+ /**
158
+ * Dots on the vertices
159
+ * @default true
160
+ */
161
+ dots?: boolean;
162
+ }
163
+ /** A colored range of a gauge */
164
+ export interface GaugeBand {
165
+ /** Upper bound of the band (the previous band's bound, or `min`, is the lower one) */
166
+ to: number;
167
+ color: string;
168
+ }
169
+ /** Gauge (speedometer) chart */
170
+ export interface GaugeChartOptions extends ShapeChartCommonOptions {
171
+ type: "gauge";
172
+ value: number;
173
+ /** @default 0 */
174
+ min?: number;
175
+ /** @default 100 */
176
+ max?: number;
177
+ /** Caption under the value */
178
+ label?: string;
179
+ /**
180
+ * Total angle of the arc, degrees
181
+ * @default 240
182
+ */
183
+ sweep?: number;
184
+ /**
185
+ * Thickness of the arc as a fraction of the radius
186
+ * @default 0.16
187
+ */
188
+ thickness?: number;
189
+ /** Colored ranges of the track; the value arc takes the color of its band */
190
+ bands?: readonly GaugeBand[];
191
+ /** Color of the value arc (when there are no bands); the first palette color by default */
192
+ color?: string;
193
+ /**
194
+ * Draws a needle in addition to the value arc
195
+ * @default false
196
+ */
197
+ needle?: boolean;
198
+ /**
199
+ * Tick labels at the ends (and at the band bounds)
200
+ * @default true
201
+ */
202
+ ticks?: boolean;
203
+ }
204
+ /** Funnel chart */
205
+ export interface FunnelChartOptions extends ShapeChartCommonOptions {
206
+ type: "funnel";
207
+ data: readonly ShapeDatum[];
208
+ /**
209
+ * Order of the stages
210
+ * @default "none" (data order)
211
+ */
212
+ sort?: "descending" | "ascending" | "none";
213
+ /**
214
+ * Vertical gap between the stages, in pixels
215
+ * @default 4
216
+ */
217
+ gap?: number;
218
+ /**
219
+ * Shows the conversion rate from the previous stage
220
+ * @default true
221
+ */
222
+ conversion?: boolean;
223
+ /**
224
+ * Shape of the stages: trapezoids that narrow to the next stage, or centered bars
225
+ * @default "trapezoid"
226
+ */
227
+ shape?: "trapezoid" | "bar";
228
+ }
229
+ /** A node of a treemap: leaves carry a value, parents sum their children */
230
+ export interface TreemapNode {
231
+ name: string;
232
+ value?: number;
233
+ color?: string;
234
+ children?: readonly TreemapNode[];
235
+ }
236
+ /** Treemap chart */
237
+ export interface TreemapChartOptions extends ShapeChartCommonOptions {
238
+ type: "treemap";
239
+ data: readonly TreemapNode[];
240
+ /**
241
+ * Gap between the cells, in pixels
242
+ * @default 2
243
+ */
244
+ gap?: number;
245
+ /**
246
+ * Draws the names of the parents above their children
247
+ * @default true
248
+ */
249
+ headers?: boolean;
250
+ }
251
+ /** Options of a shape chart, by `type` */
252
+ export type ShapeChartOptions = PieChartOptions | RadarChartOptions | GaugeChartOptions | FunnelChartOptions | TreemapChartOptions;
253
+ /** A legend item was clicked (or `toggle()` was called) */
254
+ export interface ShapeToggleEvent {
255
+ /** Index of the slice / stage / radar series / top-level treemap node */
256
+ index: number;
257
+ /** Whether that entry is (or, in a controlled chart, would be) hidden */
258
+ hidden: boolean;
259
+ /** Every hidden index after the toggle, ascending */
260
+ hiddenIndexes: number[];
261
+ }
262
+ /** Events of a shape chart */
263
+ export interface ShapeChartEventMap {
264
+ hover: ShapeHoverEvent | null;
265
+ click: ShapeHoverEvent;
266
+ /**
267
+ * Legend click or `toggle()` call. Uncontrolled charts emit it after
268
+ * hiding / showing the entry; with the `hidden` option nothing changes
269
+ * until the new `hiddenIndexes` are passed back.
270
+ */
271
+ toggle: ShapeToggleEvent;
272
+ }
273
+ /** Shape chart created by `createShapeChart` */
274
+ export interface ShapeChartInstance {
275
+ /** Replaces the options (animates from the previous values) */
276
+ setOptions(options: ShapeChartOptions): void;
277
+ /** Measures the container again (a ResizeObserver does it automatically) */
278
+ resize(): void;
279
+ /** Reads the CSS variables again (theme changes on `<html>` / `<body>` are detected automatically) */
280
+ refreshTheme(): void;
281
+ /**
282
+ * Hides / shows a slice, stage, radar series or top-level treemap node by
283
+ * index and emits `toggle` (with the `hidden` option: only emits `toggle`)
284
+ */
285
+ toggle(index: number): void;
286
+ /** Indexes of the hidden entries, ascending */
287
+ getHidden(): number[];
288
+ /** Subscribes to an event; returns the unsubscribe function */
289
+ on<K extends keyof ShapeChartEventMap>(type: K, listener: (event: ShapeChartEventMap[K]) => void): () => void;
290
+ /** Removes the DOM */
291
+ destroy(): void;
292
+ }
@@ -0,0 +1,2 @@
1
+ var e=new WeakMap,t=0,n=n=>{let r=e.get(n);return r===void 0&&e.set(n,r=++t),r},r=(e,t,r)=>{let{base:i}=e,a=`${t}|${e.baseline}|${e.percent}|${i.x[0]},${i.x[1]}|${i.y[0]},${i.y[1]}`;for(let t of e.series)a+=`\n${t.key}|${t.type}|${n(t.cols)}|${t.colorCss}|${t.hidden}|${t.lineWidth}|${t.pointSize}|${t.opacity}|${t.barOffset}|${t.barHalfWidth}|${r(t.index)??``}|${t.curve}|${t.radius}`,t.type===`candlestick`?a+=`|${t.upColor}/${t.downColor}`:t.type===`heatmap`&&(a+=`|${t.colorScale.join(`;`)}/${t.valueRange[0]},${t.valueRange[1]}/${t.cellHalf.x},${t.cellHalf.y}`);return a};exports.itemsSignature=r;
2
+ //# sourceMappingURL=signature.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.cjs","names":["ids","counter","idOf","id","value","itemsSignature","model","signature","themeKey","base","s","stackOf"],"sources":["../../../../charts/src/engine/signature.ts"],"sourcesContent":["// Signature of what the render items (GPU buffers) of a model depend on:\n// when it is unchanged, the items of the previous model can be kept.\n\nimport type { ChartModel } from \"./model\";\n\nconst ids = new WeakMap<object, number>();\nlet counter = 0;\n\n/** Stable id of an object (data columns compare by identity) */\nconst idOf = (value: object): number => {\n let id = ids.get(value);\n if (id === undefined) ids.set(value, (id = ++counter));\n return id;\n};\n\n/**\n * Every input of `buildItems` (and of the origin of its positions): data\n * identity, types, colors, visibility, widths, bar layout, stacks, curves,\n * radii, candlestick and heatmap colors. `themeKey` covers the colors resolved\n * from the theme that the model doesn't spell out (per-point colors);\n * `stackOf` gives the `stack` option of a series.\n */\nexport const itemsSignature = (\n model: ChartModel,\n themeKey: number | string,\n stackOf: (index: number) => string | undefined,\n): string => {\n const { base } = model;\n let signature = `${themeKey}|${model.baseline}|${model.percent}|${base.x[0]},${base.x[1]}|${base.y[0]},${base.y[1]}`;\n for (const s of model.series) {\n signature += `\\n${s.key}|${s.type}|${idOf(s.cols)}|${s.colorCss}|${s.hidden}|${s.lineWidth}|${s.pointSize}|${s.opacity}|${s.barOffset}|${s.barHalfWidth}|${stackOf(s.index) ?? \"\"}|${s.curve}|${s.radius}`;\n if (s.type === \"candlestick\") signature += `|${s.upColor}/${s.downColor}`;\n else if (s.type === \"heatmap\")\n signature += `|${s.colorScale.join(\";\")}/${s.valueRange[0]},${s.valueRange[1]}/${s.cellHalf.x},${s.cellHalf.y}`;\n }\n return signature;\n};\n"],"mappings":"AAKA,IAAMA,EAAM,IAAI,QACZC,EAAU,EAGRC,EAAQ,GAA0B,CACtC,IAAIC,EAAKH,EAAI,IAAII,CAAK,EAEtB,OADID,IAAO,IAAA,IAAWH,EAAI,IAAII,EAAQ,EAAK,EAAEH,CAAQ,EAC9CE,CACT,EASaE,GACX,EACA,EACA,IACW,CACX,GAAM,CAAE,QAASC,EACbC,EAAY,GAAGC,EAAS,GAAGF,EAAM,SAAS,GAAGA,EAAM,QAAQ,GAAGG,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE,KAChH,IAAK,IAAMC,KAAKJ,EAAM,OACpB,GAAa,KAAKI,EAAE,IAAI,GAAGA,EAAE,KAAK,GAAGR,EAAKQ,EAAE,IAAI,EAAE,GAAGA,EAAE,SAAS,GAAGA,EAAE,OAAO,GAAGA,EAAE,UAAU,GAAGA,EAAE,UAAU,GAAGA,EAAE,QAAQ,GAAGA,EAAE,UAAU,GAAGA,EAAE,aAAa,GAAGC,EAAQD,EAAE,KAAK,GAAK,GAAG,GAAGA,EAAE,MAAM,GAAGA,EAAE,SAC9LA,EAAE,OAAS,cAAe,GAAa,IAAIA,EAAE,QAAQ,GAAGA,EAAE,YACrDA,EAAE,OAAS,YAClB,GAAa,IAAIA,EAAE,WAAW,KAAK,GAAG,EAAE,GAAGA,EAAE,WAAW,GAAG,GAAGA,EAAE,WAAW,GAAG,GAAGA,EAAE,SAAS,EAAE,GAAGA,EAAE,SAAS,KAEhH,OAAOH,CACT"}
@@ -0,0 +1,9 @@
1
+ import { ChartModel } from './model.cjs';
2
+ /**
3
+ * Every input of `buildItems` (and of the origin of its positions): data
4
+ * identity, types, colors, visibility, widths, bar layout, stacks, curves,
5
+ * radii, candlestick and heatmap colors. `themeKey` covers the colors resolved
6
+ * from the theme that the model doesn't spell out (per-point colors);
7
+ * `stackOf` gives the `stack` option of a series.
8
+ */
9
+ export declare const itemsSignature: (model: ChartModel, themeKey: number | string, stackOf: (index: number) => string | undefined) => string;
@@ -0,0 +1,9 @@
1
+ import { ChartModel } from './model.js';
2
+ /**
3
+ * Every input of `buildItems` (and of the origin of its positions): data
4
+ * identity, types, colors, visibility, widths, bar layout, stacks, curves,
5
+ * radii, candlestick and heatmap colors. `themeKey` covers the colors resolved
6
+ * from the theme that the model doesn't spell out (per-point colors);
7
+ * `stackOf` gives the `stack` option of a series.
8
+ */
9
+ export declare const itemsSignature: (model: ChartModel, themeKey: number | string, stackOf: (index: number) => string | undefined) => string;
@@ -0,0 +1,13 @@
1
+ //#region src/engine/signature.ts
2
+ var e = /* @__PURE__ */ new WeakMap(), t = 0, n = (n) => {
3
+ let r = e.get(n);
4
+ return r === void 0 && e.set(n, r = ++t), r;
5
+ }, r = (e, t, r) => {
6
+ let { base: i } = e, a = `${t}|${e.baseline}|${e.percent}|${i.x[0]},${i.x[1]}|${i.y[0]},${i.y[1]}`;
7
+ for (let t of e.series) a += `\n${t.key}|${t.type}|${n(t.cols)}|${t.colorCss}|${t.hidden}|${t.lineWidth}|${t.pointSize}|${t.opacity}|${t.barOffset}|${t.barHalfWidth}|${r(t.index) ?? ""}|${t.curve}|${t.radius}`, t.type === "candlestick" ? a += `|${t.upColor}/${t.downColor}` : t.type === "heatmap" && (a += `|${t.colorScale.join(";")}/${t.valueRange[0]},${t.valueRange[1]}/${t.cellHalf.x},${t.cellHalf.y}`);
8
+ return a;
9
+ };
10
+ //#endregion
11
+ export { r as itemsSignature };
12
+
13
+ //# sourceMappingURL=signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","names":["ids","counter","idOf","id","value","itemsSignature","model","signature","themeKey","base","s","stackOf"],"sources":["../../../../charts/src/engine/signature.ts"],"sourcesContent":["// Signature of what the render items (GPU buffers) of a model depend on:\n// when it is unchanged, the items of the previous model can be kept.\n\nimport type { ChartModel } from \"./model\";\n\nconst ids = new WeakMap<object, number>();\nlet counter = 0;\n\n/** Stable id of an object (data columns compare by identity) */\nconst idOf = (value: object): number => {\n let id = ids.get(value);\n if (id === undefined) ids.set(value, (id = ++counter));\n return id;\n};\n\n/**\n * Every input of `buildItems` (and of the origin of its positions): data\n * identity, types, colors, visibility, widths, bar layout, stacks, curves,\n * radii, candlestick and heatmap colors. `themeKey` covers the colors resolved\n * from the theme that the model doesn't spell out (per-point colors);\n * `stackOf` gives the `stack` option of a series.\n */\nexport const itemsSignature = (\n model: ChartModel,\n themeKey: number | string,\n stackOf: (index: number) => string | undefined,\n): string => {\n const { base } = model;\n let signature = `${themeKey}|${model.baseline}|${model.percent}|${base.x[0]},${base.x[1]}|${base.y[0]},${base.y[1]}`;\n for (const s of model.series) {\n signature += `\\n${s.key}|${s.type}|${idOf(s.cols)}|${s.colorCss}|${s.hidden}|${s.lineWidth}|${s.pointSize}|${s.opacity}|${s.barOffset}|${s.barHalfWidth}|${stackOf(s.index) ?? \"\"}|${s.curve}|${s.radius}`;\n if (s.type === \"candlestick\") signature += `|${s.upColor}/${s.downColor}`;\n else if (s.type === \"heatmap\")\n signature += `|${s.colorScale.join(\";\")}/${s.valueRange[0]},${s.valueRange[1]}/${s.cellHalf.x},${s.cellHalf.y}`;\n }\n return signature;\n};\n"],"mappings":";AAKA,IAAMA,oBAAM,IAAI,QAAwB,GACpCC,IAAU,GAGRC,KAAQ,MAA0B;CACtC,IAAIC,IAAKH,EAAI,IAAII,CAAK;CAEtB,OADID,MAAO,KAAA,KAAWH,EAAI,IAAII,GAAQ,IAAK,EAAEH,CAAQ,GAC9CE;AACT,GASaE,KACX,GACA,GACA,MACW;CACX,IAAM,EAAE,YAASC,GACbC,IAAY,GAAGC,EAAS,GAAGF,EAAM,SAAS,GAAGA,EAAM,QAAQ,GAAGG,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE,GAAG,GAAGA,EAAK,EAAE;CAChH,KAAK,IAAMC,KAAKJ,EAAM,QAEpB,AADA,KAAa,KAAKI,EAAE,IAAI,GAAGA,EAAE,KAAK,GAAGR,EAAKQ,EAAE,IAAI,EAAE,GAAGA,EAAE,SAAS,GAAGA,EAAE,OAAO,GAAGA,EAAE,UAAU,GAAGA,EAAE,UAAU,GAAGA,EAAE,QAAQ,GAAGA,EAAE,UAAU,GAAGA,EAAE,aAAa,GAAGC,EAAQD,EAAE,KAAK,KAAK,GAAG,GAAGA,EAAE,MAAM,GAAGA,EAAE,UAC9LA,EAAE,SAAS,gBAAe,KAAa,IAAIA,EAAE,QAAQ,GAAGA,EAAE,cACrDA,EAAE,SAAS,cAClB,KAAa,IAAIA,EAAE,WAAW,KAAK,GAAG,EAAE,GAAGA,EAAE,WAAW,GAAG,GAAGA,EAAE,WAAW,GAAG,GAAGA,EAAE,SAAS,EAAE,GAAGA,EAAE,SAAS;CAEhH,OAAOH;AACT"}
@@ -1,2 +1,2 @@
1
- const e=require("./color.cjs");var t=[`#4f46e5`,`#10b981`,`#f59e0b`,`#ef4444`,`#0ea5e9`,`#8b5cf6`,`#14b8a6`,`#f97316`],n=(e,t)=>e?.getPropertyValue(t).trim()??``,r=(t,r)=>{let i=t&&typeof getComputedStyle==`function`?getComputedStyle(t):null;return o(e=>n(i,e),e.domColorResolver(t),r,i?.fontFamily??``)},i=(e={},t)=>{let n=e.variables??{};return{...o(e=>n[e]?.trim()??``,a(n),t?.length?t:e.palette,``),...e.fontFamily?{fontFamily:e.fontFamily}:{},...e.fontSize?{fontSize:e.fontSize}:{}}},a=t=>(n,r)=>e.resolveStaticColor(n,t,r),o=(n,r,i,a)=>{let o=[.4,.4,.4,1],s=e=>r(e,o),c=(e,t)=>{for(let t of e)if(n(t))return s(`var(${t})`);return s(t)},l=c([`--surface-color`,`--background-color`],`#ffffff`),u=c([`--text-color`],`#1f2937`),d=c([`--text-secondary-color`,`--text-muted-color`],`#6b7280`),f=c([`--border-color`],`#e5e7eb`),p;if(i&&i.length)p=i.map(e=>s(e));else{let e=[];for(let t=1;t<=8;t++){let r=`--chart-series-${t}`;n(r)&&e.push(s(`var(${r})`))}p=e.length?e:[...[`--primary-color`,`--success-color`,`--warning-color`,`--danger-color`,`--info-color`].map((e,r)=>n(e)?s(`var(${e})`):s(t[r])),...t.slice(5).map(e=>s(e))]}let m=n(`--font-family-sans`)||a||`system-ui, -apple-system, 'Segoe UI', sans-serif`;return{palette:p,text:u,textMuted:d,grid:e.mix(l,f,.75),axis:f,background:l,surface:l,primary:p[0],fontFamily:m,fontSize:11,resolve:r}},s=e=>{if(typeof document>`u`)return()=>{};let t=[];if(typeof MutationObserver==`function`){let n=new MutationObserver(e);for(let e of[document.documentElement,document.body])e&&n.observe(e,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-mode`]});t.push(()=>n.disconnect())}if(typeof matchMedia==`function`){let n=matchMedia(`(prefers-color-scheme: dark)`);n.addEventListener?.(`change`,e),t.push(()=>n.removeEventListener?.(`change`,e))}return()=>t.forEach(e=>e())};exports.createTheme=i,exports.readTheme=r,exports.staticColorResolver=a,exports.watchTheme=s;
1
+ const e=require("./color.cjs");var t=[`#4f46e5`,`#10b981`,`#f59e0b`,`#ef4444`,`#0ea5e9`,`#8b5cf6`,`#14b8a6`,`#f97316`],n=(e,t)=>e?.getPropertyValue(t).trim()??``,r=(t,r)=>{let i=t&&typeof getComputedStyle==`function`?getComputedStyle(t):null;return c(e=>n(i,e),e.memoizeColorResolver(e.domColorResolver(t)),r,i?.fontFamily??``)},i=[`text`,`textMuted`,`grid`,`axis`,`background`,`surface`,`primary`],a=(t,n)=>{if(t===n)return!1;if(t.palette.length!==n.palette.length||t.palette.some((t,r)=>!e.sameColor(t,n.palette[r]))||i.some(r=>!e.sameColor(t[r],n[r])))return!0;let r=t.resolve?.cache;if(!r||!n.resolve)return!0;let a=[NaN,NaN,NaN,NaN];for(let[t,i]of r){let r=n.resolve(t,a);if(!e.sameColor(i,r===a?null:r))return!0}return!1},o=(e={},t)=>{let n=e.variables??{};return{...c(e=>n[e]?.trim()??``,s(n),t?.length?t:e.palette,``),...e.fontFamily?{fontFamily:e.fontFamily}:{},...e.fontSize?{fontSize:e.fontSize}:{}}},s=t=>(n,r)=>e.resolveStaticColor(n,t,r),c=(n,r,i,a)=>{let o=[.4,.4,.4,1],s=e=>r(e,o),c=(e,t)=>{for(let t of e)if(n(t))return s(`var(${t})`);return s(t)},l=c([`--surface-color`,`--background-color`],`#ffffff`),u=c([`--text-color`],`#1f2937`),d=c([`--text-secondary-color`,`--text-muted-color`],`#6b7280`),f=c([`--border-color`],`#e5e7eb`),p;if(i&&i.length)p=i.map(e=>s(e));else{let e=[];for(let t=1;t<=8;t++){let r=`--chart-series-${t}`;n(r)&&e.push(s(`var(${r})`))}p=e.length?e:[...[`--primary-color`,`--success-color`,`--warning-color`,`--danger-color`,`--info-color`].map((e,r)=>n(e)?s(`var(${e})`):s(t[r])),...t.slice(5).map(e=>s(e))]}let m=n(`--font-family-sans`)||a||`system-ui, -apple-system, 'Segoe UI', sans-serif`;return{palette:p,text:u,textMuted:d,grid:e.mix(l,f,.75),axis:f,background:l,surface:l,primary:p[0],fontFamily:m,fontSize:11,resolve:r}},l=e=>{if(typeof document>`u`)return()=>{};let t=[];if(typeof MutationObserver==`function`){let n=new MutationObserver(e);for(let e of[document.documentElement,document.body])e&&n.observe(e,{attributes:!0,attributeFilter:[`class`,`style`,`data-theme`,`data-mode`]});t.push(()=>n.disconnect())}if(typeof matchMedia==`function`){let n=matchMedia(`(prefers-color-scheme: dark)`);n.addEventListener?.(`change`,e),t.push(()=>n.removeEventListener?.(`change`,e))}return()=>t.forEach(e=>e())};exports.createTheme=o,exports.readTheme=r,exports.staticColorResolver=s,exports.themeColorsChanged=a,exports.watchTheme=l;
2
2
  //# sourceMappingURL=theme.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.cjs","names":["domColorResolver","resolveStaticColor","mix","require_color","DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","palette","createTheme","variables","input","staticColorResolver","value","fallback","fallbackGray","resolveColor","resolve","color","names","readVariable","background","text","textMuted","border","colors","c","custom","i","fontFamily","inheritedFont","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n mix,\n resolveStaticColor,\n type ColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/** Reads the theme from the computed style of `element` */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n domColorResolver(element),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":"+BA2BA,IAAMI,EAAkB,CACtB,UACA,UACA,UACA,UACA,UACA,UACA,UACA,SACF,EAEMC,GAAW,EAAmC,IAClDC,GAAO,iBAAiBC,CAAI,CAAC,CAAC,KAAK,GAAK,GAG7BC,GACX,EACA,IACe,CACf,IAAMF,EACJG,GAAW,OAAO,kBAAqB,WACnC,iBAAiBA,CAAO,EACxB,KACN,OAAOC,EACJ,GAASL,EAAQC,EAAOC,CAAI,EAC7BP,EAAAA,iBAAiBS,CAAO,EACxBE,EACAL,GAAO,YAAc,EACvB,CACF,EAsBaM,GACX,EAAyB,CAAC,EAC1B,IACe,CACf,IAAMC,EAAYC,EAAM,WAAa,CAAC,EAOtC,MAAO,CACL,GAPYJ,EACX,GAASG,EAAUN,EAAK,EAAE,KAAK,GAAK,GACrCQ,EAAoBF,CAAS,EAC7BF,GAAS,OAASA,EAAUG,EAAM,QAClC,EAGG,EACH,GAAIA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CAAC,CACxD,CAEJ,CAEA,IAAMG,EACJT,EAAa,oBAAoB,GACjCU,GACA,mDAEF,MAAO,CACL,QAASL,EACT,OACA,YACA,KAAM1B,EAAAA,IAAIsB,EAAYG,EAAQ,GAAI,EAClC,KAAMA,EACN,aACA,QAASH,EACT,QAASI,EAAO,GAChB,aACA,SAAU,GACV,SACF,CACF,EAMaM,EAAc,GAAuC,CAChE,GAAI,OAAO,SAAa,IAAa,UAAa,CAAC,EACnD,IAAMC,EAA2B,CAAC,EAClC,GAAI,OAAO,kBAAqB,WAAY,CAC1C,IAAMC,EAAW,IAAI,iBAAiBC,CAAQ,EAC9C,IAAK,IAAMC,IAAQ,CAAC,SAAS,gBAAiB,SAAS,IAAI,EACrDA,GACFF,EAAS,QAAQE,EAAM,CACrB,WAAY,GACZ,gBAAiB,CAAC,QAAS,QAAS,aAAc,WAAW,CAC/D,CAAC,EAGLH,EAAS,SAAWC,EAAS,WAAW,CAAC,CAC3C,CACA,GAAI,OAAO,YAAe,WAAY,CACpC,IAAMG,EAAQ,WAAW,8BAA8B,EACvDA,EAAM,mBAAmB,SAAUF,CAAQ,EAC3CF,EAAS,SAAWI,EAAM,sBAAsB,SAAUF,CAAQ,CAAC,CACrE,CACA,UAAaF,EAAS,QAAS,GAAOK,EAAG,CAAC,CAC5C"}
1
+ {"version":3,"file":"theme.cjs","names":["memoizeColorResolver","domColorResolver","sameColor","resolveStaticColor","mix","require_color","DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","palette","THEME_COLORS","themeColorsChanged","previous","next","c","i","key","cache","probe","value","color","resolved","createTheme","variables","input","staticColorResolver","fallback","fallbackGray","resolveColor","resolve","names","readVariable","background","text","textMuted","border","colors","custom","fontFamily","inheritedFont","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n memoizeColorResolver,\n mix,\n resolveStaticColor,\n sameColor,\n type ColorResolver,\n type MemoizedColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/**\n * Reads the theme from the computed style of `element`. Its resolver caches\n * the colors (DOM probes are costly): read the theme again to see new values.\n */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n memoizeColorResolver(domColorResolver(element)),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\nconst THEME_COLORS = [\n \"text\",\n \"textMuted\",\n \"grid\",\n \"axis\",\n \"background\",\n \"surface\",\n \"primary\",\n] as const;\n\n/**\n * Whether `next` (a re-read of `previous`) resolves any color differently:\n * the theme colors, the palette and every color `previous` has resolved so\n * far (series, points, annotations...). `true` when it cannot tell.\n */\nexport const themeColorsChanged = (\n previous: ChartTheme,\n next: ChartTheme,\n): boolean => {\n if (previous === next) return false;\n if (previous.palette.length !== next.palette.length) return true;\n if (previous.palette.some((c, i) => !sameColor(c, next.palette[i])))\n return true;\n if (THEME_COLORS.some((key) => !sameColor(previous[key], next[key])))\n return true;\n const cache = (previous.resolve as Partial<MemoizedColorResolver> | undefined)\n ?.cache;\n if (!cache || !next.resolve) return true;\n const probe: Rgba = [NaN, NaN, NaN, NaN];\n for (const [value, color] of cache) {\n const resolved = next.resolve(value, probe);\n if (!sameColor(color, resolved === probe ? null : resolved)) return true;\n }\n return false;\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":"+BA8BA,IAAMM,EAAkB,CACtB,UACA,UACA,UACA,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,CACxD,CAEJ,CAEA,IAAMwB,EACJP,EAAa,oBAAoB,GACjCQ,GACA,mDAEF,MAAO,CACL,QAASH,EACT,OACA,YACA,KAAMpC,EAAAA,IAAIgC,EAAYG,EAAQ,GAAI,EAClC,KAAMA,EACN,aACA,QAASH,EACT,QAASI,EAAO,GAChB,aACA,SAAU,GACV,SACF,CACF,EAMaI,EAAc,GAAuC,CAChE,GAAI,OAAO,SAAa,IAAa,UAAa,CAAC,EACnD,IAAMC,EAA2B,CAAC,EAClC,GAAI,OAAO,kBAAqB,WAAY,CAC1C,IAAMC,EAAW,IAAI,iBAAiBC,CAAQ,EAC9C,IAAK,IAAMC,IAAQ,CAAC,SAAS,gBAAiB,SAAS,IAAI,EACrDA,GACFF,EAAS,QAAQE,EAAM,CACrB,WAAY,GACZ,gBAAiB,CAAC,QAAS,QAAS,aAAc,WAAW,CAC/D,CAAC,EAGLH,EAAS,SAAWC,EAAS,WAAW,CAAC,CAC3C,CACA,GAAI,OAAO,YAAe,WAAY,CACpC,IAAMG,EAAQ,WAAW,8BAA8B,EACvDA,EAAM,mBAAmB,SAAUF,CAAQ,EAC3CF,EAAS,SAAWI,EAAM,sBAAsB,SAAUF,CAAQ,CAAC,CACrE,CACA,UAAaF,EAAS,QAAS,GAAOK,EAAG,CAAC,CAC5C"}
@@ -14,8 +14,17 @@ export interface ChartTheme {
14
14
  /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */
15
15
  resolve?: ColorResolver;
16
16
  }
17
- /** Reads the theme from the computed style of `element` */
17
+ /**
18
+ * Reads the theme from the computed style of `element`. Its resolver caches
19
+ * the colors (DOM probes are costly): read the theme again to see new values.
20
+ */
18
21
  export declare const readTheme: (element: Element | null, palette?: readonly string[]) => ChartTheme;
22
+ /**
23
+ * Whether `next` (a re-read of `previous`) resolves any color differently:
24
+ * the theme colors, the palette and every color `previous` has resolved so
25
+ * far (series, points, annotations...). `true` when it cannot tell.
26
+ */
27
+ export declare const themeColorsChanged: (previous: ChartTheme, next: ChartTheme) => boolean;
19
28
  /** Theme of the charts drawn without a DOM (mini-programs, React Native) */
20
29
  export interface ChartThemeInput {
21
30
  /**
@@ -14,8 +14,17 @@ export interface ChartTheme {
14
14
  /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */
15
15
  resolve?: ColorResolver;
16
16
  }
17
- /** Reads the theme from the computed style of `element` */
17
+ /**
18
+ * Reads the theme from the computed style of `element`. Its resolver caches
19
+ * the colors (DOM probes are costly): read the theme again to see new values.
20
+ */
18
21
  export declare const readTheme: (element: Element | null, palette?: readonly string[]) => ChartTheme;
22
+ /**
23
+ * Whether `next` (a re-read of `previous`) resolves any color differently:
24
+ * the theme colors, the palette and every color `previous` has resolved so
25
+ * far (series, points, annotations...). `true` when it cannot tell.
26
+ */
27
+ export declare const themeColorsChanged: (previous: ChartTheme, next: ChartTheme) => boolean;
19
28
  /** Theme of the charts drawn without a DOM (mini-programs, React Native) */
20
29
  export interface ChartThemeInput {
21
30
  /**
@@ -1,6 +1,6 @@
1
- import { domColorResolver as e, mix as t, resolveStaticColor as n } from "./color.js";
1
+ import { domColorResolver as e, memoizeColorResolver as t, mix as n, resolveStaticColor as r, sameColor as i } from "./color.js";
2
2
  //#region src/engine/theme.ts
3
- var r = [
3
+ var a = [
4
4
  "#4f46e5",
5
5
  "#10b981",
6
6
  "#f59e0b",
@@ -9,27 +9,51 @@ var r = [
9
9
  "#8b5cf6",
10
10
  "#14b8a6",
11
11
  "#f97316"
12
- ], i = (e, t) => e?.getPropertyValue(t).trim() ?? "", a = (t, n) => {
13
- let r = t && typeof getComputedStyle == "function" ? getComputedStyle(t) : null;
14
- return c((e) => i(r, e), e(t), n, r?.fontFamily ?? "");
15
- }, o = (e = {}, t) => {
12
+ ], o = (e, t) => e?.getPropertyValue(t).trim() ?? "", s = (n, r) => {
13
+ let i = n && typeof getComputedStyle == "function" ? getComputedStyle(n) : null;
14
+ return f((e) => o(i, e), t(e(n)), r, i?.fontFamily ?? "");
15
+ }, c = [
16
+ "text",
17
+ "textMuted",
18
+ "grid",
19
+ "axis",
20
+ "background",
21
+ "surface",
22
+ "primary"
23
+ ], l = (e, t) => {
24
+ if (e === t) return !1;
25
+ if (e.palette.length !== t.palette.length || e.palette.some((e, n) => !i(e, t.palette[n])) || c.some((n) => !i(e[n], t[n]))) return !0;
26
+ let n = e.resolve?.cache;
27
+ if (!n || !t.resolve) return !0;
28
+ let r = [
29
+ NaN,
30
+ NaN,
31
+ NaN,
32
+ NaN
33
+ ];
34
+ for (let [e, a] of n) {
35
+ let n = t.resolve(e, r);
36
+ if (!i(a, n === r ? null : n)) return !0;
37
+ }
38
+ return !1;
39
+ }, u = (e = {}, t) => {
16
40
  let n = e.variables ?? {};
17
41
  return {
18
- ...c((e) => n[e]?.trim() ?? "", s(n), t?.length ? t : e.palette, ""),
42
+ ...f((e) => n[e]?.trim() ?? "", d(n), t?.length ? t : e.palette, ""),
19
43
  ...e.fontFamily ? { fontFamily: e.fontFamily } : {},
20
44
  ...e.fontSize ? { fontSize: e.fontSize } : {}
21
45
  };
22
- }, s = (e) => (t, r) => n(t, e, r), c = (e, n, i, a) => {
46
+ }, d = (e) => (t, n) => r(t, e, n), f = (e, t, r, i) => {
23
47
  let o = [
24
48
  .4,
25
49
  .4,
26
50
  .4,
27
51
  1
28
- ], s = (e) => n(e, o), c = (t, n) => {
52
+ ], s = (e) => t(e, o), c = (t, n) => {
29
53
  for (let n of t) if (e(n)) return s(`var(${n})`);
30
54
  return s(n);
31
55
  }, l = c(["--surface-color", "--background-color"], "#ffffff"), u = c(["--text-color"], "#1f2937"), d = c(["--text-secondary-color", "--text-muted-color"], "#6b7280"), f = c(["--border-color"], "#e5e7eb"), p;
32
- if (i && i.length) p = i.map((e) => s(e));
56
+ if (r && r.length) p = r.map((e) => s(e));
33
57
  else {
34
58
  let t = [];
35
59
  for (let n = 1; n <= 8; n++) {
@@ -42,23 +66,23 @@ var r = [
42
66
  "--warning-color",
43
67
  "--danger-color",
44
68
  "--info-color"
45
- ].map((t, n) => e(t) ? s(`var(${t})`) : s(r[n])), ...r.slice(5).map((e) => s(e))];
69
+ ].map((t, n) => e(t) ? s(`var(${t})`) : s(a[n])), ...a.slice(5).map((e) => s(e))];
46
70
  }
47
- let m = e("--font-family-sans") || a || "system-ui, -apple-system, 'Segoe UI', sans-serif";
71
+ let m = e("--font-family-sans") || i || "system-ui, -apple-system, 'Segoe UI', sans-serif";
48
72
  return {
49
73
  palette: p,
50
74
  text: u,
51
75
  textMuted: d,
52
- grid: t(l, f, .75),
76
+ grid: n(l, f, .75),
53
77
  axis: f,
54
78
  background: l,
55
79
  surface: l,
56
80
  primary: p[0],
57
81
  fontFamily: m,
58
82
  fontSize: 11,
59
- resolve: n
83
+ resolve: t
60
84
  };
61
- }, l = (e) => {
85
+ }, p = (e) => {
62
86
  if (typeof document > "u") return () => {};
63
87
  let t = [];
64
88
  if (typeof MutationObserver == "function") {
@@ -81,6 +105,6 @@ var r = [
81
105
  return () => t.forEach((e) => e());
82
106
  };
83
107
  //#endregion
84
- export { o as createTheme, a as readTheme, s as staticColorResolver, l as watchTheme };
108
+ export { u as createTheme, s as readTheme, d as staticColorResolver, l as themeColorsChanged, p as watchTheme };
85
109
 
86
110
  //# sourceMappingURL=theme.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.js","names":["DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","domColorResolver","palette","createTheme","variables","input","staticColorResolver","resolveStaticColor","value","fallback","fallbackGray","resolveColor","resolve","color","names","readVariable","background","text","textMuted","border","colors","c","custom","i","fontFamily","inheritedFont","mix","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n mix,\n resolveStaticColor,\n type ColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/** Reads the theme from the computed style of `element` */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n domColorResolver(element),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":";;AA2BA,IAAMA,IAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEMC,KAAW,GAAmC,MAClDC,GAAO,iBAAiBC,CAAI,CAAC,CAAC,KAAK,KAAK,IAG7BC,KACX,GACA,MACe;CACf,IAAMF,IACJG,KAAW,OAAO,oBAAqB,aACnC,iBAAiBA,CAAO,IACxB;CACN,OAAOC,GACJ,MAASL,EAAQC,GAAOC,CAAI,GAC7BI,EAAiBF,CAAO,GACxBG,GACAN,GAAO,cAAc,EACvB;AACF,GAsBaO,KACX,IAAyB,CAAC,GAC1B,MACe;CACf,IAAMC,IAAYC,EAAM,aAAa,CAAC;CAOtC,OAAO;EACL,GAPYL,GACX,MAASI,EAAUP,EAAK,EAAE,KAAK,KAAK,IACrCS,EAAoBF,CAAS,GAC7BF,GAAS,SAASA,IAAUG,EAAM,SAClC,EAGG;EACH,GAAIA,EAAM,aAAa,EAAE,YAAYA,EAAM,WAAW,IAAI,CAAC;EAC3D,GAAIA,EAAM,WAAW,EAAE,UAAUA,EAAM,SAAS,IAAI,CAAC;CACvD;AACF,GAGaC,KACV,OACA,GAAO,MACNC,EAAmBC,GAAOJ,GAAWK,CAAQ,GAE3CT,KACJ,GACA,GACA,GACA,MACe;CACf,IAAMU,IAAqB;EAAC;EAAK;EAAK;EAAK;CA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AAC;CACnD,IAAMC,IAA2B,CAAC;CAClC,IAAI,OAAO,oBAAqB,YAAY;EAC1C,IAAMC,IAAW,IAAI,iBAAiBC,CAAQ;EAC9C,KAAK,IAAMC,KAAQ,CAAC,SAAS,iBAAiB,SAAS,IAAI,GACzD,AAAIA,KACFF,EAAS,QAAQE,GAAM;GACrB,YAAY;GACZ,iBAAiB;IAAC;IAAS;IAAS;IAAc;GAAW;EAC/D,CAAC;EAGL,EAAS,WAAWF,EAAS,WAAW,CAAC;CAC3C;CACA,IAAI,OAAO,cAAe,YAAY;EACpC,IAAMG,IAAQ,WAAW,8BAA8B;EAEvD,AADAA,EAAM,mBAAmB,UAAUF,CAAQ,GAC3CF,EAAS,WAAWI,EAAM,sBAAsB,UAAUF,CAAQ,CAAC;CACrE;CACA,aAAaF,EAAS,SAAS,MAAOK,EAAG,CAAC;AAC5C"}
1
+ {"version":3,"file":"theme.js","names":["DEFAULT_PALETTE","readVar","style","name","readTheme","element","buildTheme","memoizeColorResolver","domColorResolver","palette","THEME_COLORS","themeColorsChanged","previous","next","sameColor","c","i","key","cache","probe","value","color","resolved","createTheme","variables","input","staticColorResolver","resolveStaticColor","fallback","fallbackGray","resolveColor","resolve","names","readVariable","background","text","textMuted","border","colors","custom","fontFamily","inheritedFont","mix","watchTheme","cleanups","observer","onChange","node","query","fn"],"sources":["../../../../charts/src/engine/theme.ts"],"sourcesContent":["// Chart colors and fonts read from the Minerva CSS variables.\n\nimport {\n domColorResolver,\n memoizeColorResolver,\n mix,\n resolveStaticColor,\n sameColor,\n type ColorResolver,\n type MemoizedColorResolver,\n type Rgba,\n} from \"./color\";\n\nexport interface ChartTheme {\n palette: Rgba[];\n text: Rgba;\n textMuted: Rgba;\n grid: Rgba;\n axis: Rgba;\n background: Rgba;\n surface: Rgba;\n primary: Rgba;\n fontFamily: string;\n /** Tick label font size in CSS pixels */\n fontSize: number;\n /** Resolves the colors of the options (`var(--x)` included); static colors only when omitted */\n resolve?: ColorResolver;\n}\n\n/** Used when no CSS variable is defined (e.g. without the Minerva stylesheet) */\nconst DEFAULT_PALETTE = [\n \"#4f46e5\",\n \"#10b981\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#0ea5e9\",\n \"#8b5cf6\",\n \"#14b8a6\",\n \"#f97316\",\n];\n\nconst readVar = (style: CSSStyleDeclaration | null, name: string) =>\n style?.getPropertyValue(name).trim() ?? \"\";\n\n/**\n * Reads the theme from the computed style of `element`. Its resolver caches\n * the colors (DOM probes are costly): read the theme again to see new values.\n */\nexport const readTheme = (\n element: Element | null,\n palette?: readonly string[],\n): ChartTheme => {\n const style =\n element && typeof getComputedStyle === \"function\"\n ? getComputedStyle(element)\n : null;\n return buildTheme(\n (name) => readVar(style, name),\n memoizeColorResolver(domColorResolver(element)),\n palette,\n style?.fontFamily ?? \"\",\n );\n};\n\nconst THEME_COLORS = [\n \"text\",\n \"textMuted\",\n \"grid\",\n \"axis\",\n \"background\",\n \"surface\",\n \"primary\",\n] as const;\n\n/**\n * Whether `next` (a re-read of `previous`) resolves any color differently:\n * the theme colors, the palette and every color `previous` has resolved so\n * far (series, points, annotations...). `true` when it cannot tell.\n */\nexport const themeColorsChanged = (\n previous: ChartTheme,\n next: ChartTheme,\n): boolean => {\n if (previous === next) return false;\n if (previous.palette.length !== next.palette.length) return true;\n if (previous.palette.some((c, i) => !sameColor(c, next.palette[i])))\n return true;\n if (THEME_COLORS.some((key) => !sameColor(previous[key], next[key])))\n return true;\n const cache = (previous.resolve as Partial<MemoizedColorResolver> | undefined)\n ?.cache;\n if (!cache || !next.resolve) return true;\n const probe: Rgba = [NaN, NaN, NaN, NaN];\n for (const [value, color] of cache) {\n const resolved = next.resolve(value, probe);\n if (!sameColor(color, resolved === probe ? null : resolved)) return true;\n }\n return false;\n};\n\n/** Theme of the charts drawn without a DOM (mini-programs, React Native) */\nexport interface ChartThemeInput {\n /**\n * Values of the Minerva CSS variables (`--primary-color`, `--text-color`,\n * `--chart-series-1`, ...) used for the theme colors and to resolve\n * `var(--name)` colors of the options\n */\n variables?: Readonly<Record<string, string>>;\n /** Series colors (hex / rgb) */\n palette?: readonly string[];\n /** Font family of the labels */\n fontFamily?: string;\n /**\n * Font size of the tick labels, in pixels\n * @default 11\n */\n fontSize?: number;\n}\n\n/** Builds a theme from plain values (no DOM) */\nexport const createTheme = (\n input: ChartThemeInput = {},\n palette?: readonly string[],\n): ChartTheme => {\n const variables = input.variables ?? {};\n const theme = buildTheme(\n (name) => variables[name]?.trim() ?? \"\",\n staticColorResolver(variables),\n palette?.length ? palette : input.palette,\n \"\",\n );\n return {\n ...theme,\n ...(input.fontFamily ? { fontFamily: input.fontFamily } : {}),\n ...(input.fontSize ? { fontSize: input.fontSize } : {}),\n };\n};\n\n/** Resolver of `var(--name, fallback)` colors against plain variables */\nexport const staticColorResolver =\n (variables: Readonly<Record<string, string>>): ColorResolver =>\n (value, fallback) =>\n resolveStaticColor(value, variables, fallback);\n\nconst buildTheme = (\n readVariable: (name: string) => string,\n resolve: ColorResolver,\n palette: readonly string[] | undefined,\n inheritedFont: string,\n): ChartTheme => {\n const fallbackGray: Rgba = [0.4, 0.4, 0.4, 1];\n const resolveColor = (value: string) => resolve(value, fallbackGray);\n const color = (names: string[], fallback: string): Rgba => {\n for (const name of names) {\n if (readVariable(name)) return resolveColor(`var(${name})`);\n }\n return resolveColor(fallback);\n };\n\n const background = color(\n [\"--surface-color\", \"--background-color\"],\n \"#ffffff\",\n );\n const text = color([\"--text-color\"], \"#1f2937\");\n const textMuted = color(\n [\"--text-secondary-color\", \"--text-muted-color\"],\n \"#6b7280\",\n );\n const border = color([\"--border-color\"], \"#e5e7eb\");\n\n let colors: Rgba[];\n if (palette && palette.length) {\n colors = palette.map((c) => resolveColor(c));\n } else {\n const custom: Rgba[] = [];\n for (let i = 1; i <= 8; i++) {\n const name = `--chart-series-${i}`;\n if (readVariable(name)) custom.push(resolveColor(`var(${name})`));\n }\n if (custom.length) {\n colors = custom;\n } else {\n const themed = [\n \"--primary-color\",\n \"--success-color\",\n \"--warning-color\",\n \"--danger-color\",\n \"--info-color\",\n ].map((name, i) =>\n readVariable(name)\n ? resolveColor(`var(${name})`)\n : resolveColor(DEFAULT_PALETTE[i]),\n );\n colors = [\n ...themed,\n ...DEFAULT_PALETTE.slice(5).map((c) => resolveColor(c)),\n ];\n }\n }\n\n const fontFamily =\n readVariable(\"--font-family-sans\") ||\n inheritedFont ||\n \"system-ui, -apple-system, 'Segoe UI', sans-serif\";\n\n return {\n palette: colors,\n text,\n textMuted,\n grid: mix(background, border, 0.75),\n axis: border,\n background,\n surface: background,\n primary: colors[0],\n fontFamily,\n fontSize: 11,\n resolve,\n };\n};\n\n/**\n * Calls `onChange` when the theme may have changed: attributes of `<html>` /\n * `<body>` (class, style, data-theme) and the color scheme.\n */\nexport const watchTheme = (onChange: () => void): (() => void) => {\n if (typeof document === \"undefined\") return () => {};\n const cleanups: (() => void)[] = [];\n if (typeof MutationObserver === \"function\") {\n const observer = new MutationObserver(onChange);\n for (const node of [document.documentElement, document.body]) {\n if (node) {\n observer.observe(node, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\", \"data-mode\"],\n });\n }\n }\n cleanups.push(() => observer.disconnect());\n }\n if (typeof matchMedia === \"function\") {\n const query = matchMedia(\"(prefers-color-scheme: dark)\");\n query.addEventListener?.(\"change\", onChange);\n cleanups.push(() => query.removeEventListener?.(\"change\", onChange));\n }\n return () => cleanups.forEach((fn) => fn());\n};\n"],"mappings":";;AA8BA,IAAMA,IAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEMC,KAAW,GAAmC,MAClDC,GAAO,iBAAiBC,CAAI,CAAC,CAAC,KAAK,KAAK,IAM7BC,KACX,GACA,MACe;CACf,IAAMF,IACJG,KAAW,OAAO,oBAAqB,aACnC,iBAAiBA,CAAO,IACxB;CACN,OAAOC,GACJ,MAASL,EAAQC,GAAOC,CAAI,GAC7BI,EAAqBC,EAAiBH,CAAO,CAAC,GAC9CI,GAC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