@tamagui/next-theme 2.7.7 → 3.0.0-beta.643.1

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 (41) hide show
  1. package/dist/cjs/NextTheme.cjs +10 -11
  2. package/dist/cjs/NextThemeProvider.cjs +182 -201
  3. package/dist/cjs/ThemeSettingContext.cjs +18 -21
  4. package/dist/cjs/UseThemeProps.cjs +10 -11
  5. package/dist/cjs/constants.cjs +17 -18
  6. package/dist/cjs/helpers.cjs +30 -31
  7. package/dist/cjs/index.cjs +10 -11
  8. package/dist/cjs/types.cjs +10 -11
  9. package/dist/cjs/useRootTheme.cjs +22 -27
  10. package/dist/cjs/useTheme.cjs +15 -20
  11. package/dist/esm/NextTheme.mjs +15 -9
  12. package/dist/esm/NextThemeProvider.mjs +166 -175
  13. package/dist/esm/NextThemeProvider.mjs.map +1 -1
  14. package/dist/esm/ThemeSettingContext.mjs +5 -3
  15. package/dist/esm/ThemeSettingContext.mjs.map +1 -1
  16. package/dist/esm/UseThemeProps.mjs +0 -2
  17. package/dist/esm/constants.mjs +1 -0
  18. package/dist/esm/constants.mjs.map +1 -1
  19. package/dist/esm/helpers.mjs +15 -13
  20. package/dist/esm/helpers.mjs.map +1 -1
  21. package/dist/esm/index.js +3 -3
  22. package/dist/esm/index.mjs +3 -3
  23. package/dist/esm/types.mjs +0 -2
  24. package/dist/esm/useRootTheme.mjs +9 -9
  25. package/dist/esm/useRootTheme.mjs.map +1 -1
  26. package/dist/esm/useTheme.mjs +3 -2
  27. package/dist/esm/useTheme.mjs.map +1 -1
  28. package/package.json +5 -5
  29. package/src/NextThemeProvider.tsx +0 -1
  30. package/src/UseThemeProps.tsx +0 -2
  31. package/src/useTheme.tsx +0 -6
  32. package/types/NextThemeProvider.d.ts.map +1 -1
  33. package/types/UseThemeProps.d.ts +0 -2
  34. package/types/UseThemeProps.d.ts.map +2 -2
  35. package/types/useTheme.d.ts +0 -4
  36. package/types/useTheme.d.ts.map +2 -2
  37. package/dist/esm/NextTheme.mjs.map +0 -1
  38. package/dist/esm/UseThemeProps.mjs.map +0 -1
  39. package/dist/esm/index.js.map +0 -1
  40. package/dist/esm/index.mjs.map +0 -1
  41. package/dist/esm/types.mjs.map +0 -1
@@ -1,47 +1,46 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var helpers_exports = {};
24
23
  __export(helpers_exports, {
25
- getSystemTheme: () => getSystemTheme,
26
- getTheme: () => getTheme,
27
- helpers: () => helpers
24
+ getSystemTheme: () => getSystemTheme,
25
+ getTheme: () => getTheme,
26
+ helpers: () => helpers
28
27
  });
29
28
  module.exports = __toCommonJS(helpers_exports);
30
29
  var import_constants = require("./constants.cjs");
31
30
  const helpers = {};
32
31
  const getTheme = (key, fallback) => {
33
- if (typeof window === "undefined") return void 0;
34
- let theme;
35
- try {
36
- theme = localStorage.getItem(key) || void 0;
37
- } catch (e) {}
38
- return theme || fallback;
32
+ if (typeof window === "undefined") return void 0;
33
+ let theme;
34
+ try {
35
+ theme = localStorage.getItem(key) || void 0;
36
+ } catch (e) {}
37
+ return theme || fallback;
38
+ };
39
+ const getSystemTheme = (e) => {
40
+ if (!e) {
41
+ e = window.matchMedia(import_constants.MEDIA);
42
+ }
43
+ const isDark = e.matches;
44
+ const systemTheme = isDark ? "dark" : "light";
45
+ return systemTheme;
39
46
  };
40
- const getSystemTheme = e => {
41
- if (!e) {
42
- e = window.matchMedia(import_constants.MEDIA);
43
- }
44
- const isDark = e.matches;
45
- const systemTheme = isDark ? "dark" : "light";
46
- return systemTheme;
47
- };
@@ -1,21 +1,20 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
- get: () => from[key],
9
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
- });
11
- }
12
- return to;
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ }
13
+ return to;
13
14
  };
14
15
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
- value: true
17
- }), mod);
16
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
17
  var index_exports = {};
19
18
  module.exports = __toCommonJS(index_exports);
20
19
  __reExport(index_exports, require("./NextTheme.cjs"), module.exports);
21
- __reExport(index_exports, require("./types.cjs"), module.exports);
20
+ __reExport(index_exports, require("./types.cjs"), module.exports);
@@ -1,18 +1,17 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
- get: () => from[key],
9
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
- });
11
- }
12
- return to;
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ }
13
+ return to;
13
14
  };
14
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
15
- value: true
16
- }), mod);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
17
16
  var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
17
+ module.exports = __toCommonJS(types_exports);
@@ -1,39 +1,34 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var useRootTheme_exports = {};
24
- __export(useRootTheme_exports, {
25
- useRootTheme: () => useRootTheme
26
- });
23
+ __export(useRootTheme_exports, { useRootTheme: () => useRootTheme });
27
24
  module.exports = __toCommonJS(useRootTheme_exports);
28
25
  var import_react = require("react");
29
26
  var import_constants = require("@tamagui/constants");
30
- const useRootTheme = ({
31
- fallback = "light"
32
- } = {}) => {
33
- let initialVal = fallback;
34
- if (import_constants.isClient) {
35
- const classes = document.documentElement.classList;
36
- initialVal = classes.contains("t_dark") ? "dark" : classes.contains("t_light") ? "light" : fallback;
37
- }
38
- return (0, import_react.useState)(initialVal);
39
- };
27
+ const useRootTheme = ({ fallback = "light" } = {}) => {
28
+ let initialVal = fallback;
29
+ if (import_constants.isClient) {
30
+ const classes = document.documentElement.classList;
31
+ initialVal = classes.contains("t_dark") ? "dark" : classes.contains("t_light") ? "light" : fallback;
32
+ }
33
+ return (0, import_react.useState)(initialVal);
34
+ };
@@ -1,32 +1,27 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var useTheme_exports = {};
24
- __export(useTheme_exports, {
25
- useTheme: () => useTheme,
26
- useThemeSetting: () => useThemeSetting
27
- });
23
+ __export(useTheme_exports, { useThemeSetting: () => useThemeSetting });
28
24
  module.exports = __toCommonJS(useTheme_exports);
29
25
  var import_react = require("react");
30
26
  var import_ThemeSettingContext = require("./ThemeSettingContext.cjs");
31
- const useTheme = () => (0, import_react.useContext)(import_ThemeSettingContext.ThemeSettingContext);
32
- const useThemeSetting = () => (0, import_react.useContext)(import_ThemeSettingContext.ThemeSettingContext);
27
+ const useThemeSetting = () => (0, import_react.useContext)(import_ThemeSettingContext.ThemeSettingContext);
@@ -1,9 +1,15 @@
1
- export * from "./NextThemeProvider.mjs";
2
- export * from "./ThemeSettingContext.mjs";
3
- export * from "./UseThemeProps.mjs";
4
- export * from "./helpers.mjs";
5
- export * from "./constants.mjs";
6
- export * from "./useTheme.mjs";
7
- export * from "./types.mjs";
8
- export * from "./useRootTheme.mjs";
9
- //# sourceMappingURL=NextTheme.mjs.map
1
+ export * from "./NextThemeProvider.mjs"
2
+
3
+ export * from "./ThemeSettingContext.mjs"
4
+
5
+ export * from "./UseThemeProps.mjs"
6
+
7
+ export * from "./helpers.mjs"
8
+
9
+ export * from "./constants.mjs"
10
+
11
+ export * from "./useTheme.mjs"
12
+
13
+ export * from "./types.mjs"
14
+
15
+ export * from "./useRootTheme.mjs"
@@ -7,183 +7,174 @@ import { MEDIA, colorSchemes } from "./constants.mjs";
7
7
  import { getSystemTheme, getTheme } from "./helpers.mjs";
8
8
  import { ThemeSettingContext } from "./ThemeSettingContext.mjs";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
- const NextThemeProvider = memo(({
11
- forcedTheme,
12
- disableTransitionOnChange = false,
13
- enableSystem = true,
14
- enableColorScheme = true,
15
- storageKey = "theme",
16
- themes = colorSchemes,
17
- defaultTheme = enableSystem ? "system" : "light",
18
- attribute = "class",
19
- skipNextHead,
20
- onChangeTheme,
21
- value = {
22
- dark: "t_dark",
23
- light: "t_light"
24
- },
25
- children
26
- }) => {
27
- const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme));
28
- const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey));
29
- const attrs = !value ? themes : Object.values(value);
30
- const handleMediaQuery = useEvent(e => {
31
- const _ = getSystemTheme(e);
32
- const update = () => setResolvedTheme(_);
33
- if (disableTransitionOnChange) {
34
- update();
35
- } else {
36
- React.startTransition(() => update());
37
- }
38
- if (theme === "system" && !forcedTheme) {
39
- handleChangeTheme(_, false);
40
- }
41
- });
42
- const handleChangeTheme = useEvent((theme2, updateStorage = true, updateDOM = true) => {
43
- let name = value?.[theme2] || theme2;
44
- if (updateStorage) {
45
- try {
46
- localStorage.setItem(storageKey, theme2);
47
- } catch (e) {}
48
- }
49
- if (theme2 === "system" && enableSystem) {
50
- const resolved = getSystemTheme();
51
- name = value?.[resolved] || resolved;
52
- }
53
- onChangeTheme?.(name.replace("t_", ""));
54
- if (updateDOM) {
55
- const d = document.documentElement;
56
- if (attribute === "class") {
57
- d.classList.remove(...attrs);
58
- d.classList.add(name);
59
- } else {
60
- d.setAttribute(attribute, name);
61
- }
62
- }
63
- });
64
- useIsomorphicLayoutEffect(() => {
65
- const media = window.matchMedia(MEDIA);
66
- media.addListener(handleMediaQuery);
67
- handleMediaQuery(media);
68
- return () => {
69
- media.removeListener(handleMediaQuery);
70
- };
71
- }, []);
72
- const set = useEvent(newTheme => {
73
- if (forcedTheme) {
74
- return;
75
- }
76
- handleChangeTheme(newTheme);
77
- setThemeState(newTheme);
78
- });
79
- useEffect(() => {
80
- const handleStorage = e => {
81
- if (e.key !== storageKey) {
82
- return;
83
- }
84
- const theme2 = e.newValue || defaultTheme;
85
- set(theme2);
86
- };
87
- window.addEventListener("storage", handleStorage);
88
- return () => {
89
- window.removeEventListener("storage", handleStorage);
90
- };
91
- }, [defaultTheme, set, storageKey]);
92
- useIsomorphicLayoutEffect(() => {
93
- if (!enableColorScheme) return;
94
- const colorScheme =
95
- // If theme is forced to light or dark, use that
96
- forcedTheme && colorSchemes.includes(forcedTheme) ? forcedTheme :
97
- // If regular theme is light or dark
98
- theme && colorSchemes.includes(theme) ? theme :
99
- // If theme is system, use the resolved version
100
- theme === "system" ? resolvedTheme || null : null;
101
- const userPrefers = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
102
- const wePrefer = colorScheme || "light";
103
- if (userPrefers !== wePrefer) {
104
- document.documentElement.style.setProperty("color-scheme", colorScheme);
105
- }
106
- }, [enableColorScheme, theme, resolvedTheme, forcedTheme]);
107
- const toggle = useEvent(() => {
108
- const order = resolvedTheme === "dark" ? ["system", "light", "dark"] : ["system", "dark", "light"];
109
- const next = order[(order.indexOf(theme) + 1) % order.length];
110
- set(next);
111
- });
112
- const systemTheme = enableSystem ? resolvedTheme : void 0;
113
- const contextValue = useMemo(() => {
114
- const value2 = {
115
- theme,
116
- current: theme,
117
- set,
118
- toggle,
119
- forcedTheme,
120
- resolvedTheme: theme === "system" ? resolvedTheme : theme,
121
- themes: enableSystem ? [...themes, "system"] : themes,
122
- systemTheme
123
- };
124
- return value2;
125
- }, [theme, set, toggle, forcedTheme, resolvedTheme, enableSystem, themes, systemTheme]);
126
- return /* @__PURE__ */jsxs(ThemeSettingContext.Provider, {
127
- value: contextValue,
128
- children: [/* @__PURE__ */jsx(ThemeScript, {
129
- ...{
130
- forcedTheme,
131
- storageKey,
132
- systemTheme: resolvedTheme,
133
- attribute,
134
- value,
135
- enableSystem,
136
- defaultTheme,
137
- attrs,
138
- skipNextHead
139
- }
140
- }), children]
141
- });
10
+
11
+ const NextThemeProvider = memo(({ forcedTheme, disableTransitionOnChange = false, enableSystem = true, enableColorScheme = true, storageKey = "theme", themes = colorSchemes, defaultTheme = enableSystem ? "system" : "light", attribute = "class", skipNextHead, onChangeTheme, value = {
12
+ dark: "t_dark",
13
+ light: "t_light"
14
+ }, children }) => {
15
+ const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme));
16
+ const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey));
17
+ const attrs = !value ? themes : Object.values(value);
18
+ const handleMediaQuery = useEvent((e) => {
19
+ const _ = getSystemTheme(e);
20
+ const update = () => setResolvedTheme(_);
21
+ if (disableTransitionOnChange) {
22
+ update();
23
+ } else {
24
+ React.startTransition(() => update());
25
+ }
26
+ if (theme === "system" && !forcedTheme) {
27
+ handleChangeTheme(_, false);
28
+ }
29
+ });
30
+ const handleChangeTheme = useEvent((theme2, updateStorage = true, updateDOM = true) => {
31
+ let name = value?.[theme2] || theme2;
32
+ if (updateStorage) {
33
+ try {
34
+ localStorage.setItem(storageKey, theme2);
35
+ } catch (e) {}
36
+ }
37
+ if (theme2 === "system" && enableSystem) {
38
+ const resolved = getSystemTheme();
39
+ name = value?.[resolved] || resolved;
40
+ }
41
+ onChangeTheme?.(name.replace("t_", ""));
42
+ if (updateDOM) {
43
+ const d = document.documentElement;
44
+ if (attribute === "class") {
45
+ d.classList.remove(...attrs);
46
+ d.classList.add(name);
47
+ } else {
48
+ d.setAttribute(attribute, name);
49
+ }
50
+ }
51
+ });
52
+ useIsomorphicLayoutEffect(() => {
53
+ const media = window.matchMedia(MEDIA);
54
+ media.addListener(handleMediaQuery);
55
+ handleMediaQuery(media);
56
+ return () => {
57
+ media.removeListener(handleMediaQuery);
58
+ };
59
+ }, []);
60
+ const set = useEvent((newTheme) => {
61
+ if (forcedTheme) {
62
+ return;
63
+ }
64
+ handleChangeTheme(newTheme);
65
+ setThemeState(newTheme);
66
+ });
67
+ useEffect(() => {
68
+ const handleStorage = (e) => {
69
+ if (e.key !== storageKey) {
70
+ return;
71
+ }
72
+ const theme2 = e.newValue || defaultTheme;
73
+ set(theme2);
74
+ };
75
+ window.addEventListener("storage", handleStorage);
76
+ return () => {
77
+ window.removeEventListener("storage", handleStorage);
78
+ };
79
+ }, [
80
+ defaultTheme,
81
+ set,
82
+ storageKey
83
+ ]);
84
+ useIsomorphicLayoutEffect(() => {
85
+ if (!enableColorScheme) return;
86
+ const colorScheme = forcedTheme && colorSchemes.includes(forcedTheme) ? forcedTheme : theme && colorSchemes.includes(theme) ? theme : theme === "system" ? resolvedTheme || null : null;
87
+ const userPrefers = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
88
+ const wePrefer = colorScheme || "light";
89
+ if (userPrefers !== wePrefer) {
90
+ document.documentElement.style.setProperty("color-scheme", colorScheme);
91
+ }
92
+ }, [
93
+ enableColorScheme,
94
+ theme,
95
+ resolvedTheme,
96
+ forcedTheme
97
+ ]);
98
+ const toggle = useEvent(() => {
99
+ const order = resolvedTheme === "dark" ? [
100
+ "system",
101
+ "light",
102
+ "dark"
103
+ ] : [
104
+ "system",
105
+ "dark",
106
+ "light"
107
+ ];
108
+ const next = order[(order.indexOf(theme) + 1) % order.length];
109
+ set(next);
110
+ });
111
+ const systemTheme = enableSystem ? resolvedTheme : void 0;
112
+ const contextValue = useMemo(() => {
113
+ const value2 = {
114
+ current: theme,
115
+ set,
116
+ toggle,
117
+ forcedTheme,
118
+ resolvedTheme: theme === "system" ? resolvedTheme : theme,
119
+ themes: enableSystem ? [...themes, "system"] : themes,
120
+ systemTheme
121
+ };
122
+ return value2;
123
+ }, [
124
+ theme,
125
+ set,
126
+ toggle,
127
+ forcedTheme,
128
+ resolvedTheme,
129
+ enableSystem,
130
+ themes,
131
+ systemTheme
132
+ ]);
133
+ return /* @__PURE__ */ jsxs(ThemeSettingContext.Provider, {
134
+ value: contextValue,
135
+ children: [/* @__PURE__ */ jsx(ThemeScript, { ...{
136
+ forcedTheme,
137
+ storageKey,
138
+ systemTheme: resolvedTheme,
139
+ attribute,
140
+ value,
141
+ enableSystem,
142
+ defaultTheme,
143
+ attrs,
144
+ skipNextHead
145
+ } }), children]
146
+ });
142
147
  });
143
- const ThemeScript = memo(({
144
- forcedTheme,
145
- storageKey,
146
- attribute,
147
- enableSystem,
148
- defaultTheme,
149
- value,
150
- attrs,
151
- skipNextHead
152
- }) => {
153
- const optimization = (() => {
154
- if (attribute === "class") {
155
- const removeClasses = attrs.map(t => `d.remove('${t}')`).join(";");
156
- return `var d=document.documentElement.classList;${removeClasses};`;
157
- }
158
- return `var d=document.documentElement;`;
159
- })();
160
- const updateDOM = (name, literal) => {
161
- name = value?.[name] || name;
162
- const val = literal ? name : `'${name}'`;
163
- if (attribute === "class") {
164
- return `d.add(${val})`;
165
- }
166
- return `d.setAttribute('${attribute}', ${val})`;
167
- };
168
- const defaultSystem = defaultTheme === "system";
169
- const scriptContent = forcedTheme ? `!function(){${optimization}${updateDOM(forcedTheme)}}()` : enableSystem ? `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');if("system"===e||(!e&&${defaultSystem})){var t="${MEDIA}",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM("dark")}:${updateDOM("light")}}else if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", true)}}${!defaultSystem ? `else{${updateDOM(defaultTheme)}}` : ""}}catch(e){}}()` : `!function(){try{${optimization}var e=localStorage.getItem("${storageKey}");if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", true)}}else{${updateDOM(defaultTheme)};}}catch(t){}}();`;
170
- if (skipNextHead) {
171
- return /* @__PURE__ */jsx("script", {
172
- dangerouslySetInnerHTML: {
173
- __html: scriptContent
174
- }
175
- }, "next-themes-script");
176
- }
177
- return /* @__PURE__ */jsx(Script, {
178
- id: "next-themes-script",
179
- strategy: "beforeInteractive",
180
- dangerouslySetInnerHTML: {
181
- __html: scriptContent
182
- }
183
- });
148
+ const ThemeScript = memo(({ forcedTheme, storageKey, attribute, enableSystem, defaultTheme, value, attrs, skipNextHead }) => {
149
+ const optimization = (() => {
150
+ if (attribute === "class") {
151
+ const removeClasses = attrs.map((t) => `d.remove('${t}')`).join(";");
152
+ return `var d=document.documentElement.classList;${removeClasses};`;
153
+ }
154
+ return `var d=document.documentElement;`;
155
+ })();
156
+ const updateDOM = (name, literal) => {
157
+ name = value?.[name] || name;
158
+ const val = literal ? name : `'${name}'`;
159
+ if (attribute === "class") {
160
+ return `d.add(${val})`;
161
+ }
162
+ return `d.setAttribute('${attribute}', ${val})`;
163
+ };
164
+ const defaultSystem = defaultTheme === "system";
165
+ const scriptContent = forcedTheme ? `!function(){${optimization}${updateDOM(forcedTheme)}}()` : enableSystem ? `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');if("system"===e||(!e&&${defaultSystem})){var t="${MEDIA}",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM("dark")}:${updateDOM("light")}}else if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", true)}}${!defaultSystem ? `else{${updateDOM(defaultTheme)}}` : ""}}catch(e){}}()` : `!function(){try{${optimization}var e=localStorage.getItem("${storageKey}");if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", true)}}else{${updateDOM(defaultTheme)};}}catch(t){}}();`;
166
+ if (skipNextHead) {
167
+ return /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: scriptContent } }, "next-themes-script");
168
+ }
169
+ return /* @__PURE__ */ jsx(Script, {
170
+ id: "next-themes-script",
171
+ strategy: "beforeInteractive",
172
+ dangerouslySetInnerHTML: { __html: scriptContent }
173
+ });
184
174
  }, (prevProps, nextProps) => {
185
- if (prevProps.forcedTheme !== nextProps.forcedTheme) return false;
186
- return true;
175
+ if (prevProps.forcedTheme !== nextProps.forcedTheme) return false;
176
+ return true;
187
177
  });
178
+
188
179
  export { NextThemeProvider };
189
180
  //# sourceMappingURL=NextThemeProvider.mjs.map