@yuhuanowo/yunui 0.2.14 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1154 @@
1
+ "use client";
2
+ import { cn, useAnchoredPosition } from './chunk-AV5TGEJS.js';
3
+ import { useYunUI } from './chunk-3RT24MSH.js';
4
+ import * as React3 from 'react';
5
+ import { forwardRef, useState, useEffect, useRef, useId, useMemo } from 'react';
6
+ import { ChevronDown, Search, X, ArrowRight, Loader2, AlertTriangle, Info, AlertCircle, CheckCircle2 } from 'lucide-react';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+ import * as Primitive from '@radix-ui/react-collapsible';
9
+ import * as PopoverPrimitive from '@radix-ui/react-popover';
10
+ import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
11
+ import { useSpring, useTransform, motion } from 'framer-motion';
12
+ import { Toaster as Toaster$1, toast as toast$1 } from 'sonner';
13
+
14
+ function CustomSelect({
15
+ options,
16
+ value,
17
+ onChange,
18
+ placeholder,
19
+ searchable = false,
20
+ className = "",
21
+ disabled = false
22
+ }) {
23
+ const t = useYunUI().useT("common.select");
24
+ const resolvedPlaceholder = placeholder || t("placeholder");
25
+ const [isOpen, setIsOpen] = useState(false);
26
+ const [searchQuery, setSearchQuery] = useState("");
27
+ const [highlighted, setHighlighted] = useState(-1);
28
+ const containerRef = useRef(null);
29
+ const inputRef = useRef(null);
30
+ const triggerRef = useRef(null);
31
+ const listRef = useRef(null);
32
+ const panelRef = useRef(null);
33
+ const { shift, maxHeight } = useAnchoredPosition(isOpen, panelRef);
34
+ const baseId = useId();
35
+ const listboxId = `${baseId}-listbox`;
36
+ const optionId = (i) => `${baseId}-opt-${i}`;
37
+ const selectedOption = options.find((o) => o.value === value);
38
+ const filteredOptions = searchQuery ? options.filter(
39
+ (o) => o.label.toLowerCase().includes(searchQuery.toLowerCase()) || o.value.toLowerCase().includes(searchQuery.toLowerCase())
40
+ ) : options;
41
+ useEffect(() => {
42
+ const handleClickOutside = (e) => {
43
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
44
+ setIsOpen(false);
45
+ setSearchQuery("");
46
+ }
47
+ };
48
+ document.addEventListener("mousedown", handleClickOutside);
49
+ return () => document.removeEventListener("mousedown", handleClickOutside);
50
+ }, []);
51
+ useEffect(() => {
52
+ if (!isOpen) return;
53
+ if (searchable && inputRef.current) inputRef.current.focus();
54
+ else triggerRef.current?.focus();
55
+ }, [isOpen, searchable]);
56
+ useEffect(() => {
57
+ if (isOpen) {
58
+ const sel = filteredOptions.findIndex((o) => o.value === value);
59
+ setHighlighted(sel >= 0 ? sel : 0);
60
+ } else {
61
+ setHighlighted(-1);
62
+ }
63
+ }, [isOpen]);
64
+ useEffect(() => {
65
+ if (highlighted >= filteredOptions.length) setHighlighted(filteredOptions.length - 1);
66
+ }, [filteredOptions.length, highlighted]);
67
+ useEffect(() => {
68
+ if (!isOpen || highlighted < 0 || !listRef.current) return;
69
+ listRef.current.querySelector(`#${CSS.escape(optionId(highlighted))}`)?.scrollIntoView({ block: "nearest" });
70
+ }, [highlighted, isOpen]);
71
+ const open = () => !disabled && setIsOpen(true);
72
+ const close = () => {
73
+ setIsOpen(false);
74
+ setSearchQuery("");
75
+ triggerRef.current?.focus();
76
+ };
77
+ const handleSelect = (optionValue) => {
78
+ onChange(optionValue);
79
+ setIsOpen(false);
80
+ setSearchQuery("");
81
+ triggerRef.current?.focus();
82
+ };
83
+ const handleKeyDown = (e) => {
84
+ if (disabled) return;
85
+ switch (e.key) {
86
+ case "ArrowDown":
87
+ e.preventDefault();
88
+ if (!isOpen) return open();
89
+ setHighlighted((h) => Math.min(h + 1, filteredOptions.length - 1));
90
+ break;
91
+ case "ArrowUp":
92
+ e.preventDefault();
93
+ if (!isOpen) return open();
94
+ setHighlighted((h) => Math.max(h - 1, 0));
95
+ break;
96
+ case "Home":
97
+ if (isOpen) {
98
+ e.preventDefault();
99
+ setHighlighted(0);
100
+ }
101
+ break;
102
+ case "End":
103
+ if (isOpen) {
104
+ e.preventDefault();
105
+ setHighlighted(filteredOptions.length - 1);
106
+ }
107
+ break;
108
+ case "Enter":
109
+ if (isOpen && filteredOptions[highlighted]) {
110
+ e.preventDefault();
111
+ handleSelect(filteredOptions[highlighted].value);
112
+ } else if (!isOpen) {
113
+ e.preventDefault();
114
+ open();
115
+ }
116
+ break;
117
+ case " ":
118
+ if (!isOpen && !searchable) {
119
+ e.preventDefault();
120
+ open();
121
+ }
122
+ break;
123
+ case "Escape":
124
+ if (isOpen) {
125
+ e.preventDefault();
126
+ close();
127
+ }
128
+ break;
129
+ case "Tab":
130
+ if (isOpen) setIsOpen(false);
131
+ break;
132
+ }
133
+ };
134
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: `relative ${className}`, onKeyDown: handleKeyDown, children: [
135
+ /* @__PURE__ */ jsxs(
136
+ "button",
137
+ {
138
+ ref: triggerRef,
139
+ type: "button",
140
+ onClick: () => !disabled && setIsOpen(!isOpen),
141
+ disabled,
142
+ "aria-haspopup": "listbox",
143
+ "aria-expanded": isOpen,
144
+ "aria-controls": isOpen ? listboxId : void 0,
145
+ "aria-activedescendant": isOpen && !searchable && highlighted >= 0 ? optionId(highlighted) : void 0,
146
+ className: `
147
+ w-full flex items-center justify-between gap-2 px-3 py-2
148
+ rounded-xl border border-(--border-default) bg-(--bg-elevated)
149
+ hover:border-(--border-strong) hover:bg-(--bg-hover)
150
+ transition-all duration-200 text-sm
151
+ ${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
152
+ ${isOpen ? "border-primary ring-2 ring-primary/20" : ""}
153
+ `,
154
+ children: [
155
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [
156
+ selectedOption?.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0", children: selectedOption.icon }),
157
+ /* @__PURE__ */ jsx("span", { className: `truncate ${!selectedOption ? "text-muted-foreground" : ""}`, children: selectedOption ? selectedOption.label : resolvedPlaceholder })
158
+ ] }),
159
+ /* @__PURE__ */ jsx(
160
+ ChevronDown,
161
+ {
162
+ size: 16,
163
+ className: `shrink-0 text-muted-foreground transition-transform ${isOpen ? "rotate-180" : ""}`
164
+ }
165
+ )
166
+ ]
167
+ }
168
+ ),
169
+ isOpen && /* @__PURE__ */ jsxs(
170
+ "div",
171
+ {
172
+ ref: panelRef,
173
+ style: { marginLeft: shift, maxHeight },
174
+ className: "\n absolute z-50 w-full mt-2\n rounded-2xl border border-border\n bg-background/60 backdrop-blur-2xl text-popover-foreground\n shadow-lg shadow-black/5\n max-h-64 overflow-hidden flex flex-col\n animate-in fade-in-0 zoom-in-95 duration-200\n ",
175
+ children: [
176
+ searchable && /* @__PURE__ */ jsx("div", { className: "px-2.5 pb-2 pt-1.5 border-b border-(--border-subtle)", children: /* @__PURE__ */ jsxs("div", { className: "relative", children: [
177
+ /* @__PURE__ */ jsx(Search, { size: 14, className: "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" }),
178
+ /* @__PURE__ */ jsx(
179
+ "input",
180
+ {
181
+ ref: inputRef,
182
+ type: "text",
183
+ role: "combobox",
184
+ "aria-expanded": isOpen,
185
+ "aria-controls": listboxId,
186
+ "aria-activedescendant": highlighted >= 0 ? optionId(highlighted) : void 0,
187
+ "aria-autocomplete": "list",
188
+ value: searchQuery,
189
+ onChange: (e) => setSearchQuery(e.target.value),
190
+ placeholder: t("search"),
191
+ "aria-label": t("search"),
192
+ className: "w-full pl-9 pr-8 py-1.5 text-sm rounded-lg\n bg-(--bg-muted) border border-transparent\n focus:border-primary focus:outline-none focus:bg-(--bg-elevated) transition-colors"
193
+ }
194
+ ),
195
+ searchQuery && /* @__PURE__ */ jsx(
196
+ "button",
197
+ {
198
+ type: "button",
199
+ onClick: () => setSearchQuery(""),
200
+ "aria-label": t("clearSearch"),
201
+ className: "absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors p-0.5 rounded-md hover:bg-(--bg-hover)",
202
+ title: t("clearSearch"),
203
+ children: /* @__PURE__ */ jsx(X, { size: 12 })
204
+ }
205
+ )
206
+ ] }) }),
207
+ /* @__PURE__ */ jsx(
208
+ "div",
209
+ {
210
+ ref: listRef,
211
+ role: "listbox",
212
+ id: listboxId,
213
+ className: "flex-1 min-h-0 max-h-52 overflow-y-auto overscroll-contain p-1",
214
+ children: filteredOptions.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-sm text-muted-foreground text-center whitespace-nowrap", children: t("noOptions") }) : filteredOptions.map((option, i) => {
215
+ const isSelected = option.value === value;
216
+ const isHigh = i === highlighted;
217
+ return /* @__PURE__ */ jsxs(
218
+ "button",
219
+ {
220
+ id: optionId(i),
221
+ type: "button",
222
+ role: "option",
223
+ "aria-selected": isSelected,
224
+ "data-highlighted": isHigh ? "" : void 0,
225
+ onClick: () => handleSelect(option.value),
226
+ onMouseEnter: () => setHighlighted(i),
227
+ className: `dropdown-item w-full text-left outline-none ${isSelected ? "active" : ""}`,
228
+ children: [
229
+ option.icon && /* @__PURE__ */ jsx("span", { className: "shrink-0 w-5 h-5 flex items-center justify-center", children: option.icon }),
230
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
231
+ /* @__PURE__ */ jsx("div", { className: "truncate", children: option.label }),
232
+ option.description && /* @__PURE__ */ jsx("div", { className: "text-xs font-normal text-muted-foreground truncate", children: option.description })
233
+ ] })
234
+ ]
235
+ },
236
+ option.value
237
+ );
238
+ })
239
+ }
240
+ )
241
+ ]
242
+ }
243
+ )
244
+ ] });
245
+ }
246
+ function SegmentedSelect({
247
+ options,
248
+ value,
249
+ onChange,
250
+ className,
251
+ disabled = false
252
+ }) {
253
+ return /* @__PURE__ */ jsx("div", { className: cn("flex gap-1 flex-wrap", className), children: options.map((opt) => {
254
+ const Icon = opt.icon;
255
+ return /* @__PURE__ */ jsxs(
256
+ "button",
257
+ {
258
+ type: "button",
259
+ onClick: () => !disabled && onChange(opt.value),
260
+ disabled,
261
+ "aria-pressed": value === opt.value,
262
+ title: opt.desc,
263
+ className: cn(
264
+ "inline-flex items-center justify-center gap-2 px-3 py-1.5 text-xs font-medium border rounded-lg whitespace-nowrap transition-all duration-150 ease cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
265
+ value === opt.value ? "text-foreground border-(--border-strong) bg-accent-subtle hover:bg-accent-muted hover:shadow-xs" : "text-muted-foreground border-(--border-default) bg-muted/50 hover:text-foreground hover:border-(--border-strong) hover:bg-muted",
266
+ disabled && "opacity-50 cursor-not-allowed pointer-events-none"
267
+ ),
268
+ children: [
269
+ Icon && /* @__PURE__ */ jsx(Icon, { size: 14 }),
270
+ opt.label
271
+ ]
272
+ },
273
+ String(opt.value)
274
+ );
275
+ }) });
276
+ }
277
+ function NavTabs({ tabs, activeKey, onChange, className = "", ariaLabel }) {
278
+ const { Link } = useYunUI();
279
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx("nav", { className: "flex items-center gap-1 overflow-x-auto overflow-y-hidden overscroll-x-contain", "aria-label": ariaLabel, children: tabs.map((tab) => {
280
+ const active = tab.key === activeKey;
281
+ const cls = `nav-tab ${active ? "active" : ""}`;
282
+ return tab.href ? /* @__PURE__ */ jsx(Link, { href: tab.href, className: cls, "aria-current": active ? "page" : void 0, children: tab.label }, tab.key) : /* @__PURE__ */ jsx(
283
+ "button",
284
+ {
285
+ type: "button",
286
+ onClick: () => onChange?.(tab.key),
287
+ className: cls,
288
+ "aria-current": active ? "true" : void 0,
289
+ children: tab.label
290
+ },
291
+ tab.key
292
+ );
293
+ }) }) });
294
+ }
295
+ function ShinyButton({
296
+ children,
297
+ className,
298
+ href,
299
+ onClick
300
+ }) {
301
+ const { Link } = useYunUI();
302
+ const ButtonContent = /* @__PURE__ */ jsxs(
303
+ "div",
304
+ {
305
+ className: cn(
306
+ "group relative flex items-center justify-center gap-2 overflow-hidden rounded-xl bg-(--text-primary) px-8 py-3 font-semibold text-background transition-all hover:ring-2 hover:ring-(--accent) hover:ring-offset-2 hover:ring-offset-background",
307
+ className
308
+ ),
309
+ children: [
310
+ /* @__PURE__ */ jsxs("span", { className: "relative z-10 flex items-center gap-2", children: [
311
+ children,
312
+ /* @__PURE__ */ jsx(ArrowRight, { className: "h-4 w-4 transition-transform group-hover:translate-x-1" })
313
+ ] }),
314
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 -z-10 block animate-shimmer bg-linear-to-r from-transparent via-(--text-primary)/10 to-transparent bg-size-[200%_100%]" })
315
+ ]
316
+ }
317
+ );
318
+ const focusCls = "rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-(--accent) focus-visible:ring-offset-2 focus-visible:ring-offset-background";
319
+ if (href) {
320
+ return /* @__PURE__ */ jsx(Link, { href, onClick, className: focusCls, children: ButtonContent });
321
+ }
322
+ return /* @__PURE__ */ jsx("button", { type: "button", onClick, className: focusCls, children: ButtonContent });
323
+ }
324
+ function Marquee({
325
+ className,
326
+ reverse,
327
+ pauseOnHover = false,
328
+ children,
329
+ vertical = false,
330
+ repeat = 4,
331
+ ...props
332
+ }) {
333
+ return /* @__PURE__ */ jsx(
334
+ "div",
335
+ {
336
+ ...props,
337
+ className: cn(
338
+ "group flex overflow-hidden p-2 [--duration:40s] [--gap:1rem] gap-(--gap)",
339
+ {
340
+ "flex-row": !vertical,
341
+ "flex-col": vertical
342
+ },
343
+ className
344
+ ),
345
+ children: Array(repeat).fill(0).map((_, i) => /* @__PURE__ */ jsx(
346
+ "div",
347
+ {
348
+ className: cn("flex shrink-0 justify-around gap-(--gap)", {
349
+ "animate-marquee flex-row": !vertical,
350
+ "animate-marquee-vertical flex-col": vertical,
351
+ "group-hover:[animation-play-state:paused]": pauseOnHover,
352
+ "[animation-direction:reverse]": reverse
353
+ }),
354
+ children
355
+ },
356
+ i
357
+ ))
358
+ }
359
+ );
360
+ }
361
+ var BentoGrid = ({
362
+ className,
363
+ children
364
+ }) => {
365
+ return /* @__PURE__ */ jsx(
366
+ "div",
367
+ {
368
+ className: cn(
369
+ "grid grid-cols-1 md:grid-cols-3 gap-6 max-w-7xl mx-auto",
370
+ className
371
+ ),
372
+ children
373
+ }
374
+ );
375
+ };
376
+ var BentoCard = ({
377
+ className,
378
+ title,
379
+ description,
380
+ header,
381
+ icon
382
+ }) => {
383
+ return /* @__PURE__ */ jsxs(
384
+ "div",
385
+ {
386
+ className: cn(
387
+ "row-span-1 glass-card p-6 flex flex-col justify-between space-y-4 group/bento overflow-hidden",
388
+ className
389
+ ),
390
+ children: [
391
+ header,
392
+ /* @__PURE__ */ jsxs("div", { className: "group-hover/bento:translate-x-2 transition duration-200", children: [
393
+ /* @__PURE__ */ jsx("div", { className: "mb-2 text-[var(--text-primary)]", children: icon }),
394
+ /* @__PURE__ */ jsx("div", { className: "font-semibold text-[var(--text-primary)] text-lg mb-2 mt-2", children: title }),
395
+ /* @__PURE__ */ jsx("div", { className: "font-normal text-[var(--text-secondary)] text-sm leading-relaxed", children: description })
396
+ ] })
397
+ ]
398
+ }
399
+ );
400
+ };
401
+ var Collapsible = Primitive.Root;
402
+ var CollapsibleTrigger2 = Primitive.CollapsibleTrigger;
403
+ var CollapsibleContent2 = forwardRef(({ children, ...props }, ref) => {
404
+ const [mounted, setMounted] = useState(false);
405
+ useEffect(() => {
406
+ setMounted(true);
407
+ }, []);
408
+ return /* @__PURE__ */ jsx(
409
+ Primitive.CollapsibleContent,
410
+ {
411
+ ref,
412
+ ...props,
413
+ className: cn(
414
+ "overflow-hidden",
415
+ mounted && "data-[state=closed]:animate-fd-collapsible-up data-[state=open]:animate-fd-collapsible-down",
416
+ props.className
417
+ ),
418
+ children
419
+ }
420
+ );
421
+ });
422
+ CollapsibleContent2.displayName = Primitive.CollapsibleContent.displayName;
423
+ var Popover = PopoverPrimitive.Root;
424
+ var PopoverTrigger = PopoverPrimitive.Trigger;
425
+ var PopoverContent = React3.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx(
426
+ PopoverPrimitive.Content,
427
+ {
428
+ ref,
429
+ align,
430
+ sideOffset,
431
+ side: "bottom",
432
+ className: cn(
433
+ "z-50 origin-(--radix-popover-content-transform-origin) overflow-y-auto max-h-(--radix-popover-content-available-height) min-w-[240px] max-w-[98vw] rounded-2xl border border-border bg-background/60 backdrop-blur-2xl p-2 text-sm text-popover-foreground shadow-lg shadow-black/5 focus-visible:outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
434
+ className
435
+ ),
436
+ ...props
437
+ }
438
+ ) }));
439
+ PopoverContent.displayName = PopoverPrimitive.Content.displayName;
440
+ var PopoverClose2 = PopoverPrimitive.PopoverClose;
441
+ var PopoverAnchor = PopoverPrimitive.Anchor;
442
+ var ScrollArea = React3.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
443
+ ScrollAreaPrimitive.Root,
444
+ {
445
+ ref,
446
+ className: cn("relative overflow-hidden", className),
447
+ ...props,
448
+ children: [
449
+ /* @__PURE__ */ jsx(ScrollAreaPrimitive.Viewport, { className: "h-full w-full rounded-[inherit]", children }),
450
+ /* @__PURE__ */ jsx(ScrollBar, {}),
451
+ /* @__PURE__ */ jsx(ScrollAreaPrimitive.Corner, {})
452
+ ]
453
+ }
454
+ ));
455
+ ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
456
+ var ScrollBar = React3.forwardRef(({ className, orientation = "vertical", ...props }, ref) => /* @__PURE__ */ jsx(
457
+ ScrollAreaPrimitive.ScrollAreaScrollbar,
458
+ {
459
+ ref,
460
+ orientation,
461
+ className: cn(
462
+ "flex touch-none select-none transition-colors",
463
+ orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
464
+ orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]",
465
+ className
466
+ ),
467
+ ...props,
468
+ children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.ScrollAreaThumb, { className: "relative flex-1 rounded-full bg-border" })
469
+ }
470
+ ));
471
+ ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
472
+ var sizeClasses = {
473
+ sm: {
474
+ track: "w-8 h-4",
475
+ thumb: "w-2.5 h-2.5",
476
+ thumbTranslate: "translate-x-3.5"
477
+ },
478
+ md: {
479
+ track: "w-11 h-6",
480
+ thumb: "w-4 h-4",
481
+ thumbTranslate: "translate-x-5"
482
+ }
483
+ };
484
+ var variantClasses = {
485
+ default: {
486
+ checkedTrack: "border-primary bg-primary/10",
487
+ uncheckedTrack: "border-(--border-strong) bg-muted",
488
+ checkedThumb: "bg-primary",
489
+ uncheckedThumb: "bg-(--border-strong)"
490
+ },
491
+ success: {
492
+ checkedTrack: "border-(--success) bg-success-soft",
493
+ uncheckedTrack: "border-(--border-strong) bg-muted",
494
+ checkedThumb: "bg-(--success)",
495
+ uncheckedThumb: "bg-(--border-strong)"
496
+ },
497
+ warning: {
498
+ checkedTrack: "border-(--warning) bg-warning-soft",
499
+ uncheckedTrack: "border-(--border-strong) bg-muted",
500
+ checkedThumb: "bg-(--warning)",
501
+ uncheckedThumb: "bg-(--border-strong)"
502
+ },
503
+ danger: {
504
+ checkedTrack: "border-(--error) bg-error-soft",
505
+ uncheckedTrack: "border-(--border-strong) bg-muted",
506
+ checkedThumb: "bg-(--error)",
507
+ uncheckedThumb: "bg-(--border-strong)"
508
+ }
509
+ };
510
+ var Switch = forwardRef(
511
+ ({ checked, onCheckedChange, disabled = false, size = "sm", variant = "default", className = "", id }, ref) => {
512
+ const sizeClass = sizeClasses[size];
513
+ const variantClass = variantClasses[variant];
514
+ return /* @__PURE__ */ jsx(
515
+ "button",
516
+ {
517
+ ref,
518
+ type: "button",
519
+ role: "switch",
520
+ "aria-checked": checked,
521
+ id,
522
+ onClick: () => !disabled && onCheckedChange(!checked),
523
+ disabled,
524
+ className: `
525
+ ${sizeClass.track} rounded-full border-2 flex items-center px-0.5
526
+ transition-all duration-200 ease-in-out
527
+ outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background
528
+ ${checked ? variantClass.checkedTrack : variantClass.uncheckedTrack}
529
+ ${disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
530
+ ${className}
531
+ `,
532
+ children: /* @__PURE__ */ jsx(
533
+ "span",
534
+ {
535
+ className: `
536
+ ${sizeClass.thumb} rounded-full transition-all duration-200 ease-in-out
537
+ ${checked ? variantClass.checkedThumb + " " + sizeClass.thumbTranslate : variantClass.uncheckedThumb + " translate-x-0"}
538
+ shadow-sm
539
+ `
540
+ }
541
+ )
542
+ }
543
+ );
544
+ }
545
+ );
546
+ Switch.displayName = "Switch";
547
+ function AnimatedNumber({ value, suffix = "", decimals = 0 }) {
548
+ const animatedValue = useSpring(0, { stiffness: 50, damping: 15 });
549
+ const displayValue = useTransform(animatedValue, (latest) => {
550
+ const numStr = decimals > 0 ? latest.toFixed(decimals) : Math.round(latest).toString();
551
+ return Number(numStr).toString() + suffix;
552
+ });
553
+ useEffect(() => {
554
+ animatedValue.set(value);
555
+ }, [animatedValue, value]);
556
+ return /* @__PURE__ */ jsx(motion.span, { children: displayValue });
557
+ }
558
+ var TONE_VAR = {
559
+ accent: "var(--color-accent)",
560
+ success: "var(--success)",
561
+ warning: "var(--warning)",
562
+ error: "var(--error)",
563
+ info: "var(--info)",
564
+ neutral: "var(--color-muted-foreground)"
565
+ };
566
+ function Sparkline({
567
+ data,
568
+ width = 100,
569
+ height = 28,
570
+ tone = "accent",
571
+ color,
572
+ strokeWidth = 1.5,
573
+ area = false,
574
+ min,
575
+ max,
576
+ className,
577
+ ...props
578
+ }) {
579
+ const gradientId = useId();
580
+ const stroke = color ?? TONE_VAR[tone];
581
+ if (!Array.isArray(data) || data.length < 2) {
582
+ return /* @__PURE__ */ jsx("svg", { width, height, className, "aria-hidden": true, ...props });
583
+ }
584
+ const lo = min ?? Math.min(...data);
585
+ const hi = max ?? Math.max(...data);
586
+ const span = hi - lo || 1;
587
+ const stepX = width / (data.length - 1);
588
+ const pad = strokeWidth;
589
+ const usableH = height - pad * 2;
590
+ const points = data.map((v, i) => {
591
+ const x = i * stepX;
592
+ const y = pad + usableH - (v - lo) / span * usableH;
593
+ return [x, y];
594
+ });
595
+ const line = points.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x.toFixed(2)} ${y.toFixed(2)}`).join(" ");
596
+ const areaPath = `${line} L${width} ${height} L0 ${height} Z`;
597
+ return /* @__PURE__ */ jsxs(
598
+ "svg",
599
+ {
600
+ viewBox: `0 0 ${width} ${height}`,
601
+ width,
602
+ height,
603
+ preserveAspectRatio: "none",
604
+ className: cn("overflow-visible", className),
605
+ role: "img",
606
+ ...props,
607
+ children: [
608
+ area && /* @__PURE__ */ jsxs(Fragment, { children: [
609
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
610
+ /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: stroke, stopOpacity: 0.28 }),
611
+ /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: stroke, stopOpacity: 0 })
612
+ ] }) }),
613
+ /* @__PURE__ */ jsx("path", { d: areaPath, fill: `url(#${gradientId})`, stroke: "none" })
614
+ ] }),
615
+ /* @__PURE__ */ jsx(
616
+ "path",
617
+ {
618
+ d: line,
619
+ fill: "none",
620
+ stroke,
621
+ strokeWidth,
622
+ strokeLinecap: "round",
623
+ strokeLinejoin: "round",
624
+ vectorEffect: "non-scaling-stroke"
625
+ }
626
+ )
627
+ ]
628
+ }
629
+ );
630
+ }
631
+ var TONE_VAR2 = {
632
+ accent: "var(--color-accent)",
633
+ success: "var(--success)",
634
+ warning: "var(--warning)",
635
+ error: "var(--error)",
636
+ info: "var(--info)",
637
+ neutral: "var(--color-muted-foreground)"
638
+ };
639
+ function Gauge({
640
+ value,
641
+ size = 72,
642
+ thickness = 6,
643
+ tone = "accent",
644
+ color,
645
+ label,
646
+ counterClockwise = false,
647
+ className
648
+ }) {
649
+ const pct = Math.max(0, Math.min(100, Number.isFinite(value) ? value : 0));
650
+ const stroke = color ?? TONE_VAR2[tone];
651
+ const r = (size - thickness) / 2;
652
+ const c = 2 * Math.PI * r;
653
+ const dash = pct / 100 * c;
654
+ return /* @__PURE__ */ jsxs(
655
+ "div",
656
+ {
657
+ className: cn("relative inline-flex items-center justify-center", className),
658
+ style: { width: size, height: size },
659
+ role: "progressbar",
660
+ "aria-valuenow": Math.round(pct),
661
+ "aria-valuemin": 0,
662
+ "aria-valuemax": 100,
663
+ children: [
664
+ /* @__PURE__ */ jsxs("svg", { width: size, height: size, className: "-rotate-90", children: [
665
+ /* @__PURE__ */ jsx(
666
+ "circle",
667
+ {
668
+ cx: size / 2,
669
+ cy: size / 2,
670
+ r,
671
+ fill: "none",
672
+ stroke: "var(--color-border)",
673
+ strokeWidth: thickness
674
+ }
675
+ ),
676
+ /* @__PURE__ */ jsx(
677
+ "circle",
678
+ {
679
+ cx: size / 2,
680
+ cy: size / 2,
681
+ r,
682
+ fill: "none",
683
+ stroke,
684
+ strokeWidth: thickness,
685
+ strokeLinecap: "round",
686
+ strokeDasharray: `${dash} ${c}`,
687
+ className: "transition-[stroke-dasharray] duration-500 ease-out",
688
+ transform: counterClockwise ? `scale(1,-1) translate(0,${-size})` : void 0
689
+ }
690
+ )
691
+ ] }),
692
+ label !== null && /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center text-sm font-semibold tabular-nums", children: label ?? `${Math.round(pct)}%` })
693
+ ]
694
+ }
695
+ );
696
+ }
697
+ var TONE_VAR3 = {
698
+ accent: "var(--color-accent)",
699
+ success: "var(--success)",
700
+ warning: "var(--warning)",
701
+ error: "var(--error)",
702
+ info: "var(--info)",
703
+ neutral: "var(--color-muted-foreground)"
704
+ };
705
+ var segColor = (s) => s.color ?? TONE_VAR3[s.tone ?? "accent"];
706
+ function SegmentedBar({
707
+ segments,
708
+ total,
709
+ height = 8,
710
+ legend = false,
711
+ formatValue,
712
+ className
713
+ }) {
714
+ const sum = segments.reduce((a, s) => a + Math.max(0, s.value), 0);
715
+ const axis = total ?? (sum || 1);
716
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
717
+ /* @__PURE__ */ jsx(
718
+ "div",
719
+ {
720
+ className: "flex w-full overflow-hidden rounded-full bg-muted",
721
+ style: { height },
722
+ role: "img",
723
+ children: segments.map((s, i) => {
724
+ const w = Math.max(0, s.value) / axis * 100;
725
+ if (w <= 0) return null;
726
+ return /* @__PURE__ */ jsx(
727
+ "div",
728
+ {
729
+ className: "h-full transition-[width] duration-300 first:rounded-l-full last:rounded-r-full",
730
+ style: { width: `${w}%`, backgroundColor: segColor(s) },
731
+ title: typeof s.label === "string" ? s.label : void 0
732
+ },
733
+ i
734
+ );
735
+ })
736
+ }
737
+ ),
738
+ legend && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: segments.map((s, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
739
+ /* @__PURE__ */ jsx(
740
+ "span",
741
+ {
742
+ className: "h-2 w-2 shrink-0 rounded-full",
743
+ style: { backgroundColor: segColor(s) }
744
+ }
745
+ ),
746
+ s.label != null && /* @__PURE__ */ jsx("span", { children: s.label }),
747
+ /* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums text-foreground/80", children: formatValue ? formatValue(s.value) : s.value })
748
+ ] }, i)) })
749
+ ] });
750
+ }
751
+ function FileDropzone({
752
+ onFiles,
753
+ accept,
754
+ multiple = false,
755
+ disabled = false,
756
+ icon,
757
+ label = "Drop a file here, or click to browse",
758
+ hint,
759
+ children,
760
+ className
761
+ }) {
762
+ const inputRef = useRef(null);
763
+ const [dragging, setDragging] = useState(false);
764
+ const emit = (list) => {
765
+ if (!list || list.length === 0) return;
766
+ onFiles(Array.from(list));
767
+ };
768
+ const onDrop = (e) => {
769
+ e.preventDefault();
770
+ setDragging(false);
771
+ if (disabled) return;
772
+ emit(e.dataTransfer.files);
773
+ };
774
+ const onDragOver = (e) => {
775
+ e.preventDefault();
776
+ if (!disabled) setDragging(true);
777
+ };
778
+ return /* @__PURE__ */ jsxs(
779
+ "div",
780
+ {
781
+ onClick: () => !disabled && inputRef.current?.click(),
782
+ onDrop,
783
+ onDragOver,
784
+ onDragLeave: () => setDragging(false),
785
+ role: "button",
786
+ tabIndex: disabled ? -1 : 0,
787
+ "aria-disabled": disabled,
788
+ onKeyDown: (e) => {
789
+ if (disabled) return;
790
+ if (e.key === "Enter" || e.key === " ") {
791
+ e.preventDefault();
792
+ inputRef.current?.click();
793
+ }
794
+ },
795
+ className: cn(
796
+ "flex flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed px-6 py-8 text-center transition-colors",
797
+ disabled ? "cursor-not-allowed opacity-50 border-border" : "cursor-pointer border-border hover:border-accent hover:bg-muted/40",
798
+ dragging && !disabled && "border-accent bg-accent/10",
799
+ className
800
+ ),
801
+ children: [
802
+ /* @__PURE__ */ jsx(
803
+ "input",
804
+ {
805
+ ref: inputRef,
806
+ type: "file",
807
+ accept,
808
+ multiple,
809
+ disabled,
810
+ className: "hidden",
811
+ onChange: (e) => {
812
+ emit(e.target.files);
813
+ e.target.value = "";
814
+ }
815
+ }
816
+ ),
817
+ children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
818
+ icon && /* @__PURE__ */ jsx("div", { className: "text-muted-foreground", children: icon }),
819
+ /* @__PURE__ */ jsx("div", { className: "text-sm font-medium", children: label }),
820
+ hint && /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground", children: hint })
821
+ ] })
822
+ ]
823
+ }
824
+ );
825
+ }
826
+ var TONE_VAR4 = {
827
+ accent: "var(--color-accent)",
828
+ success: "var(--success)",
829
+ warning: "var(--warning)",
830
+ error: "var(--error)",
831
+ info: "var(--info)",
832
+ neutral: "var(--color-muted-foreground)"
833
+ };
834
+ var VIEW_H = 140;
835
+ function normalize(data) {
836
+ return data.map((d) => typeof d === "number" ? { value: d } : d);
837
+ }
838
+ function AreaChart({
839
+ data,
840
+ tone = "accent",
841
+ color,
842
+ height = VIEW_H,
843
+ formatValue,
844
+ showGrid = true,
845
+ showTooltip = true,
846
+ showXAxis = false,
847
+ strokeWidth = 2,
848
+ ariaLabel = "Area chart",
849
+ noDataLabel = "No data",
850
+ className
851
+ }) {
852
+ const gradientId = useId();
853
+ const stroke = color ?? TONE_VAR4[tone];
854
+ const containerRef = useRef(null);
855
+ const [width, setWidth] = useState(0);
856
+ const [hovered, setHovered] = useState(null);
857
+ const points = useMemo(() => normalize(data), [data]);
858
+ useEffect(() => {
859
+ if (!containerRef.current) return;
860
+ const observer = new ResizeObserver((entries) => {
861
+ if (entries[0]) setWidth(entries[0].contentRect.width);
862
+ });
863
+ observer.observe(containerRef.current);
864
+ return () => observer.disconnect();
865
+ }, []);
866
+ const values = points.map((p) => Number.isFinite(p.value) ? p.value : 0);
867
+ const maxVal = Math.max(...values, 1);
868
+ const minVal = Math.min(...values, 0);
869
+ const span = maxVal - minVal || 1;
870
+ const chartWidth = width || 600;
871
+ const getPoint = (i) => {
872
+ const x = i / Math.max(points.length - 1, 1) * chartWidth;
873
+ const normalized = (values[i] - minVal) / span;
874
+ const y = VIEW_H - normalized * VIEW_H * 0.85 - VIEW_H * 0.05;
875
+ return { x, y };
876
+ };
877
+ const linePath = useMemo(() => {
878
+ if (points.length === 0) return "";
879
+ const start = getPoint(0);
880
+ let path = `M ${start.x},${start.y}`;
881
+ for (let i = 0; i < points.length - 1; i++) {
882
+ const curr = getPoint(i);
883
+ const next = getPoint(i + 1);
884
+ const cpx = (curr.x + next.x) / 2;
885
+ path += ` C ${cpx},${curr.y} ${cpx},${next.y} ${next.x},${next.y}`;
886
+ }
887
+ return path;
888
+ }, [points, values, maxVal, minVal, chartWidth]);
889
+ const areaPath = linePath ? `${linePath} L ${chartWidth},${VIEW_H} L 0,${VIEW_H} Z` : "";
890
+ const hoveredCoords = hovered !== null ? getPoint(hovered) : null;
891
+ const fmt = formatValue ?? ((v) => String(v));
892
+ const xLabels = points.filter((p) => p.label != null);
893
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
894
+ /* @__PURE__ */ jsxs("div", { ref: containerRef, className: "relative w-full", style: { height }, children: [
895
+ points.length < 2 ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center text-sm text-muted-foreground", children: noDataLabel }) : /* @__PURE__ */ jsxs(
896
+ "svg",
897
+ {
898
+ viewBox: `0 0 ${chartWidth} ${VIEW_H}`,
899
+ preserveAspectRatio: "none",
900
+ className: "h-full w-full overflow-visible",
901
+ role: "img",
902
+ "aria-label": ariaLabel,
903
+ onMouseMove: (e) => {
904
+ if (!showTooltip) return;
905
+ const rect = e.currentTarget.getBoundingClientRect();
906
+ const mouseX = e.clientX - rect.left;
907
+ const idx = Math.min(
908
+ Math.max(0, Math.round(mouseX / rect.width * (points.length - 1))),
909
+ points.length - 1
910
+ );
911
+ setHovered(idx);
912
+ },
913
+ onMouseLeave: () => setHovered(null),
914
+ children: [
915
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
916
+ /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: stroke, stopOpacity: 0.32 }),
917
+ /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: stroke, stopOpacity: 0 })
918
+ ] }) }),
919
+ showGrid && [0, 0.25, 0.5, 0.75, 1].map((tick) => /* @__PURE__ */ jsx(
920
+ "line",
921
+ {
922
+ x1: 0,
923
+ y1: VIEW_H * tick,
924
+ x2: chartWidth,
925
+ y2: VIEW_H * tick,
926
+ stroke: "currentColor",
927
+ strokeOpacity: 0.1,
928
+ strokeDasharray: "4 4",
929
+ className: "text-muted-foreground"
930
+ },
931
+ tick
932
+ )),
933
+ /* @__PURE__ */ jsx("path", { d: areaPath, fill: `url(#${gradientId})` }),
934
+ /* @__PURE__ */ jsx(
935
+ "path",
936
+ {
937
+ d: linePath,
938
+ fill: "none",
939
+ stroke,
940
+ strokeWidth,
941
+ strokeLinecap: "round",
942
+ strokeLinejoin: "round",
943
+ vectorEffect: "non-scaling-stroke"
944
+ }
945
+ ),
946
+ hoveredCoords && /* @__PURE__ */ jsxs(Fragment, { children: [
947
+ /* @__PURE__ */ jsx(
948
+ "line",
949
+ {
950
+ x1: hoveredCoords.x,
951
+ y1: 0,
952
+ x2: hoveredCoords.x,
953
+ y2: VIEW_H,
954
+ stroke,
955
+ strokeOpacity: 0.4,
956
+ strokeDasharray: "4 4"
957
+ }
958
+ ),
959
+ /* @__PURE__ */ jsx(
960
+ "circle",
961
+ {
962
+ cx: hoveredCoords.x,
963
+ cy: hoveredCoords.y,
964
+ r: 4,
965
+ fill: stroke,
966
+ stroke: "var(--color-background)",
967
+ strokeWidth: 2,
968
+ vectorEffect: "non-scaling-stroke"
969
+ }
970
+ )
971
+ ] })
972
+ ]
973
+ }
974
+ ),
975
+ showTooltip && hovered !== null && points[hovered] && chartWidth > 0 && /* @__PURE__ */ jsxs(
976
+ "div",
977
+ {
978
+ className: "pointer-events-none absolute z-10 -translate-x-1/2 -translate-y-full rounded-lg border border-border bg-popover/95 p-2 text-xs shadow-lg backdrop-blur-sm",
979
+ style: {
980
+ left: `${Math.min(Math.max(getPoint(hovered).x / chartWidth * 100, 8), 92)}%`,
981
+ top: Math.max(getPoint(hovered).y / VIEW_H * height - 8, 0)
982
+ },
983
+ children: [
984
+ points[hovered].label != null && /* @__PURE__ */ jsx("div", { className: "mb-0.5 font-medium", children: points[hovered].label }),
985
+ /* @__PURE__ */ jsx("div", { className: "tabular-nums text-muted-foreground", children: fmt(values[hovered]) })
986
+ ]
987
+ }
988
+ )
989
+ ] }),
990
+ showXAxis && xLabels.length > 1 && /* @__PURE__ */ jsx("div", { className: "mt-1.5 flex justify-between px-1 text-xs text-muted-foreground", children: points.filter((p, i) => p.label != null && i % Math.ceil(points.length / 6) === 0).map((p, i) => /* @__PURE__ */ jsx("span", { className: "truncate", children: p.label }, i)) })
991
+ ] });
992
+ }
993
+ function Toaster() {
994
+ return /* @__PURE__ */ jsx(
995
+ Toaster$1,
996
+ {
997
+ position: "bottom-right",
998
+ toastOptions: {
999
+ classNames: {
1000
+ toast: "bg-card border border-border rounded-xl shadow-lg p-4",
1001
+ title: "text-sm font-medium",
1002
+ description: "text-xs text-muted-foreground",
1003
+ actionButton: "bg-foreground text-background text-xs px-3 py-1.5 rounded-lg",
1004
+ cancelButton: "text-muted-foreground text-xs px-3 py-1.5 rounded-lg hover:bg-muted"
1005
+ }
1006
+ }
1007
+ }
1008
+ );
1009
+ }
1010
+ var toast = {
1011
+ success: (message, description) => {
1012
+ toast$1.success(message, {
1013
+ description,
1014
+ icon: /* @__PURE__ */ jsx(CheckCircle2, { className: "w-5 h-5 text-success" })
1015
+ });
1016
+ },
1017
+ error: (message, description) => {
1018
+ toast$1.error(message, {
1019
+ description,
1020
+ icon: /* @__PURE__ */ jsx(AlertCircle, { className: "w-5 h-5 text-error" })
1021
+ });
1022
+ },
1023
+ info: (message, description) => {
1024
+ toast$1.info(message, {
1025
+ description,
1026
+ icon: /* @__PURE__ */ jsx(Info, { className: "w-5 h-5 text-info" })
1027
+ });
1028
+ },
1029
+ warning: (message, description) => {
1030
+ toast$1.warning(message, {
1031
+ description,
1032
+ icon: /* @__PURE__ */ jsx(AlertTriangle, { className: "w-5 h-5 text-warning" })
1033
+ });
1034
+ },
1035
+ loading: (message) => {
1036
+ return toast$1.loading(message, {
1037
+ icon: /* @__PURE__ */ jsx(Loader2, { className: "w-5 h-5 animate-spin" })
1038
+ });
1039
+ },
1040
+ dismiss: (id) => {
1041
+ toast$1.dismiss(id);
1042
+ },
1043
+ promise: (promise, messages) => {
1044
+ return toast$1.promise(promise, {
1045
+ loading: messages.loading,
1046
+ success: messages.success,
1047
+ error: messages.error
1048
+ });
1049
+ }
1050
+ };
1051
+ var YUNUI_PALETTES = [
1052
+ "gray",
1053
+ "sand",
1054
+ "slate",
1055
+ "mint",
1056
+ "rose",
1057
+ "dusk",
1058
+ "red",
1059
+ "orange",
1060
+ "amber",
1061
+ "yellow",
1062
+ "lime",
1063
+ "moss",
1064
+ "green",
1065
+ "emerald",
1066
+ "teal",
1067
+ "aqua",
1068
+ "cyan",
1069
+ "blue",
1070
+ "indigo",
1071
+ "violet",
1072
+ "plum",
1073
+ "magenta",
1074
+ "fuchsia",
1075
+ "pink"
1076
+ ];
1077
+ var YUNUI_THEME_PRESETS = {
1078
+ aurora: { label: "Aurora", brand: "blue", accent: "violet", neutral: "slate" },
1079
+ sunset: { label: "Sunset", brand: "orange", accent: "pink", neutral: "sand" },
1080
+ forest: { label: "Forest", brand: "green", accent: "lime", neutral: "gray" },
1081
+ ocean: { label: "Ocean", brand: "cyan", accent: "teal", neutral: "slate" },
1082
+ grape: { label: "Grape", brand: "violet", accent: "magenta", neutral: "dusk" },
1083
+ ember: { label: "Ember", brand: "red", accent: "amber", neutral: "sand" },
1084
+ lagoon: { label: "Lagoon", brand: "teal", accent: "emerald", neutral: "mint" },
1085
+ blossom: { label: "Blossom", brand: "pink", accent: "fuchsia", neutral: "rose" },
1086
+ royal: { label: "Royal", brand: "indigo", accent: "blue", neutral: "slate" },
1087
+ citrus: { label: "Citrus", brand: "lime", accent: "yellow", neutral: "sand" },
1088
+ orchid: { label: "Orchid", brand: "plum", accent: "violet", neutral: "dusk" },
1089
+ mono: { label: "Mono", brand: "gray", accent: "gray", neutral: "gray" }
1090
+ };
1091
+ var ATTR = {
1092
+ brand: "data-brand",
1093
+ accent: "data-accent",
1094
+ neutral: "data-neutral",
1095
+ solid: "data-solid",
1096
+ surface: "data-surface",
1097
+ theme: "data-theme",
1098
+ accentSource: "data-accent-source"
1099
+ };
1100
+ function resolveTarget(el) {
1101
+ if (el) return el;
1102
+ return typeof document !== "undefined" ? document.documentElement : null;
1103
+ }
1104
+ function applyTheme(theme, el) {
1105
+ const target = resolveTarget(el);
1106
+ if (!target) return;
1107
+ for (const key of Object.keys(theme)) {
1108
+ const value = theme[key];
1109
+ const attr = ATTR[key];
1110
+ if (!attr) continue;
1111
+ if (value == null) target.removeAttribute(attr);
1112
+ else target.setAttribute(attr, value);
1113
+ }
1114
+ }
1115
+ function readTheme(el) {
1116
+ const target = resolveTarget(el);
1117
+ const out = {};
1118
+ if (!target) return out;
1119
+ for (const key of Object.keys(ATTR)) {
1120
+ const v = target.getAttribute(ATTR[key]);
1121
+ if (v != null) out[key] = v;
1122
+ }
1123
+ return out;
1124
+ }
1125
+ var STORAGE_KEY = "yunui-theme";
1126
+ function useYunUITheme(defaults = {}) {
1127
+ const [theme, setTheme] = React3.useState(defaults);
1128
+ React3.useEffect(() => {
1129
+ let stored = {};
1130
+ try {
1131
+ stored = JSON.parse(localStorage.getItem(STORAGE_KEY) || "{}");
1132
+ } catch {
1133
+ }
1134
+ const merged = { ...defaults, ...stored };
1135
+ setTheme(merged);
1136
+ applyTheme(merged);
1137
+ }, []);
1138
+ const update = React3.useCallback((patch) => {
1139
+ setTheme((prev) => {
1140
+ const next = { ...prev, ...patch };
1141
+ applyTheme(next);
1142
+ try {
1143
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
1144
+ } catch {
1145
+ }
1146
+ return next;
1147
+ });
1148
+ }, []);
1149
+ return [theme, update];
1150
+ }
1151
+
1152
+ export { AnimatedNumber, AreaChart, BentoCard, BentoGrid, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, CustomSelect, FileDropzone, Gauge, Marquee, NavTabs, Popover, PopoverAnchor, PopoverClose2 as PopoverClose, PopoverContent, PopoverTrigger, ScrollArea, ScrollBar, SegmentedBar, SegmentedSelect, ShinyButton, Sparkline, Switch, Toaster, YUNUI_PALETTES, YUNUI_THEME_PRESETS, applyTheme, readTheme, toast, useYunUITheme };
1153
+ //# sourceMappingURL=chunk-5E3O6ANF.js.map
1154
+ //# sourceMappingURL=chunk-5E3O6ANF.js.map