@mui/system 5.15.13 → 5.15.15
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/CHANGELOG.md +156 -60
- package/colorManipulator.js +1 -1
- package/cssVars/createCssVarsProvider.js +23 -22
- package/cssVars/useCurrentColorScheme.js +37 -25
- package/esm/colorManipulator.js +1 -1
- package/esm/cssVars/createCssVarsProvider.js +23 -22
- package/esm/cssVars/useCurrentColorScheme.js +37 -25
- package/index.js +1 -1
- package/legacy/colorManipulator.js +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +48 -48
- package/legacy/cssVars/useCurrentColorScheme.js +29 -23
- package/legacy/index.js +1 -1
- package/modern/colorManipulator.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +23 -22
- package/modern/cssVars/useCurrentColorScheme.js +37 -25
- package/modern/index.js +1 -1
- package/package.json +5 -5
|
@@ -88,7 +88,7 @@ function useCurrentColorScheme(options) {
|
|
|
88
88
|
// do nothing if mode does not change
|
|
89
89
|
return currentState;
|
|
90
90
|
}
|
|
91
|
-
const newMode =
|
|
91
|
+
const newMode = mode != null ? mode : defaultMode;
|
|
92
92
|
try {
|
|
93
93
|
localStorage.setItem(modeStorageKey, newMode);
|
|
94
94
|
} catch (e) {
|
|
@@ -169,11 +169,19 @@ function useCurrentColorScheme(options) {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
172
|
-
const handleMediaQuery = React.useCallback(
|
|
172
|
+
const handleMediaQuery = React.useCallback(event => {
|
|
173
173
|
if (state.mode === 'system') {
|
|
174
|
-
setState(currentState =>
|
|
175
|
-
systemMode
|
|
176
|
-
|
|
174
|
+
setState(currentState => {
|
|
175
|
+
const systemMode = event != null && event.matches ? 'dark' : 'light';
|
|
176
|
+
|
|
177
|
+
// Early exit, nothing changed.
|
|
178
|
+
if (currentState.systemMode === systemMode) {
|
|
179
|
+
return currentState;
|
|
180
|
+
}
|
|
181
|
+
return (0, _extends2.default)({}, currentState, {
|
|
182
|
+
systemMode
|
|
183
|
+
});
|
|
184
|
+
});
|
|
177
185
|
}
|
|
178
186
|
}, [state.mode]);
|
|
179
187
|
|
|
@@ -189,34 +197,38 @@ function useCurrentColorScheme(options) {
|
|
|
189
197
|
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
190
198
|
media.addListener(handler);
|
|
191
199
|
handler(media);
|
|
192
|
-
return () =>
|
|
200
|
+
return () => {
|
|
201
|
+
media.removeListener(handler);
|
|
202
|
+
};
|
|
193
203
|
}, []);
|
|
194
204
|
|
|
195
205
|
// Handle when localStorage has changed
|
|
196
206
|
React.useEffect(() => {
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
if (storageWindow) {
|
|
208
|
+
const handleStorage = event => {
|
|
209
|
+
const value = event.newValue;
|
|
210
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
211
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
212
|
+
if (event.key.endsWith('light')) {
|
|
213
|
+
setColorScheme({
|
|
214
|
+
light: value
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (event.key.endsWith('dark')) {
|
|
218
|
+
setColorScheme({
|
|
219
|
+
dark: value
|
|
220
|
+
});
|
|
221
|
+
}
|
|
205
222
|
}
|
|
206
|
-
if (event.key
|
|
207
|
-
|
|
208
|
-
dark: value
|
|
209
|
-
});
|
|
223
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
224
|
+
setMode(value || defaultMode);
|
|
210
225
|
}
|
|
211
|
-
}
|
|
212
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
213
|
-
setMode(value || defaultMode);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
if (storageWindow) {
|
|
226
|
+
};
|
|
217
227
|
// For syncing color-scheme changes between iframes
|
|
218
228
|
storageWindow.addEventListener('storage', handleStorage);
|
|
219
|
-
return () =>
|
|
229
|
+
return () => {
|
|
230
|
+
storageWindow.removeEventListener('storage', handleStorage);
|
|
231
|
+
};
|
|
220
232
|
}
|
|
221
233
|
return undefined;
|
|
222
234
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
package/esm/colorManipulator.js
CHANGED
|
@@ -316,7 +316,7 @@ export function emphasize(color, coefficient = 0.15) {
|
|
|
316
316
|
}
|
|
317
317
|
export function private_safeEmphasize(color, coefficient, warning) {
|
|
318
318
|
try {
|
|
319
|
-
return
|
|
319
|
+
return emphasize(color, coefficient);
|
|
320
320
|
} catch (error) {
|
|
321
321
|
if (warning && process.env.NODE_ENV !== 'production') {
|
|
322
322
|
console.warn(warning);
|
|
@@ -46,22 +46,23 @@ export default function createCssVarsProvider(options) {
|
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
};
|
|
49
|
-
function CssVarsProvider({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
function CssVarsProvider(props) {
|
|
50
|
+
const {
|
|
51
|
+
children,
|
|
52
|
+
theme: themeProp = defaultTheme,
|
|
53
|
+
modeStorageKey = defaultModeStorageKey,
|
|
54
|
+
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
55
|
+
attribute = defaultAttribute,
|
|
56
|
+
defaultMode = designSystemMode,
|
|
57
|
+
defaultColorScheme = designSystemColorScheme,
|
|
58
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
59
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
60
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
61
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
62
|
+
colorSchemeSelector = ':root',
|
|
63
|
+
disableNestedContext = false,
|
|
64
|
+
disableStyleSheetGeneration = false
|
|
65
|
+
} = props;
|
|
65
66
|
const hasMounted = React.useRef(false);
|
|
66
67
|
const upperTheme = muiUseTheme();
|
|
67
68
|
const ctx = React.useContext(ColorSchemeContext);
|
|
@@ -228,14 +229,14 @@ export default function createCssVarsProvider(options) {
|
|
|
228
229
|
};
|
|
229
230
|
}, []);
|
|
230
231
|
const contextValue = React.useMemo(() => ({
|
|
231
|
-
|
|
232
|
-
systemMode,
|
|
233
|
-
setMode,
|
|
234
|
-
lightColorScheme,
|
|
235
|
-
darkColorScheme,
|
|
232
|
+
allColorSchemes,
|
|
236
233
|
colorScheme,
|
|
234
|
+
darkColorScheme,
|
|
235
|
+
lightColorScheme,
|
|
236
|
+
mode,
|
|
237
237
|
setColorScheme,
|
|
238
|
-
|
|
238
|
+
setMode,
|
|
239
|
+
systemMode
|
|
239
240
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
240
241
|
let shouldGenerateStyleSheet = true;
|
|
241
242
|
if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
|
|
@@ -78,7 +78,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
78
78
|
// do nothing if mode does not change
|
|
79
79
|
return currentState;
|
|
80
80
|
}
|
|
81
|
-
const newMode =
|
|
81
|
+
const newMode = mode != null ? mode : defaultMode;
|
|
82
82
|
try {
|
|
83
83
|
localStorage.setItem(modeStorageKey, newMode);
|
|
84
84
|
} catch (e) {
|
|
@@ -159,11 +159,19 @@ export default function useCurrentColorScheme(options) {
|
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
162
|
-
const handleMediaQuery = React.useCallback(
|
|
162
|
+
const handleMediaQuery = React.useCallback(event => {
|
|
163
163
|
if (state.mode === 'system') {
|
|
164
|
-
setState(currentState =>
|
|
165
|
-
systemMode
|
|
166
|
-
|
|
164
|
+
setState(currentState => {
|
|
165
|
+
const systemMode = event != null && event.matches ? 'dark' : 'light';
|
|
166
|
+
|
|
167
|
+
// Early exit, nothing changed.
|
|
168
|
+
if (currentState.systemMode === systemMode) {
|
|
169
|
+
return currentState;
|
|
170
|
+
}
|
|
171
|
+
return _extends({}, currentState, {
|
|
172
|
+
systemMode
|
|
173
|
+
});
|
|
174
|
+
});
|
|
167
175
|
}
|
|
168
176
|
}, [state.mode]);
|
|
169
177
|
|
|
@@ -179,34 +187,38 @@ export default function useCurrentColorScheme(options) {
|
|
|
179
187
|
// Intentionally use deprecated listener methods to support iOS & old browsers
|
|
180
188
|
media.addListener(handler);
|
|
181
189
|
handler(media);
|
|
182
|
-
return () =>
|
|
190
|
+
return () => {
|
|
191
|
+
media.removeListener(handler);
|
|
192
|
+
};
|
|
183
193
|
}, []);
|
|
184
194
|
|
|
185
195
|
// Handle when localStorage has changed
|
|
186
196
|
React.useEffect(() => {
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
if (storageWindow) {
|
|
198
|
+
const handleStorage = event => {
|
|
199
|
+
const value = event.newValue;
|
|
200
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
201
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
202
|
+
if (event.key.endsWith('light')) {
|
|
203
|
+
setColorScheme({
|
|
204
|
+
light: value
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (event.key.endsWith('dark')) {
|
|
208
|
+
setColorScheme({
|
|
209
|
+
dark: value
|
|
210
|
+
});
|
|
211
|
+
}
|
|
195
212
|
}
|
|
196
|
-
if (event.key
|
|
197
|
-
|
|
198
|
-
dark: value
|
|
199
|
-
});
|
|
213
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
214
|
+
setMode(value || defaultMode);
|
|
200
215
|
}
|
|
201
|
-
}
|
|
202
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
203
|
-
setMode(value || defaultMode);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
if (storageWindow) {
|
|
216
|
+
};
|
|
207
217
|
// For syncing color-scheme changes between iframes
|
|
208
218
|
storageWindow.addEventListener('storage', handleStorage);
|
|
209
|
-
return () =>
|
|
219
|
+
return () => {
|
|
220
|
+
storageWindow.removeEventListener('storage', handleStorage);
|
|
221
|
+
};
|
|
210
222
|
}
|
|
211
223
|
return undefined;
|
|
212
224
|
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
package/index.js
CHANGED
|
@@ -324,7 +324,7 @@ export function emphasize(color) {
|
|
|
324
324
|
}
|
|
325
325
|
export function private_safeEmphasize(color, coefficient, warning) {
|
|
326
326
|
try {
|
|
327
|
-
return
|
|
327
|
+
return emphasize(color, coefficient);
|
|
328
328
|
} catch (error) {
|
|
329
329
|
if (warning && process.env.NODE_ENV !== 'production') {
|
|
330
330
|
console.warn(warning);
|
|
@@ -46,53 +46,53 @@ export default function createCssVarsProvider(options) {
|
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
};
|
|
49
|
-
function CssVarsProvider(
|
|
50
|
-
var children =
|
|
51
|
-
|
|
52
|
-
themeProp =
|
|
53
|
-
|
|
54
|
-
modeStorageKey =
|
|
55
|
-
|
|
56
|
-
colorSchemeStorageKey =
|
|
57
|
-
|
|
58
|
-
attribute =
|
|
59
|
-
|
|
60
|
-
defaultMode =
|
|
61
|
-
|
|
62
|
-
defaultColorScheme =
|
|
63
|
-
|
|
64
|
-
disableTransitionOnChange =
|
|
65
|
-
|
|
66
|
-
storageWindow =
|
|
67
|
-
|
|
68
|
-
documentNode =
|
|
69
|
-
|
|
70
|
-
colorSchemeNode =
|
|
71
|
-
|
|
72
|
-
colorSchemeSelector =
|
|
73
|
-
|
|
74
|
-
disableNestedContext =
|
|
75
|
-
|
|
76
|
-
disableStyleSheetGeneration =
|
|
49
|
+
function CssVarsProvider(props) {
|
|
50
|
+
var children = props.children,
|
|
51
|
+
_props$theme = props.theme,
|
|
52
|
+
themeProp = _props$theme === void 0 ? defaultTheme : _props$theme,
|
|
53
|
+
_props$modeStorageKey = props.modeStorageKey,
|
|
54
|
+
modeStorageKey = _props$modeStorageKey === void 0 ? defaultModeStorageKey : _props$modeStorageKey,
|
|
55
|
+
_props$colorSchemeSto = props.colorSchemeStorageKey,
|
|
56
|
+
colorSchemeStorageKey = _props$colorSchemeSto === void 0 ? defaultColorSchemeStorageKey : _props$colorSchemeSto,
|
|
57
|
+
_props$attribute = props.attribute,
|
|
58
|
+
attribute = _props$attribute === void 0 ? defaultAttribute : _props$attribute,
|
|
59
|
+
_props$defaultMode = props.defaultMode,
|
|
60
|
+
defaultMode = _props$defaultMode === void 0 ? designSystemMode : _props$defaultMode,
|
|
61
|
+
_props$defaultColorSc = props.defaultColorScheme,
|
|
62
|
+
defaultColorScheme = _props$defaultColorSc === void 0 ? designSystemColorScheme : _props$defaultColorSc,
|
|
63
|
+
_props$disableTransit = props.disableTransitionOnChange,
|
|
64
|
+
disableTransitionOnChange = _props$disableTransit === void 0 ? designSystemTransitionOnChange : _props$disableTransit,
|
|
65
|
+
_props$storageWindow = props.storageWindow,
|
|
66
|
+
storageWindow = _props$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _props$storageWindow,
|
|
67
|
+
_props$documentNode = props.documentNode,
|
|
68
|
+
documentNode = _props$documentNode === void 0 ? typeof document === 'undefined' ? undefined : document : _props$documentNode,
|
|
69
|
+
_props$colorSchemeNod = props.colorSchemeNode,
|
|
70
|
+
colorSchemeNode = _props$colorSchemeNod === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _props$colorSchemeNod,
|
|
71
|
+
_props$colorSchemeSel = props.colorSchemeSelector,
|
|
72
|
+
colorSchemeSelector = _props$colorSchemeSel === void 0 ? ':root' : _props$colorSchemeSel,
|
|
73
|
+
_props$disableNestedC = props.disableNestedContext,
|
|
74
|
+
disableNestedContext = _props$disableNestedC === void 0 ? false : _props$disableNestedC,
|
|
75
|
+
_props$disableStyleSh = props.disableStyleSheetGeneration,
|
|
76
|
+
disableStyleSheetGeneration = _props$disableStyleSh === void 0 ? false : _props$disableStyleSh;
|
|
77
77
|
var hasMounted = React.useRef(false);
|
|
78
78
|
var upperTheme = muiUseTheme();
|
|
79
79
|
var ctx = React.useContext(ColorSchemeContext);
|
|
80
80
|
var nested = !!ctx && !disableNestedContext;
|
|
81
81
|
var scopedTheme = themeProp[themeId];
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
colorSchemes =
|
|
85
|
-
|
|
86
|
-
components =
|
|
87
|
-
|
|
88
|
-
generateCssVars =
|
|
82
|
+
var _ref = scopedTheme || themeProp,
|
|
83
|
+
_ref$colorSchemes = _ref.colorSchemes,
|
|
84
|
+
colorSchemes = _ref$colorSchemes === void 0 ? {} : _ref$colorSchemes,
|
|
85
|
+
_ref$components = _ref.components,
|
|
86
|
+
components = _ref$components === void 0 ? {} : _ref$components,
|
|
87
|
+
_ref$generateCssVars = _ref.generateCssVars,
|
|
88
|
+
generateCssVars = _ref$generateCssVars === void 0 ? function () {
|
|
89
89
|
return {
|
|
90
90
|
vars: {},
|
|
91
91
|
css: {}
|
|
92
92
|
};
|
|
93
|
-
} :
|
|
94
|
-
cssVarPrefix =
|
|
95
|
-
restThemeProp = _objectWithoutProperties(
|
|
93
|
+
} : _ref$generateCssVars,
|
|
94
|
+
cssVarPrefix = _ref.cssVarPrefix,
|
|
95
|
+
restThemeProp = _objectWithoutProperties(_ref, ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"]);
|
|
96
96
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
97
97
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
98
98
|
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -161,10 +161,10 @@ export default function createCssVarsProvider(options) {
|
|
|
161
161
|
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
162
162
|
var defaultColorSchemeStyleSheet = {};
|
|
163
163
|
var otherColorSchemesStyleSheet = {};
|
|
164
|
-
Object.entries(colorSchemes).forEach(function (
|
|
165
|
-
var
|
|
166
|
-
key =
|
|
167
|
-
scheme =
|
|
164
|
+
Object.entries(colorSchemes).forEach(function (_ref2) {
|
|
165
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
166
|
+
key = _ref3[0],
|
|
167
|
+
scheme = _ref3[1];
|
|
168
168
|
var _generateCssVars2 = generateCssVars(key),
|
|
169
169
|
css = _generateCssVars2.css,
|
|
170
170
|
vars = _generateCssVars2.vars;
|
|
@@ -246,14 +246,14 @@ export default function createCssVarsProvider(options) {
|
|
|
246
246
|
}, []);
|
|
247
247
|
var contextValue = React.useMemo(function () {
|
|
248
248
|
return {
|
|
249
|
-
|
|
250
|
-
systemMode: systemMode,
|
|
251
|
-
setMode: setMode,
|
|
252
|
-
lightColorScheme: lightColorScheme,
|
|
253
|
-
darkColorScheme: darkColorScheme,
|
|
249
|
+
allColorSchemes: allColorSchemes,
|
|
254
250
|
colorScheme: colorScheme,
|
|
251
|
+
darkColorScheme: darkColorScheme,
|
|
252
|
+
lightColorScheme: lightColorScheme,
|
|
253
|
+
mode: mode,
|
|
255
254
|
setColorScheme: setColorScheme,
|
|
256
|
-
|
|
255
|
+
setMode: setMode,
|
|
256
|
+
systemMode: systemMode
|
|
257
257
|
};
|
|
258
258
|
}, [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
259
259
|
var shouldGenerateStyleSheet = true;
|
|
@@ -83,7 +83,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
83
83
|
// do nothing if mode does not change
|
|
84
84
|
return currentState;
|
|
85
85
|
}
|
|
86
|
-
var newMode =
|
|
86
|
+
var newMode = mode != null ? mode : defaultMode;
|
|
87
87
|
try {
|
|
88
88
|
localStorage.setItem(modeStorageKey, newMode);
|
|
89
89
|
} catch (e) {
|
|
@@ -164,11 +164,17 @@ export default function useCurrentColorScheme(options) {
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
167
|
-
var handleMediaQuery = React.useCallback(function (
|
|
167
|
+
var handleMediaQuery = React.useCallback(function (event) {
|
|
168
168
|
if (state.mode === 'system') {
|
|
169
169
|
setState(function (currentState) {
|
|
170
|
+
var systemMode = event != null && event.matches ? 'dark' : 'light';
|
|
171
|
+
|
|
172
|
+
// Early exit, nothing changed.
|
|
173
|
+
if (currentState.systemMode === systemMode) {
|
|
174
|
+
return currentState;
|
|
175
|
+
}
|
|
170
176
|
return _extends({}, currentState, {
|
|
171
|
-
systemMode:
|
|
177
|
+
systemMode: systemMode
|
|
172
178
|
});
|
|
173
179
|
});
|
|
174
180
|
}
|
|
@@ -189,36 +195,36 @@ export default function useCurrentColorScheme(options) {
|
|
|
189
195
|
media.addListener(handler);
|
|
190
196
|
handler(media);
|
|
191
197
|
return function () {
|
|
192
|
-
|
|
198
|
+
media.removeListener(handler);
|
|
193
199
|
};
|
|
194
200
|
}, []);
|
|
195
201
|
|
|
196
202
|
// Handle when localStorage has changed
|
|
197
203
|
React.useEffect(function () {
|
|
198
|
-
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
if (storageWindow) {
|
|
205
|
+
var handleStorage = function handleStorage(event) {
|
|
206
|
+
var value = event.newValue;
|
|
207
|
+
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
208
|
+
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
209
|
+
if (event.key.endsWith('light')) {
|
|
210
|
+
setColorScheme({
|
|
211
|
+
light: value
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (event.key.endsWith('dark')) {
|
|
215
|
+
setColorScheme({
|
|
216
|
+
dark: value
|
|
217
|
+
});
|
|
218
|
+
}
|
|
206
219
|
}
|
|
207
|
-
if (event.key
|
|
208
|
-
|
|
209
|
-
dark: value
|
|
210
|
-
});
|
|
220
|
+
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
221
|
+
setMode(value || defaultMode);
|
|
211
222
|
}
|
|
212
|
-
}
|
|
213
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
214
|
-
setMode(value || defaultMode);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
if (storageWindow) {
|
|
223
|
+
};
|
|
218
224
|
// For syncing color-scheme changes between iframes
|
|
219
225
|
storageWindow.addEventListener('storage', handleStorage);
|
|
220
226
|
return function () {
|
|
221
|
-
|
|
227
|
+
storageWindow.removeEventListener('storage', handleStorage);
|
|
222
228
|
};
|
|
223
229
|
}
|
|
224
230
|
return undefined;
|
package/legacy/index.js
CHANGED
|
@@ -316,7 +316,7 @@ export function emphasize(color, coefficient = 0.15) {
|
|
|
316
316
|
}
|
|
317
317
|
export function private_safeEmphasize(color, coefficient, warning) {
|
|
318
318
|
try {
|
|
319
|
-
return
|
|
319
|
+
return emphasize(color, coefficient);
|
|
320
320
|
} catch (error) {
|
|
321
321
|
if (warning && process.env.NODE_ENV !== 'production') {
|
|
322
322
|
console.warn(warning);
|
|
@@ -46,22 +46,23 @@ export default function createCssVarsProvider(options) {
|
|
|
46
46
|
}
|
|
47
47
|
return value;
|
|
48
48
|
};
|
|
49
|
-
function CssVarsProvider({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
function CssVarsProvider(props) {
|
|
50
|
+
const {
|
|
51
|
+
children,
|
|
52
|
+
theme: themeProp = defaultTheme,
|
|
53
|
+
modeStorageKey = defaultModeStorageKey,
|
|
54
|
+
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
55
|
+
attribute = defaultAttribute,
|
|
56
|
+
defaultMode = designSystemMode,
|
|
57
|
+
defaultColorScheme = designSystemColorScheme,
|
|
58
|
+
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
59
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
60
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
61
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
62
|
+
colorSchemeSelector = ':root',
|
|
63
|
+
disableNestedContext = false,
|
|
64
|
+
disableStyleSheetGeneration = false
|
|
65
|
+
} = props;
|
|
65
66
|
const hasMounted = React.useRef(false);
|
|
66
67
|
const upperTheme = muiUseTheme();
|
|
67
68
|
const ctx = React.useContext(ColorSchemeContext);
|
|
@@ -228,14 +229,14 @@ export default function createCssVarsProvider(options) {
|
|
|
228
229
|
};
|
|
229
230
|
}, []);
|
|
230
231
|
const contextValue = React.useMemo(() => ({
|
|
231
|
-
|
|
232
|
-
systemMode,
|
|
233
|
-
setMode,
|
|
234
|
-
lightColorScheme,
|
|
235
|
-
darkColorScheme,
|
|
232
|
+
allColorSchemes,
|
|
236
233
|
colorScheme,
|
|
234
|
+
darkColorScheme,
|
|
235
|
+
lightColorScheme,
|
|
236
|
+
mode,
|
|
237
237
|
setColorScheme,
|
|
238
|
-
|
|
238
|
+
setMode,
|
|
239
|
+
systemMode
|
|
239
240
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
240
241
|
let shouldGenerateStyleSheet = true;
|
|
241
242
|
if (disableStyleSheetGeneration || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
|