@nukleas/react-cyberdesign 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,3340 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // src/lib/cn.ts
7
+ function cn(...parts) {
8
+ return parts.filter(Boolean).join(" ");
9
+ }
10
+ var ThemeContext = react.createContext("orange");
11
+ function useTheme() {
12
+ return react.useContext(ThemeContext);
13
+ }
14
+ function ThemeProvider({
15
+ theme = "orange",
16
+ a11y = false,
17
+ className,
18
+ children,
19
+ ...rest
20
+ }) {
21
+ const value = react.useMemo(() => theme, [theme]);
22
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(
23
+ "div",
24
+ {
25
+ className: cn(`theme-${theme}`, a11y && "cd-a11y", className),
26
+ "data-cd-theme": theme,
27
+ ...rest,
28
+ children
29
+ }
30
+ ) });
31
+ }
32
+ function AccordionItem({ title, icon, children, className = "", ...rest }) {
33
+ return /* @__PURE__ */ jsxRuntime.jsxs("details", { className: cn("cd-accordion__item", className), ...rest, children: [
34
+ /* @__PURE__ */ jsxRuntime.jsxs("summary", { className: "cd-accordion__trigger", children: [
35
+ icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-accordion__icon", children: icon }),
36
+ title
37
+ ] }),
38
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-accordion__body", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-accordion__content", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-accordion__content-inner", children }) }) })
39
+ ] });
40
+ }
41
+ function AccordionRoot({
42
+ items,
43
+ variant = "default",
44
+ className = "",
45
+ children,
46
+ ...rest
47
+ }) {
48
+ return /* @__PURE__ */ jsxRuntime.jsx(
49
+ "div",
50
+ {
51
+ className: cn(
52
+ "cd-accordion",
53
+ variant !== "default" && `cd-accordion--${variant}`,
54
+ className
55
+ ),
56
+ ...rest,
57
+ children: items ? items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
58
+ AccordionItem,
59
+ {
60
+ title: item.title,
61
+ icon: item.icon,
62
+ open: item.defaultOpen,
63
+ children: item.content
64
+ },
65
+ i
66
+ )) : children
67
+ }
68
+ );
69
+ }
70
+ var Accordion = Object.assign(AccordionRoot, { Item: AccordionItem });
71
+ function Alert({
72
+ variant = "info",
73
+ size,
74
+ inline = false,
75
+ title,
76
+ icon,
77
+ onDismiss,
78
+ className = "",
79
+ children,
80
+ ...rest
81
+ }) {
82
+ return /* @__PURE__ */ jsxRuntime.jsxs(
83
+ "div",
84
+ {
85
+ className: cn(
86
+ "cd-alert",
87
+ `cd-alert--${variant}`,
88
+ size === "sm" && "cd-alert--sm",
89
+ inline && "cd-alert--inline",
90
+ className
91
+ ),
92
+ ...rest,
93
+ children: [
94
+ icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-alert__icon", children: icon }),
95
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-alert__content", children: [
96
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-alert__title", children: title }),
97
+ children != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-alert__body", children })
98
+ ] }),
99
+ onDismiss && /* @__PURE__ */ jsxRuntime.jsx("button", { className: "cd-alert__dismiss", onClick: onDismiss, "aria-label": "Dismiss", children: "\u2715" })
100
+ ]
101
+ }
102
+ );
103
+ }
104
+ function Modal({
105
+ open,
106
+ onClose,
107
+ title,
108
+ footer,
109
+ size = "default",
110
+ hideClose = false,
111
+ className = "",
112
+ children,
113
+ ...rest
114
+ }) {
115
+ return /* @__PURE__ */ jsxRuntime.jsx(
116
+ "div",
117
+ {
118
+ className: cn("cd-modal-overlay", open && "is-open"),
119
+ onClick: (e) => {
120
+ if (e.target === e.currentTarget) onClose?.();
121
+ },
122
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
123
+ "div",
124
+ {
125
+ className: cn("cd-modal", size !== "default" && `cd-modal--${size}`, className),
126
+ role: "dialog",
127
+ "aria-modal": "true",
128
+ ...rest,
129
+ children: [
130
+ (title != null || !hideClose) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-modal__header", children: [
131
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-modal__title", children: title }),
132
+ !hideClose && /* @__PURE__ */ jsxRuntime.jsx("button", { className: "cd-modal__close", onClick: onClose, "aria-label": "Close", children: "\u2715" })
133
+ ] }),
134
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-modal__body", children }),
135
+ footer != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-modal__footer", children: footer })
136
+ ]
137
+ }
138
+ )
139
+ }
140
+ );
141
+ }
142
+ function Button({
143
+ variant = "default",
144
+ size = "md",
145
+ icon = false,
146
+ className = "",
147
+ children,
148
+ ...rest
149
+ }) {
150
+ return /* @__PURE__ */ jsxRuntime.jsx(
151
+ "button",
152
+ {
153
+ className: cn(
154
+ "cd-btn",
155
+ variant !== "default" && `cd-btn--${variant}`,
156
+ size === "sm" && "cd-btn--sm",
157
+ icon && "cd-btn--icon",
158
+ className
159
+ ),
160
+ ...rest,
161
+ children
162
+ }
163
+ );
164
+ }
165
+ function AlertDialog({
166
+ open,
167
+ onClose,
168
+ title = "Confirm",
169
+ children,
170
+ confirmLabel = "Confirm",
171
+ cancelLabel = "Cancel",
172
+ onConfirm,
173
+ destructive = false
174
+ }) {
175
+ return /* @__PURE__ */ jsxRuntime.jsx(
176
+ Modal,
177
+ {
178
+ open,
179
+ onClose,
180
+ title,
181
+ size: "sm",
182
+ footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
183
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: onClose, children: cancelLabel }),
184
+ /* @__PURE__ */ jsxRuntime.jsx(
185
+ Button,
186
+ {
187
+ type: "button",
188
+ variant: destructive ? "danger" : "primary",
189
+ onClick: () => {
190
+ onConfirm?.();
191
+ onClose?.();
192
+ },
193
+ children: confirmLabel
194
+ }
195
+ )
196
+ ] }),
197
+ children
198
+ }
199
+ );
200
+ }
201
+ function AspectRatio({
202
+ ratio = 16 / 9,
203
+ className = "",
204
+ style,
205
+ children,
206
+ ...rest
207
+ }) {
208
+ const merged = {
209
+ ...style,
210
+ paddingBottom: `${1 / ratio * 100}%`
211
+ };
212
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-aspect-ratio", className), style: merged, ...rest, children });
213
+ }
214
+ function AugButton({
215
+ variant = "default",
216
+ size = "md",
217
+ reverse = false,
218
+ className = "",
219
+ children,
220
+ ...rest
221
+ }) {
222
+ return /* @__PURE__ */ jsxRuntime.jsx(
223
+ "button",
224
+ {
225
+ className: cn(
226
+ "cd-aug-btn",
227
+ variant === "primary" && "cd-aug-btn--primary",
228
+ size === "sm" && "cd-aug-btn--sm",
229
+ size === "lg" && "cd-aug-btn--lg",
230
+ reverse && "cd-aug-btn--rev",
231
+ className
232
+ ),
233
+ ...rest,
234
+ children
235
+ }
236
+ );
237
+ }
238
+ function AugPanel({
239
+ size = "md",
240
+ corners4 = false,
241
+ className = "",
242
+ children,
243
+ ...rest
244
+ }) {
245
+ return /* @__PURE__ */ jsxRuntime.jsx(
246
+ "div",
247
+ {
248
+ className: cn(
249
+ "cd-aug-panel",
250
+ size === "sm" && "cd-aug-panel--sm",
251
+ size === "lg" && "cd-aug-panel--lg",
252
+ corners4 && "cd-aug-panel--4",
253
+ className
254
+ ),
255
+ ...rest,
256
+ children
257
+ }
258
+ );
259
+ }
260
+ function Avatar({
261
+ src,
262
+ alt = "",
263
+ fallback,
264
+ size = "md",
265
+ glow = false,
266
+ status,
267
+ className = "",
268
+ ...rest
269
+ }) {
270
+ return /* @__PURE__ */ jsxRuntime.jsx(
271
+ "div",
272
+ {
273
+ className: cn(
274
+ "cd-avatar",
275
+ size !== "md" && `cd-avatar--${size}`,
276
+ glow && "cd-avatar--glow",
277
+ className
278
+ ),
279
+ "data-status": status,
280
+ ...rest,
281
+ children: src != null ? /* @__PURE__ */ jsxRuntime.jsx("img", { className: "cd-avatar__image", src, alt }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-avatar__fallback", children: fallback })
282
+ }
283
+ );
284
+ }
285
+ function AvatarGroup({ more, className = "", children, ...rest }) {
286
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-avatar-group", className), ...rest, children: [
287
+ children,
288
+ more != null && more > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cd-avatar-group__more", children: [
289
+ "+",
290
+ more
291
+ ] })
292
+ ] });
293
+ }
294
+ Avatar.Group = AvatarGroup;
295
+ function Badge({
296
+ color = "orange",
297
+ className = "",
298
+ children,
299
+ ...rest
300
+ }) {
301
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-badge", `cd-badge--${color}`, className), ...rest, children });
302
+ }
303
+ function BottomNav({
304
+ items,
305
+ value,
306
+ onValueChange,
307
+ className = "",
308
+ ...rest
309
+ }) {
310
+ return /* @__PURE__ */ jsxRuntime.jsx("nav", { className: cn("cd-bottom-nav", className), ...rest, children: items.map((item) => {
311
+ const active = value === item.id;
312
+ return /* @__PURE__ */ jsxRuntime.jsxs(
313
+ "button",
314
+ {
315
+ type: "button",
316
+ disabled: item.disabled,
317
+ className: cn("cd-bottom-nav__item", active && "is-active"),
318
+ "data-active": active || void 0,
319
+ onClick: () => onValueChange?.(item.id),
320
+ children: [
321
+ item.icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-bottom-nav__icon", children: item.icon }),
322
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-bottom-nav__label", children: item.label }),
323
+ item.badge != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-bottom-nav__badge", children: item.badge })
324
+ ]
325
+ },
326
+ item.id
327
+ );
328
+ }) });
329
+ }
330
+ function Breadcrumb({
331
+ items,
332
+ variant = "default",
333
+ className = "",
334
+ "aria-label": ariaLabel = "breadcrumb",
335
+ ...rest
336
+ }) {
337
+ const lastIndex = items.length - 1;
338
+ return /* @__PURE__ */ jsxRuntime.jsx("nav", { "aria-label": ariaLabel, ...rest, children: /* @__PURE__ */ jsxRuntime.jsx(
339
+ "ol",
340
+ {
341
+ className: cn(
342
+ "cd-breadcrumb",
343
+ variant === "arrow" && "cd-breadcrumb--arrow",
344
+ variant === "dot" && "cd-breadcrumb--dot",
345
+ className
346
+ ),
347
+ children: items.map((item, i) => {
348
+ const isActive = item.active ?? i === lastIndex;
349
+ return /* @__PURE__ */ jsxRuntime.jsx(
350
+ "li",
351
+ {
352
+ className: cn("cd-breadcrumb__item", isActive && "cd-breadcrumb__item--active"),
353
+ children: isActive || item.href == null ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: item.label }) : /* @__PURE__ */ jsxRuntime.jsx("a", { className: "cd-breadcrumb__link", href: item.href, children: item.label })
354
+ },
355
+ i
356
+ );
357
+ })
358
+ }
359
+ ) });
360
+ }
361
+ function ButtonGroup({
362
+ vertical = false,
363
+ className = "",
364
+ children,
365
+ ...rest
366
+ }) {
367
+ return /* @__PURE__ */ jsxRuntime.jsx(
368
+ "div",
369
+ {
370
+ className: cn("cd-btn-group", vertical && "cd-btn-group--vertical", className),
371
+ role: "group",
372
+ ...rest,
373
+ children
374
+ }
375
+ );
376
+ }
377
+ var WEEKDAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
378
+ function startOfMonth(d) {
379
+ return new Date(d.getFullYear(), d.getMonth(), 1);
380
+ }
381
+ function daysInMonth(d) {
382
+ return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
383
+ }
384
+ function sameDay(a, b) {
385
+ return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
386
+ }
387
+ function formatMonth(d) {
388
+ return d.toLocaleString(void 0, { month: "long", year: "numeric" });
389
+ }
390
+ function Calendar({
391
+ selected,
392
+ defaultSelected,
393
+ month,
394
+ defaultMonth,
395
+ onSelect,
396
+ onMonthChange,
397
+ className = "",
398
+ ...rest
399
+ }) {
400
+ const [internalMonth, setInternalMonth] = react.useState(
401
+ () => startOfMonth(defaultMonth ?? defaultSelected ?? /* @__PURE__ */ new Date())
402
+ );
403
+ const [internalSelected, setInternalSelected] = react.useState(defaultSelected);
404
+ const view = startOfMonth(month ?? internalMonth);
405
+ const value = selected ?? internalSelected;
406
+ const today = react.useMemo(() => /* @__PURE__ */ new Date(), []);
407
+ const setView = (d) => {
408
+ const next = startOfMonth(d);
409
+ if (month == null) setInternalMonth(next);
410
+ onMonthChange?.(next);
411
+ };
412
+ const cells = react.useMemo(() => {
413
+ const firstDow = view.getDay();
414
+ const total = daysInMonth(view);
415
+ const prevTotal = daysInMonth(new Date(view.getFullYear(), view.getMonth() - 1, 1));
416
+ const out = [];
417
+ for (let i = firstDow - 1; i >= 0; i--) {
418
+ out.push({
419
+ date: new Date(view.getFullYear(), view.getMonth() - 1, prevTotal - i),
420
+ outside: true
421
+ });
422
+ }
423
+ for (let d = 1; d <= total; d++) {
424
+ out.push({ date: new Date(view.getFullYear(), view.getMonth(), d), outside: false });
425
+ }
426
+ while (out.length % 7 !== 0) {
427
+ const last = out[out.length - 1].date;
428
+ out.push({
429
+ date: new Date(last.getFullYear(), last.getMonth(), last.getDate() + 1),
430
+ outside: true
431
+ });
432
+ }
433
+ return out;
434
+ }, [view]);
435
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-calendar", className), ...rest, children: [
436
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-calendar__header", children: [
437
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-calendar__title", children: formatMonth(view) }),
438
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-calendar__nav", children: [
439
+ /* @__PURE__ */ jsxRuntime.jsx(
440
+ "button",
441
+ {
442
+ type: "button",
443
+ className: "cd-calendar__nav-btn",
444
+ "aria-label": "Previous month",
445
+ onClick: () => setView(new Date(view.getFullYear(), view.getMonth() - 1, 1)),
446
+ children: "\u2039"
447
+ }
448
+ ),
449
+ /* @__PURE__ */ jsxRuntime.jsx(
450
+ "button",
451
+ {
452
+ type: "button",
453
+ className: "cd-calendar__nav-btn",
454
+ "aria-label": "Next month",
455
+ onClick: () => setView(new Date(view.getFullYear(), view.getMonth() + 1, 1)),
456
+ children: "\u203A"
457
+ }
458
+ )
459
+ ] })
460
+ ] }),
461
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-calendar__grid", children: [
462
+ WEEKDAYS.map((w) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-calendar__weekday", children: w }, w)),
463
+ cells.map(({ date, outside }) => {
464
+ const isSelected = value ? sameDay(date, value) : false;
465
+ const isToday = sameDay(date, today);
466
+ return /* @__PURE__ */ jsxRuntime.jsx(
467
+ "button",
468
+ {
469
+ type: "button",
470
+ className: cn(
471
+ "cd-calendar__day",
472
+ outside && "is-outside",
473
+ isToday && "is-today",
474
+ isSelected && "is-selected"
475
+ ),
476
+ onClick: () => {
477
+ if (selected == null) setInternalSelected(date);
478
+ onSelect?.(date);
479
+ },
480
+ children: date.getDate()
481
+ },
482
+ date.toISOString()
483
+ );
484
+ })
485
+ ] })
486
+ ] });
487
+ }
488
+ function Card({ glow = false, className = "", children, ...rest }) {
489
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-card", glow && "cd-card--glow", className), ...rest, children });
490
+ }
491
+ function CardHeader({ row = false, className = "", children, ...rest }) {
492
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-card__header", row && "cd-card__header--row", className), ...rest, children });
493
+ }
494
+ function CardTitle({ className = "", children, ...rest }) {
495
+ return /* @__PURE__ */ jsxRuntime.jsx("h3", { className: cn("cd-card__title", className), ...rest, children });
496
+ }
497
+ function CardDescription({ className = "", children, ...rest }) {
498
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("cd-card__description", className), ...rest, children });
499
+ }
500
+ function CardContent({ className = "", children, ...rest }) {
501
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-card__content", className), ...rest, children });
502
+ }
503
+ function CardFooter({ end = false, className = "", children, ...rest }) {
504
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-card__footer", end && "cd-card__footer--end", className), ...rest, children });
505
+ }
506
+ Object.assign(Card, {
507
+ Header: CardHeader,
508
+ Title: CardTitle,
509
+ Description: CardDescription,
510
+ Content: CardContent,
511
+ Footer: CardFooter
512
+ });
513
+ function Carousel({
514
+ children,
515
+ defaultIndex = 0,
516
+ showDots = true,
517
+ showControls = true,
518
+ className = "",
519
+ ...rest
520
+ }) {
521
+ const slides = react.Children.toArray(children).filter(react.isValidElement);
522
+ const [index, setIndex] = react.useState(defaultIndex);
523
+ const count = slides.length;
524
+ const go = (i) => setIndex((i % count + count) % count);
525
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-carousel", className), ...rest, children: [
526
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-carousel__viewport", children: /* @__PURE__ */ jsxRuntime.jsx(
527
+ "div",
528
+ {
529
+ className: "cd-carousel__track",
530
+ style: { transform: `translateX(-${index * 100}%)` },
531
+ children: slides.map((slide, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-carousel__slide", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-carousel__slide-inner", children: slide }) }, i))
532
+ }
533
+ ) }),
534
+ (showControls || showDots) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-carousel__controls", children: [
535
+ showControls && /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", size: "sm", onClick: () => go(index - 1), "aria-label": "Previous", children: "\u2039" }),
536
+ showDots && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-carousel__dots", children: slides.map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
537
+ "button",
538
+ {
539
+ type: "button",
540
+ className: cn("cd-carousel__dot", i === index && "is-active"),
541
+ "aria-label": `Go to slide ${i + 1}`,
542
+ onClick: () => setIndex(i)
543
+ },
544
+ i
545
+ )) }),
546
+ showControls && /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", size: "sm", onClick: () => go(index + 1), "aria-label": "Next", children: "\u203A" })
547
+ ] })
548
+ ] });
549
+ }
550
+ function Chip({
551
+ active = false,
552
+ size = "md",
553
+ className = "",
554
+ children,
555
+ type = "button",
556
+ ...rest
557
+ }) {
558
+ return /* @__PURE__ */ jsxRuntime.jsx(
559
+ "button",
560
+ {
561
+ type,
562
+ className: cn("cd-chip", size === "sm" && "cd-chip--sm", active && "is-active", className),
563
+ "data-active": active || void 0,
564
+ "aria-pressed": active,
565
+ ...rest,
566
+ children
567
+ }
568
+ );
569
+ }
570
+ function ChipRow({ className = "", children, ...rest }) {
571
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-chip-row", className), ...rest, children });
572
+ }
573
+ function Input({
574
+ size = "md",
575
+ accent = false,
576
+ error = false,
577
+ className = "",
578
+ type = "text",
579
+ ...rest
580
+ }) {
581
+ return /* @__PURE__ */ jsxRuntime.jsx(
582
+ "input",
583
+ {
584
+ type,
585
+ className: cn(
586
+ "cd-input",
587
+ size === "sm" && "cd-input--sm",
588
+ size === "lg" && "cd-input--lg",
589
+ accent && "cd-input--accent",
590
+ error && "cd-input--error",
591
+ className
592
+ ),
593
+ ...rest
594
+ }
595
+ );
596
+ }
597
+ function PanelHeader({
598
+ actions,
599
+ className = "",
600
+ children,
601
+ ...rest
602
+ }) {
603
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-panel-header", className), ...rest, children: [
604
+ children,
605
+ actions != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-panel-header__actions", children: actions })
606
+ ] });
607
+ }
608
+ function Spinner({
609
+ size = "md",
610
+ variant = "ring",
611
+ label = "Loading",
612
+ className = "",
613
+ ...rest
614
+ }) {
615
+ return /* @__PURE__ */ jsxRuntime.jsx(
616
+ "div",
617
+ {
618
+ role: "status",
619
+ "aria-label": label,
620
+ className: cn(
621
+ "cd-spinner",
622
+ size !== "md" && `cd-spinner--${size}`,
623
+ variant === "dual" && "cd-spinner--dual",
624
+ variant === "dots" && "cd-spinner--dots",
625
+ className
626
+ ),
627
+ ...rest,
628
+ children: variant === "dots" && /* @__PURE__ */ jsxRuntime.jsx("span", {})
629
+ }
630
+ );
631
+ }
632
+ function ChatAction({
633
+ icon,
634
+ label,
635
+ active = false,
636
+ danger = false,
637
+ showLabel = false,
638
+ className = "",
639
+ type = "button",
640
+ title,
641
+ children,
642
+ ...rest
643
+ }) {
644
+ const tip = title ?? (typeof label === "string" ? label : void 0);
645
+ return /* @__PURE__ */ jsxRuntime.jsxs(
646
+ "button",
647
+ {
648
+ type,
649
+ title: tip,
650
+ "aria-label": typeof tip === "string" ? tip : void 0,
651
+ className: cn(
652
+ "cd-chat-action",
653
+ active && "is-active",
654
+ danger && "cd-chat-action--danger",
655
+ className
656
+ ),
657
+ ...rest,
658
+ children: [
659
+ icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-chat-action__icon", children: icon }),
660
+ (showLabel || !icon && label != null) && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-chat-action__label", children: label }),
661
+ children
662
+ ]
663
+ }
664
+ );
665
+ }
666
+ function ChatActions({
667
+ placement = "overlay",
668
+ visible = false,
669
+ className = "",
670
+ children,
671
+ ...rest
672
+ }) {
673
+ return /* @__PURE__ */ jsxRuntime.jsx(
674
+ "div",
675
+ {
676
+ className: cn(
677
+ "cd-chat-actions",
678
+ placement === "overlay" ? "cd-chat-actions--overlay" : "cd-chat-actions--below",
679
+ visible && "is-visible",
680
+ className
681
+ ),
682
+ ...rest,
683
+ children
684
+ }
685
+ );
686
+ }
687
+ function ChatCodeBlock({
688
+ code,
689
+ language = "code",
690
+ onCopy,
691
+ onInsert,
692
+ onRun,
693
+ className = "",
694
+ ...rest
695
+ }) {
696
+ const [copied, setCopied] = react.useState(false);
697
+ const copy = async () => {
698
+ try {
699
+ await navigator.clipboard?.writeText(code);
700
+ } catch {
701
+ }
702
+ setCopied(true);
703
+ onCopy?.(code);
704
+ window.setTimeout(() => setCopied(false), 1400);
705
+ };
706
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-chat-code", className), ...rest, children: [
707
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-chat-code__header", children: [
708
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: language }),
709
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-chat-code__header-actions", children: [
710
+ onRun && /* @__PURE__ */ jsxRuntime.jsx(ChatAction, { icon: "\u25B6", label: "Run", title: "Run / play", onClick: () => onRun(code) }),
711
+ onInsert && /* @__PURE__ */ jsxRuntime.jsx(ChatAction, { icon: "\u21A7", label: "Insert", title: "Insert into editor", onClick: () => onInsert(code) }),
712
+ /* @__PURE__ */ jsxRuntime.jsx(
713
+ ChatAction,
714
+ {
715
+ icon: copied ? "\u2713" : "\u29C9",
716
+ label: copied ? "Copied" : "Copy",
717
+ title: "Copy code",
718
+ active: copied,
719
+ onClick: copy
720
+ }
721
+ )
722
+ ] })
723
+ ] }),
724
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: code }) })
725
+ ] });
726
+ }
727
+ var ROLE_AUTHOR = {
728
+ user: "You",
729
+ assistant: "AI",
730
+ system: "System",
731
+ error: "Error"
732
+ };
733
+ function ChatMessage({
734
+ role,
735
+ children,
736
+ code,
737
+ codeLang = "strudel",
738
+ time,
739
+ author,
740
+ actions,
741
+ actionsVisible = false,
742
+ onCopyCode,
743
+ onInsertCode,
744
+ onRunCode,
745
+ className = "",
746
+ ...rest
747
+ }) {
748
+ const showMeta = author != null || time != null || role !== "system";
749
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-chat-row", `cd-chat-row--${role}`, className), ...rest, children: [
750
+ showMeta && role !== "system" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-chat-row__meta", children: [
751
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: author ?? ROLE_AUTHOR[role] }),
752
+ time != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-chat-row__meta-right", children: time })
753
+ ] }),
754
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-chat-msg", `cd-chat-msg--${role}`), style: { position: "relative", maxWidth: "100%" }, children: [
755
+ children,
756
+ actions != null && /* @__PURE__ */ jsxRuntime.jsx(ChatActions, { placement: "overlay", visible: actionsVisible, children: actions })
757
+ ] }),
758
+ code != null && /* @__PURE__ */ jsxRuntime.jsx(
759
+ ChatCodeBlock,
760
+ {
761
+ code,
762
+ language: codeLang,
763
+ onCopy: onCopyCode,
764
+ onInsert: onInsertCode,
765
+ onRun: onRunCode,
766
+ style: { width: "100%", maxWidth: 420 }
767
+ }
768
+ )
769
+ ] });
770
+ }
771
+ function ChatTyping({ label = "Thinking", className = "", ...rest }) {
772
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-chat-typing", className), ...rest, children: [
773
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cd-chat-typing__dots", "aria-hidden": true, children: [
774
+ /* @__PURE__ */ jsxRuntime.jsx("span", {}),
775
+ /* @__PURE__ */ jsxRuntime.jsx("span", {}),
776
+ /* @__PURE__ */ jsxRuntime.jsx("span", {})
777
+ ] }),
778
+ label
779
+ ] });
780
+ }
781
+ function Chat({
782
+ title = "AI",
783
+ actions,
784
+ messages = [],
785
+ prompts,
786
+ onPrompt,
787
+ value,
788
+ onValueChange,
789
+ placeholder = "Ask for a pattern\u2026",
790
+ onSubmit,
791
+ submitLabel = "Send",
792
+ composerTools,
793
+ typing = false,
794
+ typingLabel,
795
+ disabled = false,
796
+ renderMessage,
797
+ className = "",
798
+ children,
799
+ ...rest
800
+ }) {
801
+ const handleSubmit = (e) => {
802
+ e.preventDefault();
803
+ if (disabled) return;
804
+ if (value?.trim()) onSubmit?.(value.trim());
805
+ };
806
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-chat", className), ...rest, children: [
807
+ /* @__PURE__ */ jsxRuntime.jsx(PanelHeader, { actions, children: title }),
808
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-chat__messages", children: [
809
+ messages.map(
810
+ (m, i) => renderMessage ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderMessage(m, i) }, m.id ?? i) : /* @__PURE__ */ jsxRuntime.jsx(
811
+ ChatMessage,
812
+ {
813
+ role: m.role,
814
+ code: m.code,
815
+ codeLang: m.codeLang,
816
+ time: m.time,
817
+ author: m.author,
818
+ children: m.content
819
+ },
820
+ m.id ?? i
821
+ )
822
+ ),
823
+ typing && /* @__PURE__ */ jsxRuntime.jsx(ChatTyping, { label: typingLabel }),
824
+ children
825
+ ] }),
826
+ prompts != null && prompts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-chat__prompts", children: prompts.map((p) => /* @__PURE__ */ jsxRuntime.jsx(Chip, { size: "sm", onClick: () => onPrompt?.(p.value), children: p.label }, String(p.value))) }),
827
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-chat__composer-wrap", children: [
828
+ composerTools != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-chat__composer-tools", children: composerTools }),
829
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "cd-chat__composer", onSubmit: handleSubmit, children: [
830
+ /* @__PURE__ */ jsxRuntime.jsx(
831
+ Input,
832
+ {
833
+ value,
834
+ onChange: (e) => onValueChange?.(e.target.value),
835
+ placeholder,
836
+ disabled
837
+ }
838
+ ),
839
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "submit", variant: "primary", size: "sm", disabled: disabled || !value?.trim(), children: disabled ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: "xs" }) : submitLabel })
840
+ ] })
841
+ ] })
842
+ ] });
843
+ }
844
+ function Checkbox({ label, description, className = "", ...rest }) {
845
+ const input = /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", className: cn("cd-checkbox", !label && className), ...rest });
846
+ if (label == null && description == null) return input;
847
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: cn("cd-control", className), children: [
848
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", className: "cd-checkbox", ...rest }),
849
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cd-control__label", children: [
850
+ label,
851
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-control__desc", children: description })
852
+ ] })
853
+ ] });
854
+ }
855
+ function Clock({
856
+ timeZone,
857
+ showDate = true,
858
+ hour12 = false,
859
+ className = "",
860
+ ...rest
861
+ }) {
862
+ const [now, setNow] = react.useState(() => /* @__PURE__ */ new Date());
863
+ react.useEffect(() => {
864
+ const id = window.setInterval(() => setNow(/* @__PURE__ */ new Date()), 1e3);
865
+ return () => window.clearInterval(id);
866
+ }, []);
867
+ const time = now.toLocaleTimeString(void 0, {
868
+ hour12,
869
+ hour: "2-digit",
870
+ minute: "2-digit",
871
+ second: "2-digit",
872
+ timeZone
873
+ });
874
+ const date = now.toLocaleDateString(void 0, {
875
+ year: "numeric",
876
+ month: "2-digit",
877
+ day: "2-digit",
878
+ timeZone
879
+ });
880
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("cd-clock", className), ...rest, children: [
881
+ showDate && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-clock__date", children: date }),
882
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-clock__time", children: time })
883
+ ] });
884
+ }
885
+ function Collapsible({
886
+ trigger,
887
+ defaultOpen = false,
888
+ open,
889
+ onOpenChange,
890
+ className = "",
891
+ children,
892
+ ...rest
893
+ }) {
894
+ const [internal, setInternal] = react.useState(defaultOpen);
895
+ const isOpen = open ?? internal;
896
+ const toggle = () => {
897
+ const next = !isOpen;
898
+ if (open == null) setInternal(next);
899
+ onOpenChange?.(next);
900
+ };
901
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-collapsible", isOpen && "is-open", className), ...rest, children: [
902
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "cd-collapsible__trigger", onClick: toggle, "aria-expanded": isOpen, children: [
903
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: trigger }),
904
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-collapsible__chevron", "aria-hidden": true, children: "\u25BE" })
905
+ ] }),
906
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-collapsible__content", children })
907
+ ] });
908
+ }
909
+ function Combobox({
910
+ options,
911
+ value,
912
+ defaultValue = "",
913
+ onChange,
914
+ placeholder = "Select\u2026",
915
+ emptyText = "No matches",
916
+ disabled = false,
917
+ className = "",
918
+ ...rest
919
+ }) {
920
+ const [open, setOpen] = react.useState(false);
921
+ const [internal, setInternal] = react.useState(defaultValue);
922
+ const [query, setQuery] = react.useState("");
923
+ const selected = value ?? internal;
924
+ const selectedLabel = options.find((o) => o.value === selected)?.label ?? "";
925
+ const filtered = react.useMemo(() => {
926
+ const q = query.trim().toLowerCase();
927
+ if (!q) return options;
928
+ return options.filter(
929
+ (o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q)
930
+ );
931
+ }, [options, query]);
932
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-combobox", open && "is-open", className), ...rest, children: [
933
+ /* @__PURE__ */ jsxRuntime.jsx(
934
+ Input,
935
+ {
936
+ disabled,
937
+ placeholder,
938
+ value: open ? query : selectedLabel,
939
+ onFocus: () => {
940
+ setOpen(true);
941
+ setQuery("");
942
+ },
943
+ onChange: (e) => {
944
+ setQuery(e.target.value);
945
+ setOpen(true);
946
+ },
947
+ onBlur: () => {
948
+ window.setTimeout(() => setOpen(false), 120);
949
+ }
950
+ }
951
+ ),
952
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-combobox__menu", role: "listbox", children: [
953
+ filtered.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-command__empty", style: { padding: 12 }, children: emptyText }),
954
+ filtered.map((opt) => /* @__PURE__ */ jsxRuntime.jsx(
955
+ "button",
956
+ {
957
+ type: "button",
958
+ role: "option",
959
+ disabled: opt.disabled,
960
+ "aria-selected": opt.value === selected,
961
+ className: "cd-combobox__option",
962
+ onMouseDown: (e) => e.preventDefault(),
963
+ onClick: () => {
964
+ if (value == null) setInternal(opt.value);
965
+ onChange?.(opt.value);
966
+ setOpen(false);
967
+ },
968
+ children: opt.label
969
+ },
970
+ opt.value
971
+ ))
972
+ ] })
973
+ ] });
974
+ }
975
+ function Command({
976
+ items,
977
+ placeholder = "Type a command\u2026",
978
+ emptyText = "No results",
979
+ onSelect,
980
+ className = "",
981
+ ...rest
982
+ }) {
983
+ const [query, setQuery] = react.useState("");
984
+ const [active, setActive] = react.useState(0);
985
+ const filtered = react.useMemo(() => {
986
+ const q = query.trim().toLowerCase();
987
+ if (!q) return items;
988
+ return items.filter((item) => {
989
+ const hay = `${item.value} ${item.keywords ?? ""} ${typeof item.label === "string" ? item.label : ""}`.toLowerCase();
990
+ return hay.includes(q);
991
+ });
992
+ }, [items, query]);
993
+ const groups = react.useMemo(() => {
994
+ const map = /* @__PURE__ */ new Map();
995
+ for (const item of filtered) {
996
+ const g = item.group ?? "";
997
+ if (!map.has(g)) map.set(g, []);
998
+ map.get(g).push(item);
999
+ }
1000
+ return map;
1001
+ }, [filtered]);
1002
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-command", className), ...rest, children: [
1003
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-command__input-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
1004
+ "input",
1005
+ {
1006
+ className: "cd-command__input",
1007
+ value: query,
1008
+ placeholder,
1009
+ onChange: (e) => {
1010
+ setQuery(e.target.value);
1011
+ setActive(0);
1012
+ },
1013
+ onKeyDown: (e) => {
1014
+ if (e.key === "ArrowDown") {
1015
+ e.preventDefault();
1016
+ setActive((i) => Math.min(i + 1, filtered.length - 1));
1017
+ } else if (e.key === "ArrowUp") {
1018
+ e.preventDefault();
1019
+ setActive((i) => Math.max(i - 1, 0));
1020
+ } else if (e.key === "Enter" && filtered[active] && !filtered[active].disabled) {
1021
+ filtered[active].onSelect?.();
1022
+ onSelect?.(filtered[active]);
1023
+ }
1024
+ }
1025
+ }
1026
+ ) }),
1027
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-command__list", role: "listbox", children: [
1028
+ filtered.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-command__empty", children: emptyText }),
1029
+ Array.from(groups.entries()).map(([group, groupItems]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1030
+ group && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-command__group-label", children: group }),
1031
+ groupItems.map((item) => {
1032
+ const idx = filtered.indexOf(item);
1033
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1034
+ "button",
1035
+ {
1036
+ type: "button",
1037
+ role: "option",
1038
+ disabled: item.disabled,
1039
+ className: cn("cd-command__item", idx === active && "is-selected"),
1040
+ "data-selected": idx === active,
1041
+ onMouseEnter: () => setActive(idx),
1042
+ onClick: () => {
1043
+ item.onSelect?.();
1044
+ onSelect?.(item);
1045
+ },
1046
+ children: [
1047
+ item.label,
1048
+ item.kbd != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-command__item-kbd", children: item.kbd })
1049
+ ]
1050
+ },
1051
+ item.value
1052
+ );
1053
+ })
1054
+ ] }, group || "__default"))
1055
+ ] })
1056
+ ] });
1057
+ }
1058
+ function ContextMenu({ items, children, className = "", ...rest }) {
1059
+ const [open, setOpen] = react.useState(false);
1060
+ const [pos, setPos] = react.useState({ x: 0, y: 0 });
1061
+ react.useEffect(() => {
1062
+ if (!open) return;
1063
+ const close = () => setOpen(false);
1064
+ window.addEventListener("click", close);
1065
+ window.addEventListener("scroll", close, true);
1066
+ return () => {
1067
+ window.removeEventListener("click", close);
1068
+ window.removeEventListener("scroll", close, true);
1069
+ };
1070
+ }, [open]);
1071
+ const onContextMenu = (e) => {
1072
+ e.preventDefault();
1073
+ setPos({ x: e.clientX, y: e.clientY });
1074
+ setOpen(true);
1075
+ };
1076
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(className), onContextMenu, ...rest, children: [
1077
+ children,
1078
+ /* @__PURE__ */ jsxRuntime.jsx(
1079
+ "div",
1080
+ {
1081
+ className: cn("cd-context-menu", open && "is-open"),
1082
+ style: { left: pos.x, top: pos.y },
1083
+ role: "menu",
1084
+ children: items.map(
1085
+ (item, i) => item.sep ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-context-menu__sep" }, i) : /* @__PURE__ */ jsxRuntime.jsxs(
1086
+ "button",
1087
+ {
1088
+ type: "button",
1089
+ role: "menuitem",
1090
+ disabled: item.disabled,
1091
+ className: cn("cd-context-menu__item", item.danger && "cd-context-menu__item--danger"),
1092
+ onClick: (e) => {
1093
+ e.stopPropagation();
1094
+ item.onSelect?.();
1095
+ setOpen(false);
1096
+ },
1097
+ children: [
1098
+ item.label,
1099
+ item.kbd != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-context-menu__kbd", children: item.kbd })
1100
+ ]
1101
+ },
1102
+ i
1103
+ )
1104
+ )
1105
+ }
1106
+ )
1107
+ ] });
1108
+ }
1109
+ function Table({
1110
+ compact = false,
1111
+ bordered = false,
1112
+ scroll = false,
1113
+ wrapProps,
1114
+ className = "",
1115
+ children,
1116
+ ...rest
1117
+ }) {
1118
+ const table = /* @__PURE__ */ jsxRuntime.jsx(
1119
+ "table",
1120
+ {
1121
+ className: cn(
1122
+ "cd-table",
1123
+ compact && "cd-table--compact",
1124
+ bordered && "cd-table--bordered",
1125
+ className
1126
+ ),
1127
+ ...rest,
1128
+ children
1129
+ }
1130
+ );
1131
+ if (!scroll) return table;
1132
+ const { className: wrapClassName = "", ...wrapRest } = wrapProps ?? {};
1133
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-table-wrap", wrapClassName), ...wrapRest, children: table });
1134
+ }
1135
+ function TableHead({ children, ...rest }) {
1136
+ return /* @__PURE__ */ jsxRuntime.jsx("thead", { ...rest, children });
1137
+ }
1138
+ function TableBody({ children, ...rest }) {
1139
+ return /* @__PURE__ */ jsxRuntime.jsx("tbody", { ...rest, children });
1140
+ }
1141
+ function TableRow({ children, ...rest }) {
1142
+ return /* @__PURE__ */ jsxRuntime.jsx("tr", { ...rest, children });
1143
+ }
1144
+ function TableHeaderCell({
1145
+ numeric = false,
1146
+ sort,
1147
+ className = "",
1148
+ children,
1149
+ ...rest
1150
+ }) {
1151
+ const dataSort = sort === true ? "" : sort || void 0;
1152
+ return /* @__PURE__ */ jsxRuntime.jsx(
1153
+ "th",
1154
+ {
1155
+ className: cn(numeric && "cd-table__num", className),
1156
+ "data-sort": dataSort,
1157
+ ...rest,
1158
+ children
1159
+ }
1160
+ );
1161
+ }
1162
+ function TableCell({
1163
+ numeric = false,
1164
+ status,
1165
+ className = "",
1166
+ children,
1167
+ ...rest
1168
+ }) {
1169
+ return /* @__PURE__ */ jsxRuntime.jsx(
1170
+ "td",
1171
+ {
1172
+ className: cn(numeric && "cd-table__num", className),
1173
+ "data-status": status,
1174
+ ...rest,
1175
+ children
1176
+ }
1177
+ );
1178
+ }
1179
+ Table.Head = TableHead;
1180
+ Table.Body = TableBody;
1181
+ Table.Row = TableRow;
1182
+ Table.HeaderCell = TableHeaderCell;
1183
+ Table.Cell = TableCell;
1184
+ function Empty({
1185
+ icon = "\u2B21",
1186
+ title = "No data",
1187
+ description,
1188
+ actions,
1189
+ className = "",
1190
+ children,
1191
+ ...rest
1192
+ }) {
1193
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-empty", className), ...rest, children: [
1194
+ icon != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-empty__icon", children: icon }),
1195
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "cd-empty__title", children: title }),
1196
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-empty__description", children: description }),
1197
+ children,
1198
+ actions != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-empty__actions", children: actions })
1199
+ ] });
1200
+ }
1201
+ function DataTable({
1202
+ columns,
1203
+ data,
1204
+ getRowId,
1205
+ compact,
1206
+ bordered,
1207
+ emptyTitle = "No rows",
1208
+ emptyDescription = "There is nothing to display yet.",
1209
+ className
1210
+ }) {
1211
+ if (data.length === 0) {
1212
+ return /* @__PURE__ */ jsxRuntime.jsx(Empty, { title: emptyTitle, description: emptyDescription });
1213
+ }
1214
+ return /* @__PURE__ */ jsxRuntime.jsxs(Table, { compact, bordered, scroll: true, className, children: [
1215
+ /* @__PURE__ */ jsxRuntime.jsx(Table.Head, { children: /* @__PURE__ */ jsxRuntime.jsx(Table.Row, { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(Table.HeaderCell, { children: col.header }, col.key)) }) }),
1216
+ /* @__PURE__ */ jsxRuntime.jsx(Table.Body, { children: data.map((row, i) => /* @__PURE__ */ jsxRuntime.jsx(Table.Row, { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(Table.Cell, { numeric: col.numeric, children: col.cell(row, i) }, col.key)) }, getRowId?.(row, i) ?? i)) })
1217
+ ] });
1218
+ }
1219
+ function formatDate(d) {
1220
+ return d.toLocaleDateString(void 0, {
1221
+ year: "numeric",
1222
+ month: "short",
1223
+ day: "numeric"
1224
+ });
1225
+ }
1226
+ function DatePicker({
1227
+ value,
1228
+ defaultValue,
1229
+ onChange,
1230
+ placeholder = "Pick a date",
1231
+ disabled = false,
1232
+ className = "",
1233
+ ...rest
1234
+ }) {
1235
+ const [open, setOpen] = react.useState(false);
1236
+ const [internal, setInternal] = react.useState(defaultValue);
1237
+ const selected = value ?? internal;
1238
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-date-picker", open && "is-open", className), ...rest, children: [
1239
+ /* @__PURE__ */ jsxRuntime.jsx(
1240
+ Input,
1241
+ {
1242
+ readOnly: true,
1243
+ disabled,
1244
+ value: selected ? formatDate(selected) : "",
1245
+ placeholder,
1246
+ onClick: () => !disabled && setOpen((o) => !o),
1247
+ "aria-expanded": open
1248
+ }
1249
+ ),
1250
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-date-picker__panel", children: /* @__PURE__ */ jsxRuntime.jsx(
1251
+ Calendar,
1252
+ {
1253
+ selected,
1254
+ onSelect: (d) => {
1255
+ if (value == null) setInternal(d);
1256
+ onChange?.(d);
1257
+ setOpen(false);
1258
+ }
1259
+ }
1260
+ ) })
1261
+ ] });
1262
+ }
1263
+ function Dialog(props) {
1264
+ return /* @__PURE__ */ jsxRuntime.jsx(Modal, { ...props });
1265
+ }
1266
+ function Sheet({
1267
+ open,
1268
+ onClose,
1269
+ side = "right",
1270
+ size = "default",
1271
+ title,
1272
+ description,
1273
+ footer,
1274
+ hideClose = false,
1275
+ className = "",
1276
+ children,
1277
+ ...rest
1278
+ }) {
1279
+ return /* @__PURE__ */ jsxRuntime.jsx(
1280
+ "div",
1281
+ {
1282
+ className: cn("cd-sheet-overlay", open && "is-open"),
1283
+ onClick: (e) => {
1284
+ if (e.target === e.currentTarget) onClose?.();
1285
+ },
1286
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1287
+ "div",
1288
+ {
1289
+ className: cn(
1290
+ "cd-sheet",
1291
+ `cd-sheet--${side}`,
1292
+ size !== "default" && `cd-sheet--${size}`,
1293
+ className
1294
+ ),
1295
+ role: "dialog",
1296
+ "aria-modal": "true",
1297
+ ...rest,
1298
+ children: [
1299
+ (title != null || description != null || !hideClose) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-sheet__header", children: [
1300
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1301
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheet__title", children: title }),
1302
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-sheet__description", children: description })
1303
+ ] }),
1304
+ !hideClose && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "cd-sheet__close", onClick: onClose, "aria-label": "Close", children: "\u2715" })
1305
+ ] }),
1306
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheet__body", children }),
1307
+ footer != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheet__footer", children: footer })
1308
+ ]
1309
+ }
1310
+ )
1311
+ }
1312
+ );
1313
+ }
1314
+ function Drawer({ side = "bottom", ...rest }) {
1315
+ return /* @__PURE__ */ jsxRuntime.jsx(Sheet, { side, ...rest });
1316
+ }
1317
+ function Dropdown({
1318
+ trigger,
1319
+ items,
1320
+ align = "left",
1321
+ triggerClassName = "cd-btn",
1322
+ defaultOpen = false,
1323
+ className = "",
1324
+ ...rest
1325
+ }) {
1326
+ const [open, setOpen] = react.useState(defaultOpen);
1327
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-dropdown", open && "is-open", className), ...rest, children: [
1328
+ /* @__PURE__ */ jsxRuntime.jsx(
1329
+ "button",
1330
+ {
1331
+ type: "button",
1332
+ className: cn(triggerClassName, "cd-dropdown__trigger"),
1333
+ "aria-expanded": open,
1334
+ onClick: () => setOpen((o) => !o),
1335
+ children: trigger
1336
+ }
1337
+ ),
1338
+ /* @__PURE__ */ jsxRuntime.jsx(
1339
+ "div",
1340
+ {
1341
+ className: cn("cd-dropdown__menu", align === "right" && "cd-dropdown__menu--right"),
1342
+ role: "menu",
1343
+ children: items.map((entry, i) => {
1344
+ if ("sep" in entry && entry.sep) {
1345
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-dropdown__sep" }, i);
1346
+ }
1347
+ if ("heading" in entry && entry.heading) {
1348
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-dropdown__label", children: entry.label }, i);
1349
+ }
1350
+ const item = entry;
1351
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1352
+ "button",
1353
+ {
1354
+ type: "button",
1355
+ role: "menuitem",
1356
+ className: cn("cd-dropdown__item", item.danger && "cd-dropdown__item--danger"),
1357
+ disabled: item.disabled,
1358
+ "aria-disabled": item.disabled || void 0,
1359
+ onClick: () => {
1360
+ item.onSelect?.();
1361
+ setOpen(false);
1362
+ },
1363
+ children: [
1364
+ item.icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-dropdown__item-icon", children: item.icon }),
1365
+ item.label,
1366
+ item.kbd != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-dropdown__item-kbd", children: item.kbd })
1367
+ ]
1368
+ },
1369
+ i
1370
+ );
1371
+ })
1372
+ }
1373
+ )
1374
+ ] });
1375
+ }
1376
+ function DropdownMenu(props) {
1377
+ return /* @__PURE__ */ jsxRuntime.jsx(Dropdown, { ...props });
1378
+ }
1379
+ function FeedItem({
1380
+ badge,
1381
+ title,
1382
+ subtitle,
1383
+ time,
1384
+ selected = false,
1385
+ className = "",
1386
+ children,
1387
+ type = "button",
1388
+ ...rest
1389
+ }) {
1390
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1391
+ "button",
1392
+ {
1393
+ type,
1394
+ className: cn("cd-feed-item", selected && "is-selected", className),
1395
+ "data-active": selected || void 0,
1396
+ ...rest,
1397
+ children: [
1398
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-feed-item__meta", children: [
1399
+ badge,
1400
+ time != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-feed-item__time", children: time })
1401
+ ] }),
1402
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-feed-item__title", children: title }),
1403
+ subtitle != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-feed-item__subtitle", children: subtitle }),
1404
+ children
1405
+ ]
1406
+ }
1407
+ );
1408
+ }
1409
+ function Feed({ className = "", children, ...rest }) {
1410
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-feed", className), ...rest, children });
1411
+ }
1412
+ function Field({
1413
+ inline = false,
1414
+ description,
1415
+ error,
1416
+ className = "",
1417
+ children,
1418
+ ...rest
1419
+ }) {
1420
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1421
+ "div",
1422
+ {
1423
+ className: cn("cd-field", inline && "cd-field--inline", className),
1424
+ ...rest,
1425
+ children: [
1426
+ children,
1427
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-field-desc", children: description }),
1428
+ error != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-field-error", children: error })
1429
+ ]
1430
+ }
1431
+ );
1432
+ }
1433
+ function Gauge({
1434
+ value,
1435
+ display,
1436
+ label,
1437
+ size,
1438
+ variant,
1439
+ radar = false,
1440
+ className = "",
1441
+ style,
1442
+ children,
1443
+ ...rest
1444
+ }) {
1445
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1446
+ "div",
1447
+ {
1448
+ className: cn(
1449
+ "cd-gauge",
1450
+ size === "small" && "cd-gauge--small",
1451
+ variant && `cd-gauge--${variant}`,
1452
+ radar && "cd-gauge--radar",
1453
+ className
1454
+ ),
1455
+ style: { ["--value"]: value, ...style },
1456
+ ...rest,
1457
+ children: [
1458
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-gauge__track" }),
1459
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-gauge__fill" }),
1460
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-gauge__center", children: [
1461
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-gauge__value", children: display ?? value }),
1462
+ label != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-gauge__label", children: label }),
1463
+ children
1464
+ ] })
1465
+ ]
1466
+ }
1467
+ );
1468
+ }
1469
+ function GlowCard({
1470
+ color = "orange",
1471
+ active,
1472
+ className,
1473
+ onClick,
1474
+ style,
1475
+ children,
1476
+ ...rest
1477
+ }) {
1478
+ return /* @__PURE__ */ jsxRuntime.jsx(
1479
+ "div",
1480
+ {
1481
+ className: cn("cd-glow-card", `cd-glow-card--${color}`, className),
1482
+ "data-active": active ? "true" : void 0,
1483
+ onClick,
1484
+ style,
1485
+ ...rest,
1486
+ children
1487
+ }
1488
+ );
1489
+ }
1490
+ function HBar({
1491
+ label,
1492
+ value,
1493
+ display,
1494
+ color,
1495
+ className = "",
1496
+ ...rest
1497
+ }) {
1498
+ const pct = Math.max(0, Math.min(100, value));
1499
+ const fillStyle = {
1500
+ width: `${pct}%`,
1501
+ ...color ? { background: color } : null
1502
+ };
1503
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-hbar-row", className), ...rest, children: [
1504
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-hbar-row__label", children: label }),
1505
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-hbar-row__track", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-hbar-row__fill", style: fillStyle }) }),
1506
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-hbar-row__value", children: display ?? Math.round(pct) })
1507
+ ] });
1508
+ }
1509
+ function HoverCard({
1510
+ trigger,
1511
+ title,
1512
+ description,
1513
+ className = "",
1514
+ children,
1515
+ ...rest
1516
+ }) {
1517
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-hover-card", className), ...rest, children: [
1518
+ /* @__PURE__ */ jsxRuntime.jsx("span", { tabIndex: 0, children: trigger }),
1519
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-hover-card__content", role: "tooltip", children: [
1520
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-popover__title", children: title }),
1521
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-popover__description", children: description }),
1522
+ children
1523
+ ] })
1524
+ ] });
1525
+ }
1526
+ function HudSegment({
1527
+ label,
1528
+ value,
1529
+ status,
1530
+ className = "",
1531
+ children,
1532
+ ...rest
1533
+ }) {
1534
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-hud-segment", className), ...rest, children: [
1535
+ label != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-hud-segment__label", children: label }),
1536
+ value != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-hud-segment__value", status && `cd-hud-segment__value--${status}`), children: value }),
1537
+ children
1538
+ ] });
1539
+ }
1540
+ function HudBar({
1541
+ segments,
1542
+ position,
1543
+ compact = false,
1544
+ className = "",
1545
+ children,
1546
+ ...rest
1547
+ }) {
1548
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1549
+ "div",
1550
+ {
1551
+ className: cn(
1552
+ "cd-hud-bar",
1553
+ position && `cd-hud-bar--${position}`,
1554
+ compact && "cd-hud-bar--compact",
1555
+ className
1556
+ ),
1557
+ ...rest,
1558
+ children: [
1559
+ segments?.map((seg, i) => /* @__PURE__ */ jsxRuntime.jsx(HudSegment, { label: seg.label, value: seg.value, status: seg.status }, i)),
1560
+ children
1561
+ ]
1562
+ }
1563
+ );
1564
+ }
1565
+ function HudFrame({
1566
+ label,
1567
+ value,
1568
+ status,
1569
+ compact = false,
1570
+ floating = false,
1571
+ className = "",
1572
+ children,
1573
+ ...rest
1574
+ }) {
1575
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1576
+ "div",
1577
+ {
1578
+ className: cn(
1579
+ "cd-hud-frame",
1580
+ compact && "cd-hud--compact",
1581
+ floating && "cd-hud--floating",
1582
+ className
1583
+ ),
1584
+ ...rest,
1585
+ children: [
1586
+ label != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-hud__label", children: label }),
1587
+ value != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-hud__value", status && `cd-hud__value--${status}`), children: value }),
1588
+ children
1589
+ ]
1590
+ }
1591
+ );
1592
+ }
1593
+ function InputGroup({ className = "", children, ...rest }) {
1594
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-input-group", className), ...rest, children });
1595
+ }
1596
+ function InputGroupAddon({ className = "", children, ...rest }) {
1597
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-input-addon", className), ...rest, children });
1598
+ }
1599
+ Object.assign(InputGroup, { Addon: InputGroupAddon });
1600
+ function InputOTP({
1601
+ length = 6,
1602
+ value = "",
1603
+ onChange,
1604
+ disabled = false,
1605
+ size = "md",
1606
+ separatorAfter,
1607
+ className = "",
1608
+ ...rest
1609
+ }) {
1610
+ const refs = react.useRef([]);
1611
+ const digits = value.padEnd(length, " ").slice(0, length).split("");
1612
+ const setAt = (index, char) => {
1613
+ const next = digits.map((d, i) => i === index ? char : d === " " ? "" : d);
1614
+ const joined = next.join("").replace(/\s/g, "").slice(0, length);
1615
+ onChange?.(joined);
1616
+ };
1617
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-input-otp", size === "sm" && "cd-input-otp--sm", className), ...rest, children: Array.from({ length }, (_, i) => /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "contents" }, children: [
1618
+ separatorAfter != null && i === separatorAfter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-input-otp__sep", "aria-hidden": true, children: "-" }),
1619
+ /* @__PURE__ */ jsxRuntime.jsx(
1620
+ "input",
1621
+ {
1622
+ ref: (el) => {
1623
+ refs.current[i] = el;
1624
+ },
1625
+ className: cn("cd-input-otp__slot", digits[i] && digits[i] !== " " && "is-filled"),
1626
+ inputMode: "numeric",
1627
+ autoComplete: "one-time-code",
1628
+ maxLength: 1,
1629
+ disabled,
1630
+ value: digits[i] === " " ? "" : digits[i],
1631
+ "aria-label": `Digit ${i + 1}`,
1632
+ onChange: (e) => {
1633
+ const v = e.target.value.replace(/\D/g, "").slice(-1);
1634
+ setAt(i, v);
1635
+ if (v && i < length - 1) refs.current[i + 1]?.focus();
1636
+ },
1637
+ onKeyDown: (e) => {
1638
+ if (e.key === "Backspace" && !digits[i]?.trim() && i > 0) {
1639
+ refs.current[i - 1]?.focus();
1640
+ }
1641
+ },
1642
+ onPaste: (e) => {
1643
+ e.preventDefault();
1644
+ const paste = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, length);
1645
+ if (paste) onChange?.(paste);
1646
+ }
1647
+ }
1648
+ )
1649
+ ] }, i)) });
1650
+ }
1651
+ function Interference({
1652
+ intensity,
1653
+ intense = false,
1654
+ glitch = false,
1655
+ corruptText,
1656
+ className = "",
1657
+ children,
1658
+ ...rest
1659
+ }) {
1660
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1661
+ "div",
1662
+ {
1663
+ className: cn(
1664
+ "cd-interference",
1665
+ intensity && `cd-interference--${intensity}`,
1666
+ intense && "cd-interference--intense",
1667
+ glitch && "cd-interference--glitch",
1668
+ className
1669
+ ),
1670
+ ...rest,
1671
+ children: [
1672
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-interference__noise" }),
1673
+ glitch ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-interference__content", "data-text": corruptText, children }) : children
1674
+ ]
1675
+ }
1676
+ );
1677
+ }
1678
+ function Item({
1679
+ media,
1680
+ title,
1681
+ description,
1682
+ actions,
1683
+ bordered = false,
1684
+ interactive = false,
1685
+ className = "",
1686
+ children,
1687
+ ...rest
1688
+ }) {
1689
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1690
+ "div",
1691
+ {
1692
+ className: cn(
1693
+ "cd-item",
1694
+ bordered && "cd-item--bordered",
1695
+ interactive && "cd-item--interactive",
1696
+ className
1697
+ ),
1698
+ ...rest,
1699
+ children: [
1700
+ media != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-item__media", children: media }),
1701
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-item__content", children: [
1702
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-item__title", children: title }),
1703
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-item__description", children: description }),
1704
+ children
1705
+ ] }),
1706
+ actions != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-item__actions", children: actions })
1707
+ ]
1708
+ }
1709
+ );
1710
+ }
1711
+ function ItemGroup({ className = "", children, ...rest }) {
1712
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-item-group", className), ...rest, children });
1713
+ }
1714
+ function Kbd({
1715
+ size = "md",
1716
+ accent = false,
1717
+ className = "",
1718
+ children,
1719
+ ...rest
1720
+ }) {
1721
+ return /* @__PURE__ */ jsxRuntime.jsx(
1722
+ "kbd",
1723
+ {
1724
+ className: cn(
1725
+ "cd-kbd",
1726
+ size === "lg" && "cd-kbd--lg",
1727
+ accent && "cd-kbd--accent",
1728
+ className
1729
+ ),
1730
+ ...rest,
1731
+ children
1732
+ }
1733
+ );
1734
+ }
1735
+ function KbdGroup({
1736
+ separator = "+",
1737
+ className = "",
1738
+ children,
1739
+ ...rest
1740
+ }) {
1741
+ const keys = Array.isArray(children) ? children : [children];
1742
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-kbd-group", className), ...rest, children: keys.map((key, i) => /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "contents" }, children: [
1743
+ i > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-kbd-group__sep", children: separator }),
1744
+ key
1745
+ ] }, i)) });
1746
+ }
1747
+ function Label({
1748
+ required = false,
1749
+ className = "",
1750
+ children,
1751
+ ...rest
1752
+ }) {
1753
+ return /* @__PURE__ */ jsxRuntime.jsx(
1754
+ "label",
1755
+ {
1756
+ className: cn(
1757
+ "cd-form-label",
1758
+ required && "cd-form-label--required",
1759
+ className
1760
+ ),
1761
+ ...rest,
1762
+ children
1763
+ }
1764
+ );
1765
+ }
1766
+ function Menubar({ menus, className = "", ...rest }) {
1767
+ const [open, setOpen] = react.useState(null);
1768
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-menubar", className), role: "menubar", ...rest, children: menus.map((menu, i) => /* @__PURE__ */ jsxRuntime.jsxs(
1769
+ "div",
1770
+ {
1771
+ className: cn("cd-menubar__item", open === i && "is-open"),
1772
+ onMouseLeave: () => setOpen(null),
1773
+ children: [
1774
+ /* @__PURE__ */ jsxRuntime.jsx(
1775
+ "button",
1776
+ {
1777
+ type: "button",
1778
+ className: "cd-menubar__trigger",
1779
+ onClick: () => setOpen(open === i ? null : i),
1780
+ onMouseEnter: () => open != null && setOpen(i),
1781
+ children: menu.label
1782
+ }
1783
+ ),
1784
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-menubar__menu", role: "menu", children: menu.items.map((item, j) => /* @__PURE__ */ jsxRuntime.jsx(
1785
+ "button",
1786
+ {
1787
+ type: "button",
1788
+ role: "menuitem",
1789
+ disabled: item.disabled,
1790
+ className: "cd-menubar__action",
1791
+ onClick: () => {
1792
+ item.onSelect?.();
1793
+ setOpen(null);
1794
+ },
1795
+ children: item.label
1796
+ },
1797
+ j
1798
+ )) })
1799
+ ]
1800
+ },
1801
+ i
1802
+ )) });
1803
+ }
1804
+ function Select({
1805
+ size = "md",
1806
+ label = false,
1807
+ error = false,
1808
+ className = "",
1809
+ children,
1810
+ ...rest
1811
+ }) {
1812
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-select-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(
1813
+ "select",
1814
+ {
1815
+ className: cn(
1816
+ "cd-select",
1817
+ size === "sm" && "cd-select--sm",
1818
+ label && "cd-select--label",
1819
+ error && "cd-select--error",
1820
+ className
1821
+ ),
1822
+ ...rest,
1823
+ children
1824
+ }
1825
+ ) });
1826
+ }
1827
+ function NativeSelect(props) {
1828
+ return /* @__PURE__ */ jsxRuntime.jsx(Select, { ...props });
1829
+ }
1830
+ function NavigationMenu({ items, className = "", ...rest }) {
1831
+ return /* @__PURE__ */ jsxRuntime.jsx("nav", { className: cn("cd-nav-menu", className), ...rest, children: items.map((item, i) => {
1832
+ const cls = cn("cd-nav-menu__link", item.active && "is-active");
1833
+ if (item.href) {
1834
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { href: item.href, className: cls, onClick: item.onClick, children: item.label }, i);
1835
+ }
1836
+ return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: cls, onClick: item.onClick, children: item.label }, i);
1837
+ }) });
1838
+ }
1839
+ function buildPages(page, pageCount, siblingCount) {
1840
+ const total = pageCount;
1841
+ const left = Math.max(2, page - siblingCount);
1842
+ const right = Math.min(total - 1, page + siblingCount);
1843
+ const pages = [1];
1844
+ if (left > 2) pages.push("\u2026");
1845
+ for (let p = left; p <= right; p++) pages.push(p);
1846
+ if (right < total - 1) pages.push("\u2026");
1847
+ if (total > 1) pages.push(total);
1848
+ return pages;
1849
+ }
1850
+ function Pagination({
1851
+ page,
1852
+ pageCount,
1853
+ onPageChange,
1854
+ siblingCount = 1,
1855
+ size = "default",
1856
+ compact = false,
1857
+ showInfo = false,
1858
+ prevLabel = "\u2039 Prev",
1859
+ nextLabel = "Next \u203A",
1860
+ className = "",
1861
+ ...rest
1862
+ }) {
1863
+ const go = (p) => {
1864
+ if (p < 1 || p > pageCount || p === page) return;
1865
+ onPageChange?.(p);
1866
+ };
1867
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1868
+ "nav",
1869
+ {
1870
+ className: cn(
1871
+ "cd-pagination",
1872
+ size !== "default" && `cd-pagination--${size}`,
1873
+ compact && "cd-pagination--compact",
1874
+ className
1875
+ ),
1876
+ "aria-label": "Pagination",
1877
+ ...rest,
1878
+ children: [
1879
+ /* @__PURE__ */ jsxRuntime.jsx(
1880
+ "button",
1881
+ {
1882
+ type: "button",
1883
+ className: "cd-pagination__prev cd-pagination__item",
1884
+ disabled: page <= 1,
1885
+ "aria-disabled": page <= 1 || void 0,
1886
+ onClick: () => go(page - 1),
1887
+ children: prevLabel
1888
+ }
1889
+ ),
1890
+ buildPages(page, pageCount, siblingCount).map(
1891
+ (p, i) => p === "\u2026" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-pagination__ellipsis", children: "\xB7\xB7\xB7" }, `e${i}`) : /* @__PURE__ */ jsxRuntime.jsx(
1892
+ "button",
1893
+ {
1894
+ type: "button",
1895
+ className: cn("cd-pagination__item", p === page && "is-active"),
1896
+ "aria-current": p === page ? "page" : void 0,
1897
+ onClick: () => go(p),
1898
+ children: p
1899
+ },
1900
+ p
1901
+ )
1902
+ ),
1903
+ /* @__PURE__ */ jsxRuntime.jsx(
1904
+ "button",
1905
+ {
1906
+ type: "button",
1907
+ className: "cd-pagination__next cd-pagination__item",
1908
+ disabled: page >= pageCount,
1909
+ "aria-disabled": page >= pageCount || void 0,
1910
+ onClick: () => go(page + 1),
1911
+ children: nextLabel
1912
+ }
1913
+ ),
1914
+ showInfo && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cd-pagination__info", children: [
1915
+ "Page ",
1916
+ page,
1917
+ " of ",
1918
+ pageCount
1919
+ ] })
1920
+ ]
1921
+ }
1922
+ );
1923
+ }
1924
+ function Popover({
1925
+ trigger,
1926
+ defaultOpen = false,
1927
+ open,
1928
+ onOpenChange,
1929
+ side = "bottom",
1930
+ title,
1931
+ description,
1932
+ className = "",
1933
+ children,
1934
+ ...rest
1935
+ }) {
1936
+ const [internal, setInternal] = react.useState(defaultOpen);
1937
+ const isOpen = open ?? internal;
1938
+ const setOpen = (next) => {
1939
+ if (open == null) setInternal(next);
1940
+ onOpenChange?.(next);
1941
+ };
1942
+ const sideClass = side === "top" ? "cd-popover__content--top" : side === "right" ? "cd-popover__content--right" : side === "bottom-end" ? "cd-popover__content--bottom-end" : "cd-popover__content--bottom";
1943
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-popover", isOpen && "is-open", className), ...rest, children: [
1944
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => setOpen(!isOpen), "aria-expanded": isOpen, children: trigger }),
1945
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-popover__content", sideClass), role: "dialog", children: [
1946
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-popover__title", children: title }),
1947
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "cd-popover__description", children: description }),
1948
+ children
1949
+ ] })
1950
+ ] });
1951
+ }
1952
+ function Progress({
1953
+ value = 0,
1954
+ variant = "default",
1955
+ thick = false,
1956
+ indeterminate = false,
1957
+ className = "",
1958
+ ...rest
1959
+ }) {
1960
+ return /* @__PURE__ */ jsxRuntime.jsx(
1961
+ "div",
1962
+ {
1963
+ className: cn(
1964
+ "cd-progress",
1965
+ variant !== "default" && `cd-progress--${variant}`,
1966
+ thick && "cd-progress--thick",
1967
+ indeterminate && "cd-progress--indeterminate",
1968
+ className
1969
+ ),
1970
+ role: "progressbar",
1971
+ "aria-valuenow": indeterminate ? void 0 : value,
1972
+ "aria-valuemin": 0,
1973
+ "aria-valuemax": 100,
1974
+ ...rest,
1975
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1976
+ "div",
1977
+ {
1978
+ className: "cd-progress__bar",
1979
+ style: indeterminate ? void 0 : { width: `${value}%` }
1980
+ }
1981
+ )
1982
+ }
1983
+ );
1984
+ }
1985
+ function Radio({ label, description, className = "", ...rest }) {
1986
+ const input = /* @__PURE__ */ jsxRuntime.jsx("input", { type: "radio", className: cn("cd-radio", !label && className), ...rest });
1987
+ if (label == null && description == null) return input;
1988
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: cn("cd-control", className), children: [
1989
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "radio", className: "cd-radio", ...rest }),
1990
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cd-control__label", children: [
1991
+ label,
1992
+ description != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-control__desc", children: description })
1993
+ ] })
1994
+ ] });
1995
+ }
1996
+ function RadioGroup({
1997
+ name,
1998
+ items,
1999
+ value,
2000
+ defaultValue,
2001
+ onValueChange,
2002
+ orientation = "vertical",
2003
+ className = "",
2004
+ ...rest
2005
+ }) {
2006
+ return /* @__PURE__ */ jsxRuntime.jsx(
2007
+ "div",
2008
+ {
2009
+ className: cn(className),
2010
+ role: "radiogroup",
2011
+ style: {
2012
+ display: "flex",
2013
+ flexDirection: orientation === "horizontal" ? "row" : "column",
2014
+ gap: orientation === "horizontal" ? 16 : 8
2015
+ },
2016
+ ...rest,
2017
+ children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
2018
+ Radio,
2019
+ {
2020
+ name,
2021
+ value: item.value,
2022
+ label: item.label,
2023
+ description: item.description,
2024
+ disabled: item.disabled,
2025
+ defaultChecked: defaultValue === item.value,
2026
+ checked: value != null ? value === item.value : void 0,
2027
+ onChange: () => onValueChange?.(item.value)
2028
+ },
2029
+ item.value
2030
+ ))
2031
+ }
2032
+ );
2033
+ }
2034
+ function Resizable({
2035
+ first,
2036
+ second,
2037
+ orientation = "horizontal",
2038
+ defaultSize = 50,
2039
+ minSize = 15,
2040
+ maxSize = 85,
2041
+ className = "",
2042
+ ...rest
2043
+ }) {
2044
+ const [size, setSize] = react.useState(defaultSize);
2045
+ const rootRef = react.useRef(null);
2046
+ const dragging = react.useRef(false);
2047
+ const onMove = react.useCallback(
2048
+ (clientX, clientY) => {
2049
+ const el = rootRef.current;
2050
+ if (!el || !dragging.current) return;
2051
+ const rect = el.getBoundingClientRect();
2052
+ const pct = orientation === "horizontal" ? (clientX - rect.left) / rect.width * 100 : (clientY - rect.top) / rect.height * 100;
2053
+ setSize(Math.min(maxSize, Math.max(minSize, pct)));
2054
+ },
2055
+ [orientation, minSize, maxSize]
2056
+ );
2057
+ const onMouseDown = (e) => {
2058
+ e.preventDefault();
2059
+ dragging.current = true;
2060
+ const move = (ev) => onMove(ev.clientX, ev.clientY);
2061
+ const up = () => {
2062
+ dragging.current = false;
2063
+ window.removeEventListener("mousemove", move);
2064
+ window.removeEventListener("mouseup", up);
2065
+ };
2066
+ window.addEventListener("mousemove", move);
2067
+ window.addEventListener("mouseup", up);
2068
+ };
2069
+ const firstStyle = orientation === "horizontal" ? { width: `${size}%`, flex: "none" } : { height: `${size}%`, flex: "none" };
2070
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2071
+ "div",
2072
+ {
2073
+ ref: rootRef,
2074
+ className: cn(
2075
+ "cd-resizable",
2076
+ orientation === "vertical" && "cd-resizable--vertical",
2077
+ className
2078
+ ),
2079
+ ...rest,
2080
+ children: [
2081
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-resizable__panel", style: firstStyle, children: first }),
2082
+ /* @__PURE__ */ jsxRuntime.jsx(
2083
+ "div",
2084
+ {
2085
+ className: "cd-resizable__handle",
2086
+ role: "separator",
2087
+ "aria-orientation": orientation,
2088
+ onMouseDown
2089
+ }
2090
+ ),
2091
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-resizable__panel", style: { flex: 1 }, children: second })
2092
+ ]
2093
+ }
2094
+ );
2095
+ }
2096
+ function Scanner({
2097
+ vertical = false,
2098
+ ping = false,
2099
+ className = "",
2100
+ children,
2101
+ ...rest
2102
+ }) {
2103
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2104
+ "div",
2105
+ {
2106
+ className: cn(
2107
+ "cd-scanner",
2108
+ vertical && "cd-scanner--vertical",
2109
+ ping && "cd-scanner--ping",
2110
+ className
2111
+ ),
2112
+ ...rest,
2113
+ children: [
2114
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-scanner__line" }),
2115
+ children
2116
+ ]
2117
+ }
2118
+ );
2119
+ }
2120
+ function ScrollArea({
2121
+ thin = true,
2122
+ className = "",
2123
+ children,
2124
+ ...rest
2125
+ }) {
2126
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-scroll-area", thin && "cd-scroll-area--thin", className), ...rest, children });
2127
+ }
2128
+ function SectionHeader({
2129
+ title,
2130
+ caret = "\u25B8",
2131
+ actions,
2132
+ className = "",
2133
+ children,
2134
+ ...rest
2135
+ }) {
2136
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-section-header", className), ...rest, children: [
2137
+ caret != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-section-header__caret", children: caret }),
2138
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "cd-section-header__title", children: title }),
2139
+ children,
2140
+ actions != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-section-header__actions", children: actions })
2141
+ ] });
2142
+ }
2143
+ function Separator({
2144
+ orientation = "horizontal",
2145
+ neon = false,
2146
+ className = "",
2147
+ children,
2148
+ ...rest
2149
+ }) {
2150
+ const hasLabel = children != null;
2151
+ return /* @__PURE__ */ jsxRuntime.jsx(
2152
+ "div",
2153
+ {
2154
+ className: cn(
2155
+ "cd-separator",
2156
+ orientation === "vertical" && "cd-separator--vertical",
2157
+ neon && "cd-separator--neon",
2158
+ hasLabel && "cd-separator--label",
2159
+ !hasLabel && orientation === "horizontal" && "cd-separator--plain",
2160
+ className
2161
+ ),
2162
+ role: "separator",
2163
+ ...rest,
2164
+ children
2165
+ }
2166
+ );
2167
+ }
2168
+ function Sidebar({
2169
+ title = "Nav",
2170
+ links,
2171
+ children,
2172
+ defaultCollapsed = false,
2173
+ collapsed,
2174
+ onCollapsedChange,
2175
+ className = "",
2176
+ ...rest
2177
+ }) {
2178
+ const [internal, setInternal] = react.useState(defaultCollapsed);
2179
+ const isCollapsed = collapsed ?? internal;
2180
+ const toggle = () => {
2181
+ const next = !isCollapsed;
2182
+ if (collapsed == null) setInternal(next);
2183
+ onCollapsedChange?.(next);
2184
+ };
2185
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-sidebar-layout", className), ...rest, children: [
2186
+ /* @__PURE__ */ jsxRuntime.jsxs("aside", { className: cn("cd-sidebar", isCollapsed && "cd-sidebar--collapsed"), children: [
2187
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-sidebar__header", children: [
2188
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-sidebar__title", children: title }),
2189
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", size: "sm", icon: true, onClick: toggle, "aria-label": "Toggle sidebar", children: isCollapsed ? "\u203A" : "\u2039" })
2190
+ ] }),
2191
+ /* @__PURE__ */ jsxRuntime.jsx("nav", { className: "cd-sidebar__nav", children: links.map((link, i) => {
2192
+ const cls = cn("cd-sidebar__link", link.active && "is-active");
2193
+ const body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2194
+ link.icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-sidebar__link-icon", children: link.icon }),
2195
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-sidebar__link-label", children: link.label })
2196
+ ] });
2197
+ if (link.href) {
2198
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { href: link.href, className: cls, onClick: link.onClick, children: body }, i);
2199
+ }
2200
+ return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: cls, onClick: link.onClick, children: body }, i);
2201
+ }) })
2202
+ ] }),
2203
+ /* @__PURE__ */ jsxRuntime.jsx("main", { className: "cd-sidebar__main", children })
2204
+ ] });
2205
+ }
2206
+ function Skeleton({
2207
+ shape = "plain",
2208
+ width,
2209
+ className = "",
2210
+ children,
2211
+ ...rest
2212
+ }) {
2213
+ if (shape === "card" || shape === "block") {
2214
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(`cd-skeleton-${shape}`, className), ...rest, children });
2215
+ }
2216
+ return /* @__PURE__ */ jsxRuntime.jsx(
2217
+ "div",
2218
+ {
2219
+ className: cn(
2220
+ "cd-skeleton",
2221
+ shape !== "plain" && `cd-skeleton--${shape}`,
2222
+ width && `cd-skeleton--w-${width}`,
2223
+ className
2224
+ ),
2225
+ ...rest,
2226
+ children
2227
+ }
2228
+ );
2229
+ }
2230
+ function SkeletonRow({ className = "", children, ...rest }) {
2231
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-skeleton-block__row", className), ...rest, children });
2232
+ }
2233
+ function Slider({ valueLabel, className = "", ...rest }) {
2234
+ const input = /* @__PURE__ */ jsxRuntime.jsx("input", { type: "range", className: cn("cd-slider", !valueLabel && className), ...rest });
2235
+ if (valueLabel == null) return input;
2236
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-slider-wrap", className), children: [
2237
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "range", className: "cd-slider", ...rest }),
2238
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-slider-value", children: valueLabel })
2239
+ ] });
2240
+ }
2241
+ function colToLetter(index) {
2242
+ let n = index;
2243
+ let s = "";
2244
+ do {
2245
+ s = String.fromCharCode(65 + n % 26) + s;
2246
+ n = Math.floor(n / 26) - 1;
2247
+ } while (n >= 0);
2248
+ return s;
2249
+ }
2250
+ function parseCellRef(ref) {
2251
+ const m = ref.trim().toUpperCase().match(/^([A-Z]+)(\d+)$/);
2252
+ if (!m) return null;
2253
+ const letters = m[1];
2254
+ const row = parseInt(m[2], 10) - 1;
2255
+ let col = 0;
2256
+ for (let i = 0; i < letters.length; i++) {
2257
+ col = col * 26 + (letters.charCodeAt(i) - 64);
2258
+ }
2259
+ col -= 1;
2260
+ if (row < 0 || col < 0) return null;
2261
+ return { row, col };
2262
+ }
2263
+ function cellAddress(row, col) {
2264
+ return `${colToLetter(col)}${row + 1}`;
2265
+ }
2266
+ function createMatrix(rows, cols, fill = "") {
2267
+ return Array.from({ length: rows }, () => Array.from({ length: cols }, () => fill));
2268
+ }
2269
+ function cloneMatrix(data) {
2270
+ return data.map((row) => [...row]);
2271
+ }
2272
+ function ensureSize(data, rows, cols) {
2273
+ const next = data.map((row) => {
2274
+ const r = [...row];
2275
+ while (r.length < cols) r.push("");
2276
+ return r.slice(0, cols);
2277
+ });
2278
+ while (next.length < rows) next.push(Array.from({ length: cols }, () => ""));
2279
+ return next.slice(0, rows);
2280
+ }
2281
+ function isNumericDisplay(value) {
2282
+ if (value === "" || value.startsWith("=")) return false;
2283
+ return !Number.isNaN(Number(value)) && value.trim() !== "";
2284
+ }
2285
+ function evaluateFormula(raw, data, stack = /* @__PURE__ */ new Set()) {
2286
+ const expr = raw.slice(1).trim();
2287
+ if (!expr) return "";
2288
+ const getCell = (row, col) => {
2289
+ if (row < 0 || col < 0 || row >= data.length || col >= (data[0]?.length ?? 0)) return 0;
2290
+ const v = data[row][col] ?? "";
2291
+ if (v.startsWith("=")) {
2292
+ const addr = cellAddress(row, col);
2293
+ if (stack.has(addr)) return "#CYCLE!";
2294
+ const next = new Set(stack);
2295
+ next.add(addr);
2296
+ const out = evaluateFormula(v, data, next);
2297
+ if (out.startsWith("#")) return out;
2298
+ const n2 = Number(out);
2299
+ return Number.isNaN(n2) ? out : n2;
2300
+ }
2301
+ if (v === "") return 0;
2302
+ const n = Number(v);
2303
+ return Number.isNaN(n) ? v : n;
2304
+ };
2305
+ const rangeValues = (a, b) => {
2306
+ const start = parseCellRef(a);
2307
+ const end = parseCellRef(b);
2308
+ if (!start || !end) return [];
2309
+ const r0 = Math.min(start.row, end.row);
2310
+ const r1 = Math.max(start.row, end.row);
2311
+ const c0 = Math.min(start.col, end.col);
2312
+ const c1 = Math.max(start.col, end.col);
2313
+ const vals = [];
2314
+ for (let r = r0; r <= r1; r++) {
2315
+ for (let c = c0; c <= c1; c++) {
2316
+ const v = getCell(r, c);
2317
+ if (typeof v === "number") vals.push(v);
2318
+ else if (typeof v === "string" && !v.startsWith("#")) {
2319
+ const n = Number(v);
2320
+ if (!Number.isNaN(n)) vals.push(n);
2321
+ }
2322
+ }
2323
+ }
2324
+ return vals;
2325
+ };
2326
+ const fnMatch = expr.match(/^(SUM|AVG|AVERAGE|MIN|MAX|COUNT)\(([^)]+)\)$/i);
2327
+ if (fnMatch) {
2328
+ const fn = fnMatch[1].toUpperCase();
2329
+ const arg = fnMatch[2].trim();
2330
+ let vals = [];
2331
+ if (arg.includes(":")) {
2332
+ const [a, b] = arg.split(":");
2333
+ vals = rangeValues(a, b);
2334
+ } else {
2335
+ const parts = arg.split(",").map((p) => p.trim());
2336
+ for (const p of parts) {
2337
+ const ref = parseCellRef(p);
2338
+ if (ref) {
2339
+ const v = getCell(ref.row, ref.col);
2340
+ if (typeof v === "number") vals.push(v);
2341
+ } else {
2342
+ const n = Number(p);
2343
+ if (!Number.isNaN(n)) vals.push(n);
2344
+ }
2345
+ }
2346
+ }
2347
+ if (fn === "COUNT") return String(vals.length);
2348
+ if (vals.length === 0) return "0";
2349
+ if (fn === "SUM") return String(vals.reduce((a, b) => a + b, 0));
2350
+ if (fn === "AVG" || fn === "AVERAGE")
2351
+ return String(vals.reduce((a, b) => a + b, 0) / vals.length);
2352
+ if (fn === "MIN") return String(Math.min(...vals));
2353
+ if (fn === "MAX") return String(Math.max(...vals));
2354
+ }
2355
+ try {
2356
+ let replaced = expr.replace(/[A-Z]+\d+/gi, (ref) => {
2357
+ const coord = parseCellRef(ref);
2358
+ if (!coord) return "0";
2359
+ const v = getCell(coord.row, coord.col);
2360
+ if (typeof v === "string" && v.startsWith("#")) throw new Error(v);
2361
+ if (typeof v === "number") return String(v);
2362
+ const n = Number(v);
2363
+ if (Number.isNaN(n)) throw new Error("#VALUE!");
2364
+ return String(n);
2365
+ });
2366
+ if (!/^[\d+\-*/().\s]+$/.test(replaced)) return "#NAME?";
2367
+ const result = Function(`"use strict"; return (${replaced});`)();
2368
+ if (typeof result !== "number" || !Number.isFinite(result)) return "#NUM!";
2369
+ return String(Math.round(result * 1e10) / 1e10);
2370
+ } catch (e) {
2371
+ if (e instanceof Error && e.message.startsWith("#")) return e.message;
2372
+ return "#ERROR!";
2373
+ }
2374
+ }
2375
+ function displayValue(raw, data, formulas) {
2376
+ if (!formulas || !raw.startsWith("=")) return raw;
2377
+ return evaluateFormula(raw, data);
2378
+ }
2379
+ function inRange(cell, a, b) {
2380
+ const r0 = Math.min(a.row, b.row);
2381
+ const r1 = Math.max(a.row, b.row);
2382
+ const c0 = Math.min(a.col, b.col);
2383
+ const c1 = Math.max(a.col, b.col);
2384
+ return cell.row >= r0 && cell.row <= r1 && cell.col >= c0 && cell.col <= c1;
2385
+ }
2386
+ function Spreadsheet({
2387
+ data: controlledData,
2388
+ defaultData,
2389
+ onChange,
2390
+ onCellChange,
2391
+ rows: rowsProp,
2392
+ cols: colsProp,
2393
+ columnWidth = 96,
2394
+ maxHeight = 420,
2395
+ compact = false,
2396
+ readOnly = false,
2397
+ formulas = true,
2398
+ showFormulaBar = true,
2399
+ showStatus = true,
2400
+ columnLabels,
2401
+ rowLabels,
2402
+ className = "",
2403
+ style,
2404
+ ...rest
2405
+ }) {
2406
+ const rows = rowsProp ?? controlledData?.length ?? defaultData?.length ?? 12;
2407
+ const cols = colsProp ?? controlledData?.[0]?.length ?? defaultData?.[0]?.length ?? 8;
2408
+ const [internal, setInternal] = react.useState(
2409
+ () => ensureSize(defaultData ?? createMatrix(rows, cols), rows, cols)
2410
+ );
2411
+ const matrix = react.useMemo(() => {
2412
+ const source = controlledData ?? internal;
2413
+ return ensureSize(source, rows, cols);
2414
+ }, [controlledData, internal, rows, cols]);
2415
+ const [active, setActive] = react.useState({ row: 0, col: 0 });
2416
+ const [anchor, setAnchor] = react.useState({ row: 0, col: 0 });
2417
+ const [editing, setEditing] = react.useState(false);
2418
+ const [draft, setDraft] = react.useState("");
2419
+ const [editOrigin, setEditOrigin] = react.useState("edit");
2420
+ const rootRef = react.useRef(null);
2421
+ const cellInputRef = react.useRef(null);
2422
+ const fxInputRef = react.useRef(null);
2423
+ const setMatrix = react.useCallback(
2424
+ (next, cell) => {
2425
+ if (controlledData == null) setInternal(next);
2426
+ onChange?.(next);
2427
+ if (cell) onCellChange?.(cell.row, cell.col, cell.value, next);
2428
+ },
2429
+ [controlledData, onChange, onCellChange]
2430
+ );
2431
+ const commit = react.useCallback(
2432
+ (row, col, value) => {
2433
+ const next = cloneMatrix(matrix);
2434
+ next[row][col] = value;
2435
+ setMatrix(next, { row, col, value });
2436
+ },
2437
+ [matrix, setMatrix]
2438
+ );
2439
+ const beginEdit = react.useCallback(
2440
+ (mode, seed) => {
2441
+ if (readOnly) return;
2442
+ const raw = matrix[active.row]?.[active.col] ?? "";
2443
+ setDraft(seed !== void 0 ? seed : raw);
2444
+ setEditOrigin(mode);
2445
+ setEditing(true);
2446
+ },
2447
+ [readOnly, matrix, active]
2448
+ );
2449
+ const endEdit = react.useCallback(
2450
+ (save, move) => {
2451
+ if (editing && save) {
2452
+ commit(active.row, active.col, draft);
2453
+ }
2454
+ setEditing(false);
2455
+ setDraft("");
2456
+ if (move) {
2457
+ setActive(move);
2458
+ setAnchor(move);
2459
+ }
2460
+ requestAnimationFrame(() => rootRef.current?.focus());
2461
+ },
2462
+ [editing, draft, active, commit]
2463
+ );
2464
+ react.useEffect(() => {
2465
+ if (editing) {
2466
+ const el = cellInputRef.current;
2467
+ if (el) {
2468
+ el.focus();
2469
+ if (editOrigin === "edit") el.select();
2470
+ else {
2471
+ const len = el.value.length;
2472
+ el.setSelectionRange(len, len);
2473
+ }
2474
+ }
2475
+ }
2476
+ }, [editing, editOrigin]);
2477
+ const activeRaw = matrix[active.row]?.[active.col] ?? "";
2478
+ const activeDisplay = displayValue(activeRaw, matrix, formulas);
2479
+ const selectionCount = react.useMemo(() => {
2480
+ const r0 = Math.min(active.row, anchor.row);
2481
+ const r1 = Math.max(active.row, anchor.row);
2482
+ const c0 = Math.min(active.col, anchor.col);
2483
+ const c1 = Math.max(active.col, anchor.col);
2484
+ return (r1 - r0 + 1) * (c1 - c0 + 1);
2485
+ }, [active, anchor]);
2486
+ const moveActive = (row, col, extend) => {
2487
+ const next = {
2488
+ row: Math.max(0, Math.min(rows - 1, row)),
2489
+ col: Math.max(0, Math.min(cols - 1, col))
2490
+ };
2491
+ setActive(next);
2492
+ if (!extend) setAnchor(next);
2493
+ };
2494
+ const onGridKeyDown = (e) => {
2495
+ if (editing) return;
2496
+ const { key, shiftKey, metaKey, ctrlKey } = e;
2497
+ const mod = metaKey || ctrlKey;
2498
+ if (key === "F2" || key === "Enter") {
2499
+ e.preventDefault();
2500
+ if (key === "Enter" && !shiftKey) {
2501
+ beginEdit("edit");
2502
+ } else if (key === "F2") {
2503
+ beginEdit("edit");
2504
+ } else if (key === "Enter" && shiftKey) {
2505
+ moveActive(active.row - 1, active.col, false);
2506
+ }
2507
+ return;
2508
+ }
2509
+ if (key === "Delete" || key === "Backspace") {
2510
+ if (readOnly) return;
2511
+ e.preventDefault();
2512
+ if (key === "Backspace") {
2513
+ beginEdit("type", "");
2514
+ } else {
2515
+ const next = cloneMatrix(matrix);
2516
+ for (let r = 0; r < rows; r++) {
2517
+ for (let c = 0; c < cols; c++) {
2518
+ if (inRange({ row: r, col: c }, active, anchor)) next[r][c] = "";
2519
+ }
2520
+ }
2521
+ setMatrix(next);
2522
+ }
2523
+ return;
2524
+ }
2525
+ if (mod && key.toLowerCase() === "c") {
2526
+ e.preventDefault();
2527
+ const text = activeRaw;
2528
+ void navigator.clipboard?.writeText(text);
2529
+ return;
2530
+ }
2531
+ if (mod && key.toLowerCase() === "v" && !readOnly) {
2532
+ e.preventDefault();
2533
+ void navigator.clipboard?.readText().then((text) => {
2534
+ const lines = text.replace(/\r/g, "").split("\n").filter((l, i, arr) => !(i === arr.length - 1 && l === ""));
2535
+ const next = cloneMatrix(matrix);
2536
+ lines.forEach((line, ri) => {
2537
+ const cells = line.split(" ");
2538
+ cells.forEach((val, ci) => {
2539
+ const r = active.row + ri;
2540
+ const c = active.col + ci;
2541
+ if (r < rows && c < cols) next[r][c] = val;
2542
+ });
2543
+ });
2544
+ setMatrix(next);
2545
+ });
2546
+ return;
2547
+ }
2548
+ const nav = {
2549
+ ArrowUp: [-1, 0],
2550
+ ArrowDown: [1, 0],
2551
+ ArrowLeft: [0, -1],
2552
+ ArrowRight: [0, 1],
2553
+ Tab: [0, shiftKey ? -1 : 1],
2554
+ Home: [0, -active.col],
2555
+ End: [0, cols - 1 - active.col]
2556
+ };
2557
+ if (key in nav) {
2558
+ e.preventDefault();
2559
+ const [dr, dc] = nav[key];
2560
+ if (key === "Tab") {
2561
+ moveActive(active.row + dr, active.col + dc, false);
2562
+ } else {
2563
+ moveActive(active.row + dr, active.col + dc, shiftKey);
2564
+ }
2565
+ return;
2566
+ }
2567
+ if (!readOnly && key.length === 1 && !mod && !e.altKey) {
2568
+ e.preventDefault();
2569
+ beginEdit("type", key);
2570
+ }
2571
+ };
2572
+ const onEditorKeyDown = (e) => {
2573
+ if (e.key === "Escape") {
2574
+ e.preventDefault();
2575
+ endEdit(false);
2576
+ return;
2577
+ }
2578
+ if (e.key === "Enter") {
2579
+ e.preventDefault();
2580
+ endEdit(true, {
2581
+ row: Math.min(rows - 1, active.row + (e.shiftKey ? -1 : 1)),
2582
+ col: active.col
2583
+ });
2584
+ return;
2585
+ }
2586
+ if (e.key === "Tab") {
2587
+ e.preventDefault();
2588
+ endEdit(true, {
2589
+ row: active.row,
2590
+ col: Math.max(0, Math.min(cols - 1, active.col + (e.shiftKey ? -1 : 1)))
2591
+ });
2592
+ return;
2593
+ }
2594
+ };
2595
+ const styleVars = {
2596
+ ...style,
2597
+ ["--cd-sheetgrid-col-width"]: `${columnWidth}px`,
2598
+ ["--cd-sheetgrid-max-height"]: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight
2599
+ };
2600
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2601
+ "div",
2602
+ {
2603
+ ref: rootRef,
2604
+ className: cn(
2605
+ "cd-sheetgrid",
2606
+ compact && "cd-sheetgrid--compact",
2607
+ readOnly && "cd-sheetgrid--readonly",
2608
+ className
2609
+ ),
2610
+ style: styleVars,
2611
+ tabIndex: 0,
2612
+ role: "grid",
2613
+ "aria-rowcount": rows,
2614
+ "aria-colcount": cols,
2615
+ "aria-label": "Spreadsheet",
2616
+ onKeyDown: onGridKeyDown,
2617
+ ...rest,
2618
+ children: [
2619
+ showFormulaBar && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-sheetgrid__bar", children: [
2620
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheetgrid__addr", children: cellAddress(active.row, active.col) }),
2621
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheetgrid__fx-label", children: "\u0192x" }),
2622
+ /* @__PURE__ */ jsxRuntime.jsx(
2623
+ "input",
2624
+ {
2625
+ ref: fxInputRef,
2626
+ className: "cd-sheetgrid__fx-input",
2627
+ value: editing ? draft : activeRaw,
2628
+ disabled: readOnly,
2629
+ spellCheck: false,
2630
+ "aria-label": "Formula bar",
2631
+ onFocus: () => {
2632
+ if (!readOnly && !editing) beginEdit("edit");
2633
+ },
2634
+ onChange: (e) => {
2635
+ if (!editing) beginEdit("type", e.target.value);
2636
+ else setDraft(e.target.value);
2637
+ },
2638
+ onKeyDown: onEditorKeyDown,
2639
+ onBlur: () => {
2640
+ if (editing) endEdit(true);
2641
+ }
2642
+ }
2643
+ )
2644
+ ] }),
2645
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-sheetgrid__viewport", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "cd-sheetgrid__table", children: [
2646
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2647
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "cd-sheetgrid__corner", scope: "col" }),
2648
+ Array.from({ length: cols }, (_, c) => /* @__PURE__ */ jsxRuntime.jsx(
2649
+ "th",
2650
+ {
2651
+ className: cn(
2652
+ "cd-sheetgrid__col-head",
2653
+ (active.col === c || inRange({ row: active.row, col: c }, active, anchor)) && "is-active"
2654
+ ),
2655
+ scope: "col",
2656
+ children: columnLabels?.[c] ?? colToLetter(c)
2657
+ },
2658
+ c
2659
+ ))
2660
+ ] }) }),
2661
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: Array.from({ length: rows }, (_, r) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2662
+ /* @__PURE__ */ jsxRuntime.jsx(
2663
+ "th",
2664
+ {
2665
+ className: cn(
2666
+ "cd-sheetgrid__row-head",
2667
+ (active.row === r || inRange({ row: r, col: active.col }, active, anchor)) && "is-active"
2668
+ ),
2669
+ scope: "row",
2670
+ children: rowLabels?.[r] ?? r + 1
2671
+ }
2672
+ ),
2673
+ Array.from({ length: cols }, (_2, c) => {
2674
+ const raw = matrix[r]?.[c] ?? "";
2675
+ const shown = displayValue(raw, matrix, formulas);
2676
+ const isActive = active.row === r && active.col === c;
2677
+ const isSelected = inRange({ row: r, col: c }, active, anchor);
2678
+ const isEditing = isActive && editing;
2679
+ const isErr = formulas && raw.startsWith("=") && shown.startsWith("#");
2680
+ const isNum = !raw.startsWith("=") && isNumericDisplay(raw) || raw.startsWith("=") && isNumericDisplay(shown);
2681
+ return /* @__PURE__ */ jsxRuntime.jsx(
2682
+ "td",
2683
+ {
2684
+ role: "gridcell",
2685
+ "aria-selected": isSelected,
2686
+ "aria-colindex": c + 1,
2687
+ className: cn(
2688
+ "cd-sheetgrid__cell",
2689
+ isActive && "is-active",
2690
+ isSelected && "is-selected",
2691
+ isEditing && "is-editing",
2692
+ isNum && "cd-sheetgrid__cell--number",
2693
+ raw.startsWith("=") && "cd-sheetgrid__cell--formula",
2694
+ isErr && "cd-sheetgrid__cell--error"
2695
+ ),
2696
+ onMouseDown: (e) => {
2697
+ if (editing && isActive) return;
2698
+ if (editing) endEdit(true);
2699
+ e.preventDefault();
2700
+ rootRef.current?.focus();
2701
+ const next = { row: r, col: c };
2702
+ setActive(next);
2703
+ if (e.shiftKey) ; else {
2704
+ setAnchor(next);
2705
+ }
2706
+ },
2707
+ onDoubleClick: () => {
2708
+ if (!readOnly) beginEdit("edit");
2709
+ },
2710
+ children: isEditing ? /* @__PURE__ */ jsxRuntime.jsx(
2711
+ "input",
2712
+ {
2713
+ ref: cellInputRef,
2714
+ className: cn(
2715
+ "cd-sheetgrid__cell-input",
2716
+ isNum && "cd-sheetgrid__cell-input--number"
2717
+ ),
2718
+ value: draft,
2719
+ spellCheck: false,
2720
+ "aria-label": `Edit ${cellAddress(r, c)}`,
2721
+ onChange: (e) => setDraft(e.target.value),
2722
+ onKeyDown: onEditorKeyDown,
2723
+ onBlur: () => {
2724
+ requestAnimationFrame(() => {
2725
+ if (document.activeElement === fxInputRef.current) return;
2726
+ if (document.activeElement === cellInputRef.current) return;
2727
+ if (editing) endEdit(true);
2728
+ });
2729
+ }
2730
+ }
2731
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-sheetgrid__cell-display", children: shown })
2732
+ },
2733
+ c
2734
+ );
2735
+ })
2736
+ ] }, r)) })
2737
+ ] }) }),
2738
+ showStatus && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-sheetgrid__status", children: [
2739
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2740
+ "cell ",
2741
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: cellAddress(active.row, active.col) })
2742
+ ] }),
2743
+ selectionCount > 1 && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2744
+ "sel ",
2745
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: selectionCount })
2746
+ ] }),
2747
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: readOnly ? "read-only" : editing ? "editing" : "ready" }),
2748
+ formulas && activeRaw.startsWith("=") && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2749
+ "\u2192 ",
2750
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: activeDisplay })
2751
+ ] }),
2752
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { marginLeft: "auto" }, children: [
2753
+ rows,
2754
+ "\xD7",
2755
+ cols
2756
+ ] })
2757
+ ] })
2758
+ ]
2759
+ }
2760
+ );
2761
+ }
2762
+ function createSpreadsheetData(rows, cols, fill = "") {
2763
+ return createMatrix(rows, cols, fill);
2764
+ }
2765
+ function Stat({
2766
+ label,
2767
+ value,
2768
+ delta,
2769
+ trend,
2770
+ variant = "default",
2771
+ className = "",
2772
+ ...rest
2773
+ }) {
2774
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2775
+ "div",
2776
+ {
2777
+ className: cn("cd-stat", variant !== "default" && `cd-stat--${variant}`, className),
2778
+ ...rest,
2779
+ children: [
2780
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-stat__label", children: label }),
2781
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-stat__value", children: value }),
2782
+ delta != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-stat__delta", trend && `cd-stat__delta--${trend}`), children: delta })
2783
+ ]
2784
+ }
2785
+ );
2786
+ }
2787
+ function StatGrid({ className = "", children, ...rest }) {
2788
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-stats", className), ...rest, children });
2789
+ }
2790
+ Stat.Grid = StatGrid;
2791
+ function StatusBar({
2792
+ message,
2793
+ cursor = true,
2794
+ leading,
2795
+ meta,
2796
+ className = "",
2797
+ children,
2798
+ ...rest
2799
+ }) {
2800
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-status-bar", className), ...rest, children: [
2801
+ leading,
2802
+ message != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("cd-status-bar__message", cursor && "cd-status-bar__message--cursor"), children: message }),
2803
+ children,
2804
+ meta != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-status-bar__meta", children: meta })
2805
+ ] });
2806
+ }
2807
+ function StatusDot({
2808
+ status = "live",
2809
+ children,
2810
+ orbOnly = false,
2811
+ className = "",
2812
+ ...rest
2813
+ }) {
2814
+ const statusClass = status === "idle" ? void 0 : status === "success" ? "cd-status-dot--success" : `cd-status-dot--${status}`;
2815
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("cd-status-dot", statusClass, className), ...rest, children: [
2816
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-status-dot__orb", "aria-hidden": true }),
2817
+ !orbOnly && children != null && /* @__PURE__ */ jsxRuntime.jsx("span", { children })
2818
+ ] });
2819
+ }
2820
+ function StatusPill({
2821
+ variant = "default",
2822
+ className = "",
2823
+ children,
2824
+ ...rest
2825
+ }) {
2826
+ return /* @__PURE__ */ jsxRuntime.jsx(
2827
+ "span",
2828
+ {
2829
+ className: cn(
2830
+ "cd-status-pill",
2831
+ variant !== "default" && `cd-status-pill--${variant}`,
2832
+ className
2833
+ ),
2834
+ ...rest,
2835
+ children
2836
+ }
2837
+ );
2838
+ }
2839
+ function Switch({ size = "md", label, className = "", ...rest }) {
2840
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: cn("cd-switch", size === "sm" && "cd-switch--sm", className), children: [
2841
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "checkbox", className: "cd-switch__input", ...rest }),
2842
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-switch__track", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-switch__thumb" }) }),
2843
+ label != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-switch__label", children: label })
2844
+ ] });
2845
+ }
2846
+ function Tabs({
2847
+ items,
2848
+ variant = "underline",
2849
+ defaultActive = 0,
2850
+ active,
2851
+ onTabChange,
2852
+ hidePanels = false,
2853
+ className = ""
2854
+ }) {
2855
+ const [internal, setInternal] = react.useState(defaultActive);
2856
+ const current = active ?? internal;
2857
+ const select = (i) => {
2858
+ if (items[i]?.disabled) return;
2859
+ if (active == null) setInternal(i);
2860
+ onTabChange?.(i);
2861
+ };
2862
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2863
+ "div",
2864
+ {
2865
+ className: cn(
2866
+ "cd-tabs",
2867
+ variant === "pills" && "cd-tabs--pills",
2868
+ variant === "vertical" && "cd-tabs--vertical",
2869
+ className
2870
+ ),
2871
+ children: [
2872
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-tabs__list", role: "tablist", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs(
2873
+ "button",
2874
+ {
2875
+ type: "button",
2876
+ role: "tab",
2877
+ "aria-selected": i === current,
2878
+ disabled: item.disabled,
2879
+ className: cn("cd-tabs__trigger", i === current && "is-active"),
2880
+ onClick: () => select(i),
2881
+ children: [
2882
+ item.label,
2883
+ item.badge != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-badge cd-badge--orange", style: { marginLeft: 4 }, children: item.badge })
2884
+ ]
2885
+ },
2886
+ i
2887
+ )) }),
2888
+ !hidePanels && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-tabs__panels", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
2889
+ "div",
2890
+ {
2891
+ role: "tabpanel",
2892
+ className: cn("cd-tabs__panel", i === current && "is-active"),
2893
+ children: item.content
2894
+ },
2895
+ i
2896
+ )) })
2897
+ ]
2898
+ }
2899
+ );
2900
+ }
2901
+ function Terminal({
2902
+ title,
2903
+ controls = false,
2904
+ lines = [],
2905
+ compact = false,
2906
+ crt = false,
2907
+ input = false,
2908
+ inputPrompt = "root@net> ",
2909
+ inputProps,
2910
+ className = "",
2911
+ children,
2912
+ ...rest
2913
+ }) {
2914
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2915
+ "div",
2916
+ {
2917
+ className: cn(
2918
+ "cd-terminal",
2919
+ compact && "cd-terminal--compact",
2920
+ crt && "cd-terminal--crt",
2921
+ className
2922
+ ),
2923
+ ...rest,
2924
+ children: [
2925
+ (title != null || controls) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-terminal__header", children: [
2926
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__title", children: title }),
2927
+ controls && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-terminal__controls", children: [
2928
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__dot cd-terminal__dot--min", title: "Minimize" }),
2929
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__dot cd-terminal__dot--max", title: "Maximize" }),
2930
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__dot cd-terminal__dot--close", title: "Close" })
2931
+ ] })
2932
+ ] }),
2933
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-terminal__body cd-scrollbar", children: [
2934
+ lines.map((line, i) => /* @__PURE__ */ jsxRuntime.jsxs(
2935
+ "div",
2936
+ {
2937
+ className: cn("cd-terminal__line", line.type && `cd-terminal__line--${line.type}`),
2938
+ children: [
2939
+ line.prompt != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__prompt", children: line.prompt }),
2940
+ line.text
2941
+ ]
2942
+ },
2943
+ i
2944
+ )),
2945
+ children
2946
+ ] }),
2947
+ input && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-terminal__input", children: [
2948
+ inputPrompt != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-terminal__prompt", children: inputPrompt }),
2949
+ /* @__PURE__ */ jsxRuntime.jsx("input", { className: "cd-terminal__field", placeholder: "type command...", ...inputProps })
2950
+ ] })
2951
+ ]
2952
+ }
2953
+ );
2954
+ }
2955
+ function Textarea({ error = false, className = "", ...rest }) {
2956
+ return /* @__PURE__ */ jsxRuntime.jsx(
2957
+ "textarea",
2958
+ {
2959
+ className: cn("cd-textarea", error && "cd-textarea--error", className),
2960
+ ...rest
2961
+ }
2962
+ );
2963
+ }
2964
+ function Ticker({
2965
+ items,
2966
+ speed,
2967
+ fast = false,
2968
+ vertical = false,
2969
+ className = "",
2970
+ ...rest
2971
+ }) {
2972
+ const resolvedSpeed = fast ? "fast" : speed;
2973
+ return /* @__PURE__ */ jsxRuntime.jsx(
2974
+ "div",
2975
+ {
2976
+ className: cn(
2977
+ "cd-ticker",
2978
+ resolvedSpeed && `cd-ticker--${resolvedSpeed}`,
2979
+ vertical && "cd-ticker--vertical",
2980
+ className
2981
+ ),
2982
+ ...rest,
2983
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-ticker__inner", children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-ticker__item", children: item }, i)) })
2984
+ }
2985
+ );
2986
+ }
2987
+ function Toast({
2988
+ variant = "info",
2989
+ icon,
2990
+ title,
2991
+ onDismiss,
2992
+ className = "",
2993
+ children,
2994
+ ...rest
2995
+ }) {
2996
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-toast", `cd-toast--${variant}`, className), ...rest, children: [
2997
+ icon != null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cd-toast__icon", children: icon }),
2998
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-toast__content", children: [
2999
+ title != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-toast__title", children: title }),
3000
+ children != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cd-toast__body", children })
3001
+ ] }),
3002
+ onDismiss && /* @__PURE__ */ jsxRuntime.jsx("button", { className: "cd-toast__dismiss", onClick: onDismiss, "aria-label": "Dismiss", children: "\u2715" })
3003
+ ] });
3004
+ }
3005
+ var ToasterContext = react.createContext(null);
3006
+ function useToast() {
3007
+ const ctx = react.useContext(ToasterContext);
3008
+ if (!ctx) throw new Error("useToast must be used within <ToasterProvider>");
3009
+ return ctx;
3010
+ }
3011
+ function ToasterProvider({
3012
+ children,
3013
+ position = "bottom-right",
3014
+ duration = 4e3
3015
+ }) {
3016
+ const [items, setItems] = react.useState([]);
3017
+ const dismiss = react.useCallback((id) => {
3018
+ setItems((list) => list.filter((t) => t.id !== id));
3019
+ }, []);
3020
+ const toast = react.useCallback(
3021
+ (input) => {
3022
+ const id = input.id ?? `t-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
3023
+ const rec = { ...input, id };
3024
+ setItems((list) => [...list, rec]);
3025
+ const ms = input.duration ?? duration;
3026
+ if (ms > 0) window.setTimeout(() => dismiss(id), ms);
3027
+ return id;
3028
+ },
3029
+ [duration, dismiss]
3030
+ );
3031
+ const value = react.useMemo(() => ({ toast, dismiss }), [toast, dismiss]);
3032
+ return /* @__PURE__ */ jsxRuntime.jsxs(ToasterContext.Provider, { value, children: [
3033
+ children,
3034
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-toaster", `cd-toaster--${position}`), "aria-live": "polite", children: items.map(({ id, duration: _d, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(Toast, { ...props, onDismiss: () => dismiss(id) }, id)) })
3035
+ ] });
3036
+ }
3037
+ function Toaster(props) {
3038
+ return /* @__PURE__ */ jsxRuntime.jsx(ToasterProvider, { ...props });
3039
+ }
3040
+ function Toggle({
3041
+ pressed,
3042
+ defaultPressed = false,
3043
+ onPressedChange,
3044
+ size = "md",
3045
+ variant = "default",
3046
+ className = "",
3047
+ children,
3048
+ ...rest
3049
+ }) {
3050
+ const [internal, setInternal] = react.useState(defaultPressed);
3051
+ const isOn = pressed ?? internal;
3052
+ const { onClick, ...buttonRest } = rest;
3053
+ return /* @__PURE__ */ jsxRuntime.jsx(
3054
+ "button",
3055
+ {
3056
+ type: "button",
3057
+ className: cn(
3058
+ "cd-toggle",
3059
+ size === "sm" && "cd-toggle--sm",
3060
+ variant === "outline" && "cd-toggle--outline",
3061
+ isOn && "is-on",
3062
+ className
3063
+ ),
3064
+ "data-state": isOn ? "on" : "off",
3065
+ "aria-pressed": isOn,
3066
+ onClick: (e) => {
3067
+ onClick?.(e);
3068
+ const next = !isOn;
3069
+ if (pressed == null) setInternal(next);
3070
+ onPressedChange?.(next);
3071
+ },
3072
+ ...buttonRest,
3073
+ children
3074
+ }
3075
+ );
3076
+ }
3077
+ function ToggleGroup({
3078
+ items,
3079
+ value,
3080
+ defaultValue,
3081
+ multiple = false,
3082
+ onValueChange,
3083
+ size = "md",
3084
+ className = "",
3085
+ ...rest
3086
+ }) {
3087
+ const [internal, setInternal] = react.useState(
3088
+ defaultValue ?? (multiple ? [] : "")
3089
+ );
3090
+ const current = value ?? internal;
3091
+ const isOn = (v) => multiple ? current.includes(v) : current === v;
3092
+ const select = (v) => {
3093
+ let next;
3094
+ if (multiple) {
3095
+ const arr = [...current];
3096
+ const i = arr.indexOf(v);
3097
+ if (i >= 0) arr.splice(i, 1);
3098
+ else arr.push(v);
3099
+ next = arr;
3100
+ } else {
3101
+ next = current === v ? "" : v;
3102
+ }
3103
+ if (value == null) setInternal(next);
3104
+ onValueChange?.(next);
3105
+ };
3106
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-toggle-group", className), role: "group", ...rest, children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
3107
+ "button",
3108
+ {
3109
+ type: "button",
3110
+ disabled: item.disabled,
3111
+ className: cn("cd-toggle", size === "sm" && "cd-toggle--sm", isOn(item.value) && "is-on"),
3112
+ "data-state": isOn(item.value) ? "on" : "off",
3113
+ "aria-pressed": isOn(item.value),
3114
+ onClick: () => select(item.value),
3115
+ children: item.label
3116
+ },
3117
+ item.value
3118
+ )) });
3119
+ }
3120
+ function Tooltip({
3121
+ tip,
3122
+ below = false,
3123
+ className = "",
3124
+ children,
3125
+ ...rest
3126
+ }) {
3127
+ return /* @__PURE__ */ jsxRuntime.jsx(
3128
+ "span",
3129
+ {
3130
+ className: cn("cd-tooltip", below && "cd-tooltip--below", className),
3131
+ "data-tip": tip,
3132
+ ...rest,
3133
+ children
3134
+ }
3135
+ );
3136
+ }
3137
+ function Transport({
3138
+ playing = false,
3139
+ onPlay,
3140
+ onStop,
3141
+ playLabel = "\u25B6 Play",
3142
+ stopLabel = "\u25A0 Stop",
3143
+ disabled = false,
3144
+ className = "",
3145
+ children,
3146
+ ...rest
3147
+ }) {
3148
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("cd-transport", className), ...rest, children: [
3149
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cd-transport__group", children: [
3150
+ /* @__PURE__ */ jsxRuntime.jsx(
3151
+ Button,
3152
+ {
3153
+ type: "button",
3154
+ variant: "primary",
3155
+ disabled: disabled || playing,
3156
+ onClick: onPlay,
3157
+ children: playLabel
3158
+ }
3159
+ ),
3160
+ /* @__PURE__ */ jsxRuntime.jsx(
3161
+ Button,
3162
+ {
3163
+ type: "button",
3164
+ variant: "danger",
3165
+ disabled: disabled || !playing,
3166
+ onClick: onStop,
3167
+ children: stopLabel
3168
+ }
3169
+ )
3170
+ ] }),
3171
+ children
3172
+ ] });
3173
+ }
3174
+ function H1({ className = "", ...rest }) {
3175
+ return /* @__PURE__ */ jsxRuntime.jsx("h1", { className: cn("cd-h1", className), ...rest });
3176
+ }
3177
+ function H2({ className = "", ...rest }) {
3178
+ return /* @__PURE__ */ jsxRuntime.jsx("h2", { className: cn("cd-h2", className), ...rest });
3179
+ }
3180
+ function H3({ className = "", ...rest }) {
3181
+ return /* @__PURE__ */ jsxRuntime.jsx("h3", { className: cn("cd-h3", className), ...rest });
3182
+ }
3183
+ function H4({ className = "", ...rest }) {
3184
+ return /* @__PURE__ */ jsxRuntime.jsx("h4", { className: cn("cd-h4", className), ...rest });
3185
+ }
3186
+ function P({ className = "", ...rest }) {
3187
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("cd-p", className), ...rest });
3188
+ }
3189
+ function Lead({ className = "", ...rest }) {
3190
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("cd-lead", className), ...rest });
3191
+ }
3192
+ function Muted({ className = "", ...rest }) {
3193
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn("cd-muted", className), ...rest });
3194
+ }
3195
+ function Small({ className = "", ...rest }) {
3196
+ return /* @__PURE__ */ jsxRuntime.jsx("small", { className: cn("cd-small", className), ...rest });
3197
+ }
3198
+ function InlineCode({ className = "", ...rest }) {
3199
+ return /* @__PURE__ */ jsxRuntime.jsx("code", { className: cn("cd-code", className), ...rest });
3200
+ }
3201
+ function Pre({ className = "", ...rest }) {
3202
+ return /* @__PURE__ */ jsxRuntime.jsx("pre", { className: cn("cd-pre", className), ...rest });
3203
+ }
3204
+ function Blockquote({ className = "", ...rest }) {
3205
+ return /* @__PURE__ */ jsxRuntime.jsx("blockquote", { className: cn("cd-blockquote", className), ...rest });
3206
+ }
3207
+ function List({ className = "", ...rest }) {
3208
+ return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: cn("cd-list", className), ...rest });
3209
+ }
3210
+ function InlineLink({ className = "", ...rest }) {
3211
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { className: cn("cd-inline-link", className), ...rest });
3212
+ }
3213
+ function Typography({ className = "", children, ...rest }) {
3214
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("cd-typography", className), ...rest, children });
3215
+ }
3216
+
3217
+ exports.Accordion = Accordion;
3218
+ exports.Alert = Alert;
3219
+ exports.AlertDialog = AlertDialog;
3220
+ exports.AspectRatio = AspectRatio;
3221
+ exports.AugButton = AugButton;
3222
+ exports.AugPanel = AugPanel;
3223
+ exports.Avatar = Avatar;
3224
+ exports.AvatarGroup = AvatarGroup;
3225
+ exports.Badge = Badge;
3226
+ exports.Blockquote = Blockquote;
3227
+ exports.BottomNav = BottomNav;
3228
+ exports.Breadcrumb = Breadcrumb;
3229
+ exports.Button = Button;
3230
+ exports.ButtonGroup = ButtonGroup;
3231
+ exports.Calendar = Calendar;
3232
+ exports.Card = Card;
3233
+ exports.CardContent = CardContent;
3234
+ exports.CardDescription = CardDescription;
3235
+ exports.CardFooter = CardFooter;
3236
+ exports.CardHeader = CardHeader;
3237
+ exports.CardTitle = CardTitle;
3238
+ exports.Carousel = Carousel;
3239
+ exports.Chat = Chat;
3240
+ exports.ChatAction = ChatAction;
3241
+ exports.ChatActions = ChatActions;
3242
+ exports.ChatCodeBlock = ChatCodeBlock;
3243
+ exports.ChatMessage = ChatMessage;
3244
+ exports.ChatTyping = ChatTyping;
3245
+ exports.Checkbox = Checkbox;
3246
+ exports.Chip = Chip;
3247
+ exports.ChipRow = ChipRow;
3248
+ exports.Clock = Clock;
3249
+ exports.Collapsible = Collapsible;
3250
+ exports.Combobox = Combobox;
3251
+ exports.Command = Command;
3252
+ exports.ContextMenu = ContextMenu;
3253
+ exports.DataTable = DataTable;
3254
+ exports.DatePicker = DatePicker;
3255
+ exports.Dialog = Dialog;
3256
+ exports.Drawer = Drawer;
3257
+ exports.Dropdown = Dropdown;
3258
+ exports.DropdownMenu = DropdownMenu;
3259
+ exports.Empty = Empty;
3260
+ exports.Feed = Feed;
3261
+ exports.FeedItem = FeedItem;
3262
+ exports.Field = Field;
3263
+ exports.Gauge = Gauge;
3264
+ exports.GlowCard = GlowCard;
3265
+ exports.H1 = H1;
3266
+ exports.H2 = H2;
3267
+ exports.H3 = H3;
3268
+ exports.H4 = H4;
3269
+ exports.HBar = HBar;
3270
+ exports.HoverCard = HoverCard;
3271
+ exports.HudBar = HudBar;
3272
+ exports.HudFrame = HudFrame;
3273
+ exports.HudSegment = HudSegment;
3274
+ exports.InlineCode = InlineCode;
3275
+ exports.InlineLink = InlineLink;
3276
+ exports.Input = Input;
3277
+ exports.InputGroup = InputGroup;
3278
+ exports.InputGroupAddon = InputGroupAddon;
3279
+ exports.InputOTP = InputOTP;
3280
+ exports.Interference = Interference;
3281
+ exports.Item = Item;
3282
+ exports.ItemGroup = ItemGroup;
3283
+ exports.Kbd = Kbd;
3284
+ exports.KbdGroup = KbdGroup;
3285
+ exports.Label = Label;
3286
+ exports.Lead = Lead;
3287
+ exports.List = List;
3288
+ exports.Menubar = Menubar;
3289
+ exports.Modal = Modal;
3290
+ exports.Muted = Muted;
3291
+ exports.NativeSelect = NativeSelect;
3292
+ exports.NavigationMenu = NavigationMenu;
3293
+ exports.P = P;
3294
+ exports.Pagination = Pagination;
3295
+ exports.PanelHeader = PanelHeader;
3296
+ exports.Popover = Popover;
3297
+ exports.Pre = Pre;
3298
+ exports.Progress = Progress;
3299
+ exports.Radio = Radio;
3300
+ exports.RadioGroup = RadioGroup;
3301
+ exports.Resizable = Resizable;
3302
+ exports.Scanner = Scanner;
3303
+ exports.ScrollArea = ScrollArea;
3304
+ exports.SectionHeader = SectionHeader;
3305
+ exports.Select = Select;
3306
+ exports.Separator = Separator;
3307
+ exports.Sheet = Sheet;
3308
+ exports.Sidebar = Sidebar;
3309
+ exports.Skeleton = Skeleton;
3310
+ exports.SkeletonRow = SkeletonRow;
3311
+ exports.Slider = Slider;
3312
+ exports.Small = Small;
3313
+ exports.Spinner = Spinner;
3314
+ exports.Spreadsheet = Spreadsheet;
3315
+ exports.Stat = Stat;
3316
+ exports.StatGrid = StatGrid;
3317
+ exports.StatusBar = StatusBar;
3318
+ exports.StatusDot = StatusDot;
3319
+ exports.StatusPill = StatusPill;
3320
+ exports.Switch = Switch;
3321
+ exports.Table = Table;
3322
+ exports.Tabs = Tabs;
3323
+ exports.Terminal = Terminal;
3324
+ exports.Textarea = Textarea;
3325
+ exports.ThemeProvider = ThemeProvider;
3326
+ exports.Ticker = Ticker;
3327
+ exports.Toast = Toast;
3328
+ exports.Toaster = Toaster;
3329
+ exports.ToasterProvider = ToasterProvider;
3330
+ exports.Toggle = Toggle;
3331
+ exports.ToggleGroup = ToggleGroup;
3332
+ exports.Tooltip = Tooltip;
3333
+ exports.Transport = Transport;
3334
+ exports.Typography = Typography;
3335
+ exports.cn = cn;
3336
+ exports.createSpreadsheetData = createSpreadsheetData;
3337
+ exports.useTheme = useTheme;
3338
+ exports.useToast = useToast;
3339
+ //# sourceMappingURL=index.cjs.map
3340
+ //# sourceMappingURL=index.cjs.map