@vuer-ai/vuer-uikit 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/chunk-4FOSHIMU.mjs +1 -0
  2. package/dist/chunk-CCGCEN7Z.js +79 -0
  3. package/dist/{chunk-Q5KEB4UK.mjs → chunk-GXZZGOXX.mjs} +19 -22
  4. package/dist/{chunk-FEYQ2OWB.mjs → chunk-I55IRAYH.mjs} +1 -1
  5. package/dist/chunk-LHWH4GP5.mjs +77 -0
  6. package/dist/chunk-Q3GXSHJV.mjs +214 -0
  7. package/dist/{chunk-OO7LYJQL.js → chunk-QSW45JZH.js} +1 -1
  8. package/dist/chunk-UOFJLQ72.js +2 -0
  9. package/dist/chunk-ZTNXAV64.js +217 -0
  10. package/dist/{chunk-EOFYA6CS.js → chunk-ZX6K2A3O.js} +18 -21
  11. package/dist/highlight-cursor/enhanced-components.js +9 -9
  12. package/dist/highlight-cursor/enhanced-components.mjs +4 -4
  13. package/dist/highlight-cursor/index.js +9 -9
  14. package/dist/highlight-cursor/index.mjs +4 -4
  15. package/dist/index.css +1 -1
  16. package/dist/index.d.mts +2 -1
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.js +139 -137
  19. package/dist/index.mjs +16 -14
  20. package/dist/ui/avatar.js +1 -1
  21. package/dist/ui/avatar.mjs +1 -1
  22. package/dist/ui/badge.js +1 -1
  23. package/dist/ui/badge.mjs +1 -1
  24. package/dist/ui/button.js +1 -1
  25. package/dist/ui/button.mjs +1 -1
  26. package/dist/ui/card.js +1 -1
  27. package/dist/ui/card.mjs +1 -1
  28. package/dist/ui/checkbox.js +1 -1
  29. package/dist/ui/checkbox.mjs +1 -1
  30. package/dist/ui/collapsible.js +1 -1
  31. package/dist/ui/collapsible.mjs +1 -1
  32. package/dist/ui/dropdown.js +1 -1
  33. package/dist/ui/dropdown.mjs +1 -1
  34. package/dist/ui/index.d.mts +2 -1
  35. package/dist/ui/index.d.ts +2 -1
  36. package/dist/ui/index.js +125 -123
  37. package/dist/ui/index.mjs +15 -13
  38. package/dist/ui/input-numbers.js +1 -1
  39. package/dist/ui/input-numbers.mjs +1 -1
  40. package/dist/ui/input.d.mts +1 -1
  41. package/dist/ui/input.d.ts +1 -1
  42. package/dist/ui/input.js +1 -1
  43. package/dist/ui/input.mjs +1 -1
  44. package/dist/ui/layout.js +1 -1
  45. package/dist/ui/layout.mjs +1 -1
  46. package/dist/ui/modal.js +1 -1
  47. package/dist/ui/modal.mjs +1 -1
  48. package/dist/ui/popover.js +1 -1
  49. package/dist/ui/popover.mjs +1 -1
  50. package/dist/ui/radio-group.js +1 -1
  51. package/dist/ui/radio-group.mjs +1 -1
  52. package/dist/ui/select.d.mts +1 -1
  53. package/dist/ui/select.d.ts +1 -1
  54. package/dist/ui/select.js +1 -1
  55. package/dist/ui/select.mjs +1 -1
  56. package/dist/ui/slider.js +1 -1
  57. package/dist/ui/slider.mjs +1 -1
  58. package/dist/ui/switch.js +1 -1
  59. package/dist/ui/switch.mjs +1 -1
  60. package/dist/ui/tabs.js +1 -1
  61. package/dist/ui/tabs.mjs +1 -1
  62. package/dist/ui/textarea.d.mts +1 -1
  63. package/dist/ui/textarea.d.ts +1 -1
  64. package/dist/ui/textarea.js +1 -1
  65. package/dist/ui/textarea.mjs +1 -1
  66. package/dist/ui/theme-context/index.d.mts +4 -0
  67. package/dist/ui/theme-context/index.d.ts +4 -0
  68. package/dist/ui/theme-context/index.js +16 -0
  69. package/dist/ui/theme-context/index.mjs +3 -0
  70. package/dist/ui/theme-context/theme-context.d.mts +8 -0
  71. package/dist/ui/theme-context/theme-context.d.ts +8 -0
  72. package/dist/ui/theme-context/theme-context.js +15 -0
  73. package/dist/ui/theme-context/theme-context.mjs +2 -0
  74. package/dist/ui/theme-context/theme-script.d.mts +13 -0
  75. package/dist/ui/theme-context/theme-script.d.ts +13 -0
  76. package/dist/ui/theme-context/theme-script.js +10 -0
  77. package/dist/ui/theme-context/theme-script.mjs +1 -0
  78. package/dist/ui/theme-context/theme-types.d.mts +47 -0
  79. package/dist/ui/theme-context/theme-types.d.ts +47 -0
  80. package/dist/ui/theme-context/theme-types.js +2 -0
  81. package/dist/ui/theme-context/theme-types.mjs +1 -0
  82. package/dist/ui/timeline.js +1 -1
  83. package/dist/ui/timeline.mjs +1 -1
  84. package/dist/ui/toggle-group.js +1 -1
  85. package/dist/ui/toggle-group.mjs +1 -1
  86. package/dist/ui/toggle.js +1 -1
  87. package/dist/ui/toggle.mjs +1 -1
  88. package/dist/ui/tooltip.js +1 -1
  89. package/dist/ui/tooltip.mjs +1 -1
  90. package/dist/ui/tree-view-v2.js +1 -1
  91. package/dist/ui/tree-view-v2.mjs +1 -1
  92. package/dist/ui/version-badge.js +3 -3
  93. package/dist/ui/version-badge.mjs +2 -2
  94. package/dist/utils/index.js +2 -2
  95. package/dist/utils/index.mjs +1 -1
  96. package/dist/utils/use-local-storage.js +2 -2
  97. package/dist/utils/use-local-storage.mjs +1 -1
  98. package/package.json +1 -1
  99. package/src/ui/theme-context/index.ts +3 -0
  100. package/src/ui/theme-context/theme-context.tsx +266 -0
  101. package/src/ui/theme-context/theme-script.tsx +101 -0
  102. package/src/ui/theme-context/theme-types.ts +50 -0
  103. package/src/utils/use-local-storage.ts +23 -25
  104. package/dist/chunk-LEPXSM36.mjs +0 -46
  105. package/dist/chunk-PVRQNCSJ.js +0 -49
  106. package/dist/ui/theme-context.d.mts +0 -17
  107. package/dist/ui/theme-context.d.ts +0 -17
  108. package/dist/ui/theme-context.js +0 -17
  109. package/dist/ui/theme-context.mjs +0 -4
  110. package/src/ui/theme-context.tsx +0 -80
  111. package/dist/{chunk-ALTUOIWV.mjs → chunk-HLJ7PQA7.mjs} +2 -2
  112. package/dist/{chunk-W7D57QE6.js → chunk-V4KNORQN.js} +2 -2
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // src/ui/theme-context/theme-script.tsx
7
+ var themeScript = (defaultTheme, storageKey, attribute, themes, value, forcedTheme, enableSystem, enableColorScheme) => {
8
+ const el = document.documentElement;
9
+ const systemThemes = ["light", "dark"];
10
+ function updateDOM(theme) {
11
+ const attributes = Array.isArray(attribute) ? attribute : [attribute];
12
+ attributes.forEach((attr) => {
13
+ const isClass = attr === "class";
14
+ const classes = isClass && value ? themes.map((t) => value[t] || t) : themes;
15
+ if (isClass) {
16
+ el.classList.remove(...classes);
17
+ el.classList.add(value && value[theme] ? value[theme] : theme);
18
+ } else {
19
+ el.setAttribute(attr, theme);
20
+ }
21
+ });
22
+ setColorScheme(theme);
23
+ }
24
+ function setColorScheme(theme) {
25
+ if (enableColorScheme && systemThemes.includes(theme)) {
26
+ el.style.colorScheme = theme;
27
+ }
28
+ }
29
+ function getSystemTheme() {
30
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
31
+ }
32
+ if (forcedTheme) {
33
+ updateDOM(forcedTheme);
34
+ } else {
35
+ try {
36
+ const themeName = localStorage.getItem(storageKey ?? "") || defaultTheme;
37
+ const isSystem = enableSystem && themeName === "system";
38
+ const theme = isSystem ? getSystemTheme() : themeName;
39
+ updateDOM(theme);
40
+ } catch {
41
+ }
42
+ }
43
+ };
44
+ var ThemeScript = react.memo(
45
+ ({
46
+ forcedTheme,
47
+ storageKey,
48
+ attribute,
49
+ enableSystem,
50
+ enableColorScheme,
51
+ defaultTheme,
52
+ value,
53
+ themes,
54
+ nonce,
55
+ scriptProps
56
+ }) => {
57
+ const scriptArgs = JSON.stringify([
58
+ defaultTheme,
59
+ storageKey,
60
+ attribute,
61
+ themes,
62
+ value,
63
+ forcedTheme,
64
+ enableSystem,
65
+ enableColorScheme
66
+ ]).slice(1, -1);
67
+ return /* @__PURE__ */ jsxRuntime.jsx(
68
+ "script",
69
+ {
70
+ ...scriptProps,
71
+ suppressHydrationWarning: true,
72
+ nonce: typeof window === "undefined" ? nonce : "",
73
+ dangerouslySetInnerHTML: { __html: `(${themeScript.toString()})(${scriptArgs})` }
74
+ }
75
+ );
76
+ }
77
+ );
78
+
79
+ exports.ThemeScript = ThemeScript;
@@ -1,28 +1,8 @@
1
- import { useState, useCallback } from 'react';
1
+ import { useState, useCallback, useEffect } from 'react';
2
2
 
3
3
  // src/utils/use-local-storage.ts
4
4
  function useLocalStorage(key, initialValue) {
5
- const [storedValue, setStoredValue] = useState(() => {
6
- if (typeof window === "undefined") {
7
- return initialValue;
8
- }
9
- try {
10
- const item = window.localStorage.getItem(key);
11
- if (item === null) return initialValue;
12
- if (typeof initialValue === "string") {
13
- return item;
14
- } else if (typeof initialValue === "number") {
15
- return parseFloat(item) || initialValue;
16
- } else if (typeof initialValue === "boolean") {
17
- return item === "true";
18
- } else {
19
- return JSON.parse(item);
20
- }
21
- } catch (error) {
22
- console.warn(`Error reading localStorage key "${key}":`, error);
23
- return initialValue;
24
- }
25
- });
5
+ const [storedValue, setStoredValue] = useState(initialValue);
26
6
  const setValue = useCallback(
27
7
  (value) => {
28
8
  try {
@@ -45,6 +25,23 @@ function useLocalStorage(key, initialValue) {
45
25
  },
46
26
  [key, storedValue]
47
27
  );
28
+ useEffect(() => {
29
+ try {
30
+ const item = window.localStorage.getItem(key);
31
+ if (item === null) return;
32
+ if (typeof initialValue === "string") {
33
+ setStoredValue(item);
34
+ } else if (typeof initialValue === "number") {
35
+ return setStoredValue(parseFloat(item) || initialValue);
36
+ } else if (typeof initialValue === "boolean") {
37
+ return setStoredValue(item === "true");
38
+ } else {
39
+ return setStoredValue(JSON.parse(item));
40
+ }
41
+ } catch (error) {
42
+ console.warn(`Error reading localStorage key "${key}":`, error);
43
+ }
44
+ }, [initialValue, key]);
48
45
  return [storedValue, setValue];
49
46
  }
50
47
 
@@ -1,7 +1,7 @@
1
1
  import { Badge } from './chunk-WO3WHXDP.mjs';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
 
4
- var PACKAGE_VERSION = "0.0.24" ;
4
+ var PACKAGE_VERSION = "0.0.25" ;
5
5
  var PACKAGE_NAME = "@vuer-ai/vuer-uikit" ;
6
6
  function VersionBadge({
7
7
  className,
@@ -0,0 +1,77 @@
1
+ import { memo } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ // src/ui/theme-context/theme-script.tsx
5
+ var themeScript = (defaultTheme, storageKey, attribute, themes, value, forcedTheme, enableSystem, enableColorScheme) => {
6
+ const el = document.documentElement;
7
+ const systemThemes = ["light", "dark"];
8
+ function updateDOM(theme) {
9
+ const attributes = Array.isArray(attribute) ? attribute : [attribute];
10
+ attributes.forEach((attr) => {
11
+ const isClass = attr === "class";
12
+ const classes = isClass && value ? themes.map((t) => value[t] || t) : themes;
13
+ if (isClass) {
14
+ el.classList.remove(...classes);
15
+ el.classList.add(value && value[theme] ? value[theme] : theme);
16
+ } else {
17
+ el.setAttribute(attr, theme);
18
+ }
19
+ });
20
+ setColorScheme(theme);
21
+ }
22
+ function setColorScheme(theme) {
23
+ if (enableColorScheme && systemThemes.includes(theme)) {
24
+ el.style.colorScheme = theme;
25
+ }
26
+ }
27
+ function getSystemTheme() {
28
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
29
+ }
30
+ if (forcedTheme) {
31
+ updateDOM(forcedTheme);
32
+ } else {
33
+ try {
34
+ const themeName = localStorage.getItem(storageKey ?? "") || defaultTheme;
35
+ const isSystem = enableSystem && themeName === "system";
36
+ const theme = isSystem ? getSystemTheme() : themeName;
37
+ updateDOM(theme);
38
+ } catch {
39
+ }
40
+ }
41
+ };
42
+ var ThemeScript = memo(
43
+ ({
44
+ forcedTheme,
45
+ storageKey,
46
+ attribute,
47
+ enableSystem,
48
+ enableColorScheme,
49
+ defaultTheme,
50
+ value,
51
+ themes,
52
+ nonce,
53
+ scriptProps
54
+ }) => {
55
+ const scriptArgs = JSON.stringify([
56
+ defaultTheme,
57
+ storageKey,
58
+ attribute,
59
+ themes,
60
+ value,
61
+ forcedTheme,
62
+ enableSystem,
63
+ enableColorScheme
64
+ ]).slice(1, -1);
65
+ return /* @__PURE__ */ jsx(
66
+ "script",
67
+ {
68
+ ...scriptProps,
69
+ suppressHydrationWarning: true,
70
+ nonce: typeof window === "undefined" ? nonce : "",
71
+ dangerouslySetInnerHTML: { __html: `(${themeScript.toString()})(${scriptArgs})` }
72
+ }
73
+ );
74
+ }
75
+ );
76
+
77
+ export { ThemeScript };
@@ -0,0 +1,214 @@
1
+ import { ThemeScript } from './chunk-LHWH4GP5.mjs';
2
+ import { createContext, useContext, useState, useCallback, useEffect, useMemo } from 'react';
3
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
+
5
+ var colorSchemes = ["light", "dark"];
6
+ var MEDIA = "(prefers-color-scheme: dark)";
7
+ var isServer = typeof window === "undefined";
8
+ var ThemeContext = createContext(void 0);
9
+ var saveToLS = (storageKey, value) => {
10
+ try {
11
+ localStorage.setItem(storageKey, value);
12
+ } catch {
13
+ }
14
+ };
15
+ var useTheme = () => {
16
+ const context = useContext(ThemeContext);
17
+ if (context === void 0) throw new Error("useTheme must be used within a ThemeProvider");
18
+ return context;
19
+ };
20
+ var ThemeProvider = (props) => {
21
+ const context = useContext(ThemeContext);
22
+ if (context) return /* @__PURE__ */ jsx(Fragment, { children: props.children });
23
+ return /* @__PURE__ */ jsx(Theme, { ...props });
24
+ };
25
+ var defaultThemes = ["light", "dark", "liquidlight", "liquiddark"];
26
+ var Theme = ({
27
+ forcedTheme,
28
+ disableTransitionOnChange = false,
29
+ enableSystem = false,
30
+ enableColorScheme = true,
31
+ storageKey = "theme",
32
+ themes = defaultThemes,
33
+ defaultTheme = enableSystem ? "system" : "light",
34
+ attribute = "class",
35
+ value,
36
+ children,
37
+ nonce,
38
+ scriptProps
39
+ }) => {
40
+ const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme));
41
+ const [resolvedTheme, setResolvedTheme] = useState(
42
+ () => theme === "system" ? getSystemTheme() : theme
43
+ );
44
+ const attrs = !value ? themes : Object.values(value);
45
+ const applyTheme = useCallback(
46
+ (theme2) => {
47
+ let resolved = theme2;
48
+ if (!resolved) return;
49
+ if (theme2 === "system" && enableSystem) {
50
+ resolved = getSystemTheme();
51
+ }
52
+ const name = value ? value[resolved] : resolved;
53
+ const enable = disableTransitionOnChange ? disableAnimation(nonce) : null;
54
+ const d = document.documentElement;
55
+ const handleAttribute = (attr) => {
56
+ if (attr === "class") {
57
+ d.classList.remove(...attrs);
58
+ if (name) d.classList.add(name);
59
+ } else if (attr.startsWith("data-")) {
60
+ if (name) {
61
+ d.setAttribute(attr, name);
62
+ } else {
63
+ d.removeAttribute(attr);
64
+ }
65
+ }
66
+ };
67
+ if (Array.isArray(attribute)) attribute.forEach(handleAttribute);
68
+ else handleAttribute(attribute);
69
+ if (enableColorScheme) {
70
+ let fallback = "light";
71
+ const c = colorSchemes.reduce(
72
+ (schema, currentValue) => {
73
+ if (defaultTheme.includes(currentValue)) {
74
+ fallback = currentValue;
75
+ }
76
+ if (resolved.includes(currentValue)) {
77
+ return currentValue;
78
+ }
79
+ return schema;
80
+ },
81
+ void 0
82
+ );
83
+ d.style.colorScheme = c ?? fallback;
84
+ }
85
+ enable == null ? void 0 : enable();
86
+ },
87
+ [
88
+ attribute,
89
+ attrs,
90
+ defaultTheme,
91
+ disableTransitionOnChange,
92
+ enableColorScheme,
93
+ enableSystem,
94
+ nonce,
95
+ value
96
+ ]
97
+ );
98
+ const setTheme = useCallback(
99
+ (value2) => {
100
+ if (typeof value2 === "function") {
101
+ setThemeState((prevTheme) => {
102
+ const newTheme = value2(prevTheme);
103
+ saveToLS(storageKey, newTheme);
104
+ return newTheme;
105
+ });
106
+ } else {
107
+ setThemeState(value2);
108
+ saveToLS(storageKey, value2);
109
+ }
110
+ },
111
+ [storageKey]
112
+ );
113
+ const handleMediaQuery = useCallback(
114
+ (e) => {
115
+ const resolved = getSystemTheme(e);
116
+ setResolvedTheme(resolved);
117
+ if (theme === "system" && enableSystem && !forcedTheme) {
118
+ applyTheme("system");
119
+ }
120
+ },
121
+ [theme, enableSystem, forcedTheme, applyTheme]
122
+ );
123
+ useEffect(() => {
124
+ const media = window.matchMedia(MEDIA);
125
+ media.addListener(handleMediaQuery);
126
+ handleMediaQuery(media);
127
+ return () => media.removeListener(handleMediaQuery);
128
+ }, [handleMediaQuery]);
129
+ useEffect(() => {
130
+ const handleStorage = (e) => {
131
+ if (e.key !== storageKey) {
132
+ return;
133
+ }
134
+ if (!e.newValue) {
135
+ setTheme(defaultTheme);
136
+ } else {
137
+ setThemeState(e.newValue);
138
+ }
139
+ };
140
+ window.addEventListener("storage", handleStorage);
141
+ return () => window.removeEventListener("storage", handleStorage);
142
+ }, [defaultTheme, setTheme, storageKey]);
143
+ useEffect(() => {
144
+ applyTheme(forcedTheme ?? theme);
145
+ }, [applyTheme, forcedTheme, theme]);
146
+ return /* @__PURE__ */ jsxs(
147
+ ThemeContext.Provider,
148
+ {
149
+ value: useMemo(
150
+ () => ({
151
+ theme,
152
+ setTheme,
153
+ forcedTheme,
154
+ resolvedTheme: theme === "system" ? resolvedTheme : theme,
155
+ themes: enableSystem ? [...themes, "system"] : themes,
156
+ systemTheme: enableSystem ? resolvedTheme : void 0
157
+ }),
158
+ [theme, setTheme, forcedTheme, resolvedTheme, enableSystem, themes]
159
+ ),
160
+ children: [
161
+ /* @__PURE__ */ jsx(
162
+ ThemeScript,
163
+ {
164
+ ...{
165
+ forcedTheme,
166
+ storageKey,
167
+ attribute,
168
+ enableSystem,
169
+ enableColorScheme,
170
+ defaultTheme,
171
+ value,
172
+ themes,
173
+ nonce,
174
+ scriptProps
175
+ }
176
+ }
177
+ ),
178
+ children
179
+ ]
180
+ }
181
+ );
182
+ };
183
+ var getTheme = (key, fallback) => {
184
+ if (isServer) return fallback;
185
+ let theme;
186
+ try {
187
+ theme = localStorage.getItem(key) || void 0;
188
+ } catch {
189
+ }
190
+ return theme || fallback;
191
+ };
192
+ var disableAnimation = (nonce) => {
193
+ const css = document.createElement("style");
194
+ if (nonce) css.setAttribute("nonce", nonce);
195
+ css.appendChild(
196
+ document.createTextNode(
197
+ `*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`
198
+ )
199
+ );
200
+ document.head.appendChild(css);
201
+ return () => {
202
+ (() => window.getComputedStyle(document.body))();
203
+ setTimeout(() => {
204
+ document.head.removeChild(css);
205
+ }, 1);
206
+ };
207
+ };
208
+ var getSystemTheme = (e) => {
209
+ if (!e) e = window.matchMedia(MEDIA);
210
+ const isDark = e.matches;
211
+ return isDark ? "dark" : "light";
212
+ };
213
+
214
+ export { ThemeProvider, useTheme };
@@ -3,7 +3,7 @@
3
3
  var chunkEFIRD3FN_js = require('./chunk-EFIRD3FN.js');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
 
6
- var PACKAGE_VERSION = "0.0.24" ;
6
+ var PACKAGE_VERSION = "0.0.25" ;
7
7
  var PACKAGE_NAME = "@vuer-ai/vuer-uikit" ;
8
8
  function VersionBadge({
9
9
  className,
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1,217 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGCEN7Z_js = require('./chunk-CCGCEN7Z.js');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ var colorSchemes = ["light", "dark"];
8
+ var MEDIA = "(prefers-color-scheme: dark)";
9
+ var isServer = typeof window === "undefined";
10
+ var ThemeContext = react.createContext(void 0);
11
+ var saveToLS = (storageKey, value) => {
12
+ try {
13
+ localStorage.setItem(storageKey, value);
14
+ } catch {
15
+ }
16
+ };
17
+ var useTheme = () => {
18
+ const context = react.useContext(ThemeContext);
19
+ if (context === void 0) throw new Error("useTheme must be used within a ThemeProvider");
20
+ return context;
21
+ };
22
+ var ThemeProvider = (props) => {
23
+ const context = react.useContext(ThemeContext);
24
+ if (context) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
25
+ return /* @__PURE__ */ jsxRuntime.jsx(Theme, { ...props });
26
+ };
27
+ var defaultThemes = ["light", "dark", "liquidlight", "liquiddark"];
28
+ var Theme = ({
29
+ forcedTheme,
30
+ disableTransitionOnChange = false,
31
+ enableSystem = false,
32
+ enableColorScheme = true,
33
+ storageKey = "theme",
34
+ themes = defaultThemes,
35
+ defaultTheme = enableSystem ? "system" : "light",
36
+ attribute = "class",
37
+ value,
38
+ children,
39
+ nonce,
40
+ scriptProps
41
+ }) => {
42
+ const [theme, setThemeState] = react.useState(() => getTheme(storageKey, defaultTheme));
43
+ const [resolvedTheme, setResolvedTheme] = react.useState(
44
+ () => theme === "system" ? getSystemTheme() : theme
45
+ );
46
+ const attrs = !value ? themes : Object.values(value);
47
+ const applyTheme = react.useCallback(
48
+ (theme2) => {
49
+ let resolved = theme2;
50
+ if (!resolved) return;
51
+ if (theme2 === "system" && enableSystem) {
52
+ resolved = getSystemTheme();
53
+ }
54
+ const name = value ? value[resolved] : resolved;
55
+ const enable = disableTransitionOnChange ? disableAnimation(nonce) : null;
56
+ const d = document.documentElement;
57
+ const handleAttribute = (attr) => {
58
+ if (attr === "class") {
59
+ d.classList.remove(...attrs);
60
+ if (name) d.classList.add(name);
61
+ } else if (attr.startsWith("data-")) {
62
+ if (name) {
63
+ d.setAttribute(attr, name);
64
+ } else {
65
+ d.removeAttribute(attr);
66
+ }
67
+ }
68
+ };
69
+ if (Array.isArray(attribute)) attribute.forEach(handleAttribute);
70
+ else handleAttribute(attribute);
71
+ if (enableColorScheme) {
72
+ let fallback = "light";
73
+ const c = colorSchemes.reduce(
74
+ (schema, currentValue) => {
75
+ if (defaultTheme.includes(currentValue)) {
76
+ fallback = currentValue;
77
+ }
78
+ if (resolved.includes(currentValue)) {
79
+ return currentValue;
80
+ }
81
+ return schema;
82
+ },
83
+ void 0
84
+ );
85
+ d.style.colorScheme = c ?? fallback;
86
+ }
87
+ enable == null ? void 0 : enable();
88
+ },
89
+ [
90
+ attribute,
91
+ attrs,
92
+ defaultTheme,
93
+ disableTransitionOnChange,
94
+ enableColorScheme,
95
+ enableSystem,
96
+ nonce,
97
+ value
98
+ ]
99
+ );
100
+ const setTheme = react.useCallback(
101
+ (value2) => {
102
+ if (typeof value2 === "function") {
103
+ setThemeState((prevTheme) => {
104
+ const newTheme = value2(prevTheme);
105
+ saveToLS(storageKey, newTheme);
106
+ return newTheme;
107
+ });
108
+ } else {
109
+ setThemeState(value2);
110
+ saveToLS(storageKey, value2);
111
+ }
112
+ },
113
+ [storageKey]
114
+ );
115
+ const handleMediaQuery = react.useCallback(
116
+ (e) => {
117
+ const resolved = getSystemTheme(e);
118
+ setResolvedTheme(resolved);
119
+ if (theme === "system" && enableSystem && !forcedTheme) {
120
+ applyTheme("system");
121
+ }
122
+ },
123
+ [theme, enableSystem, forcedTheme, applyTheme]
124
+ );
125
+ react.useEffect(() => {
126
+ const media = window.matchMedia(MEDIA);
127
+ media.addListener(handleMediaQuery);
128
+ handleMediaQuery(media);
129
+ return () => media.removeListener(handleMediaQuery);
130
+ }, [handleMediaQuery]);
131
+ react.useEffect(() => {
132
+ const handleStorage = (e) => {
133
+ if (e.key !== storageKey) {
134
+ return;
135
+ }
136
+ if (!e.newValue) {
137
+ setTheme(defaultTheme);
138
+ } else {
139
+ setThemeState(e.newValue);
140
+ }
141
+ };
142
+ window.addEventListener("storage", handleStorage);
143
+ return () => window.removeEventListener("storage", handleStorage);
144
+ }, [defaultTheme, setTheme, storageKey]);
145
+ react.useEffect(() => {
146
+ applyTheme(forcedTheme ?? theme);
147
+ }, [applyTheme, forcedTheme, theme]);
148
+ return /* @__PURE__ */ jsxRuntime.jsxs(
149
+ ThemeContext.Provider,
150
+ {
151
+ value: react.useMemo(
152
+ () => ({
153
+ theme,
154
+ setTheme,
155
+ forcedTheme,
156
+ resolvedTheme: theme === "system" ? resolvedTheme : theme,
157
+ themes: enableSystem ? [...themes, "system"] : themes,
158
+ systemTheme: enableSystem ? resolvedTheme : void 0
159
+ }),
160
+ [theme, setTheme, forcedTheme, resolvedTheme, enableSystem, themes]
161
+ ),
162
+ children: [
163
+ /* @__PURE__ */ jsxRuntime.jsx(
164
+ chunkCCGCEN7Z_js.ThemeScript,
165
+ {
166
+ ...{
167
+ forcedTheme,
168
+ storageKey,
169
+ attribute,
170
+ enableSystem,
171
+ enableColorScheme,
172
+ defaultTheme,
173
+ value,
174
+ themes,
175
+ nonce,
176
+ scriptProps
177
+ }
178
+ }
179
+ ),
180
+ children
181
+ ]
182
+ }
183
+ );
184
+ };
185
+ var getTheme = (key, fallback) => {
186
+ if (isServer) return fallback;
187
+ let theme;
188
+ try {
189
+ theme = localStorage.getItem(key) || void 0;
190
+ } catch {
191
+ }
192
+ return theme || fallback;
193
+ };
194
+ var disableAnimation = (nonce) => {
195
+ const css = document.createElement("style");
196
+ if (nonce) css.setAttribute("nonce", nonce);
197
+ css.appendChild(
198
+ document.createTextNode(
199
+ `*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`
200
+ )
201
+ );
202
+ document.head.appendChild(css);
203
+ return () => {
204
+ (() => window.getComputedStyle(document.body))();
205
+ setTimeout(() => {
206
+ document.head.removeChild(css);
207
+ }, 1);
208
+ };
209
+ };
210
+ var getSystemTheme = (e) => {
211
+ if (!e) e = window.matchMedia(MEDIA);
212
+ const isDark = e.matches;
213
+ return isDark ? "dark" : "light";
214
+ };
215
+
216
+ exports.ThemeProvider = ThemeProvider;
217
+ exports.useTheme = useTheme;