@overdoser/react-toolkit 0.6.0 → 0.8.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 (116) hide show
  1. package/AGENTS.md +6 -0
  2. package/CHANGELOG.md +82 -0
  3. package/components/ActionButton/ActionButton.d.ts +105 -0
  4. package/components/ActionButton/ActionButton.js +211 -0
  5. package/components/ActionButton/ActionButton.module.scss.js +47 -0
  6. package/components/ActionButton/CopyButton.d.ts +31 -0
  7. package/components/ActionButton/CopyButton.js +66 -0
  8. package/components/ActionButton/index.d.ts +4 -0
  9. package/components/Alert/Alert.js +82 -0
  10. package/components/Alert/Alert.module.scss.js +25 -0
  11. package/components/Avatar/Avatar.js +57 -0
  12. package/components/Avatar/Avatar.module.scss.js +43 -0
  13. package/components/Badge/Badge.js +38 -0
  14. package/components/Badge/Badge.module.scss.js +31 -0
  15. package/components/Breadcrumbs/Breadcrumbs.js +49 -0
  16. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +17 -0
  17. package/components/Button/Button.js +57 -0
  18. package/components/Button/Button.module.scss.js +47 -0
  19. package/components/Chart/AreaChart.js +244 -0
  20. package/components/Chart/Axis.js +45 -0
  21. package/components/Chart/BarChart.js +353 -0
  22. package/components/Chart/Chart.module.scss.js +61 -0
  23. package/components/Chart/ChartContainer.js +41 -0
  24. package/components/Chart/ChartLegend.js +31 -0
  25. package/components/Chart/ChartTooltip.js +42 -0
  26. package/components/Chart/LineChart.js +236 -0
  27. package/components/Chart/PieChart.js +248 -0
  28. package/components/Chart/RadarChart.js +221 -0
  29. package/components/Chart/Sparkline.js +69 -0
  30. package/components/Chart/TradingChart.js +732 -0
  31. package/components/Chart/scales.js +39 -0
  32. package/components/Chart/trading/indicators.js +68 -0
  33. package/components/Chart/trading/period.js +71 -0
  34. package/components/Chart/useChartDimensions.js +23 -0
  35. package/components/Divider/Divider.js +36 -0
  36. package/components/Divider/Divider.module.scss.js +31 -0
  37. package/components/Draggable/Draggable.js +155 -0
  38. package/components/Draggable/Draggable.module.scss.js +17 -0
  39. package/components/Drawer/Drawer.js +126 -0
  40. package/components/Drawer/Drawer.module.scss.js +117 -0
  41. package/components/Dropdown/Dropdown.js +142 -0
  42. package/components/Dropdown/Dropdown.module.scss.js +35 -0
  43. package/components/Dropdown/DropdownItem.js +31 -0
  44. package/components/Dropzone/Dropzone.js +107 -0
  45. package/components/Dropzone/Dropzone.module.scss.js +21 -0
  46. package/components/Form/Form.js +36 -0
  47. package/components/Form/Form.module.scss.js +29 -0
  48. package/components/Form/FormField.js +76 -0
  49. package/components/Form/FormRow.js +9 -0
  50. package/components/Form/formFieldDefaults.js +5 -0
  51. package/components/Link/Link.js +59 -0
  52. package/components/Link/Link.module.scss.js +16 -0
  53. package/components/List/List.js +46 -0
  54. package/components/List/List.module.scss.js +21 -0
  55. package/components/Modal/Modal.js +109 -0
  56. package/components/Modal/Modal.module.scss.js +31 -0
  57. package/components/Pagination/Pagination.js +84 -0
  58. package/components/Pagination/Pagination.module.scss.js +23 -0
  59. package/components/Pagination/paginationRange.js +24 -0
  60. package/components/Popover/Popover.js +138 -0
  61. package/components/Popover/Popover.module.scss.js +21 -0
  62. package/components/Skeleton/Skeleton.js +50 -0
  63. package/components/Skeleton/Skeleton.module.scss.js +25 -0
  64. package/components/Spinner/Spinner.js +25 -0
  65. package/components/Spinner/Spinner.module.scss.js +20 -0
  66. package/components/Table/Table.d.ts +61 -6
  67. package/components/Table/Table.js +284 -0
  68. package/components/Table/Table.module.scss.js +59 -0
  69. package/components/Table/useTableSort.d.ts +7 -5
  70. package/components/Table/useTableSort.js +44 -0
  71. package/components/Tabs/Tabs.js +163 -0
  72. package/components/Tabs/Tabs.module.scss.js +53 -0
  73. package/components/Timer/Timer.js +159 -0
  74. package/components/Timer/Timer.module.scss.js +55 -0
  75. package/components/Toast/Toast.js +133 -0
  76. package/components/Toast/Toast.module.scss.js +62 -0
  77. package/components/Toast/toastStore.js +62 -0
  78. package/components/ToggleIconButton/ToggleIconButton.d.ts +62 -0
  79. package/components/ToggleIconButton/ToggleIconButton.js +58 -0
  80. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +27 -0
  81. package/components/ToggleIconButton/index.d.ts +2 -0
  82. package/components/Tooltip/Tooltip.js +86 -0
  83. package/components/Tooltip/Tooltip.module.scss.js +30 -0
  84. package/components/Typography/Typography.js +37 -0
  85. package/components/Typography/Typography.module.scss.js +53 -0
  86. package/components/inputs/Checkbox/Checkbox.js +50 -0
  87. package/components/inputs/Checkbox/Checkbox.module.scss.js +15 -0
  88. package/components/inputs/Checkbox/CheckboxGroup.js +111 -0
  89. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +31 -0
  90. package/components/inputs/DatePicker/DatePicker.js +229 -0
  91. package/components/inputs/DatePicker/DatePicker.module.scss.js +45 -0
  92. package/components/inputs/DatePicker/dateUtils.js +41 -0
  93. package/components/inputs/Input/Input.js +50 -0
  94. package/components/inputs/Input/Input.module.scss.js +25 -0
  95. package/components/inputs/NumberInput/NumberInput.js +134 -0
  96. package/components/inputs/NumberInput/NumberInput.module.scss.js +25 -0
  97. package/components/inputs/Radio/Radio.js +68 -0
  98. package/components/inputs/Radio/Radio.module.scss.js +13 -0
  99. package/components/inputs/Select/Select.js +520 -0
  100. package/components/inputs/Select/Select.module.scss.js +69 -0
  101. package/components/inputs/Slider/Slider.js +128 -0
  102. package/components/inputs/Slider/Slider.module.scss.js +15 -0
  103. package/components/inputs/Textarea/Textarea.js +58 -0
  104. package/components/inputs/Textarea/Textarea.module.scss.js +25 -0
  105. package/hooks/useClickOutside.js +15 -0
  106. package/hooks/useFocusTrap.js +39 -0
  107. package/hooks/useKeyboard.js +19 -0
  108. package/hooks/usePortalPosition.js +20 -0
  109. package/index.css +1 -1
  110. package/index.d.ts +4 -0
  111. package/index.js +119 -6575
  112. package/index.layered.css +1 -1
  113. package/llms.txt +123 -5
  114. package/manifest.json +230 -2
  115. package/package.json +3 -2
  116. package/recipes/comparison-table.tsx +123 -0
@@ -0,0 +1,236 @@
1
+ import { jsx as l, jsxs as J, Fragment as xt } from "react/jsx-runtime";
2
+ import { useMemo as ft, useState as yt, useRef as dt } from "react";
3
+ import S from "clsx";
4
+ import { ChartContainer as gt } from "./ChartContainer.js";
5
+ import { ChartLegend as vt } from "./ChartLegend.js";
6
+ import { ChartTooltip as pt } from "./ChartTooltip.js";
7
+ import { YAxis as $t, XAxis as Mt } from "./Axis.js";
8
+ import { bandScale as Q, extent as wt, niceTicks as Lt, linearScale as Ct } from "./scales.js";
9
+ import g from "./Chart.module.scss.js";
10
+ const Nt = { top: 12, right: 16, bottom: 28, left: 48 };
11
+ function Rt(t, u) {
12
+ if (t.length === 0) return "";
13
+ if (t.length === 1) return `M ${t[0].x} ${t[0].y}`;
14
+ if (u === "linear")
15
+ return t.map((r, o) => `${o === 0 ? "M" : "L"} ${r.x} ${r.y}`).join(" ");
16
+ if (u === "step") {
17
+ let r = `M ${t[0].x} ${t[0].y}`;
18
+ for (let o = 1; o < t.length; o++)
19
+ r += ` L ${t[o].x} ${t[o - 1].y} L ${t[o].x} ${t[o].y}`;
20
+ return r;
21
+ }
22
+ let i = `M ${t[0].x} ${t[0].y}`;
23
+ for (let r = 0; r < t.length - 1; r++) {
24
+ const o = t[r - 1] ?? t[r], f = t[r], h = t[r + 1], y = t[r + 2] ?? h, L = f.x + (h.x - o.x) / 6, $ = f.y + (h.y - o.y) / 6, A = h.x - (y.x - f.x) / 6, C = h.y - (y.y - f.y) / 6;
25
+ i += ` C ${L} ${$}, ${A} ${C}, ${h.x} ${h.y}`;
26
+ }
27
+ return i;
28
+ }
29
+ function Tt(t, u = 8) {
30
+ if (t.length <= u) return t;
31
+ const i = Math.ceil(t.length / u);
32
+ return t.filter((r, o) => o % i === 0);
33
+ }
34
+ function Dt({
35
+ data: t,
36
+ xKey: u,
37
+ config: i,
38
+ aspectRatio: r = 16 / 9,
39
+ height: o,
40
+ curve: f = "monotone",
41
+ showPoints: h = !0,
42
+ dotColorKey: y,
43
+ renderDot: L,
44
+ showValues: $ = !1,
45
+ valuePosition: A = "top",
46
+ renderLabel: C,
47
+ activeIndex: D,
48
+ onPointClick: N,
49
+ showGrid: V = !0,
50
+ showLegend: Z = !0,
51
+ showTooltip: P = !0,
52
+ yTickCount: tt = 5,
53
+ yFormat: et,
54
+ xFormat: nt,
55
+ valueFormat: K,
56
+ renderTooltip: E,
57
+ margin: rt,
58
+ emptyMessage: ot = "No data",
59
+ className: F,
60
+ style: G,
61
+ classes: v
62
+ }) {
63
+ const R = { ...Nt, ...rt }, H = ft(() => Object.keys(i), [i]), [ct, O] = yt(null), X = dt(null), d = D ?? ct, U = (T, _) => {
64
+ if (y) {
65
+ const m = t[_]?.[y];
66
+ if (typeof m == "string") return m;
67
+ }
68
+ return i[T]?.color ?? "var(--crk-chart-1)";
69
+ };
70
+ if (t.length === 0)
71
+ return /* @__PURE__ */ l("div", { ref: X, className: S(g.root, v?.root, F), style: G, children: /* @__PURE__ */ l("div", { className: g.canvas, style: { height: o ?? 240 }, children: /* @__PURE__ */ l("div", { className: g.empty, children: ot }) }) });
72
+ const it = P && d !== null ? /* @__PURE__ */ l(
73
+ pt,
74
+ {
75
+ row: t[d],
76
+ x: bt(t, u, R, d, X),
77
+ y: 16,
78
+ containerWidth: X.current?.getBoundingClientRect().width ?? 0,
79
+ config: i,
80
+ render: E ? () => E(t[d]) : void 0,
81
+ valueFormat: K,
82
+ titleKey: u,
83
+ resolveColor: y ? (T) => U(T, d) : void 0,
84
+ classes: v
85
+ }
86
+ ) : null;
87
+ return /* @__PURE__ */ l(
88
+ gt,
89
+ {
90
+ ref: X,
91
+ aspectRatio: r,
92
+ height: o,
93
+ className: F,
94
+ style: G,
95
+ classes: v,
96
+ legend: Z ? /* @__PURE__ */ l(vt, { config: i, classes: v }) : void 0,
97
+ overlay: it,
98
+ children: ({ width: T, height: _ }) => {
99
+ const m = R.left, Y = T - R.right, B = R.top, j = _ - R.bottom, q = Math.max(0, Y - m), lt = Math.max(0, j - B), b = t.map((e) => String(e[u])), M = Q(b, [m, Y], 0), z = [];
100
+ for (const e of H)
101
+ for (const p of t) {
102
+ const x = p[e];
103
+ typeof x == "number" && z.push(x);
104
+ }
105
+ const [st, at] = wt(z), ut = Math.min(0, st), W = Lt(ut, at, tt), I = Ct([W[0], W[W.length - 1]], [j, B]), ht = W.map((e) => ({ value: e, y: I(e) })), mt = Tt(b).map((e) => ({ label: e, x: M(e) }));
106
+ return /* @__PURE__ */ J(xt, { children: [
107
+ /* @__PURE__ */ l(
108
+ $t,
109
+ {
110
+ ticks: ht,
111
+ x: m,
112
+ plotWidth: q,
113
+ format: et,
114
+ showGrid: V,
115
+ classes: v
116
+ }
117
+ ),
118
+ /* @__PURE__ */ l(Mt, { ticks: mt, y: j, format: nt, classes: v }),
119
+ H.map((e) => {
120
+ const p = i[e], x = t.map((n, c) => {
121
+ const s = n[e], a = typeof s == "number" ? s : 0;
122
+ return { x: M(b[c]), y: I(a), value: a, row: n };
123
+ });
124
+ return /* @__PURE__ */ J("g", { className: S(g.series, v?.series), children: [
125
+ /* @__PURE__ */ l(
126
+ "path",
127
+ {
128
+ className: S(g.linePath),
129
+ d: Rt(x, f),
130
+ stroke: p.color
131
+ }
132
+ ),
133
+ h && x.map((n, c) => {
134
+ const s = U(e, c), a = d === c, w = D !== void 0 && !a, k = N ? () => N({ row: n.row, value: n.value, seriesKey: e, index: c }) : void 0;
135
+ return L ? /* @__PURE__ */ l(
136
+ "g",
137
+ {
138
+ onClick: k,
139
+ style: k ? { cursor: "pointer" } : void 0,
140
+ opacity: w ? 0.45 : 1,
141
+ children: L({
142
+ row: n.row,
143
+ value: n.value,
144
+ seriesKey: e,
145
+ index: c,
146
+ x: n.x,
147
+ y: n.y,
148
+ color: s,
149
+ active: a
150
+ })
151
+ },
152
+ `${e}-${c}`
153
+ ) : /* @__PURE__ */ l(
154
+ "circle",
155
+ {
156
+ className: S(g.point, v?.point),
157
+ cx: n.x,
158
+ cy: n.y,
159
+ r: a ? 5 : 3.5,
160
+ fill: s,
161
+ onClick: k,
162
+ style: k ? { cursor: "pointer" } : void 0,
163
+ opacity: w ? 0.45 : 1
164
+ },
165
+ `${e}-${c}`
166
+ );
167
+ }),
168
+ ($ || C) && x.map((n, c) => {
169
+ const s = C ? C({ row: n.row, value: n.value, seriesKey: e, index: c }) : $ ? K ? K(n.value) : String(n.value) : null;
170
+ if (s == null) return null;
171
+ const a = 10, w = A === "top" ? n.y - a : n.y + a + 4;
172
+ return /* @__PURE__ */ l(
173
+ "text",
174
+ {
175
+ className: S(g.axisLabel),
176
+ x: n.x,
177
+ y: w,
178
+ textAnchor: "middle",
179
+ dominantBaseline: A === "top" ? "auto" : "middle",
180
+ children: s
181
+ },
182
+ `label-${e}-${c}`
183
+ );
184
+ })
185
+ ] }, e);
186
+ }),
187
+ d !== null && /* @__PURE__ */ l(
188
+ "line",
189
+ {
190
+ className: g.cursorLine,
191
+ x1: M(b[d]),
192
+ x2: M(b[d]),
193
+ y1: B,
194
+ y2: j
195
+ }
196
+ ),
197
+ /* @__PURE__ */ l(
198
+ "rect",
199
+ {
200
+ className: g.interactionLayer,
201
+ x: m,
202
+ y: B,
203
+ width: q,
204
+ height: lt,
205
+ onMouseMove: (e) => {
206
+ const p = e.currentTarget.getBoundingClientRect(), x = e.clientX - p.left + m, n = M.step(), c = Math.max(
207
+ 0,
208
+ Math.min(t.length - 1, Math.round((x - m - n / 2) / n))
209
+ );
210
+ O(c);
211
+ },
212
+ onMouseLeave: () => O(null),
213
+ onClick: N ? (e) => {
214
+ const p = e.currentTarget.getBoundingClientRect(), x = e.clientX - p.left + m, n = M.step(), c = Math.max(
215
+ 0,
216
+ Math.min(t.length - 1, Math.round((x - m - n / 2) / n))
217
+ ), s = H[0], a = t[c][s], w = typeof a == "number" ? a : 0;
218
+ N({ row: t[c], value: w, seriesKey: s, index: c });
219
+ } : void 0,
220
+ style: N ? { cursor: "pointer" } : void 0
221
+ }
222
+ )
223
+ ] });
224
+ }
225
+ }
226
+ );
227
+ }
228
+ function bt(t, u, i, r, o) {
229
+ const f = o.current;
230
+ if (!f) return 0;
231
+ const h = f.getBoundingClientRect().width, y = t.map(($) => String($[u]));
232
+ return Q(y, [i.left, h - i.right], 0)(y[r]);
233
+ }
234
+ export {
235
+ Dt as LineChart
236
+ };
@@ -0,0 +1,248 @@
1
+ import { jsx as a, jsxs as J, Fragment as at } from "react/jsx-runtime";
2
+ import { useState as lt, useRef as dt, useMemo as Q } from "react";
3
+ import D from "clsx";
4
+ import { ChartContainer as ht } from "./ChartContainer.js";
5
+ import { ChartTooltip as $t } from "./ChartTooltip.js";
6
+ import f from "./Chart.module.scss.js";
7
+ const ft = [
8
+ "var(--crk-chart-1)",
9
+ "var(--crk-chart-2)",
10
+ "var(--crk-chart-3)",
11
+ "var(--crk-chart-4)",
12
+ "var(--crk-chart-5)"
13
+ ];
14
+ function O(t, i) {
15
+ if (typeof t == "number") return t;
16
+ const n = /^([\d.]+)%$/.exec(t);
17
+ return n ? parseFloat(n[1]) / 100 * i : parseFloat(t) || 0;
18
+ }
19
+ function mt(t, i, n, e, m, M) {
20
+ if (Math.abs(M - m) >= 360 - 1e-6)
21
+ return e > 0 ? [
22
+ `M ${t + n} ${i}`,
23
+ `A ${n} ${n} 0 1 1 ${t - n} ${i}`,
24
+ `A ${n} ${n} 0 1 1 ${t + n} ${i}`,
25
+ `M ${t + e} ${i}`,
26
+ `A ${e} ${e} 0 1 0 ${t - e} ${i}`,
27
+ `A ${e} ${e} 0 1 0 ${t + e} ${i}`,
28
+ "Z"
29
+ ].join(" ") : [
30
+ `M ${t + n} ${i}`,
31
+ `A ${n} ${n} 0 1 1 ${t - n} ${i}`,
32
+ `A ${n} ${n} 0 1 1 ${t + n} ${i}`,
33
+ "Z"
34
+ ].join(" ");
35
+ const d = (m - 90) * Math.PI / 180, p = (M - 90) * Math.PI / 180, b = M - m > 180 ? 1 : 0, k = t + n * Math.cos(d), E = i + n * Math.sin(d), L = t + n * Math.cos(p), A = i + n * Math.sin(p);
36
+ if (e > 0) {
37
+ const H = t + e * Math.cos(p), U = i + e * Math.sin(p), C = t + e * Math.cos(d), Z = i + e * Math.sin(d);
38
+ return [
39
+ `M ${k} ${E}`,
40
+ `A ${n} ${n} 0 ${b} 1 ${L} ${A}`,
41
+ `L ${H} ${U}`,
42
+ `A ${e} ${e} 0 ${b} 0 ${C} ${Z}`,
43
+ "Z"
44
+ ].join(" ");
45
+ }
46
+ return [
47
+ `M ${t} ${i}`,
48
+ `L ${k} ${E}`,
49
+ `A ${n} ${n} 0 ${b} 1 ${L} ${A}`,
50
+ "Z"
51
+ ].join(" ");
52
+ }
53
+ function tt(t, i, n, e, m) {
54
+ const d = ((e + m) / 2 - 90) * Math.PI / 180;
55
+ return { x: t + n * Math.cos(d), y: i + n * Math.sin(d) };
56
+ }
57
+ function yt({
58
+ data: t,
59
+ valueKey: i,
60
+ nameKey: n,
61
+ colorKey: e,
62
+ colors: m = ft,
63
+ aspectRatio: M = 1,
64
+ height: d,
65
+ innerRadius: p = 0,
66
+ outerRadius: b = "90%",
67
+ strokeWidth: k = 2,
68
+ strokeColor: E = "var(--crk-color-bg)",
69
+ padAngle: L = 0,
70
+ showLabels: A = !1,
71
+ valuePosition: H = "outside",
72
+ showLabelLines: U = !0,
73
+ renderLabel: C,
74
+ centerLabel: Z,
75
+ activeIndex: W,
76
+ onSliceClick: V,
77
+ showLegend: nt = !0,
78
+ showTooltip: ot = !0,
79
+ valueFormat: _,
80
+ renderTooltip: X,
81
+ emptyMessage: it = "No data",
82
+ className: Y,
83
+ style: K,
84
+ classes: P
85
+ }) {
86
+ const [et, I] = lt(null), j = dt(null), u = W ?? et, B = (c) => {
87
+ if (e) {
88
+ const r = t[c]?.[e];
89
+ if (typeof r == "string") return r;
90
+ }
91
+ return m[c % m.length];
92
+ }, q = Q(() => {
93
+ let c = 0;
94
+ for (const r of t) {
95
+ const s = r[i];
96
+ typeof s == "number" && s > 0 && (c += s);
97
+ }
98
+ return c;
99
+ }, [t, i]);
100
+ if (t.length === 0 || q === 0)
101
+ return /* @__PURE__ */ a("div", { ref: j, className: D(f.root, P?.root, Y), style: K, children: /* @__PURE__ */ a("div", { className: f.canvas, style: { height: d ?? 240 }, children: /* @__PURE__ */ a("div", { className: f.empty, children: it }) }) });
102
+ const N = Q(() => {
103
+ const c = [];
104
+ let r = 0;
105
+ for (let s = 0; s < t.length; s++) {
106
+ const g = t[s], v = g[i], l = typeof v == "number" && v > 0 ? v : 0;
107
+ if (l === 0) continue;
108
+ const h = l / q, F = h * 360;
109
+ c.push({ index: s, row: g, value: l, start: r, end: r + F, fraction: h }), r += F;
110
+ }
111
+ return c;
112
+ }, [t, i, q]), ct = nt ? /* @__PURE__ */ a("div", { className: D(f.legend, P?.legend), role: "list", children: N.map((c) => /* @__PURE__ */ J("div", { className: D(f.legendItem, P?.legendItem), role: "listitem", children: [
113
+ /* @__PURE__ */ a(
114
+ "span",
115
+ {
116
+ className: f.legendSwatch,
117
+ style: { background: B(c.index) },
118
+ "aria-hidden": "true"
119
+ }
120
+ ),
121
+ /* @__PURE__ */ a("span", { className: f.legendLabel, children: String(c.row[n]) })
122
+ ] }, c.index)) }) : void 0, rt = Q(() => {
123
+ const c = {};
124
+ for (const r of N)
125
+ c[r.index.toString()] = {
126
+ label: String(r.row[n]),
127
+ color: B(r.index)
128
+ };
129
+ return c;
130
+ }, [N]);
131
+ return /* @__PURE__ */ a(
132
+ ht,
133
+ {
134
+ ref: j,
135
+ aspectRatio: M,
136
+ height: d,
137
+ className: Y,
138
+ style: K,
139
+ classes: P,
140
+ legend: ct,
141
+ overlay: ot && u !== null && t[u] ? /* @__PURE__ */ a(
142
+ $t,
143
+ {
144
+ row: { [u.toString()]: t[u][i] },
145
+ x: j.current ? j.current.getBoundingClientRect().width / 2 : 0,
146
+ y: 16,
147
+ containerWidth: j.current?.getBoundingClientRect().width ?? 0,
148
+ config: { [u.toString()]: rt[u.toString()] },
149
+ render: X ? () => X(t[u]) : void 0,
150
+ valueFormat: _,
151
+ titleKey: void 0,
152
+ classes: P
153
+ }
154
+ ) : null,
155
+ children: ({ width: c, height: r }) => {
156
+ const s = c / 2, g = r / 2, v = Math.min(c, r) / 2 - 4, l = O(b, v), h = Math.min(l - 1, O(p, v)), F = Math.max(4, l * 0.06);
157
+ return /* @__PURE__ */ J(at, { children: [
158
+ /* @__PURE__ */ a("g", { children: N.map((o) => {
159
+ const y = L / 2, w = Math.min(o.end, o.start + y), z = Math.max(o.start, o.end - y), G = B(o.index), $ = u === o.index, R = W !== void 0 && !$, x = $ && W !== void 0 ? l + F : l, T = mt(s, g, x, h, w, z), S = V ? () => V({ row: o.row, value: o.value, index: o.index }) : void 0;
160
+ return /* @__PURE__ */ a(
161
+ "path",
162
+ {
163
+ d: T,
164
+ fill: G,
165
+ stroke: k > 0 ? E : "none",
166
+ strokeWidth: k,
167
+ opacity: R ? 0.45 : 1,
168
+ onMouseEnter: () => I(o.index),
169
+ onMouseLeave: () => I(null),
170
+ onClick: S,
171
+ style: S ? { cursor: "pointer" } : void 0
172
+ },
173
+ o.index
174
+ );
175
+ }) }),
176
+ (A || C) && N.map((o) => {
177
+ const y = C ? C({ row: o.row, value: o.value, fraction: o.fraction, index: o.index }) : A ? `${String(o.row[n])} ${_ ? _(o.value) : Math.round(o.fraction * 100) + "%"}` : null;
178
+ if (y == null) return null;
179
+ const w = H === "inside", z = Math.max(16, l * 0.12), G = w ? (l + h) / 2 : l + z, $ = tt(s, g, G, o.start, o.end), R = w ? "middle" : $.x < s - 1 ? "end" : $.x > s + 1 ? "start" : "middle";
180
+ let x = null;
181
+ if (!w && U) {
182
+ const T = tt(s, g, l, o.start, o.end), S = 4, st = R === "end" ? S : R === "start" ? -S : 0;
183
+ x = { x1: T.x, y1: T.y, x2: $.x + st, y2: $.y };
184
+ }
185
+ return /* @__PURE__ */ J("g", { children: [
186
+ x && /* @__PURE__ */ a(
187
+ "line",
188
+ {
189
+ x1: x.x1,
190
+ y1: x.y1,
191
+ x2: x.x2,
192
+ y2: x.y2,
193
+ stroke: B(o.index),
194
+ strokeWidth: 1,
195
+ opacity: 0.7
196
+ }
197
+ ),
198
+ /* @__PURE__ */ a(
199
+ "text",
200
+ {
201
+ x: $.x,
202
+ y: $.y,
203
+ className: D(
204
+ f.axisLabel,
205
+ w && f.barLabelInside
206
+ ),
207
+ textAnchor: R,
208
+ dominantBaseline: "middle",
209
+ children: y
210
+ }
211
+ )
212
+ ] }, `label-${o.index}`);
213
+ }),
214
+ Z !== void 0 && /* @__PURE__ */ a(
215
+ "foreignObject",
216
+ {
217
+ x: s - h,
218
+ y: g - h,
219
+ width: Math.max(0, h * 2),
220
+ height: Math.max(0, h * 2),
221
+ style: { pointerEvents: "none" },
222
+ children: /* @__PURE__ */ a(
223
+ "div",
224
+ {
225
+ style: {
226
+ width: "100%",
227
+ height: "100%",
228
+ display: "flex",
229
+ flexDirection: "column",
230
+ alignItems: "center",
231
+ justifyContent: "center",
232
+ textAlign: "center",
233
+ color: "var(--crk-color-text)",
234
+ fontFamily: "var(--crk-font-family)"
235
+ },
236
+ children: Z
237
+ }
238
+ )
239
+ }
240
+ )
241
+ ] });
242
+ }
243
+ }
244
+ );
245
+ }
246
+ export {
247
+ yt as PieChart
248
+ };
@@ -0,0 +1,221 @@
1
+ import { jsx as o, jsxs as _, Fragment as F } from "react/jsx-runtime";
2
+ import { useState as nn, useRef as tn, useMemo as C } from "react";
3
+ import h from "clsx";
4
+ import { ChartContainer as en } from "./ChartContainer.js";
5
+ import { ChartLegend as rn } from "./ChartLegend.js";
6
+ import { ChartTooltip as on } from "./ChartTooltip.js";
7
+ import { extent as cn, niceTicks as ln } from "./scales.js";
8
+ import u from "./Chart.module.scss.js";
9
+ function R(e, f, m, M) {
10
+ const g = (M - 90) * Math.PI / 180;
11
+ return { x: e + m * Math.cos(g), y: f + m * Math.sin(g) };
12
+ }
13
+ function sn(e, f, m, M) {
14
+ return M.map((g) => {
15
+ const v = R(e, f, m, g);
16
+ return `${v.x},${v.y}`;
17
+ }).join(" ");
18
+ }
19
+ function yn({
20
+ data: e,
21
+ axisKey: f,
22
+ config: m,
23
+ aspectRatio: M = 1,
24
+ height: g,
25
+ gridType: v = "polygon",
26
+ showGrid: q = !0,
27
+ showRadialLines: z = !0,
28
+ showAxisLabels: A = !0,
29
+ showRadiusAxis: D = !1,
30
+ levels: I = 5,
31
+ showPoints: E = !0,
32
+ fillOpacity: G = 0.4,
33
+ strokeWidth: H = 2,
34
+ renderAxisLabel: S,
35
+ axisFormat: X,
36
+ valueFormat: j,
37
+ renderTooltip: Y,
38
+ showLegend: J = !0,
39
+ showTooltip: Q = !0,
40
+ emptyMessage: U = "No data",
41
+ className: K,
42
+ style: O,
43
+ classes: c
44
+ }) {
45
+ const [$, W] = nn(null), N = tn(null), P = C(() => Object.keys(m), [m]);
46
+ if (e.length === 0)
47
+ return /* @__PURE__ */ o("div", { ref: N, className: h(u.root, c?.root, K), style: O, children: /* @__PURE__ */ o("div", { className: u.canvas, style: { height: g ?? 240 }, children: /* @__PURE__ */ o("div", { className: u.empty, children: U }) }) });
48
+ const L = C(
49
+ () => e.map((d, p) => p / e.length * 360),
50
+ [e]
51
+ ), B = C(() => {
52
+ const d = [];
53
+ for (const T of P)
54
+ for (const i of e) {
55
+ const l = i[T];
56
+ typeof l == "number" && d.push(l);
57
+ }
58
+ const [, p] = cn(d);
59
+ return Math.max(1, p);
60
+ }, [e, P]), b = C(() => ln(0, B, I).filter((p) => p > 0), [B, I]), V = b[b.length - 1] ?? B;
61
+ return /* @__PURE__ */ o(
62
+ en,
63
+ {
64
+ ref: N,
65
+ aspectRatio: M,
66
+ height: g,
67
+ className: K,
68
+ style: O,
69
+ classes: c,
70
+ legend: J ? /* @__PURE__ */ o(rn, { config: m, classes: c }) : void 0,
71
+ overlay: Q && $ !== null ? /* @__PURE__ */ o(
72
+ on,
73
+ {
74
+ row: e[$],
75
+ x: (N.current?.getBoundingClientRect().width ?? 0) / 2,
76
+ y: 16,
77
+ containerWidth: N.current?.getBoundingClientRect().width ?? 0,
78
+ config: m,
79
+ render: Y ? () => Y(e[$]) : void 0,
80
+ valueFormat: j,
81
+ titleKey: f,
82
+ classes: c
83
+ }
84
+ ) : null,
85
+ children: ({ width: d, height: p }) => {
86
+ const T = A ? 32 : 8, i = d / 2, l = p / 2, w = Math.max(0, Math.min(d, p) / 2 - T), k = (n) => Math.max(0, n) / V * w;
87
+ return /* @__PURE__ */ _(F, { children: [
88
+ q && b.map((n) => {
89
+ const t = k(n);
90
+ return v === "circle" ? /* @__PURE__ */ o(
91
+ "circle",
92
+ {
93
+ className: h(u.gridLine, c?.grid),
94
+ cx: i,
95
+ cy: l,
96
+ r: t,
97
+ fill: "none"
98
+ },
99
+ `ring-${n}`
100
+ ) : /* @__PURE__ */ o(
101
+ "polygon",
102
+ {
103
+ className: h(u.gridLine, c?.grid),
104
+ points: sn(i, l, t, L),
105
+ fill: "none"
106
+ },
107
+ `ring-${n}`
108
+ );
109
+ }),
110
+ z && L.map((n, t) => {
111
+ const s = R(i, l, w, n);
112
+ return /* @__PURE__ */ o(
113
+ "line",
114
+ {
115
+ className: h(u.gridLine, c?.grid),
116
+ x1: i,
117
+ y1: l,
118
+ x2: s.x,
119
+ y2: s.y
120
+ },
121
+ `spoke-${t}`
122
+ );
123
+ }),
124
+ D && b.map((n) => {
125
+ const t = k(n);
126
+ return /* @__PURE__ */ o(
127
+ "text",
128
+ {
129
+ className: h(u.axisLabel, c?.axisLabel),
130
+ x: i + 4,
131
+ y: l - t,
132
+ textAnchor: "start",
133
+ dominantBaseline: "middle",
134
+ children: j ? j(n) : n
135
+ },
136
+ `raxis-${n}`
137
+ );
138
+ }),
139
+ A && e.map((n, t) => {
140
+ const s = L[t], a = R(i, l, w + 14, s), r = a.x < i - 1 ? "end" : a.x > i + 1 ? "start" : "middle";
141
+ if (S)
142
+ return /* @__PURE__ */ o("g", { children: S({
143
+ row: n,
144
+ index: t,
145
+ angle: s,
146
+ x: a.x,
147
+ y: a.y,
148
+ textAnchor: r
149
+ }) }, `label-${t}`);
150
+ const x = String(n[f]), y = X ? X(x) : x;
151
+ return /* @__PURE__ */ o(
152
+ "text",
153
+ {
154
+ className: h(u.axisLabel, c?.axisLabel),
155
+ x: a.x,
156
+ y: a.y,
157
+ textAnchor: r,
158
+ dominantBaseline: "middle",
159
+ children: y
160
+ },
161
+ `label-${t}`
162
+ );
163
+ }),
164
+ P.map((n) => {
165
+ const t = m[n], s = e.map((r, x) => {
166
+ const y = r[n], Z = k(typeof y == "number" ? y : 0);
167
+ return R(i, l, Z, L[x]);
168
+ }), a = s.map((r) => `${r.x},${r.y}`).join(" ");
169
+ return /* @__PURE__ */ _("g", { className: h(u.series, c?.series), children: [
170
+ /* @__PURE__ */ o(
171
+ "polygon",
172
+ {
173
+ points: a,
174
+ fill: t.color,
175
+ fillOpacity: G,
176
+ stroke: t.color,
177
+ strokeWidth: H,
178
+ strokeLinejoin: "round",
179
+ strokeLinecap: "round"
180
+ }
181
+ ),
182
+ E && s.map((r, x) => /* @__PURE__ */ o(
183
+ "circle",
184
+ {
185
+ className: h(u.point, c?.point),
186
+ cx: r.x,
187
+ cy: r.y,
188
+ r: $ === x ? 5 : 3.5,
189
+ fill: t.color
190
+ },
191
+ `${n}-${x}`
192
+ ))
193
+ ] }, n);
194
+ }),
195
+ /* @__PURE__ */ o(
196
+ "rect",
197
+ {
198
+ className: u.interactionLayer,
199
+ x: 0,
200
+ y: 0,
201
+ width: d,
202
+ height: p,
203
+ onMouseMove: (n) => {
204
+ const t = n.currentTarget.getBoundingClientRect(), s = n.clientX - t.left - i, a = n.clientY - t.top - l;
205
+ if (s === 0 && a === 0) return;
206
+ let r = Math.atan2(a, s) * 180 / Math.PI + 90;
207
+ r < 0 && (r += 360), r >= 360 && (r -= 360);
208
+ const x = 360 / e.length, y = Math.round(r / x) % e.length;
209
+ W(y);
210
+ },
211
+ onMouseLeave: () => W(null)
212
+ }
213
+ )
214
+ ] });
215
+ }
216
+ }
217
+ );
218
+ }
219
+ export {
220
+ yn as RadarChart
221
+ };