uitheme-web 1.0.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.
@@ -0,0 +1,1732 @@
1
+ import React, { createContext, useState, useEffect, useRef, useCallback, useContext, useSyncExternalStore } from 'react';
2
+ import { flushSync } from 'react-dom';
3
+ import { jsx, jsxs } from 'react/jsx-runtime';
4
+ import * as SelectPrimitive from '@radix-ui/react-select';
5
+
6
+ // src/core/types.ts
7
+ var ThemeAnimationType = /* @__PURE__ */ ((ThemeAnimationType2) => {
8
+ ThemeAnimationType2["CIRCLE"] = "circle";
9
+ ThemeAnimationType2["BLUR_CIRCLE"] = "blur-circle";
10
+ ThemeAnimationType2["SLIDE"] = "slide";
11
+ return ThemeAnimationType2;
12
+ })(ThemeAnimationType || {});
13
+
14
+ // src/core/constants.ts
15
+ var STORAGE_KEY = "theme";
16
+ var COLOR_STORAGE_KEY = "color-theme";
17
+ var GLOBAL_CLASS_NAME = "dark";
18
+ var COLOR_THEME_PREFIX = "theme-";
19
+ var DEFAULT_DURATION = 750;
20
+ var DEFAULT_EASING = "ease-in-out";
21
+ var DEFAULT_BLUR_AMOUNT = 2;
22
+ var DEFAULT_STYLE_ID = "ui-theme-style";
23
+
24
+ // src/core/animations.ts
25
+ var isBrowser = typeof window !== "undefined";
26
+ var getIsHighResolution = () => {
27
+ if (!isBrowser) return false;
28
+ return window.innerWidth >= 3e3 || window.innerHeight >= 2e3;
29
+ };
30
+ var injectBaseStyles = () => {
31
+ if (!isBrowser) return;
32
+ const styleId = "ui-theme-base-style";
33
+ if (document.getElementById(styleId)) return;
34
+ const style = document.createElement("style");
35
+ style.id = styleId;
36
+ const isHighResolution = getIsHighResolution();
37
+ style.textContent = `
38
+ ::view-transition-old(root),
39
+ ::view-transition-new(root) {
40
+ animation: none;
41
+ mix-blend-mode: normal;
42
+ ${isHighResolution ? "transform: translateZ(0);" : ""}
43
+ }
44
+
45
+ ${isHighResolution ? `
46
+ ::view-transition-group(root),
47
+ ::view-transition-image-pair(root),
48
+ ::view-transition-old(root),
49
+ ::view-transition-new(root) {
50
+ backface-visibility: hidden;
51
+ perspective: 1000px;
52
+ transform: translate3d(0, 0, 0);
53
+ }
54
+ ` : ""}
55
+ `;
56
+ document.head.appendChild(style);
57
+ };
58
+ var createBlurCircleMask = (blur) => {
59
+ const isHighResolution = getIsHighResolution();
60
+ const blurFilter = `<filter id="blur"><feGaussianBlur stdDeviation="${blur}" /></filter>`;
61
+ const circleRadius = isHighResolution ? 20 : 25;
62
+ return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 -50 100 100"><defs>${blurFilter}</defs><circle cx="0" cy="0" r="${circleRadius}" fill="white" filter="url(%23blur)"/></svg>')`;
63
+ };
64
+ var getSystemTheme = () => {
65
+ if (!isBrowser) return "light";
66
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
67
+ };
68
+ var resolveTheme = (theme) => {
69
+ if (theme === "system") {
70
+ return getSystemTheme();
71
+ }
72
+ return theme === "dark" ? "dark" : "light";
73
+ };
74
+ var resolveThemeForServer = (theme) => {
75
+ if (theme === "system") {
76
+ return "system";
77
+ }
78
+ return theme === "dark" ? "dark" : "light";
79
+ };
80
+ var supportsViewTransitions = () => {
81
+ return isBrowser && "startViewTransition" in document;
82
+ };
83
+ var prefersReducedMotion = () => {
84
+ return isBrowser && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
85
+ };
86
+ var getSlideFromCoords = (direction) => {
87
+ switch (direction) {
88
+ case "left":
89
+ return { a: -100, b: 0 };
90
+ case "right":
91
+ return { a: 100, b: 0 };
92
+ case "top":
93
+ return { a: 0, b: -100 };
94
+ case "bottom":
95
+ return { a: 0, b: 100 };
96
+ case "top-left":
97
+ return { a: -100, b: -100 };
98
+ case "top-right":
99
+ return { a: 100, b: -100 };
100
+ case "bottom-left":
101
+ return { a: -100, b: 100 };
102
+ case "bottom-right":
103
+ return { a: 100, b: 100 };
104
+ default:
105
+ return { a: -100, b: 0 };
106
+ }
107
+ };
108
+ var createCircleAnimation = (config) => {
109
+ const { x, y, duration, easing } = config;
110
+ const topLeft = Math.hypot(x, y);
111
+ const topRight = Math.hypot(window.innerWidth - x, y);
112
+ const bottomLeft = Math.hypot(x, window.innerHeight - y);
113
+ const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
114
+ const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
115
+ document.documentElement.animate(
116
+ {
117
+ clipPath: [
118
+ `circle(0px at ${x}px ${y}px)`,
119
+ `circle(${maxRadius}px at ${x}px ${y}px)`
120
+ ]
121
+ },
122
+ {
123
+ duration,
124
+ easing,
125
+ pseudoElement: "::view-transition-new(root)"
126
+ }
127
+ );
128
+ };
129
+ var createSlideAnimation = (config) => {
130
+ const {
131
+ a = -100,
132
+ b = 0,
133
+ x = 0,
134
+ y = 0,
135
+ duration,
136
+ styleId = DEFAULT_STYLE_ID
137
+ } = config;
138
+ const styleElement = document.createElement("style");
139
+ styleElement.id = styleId;
140
+ styleElement.textContent = `
141
+ ::view-transition-old(root) {
142
+ animation-delay: ${duration}ms;
143
+ }
144
+
145
+ ::view-transition-new(root) {
146
+ animation: move-in ${duration}ms;
147
+ animation-timing-function: cubic-bezier(0.66, 0, 0.34, 1);
148
+ }
149
+
150
+ @keyframes move-in {
151
+ from {
152
+ translate: ${a}% ${b}%;
153
+ }
154
+ to {
155
+ translate: ${x}% ${y}%;
156
+ }
157
+ }
158
+ `;
159
+ document.head.appendChild(styleElement);
160
+ setTimeout(() => {
161
+ const el = document.getElementById(styleId);
162
+ if (el) {
163
+ el.remove();
164
+ }
165
+ }, duration);
166
+ };
167
+ var createBlurCircleAnimation = (config) => {
168
+ const {
169
+ x,
170
+ y,
171
+ duration,
172
+ easing,
173
+ blurAmount,
174
+ styleId = DEFAULT_STYLE_ID
175
+ } = config;
176
+ const existingStyle = document.getElementById(styleId);
177
+ if (existingStyle) {
178
+ existingStyle.remove();
179
+ }
180
+ const isHighResolution = getIsHighResolution();
181
+ const viewportSize = Math.max(window.innerWidth, window.innerHeight) + 200;
182
+ const scaleFactor = isHighResolution ? 2.5 : 4;
183
+ const optimalMaskSize = isHighResolution ? Math.min(viewportSize * scaleFactor, 5e3) : viewportSize * scaleFactor;
184
+ const topLeft = Math.hypot(x, y);
185
+ const topRight = Math.hypot(window.innerWidth - x, y);
186
+ const bottomLeft = Math.hypot(x, window.innerHeight - y);
187
+ const bottomRight = Math.hypot(window.innerWidth - x, window.innerHeight - y);
188
+ const maxRadius = Math.max(topLeft, topRight, bottomLeft, bottomRight);
189
+ const styleElement = document.createElement("style");
190
+ styleElement.id = styleId;
191
+ const blurFactor = isHighResolution ? 1.5 : 1.2;
192
+ const finalMaskSize = Math.max(optimalMaskSize, maxRadius * 2.5);
193
+ styleElement.textContent = `
194
+ ::view-transition-group(root) {
195
+ animation-duration: ${duration}ms;
196
+ animation-timing-function: ${isHighResolution ? "cubic-bezier(0.2, 0, 0.2, 1)" : "linear(0 0%, 0.2342 12.49%, 0.4374 24.99%,0.6093 37.49%, 0.6835 43.74%,0.7499 49.99%, 0.8086 56.25%,0.8593 62.5%, 0.9023 68.75%, 0.9375 75%,0.9648 81.25%, 0.9844 87.5%,0.9961 93.75%, 1 100%)"};
197
+ will-change: transform;
198
+ }
199
+
200
+ ::view-transition-new(root) {
201
+ mask: ${createBlurCircleMask(blurAmount * blurFactor)} 0 0 / 100% 100% no-repeat;
202
+ mask-position: ${x}px ${y}px;
203
+ animation: ui-theme-mask-scale ${duration}ms ${easing};
204
+ transform-origin: ${x}px ${y}px;
205
+ will-change: mask-size, mask-position;
206
+ }
207
+
208
+ ::view-transition-old(root),
209
+ .dark::view-transition-old(root) {
210
+ animation: ui-theme-mask-scale ${duration}ms ${easing};
211
+ transform-origin: ${x}px ${y}px;
212
+ z-index: -1;
213
+ will-change: mask-size, mask-position;
214
+ }
215
+
216
+ @keyframes ui-theme-mask-scale {
217
+ 0% {
218
+ mask-size: 0px;
219
+ mask-position: ${x}px ${y}px;
220
+ }
221
+ 100% {
222
+ mask-size: ${finalMaskSize}px;
223
+ mask-position: ${x - finalMaskSize / 2}px ${y - finalMaskSize / 2}px;
224
+ }
225
+ }
226
+ `;
227
+ document.head.appendChild(styleElement);
228
+ setTimeout(() => {
229
+ const el = document.getElementById(styleId);
230
+ if (el) {
231
+ el.remove();
232
+ }
233
+ }, duration);
234
+ };
235
+
236
+ // src/core/storage.ts
237
+ var isBrowser2 = typeof window !== "undefined";
238
+ var getStoredTheme = (key = STORAGE_KEY, validThemes = ["light", "dark", "system"], defaultTheme = "system") => {
239
+ if (!isBrowser2) return defaultTheme;
240
+ const saved = localStorage.getItem(key);
241
+ return saved && validThemes.includes(saved) ? saved : defaultTheme;
242
+ };
243
+ var setStoredTheme = (theme, key = STORAGE_KEY) => {
244
+ if (!isBrowser2) return;
245
+ localStorage.setItem(key, theme);
246
+ };
247
+ var getStoredColorTheme = (key = COLOR_STORAGE_KEY, validColorThemes = ["default"], defaultColorTheme = "default") => {
248
+ if (!isBrowser2) return defaultColorTheme;
249
+ const saved = localStorage.getItem(key);
250
+ return saved && validColorThemes.includes(saved) ? saved : defaultColorTheme;
251
+ };
252
+ var setStoredColorTheme = (colorTheme, key = COLOR_STORAGE_KEY) => {
253
+ if (!isBrowser2) return;
254
+ localStorage.setItem(key, colorTheme);
255
+ };
256
+
257
+ // src/react/hooks/use-theme.ts
258
+ var isBrowser3 = typeof window !== "undefined";
259
+ var useTheme = (props = {}) => {
260
+ const {
261
+ duration: propsDuration = DEFAULT_DURATION,
262
+ easing = DEFAULT_EASING,
263
+ animationType = "circle" /* CIRCLE */,
264
+ blurAmount = DEFAULT_BLUR_AMOUNT,
265
+ styleId = DEFAULT_STYLE_ID,
266
+ themes = ["light", "dark", "system"],
267
+ colorThemes = ["default"],
268
+ defaultTheme = "system",
269
+ defaultColorTheme = "default",
270
+ globalClassName = GLOBAL_CLASS_NAME,
271
+ colorThemePrefix = COLOR_THEME_PREFIX,
272
+ storageKey = STORAGE_KEY,
273
+ colorStorageKey = COLOR_STORAGE_KEY,
274
+ theme: externalTheme,
275
+ colorTheme: externalColorTheme,
276
+ onThemeChange,
277
+ onColorThemeChange,
278
+ slideDirection = "left",
279
+ slideFromX,
280
+ slideFromY,
281
+ slideToX = 0,
282
+ slideToY = 0,
283
+ initialTheme,
284
+ initialColorTheme,
285
+ systemThemeMode = "js"
286
+ } = props;
287
+ const isHighResolution = isBrowser3 && (window.innerWidth >= 3e3 || window.innerHeight >= 2e3);
288
+ const duration = isHighResolution ? Math.max(propsDuration * 0.8, 500) : propsDuration;
289
+ const [mounted, setMounted] = useState(false);
290
+ useEffect(() => {
291
+ injectBaseStyles();
292
+ setMounted(true);
293
+ }, []);
294
+ const [internalTheme, setInternalTheme] = useState(() => {
295
+ if (initialTheme !== void 0) return initialTheme;
296
+ return getStoredTheme(storageKey, themes, defaultTheme);
297
+ });
298
+ const [internalColorTheme, setInternalColorTheme] = useState(() => {
299
+ if (initialColorTheme !== void 0) return initialColorTheme;
300
+ return getStoredColorTheme(colorStorageKey, colorThemes, defaultColorTheme);
301
+ });
302
+ const currentTheme = externalTheme ?? internalTheme;
303
+ const currentColorTheme = externalColorTheme ?? internalColorTheme;
304
+ const [, setSystemTheme] = useState(() => getSystemTheme());
305
+ const resolvedTheme = resolveTheme(currentTheme);
306
+ useEffect(() => {
307
+ if (!isBrowser3) return;
308
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
309
+ const handleChange = () => setSystemTheme(getSystemTheme());
310
+ mediaQuery.addEventListener("change", handleChange);
311
+ return () => mediaQuery.removeEventListener("change", handleChange);
312
+ }, []);
313
+ useEffect(() => {
314
+ if (!isBrowser3 || !mounted) return;
315
+ const el = document.documentElement;
316
+ if (systemThemeMode === "css" && currentTheme === "system") {
317
+ el.classList.remove(globalClassName);
318
+ el.classList.remove("auto");
319
+ el.classList.remove("system");
320
+ el.classList.add("system");
321
+ el.style.colorScheme = "";
322
+ } else {
323
+ el.classList.remove("system");
324
+ el.classList.remove("auto");
325
+ if (resolvedTheme === "dark") {
326
+ el.classList.add(globalClassName);
327
+ } else {
328
+ el.classList.remove(globalClassName);
329
+ }
330
+ el.style.colorScheme = resolvedTheme;
331
+ }
332
+ colorThemes.forEach((theme) => {
333
+ el.classList.remove(`${colorThemePrefix}${theme}`);
334
+ });
335
+ el.classList.add(`${colorThemePrefix}${currentColorTheme}`);
336
+ }, [
337
+ resolvedTheme,
338
+ currentTheme,
339
+ currentColorTheme,
340
+ globalClassName,
341
+ colorThemePrefix,
342
+ colorThemes,
343
+ mounted,
344
+ systemThemeMode
345
+ ]);
346
+ const ref = useRef(null);
347
+ const setTheme = useCallback(
348
+ (newTheme) => {
349
+ setStoredTheme(newTheme, storageKey);
350
+ if (externalTheme === void 0) {
351
+ setInternalTheme(newTheme);
352
+ }
353
+ if (onThemeChange) {
354
+ onThemeChange(newTheme);
355
+ }
356
+ },
357
+ [onThemeChange, externalTheme, storageKey]
358
+ );
359
+ const setColorTheme = useCallback(
360
+ (newColorTheme) => {
361
+ setStoredColorTheme(newColorTheme, colorStorageKey);
362
+ if (externalColorTheme === void 0) {
363
+ setInternalColorTheme(newColorTheme);
364
+ }
365
+ if (onColorThemeChange) {
366
+ onColorThemeChange(newColorTheme);
367
+ }
368
+ },
369
+ [onColorThemeChange, externalColorTheme, colorStorageKey]
370
+ );
371
+ const switchTheme = useCallback(
372
+ async (newTheme, animationOff = false) => {
373
+ if (!ref.current || !supportsViewTransitions() || prefersReducedMotion() || animationOff) {
374
+ setTheme(newTheme);
375
+ return;
376
+ }
377
+ let animationConfig;
378
+ if (animationType === "slide" /* SLIDE */) {
379
+ const fromCoords = slideFromX !== void 0 && slideFromY !== void 0 ? { a: slideFromX, b: slideFromY } : getSlideFromCoords(slideDirection);
380
+ animationConfig = {
381
+ a: fromCoords.a,
382
+ b: fromCoords.b,
383
+ x: slideToX,
384
+ y: slideToY,
385
+ duration,
386
+ easing,
387
+ animationType,
388
+ blurAmount,
389
+ styleId
390
+ };
391
+ } else {
392
+ const { top, left, width, height } = ref.current.getBoundingClientRect();
393
+ const x = left + width / 2;
394
+ const y = top + height / 2;
395
+ animationConfig = {
396
+ x,
397
+ y,
398
+ duration,
399
+ easing,
400
+ animationType,
401
+ blurAmount,
402
+ styleId
403
+ };
404
+ }
405
+ if (animationType === "blur-circle" /* BLUR_CIRCLE */) {
406
+ createBlurCircleAnimation(animationConfig);
407
+ }
408
+ if (animationType === "slide" /* SLIDE */) {
409
+ createSlideAnimation(animationConfig);
410
+ }
411
+ await document.startViewTransition(() => {
412
+ flushSync(() => {
413
+ setTheme(newTheme);
414
+ });
415
+ }).ready;
416
+ if (animationType === "circle" /* CIRCLE */) {
417
+ createCircleAnimation(animationConfig);
418
+ }
419
+ },
420
+ [
421
+ setTheme,
422
+ duration,
423
+ easing,
424
+ animationType,
425
+ blurAmount,
426
+ styleId,
427
+ slideDirection,
428
+ slideFromX,
429
+ slideFromY,
430
+ slideToX,
431
+ slideToY
432
+ ]
433
+ );
434
+ const switchColorTheme = useCallback(
435
+ (newColorTheme) => {
436
+ if (colorThemes.indexOf(newColorTheme) === -1) {
437
+ console.warn(
438
+ `Color theme "${newColorTheme}" not found in available themes`
439
+ );
440
+ return;
441
+ }
442
+ setColorTheme(newColorTheme);
443
+ },
444
+ [colorThemes, setColorTheme]
445
+ );
446
+ const toggleTheme = useCallback(
447
+ async (animationOff = false) => {
448
+ const newTheme = resolvedTheme === "dark" ? "light" : "dark";
449
+ await switchTheme(newTheme, animationOff);
450
+ },
451
+ [resolvedTheme, switchTheme]
452
+ );
453
+ const toggleLightTheme = useCallback(
454
+ async (animationOff = false) => {
455
+ if (resolvedTheme === "light") return;
456
+ await switchTheme("light", animationOff);
457
+ },
458
+ [resolvedTheme, switchTheme]
459
+ );
460
+ const toggleDarkTheme = useCallback(
461
+ async (animationOff = false) => {
462
+ if (resolvedTheme === "dark") return;
463
+ await switchTheme("dark", animationOff);
464
+ },
465
+ [resolvedTheme, switchTheme]
466
+ );
467
+ const toggleColorTheme = useCallback(() => {
468
+ const currentIndex = colorThemes.indexOf(currentColorTheme);
469
+ const nextIndex = (currentIndex + 1) % colorThemes.length;
470
+ const nextColorTheme = colorThemes[nextIndex];
471
+ setColorTheme(nextColorTheme);
472
+ }, [currentColorTheme, colorThemes, setColorTheme]);
473
+ const createColorThemeToggle = useCallback(
474
+ (targetColorTheme) => {
475
+ return () => {
476
+ if (colorThemes.indexOf(targetColorTheme) === -1) {
477
+ console.warn(
478
+ `Color theme "${targetColorTheme}" not found in available themes`
479
+ );
480
+ return;
481
+ }
482
+ setColorTheme(targetColorTheme);
483
+ };
484
+ },
485
+ [colorThemes, setColorTheme]
486
+ );
487
+ const isColorThemeActive = useCallback(
488
+ (targetColorTheme) => {
489
+ return currentColorTheme === targetColorTheme;
490
+ },
491
+ [currentColorTheme]
492
+ );
493
+ return {
494
+ ref,
495
+ theme: currentTheme,
496
+ colorTheme: currentColorTheme,
497
+ resolvedTheme,
498
+ setTheme,
499
+ setColorTheme,
500
+ switchTheme,
501
+ switchColorTheme,
502
+ toggleTheme,
503
+ toggleLightTheme,
504
+ toggleDarkTheme,
505
+ toggleColorTheme,
506
+ createColorThemeToggle,
507
+ isColorThemeActive
508
+ };
509
+ };
510
+ var NextUIThemeContext = createContext(
511
+ void 0
512
+ );
513
+ var generatePreHydrationScript = (storageKey, colorStorageKey, defaultTheme, defaultColorTheme, attribute, globalClassName, colorThemePrefix) => {
514
+ return `
515
+ (function() {
516
+ try {
517
+ var theme = localStorage.getItem('${storageKey}') || '${defaultTheme}';
518
+ var colorTheme = localStorage.getItem('${colorStorageKey}') || '${defaultColorTheme}';
519
+ var resolved = theme === 'system'
520
+ ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
521
+ : theme;
522
+
523
+ if ('${attribute}' === 'class') {
524
+ if (resolved === 'dark') {
525
+ document.documentElement.classList.add('${globalClassName}');
526
+ } else {
527
+ document.documentElement.classList.remove('${globalClassName}');
528
+ }
529
+ } else {
530
+ document.documentElement.setAttribute('data-theme', resolved);
531
+ }
532
+
533
+ document.documentElement.style.colorScheme = resolved;
534
+ document.documentElement.classList.add('${colorThemePrefix}' + colorTheme);
535
+ } catch (e) {
536
+ console.warn('Theme pre-hydration script failed:', e);
537
+ }
538
+ })();
539
+ `;
540
+ };
541
+ var ThemePreHydrationScript = React.memo(
542
+ ({
543
+ storageKey,
544
+ colorStorageKey,
545
+ defaultTheme,
546
+ defaultColorTheme,
547
+ attribute,
548
+ globalClassName,
549
+ colorThemePrefix,
550
+ nonce
551
+ }) => {
552
+ const scriptContent = generatePreHydrationScript(
553
+ storageKey,
554
+ colorStorageKey,
555
+ defaultTheme,
556
+ defaultColorTheme,
557
+ attribute,
558
+ globalClassName,
559
+ colorThemePrefix
560
+ );
561
+ return /* @__PURE__ */ jsx(
562
+ "script",
563
+ {
564
+ nonce,
565
+ suppressHydrationWarning: true,
566
+ dangerouslySetInnerHTML: { __html: scriptContent }
567
+ }
568
+ );
569
+ }
570
+ );
571
+ ThemePreHydrationScript.displayName = "ThemePreHydrationScript";
572
+ var NextUIThemeProvider = ({
573
+ children,
574
+ themes = ["light", "dark", "system"],
575
+ colorThemes = ["default"],
576
+ defaultTheme = "system",
577
+ defaultColorTheme = "default",
578
+ animationType = "circle" /* CIRCLE */,
579
+ duration = 750,
580
+ storageKey = STORAGE_KEY,
581
+ colorStorageKey = COLOR_STORAGE_KEY,
582
+ attribute = "class",
583
+ globalClassName = GLOBAL_CLASS_NAME,
584
+ colorThemePrefix = COLOR_THEME_PREFIX,
585
+ nonce,
586
+ disableAnimationOnInit = true,
587
+ disablePreHydrationScript = false
588
+ }) => {
589
+ const [mounted, setMounted] = useState(false);
590
+ const themeState = useTheme({
591
+ themes,
592
+ colorThemes,
593
+ defaultTheme,
594
+ defaultColorTheme,
595
+ animationType,
596
+ duration,
597
+ storageKey,
598
+ colorStorageKey,
599
+ globalClassName: attribute === "class" ? globalClassName : void 0,
600
+ colorThemePrefix
601
+ });
602
+ useEffect(() => {
603
+ setMounted(true);
604
+ }, []);
605
+ const switchThemeWithHydrationAwareness = useCallback(
606
+ async (theme, animationOff = false) => {
607
+ if (!mounted && disableAnimationOnInit) {
608
+ themeState.setTheme(theme);
609
+ } else {
610
+ await themeState.switchTheme(theme, animationOff);
611
+ }
612
+ },
613
+ [mounted, disableAnimationOnInit, themeState]
614
+ );
615
+ const switchThemeFromElement = useCallback(
616
+ async (theme, element) => {
617
+ if (!mounted && disableAnimationOnInit) {
618
+ themeState.setTheme(theme);
619
+ return;
620
+ }
621
+ if (themeState.ref.current) {
622
+ const originalRef = themeState.ref.current;
623
+ Object.defineProperty(themeState.ref, "current", {
624
+ value: element,
625
+ writable: true,
626
+ configurable: true
627
+ });
628
+ await themeState.switchTheme(theme);
629
+ Object.defineProperty(themeState.ref, "current", {
630
+ value: originalRef,
631
+ writable: true,
632
+ configurable: true
633
+ });
634
+ } else {
635
+ Object.defineProperty(themeState.ref, "current", {
636
+ value: element,
637
+ writable: true,
638
+ configurable: true
639
+ });
640
+ await themeState.switchTheme(theme);
641
+ }
642
+ },
643
+ [mounted, disableAnimationOnInit, themeState]
644
+ );
645
+ const systemTheme = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
646
+ if (!mounted) {
647
+ const loadingContextValue = {
648
+ ref: { current: null },
649
+ theme: defaultTheme,
650
+ colorTheme: defaultColorTheme,
651
+ resolvedTheme: defaultTheme === "dark" ? "dark" : "light",
652
+ systemTheme: "light",
653
+ setTheme: () => {
654
+ },
655
+ setColorTheme: () => {
656
+ },
657
+ switchTheme: async () => {
658
+ },
659
+ switchThemeFromElement: async () => {
660
+ },
661
+ switchColorTheme: () => {
662
+ },
663
+ toggleTheme: async () => {
664
+ },
665
+ toggleLightTheme: async () => {
666
+ },
667
+ toggleDarkTheme: async () => {
668
+ },
669
+ toggleColorTheme: () => {
670
+ },
671
+ createColorThemeToggle: () => () => {
672
+ },
673
+ isColorThemeActive: () => false
674
+ };
675
+ return /* @__PURE__ */ jsxs(NextUIThemeContext.Provider, { value: loadingContextValue, children: [
676
+ !disablePreHydrationScript && /* @__PURE__ */ jsx(
677
+ ThemePreHydrationScript,
678
+ {
679
+ storageKey,
680
+ colorStorageKey,
681
+ defaultTheme,
682
+ defaultColorTheme,
683
+ attribute,
684
+ globalClassName,
685
+ colorThemePrefix,
686
+ nonce
687
+ }
688
+ ),
689
+ children
690
+ ] });
691
+ }
692
+ const contextValue = {
693
+ ref: themeState.ref,
694
+ theme: themeState.theme,
695
+ colorTheme: themeState.colorTheme,
696
+ resolvedTheme: themeState.resolvedTheme,
697
+ systemTheme,
698
+ setTheme: themeState.setTheme,
699
+ setColorTheme: themeState.setColorTheme,
700
+ switchTheme: switchThemeWithHydrationAwareness,
701
+ switchThemeFromElement,
702
+ switchColorTheme: themeState.switchColorTheme,
703
+ toggleTheme: themeState.toggleTheme,
704
+ toggleLightTheme: themeState.toggleLightTheme,
705
+ toggleDarkTheme: themeState.toggleDarkTheme,
706
+ toggleColorTheme: themeState.toggleColorTheme,
707
+ createColorThemeToggle: themeState.createColorThemeToggle,
708
+ isColorThemeActive: themeState.isColorThemeActive
709
+ };
710
+ return /* @__PURE__ */ jsxs(NextUIThemeContext.Provider, { value: contextValue, children: [
711
+ !disablePreHydrationScript && /* @__PURE__ */ jsx(
712
+ ThemePreHydrationScript,
713
+ {
714
+ storageKey,
715
+ colorStorageKey,
716
+ defaultTheme,
717
+ defaultColorTheme,
718
+ attribute,
719
+ globalClassName,
720
+ colorThemePrefix,
721
+ nonce
722
+ }
723
+ ),
724
+ children
725
+ ] });
726
+ };
727
+ var useNextUITheme = () => {
728
+ const context = useContext(NextUIThemeContext);
729
+ if (context === void 0) {
730
+ throw new Error("useNextUITheme must be used within a NextUIThemeProvider");
731
+ }
732
+ return context;
733
+ };
734
+ var TanStackUIThemeContext = createContext(void 0);
735
+ var generateTanStackPreHydrationScript = (storageKey, colorStorageKey, defaultTheme, defaultColorTheme, globalClassName, colorThemePrefix, systemThemeMode) => {
736
+ return `
737
+ (function() {
738
+ try {
739
+ var theme = localStorage.getItem('${storageKey}') || '${defaultTheme}';
740
+ var colorTheme = localStorage.getItem('${colorStorageKey}') || '${defaultColorTheme}';
741
+ var el = document.documentElement;
742
+ var resolved;
743
+ if (theme === 'system') {
744
+ if ('${systemThemeMode}' === 'css') {
745
+ el.classList.remove('${globalClassName}');
746
+ el.classList.remove('auto');
747
+ el.classList.remove('system');
748
+ el.classList.add('system');
749
+ el.style.colorScheme = '';
750
+ } else {
751
+ resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
752
+ if (resolved === 'dark') {
753
+ el.classList.add('${globalClassName}');
754
+ } else {
755
+ el.classList.remove('${globalClassName}');
756
+ }
757
+ el.classList.remove('system');
758
+ el.classList.remove('auto');
759
+ el.style.colorScheme = resolved;
760
+ }
761
+ } else {
762
+ resolved = theme;
763
+ el.classList.remove('system');
764
+ el.classList.remove('auto');
765
+ if (resolved === 'dark') {
766
+ el.classList.add('${globalClassName}');
767
+ } else {
768
+ el.classList.remove('${globalClassName}');
769
+ }
770
+ el.style.colorScheme = resolved;
771
+ }
772
+ if (colorTheme && colorTheme !== 'default') {
773
+ el.classList.add('${colorThemePrefix}' + colorTheme);
774
+ }
775
+ } catch (e) {
776
+ console.warn('Theme pre-hydration script failed:', e);
777
+ }
778
+ })();
779
+ `;
780
+ };
781
+ var TanStackStartThemeScript = React.memo(
782
+ ({
783
+ storageKey = STORAGE_KEY,
784
+ colorStorageKey = COLOR_STORAGE_KEY,
785
+ defaultTheme = "system",
786
+ defaultColorTheme = "default",
787
+ globalClassName = GLOBAL_CLASS_NAME,
788
+ colorThemePrefix = COLOR_THEME_PREFIX,
789
+ nonce,
790
+ systemThemeMode = "js"
791
+ }) => {
792
+ const scriptContent = generateTanStackPreHydrationScript(
793
+ storageKey,
794
+ colorStorageKey,
795
+ defaultTheme,
796
+ defaultColorTheme,
797
+ globalClassName,
798
+ colorThemePrefix,
799
+ systemThemeMode
800
+ );
801
+ return /* @__PURE__ */ jsx(
802
+ "script",
803
+ {
804
+ nonce,
805
+ suppressHydrationWarning: true,
806
+ dangerouslySetInnerHTML: { __html: scriptContent }
807
+ }
808
+ );
809
+ }
810
+ );
811
+ TanStackStartThemeScript.displayName = "TanStackStartThemeScript";
812
+ var useHydrated = () => {
813
+ return useSyncExternalStore(
814
+ () => () => {
815
+ },
816
+ () => true,
817
+ () => false
818
+ );
819
+ };
820
+ var TanStackUIThemeProvider = ({
821
+ children,
822
+ themes = ["light", "dark", "system"],
823
+ colorThemes = ["default"],
824
+ defaultTheme = "system",
825
+ defaultColorTheme = "default",
826
+ animationType = "circle" /* CIRCLE */,
827
+ duration = 750,
828
+ storageKey = STORAGE_KEY,
829
+ colorStorageKey = COLOR_STORAGE_KEY,
830
+ globalClassName = GLOBAL_CLASS_NAME,
831
+ colorThemePrefix = COLOR_THEME_PREFIX,
832
+ serverTheme,
833
+ serverColorTheme,
834
+ systemThemeMode = "css",
835
+ onServerThemeChange,
836
+ onServerColorThemeChange
837
+ }) => {
838
+ const isHydrated = useHydrated();
839
+ const hasServerTheme = serverTheme !== void 0;
840
+ const initialTheme = hasServerTheme ? serverTheme === "system" ? "system" : serverTheme : void 0;
841
+ const themeState = useTheme({
842
+ themes,
843
+ colorThemes,
844
+ defaultTheme,
845
+ defaultColorTheme,
846
+ animationType,
847
+ duration,
848
+ storageKey,
849
+ colorStorageKey,
850
+ globalClassName,
851
+ colorThemePrefix,
852
+ systemThemeMode,
853
+ initialTheme,
854
+ initialColorTheme: serverColorTheme
855
+ });
856
+ useEffect(() => {
857
+ if (!hasServerTheme) return;
858
+ if (initialTheme) {
859
+ setStoredTheme(initialTheme, storageKey);
860
+ }
861
+ if (serverColorTheme) {
862
+ setStoredColorTheme(serverColorTheme, colorStorageKey);
863
+ }
864
+ }, []);
865
+ const setThemeWithServer = useCallback(
866
+ (newTheme) => {
867
+ themeState.setTheme(newTheme);
868
+ if (onServerThemeChange) {
869
+ onServerThemeChange(newTheme);
870
+ }
871
+ },
872
+ [themeState, onServerThemeChange]
873
+ );
874
+ const setColorThemeWithServer = useCallback(
875
+ (newColorTheme) => {
876
+ themeState.setColorTheme(newColorTheme);
877
+ if (onServerColorThemeChange) {
878
+ onServerColorThemeChange(newColorTheme);
879
+ }
880
+ },
881
+ [themeState, onServerColorThemeChange]
882
+ );
883
+ const switchThemeWithHydrationAwareness = useCallback(
884
+ async (theme, animationOff = false) => {
885
+ if (!isHydrated) {
886
+ setThemeWithServer(theme);
887
+ } else {
888
+ await themeState.switchTheme(theme, animationOff);
889
+ if (onServerThemeChange) {
890
+ onServerThemeChange(theme);
891
+ }
892
+ }
893
+ },
894
+ [isHydrated, themeState, setThemeWithServer, onServerThemeChange]
895
+ );
896
+ const toggleThemeWithHydrationAwareness = useCallback(
897
+ async (animationOff = false) => {
898
+ if (!isHydrated) {
899
+ const nextTheme = themeState.resolvedTheme === "dark" ? "light" : "dark";
900
+ setThemeWithServer(nextTheme);
901
+ } else {
902
+ await themeState.toggleTheme(animationOff);
903
+ const nextTheme = themeState.resolvedTheme === "dark" ? "light" : "dark";
904
+ if (onServerThemeChange) {
905
+ onServerThemeChange(nextTheme);
906
+ }
907
+ }
908
+ },
909
+ [isHydrated, themeState, setThemeWithServer, onServerThemeChange]
910
+ );
911
+ const toggleLightThemeWithHydrationAwareness = useCallback(
912
+ async (animationOff = false) => {
913
+ if (!isHydrated) {
914
+ setThemeWithServer("light");
915
+ } else {
916
+ await themeState.toggleLightTheme(animationOff);
917
+ if (onServerThemeChange) {
918
+ onServerThemeChange("light");
919
+ }
920
+ }
921
+ },
922
+ [isHydrated, themeState, setThemeWithServer, onServerThemeChange]
923
+ );
924
+ const toggleDarkThemeWithHydrationAwareness = useCallback(
925
+ async (animationOff = false) => {
926
+ if (!isHydrated) {
927
+ setThemeWithServer("dark");
928
+ } else {
929
+ await themeState.toggleDarkTheme(animationOff);
930
+ if (onServerThemeChange) {
931
+ onServerThemeChange("dark");
932
+ }
933
+ }
934
+ },
935
+ [isHydrated, themeState, setThemeWithServer, onServerThemeChange]
936
+ );
937
+ const switchColorThemeWithServer = useCallback(
938
+ (newColorTheme) => {
939
+ themeState.switchColorTheme(newColorTheme);
940
+ if (onServerColorThemeChange) {
941
+ onServerColorThemeChange(newColorTheme);
942
+ }
943
+ },
944
+ [themeState, onServerColorThemeChange]
945
+ );
946
+ const switchThemeFromElement = useCallback(
947
+ async (theme, element) => {
948
+ if (!isHydrated) {
949
+ setThemeWithServer(theme);
950
+ return;
951
+ }
952
+ if (themeState.ref.current) {
953
+ const originalRef = themeState.ref.current;
954
+ Object.defineProperty(themeState.ref, "current", {
955
+ value: element,
956
+ writable: true,
957
+ configurable: true
958
+ });
959
+ await themeState.switchTheme(theme);
960
+ Object.defineProperty(themeState.ref, "current", {
961
+ value: originalRef,
962
+ writable: true,
963
+ configurable: true
964
+ });
965
+ } else {
966
+ Object.defineProperty(themeState.ref, "current", {
967
+ value: element,
968
+ writable: true,
969
+ configurable: true
970
+ });
971
+ await themeState.switchTheme(theme);
972
+ }
973
+ if (onServerThemeChange) {
974
+ onServerThemeChange(theme);
975
+ }
976
+ },
977
+ [isHydrated, themeState, setThemeWithServer, onServerThemeChange]
978
+ );
979
+ const systemTheme = typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
980
+ const serverResolvedTheme = (() => {
981
+ if (hasServerTheme) {
982
+ if (serverTheme === "dark") return "dark";
983
+ if (serverTheme === "system") return systemTheme;
984
+ return "light";
985
+ }
986
+ return defaultTheme === "dark" ? "dark" : "light";
987
+ })();
988
+ if (!isHydrated) {
989
+ const loadingContextValue = {
990
+ ref: { current: null },
991
+ theme: initialTheme ?? defaultTheme,
992
+ colorTheme: serverColorTheme ?? defaultColorTheme,
993
+ resolvedTheme: serverResolvedTheme,
994
+ systemTheme: "light",
995
+ isHydrated: false,
996
+ setTheme: setThemeWithServer,
997
+ setColorTheme: setColorThemeWithServer,
998
+ switchTheme: async (theme) => setThemeWithServer(theme),
999
+ switchThemeFromElement: async (theme) => setThemeWithServer(theme),
1000
+ switchColorTheme: switchColorThemeWithServer,
1001
+ toggleTheme: async () => {
1002
+ const nextTheme = serverResolvedTheme === "dark" ? "light" : "dark";
1003
+ setThemeWithServer(nextTheme);
1004
+ },
1005
+ toggleLightTheme: async () => setThemeWithServer("light"),
1006
+ toggleDarkTheme: async () => setThemeWithServer("dark"),
1007
+ toggleColorTheme: themeState.toggleColorTheme,
1008
+ createColorThemeToggle: themeState.createColorThemeToggle,
1009
+ isColorThemeActive: themeState.isColorThemeActive
1010
+ };
1011
+ return /* @__PURE__ */ jsx(TanStackUIThemeContext.Provider, { value: loadingContextValue, children });
1012
+ }
1013
+ const contextValue = {
1014
+ ref: themeState.ref,
1015
+ theme: themeState.theme,
1016
+ colorTheme: themeState.colorTheme,
1017
+ resolvedTheme: themeState.resolvedTheme,
1018
+ systemTheme,
1019
+ isHydrated: true,
1020
+ setTheme: setThemeWithServer,
1021
+ setColorTheme: setColorThemeWithServer,
1022
+ switchTheme: switchThemeWithHydrationAwareness,
1023
+ switchThemeFromElement,
1024
+ switchColorTheme: switchColorThemeWithServer,
1025
+ toggleTheme: toggleThemeWithHydrationAwareness,
1026
+ toggleLightTheme: toggleLightThemeWithHydrationAwareness,
1027
+ toggleDarkTheme: toggleDarkThemeWithHydrationAwareness,
1028
+ toggleColorTheme: themeState.toggleColorTheme,
1029
+ createColorThemeToggle: themeState.createColorThemeToggle,
1030
+ isColorThemeActive: themeState.isColorThemeActive
1031
+ };
1032
+ return /* @__PURE__ */ jsx(TanStackUIThemeContext.Provider, { value: contextValue, children });
1033
+ };
1034
+ var useTanStackUITheme = () => {
1035
+ const context = useContext(TanStackUIThemeContext);
1036
+ if (context === void 0) {
1037
+ throw new Error(
1038
+ "useTanStackUITheme must be used within a TanStackUIThemeProvider"
1039
+ );
1040
+ }
1041
+ return context;
1042
+ };
1043
+ var ViteUIThemeContext = createContext(
1044
+ void 0
1045
+ );
1046
+ var ViteUIThemeProvider = ({
1047
+ children,
1048
+ themes = ["light", "dark", "system"],
1049
+ colorThemes = ["default"],
1050
+ defaultTheme = "system",
1051
+ defaultColorTheme = "default",
1052
+ animationType = "circle" /* CIRCLE */,
1053
+ duration = 750,
1054
+ attribute = "class",
1055
+ disableTransitionOnChange = false,
1056
+ storageKey = "ui-theme",
1057
+ colorStorageKey = "ui-color-theme",
1058
+ globalClassName = "dark",
1059
+ colorThemePrefix = "theme-"
1060
+ }) => {
1061
+ const themeState = useTheme({
1062
+ themes,
1063
+ colorThemes,
1064
+ defaultTheme,
1065
+ defaultColorTheme,
1066
+ animationType,
1067
+ duration,
1068
+ storageKey,
1069
+ colorStorageKey,
1070
+ globalClassName: attribute === "class" ? globalClassName : void 0,
1071
+ colorThemePrefix
1072
+ });
1073
+ const applyTransitionDisable = useCallback(() => {
1074
+ if (!disableTransitionOnChange) return () => {
1075
+ };
1076
+ const css = document.createElement("style");
1077
+ css.textContent = `*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`;
1078
+ document.head.appendChild(css);
1079
+ window.getComputedStyle(document.body);
1080
+ return () => {
1081
+ setTimeout(() => {
1082
+ document.head.removeChild(css);
1083
+ }, 1);
1084
+ };
1085
+ }, [disableTransitionOnChange]);
1086
+ const wrappedSetTheme = useCallback(
1087
+ (theme) => {
1088
+ const cleanup = applyTransitionDisable();
1089
+ themeState.setTheme(theme);
1090
+ cleanup();
1091
+ },
1092
+ [themeState.setTheme, applyTransitionDisable]
1093
+ );
1094
+ const wrappedSwitchTheme = useCallback(
1095
+ async (theme, animationOff = false) => {
1096
+ const cleanup = applyTransitionDisable();
1097
+ await themeState.switchTheme(theme, animationOff);
1098
+ cleanup();
1099
+ },
1100
+ [themeState.switchTheme, applyTransitionDisable]
1101
+ );
1102
+ const wrappedToggleTheme = useCallback(
1103
+ async (animationOff = false) => {
1104
+ const cleanup = applyTransitionDisable();
1105
+ await themeState.toggleTheme(animationOff);
1106
+ cleanup();
1107
+ },
1108
+ [themeState.toggleTheme, applyTransitionDisable]
1109
+ );
1110
+ const wrappedToggleLightTheme = useCallback(
1111
+ async (animationOff = false) => {
1112
+ const cleanup = applyTransitionDisable();
1113
+ await themeState.toggleLightTheme(animationOff);
1114
+ cleanup();
1115
+ },
1116
+ [themeState.toggleLightTheme, applyTransitionDisable]
1117
+ );
1118
+ const wrappedToggleDarkTheme = useCallback(
1119
+ async (animationOff = false) => {
1120
+ const cleanup = applyTransitionDisable();
1121
+ await themeState.toggleDarkTheme(animationOff);
1122
+ cleanup();
1123
+ },
1124
+ [themeState.toggleDarkTheme, applyTransitionDisable]
1125
+ );
1126
+ const switchThemeFromElement = async (theme, element) => {
1127
+ const cleanup = applyTransitionDisable();
1128
+ if (themeState.ref.current) {
1129
+ const originalRef = themeState.ref.current;
1130
+ Object.defineProperty(themeState.ref, "current", {
1131
+ value: element,
1132
+ writable: true,
1133
+ configurable: true
1134
+ });
1135
+ await themeState.switchTheme(theme);
1136
+ Object.defineProperty(themeState.ref, "current", {
1137
+ value: originalRef,
1138
+ writable: true,
1139
+ configurable: true
1140
+ });
1141
+ } else {
1142
+ Object.defineProperty(themeState.ref, "current", {
1143
+ value: element,
1144
+ writable: true,
1145
+ configurable: true
1146
+ });
1147
+ await themeState.switchTheme(theme);
1148
+ }
1149
+ cleanup();
1150
+ };
1151
+ const systemTheme = getSystemTheme();
1152
+ const contextValue = {
1153
+ ref: themeState.ref,
1154
+ theme: themeState.theme,
1155
+ colorTheme: themeState.colorTheme,
1156
+ resolvedTheme: themeState.resolvedTheme,
1157
+ systemTheme,
1158
+ setTheme: wrappedSetTheme,
1159
+ setColorTheme: themeState.setColorTheme,
1160
+ switchTheme: wrappedSwitchTheme,
1161
+ switchThemeFromElement,
1162
+ switchColorTheme: themeState.switchColorTheme,
1163
+ toggleTheme: wrappedToggleTheme,
1164
+ toggleLightTheme: wrappedToggleLightTheme,
1165
+ toggleDarkTheme: wrappedToggleDarkTheme,
1166
+ toggleColorTheme: themeState.toggleColorTheme,
1167
+ createColorThemeToggle: themeState.createColorThemeToggle,
1168
+ isColorThemeActive: themeState.isColorThemeActive
1169
+ };
1170
+ return /* @__PURE__ */ jsx(ViteUIThemeContext.Provider, { value: contextValue, children });
1171
+ };
1172
+ var useViteUITheme = () => {
1173
+ const context = useContext(ViteUIThemeContext);
1174
+ if (context === void 0) {
1175
+ throw new Error("useViteUITheme must be used within a ViteUIThemeProvider");
1176
+ }
1177
+ return context;
1178
+ };
1179
+ var UIThemeContext = createContext(void 0);
1180
+ var UIThemeProvider = ({
1181
+ children,
1182
+ themes = ["light", "dark", "system"],
1183
+ colorThemes = ["default"],
1184
+ defaultTheme = "system",
1185
+ defaultColorTheme = "default",
1186
+ animationType = "circle" /* CIRCLE */,
1187
+ duration = 750,
1188
+ storageKey,
1189
+ colorStorageKey
1190
+ }) => {
1191
+ const [mounted, setMounted] = useState(false);
1192
+ const themeState = useTheme({
1193
+ themes,
1194
+ colorThemes,
1195
+ defaultTheme,
1196
+ defaultColorTheme,
1197
+ animationType,
1198
+ duration,
1199
+ storageKey,
1200
+ colorStorageKey
1201
+ });
1202
+ useEffect(() => {
1203
+ setMounted(true);
1204
+ }, []);
1205
+ const switchThemeFromElement = async (theme, element) => {
1206
+ if (themeState.ref.current) {
1207
+ const originalRef = themeState.ref.current;
1208
+ Object.defineProperty(themeState.ref, "current", {
1209
+ value: element,
1210
+ writable: true,
1211
+ configurable: true
1212
+ });
1213
+ await themeState.switchTheme(theme);
1214
+ Object.defineProperty(themeState.ref, "current", {
1215
+ value: originalRef,
1216
+ writable: true,
1217
+ configurable: true
1218
+ });
1219
+ } else {
1220
+ Object.defineProperty(themeState.ref, "current", {
1221
+ value: element,
1222
+ writable: true,
1223
+ configurable: true
1224
+ });
1225
+ await themeState.switchTheme(theme);
1226
+ }
1227
+ };
1228
+ if (!mounted) {
1229
+ const loadingContextValue = {
1230
+ ref: { current: null },
1231
+ theme: defaultTheme,
1232
+ colorTheme: defaultColorTheme,
1233
+ resolvedTheme: defaultTheme === "dark" ? "dark" : "light",
1234
+ setTheme: () => {
1235
+ },
1236
+ setColorTheme: () => {
1237
+ },
1238
+ switchTheme: async () => {
1239
+ },
1240
+ switchThemeFromElement: async () => {
1241
+ },
1242
+ switchColorTheme: () => {
1243
+ },
1244
+ toggleTheme: async () => {
1245
+ },
1246
+ toggleLightTheme: async () => {
1247
+ },
1248
+ toggleDarkTheme: async () => {
1249
+ },
1250
+ toggleColorTheme: () => {
1251
+ },
1252
+ createColorThemeToggle: () => () => {
1253
+ },
1254
+ isColorThemeActive: () => false
1255
+ };
1256
+ return /* @__PURE__ */ jsx(UIThemeContext.Provider, { value: loadingContextValue, children });
1257
+ }
1258
+ const contextValue = {
1259
+ ref: themeState.ref,
1260
+ theme: themeState.theme,
1261
+ colorTheme: themeState.colorTheme,
1262
+ resolvedTheme: themeState.resolvedTheme,
1263
+ setTheme: themeState.setTheme,
1264
+ setColorTheme: themeState.setColorTheme,
1265
+ switchTheme: themeState.switchTheme,
1266
+ switchThemeFromElement,
1267
+ switchColorTheme: themeState.switchColorTheme,
1268
+ toggleTheme: themeState.toggleTheme,
1269
+ toggleLightTheme: themeState.toggleLightTheme,
1270
+ toggleDarkTheme: themeState.toggleDarkTheme,
1271
+ toggleColorTheme: themeState.toggleColorTheme,
1272
+ createColorThemeToggle: themeState.createColorThemeToggle,
1273
+ isColorThemeActive: themeState.isColorThemeActive
1274
+ };
1275
+ return /* @__PURE__ */ jsx(UIThemeContext.Provider, { value: contextValue, children });
1276
+ };
1277
+ var useUITheme = () => {
1278
+ const context = useContext(UIThemeContext);
1279
+ if (context === void 0) {
1280
+ throw new Error("useUITheme must be used within a UIThemeProvider");
1281
+ }
1282
+ return context;
1283
+ };
1284
+ var SunIcon = () => /* @__PURE__ */ jsxs(
1285
+ "svg",
1286
+ {
1287
+ width: "16",
1288
+ height: "16",
1289
+ viewBox: "0 0 24 24",
1290
+ fill: "none",
1291
+ stroke: "currentColor",
1292
+ strokeWidth: "2",
1293
+ strokeLinecap: "round",
1294
+ strokeLinejoin: "round",
1295
+ children: [
1296
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "5" }),
1297
+ /* @__PURE__ */ jsx("path", { d: "M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" })
1298
+ ]
1299
+ }
1300
+ );
1301
+ var MoonIcon = () => /* @__PURE__ */ jsx(
1302
+ "svg",
1303
+ {
1304
+ width: "16",
1305
+ height: "16",
1306
+ viewBox: "0 0 24 24",
1307
+ fill: "none",
1308
+ stroke: "currentColor",
1309
+ strokeWidth: "2",
1310
+ strokeLinecap: "round",
1311
+ strokeLinejoin: "round",
1312
+ children: /* @__PURE__ */ jsx("path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" })
1313
+ }
1314
+ );
1315
+ var MonitorIcon = () => /* @__PURE__ */ jsxs(
1316
+ "svg",
1317
+ {
1318
+ width: "16",
1319
+ height: "16",
1320
+ viewBox: "0 0 24 24",
1321
+ fill: "none",
1322
+ stroke: "currentColor",
1323
+ strokeWidth: "2",
1324
+ strokeLinecap: "round",
1325
+ strokeLinejoin: "round",
1326
+ children: [
1327
+ /* @__PURE__ */ jsx("rect", { width: "20", height: "14", x: "2", y: "3", rx: "2" }),
1328
+ /* @__PURE__ */ jsx("line", { x1: "8", x2: "16", y1: "21", y2: "21" }),
1329
+ /* @__PURE__ */ jsx("line", { x1: "12", x2: "12", y1: "17", y2: "21" })
1330
+ ]
1331
+ }
1332
+ );
1333
+ var ThemeOption = ({
1334
+ icon,
1335
+ value,
1336
+ isActive,
1337
+ isHovered,
1338
+ onClick,
1339
+ onMouseEnter,
1340
+ onMouseLeave,
1341
+ buttonRef
1342
+ }) => {
1343
+ return /* @__PURE__ */ jsxs(
1344
+ "button",
1345
+ {
1346
+ ref: isActive ? buttonRef : void 0,
1347
+ className: `
1348
+ relative flex h-9 w-12 cursor-pointer items-center justify-center
1349
+ text-muted-foreground hover:text-foreground
1350
+ ${isActive ? "text-foreground font-medium" : ""}
1351
+ `,
1352
+ role: "radio",
1353
+ "aria-checked": isActive,
1354
+ "aria-label": `Switch to ${value} theme`,
1355
+ onClick: (event) => onClick(value, event),
1356
+ onMouseEnter,
1357
+ onMouseLeave,
1358
+ style: {
1359
+ borderRadius: "var(--radius)"
1360
+ },
1361
+ children: [
1362
+ isHovered && /* @__PURE__ */ jsx(
1363
+ "div",
1364
+ {
1365
+ className: "absolute inset-0 bg-muted",
1366
+ style: {
1367
+ borderRadius: "var(--radius)",
1368
+ transition: "all 0.2s ease"
1369
+ }
1370
+ }
1371
+ ),
1372
+ /* @__PURE__ */ jsx("div", { className: "relative z-10 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "[&_svg]:size-4", children: icon }) }),
1373
+ isActive && /* @__PURE__ */ jsx(
1374
+ "div",
1375
+ {
1376
+ className: "absolute bottom-0 left-1/2 h-0.5 w-6 -translate-x-1/2 rounded-full",
1377
+ style: {
1378
+ backgroundColor: "hsl(var(--primary))"
1379
+ }
1380
+ }
1381
+ )
1382
+ ]
1383
+ }
1384
+ );
1385
+ };
1386
+ var THEME_OPTIONS = [
1387
+ { icon: /* @__PURE__ */ jsx(MonitorIcon, {}), value: "system" },
1388
+ { icon: /* @__PURE__ */ jsx(SunIcon, {}), value: "light" },
1389
+ { icon: /* @__PURE__ */ jsx(MoonIcon, {}), value: "dark" }
1390
+ ];
1391
+ var UIThemeSwitcher = ({
1392
+ themes = ["light", "dark", "system"],
1393
+ currentTheme,
1394
+ onThemeChange,
1395
+ animationType,
1396
+ duration,
1397
+ className
1398
+ }) => {
1399
+ let contextTheme = null;
1400
+ try {
1401
+ contextTheme = useUITheme();
1402
+ } catch {
1403
+ }
1404
+ const standaloneHook = useTheme({
1405
+ animationType,
1406
+ duration,
1407
+ themes,
1408
+ ...currentTheme !== void 0 && { theme: currentTheme },
1409
+ onThemeChange
1410
+ });
1411
+ const isControlled = contextTheme !== null;
1412
+ const { ref, theme, switchTheme } = isControlled && contextTheme ? {
1413
+ ref: contextTheme.ref,
1414
+ theme: contextTheme.theme,
1415
+ switchTheme: contextTheme.switchTheme
1416
+ } : standaloneHook;
1417
+ const [isMounted, setIsMounted] = useState(false);
1418
+ const [hoveredTheme, setHoveredTheme] = useState(null);
1419
+ useEffect(() => {
1420
+ setIsMounted(true);
1421
+ }, []);
1422
+ const handleThemeChange = async (newTheme, event) => {
1423
+ if (isControlled && contextTheme?.switchThemeFromElement && event) {
1424
+ await contextTheme.switchThemeFromElement(
1425
+ newTheme,
1426
+ event.currentTarget
1427
+ );
1428
+ if (onThemeChange) {
1429
+ onThemeChange(newTheme);
1430
+ }
1431
+ } else {
1432
+ await switchTheme(newTheme);
1433
+ }
1434
+ };
1435
+ const filteredOptions = THEME_OPTIONS.filter(
1436
+ (option) => themes.includes(option.value)
1437
+ );
1438
+ return /* @__PURE__ */ jsx(
1439
+ "div",
1440
+ {
1441
+ className: `
1442
+ inline-flex h-9 items-center overflow-hidden bg-background shadow-sm border border-border
1443
+ ${isMounted ? "opacity-100" : "opacity-0"}
1444
+ ${className || ""}
1445
+ `,
1446
+ style: {
1447
+ borderRadius: "var(--radius)",
1448
+ backgroundColor: "hsl(var(--background))"
1449
+ },
1450
+ role: "radiogroup",
1451
+ onMouseLeave: () => setHoveredTheme(null),
1452
+ children: filteredOptions.map((option) => /* @__PURE__ */ jsx(
1453
+ ThemeOption,
1454
+ {
1455
+ icon: option.icon,
1456
+ value: option.value,
1457
+ isActive: theme === option.value,
1458
+ isHovered: hoveredTheme === option.value,
1459
+ onClick: handleThemeChange,
1460
+ onMouseEnter: () => setHoveredTheme(option.value),
1461
+ onMouseLeave: () => {
1462
+ },
1463
+ buttonRef: theme === option.value ? ref : void 0
1464
+ },
1465
+ option.value
1466
+ ))
1467
+ }
1468
+ );
1469
+ };
1470
+ var ChevronDownIcon = () => /* @__PURE__ */ jsx(
1471
+ "svg",
1472
+ {
1473
+ width: "16",
1474
+ height: "16",
1475
+ viewBox: "0 0 24 24",
1476
+ fill: "none",
1477
+ stroke: "currentColor",
1478
+ strokeWidth: "2",
1479
+ strokeLinecap: "round",
1480
+ strokeLinejoin: "round",
1481
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
1482
+ }
1483
+ );
1484
+ var ChevronUpIcon = () => /* @__PURE__ */ jsx(
1485
+ "svg",
1486
+ {
1487
+ width: "16",
1488
+ height: "16",
1489
+ viewBox: "0 0 24 24",
1490
+ fill: "none",
1491
+ stroke: "currentColor",
1492
+ strokeWidth: "2",
1493
+ strokeLinecap: "round",
1494
+ strokeLinejoin: "round",
1495
+ children: /* @__PURE__ */ jsx("path", { d: "m18 15-6-6-6 6" })
1496
+ }
1497
+ );
1498
+ var CheckIcon = () => /* @__PURE__ */ jsx(
1499
+ "svg",
1500
+ {
1501
+ width: "16",
1502
+ height: "16",
1503
+ viewBox: "0 0 24 24",
1504
+ fill: "none",
1505
+ stroke: "currentColor",
1506
+ strokeWidth: "2",
1507
+ strokeLinecap: "round",
1508
+ strokeLinejoin: "round",
1509
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
1510
+ }
1511
+ );
1512
+ function UISelect({
1513
+ ...props
1514
+ }) {
1515
+ return /* @__PURE__ */ jsx(SelectPrimitive.Root, { "data-slot": "ui-select", ...props });
1516
+ }
1517
+ function UISelectGroup({
1518
+ ...props
1519
+ }) {
1520
+ return /* @__PURE__ */ jsx(SelectPrimitive.Group, { "data-slot": "ui-select-group", ...props });
1521
+ }
1522
+ function UISelectValue({
1523
+ ...props
1524
+ }) {
1525
+ return /* @__PURE__ */ jsx(SelectPrimitive.Value, { "data-slot": "ui-select-value", ...props });
1526
+ }
1527
+ function UISelectTrigger({
1528
+ className,
1529
+ size = "default",
1530
+ children,
1531
+ ...props
1532
+ }) {
1533
+ return /* @__PURE__ */ jsxs(
1534
+ SelectPrimitive.Trigger,
1535
+ {
1536
+ "data-slot": "ui-select-trigger",
1537
+ "data-size": size,
1538
+ className: `
1539
+ border-input data-[placeholder]:text-muted-foreground
1540
+ [&_svg:not([class*='text-'])]:text-muted-foreground
1541
+ focus-visible:border-ring focus-visible:ring-ring/50
1542
+ aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40
1543
+ aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50
1544
+ flex w-fit items-center justify-between gap-2 rounded-md border
1545
+ bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs
1546
+ transition-[color,box-shadow] outline-none focus-visible:ring-[3px]
1547
+ disabled:cursor-not-allowed disabled:opacity-50
1548
+ data-[size=default]:h-9 data-[size=sm]:h-8
1549
+ *:data-[slot=ui-select-value]:line-clamp-1
1550
+ *:data-[slot=ui-select-value]:flex
1551
+ *:data-[slot=ui-select-value]:items-center
1552
+ *:data-[slot=ui-select-value]:gap-2
1553
+ [&_svg]:pointer-events-none [&_svg]:shrink-0
1554
+ [&_svg:not([class*='size-'])]:size-4
1555
+ ${className || ""}
1556
+ `,
1557
+ ...props,
1558
+ children: [
1559
+ children,
1560
+ /* @__PURE__ */ jsx(SelectPrimitive.Icon, { asChild: true, children: /* @__PURE__ */ jsx(ChevronDownIcon, {}) })
1561
+ ]
1562
+ }
1563
+ );
1564
+ }
1565
+ function UISelectContent({
1566
+ className,
1567
+ children,
1568
+ position = "popper",
1569
+ ...props
1570
+ }) {
1571
+ return /* @__PURE__ */ jsx(SelectPrimitive.Portal, { children: /* @__PURE__ */ jsx(
1572
+ SelectPrimitive.Content,
1573
+ {
1574
+ "data-slot": "ui-select-content",
1575
+ className: `
1576
+ bg-popover text-popover-foreground
1577
+ data-[state=open]:animate-in data-[state=closed]:animate-out
1578
+ data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0
1579
+ data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95
1580
+ data-[side=bottom]:slide-in-from-top-2
1581
+ data-[side=left]:slide-in-from-right-2
1582
+ data-[side=right]:slide-in-from-left-2
1583
+ data-[side=top]:slide-in-from-bottom-2
1584
+ relative z-50 max-h-[var(--radix-select-content-available-height)]
1585
+ min-w-[8rem] origin-[var(--radix-select-content-transform-origin)]
1586
+ overflow-x-hidden overflow-y-auto rounded-md border shadow-md
1587
+ ${position === "popper" ? "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1" : ""}
1588
+ ${className || ""}
1589
+ `,
1590
+ position,
1591
+ ...props,
1592
+ children: /* @__PURE__ */ jsx(
1593
+ SelectPrimitive.Viewport,
1594
+ {
1595
+ className: `
1596
+ p-1
1597
+ ${position === "popper" ? "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]" : ""}
1598
+ `,
1599
+ children
1600
+ }
1601
+ )
1602
+ }
1603
+ ) });
1604
+ }
1605
+ function UISelectLabel({
1606
+ className,
1607
+ ...props
1608
+ }) {
1609
+ return /* @__PURE__ */ jsx(
1610
+ SelectPrimitive.Label,
1611
+ {
1612
+ "data-slot": "ui-select-label",
1613
+ className: `py-1.5 pl-8 pr-2 text-sm font-semibold ${className || ""}`,
1614
+ ...props
1615
+ }
1616
+ );
1617
+ }
1618
+ function UISelectItem({
1619
+ className,
1620
+ children,
1621
+ ...props
1622
+ }) {
1623
+ return /* @__PURE__ */ jsxs(
1624
+ SelectPrimitive.Item,
1625
+ {
1626
+ "data-slot": "ui-select-item",
1627
+ className: `
1628
+ focus:bg-accent focus:text-accent-foreground
1629
+ [&_svg:not([class*='text-'])]:text-muted-foreground
1630
+ relative flex w-full cursor-default items-center gap-2
1631
+ rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none
1632
+ data-[disabled]:pointer-events-none data-[disabled]:opacity-50
1633
+ [&_svg]:pointer-events-none [&_svg]:shrink-0
1634
+ [&_svg:not([class*='size-'])]:size-4
1635
+ *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2
1636
+ ${className || ""}
1637
+ `,
1638
+ ...props,
1639
+ children: [
1640
+ /* @__PURE__ */ jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsx(SelectPrimitive.ItemIndicator, { children: /* @__PURE__ */ jsx(CheckIcon, {}) }) }),
1641
+ /* @__PURE__ */ jsx(SelectPrimitive.ItemText, { children })
1642
+ ]
1643
+ }
1644
+ );
1645
+ }
1646
+ function UISelectSeparator({
1647
+ className,
1648
+ ...props
1649
+ }) {
1650
+ return /* @__PURE__ */ jsx(
1651
+ SelectPrimitive.Separator,
1652
+ {
1653
+ "data-slot": "ui-select-separator",
1654
+ className: `-mx-1 my-1 h-px bg-muted ${className || ""}`,
1655
+ ...props
1656
+ }
1657
+ );
1658
+ }
1659
+ function UISelectScrollUpButton({
1660
+ className,
1661
+ ...props
1662
+ }) {
1663
+ return /* @__PURE__ */ jsx(
1664
+ SelectPrimitive.ScrollUpButton,
1665
+ {
1666
+ "data-slot": "ui-select-scroll-up-button",
1667
+ className: `flex cursor-default items-center justify-center py-1 ${className || ""}`,
1668
+ ...props,
1669
+ children: /* @__PURE__ */ jsx(ChevronUpIcon, {})
1670
+ }
1671
+ );
1672
+ }
1673
+ function UISelectScrollDownButton({
1674
+ className,
1675
+ ...props
1676
+ }) {
1677
+ return /* @__PURE__ */ jsx(
1678
+ SelectPrimitive.ScrollDownButton,
1679
+ {
1680
+ "data-slot": "ui-select-scroll-down-button",
1681
+ className: `flex cursor-default items-center justify-center py-1 ${className || ""}`,
1682
+ ...props,
1683
+ children: /* @__PURE__ */ jsx(ChevronDownIcon, {})
1684
+ }
1685
+ );
1686
+ }
1687
+ var UIThemeSelector = ({
1688
+ themes = ["light", "dark", "system"],
1689
+ colorThemes = ["default"],
1690
+ currentColorTheme,
1691
+ onColorThemeChange,
1692
+ animationType,
1693
+ duration,
1694
+ className,
1695
+ placeholder = "Choose a color theme"
1696
+ }) => {
1697
+ let contextTheme = null;
1698
+ try {
1699
+ contextTheme = useUITheme();
1700
+ } catch {
1701
+ }
1702
+ const standaloneHook = useTheme({
1703
+ animationType,
1704
+ duration,
1705
+ themes,
1706
+ colorThemes,
1707
+ ...currentColorTheme !== void 0 && { colorTheme: currentColorTheme },
1708
+ onColorThemeChange
1709
+ });
1710
+ const isControlled = contextTheme !== null;
1711
+ const { colorTheme, setColorTheme } = isControlled && contextTheme ? {
1712
+ colorTheme: contextTheme.colorTheme,
1713
+ setColorTheme: contextTheme.setColorTheme
1714
+ } : standaloneHook;
1715
+ const handleColorThemeChange = (newColorTheme) => {
1716
+ setColorTheme(newColorTheme);
1717
+ if (onColorThemeChange) {
1718
+ onColorThemeChange(newColorTheme);
1719
+ }
1720
+ };
1721
+ if (colorThemes.length <= 1) {
1722
+ return null;
1723
+ }
1724
+ return /* @__PURE__ */ jsx("div", { className: `flex flex-col gap-2 ${className || ""}`, children: /* @__PURE__ */ jsxs(UISelect, { value: colorTheme, onValueChange: handleColorThemeChange, children: [
1725
+ /* @__PURE__ */ jsx(UISelectTrigger, { className: "capitalize", children: /* @__PURE__ */ jsx(UISelectValue, { placeholder }) }),
1726
+ /* @__PURE__ */ jsx(UISelectContent, { children: colorThemes.map((theme) => /* @__PURE__ */ jsx(UISelectItem, { className: "capitalize", value: theme, children: theme }, theme)) })
1727
+ ] }) });
1728
+ };
1729
+
1730
+ export { COLOR_STORAGE_KEY, COLOR_THEME_PREFIX, DEFAULT_BLUR_AMOUNT, DEFAULT_DURATION, DEFAULT_EASING, DEFAULT_STYLE_ID, GLOBAL_CLASS_NAME, NextUIThemeProvider, STORAGE_KEY, TanStackStartThemeScript, TanStackUIThemeProvider, ThemeAnimationType, UISelect, UISelectContent, UISelectGroup, UISelectItem, UISelectLabel, UISelectScrollDownButton, UISelectScrollUpButton, UISelectSeparator, UISelectTrigger, UISelectValue, UIThemeProvider, UIThemeSelector, UIThemeSwitcher, ViteUIThemeProvider, getSystemTheme, injectBaseStyles, prefersReducedMotion, resolveTheme, resolveThemeForServer, supportsViewTransitions, useNextUITheme, useTanStackUITheme, useTheme, useUITheme, useViteUITheme };
1731
+ //# sourceMappingURL=index.js.map
1732
+ //# sourceMappingURL=index.js.map