@nice2dev/ui-forms 1.0.12 → 1.0.14

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.
@@ -0,0 +1,3868 @@
1
+ import { jsx as e, jsxs as b, Fragment as Fe } from "react/jsx-runtime";
2
+ import He, { useRef as Ne, useState as he, useMemo as ue, useCallback as ce, forwardRef as _e, useEffect as Se, useImperativeHandle as Ie } from "react";
3
+ import { u as Ee, G as Be, N as Ue, U as Pe } from "./index-CCComLaF.js";
4
+ const ke = [
5
+ "var(--color-primary, #3b82f6)",
6
+ "var(--color-error, #ef4444)",
7
+ "var(--color-success, #22c55e)",
8
+ "var(--color-warning, #f59e0b)",
9
+ "var(--color-accent, #8b5cf6)",
10
+ "var(--color-accent-pink, #ec4899)",
11
+ "var(--color-info, #06b6d4)",
12
+ "var(--nice-success, #84cc16)"
13
+ ], je = ({
14
+ series: t,
15
+ categories: u,
16
+ width: c = 600,
17
+ height: m = 400,
18
+ title: n,
19
+ showLegend: g = !0,
20
+ showGrid: w = !0,
21
+ axisLabels: A = !0,
22
+ yAxisLabel: L,
23
+ xAxisLabel: l,
24
+ stacked: p,
25
+ animated: y,
26
+ zoomable: f,
27
+ crosshair: N,
28
+ annotations: k,
29
+ legendInteractive: o,
30
+ onDataPointClick: d,
31
+ exportable: s,
32
+ className: $,
33
+ style: _
34
+ }) => {
35
+ var $e, Ce, Ae;
36
+ const S = Ne(null), [x, v] = he(/* @__PURE__ */ new Set()), [i, z] = he(null), [a, j] = he(null), [T, B] = he(!1), Y = Ne(null), G = ue(
37
+ () => t.filter((M) => !x.has(M.name)),
38
+ [t, x]
39
+ ), ee = ce(
40
+ (M) => {
41
+ o && v((ae) => {
42
+ const te = new Set(ae);
43
+ return te.has(M) ? te.delete(M) : te.add(M), te;
44
+ });
45
+ },
46
+ [o]
47
+ ), J = {
48
+ top: n ? 40 : 20,
49
+ right: 20,
50
+ bottom: l ? 60 : 40,
51
+ left: L ? 60 : 50
52
+ }, re = c - J.left - J.right, q = m - J.top - J.bottom, Z = (($e = G[0]) == null ? void 0 : $e.data.length) ?? ((Ce = t[0]) == null ? void 0 : Ce.data.length) ?? 0, se = (a == null ? void 0 : a.start) ?? 0, de = (a == null ? void 0 : a.end) ?? Z, C = de - se, D = ue(
53
+ () => G.map((M) => ({ ...M, data: M.data.slice(se, de) })),
54
+ [G, se, de]
55
+ ), F = ue(
56
+ () => u == null ? void 0 : u.slice(se, de),
57
+ [u, se, de]
58
+ ), { minY: X, maxY: K, yTicks: V } = ue(() => {
59
+ let M;
60
+ if (p) {
61
+ M = [];
62
+ for (let H = 0; H < C; H++)
63
+ M.push(D.reduce((ne, le) => ne + (le.data[H] || 0), 0));
64
+ } else
65
+ M = D.flatMap((H) => H.data);
66
+ M.length === 0 && (M = [0]);
67
+ const ae = Math.min(0, ...M), te = Math.max(0, ...M), r = te - ae || 1, I = Math.pow(10, Math.floor(Math.log10(r))) || 1, W = Math.floor(ae / I) * I, h = Math.ceil(te / I) * I, R = [];
68
+ for (let H = W; H <= h; H += I)
69
+ R.push(Math.round(H * 1e6) / 1e6);
70
+ return R.length < 2 && R.push(h), { minY: W, maxY: h, yTicks: R };
71
+ }, [D, C, p]), O = (M) => q - (M - X) / (K - X || 1) * q, U = (M) => (M + 0.5) / C * re, Q = C > 0 ? re / C / (p ? 1.5 : Math.max(G.length, 1) * 1.5) : 20, P = ce(
72
+ (M) => {
73
+ if (!f)
74
+ return;
75
+ M.preventDefault();
76
+ const ae = a ?? { start: 0, end: Z }, te = ae.end - ae.start, r = (ae.start + ae.end) / 2, I = M.deltaY > 0 ? 1.2 : 0.8, W = Math.max(2, Math.min(Z, Math.round(te * I))), h = Math.max(0, Math.round(r - W / 2)), R = Math.min(Z, h + W);
77
+ j({ start: h, end: R });
78
+ },
79
+ [f, a, Z]
80
+ ), E = ce(
81
+ (M) => {
82
+ f && (B(!0), Y.current = { x: M.clientX, range: a ?? { start: 0, end: Z } });
83
+ },
84
+ [f, a, Z]
85
+ ), ie = ce(
86
+ (M) => {
87
+ var te;
88
+ const ae = (te = S.current) == null ? void 0 : te.getBoundingClientRect();
89
+ if (ae && z({ x: M.clientX - ae.left - J.left, y: M.clientY - ae.top - J.top }), T && Y.current && f) {
90
+ const r = M.clientX - Y.current.x, I = re / C, W = -Math.round(r / I), h = Y.current.range, R = h.end - h.start;
91
+ let H = h.start + W;
92
+ H < 0 && (H = 0), H + R > Z && (H = Z - R), j({ start: H, end: H + R });
93
+ }
94
+ },
95
+ [T, f, re, C, Z, J.left, J.top]
96
+ ), fe = ce(() => {
97
+ B(!1), Y.current = null;
98
+ }, []), ge = ce(() => {
99
+ z(null), B(!1), Y.current = null;
100
+ }, []), xe = ce(() => {
101
+ const M = S.current;
102
+ if (!M)
103
+ return;
104
+ const ae = new XMLSerializer().serializeToString(M), te = document.createElement("canvas");
105
+ te.width = c, te.height = m + (g ? 30 : 0);
106
+ const r = te.getContext("2d");
107
+ if (!r)
108
+ return;
109
+ const I = new Image();
110
+ I.onload = () => {
111
+ r.fillStyle = "var(--bg-primary, #fff)", r.fillRect(0, 0, te.width, te.height), r.drawImage(I, 0, 0);
112
+ const W = document.createElement("a");
113
+ W.download = "chart.png", W.href = te.toDataURL("image/png"), W.click();
114
+ }, I.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(ae);
115
+ }, [c, m, g]), ve = m + (g ? 30 : 0), Me = D.length > 0 && D.every((M) => M.type === "radar"), we = ue(() => {
116
+ if (!Me)
117
+ return 1;
118
+ const M = D.flatMap((ae) => ae.data);
119
+ return Math.max(1, ...M);
120
+ }, [Me, D]);
121
+ if (Me) {
122
+ const M = c / 2, ae = (m - J.top - J.bottom) / 2 + J.top, te = Math.min(re, m - J.top - J.bottom) / 2 - 10, r = (F == null ? void 0 : F.length) ?? ((Ae = D[0]) == null ? void 0 : Ae.data.length) ?? 0, I = (R) => R / r * Math.PI * 2 - Math.PI / 2, W = (R, H) => {
123
+ const ne = H / we * te;
124
+ return [M + Math.cos(I(R)) * ne, ae + Math.sin(I(R)) * ne];
125
+ }, h = 4;
126
+ return /* @__PURE__ */ e("div", { className: `nice-chart nice-chart--radar ${$ || ""}`, style: _, children: /* @__PURE__ */ b(
127
+ "svg",
128
+ {
129
+ ref: S,
130
+ viewBox: `0 0 ${c} ${ve}`,
131
+ preserveAspectRatio: "xMidYMid meet",
132
+ width: "100%",
133
+ height: "100%",
134
+ className: "nice-chart__svg",
135
+ style: { display: "block", maxWidth: "100%", maxHeight: "100%" },
136
+ children: [
137
+ n && /* @__PURE__ */ e("text", { x: c / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: n }),
138
+ w && Array.from({ length: h }, (R, H) => {
139
+ const ne = (H + 1) / h * te, le = [];
140
+ for (let oe = 0; oe < r; oe++)
141
+ le.push(`${M + Math.cos(I(oe)) * ne},${ae + Math.sin(I(oe)) * ne}`);
142
+ return /* @__PURE__ */ e(
143
+ "polygon",
144
+ {
145
+ points: le.join(" "),
146
+ fill: "none",
147
+ className: "nice-chart__grid-line"
148
+ },
149
+ H
150
+ );
151
+ }),
152
+ Array.from({ length: r }, (R, H) => {
153
+ const [ne, le] = W(H, we);
154
+ return /* @__PURE__ */ e("line", { x1: M, y1: ae, x2: ne, y2: le, className: "nice-chart__grid-line" }, H);
155
+ }),
156
+ A && (F == null ? void 0 : F.map((R, H) => {
157
+ const [ne, le] = W(H, we * 1.12);
158
+ return /* @__PURE__ */ e(
159
+ "text",
160
+ {
161
+ x: ne,
162
+ y: le,
163
+ textAnchor: "middle",
164
+ dominantBaseline: "middle",
165
+ className: "nice-chart__axis-label",
166
+ children: R
167
+ },
168
+ H
169
+ );
170
+ })),
171
+ D.map((R, H) => {
172
+ const ne = R.color || ke[H % ke.length], le = R.data.map((oe, be) => W(be, oe).join(",")).join(" ");
173
+ return /* @__PURE__ */ b(
174
+ "g",
175
+ {
176
+ className: y ? "nice-chart__series nice-chart__series--radar nice-chart__series--anim" : "nice-chart__series nice-chart__series--radar",
177
+ children: [
178
+ /* @__PURE__ */ e(
179
+ "polygon",
180
+ {
181
+ points: le,
182
+ fill: ne,
183
+ fillOpacity: 0.2,
184
+ stroke: ne,
185
+ strokeWidth: 2
186
+ }
187
+ ),
188
+ R.data.map((oe, be) => {
189
+ const [De, ze] = W(be, oe);
190
+ return /* @__PURE__ */ e("circle", { cx: De, cy: ze, r: 3, fill: ne, children: /* @__PURE__ */ e("title", { children: `${R.name}: ${oe}` }) }, be);
191
+ })
192
+ ]
193
+ },
194
+ R.name
195
+ );
196
+ }),
197
+ g && /* @__PURE__ */ e("g", { transform: `translate(${J.left}, ${m})`, children: t.map((R, H) => {
198
+ const ne = H * 120, le = x.has(R.name);
199
+ return /* @__PURE__ */ b(
200
+ "g",
201
+ {
202
+ transform: `translate(${ne}, 10)`,
203
+ style: o ? { cursor: "pointer" } : void 0,
204
+ onClick: () => ee(R.name),
205
+ opacity: le ? 0.35 : 1,
206
+ children: [
207
+ /* @__PURE__ */ e(
208
+ "rect",
209
+ {
210
+ width: 12,
211
+ height: 12,
212
+ rx: 2,
213
+ fill: R.color || ke[H % ke.length]
214
+ }
215
+ ),
216
+ /* @__PURE__ */ e("text", { x: 16, y: 10, className: "nice-chart__legend-text", children: R.name })
217
+ ]
218
+ },
219
+ R.name
220
+ );
221
+ }) })
222
+ ]
223
+ }
224
+ ) });
225
+ }
226
+ return /* @__PURE__ */ b("div", { className: `nice-chart ${$ || ""}`, style: _, children: [
227
+ s && /* @__PURE__ */ e(
228
+ "button",
229
+ {
230
+ type: "button",
231
+ className: "nice-chart__export-btn",
232
+ onClick: xe,
233
+ title: "Export PNG",
234
+ children: "📷"
235
+ }
236
+ ),
237
+ /* @__PURE__ */ b(
238
+ "svg",
239
+ {
240
+ ref: S,
241
+ viewBox: `0 0 ${c} ${ve}`,
242
+ preserveAspectRatio: "xMidYMid meet",
243
+ width: "100%",
244
+ height: "100%",
245
+ style: { display: "block", maxWidth: "100%", maxHeight: "100%" },
246
+ className: "nice-chart__svg",
247
+ onWheel: P,
248
+ onMouseDown: E,
249
+ onMouseMove: ie,
250
+ onMouseUp: fe,
251
+ onMouseLeave: ge,
252
+ children: [
253
+ /* @__PURE__ */ b("g", { transform: `translate(${J.left},${J.top})`, children: [
254
+ n && /* @__PURE__ */ e("text", { x: re / 2, y: -10, textAnchor: "middle", className: "nice-chart__title", children: n }),
255
+ w && V.map((M) => /* @__PURE__ */ e(
256
+ "line",
257
+ {
258
+ x1: 0,
259
+ y1: O(M),
260
+ x2: re,
261
+ y2: O(M),
262
+ className: "nice-chart__grid-line"
263
+ },
264
+ `grid-${M}`
265
+ )),
266
+ A && V.map((M) => /* @__PURE__ */ e(
267
+ "text",
268
+ {
269
+ x: -8,
270
+ y: O(M) + 4,
271
+ textAnchor: "end",
272
+ className: "nice-chart__axis-label",
273
+ children: M
274
+ },
275
+ `ylabel-${M}`
276
+ )),
277
+ A && F && F.map((M, ae) => /* @__PURE__ */ e(
278
+ "text",
279
+ {
280
+ x: U(ae),
281
+ y: q + 20,
282
+ textAnchor: "middle",
283
+ className: "nice-chart__axis-label",
284
+ children: M
285
+ },
286
+ ae
287
+ )),
288
+ L && /* @__PURE__ */ e(
289
+ "text",
290
+ {
291
+ x: -J.left + 14,
292
+ y: q / 2,
293
+ textAnchor: "middle",
294
+ transform: `rotate(-90, -${J.left - 14}, ${q / 2})`,
295
+ className: "nice-chart__axis-title",
296
+ children: L
297
+ }
298
+ ),
299
+ l && /* @__PURE__ */ e("text", { x: re / 2, y: q + 45, textAnchor: "middle", className: "nice-chart__axis-title", children: l }),
300
+ /* @__PURE__ */ e("line", { x1: 0, y1: 0, x2: 0, y2: q, className: "nice-chart__axis" }),
301
+ /* @__PURE__ */ e("line", { x1: 0, y1: q, x2: re, y2: q, className: "nice-chart__axis" }),
302
+ k == null ? void 0 : k.map((M, ae) => {
303
+ if (M.type === "line") {
304
+ const te = O(M.value);
305
+ return /* @__PURE__ */ b("g", { children: [
306
+ /* @__PURE__ */ e(
307
+ "line",
308
+ {
309
+ x1: 0,
310
+ y1: te,
311
+ x2: re,
312
+ y2: te,
313
+ stroke: M.color || "var(--color-error, #ef4444)",
314
+ strokeWidth: 1.5,
315
+ strokeDasharray: M.dash || "6,3"
316
+ }
317
+ ),
318
+ M.label && /* @__PURE__ */ e(
319
+ "text",
320
+ {
321
+ x: re + 4,
322
+ y: te + 4,
323
+ className: "nice-chart__annotation-label",
324
+ fill: M.color || "var(--color-error, #ef4444)",
325
+ children: M.label
326
+ }
327
+ )
328
+ ] }, ae);
329
+ }
330
+ return /* @__PURE__ */ e(
331
+ "text",
332
+ {
333
+ x: U(M.value),
334
+ y: -4,
335
+ textAnchor: "middle",
336
+ className: "nice-chart__annotation-label",
337
+ fill: M.color || "var(--text-muted, #6b7280)",
338
+ children: M.label
339
+ },
340
+ ae
341
+ );
342
+ }),
343
+ N && i && i.x >= 0 && i.x <= re && i.y >= 0 && i.y <= q && /* @__PURE__ */ b(Fe, { children: [
344
+ /* @__PURE__ */ e(
345
+ "line",
346
+ {
347
+ x1: i.x,
348
+ y1: 0,
349
+ x2: i.x,
350
+ y2: q,
351
+ stroke: "var(--nice-text-muted, #9ca3af)",
352
+ strokeWidth: 1,
353
+ strokeDasharray: "4,2"
354
+ }
355
+ ),
356
+ /* @__PURE__ */ e(
357
+ "line",
358
+ {
359
+ x1: 0,
360
+ y1: i.y,
361
+ x2: re,
362
+ y2: i.y,
363
+ stroke: "var(--nice-text-muted, #9ca3af)",
364
+ strokeWidth: 1,
365
+ strokeDasharray: "4,2"
366
+ }
367
+ )
368
+ ] }),
369
+ D.map((M, ae) => {
370
+ const te = M.color || ke[ae % ke.length], r = M.type || "bar";
371
+ if (r === "bar")
372
+ return /* @__PURE__ */ e(
373
+ "g",
374
+ {
375
+ className: y ? "nice-chart__series nice-chart__series--bar nice-chart__series--anim" : "nice-chart__series nice-chart__series--bar",
376
+ children: M.data.map((W, h) => {
377
+ let R, H;
378
+ if (p) {
379
+ const le = D.slice(0, ae).reduce((oe, be) => oe + (be.data[h] || 0), 0);
380
+ R = O(le + W), H = O(le) - R;
381
+ } else
382
+ R = O(Math.max(0, W)), H = Math.abs(O(W) - O(0));
383
+ const ne = p ? U(h) - Q / 2 : U(h) - D.length * Q / 2 + ae * Q;
384
+ return /* @__PURE__ */ e(
385
+ "rect",
386
+ {
387
+ x: ne,
388
+ y: R,
389
+ width: Q * 0.9,
390
+ height: Math.max(0, H),
391
+ fill: te,
392
+ rx: 2,
393
+ style: {
394
+ transformOrigin: `${ne + Q * 0.9 / 2}px ${O(0)}px`,
395
+ ...d ? { cursor: "pointer" } : {}
396
+ },
397
+ onClick: d ? () => d(M.name, se + h, W) : void 0,
398
+ children: /* @__PURE__ */ e("title", { children: `${M.name}: ${W}` })
399
+ },
400
+ h
401
+ );
402
+ })
403
+ },
404
+ M.name
405
+ );
406
+ if (r === "scatter")
407
+ return /* @__PURE__ */ e(
408
+ "g",
409
+ {
410
+ className: y ? "nice-chart__series nice-chart__series--scatter nice-chart__series--anim" : "nice-chart__series nice-chart__series--scatter",
411
+ children: M.data.map((W, h) => /* @__PURE__ */ e(
412
+ "circle",
413
+ {
414
+ cx: U(h),
415
+ cy: O(W),
416
+ r: 5,
417
+ fill: te,
418
+ fillOpacity: 0.7,
419
+ stroke: te,
420
+ strokeWidth: 1.5,
421
+ style: d ? { cursor: "pointer" } : void 0,
422
+ onClick: d ? () => d(M.name, se + h, W) : void 0,
423
+ children: /* @__PURE__ */ e("title", { children: `${M.name}: ${W}` })
424
+ },
425
+ h
426
+ ))
427
+ },
428
+ M.name
429
+ );
430
+ const I = M.data.map((W, h) => `${U(h)},${O(W)}`);
431
+ return /* @__PURE__ */ b(
432
+ "g",
433
+ {
434
+ className: y ? `nice-chart__series nice-chart__series--${r} nice-chart__series--anim` : `nice-chart__series nice-chart__series--${r}`,
435
+ children: [
436
+ r === "area" && /* @__PURE__ */ e(
437
+ "polygon",
438
+ {
439
+ points: `${U(0)},${O(0)} ${I.join(" ")} ${U(C - 1)},${O(0)}`,
440
+ fill: te,
441
+ opacity: 0.15
442
+ }
443
+ ),
444
+ /* @__PURE__ */ e(
445
+ "polyline",
446
+ {
447
+ points: I.join(" "),
448
+ fill: "none",
449
+ stroke: te,
450
+ strokeWidth: 2,
451
+ className: y ? "nice-chart__line" : void 0
452
+ }
453
+ ),
454
+ M.data.map((W, h) => /* @__PURE__ */ e(
455
+ "circle",
456
+ {
457
+ cx: U(h),
458
+ cy: O(W),
459
+ r: 3,
460
+ fill: te,
461
+ style: d ? { cursor: "pointer" } : void 0,
462
+ onClick: d ? () => d(M.name, se + h, W) : void 0,
463
+ children: /* @__PURE__ */ e("title", { children: `${M.name}: ${W}` })
464
+ },
465
+ h
466
+ ))
467
+ ]
468
+ },
469
+ M.name
470
+ );
471
+ })
472
+ ] }),
473
+ g && /* @__PURE__ */ e("g", { transform: `translate(${J.left}, ${m})`, children: t.map((M, ae) => {
474
+ const te = ae * 120, r = x.has(M.name);
475
+ return /* @__PURE__ */ b(
476
+ "g",
477
+ {
478
+ transform: `translate(${te}, 10)`,
479
+ style: o ? { cursor: "pointer" } : void 0,
480
+ onClick: () => ee(M.name),
481
+ opacity: r ? 0.35 : 1,
482
+ children: [
483
+ /* @__PURE__ */ e("rect", { width: 12, height: 12, rx: 2, fill: M.color || ke[ae % ke.length] }),
484
+ /* @__PURE__ */ e(
485
+ "text",
486
+ {
487
+ x: 16,
488
+ y: 10,
489
+ className: "nice-chart__legend-text",
490
+ style: r ? { textDecoration: "line-through" } : void 0,
491
+ children: M.name
492
+ }
493
+ )
494
+ ]
495
+ },
496
+ M.name
497
+ );
498
+ }) })
499
+ ]
500
+ }
501
+ )
502
+ ] });
503
+ }, ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
504
+ __proto__: null,
505
+ NiceChart: je
506
+ }, Symbol.toStringTag, { value: "Module" }));
507
+ function Ge(t) {
508
+ if (!t.length)
509
+ return { categories: [], numericFields: [], sampleValues: {} };
510
+ const u = t[0], c = [], m = {};
511
+ let n = null;
512
+ for (const [g, w] of Object.entries(u))
513
+ typeof w == "number" ? (c.push(g), m[g] = t.map((A) => Number(A[g]) || 0)) : !n && (typeof w == "string" || w instanceof Date) && (n = g);
514
+ return { categories: n ? t.map((g) => String(g[n] || "")) : t.map((g, w) => `Item ${w + 1}`), numericFields: c, sampleValues: m };
515
+ }
516
+ function Xe(t, u) {
517
+ const { categories: c, numericFields: m, sampleValues: n } = Ge(t);
518
+ return { series: m.map((g, w) => ({
519
+ name: g.replace(/([A-Z])/g, " $1").replace(/^./, (A) => A.toUpperCase()).trim(),
520
+ data: n[g],
521
+ type: u === "area" ? "area" : u === "line" ? "line" : "bar"
522
+ })), categories: c };
523
+ }
524
+ _e(
525
+ function(t, u) {
526
+ const {
527
+ rawData: c,
528
+ enableAI: m = !0,
529
+ aiModel: n,
530
+ enableAutoType: g = !0,
531
+ enableInsights: w = !0,
532
+ dataDescription: A,
533
+ onChartSuggestion: L,
534
+ onInsights: l,
535
+ showAIToolbar: p = !0,
536
+ showInsightsOnLoad: y = !1,
537
+ series: f,
538
+ categories: N,
539
+ ...k
540
+ } = t, [o, d] = he("bar"), [s, $] = he(null), [_, S] = he([]), [x, v] = he(y), [i, z] = he(null), { t: a } = Ee(), j = Be(), {
541
+ suggestChartType: T,
542
+ generateInsights: B,
543
+ isLoading: Y
544
+ } = Ue(), G = m && j.isConfigured, { series: ee, categories: J } = c ? Xe(c, i || o) : { series: f || [], categories: N }, re = ce(async () => {
545
+ if (!G || !g)
546
+ return { type: "bar", reason: "Default", config: {} };
547
+ const C = c || (f != null && f.length ? f.flatMap((D) => D.data.map((F, X) => ({ [D.name]: F, index: X }))) : []);
548
+ try {
549
+ const D = await T(C, A), F = {
550
+ type: D.type,
551
+ reason: D.reason,
552
+ config: D.config
553
+ };
554
+ return $(F), d(F.type), L == null || L(F), F;
555
+ } catch {
556
+ return { type: "bar", reason: "Default fallback", config: {} };
557
+ }
558
+ }, [
559
+ G,
560
+ g,
561
+ c,
562
+ f,
563
+ A,
564
+ T,
565
+ L
566
+ ]), q = ce(async () => {
567
+ if (!G || !w)
568
+ return [];
569
+ const C = c || (f != null && f.length ? f.flatMap(
570
+ (D) => D.data.map((F, X) => ({ [D.name]: F, category: (N == null ? void 0 : N[X]) || X }))
571
+ ) : []);
572
+ try {
573
+ const D = await B(C, i || o);
574
+ return S(D), l == null || l(D), D;
575
+ } catch {
576
+ return [];
577
+ }
578
+ }, [
579
+ G,
580
+ w,
581
+ c,
582
+ f,
583
+ N,
584
+ o,
585
+ i,
586
+ B,
587
+ l
588
+ ]), Z = ce(
589
+ () => i || o,
590
+ [i, o]
591
+ );
592
+ Se(() => {
593
+ G && g && (c != null && c.length || f != null && f.length) && re();
594
+ }, [G, g, c, f]), Ie(u, () => ({
595
+ getSuggestion: re,
596
+ generateInsights: q,
597
+ getCurrentType: Z
598
+ }));
599
+ const se = [
600
+ { type: "bar", icon: "📊", label: "Bar" },
601
+ { type: "line", icon: "📈", label: "Line" },
602
+ { type: "area", icon: "🏔️", label: "Area" },
603
+ { type: "pie", icon: "🥧", label: "Pie" },
604
+ { type: "donut", icon: "🍩", label: "Donut" },
605
+ { type: "scatter", icon: "⭐", label: "Scatter" }
606
+ ], de = i || o;
607
+ return /* @__PURE__ */ b("div", { className: "nice-chart-ai", "data-testid": t["data-testid"], children: [
608
+ p && G && /* @__PURE__ */ b("div", { className: "nice-chart-ai__toolbar", children: [
609
+ /* @__PURE__ */ b("div", { className: "nice-chart-ai__toolbar-left", children: [
610
+ /* @__PURE__ */ e("span", { className: "nice-chart-ai__badge", children: "AI" }),
611
+ s && /* @__PURE__ */ b("div", { className: "nice-chart-ai__suggestion", children: [
612
+ /* @__PURE__ */ e("span", { className: "nice-chart-ai__suggestion-icon", children: "💡" }),
613
+ /* @__PURE__ */ b("span", { className: "nice-chart-ai__suggestion-text", children: [
614
+ a("chartAI.suggestedType", "Suggested:"),
615
+ " ",
616
+ s.type
617
+ ] }),
618
+ /* @__PURE__ */ b("span", { className: "nice-chart-ai__suggestion-reason", title: s.reason, children: [
619
+ "(",
620
+ s.reason,
621
+ ")"
622
+ ] })
623
+ ] }),
624
+ Y && /* @__PURE__ */ e("span", { className: "nice-chart-ai__loading", children: a("chartAI.analyzing", "Analyzing...") })
625
+ ] }),
626
+ /* @__PURE__ */ e("div", { className: "nice-chart-ai__toolbar-center", children: /* @__PURE__ */ e("div", { className: "nice-chart-ai__type-selector", children: se.filter((C) => ["bar", "line", "area"].includes(C.type)).map(({ type: C, icon: D, label: F }) => /* @__PURE__ */ e(
627
+ "button",
628
+ {
629
+ type: "button",
630
+ className: `nice-chart-ai__type-btn ${de === C ? "nice-chart-ai__type-btn--active" : ""}`,
631
+ onClick: () => z(C),
632
+ title: F,
633
+ children: D
634
+ },
635
+ C
636
+ )) }) }),
637
+ /* @__PURE__ */ b("div", { className: "nice-chart-ai__toolbar-right", children: [
638
+ /* @__PURE__ */ b(
639
+ "button",
640
+ {
641
+ type: "button",
642
+ className: "nice-chart-ai__auto-btn",
643
+ onClick: () => re(),
644
+ disabled: Y,
645
+ title: a("chartAI.autoDetect", "Auto-detect best chart type"),
646
+ children: [
647
+ "🔮 ",
648
+ a("chartAI.auto", "Auto")
649
+ ]
650
+ }
651
+ ),
652
+ w && /* @__PURE__ */ b(
653
+ "button",
654
+ {
655
+ type: "button",
656
+ className: "nice-chart-ai__insights-btn",
657
+ onClick: () => {
658
+ _.length || q(), v(!x);
659
+ },
660
+ disabled: Y,
661
+ title: a("chartAI.showInsights", "Show data insights"),
662
+ children: [
663
+ "💡 ",
664
+ a("chartAI.insights", "Insights")
665
+ ]
666
+ }
667
+ )
668
+ ] })
669
+ ] }),
670
+ /* @__PURE__ */ e("div", { className: "nice-chart-ai__chart-wrapper", children: /* @__PURE__ */ e(je, { series: ee, categories: J, ...k }) }),
671
+ x && _.length > 0 && /* @__PURE__ */ b("div", { className: "nice-chart-ai__insights", children: [
672
+ /* @__PURE__ */ b("div", { className: "nice-chart-ai__insights-header", children: [
673
+ /* @__PURE__ */ b("h4", { children: [
674
+ "💡 ",
675
+ a("chartAI.dataInsights", "Data Insights")
676
+ ] }),
677
+ /* @__PURE__ */ e(
678
+ "button",
679
+ {
680
+ type: "button",
681
+ className: "nice-chart-ai__insights-close",
682
+ onClick: () => v(!1),
683
+ children: "✕"
684
+ }
685
+ )
686
+ ] }),
687
+ /* @__PURE__ */ e("ul", { className: "nice-chart-ai__insights-list", children: _.map((C, D) => /* @__PURE__ */ b("li", { className: "nice-chart-ai__insight", children: [
688
+ /* @__PURE__ */ e("span", { className: "nice-chart-ai__insight-icon", children: "•" }),
689
+ C
690
+ ] }, D)) }),
691
+ /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights-footer", children: /* @__PURE__ */ b(
692
+ "button",
693
+ {
694
+ type: "button",
695
+ className: "nice-chart-ai__refresh",
696
+ onClick: () => q(),
697
+ disabled: Y,
698
+ children: [
699
+ "🔄 ",
700
+ a("chartAI.refresh", "Refresh")
701
+ ]
702
+ }
703
+ ) })
704
+ ] }),
705
+ x && Y && /* @__PURE__ */ e("div", { className: "nice-chart-ai__insights nice-chart-ai__insights--loading", children: /* @__PURE__ */ b("div", { className: "nice-chart-ai__loading-content", children: [
706
+ /* @__PURE__ */ e("span", { className: "nice-chart-ai__spinner" }),
707
+ a("chartAI.generatingInsights", "Generating insights...")
708
+ ] }) })
709
+ ] });
710
+ }
711
+ );
712
+ function Ze(t, u) {
713
+ const c = t ? typeof t == "number" ? new Date(t) : new Date(t) : /* @__PURE__ */ new Date(), m = (L) => L.toString().padStart(2, "0"), n = m(c.getHours()), g = m(c.getMinutes()), w = m(c.getSeconds()), A = c.getMilliseconds().toString().padStart(3, "0");
714
+ switch (u) {
715
+ case "HH:mm:ss":
716
+ return `${n}:${g}:${w}`;
717
+ case "HH:mm":
718
+ return `${n}:${g}`;
719
+ case "mm:ss":
720
+ return `${g}:${w}`;
721
+ case "ss.SSS":
722
+ return `${w}.${A}`;
723
+ case "ISO":
724
+ return c.toISOString();
725
+ default:
726
+ return `${n}:${g}:${w}`;
727
+ }
728
+ }
729
+ function Oe(t) {
730
+ if (t.length === 0)
731
+ return null;
732
+ const u = Math.min(...t), c = Math.max(...t), m = t.reduce((g, w) => g + w, 0) / t.length, n = t[t.length - 1];
733
+ return { min: u, max: c, avg: m, current: n, count: t.length };
734
+ }
735
+ const Ye = _e(
736
+ ({
737
+ series: t,
738
+ maxPoints: u = 100,
739
+ slidingWindow: c = !0,
740
+ refreshRate: m = 16,
741
+ dataSource: n,
742
+ width: g = 600,
743
+ height: w = 400,
744
+ title: A,
745
+ showLegend: L = !0,
746
+ showGrid: l = !0,
747
+ yAxisLabel: p,
748
+ xAxisLabel: y,
749
+ stacked: f,
750
+ zoomable: N,
751
+ crosshair: k,
752
+ annotations: o = [],
753
+ legendInteractive: d,
754
+ onDataPointClick: s,
755
+ exportable: $,
756
+ showControls: _ = !0,
757
+ showStatus: S = !0,
758
+ initialPaused: x = !1,
759
+ onDataReceived: v,
760
+ onDataDropped: i,
761
+ timeFormat: z = "HH:mm:ss",
762
+ showStats: a,
763
+ thresholds: j = [],
764
+ className: T,
765
+ style: B
766
+ }, Y) => {
767
+ const [G, ee] = he(() => {
768
+ var E;
769
+ const P = /* @__PURE__ */ new Map();
770
+ for (const ie of t)
771
+ P.set(ie.name, ((E = ie.initialData) == null ? void 0 : E.slice()) ?? []);
772
+ return P;
773
+ }), [J, re] = he([]), [q, Z] = he(x), [se, de] = he(!1), C = Ne([]), D = Ne(Date.now()), F = Ne(null), X = ce(() => {
774
+ const P = C.current;
775
+ P.length !== 0 && (C.current = [], ee((E) => {
776
+ const ie = new Map(E);
777
+ for (const fe of P) {
778
+ const ge = ie.get(fe.series);
779
+ if (!ge)
780
+ continue;
781
+ const xe = [...ge, fe.value];
782
+ if (c && xe.length > u) {
783
+ const ve = xe.length - u;
784
+ i == null || i(ve, fe.series), xe.splice(0, ve);
785
+ }
786
+ ie.set(fe.series, xe);
787
+ }
788
+ return ie;
789
+ }), P.length > 0 && re((E) => {
790
+ const ie = [...E];
791
+ for (const fe of P) {
792
+ const ge = fe.category ?? Ze(fe.timestamp, z);
793
+ ie.push(ge);
794
+ }
795
+ return c && ie.length > u && ie.splice(0, ie.length - u), ie;
796
+ }));
797
+ }, [c, u, z, i]), K = ce(() => {
798
+ const P = Date.now();
799
+ P - D.current >= m && (X(), D.current = P), F.current = requestAnimationFrame(K);
800
+ }, [m, X]);
801
+ Se(() => (q || (F.current = requestAnimationFrame(K)), () => {
802
+ F.current !== null && (cancelAnimationFrame(F.current), F.current = null);
803
+ }), [q, K]);
804
+ const V = ce(
805
+ (P) => {
806
+ if (q)
807
+ return;
808
+ const E = "points" in P ? P.points : [P];
809
+ for (const ie of E)
810
+ G.has(ie.series) && (C.current.push(ie), v == null || v(ie));
811
+ },
812
+ [q, G, v]
813
+ );
814
+ Se(() => {
815
+ if (!n)
816
+ return;
817
+ const P = n.subscribe(V);
818
+ let E;
819
+ return n.onStatusChange ? E = n.onStatusChange(de) : de(!0), n.fetchHistory && n.fetchHistory(u).then((ie) => {
820
+ for (const fe of ie)
821
+ C.current.push(fe);
822
+ X();
823
+ }), () => {
824
+ P(), E == null || E();
825
+ };
826
+ }, [n, V, u, X]);
827
+ const O = ue(() => t.map((P) => ({
828
+ name: P.name,
829
+ color: P.color,
830
+ type: P.type,
831
+ data: G.get(P.name) ?? []
832
+ })), [t, G]), U = ue(() => {
833
+ const P = [...o];
834
+ for (const E of j)
835
+ P.push({
836
+ type: "line",
837
+ value: E.value,
838
+ color: E.color,
839
+ label: E.label,
840
+ dash: E.style === "dashed" ? "5,5" : E.style === "dotted" ? "2,2" : void 0
841
+ });
842
+ return P;
843
+ }, [o, j]);
844
+ Ie(
845
+ Y,
846
+ () => ({
847
+ pause() {
848
+ Z(!0);
849
+ },
850
+ resume() {
851
+ Z(!1);
852
+ },
853
+ isPaused() {
854
+ return q;
855
+ },
856
+ clear() {
857
+ ee((P) => {
858
+ const E = new Map(P);
859
+ for (const ie of E.keys())
860
+ E.set(ie, []);
861
+ return E;
862
+ }), re([]), C.current = [];
863
+ },
864
+ addPoint(P) {
865
+ V(P);
866
+ },
867
+ addPoints(P) {
868
+ V({ points: P });
869
+ },
870
+ getData(P) {
871
+ return G.get(P) ?? [];
872
+ },
873
+ getCategories() {
874
+ return J;
875
+ },
876
+ exportData() {
877
+ return { series: O, categories: J };
878
+ },
879
+ getStats(P) {
880
+ const E = G.get(P);
881
+ return E ? Oe(E) : null;
882
+ }
883
+ }),
884
+ [q, G, J, O, V]
885
+ );
886
+ const Q = ue(() => {
887
+ if (!a)
888
+ return null;
889
+ const P = {};
890
+ for (const [E, ie] of G)
891
+ P[E] = Oe(ie);
892
+ return P;
893
+ }, [a, G]);
894
+ return /* @__PURE__ */ b("div", { className: T, style: { position: "relative", ...B }, children: [
895
+ S && /* @__PURE__ */ b(
896
+ "div",
897
+ {
898
+ style: {
899
+ position: "absolute",
900
+ top: 8,
901
+ right: 8,
902
+ display: "flex",
903
+ alignItems: "center",
904
+ gap: 4,
905
+ fontSize: 12,
906
+ color: se ? "var(--color-success, #22c55e)" : "var(--color-error, #ef4444)",
907
+ zIndex: 10
908
+ },
909
+ children: [
910
+ /* @__PURE__ */ e(
911
+ "span",
912
+ {
913
+ style: {
914
+ width: 8,
915
+ height: 8,
916
+ borderRadius: "50%",
917
+ backgroundColor: se ? "var(--color-success, #22c55e)" : "var(--color-error, #ef4444)"
918
+ }
919
+ }
920
+ ),
921
+ se ? "Live" : "Disconnected"
922
+ ]
923
+ }
924
+ ),
925
+ _ && /* @__PURE__ */ e(
926
+ "div",
927
+ {
928
+ style: {
929
+ position: "absolute",
930
+ top: 8,
931
+ left: 8,
932
+ display: "flex",
933
+ gap: 4,
934
+ zIndex: 10
935
+ },
936
+ children: /* @__PURE__ */ e(
937
+ "button",
938
+ {
939
+ onClick: () => Z((P) => !P),
940
+ style: {
941
+ padding: "4px 8px",
942
+ fontSize: 12,
943
+ border: "1px solid var(--border-color, #ddd)",
944
+ borderRadius: 4,
945
+ background: q ? "var(--warning-bg, #fef3c7)" : "var(--bg-primary, #fff)",
946
+ cursor: "pointer"
947
+ },
948
+ title: q ? "Resume" : "Pause",
949
+ children: q ? "▶" : "⏸"
950
+ }
951
+ )
952
+ }
953
+ ),
954
+ a && Q && /* @__PURE__ */ e(
955
+ "div",
956
+ {
957
+ style: {
958
+ position: "absolute",
959
+ bottom: 50,
960
+ right: 8,
961
+ background: "var(--nice-overlay-light-90, rgba(255, 255, 255, 0.9))",
962
+ border: "1px solid var(--border-color, #ddd)",
963
+ borderRadius: 4,
964
+ padding: 8,
965
+ fontSize: 11,
966
+ zIndex: 10
967
+ },
968
+ children: Object.entries(Q).map(
969
+ ([P, E]) => E ? /* @__PURE__ */ b("div", { style: { marginBottom: 4 }, children: [
970
+ /* @__PURE__ */ e("strong", { children: P }),
971
+ /* @__PURE__ */ b("div", { children: [
972
+ "Min: ",
973
+ E.min.toFixed(2),
974
+ " | Max: ",
975
+ E.max.toFixed(2)
976
+ ] }),
977
+ /* @__PURE__ */ b("div", { children: [
978
+ "Avg: ",
979
+ E.avg.toFixed(2),
980
+ " | Now: ",
981
+ E.current.toFixed(2)
982
+ ] })
983
+ ] }, P) : null
984
+ )
985
+ }
986
+ ),
987
+ /* @__PURE__ */ e(
988
+ je,
989
+ {
990
+ series: O,
991
+ categories: J,
992
+ width: g,
993
+ height: w,
994
+ title: A,
995
+ showLegend: L,
996
+ showGrid: l,
997
+ yAxisLabel: p,
998
+ xAxisLabel: y,
999
+ stacked: f,
1000
+ zoomable: N,
1001
+ crosshair: k,
1002
+ annotations: U,
1003
+ legendInteractive: d,
1004
+ onDataPointClick: s,
1005
+ exportable: $
1006
+ }
1007
+ )
1008
+ ] });
1009
+ }
1010
+ );
1011
+ Ye.displayName = "NiceLiveChart";
1012
+ const ye = ["#3b82f6", "#ef4444", "#22c55e", "#f59e0b", "#8b5cf6", "#ec4899", "#06b6d4", "#84cc16"], ft = ({
1013
+ data: t,
1014
+ width: u = 400,
1015
+ height: c = 400,
1016
+ innerRadius: m = 0,
1017
+ title: n,
1018
+ showLegend: g = !0,
1019
+ showLabels: w = !0,
1020
+ className: A,
1021
+ style: L
1022
+ }) => {
1023
+ const l = u / 2, p = (c - (g ? 30 : 0)) / 2 + (n ? 10 : 0), y = Math.min(l, p) - 40, f = t.reduce((o, d) => o + d.value, 0);
1024
+ let N = -Math.PI / 2;
1025
+ const k = t.map((o, d) => {
1026
+ const s = o.value / (f || 1) * Math.PI * 2, $ = N;
1027
+ N += s;
1028
+ const _ = N, S = ($ + _) / 2, x = l + y * Math.cos($), v = p + y * Math.sin($), i = l + y * Math.cos(_), z = p + y * Math.sin(_), a = s > Math.PI ? 1 : 0, j = o.color || ye[d % ye.length];
1029
+ let T;
1030
+ if (m > 0) {
1031
+ const ee = l + m * Math.cos($), J = p + m * Math.sin($), re = l + m * Math.cos(_), q = p + m * Math.sin(_);
1032
+ T = `M${x},${v} A${y},${y} 0 ${a},1 ${i},${z} L${re},${q} A${m},${m} 0 ${a},0 ${ee},${J} Z`;
1033
+ } else
1034
+ T = `M${l},${p} L${x},${v} A${y},${y} 0 ${a},1 ${i},${z} Z`;
1035
+ const B = l + y * 0.7 * Math.cos(S), Y = p + y * 0.7 * Math.sin(S), G = f > 0 ? Math.round(o.value / f * 100) : 0;
1036
+ return { ...o, path: T, labelX: B, labelY: Y, pct: G, color: j };
1037
+ });
1038
+ return /* @__PURE__ */ e("div", { className: `nice-piechart ${A || ""}`, style: L, children: /* @__PURE__ */ b(
1039
+ "svg",
1040
+ {
1041
+ viewBox: `0 0 ${u} ${c}`,
1042
+ preserveAspectRatio: "xMidYMid meet",
1043
+ width: "100%",
1044
+ height: "100%",
1045
+ style: { display: "block", maxWidth: "100%", maxHeight: "100%" },
1046
+ className: "nice-piechart__svg",
1047
+ children: [
1048
+ n && /* @__PURE__ */ e("text", { x: l, y: 20, textAnchor: "middle", className: "nice-chart__title", children: n }),
1049
+ k.map((o, d) => /* @__PURE__ */ b("g", { children: [
1050
+ /* @__PURE__ */ e("path", { d: o.path, fill: o.color, stroke: "var(--bg-primary, #fff)", strokeWidth: 2, children: /* @__PURE__ */ e("title", { children: `${o.label}: ${o.value} (${o.pct}%)` }) }),
1051
+ w && o.pct >= 5 && /* @__PURE__ */ b(
1052
+ "text",
1053
+ {
1054
+ x: o.labelX,
1055
+ y: o.labelY,
1056
+ textAnchor: "middle",
1057
+ dominantBaseline: "middle",
1058
+ className: "nice-piechart__label",
1059
+ children: [
1060
+ o.pct,
1061
+ "%"
1062
+ ]
1063
+ }
1064
+ )
1065
+ ] }, d)),
1066
+ g && /* @__PURE__ */ e("g", { transform: `translate(10, ${c - 25})`, children: t.map((o, d) => /* @__PURE__ */ b("g", { transform: `translate(${d * 100}, 0)`, children: [
1067
+ /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: o.color || ye[d % ye.length] }),
1068
+ /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: o.label })
1069
+ ] }, d)) })
1070
+ ]
1071
+ }
1072
+ ) });
1073
+ }, gt = ({
1074
+ series: t,
1075
+ categories: u,
1076
+ width: c = 400,
1077
+ height: m = 400,
1078
+ maxValue: n,
1079
+ title: g,
1080
+ showLegend: w = !0,
1081
+ className: A,
1082
+ style: L
1083
+ }) => {
1084
+ const l = c / 2, p = (m - (w ? 30 : 0)) / 2 + (g ? 10 : 0), y = Math.min(l, p) - 60, f = u.length, N = n ?? Math.max(...t.flatMap((s) => s.data), 1), k = Math.PI * 2 / f, o = 5, d = (s, $) => {
1085
+ const _ = s * k - Math.PI / 2, S = $ / N * y;
1086
+ return { x: l + S * Math.cos(_), y: p + S * Math.sin(_) };
1087
+ };
1088
+ return /* @__PURE__ */ e("div", { className: `nice-polarchart ${A || ""}`, style: L, children: /* @__PURE__ */ b("svg", { width: c, height: m, className: "nice-polarchart__svg", children: [
1089
+ g && /* @__PURE__ */ e("text", { x: l, y: 20, textAnchor: "middle", className: "nice-chart__title", children: g }),
1090
+ Array.from({ length: o }, (s, $) => {
1091
+ const _ = y * (($ + 1) / o);
1092
+ return /* @__PURE__ */ e(
1093
+ "circle",
1094
+ {
1095
+ cx: l,
1096
+ cy: p,
1097
+ r: _,
1098
+ fill: "none",
1099
+ stroke: "var(--border-color, #ddd)",
1100
+ strokeWidth: 0.5
1101
+ },
1102
+ $
1103
+ );
1104
+ }),
1105
+ u.map((s, $) => {
1106
+ const _ = d($, N), S = d($, N * 1.22), x = $ * k - Math.PI / 2, v = Math.cos(x), i = Math.sin(x), z = v > 0.2 ? "start" : v < -0.2 ? "end" : "middle", a = i > 0.2 ? "hanging" : i < -0.2 ? "auto" : "middle";
1107
+ return /* @__PURE__ */ b("g", { children: [
1108
+ /* @__PURE__ */ e(
1109
+ "line",
1110
+ {
1111
+ x1: l,
1112
+ y1: p,
1113
+ x2: _.x,
1114
+ y2: _.y,
1115
+ stroke: "var(--border-color, #ddd)",
1116
+ strokeWidth: 0.5
1117
+ }
1118
+ ),
1119
+ /* @__PURE__ */ e(
1120
+ "text",
1121
+ {
1122
+ x: S.x,
1123
+ y: S.y,
1124
+ textAnchor: z,
1125
+ dominantBaseline: a,
1126
+ className: "nice-chart__axis-label nice-chart__axis-label--polar",
1127
+ children: s
1128
+ }
1129
+ )
1130
+ ] }, $);
1131
+ }),
1132
+ t.map((s, $) => {
1133
+ const _ = s.color || ye[$ % ye.length], S = s.data.map((x, v) => {
1134
+ const i = d(v, x);
1135
+ return `${i.x},${i.y}`;
1136
+ }).join(" ");
1137
+ return /* @__PURE__ */ b("g", { children: [
1138
+ /* @__PURE__ */ e(
1139
+ "polygon",
1140
+ {
1141
+ points: S,
1142
+ fill: s.fill !== !1 ? _ : "none",
1143
+ fillOpacity: 0.15,
1144
+ stroke: _,
1145
+ strokeWidth: 2
1146
+ }
1147
+ ),
1148
+ s.data.map((x, v) => {
1149
+ const i = d(v, x);
1150
+ return /* @__PURE__ */ e("circle", { cx: i.x, cy: i.y, r: 3, fill: _, children: /* @__PURE__ */ e("title", { children: `${s.name} - ${u[v]}: ${x}` }) }, v);
1151
+ })
1152
+ ] }, s.name);
1153
+ }),
1154
+ w && /* @__PURE__ */ e("g", { transform: `translate(10, ${m - 25})`, children: t.map((s, $) => /* @__PURE__ */ b("g", { transform: `translate(${$ * 100}, 0)`, children: [
1155
+ /* @__PURE__ */ e("rect", { width: 10, height: 10, rx: 2, fill: s.color || ye[$ % ye.length] }),
1156
+ /* @__PURE__ */ e("text", { x: 14, y: 9, className: "nice-chart__legend-text", children: s.name })
1157
+ ] }, $)) })
1158
+ ] }) });
1159
+ }, pt = ({
1160
+ value: t,
1161
+ min: u = 0,
1162
+ max: c = 100,
1163
+ width: m = 200,
1164
+ height: n = 200,
1165
+ startAngle: g = 225,
1166
+ endAngle: w = -45,
1167
+ color: A = "var(--color-primary, #3b82f6)",
1168
+ trackColor: L,
1169
+ label: l,
1170
+ formatValue: p,
1171
+ ranges: y,
1172
+ className: f,
1173
+ style: N
1174
+ }) => {
1175
+ const k = m / 2, o = n / 2, d = Math.min(k, o) - 20, s = Math.max(0, Math.min(1, (t - u) / (c - u || 1))), $ = (a) => a * Math.PI / 180, _ = (g - w + 360) % 360 || 360, S = (a) => ({
1176
+ x: k + d * Math.cos($(a)),
1177
+ y: o - d * Math.sin($(a))
1178
+ }), x = (a, j) => {
1179
+ const T = S(a), B = S(j), Y = (a - j + 360) % 360 > 180 ? 1 : 0;
1180
+ return `M${T.x},${T.y} A${d},${d} 0 ${Y},1 ${B.x},${B.y}`;
1181
+ }, v = g - s * _, i = S(v);
1182
+ let z = A;
1183
+ if (y) {
1184
+ for (const a of y)
1185
+ if (t >= a.start && t <= a.end) {
1186
+ z = a.color;
1187
+ break;
1188
+ }
1189
+ }
1190
+ return /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--circular ${f || ""}`, style: N, children: /* @__PURE__ */ b("svg", { width: m, height: n, children: [
1191
+ /* @__PURE__ */ e(
1192
+ "path",
1193
+ {
1194
+ d: x(g, w),
1195
+ fill: "none",
1196
+ stroke: L || "var(--border-color, #e2e8f0)",
1197
+ strokeWidth: 12,
1198
+ strokeLinecap: "round"
1199
+ }
1200
+ ),
1201
+ s > 0 && /* @__PURE__ */ e(
1202
+ "path",
1203
+ {
1204
+ d: x(g, v),
1205
+ fill: "none",
1206
+ stroke: z,
1207
+ strokeWidth: 12,
1208
+ strokeLinecap: "round"
1209
+ }
1210
+ ),
1211
+ /* @__PURE__ */ e(
1212
+ "line",
1213
+ {
1214
+ x1: k,
1215
+ y1: o,
1216
+ x2: i.x,
1217
+ y2: i.y,
1218
+ stroke: "var(--text-primary, #333)",
1219
+ strokeWidth: 2,
1220
+ strokeLinecap: "round"
1221
+ }
1222
+ ),
1223
+ /* @__PURE__ */ e("circle", { cx: k, cy: o, r: 4, fill: "var(--text-primary, #333)" }),
1224
+ /* @__PURE__ */ e("text", { x: k, y: o + d * 0.6, textAnchor: "middle", className: "nice-gauge__value", children: p ? p(t) : t }),
1225
+ l && /* @__PURE__ */ e("text", { x: k, y: o + d * 0.95, textAnchor: "middle", className: "nice-gauge__label", children: l })
1226
+ ] }) });
1227
+ }, xt = ({
1228
+ value: t,
1229
+ min: u = 0,
1230
+ max: c = 100,
1231
+ width: m = 300,
1232
+ height: n = 60,
1233
+ orientation: g = "horizontal",
1234
+ color: w = "var(--color-primary, #3b82f6)",
1235
+ label: A,
1236
+ formatValue: L,
1237
+ ranges: l,
1238
+ showTicks: p = !0,
1239
+ tickCount: y = 5,
1240
+ className: f,
1241
+ style: N
1242
+ }) => {
1243
+ const k = g === "horizontal", o = k ? m - 40 : n - 40, d = Math.max(0, Math.min(1, (t - u) / (c - u || 1))), s = 10;
1244
+ let $ = w;
1245
+ if (l) {
1246
+ for (const S of l)
1247
+ if (t >= S.start && t <= S.end) {
1248
+ $ = S.color;
1249
+ break;
1250
+ }
1251
+ }
1252
+ const _ = Array.from(
1253
+ { length: y },
1254
+ (S, x) => u + (c - u) * (x / (y - 1))
1255
+ );
1256
+ return k ? /* @__PURE__ */ e("div", { className: `nice-gauge nice-gauge--linear ${f || ""}`, style: N, children: /* @__PURE__ */ b("svg", { width: m, height: n, children: [
1257
+ /* @__PURE__ */ e(
1258
+ "text",
1259
+ {
1260
+ x: 20 + o * d,
1261
+ y: 14,
1262
+ textAnchor: "middle",
1263
+ className: "nice-gauge__value",
1264
+ style: { fontSize: 12 },
1265
+ children: L ? L(t) : t
1266
+ }
1267
+ ),
1268
+ /* @__PURE__ */ e(
1269
+ "rect",
1270
+ {
1271
+ x: 20,
1272
+ y: n / 2 - s / 2,
1273
+ width: o,
1274
+ height: s,
1275
+ rx: 5,
1276
+ fill: "var(--border-color, #e2e8f0)"
1277
+ }
1278
+ ),
1279
+ /* @__PURE__ */ e(
1280
+ "rect",
1281
+ {
1282
+ x: 20,
1283
+ y: n / 2 - s / 2,
1284
+ width: o * d,
1285
+ height: s,
1286
+ rx: 5,
1287
+ fill: $
1288
+ }
1289
+ ),
1290
+ /* @__PURE__ */ e(
1291
+ "polygon",
1292
+ {
1293
+ points: `${20 + o * d},${n / 2 - s / 2 - 2} ${20 + o * d - 5},${n / 2 - s / 2 - 8} ${20 + o * d + 5},${n / 2 - s / 2 - 8}`,
1294
+ fill: "var(--text-primary, #333)"
1295
+ }
1296
+ ),
1297
+ p && _.map((S, x) => {
1298
+ const v = 20 + (S - u) / (c - u) * o;
1299
+ return /* @__PURE__ */ e(
1300
+ "text",
1301
+ {
1302
+ x: v,
1303
+ y: n / 2 + s / 2 + 12,
1304
+ textAnchor: "middle",
1305
+ className: "nice-gauge__tick",
1306
+ children: S
1307
+ },
1308
+ x
1309
+ );
1310
+ }),
1311
+ A && /* @__PURE__ */ e("text", { x: m / 2, y: n - 2, textAnchor: "middle", className: "nice-gauge__label", children: A })
1312
+ ] }) }) : /* @__PURE__ */ e(
1313
+ "div",
1314
+ {
1315
+ className: `nice-gauge nice-gauge--linear nice-gauge--vertical ${f || ""}`,
1316
+ style: N,
1317
+ children: /* @__PURE__ */ b("svg", { width: m, height: n, children: [
1318
+ /* @__PURE__ */ e(
1319
+ "rect",
1320
+ {
1321
+ x: m / 2 - s / 2,
1322
+ y: 20,
1323
+ width: s,
1324
+ height: o,
1325
+ rx: 5,
1326
+ fill: "var(--border-color, #e2e8f0)"
1327
+ }
1328
+ ),
1329
+ /* @__PURE__ */ e(
1330
+ "rect",
1331
+ {
1332
+ x: m / 2 - s / 2,
1333
+ y: 20 + o * (1 - d),
1334
+ width: s,
1335
+ height: o * d,
1336
+ rx: 5,
1337
+ fill: $
1338
+ }
1339
+ ),
1340
+ /* @__PURE__ */ e("text", { x: m / 2, y: 14, textAnchor: "middle", className: "nice-gauge__value", children: L ? L(t) : t }),
1341
+ A && /* @__PURE__ */ e("text", { x: m / 2, y: n - 4, textAnchor: "middle", className: "nice-gauge__label", children: A })
1342
+ ] })
1343
+ }
1344
+ );
1345
+ }, yt = ({
1346
+ items: t,
1347
+ min: u = 0,
1348
+ max: c = 100,
1349
+ width: m = 300,
1350
+ height: n = 300,
1351
+ startAngle: g = 225,
1352
+ endAngle: w = -45,
1353
+ formatValue: A,
1354
+ title: L,
1355
+ className: l,
1356
+ style: p
1357
+ }) => {
1358
+ const y = m / 2, f = n / 2, N = Math.min(y, f) - 30, k = Math.min(20, N / (t.length + 1)), o = 4, d = (_) => _ * Math.PI / 180, s = (g - w + 360) % 360 || 360, $ = (_, S, x) => {
1359
+ const v = y + _ * Math.cos(d(S)), i = f - _ * Math.sin(d(S)), z = y + _ * Math.cos(d(x)), a = f - _ * Math.sin(d(x)), j = (S - x + 360) % 360;
1360
+ return `M${v},${i} A${_},${_} 0 ${j > 180 ? 1 : 0},1 ${z},${a}`;
1361
+ };
1362
+ return /* @__PURE__ */ e("div", { className: `nice-bargauge ${l || ""}`, style: p, children: /* @__PURE__ */ b("svg", { width: m, height: n, children: [
1363
+ L && /* @__PURE__ */ e("text", { x: y, y: 20, textAnchor: "middle", className: "nice-chart__title", children: L }),
1364
+ t.map((_, S) => {
1365
+ const x = N - S * (k + o), v = Math.max(0, Math.min(1, (_.value - u) / (c - u || 1))), i = g - v * s, z = _.color || ye[S % ye.length];
1366
+ return /* @__PURE__ */ b("g", { children: [
1367
+ /* @__PURE__ */ e(
1368
+ "path",
1369
+ {
1370
+ d: $(x, g, w),
1371
+ fill: "none",
1372
+ stroke: "var(--border-color, #e2e8f0)",
1373
+ strokeWidth: k,
1374
+ strokeLinecap: "round"
1375
+ }
1376
+ ),
1377
+ v > 0 && /* @__PURE__ */ e(
1378
+ "path",
1379
+ {
1380
+ d: $(x, g, i),
1381
+ fill: "none",
1382
+ stroke: z,
1383
+ strokeWidth: k,
1384
+ strokeLinecap: "round"
1385
+ }
1386
+ )
1387
+ ] }, S);
1388
+ }),
1389
+ /* @__PURE__ */ e("g", { children: t.map((_, S) => /* @__PURE__ */ b(
1390
+ "text",
1391
+ {
1392
+ x: y,
1393
+ y: f - ((t.length - 1) / 2 - S) * 16,
1394
+ textAnchor: "middle",
1395
+ dominantBaseline: "middle",
1396
+ className: "nice-gauge__value",
1397
+ style: { fontSize: 12 },
1398
+ children: [
1399
+ _.label ? `${_.label}: ` : "",
1400
+ A ? A(_.value) : _.value
1401
+ ]
1402
+ },
1403
+ S
1404
+ )) })
1405
+ ] }) });
1406
+ }, bt = ({
1407
+ data: t,
1408
+ width: u = 120,
1409
+ height: c = 30,
1410
+ type: m = "line",
1411
+ color: n = "var(--color-primary, #3b82f6)",
1412
+ showMinMax: g,
1413
+ showLastPoint: w = !0,
1414
+ className: A,
1415
+ style: L
1416
+ }) => {
1417
+ if (t.length === 0)
1418
+ return null;
1419
+ const l = 2, p = Math.min(...t), y = Math.max(...t), f = y - p || 1, N = u - l * 2, k = c - l * 2, o = (x) => l + x / (t.length - 1 || 1) * N, d = (x) => l + k - (x - p) / f * k;
1420
+ if (m === "bar") {
1421
+ const x = Math.max(1, N / t.length - 1);
1422
+ return /* @__PURE__ */ e(
1423
+ "svg",
1424
+ {
1425
+ width: u,
1426
+ height: c,
1427
+ className: `nice-sparkline ${A || ""}`,
1428
+ style: L,
1429
+ children: t.map((v, i) => /* @__PURE__ */ e(
1430
+ "rect",
1431
+ {
1432
+ x: l + i / t.length * N,
1433
+ y: d(v),
1434
+ width: x,
1435
+ height: k - (d(v) - l),
1436
+ fill: n,
1437
+ rx: 1
1438
+ },
1439
+ i
1440
+ ))
1441
+ }
1442
+ );
1443
+ }
1444
+ const s = t.map((x, v) => `${o(v)},${d(x)}`).join(" "), $ = t.indexOf(p), _ = t.indexOf(y), S = t.length - 1;
1445
+ return /* @__PURE__ */ b(
1446
+ "svg",
1447
+ {
1448
+ width: u,
1449
+ height: c,
1450
+ className: `nice-sparkline ${A || ""}`,
1451
+ style: L,
1452
+ children: [
1453
+ m === "area" && /* @__PURE__ */ e(
1454
+ "polygon",
1455
+ {
1456
+ points: `${o(0)},${l + k} ${s} ${o(S)},${l + k}`,
1457
+ fill: n,
1458
+ opacity: 0.15
1459
+ }
1460
+ ),
1461
+ /* @__PURE__ */ e("polyline", { points: s, fill: "none", stroke: n, strokeWidth: 1.5 }),
1462
+ g && /* @__PURE__ */ e("circle", { cx: o($), cy: d(p), r: 2, fill: "var(--nice-danger, #ef4444)" }),
1463
+ g && /* @__PURE__ */ e("circle", { cx: o(_), cy: d(y), r: 2, fill: "var(--nice-success, #22c55e)" }),
1464
+ w && /* @__PURE__ */ e("circle", { cx: o(S), cy: d(t[S]), r: 2, fill: n })
1465
+ ]
1466
+ }
1467
+ );
1468
+ }, qe = {
1469
+ sm: { width: 160, height: 22, fontSize: 11 },
1470
+ md: { width: 220, height: 32, fontSize: 12 },
1471
+ lg: { width: 320, height: 44, fontSize: 14 }
1472
+ }, vt = ({
1473
+ value: t,
1474
+ target: u,
1475
+ min: c = 0,
1476
+ max: m = 100,
1477
+ width: n,
1478
+ height: g,
1479
+ color: w = "var(--color-primary, #3b82f6)",
1480
+ targetColor: A = "var(--color-error, #ef4444)",
1481
+ size: L = "md",
1482
+ label: l,
1483
+ labelPlacement: p = "top",
1484
+ showValue: y = !1,
1485
+ showTarget: f = !1,
1486
+ formatValue: N = ($) => String($),
1487
+ state: k = "normal",
1488
+ errorMessage: o,
1489
+ className: d,
1490
+ style: s
1491
+ }) => {
1492
+ const $ = qe[L], _ = n ?? $.width, S = g ?? $.height, x = $.fontSize, v = 4, i = _ - v * 2, z = f && u != null ? x + 4 : v, a = f && u != null ? S + (z - v) : S, j = a - z - v, T = Math.max(0, Math.min(1, (t - c) / (m - c || 1))), B = u != null ? Math.max(0, Math.min(1, (u - c) / (m - c || 1))) : null, Y = () => k === "error" ? /* @__PURE__ */ e(
1493
+ "div",
1494
+ {
1495
+ role: "alert",
1496
+ style: {
1497
+ width: _,
1498
+ height: a,
1499
+ display: "flex",
1500
+ alignItems: "center",
1501
+ justifyContent: "center",
1502
+ border: "1px dashed var(--color-error, #ef4444)",
1503
+ borderRadius: 4,
1504
+ color: "var(--color-error, #ef4444)",
1505
+ fontSize: x,
1506
+ padding: "0 8px",
1507
+ boxSizing: "border-box"
1508
+ },
1509
+ children: o ?? "Error"
1510
+ }
1511
+ ) : k === "loading" ? /* @__PURE__ */ e(
1512
+ "div",
1513
+ {
1514
+ role: "status",
1515
+ "aria-label": "Loading",
1516
+ className: "nice-bullet__skeleton",
1517
+ style: {
1518
+ width: _,
1519
+ height: a,
1520
+ borderRadius: 4,
1521
+ background: "linear-gradient(90deg, var(--bg-tertiary, #e5e7eb) 25%, var(--bg-secondary, #f3f4f6) 50%, var(--bg-tertiary, #e5e7eb) 75%)",
1522
+ backgroundSize: "200% 100%",
1523
+ animation: "nice-bullet-shimmer 1.4s linear infinite"
1524
+ }
1525
+ }
1526
+ ) : /* @__PURE__ */ b(
1527
+ "svg",
1528
+ {
1529
+ width: _,
1530
+ height: a,
1531
+ role: "img",
1532
+ "aria-label": typeof l == "string" ? l : void 0,
1533
+ children: [
1534
+ /* @__PURE__ */ e(
1535
+ "rect",
1536
+ {
1537
+ x: v,
1538
+ y: z,
1539
+ width: i,
1540
+ height: j,
1541
+ rx: 3,
1542
+ fill: "var(--border-color, #e2e8f0)"
1543
+ }
1544
+ ),
1545
+ /* @__PURE__ */ e(
1546
+ "rect",
1547
+ {
1548
+ x: v,
1549
+ y: z + j * 0.2,
1550
+ width: i * T,
1551
+ height: j * 0.6,
1552
+ rx: 2,
1553
+ fill: w
1554
+ }
1555
+ ),
1556
+ B != null && /* @__PURE__ */ e(
1557
+ "line",
1558
+ {
1559
+ x1: v + i * B,
1560
+ y1: z + 2,
1561
+ x2: v + i * B,
1562
+ y2: z + j - 2,
1563
+ stroke: A,
1564
+ strokeWidth: 2
1565
+ }
1566
+ ),
1567
+ y && /* @__PURE__ */ e(
1568
+ "text",
1569
+ {
1570
+ x: v + Math.max(i * T, 4),
1571
+ y: z + j / 2,
1572
+ dx: i * T > 24 ? -4 : 4,
1573
+ textAnchor: i * T > 24 ? "end" : "start",
1574
+ dominantBaseline: "middle",
1575
+ fontSize: x,
1576
+ fill: i * T > 24 ? "var(--text-on-primary, #ffffff)" : "var(--text-primary)",
1577
+ fontWeight: 600,
1578
+ children: N(t)
1579
+ }
1580
+ ),
1581
+ f && B != null && /* @__PURE__ */ b(
1582
+ "text",
1583
+ {
1584
+ x: v + i * B,
1585
+ y: z - 2,
1586
+ textAnchor: "middle",
1587
+ fontSize: x - 1,
1588
+ fill: A,
1589
+ fontWeight: 600,
1590
+ children: [
1591
+ "▼",
1592
+ N(u)
1593
+ ]
1594
+ }
1595
+ )
1596
+ ]
1597
+ }
1598
+ );
1599
+ if (p === "none" || !l)
1600
+ return /* @__PURE__ */ b("div", { className: `nice-bullet ${d || ""}`, style: s, children: [
1601
+ Y(),
1602
+ /* @__PURE__ */ e("style", { children: Te })
1603
+ ] });
1604
+ const G = p === "top" || p === "bottom", ee = /* @__PURE__ */ e(
1605
+ "span",
1606
+ {
1607
+ className: "nice-bullet__label",
1608
+ style: {
1609
+ fontSize: x,
1610
+ fontWeight: 600,
1611
+ color: "var(--text-primary)",
1612
+ ...G ? {
1613
+ marginBottom: p === "top" ? 4 : 0,
1614
+ marginTop: p === "bottom" ? 4 : 0
1615
+ } : {},
1616
+ ...p === "left" ? { marginRight: 8 } : {},
1617
+ ...p === "right" ? { marginLeft: 8 } : {}
1618
+ },
1619
+ children: l
1620
+ }
1621
+ );
1622
+ return /* @__PURE__ */ b(
1623
+ "div",
1624
+ {
1625
+ className: `nice-bullet nice-bullet--${p} ${d || ""}`,
1626
+ style: {
1627
+ display: "inline-flex",
1628
+ flexDirection: G ? "column" : "row",
1629
+ alignItems: G ? "flex-start" : "center",
1630
+ ...s
1631
+ },
1632
+ children: [
1633
+ (p === "top" || p === "left") && ee,
1634
+ Y(),
1635
+ (p === "bottom" || p === "right") && ee,
1636
+ /* @__PURE__ */ e("style", { children: Te })
1637
+ ]
1638
+ }
1639
+ );
1640
+ }, Te = `
1641
+ @keyframes nice-bullet-shimmer {
1642
+ 0% { background-position: 200% 0; }
1643
+ 100% { background-position: -200% 0; }
1644
+ }
1645
+ `, _t = ({
1646
+ data: t,
1647
+ width: u = 400,
1648
+ height: c = 300,
1649
+ inverted: m,
1650
+ showLabels: n = !0,
1651
+ showValues: g = !0,
1652
+ title: w,
1653
+ className: A,
1654
+ style: L
1655
+ }) => {
1656
+ const l = { top: w ? 30 : 10, bottom: 10, x: 40 }, p = u - l.x * 2, y = c - l.top - l.bottom, f = m ? [...t].reverse() : t, N = Math.max(...f.map((o) => o.value), 1), k = y / f.length;
1657
+ return /* @__PURE__ */ e("div", { className: `nice-funnel ${A || ""}`, style: L, children: /* @__PURE__ */ b("svg", { width: u, height: c, children: [
1658
+ w && /* @__PURE__ */ e("text", { x: u / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: w }),
1659
+ f.map((o, d) => {
1660
+ const s = o.value / N * p, $ = d < f.length - 1 ? f[d + 1].value / N * p : s * 0.3, _ = l.top + d * k, S = _ + k, x = u / 2, v = `${x - s / 2},${_} ${x + s / 2},${_} ${x + $ / 2},${S} ${x - $ / 2},${S}`, i = o.color || ye[d % ye.length];
1661
+ return /* @__PURE__ */ b("g", { children: [
1662
+ /* @__PURE__ */ e(
1663
+ "polygon",
1664
+ {
1665
+ points: v,
1666
+ fill: i,
1667
+ stroke: "var(--bg-primary, #fff)",
1668
+ strokeWidth: 1,
1669
+ children: /* @__PURE__ */ e("title", { children: `${o.label}: ${o.value}` })
1670
+ }
1671
+ ),
1672
+ n && /* @__PURE__ */ e(
1673
+ "text",
1674
+ {
1675
+ x,
1676
+ y: _ + k / 2 - (g ? 4 : 0),
1677
+ textAnchor: "middle",
1678
+ dominantBaseline: "middle",
1679
+ className: "nice-funnel__label",
1680
+ children: o.label
1681
+ }
1682
+ ),
1683
+ g && /* @__PURE__ */ e(
1684
+ "text",
1685
+ {
1686
+ x,
1687
+ y: _ + k / 2 + 10,
1688
+ textAnchor: "middle",
1689
+ dominantBaseline: "middle",
1690
+ className: "nice-funnel__value",
1691
+ children: o.value
1692
+ }
1693
+ )
1694
+ ] }, d);
1695
+ })
1696
+ ] }) });
1697
+ }, Qe = ({
1698
+ nodes: t,
1699
+ links: u,
1700
+ width: c = 600,
1701
+ height: m = 400,
1702
+ nodeWidth: n = 20,
1703
+ nodePadding: g = 10,
1704
+ title: w,
1705
+ className: A,
1706
+ style: L
1707
+ }) => {
1708
+ const l = { top: w ? 40 : 20, bottom: 20, left: 20, right: 20 }, p = c - l.left - l.right, y = m - l.top - l.bottom, f = new Set(u.map((a) => a.source)), N = new Set(u.map((a) => a.target)), k = t.filter((a) => f.has(a.id) && !N.has(a.id)), o = t.filter((a) => N.has(a.id)), d = t.filter((a) => f.has(a.id) && N.has(a.id)), s = [k, ...d.length ? [d] : [], o].filter(
1709
+ (a) => a.length > 0
1710
+ ), $ = s.length, _ = /* @__PURE__ */ new Map();
1711
+ t.forEach((a) => {
1712
+ const j = u.filter((B) => B.source === a.id).reduce((B, Y) => B + Y.value, 0), T = u.filter((B) => B.target === a.id).reduce((B, Y) => B + Y.value, 0);
1713
+ _.set(a.id, Math.max(j, T));
1714
+ });
1715
+ const S = s.map(
1716
+ (a) => a.reduce((j, T) => j + (_.get(T.id) || 0), 0) + (a.length - 1) * g
1717
+ ), x = Math.max(...S, 1), v = /* @__PURE__ */ new Map();
1718
+ s.forEach((a, j) => {
1719
+ const T = l.left + j / ($ - 1 || 1) * (p - n);
1720
+ let B = 0;
1721
+ a.forEach((Y) => {
1722
+ const G = (_.get(Y.id) || 0) / x * y;
1723
+ v.set(Y.id, { x: T, y: l.top + B, h: G }), B += G + g;
1724
+ });
1725
+ });
1726
+ const i = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map();
1727
+ return t.forEach((a) => {
1728
+ i.set(a.id, 0), z.set(a.id, 0);
1729
+ }), /* @__PURE__ */ e("div", { className: `nice-sankey ${A || ""}`, style: L, children: /* @__PURE__ */ b("svg", { width: c, height: m, children: [
1730
+ w && /* @__PURE__ */ e("text", { x: c / 2, y: 20, textAnchor: "middle", className: "nice-chart__title", children: w }),
1731
+ u.map((a, j) => {
1732
+ var C;
1733
+ const T = v.get(a.source), B = v.get(a.target);
1734
+ if (!T || !B)
1735
+ return null;
1736
+ const Y = i.get(a.source) || 0, G = z.get(a.target) || 0, ee = a.value / x * y;
1737
+ i.set(a.source, Y + ee), z.set(a.target, G + ee);
1738
+ const J = T.x + n, re = T.y + Y, q = B.x, Z = B.y + G, se = (J + q) / 2, de = ((C = t.find((D) => D.id === a.source)) == null ? void 0 : C.color) || ye[j % ye.length];
1739
+ return /* @__PURE__ */ e(
1740
+ "path",
1741
+ {
1742
+ d: `M${J},${re} C${se},${re} ${se},${Z} ${q},${Z} L${q},${Z + ee} C${se},${Z + ee} ${se},${re + ee} ${J},${re + ee} Z`,
1743
+ fill: de,
1744
+ fillOpacity: 0.3,
1745
+ stroke: de,
1746
+ strokeOpacity: 0.5,
1747
+ strokeWidth: 0.5,
1748
+ children: /* @__PURE__ */ e("title", { children: `${a.source} → ${a.target}: ${a.value}` })
1749
+ },
1750
+ j
1751
+ );
1752
+ }),
1753
+ t.map((a, j) => {
1754
+ const T = v.get(a.id);
1755
+ if (!T)
1756
+ return null;
1757
+ const B = a.color || ye[j % ye.length];
1758
+ return /* @__PURE__ */ b("g", { children: [
1759
+ /* @__PURE__ */ e(
1760
+ "rect",
1761
+ {
1762
+ x: T.x,
1763
+ y: T.y,
1764
+ width: n,
1765
+ height: Math.max(T.h, 2),
1766
+ fill: B,
1767
+ rx: 2
1768
+ }
1769
+ ),
1770
+ /* @__PURE__ */ e(
1771
+ "text",
1772
+ {
1773
+ x: T.x < p / 2 ? T.x + n + 4 : T.x - 4,
1774
+ y: T.y + T.h / 2,
1775
+ textAnchor: T.x < p / 2 ? "start" : "end",
1776
+ dominantBaseline: "middle",
1777
+ className: "nice-chart__legend-text",
1778
+ children: a.label
1779
+ }
1780
+ )
1781
+ ] }, a.id);
1782
+ })
1783
+ ] }) });
1784
+ }, wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1785
+ __proto__: null,
1786
+ NiceSankey: Qe
1787
+ }, Symbol.toStringTag, { value: "Module" })), $t = ({
1788
+ data: t,
1789
+ min: u,
1790
+ max: c,
1791
+ start: m,
1792
+ end: n,
1793
+ onChange: g,
1794
+ width: w = 500,
1795
+ height: A = 100,
1796
+ step: L = 1,
1797
+ formatValue: l,
1798
+ chartColor: p = "var(--color-primary, #3b82f6)",
1799
+ className: y,
1800
+ style: f
1801
+ }) => {
1802
+ const N = { top: 10, bottom: 30, left: 10, right: 10 }, k = w - N.left - N.right, o = A - N.top - N.bottom, d = (x) => N.left + (x - u) / (c - u || 1) * k, s = (x) => {
1803
+ const v = Math.max(0, Math.min(1, (x - N.left) / k)), i = u + v * (c - u);
1804
+ return Math.round(i / L) * L;
1805
+ }, $ = (x, v) => {
1806
+ v.preventDefault();
1807
+ const i = v.target.closest("svg");
1808
+ if (!i)
1809
+ return;
1810
+ const z = (j) => {
1811
+ const T = i.getBoundingClientRect(), B = s(j.clientX - T.left);
1812
+ x === "start" ? g(Math.min(B, n), n) : g(m, Math.max(B, m));
1813
+ }, a = () => {
1814
+ document.removeEventListener("pointermove", z), document.removeEventListener("pointerup", a);
1815
+ };
1816
+ document.addEventListener("pointermove", z), document.addEventListener("pointerup", a);
1817
+ }, _ = t ? Math.min(...t) : 0, S = (t ? Math.max(...t) : 1) - _ || 1;
1818
+ return /* @__PURE__ */ e("div", { className: `nice-rangeselector ${y || ""}`, style: f, children: /* @__PURE__ */ b("svg", { width: w, height: A, children: [
1819
+ t && t.length > 1 && /* @__PURE__ */ e(
1820
+ "polygon",
1821
+ {
1822
+ points: `${N.left},${N.top + o} ${t.map((x, v) => `${N.left + v / (t.length - 1) * k},${N.top + o - (x - _) / S * o}`).join(" ")} ${N.left + k},${N.top + o}`,
1823
+ fill: p,
1824
+ opacity: 0.15
1825
+ }
1826
+ ),
1827
+ /* @__PURE__ */ e(
1828
+ "rect",
1829
+ {
1830
+ x: d(m),
1831
+ y: N.top,
1832
+ width: d(n) - d(m),
1833
+ height: o,
1834
+ fill: p,
1835
+ opacity: 0.1
1836
+ }
1837
+ ),
1838
+ /* @__PURE__ */ e(
1839
+ "rect",
1840
+ {
1841
+ x: N.left,
1842
+ y: N.top,
1843
+ width: d(m) - N.left,
1844
+ height: o,
1845
+ fill: "var(--bg-secondary, #f5f5f5)",
1846
+ opacity: 0.6
1847
+ }
1848
+ ),
1849
+ /* @__PURE__ */ e(
1850
+ "rect",
1851
+ {
1852
+ x: d(n),
1853
+ y: N.top,
1854
+ width: N.left + k - d(n),
1855
+ height: o,
1856
+ fill: "var(--bg-secondary, #f5f5f5)",
1857
+ opacity: 0.6
1858
+ }
1859
+ ),
1860
+ /* @__PURE__ */ e(
1861
+ "rect",
1862
+ {
1863
+ x: d(m) - 4,
1864
+ y: N.top,
1865
+ width: 8,
1866
+ height: o,
1867
+ fill: p,
1868
+ rx: 2,
1869
+ cursor: "ew-resize",
1870
+ onPointerDown: (x) => $("start", x)
1871
+ }
1872
+ ),
1873
+ /* @__PURE__ */ e(
1874
+ "rect",
1875
+ {
1876
+ x: d(n) - 4,
1877
+ y: N.top,
1878
+ width: 8,
1879
+ height: o,
1880
+ fill: p,
1881
+ rx: 2,
1882
+ cursor: "ew-resize",
1883
+ onPointerDown: (x) => $("end", x)
1884
+ }
1885
+ ),
1886
+ /* @__PURE__ */ e(
1887
+ "text",
1888
+ {
1889
+ x: d(m),
1890
+ y: N.top + o + 18,
1891
+ textAnchor: "middle",
1892
+ className: "nice-chart__axis-label",
1893
+ children: l ? l(m) : m
1894
+ }
1895
+ ),
1896
+ /* @__PURE__ */ e(
1897
+ "text",
1898
+ {
1899
+ x: d(n),
1900
+ y: N.top + o + 18,
1901
+ textAnchor: "middle",
1902
+ className: "nice-chart__axis-label",
1903
+ children: l ? l(n) : n
1904
+ }
1905
+ )
1906
+ ] }) });
1907
+ }, Je = ({
1908
+ regions: t,
1909
+ width: u = 600,
1910
+ height: c = 400,
1911
+ viewBox: m = "0 0 1000 600",
1912
+ colorRange: n = ["var(--info-bg, #dbeafe)", "var(--color-primary-active, #1d4ed8)"],
1913
+ maxValue: g,
1914
+ onRegionClick: w,
1915
+ selectedRegionId: A,
1916
+ title: L,
1917
+ showTooltip: l = !0,
1918
+ className: p,
1919
+ style: y
1920
+ }) => {
1921
+ const f = g ?? Math.max(...t.map((k) => k.value ?? 0), 1), N = (k) => {
1922
+ const o = (a) => [
1923
+ parseInt(a.slice(1, 3), 16),
1924
+ parseInt(a.slice(3, 5), 16),
1925
+ parseInt(a.slice(5, 7), 16)
1926
+ ], [d, s, $] = o(n[0]), [_, S, x] = o(n[1]), v = Math.round(d + (_ - d) * k), i = Math.round(s + (S - s) * k), z = Math.round($ + (x - $) * k);
1927
+ return `rgb(${v},${i},${z})`;
1928
+ };
1929
+ return /* @__PURE__ */ b("div", { className: `nice-vectormap ${p || ""}`, style: y, children: [
1930
+ L && /* @__PURE__ */ e("div", { className: "nice-vectormap__title", children: L }),
1931
+ /* @__PURE__ */ e("svg", { width: u, height: c, viewBox: m, children: t.map((k) => {
1932
+ const o = k.value != null ? Math.max(0, Math.min(1, k.value / f)) : 0, d = k.value != null ? N(o) : "var(--bg-tertiary, #e5e7eb)", s = k.id === A;
1933
+ return /* @__PURE__ */ e(
1934
+ "path",
1935
+ {
1936
+ d: k.path,
1937
+ fill: d,
1938
+ stroke: s ? "var(--color-primary, #3b82f6)" : "var(--border-color, #d1d5db)",
1939
+ strokeWidth: s ? 2 : 0.5,
1940
+ cursor: w ? "pointer" : void 0,
1941
+ onClick: () => w == null ? void 0 : w(k),
1942
+ children: l && /* @__PURE__ */ e("title", { children: `${k.name}${k.value != null ? `: ${k.value}` : ""}` })
1943
+ },
1944
+ k.id
1945
+ );
1946
+ }) })
1947
+ ] });
1948
+ }, kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1949
+ __proto__: null,
1950
+ NiceVectorMap: Je
1951
+ }, Symbol.toStringTag, { value: "Module" })), Ke = `
1952
+ .nice-forecast-chart {
1953
+ display: flex;
1954
+ flex-direction: column;
1955
+ background: var(--nice-bg-primary, #ffffff);
1956
+ border: 1px solid var(--nice-border-color, #e5e7eb);
1957
+ border-radius: var(--nice-radius-lg, 0.5rem);
1958
+ overflow: hidden;
1959
+ }
1960
+
1961
+ .nice-forecast-chart__header {
1962
+ display: flex;
1963
+ align-items: center;
1964
+ justify-content: space-between;
1965
+ padding: 0.75rem 1rem;
1966
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
1967
+ }
1968
+
1969
+ .nice-forecast-chart__title {
1970
+ font-size: 1rem;
1971
+ font-weight: 600;
1972
+ color: var(--nice-text-primary);
1973
+ margin: 0;
1974
+ }
1975
+
1976
+ .nice-forecast-chart__actions {
1977
+ display: flex;
1978
+ gap: 0.5rem;
1979
+ }
1980
+
1981
+ .nice-forecast-chart__btn {
1982
+ display: inline-flex;
1983
+ align-items: center;
1984
+ justify-content: center;
1985
+ width: 2rem;
1986
+ height: 2rem;
1987
+ font-size: 1rem;
1988
+ border-radius: var(--nice-radius-md, 0.375rem);
1989
+ cursor: pointer;
1990
+ transition: all 0.15s ease;
1991
+ border: 1px solid var(--nice-border-color, #d1d5db);
1992
+ background: var(--nice-bg-primary, #ffffff);
1993
+ color: var(--nice-text-secondary);
1994
+ }
1995
+
1996
+ .nice-forecast-chart__btn:hover {
1997
+ background: var(--nice-bg-hover, #f3f4f6);
1998
+ color: var(--nice-text-primary);
1999
+ }
2000
+
2001
+ .nice-forecast-chart__btn:disabled {
2002
+ opacity: 0.5;
2003
+ cursor: not-allowed;
2004
+ }
2005
+
2006
+ .nice-forecast-chart__container {
2007
+ position: relative;
2008
+ width: 100%;
2009
+ padding: 1rem;
2010
+ }
2011
+
2012
+ .nice-forecast-chart__svg {
2013
+ width: 100%;
2014
+ overflow: visible;
2015
+ }
2016
+
2017
+ .nice-forecast-chart__grid-line {
2018
+ stroke: var(--nice-border-divider, #f3f4f6);
2019
+ stroke-width: 1;
2020
+ }
2021
+
2022
+ .nice-forecast-chart__axis-line {
2023
+ stroke: var(--nice-border-color, #e5e7eb);
2024
+ stroke-width: 1;
2025
+ }
2026
+
2027
+ .nice-forecast-chart__axis-label {
2028
+ font-size: 0.6875rem;
2029
+ fill: var(--nice-text-secondary);
2030
+ }
2031
+
2032
+ .nice-forecast-chart__axis-title {
2033
+ font-size: 0.75rem;
2034
+ font-weight: 500;
2035
+ fill: var(--nice-text-primary);
2036
+ }
2037
+
2038
+ .nice-forecast-chart__historical-line {
2039
+ fill: none;
2040
+ stroke-width: 2;
2041
+ stroke-linecap: round;
2042
+ stroke-linejoin: round;
2043
+ }
2044
+
2045
+ .nice-forecast-chart__forecast-line {
2046
+ fill: none;
2047
+ stroke-width: 2;
2048
+ stroke-linecap: round;
2049
+ stroke-linejoin: round;
2050
+ stroke-dasharray: 6, 4;
2051
+ }
2052
+
2053
+ .nice-forecast-chart__confidence-band {
2054
+ opacity: 0.2;
2055
+ }
2056
+
2057
+ .nice-forecast-chart__forecast-region {
2058
+ fill: var(--nice-bg-secondary, #f9fafb);
2059
+ opacity: 0.5;
2060
+ }
2061
+
2062
+ .nice-forecast-chart__point {
2063
+ cursor: pointer;
2064
+ transition: r 0.15s ease;
2065
+ }
2066
+
2067
+ .nice-forecast-chart__point:hover {
2068
+ r: 6;
2069
+ }
2070
+
2071
+ .nice-forecast-chart__annotation-line {
2072
+ stroke-dasharray: 4, 2;
2073
+ stroke-width: 1;
2074
+ }
2075
+
2076
+ .nice-forecast-chart__annotation-marker {
2077
+ cursor: pointer;
2078
+ transition: transform 0.15s ease;
2079
+ }
2080
+
2081
+ .nice-forecast-chart__annotation-marker:hover {
2082
+ transform: scale(1.2);
2083
+ }
2084
+
2085
+ .nice-forecast-chart__reference-line {
2086
+ stroke-width: 1;
2087
+ }
2088
+
2089
+ .nice-forecast-chart__reference-label {
2090
+ font-size: 0.625rem;
2091
+ fill: var(--nice-text-secondary);
2092
+ }
2093
+
2094
+ .nice-forecast-chart__cash-runway {
2095
+ pointer-events: none;
2096
+ }
2097
+
2098
+ .nice-forecast-chart__cash-runway-line {
2099
+ stroke: var(--nice-danger, #ef4444);
2100
+ stroke-width: 2;
2101
+ stroke-dasharray: 8, 4;
2102
+ }
2103
+
2104
+ .nice-forecast-chart__cash-runway-label-bg {
2105
+ fill: var(--nice-danger, #ef4444);
2106
+ rx: 4;
2107
+ }
2108
+
2109
+ .nice-forecast-chart__cash-runway-label {
2110
+ font-size: 0.6875rem;
2111
+ font-weight: 600;
2112
+ fill: var(--nice-bg, #FFFFFF);
2113
+ }
2114
+
2115
+ .nice-forecast-chart__cash-runway-date {
2116
+ font-size: 0.625rem;
2117
+ fill: var(--nice-danger, #ef4444);
2118
+ font-weight: 500;
2119
+ }
2120
+
2121
+ .nice-forecast-chart__tooltip {
2122
+ position: absolute;
2123
+ pointer-events: none;
2124
+ z-index: 100;
2125
+ padding: 0.75rem;
2126
+ background: var(--nice-bg-primary, #ffffff);
2127
+ border: 1px solid var(--nice-border-color, #e5e7eb);
2128
+ border-radius: var(--nice-radius-lg, 0.5rem);
2129
+ box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
2130
+ font-size: 0.8125rem;
2131
+ max-width: 250px;
2132
+ }
2133
+
2134
+ .nice-forecast-chart__tooltip-date {
2135
+ font-weight: 600;
2136
+ color: var(--nice-text-primary);
2137
+ margin-bottom: 0.5rem;
2138
+ padding-bottom: 0.5rem;
2139
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
2140
+ }
2141
+
2142
+ .nice-forecast-chart__tooltip-item {
2143
+ display: flex;
2144
+ align-items: center;
2145
+ gap: 0.5rem;
2146
+ margin-bottom: 0.25rem;
2147
+ }
2148
+
2149
+ .nice-forecast-chart__tooltip-color {
2150
+ width: 10px;
2151
+ height: 10px;
2152
+ border-radius: var(--nice-radius-sm, 2px);
2153
+ flex-shrink: 0;
2154
+ }
2155
+
2156
+ .nice-forecast-chart__tooltip-label {
2157
+ color: var(--nice-text-secondary);
2158
+ flex: 1;
2159
+ }
2160
+
2161
+ .nice-forecast-chart__tooltip-value {
2162
+ font-weight: 600;
2163
+ color: var(--nice-text-primary);
2164
+ font-variant-numeric: tabular-nums;
2165
+ }
2166
+
2167
+ .nice-forecast-chart__tooltip-confidence {
2168
+ font-size: 0.75rem;
2169
+ color: var(--nice-text-tertiary);
2170
+ }
2171
+
2172
+ .nice-forecast-chart__legend {
2173
+ display: flex;
2174
+ flex-wrap: wrap;
2175
+ gap: 1rem;
2176
+ padding: 0.75rem 1rem;
2177
+ border-top: 1px solid var(--nice-border-color, #e5e7eb);
2178
+ }
2179
+
2180
+ .nice-forecast-chart__legend-item {
2181
+ display: flex;
2182
+ align-items: center;
2183
+ gap: 0.375rem;
2184
+ font-size: 0.8125rem;
2185
+ color: var(--nice-text-secondary);
2186
+ cursor: pointer;
2187
+ user-select: none;
2188
+ transition: opacity 0.15s ease;
2189
+ }
2190
+
2191
+ .nice-forecast-chart__legend-item:hover {
2192
+ color: var(--nice-text-primary);
2193
+ }
2194
+
2195
+ .nice-forecast-chart__legend-item--hidden {
2196
+ opacity: 0.4;
2197
+ }
2198
+
2199
+ .nice-forecast-chart__legend-color {
2200
+ width: 16px;
2201
+ height: 3px;
2202
+ border-radius: var(--nice-radius-xs, 1px);
2203
+ }
2204
+
2205
+ .nice-forecast-chart__legend-color--dashed {
2206
+ background: repeating-linear-gradient(
2207
+ 90deg,
2208
+ currentColor,
2209
+ currentColor 4px,
2210
+ transparent 4px,
2211
+ transparent 6px
2212
+ );
2213
+ }
2214
+
2215
+ .nice-forecast-chart__empty {
2216
+ display: flex;
2217
+ align-items: center;
2218
+ justify-content: center;
2219
+ height: 300px;
2220
+ color: var(--nice-text-secondary);
2221
+ }
2222
+
2223
+ /* Dark mode */
2224
+ .dark .nice-forecast-chart {
2225
+ background: var(--nice-bg-primary-dark, #111827);
2226
+ border-color: var(--nice-border-color-dark, #374151);
2227
+ }
2228
+
2229
+ .dark .nice-forecast-chart__tooltip {
2230
+ background: var(--nice-bg-secondary-dark, #1f2937);
2231
+ border-color: var(--nice-border-color-dark, #374151);
2232
+ }
2233
+
2234
+ .dark .nice-forecast-chart__forecast-region {
2235
+ fill: var(--nice-bg-secondary-dark, #1f2937);
2236
+ }
2237
+ `, Ve = [
2238
+ "var(--color-primary, #3b82f6)",
2239
+ // blue
2240
+ "var(--color-success, #10b981)",
2241
+ // green
2242
+ "var(--color-warning, #f59e0b)",
2243
+ // amber
2244
+ "var(--color-error, #ef4444)",
2245
+ // red
2246
+ "var(--color-accent, #8b5cf6)",
2247
+ // purple
2248
+ "var(--color-accent-pink, #ec4899)",
2249
+ // pink
2250
+ "var(--color-info, #06b6d4)",
2251
+ // cyan
2252
+ "var(--nice-warning, #f97316)"
2253
+ // orange
2254
+ ];
2255
+ function pe(t) {
2256
+ return t instanceof Date ? t : new Date(t);
2257
+ }
2258
+ function Re(t, u = "pl-PL") {
2259
+ return t.toLocaleDateString(u, {
2260
+ year: "numeric",
2261
+ month: "short",
2262
+ day: "numeric"
2263
+ });
2264
+ }
2265
+ function Le(t, u = "pl-PL") {
2266
+ return new Intl.NumberFormat(u, {
2267
+ minimumFractionDigits: 0,
2268
+ maximumFractionDigits: 2
2269
+ }).format(t);
2270
+ }
2271
+ _e(
2272
+ function(t, u) {
2273
+ var ae, te;
2274
+ const {
2275
+ scenarios: c,
2276
+ data: m,
2277
+ annotations: n = [],
2278
+ referenceLines: g = [],
2279
+ forecastStartDate: w,
2280
+ cashRunway: A,
2281
+ xAxis: L,
2282
+ yAxis: l,
2283
+ confidenceBands: p = [{ level: 95, color: "var(--color-primary, #3b82f6)", opacity: 0.15 }],
2284
+ tooltip: y,
2285
+ legend: f = { enabled: !0, position: "bottom", interactive: !0 },
2286
+ height: N = 350,
2287
+ showForecastRegion: k = !0,
2288
+ lineWidth: o = 2,
2289
+ showPoints: d = !1,
2290
+ pointRadius: s = 4,
2291
+ enableZoom: $ = !1,
2292
+ zoomEnabled: _,
2293
+ animationDuration: S = 300,
2294
+ showLegend: x,
2295
+ responsive: v = !0,
2296
+ onPointClick: i,
2297
+ onAnnotationClick: z,
2298
+ onScenarioToggle: a,
2299
+ onViewportChange: j,
2300
+ size: T = "medium",
2301
+ disabled: B = !1,
2302
+ labels: Y = {},
2303
+ locale: G = "pl-PL",
2304
+ className: ee,
2305
+ style: J
2306
+ } = t, re = c && c.length > 0 ? c : m ? [
2307
+ {
2308
+ id: "default",
2309
+ name: "Series",
2310
+ data: m
2311
+ }
2312
+ ] : [], q = {
2313
+ ...f,
2314
+ enabled: x ?? f.enabled
2315
+ }, [Z, se] = he(
2316
+ () => re.map((r, I) => ({
2317
+ ...r,
2318
+ color: r.color ?? Ve[I % Ve.length],
2319
+ visible: r.visible !== !1
2320
+ }))
2321
+ ), [de, C] = he(null), [D, F] = he({ x: 0, y: 0 }), X = Ne(null), K = Ne(null), V = { top: 20, right: 30, bottom: 40, left: 60 }, [O, U] = he({
2322
+ width: 600,
2323
+ height: typeof N == "number" ? N : 350
2324
+ });
2325
+ Se(() => {
2326
+ if (!v || !X.current)
2327
+ return;
2328
+ const r = new ResizeObserver((I) => {
2329
+ for (const W of I)
2330
+ U((h) => ({
2331
+ width: W.contentRect.width,
2332
+ height: h.height
2333
+ }));
2334
+ });
2335
+ return r.observe(X.current), () => r.disconnect();
2336
+ }, [v]), Se(() => {
2337
+ const r = "nice-forecast-chart-styles";
2338
+ if (!document.getElementById(r)) {
2339
+ const I = document.createElement("style");
2340
+ I.id = r, I.textContent = Ke, document.head.appendChild(I);
2341
+ }
2342
+ }, []);
2343
+ const { xScale: Q, yScale: P, allDates: E, minY: ie, maxY: fe } = ue(() => {
2344
+ const r = Z.filter((me) => me.visible !== !1).flatMap((me) => me.data);
2345
+ if (r.length === 0)
2346
+ return { xScale: () => 0, yScale: () => 0, allDates: [], minY: 0, maxY: 100 };
2347
+ const I = r.map((me) => pe(me.date).getTime()), W = Math.min(...I), h = Math.max(...I), R = r.flatMap((me) => [me.value, me.forecast, me.lowerBound, me.upperBound]).filter((me) => me != null), H = (l == null ? void 0 : l.min) ?? Math.min(...R) * 0.95, ne = (l == null ? void 0 : l.max) ?? Math.max(...R) * 1.05, le = O.width - V.left - V.right, oe = O.height - V.top - V.bottom, be = (me) => {
2348
+ const We = typeof me == "number" ? me : me.getTime();
2349
+ return V.left + (We - W) / (h - W) * le;
2350
+ }, De = (me) => V.top + oe - (me - H) / (ne - H) * oe, ze = [...new Set(I)].sort((me, We) => me - We).map((me) => new Date(me));
2351
+ return {
2352
+ xScale: be,
2353
+ yScale: De,
2354
+ allDates: ze,
2355
+ minY: H,
2356
+ maxY: ne
2357
+ };
2358
+ }, [Z, O, V, l]), ge = w ? pe(w) : null, xe = ue(() => {
2359
+ if (!(A != null && A.enabled))
2360
+ return null;
2361
+ const r = A.threshold ?? 0, I = A.scenarioId ? Z.find((h) => h.id === A.scenarioId && h.visible !== !1) : Z.find((h) => h.visible !== !1);
2362
+ if (!I)
2363
+ return null;
2364
+ const W = I.data.sort(
2365
+ (h, R) => pe(h.date).getTime() - pe(R.date).getTime()
2366
+ );
2367
+ for (let h = 1; h < W.length; h++) {
2368
+ const R = W[h - 1], H = W[h], ne = R.forecast ?? R.value, le = H.forecast ?? H.value;
2369
+ if (ne != null && le != null && ne > r && le <= r) {
2370
+ const oe = (ne - r) / (ne - le), be = pe(R.date).getTime(), De = pe(H.date).getTime(), ze = be + oe * (De - be);
2371
+ return new Date(ze);
2372
+ }
2373
+ }
2374
+ return null;
2375
+ }, [A, Z]), ve = ce(
2376
+ (r, I) => {
2377
+ const W = r.filter((h) => h[I] != null).map((h) => ({ x: Q(pe(h.date)), y: P(h[I]) }));
2378
+ return W.length === 0 ? "" : `M ${W.map((h) => `${h.x},${h.y}`).join(" L ")}`;
2379
+ },
2380
+ [Q, P]
2381
+ ), Me = ce(
2382
+ (r) => {
2383
+ const I = r.filter((R) => R.lowerBound != null && R.upperBound != null);
2384
+ if (I.length === 0)
2385
+ return "";
2386
+ const W = I.map((R) => ({
2387
+ x: Q(pe(R.date)),
2388
+ y: P(R.upperBound)
2389
+ })), h = I.map((R) => ({ x: Q(pe(R.date)), y: P(R.lowerBound) })).reverse();
2390
+ return `M ${W.map((R) => `${R.x},${R.y}`).join(" L ")} L ${h.map((R) => `${R.x},${R.y}`).join(" L ")} Z`;
2391
+ },
2392
+ [Q, P]
2393
+ ), we = ce(
2394
+ (r) => {
2395
+ if (!K.current || (y == null ? void 0 : y.enabled) === !1)
2396
+ return;
2397
+ const I = K.current.getBoundingClientRect(), W = r.clientX - I.left;
2398
+ r.clientY - I.top;
2399
+ let h = null, R = 1 / 0;
2400
+ for (const H of E) {
2401
+ const ne = Q(H), le = Math.abs(ne - W);
2402
+ le < R && (R = le, h = H);
2403
+ }
2404
+ if (h && R < 50) {
2405
+ const H = Z.filter((le) => le.visible !== !1).map((le) => {
2406
+ const oe = le.data.find((be) => pe(be.date).getTime() === h.getTime());
2407
+ return {
2408
+ scenario: le,
2409
+ value: oe == null ? void 0 : oe.value,
2410
+ forecast: oe == null ? void 0 : oe.forecast,
2411
+ lowerBound: oe == null ? void 0 : oe.lowerBound,
2412
+ upperBound: oe == null ? void 0 : oe.upperBound
2413
+ };
2414
+ }), ne = n.filter(
2415
+ (le) => Math.abs(pe(le.date).getTime() - h.getTime()) < 864e5
2416
+ );
2417
+ C({ date: h, values: H, annotations: ne }), F({ x: r.clientX - I.left + 10, y: r.clientY - I.top - 10 });
2418
+ } else
2419
+ C(null);
2420
+ },
2421
+ [Q, E, Z, n, y]
2422
+ ), $e = ce(
2423
+ (r) => {
2424
+ if (!q.interactive)
2425
+ return;
2426
+ se((W) => W.map((h) => h.id === r ? { ...h, visible: !h.visible } : h));
2427
+ const I = Z.find((W) => W.id === r);
2428
+ I && (a == null || a(r, !I.visible));
2429
+ },
2430
+ [q.interactive, Z, a]
2431
+ );
2432
+ Ie(
2433
+ u,
2434
+ () => ({
2435
+ getScenarios: () => Z,
2436
+ updateScenario: (r, I) => {
2437
+ se((W) => W.map((h) => h.id === r ? { ...h, data: I } : h));
2438
+ },
2439
+ toggleScenario: $e,
2440
+ setZoomRange: () => {
2441
+ },
2442
+ // Would need pan/zoom implementation
2443
+ resetZoom: () => {
2444
+ },
2445
+ exportImage: (r) => {
2446
+ if (!K.current)
2447
+ return null;
2448
+ const I = K.current, W = new XMLSerializer().serializeToString(I);
2449
+ return `data:image/svg+xml;base64,${btoa(W)}`;
2450
+ },
2451
+ getDataAtDate: (r) => {
2452
+ const I = Z.filter((W) => W.visible !== !1).map((W) => {
2453
+ const h = W.data.find((R) => pe(R.date).getTime() === r.getTime());
2454
+ return {
2455
+ scenario: W,
2456
+ value: h == null ? void 0 : h.value,
2457
+ forecast: h == null ? void 0 : h.forecast,
2458
+ lowerBound: h == null ? void 0 : h.lowerBound,
2459
+ upperBound: h == null ? void 0 : h.upperBound
2460
+ };
2461
+ });
2462
+ return {
2463
+ date: r,
2464
+ values: I,
2465
+ annotations: n.filter((W) => pe(W.date).getTime() === r.getTime())
2466
+ };
2467
+ }
2468
+ }),
2469
+ [Z, n, $e]
2470
+ ), O.width - V.left - V.right;
2471
+ const Ce = O.height - V.top - V.bottom, Ae = ue(() => {
2472
+ const r = (l == null ? void 0 : l.tickCount) ?? 5, I = [], W = (fe - ie) / (r - 1);
2473
+ for (let h = 0; h < r; h++)
2474
+ I.push(ie + W * h);
2475
+ return I;
2476
+ }, [ie, fe, l == null ? void 0 : l.tickCount]), M = ue(() => {
2477
+ const r = (L == null ? void 0 : L.tickCount) ?? 6;
2478
+ if (E.length === 0)
2479
+ return [];
2480
+ const I = Math.max(1, Math.floor(E.length / (r - 1)));
2481
+ return E.filter((W, h) => h % I === 0 || h === E.length - 1);
2482
+ }, [E, L == null ? void 0 : L.tickCount]);
2483
+ return Z.length === 0 || Z.every((r) => r.data.length === 0) ? /* @__PURE__ */ e("div", { className: `nice-forecast-chart ${ee ?? ""}`, style: J, children: /* @__PURE__ */ e("div", { className: "nice-forecast-chart__empty", children: Y.noData ?? "No data available" }) }) : /* @__PURE__ */ b("div", { className: `nice-forecast-chart ${ee ?? ""}`, style: { ...J, height: N }, children: [
2484
+ /* @__PURE__ */ b("div", { ref: X, className: "nice-forecast-chart__container", children: [
2485
+ /* @__PURE__ */ b(
2486
+ "svg",
2487
+ {
2488
+ ref: K,
2489
+ className: "nice-forecast-chart__svg",
2490
+ width: O.width,
2491
+ height: O.height,
2492
+ onMouseMove: we,
2493
+ onMouseLeave: () => C(null),
2494
+ children: [
2495
+ (l == null ? void 0 : l.showGrid) !== !1 && Ae.map((r) => /* @__PURE__ */ e(
2496
+ "line",
2497
+ {
2498
+ className: "nice-forecast-chart__grid-line",
2499
+ x1: V.left,
2500
+ x2: O.width - V.right,
2501
+ y1: P(r),
2502
+ y2: P(r)
2503
+ },
2504
+ r
2505
+ )),
2506
+ k && ge && /* @__PURE__ */ e(
2507
+ "rect",
2508
+ {
2509
+ className: "nice-forecast-chart__forecast-region",
2510
+ x: Q(ge),
2511
+ y: V.top,
2512
+ width: O.width - V.right - Q(ge),
2513
+ height: Ce
2514
+ }
2515
+ ),
2516
+ g.map((r) => /* @__PURE__ */ b("g", { children: [
2517
+ /* @__PURE__ */ e(
2518
+ "line",
2519
+ {
2520
+ className: "nice-forecast-chart__reference-line",
2521
+ x1: V.left,
2522
+ x2: O.width - V.right,
2523
+ y1: P(r.value),
2524
+ y2: P(r.value),
2525
+ stroke: r.color ?? "var(--text-muted, #9ca3af)",
2526
+ strokeDasharray: r.dashArray ?? "4,2"
2527
+ }
2528
+ ),
2529
+ r.label && /* @__PURE__ */ e(
2530
+ "text",
2531
+ {
2532
+ className: "nice-forecast-chart__reference-label",
2533
+ x: O.width - V.right - 4,
2534
+ y: P(r.value) - 4,
2535
+ textAnchor: "end",
2536
+ children: r.label
2537
+ }
2538
+ )
2539
+ ] }, r.id)),
2540
+ xe && (A == null ? void 0 : A.enabled) && /* @__PURE__ */ b("g", { className: "nice-forecast-chart__cash-runway", children: [
2541
+ /* @__PURE__ */ e(
2542
+ "line",
2543
+ {
2544
+ className: "nice-forecast-chart__cash-runway-line",
2545
+ x1: Q(xe),
2546
+ x2: Q(xe),
2547
+ y1: V.top,
2548
+ y2: O.height - V.bottom,
2549
+ stroke: A.color ?? "var(--color-error, #ef4444)"
2550
+ }
2551
+ ),
2552
+ A.showLabel !== !1 && /* @__PURE__ */ b(Fe, { children: [
2553
+ /* @__PURE__ */ e(
2554
+ "rect",
2555
+ {
2556
+ className: "nice-forecast-chart__cash-runway-label-bg",
2557
+ x: Q(xe) - 60,
2558
+ y: V.top - 2,
2559
+ width: 120,
2560
+ height: A.showDate !== !1 ? 32 : 20,
2561
+ fill: A.color ?? "var(--color-error, #ef4444)",
2562
+ rx: 4
2563
+ }
2564
+ ),
2565
+ /* @__PURE__ */ e(
2566
+ "text",
2567
+ {
2568
+ className: "nice-forecast-chart__cash-runway-label",
2569
+ x: Q(xe),
2570
+ y: V.top + 12,
2571
+ textAnchor: "middle",
2572
+ fill: "var(--nice-bg, #fff)",
2573
+ children: A.label ?? Y.cashRunsOut ?? "💰 Cash runs out"
2574
+ }
2575
+ ),
2576
+ A.showDate !== !1 && /* @__PURE__ */ e(
2577
+ "text",
2578
+ {
2579
+ className: "nice-forecast-chart__cash-runway-label",
2580
+ x: Q(xe),
2581
+ y: V.top + 26,
2582
+ textAnchor: "middle",
2583
+ fill: "var(--nice-bg, #fff)",
2584
+ style: { fontSize: "0.625rem", opacity: 0.9 },
2585
+ children: Re(xe, G)
2586
+ }
2587
+ )
2588
+ ] })
2589
+ ] }),
2590
+ Z.filter((r) => r.visible !== !1 && r.showConfidenceBand).map((r) => /* @__PURE__ */ e(
2591
+ "path",
2592
+ {
2593
+ className: "nice-forecast-chart__confidence-band",
2594
+ d: Me(r.data),
2595
+ fill: r.color
2596
+ },
2597
+ `band-${r.id}`
2598
+ )),
2599
+ Z.filter((r) => r.visible !== !1).map((r) => {
2600
+ const I = ge ? r.data.filter((h) => pe(h.date) < ge) : r.data.filter((h) => h.value != null), W = ge ? r.data.filter((h) => pe(h.date) >= ge) : r.data.filter((h) => h.forecast != null);
2601
+ return /* @__PURE__ */ b("g", { children: [
2602
+ /* @__PURE__ */ e(
2603
+ "path",
2604
+ {
2605
+ className: "nice-forecast-chart__historical-line",
2606
+ d: ve(I, "value"),
2607
+ stroke: r.color,
2608
+ strokeWidth: o
2609
+ }
2610
+ ),
2611
+ /* @__PURE__ */ e(
2612
+ "path",
2613
+ {
2614
+ className: "nice-forecast-chart__forecast-line",
2615
+ d: ve(W, ge ? "value" : "forecast"),
2616
+ stroke: r.color,
2617
+ strokeWidth: o
2618
+ }
2619
+ ),
2620
+ W.length > 0 && r.data.some((h) => h.forecast != null) && /* @__PURE__ */ e(
2621
+ "path",
2622
+ {
2623
+ className: "nice-forecast-chart__forecast-line",
2624
+ d: ve(r.data, "forecast"),
2625
+ stroke: r.color,
2626
+ strokeWidth: o
2627
+ }
2628
+ ),
2629
+ d && r.data.map((h, R) => {
2630
+ const H = h.value ?? h.forecast;
2631
+ return H == null ? null : /* @__PURE__ */ e(
2632
+ "circle",
2633
+ {
2634
+ className: "nice-forecast-chart__point",
2635
+ cx: Q(pe(h.date)),
2636
+ cy: P(H),
2637
+ r: s,
2638
+ fill: r.color,
2639
+ onClick: () => i == null ? void 0 : i(h, r)
2640
+ },
2641
+ R
2642
+ );
2643
+ })
2644
+ ] }, r.id);
2645
+ }),
2646
+ n.map((r) => {
2647
+ const I = Q(pe(r.date));
2648
+ return /* @__PURE__ */ b(
2649
+ "g",
2650
+ {
2651
+ className: "nice-forecast-chart__annotation-marker",
2652
+ onClick: () => z == null ? void 0 : z(r),
2653
+ children: [
2654
+ r.showLine !== !1 && /* @__PURE__ */ e(
2655
+ "line",
2656
+ {
2657
+ className: "nice-forecast-chart__annotation-line",
2658
+ x1: I,
2659
+ x2: I,
2660
+ y1: V.top,
2661
+ y2: O.height - V.bottom,
2662
+ stroke: r.color ?? "var(--text-muted, #9ca3af)"
2663
+ }
2664
+ ),
2665
+ /* @__PURE__ */ e(
2666
+ "circle",
2667
+ {
2668
+ cx: I,
2669
+ cy: V.top + 10,
2670
+ r: 8,
2671
+ fill: r.color ?? "var(--text-muted, #9ca3af)"
2672
+ }
2673
+ ),
2674
+ /* @__PURE__ */ e("text", { x: I, y: V.top + 14, textAnchor: "middle", fill: "white", fontSize: "10", children: r.icon ?? "!" })
2675
+ ]
2676
+ },
2677
+ r.id
2678
+ );
2679
+ }),
2680
+ /* @__PURE__ */ e(
2681
+ "line",
2682
+ {
2683
+ className: "nice-forecast-chart__axis-line",
2684
+ x1: V.left,
2685
+ x2: V.left,
2686
+ y1: V.top,
2687
+ y2: O.height - V.bottom
2688
+ }
2689
+ ),
2690
+ /* @__PURE__ */ e(
2691
+ "line",
2692
+ {
2693
+ className: "nice-forecast-chart__axis-line",
2694
+ x1: V.left,
2695
+ x2: O.width - V.right,
2696
+ y1: O.height - V.bottom,
2697
+ y2: O.height - V.bottom
2698
+ }
2699
+ ),
2700
+ Ae.map((r) => /* @__PURE__ */ e(
2701
+ "text",
2702
+ {
2703
+ className: "nice-forecast-chart__axis-label",
2704
+ x: V.left - 8,
2705
+ y: P(r) + 4,
2706
+ textAnchor: "end",
2707
+ children: l != null && l.format ? l.format(r) : Le(r, G)
2708
+ },
2709
+ r
2710
+ )),
2711
+ M.map((r) => /* @__PURE__ */ e(
2712
+ "text",
2713
+ {
2714
+ className: "nice-forecast-chart__axis-label",
2715
+ x: Q(r),
2716
+ y: O.height - V.bottom + 16,
2717
+ textAnchor: "middle",
2718
+ children: L != null && L.format ? L.format(r) : Re(r, G)
2719
+ },
2720
+ r.getTime()
2721
+ )),
2722
+ (l == null ? void 0 : l.title) && /* @__PURE__ */ e(
2723
+ "text",
2724
+ {
2725
+ className: "nice-forecast-chart__axis-title",
2726
+ x: 15,
2727
+ y: O.height / 2,
2728
+ textAnchor: "middle",
2729
+ transform: `rotate(-90, 15, ${O.height / 2})`,
2730
+ children: l.title
2731
+ }
2732
+ )
2733
+ ]
2734
+ }
2735
+ ),
2736
+ de && /* @__PURE__ */ b(
2737
+ "div",
2738
+ {
2739
+ className: "nice-forecast-chart__tooltip",
2740
+ style: { left: D.x, top: D.y },
2741
+ children: [
2742
+ /* @__PURE__ */ e("div", { className: "nice-forecast-chart__tooltip-date", children: Re(de.date, G) }),
2743
+ de.values.map((r) => {
2744
+ const I = r.value ?? r.forecast;
2745
+ return I == null ? null : /* @__PURE__ */ b("div", { className: "nice-forecast-chart__tooltip-item", children: [
2746
+ /* @__PURE__ */ e(
2747
+ "span",
2748
+ {
2749
+ className: "nice-forecast-chart__tooltip-color",
2750
+ style: { background: r.scenario.color }
2751
+ }
2752
+ ),
2753
+ /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-label", children: r.scenario.name }),
2754
+ /* @__PURE__ */ e("span", { className: "nice-forecast-chart__tooltip-value", children: Le(I, G) })
2755
+ ] }, r.scenario.id);
2756
+ }),
2757
+ de.values.some((r) => r.lowerBound != null) && /* @__PURE__ */ b("div", { className: "nice-forecast-chart__tooltip-confidence", children: [
2758
+ Y.confidence ?? "CI",
2759
+ ":",
2760
+ " ",
2761
+ Le(((ae = de.values[0]) == null ? void 0 : ae.lowerBound) ?? 0, G),
2762
+ " –",
2763
+ " ",
2764
+ Le(((te = de.values[0]) == null ? void 0 : te.upperBound) ?? 0, G)
2765
+ ] })
2766
+ ]
2767
+ }
2768
+ )
2769
+ ] }),
2770
+ q.enabled && /* @__PURE__ */ e("div", { className: "nice-forecast-chart__legend", children: Z.map((r) => /* @__PURE__ */ b(
2771
+ "div",
2772
+ {
2773
+ className: `nice-forecast-chart__legend-item ${r.visible === !1 ? "nice-forecast-chart__legend-item--hidden" : ""}`,
2774
+ onClick: () => $e(r.id),
2775
+ children: [
2776
+ /* @__PURE__ */ e(
2777
+ "span",
2778
+ {
2779
+ className: `nice-forecast-chart__legend-color ${r.isBase ? "" : "nice-forecast-chart__legend-color--dashed"}`,
2780
+ style: { background: r.color }
2781
+ }
2782
+ ),
2783
+ r.name
2784
+ ]
2785
+ },
2786
+ r.id
2787
+ )) })
2788
+ ] });
2789
+ }
2790
+ );
2791
+ const et = [
2792
+ "var(--color-primary, #3b82f6)",
2793
+ "var(--color-error, #ef4444)",
2794
+ "var(--color-success, #22c55e)",
2795
+ "var(--color-warning, #f59e0b)",
2796
+ "var(--color-accent, #8b5cf6)",
2797
+ "var(--color-accent-pink, #ec4899)",
2798
+ "var(--color-info, #06b6d4)",
2799
+ "var(--nice-success, #84cc16)",
2800
+ "var(--nice-warning, #f97316)",
2801
+ "var(--color-accent, #6366f1)"
2802
+ ], tt = _e(
2803
+ (t, u) => {
2804
+ var se, de;
2805
+ const {
2806
+ levels: c,
2807
+ initialLevelId: m,
2808
+ chartType: n = "bar",
2809
+ width: g = 600,
2810
+ height: w = 400,
2811
+ showBreadcrumbs: A = !0,
2812
+ showBackButton: L = !0,
2813
+ animationDuration: l = 300,
2814
+ onLevelChange: p,
2815
+ onItemClick: y,
2816
+ colors: f = et,
2817
+ showValues: N = !0,
2818
+ showLegend: k = !0,
2819
+ className: o,
2820
+ style: d,
2821
+ ...s
2822
+ } = t, [$, _] = he(m || ((se = c[0]) == null ? void 0 : se.id)), [S, x] = he([m || ((de = c[0]) == null ? void 0 : de.id)]), [v, i] = he(!1), [z, a] = he("in"), j = ue(
2823
+ () => c.find((C) => C.id === $),
2824
+ [c, $]
2825
+ ), T = ce(
2826
+ (C) => {
2827
+ c.find((D) => D.id === C) && (a("in"), i(!0), setTimeout(() => {
2828
+ _(C), x((D) => [...D, C]), p == null || p(C, [...S, C]), i(!1);
2829
+ }, l / 2));
2830
+ },
2831
+ [c, S, l, p]
2832
+ ), B = ce(() => {
2833
+ if (S.length <= 1)
2834
+ return;
2835
+ a("out"), i(!0);
2836
+ const C = S.slice(0, -1), D = C[C.length - 1];
2837
+ setTimeout(() => {
2838
+ _(D), x(C), p == null || p(D, C), i(!1);
2839
+ }, l / 2);
2840
+ }, [S, l, p]), Y = ce(() => {
2841
+ var D;
2842
+ const C = (D = c[0]) == null ? void 0 : D.id;
2843
+ C && (a("out"), i(!0), setTimeout(() => {
2844
+ _(C), x([C]), p == null || p(C, [C]), i(!1);
2845
+ }, l / 2));
2846
+ }, [c, l, p]);
2847
+ Ie(
2848
+ u,
2849
+ () => ({
2850
+ drillDown: T,
2851
+ drillUp: B,
2852
+ resetToRoot: Y,
2853
+ getCurrentLevel: () => $,
2854
+ getPath: () => S
2855
+ }),
2856
+ [T, B, Y, $, S]
2857
+ );
2858
+ const G = ce(
2859
+ (C, D) => {
2860
+ y == null || y(C, $);
2861
+ const F = c.find(
2862
+ (X) => {
2863
+ var K;
2864
+ return X.parentId === $ && X.id === ((K = C.metadata) == null ? void 0 : K.childLevelId);
2865
+ }
2866
+ );
2867
+ F && T(F.id);
2868
+ },
2869
+ [$, c, T, y]
2870
+ ), ee = ue(
2871
+ () => (j == null ? void 0 : j.data.reduce((C, D) => C + D.value, 0)) || 0,
2872
+ [j]
2873
+ ), J = ue(
2874
+ () => S.map((C) => {
2875
+ var D;
2876
+ return ((D = c.find((F) => F.id === C)) == null ? void 0 : D.label) || C;
2877
+ }),
2878
+ [S, c]
2879
+ ), re = () => {
2880
+ if (!j)
2881
+ return null;
2882
+ const C = j.data, D = Math.max(...C.map((X) => X.value)), F = Math.min(40, (w - 100) / C.length - 8);
2883
+ return /* @__PURE__ */ e("div", { className: "nice-drilldown-bars", children: C.map((X, K) => {
2884
+ const V = X.value / D * 100;
2885
+ return /* @__PURE__ */ b(
2886
+ "div",
2887
+ {
2888
+ className: "nice-drilldown-bar-row",
2889
+ onClick: () => G(X, K),
2890
+ children: [
2891
+ /* @__PURE__ */ e("span", { className: "nice-drilldown-bar-label", children: X.label || `Item ${K + 1}` }),
2892
+ /* @__PURE__ */ e("div", { className: "nice-drilldown-bar-track", children: /* @__PURE__ */ e(
2893
+ "div",
2894
+ {
2895
+ className: "nice-drilldown-bar-fill",
2896
+ style: {
2897
+ width: `${V}%`,
2898
+ backgroundColor: X.color || f[K % f.length],
2899
+ height: F
2900
+ }
2901
+ }
2902
+ ) }),
2903
+ N && /* @__PURE__ */ e("span", { className: "nice-drilldown-bar-value", children: X.value.toLocaleString() })
2904
+ ]
2905
+ },
2906
+ K
2907
+ );
2908
+ }) });
2909
+ }, q = () => {
2910
+ if (!j)
2911
+ return null;
2912
+ const C = j.data, D = g / 2, F = (w - 60) / 2 + 30, X = Math.min(D, F) - 40;
2913
+ let K = -90;
2914
+ const V = C.map((O, U) => {
2915
+ const Q = O.value / ee * 360, P = K + Q, E = Q > 180 ? 1 : 0, ie = K * Math.PI / 180, fe = P * Math.PI / 180, ge = D + X * Math.cos(ie), xe = F + X * Math.sin(ie), ve = D + X * Math.cos(fe), Me = F + X * Math.sin(fe), we = (K + Q / 2) * Math.PI / 180, $e = D + X * 0.7 * Math.cos(we), Ce = F + X * 0.7 * Math.sin(we), Ae = `M ${D} ${F} L ${ge} ${xe} A ${X} ${X} 0 ${E} 1 ${ve} ${Me} Z`;
2916
+ return K = P, {
2917
+ path: Ae,
2918
+ color: O.color || f[U % f.length],
2919
+ label: O.label || `Item ${U + 1}`,
2920
+ value: O.value,
2921
+ percentage: (O.value / ee * 100).toFixed(1),
2922
+ labelX: $e,
2923
+ labelY: Ce,
2924
+ item: O,
2925
+ index: U
2926
+ };
2927
+ });
2928
+ return /* @__PURE__ */ e("svg", { width: g, height: w - 40, className: "nice-drilldown-pie", children: /* @__PURE__ */ e("g", { children: V.map((O, U) => /* @__PURE__ */ b("g", { onClick: () => G(O.item, O.index), children: [
2929
+ /* @__PURE__ */ e(
2930
+ "path",
2931
+ {
2932
+ d: O.path,
2933
+ fill: O.color,
2934
+ stroke: "white",
2935
+ strokeWidth: 2,
2936
+ className: "nice-drilldown-pie-slice"
2937
+ }
2938
+ ),
2939
+ N && parseFloat(O.percentage) > 5 && /* @__PURE__ */ b(
2940
+ "text",
2941
+ {
2942
+ x: O.labelX,
2943
+ y: O.labelY,
2944
+ textAnchor: "middle",
2945
+ dominantBaseline: "middle",
2946
+ fill: "white",
2947
+ fontSize: "12",
2948
+ fontWeight: "600",
2949
+ children: [
2950
+ O.percentage,
2951
+ "%"
2952
+ ]
2953
+ }
2954
+ )
2955
+ ] }, U)) }) });
2956
+ }, Z = () => {
2957
+ if (!j)
2958
+ return null;
2959
+ const C = j.data, D = Math.max(...C.map((K) => K.value)), F = Math.min(60, (g - 100) / C.length - 8), X = w - 100;
2960
+ return /* @__PURE__ */ e("svg", { width: g, height: w - 40, className: "nice-drilldown-columns", children: /* @__PURE__ */ b("g", { transform: "translate(50, 20)", children: [
2961
+ [0, 0.25, 0.5, 0.75, 1].map((K, V) => /* @__PURE__ */ b("g", { children: [
2962
+ /* @__PURE__ */ e(
2963
+ "line",
2964
+ {
2965
+ x1: 0,
2966
+ y1: X * (1 - K),
2967
+ x2: g - 80,
2968
+ y2: X * (1 - K),
2969
+ stroke: "var(--border-color, #e5e7eb)",
2970
+ strokeDasharray: K === 0 ? void 0 : "4"
2971
+ }
2972
+ ),
2973
+ /* @__PURE__ */ e(
2974
+ "text",
2975
+ {
2976
+ x: -8,
2977
+ y: X * (1 - K),
2978
+ textAnchor: "end",
2979
+ dominantBaseline: "middle",
2980
+ fontSize: "11",
2981
+ fill: "var(--text-secondary, #6b7280)",
2982
+ children: Math.round(D * K).toLocaleString()
2983
+ }
2984
+ )
2985
+ ] }, V)),
2986
+ C.map((K, V) => {
2987
+ const O = K.value / D * X, U = V * ((g - 100) / C.length) + ((g - 100) / C.length - F) / 2;
2988
+ return /* @__PURE__ */ b("g", { onClick: () => G(K, V), children: [
2989
+ /* @__PURE__ */ e(
2990
+ "rect",
2991
+ {
2992
+ x: U,
2993
+ y: X - O,
2994
+ width: F,
2995
+ height: O,
2996
+ fill: K.color || f[V % f.length],
2997
+ rx: 4,
2998
+ className: "nice-drilldown-column-bar"
2999
+ }
3000
+ ),
3001
+ /* @__PURE__ */ e(
3002
+ "text",
3003
+ {
3004
+ x: U + F / 2,
3005
+ y: X + 16,
3006
+ textAnchor: "middle",
3007
+ fontSize: "11",
3008
+ fill: "var(--text-primary, #374151)",
3009
+ children: (K.label || `${V + 1}`).slice(0, 10)
3010
+ }
3011
+ ),
3012
+ N && /* @__PURE__ */ e(
3013
+ "text",
3014
+ {
3015
+ x: U + F / 2,
3016
+ y: X - O - 8,
3017
+ textAnchor: "middle",
3018
+ fontSize: "11",
3019
+ fill: "var(--text-primary, #374151)",
3020
+ fontWeight: "500",
3021
+ children: K.value.toLocaleString()
3022
+ }
3023
+ )
3024
+ ] }, V);
3025
+ })
3026
+ ] }) });
3027
+ };
3028
+ return /* @__PURE__ */ b(
3029
+ "div",
3030
+ {
3031
+ className: `nice-drilldown-chart ${v ? `animating ${z}` : ""} ${o || ""}`,
3032
+ style: { width: g, ...d },
3033
+ ...s,
3034
+ children: [
3035
+ /* @__PURE__ */ b("div", { className: "nice-drilldown-header", children: [
3036
+ L && S.length > 1 && /* @__PURE__ */ e("button", { className: "nice-drilldown-back", onClick: B, children: "← Wstecz" }),
3037
+ A && /* @__PURE__ */ e("div", { className: "nice-drilldown-breadcrumbs", children: J.map((C, D) => /* @__PURE__ */ b(He.Fragment, { children: [
3038
+ D > 0 && /* @__PURE__ */ e("span", { className: "nice-drilldown-separator", children: "/" }),
3039
+ /* @__PURE__ */ e(
3040
+ "span",
3041
+ {
3042
+ className: `nice-drilldown-crumb ${D === J.length - 1 ? "active" : ""}`,
3043
+ onClick: () => {
3044
+ if (D < J.length - 1) {
3045
+ const F = S.slice(0, D + 1);
3046
+ x(F), _(F[F.length - 1]);
3047
+ }
3048
+ },
3049
+ children: C
3050
+ }
3051
+ )
3052
+ ] }, D)) })
3053
+ ] }),
3054
+ /* @__PURE__ */ b("div", { className: "nice-drilldown-content", style: { height: w - 40 }, children: [
3055
+ n === "bar" && re(),
3056
+ n === "pie" && q(),
3057
+ n === "column" && Z()
3058
+ ] }),
3059
+ k && j && /* @__PURE__ */ e("div", { className: "nice-drilldown-legend", children: j.data.map((C, D) => /* @__PURE__ */ b("div", { className: "nice-drilldown-legend-item", children: [
3060
+ /* @__PURE__ */ e(
3061
+ "span",
3062
+ {
3063
+ className: "nice-drilldown-legend-color",
3064
+ style: { backgroundColor: C.color || f[D % f.length] }
3065
+ }
3066
+ ),
3067
+ /* @__PURE__ */ e("span", { className: "nice-drilldown-legend-label", children: C.label || `Item ${D + 1}` })
3068
+ ] }, D)) }),
3069
+ /* @__PURE__ */ e("style", { children: `
3070
+ .nice-drilldown-chart {
3071
+ font-family: inherit;
3072
+ color: var(--text-primary, #111827);
3073
+ background: var(--bg-elevated, #ffffff);
3074
+ border-radius: 8px;
3075
+ overflow: hidden;
3076
+ }
3077
+
3078
+ .nice-drilldown-header {
3079
+ display: flex;
3080
+ align-items: center;
3081
+ gap: 12px;
3082
+ padding: 12px 16px;
3083
+ border-bottom: 1px solid var(--border-color, #e5e7eb);
3084
+ min-height: 40px;
3085
+ }
3086
+
3087
+ .nice-drilldown-back {
3088
+ background: var(--bg-secondary, #f3f4f6);
3089
+ border: none;
3090
+ padding: 6px 12px;
3091
+ border-radius: 6px;
3092
+ cursor: pointer;
3093
+ font-size: 13px;
3094
+ font-family: inherit;
3095
+ color: var(--text-primary, #374151);
3096
+ transition: background 0.2s;
3097
+ }
3098
+
3099
+ .nice-drilldown-back:hover {
3100
+ background: var(--hover-bg, #e5e7eb);
3101
+ }
3102
+
3103
+ .nice-drilldown-breadcrumbs {
3104
+ display: flex;
3105
+ align-items: center;
3106
+ gap: 4px;
3107
+ font-size: 13px;
3108
+ font-family: inherit;
3109
+ }
3110
+
3111
+ .nice-drilldown-separator {
3112
+ color: var(--text-muted, #9ca3af);
3113
+ }
3114
+
3115
+ .nice-drilldown-crumb {
3116
+ color: var(--text-secondary, #6b7280);
3117
+ cursor: pointer;
3118
+ }
3119
+
3120
+ .nice-drilldown-crumb:hover:not(.active) {
3121
+ color: var(--color-primary, #3b82f6);
3122
+ }
3123
+
3124
+ .nice-drilldown-crumb.active {
3125
+ color: var(--text-primary, #111827);
3126
+ font-weight: 500;
3127
+ cursor: default;
3128
+ }
3129
+
3130
+ .nice-drilldown-content {
3131
+ padding: 16px;
3132
+ transition: opacity 0.15s, transform 0.15s;
3133
+ }
3134
+
3135
+ .nice-drilldown-chart.animating .nice-drilldown-content {
3136
+ opacity: 0;
3137
+ }
3138
+
3139
+ .nice-drilldown-chart.animating.in .nice-drilldown-content {
3140
+ transform: translateX(20px);
3141
+ }
3142
+
3143
+ .nice-drilldown-chart.animating.out .nice-drilldown-content {
3144
+ transform: translateX(-20px);
3145
+ }
3146
+
3147
+ .nice-drilldown-bars {
3148
+ display: flex;
3149
+ flex-direction: column;
3150
+ gap: 8px;
3151
+ }
3152
+
3153
+ .nice-drilldown-bar-row {
3154
+ display: flex;
3155
+ align-items: center;
3156
+ gap: 12px;
3157
+ cursor: pointer;
3158
+ padding: 4px 8px;
3159
+ margin: -4px -8px;
3160
+ border-radius: 6px;
3161
+ transition: background 0.2s;
3162
+ }
3163
+
3164
+ .nice-drilldown-bar-row:hover {
3165
+ background: var(--hover-bg, #f9fafb);
3166
+ }
3167
+
3168
+ .nice-drilldown-bar-label {
3169
+ width: 120px;
3170
+ font-size: 13px;
3171
+ font-family: inherit;
3172
+ color: var(--text-primary, #374151);
3173
+ overflow: hidden;
3174
+ text-overflow: ellipsis;
3175
+ white-space: nowrap;
3176
+ }
3177
+
3178
+ .nice-drilldown-bar-track {
3179
+ flex: 1;
3180
+ background: var(--bg-tertiary, #f3f4f6);
3181
+ border-radius: 6px;
3182
+ overflow: hidden;
3183
+ }
3184
+
3185
+ .nice-drilldown-bar-fill {
3186
+ transition: width 0.3s ease;
3187
+ border-radius: 6px;
3188
+ }
3189
+
3190
+ .nice-drilldown-bar-value {
3191
+ width: 80px;
3192
+ text-align: right;
3193
+ font-size: 13px;
3194
+ font-family: inherit;
3195
+ font-weight: 500;
3196
+ color: var(--text-primary, #111827);
3197
+ }
3198
+
3199
+ .nice-drilldown-pie-slice {
3200
+ cursor: pointer;
3201
+ transition: transform 0.2s, opacity 0.2s;
3202
+ transform-origin: center;
3203
+ }
3204
+
3205
+ .nice-drilldown-pie-slice:hover {
3206
+ opacity: 0.85;
3207
+ transform: scale(1.02);
3208
+ }
3209
+
3210
+ .nice-drilldown-column-bar {
3211
+ cursor: pointer;
3212
+ transition: opacity 0.2s;
3213
+ }
3214
+
3215
+ .nice-drilldown-column-bar:hover {
3216
+ opacity: 0.8;
3217
+ }
3218
+
3219
+ .nice-drilldown-legend {
3220
+ display: flex;
3221
+ flex-wrap: wrap;
3222
+ gap: 16px;
3223
+ padding: 12px 16px;
3224
+ border-top: 1px solid var(--border-color, #e5e7eb);
3225
+ }
3226
+
3227
+ .nice-drilldown-legend-item {
3228
+ display: flex;
3229
+ align-items: center;
3230
+ gap: 6px;
3231
+ }
3232
+
3233
+ .nice-drilldown-legend-color {
3234
+ width: 12px;
3235
+ height: 12px;
3236
+ border-radius: 3px;
3237
+ }
3238
+
3239
+ .nice-drilldown-legend-label {
3240
+ font-size: 12px;
3241
+ font-family: inherit;
3242
+ color: var(--text-secondary, #6b7280);
3243
+ }
3244
+ ` })
3245
+ ]
3246
+ }
3247
+ );
3248
+ }
3249
+ );
3250
+ tt.displayName = "NiceDrillDownChart";
3251
+ const rt = _e(
3252
+ (t, u) => {
3253
+ const {
3254
+ initialData: c,
3255
+ data: m,
3256
+ maxPoints: n = 60,
3257
+ updateInterval: g = 1e3,
3258
+ fetchData: w,
3259
+ width: A = 600,
3260
+ height: L = 200,
3261
+ chartType: l = "line",
3262
+ color: p = "var(--color-primary, #3b82f6)",
3263
+ showGrid: y = !0,
3264
+ showTimeAxis: f = !0,
3265
+ showCurrentValue: N = !0,
3266
+ title: k,
3267
+ valueFormatter: o = (U) => U.toFixed(2),
3268
+ timeFormatter: d = (U) => new Date(U).toLocaleTimeString(),
3269
+ onDataUpdate: s,
3270
+ paused: $,
3271
+ className: _,
3272
+ style: S,
3273
+ ...x
3274
+ } = t, [v, i] = he(c ?? m ?? []), [z, a] = he($ || !1), j = Ne();
3275
+ Se(() => {
3276
+ $ !== void 0 && a($);
3277
+ }, [$]), Se(() => {
3278
+ if (z || !w)
3279
+ return;
3280
+ const U = async () => {
3281
+ try {
3282
+ const Q = await w();
3283
+ i((P) => {
3284
+ const E = [...P, Q].slice(-n);
3285
+ return s == null || s(E), E;
3286
+ });
3287
+ } catch (Q) {
3288
+ console.error("Failed to fetch realtime data:", Q);
3289
+ }
3290
+ };
3291
+ return j.current = setInterval(U, g), () => {
3292
+ j.current && clearInterval(j.current);
3293
+ };
3294
+ }, [z, w, g, n, s]);
3295
+ const T = ce(
3296
+ (U) => {
3297
+ i((Q) => {
3298
+ const P = [...Q, U].slice(-n);
3299
+ return s == null || s(P), P;
3300
+ });
3301
+ },
3302
+ [n, s]
3303
+ ), B = ce(() => {
3304
+ i([]), s == null || s([]);
3305
+ }, [s]), Y = ce(() => a(!0), []), G = ce(() => a(!1), []);
3306
+ Ie(
3307
+ u,
3308
+ () => ({
3309
+ addDataPoint: T,
3310
+ clearData: B,
3311
+ pause: Y,
3312
+ resume: G,
3313
+ getData: () => v
3314
+ }),
3315
+ [T, B, v]
3316
+ );
3317
+ const ee = { top: 20, right: 60, bottom: f ? 40 : 20, left: 50 }, J = A - ee.left - ee.right, re = L - ee.top - ee.bottom, q = v.map((U) => U.value), Z = q.length ? Math.min(...q) : 0, se = q.length ? Math.max(...q) : 100, de = (se - Z || 1) * 0.1, C = Z - de, D = se + de - C, F = (U) => {
3318
+ const Q = w ? n - 1 : Math.max(1, v.length - 1);
3319
+ return ee.left + U / Q * J;
3320
+ }, X = (U) => ee.top + re - (U - C) / D * re, K = v.map((U, Q) => `${F(Q)},${X(U.value)}`).join(" "), V = v.length > 0 ? `M ${F(0)},${ee.top + re} L ${K} L ${F(v.length - 1)},${ee.top + re} Z` : "", O = v.length > 0 ? v[v.length - 1].value : null;
3321
+ return /* @__PURE__ */ b(
3322
+ "div",
3323
+ {
3324
+ className: `nice-realtime-chart ${_ || ""}`,
3325
+ style: { width: A, ...S },
3326
+ ...x,
3327
+ children: [
3328
+ /* @__PURE__ */ b("div", { className: "nice-realtime-header", children: [
3329
+ /* @__PURE__ */ e("span", { className: "nice-realtime-title", children: k }),
3330
+ /* @__PURE__ */ b("div", { className: "nice-realtime-controls", children: [
3331
+ /* @__PURE__ */ b("span", { className: `nice-realtime-status ${z ? "paused" : "live"}`, children: [
3332
+ /* @__PURE__ */ e("span", { className: "nice-realtime-status-dot" }),
3333
+ /* @__PURE__ */ e("span", { children: z ? "Wstrzymano" : "Na żywo" })
3334
+ ] }),
3335
+ /* @__PURE__ */ e(
3336
+ "button",
3337
+ {
3338
+ className: `nice-realtime-btn ${z ? "paused" : ""}`,
3339
+ onClick: () => a(!z),
3340
+ children: z ? "▶️" : "⏸️"
3341
+ }
3342
+ ),
3343
+ N && O !== null && /* @__PURE__ */ e("span", { className: "nice-realtime-value", children: o(O) })
3344
+ ] })
3345
+ ] }),
3346
+ /* @__PURE__ */ b("svg", { width: A, height: L, className: "nice-realtime-svg", children: [
3347
+ y && /* @__PURE__ */ e("g", { className: "nice-realtime-grid", children: [0, 0.25, 0.5, 0.75, 1].map((U, Q) => {
3348
+ const P = ee.top + re * (1 - U), E = C + D * U;
3349
+ return /* @__PURE__ */ b("g", { children: [
3350
+ /* @__PURE__ */ e(
3351
+ "line",
3352
+ {
3353
+ x1: ee.left,
3354
+ y1: P,
3355
+ x2: A - ee.right,
3356
+ y2: P,
3357
+ stroke: "var(--border-color, #e5e7eb)",
3358
+ strokeDasharray: U === 0 ? void 0 : "3"
3359
+ }
3360
+ ),
3361
+ /* @__PURE__ */ e(
3362
+ "text",
3363
+ {
3364
+ x: ee.left - 8,
3365
+ y: P,
3366
+ textAnchor: "end",
3367
+ dominantBaseline: "middle",
3368
+ fontSize: "10",
3369
+ fill: "var(--text-secondary, #6b7280)",
3370
+ children: Math.round(E).toLocaleString()
3371
+ }
3372
+ )
3373
+ ] }, Q);
3374
+ }) }),
3375
+ l === "area" && v.length > 0 && /* @__PURE__ */ e("path", { d: V, fill: p, fillOpacity: 0.2 }),
3376
+ v.length > 1 && /* @__PURE__ */ e(
3377
+ "polyline",
3378
+ {
3379
+ points: K,
3380
+ fill: "none",
3381
+ stroke: p,
3382
+ strokeWidth: 2,
3383
+ strokeLinecap: "round",
3384
+ strokeLinejoin: "round"
3385
+ }
3386
+ ),
3387
+ v.length > 0 && /* @__PURE__ */ e(
3388
+ "circle",
3389
+ {
3390
+ cx: F(v.length - 1),
3391
+ cy: X(v[v.length - 1].value),
3392
+ r: 3,
3393
+ fill: p,
3394
+ className: "nice-realtime-point"
3395
+ }
3396
+ ),
3397
+ f && v.length > 0 && /* @__PURE__ */ e("g", { className: "nice-realtime-time-axis", children: Array.from(
3398
+ new Set([0, Math.floor(v.length / 2), v.length - 1].filter((U) => v[U]))
3399
+ ).map((U) => /* @__PURE__ */ e(
3400
+ "text",
3401
+ {
3402
+ x: F(U),
3403
+ y: L - 8,
3404
+ textAnchor: "middle",
3405
+ fontSize: "10",
3406
+ fill: "var(--text-secondary, #6b7280)",
3407
+ children: d(v[U].timestamp)
3408
+ },
3409
+ `tx-${U}`
3410
+ )) })
3411
+ ] }),
3412
+ /* @__PURE__ */ e("style", { children: `
3413
+ .nice-realtime-chart {
3414
+ font-family: inherit;
3415
+ color: var(--text-primary, #111827);
3416
+ background: var(--bg-elevated, #ffffff);
3417
+ border-radius: 8px;
3418
+ position: relative;
3419
+ }
3420
+
3421
+ .nice-realtime-header {
3422
+ display: flex;
3423
+ justify-content: space-between;
3424
+ align-items: center;
3425
+ padding: 12px 16px;
3426
+ border-bottom: 1px solid var(--border-color, #e5e7eb);
3427
+ }
3428
+
3429
+ .nice-realtime-title {
3430
+ font-size: 14px;
3431
+ font-weight: 600;
3432
+ color: var(--text-primary, #111827);
3433
+ }
3434
+
3435
+ .nice-realtime-controls {
3436
+ display: flex;
3437
+ align-items: center;
3438
+ gap: 12px;
3439
+ }
3440
+
3441
+ .nice-realtime-btn {
3442
+ background: none;
3443
+ border: none;
3444
+ cursor: pointer;
3445
+ font-size: 16px;
3446
+ padding: 4px;
3447
+ font-family: inherit;
3448
+ color: inherit;
3449
+ }
3450
+
3451
+ .nice-realtime-value {
3452
+ font-size: 18px;
3453
+ font-weight: 600;
3454
+ color: ${p};
3455
+ font-variant-numeric: tabular-nums;
3456
+ }
3457
+
3458
+ /* Static current-value dot — no pulsing animation (was distracting) */
3459
+
3460
+ .nice-realtime-status {
3461
+ display: inline-flex;
3462
+ align-items: center;
3463
+ gap: 6px;
3464
+ font-size: 11px;
3465
+ font-family: inherit;
3466
+ color: var(--text-secondary, #6b7280);
3467
+ background: var(--bg-secondary, #f3f4f6);
3468
+ padding: 2px 10px;
3469
+ border-radius: 999px;
3470
+ }
3471
+
3472
+ .nice-realtime-status-dot {
3473
+ width: 8px;
3474
+ height: 8px;
3475
+ border-radius: 50%;
3476
+ background: var(--color-success, #22c55e);
3477
+ }
3478
+
3479
+ .nice-realtime-status.paused .nice-realtime-status-dot {
3480
+ background: var(--color-warning, #f59e0b);
3481
+ }
3482
+
3483
+ .nice-realtime-status.live .nice-realtime-status-dot {
3484
+ animation: live-pulse 2s ease-in-out infinite;
3485
+ }
3486
+
3487
+ @keyframes live-pulse {
3488
+ 0%, 100% { opacity: 1; }
3489
+ 50% { opacity: 0.4; }
3490
+ }
3491
+ ` })
3492
+ ]
3493
+ }
3494
+ );
3495
+ }
3496
+ );
3497
+ rt.displayName = "NiceRealtimeChart";
3498
+ const at = _e(
3499
+ ({
3500
+ data: t,
3501
+ renderNode: u,
3502
+ selectable: c,
3503
+ selectedKey: m,
3504
+ onSelect: n,
3505
+ direction: g = "top-down",
3506
+ collapsible: w = !0,
3507
+ className: A,
3508
+ style: L,
3509
+ id: l
3510
+ }, p) => {
3511
+ const y = Pe(l), [f, N] = he(/* @__PURE__ */ new Set()), k = ce((s) => {
3512
+ N(($) => {
3513
+ const _ = new Set($);
3514
+ return _.has(s) ? _.delete(s) : _.add(s), _;
3515
+ });
3516
+ }, []), o = ce(
3517
+ (s) => {
3518
+ c && (n == null || n(s));
3519
+ },
3520
+ [c, n]
3521
+ ), d = ce(
3522
+ (s) => {
3523
+ const $ = f.has(s.key), _ = s.children && s.children.length > 0;
3524
+ return /* @__PURE__ */ b("li", { className: "nice-org-chart__item", children: [
3525
+ /* @__PURE__ */ b(
3526
+ "div",
3527
+ {
3528
+ className: `nice-org-chart__node${m === s.key ? " nice-org-chart__node--selected" : ""}`,
3529
+ onClick: () => o(s.key),
3530
+ role: c ? "button" : void 0,
3531
+ children: [
3532
+ u ? u(s) : /* @__PURE__ */ e("span", { children: s.label }),
3533
+ w && _ && /* @__PURE__ */ e(
3534
+ "button",
3535
+ {
3536
+ type: "button",
3537
+ className: "nice-org-chart__toggle",
3538
+ onClick: (S) => {
3539
+ S.stopPropagation(), k(s.key);
3540
+ },
3541
+ "aria-label": $ ? "Expand" : "Collapse",
3542
+ children: $ ? "+" : "−"
3543
+ }
3544
+ )
3545
+ ]
3546
+ }
3547
+ ),
3548
+ _ && !$ && /* @__PURE__ */ e("ul", { className: "nice-org-chart__children", children: s.children.map((S) => d(S)) })
3549
+ ] }, s.key);
3550
+ },
3551
+ [f, m, u, c, w, o, k]
3552
+ );
3553
+ return /* @__PURE__ */ e(
3554
+ "div",
3555
+ {
3556
+ ref: p,
3557
+ id: y,
3558
+ className: `nice-org-chart nice-org-chart--${g} ${A || ""}`,
3559
+ style: L,
3560
+ children: /* @__PURE__ */ e("ul", { className: "nice-org-chart__root", children: d(t) })
3561
+ }
3562
+ );
3563
+ }
3564
+ );
3565
+ at.displayName = "NiceOrganizationChart";
3566
+ function nt(t, u, c) {
3567
+ const m = (N) => {
3568
+ const k = N.replace("#", "");
3569
+ return [
3570
+ parseInt(k.slice(0, 2), 16),
3571
+ parseInt(k.slice(2, 4), 16),
3572
+ parseInt(k.slice(4, 6), 16)
3573
+ ];
3574
+ }, [n, g, w] = m(t), [A, L, l] = m(u), p = Math.round(n + (A - n) * c), y = Math.round(g + (L - g) * c), f = Math.round(w + (l - w) * c);
3575
+ return `rgb(${p},${y},${f})`;
3576
+ }
3577
+ const it = _e(
3578
+ ({
3579
+ data: t,
3580
+ xLabels: u,
3581
+ yLabels: c,
3582
+ colors: m = ["var(--nice-primary-bg, #e0f2fe)", "var(--color-primary-active, #1d4ed8)"],
3583
+ onCellClick: n,
3584
+ cellSize: g = 40,
3585
+ showValues: w = !0,
3586
+ className: A,
3587
+ style: L,
3588
+ id: l
3589
+ }, p) => {
3590
+ const y = Pe(l), { minVal: f, maxVal: N } = ue(() => {
3591
+ let o = 1 / 0, d = -1 / 0;
3592
+ for (const s of t)
3593
+ for (const $ of s)
3594
+ $ < o && (o = $), $ > d && (d = $);
3595
+ return { minVal: o, maxVal: d };
3596
+ }, [t]), k = ce(
3597
+ (o) => N === f ? 0.5 : (o - f) / (N - f),
3598
+ [f, N]
3599
+ );
3600
+ return /* @__PURE__ */ e("div", { ref: p, id: y, className: `nice-heatmap ${A || ""}`, style: L, children: /* @__PURE__ */ b("table", { className: "nice-heatmap__table", children: [
3601
+ u && /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ b("tr", { children: [
3602
+ c && /* @__PURE__ */ e("th", {}),
3603
+ u.map((o, d) => /* @__PURE__ */ e("th", { className: "nice-heatmap__header", children: o }, d))
3604
+ ] }) }),
3605
+ /* @__PURE__ */ e("tbody", { children: t.map((o, d) => /* @__PURE__ */ b("tr", { children: [
3606
+ c && /* @__PURE__ */ e("th", { className: "nice-heatmap__row-label", children: c[d] }),
3607
+ o.map((s, $) => /* @__PURE__ */ e(
3608
+ "td",
3609
+ {
3610
+ className: "nice-heatmap__cell",
3611
+ style: {
3612
+ background: nt(m[0], m[1], k(s)),
3613
+ width: g,
3614
+ height: g,
3615
+ textAlign: "center",
3616
+ color: k(s) > 0.6 ? "var(--bg-primary, #fff)" : "var(--bg-tertiary, #333)",
3617
+ cursor: n ? "pointer" : void 0
3618
+ },
3619
+ onClick: () => n == null ? void 0 : n(d, $, s),
3620
+ title: String(s),
3621
+ children: w ? s : ""
3622
+ },
3623
+ $
3624
+ ))
3625
+ ] }, d)) })
3626
+ ] }) });
3627
+ }
3628
+ );
3629
+ it.displayName = "NiceHeatMap";
3630
+ function lt(t, u) {
3631
+ const c = t.reduce((l, p) => l + p.value, 0);
3632
+ if (c === 0 || t.length === 0)
3633
+ return [];
3634
+ const m = [];
3635
+ let { x: n, y: g, w, h: A } = u;
3636
+ const L = [...t].sort((l, p) => p.value - l.value);
3637
+ for (const l of L) {
3638
+ const p = l.value / c;
3639
+ if (w >= A) {
3640
+ const y = w * p;
3641
+ m.push({ x: n, y: g, w: y, h: A, node: l }), n += y, w -= y;
3642
+ } else {
3643
+ const y = A * p;
3644
+ m.push({ x: n, y: g, w, h: y, node: l }), g += y, A -= y;
3645
+ }
3646
+ }
3647
+ return m;
3648
+ }
3649
+ const ot = [
3650
+ "var(--color-primary, #3b82f6)",
3651
+ "var(--color-success, #10b981)",
3652
+ "var(--color-warning, #f59e0b)",
3653
+ "var(--color-error, #ef4444)",
3654
+ "var(--color-accent, #8b5cf6)",
3655
+ "var(--color-info, #06b6d4)",
3656
+ "var(--color-accent-pink, #ec4899)",
3657
+ "var(--nice-success, #84cc16)"
3658
+ ], ct = _e(
3659
+ ({ data: t, width: u = 600, height: c = 400, onNodeClick: m, colors: n = ot, className: g, style: w, id: A }, L) => {
3660
+ const l = Pe(A), p = ue(() => {
3661
+ const y = t.children ?? [t];
3662
+ return lt(y, { x: 0, y: 0, w: u, h: c });
3663
+ }, [t, u, c]);
3664
+ return /* @__PURE__ */ e("div", { ref: L, id: l, className: `nice-treemap ${g || ""}`, style: w, children: /* @__PURE__ */ e("svg", { width: u, height: c, className: "nice-treemap__svg", children: p.map((y, f) => /* @__PURE__ */ b(
3665
+ "g",
3666
+ {
3667
+ onClick: () => m == null ? void 0 : m(y.node),
3668
+ style: { cursor: m ? "pointer" : void 0 },
3669
+ children: [
3670
+ /* @__PURE__ */ e(
3671
+ "rect",
3672
+ {
3673
+ x: y.x,
3674
+ y: y.y,
3675
+ width: Math.max(y.w - 1, 0),
3676
+ height: Math.max(y.h - 1, 0),
3677
+ fill: y.node.color ?? n[f % n.length],
3678
+ rx: 2
3679
+ }
3680
+ ),
3681
+ y.w > 40 && y.h > 20 && /* @__PURE__ */ e(
3682
+ "text",
3683
+ {
3684
+ x: y.x + y.w / 2,
3685
+ y: y.y + y.h / 2,
3686
+ textAnchor: "middle",
3687
+ dominantBaseline: "central",
3688
+ fill: "var(--nice-bg, #fff)",
3689
+ fontSize: Math.min(12, y.w / 6),
3690
+ className: "nice-treemap__label",
3691
+ children: y.node.label
3692
+ }
3693
+ )
3694
+ ]
3695
+ },
3696
+ y.node.key
3697
+ )) }) });
3698
+ }
3699
+ );
3700
+ ct.displayName = "NiceTreeMap";
3701
+ const st = _e(
3702
+ ({
3703
+ data: t,
3704
+ type: u = "candlestick",
3705
+ showVolume: c = !0,
3706
+ width: m = 800,
3707
+ height: n = 400,
3708
+ bullColor: g = "var(--color-success, #22c55e)",
3709
+ bearColor: w = "var(--color-error, #ef4444)",
3710
+ className: A,
3711
+ style: L,
3712
+ id: l
3713
+ }, p) => {
3714
+ const y = Pe(l), f = { top: 20, right: 20, bottom: c ? 80 : 30, left: 60 }, N = m - f.left - f.right, k = c ? 50 : 0, o = n - f.top - f.bottom - k, { minP: d, maxP: s, maxVol: $ } = ue(() => {
3715
+ let i = 1 / 0, z = -1 / 0, a = 0;
3716
+ for (const j of t)
3717
+ j.low < i && (i = j.low), j.high > z && (z = j.high), j.volume && j.volume > a && (a = j.volume);
3718
+ return { minP: i, maxP: z, maxVol: a };
3719
+ }, [t]), _ = Math.max(1, N / t.length * 0.7), S = (i) => f.left + (i + 0.5) * (N / t.length), x = (i) => f.top + o - (i - d) / (s - d || 1) * o, v = (i) => n - f.bottom - k + k * (1 - i / ($ || 1));
3720
+ return /* @__PURE__ */ e("div", { ref: p, id: y, className: `nice-stock-chart ${A || ""}`, style: L, children: /* @__PURE__ */ b("svg", { width: m, height: n, className: "nice-stock-chart__svg", children: [
3721
+ [0, 0.25, 0.5, 0.75, 1].map((i) => {
3722
+ const z = d + i * (s - d);
3723
+ return /* @__PURE__ */ b("g", { children: [
3724
+ /* @__PURE__ */ e(
3725
+ "line",
3726
+ {
3727
+ x1: f.left,
3728
+ x2: m - f.right,
3729
+ y1: x(z),
3730
+ y2: x(z),
3731
+ stroke: "var(--nice-border, #e5e7eb)",
3732
+ strokeDasharray: "2,2"
3733
+ }
3734
+ ),
3735
+ /* @__PURE__ */ e("text", { x: f.left - 4, y: x(z) + 4, textAnchor: "end", fontSize: 10, fill: "var(--nice-text-secondary, #888)", children: z.toFixed(2) })
3736
+ ] }, i);
3737
+ }),
3738
+ u === "line" ? /* @__PURE__ */ e(
3739
+ "polyline",
3740
+ {
3741
+ points: t.map((i, z) => `${S(z)},${x(i.close)}`).join(" "),
3742
+ fill: "none",
3743
+ stroke: g,
3744
+ strokeWidth: 1.5
3745
+ }
3746
+ ) : t.map((i, z) => {
3747
+ const a = i.close >= i.open, j = a ? g : w, T = S(z);
3748
+ if (u === "ohlc")
3749
+ return /* @__PURE__ */ b("g", { children: [
3750
+ /* @__PURE__ */ e(
3751
+ "line",
3752
+ {
3753
+ x1: T,
3754
+ x2: T,
3755
+ y1: x(i.high),
3756
+ y2: x(i.low),
3757
+ stroke: j,
3758
+ strokeWidth: 1
3759
+ }
3760
+ ),
3761
+ /* @__PURE__ */ e(
3762
+ "line",
3763
+ {
3764
+ x1: T - _ / 2,
3765
+ x2: T,
3766
+ y1: x(i.open),
3767
+ y2: x(i.open),
3768
+ stroke: j,
3769
+ strokeWidth: 1.5
3770
+ }
3771
+ ),
3772
+ /* @__PURE__ */ e(
3773
+ "line",
3774
+ {
3775
+ x1: T,
3776
+ x2: T + _ / 2,
3777
+ y1: x(i.close),
3778
+ y2: x(i.close),
3779
+ stroke: j,
3780
+ strokeWidth: 1.5
3781
+ }
3782
+ )
3783
+ ] }, z);
3784
+ const B = x(Math.max(i.open, i.close)), Y = x(Math.min(i.open, i.close));
3785
+ return /* @__PURE__ */ b("g", { children: [
3786
+ /* @__PURE__ */ e(
3787
+ "line",
3788
+ {
3789
+ x1: T,
3790
+ x2: T,
3791
+ y1: x(i.high),
3792
+ y2: x(i.low),
3793
+ stroke: j,
3794
+ strokeWidth: 1
3795
+ }
3796
+ ),
3797
+ /* @__PURE__ */ e(
3798
+ "rect",
3799
+ {
3800
+ x: T - _ / 2,
3801
+ y: B,
3802
+ width: _,
3803
+ height: Math.max(Y - B, 1),
3804
+ fill: a ? "transparent" : j,
3805
+ stroke: j,
3806
+ strokeWidth: 1
3807
+ }
3808
+ )
3809
+ ] }, z);
3810
+ }),
3811
+ c && t.map((i, z) => {
3812
+ if (!i.volume)
3813
+ return null;
3814
+ const a = i.close >= i.open;
3815
+ return /* @__PURE__ */ e(
3816
+ "rect",
3817
+ {
3818
+ x: S(z) - _ / 2,
3819
+ y: v(i.volume),
3820
+ width: _,
3821
+ height: n - f.bottom - v(i.volume),
3822
+ fill: a ? g : w,
3823
+ opacity: 0.3
3824
+ },
3825
+ `v${z}`
3826
+ );
3827
+ }),
3828
+ t.map((i, z) => z % Math.max(1, Math.floor(t.length / 8)) !== 0 ? null : /* @__PURE__ */ e(
3829
+ "text",
3830
+ {
3831
+ x: S(z),
3832
+ y: n - f.bottom + k + 14,
3833
+ textAnchor: "middle",
3834
+ fontSize: 9,
3835
+ fill: "var(--nice-text-secondary, #888)",
3836
+ children: i.date
3837
+ },
3838
+ `l${z}`
3839
+ ))
3840
+ ] }) });
3841
+ }
3842
+ );
3843
+ st.displayName = "NiceStockChart";
3844
+ export {
3845
+ ut as A,
3846
+ wt as B,
3847
+ ye as C,
3848
+ kt as D,
3849
+ Je as N,
3850
+ $t as a,
3851
+ at as b,
3852
+ st as c,
3853
+ ct as d,
3854
+ it as e,
3855
+ Qe as f,
3856
+ _t as g,
3857
+ vt as h,
3858
+ bt as i,
3859
+ yt as j,
3860
+ xt as k,
3861
+ pt as l,
3862
+ gt as m,
3863
+ ft as n,
3864
+ je as o,
3865
+ tt as q,
3866
+ Ye as s,
3867
+ rt as u
3868
+ };