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,1094 @@
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-legend.tsx
217
+ import * as RechartsPrimitive2 from "recharts";
218
+ import "react";
219
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
220
+ function ChartLegendContent({
221
+ className,
222
+ hideIcon = false,
223
+ nameKey,
224
+ payload,
225
+ verticalAlign,
226
+ align = "right",
227
+ selected,
228
+ onSelectChange,
229
+ isClickable,
230
+ variant = "rounded-square"
231
+ }) {
232
+ const { config } = useChart();
233
+ if (!payload?.length) {
234
+ return null;
235
+ }
236
+ return /* @__PURE__ */ jsx2(
237
+ "div",
238
+ {
239
+ className: cn(
240
+ "flex items-center gap-4 select-none",
241
+ align === "left" && "justify-start",
242
+ align === "center" && "justify-center",
243
+ align === "right" && "justify-end",
244
+ verticalAlign === "top" ? "pb-4" : "pt-4",
245
+ className
246
+ ),
247
+ children: payload.filter((item) => item.type !== "none").map((item) => {
248
+ const payloadName = nameKey && item.payload ? item.payload[nameKey] : void 0;
249
+ const key = `${payloadName ?? item.value ?? item.dataKey ?? "value"}`;
250
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
251
+ const isSelected = selected === null || selected === key;
252
+ const colorsCount = itemConfig ? getColorsCount(itemConfig) : 1;
253
+ return /* @__PURE__ */ jsxs2(
254
+ "div",
255
+ {
256
+ className: cn(
257
+ "[&>svg]:text-bruv-secondary flex items-center gap-1.5 transition-opacity [&>svg]:h-3 [&>svg]:w-3",
258
+ !isSelected && "opacity-30",
259
+ isClickable && "cursor-pointer"
260
+ ),
261
+ onClick: () => {
262
+ if (!isClickable) return;
263
+ onSelectChange?.(selected === key ? null : key);
264
+ },
265
+ children: [
266
+ itemConfig?.icon && !hideIcon ? /* @__PURE__ */ jsx2(itemConfig.icon, {}) : /* @__PURE__ */ jsx2(
267
+ LegendIndicator,
268
+ {
269
+ variant,
270
+ dataKey: key,
271
+ colorsCount
272
+ }
273
+ ),
274
+ itemConfig?.label
275
+ ]
276
+ },
277
+ key
278
+ );
279
+ })
280
+ }
281
+ );
282
+ }
283
+ function LegendIndicator({
284
+ variant,
285
+ dataKey,
286
+ colorsCount
287
+ }) {
288
+ const fillStyle = getLegendFillStyle(dataKey, colorsCount);
289
+ const outlineStyle = getLegendOutlineStyle(dataKey, colorsCount);
290
+ switch (variant) {
291
+ case "square":
292
+ return /* @__PURE__ */ jsx2("div", { className: "h-2 w-2 shrink-0", style: fillStyle });
293
+ case "circle":
294
+ return /* @__PURE__ */ jsx2("div", { className: "h-2 w-2 shrink-0 rounded-full", style: fillStyle });
295
+ case "circle-outline":
296
+ return /* @__PURE__ */ jsx2(
297
+ "div",
298
+ {
299
+ className: "h-2.5 w-2.5 shrink-0 rounded-full p-[1.5px]",
300
+ style: outlineStyle
301
+ }
302
+ );
303
+ case "vertical-bar":
304
+ return /* @__PURE__ */ jsx2("div", { className: "h-3 w-1 shrink-0 rounded-[2px]", style: fillStyle });
305
+ case "horizontal-bar":
306
+ return /* @__PURE__ */ jsx2("div", { className: "h-1 w-3 shrink-0 rounded-[2px]", style: fillStyle });
307
+ case "rounded-square-outline":
308
+ return /* @__PURE__ */ jsx2(
309
+ "div",
310
+ {
311
+ className: "h-2.5 w-2.5 shrink-0 rounded-[3px] p-[1.5px]",
312
+ style: outlineStyle
313
+ }
314
+ );
315
+ case "rounded-square":
316
+ default:
317
+ return /* @__PURE__ */ jsx2("div", { className: "h-2 w-2 shrink-0 rounded-[2px]", style: fillStyle });
318
+ }
319
+ }
320
+ function getLegendFillStyle(dataKey, colorsCount) {
321
+ if (colorsCount <= 1) {
322
+ return { backgroundColor: `var(--color-${dataKey}-0)` };
323
+ }
324
+ const stops = Array.from({ length: colorsCount }, (_, i) => {
325
+ const offset = i / (colorsCount - 1) * 100;
326
+ return `var(--color-${dataKey}-${i}) ${offset}%`;
327
+ }).join(", ");
328
+ return { background: `linear-gradient(to right, ${stops})` };
329
+ }
330
+ function getLegendOutlineStyle(dataKey, colorsCount) {
331
+ const maskStyle = {
332
+ WebkitMask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
333
+ WebkitMaskComposite: "xor",
334
+ mask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
335
+ maskComposite: "exclude"
336
+ };
337
+ if (colorsCount <= 1) {
338
+ return {
339
+ backgroundColor: `var(--color-${dataKey}-0)`,
340
+ ...maskStyle
341
+ };
342
+ }
343
+ const stops = Array.from({ length: colorsCount }, (_, i) => {
344
+ const offset = i / (colorsCount - 1) * 100;
345
+ return `var(--color-${dataKey}-${i}) ${offset}%`;
346
+ }).join(", ");
347
+ return {
348
+ background: `linear-gradient(to right, ${stops})`,
349
+ ...maskStyle
350
+ };
351
+ }
352
+ var ChartLegend = RechartsPrimitive2.Legend;
353
+
354
+ // src/components/charts/chart-tooltip.tsx
355
+ import * as RechartsPrimitive3 from "recharts";
356
+ import * as React2 from "react";
357
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
358
+ var roundnessMap = {
359
+ sm: "rounded-bruv-sm",
360
+ md: "rounded-bruv-md",
361
+ lg: "rounded-bruv-lg",
362
+ xl: "rounded-bruv-xl"
363
+ };
364
+ var variantMap = {
365
+ default: "bg-bruv-base-2",
366
+ "frosted-glass": "bg-bruv-base-2/70 backdrop-blur-sm"
367
+ };
368
+ function ChartTooltipContent({
369
+ active,
370
+ payload,
371
+ className,
372
+ indicator = "dot",
373
+ hideLabel = false,
374
+ hideIndicator = false,
375
+ label,
376
+ labelFormatter,
377
+ labelClassName,
378
+ formatter,
379
+ nameKey,
380
+ labelKey,
381
+ selected,
382
+ roundness = "lg",
383
+ variant = "default"
384
+ }) {
385
+ const { config } = useChart();
386
+ const tooltipLabel = React2.useMemo(() => {
387
+ if (hideLabel || !payload?.length) {
388
+ return null;
389
+ }
390
+ const [item] = payload;
391
+ const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
392
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
393
+ const value = !labelKey && typeof label === "string" ? config[label]?.label ?? label : itemConfig?.label;
394
+ if (labelFormatter) {
395
+ return /* @__PURE__ */ jsx3("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
396
+ }
397
+ if (!value) {
398
+ return null;
399
+ }
400
+ return /* @__PURE__ */ jsx3("div", { className: cn("font-medium", labelClassName), children: value });
401
+ }, [
402
+ label,
403
+ labelFormatter,
404
+ payload,
405
+ hideLabel,
406
+ labelClassName,
407
+ config,
408
+ labelKey
409
+ ]);
410
+ if (!active || !payload?.length) {
411
+ return /* @__PURE__ */ jsx3("span", { className: "p-4" });
412
+ }
413
+ const nestLabel = payload.length === 1 && indicator !== "dot";
414
+ return /* @__PURE__ */ jsxs3(
415
+ "div",
416
+ {
417
+ className: cn(
418
+ "border-bruv-neutral/50 grid min-w-32 items-start gap-1.5 border px-2.5 py-1.5 text-xs shadow-xl",
419
+ roundnessMap[roundness],
420
+ variantMap[variant],
421
+ className
422
+ ),
423
+ children: [
424
+ !nestLabel ? tooltipLabel : null,
425
+ /* @__PURE__ */ jsx3("div", { className: "grid gap-1.5", children: payload.filter((item) => item.type !== "none").map((item, index) => {
426
+ const payloadName = nameKey && item.payload ? item.payload[nameKey] : void 0;
427
+ const key = `${payloadName ?? item.name ?? item.dataKey ?? "value"}`;
428
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
429
+ const colorsCount = itemConfig ? getColorsCount(itemConfig) : 1;
430
+ return /* @__PURE__ */ jsx3(
431
+ "div",
432
+ {
433
+ className: cn(
434
+ "[&>svg]:text-bruv-secondary flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
435
+ indicator === "dot" && "items-center",
436
+ selected != null && selected !== item.dataKey && "opacity-30"
437
+ ),
438
+ children: formatter && item?.value !== void 0 && item.name ? formatter(item.value, item.name, item, index, item.payload) : /* @__PURE__ */ jsxs3(Fragment, { children: [
439
+ itemConfig?.icon ? /* @__PURE__ */ jsx3(itemConfig.icon, {}) : !hideIndicator && /* @__PURE__ */ jsx3(
440
+ "div",
441
+ {
442
+ className: cn("shrink-0 rounded-[2px]", {
443
+ "h-2.5 w-2.5": indicator === "dot",
444
+ "w-1": indicator === "line",
445
+ "w-0 border-[1.5px] border-dashed bg-transparent!": indicator === "dashed",
446
+ "my-0.5": nestLabel && indicator === "dashed"
447
+ }),
448
+ style: getIndicatorColorStyle(key, colorsCount)
449
+ }
450
+ ),
451
+ /* @__PURE__ */ jsxs3(
452
+ "div",
453
+ {
454
+ className: cn(
455
+ "flex flex-1 justify-between gap-4 leading-none",
456
+ nestLabel ? "items-end" : "items-center"
457
+ ),
458
+ children: [
459
+ /* @__PURE__ */ jsxs3("div", { className: "grid gap-1.5", children: [
460
+ nestLabel ? tooltipLabel : null,
461
+ /* @__PURE__ */ jsx3("span", { className: "text-bruv-secondary", children: itemConfig?.label ?? item.name })
462
+ ] }),
463
+ item.value != null && /* @__PURE__ */ jsx3("span", { className: "text-bruv-primary font-mono font-medium tabular-nums", children: typeof item.value === "number" ? item.value.toLocaleString() : String(item.value) })
464
+ ]
465
+ }
466
+ )
467
+ ] })
468
+ },
469
+ index
470
+ );
471
+ }) })
472
+ ]
473
+ }
474
+ );
475
+ }
476
+ function getIndicatorColorStyle(dataKey, colorsCount) {
477
+ if (colorsCount <= 1) {
478
+ return { background: `var(--color-${dataKey}-0)` };
479
+ }
480
+ const stops = Array.from({ length: colorsCount }, (_, index) => {
481
+ const offset = index / (colorsCount - 1) * 100;
482
+ return `var(--color-${dataKey}-${index}) ${offset}%`;
483
+ }).join(", ");
484
+ return { background: `linear-gradient(to right, ${stops})` };
485
+ }
486
+ var ChartTooltip = ({
487
+ animationDuration = 200,
488
+ ...props
489
+ }) => /* @__PURE__ */ jsx3(RechartsPrimitive3.Tooltip, { animationDuration, ...props });
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/pie-chart.tsx
779
+ import {
780
+ Children,
781
+ createContext as createContext2,
782
+ isValidElement,
783
+ use,
784
+ useCallback,
785
+ useId as useId3,
786
+ useMemo as useMemo2,
787
+ useState
788
+ } from "react";
789
+ import {
790
+ LabelList as RechartsLabelList,
791
+ Pie as RechartsPie,
792
+ PieChart as RechartsPieChart,
793
+ Sector
794
+ } from "recharts";
795
+ import { motion } from "motion/react";
796
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
797
+ var LOADING_SECTORS = 5;
798
+ var LOADING_ANIMATION_DURATION = 2e3;
799
+ var DEFAULT_INNER_RADIUS = 0;
800
+ var DEFAULT_OUTER_RADIUS = "80%";
801
+ var DEFAULT_CORNER_RADIUS = 0;
802
+ var DEFAULT_PADDING_ANGLE = 0;
803
+ var DEFAULT_START_ANGLE = 0;
804
+ var DEFAULT_END_ANGLE = 360;
805
+ var PieChartContext = createContext2(null);
806
+ function usePieChart() {
807
+ const context = use(PieChartContext);
808
+ if (!context) {
809
+ throw new Error(
810
+ "Pie chart parts (<Pie />, <Tooltip />, \u2026) must be used within <PieChart />"
811
+ );
812
+ }
813
+ return context;
814
+ }
815
+ function PieChart({
816
+ config,
817
+ data,
818
+ dataKey,
819
+ nameKey,
820
+ children,
821
+ className,
822
+ chartProps,
823
+ defaultSelectedSector = null,
824
+ onSelectionChange,
825
+ isLoading = false
826
+ }) {
827
+ const [selectedSector, setSelectedSector] = useState(
828
+ defaultSelectedSector
829
+ );
830
+ const selectSector = useCallback(
831
+ (sectorName) => {
832
+ setSelectedSector(sectorName);
833
+ if (sectorName === null) {
834
+ onSelectionChange?.(null);
835
+ return;
836
+ }
837
+ const selectedItem = data.find(
838
+ (item) => item[nameKey] === sectorName
839
+ );
840
+ if (selectedItem) {
841
+ onSelectionChange?.({
842
+ dataKey: sectorName,
843
+ value: selectedItem[dataKey]
844
+ });
845
+ }
846
+ },
847
+ [data, dataKey, nameKey, onSelectionChange]
848
+ );
849
+ const contextValue = useMemo2(
850
+ () => ({
851
+ config,
852
+ data,
853
+ dataKey,
854
+ nameKey,
855
+ isLoading,
856
+ selectedSector,
857
+ selectSector
858
+ }),
859
+ [config, data, dataKey, nameKey, isLoading, selectedSector, selectSector]
860
+ );
861
+ return /* @__PURE__ */ jsx5(PieChartContext, { value: contextValue, children: /* @__PURE__ */ jsxs5(Chart, { className, config, children: [
862
+ /* @__PURE__ */ jsx5(LoadingIndicator, { isLoading }),
863
+ /* @__PURE__ */ jsx5(
864
+ RechartsPieChart,
865
+ {
866
+ id: "evil-charts-pie-chart",
867
+ accessibilityLayer: true,
868
+ ...chartProps,
869
+ children
870
+ }
871
+ )
872
+ ] }) });
873
+ }
874
+ function Pie({
875
+ variant = "gradient",
876
+ innerRadius = DEFAULT_INNER_RADIUS,
877
+ outerRadius = DEFAULT_OUTER_RADIUS,
878
+ cornerRadius = DEFAULT_CORNER_RADIUS,
879
+ paddingAngle = DEFAULT_PADDING_ANGLE,
880
+ startAngle = DEFAULT_START_ANGLE,
881
+ endAngle = DEFAULT_END_ANGLE,
882
+ isClickable = false,
883
+ children,
884
+ pieProps
885
+ }) {
886
+ const {
887
+ config,
888
+ data,
889
+ dataKey,
890
+ nameKey,
891
+ isLoading,
892
+ selectedSector,
893
+ selectSector
894
+ } = usePieChart();
895
+ const id = useId3().replace(/:/g, "");
896
+ if (isLoading) {
897
+ return /* @__PURE__ */ jsx5(
898
+ RechartsPie,
899
+ {
900
+ data: LOADING_PIE_DATA,
901
+ dataKey: "value",
902
+ nameKey: "name",
903
+ innerRadius,
904
+ outerRadius,
905
+ cornerRadius,
906
+ paddingAngle,
907
+ startAngle,
908
+ endAngle,
909
+ strokeWidth: 0,
910
+ isAnimationActive: false,
911
+ shape: (props) => /* @__PURE__ */ jsx5(AnimatedLoadingSector, { ...props })
912
+ }
913
+ );
914
+ }
915
+ const label = resolveLabel(children, dataKey);
916
+ const preparedData = data.map((item) => ({
917
+ ...item,
918
+ fill: `url(#${id}-colors-${item[nameKey]})`
919
+ }));
920
+ return /* @__PURE__ */ jsxs5(Fragment2, { children: [
921
+ /* @__PURE__ */ jsx5(
922
+ RechartsPie,
923
+ {
924
+ data: preparedData,
925
+ dataKey,
926
+ nameKey,
927
+ innerRadius,
928
+ outerRadius,
929
+ cornerRadius,
930
+ paddingAngle,
931
+ startAngle,
932
+ endAngle,
933
+ strokeWidth: 0,
934
+ isAnimationActive: true,
935
+ style: isClickable ? { cursor: "pointer" } : void 0,
936
+ onClick: (_, index) => {
937
+ if (!isClickable) return;
938
+ const clickedName = data[index]?.[nameKey];
939
+ selectSector(selectedSector === clickedName ? null : clickedName);
940
+ },
941
+ shape: (props) => {
942
+ const sectorName = data[props.index ?? 0]?.[nameKey];
943
+ const isDimmed = isClickable && selectedSector !== null && selectedSector !== sectorName;
944
+ return /* @__PURE__ */ jsx5(
945
+ Sector,
946
+ {
947
+ ...props,
948
+ fill: `url(#${id}-colors-${sectorName})`,
949
+ stroke: paddingAngle < 0 ? "var(--background)" : "none",
950
+ strokeWidth: paddingAngle < 0 ? 5 : 0,
951
+ opacity: isDimmed ? 0.3 : 1,
952
+ className: "transition-opacity duration-200"
953
+ }
954
+ );
955
+ },
956
+ ...pieProps,
957
+ children: label
958
+ }
959
+ ),
960
+ /* @__PURE__ */ jsx5("defs", { children: /* @__PURE__ */ jsx5(RadialColorGradient, { id, config, variant }) })
961
+ ] });
962
+ }
963
+ var Label = () => null;
964
+ function Tooltip2({ variant, roundness, defaultIndex }) {
965
+ const { isLoading, nameKey } = usePieChart();
966
+ if (isLoading) return null;
967
+ return /* @__PURE__ */ jsx5(
968
+ ChartTooltip,
969
+ {
970
+ defaultIndex,
971
+ content: /* @__PURE__ */ jsx5(
972
+ ChartTooltipContent,
973
+ {
974
+ nameKey,
975
+ hideLabel: true,
976
+ roundness,
977
+ variant
978
+ }
979
+ )
980
+ }
981
+ );
982
+ }
983
+ function Legend2({
984
+ variant,
985
+ align = "center",
986
+ verticalAlign = "bottom",
987
+ isClickable = false
988
+ }) {
989
+ const { nameKey, selectedSector, selectSector } = usePieChart();
990
+ return /* @__PURE__ */ jsx5(
991
+ ChartLegend,
992
+ {
993
+ verticalAlign,
994
+ align,
995
+ content: /* @__PURE__ */ jsx5(
996
+ ChartLegendContent,
997
+ {
998
+ selected: selectedSector,
999
+ onSelectChange: selectSector,
1000
+ isClickable,
1001
+ nameKey,
1002
+ variant
1003
+ }
1004
+ )
1005
+ }
1006
+ );
1007
+ }
1008
+ function Background({ variant = "dots" }) {
1009
+ return /* @__PURE__ */ jsx5(ChartBackground, { variant });
1010
+ }
1011
+ var resolveLabel = (children, valueKey) => {
1012
+ let label = null;
1013
+ Children.forEach(children, (child) => {
1014
+ if (!isValidElement(child) || child.type !== Label) return;
1015
+ const { dataKey, labelListProps } = child.props;
1016
+ label = /* @__PURE__ */ jsx5(
1017
+ RechartsLabelList,
1018
+ {
1019
+ dataKey: dataKey ?? valueKey,
1020
+ stroke: "none",
1021
+ fontSize: 12,
1022
+ fontWeight: 500,
1023
+ fill: "currentColor",
1024
+ className: "fill-background",
1025
+ ...labelListProps
1026
+ }
1027
+ );
1028
+ });
1029
+ return label;
1030
+ };
1031
+ var RadialColorGradient = ({
1032
+ id,
1033
+ config
1034
+ }) => {
1035
+ return /* @__PURE__ */ jsx5(Fragment2, { children: Object.entries(config).map(([sectorKey, sectorConfig]) => {
1036
+ const colorsCount = getColorsCount(sectorConfig);
1037
+ return /* @__PURE__ */ jsx5(
1038
+ "linearGradient",
1039
+ {
1040
+ id: `${id}-colors-${sectorKey}`,
1041
+ x1: "0",
1042
+ y1: "0",
1043
+ x2: "1",
1044
+ y2: "1",
1045
+ children: colorsCount === 1 ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
1046
+ /* @__PURE__ */ jsx5("stop", { offset: "0%", stopColor: `var(--color-${sectorKey}-0)` }),
1047
+ /* @__PURE__ */ jsx5("stop", { offset: "100%", stopColor: `var(--color-${sectorKey}-0)` })
1048
+ ] }) : Array.from({ length: colorsCount }, (_, index) => {
1049
+ const offset = `${index / (colorsCount - 1) * 100}%`;
1050
+ return /* @__PURE__ */ jsx5(
1051
+ "stop",
1052
+ {
1053
+ offset,
1054
+ stopColor: `var(--color-${sectorKey}-${index}, var(--color-${sectorKey}-0))`
1055
+ },
1056
+ offset
1057
+ );
1058
+ })
1059
+ },
1060
+ `${id}-colors-${sectorKey}`
1061
+ );
1062
+ }) });
1063
+ };
1064
+ var LOADING_PIE_DATA = Array.from({ length: LOADING_SECTORS }, (_, i) => ({
1065
+ name: `loading${i}`,
1066
+ value: 100 / LOADING_SECTORS
1067
+ }));
1068
+ var AnimatedLoadingSector = (props) => {
1069
+ const { index = 0, ...sectorProps } = props;
1070
+ const delay = index / LOADING_SECTORS * (LOADING_ANIMATION_DURATION / 1e3);
1071
+ return /* @__PURE__ */ jsx5(
1072
+ motion.g,
1073
+ {
1074
+ initial: { opacity: 0.15 },
1075
+ animate: { opacity: [0.15, 0.5, 0.15] },
1076
+ transition: {
1077
+ duration: LOADING_ANIMATION_DURATION / 1e3,
1078
+ delay,
1079
+ repeat: Infinity,
1080
+ ease: "easeInOut"
1081
+ },
1082
+ children: /* @__PURE__ */ jsx5(Sector, { ...sectorProps, fill: "currentColor" })
1083
+ }
1084
+ );
1085
+ };
1086
+ export {
1087
+ Background,
1088
+ Label,
1089
+ Legend2 as Legend,
1090
+ Pie,
1091
+ PieChart,
1092
+ Tooltip2 as Tooltip
1093
+ };
1094
+ //# sourceMappingURL=pie-chart.js.map