@craftzbay/ui 0.10.0 → 0.11.1

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 (187) hide show
  1. package/README.md +18 -12
  2. package/dist-lib/__tests__/helpers/color.d.ts +9 -0
  3. package/dist-lib/__tests__/helpers/theme.d.ts +18 -0
  4. package/dist-lib/components/ui/Accordion.js +18 -7
  5. package/dist-lib/components/ui/Accordion.js.map +1 -1
  6. package/dist-lib/components/ui/Alert.d.ts +16 -0
  7. package/dist-lib/components/ui/Alert.js +47 -34
  8. package/dist-lib/components/ui/Alert.js.map +1 -1
  9. package/dist-lib/components/ui/Avatar.d.ts +1 -1
  10. package/dist-lib/components/ui/Avatar.js +45 -47
  11. package/dist-lib/components/ui/Avatar.js.map +1 -1
  12. package/dist-lib/components/ui/Badge.d.ts +3 -1
  13. package/dist-lib/components/ui/Badge.js +24 -15
  14. package/dist-lib/components/ui/Badge.js.map +1 -1
  15. package/dist-lib/components/ui/Breadcrumbs.d.ts +2 -0
  16. package/dist-lib/components/ui/Breadcrumbs.js +46 -28
  17. package/dist-lib/components/ui/Breadcrumbs.js.map +1 -1
  18. package/dist-lib/components/ui/Button.d.ts +5 -3
  19. package/dist-lib/components/ui/Button.js +59 -45
  20. package/dist-lib/components/ui/Button.js.map +1 -1
  21. package/dist-lib/components/ui/Calendar.d.ts +1 -1
  22. package/dist-lib/components/ui/Calendar.js +87 -59
  23. package/dist-lib/components/ui/Calendar.js.map +1 -1
  24. package/dist-lib/components/ui/Card.d.ts +2 -0
  25. package/dist-lib/components/ui/Card.js +48 -67
  26. package/dist-lib/components/ui/Card.js.map +1 -1
  27. package/dist-lib/components/ui/Carousel.d.ts +6 -6
  28. package/dist-lib/components/ui/Carousel.js +133 -102
  29. package/dist-lib/components/ui/Carousel.js.map +1 -1
  30. package/dist-lib/components/ui/Chart.d.ts +49 -10
  31. package/dist-lib/components/ui/Chart.js +415 -181
  32. package/dist-lib/components/ui/Chart.js.map +1 -1
  33. package/dist-lib/components/ui/Checkbox.js +42 -28
  34. package/dist-lib/components/ui/Checkbox.js.map +1 -1
  35. package/dist-lib/components/ui/Combobox.d.ts +2 -0
  36. package/dist-lib/components/ui/Combobox.js +142 -111
  37. package/dist-lib/components/ui/Combobox.js.map +1 -1
  38. package/dist-lib/components/ui/CommandPalette.d.ts +6 -3
  39. package/dist-lib/components/ui/CommandPalette.js +92 -87
  40. package/dist-lib/components/ui/CommandPalette.js.map +1 -1
  41. package/dist-lib/components/ui/ContextMenu.d.ts +7 -2
  42. package/dist-lib/components/ui/ContextMenu.js +77 -62
  43. package/dist-lib/components/ui/ContextMenu.js.map +1 -1
  44. package/dist-lib/components/ui/DataGrid.d.ts +17 -4
  45. package/dist-lib/components/ui/DataGrid.js +65 -50
  46. package/dist-lib/components/ui/DataGrid.js.map +1 -1
  47. package/dist-lib/components/ui/DatePicker.js +118 -99
  48. package/dist-lib/components/ui/DatePicker.js.map +1 -1
  49. package/dist-lib/components/ui/DesignSystemProvider.d.ts +94 -40
  50. package/dist-lib/components/ui/DesignSystemProvider.js +111 -55
  51. package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
  52. package/dist-lib/components/ui/Dialog.d.ts +18 -3
  53. package/dist-lib/components/ui/Dialog.js +105 -80
  54. package/dist-lib/components/ui/Dialog.js.map +1 -1
  55. package/dist-lib/components/ui/Drawer.d.ts +17 -2
  56. package/dist-lib/components/ui/Drawer.js +89 -55
  57. package/dist-lib/components/ui/Drawer.js.map +1 -1
  58. package/dist-lib/components/ui/DropdownMenu.js +14 -9
  59. package/dist-lib/components/ui/DropdownMenu.js.map +1 -1
  60. package/dist-lib/components/ui/EmptyState.d.ts +2 -0
  61. package/dist-lib/components/ui/EmptyState.js +30 -16
  62. package/dist-lib/components/ui/EmptyState.js.map +1 -1
  63. package/dist-lib/components/ui/ErrorState.d.ts +13 -2
  64. package/dist-lib/components/ui/ErrorState.js +44 -23
  65. package/dist-lib/components/ui/ErrorState.js.map +1 -1
  66. package/dist-lib/components/ui/FileUpload.js +59 -56
  67. package/dist-lib/components/ui/FileUpload.js.map +1 -1
  68. package/dist-lib/components/ui/Form.d.ts +15 -2
  69. package/dist-lib/components/ui/Form.js +97 -71
  70. package/dist-lib/components/ui/Form.js.map +1 -1
  71. package/dist-lib/components/ui/Icon.d.ts +1 -1
  72. package/dist-lib/components/ui/Icon.js +20 -14
  73. package/dist-lib/components/ui/Icon.js.map +1 -1
  74. package/dist-lib/components/ui/IconButton.d.ts +2 -2
  75. package/dist-lib/components/ui/IconButton.js +28 -20
  76. package/dist-lib/components/ui/IconButton.js.map +1 -1
  77. package/dist-lib/components/ui/Input.d.ts +3 -1
  78. package/dist-lib/components/ui/Input.js +102 -79
  79. package/dist-lib/components/ui/Input.js.map +1 -1
  80. package/dist-lib/components/ui/Kbd.js +1 -1
  81. package/dist-lib/components/ui/Kbd.js.map +1 -1
  82. package/dist-lib/components/ui/MultiSelect.js +121 -107
  83. package/dist-lib/components/ui/MultiSelect.js.map +1 -1
  84. package/dist-lib/components/ui/Pagination.js +67 -62
  85. package/dist-lib/components/ui/Pagination.js.map +1 -1
  86. package/dist-lib/components/ui/Popover.js +14 -14
  87. package/dist-lib/components/ui/Popover.js.map +1 -1
  88. package/dist-lib/components/ui/Progress.d.ts +3 -3
  89. package/dist-lib/components/ui/Progress.js +77 -72
  90. package/dist-lib/components/ui/Progress.js.map +1 -1
  91. package/dist-lib/components/ui/RadioGroup.d.ts +1 -1
  92. package/dist-lib/components/ui/RadioGroup.js +69 -52
  93. package/dist-lib/components/ui/RadioGroup.js.map +1 -1
  94. package/dist-lib/components/ui/RelativeTime.d.ts +19 -0
  95. package/dist-lib/components/ui/RelativeTime.js +31 -0
  96. package/dist-lib/components/ui/RelativeTime.js.map +1 -0
  97. package/dist-lib/components/ui/ScrollArea.d.ts +9 -1
  98. package/dist-lib/components/ui/ScrollArea.js +43 -27
  99. package/dist-lib/components/ui/ScrollArea.js.map +1 -1
  100. package/dist-lib/components/ui/Select.d.ts +6 -1
  101. package/dist-lib/components/ui/Select.js +79 -71
  102. package/dist-lib/components/ui/Select.js.map +1 -1
  103. package/dist-lib/components/ui/Separator.js +1 -1
  104. package/dist-lib/components/ui/Separator.js.map +1 -1
  105. package/dist-lib/components/ui/Sheet.d.ts +9 -0
  106. package/dist-lib/components/ui/Sheet.js +69 -46
  107. package/dist-lib/components/ui/Sheet.js.map +1 -1
  108. package/dist-lib/components/ui/Sidebar.d.ts +12 -9
  109. package/dist-lib/components/ui/Sidebar.js +152 -109
  110. package/dist-lib/components/ui/Sidebar.js.map +1 -1
  111. package/dist-lib/components/ui/Skeleton.d.ts +13 -2
  112. package/dist-lib/components/ui/Skeleton.js +15 -14
  113. package/dist-lib/components/ui/Skeleton.js.map +1 -1
  114. package/dist-lib/components/ui/Slider.js +41 -29
  115. package/dist-lib/components/ui/Slider.js.map +1 -1
  116. package/dist-lib/components/ui/Snackbar.js +23 -22
  117. package/dist-lib/components/ui/Snackbar.js.map +1 -1
  118. package/dist-lib/components/ui/Spinner.js +18 -6
  119. package/dist-lib/components/ui/Spinner.js.map +1 -1
  120. package/dist-lib/components/ui/Stepper.d.ts +6 -0
  121. package/dist-lib/components/ui/Stepper.js +71 -48
  122. package/dist-lib/components/ui/Stepper.js.map +1 -1
  123. package/dist-lib/components/ui/Switch.js +46 -43
  124. package/dist-lib/components/ui/Switch.js.map +1 -1
  125. package/dist-lib/components/ui/Table.d.ts +33 -5
  126. package/dist-lib/components/ui/Table.js +141 -119
  127. package/dist-lib/components/ui/Table.js.map +1 -1
  128. package/dist-lib/components/ui/Tabs.js +50 -48
  129. package/dist-lib/components/ui/Tabs.js.map +1 -1
  130. package/dist-lib/components/ui/TagInput.js +45 -45
  131. package/dist-lib/components/ui/TagInput.js.map +1 -1
  132. package/dist-lib/components/ui/Textarea.js +65 -54
  133. package/dist-lib/components/ui/Textarea.js.map +1 -1
  134. package/dist-lib/components/ui/Timeline.js +39 -35
  135. package/dist-lib/components/ui/Timeline.js.map +1 -1
  136. package/dist-lib/components/ui/Toast.js +44 -57
  137. package/dist-lib/components/ui/Toast.js.map +1 -1
  138. package/dist-lib/components/ui/Tooltip.d.ts +4 -1
  139. package/dist-lib/components/ui/Tooltip.js +24 -22
  140. package/dist-lib/components/ui/Tooltip.js.map +1 -1
  141. package/dist-lib/components/ui/TopNav.d.ts +7 -3
  142. package/dist-lib/components/ui/TopNav.js +39 -22
  143. package/dist-lib/components/ui/TopNav.js.map +1 -1
  144. package/dist-lib/components/ui/Tree.d.ts +15 -10
  145. package/dist-lib/components/ui/Tree.js +82 -79
  146. package/dist-lib/components/ui/Tree.js.map +1 -1
  147. package/dist-lib/hooks/use-debounce.d.ts +19 -0
  148. package/dist-lib/hooks/use-debounce.js +36 -0
  149. package/dist-lib/hooks/use-debounce.js.map +1 -0
  150. package/dist-lib/hooks/use-delayed-loading.d.ts +21 -0
  151. package/dist-lib/hooks/use-delayed-loading.js +20 -0
  152. package/dist-lib/hooks/use-delayed-loading.js.map +1 -0
  153. package/dist-lib/hooks/use-field-ids.d.ts +2 -1
  154. package/dist-lib/hooks/use-field-ids.js +9 -9
  155. package/dist-lib/hooks/use-field-ids.js.map +1 -1
  156. package/dist-lib/hooks/use-media-query.d.ts +3 -1
  157. package/dist-lib/hooks/use-media-query.js +16 -12
  158. package/dist-lib/hooks/use-media-query.js.map +1 -1
  159. package/dist-lib/hooks/use-modifier-key.d.ts +13 -0
  160. package/dist-lib/hooks/use-modifier-key.js +19 -0
  161. package/dist-lib/hooks/use-modifier-key.js.map +1 -0
  162. package/dist-lib/hooks/use-toast.d.ts +7 -2
  163. package/dist-lib/hooks/use-toast.js +61 -30
  164. package/dist-lib/hooks/use-toast.js.map +1 -1
  165. package/dist-lib/icons/index.d.ts +9 -0
  166. package/dist-lib/icons/index.js +148 -130
  167. package/dist-lib/icons/index.js.map +1 -1
  168. package/dist-lib/illustrations/index.d.ts +1 -0
  169. package/dist-lib/illustrations/index.js +15 -6
  170. package/dist-lib/illustrations/index.js.map +1 -1
  171. package/dist-lib/index.d.ts +6 -0
  172. package/dist-lib/index.js +280 -260
  173. package/dist-lib/index.js.map +1 -1
  174. package/dist-lib/lib/format.d.ts +65 -0
  175. package/dist-lib/lib/format.js +95 -0
  176. package/dist-lib/lib/format.js.map +1 -0
  177. package/dist-lib/lib/return-focus.d.ts +11 -0
  178. package/dist-lib/lib/return-focus.js +12 -0
  179. package/dist-lib/lib/return-focus.js.map +1 -0
  180. package/dist-lib/lib/strings.d.ts +62 -1
  181. package/dist-lib/lib/strings.js +75 -19
  182. package/dist-lib/lib/strings.js.map +1 -1
  183. package/dist-lib/lib/strings.mn.js +50 -5
  184. package/dist-lib/lib/strings.mn.js.map +1 -1
  185. package/dist-lib/styles.css +1 -1
  186. package/dist-lib/theme.css +141 -78
  187. package/package.json +11 -4
@@ -1,253 +1,487 @@
1
1
  "use client";
2
- import { jsx as i, jsxs as M } from "react/jsx-runtime";
3
- import { useId as T } from "react";
4
- import { cn as G } from "../../lib/utils.js";
5
- const w = [
2
+ import { jsx as s, jsxs as $, Fragment as U } from "react/jsx-runtime";
3
+ import { useId as oe, useState as K, useRef as ae, useCallback as se, useEffect as ie, useLayoutEffect as ce } from "react";
4
+ import { cn as w } from "../../lib/utils.js";
5
+ import { useStrings as X } from "../../hooks/use-strings.js";
6
+ import { formatString as z } from "../../lib/strings.js";
7
+ import { Skeleton as le } from "./Skeleton.js";
8
+ const Ie = {
9
+ summary: ({ name: e, count: n, min: r, max: t, lastX: o, lastY: a }) => `${e}: ${n} points, min ${r}, max ${t}, last ${o}: ${a}`,
10
+ point: (e, n, r) => `${e ? `${e} — ` : ""}${n}: ${r}`,
11
+ series: (e, n) => `${e}, ${n} points. Use arrow keys to move between points.`
12
+ };
13
+ function V(e) {
14
+ return {
15
+ summary: ({ name: n, count: r, min: t, max: o, lastX: a, lastY: i }) => z(e.summary, { name: n, count: r, min: t, max: o, x: a, y: i }),
16
+ point: (n, r, t) => (n ? `${n} — ` : "") + z(e.point, { x: r, y: t }),
17
+ series: (n, r) => z(e.seriesNav, { name: n, count: r })
18
+ };
19
+ }
20
+ const q = [
6
21
  "var(--chart-1)",
7
22
  "var(--chart-2)",
8
23
  "var(--chart-3)",
9
24
  "var(--chart-4)",
10
25
  "var(--chart-5)",
11
26
  "var(--chart-6)"
12
- ], A = 600, h = 6, W = 4, _ = 5;
13
- function K(t) {
14
- const n = Math.abs(t), e = (r, a) => `${(Math.round(r * 10) / 10).toString()}${a}`;
15
- return n >= 1e9 ? e(t / 1e9, "B") : n >= 1e6 ? e(t / 1e6, "M") : n >= 1e3 ? e(t / 1e3, "K") : Number.isInteger(t) ? String(t) : (Math.round(t * 100) / 100).toString();
16
- }
17
- function E(t, n) {
18
- return n && n.length ? n : [{ data: t ?? [] }];
19
- }
20
- function B(t, n = !0) {
21
- const e = t.flatMap((o) => o.data.map((c) => c.y)), r = n ? Math.min(0, ...e) : Math.min(...e), a = Math.max(...e, n ? 1 : -1 / 0);
22
- return { min: r, max: a === -1 / 0 ? 1 : a, range: a - r || 1 };
23
- }
24
- function X(t, n, e, r) {
25
- const a = A - h * 2, o = n - h * 2;
26
- return { sx: (l) => t <= 1 ? h + a / 2 : h + l / (t - 1) * a, sy: (l) => h + o - (l - e) / r * o };
27
- }
28
- function U(t) {
29
- if (t.length === 0) return "";
30
- if (t.length < 3) return t.map((e, r) => `${r ? "L" : "M"}${e[0]},${e[1]}`).join(" ");
31
- let n = `M${t[0][0]},${t[0][1]}`;
32
- for (let e = 0; e < t.length - 1; e++) {
33
- const r = t[e - 1] ?? t[e], a = t[e], o = t[e + 1], c = t[e + 2] ?? o, d = a[0] + (o[0] - r[0]) / 6, l = a[1] + (o[1] - r[1]) / 6, $ = o[0] - (c[0] - a[0]) / 6, y = o[1] - (c[1] - a[1]) / 6;
34
- n += ` C${d.toFixed(1)},${l.toFixed(1)} ${$.toFixed(1)},${y.toFixed(1)} ${o[0].toFixed(1)},${o[1].toFixed(1)}`;
27
+ ], de = 600, S = 6;
28
+ function ue() {
29
+ const e = ae(null), [n, r] = K(0);
30
+ return (typeof window > "u" ? ie : ce)(() => {
31
+ const o = e.current;
32
+ if (!o) return;
33
+ const a = () => r(o.clientWidth);
34
+ if (a(), typeof ResizeObserver > "u") return;
35
+ const i = new ResizeObserver(a);
36
+ return i.observe(o), () => i.disconnect();
37
+ }, []), { ref: e, width: n || de };
38
+ }
39
+ const he = 5;
40
+ function fe(e) {
41
+ const n = Math.abs(e), r = (t, o) => `${(Math.round(t * 10) / 10).toString()}${o}`;
42
+ return n >= 1e9 ? r(e / 1e9, "B") : n >= 1e6 ? r(e / 1e6, "M") : n >= 1e3 ? r(e / 1e3, "K") : Number.isInteger(e) ? String(e) : (Math.round(e * 100) / 100).toString();
43
+ }
44
+ function me(e) {
45
+ if (e <= 0) return 1;
46
+ const r = 10 ** Math.floor(Math.log10(e)), t = e / r;
47
+ return (t <= 1 ? 1 : t <= 2 ? 2 : t <= 2.5 ? 2.5 : t <= 5 ? 5 : 10) * r;
48
+ }
49
+ function xe(e, n, r = he) {
50
+ n === e && (n = e + 1);
51
+ const t = me((n - e) / Math.max(1, r - 1)), o = Math.floor(e / t) * t, a = Math.ceil(n / t) * t, i = [];
52
+ for (let c = a; c >= o - t / 2; c -= t) i.push(Number(c.toFixed(10)));
53
+ return { min: o, max: a, ticks: i };
54
+ }
55
+ function J(e, n) {
56
+ return n && n.length ? n : [{ data: e ?? [] }];
57
+ }
58
+ const k = (e) => typeof e == "number";
59
+ function Q(e, n = !0) {
60
+ const r = e.flatMap((f) => f.data.map((u) => u.y).filter(k)), t = n ? Math.min(0, ...r) : Math.min(...r), o = Math.max(...r, n ? 1 : -1 / 0), { min: a, max: i, ticks: c } = xe(
61
+ Number.isFinite(t) ? t : 0,
62
+ o === -1 / 0 ? 1 : o
63
+ );
64
+ return { min: a, max: i, range: i - a || 1, ticks: c };
65
+ }
66
+ function Z(e, n, r, t, o) {
67
+ const a = n - S * 2, i = r - S * 2;
68
+ return { sx: (u) => e <= 1 ? S + a / 2 : S + u / (e - 1) * a, sy: (u) => S + i - (u - t) / o * i };
69
+ }
70
+ function G(e) {
71
+ if (e.length === 0) return "";
72
+ if (e.length < 3) return e.map((r, t) => `${t ? "L" : "M"}${r[0]},${r[1]}`).join(" ");
73
+ let n = `M${e[0][0]},${e[0][1]}`;
74
+ for (let r = 0; r < e.length - 1; r++) {
75
+ const t = e[r - 1] ?? e[r], o = e[r], a = e[r + 1], i = e[r + 2] ?? a, c = o[0] + (a[0] - t[0]) / 6, f = o[1] + (a[1] - t[1]) / 6, u = a[0] - (i[0] - o[0]) / 6, l = a[1] - (i[1] - o[1]) / 6;
76
+ n += ` C${c.toFixed(1)},${f.toFixed(1)} ${u.toFixed(1)},${l.toFixed(1)} ${a[0].toFixed(1)},${a[1].toFixed(1)}`;
35
77
  }
36
78
  return n;
37
79
  }
38
- function D(t) {
39
- return t.map((n, e) => {
40
- const r = n.data.map((d) => d.y);
41
- if (!r.length) return `${n.name ?? `Series ${e + 1}`}: no data`;
42
- const a = Math.min(...r), o = Math.max(...r), c = n.data[n.data.length - 1];
43
- return `${n.name ?? `Series ${e + 1}`}: ${r.length} points, min ${a}, max ${o}, last ${c.x}: ${c.y}`;
80
+ function pe(e, n, r) {
81
+ const t = [];
82
+ let o = [];
83
+ return e.forEach((a, i) => {
84
+ k(a.y) ? o.push([n(i), r(a.y)]) : o.length && (t.push(o), o = []);
85
+ }), o.length && t.push(o), t;
86
+ }
87
+ const Y = (e, n, r) => e.name ?? z(r.series, { n: n + 1 });
88
+ function ye(e, n, r) {
89
+ return e.map((t, o) => {
90
+ const a = t.data.map((f) => f.y).filter(k), i = Y(t, o, n);
91
+ if (!a.length) return `${i}: ${n.noData}`;
92
+ const c = [...t.data].reverse().find((f) => k(f.y));
93
+ return r.summary({
94
+ name: i,
95
+ count: a.length,
96
+ min: Math.min(...a),
97
+ max: Math.max(...a),
98
+ lastX: c == null ? void 0 : c.x,
99
+ lastY: (c == null ? void 0 : c.y) ?? void 0
100
+ });
44
101
  }).join(". ");
45
102
  }
46
- function H({ height: t }) {
47
- const n = t - h * 2;
48
- return /* @__PURE__ */ i("g", { "aria-hidden": !0, children: Array.from({ length: W + 1 }, (e, r) => {
49
- const a = h + r / W * n;
50
- return /* @__PURE__ */ i(
103
+ function ee({ width: e, height: n, lines: r }) {
104
+ const t = n - S * 2, o = Math.max(1, r);
105
+ return /* @__PURE__ */ s("g", { "aria-hidden": !0, children: Array.from({ length: o + 1 }, (a, i) => {
106
+ const c = S + i / o * t;
107
+ return /* @__PURE__ */ s(
51
108
  "line",
52
109
  {
53
110
  x1: 0,
54
- x2: A,
55
- y1: a,
56
- y2: a,
111
+ x2: e,
112
+ y1: c,
113
+ y2: c,
57
114
  stroke: "var(--color-border)",
58
115
  strokeWidth: 1,
59
- vectorEffect: "non-scaling-stroke",
60
116
  opacity: 0.6
61
117
  },
62
- r
118
+ i
63
119
  );
64
120
  }) });
65
121
  }
66
- function V({ min: t, max: n }) {
67
- const e = Array.from(
68
- { length: _ },
69
- (r, a) => n - (n - t) * a / (_ - 1)
70
- );
71
- return /* @__PURE__ */ i(
122
+ function ge({ ticks: e }) {
123
+ return /* @__PURE__ */ s(
72
124
  "div",
73
125
  {
74
126
  "aria-hidden": !0,
75
- className: "tabular text-foreground-subtle pointer-events-none flex shrink-0 flex-col justify-between py-[6px] pr-1.5 text-right text-xs",
76
- children: e.map((r, a) => /* @__PURE__ */ i("span", { className: "leading-none", children: K(r) }, a))
127
+ className: "tabular text-foreground-subtle pointer-events-none flex shrink-0 flex-col justify-between py-1.5 pr-1.5 text-right text-xs",
128
+ children: e.map((n, r) => /* @__PURE__ */ s("span", { className: "leading-none", children: fe(n) }, r))
77
129
  }
78
130
  );
79
131
  }
80
- function Y({ first: t, last: n }) {
81
- return t ? /* @__PURE__ */ M("div", { "aria-hidden": !0, className: "text-foreground-subtle flex justify-between text-xs", children: [
82
- /* @__PURE__ */ i("span", { children: String(t.x) }),
83
- n && n !== t && /* @__PURE__ */ i("span", { children: String(n.x) })
132
+ function be({ first: e, last: n }) {
133
+ return e ? /* @__PURE__ */ $("div", { "aria-hidden": !0, className: "text-foreground-subtle flex justify-between text-xs", children: [
134
+ /* @__PURE__ */ s("span", { children: String(e.x) }),
135
+ n && n !== e && /* @__PURE__ */ s("span", { children: String(n.x) })
84
136
  ] }) : null;
85
137
  }
86
- function R({
87
- caption: t,
138
+ function ve({
139
+ id: e,
140
+ all: n,
141
+ name: r,
142
+ visible: t,
143
+ t: o
144
+ }) {
145
+ var f;
146
+ const a = Math.max(...n.map((u) => u.data.length)), i = ((f = n.find((u) => u.data.length === a)) == null ? void 0 : f.data) ?? [], c = /* @__PURE__ */ $(
147
+ "table",
148
+ {
149
+ id: e,
150
+ "data-chart-table": !0,
151
+ className: w(t && "tabular text-foreground-muted mt-2 w-full text-left text-xs"),
152
+ children: [
153
+ /* @__PURE__ */ s("caption", { className: w(t && "text-foreground-subtle pb-1 text-left"), children: z(o.tableCaption, { name: r ?? "" }).trim() }),
154
+ /* @__PURE__ */ s("thead", { children: /* @__PURE__ */ $("tr", { children: [
155
+ /* @__PURE__ */ s("th", { scope: "col", className: w(t && "border-border border-b py-1 pr-3 font-medium"), children: "x" }),
156
+ n.map((u, l) => /* @__PURE__ */ s(
157
+ "th",
158
+ {
159
+ scope: "col",
160
+ className: w(t && "border-border border-b py-1 pr-3 font-medium"),
161
+ children: Y(u, l, o)
162
+ },
163
+ l
164
+ ))
165
+ ] }) }),
166
+ /* @__PURE__ */ s("tbody", { children: i.map((u, l) => /* @__PURE__ */ $("tr", { children: [
167
+ /* @__PURE__ */ s("th", { scope: "row", className: w(t && "py-0.5 pr-3 font-normal"), children: String(u.x) }),
168
+ n.map((d, m) => {
169
+ var h, y;
170
+ return /* @__PURE__ */ s("td", { className: w(t && "py-0.5 pr-3"), children: k((h = d.data[l]) == null ? void 0 : h.y) ? String((y = d.data[l]) == null ? void 0 : y.y) : "—" }, m);
171
+ })
172
+ ] }, l)) })
173
+ ]
174
+ }
175
+ );
176
+ return t ? c : /* @__PURE__ */ s("div", { className: "sr-only", children: c });
177
+ }
178
+ function te({
179
+ caption: e,
88
180
  ariaLabel: n,
89
- title: e,
90
- desc: r,
91
- height: a,
92
- width: o,
93
- className: c,
94
- showAxis: d,
95
- yDomain: l,
96
- xFirst: $,
97
- xLast: y,
98
- children: s
181
+ title: r,
182
+ all: t,
183
+ height: o,
184
+ width: a,
185
+ className: i,
186
+ showAxis: c,
187
+ ticks: f,
188
+ xFirst: u,
189
+ xLast: l,
190
+ tableFallback: d,
191
+ showTableToggle: m,
192
+ state: h,
193
+ labels: y,
194
+ children: E
99
195
  }) {
100
- const f = T().replace(/:/g, ""), p = `chart-cap-${f}`, F = `chart-title-${f}`, g = `chart-desc-${f}`, x = n ?? e;
101
- return /* @__PURE__ */ M("figure", { className: G("flex flex-col gap-1.5", c), style: { width: o }, children: [
102
- t && /* @__PURE__ */ i("figcaption", { id: p, className: "text-foreground-muted text-xs", children: t }),
103
- /* @__PURE__ */ M("div", { className: "flex", children: [
104
- d && /* @__PURE__ */ i(V, { min: l.min, max: l.max }),
105
- /* @__PURE__ */ M(
106
- "svg",
107
- {
108
- viewBox: `0 0 ${A} ${a}`,
109
- width: "100%",
110
- height: a,
111
- preserveAspectRatio: "none",
112
- role: "img",
113
- "aria-labelledby": t ? p : x ? F : void 0,
114
- "aria-describedby": g,
115
- className: "min-w-0 flex-1 overflow-visible",
116
- children: [
117
- x && /* @__PURE__ */ i("title", { id: F, children: x }),
118
- /* @__PURE__ */ i("desc", { id: g, children: r }),
119
- s
120
- ]
121
- }
122
- )
196
+ const g = X().chart, x = oe().replace(/:/g, ""), I = `chart-cap-${x}`, F = `chart-title-${x}`, C = `chart-desc-${x}`, O = `chart-table-${x}`, v = n ?? r, [p, M] = K(!1), { ref: P, width: A } = ue(), N = $e(t, g, y);
197
+ process.env.NODE_ENV !== "production" && !v && !e && console.warn(
198
+ "[craftzbay/ui] Chart: provide `caption`, `aria-label`, or `title` so the chart has an accessible name."
199
+ );
200
+ const L = (d || p) && !h, R = h === "loading" ? /* @__PURE__ */ $("div", { role: "status", "aria-label": g.loading, style: { height: o }, className: "w-full", children: [
201
+ /* @__PURE__ */ s(le, { style: { height: o }, className: "w-full" }),
202
+ /* @__PURE__ */ s("span", { className: "sr-only", children: g.loading })
203
+ ] }) : h ? /* @__PURE__ */ s(
204
+ "div",
205
+ {
206
+ role: h === "error" ? "alert" : "status",
207
+ style: { height: o },
208
+ className: "text-foreground-subtle flex w-full items-center justify-center text-sm",
209
+ children: h === "error" ? g.error : g.empty
210
+ }
211
+ ) : null;
212
+ return /* @__PURE__ */ $("figure", { className: w("flex flex-col gap-1.5", i), style: { width: a }, children: [
213
+ e && /* @__PURE__ */ s("figcaption", { id: I, className: "text-foreground-muted text-xs", children: e }),
214
+ R ?? /* @__PURE__ */ $(U, { children: [
215
+ /* @__PURE__ */ $("div", { className: "flex", children: [
216
+ c && /* @__PURE__ */ s(ge, { ticks: f }),
217
+ /* @__PURE__ */ s("div", { ref: P, className: "min-w-0 flex-1", children: /* @__PURE__ */ $(
218
+ "svg",
219
+ {
220
+ viewBox: `0 0 ${A} ${o}`,
221
+ width: A,
222
+ height: o,
223
+ role: "group",
224
+ "aria-labelledby": e ? I : v ? F : void 0,
225
+ "aria-describedby": C,
226
+ className: "block max-w-full overflow-visible",
227
+ children: [
228
+ v && /* @__PURE__ */ s("title", { id: F, children: v }),
229
+ /* @__PURE__ */ s("desc", { id: C, children: ye(t, g, y) }),
230
+ E({ width: A, ...N })
231
+ ]
232
+ }
233
+ ) })
234
+ ] }),
235
+ c && /* @__PURE__ */ s(be, { first: u, last: l }),
236
+ /* @__PURE__ */ s("span", { className: "sr-only", "aria-live": "polite", "aria-atomic": "true", children: N.announcement })
123
237
  ] }),
124
- d && /* @__PURE__ */ i(Y, { first: $, last: y })
238
+ m && !h && /* @__PURE__ */ s(
239
+ "button",
240
+ {
241
+ type: "button",
242
+ onClick: () => M((W) => !W),
243
+ "aria-expanded": p,
244
+ "aria-controls": L ? O : void 0,
245
+ className: w(
246
+ "text-foreground-subtle hover:text-foreground self-start rounded-sm text-xs underline-offset-2 outline-none hover:underline",
247
+ "focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-2"
248
+ ),
249
+ children: p ? g.hideTable : g.viewAsTable
250
+ }
251
+ ),
252
+ L && /* @__PURE__ */ s(
253
+ ve,
254
+ {
255
+ id: O,
256
+ all: t,
257
+ name: v ?? (typeof e == "string" ? e : void 0),
258
+ visible: p,
259
+ t: g
260
+ }
261
+ )
125
262
  ] });
126
263
  }
127
- function q({
128
- data: t,
264
+ function $e(e, n, r) {
265
+ const [t, o] = K(null), [a, i] = K(""), c = se(
266
+ (l, d) => {
267
+ const m = e[l], h = m == null ? void 0 : m.data[d];
268
+ !h || !k(h.y) || (o({ series: l, index: d }), i(r.point(m.name, h.x, h.y)));
269
+ },
270
+ [e, r]
271
+ ), f = (l) => e[l].data.map((d, m) => k(d.y) ? m : -1).filter((d) => d >= 0);
272
+ return { active: t, announcement: a, seriesProps: (l) => ({
273
+ tabIndex: 0,
274
+ role: "group",
275
+ "aria-label": r.series(Y(e[l], l, n), f(l).length),
276
+ // Focus ring comes from theme.css `[data-chart-series]:focus-visible`
277
+ // (CSS outline — Tailwind's box-shadow ring does not paint on SVG <g>).
278
+ "data-chart-series": !0,
279
+ className: w(
280
+ "[&:focus-visible_[data-active]]:stroke-[var(--ring)] [&:focus-visible_[data-active]]:stroke-[3px]"
281
+ ),
282
+ onFocus: () => {
283
+ const d = f(l);
284
+ d.length && c(l, (t == null ? void 0 : t.series) === l ? t.index : d[d.length - 1]);
285
+ },
286
+ onBlur: () => {
287
+ o(null), i("");
288
+ },
289
+ onKeyDown: (d) => {
290
+ const m = f(l);
291
+ if (!m.length) return;
292
+ const h = (t == null ? void 0 : t.series) === l ? m.indexOf(t.index) : m.length - 1;
293
+ let y = h;
294
+ if (d.key === "ArrowRight" || d.key === "ArrowUp") y = Math.min(m.length - 1, h + 1);
295
+ else if (d.key === "ArrowLeft" || d.key === "ArrowDown") y = Math.max(0, h - 1);
296
+ else if (d.key === "Home") y = 0;
297
+ else if (d.key === "End") y = m.length - 1;
298
+ else return;
299
+ d.preventDefault(), c(l, m[y]);
300
+ }
301
+ }) };
302
+ }
303
+ function Me({
304
+ x: e,
305
+ y: n,
306
+ color: r,
307
+ label: t,
308
+ always: o,
309
+ active: a
310
+ }) {
311
+ return /* @__PURE__ */ s(
312
+ "circle",
313
+ {
314
+ cx: e,
315
+ cy: n,
316
+ r: 3.5,
317
+ fill: r,
318
+ "data-active": a || void 0,
319
+ className: w(!o && !a && "opacity-0 hover:opacity-100"),
320
+ children: /* @__PURE__ */ s("title", { children: t })
321
+ }
322
+ );
323
+ }
324
+ function Ne({
325
+ data: e,
129
326
  series: n,
130
- colors: e = w,
131
- height: r = 160,
132
- width: a = "100%",
133
- caption: o,
134
- "aria-label": c,
135
- title: d,
136
- grid: l = !0,
137
- showAxis: $ = !0,
327
+ colors: r = q,
328
+ height: t = 160,
329
+ width: o = "100%",
330
+ caption: a,
331
+ "aria-label": i,
332
+ title: c,
333
+ grid: f = !0,
334
+ showAxis: u = !0,
335
+ tableFallback: l = !0,
336
+ showTableToggle: d,
337
+ state: m,
338
+ labels: h,
138
339
  className: y
139
340
  }) {
140
- const s = E(t, n), { min: f, max: p, range: F } = B(s), g = Math.max(...s.map((u) => u.data.length)), x = s[0].data;
141
- return /* @__PURE__ */ M(
142
- R,
341
+ const E = X().chart, g = { ...V(E), ...h }, x = J(e, n), { min: I, range: F, ticks: C } = Q(x), O = Math.max(...x.map((p) => p.data.length)), v = x[0].data;
342
+ return /* @__PURE__ */ s(
343
+ te,
143
344
  {
144
- caption: o,
145
- ariaLabel: c,
146
- title: d,
147
- desc: D(s),
148
- height: r,
149
- width: a,
345
+ caption: a,
346
+ ariaLabel: i,
347
+ title: c,
348
+ all: x,
349
+ height: t,
350
+ width: o,
150
351
  className: y,
151
- showAxis: $,
152
- yDomain: { min: f, max: p },
153
- xFirst: x[0],
154
- xLast: x[x.length - 1],
155
- children: [
156
- l && /* @__PURE__ */ i(H, { height: r }),
157
- s.map((u, L) => {
158
- const v = e[L % e.length], { sx: b, sy: k } = X(g, r, f, F), m = u.data.map((O, P) => [b(P), k(O.y)]), N = U(m), S = k(Math.max(f, 0)), I = m.length ? `${N} L${m[m.length - 1][0].toFixed(1)},${S.toFixed(1)} L${m[0][0].toFixed(1)},${S.toFixed(1)} Z` : "", j = m[m.length - 1], C = u.data[u.data.length - 1];
159
- return /* @__PURE__ */ M("g", { children: [
160
- I && /* @__PURE__ */ i("path", { d: I, fill: v, fillOpacity: 0.08 }),
161
- /* @__PURE__ */ i(
352
+ showAxis: u,
353
+ ticks: C,
354
+ xFirst: v[0],
355
+ xLast: v[v.length - 1],
356
+ tableFallback: l,
357
+ showTableToggle: d,
358
+ state: m,
359
+ labels: g,
360
+ children: ({ width: p, active: M, seriesProps: P }) => /* @__PURE__ */ $(U, { children: [
361
+ f && /* @__PURE__ */ s(ee, { width: p, height: t, lines: C.length - 1 }),
362
+ x.map((A, N) => {
363
+ const L = r[N % r.length], { sx: R, sy: W } = Z(O, p, t, I, F), D = pe(A.data, R, W), H = D.map(G).join(" "), j = W(Math.max(I, 0)), T = D.map(
364
+ (b) => `${G(b)} L${b[b.length - 1][0].toFixed(1)},${j.toFixed(1)} L${b[0][0].toFixed(1)},${j.toFixed(1)} Z`
365
+ ).join(" "), B = A.data.map((b) => k(b.y)).lastIndexOf(!0);
366
+ return /* @__PURE__ */ $("g", { ...P(N), children: [
367
+ T && /* @__PURE__ */ s("path", { d: T, fill: L, fillOpacity: 0.08 }),
368
+ /* @__PURE__ */ s(
162
369
  "path",
163
370
  {
164
- d: N,
371
+ d: H,
165
372
  fill: "none",
166
- stroke: v,
373
+ stroke: L,
167
374
  strokeWidth: 2,
168
375
  strokeLinecap: "round",
169
- strokeLinejoin: "round",
170
- vectorEffect: "non-scaling-stroke"
376
+ strokeLinejoin: "round"
171
377
  }
172
378
  ),
173
- j && /* @__PURE__ */ i(
174
- "circle",
175
- {
176
- cx: j[0],
177
- cy: j[1],
178
- r: 3.5,
179
- fill: v,
180
- vectorEffect: "non-scaling-stroke",
181
- children: /* @__PURE__ */ i("title", { children: `${u.name ? `${u.name} ` : ""}${C.x}: ${C.y}` })
182
- }
379
+ A.data.map(
380
+ (b, _) => k(b.y) ? /* @__PURE__ */ s(
381
+ Me,
382
+ {
383
+ x: R(_),
384
+ y: W(b.y),
385
+ color: L,
386
+ always: _ === B,
387
+ active: (M == null ? void 0 : M.series) === N && M.index === _,
388
+ label: g.point(A.name, b.x, b.y)
389
+ },
390
+ _
391
+ ) : null
183
392
  )
184
- ] }, L);
393
+ ] }, N);
185
394
  })
186
- ]
395
+ ] })
187
396
  }
188
397
  );
189
398
  }
190
- function Z(t) {
191
- return /* @__PURE__ */ i(q, { ...t });
399
+ function Ce(e) {
400
+ return /* @__PURE__ */ s(Ne, { ...e });
192
401
  }
193
- function tt({
194
- data: t,
402
+ function We({
403
+ data: e,
195
404
  series: n,
196
- colors: e = w,
197
- height: r = 160,
198
- width: a = "100%",
199
- caption: o,
200
- "aria-label": c,
201
- title: d,
202
- grid: l = !0,
203
- showAxis: $ = !0,
405
+ colors: r = q,
406
+ height: t = 160,
407
+ width: o = "100%",
408
+ caption: a,
409
+ "aria-label": i,
410
+ title: c,
411
+ grid: f = !0,
412
+ showAxis: u = !0,
413
+ tableFallback: l = !0,
414
+ showTableToggle: d,
415
+ state: m,
416
+ labels: h,
204
417
  className: y
205
418
  }) {
206
- const s = E(t, n), f = A - h * 2, p = r - h * 2, F = Math.max(...s.map((b) => b.data.length)), g = f / Math.max(1, F), x = g * 0.62, u = Math.max(2, x / s.length), { max: L } = B(s), v = s[0].data;
207
- return /* @__PURE__ */ M(
208
- R,
419
+ const E = X().chart, g = { ...V(E), ...h }, x = J(e, n), I = Math.max(...x.map((p) => p.data.length)), { min: F, range: C, ticks: O } = Q(x), v = x[0].data;
420
+ return /* @__PURE__ */ s(
421
+ te,
209
422
  {
210
- caption: o,
211
- ariaLabel: c,
212
- title: d,
213
- desc: D(s),
214
- height: r,
215
- width: a,
423
+ caption: a,
424
+ ariaLabel: i,
425
+ title: c,
426
+ all: x,
427
+ height: t,
428
+ width: o,
216
429
  className: y,
217
- showAxis: $,
218
- yDomain: { min: 0, max: L },
430
+ showAxis: u,
431
+ ticks: O,
219
432
  xFirst: v[0],
220
433
  xLast: v[v.length - 1],
221
- children: [
222
- l && /* @__PURE__ */ i(H, { height: r }),
223
- s.map(
224
- (b, k) => b.data.map((m, N) => {
225
- const S = Math.max(0, m.y) / L * p, I = h + N * g + (g - x) / 2 + k * u;
226
- return /* @__PURE__ */ i(
434
+ tableFallback: l,
435
+ showTableToggle: d,
436
+ state: m,
437
+ labels: g,
438
+ children: ({ width: p, active: M, seriesProps: P }) => {
439
+ const N = (p - S * 2) / Math.max(1, I), L = N * 0.62, R = Math.max(2, L / x.length), { sy: W } = Z(I, p, t, F, C), D = W(Math.min(Math.max(0, F), F + C));
440
+ return /* @__PURE__ */ $(U, { children: [
441
+ f && /* @__PURE__ */ s(ee, { width: p, height: t, lines: O.length - 1 }),
442
+ F < 0 && /* @__PURE__ */ s(
443
+ "line",
444
+ {
445
+ "aria-hidden": !0,
446
+ x1: 0,
447
+ x2: p,
448
+ y1: D,
449
+ y2: D,
450
+ stroke: "var(--color-border-strong)",
451
+ strokeWidth: 1
452
+ }
453
+ ),
454
+ x.map((H, j) => /* @__PURE__ */ s("g", { ...P(j), children: H.data.map((T, B) => {
455
+ if (!k(T.y)) return null;
456
+ const b = W(T.y), _ = S + B * N + (N - L) / 2 + j * R, ne = g.point(H.name, T.x, T.y), re = (M == null ? void 0 : M.series) === j && M.index === B;
457
+ return /* @__PURE__ */ s(
227
458
  "rect",
228
459
  {
229
- x: I,
230
- y: h + p - S,
231
- width: u,
232
- height: Math.max(0, S),
233
- fill: e[k % e.length],
460
+ x: _,
461
+ y: Math.min(D, b),
462
+ width: R,
463
+ height: Math.abs(D - b),
464
+ fill: r[j % r.length],
234
465
  rx: 2,
466
+ "data-active": re || void 0,
235
467
  className: "transition-opacity hover:opacity-80",
236
- children: /* @__PURE__ */ i("title", { children: `${b.name ? `${b.name} — ` : ""}${m.x}: ${m.y}` })
468
+ children: /* @__PURE__ */ s("title", { children: ne })
237
469
  },
238
- `${k}-${N}`
470
+ B
239
471
  );
240
- })
241
- )
242
- ]
472
+ }) }, j))
473
+ ] });
474
+ }
243
475
  }
244
476
  );
245
477
  }
246
478
  export {
247
- Z as AreaChart,
248
- tt as BarChart,
249
- w as DEFAULT_CHART_COLORS,
250
- q as LineChart,
251
- K as abbreviateNumber
479
+ Ce as AreaChart,
480
+ We as BarChart,
481
+ q as DEFAULT_CHART_COLORS,
482
+ Ne as LineChart,
483
+ fe as abbreviateNumber,
484
+ Ie as defaultChartLabels,
485
+ xe as niceTicks
252
486
  };
253
487
  //# sourceMappingURL=Chart.js.map