bruv-ui 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/area-chart.d.ts +84 -0
  2. package/dist/area-chart.js +2002 -0
  3. package/dist/area-chart.js.map +1 -0
  4. package/dist/bar-chart.d.ts +80 -0
  5. package/dist/bar-chart.js +2251 -0
  6. package/dist/bar-chart.js.map +1 -0
  7. package/dist/chart-background-BK77UXhl.d.ts +9 -0
  8. package/dist/chart-brush-BoxY9aDm.d.ts +72 -0
  9. package/dist/chart-dot-8H287EDv.d.ts +17 -0
  10. package/dist/chart-legend-Dv9pqes-.d.ts +16 -0
  11. package/dist/chart-tooltip-DajpzJRy.d.ts +68 -0
  12. package/dist/charts.d.ts +17 -0
  13. package/dist/charts.js +5097 -0
  14. package/dist/charts.js.map +1 -0
  15. package/dist/composed-chart.d.ts +93 -0
  16. package/dist/composed-chart.js +2338 -0
  17. package/dist/composed-chart.js.map +1 -0
  18. package/dist/form-dK_DJRTw.d.ts +43 -0
  19. package/dist/form-rhf.d.ts +26 -0
  20. package/dist/form-rhf.js +268 -0
  21. package/dist/form-rhf.js.map +1 -0
  22. package/dist/index.d.ts +2881 -0
  23. package/dist/index.js +9368 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/line-chart.d.ts +81 -0
  26. package/dist/line-chart.js +1879 -0
  27. package/dist/line-chart.js.map +1 -0
  28. package/dist/pie-chart.d.ts +64 -0
  29. package/dist/pie-chart.js +1094 -0
  30. package/dist/pie-chart.js.map +1 -0
  31. package/dist/radar-chart.d.ts +67 -0
  32. package/dist/radar-chart.js +1318 -0
  33. package/dist/radar-chart.js.map +1 -0
  34. package/dist/radial-chart.d.ts +56 -0
  35. package/dist/radial-chart.js +1051 -0
  36. package/dist/radial-chart.js.map +1 -0
  37. package/dist/sankey-chart.d.ts +58 -0
  38. package/dist/sankey-chart.js +1179 -0
  39. package/dist/sankey-chart.js.map +1 -0
  40. package/package.json +135 -0
  41. package/src/scales.css +288 -0
  42. package/src/shiki.css +37 -0
  43. package/src/styles.css +23 -0
  44. package/src/theme.css +659 -0
@@ -0,0 +1,1051 @@
1
+ // src/components/charts/chart.tsx
2
+ import * as RechartsPrimitive from "recharts";
3
+
4
+ // src/lib/cn.ts
5
+ import { clsx } from "clsx";
6
+ import { extendTailwindMerge } from "tailwind-merge";
7
+ var twMerge = extendTailwindMerge({
8
+ extend: {
9
+ classGroups: {
10
+ "font-size": [{ "text-cui": ["sm", "base", "lg", "xl"] }],
11
+ "text-color": [
12
+ {
13
+ "text-cui": [
14
+ "primary",
15
+ "secondary",
16
+ "tertiary",
17
+ "inverse",
18
+ "accent",
19
+ "accent-on",
20
+ "danger",
21
+ "danger-on",
22
+ "warn",
23
+ "warn-on",
24
+ "success",
25
+ "success-on"
26
+ ]
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ });
32
+ function cn(...inputs) {
33
+ return twMerge(clsx(inputs));
34
+ }
35
+
36
+ // src/components/charts/chart.tsx
37
+ import {
38
+ forwardRef,
39
+ useId,
40
+ createContext,
41
+ useContext
42
+ } from "react";
43
+ import { jsx, jsxs } from "react/jsx-runtime";
44
+ var THEMES = { light: "", dark: '[data-theme="dark"]' };
45
+ var VALID_THEME_KEYS = Object.keys(THEMES);
46
+ var DEFAULT_PALETTE = [
47
+ "var(--color-bruv-chart-1)",
48
+ "var(--color-bruv-chart-2)",
49
+ "var(--color-bruv-chart-3)",
50
+ "var(--color-bruv-chart-4)",
51
+ "var(--color-bruv-chart-5)",
52
+ "var(--color-bruv-chart-6)"
53
+ ];
54
+ var ChartContext = createContext(null);
55
+ function useChart() {
56
+ const context = useContext(ChartContext);
57
+ if (!context) {
58
+ throw new Error("useChart must be used within a <Chart />");
59
+ }
60
+ return context;
61
+ }
62
+ function validateChartConfigColors(config) {
63
+ for (const [key, value] of Object.entries(config)) {
64
+ if (value.colors) {
65
+ const hasValidThemeKey = VALID_THEME_KEYS.some(
66
+ (themeKey) => value.colors?.[themeKey] !== void 0
67
+ );
68
+ if (!hasValidThemeKey) {
69
+ throw new Error(
70
+ `[BruvCharts] Invalid chart config for "${key}": colors object must have at least one theme key (${VALID_THEME_KEYS.join(", ")}).`
71
+ );
72
+ }
73
+ }
74
+ }
75
+ }
76
+ function applyDefaultChartColors(config) {
77
+ const entries = Object.entries(config);
78
+ return Object.fromEntries(
79
+ entries.map(([key, item], index) => {
80
+ if (item.colors || item.color) {
81
+ if (item.color && !item.colors) {
82
+ return [
83
+ key,
84
+ {
85
+ ...item,
86
+ colors: {
87
+ light: [item.color],
88
+ dark: [item.color]
89
+ }
90
+ }
91
+ ];
92
+ }
93
+ return [key, item];
94
+ }
95
+ const paletteColor = DEFAULT_PALETTE[index % DEFAULT_PALETTE.length] ?? DEFAULT_PALETTE[0];
96
+ return [
97
+ key,
98
+ {
99
+ ...item,
100
+ colors: {
101
+ light: [paletteColor],
102
+ dark: [paletteColor]
103
+ }
104
+ }
105
+ ];
106
+ })
107
+ );
108
+ }
109
+ var Chart = forwardRef(function Chart2({
110
+ id,
111
+ config,
112
+ initialDimension = { width: 320, height: 200 },
113
+ className,
114
+ children,
115
+ footer,
116
+ ...props
117
+ }, ref) {
118
+ const uniqueId = useId();
119
+ const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
120
+ const resolvedConfig = applyDefaultChartColors(config);
121
+ validateChartConfigColors(resolvedConfig);
122
+ return /* @__PURE__ */ jsx(ChartContext.Provider, { value: { config: resolvedConfig }, children: /* @__PURE__ */ jsxs(
123
+ "div",
124
+ {
125
+ ref,
126
+ "data-slot": "chart",
127
+ "data-chart": chartId,
128
+ className: cn(
129
+ "bruv-chart relative flex min-h-0 w-full flex-1 flex-col justify-center text-bruv-sm text-bruv-secondary",
130
+ "[&_.recharts-cartesian-axis-tick_text]:fill-bruv-chart-axis [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-bruv-chart-grid/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-bruv-chart-cursor [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-bruv-chart-grid [&_.recharts-radial-bar-background-sector]:fill-bruv-subtle [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-bruv-subtle [&_.recharts-reference-line_[stroke='#ccc']]:stroke-bruv-chart-grid [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
131
+ !footer && "aspect-video",
132
+ className
133
+ ),
134
+ ...props,
135
+ children: [
136
+ /* @__PURE__ */ jsx(ChartStyle, { id: chartId, config: resolvedConfig }),
137
+ /* @__PURE__ */ jsx(
138
+ RechartsPrimitive.ResponsiveContainer,
139
+ {
140
+ className: "min-h-0 w-full flex-1",
141
+ initialDimension,
142
+ children
143
+ }
144
+ ),
145
+ footer
146
+ ]
147
+ }
148
+ ) });
149
+ });
150
+ function LoadingIndicator({ isLoading }) {
151
+ if (!isLoading) return null;
152
+ return /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 z-20 flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "border-bruv-neutral bg-bruv-base-2 text-bruv-sm text-bruv-primary rounded-bruv-md flex items-center justify-center gap-2 border px-2 py-0.5", children: [
153
+ /* @__PURE__ */ jsx("div", { className: "border-bruv-neutral border-t-bruv-accent size-3 animate-spin rounded-full border" }),
154
+ /* @__PURE__ */ jsx("span", { children: "Loading" })
155
+ ] }) });
156
+ }
157
+ function distributeColors(colorsArray, maxCount) {
158
+ const availableCount = colorsArray.length;
159
+ if (availableCount >= maxCount) {
160
+ return colorsArray.slice(0, maxCount);
161
+ }
162
+ const result = [];
163
+ const baseSlots = Math.floor(maxCount / availableCount);
164
+ const extraSlots = maxCount % availableCount;
165
+ for (let colorIdx = 0; colorIdx < availableCount; colorIdx++) {
166
+ const isExtraColor = colorIdx >= availableCount - extraSlots;
167
+ const slotsForThisColor = baseSlots + (isExtraColor ? 1 : 0);
168
+ for (let j = 0; j < slotsForThisColor; j++) {
169
+ const color = colorsArray[colorIdx];
170
+ if (color) result.push(color);
171
+ }
172
+ }
173
+ return result;
174
+ }
175
+ function ChartStyle({
176
+ id,
177
+ config
178
+ }) {
179
+ const colorConfig = Object.entries(config).filter(([, item]) => item.colors);
180
+ if (!colorConfig.length) return null;
181
+ const generateCssVars = (theme) => colorConfig.flatMap(([key, itemConfig]) => {
182
+ const colorsArray = itemConfig.colors?.[theme];
183
+ if (!colorsArray?.length) return [];
184
+ const maxCount = getColorsCount(itemConfig);
185
+ const distributedColors = distributeColors(colorsArray, maxCount);
186
+ return distributedColors.map(
187
+ (color, index) => ` --color-${key}-${index}: ${color};`
188
+ );
189
+ }).filter(Boolean).join("\n");
190
+ const css = Object.entries(THEMES).map(
191
+ ([theme, prefix]) => `${prefix} [data-chart=${id}] {
192
+ ${generateCssVars(theme)}
193
+ }`
194
+ ).join("\n");
195
+ return /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: css } });
196
+ }
197
+ function getPayloadConfigFromPayload(config, payload, key) {
198
+ if (typeof payload !== "object" || payload === null) return void 0;
199
+ const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null ? payload.payload : void 0;
200
+ let configLabelKey = key;
201
+ if (key in payload && typeof payload[key] === "string") {
202
+ configLabelKey = payload[key];
203
+ } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key] === "string") {
204
+ configLabelKey = payloadPayload[key];
205
+ }
206
+ return configLabelKey in config ? config[configLabelKey] : config[key];
207
+ }
208
+ function getColorsCount(config) {
209
+ if (!config.colors) return 1;
210
+ const counts = VALID_THEME_KEYS.map(
211
+ (theme) => config.colors?.[theme]?.length ?? 0
212
+ );
213
+ return Math.max(...counts, 1);
214
+ }
215
+
216
+ // src/components/charts/chart-tooltip.tsx
217
+ import * as RechartsPrimitive2 from "recharts";
218
+ import * as React from "react";
219
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
220
+ var roundnessMap = {
221
+ sm: "rounded-bruv-sm",
222
+ md: "rounded-bruv-md",
223
+ lg: "rounded-bruv-lg",
224
+ xl: "rounded-bruv-xl"
225
+ };
226
+ var variantMap = {
227
+ default: "bg-bruv-base-2",
228
+ "frosted-glass": "bg-bruv-base-2/70 backdrop-blur-sm"
229
+ };
230
+ function ChartTooltipContent({
231
+ active,
232
+ payload,
233
+ className,
234
+ indicator = "dot",
235
+ hideLabel = false,
236
+ hideIndicator = false,
237
+ label,
238
+ labelFormatter,
239
+ labelClassName,
240
+ formatter,
241
+ nameKey,
242
+ labelKey,
243
+ selected,
244
+ roundness = "lg",
245
+ variant = "default"
246
+ }) {
247
+ const { config } = useChart();
248
+ const tooltipLabel = React.useMemo(() => {
249
+ if (hideLabel || !payload?.length) {
250
+ return null;
251
+ }
252
+ const [item] = payload;
253
+ const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
254
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
255
+ const value = !labelKey && typeof label === "string" ? config[label]?.label ?? label : itemConfig?.label;
256
+ if (labelFormatter) {
257
+ return /* @__PURE__ */ jsx2("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
258
+ }
259
+ if (!value) {
260
+ return null;
261
+ }
262
+ return /* @__PURE__ */ jsx2("div", { className: cn("font-medium", labelClassName), children: value });
263
+ }, [
264
+ label,
265
+ labelFormatter,
266
+ payload,
267
+ hideLabel,
268
+ labelClassName,
269
+ config,
270
+ labelKey
271
+ ]);
272
+ if (!active || !payload?.length) {
273
+ return /* @__PURE__ */ jsx2("span", { className: "p-4" });
274
+ }
275
+ const nestLabel = payload.length === 1 && indicator !== "dot";
276
+ return /* @__PURE__ */ jsxs2(
277
+ "div",
278
+ {
279
+ className: cn(
280
+ "border-bruv-neutral/50 grid min-w-32 items-start gap-1.5 border px-2.5 py-1.5 text-xs shadow-xl",
281
+ roundnessMap[roundness],
282
+ variantMap[variant],
283
+ className
284
+ ),
285
+ children: [
286
+ !nestLabel ? tooltipLabel : null,
287
+ /* @__PURE__ */ jsx2("div", { className: "grid gap-1.5", children: payload.filter((item) => item.type !== "none").map((item, index) => {
288
+ const payloadName = nameKey && item.payload ? item.payload[nameKey] : void 0;
289
+ const key = `${payloadName ?? item.name ?? item.dataKey ?? "value"}`;
290
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
291
+ const colorsCount = itemConfig ? getColorsCount(itemConfig) : 1;
292
+ return /* @__PURE__ */ jsx2(
293
+ "div",
294
+ {
295
+ className: cn(
296
+ "[&>svg]:text-bruv-secondary flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
297
+ indicator === "dot" && "items-center",
298
+ selected != null && selected !== item.dataKey && "opacity-30"
299
+ ),
300
+ children: formatter && item?.value !== void 0 && item.name ? formatter(item.value, item.name, item, index, item.payload) : /* @__PURE__ */ jsxs2(Fragment, { children: [
301
+ itemConfig?.icon ? /* @__PURE__ */ jsx2(itemConfig.icon, {}) : !hideIndicator && /* @__PURE__ */ jsx2(
302
+ "div",
303
+ {
304
+ className: cn("shrink-0 rounded-[2px]", {
305
+ "h-2.5 w-2.5": indicator === "dot",
306
+ "w-1": indicator === "line",
307
+ "w-0 border-[1.5px] border-dashed bg-transparent!": indicator === "dashed",
308
+ "my-0.5": nestLabel && indicator === "dashed"
309
+ }),
310
+ style: getIndicatorColorStyle(key, colorsCount)
311
+ }
312
+ ),
313
+ /* @__PURE__ */ jsxs2(
314
+ "div",
315
+ {
316
+ className: cn(
317
+ "flex flex-1 justify-between gap-4 leading-none",
318
+ nestLabel ? "items-end" : "items-center"
319
+ ),
320
+ children: [
321
+ /* @__PURE__ */ jsxs2("div", { className: "grid gap-1.5", children: [
322
+ nestLabel ? tooltipLabel : null,
323
+ /* @__PURE__ */ jsx2("span", { className: "text-bruv-secondary", children: itemConfig?.label ?? item.name })
324
+ ] }),
325
+ item.value != null && /* @__PURE__ */ jsx2("span", { className: "text-bruv-primary font-mono font-medium tabular-nums", children: typeof item.value === "number" ? item.value.toLocaleString() : String(item.value) })
326
+ ]
327
+ }
328
+ )
329
+ ] })
330
+ },
331
+ index
332
+ );
333
+ }) })
334
+ ]
335
+ }
336
+ );
337
+ }
338
+ function getIndicatorColorStyle(dataKey, colorsCount) {
339
+ if (colorsCount <= 1) {
340
+ return { background: `var(--color-${dataKey}-0)` };
341
+ }
342
+ const stops = Array.from({ length: colorsCount }, (_, index) => {
343
+ const offset = index / (colorsCount - 1) * 100;
344
+ return `var(--color-${dataKey}-${index}) ${offset}%`;
345
+ }).join(", ");
346
+ return { background: `linear-gradient(to right, ${stops})` };
347
+ }
348
+ var ChartTooltip = ({
349
+ animationDuration = 200,
350
+ ...props
351
+ }) => /* @__PURE__ */ jsx2(RechartsPrimitive2.Tooltip, { animationDuration, ...props });
352
+
353
+ // src/components/charts/chart-legend.tsx
354
+ import * as RechartsPrimitive3 from "recharts";
355
+ import "react";
356
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
357
+ function ChartLegendContent({
358
+ className,
359
+ hideIcon = false,
360
+ nameKey,
361
+ payload,
362
+ verticalAlign,
363
+ align = "right",
364
+ selected,
365
+ onSelectChange,
366
+ isClickable,
367
+ variant = "rounded-square"
368
+ }) {
369
+ const { config } = useChart();
370
+ if (!payload?.length) {
371
+ return null;
372
+ }
373
+ return /* @__PURE__ */ jsx3(
374
+ "div",
375
+ {
376
+ className: cn(
377
+ "flex items-center gap-4 select-none",
378
+ align === "left" && "justify-start",
379
+ align === "center" && "justify-center",
380
+ align === "right" && "justify-end",
381
+ verticalAlign === "top" ? "pb-4" : "pt-4",
382
+ className
383
+ ),
384
+ children: payload.filter((item) => item.type !== "none").map((item) => {
385
+ const payloadName = nameKey && item.payload ? item.payload[nameKey] : void 0;
386
+ const key = `${payloadName ?? item.value ?? item.dataKey ?? "value"}`;
387
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
388
+ const isSelected = selected === null || selected === key;
389
+ const colorsCount = itemConfig ? getColorsCount(itemConfig) : 1;
390
+ return /* @__PURE__ */ jsxs3(
391
+ "div",
392
+ {
393
+ className: cn(
394
+ "[&>svg]:text-bruv-secondary flex items-center gap-1.5 transition-opacity [&>svg]:h-3 [&>svg]:w-3",
395
+ !isSelected && "opacity-30",
396
+ isClickable && "cursor-pointer"
397
+ ),
398
+ onClick: () => {
399
+ if (!isClickable) return;
400
+ onSelectChange?.(selected === key ? null : key);
401
+ },
402
+ children: [
403
+ itemConfig?.icon && !hideIcon ? /* @__PURE__ */ jsx3(itemConfig.icon, {}) : /* @__PURE__ */ jsx3(
404
+ LegendIndicator,
405
+ {
406
+ variant,
407
+ dataKey: key,
408
+ colorsCount
409
+ }
410
+ ),
411
+ itemConfig?.label
412
+ ]
413
+ },
414
+ key
415
+ );
416
+ })
417
+ }
418
+ );
419
+ }
420
+ function LegendIndicator({
421
+ variant,
422
+ dataKey,
423
+ colorsCount
424
+ }) {
425
+ const fillStyle = getLegendFillStyle(dataKey, colorsCount);
426
+ const outlineStyle = getLegendOutlineStyle(dataKey, colorsCount);
427
+ switch (variant) {
428
+ case "square":
429
+ return /* @__PURE__ */ jsx3("div", { className: "h-2 w-2 shrink-0", style: fillStyle });
430
+ case "circle":
431
+ return /* @__PURE__ */ jsx3("div", { className: "h-2 w-2 shrink-0 rounded-full", style: fillStyle });
432
+ case "circle-outline":
433
+ return /* @__PURE__ */ jsx3(
434
+ "div",
435
+ {
436
+ className: "h-2.5 w-2.5 shrink-0 rounded-full p-[1.5px]",
437
+ style: outlineStyle
438
+ }
439
+ );
440
+ case "vertical-bar":
441
+ return /* @__PURE__ */ jsx3("div", { className: "h-3 w-1 shrink-0 rounded-[2px]", style: fillStyle });
442
+ case "horizontal-bar":
443
+ return /* @__PURE__ */ jsx3("div", { className: "h-1 w-3 shrink-0 rounded-[2px]", style: fillStyle });
444
+ case "rounded-square-outline":
445
+ return /* @__PURE__ */ jsx3(
446
+ "div",
447
+ {
448
+ className: "h-2.5 w-2.5 shrink-0 rounded-[3px] p-[1.5px]",
449
+ style: outlineStyle
450
+ }
451
+ );
452
+ case "rounded-square":
453
+ default:
454
+ return /* @__PURE__ */ jsx3("div", { className: "h-2 w-2 shrink-0 rounded-[2px]", style: fillStyle });
455
+ }
456
+ }
457
+ function getLegendFillStyle(dataKey, colorsCount) {
458
+ if (colorsCount <= 1) {
459
+ return { backgroundColor: `var(--color-${dataKey}-0)` };
460
+ }
461
+ const stops = Array.from({ length: colorsCount }, (_, i) => {
462
+ const offset = i / (colorsCount - 1) * 100;
463
+ return `var(--color-${dataKey}-${i}) ${offset}%`;
464
+ }).join(", ");
465
+ return { background: `linear-gradient(to right, ${stops})` };
466
+ }
467
+ function getLegendOutlineStyle(dataKey, colorsCount) {
468
+ const maskStyle = {
469
+ WebkitMask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
470
+ WebkitMaskComposite: "xor",
471
+ mask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
472
+ maskComposite: "exclude"
473
+ };
474
+ if (colorsCount <= 1) {
475
+ return {
476
+ backgroundColor: `var(--color-${dataKey}-0)`,
477
+ ...maskStyle
478
+ };
479
+ }
480
+ const stops = Array.from({ length: colorsCount }, (_, i) => {
481
+ const offset = i / (colorsCount - 1) * 100;
482
+ return `var(--color-${dataKey}-${i}) ${offset}%`;
483
+ }).join(", ");
484
+ return {
485
+ background: `linear-gradient(to right, ${stops})`,
486
+ ...maskStyle
487
+ };
488
+ }
489
+ var ChartLegend = RechartsPrimitive3.Legend;
490
+
491
+ // src/components/charts/chart-background.tsx
492
+ import { ZIndexLayer } from "recharts";
493
+ import { useId as useId2 } from "react";
494
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
495
+ var DotsPattern = ({ id }) => /* @__PURE__ */ jsx4(
496
+ "pattern",
497
+ {
498
+ id,
499
+ x: "0",
500
+ y: "0",
501
+ width: "20",
502
+ height: "20",
503
+ patternUnits: "userSpaceOnUse",
504
+ children: /* @__PURE__ */ jsx4(
505
+ "circle",
506
+ {
507
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
508
+ cx: "2",
509
+ cy: "2",
510
+ r: "1",
511
+ fill: "currentColor"
512
+ }
513
+ )
514
+ }
515
+ );
516
+ var GridPattern = ({ id }) => /* @__PURE__ */ jsx4(
517
+ "pattern",
518
+ {
519
+ id,
520
+ x: "0",
521
+ y: "0",
522
+ width: "20",
523
+ height: "20",
524
+ patternUnits: "userSpaceOnUse",
525
+ children: /* @__PURE__ */ jsx4(
526
+ "path",
527
+ {
528
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
529
+ d: "M 20 0 L 0 0 0 20",
530
+ fill: "none",
531
+ stroke: "currentColor",
532
+ strokeWidth: "0.5"
533
+ }
534
+ )
535
+ }
536
+ );
537
+ var CrossHatchPattern = ({ id }) => /* @__PURE__ */ jsx4(
538
+ "pattern",
539
+ {
540
+ id,
541
+ x: "0",
542
+ y: "0",
543
+ width: "20",
544
+ height: "20",
545
+ patternUnits: "userSpaceOnUse",
546
+ children: /* @__PURE__ */ jsx4(
547
+ "path",
548
+ {
549
+ className: "text-bruv-chart-grid/60 text-bruv-chart-grid/50",
550
+ d: "M 0 0 L 20 20 M 20 0 L 0 20",
551
+ fill: "none",
552
+ stroke: "currentColor",
553
+ strokeWidth: "0.5"
554
+ }
555
+ )
556
+ }
557
+ );
558
+ var DiagonalLinesPattern = ({ id }) => /* @__PURE__ */ jsx4(
559
+ "pattern",
560
+ {
561
+ id,
562
+ x: "0",
563
+ y: "0",
564
+ width: "6",
565
+ height: "6",
566
+ patternUnits: "userSpaceOnUse",
567
+ patternTransform: "rotate(45)",
568
+ children: /* @__PURE__ */ jsx4(
569
+ "line",
570
+ {
571
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
572
+ x1: "0",
573
+ y1: "0",
574
+ x2: "0",
575
+ y2: "6",
576
+ stroke: "currentColor",
577
+ strokeWidth: "0.5"
578
+ }
579
+ )
580
+ }
581
+ );
582
+ var PlusPattern = ({ id }) => /* @__PURE__ */ jsx4(
583
+ "pattern",
584
+ {
585
+ id,
586
+ x: "0",
587
+ y: "0",
588
+ width: "16",
589
+ height: "16",
590
+ patternUnits: "userSpaceOnUse",
591
+ children: /* @__PURE__ */ jsx4(
592
+ "path",
593
+ {
594
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
595
+ d: "M 8 4 L 8 12 M 4 8 L 12 8",
596
+ fill: "none",
597
+ stroke: "currentColor",
598
+ strokeWidth: "0.5",
599
+ strokeLinecap: "round"
600
+ }
601
+ )
602
+ }
603
+ );
604
+ var FallingTrianglesPattern = ({ id }) => /* @__PURE__ */ jsx4(
605
+ "pattern",
606
+ {
607
+ id,
608
+ x: "0",
609
+ y: "0",
610
+ width: "18",
611
+ height: "36",
612
+ patternUnits: "userSpaceOnUse",
613
+ children: /* @__PURE__ */ jsx4(
614
+ "path",
615
+ {
616
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
617
+ d: "M2 6h12L8 18 2 6zm18 36h12l-6 12-6-12z",
618
+ transform: "scale(0.5)",
619
+ fill: "currentColor",
620
+ fillOpacity: "0.4"
621
+ }
622
+ )
623
+ }
624
+ );
625
+ var FourPointedStarPattern = ({ id }) => /* @__PURE__ */ jsx4(
626
+ "pattern",
627
+ {
628
+ id,
629
+ x: "0",
630
+ y: "0",
631
+ width: "16",
632
+ height: "16",
633
+ patternUnits: "userSpaceOnUse",
634
+ children: /* @__PURE__ */ jsx4(
635
+ "polygon",
636
+ {
637
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
638
+ fillRule: "evenodd",
639
+ points: "5 3 8 4 5 5 4 8 3 5 0 4 3 3 4 0 5 3",
640
+ fill: "currentColor",
641
+ fillOpacity: "0.4"
642
+ }
643
+ )
644
+ }
645
+ );
646
+ var TinyCheckersPattern = ({ id }) => /* @__PURE__ */ jsx4(
647
+ "pattern",
648
+ {
649
+ id,
650
+ x: "0",
651
+ y: "0",
652
+ width: "8",
653
+ height: "8",
654
+ patternUnits: "userSpaceOnUse",
655
+ children: /* @__PURE__ */ jsx4(
656
+ "path",
657
+ {
658
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
659
+ fillRule: "evenodd",
660
+ d: "M0 0h4v4H0V0zm4 4h4v4H4V4z",
661
+ fill: "currentColor",
662
+ fillOpacity: "0.2"
663
+ }
664
+ )
665
+ }
666
+ );
667
+ var OverlappingCirclesPattern = ({ id }) => /* @__PURE__ */ jsx4(
668
+ "pattern",
669
+ {
670
+ id,
671
+ x: "0",
672
+ y: "0",
673
+ width: "40",
674
+ height: "40",
675
+ patternUnits: "userSpaceOnUse",
676
+ children: /* @__PURE__ */ jsx4(
677
+ "path",
678
+ {
679
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
680
+ fillRule: "evenodd",
681
+ d: "M25 25c0-2.762 2.238-5 5-5s5 2.238 5 5-2.238 5-5 5c0 2.762-2.238 5-5 5s-5-2.238-5-5 2.238-5 5-5zM5 5c0-2.762 2.238-5 5-5s5 2.238 5 5-2.238 5-5 5c0 2.762-2.238 5-5 5S0 12.762 0 10s2.238-5 5-5zm5 4c2.209 0 4-1.791 4-4s-1.791-4-4-4-4 1.791-4 4 1.791 4 4 4zm20 20c2.209 0 4-1.791 4-4s-1.791-4-4-4-4 1.791-4 4 1.791 4 4 4z",
682
+ fill: "currentColor",
683
+ fillOpacity: "0.4"
684
+ }
685
+ )
686
+ }
687
+ );
688
+ var WiggleLinesPattern = ({ id }) => /* @__PURE__ */ jsx4(
689
+ "pattern",
690
+ {
691
+ id,
692
+ x: "0",
693
+ y: "0",
694
+ width: "52",
695
+ height: "26",
696
+ patternUnits: "userSpaceOnUse",
697
+ patternTransform: "scale(0.6)",
698
+ children: /* @__PURE__ */ jsx4(
699
+ "path",
700
+ {
701
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
702
+ d: "M10 10c0-2.21-1.79-4-4-4-3.314 0-6-2.686-6-6h2c0 2.21 1.79 4 4 4 3.314 0 6 2.686 6 6 0 2.21 1.79 4 4 4 3.314 0 6 2.686 6 6 0 2.21 1.79 4 4 4v2c-3.314 0-6-2.686-6-6 0-2.21-1.79-4-4-4-3.314 0-6-2.686-6-6zm25.464-1.95l8.486 8.486-1.414 1.414-8.486-8.486 1.414-1.414z",
703
+ fill: "currentColor",
704
+ fillOpacity: "0.4"
705
+ }
706
+ )
707
+ }
708
+ );
709
+ var BubblesPattern = ({ id }) => /* @__PURE__ */ jsx4(
710
+ "pattern",
711
+ {
712
+ id,
713
+ x: "0",
714
+ y: "0",
715
+ width: "100",
716
+ height: "100",
717
+ patternUnits: "userSpaceOnUse",
718
+ patternTransform: "scale(0.6667)",
719
+ children: /* @__PURE__ */ jsx4(
720
+ "path",
721
+ {
722
+ className: "text-bruv-chart-grid text-bruv-chart-grid",
723
+ d: "M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z",
724
+ fill: "currentColor",
725
+ fillOpacity: "0.4",
726
+ fillRule: "evenodd"
727
+ }
728
+ )
729
+ }
730
+ );
731
+ var PATTERN_MAP = {
732
+ dots: DotsPattern,
733
+ grid: GridPattern,
734
+ plus: PlusPattern,
735
+ bubbles: BubblesPattern,
736
+ "cross-hatch": CrossHatchPattern,
737
+ "diagonal-lines": DiagonalLinesPattern,
738
+ "falling-triangles": FallingTrianglesPattern,
739
+ "4-pointed-star": FourPointedStarPattern,
740
+ "tiny-checkers": TinyCheckersPattern,
741
+ "overlapping-circles": OverlappingCirclesPattern,
742
+ "wiggle-lines": WiggleLinesPattern
743
+ };
744
+ function ChartBackground({ variant }) {
745
+ const baseId = useId2().replace(/:/g, "");
746
+ const patternId = `${baseId}-bg-${variant}`;
747
+ const maskId = `${baseId}-bg-edge-fade`;
748
+ const filterId = `${baseId}-bg-blur`;
749
+ const PatternComponent = PATTERN_MAP[variant];
750
+ return /* @__PURE__ */ jsxs4(ZIndexLayer, { zIndex: -1, children: [
751
+ /* @__PURE__ */ jsxs4("defs", { children: [
752
+ /* @__PURE__ */ jsx4(PatternComponent, { id: patternId }),
753
+ /* @__PURE__ */ jsx4("filter", { id: filterId, children: /* @__PURE__ */ jsx4("feGaussianBlur", { stdDeviation: "25" }) }),
754
+ /* @__PURE__ */ jsx4("mask", { id: maskId, maskUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx4(
755
+ "rect",
756
+ {
757
+ x: "8%",
758
+ y: "20%",
759
+ width: "85%",
760
+ height: "60%",
761
+ fill: "white",
762
+ filter: `url(#${filterId})`
763
+ }
764
+ ) })
765
+ ] }),
766
+ /* @__PURE__ */ jsx4(
767
+ "rect",
768
+ {
769
+ width: "100%",
770
+ height: "100%",
771
+ fill: `url(#${patternId})`,
772
+ mask: `url(#${maskId})`
773
+ }
774
+ )
775
+ ] });
776
+ }
777
+
778
+ // src/components/charts/radial-chart.tsx
779
+ import {
780
+ createContext as createContext2,
781
+ use,
782
+ useCallback,
783
+ useEffect,
784
+ useId as useId3,
785
+ useMemo as useMemo2,
786
+ useState
787
+ } from "react";
788
+ import {
789
+ RadialBar as RechartsRadialBar,
790
+ RadialBarChart as RechartsRadialBarChart,
791
+ Sector
792
+ } from "recharts";
793
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
794
+ var DEFAULT_INNER_RADIUS = "30%";
795
+ var DEFAULT_OUTER_RADIUS = "100%";
796
+ var DEFAULT_CORNER_RADIUS = 5;
797
+ var DEFAULT_BAR_SIZE = 14;
798
+ var LOADING_BARS = 5;
799
+ var LOADING_ANIMATION_DURATION = 1500;
800
+ var RadialChartContext = createContext2(null);
801
+ function useRadialChart() {
802
+ const context = use(RadialChartContext);
803
+ if (!context) {
804
+ throw new Error(
805
+ "Radial chart parts (<RadialBar />, <Tooltip />, \u2026) must be used within <RadialChart />"
806
+ );
807
+ }
808
+ return context;
809
+ }
810
+ function RadialChart({
811
+ config,
812
+ data,
813
+ nameKey,
814
+ children,
815
+ className,
816
+ chartProps,
817
+ variant = "full",
818
+ innerRadius = DEFAULT_INNER_RADIUS,
819
+ outerRadius = DEFAULT_OUTER_RADIUS,
820
+ defaultSelectedDataKey = null,
821
+ onSelectionChange,
822
+ isLoading = false,
823
+ backgroundVariant
824
+ }) {
825
+ const chartId = useId3().replace(/:/g, "");
826
+ const [selectedBar, setSelectedBar] = useState(
827
+ defaultSelectedDataKey
828
+ );
829
+ const loadingData = useLoadingData(isLoading);
830
+ const variantConfig = getVariantConfig(variant);
831
+ const selectBar = useCallback(
832
+ (barName, value) => {
833
+ setSelectedBar(barName);
834
+ onSelectionChange?.(
835
+ barName === null ? null : { dataKey: barName, value: value ?? 0 }
836
+ );
837
+ },
838
+ [onSelectionChange]
839
+ );
840
+ const preparedData = useMemo2(
841
+ () => data.map((item) => ({
842
+ ...item,
843
+ fill: `url(#${chartId}-radial-colors-${item[nameKey]})`
844
+ })),
845
+ [data, nameKey, chartId]
846
+ );
847
+ const contextValue = useMemo2(
848
+ () => ({
849
+ config,
850
+ nameKey,
851
+ chartId,
852
+ isLoading,
853
+ selectedBar,
854
+ selectBar
855
+ }),
856
+ [config, nameKey, chartId, isLoading, selectedBar, selectBar]
857
+ );
858
+ return /* @__PURE__ */ jsx5(RadialChartContext, { value: contextValue, children: /* @__PURE__ */ jsxs5(Chart, { className, config, children: [
859
+ /* @__PURE__ */ jsx5(LoadingIndicator, { isLoading }),
860
+ /* @__PURE__ */ jsxs5(
861
+ RechartsRadialBarChart,
862
+ {
863
+ id: chartId,
864
+ data: isLoading ? loadingData : preparedData,
865
+ innerRadius,
866
+ outerRadius,
867
+ startAngle: variantConfig.startAngle,
868
+ endAngle: variantConfig.endAngle,
869
+ cx: variantConfig.cx,
870
+ cy: variantConfig.cy,
871
+ ...chartProps,
872
+ children: [
873
+ backgroundVariant && /* @__PURE__ */ jsx5(ChartBackground, { variant: backgroundVariant }),
874
+ children,
875
+ isLoading && /* @__PURE__ */ jsx5(LoadingRadialBar, {}),
876
+ /* @__PURE__ */ jsx5("defs", { children: /* @__PURE__ */ jsx5(ColorGradientStyle, { config, chartId }) })
877
+ ]
878
+ }
879
+ )
880
+ ] }) });
881
+ }
882
+ function RadialBar({
883
+ dataKey,
884
+ cornerRadius = DEFAULT_CORNER_RADIUS,
885
+ barSize = DEFAULT_BAR_SIZE,
886
+ showBackground = true,
887
+ isClickable = false,
888
+ radialBarProps
889
+ }) {
890
+ const { nameKey, isLoading, selectedBar, selectBar } = useRadialChart();
891
+ if (isLoading) return null;
892
+ return /* @__PURE__ */ jsx5(Fragment2, { children: /* @__PURE__ */ jsx5(
893
+ RechartsRadialBar,
894
+ {
895
+ dataKey,
896
+ cornerRadius,
897
+ barSize,
898
+ background: showBackground,
899
+ className: "drop-shadow-sm",
900
+ style: isClickable ? { cursor: "pointer" } : void 0,
901
+ onClick: (payload, index) => {
902
+ if (!isClickable) return;
903
+ const entry = payload;
904
+ const barName = entry?.[nameKey] ?? String(index);
905
+ const value = Number(entry?.[dataKey] ?? 0);
906
+ selectBar(selectedBar === barName ? null : barName, value);
907
+ },
908
+ shape: (props) => {
909
+ const barName = props[nameKey];
910
+ const isSelected = selectedBar === null || selectedBar === barName;
911
+ return /* @__PURE__ */ jsx5(
912
+ Sector,
913
+ {
914
+ ...props,
915
+ opacity: isClickable && !isSelected ? 0.3 : 1,
916
+ className: "transition-opacity duration-200"
917
+ }
918
+ );
919
+ },
920
+ ...radialBarProps
921
+ }
922
+ ) });
923
+ }
924
+ function Tooltip2({ variant, roundness, defaultIndex }) {
925
+ const { nameKey, isLoading } = useRadialChart();
926
+ if (isLoading) return null;
927
+ return /* @__PURE__ */ jsx5(
928
+ ChartTooltip,
929
+ {
930
+ defaultIndex,
931
+ cursor: false,
932
+ content: /* @__PURE__ */ jsx5(
933
+ ChartTooltipContent,
934
+ {
935
+ nameKey,
936
+ hideLabel: true,
937
+ roundness,
938
+ variant
939
+ }
940
+ )
941
+ }
942
+ );
943
+ }
944
+ function Legend2({
945
+ variant,
946
+ align = "center",
947
+ verticalAlign = "bottom",
948
+ isClickable = false
949
+ }) {
950
+ const { nameKey, isLoading, selectedBar, selectBar } = useRadialChart();
951
+ if (isLoading) return null;
952
+ return /* @__PURE__ */ jsx5(
953
+ ChartLegend,
954
+ {
955
+ verticalAlign,
956
+ align,
957
+ content: /* @__PURE__ */ jsx5(
958
+ ChartLegendContent,
959
+ {
960
+ selected: selectedBar,
961
+ onSelectChange: selectBar,
962
+ isClickable,
963
+ nameKey,
964
+ variant
965
+ }
966
+ )
967
+ }
968
+ );
969
+ }
970
+ function getVariantConfig(variant) {
971
+ switch (variant) {
972
+ case "semi":
973
+ return { startAngle: 180, endAngle: 0, cx: "50%", cy: "70%" };
974
+ case "full":
975
+ default:
976
+ return { startAngle: 90, endAngle: -270, cx: "50%", cy: "50%" };
977
+ }
978
+ }
979
+ var ColorGradientStyle = ({
980
+ config,
981
+ chartId
982
+ }) => {
983
+ return /* @__PURE__ */ jsx5(Fragment2, { children: Object.entries(config).map(([dataKey, colorConfig]) => {
984
+ const colorsCount = getColorsCount(colorConfig);
985
+ return /* @__PURE__ */ jsx5(
986
+ "linearGradient",
987
+ {
988
+ id: `${chartId}-radial-colors-${dataKey}`,
989
+ x1: "0",
990
+ y1: "0",
991
+ x2: "1",
992
+ y2: "1",
993
+ children: colorsCount === 1 ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
994
+ /* @__PURE__ */ jsx5("stop", { offset: "0%", stopColor: `var(--color-${dataKey}-0)` }),
995
+ /* @__PURE__ */ jsx5("stop", { offset: "100%", stopColor: `var(--color-${dataKey}-0)` })
996
+ ] }) : Array.from({ length: colorsCount }, (_, index) => {
997
+ const offset = `${index / (colorsCount - 1) * 100}%`;
998
+ return /* @__PURE__ */ jsx5(
999
+ "stop",
1000
+ {
1001
+ offset,
1002
+ stopColor: `var(--color-${dataKey}-${index}, var(--color-${dataKey}-0))`
1003
+ },
1004
+ offset
1005
+ );
1006
+ })
1007
+ },
1008
+ `${chartId}-radial-colors-${dataKey}`
1009
+ );
1010
+ }) });
1011
+ };
1012
+ function generateLoadingData() {
1013
+ return Array.from({ length: LOADING_BARS }, (_, i) => ({
1014
+ name: `loading${i}`,
1015
+ value: 40 + Math.random() * 60
1016
+ }));
1017
+ }
1018
+ function useLoadingData(isLoading) {
1019
+ const [tick, setTick] = useState(0);
1020
+ useEffect(() => {
1021
+ if (!isLoading) return;
1022
+ const interval = setInterval(() => {
1023
+ setTick((prev) => prev + 1);
1024
+ }, LOADING_ANIMATION_DURATION);
1025
+ return () => clearInterval(interval);
1026
+ }, [isLoading]);
1027
+ const loadingData = useMemo2(() => generateLoadingData(), [tick]);
1028
+ return loadingData;
1029
+ }
1030
+ var LoadingRadialBar = () => {
1031
+ return /* @__PURE__ */ jsx5(
1032
+ RechartsRadialBar,
1033
+ {
1034
+ dataKey: "value",
1035
+ cornerRadius: DEFAULT_CORNER_RADIUS,
1036
+ barSize: DEFAULT_BAR_SIZE,
1037
+ background: true,
1038
+ isAnimationActive: true,
1039
+ animationDuration: LOADING_ANIMATION_DURATION,
1040
+ animationEasing: "ease-in-out",
1041
+ shape: (props) => /* @__PURE__ */ jsx5(Sector, { ...props, fill: "currentColor", fillOpacity: 0.25 })
1042
+ }
1043
+ );
1044
+ };
1045
+ export {
1046
+ Legend2 as Legend,
1047
+ RadialBar,
1048
+ RadialChart,
1049
+ Tooltip2 as Tooltip
1050
+ };
1051
+ //# sourceMappingURL=radial-chart.js.map