@tamagui/next-theme 1.61.2 → 1.62.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.
- package/dist/cjs/NextTheme.js +4 -8
- package/dist/cjs/NextTheme.js.map +1 -1
- package/dist/cjs/NextTheme.native.js +34 -0
- package/dist/cjs/NextTheme.native.js.map +6 -0
- package/dist/cjs/NextThemeProvider.js +59 -134
- package/dist/cjs/NextThemeProvider.js.map +2 -2
- package/dist/cjs/NextThemeProvider.native.js +196 -0
- package/dist/cjs/NextThemeProvider.native.js.map +6 -0
- package/dist/cjs/ThemeSettingContext.js +5 -9
- package/dist/cjs/ThemeSettingContext.js.map +1 -1
- package/dist/cjs/ThemeSettingContext.native.js +33 -0
- package/dist/cjs/ThemeSettingContext.native.js.map +6 -0
- package/dist/cjs/UseThemeProps.js +3 -6
- package/dist/cjs/UseThemeProps.js.map +1 -1
- package/dist/cjs/UseThemeProps.native.js +15 -0
- package/dist/cjs/UseThemeProps.native.js.map +6 -0
- package/dist/cjs/constants.js +6 -12
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/constants.native.js +30 -0
- package/dist/cjs/constants.native.js.map +6 -0
- package/dist/cjs/helpers.js +10 -23
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/helpers.native.js +40 -0
- package/dist/cjs/helpers.native.js.map +6 -0
- package/dist/cjs/index.js +4 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +22 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/cjs/types.js +3 -6
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/types.native.js +15 -0
- package/dist/cjs/types.native.js.map +6 -0
- package/dist/cjs/useIsomorphicLayoutEffect.js +6 -10
- package/dist/cjs/useIsomorphicLayoutEffect.js.map +1 -1
- package/dist/cjs/useIsomorphicLayoutEffect.native.js +27 -0
- package/dist/cjs/useIsomorphicLayoutEffect.native.js.map +6 -0
- package/dist/cjs/useRootTheme.js +9 -16
- package/dist/cjs/useRootTheme.js.map +1 -1
- package/dist/cjs/useRootTheme.native.js +35 -0
- package/dist/cjs/useRootTheme.native.js.map +6 -0
- package/dist/cjs/useTheme.js +7 -13
- package/dist/cjs/useTheme.js.map +1 -1
- package/dist/cjs/useTheme.native.js +29 -0
- package/dist/cjs/useTheme.native.js.map +6 -0
- package/dist/esm/NextThemeProvider.js +52 -113
- package/dist/esm/NextThemeProvider.js.map +2 -2
- package/dist/esm/constants.js +1 -3
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/helpers.js +5 -14
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/useIsomorphicLayoutEffect.js.map +1 -1
- package/dist/esm/useRootTheme.js +3 -5
- package/dist/esm/useRootTheme.js.map +1 -1
- package/dist/esm/useTheme.js +1 -2
- package/dist/esm/useTheme.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/NextTheme.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
5
|
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
7
|
for (let key of __getOwnPropNames(from))
|
|
9
|
-
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
8
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
9
|
return to;
|
|
13
|
-
};
|
|
14
|
-
var
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
10
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
12
|
var NextTheme_exports = {};
|
|
17
13
|
module.exports = __toCommonJS(NextTheme_exports);
|
|
18
14
|
__reExport(NextTheme_exports, require("./NextThemeProvider"), module.exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/NextTheme.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": ";;;;;;;;;;;AAAA;AAAA;AAGA,8BAAc,gCAHd;AAIA,8BAAc,kCAJd;AAKA,8BAAc,4BALd;AAMA,8BAAc,sBANd;AAOA,8BAAc,wBAPd;AAQA,8BAAc,uBARd;AASA,8BAAc,oBATd;AAUA,8BAAc,2BAVd;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
return to;
|
|
11
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
12
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
13
|
+
var NextTheme_exports = {};
|
|
14
|
+
module.exports = __toCommonJS(NextTheme_exports);
|
|
15
|
+
__reExport(NextTheme_exports, require("./NextThemeProvider"), module.exports);
|
|
16
|
+
__reExport(NextTheme_exports, require("./ThemeSettingContext"), module.exports);
|
|
17
|
+
__reExport(NextTheme_exports, require("./UseThemeProps"), module.exports);
|
|
18
|
+
__reExport(NextTheme_exports, require("./helpers"), module.exports);
|
|
19
|
+
__reExport(NextTheme_exports, require("./constants"), module.exports);
|
|
20
|
+
__reExport(NextTheme_exports, require("./useTheme"), module.exports);
|
|
21
|
+
__reExport(NextTheme_exports, require("./types"), module.exports);
|
|
22
|
+
__reExport(NextTheme_exports, require("./useRootTheme"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./NextThemeProvider"),
|
|
26
|
+
...require("./ThemeSettingContext"),
|
|
27
|
+
...require("./UseThemeProps"),
|
|
28
|
+
...require("./helpers"),
|
|
29
|
+
...require("./constants"),
|
|
30
|
+
...require("./useTheme"),
|
|
31
|
+
...require("./types"),
|
|
32
|
+
...require("./useRootTheme")
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=NextTheme.js.map
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,30 +17,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
var NextThemeProvider_exports = {};
|
|
30
24
|
__export(NextThemeProvider_exports, {
|
|
31
25
|
NextThemeProvider: () => NextThemeProvider
|
|
32
26
|
});
|
|
33
27
|
module.exports = __toCommonJS(NextThemeProvider_exports);
|
|
34
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
-
var import_use_event = require("@tamagui/use-event");
|
|
36
|
-
var import_head = __toESM(require("next/head"));
|
|
37
|
-
var React = __toESM(require("react"));
|
|
38
|
-
var import_react = require("react");
|
|
39
|
-
var import_constants = require("./constants");
|
|
40
|
-
var import_helpers = require("./helpers");
|
|
41
|
-
var import_ThemeSettingContext = require("./ThemeSettingContext");
|
|
42
|
-
var import_useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
|
28
|
+
var import_use_event = require("@tamagui/use-event"), import_head = __toESM(require("next/head")), React = __toESM(require("react")), import_react = require("react"), import_constants = require("./constants"), import_helpers = require("./helpers"), import_ThemeSettingContext = require("./ThemeSettingContext"), import_useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect"), import_jsx_runtime = require("react/jsx-runtime");
|
|
43
29
|
const NextThemeProvider = (0, import_react.memo)(
|
|
44
30
|
({
|
|
45
31
|
forcedTheme,
|
|
46
|
-
disableTransitionOnChange =
|
|
47
|
-
enableSystem =
|
|
48
|
-
enableColorScheme =
|
|
32
|
+
disableTransitionOnChange = !1,
|
|
33
|
+
enableSystem = !0,
|
|
34
|
+
enableColorScheme = !0,
|
|
49
35
|
storageKey = "theme",
|
|
50
36
|
themes = import_constants.colorSchemes,
|
|
51
37
|
defaultTheme = enableSystem ? "system" : "light",
|
|
@@ -58,76 +44,47 @@ const NextThemeProvider = (0, import_react.memo)(
|
|
|
58
44
|
},
|
|
59
45
|
children
|
|
60
46
|
}) => {
|
|
61
|
-
const [theme, setThemeState] = (0, import_react.useState)(() => (0, import_helpers.getTheme)(storageKey, defaultTheme))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
update();
|
|
69
|
-
} else {
|
|
70
|
-
React.startTransition(() => update());
|
|
71
|
-
}
|
|
72
|
-
if (theme === "system" && !forcedTheme) {
|
|
73
|
-
handleChangeTheme(_, false);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const handleChangeTheme = (0, import_use_event.useEvent)(
|
|
77
|
-
(theme2, updateStorage = true, updateDOM = true) => {
|
|
78
|
-
let name = (value == null ? void 0 : value[theme2]) || theme2;
|
|
79
|
-
if (updateStorage) {
|
|
47
|
+
const [theme, setThemeState] = (0, import_react.useState)(() => (0, import_helpers.getTheme)(storageKey, defaultTheme)), [resolvedTheme, setResolvedTheme] = (0, import_react.useState)(() => (0, import_helpers.getTheme)(storageKey)), attrs = value ? Object.values(value) : themes, handleMediaQuery = (0, import_use_event.useEvent)((e) => {
|
|
48
|
+
const _ = (0, import_helpers.getSystemTheme)(e), update = () => setResolvedTheme(_);
|
|
49
|
+
disableTransitionOnChange ? update() : React.startTransition(() => update()), theme === "system" && !forcedTheme && handleChangeTheme(_, !1);
|
|
50
|
+
}), handleChangeTheme = (0, import_use_event.useEvent)(
|
|
51
|
+
(theme2, updateStorage = !0, updateDOM = !0) => {
|
|
52
|
+
let name = value?.[theme2] || theme2;
|
|
53
|
+
if (updateStorage)
|
|
80
54
|
try {
|
|
81
55
|
localStorage.setItem(storageKey, theme2);
|
|
82
|
-
} catch
|
|
56
|
+
} catch {
|
|
83
57
|
}
|
|
84
|
-
}
|
|
85
58
|
if (theme2 === "system" && enableSystem) {
|
|
86
59
|
const resolved = (0, import_helpers.getSystemTheme)();
|
|
87
|
-
name =
|
|
60
|
+
name = value?.[resolved] || resolved;
|
|
88
61
|
}
|
|
89
|
-
|
|
90
|
-
if (updateDOM) {
|
|
62
|
+
if (onChangeTheme?.(name.replace("t_", "")), updateDOM) {
|
|
91
63
|
const d = document.documentElement;
|
|
92
|
-
|
|
93
|
-
d.classList.remove(...attrs);
|
|
94
|
-
d.classList.add(name);
|
|
95
|
-
} else {
|
|
96
|
-
d.setAttribute(attribute, name);
|
|
97
|
-
}
|
|
64
|
+
attribute === "class" ? (d.classList.remove(...attrs), d.classList.add(name)) : d.setAttribute(attribute, name);
|
|
98
65
|
}
|
|
99
66
|
}
|
|
100
67
|
);
|
|
101
68
|
(0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
|
|
102
69
|
const media = window.matchMedia(import_constants.MEDIA);
|
|
103
|
-
media.addListener(handleMediaQuery)
|
|
104
|
-
handleMediaQuery(media);
|
|
105
|
-
return () => {
|
|
70
|
+
return media.addListener(handleMediaQuery), handleMediaQuery(media), () => {
|
|
106
71
|
media.removeListener(handleMediaQuery);
|
|
107
72
|
};
|
|
108
73
|
}, []);
|
|
109
74
|
const set = (0, import_use_event.useEvent)((newTheme) => {
|
|
110
|
-
|
|
111
|
-
handleChangeTheme(newTheme, true, false);
|
|
112
|
-
} else {
|
|
113
|
-
handleChangeTheme(newTheme);
|
|
114
|
-
}
|
|
115
|
-
setThemeState(newTheme);
|
|
75
|
+
forcedTheme ? handleChangeTheme(newTheme, !0, !1) : handleChangeTheme(newTheme), setThemeState(newTheme);
|
|
116
76
|
});
|
|
117
77
|
(0, import_react.useEffect)(() => {
|
|
118
78
|
const handleStorage = (e) => {
|
|
119
|
-
if (e.key !== storageKey)
|
|
79
|
+
if (e.key !== storageKey)
|
|
120
80
|
return;
|
|
121
|
-
}
|
|
122
81
|
const theme2 = e.newValue || defaultTheme;
|
|
123
82
|
set(theme2);
|
|
124
83
|
};
|
|
125
|
-
window.addEventListener("storage", handleStorage)
|
|
126
|
-
return () => {
|
|
84
|
+
return window.addEventListener("storage", handleStorage), () => {
|
|
127
85
|
window.removeEventListener("storage", handleStorage);
|
|
128
86
|
};
|
|
129
|
-
}, [defaultTheme, set, storageKey])
|
|
130
|
-
(0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
|
|
87
|
+
}, [defaultTheme, set, storageKey]), (0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
|
|
131
88
|
if (!enableColorScheme)
|
|
132
89
|
return;
|
|
133
90
|
const colorScheme = (
|
|
@@ -136,35 +93,25 @@ const NextThemeProvider = (0, import_react.memo)(
|
|
|
136
93
|
// If regular theme is light or dark
|
|
137
94
|
theme && import_constants.colorSchemes.includes(theme) ? theme : (
|
|
138
95
|
// If theme is system, use the resolved version
|
|
139
|
-
theme === "system"
|
|
96
|
+
theme === "system" && resolvedTheme || null
|
|
140
97
|
)
|
|
141
98
|
)
|
|
142
99
|
);
|
|
143
|
-
|
|
144
|
-
const wePrefer = colorScheme || "light";
|
|
145
|
-
if (userPrefers !== wePrefer) {
|
|
146
|
-
document.documentElement.style.setProperty("color-scheme", colorScheme);
|
|
147
|
-
}
|
|
100
|
+
(typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") !== (colorScheme || "light") && document.documentElement.style.setProperty("color-scheme", colorScheme);
|
|
148
101
|
}, [enableColorScheme, theme, resolvedTheme, forcedTheme]);
|
|
149
102
|
const toggle = (0, import_use_event.useEvent)(() => {
|
|
150
|
-
const order = resolvedTheme === "dark" ? ["system", "light", "dark"] : ["system", "dark", "light"];
|
|
151
|
-
const next = order[(order.indexOf(theme) + 1) % order.length];
|
|
103
|
+
const order = resolvedTheme === "dark" ? ["system", "light", "dark"] : ["system", "dark", "light"], next = order[(order.indexOf(theme) + 1) % order.length];
|
|
152
104
|
set(next);
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
themes: enableSystem ? [...themes, "system"] : themes,
|
|
164
|
-
systemTheme
|
|
165
|
-
};
|
|
166
|
-
return value2;
|
|
167
|
-
}, [
|
|
105
|
+
}), systemTheme = enableSystem ? resolvedTheme : void 0, contextValue = (0, import_react.useMemo)(() => ({
|
|
106
|
+
theme,
|
|
107
|
+
current: theme,
|
|
108
|
+
set,
|
|
109
|
+
toggle,
|
|
110
|
+
forcedTheme,
|
|
111
|
+
resolvedTheme: theme === "system" ? resolvedTheme : theme,
|
|
112
|
+
themes: enableSystem ? [...themes, "system"] : themes,
|
|
113
|
+
systemTheme
|
|
114
|
+
}), [
|
|
168
115
|
theme,
|
|
169
116
|
set,
|
|
170
117
|
toggle,
|
|
@@ -178,24 +125,21 @@ const NextThemeProvider = (0, import_react.memo)(
|
|
|
178
125
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
179
126
|
ThemeScript,
|
|
180
127
|
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
skipNextHead
|
|
191
|
-
}
|
|
128
|
+
forcedTheme,
|
|
129
|
+
storageKey,
|
|
130
|
+
systemTheme: resolvedTheme,
|
|
131
|
+
attribute,
|
|
132
|
+
value,
|
|
133
|
+
enableSystem,
|
|
134
|
+
defaultTheme,
|
|
135
|
+
attrs,
|
|
136
|
+
skipNextHead
|
|
192
137
|
}
|
|
193
138
|
),
|
|
194
139
|
(0, import_react.useMemo)(() => children, [children])
|
|
195
140
|
] });
|
|
196
141
|
}
|
|
197
|
-
)
|
|
198
|
-
const ThemeScript = (0, import_react.memo)(
|
|
142
|
+
), ThemeScript = (0, import_react.memo)(
|
|
199
143
|
({
|
|
200
144
|
forcedTheme,
|
|
201
145
|
storageKey,
|
|
@@ -206,24 +150,11 @@ const ThemeScript = (0, import_react.memo)(
|
|
|
206
150
|
attrs,
|
|
207
151
|
skipNextHead
|
|
208
152
|
}) => {
|
|
209
|
-
const optimization = (() => {
|
|
210
|
-
|
|
211
|
-
const removeClasses = attrs.map((t) => `d.remove('${t}')`).join(";");
|
|
212
|
-
return `var d=document.documentElement.classList;${removeClasses};`;
|
|
213
|
-
} else {
|
|
214
|
-
return `var d=document.documentElement;`;
|
|
215
|
-
}
|
|
216
|
-
})();
|
|
217
|
-
const updateDOM = (name, literal) => {
|
|
218
|
-
name = (value == null ? void 0 : value[name]) || name;
|
|
153
|
+
const optimization = (() => attribute === "class" ? `var d=document.documentElement.classList;${attrs.map((t) => `d.remove('${t}')`).join(";")};` : "var d=document.documentElement;")(), updateDOM = (name, literal) => {
|
|
154
|
+
name = value?.[name] || name;
|
|
219
155
|
const val = literal ? name : `'${name}'`;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
return `d.setAttribute('${attribute}', ${val})`;
|
|
224
|
-
};
|
|
225
|
-
const defaultSystem = defaultTheme === "system";
|
|
226
|
-
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: forcedTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
156
|
+
return attribute === "class" ? `d.add(${val})` : `d.setAttribute('${attribute}', ${val})`;
|
|
157
|
+
}, defaultSystem = defaultTheme === "system", contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: forcedTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
227
158
|
"script",
|
|
228
159
|
{
|
|
229
160
|
dangerouslySetInnerHTML: {
|
|
@@ -236,9 +167,9 @@ const ThemeScript = (0, import_react.memo)(
|
|
|
236
167
|
"script",
|
|
237
168
|
{
|
|
238
169
|
dangerouslySetInnerHTML: {
|
|
239
|
-
__html: `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');${
|
|
170
|
+
__html: `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');${defaultSystem ? "" : updateDOM(defaultTheme) + ";"}if("system"===e||(!e&&${defaultSystem})){var t="${import_constants.MEDIA}",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM(
|
|
240
171
|
"dark"
|
|
241
|
-
)}:${updateDOM("light")}}else if(e) ${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e",
|
|
172
|
+
)}:${updateDOM("light")}}else if(e) ${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", !0)}}catch(e){}}()`
|
|
242
173
|
}
|
|
243
174
|
},
|
|
244
175
|
"next-themes-script"
|
|
@@ -246,22 +177,16 @@ const ThemeScript = (0, import_react.memo)(
|
|
|
246
177
|
"script",
|
|
247
178
|
{
|
|
248
179
|
dangerouslySetInnerHTML: {
|
|
249
|
-
__html: `!function(){try{${optimization}var e=localStorage.getItem("${storageKey}");if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e",
|
|
180
|
+
__html: `!function(){try{${optimization}var e=localStorage.getItem("${storageKey}");if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", !0)}}else{${updateDOM(
|
|
250
181
|
defaultTheme
|
|
251
182
|
)};}}catch(t){}}();`
|
|
252
183
|
}
|
|
253
184
|
},
|
|
254
185
|
"next-themes-script"
|
|
255
186
|
) });
|
|
256
|
-
|
|
257
|
-
return contents;
|
|
258
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_head.default, { children: contents });
|
|
187
|
+
return skipNextHead ? contents : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_head.default, { children: contents });
|
|
259
188
|
},
|
|
260
|
-
(prevProps, nextProps) =>
|
|
261
|
-
if (prevProps.forcedTheme !== nextProps.forcedTheme)
|
|
262
|
-
return false;
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
189
|
+
(prevProps, nextProps) => prevProps.forcedTheme === nextProps.forcedTheme
|
|
265
190
|
);
|
|
266
191
|
// Annotate the CommonJS export names for ESM import in node:
|
|
267
192
|
0 && (module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/NextThemeProvider.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["theme", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB,+BACzB,cAAqB,+BACrB,QAAuB,2BACvB,eAA2D,kBAE3D,mBAAoC,wBACpC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BAAyB;AAAA;AAAA,UAEvB,QAAQ,eAAe,YAAY,GAAG,UAAU,WAAW,CAAC;AAAA,QAC9D;AAAA;AAAA,MAJI;AAAA,IAKN,IACE,eACF;AAAA,MAAC;AAAA;AAAA,QAGC,yBAAyB;AAAA,UACvB,QAAQ,oBAAoB,YAAY,+BAA+B,UAAU,MAC9E,gBAAgD,KAAhC,UAAU,YAAY,IAAI,GAC7C,yBAAyB,aAAa,aAAa,sBAAK,mDAAmD;AAAA,YACzG;AAAA,UACF,CAAC,IAAI,UAAU,OAAO,CAAC,eACrB,QAAQ,SAAS,KAAK,UAAU,KAAK,CAAC,MAAM,EAC9C,GAAG,UAAU,QAAQ,SAAS,KAAK,EAAI,CAAC;AAAA,QAC1C;AAAA;AAAA,MATI;AAAA,IAUN,IAEA;AAAA,MAAC;AAAA;AAAA,QAGC,yBAAyB;AAAA,UACvB,QAAQ,mBAAmB,YAAY,+BAA+B,UAAU,YAC9E,QAAQ,SAAS,KAAK,UAAU,KAAK,CAAC,MAAM,EAC9C,GAAG,UAAU,QAAQ,SAAS,KAAK,EAAI,CAAC,SAAS;AAAA,YAC/C;AAAA,UACF,CAAC;AAAA,QACH;AAAA;AAAA,MAPI;AAAA,IAQN,GAEJ;AAGF,WAAI,eAAqB,WAElB,4CAAC,YAAAC,SAAA,EAAU,oBAAS;AAAA,EAC7B;AAAA,EACA,CAAC,WAAW,cAGN,UAAU,gBAAgB,UAAU;AAG5C;",
|
|
5
|
+
"names": ["theme", "NextHead"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
+
mod
|
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
+
var NextThemeProvider_exports = {};
|
|
25
|
+
__export(NextThemeProvider_exports, {
|
|
26
|
+
NextThemeProvider: () => NextThemeProvider
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(NextThemeProvider_exports);
|
|
29
|
+
var import_use_event = require("@tamagui/use-event"), import_head = __toESM(require("next/head")), React = __toESM(require("react")), import_react = require("react"), import_constants = require("./constants"), import_helpers = require("./helpers"), import_ThemeSettingContext = require("./ThemeSettingContext"), import_useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect"), import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
const NextThemeProvider = (0, import_react.memo)(
|
|
31
|
+
({
|
|
32
|
+
forcedTheme,
|
|
33
|
+
disableTransitionOnChange = !1,
|
|
34
|
+
enableSystem = !0,
|
|
35
|
+
enableColorScheme = !0,
|
|
36
|
+
storageKey = "theme",
|
|
37
|
+
themes = import_constants.colorSchemes,
|
|
38
|
+
defaultTheme = enableSystem ? "system" : "light",
|
|
39
|
+
attribute = "class",
|
|
40
|
+
skipNextHead,
|
|
41
|
+
onChangeTheme,
|
|
42
|
+
value = {
|
|
43
|
+
dark: "t_dark",
|
|
44
|
+
light: "t_light"
|
|
45
|
+
},
|
|
46
|
+
children
|
|
47
|
+
}) => {
|
|
48
|
+
const [theme, setThemeState] = (0, import_react.useState)(() => (0, import_helpers.getTheme)(storageKey, defaultTheme)), [resolvedTheme, setResolvedTheme] = (0, import_react.useState)(() => (0, import_helpers.getTheme)(storageKey)), attrs = value ? Object.values(value) : themes, handleMediaQuery = (0, import_use_event.useEvent)((e) => {
|
|
49
|
+
const _ = (0, import_helpers.getSystemTheme)(e), update = () => setResolvedTheme(_);
|
|
50
|
+
disableTransitionOnChange ? update() : React.startTransition(() => update()), theme === "system" && !forcedTheme && handleChangeTheme(_, !1);
|
|
51
|
+
}), handleChangeTheme = (0, import_use_event.useEvent)(
|
|
52
|
+
(theme2, updateStorage = !0, updateDOM = !0) => {
|
|
53
|
+
let name = value?.[theme2] || theme2;
|
|
54
|
+
if (updateStorage)
|
|
55
|
+
try {
|
|
56
|
+
localStorage.setItem(storageKey, theme2);
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
if (theme2 === "system" && enableSystem) {
|
|
60
|
+
const resolved = (0, import_helpers.getSystemTheme)();
|
|
61
|
+
name = value?.[resolved] || resolved;
|
|
62
|
+
}
|
|
63
|
+
if (onChangeTheme?.(name.replace("t_", "")), updateDOM) {
|
|
64
|
+
const d = document.documentElement;
|
|
65
|
+
attribute === "class" ? (d.classList.remove(...attrs), d.classList.add(name)) : d.setAttribute(attribute, name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
(0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
|
|
70
|
+
const media = window.matchMedia(import_constants.MEDIA);
|
|
71
|
+
return media.addListener(handleMediaQuery), handleMediaQuery(media), () => {
|
|
72
|
+
media.removeListener(handleMediaQuery);
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
const set = (0, import_use_event.useEvent)((newTheme) => {
|
|
76
|
+
forcedTheme ? handleChangeTheme(newTheme, !0, !1) : handleChangeTheme(newTheme), setThemeState(newTheme);
|
|
77
|
+
});
|
|
78
|
+
(0, import_react.useEffect)(() => {
|
|
79
|
+
const handleStorage = (e) => {
|
|
80
|
+
if (e.key !== storageKey)
|
|
81
|
+
return;
|
|
82
|
+
const theme2 = e.newValue || defaultTheme;
|
|
83
|
+
set(theme2);
|
|
84
|
+
};
|
|
85
|
+
return window.addEventListener("storage", handleStorage), () => {
|
|
86
|
+
window.removeEventListener("storage", handleStorage);
|
|
87
|
+
};
|
|
88
|
+
}, [defaultTheme, set, storageKey]), (0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
|
|
89
|
+
if (!enableColorScheme)
|
|
90
|
+
return;
|
|
91
|
+
const colorScheme = (
|
|
92
|
+
// If theme is forced to light or dark, use that
|
|
93
|
+
forcedTheme && import_constants.colorSchemes.includes(forcedTheme) ? forcedTheme : (
|
|
94
|
+
// If regular theme is light or dark
|
|
95
|
+
theme && import_constants.colorSchemes.includes(theme) ? theme : (
|
|
96
|
+
// If theme is system, use the resolved version
|
|
97
|
+
theme === "system" && resolvedTheme || null
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
(typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") !== (colorScheme || "light") && document.documentElement.style.setProperty("color-scheme", colorScheme);
|
|
102
|
+
}, [enableColorScheme, theme, resolvedTheme, forcedTheme]);
|
|
103
|
+
const toggle = (0, import_use_event.useEvent)(() => {
|
|
104
|
+
const order = resolvedTheme === "dark" ? ["system", "light", "dark"] : ["system", "dark", "light"], next = order[(order.indexOf(theme) + 1) % order.length];
|
|
105
|
+
set(next);
|
|
106
|
+
}), systemTheme = enableSystem ? resolvedTheme : void 0, contextValue = (0, import_react.useMemo)(() => ({
|
|
107
|
+
theme,
|
|
108
|
+
current: theme,
|
|
109
|
+
set,
|
|
110
|
+
toggle,
|
|
111
|
+
forcedTheme,
|
|
112
|
+
resolvedTheme: theme === "system" ? resolvedTheme : theme,
|
|
113
|
+
themes: enableSystem ? [...themes, "system"] : themes,
|
|
114
|
+
systemTheme
|
|
115
|
+
}), [
|
|
116
|
+
theme,
|
|
117
|
+
set,
|
|
118
|
+
toggle,
|
|
119
|
+
forcedTheme,
|
|
120
|
+
resolvedTheme,
|
|
121
|
+
enableSystem,
|
|
122
|
+
themes,
|
|
123
|
+
systemTheme
|
|
124
|
+
]);
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ThemeSettingContext.ThemeSettingContext.Provider, { value: contextValue, children: [
|
|
126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
127
|
+
ThemeScript,
|
|
128
|
+
{
|
|
129
|
+
forcedTheme,
|
|
130
|
+
storageKey,
|
|
131
|
+
systemTheme: resolvedTheme,
|
|
132
|
+
attribute,
|
|
133
|
+
value,
|
|
134
|
+
enableSystem,
|
|
135
|
+
defaultTheme,
|
|
136
|
+
attrs,
|
|
137
|
+
skipNextHead
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
(0, import_react.useMemo)(() => children, [children])
|
|
141
|
+
] });
|
|
142
|
+
}
|
|
143
|
+
), ThemeScript = (0, import_react.memo)(
|
|
144
|
+
({
|
|
145
|
+
forcedTheme,
|
|
146
|
+
storageKey,
|
|
147
|
+
attribute,
|
|
148
|
+
enableSystem,
|
|
149
|
+
defaultTheme,
|
|
150
|
+
value,
|
|
151
|
+
attrs,
|
|
152
|
+
skipNextHead
|
|
153
|
+
}) => {
|
|
154
|
+
const optimization = (() => attribute === "class" ? `var d=document.documentElement.classList;${attrs.map((t) => `d.remove('${t}')`).join(";")};` : "var d=document.documentElement;")(), updateDOM = (name, literal) => {
|
|
155
|
+
name = value?.[name] || name;
|
|
156
|
+
const val = literal ? name : `'${name}'`;
|
|
157
|
+
return attribute === "class" ? `d.add(${val})` : `d.setAttribute('${attribute}', ${val})`;
|
|
158
|
+
}, defaultSystem = defaultTheme === "system", contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: forcedTheme ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
|
+
"script",
|
|
160
|
+
{
|
|
161
|
+
dangerouslySetInnerHTML: {
|
|
162
|
+
// These are minified via Terser and then updated by hand, don't recommend
|
|
163
|
+
__html: `!function(){${optimization}${updateDOM(forcedTheme)}}()`
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"next-themes-script"
|
|
167
|
+
) : enableSystem ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
168
|
+
"script",
|
|
169
|
+
{
|
|
170
|
+
dangerouslySetInnerHTML: {
|
|
171
|
+
__html: `!function(){try {${optimization}var e=localStorage.getItem('${storageKey}');${defaultSystem ? "" : updateDOM(defaultTheme) + ";"}if("system"===e||(!e&&${defaultSystem})){var t="${import_constants.MEDIA}",m=window.matchMedia(t);m.media!==t||m.matches?${updateDOM(
|
|
172
|
+
"dark"
|
|
173
|
+
)}:${updateDOM("light")}}else if(e) ${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", !0)}}catch(e){}}()`
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
"next-themes-script"
|
|
177
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
|
+
"script",
|
|
179
|
+
{
|
|
180
|
+
dangerouslySetInnerHTML: {
|
|
181
|
+
__html: `!function(){try{${optimization}var e=localStorage.getItem("${storageKey}");if(e){${value ? `var x=${JSON.stringify(value)};` : ""}${updateDOM(value ? "x[e]" : "e", !0)}}else{${updateDOM(
|
|
182
|
+
defaultTheme
|
|
183
|
+
)};}}catch(t){}}();`
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"next-themes-script"
|
|
187
|
+
) });
|
|
188
|
+
return skipNextHead ? contents : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_head.default, { children: contents });
|
|
189
|
+
},
|
|
190
|
+
(prevProps, nextProps) => prevProps.forcedTheme === nextProps.forcedTheme
|
|
191
|
+
);
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
NextThemeProvider
|
|
195
|
+
});
|
|
196
|
+
//# sourceMappingURL=NextThemeProvider.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/NextThemeProvider.tsx"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB,+BACzB,cAAqB,+BACrB,QAAuB,2BACvB,eAA2D,kBAE3D,mBAAoC,wBACpC,iBAAyC,sBACzC,6BAAoC,kCAEpC,mCAA0C,wCAgLpC;AA7KC,MAAM,wBAAoB;AAAA,EAC/B,CAAC;AAAA,IACC;AAAA,IACA,4BAA4B;AAAA,IAC5B,eAAe;AAAA,IACf,oBAAoB;AAAA,IACpB,aAAa;AAAA,IACb,SAAS;AAAA,IACT,eAAe,eAAe,WAAW;AAAA,IACzC,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,OAAO;AAAA,IACT;AAAA,IACA;AAAA,EACF,MAA0B;AACxB,UAAM,CAAC,OAAO,aAAa,QAAI,uBAAS,UAAM,yBAAS,YAAY,YAAY,CAAC,GAC1E,CAAC,eAAe,gBAAgB,QAAI,uBAAS,UAAM,yBAAS,UAAU,CAAC,GACvE,QAAS,QAAiB,OAAO,OAAO,KAAK,IAA5B,Q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