@overdoser/react-toolkit 0.20.0 → 0.21.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 (273) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/components/Accordion/Accordion.js +160 -177
  4. package/components/Accordion/Accordion.module.js +20 -0
  5. package/components/ActionButton/ActionButton.js +155 -209
  6. package/components/ActionButton/ActionButton.module.js +25 -0
  7. package/components/ActionButton/CopyButton.js +52 -64
  8. package/components/Alert/Alert.js +92 -95
  9. package/components/Alert/Alert.module.js +18 -0
  10. package/components/Avatar/Avatar.js +44 -55
  11. package/components/Avatar/Avatar.module.js +23 -0
  12. package/components/Badge/Badge.js +16 -38
  13. package/components/Badge/Badge.module.js +17 -0
  14. package/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  15. package/components/Breadcrumbs/Breadcrumbs.js +52 -48
  16. package/components/Breadcrumbs/Breadcrumbs.module.js +10 -0
  17. package/components/Button/Button.js +35 -57
  18. package/components/Button/Button.module.js +25 -0
  19. package/components/Card/Card.js +94 -131
  20. package/components/Card/Card.module.js +35 -0
  21. package/components/Chart/AreaChart.d.ts +1 -1
  22. package/components/Chart/AreaChart.js +248 -249
  23. package/components/Chart/Axis.d.ts +2 -2
  24. package/components/Chart/Axis.js +34 -43
  25. package/components/Chart/BarChart.d.ts +1 -1
  26. package/components/Chart/BarChart.js +307 -348
  27. package/components/Chart/Chart.module.js +32 -0
  28. package/components/Chart/ChartContainer.js +33 -41
  29. package/components/Chart/ChartLegend.d.ts +1 -1
  30. package/components/Chart/ChartLegend.js +31 -30
  31. package/components/Chart/ChartTooltip.d.ts +1 -1
  32. package/components/Chart/ChartTooltip.js +46 -41
  33. package/components/Chart/LineChart.d.ts +1 -1
  34. package/components/Chart/LineChart.js +220 -232
  35. package/components/Chart/PieChart.d.ts +1 -1
  36. package/components/Chart/PieChart.js +224 -240
  37. package/components/Chart/RadarChart.d.ts +1 -1
  38. package/components/Chart/RadarChart.js +166 -215
  39. package/components/Chart/Sparkline.js +73 -68
  40. package/components/Chart/TradingChart.d.ts +1 -1
  41. package/components/Chart/TradingChart.js +804 -701
  42. package/components/Chart/scales.js +28 -35
  43. package/components/Chart/trading/indicators.js +61 -62
  44. package/components/Chart/trading/period.js +46 -68
  45. package/components/Chart/useChartDimensions.js +30 -22
  46. package/components/Chip/Chip.js +98 -141
  47. package/components/Chip/Chip.module.js +32 -0
  48. package/components/CodeBlock/CodeBlock.js +111 -119
  49. package/components/CodeBlock/CodeBlock.module.js +23 -0
  50. package/components/CommandPalette/CommandPalette.js +387 -392
  51. package/components/CommandPalette/CommandPalette.module.js +28 -0
  52. package/components/ConfirmDialog/ConfirmDialog.d.ts +1 -1
  53. package/components/ConfirmDialog/ConfirmDialog.js +184 -199
  54. package/components/ConfirmDialog/ConfirmDialog.module.js +12 -0
  55. package/components/Divider/Divider.js +25 -36
  56. package/components/Divider/Divider.module.js +17 -0
  57. package/components/Draggable/Draggable.d.ts +1 -1
  58. package/components/Draggable/Draggable.js +157 -164
  59. package/components/Draggable/Draggable.module.js +10 -0
  60. package/components/Drawer/Drawer.js +104 -126
  61. package/components/Drawer/Drawer.module.js +66 -0
  62. package/components/Dropdown/Dropdown.js +175 -234
  63. package/components/Dropdown/Dropdown.module.js +29 -0
  64. package/components/Dropdown/DropdownItem.js +55 -58
  65. package/components/Dropdown/DropdownLabel.js +14 -11
  66. package/components/Dropdown/DropdownSeparator.js +12 -10
  67. package/components/Dropdown/dropdownContext.js +4 -5
  68. package/components/Dropdown/useContextMenu.js +27 -17
  69. package/components/Dropzone/Dropzone.js +99 -105
  70. package/components/Dropzone/Dropzone.module.js +12 -0
  71. package/components/EmptyState/EmptyState.js +58 -55
  72. package/components/EmptyState/EmptyState.module.js +14 -0
  73. package/components/Form/Form.d.ts +1 -1
  74. package/components/Form/Form.js +32 -35
  75. package/components/Form/Form.module.js +16 -0
  76. package/components/Form/FormField.d.ts +1 -1
  77. package/components/Form/FormField.js +71 -75
  78. package/components/Form/FormRow.d.ts +1 -1
  79. package/components/Form/FormRow.js +11 -8
  80. package/components/Form/formFieldDefaults.js +4 -5
  81. package/components/ImageViewer/ImageViewer.js +312 -201
  82. package/components/ImageViewer/ImageViewer.module.js +26 -0
  83. package/components/ImageViewer/useZoomPan.js +206 -137
  84. package/components/Kbd/Kbd.js +25 -22
  85. package/components/Kbd/Kbd.module.js +10 -0
  86. package/components/KeyValueList/KeyValueList.js +119 -123
  87. package/components/KeyValueList/KeyValueList.module.js +23 -0
  88. package/components/Link/Link.js +45 -59
  89. package/components/Link/Link.module.js +10 -0
  90. package/components/List/List.js +22 -46
  91. package/components/List/List.module.js +12 -0
  92. package/components/Loader/Loader.js +152 -182
  93. package/components/Loader/Loader.module.js +40 -0
  94. package/components/Modal/Modal.js +93 -105
  95. package/components/Modal/Modal.module.js +18 -0
  96. package/components/PageHeader/PageHeader.js +78 -72
  97. package/components/PageHeader/PageHeader.module.js +23 -0
  98. package/components/Pagination/Pagination.js +63 -84
  99. package/components/Pagination/Pagination.module.js +13 -0
  100. package/components/Pagination/paginationRange.js +15 -22
  101. package/components/Popover/Popover.js +110 -134
  102. package/components/Popover/Popover.module.js +12 -0
  103. package/components/ProgressBar/ProgressBar.d.ts +15 -1
  104. package/components/ProgressBar/ProgressBar.js +57 -90
  105. package/components/ProgressBar/ProgressBar.module.js +29 -0
  106. package/components/RelativeTime/RelativeTime.js +36 -43
  107. package/components/RelativeTime/RelativeTime.module.js +3 -0
  108. package/components/SegmentedControl/SegmentedControl.js +94 -130
  109. package/components/SegmentedControl/SegmentedControl.module.js +21 -0
  110. package/components/Skeleton/Skeleton.js +36 -50
  111. package/components/Skeleton/Skeleton.module.js +15 -0
  112. package/components/Spinner/Spinner.js +25 -25
  113. package/components/Spinner/Spinner.module.js +12 -0
  114. package/components/SplitButton/SplitButton.js +149 -196
  115. package/components/SplitButton/SplitButton.module.js +31 -0
  116. package/components/SplitPane/SplitPane.js +134 -170
  117. package/components/SplitPane/SplitPane.module.js +14 -0
  118. package/components/StatCard/StatCard.js +132 -125
  119. package/components/StatCard/StatCard.module.js +42 -0
  120. package/components/StatusDot/StatusDot.js +28 -39
  121. package/components/StatusDot/StatusDot.module.js +18 -0
  122. package/components/Table/Table.d.ts +1 -1
  123. package/components/Table/Table.js +381 -451
  124. package/components/Table/Table.module.js +42 -0
  125. package/components/Table/useTableSort.js +51 -42
  126. package/components/Tabs/Tabs.js +109 -161
  127. package/components/Tabs/Tabs.module.js +28 -0
  128. package/components/ThemeToggle/ThemeToggle.js +122 -98
  129. package/components/ThemeToggle/ThemeToggle.module.js +13 -0
  130. package/components/Timeline/GanttTimeline.js +357 -318
  131. package/components/Timeline/GanttTimeline.module.js +29 -0
  132. package/components/Timeline/HistoryTimeline.js +486 -450
  133. package/components/Timeline/HistoryTimeline.module.js +31 -0
  134. package/components/Timeline/Timeline.module.js +76 -0
  135. package/components/Timeline/TimelineShared.d.ts +7 -7
  136. package/components/Timeline/TimelineShared.js +288 -279
  137. package/components/Timeline/TraceEventDetails.d.ts +3 -3
  138. package/components/Timeline/TraceEventDetails.js +245 -178
  139. package/components/Timeline/TraceTimeline.js +823 -783
  140. package/components/Timeline/TraceTimeline.module.js +98 -0
  141. package/components/Timeline/historyLayout.js +336 -263
  142. package/components/Timeline/timelineCore.js +208 -183
  143. package/components/Timeline/traceEvent.js +59 -61
  144. package/components/Timeline/traceLayout.js +101 -90
  145. package/components/Timeline/useTimeline.js +76 -79
  146. package/components/Timer/Timer.js +190 -156
  147. package/components/Timer/Timer.module.js +29 -0
  148. package/components/Toast/Toast.d.ts +1 -1
  149. package/components/Toast/Toast.js +128 -128
  150. package/components/Toast/Toast.module.js +37 -0
  151. package/components/Toast/toastStore.js +58 -62
  152. package/components/ToggleIconButton/ToggleIconButton.js +35 -57
  153. package/components/ToggleIconButton/ToggleIconButton.module.js +15 -0
  154. package/components/Tooltip/Tooltip.d.ts +1 -1
  155. package/components/Tooltip/Tooltip.js +76 -85
  156. package/components/Tooltip/Tooltip.module.js +17 -0
  157. package/components/Typography/Typography.js +11 -36
  158. package/components/Typography/Typography.module.js +30 -0
  159. package/components/inputs/Checkbox/Checkbox.js +27 -51
  160. package/components/inputs/Checkbox/Checkbox.module.js +10 -0
  161. package/components/inputs/Checkbox/CheckboxGroup.js +53 -111
  162. package/components/inputs/Checkbox/CheckboxGroup.module.js +17 -0
  163. package/components/inputs/DatePicker/CalendarPanel.d.ts +1 -1
  164. package/components/inputs/DatePicker/CalendarPanel.js +263 -286
  165. package/components/inputs/DatePicker/CalendarPanel.module.js +23 -0
  166. package/components/inputs/DatePicker/DatePicker.js +115 -142
  167. package/components/inputs/DatePicker/DatePicker.module.js +14 -0
  168. package/components/inputs/DatePicker/dateUtils.js +32 -41
  169. package/components/inputs/DateTimePicker/DateTimePicker.js +226 -232
  170. package/components/inputs/DateTimePicker/DateTimePicker.module.js +20 -0
  171. package/components/inputs/DateTimePicker/DateTimeSegments.js +273 -252
  172. package/components/inputs/DateTimePicker/TimeField.d.ts +1 -1
  173. package/components/inputs/DateTimePicker/TimeField.js +131 -132
  174. package/components/inputs/DateTimePicker/timeZoneUtils.js +95 -92
  175. package/components/inputs/Input/Input.js +98 -109
  176. package/components/inputs/Input/Input.module.js +15 -0
  177. package/components/inputs/NumberInput/NumberInput.js +112 -132
  178. package/components/inputs/NumberInput/NumberInput.module.js +14 -0
  179. package/components/inputs/Radio/Radio.js +50 -73
  180. package/components/inputs/Radio/Radio.module.js +9 -0
  181. package/components/inputs/SearchInput/SearchInput.js +98 -115
  182. package/components/inputs/SearchInput/SearchInput.module.js +8 -0
  183. package/components/inputs/Select/Select.js +555 -682
  184. package/components/inputs/Select/Select.module.js +38 -0
  185. package/components/inputs/Slider/Slider.js +97 -128
  186. package/components/inputs/Slider/Slider.module.js +9 -0
  187. package/components/inputs/Switch/Switch.js +11 -8
  188. package/components/inputs/Textarea/Textarea.js +42 -58
  189. package/components/inputs/Textarea/Textarea.module.js +14 -0
  190. package/hooks/useClickOutside.js +17 -14
  191. package/hooks/useDebouncedValue.js +13 -14
  192. package/hooks/useElementSize.js +27 -22
  193. package/hooks/useEscapeLayer.js +28 -29
  194. package/hooks/useFocusTrap.js +27 -38
  195. package/hooks/useKeyboard.js +76 -64
  196. package/hooks/useMediaQuery.js +10 -15
  197. package/hooks/useNow.js +28 -33
  198. package/hooks/usePersistedState.js +98 -94
  199. package/hooks/usePortalPosition.js +25 -19
  200. package/hooks/useResizable.js +106 -104
  201. package/hooks/useTheme.js +28 -23
  202. package/index.css +2 -1
  203. package/index.js +97 -215
  204. package/index.layered.css +2 -3
  205. package/llms.txt +3 -0
  206. package/manifest.json +8 -0
  207. package/package.json +1 -1
  208. package/utils/formatBytes.js +29 -13
  209. package/utils/themeScript.js +6 -8
  210. package/utils/timeAgo.js +59 -32
  211. package/components/Accordion/Accordion.module.scss.js +0 -36
  212. package/components/ActionButton/ActionButton.module.scss.js +0 -47
  213. package/components/Alert/Alert.module.scss.js +0 -33
  214. package/components/Avatar/Avatar.module.scss.js +0 -43
  215. package/components/Badge/Badge.module.scss.js +0 -31
  216. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +0 -17
  217. package/components/Button/Button.module.scss.js +0 -47
  218. package/components/Card/Card.module.scss.js +0 -60
  219. package/components/Chart/Chart.module.scss.js +0 -61
  220. package/components/Chip/Chip.module.scss.js +0 -59
  221. package/components/CodeBlock/CodeBlock.module.scss.js +0 -43
  222. package/components/CommandPalette/CommandPalette.module.scss.js +0 -49
  223. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +0 -21
  224. package/components/Divider/Divider.module.scss.js +0 -31
  225. package/components/Draggable/Draggable.module.scss.js +0 -17
  226. package/components/Drawer/Drawer.module.scss.js +0 -119
  227. package/components/Dropdown/Dropdown.module.scss.js +0 -53
  228. package/components/Dropzone/Dropzone.module.scss.js +0 -21
  229. package/components/EmptyState/EmptyState.module.scss.js +0 -25
  230. package/components/Form/Form.module.scss.js +0 -29
  231. package/components/ImageViewer/ImageViewer.module.scss.js +0 -47
  232. package/components/Kbd/Kbd.module.scss.js +0 -17
  233. package/components/KeyValueList/KeyValueList.module.scss.js +0 -43
  234. package/components/Link/Link.module.scss.js +0 -16
  235. package/components/List/List.module.scss.js +0 -21
  236. package/components/Loader/Loader.module.scss.js +0 -70
  237. package/components/Modal/Modal.module.scss.js +0 -33
  238. package/components/PageHeader/PageHeader.module.scss.js +0 -43
  239. package/components/Pagination/Pagination.module.scss.js +0 -23
  240. package/components/Popover/Popover.module.scss.js +0 -21
  241. package/components/ProgressBar/ProgressBar.module.scss.js +0 -51
  242. package/components/RelativeTime/RelativeTime.module.scss.js +0 -7
  243. package/components/SegmentedControl/SegmentedControl.module.scss.js +0 -39
  244. package/components/Skeleton/Skeleton.module.scss.js +0 -25
  245. package/components/Spinner/Spinner.module.scss.js +0 -20
  246. package/components/SplitButton/SplitButton.module.scss.js +0 -57
  247. package/components/SplitPane/SplitPane.module.scss.js +0 -25
  248. package/components/StatCard/StatCard.module.scss.js +0 -72
  249. package/components/StatusDot/StatusDot.module.scss.js +0 -32
  250. package/components/Table/Table.module.scss.js +0 -81
  251. package/components/Tabs/Tabs.module.scss.js +0 -53
  252. package/components/ThemeToggle/ThemeToggle.module.scss.js +0 -23
  253. package/components/Timeline/GanttTimeline.module.scss.js +0 -55
  254. package/components/Timeline/HistoryTimeline.module.scss.js +0 -59
  255. package/components/Timeline/Timeline.module.scss.js +0 -141
  256. package/components/Timeline/TraceTimeline.module.scss.js +0 -189
  257. package/components/Timer/Timer.module.scss.js +0 -55
  258. package/components/Toast/Toast.module.scss.js +0 -62
  259. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +0 -27
  260. package/components/Tooltip/Tooltip.module.scss.js +0 -30
  261. package/components/Typography/Typography.module.scss.js +0 -53
  262. package/components/inputs/Checkbox/Checkbox.module.scss.js +0 -17
  263. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +0 -31
  264. package/components/inputs/DatePicker/CalendarPanel.module.scss.js +0 -41
  265. package/components/inputs/DatePicker/DatePicker.module.scss.js +0 -25
  266. package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +0 -37
  267. package/components/inputs/Input/Input.module.scss.js +0 -27
  268. package/components/inputs/NumberInput/NumberInput.module.scss.js +0 -25
  269. package/components/inputs/Radio/Radio.module.scss.js +0 -15
  270. package/components/inputs/SearchInput/SearchInput.module.scss.js +0 -13
  271. package/components/inputs/Select/Select.module.scss.js +0 -73
  272. package/components/inputs/Slider/Slider.module.scss.js +0 -15
  273. package/components/inputs/Textarea/Textarea.module.scss.js +0 -25
@@ -1,353 +1,312 @@
1
- import { jsx as r, jsxs as Tt, Fragment as Gt } from "react/jsx-runtime";
2
- import { useMemo as $t, useState as It, useRef as Ft } from "react";
3
- import x from "clsx";
4
- import { ChartContainer as qt } from "./ChartContainer.js";
5
- import { ChartLegend as Ht } from "./ChartLegend.js";
6
- import { ChartTooltip as Jt } from "./ChartTooltip.js";
7
- import { extent as Kt, niceTicks as Qt, bandScale as dt, linearScale as Zt } from "./scales.js";
8
- import i from "./Chart.module.scss.js";
9
- const Wt = [
10
- "var(--crk-chart-1)",
11
- "var(--crk-chart-2)",
12
- "var(--crk-chart-3)",
13
- "var(--crk-chart-4)",
14
- "var(--crk-chart-5)"
15
- ], Pt = { top: 12, right: 16, bottom: 28, left: 48 }, te = { top: 12, right: 16, bottom: 28, left: 72 };
16
- function ee(t, c = 8) {
17
- if (t.length <= c) return t;
18
- const e = Math.ceil(t.length / c);
19
- return t.filter((s, a) => a % e === 0);
1
+ import { ChartContainer as e } from "./ChartContainer.js";
2
+ import { ChartLegend as t } from "./ChartLegend.js";
3
+ import { ChartTooltip as n } from "./ChartTooltip.js";
4
+ import { bandScale as r, extent as i, linearScale as a, niceTicks as o } from "./scales.js";
5
+ import s from "./Chart.module.js";
6
+ import { useMemo as c, useRef as l, useState as u } from "react";
7
+ import d from "clsx";
8
+ import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
9
+ // src/components/Chart/BarChart.tsx
10
+ var h = [
11
+ "var(--crk-chart-1)",
12
+ "var(--crk-chart-2)",
13
+ "var(--crk-chart-3)",
14
+ "var(--crk-chart-4)",
15
+ "var(--crk-chart-5)"
16
+ ], g = {
17
+ top: 12,
18
+ right: 16,
19
+ bottom: 28,
20
+ left: 48
21
+ }, _ = {
22
+ top: 12,
23
+ right: 16,
24
+ bottom: 28,
25
+ left: 72
26
+ };
27
+ function v(e, t = 8) {
28
+ if (e.length <= t) return e;
29
+ let n = Math.ceil(e.length / t);
30
+ return e.filter((e, t) => t % n === 0);
20
31
  }
21
- function ue({
22
- data: t,
23
- xKey: c,
24
- config: e,
25
- orientation: s = "vertical",
26
- stacked: a = !1,
27
- aspectRatio: u = 16 / 9,
28
- height: p,
29
- groupPadding: v = 0.2,
30
- barPadding: f = 0.1,
31
- barRadius: y = 4,
32
- showGrid: j = !0,
33
- showLegend: tt = !0,
34
- showTooltip: wt = !0,
35
- showValues: kt = !1,
36
- valuePosition: et = "outside",
37
- renderLabel: mt,
38
- colorBy: _t = "series",
39
- colors: nt = Wt,
40
- negativeColor: O,
41
- activeIndex: U,
42
- onBarClick: ot,
43
- yTickCount: zt = 5,
44
- yFormat: ht,
45
- xFormat: xt,
46
- valueFormat: rt,
47
- renderTooltip: ut,
48
- margin: Et,
49
- emptyMessage: Xt = "No data",
50
- className: pt,
51
- style: ft,
52
- classes: l
53
- }) {
54
- const d = s === "horizontal", T = { ...d ? te : Pt, ...Et }, $ = $t(() => Object.keys(e), [e]), _ = a && $.length > 1, [gt, yt] = It(null), z = Ft(null), it = t.map((b) => String(b[c])), N = U ?? gt, bt = $t(() => {
55
- if (_) {
56
- let L = 0, h = 0;
57
- for (const g of t) {
58
- let E = 0, X = 0;
59
- for (const At of $) {
60
- const A = g[At];
61
- typeof A == "number" && (A >= 0 ? E += A : X += A);
62
- }
63
- E > L && (L = E), X < h && (h = X);
64
- }
65
- return [h, L];
66
- }
67
- const b = [];
68
- for (const L of t)
69
- for (const h of $) {
70
- const g = L[h];
71
- typeof g == "number" && b.push(g);
72
- }
73
- const [B, m] = Kt(b);
74
- return [Math.min(0, B), Math.max(0, m)];
75
- }, [t, $, _]);
76
- if (t.length === 0)
77
- return /* @__PURE__ */ r("div", { ref: z, className: x(i.root, l?.root, pt), style: ft, children: /* @__PURE__ */ r("div", { className: i.canvas, style: { height: p ?? 240 }, children: /* @__PURE__ */ r("div", { className: i.empty, children: Xt }) }) });
78
- const V = Qt(bt[0], bt[1], zt), Lt = V[0], Mt = V[V.length - 1], vt = (b, B) => _t === "index" ? nt[B % nt.length] : e[b]?.color ?? nt[0], Yt = wt && N !== null && t[N] ? /* @__PURE__ */ r(
79
- Jt,
80
- {
81
- row: t[N],
82
- x: oe(t, c, T, N, z, d, v),
83
- y: d ? re(t, c, T, N, z, v) : 16,
84
- containerWidth: z.current?.getBoundingClientRect().width ?? 0,
85
- config: e,
86
- render: ut ? () => ut(t[N]) : void 0,
87
- valueFormat: rt,
88
- titleKey: c,
89
- resolveColor: (b) => {
90
- const B = t[N][b], m = vt(b, N);
91
- return typeof B != "number" ? m : O !== void 0 && B < 0 ? O : m;
92
- },
93
- classes: l
94
- }
95
- ) : null;
96
- return /* @__PURE__ */ r(
97
- qt,
98
- {
99
- ref: z,
100
- aspectRatio: u,
101
- height: p,
102
- className: pt,
103
- style: ft,
104
- classes: l,
105
- legend: tt ? /* @__PURE__ */ r(Ht, { config: e, classes: l }) : void 0,
106
- overlay: Yt,
107
- children: ({ width: b, height: B }) => {
108
- const m = T.left, L = b - T.right, h = T.top, g = B - T.bottom, E = Math.max(0, L - m), X = Math.max(0, g - h), A = dt(it, d ? [h, g] : [m, L], v), st = A.bandWidth(), G = Zt([Lt, Mt], d ? [m, L] : [g, h]), I = G(0), Dt = _ ? 1 : Math.max(1, $.length), ct = st / Dt, F = ct * (1 - f), Nt = V.map((n) => ({
109
- value: n,
110
- pos: G(n)
111
- })), jt = ee(it);
112
- return /* @__PURE__ */ Tt(Gt, { children: [
113
- j && /* @__PURE__ */ r("g", { className: x(i.axis, l?.axis), children: Nt.map(
114
- ({ value: n, pos: o }) => d ? /* @__PURE__ */ r(
115
- "line",
116
- {
117
- className: x(i.gridLine, l?.grid),
118
- x1: o,
119
- x2: o,
120
- y1: h,
121
- y2: g
122
- },
123
- `g-${n}`
124
- ) : /* @__PURE__ */ r(
125
- "line",
126
- {
127
- className: x(i.gridLine, l?.grid),
128
- x1: m,
129
- x2: L,
130
- y1: o,
131
- y2: o
132
- },
133
- `g-${n}`
134
- )
135
- ) }),
136
- /* @__PURE__ */ r("g", { className: x(i.axis, l?.axis), children: Nt.map(({ value: n, pos: o }) => {
137
- const C = ht ? ht(n) : String(n);
138
- return d ? /* @__PURE__ */ r(
139
- "text",
140
- {
141
- className: x(i.axisLabel, l?.axisLabel),
142
- x: o,
143
- y: g + 16,
144
- textAnchor: "middle",
145
- children: C
146
- },
147
- `vt-${n}`
148
- ) : /* @__PURE__ */ r(
149
- "text",
150
- {
151
- className: x(i.axisLabel, l?.axisLabel),
152
- x: m - 8,
153
- y: o,
154
- textAnchor: "end",
155
- dominantBaseline: "middle",
156
- children: C
157
- },
158
- `vt-${n}`
159
- );
160
- }) }),
161
- /* @__PURE__ */ r("g", { className: x(i.axis, l?.axis), children: jt.map((n) => {
162
- const o = A(n), C = xt ? xt(n) : n;
163
- return d ? /* @__PURE__ */ r(
164
- "text",
165
- {
166
- className: x(i.axisLabel, l?.axisLabel),
167
- x: m - 8,
168
- y: o,
169
- textAnchor: "end",
170
- dominantBaseline: "middle",
171
- children: C
172
- },
173
- `c-${n}`
174
- ) : /* @__PURE__ */ r(
175
- "text",
176
- {
177
- className: x(i.axisLabel, l?.axisLabel),
178
- x: o,
179
- y: g + 16,
180
- textAnchor: "middle",
181
- children: C
182
- },
183
- `c-${n}`
184
- );
185
- }) }),
186
- t.map((n, o) => {
187
- const q = A(it[o]) - st / 2;
188
- let w = 0, Y = 0;
189
- return /* @__PURE__ */ r("g", { className: x(i.series, l?.series), children: $.map((R, Ot) => {
190
- const Bt = n[R];
191
- if (typeof Bt != "number") return null;
192
- const M = Bt, Ut = vt(R, o), Vt = O !== void 0 && M < 0 ? O : Ut, Ct = U !== void 0 ? U === o : gt === o, St = U !== void 0 && !Ct;
193
- let H, k;
194
- _ ? M >= 0 ? (H = w, k = w + M, w = k) : (H = Y, k = Y + M, Y = k) : (H = 0, k = M);
195
- const J = G(H), K = G(k), Rt = _ ? (st - F) / 2 : Ot * ct + (ct - F) / 2;
196
- let Q = 0, Z = 0, W = 0, P = 0;
197
- if (d) {
198
- const D = Math.min(J, K), lt = Math.max(J, K);
199
- Q = D, W = lt - D, Z = q + Rt, P = F;
200
- } else {
201
- const D = Math.min(J, K), lt = Math.max(J, K);
202
- Q = q + Rt, W = F, Z = D, P = lt - D;
203
- }
204
- const at = mt ? mt({ row: n, value: M, seriesKey: R, index: o }) : kt ? rt ? rt(M) : String(M) : null, S = ne({
205
- isHorizontal: d,
206
- valuePosition: et,
207
- x: Q,
208
- y: Z,
209
- rectW: W,
210
- rectH: P,
211
- value: M
212
- });
213
- return /* @__PURE__ */ Tt("g", { children: [
214
- /* @__PURE__ */ r(
215
- "rect",
216
- {
217
- className: x(
218
- i.bar,
219
- Ct && i.activeBar,
220
- l?.point
221
- ),
222
- x: Q,
223
- y: Z,
224
- width: Math.max(0, W),
225
- height: Math.max(0, P),
226
- rx: y,
227
- ry: y,
228
- fill: Vt,
229
- opacity: St ? 0.35 : 1,
230
- onClick: ot ? () => ot({ row: n, value: M, seriesKey: R, index: o }) : void 0,
231
- style: ot ? { cursor: "pointer" } : void 0
232
- }
233
- ),
234
- at != null && /* @__PURE__ */ r(
235
- "text",
236
- {
237
- className: x(
238
- i.axisLabel,
239
- (et === "inside" || et === "inside-start") && i.barLabelInside
240
- ),
241
- x: S.x,
242
- y: S.y,
243
- textAnchor: S.textAnchor,
244
- dominantBaseline: S.dominantBaseline,
245
- transform: S.rotate ? `rotate(${S.rotate} ${S.x} ${S.y})` : void 0,
246
- opacity: St ? 0.5 : 1,
247
- children: at
248
- }
249
- )
250
- ] }, R);
251
- }) }, `group-${o}`);
252
- }),
253
- Lt < 0 && Mt > 0 && /* @__PURE__ */ r(
254
- "line",
255
- {
256
- className: x(i.gridLine),
257
- x1: d ? I : m,
258
- x2: d ? I : L,
259
- y1: d ? h : I,
260
- y2: d ? g : I,
261
- opacity: 0.9
262
- }
263
- ),
264
- /* @__PURE__ */ r(
265
- "rect",
266
- {
267
- className: i.interactionLayer,
268
- x: m,
269
- y: h,
270
- width: E,
271
- height: X,
272
- onMouseMove: (n) => {
273
- const o = n.currentTarget.getBoundingClientRect(), C = n.clientX - o.left + m, q = n.clientY - o.top + h, w = A.step(), Y = d ? q - h : C - m, R = Math.max(
274
- 0,
275
- Math.min(t.length - 1, Math.round((Y - w / 2) / w))
276
- );
277
- yt(R);
278
- },
279
- onMouseLeave: () => yt(null)
280
- }
281
- )
282
- ] });
283
- }
284
- }
285
- );
32
+ function y({ data: y, xKey: S, config: C, orientation: w = "vertical", stacked: T = !1, aspectRatio: E = 16 / 9, height: D, groupPadding: O = .2, barPadding: k = .1, barRadius: A = 4, showGrid: j = !0, showLegend: M = !0, showTooltip: te = !0, showValues: ne = !1, valuePosition: N = "outside", renderLabel: re, colorBy: ie = "series", colors: P = h, negativeColor: F, activeIndex: I, onBarClick: L, yTickCount: ae = 5, yFormat: R, xFormat: oe, valueFormat: z, renderTooltip: B, margin: se, emptyMessage: ce = "No data", className: V, style: H, classes: U }) {
33
+ let W = w === "horizontal", G = {
34
+ ...W ? _ : g,
35
+ ...se
36
+ }, K = c(() => Object.keys(C), [C]), q = T && K.length > 1, [J, Y] = u(null), X = l(null), Z = y.map((e) => String(e[S])), Q = I ?? J, le = c(() => {
37
+ if (q) {
38
+ let e = 0, t = 0;
39
+ for (let n of y) {
40
+ let r = 0, i = 0;
41
+ for (let e of K) {
42
+ let t = n[e];
43
+ typeof t == "number" && (t >= 0 ? r += t : i += t);
44
+ }
45
+ r > e && (e = r), i < t && (t = i);
46
+ }
47
+ return [t, e];
48
+ }
49
+ let e = [];
50
+ for (let t of y) for (let n of K) {
51
+ let r = t[n];
52
+ typeof r == "number" && e.push(r);
53
+ }
54
+ let [t, n] = i(e);
55
+ return [Math.min(0, t), Math.max(0, n)];
56
+ }, [
57
+ y,
58
+ K,
59
+ q
60
+ ]);
61
+ if (y.length === 0) return /* @__PURE__ */ p("div", {
62
+ ref: X,
63
+ className: d(s.root, U?.root, V),
64
+ style: H,
65
+ children: /* @__PURE__ */ p("div", {
66
+ className: s.canvas,
67
+ style: { height: D ?? 240 },
68
+ children: /* @__PURE__ */ p("div", {
69
+ className: s.empty,
70
+ children: ce
71
+ })
72
+ })
73
+ });
74
+ let $ = o(le[0], le[1], ae), ue = $[0], de = $[$.length - 1], fe = (e, t) => ie === "index" ? P[t % P.length] : C[e]?.color ?? P[0], pe = te && Q !== null && y[Q] ? /* @__PURE__ */ p(n, {
75
+ row: y[Q],
76
+ x: b(y, S, G, Q, X, W, O),
77
+ y: W ? x(y, S, G, Q, X, O) : 16,
78
+ containerWidth: X.current?.getBoundingClientRect().width ?? 0,
79
+ config: C,
80
+ render: B ? () => B(y[Q]) : void 0,
81
+ valueFormat: z,
82
+ titleKey: S,
83
+ resolveColor: (e) => {
84
+ let t = y[Q][e], n = fe(e, Q);
85
+ return typeof t == "number" && F !== void 0 && t < 0 ? F : n;
86
+ },
87
+ classes: U
88
+ }) : null;
89
+ return /* @__PURE__ */ p(e, {
90
+ ref: X,
91
+ aspectRatio: E,
92
+ height: D,
93
+ className: V,
94
+ style: H,
95
+ classes: U,
96
+ legend: M ? /* @__PURE__ */ p(t, {
97
+ config: C,
98
+ classes: U
99
+ }) : void 0,
100
+ overlay: pe,
101
+ children: ({ width: e, height: t }) => {
102
+ let n = G.left, i = e - G.right, o = G.top, c = t - G.bottom, l = Math.max(0, i - n), u = Math.max(0, c - o), h = r(Z, W ? [o, c] : [n, i], O), g = h.bandWidth(), _ = a([ue, de], W ? [n, i] : [c, o]), b = _(0), x = g / (q ? 1 : Math.max(1, K.length)), S = x * (1 - k), C = $.map((e) => ({
103
+ value: e,
104
+ pos: _(e)
105
+ })), w = v(Z);
106
+ return /* @__PURE__ */ m(f, { children: [
107
+ j && /* @__PURE__ */ p("g", {
108
+ className: d(s.axis, U?.axis),
109
+ children: C.map(({ value: e, pos: t }) => W ? /* @__PURE__ */ p("line", {
110
+ className: d(s.gridLine, U?.grid),
111
+ x1: t,
112
+ x2: t,
113
+ y1: o,
114
+ y2: c
115
+ }, `g-${e}`) : /* @__PURE__ */ p("line", {
116
+ className: d(s.gridLine, U?.grid),
117
+ x1: n,
118
+ x2: i,
119
+ y1: t,
120
+ y2: t
121
+ }, `g-${e}`))
122
+ }),
123
+ /* @__PURE__ */ p("g", {
124
+ className: d(s.axis, U?.axis),
125
+ children: C.map(({ value: e, pos: t }) => {
126
+ let r = R ? R(e) : String(e);
127
+ return W ? /* @__PURE__ */ p("text", {
128
+ className: d(s.axisLabel, U?.axisLabel),
129
+ x: t,
130
+ y: c + 16,
131
+ textAnchor: "middle",
132
+ children: r
133
+ }, `vt-${e}`) : /* @__PURE__ */ p("text", {
134
+ className: d(s.axisLabel, U?.axisLabel),
135
+ x: n - 8,
136
+ y: t,
137
+ textAnchor: "end",
138
+ dominantBaseline: "middle",
139
+ children: r
140
+ }, `vt-${e}`);
141
+ })
142
+ }),
143
+ /* @__PURE__ */ p("g", {
144
+ className: d(s.axis, U?.axis),
145
+ children: w.map((e) => {
146
+ let t = h(e), r = oe ? oe(e) : e;
147
+ return W ? /* @__PURE__ */ p("text", {
148
+ className: d(s.axisLabel, U?.axisLabel),
149
+ x: n - 8,
150
+ y: t,
151
+ textAnchor: "end",
152
+ dominantBaseline: "middle",
153
+ children: r
154
+ }, `c-${e}`) : /* @__PURE__ */ p("text", {
155
+ className: d(s.axisLabel, U?.axisLabel),
156
+ x: t,
157
+ y: c + 16,
158
+ textAnchor: "middle",
159
+ children: r
160
+ }, `c-${e}`);
161
+ })
162
+ }),
163
+ y.map((e, t) => {
164
+ let n = h(Z[t]) - g / 2, r = 0, i = 0;
165
+ return /* @__PURE__ */ p("g", {
166
+ className: d(s.series, U?.series),
167
+ children: K.map((a, o) => {
168
+ let c = e[a];
169
+ if (typeof c != "number") return null;
170
+ let l = c, u = fe(a, t), f = F !== void 0 && l < 0 ? F : u, h = I === void 0 ? J === t : I === t, v = I !== void 0 && !h, y, b;
171
+ q ? l >= 0 ? (y = r, b = r + l, r = b) : (y = i, b = i + l, i = b) : (y = 0, b = l);
172
+ let C = _(y), w = _(b), T = q ? (g - S) / 2 : o * x + (x - S) / 2, E = 0, D = 0, O = 0, k = 0;
173
+ if (W) {
174
+ let e = Math.min(C, w), t = Math.max(C, w);
175
+ E = e, O = t - e, D = n + T, k = S;
176
+ } else {
177
+ let e = Math.min(C, w), t = Math.max(C, w);
178
+ E = n + T, O = S, D = e, k = t - e;
179
+ }
180
+ let j = re ? re({
181
+ row: e,
182
+ value: l,
183
+ seriesKey: a,
184
+ index: t
185
+ }) : ne ? z ? z(l) : String(l) : null, M = ee({
186
+ isHorizontal: W,
187
+ valuePosition: N,
188
+ x: E,
189
+ y: D,
190
+ rectW: O,
191
+ rectH: k,
192
+ value: l
193
+ });
194
+ return /* @__PURE__ */ m("g", { children: [/* @__PURE__ */ p("rect", {
195
+ className: d(s.bar, h && s.activeBar, U?.point),
196
+ x: E,
197
+ y: D,
198
+ width: Math.max(0, O),
199
+ height: Math.max(0, k),
200
+ rx: A,
201
+ ry: A,
202
+ fill: f,
203
+ opacity: v ? .35 : 1,
204
+ onClick: L ? () => L({
205
+ row: e,
206
+ value: l,
207
+ seriesKey: a,
208
+ index: t
209
+ }) : void 0,
210
+ style: L ? { cursor: "pointer" } : void 0
211
+ }), j != null && /* @__PURE__ */ p("text", {
212
+ className: d(s.axisLabel, (N === "inside" || N === "inside-start") && s.barLabelInside),
213
+ x: M.x,
214
+ y: M.y,
215
+ textAnchor: M.textAnchor,
216
+ dominantBaseline: M.dominantBaseline,
217
+ transform: M.rotate ? `rotate(${M.rotate} ${M.x} ${M.y})` : void 0,
218
+ opacity: v ? .5 : 1,
219
+ children: j
220
+ })] }, a);
221
+ })
222
+ }, `group-${t}`);
223
+ }),
224
+ ue < 0 && de > 0 && /* @__PURE__ */ p("line", {
225
+ className: d(s.gridLine),
226
+ x1: W ? b : n,
227
+ x2: W ? b : i,
228
+ y1: W ? o : b,
229
+ y2: W ? c : b,
230
+ opacity: .9
231
+ }),
232
+ /* @__PURE__ */ p("rect", {
233
+ className: s.interactionLayer,
234
+ x: n,
235
+ y: o,
236
+ width: l,
237
+ height: u,
238
+ onMouseMove: (e) => {
239
+ let t = e.currentTarget.getBoundingClientRect(), r = e.clientX - t.left + n, i = e.clientY - t.top + o, a = h.step(), s = W ? i - o : r - n, c = Math.max(0, Math.min(y.length - 1, Math.round((s - a / 2) / a)));
240
+ Y(c);
241
+ },
242
+ onMouseLeave: () => Y(null)
243
+ })
244
+ ] });
245
+ }
246
+ });
286
247
  }
287
- function ne({
288
- isHorizontal: t,
289
- valuePosition: c,
290
- x: e,
291
- y: s,
292
- rectW: a,
293
- rectH: u,
294
- value: p
295
- }) {
296
- if (t) {
297
- if (c === "inside-start")
298
- return p >= 0 ? { x: e + 6, y: s + u / 2, textAnchor: "start", dominantBaseline: "middle" } : { x: e + a - 6, y: s + u / 2, textAnchor: "end", dominantBaseline: "middle" };
299
- const y = c === "inside";
300
- return p >= 0 ? {
301
- x: y ? e + a - 6 : e + a + 6,
302
- y: s + u / 2,
303
- textAnchor: y ? "end" : "start",
304
- dominantBaseline: "middle"
305
- } : {
306
- x: y ? e + 6 : e - 6,
307
- y: s + u / 2,
308
- textAnchor: y ? "start" : "end",
309
- dominantBaseline: "middle"
310
- };
311
- }
312
- if (c === "inside-start")
313
- return p >= 0 ? {
314
- x: e + a / 2,
315
- y: s + u - 6,
316
- textAnchor: "start",
317
- dominantBaseline: "middle",
318
- rotate: -90
319
- } : {
320
- x: e + a / 2,
321
- y: s + 6,
322
- textAnchor: "start",
323
- dominantBaseline: "middle",
324
- rotate: 90
325
- };
326
- const f = c === "inside";
327
- return p >= 0 ? {
328
- x: e + a / 2,
329
- y: f ? s + 12 : s - 6,
330
- textAnchor: "middle",
331
- dominantBaseline: f ? "middle" : "auto"
332
- } : {
333
- x: e + a / 2,
334
- y: f ? s + u - 6 : s + u + 12,
335
- textAnchor: "middle",
336
- dominantBaseline: f ? "auto" : "middle"
337
- };
248
+ function ee({ isHorizontal: e, valuePosition: t, x: n, y: r, rectW: i, rectH: a, value: o }) {
249
+ if (e) {
250
+ if (t === "inside-start") return o >= 0 ? {
251
+ x: n + 6,
252
+ y: r + a / 2,
253
+ textAnchor: "start",
254
+ dominantBaseline: "middle"
255
+ } : {
256
+ x: n + i - 6,
257
+ y: r + a / 2,
258
+ textAnchor: "end",
259
+ dominantBaseline: "middle"
260
+ };
261
+ let e = t === "inside";
262
+ return o >= 0 ? {
263
+ x: e ? n + i - 6 : n + i + 6,
264
+ y: r + a / 2,
265
+ textAnchor: e ? "end" : "start",
266
+ dominantBaseline: "middle"
267
+ } : {
268
+ x: e ? n + 6 : n - 6,
269
+ y: r + a / 2,
270
+ textAnchor: e ? "start" : "end",
271
+ dominantBaseline: "middle"
272
+ };
273
+ }
274
+ if (t === "inside-start") return o >= 0 ? {
275
+ x: n + i / 2,
276
+ y: r + a - 6,
277
+ textAnchor: "start",
278
+ dominantBaseline: "middle",
279
+ rotate: -90
280
+ } : {
281
+ x: n + i / 2,
282
+ y: r + 6,
283
+ textAnchor: "start",
284
+ dominantBaseline: "middle",
285
+ rotate: 90
286
+ };
287
+ let s = t === "inside";
288
+ return o >= 0 ? {
289
+ x: n + i / 2,
290
+ y: s ? r + 12 : r - 6,
291
+ textAnchor: "middle",
292
+ dominantBaseline: s ? "middle" : "auto"
293
+ } : {
294
+ x: n + i / 2,
295
+ y: s ? r + a - 6 : r + a + 12,
296
+ textAnchor: "middle",
297
+ dominantBaseline: s ? "auto" : "middle"
298
+ };
338
299
  }
339
- function oe(t, c, e, s, a, u, p) {
340
- const v = a.current;
341
- if (!v) return 0;
342
- const f = v.getBoundingClientRect(), y = t.map((tt) => String(tt[c]));
343
- return u ? f.width / 2 : dt(y, [e.left, f.width - e.right], p)(y[s]);
300
+ function b(e, t, n, i, a, o, s) {
301
+ let c = a.current;
302
+ if (!c) return 0;
303
+ let l = c.getBoundingClientRect(), u = e.map((e) => String(e[t]));
304
+ return o ? l.width / 2 : r(u, [n.left, l.width - n.right], s)(u[i]);
344
305
  }
345
- function re(t, c, e, s, a, u) {
346
- const p = a.current;
347
- if (!p) return 16;
348
- const v = p.getBoundingClientRect(), f = t.map((j) => String(j[c]));
349
- return dt(f, [e.top, v.height - e.bottom], u)(f[s]);
306
+ function x(e, t, n, i, a, o) {
307
+ let s = a.current;
308
+ if (!s) return 16;
309
+ let c = s.getBoundingClientRect(), l = e.map((e) => String(e[t]));
310
+ return r(l, [n.top, c.height - n.bottom], o)(l[i]);
350
311
  }
351
- export {
352
- ue as BarChart
353
- };
312
+ export { y as BarChart };