@vxrn/color-scheme 1.14.4 → 1.14.5
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/index.cjs +52 -38
- package/dist/cjs/index.native.js +67 -38
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/systemScheme.cjs +20 -16
- package/dist/cjs/systemScheme.native.js +33 -29
- package/dist/cjs/systemScheme.native.js.map +1 -1
- package/dist/cjs/userScheme.cjs +111 -44
- package/dist/cjs/userScheme.native.js +115 -59
- package/dist/cjs/userScheme.native.js.map +1 -1
- package/dist/esm/index.js +35 -23
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +35 -23
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +51 -23
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/systemScheme.mjs +6 -4
- package/dist/esm/systemScheme.mjs.map +1 -1
- package/dist/esm/systemScheme.native.js +19 -17
- package/dist/esm/systemScheme.native.js.map +1 -1
- package/dist/esm/userScheme.mjs +95 -30
- package/dist/esm/userScheme.mjs.map +1 -1
- package/dist/esm/userScheme.native.js +99 -45
- package/dist/esm/userScheme.native.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/userScheme.cjs
CHANGED
|
@@ -3,20 +3,22 @@ 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
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, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var userScheme_exports = {};
|
|
22
24
|
__export(userScheme_exports, {
|
|
@@ -28,12 +30,12 @@ __export(userScheme_exports, {
|
|
|
28
30
|
useUserScheme: () => useUserScheme
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(userScheme_exports);
|
|
31
|
-
var import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const listeners = /* @__PURE__ */new Set()
|
|
36
|
-
|
|
33
|
+
var import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect");
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_react_native = require("react-native-web");
|
|
36
|
+
var import_systemScheme = require("./systemScheme.cjs");
|
|
37
|
+
const listeners = /* @__PURE__ */new Set();
|
|
38
|
+
const storageKey = "vxrn-scheme";
|
|
37
39
|
let _forceScheme = null;
|
|
38
40
|
function notifyListeners() {
|
|
39
41
|
listeners.forEach(listener => {
|
|
@@ -41,90 +43,155 @@ function notifyListeners() {
|
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
function restoreUnforcedScheme() {
|
|
44
|
-
if (typeof localStorage
|
|
46
|
+
if (typeof localStorage !== "undefined") {
|
|
45
47
|
const stored = localStorage.getItem(storageKey);
|
|
46
48
|
if (stored) {
|
|
47
|
-
currentSetting = stored
|
|
49
|
+
currentSetting = stored;
|
|
50
|
+
currentValue = stored === "system" ? resolveValue("system") : stored;
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
currentSetting = "system"
|
|
54
|
+
currentSetting = "system";
|
|
55
|
+
currentValue = resolveValue("system");
|
|
52
56
|
}
|
|
53
57
|
function setForceScheme(scheme) {
|
|
54
58
|
const wasForced = _forceScheme;
|
|
55
|
-
|
|
59
|
+
if (wasForced === scheme) return;
|
|
60
|
+
_forceScheme = scheme;
|
|
61
|
+
if (scheme) {
|
|
62
|
+
currentSetting = scheme;
|
|
63
|
+
currentValue = scheme;
|
|
64
|
+
} else if (wasForced) {
|
|
65
|
+
restoreUnforcedScheme();
|
|
66
|
+
startWebListener();
|
|
67
|
+
}
|
|
56
68
|
}
|
|
57
69
|
function getForceScheme() {
|
|
58
70
|
return _forceScheme;
|
|
59
71
|
}
|
|
60
72
|
function getInitialSetting() {
|
|
73
|
+
if (false) {
|
|
74
|
+
if (typeof localStorage !== "undefined") {
|
|
75
|
+
const stored = localStorage.getItem(storageKey);
|
|
76
|
+
if (stored === "light" || stored === "dark" || stored === "system") {
|
|
77
|
+
return stored;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
61
81
|
return "system";
|
|
62
82
|
}
|
|
63
83
|
function getInitialValue(setting) {
|
|
84
|
+
if (false) {
|
|
85
|
+
if (setting === "system") {
|
|
86
|
+
return Appearance.getColorScheme() === "dark" ? "dark" : "light";
|
|
87
|
+
}
|
|
88
|
+
return setting;
|
|
89
|
+
}
|
|
64
90
|
return "light";
|
|
65
91
|
}
|
|
66
92
|
const initialSetting = getInitialSetting();
|
|
67
|
-
let currentSetting = initialSetting
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
let currentSetting = initialSetting;
|
|
94
|
+
let currentValue = getInitialValue(initialSetting);
|
|
95
|
+
if (false) {
|
|
96
|
+
Appearance.addChangeListener(next => {
|
|
97
|
+
if (currentSetting === "system" && next.colorScheme) {
|
|
98
|
+
updateValueFromSystem();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
let isWebListening = false;
|
|
70
103
|
function startWebListener() {
|
|
71
104
|
if (isWebListening) return;
|
|
72
|
-
isWebListening =
|
|
73
|
-
const matcher = typeof window
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
isWebListening = true;
|
|
106
|
+
const matcher = typeof window !== "undefined" ? window.matchMedia?.("(prefers-color-scheme: dark)") : null;
|
|
107
|
+
const onSystemChange = () => {
|
|
108
|
+
if (currentSetting === "system") {
|
|
109
|
+
updateValueFromSystem();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
onSystemChange();
|
|
113
|
+
matcher?.addEventListener?.("change", onSystemChange);
|
|
78
114
|
}
|
|
79
115
|
function resolveValue(setting) {
|
|
80
|
-
|
|
116
|
+
if (setting === "system") {
|
|
117
|
+
if (false) {
|
|
118
|
+
return Appearance.getColorScheme() === "dark" ? "dark" : "light";
|
|
119
|
+
}
|
|
120
|
+
return (0, import_systemScheme.getSystemScheme)();
|
|
121
|
+
}
|
|
122
|
+
return setting;
|
|
81
123
|
}
|
|
82
124
|
function updateValueFromSystem() {
|
|
83
125
|
if (_forceScheme) return;
|
|
84
126
|
const value = resolveValue("system");
|
|
85
|
-
value !== currentValue
|
|
127
|
+
if (value !== currentValue) {
|
|
128
|
+
currentValue = value;
|
|
129
|
+
notifyListeners();
|
|
130
|
+
}
|
|
86
131
|
}
|
|
87
132
|
function updateScheme(setting) {
|
|
88
133
|
if (_forceScheme) return;
|
|
89
134
|
const value = setting === "system" ? resolveValue("system") : setting;
|
|
90
|
-
(value !== currentValue || currentSetting !== setting)
|
|
135
|
+
if (value !== currentValue || currentSetting !== setting) {
|
|
136
|
+
currentSetting = setting;
|
|
137
|
+
currentValue = value;
|
|
138
|
+
if (false) {
|
|
139
|
+
if (setting !== "system") {
|
|
140
|
+
Appearance.setColorScheme(value);
|
|
141
|
+
} else {
|
|
142
|
+
Appearance.setColorScheme("unspecified");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
notifyListeners();
|
|
146
|
+
}
|
|
91
147
|
}
|
|
92
148
|
function setUserScheme(setting) {
|
|
93
|
-
|
|
149
|
+
if (_forceScheme) return;
|
|
150
|
+
if (typeof localStorage !== "undefined") {
|
|
151
|
+
localStorage.setItem(storageKey, setting);
|
|
152
|
+
}
|
|
153
|
+
updateScheme(setting);
|
|
94
154
|
}
|
|
95
155
|
function getUserScheme() {
|
|
96
|
-
|
|
156
|
+
if (_forceScheme) return {
|
|
97
157
|
setting: _forceScheme,
|
|
98
158
|
value: _forceScheme
|
|
99
|
-
}
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
100
161
|
setting: currentSetting,
|
|
101
162
|
value: currentValue
|
|
102
163
|
};
|
|
103
164
|
}
|
|
104
165
|
function onUserSchemeChange(listener) {
|
|
105
|
-
|
|
166
|
+
listeners.add(listener);
|
|
167
|
+
listener(currentSetting, currentValue);
|
|
168
|
+
return () => {
|
|
106
169
|
listeners.delete(listener);
|
|
107
170
|
};
|
|
108
171
|
}
|
|
109
172
|
function useUserScheme() {
|
|
110
|
-
const [state, setState] = (0, import_react.useState)(() => getUserScheme())
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
173
|
+
const [state, setState] = (0, import_react.useState)(() => getUserScheme());
|
|
174
|
+
const snapshot = getUserScheme();
|
|
175
|
+
const resolvedState = state.setting === snapshot.setting && state.value === snapshot.value ? state : snapshot;
|
|
176
|
+
(0, import_use_isomorphic_layout_effect.useIsomorphicLayoutEffect)(() => {
|
|
114
177
|
if (!_forceScheme) {
|
|
115
|
-
if (typeof localStorage
|
|
178
|
+
if (typeof localStorage !== "undefined") {
|
|
116
179
|
const stored = localStorage.getItem(storageKey);
|
|
117
|
-
|
|
180
|
+
if (stored) {
|
|
181
|
+
updateScheme(stored);
|
|
182
|
+
}
|
|
118
183
|
}
|
|
119
184
|
startWebListener();
|
|
120
185
|
}
|
|
121
|
-
|
|
186
|
+
const dispose = onUserSchemeChange((setting, value) => {
|
|
122
187
|
setState({
|
|
123
188
|
setting,
|
|
124
189
|
value
|
|
125
190
|
});
|
|
126
191
|
});
|
|
127
|
-
|
|
192
|
+
return dispose;
|
|
193
|
+
}, []);
|
|
194
|
+
return (0, import_react.useMemo)(() => ({
|
|
128
195
|
setting: resolvedState.setting,
|
|
129
196
|
value: resolvedState.value,
|
|
130
197
|
set: setUserScheme
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var userScheme_exports = {};
|
|
24
26
|
__export(userScheme_exports, {
|
|
@@ -30,106 +32,159 @@ __export(userScheme_exports, {
|
|
|
30
32
|
useUserScheme: () => useUserScheme
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(userScheme_exports);
|
|
33
|
-
var import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect")
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
var import_use_isomorphic_layout_effect = require("@vxrn/use-isomorphic-layout-effect");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_react_native = require("react-native");
|
|
38
|
+
var import_systemScheme = require("./systemScheme.native.js");
|
|
39
|
+
var listeners = /* @__PURE__ */new Set();
|
|
40
|
+
var storageKey = "vxrn-scheme";
|
|
41
|
+
var _forceScheme = null;
|
|
40
42
|
function notifyListeners() {
|
|
41
43
|
listeners.forEach(function (listener) {
|
|
42
44
|
listener(currentSetting, currentValue);
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
47
|
function restoreUnforcedScheme() {
|
|
46
|
-
if (typeof localStorage
|
|
48
|
+
if (typeof localStorage !== "undefined") {
|
|
47
49
|
var stored = localStorage.getItem(storageKey);
|
|
48
50
|
if (stored) {
|
|
49
|
-
currentSetting = stored
|
|
51
|
+
currentSetting = stored;
|
|
52
|
+
currentValue = stored === "system" ? resolveValue("system") : stored;
|
|
50
53
|
return;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
|
-
currentSetting = "system"
|
|
56
|
+
currentSetting = "system";
|
|
57
|
+
currentValue = resolveValue("system");
|
|
54
58
|
}
|
|
55
59
|
function setForceScheme(scheme) {
|
|
56
60
|
var wasForced = _forceScheme;
|
|
57
|
-
|
|
61
|
+
if (wasForced === scheme) return;
|
|
62
|
+
_forceScheme = scheme;
|
|
63
|
+
if (scheme) {
|
|
64
|
+
currentSetting = scheme;
|
|
65
|
+
currentValue = scheme;
|
|
66
|
+
} else if (wasForced) {
|
|
67
|
+
restoreUnforcedScheme();
|
|
68
|
+
startWebListener();
|
|
69
|
+
}
|
|
58
70
|
}
|
|
59
71
|
function getForceScheme() {
|
|
60
72
|
return _forceScheme;
|
|
61
73
|
}
|
|
62
74
|
function getInitialSetting() {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
if (true) {
|
|
76
|
+
if (typeof localStorage !== "undefined") {
|
|
77
|
+
var stored = localStorage.getItem(storageKey);
|
|
78
|
+
if (stored === "light" || stored === "dark" || stored === "system") {
|
|
79
|
+
return stored;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
66
82
|
}
|
|
67
83
|
return "system";
|
|
68
84
|
}
|
|
69
85
|
function getInitialValue(setting) {
|
|
70
|
-
|
|
86
|
+
if (true) {
|
|
87
|
+
if (setting === "system") {
|
|
88
|
+
return import_react_native.Appearance.getColorScheme() === "dark" ? "dark" : "light";
|
|
89
|
+
}
|
|
90
|
+
return setting;
|
|
91
|
+
}
|
|
92
|
+
return "light";
|
|
71
93
|
}
|
|
72
|
-
var initialSetting = getInitialSetting()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
var initialSetting = getInitialSetting();
|
|
95
|
+
var currentSetting = initialSetting;
|
|
96
|
+
var currentValue = getInitialValue(initialSetting);
|
|
97
|
+
if (true) {
|
|
98
|
+
import_react_native.Appearance.addChangeListener(function (next) {
|
|
99
|
+
if (currentSetting === "system" && next.colorScheme) {
|
|
100
|
+
updateValueFromSystem();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
var isWebListening = false;
|
|
79
105
|
function startWebListener() {
|
|
80
106
|
var _window_matchMedia, _window, _matcher_addEventListener;
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
107
|
+
if (isWebListening) return;
|
|
108
|
+
isWebListening = true;
|
|
109
|
+
var matcher = typeof window !== "undefined" ? (_window_matchMedia = (_window = window).matchMedia) === null || _window_matchMedia === void 0 ? void 0 : _window_matchMedia.call(_window, "(prefers-color-scheme: dark)") : null;
|
|
110
|
+
var onSystemChange = function () {
|
|
111
|
+
if (currentSetting === "system") {
|
|
112
|
+
updateValueFromSystem();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
onSystemChange();
|
|
116
|
+
matcher === null || matcher === void 0 ? void 0 : (_matcher_addEventListener = matcher.addEventListener) === null || _matcher_addEventListener === void 0 ? void 0 : _matcher_addEventListener.call(matcher, "change", onSystemChange);
|
|
89
117
|
}
|
|
90
118
|
function resolveValue(setting) {
|
|
91
|
-
|
|
119
|
+
if (setting === "system") {
|
|
120
|
+
if (true) {
|
|
121
|
+
return import_react_native.Appearance.getColorScheme() === "dark" ? "dark" : "light";
|
|
122
|
+
}
|
|
123
|
+
return (0, import_systemScheme.getSystemScheme)();
|
|
124
|
+
}
|
|
125
|
+
return setting;
|
|
92
126
|
}
|
|
93
127
|
function updateValueFromSystem() {
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
128
|
+
if (_forceScheme) return;
|
|
129
|
+
var value = resolveValue("system");
|
|
130
|
+
if (value !== currentValue) {
|
|
131
|
+
currentValue = value;
|
|
132
|
+
notifyListeners();
|
|
97
133
|
}
|
|
98
134
|
}
|
|
99
135
|
function updateScheme(setting) {
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
136
|
+
if (_forceScheme) return;
|
|
137
|
+
var value = setting === "system" ? resolveValue("system") : setting;
|
|
138
|
+
if (value !== currentValue || currentSetting !== setting) {
|
|
139
|
+
currentSetting = setting;
|
|
140
|
+
currentValue = value;
|
|
141
|
+
if (true) {
|
|
142
|
+
if (setting !== "system") {
|
|
143
|
+
import_react_native.Appearance.setColorScheme(value);
|
|
144
|
+
} else {
|
|
145
|
+
import_react_native.Appearance.setColorScheme("unspecified");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
notifyListeners();
|
|
103
149
|
}
|
|
104
150
|
}
|
|
105
151
|
function setUserScheme(setting) {
|
|
106
|
-
|
|
152
|
+
if (_forceScheme) return;
|
|
153
|
+
if (typeof localStorage !== "undefined") {
|
|
154
|
+
localStorage.setItem(storageKey, setting);
|
|
155
|
+
}
|
|
156
|
+
updateScheme(setting);
|
|
107
157
|
}
|
|
108
158
|
function getUserScheme() {
|
|
109
|
-
|
|
159
|
+
if (_forceScheme) return {
|
|
110
160
|
setting: _forceScheme,
|
|
111
161
|
value: _forceScheme
|
|
112
|
-
}
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
113
164
|
setting: currentSetting,
|
|
114
165
|
value: currentValue
|
|
115
166
|
};
|
|
116
167
|
}
|
|
117
168
|
function onUserSchemeChange(listener) {
|
|
118
|
-
|
|
169
|
+
listeners.add(listener);
|
|
170
|
+
listener(currentSetting, currentValue);
|
|
171
|
+
return function () {
|
|
119
172
|
listeners.delete(listener);
|
|
120
173
|
};
|
|
121
174
|
}
|
|
122
175
|
function useUserScheme() {
|
|
123
176
|
var [state, setState] = (0, import_react.useState)(function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
177
|
+
return getUserScheme();
|
|
178
|
+
});
|
|
179
|
+
var snapshot = getUserScheme();
|
|
180
|
+
var resolvedState = state.setting === snapshot.setting && state.value === snapshot.value ? state : snapshot;
|
|
181
|
+
(0, import_use_isomorphic_layout_effect.useIsomorphicLayoutEffect)(function () {
|
|
129
182
|
if (!_forceScheme) {
|
|
130
|
-
if (typeof localStorage
|
|
183
|
+
if (typeof localStorage !== "undefined") {
|
|
131
184
|
var stored = localStorage.getItem(storageKey);
|
|
132
|
-
|
|
185
|
+
if (stored) {
|
|
186
|
+
updateScheme(stored);
|
|
187
|
+
}
|
|
133
188
|
}
|
|
134
189
|
startWebListener();
|
|
135
190
|
}
|
|
@@ -140,7 +195,8 @@ function useUserScheme() {
|
|
|
140
195
|
});
|
|
141
196
|
});
|
|
142
197
|
return dispose;
|
|
143
|
-
}, [])
|
|
198
|
+
}, []);
|
|
199
|
+
return (0, import_react.useMemo)(function () {
|
|
144
200
|
return {
|
|
145
201
|
setting: resolvedState.setting,
|
|
146
202
|
value: resolvedState.value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","userScheme_exports","__export","getForceScheme","getUserScheme","onUserSchemeChange","setForceScheme","setUserScheme","useUserScheme","module","exports","import_use_isomorphic_layout_effect","require","import_react","import_react_native","import_systemScheme","listeners","Set","storageKey","_forceScheme","notifyListeners","forEach","listener","currentSetting","currentValue","restoreUnforcedScheme","localStorage","stored","getItem","resolveValue","scheme","wasForced","startWebListener","getInitialSetting","getInitialValue","setting","Appearance","getColorScheme","initialSetting","addChangeListener","next","colorScheme","updateValueFromSystem","isWebListening","_window_matchMedia","_window","_matcher_addEventListener","matcher","window","matchMedia","call","onSystemChange","addEventListener","updateScheme","setColorScheme","setItem","add","delete","state","setState","useState","snapshot","resolvedState","useIsomorphicLayoutEffect"],"sources":["../../src/userScheme.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","userScheme_exports","__export","getForceScheme","getUserScheme","onUserSchemeChange","setForceScheme","setUserScheme","useUserScheme","module","exports","import_use_isomorphic_layout_effect","require","import_react","import_react_native","import_systemScheme","listeners","Set","storageKey","_forceScheme","notifyListeners","forEach","listener","currentSetting","currentValue","restoreUnforcedScheme","localStorage","stored","getItem","resolveValue","scheme","wasForced","startWebListener","getInitialSetting","getInitialValue","setting","Appearance","getColorScheme","initialSetting","addChangeListener","next","colorScheme","updateValueFromSystem","isWebListening","_window_matchMedia","_window","_matcher_addEventListener","matcher","window","matchMedia","call","onSystemChange","addEventListener","getSystemScheme","updateScheme","setColorScheme","setItem","add","delete","state","setState","useState","snapshot","resolvedState","useIsomorphicLayoutEffect","dispose"],"sources":["../../src/userScheme.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,I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AAAnC,QAAW;EACjBA,QAAM,CAAAC,cACJ,EAAAC,YAAM;EAIR;IACER,SAAK,CAAA0C,MAAA,CAAApC,QAAc;EAEjB;AACE;AACA,SAAAd,aAAYA,CAAA;EACV,KAAAmD,KAAA,EAAAC,QAAA,CAAa,OAAM/C,YAAA,CAAAgD,QAAA;IAAA,OACrBzD,aAAA;EAAA;EAEF,IAAA0D,QAAA,GAAA1D,aAAiB;EAAA,IACnB2D,aAAA,GAAAJ,KAAA,CAAAxB,OAAA,KAAA2B,QAAA,CAAA3B,OAAA,IAAAwB,KAAA,CAAA3D,KAAA,KAAA8D,QAAA,CAAA9D,KAAA,GAAA2D,KAAA,GAAAG,QAAA;EAGA,IAAAnD,mCAAoC,CAAAqD,yBAAmB;IACrD,KAAA7C,YAAW;MACZ,WAAAO,YAAA;QAED,IAAOC,MAAA,GAAAD,YAAA,CAAAE,OAAA,CAAAV,UAAA;QACJ,IAAAS,MAAA;UAEL2B,YAAO,CAAA3B,MAAA;QACL;MACE;MACAK,gBAAO;IAAc;IAEvB,IAAAiC,OAAA,GAAA5D,kBAAA,WAAA8B,OAAA,EAAAnC,KAAA;MACC4D,QAAA;QACHzB,OAAA;QACFnC","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -12,26 +12,38 @@ function SchemeProvider({
|
|
|
12
12
|
}) {
|
|
13
13
|
setForceScheme(forceScheme ?? null);
|
|
14
14
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
value
|
|
16
|
+
} = useUserScheme();
|
|
17
|
+
const resolvedValue = forceScheme ?? value;
|
|
18
|
+
if (true) {
|
|
19
|
+
useIsomorphicLayoutEffect(() => {
|
|
20
|
+
if (!forceScheme && defaultScheme && typeof localStorage !== "undefined") {
|
|
21
|
+
if (!localStorage.getItem(storageKey)) {
|
|
22
|
+
setUserScheme(defaultScheme);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, [defaultScheme, forceScheme]);
|
|
26
|
+
useIsomorphicLayoutEffect(() => {
|
|
27
|
+
const toAdd = getClassName(resolvedValue);
|
|
28
|
+
const toRemove = getClassName(resolvedValue === "light" ? "dark" : "light");
|
|
29
|
+
const {
|
|
24
30
|
classList
|
|
25
31
|
} = document.documentElement;
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
classList.remove(toRemove);
|
|
33
|
+
if (!classList.contains(toAdd)) {
|
|
34
|
+
classList.add(toAdd);
|
|
35
|
+
}
|
|
36
|
+
}, [getClassName, resolvedValue]);
|
|
37
|
+
}
|
|
28
38
|
let scriptContent;
|
|
29
|
-
if (forceScheme)
|
|
39
|
+
if (forceScheme) {
|
|
40
|
+
scriptContent = `let d = document.documentElement.classList
|
|
30
41
|
d.remove('${getClassName("light")}')
|
|
31
42
|
d.remove('${getClassName("dark")}')
|
|
32
|
-
d.add('${getClassName(forceScheme)}')`;
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
d.add('${getClassName(forceScheme)}')`;
|
|
44
|
+
} else {
|
|
45
|
+
const fallback = defaultScheme ? `'${defaultScheme}' === 'dark'` : `window.matchMedia('(prefers-color-scheme: dark)').matches`;
|
|
46
|
+
const seedStorage = defaultScheme ? `if(!e){localStorage.setItem('${storageKey}','${defaultScheme}')}` : "";
|
|
35
47
|
scriptContent = `let d = document.documentElement.classList
|
|
36
48
|
d.remove('${getClassName("light")}')
|
|
37
49
|
d.remove('${getClassName("dark")}')
|
|
@@ -43,8 +55,8 @@ let t = 'system' === e || !e
|
|
|
43
55
|
t ? d.add('${getClassName("dark")}') : d.add('${getClassName("light")}')`;
|
|
44
56
|
}
|
|
45
57
|
return /* @__PURE__ */jsxs(Fragment, {
|
|
46
|
-
children: [/* @__PURE__ */jsx("script", {
|
|
47
|
-
suppressHydrationWarning:
|
|
58
|
+
children: [false ? null : /* @__PURE__ */jsx("script", {
|
|
59
|
+
suppressHydrationWarning: true,
|
|
48
60
|
dangerouslySetInnerHTML: {
|
|
49
61
|
__html: scriptContent
|
|
50
62
|
}
|
|
@@ -57,21 +69,21 @@ function MetaTheme({
|
|
|
57
69
|
lightColor
|
|
58
70
|
}) {
|
|
59
71
|
const {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
value
|
|
73
|
+
} = useUserScheme();
|
|
74
|
+
const forced = getForceScheme();
|
|
75
|
+
const scriptContent = forced ? `document.getElementById('vxrn-theme-color').setAttribute('content','${forced === "dark" ? darkColor : lightColor}')` : `let dc = document.getElementById('vxrn-theme-color')
|
|
64
76
|
let e1 = localStorage.getItem('${storageKey}')
|
|
65
77
|
let isD = 'system' === e1 || !e1 ? window.matchMedia('(prefers-color-scheme: dark)').matches : e1 === 'dark'
|
|
66
78
|
dc.setAttribute('content', isD ? '${darkColor}' : '${lightColor}')`;
|
|
67
79
|
return /* @__PURE__ */jsxs(Fragment, {
|
|
68
80
|
children: [/* @__PURE__ */jsx("meta", {
|
|
69
|
-
suppressHydrationWarning:
|
|
81
|
+
suppressHydrationWarning: true,
|
|
70
82
|
id: "vxrn-theme-color",
|
|
71
83
|
name: "theme-color",
|
|
72
84
|
content: color ?? (value === "dark" ? darkColor : lightColor)
|
|
73
85
|
}), /* @__PURE__ */jsx("script", {
|
|
74
|
-
suppressHydrationWarning:
|
|
86
|
+
suppressHydrationWarning: true,
|
|
75
87
|
id: "meta-theme-hydrate",
|
|
76
88
|
dangerouslySetInnerHTML: {
|
|
77
89
|
__html: scriptContent
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useIsomorphicLayoutEffect","getForceScheme","setForceScheme","setUserScheme","useUserScheme","getSystemScheme","useSystemScheme","getUserScheme","onUserSchemeChange","setUserScheme2","useUserScheme2","Fragment","jsx","jsxs","storageKey","SchemeProvider","children","getClassName","name","defaultScheme","forceScheme","value","resolvedValue","localStorage","getItem","toAdd","toRemove","classList","document","documentElement","remove","contains","add","scriptContent","fallback","seedStorage","suppressHydrationWarning","dangerouslySetInnerHTML","__html","MetaTheme","color","darkColor","lightColor","forced","id","content"],"sources":["../../src/index.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,yBAAA,QAAiC;AAE1C,SACEC,cAAA,EACAC,cAAA,EACAC,aAAA,EACAC,aAAA,QACK;AAOP,SAASC,eAAA,EAAiBC,eAAA,QAAuB;AACjD,SACEC,aAAA,EACAC,kBAAA,EACAL,aAAA,IAAAM,cAAA,EACAL,aAAA,IAAAM,cAAA,QACK;AAyEH,SAAAC,QAAA,EAEIC,GAAA,EAFJC,IAAA;AAvEJ,MAAMC,UAAA,GAAa;AAEZ,SAASC,eAAe;EAC7BC,QAAA;EACAC,YAAA,GAAgBC,IAAA,IAAS,KAAKA,IAAI;EAClCC,aAAA;EACAC;AACF,GAOG;EAEDlB,cAAA,CAAekB,WAAA,IAAe,IAAI;EAElC,MAAM;
|
|
1
|
+
{"version":3,"names":["useIsomorphicLayoutEffect","getForceScheme","setForceScheme","setUserScheme","useUserScheme","getSystemScheme","useSystemScheme","getUserScheme","onUserSchemeChange","setUserScheme2","useUserScheme2","Fragment","jsx","jsxs","storageKey","SchemeProvider","children","getClassName","name","defaultScheme","forceScheme","value","resolvedValue","localStorage","getItem","toAdd","toRemove","classList","document","documentElement","remove","contains","add","scriptContent","fallback","seedStorage","suppressHydrationWarning","dangerouslySetInnerHTML","__html","MetaTheme","color","darkColor","lightColor","forced","id","content"],"sources":["../../src/index.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,yBAAA,QAAiC;AAE1C,SACEC,cAAA,EACAC,cAAA,EACAC,aAAA,EACAC,aAAA,QACK;AAOP,SAASC,eAAA,EAAiBC,eAAA,QAAuB;AACjD,SACEC,aAAA,EACAC,kBAAA,EACAL,aAAA,IAAAM,cAAA,EACAL,aAAA,IAAAM,cAAA,QACK;AAyEH,SAAAC,QAAA,EAEIC,GAAA,EAFJC,I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