@tamagui/next-theme 2.7.7 → 3.0.0-beta.1091.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.
- package/dist/cjs/NextTheme.cjs +9 -11
- package/dist/cjs/NextThemeProvider.cjs +181 -201
- package/dist/cjs/ThemeSettingContext.cjs +17 -21
- package/dist/cjs/UseThemeProps.cjs +9 -11
- package/dist/cjs/constants.cjs +16 -18
- package/dist/cjs/helpers.cjs +29 -31
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/useRootTheme.cjs +21 -27
- package/dist/cjs/useTheme.cjs +14 -20
- package/dist/esm/NextTheme.mjs +15 -9
- package/dist/esm/NextThemeProvider.mjs +166 -175
- package/dist/esm/NextThemeProvider.mjs.map +1 -1
- package/dist/esm/ThemeSettingContext.mjs +5 -3
- package/dist/esm/ThemeSettingContext.mjs.map +1 -1
- package/dist/esm/UseThemeProps.mjs +0 -2
- package/dist/esm/constants.mjs +1 -0
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/helpers.mjs +15 -13
- package/dist/esm/helpers.mjs.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/useRootTheme.mjs +9 -9
- package/dist/esm/useRootTheme.mjs.map +1 -1
- package/dist/esm/useTheme.mjs +3 -2
- package/dist/esm/useTheme.mjs.map +1 -1
- package/package.json +8 -7
- package/src/NextThemeProvider.tsx +0 -1
- package/src/UseThemeProps.tsx +0 -2
- package/src/useTheme.tsx +0 -6
- package/types/NextThemeProvider.d.ts.map +1 -1
- package/types/UseThemeProps.d.ts +0 -2
- package/types/UseThemeProps.d.ts.map +2 -2
- package/types/useTheme.d.ts +0 -4
- package/types/useTheme.d.ts.map +2 -2
- package/dist/esm/NextTheme.mjs.map +0 -1
- package/dist/esm/UseThemeProps.mjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,19 +3,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
13
|
};
|
|
14
14
|
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);
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
16
|
var index_exports = {};
|
|
19
17
|
module.exports = __toCommonJS(index_exports);
|
|
20
18
|
__reExport(index_exports, require("./NextTheme.cjs"), module.exports);
|
|
21
|
-
__reExport(index_exports, require("./types.cjs"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./types.cjs"), module.exports);
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -3,16 +3,14 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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;
|
|
13
13
|
};
|
|
14
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
}), mod);
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
17
15
|
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -3,37 +3,31 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
19
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var useRootTheme_exports = {};
|
|
24
|
-
__export(useRootTheme_exports, {
|
|
25
|
-
useRootTheme: () => useRootTheme
|
|
26
|
-
});
|
|
22
|
+
__export(useRootTheme_exports, { useRootTheme: () => useRootTheme });
|
|
27
23
|
module.exports = __toCommonJS(useRootTheme_exports);
|
|
28
24
|
var import_react = require("react");
|
|
29
25
|
var import_constants = require("@tamagui/constants");
|
|
30
|
-
const useRootTheme = ({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return (0, import_react.useState)(initialVal);
|
|
39
|
-
};
|
|
26
|
+
const useRootTheme = ({ fallback = "light" } = {}) => {
|
|
27
|
+
let initialVal = fallback;
|
|
28
|
+
if (import_constants.isClient) {
|
|
29
|
+
const classes = document.documentElement.classList;
|
|
30
|
+
initialVal = classes.contains("t_dark") ? "dark" : classes.contains("t_light") ? "light" : fallback;
|
|
31
|
+
}
|
|
32
|
+
return (0, import_react.useState)(initialVal);
|
|
33
|
+
};
|
package/dist/cjs/useTheme.cjs
CHANGED
|
@@ -3,30 +3,24 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
19
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var useTheme_exports = {};
|
|
24
|
-
__export(useTheme_exports, {
|
|
25
|
-
useTheme: () => useTheme,
|
|
26
|
-
useThemeSetting: () => useThemeSetting
|
|
27
|
-
});
|
|
22
|
+
__export(useTheme_exports, { useThemeSetting: () => useThemeSetting });
|
|
28
23
|
module.exports = __toCommonJS(useTheme_exports);
|
|
29
24
|
var import_react = require("react");
|
|
30
25
|
var import_ThemeSettingContext = require("./ThemeSettingContext.cjs");
|
|
31
|
-
const
|
|
32
|
-
const useThemeSetting = () => (0, import_react.useContext)(import_ThemeSettingContext.ThemeSettingContext);
|
|
26
|
+
const useThemeSetting = () => (0, import_react.useContext)(import_ThemeSettingContext.ThemeSettingContext);
|
package/dist/esm/NextTheme.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
export * from "./NextThemeProvider.mjs"
|
|
2
|
-
|
|
3
|
-
export * from "./
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
6
|
-
|
|
7
|
-
export * from "./
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
186
|
-
|
|
175
|
+
if (prevProps.forcedTheme !== nextProps.forcedTheme) return false;
|
|
176
|
+
return true;
|
|
187
177
|
});
|
|
178
|
+
|
|
188
179
|
export { NextThemeProvider };
|
|
189
180
|
//# sourceMappingURL=NextThemeProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useIsomorphicLayoutEffect","useEvent","Script","React","memo","useEffect","useMemo","useState","MEDIA","colorSchemes","getSystemTheme","getTheme","ThemeSettingContext","jsx","jsxs","NextThemeProvider","forcedTheme","disableTransitionOnChange","enableSystem","enableColorScheme","storageKey","themes","defaultTheme","attribute","skipNextHead","onChangeTheme","value","dark","light","children","theme","setThemeState","resolvedTheme","setResolvedTheme","attrs","Object","values","handleMediaQuery","e","_","update","startTransition","handleChangeTheme","updateStorage","updateDOM","name","theme2","localStorage","setItem","resolved","replace","d","document","documentElement","classList","remove","add","setAttribute","media","window","matchMedia","addListener","removeListener","set","newTheme","handleStorage","key","newValue","addEventListener","removeEventListener","colorScheme","includes","userPrefers","matches","wePrefer","style","setProperty","toggle","order","next","indexOf","length","systemTheme","contextValue","current","Provider","ThemeScript","optimization","removeClasses","map","t","join","literal","val","defaultSystem","scriptContent","JSON","stringify","dangerouslySetInnerHTML","__html","id","strategy","prevProps","nextProps"],"sources":["../../src/NextThemeProvider.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,yBAAA,QAAiC;AAC1C,SAASC,QAAA,QAAgB;AACzB,OAAOC,MAAA,MAAY;AACnB,YAAYC,KAAA,MAAW;AACvB,SAASC,IAAA,EAAMC,SAAA,EAAWC,OAAA,EAASC,QAAA,QAAgB;AAEnD,SAASC,KAAA,EAAOC,YAAA,QAAoB;AACpC,SAASC,cAAA,EAAgBC,QAAA,QAAgB;AACzC,SAASC,mBAAA,QAA2B;AAiL9B,SACEC,GAAA,EADFC,IAAA;AA7KC,MAAMC,iBAAA,GAAiEX,IAAA,CAC5E,CAAC;EACCY,WAAA;EACAC,yBAAA,GAA4B;EAC5BC,YAAA,GAAe;EACfC,iBAAA,GAAoB;EACpBC,UAAA,GAAa;EACbC,MAAA,GAASZ,YAAA;EACTa,YAAA,GAAeJ,YAAA,GAAe,WAAW;EACzCK,SAAA,GAAY;EACZC,YAAA;EACAC,aAAA;EACAC,KAAA,GAAQ;IACNC,IAAA,EAAM;IACNC,KAAA,EAAO;EACT;EACAC;AACF,MAAM;EACJ,MAAM,CAACC,KAAA,EAAOC,aAAa,IAAIxB,QAAA,CAAS,MAAMI,QAAA,CAASS,UAAA,EAAYE,YAAY,CAAC;EAChF,MAAM,CAACU,aAAA,EAAeC,gBAAgB,IAAI1B,QAAA,CAAS,MAAMI,QAAA,CAASS,UAAU,CAAC;EAC7E,MAAMc,KAAA,GAAQ,CAACR,KAAA,GAAQL,MAAA,GAASc,MAAA,CAAOC,MAAA,CA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IACtC,CAACoE,aAAA,GAAgB,QAAQlD,SAAA,CAAUtB,YAAY,CAAC,MAAM,EACxD,mBACA,mBAAmBiE,YAAY,+BAA+BnE,UAAU,YACtEM,KAAA,GAAQ,SAASsE,IAAA,CAAKC,SAAA,CAAUvE,KAAK,CAAC,MAAM,EAC9C,GAAGkB,SAAA,CAAUlB,KAAA,GAAQ,SAAS,KAAK,IAAI,CAAC,SAASkB,SAAA,CAC/CtB,YACF,CAAC;EAGP,IAAIE,YAAA,EAAc;IAChB,OACE,eAAAX,GAAA,CAAC;MAECqF,uBAAA,EAAyB;QAAEC,MAAA,EAAQJ;MAAc;IAAA,GAD7C,oBAEN;EAEJ;EAEA,OACE,eAAAlF,GAAA,CAACX,MAAA;IACCkG,EAAA,EAAG;IACHC,QAAA,EAAS;IACTH,uBAAA,EAAyB;MAAEC,MAAA,EAAQJ;IAAc;EAAA,CACnD;AAEJ,GACA,CAACO,SAAA,EAAWC,SAAA,KAAc;EAGxB,IAAID,SAAA,CAAUtF,WAAA,KAAgBuF,SAAA,CAAUvF,WAAA,EAAa,OAAO;EAC5D,OAAO;AACT,CACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"NextThemeProvider.js","names":[],"sources":["esm/NextThemeProvider.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { useEvent } from \"@tamagui/use-event\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { memo, useEffect, useMemo, useState } from \"react\";\nimport { MEDIA, colorSchemes } from \"./constants\";\nimport { getSystemTheme, getTheme } from \"./helpers\";\nimport { ThemeSettingContext } from \"./ThemeSettingContext\";\nimport { jsx, jsxs } from \"react/jsx-runtime\";\nconst NextThemeProvider = memo(\n ({\n forcedTheme,\n disableTransitionOnChange = false,\n enableSystem = true,\n enableColorScheme = true,\n storageKey = \"theme\",\n themes = colorSchemes,\n defaultTheme = enableSystem ? \"system\" : \"light\",\n attribute = \"class\",\n skipNextHead,\n onChangeTheme,\n value = {\n dark: \"t_dark\",\n light: \"t_light\"\n },\n children\n }) => {\n const [theme, setThemeState] = useState(() => getTheme(storageKey, defaultTheme));\n const [resolvedTheme, setResolvedTheme] = useState(() => getTheme(storageKey));\n const attrs = !value ? themes : Object.values(value);\n const handleMediaQuery = useEvent((e) => {\n const _ = getSystemTheme(e);\n const update = () => setResolvedTheme(_);\n if (disableTransitionOnChange) {\n update();\n } else {\n React.startTransition(() => update());\n }\n if (theme === \"system\" && !forcedTheme) {\n handleChangeTheme(_, false);\n }\n });\n const handleChangeTheme = useEvent(\n (theme2, updateStorage = true, updateDOM = true) => {\n let name = value?.[theme2] || theme2;\n if (updateStorage) {\n try {\n localStorage.setItem(storageKey, theme2);\n } catch (e) {\n }\n }\n if (theme2 === \"system\" && enableSystem) {\n const resolved = getSystemTheme();\n name = value?.[resolved] || resolved;\n }\n onChangeTheme?.(name.replace(\"t_\", \"\"));\n if (updateDOM) {\n const d = document.documentElement;\n if (attribute === \"class\") {\n d.classList.remove(...attrs);\n d.classList.add(name);\n } else {\n d.setAttribute(attribute, name);\n }\n }\n }\n );\n useIsomorphicLayoutEffect(() => {\n const media = window.matchMedia(MEDIA);\n media.addListener(handleMediaQuery);\n handleMediaQuery(media);\n return () => {\n media.removeListener(handleMediaQuery);\n };\n }, []);\n const set = useEvent((newTheme) => {\n if (forcedTheme) {\n return;\n }\n handleChangeTheme(newTheme);\n setThemeState(newTheme);\n });\n useEffect(() => {\n const handleStorage = (e) => {\n if (e.key !== storageKey) {\n return;\n }\n const theme2 = e.newValue || defaultTheme;\n set(theme2);\n };\n window.addEventListener(\"storage\", handleStorage);\n return () => {\n window.removeEventListener(\"storage\", handleStorage);\n };\n }, [defaultTheme, set, storageKey]);\n useIsomorphicLayoutEffect(() => {\n if (!enableColorScheme) return;\n const colorScheme = (\n // If theme is forced to light or dark, use that\n forcedTheme && colorSchemes.includes(forcedTheme) ? forcedTheme : (\n // If regular theme is light or dark\n theme && colorSchemes.includes(theme) ? theme : (\n // If theme is system, use the resolved version\n theme === \"system\" ? resolvedTheme || null : null\n )\n )\n );\n const userPrefers = typeof window !== \"undefined\" && window.matchMedia && window.matchMedia(\"(prefers-color-scheme: dark)\").matches ? \"dark\" : \"light\";\n const wePrefer = colorScheme || \"light\";\n if (userPrefers !== wePrefer) {\n document.documentElement.style.setProperty(\"color-scheme\", colorScheme);\n }\n }, [enableColorScheme, theme, resolvedTheme, forcedTheme]);\n const toggle = useEvent(() => {\n const order = resolvedTheme === \"dark\" ? [\"system\", \"light\", \"dark\"] : [\"system\", \"dark\", \"light\"];\n const next = order[(order.indexOf(theme) + 1) % order.length];\n set(next);\n });\n const systemTheme = enableSystem ? resolvedTheme : void 0;\n const contextValue = useMemo(() => {\n const value2 = {\n current: theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme: theme === \"system\" ? resolvedTheme : theme,\n themes: enableSystem ? [...themes, \"system\"] : themes,\n systemTheme\n };\n return value2;\n }, [\n theme,\n set,\n toggle,\n forcedTheme,\n resolvedTheme,\n enableSystem,\n themes,\n systemTheme\n ]);\n return /* @__PURE__ */ jsxs(ThemeSettingContext.Provider, { value: contextValue, children: [\n /* @__PURE__ */ jsx(\n ThemeScript,\n {\n ...{\n forcedTheme,\n storageKey,\n systemTheme: resolvedTheme,\n attribute,\n value,\n enableSystem,\n defaultTheme,\n attrs,\n skipNextHead\n }\n }\n ),\n children\n ] });\n }\n);\nconst ThemeScript = memo(\n ({\n forcedTheme,\n storageKey,\n attribute,\n enableSystem,\n defaultTheme,\n value,\n attrs,\n skipNextHead\n }) => {\n const optimization = (() => {\n if (attribute === \"class\") {\n const removeClasses = attrs.map((t) => `d.remove('${t}')`).join(\";\");\n return `var d=document.documentElement.classList;${removeClasses};`;\n }\n return `var d=document.documentElement;`;\n })();\n const updateDOM = (name, literal) => {\n name = value?.[name] || name;\n const val = literal ? name : `'${name}'`;\n if (attribute === \"class\") {\n return `d.add(${val})`;\n }\n return `d.setAttribute('${attribute}', ${val})`;\n };\n const defaultSystem = defaultTheme === \"system\";\n 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(\n \"dark\"\n )}:${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(\n defaultTheme\n )};}}catch(t){}}();`;\n if (skipNextHead) {\n return /* @__PURE__ */ jsx(\n \"script\",\n {\n dangerouslySetInnerHTML: { __html: scriptContent }\n },\n \"next-themes-script\"\n );\n }\n return /* @__PURE__ */ jsx(\n Script,\n {\n id: \"next-themes-script\",\n strategy: \"beforeInteractive\",\n dangerouslySetInnerHTML: { __html: scriptContent }\n }\n );\n },\n (prevProps, nextProps) => {\n if (prevProps.forcedTheme !== nextProps.forcedTheme) return false;\n return true;\n }\n);\nexport {\n NextThemeProvider\n};\n//# sourceMappingURL=NextThemeProvider.js.map\n"],"mappings":";;;;;;;;;;;AASA,MAAM,oBAAoB,MACvB,EACC,aACA,4BAA4B,OAC5B,eAAe,MACf,oBAAoB,MACpB,aAAa,SACb,SAAS,cACT,eAAe,eAAe,WAAW,SACzC,YAAY,SACZ,cACA,eACA,QAAQ;CACN,MAAM;CACN,OAAO;AACT,GACA,eACI;CACJ,MAAM,CAAC,OAAO,iBAAiB,eAAe,SAAS,YAAY,YAAY,CAAC;CAChF,MAAM,CAAC,eAAe,oBAAoB,eAAe,SAAS,UAAU,CAAC;CAC7E,MAAM,QAAQ,CAAC,QAAQ,SAAS,OAAO,OAAO,K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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
toggle: () => {},
|
|
5
|
+
set: (_) => {},
|
|
6
|
+
themes: []
|
|
6
7
|
});
|
|
8
|
+
|
|
7
9
|
export { ThemeSettingContext };
|
|
8
10
|
//# sourceMappingURL=ThemeSettingContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ThemeSettingContext.js","names":[],"sources":["esm/ThemeSettingContext.js"],"sourcesContent":["import { createContext } from \"react\";\nconst ThemeSettingContext = createContext({\n toggle: () => {\n },\n set: (_) => {\n },\n themes: []\n});\nexport {\n ThemeSettingContext\n};\n//# sourceMappingURL=ThemeSettingContext.js.map\n"],"mappings":";;;AACA,MAAM,sBAAsB,cAAc;CACxC,cAAc,CACd;CACA,MAAM,MAAM,CACZ;CACA,QAAQ,CAAC;AACX,CAAC"}
|
package/dist/esm/constants.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["esm/constants.js"],"sourcesContent":["const constants = {};\nconst colorSchemes = [\"light\", \"dark\"];\nconst MEDIA = \"(prefers-color-scheme: dark)\";\nexport {\n MEDIA,\n colorSchemes,\n constants\n};\n//# sourceMappingURL=constants.js.map\n"],"mappings":";AAAA,MAAM,YAAY,CAAC;AACnB,MAAM,eAAe,CAAC,SAAS,MAAM;AACrC,MAAM,QAAQ"}
|