@mui/system 5.8.4 → 5.8.7
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/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +185 -4
- package/Container/Container.d.ts +13 -13
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/createContainer.d.ts +18 -18
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +13 -18
- package/cssVars/createCssVarsProvider.js +13 -17
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +2 -2
- package/cssVars/cssVarsParser.d.ts +65 -70
- package/cssVars/cssVarsParser.js +4 -19
- package/cssVars/getInitColorSchemeScript.d.ts +45 -40
- package/cssVars/getInitColorSchemeScript.js +7 -0
- package/cssVars/index.d.ts +3 -2
- package/cssVars/index.js +9 -1
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/cssVars/createCssVarsProvider.js +13 -16
- package/esm/cssVars/createGetCssVar.js +2 -2
- package/esm/cssVars/cssVarsParser.js +4 -19
- package/esm/cssVars/getInitColorSchemeScript.js +7 -0
- package/esm/cssVars/index.js +2 -1
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +13 -17
- package/legacy/cssVars/createGetCssVar.js +3 -3
- package/legacy/cssVars/cssVarsParser.js +4 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +3 -1
- package/legacy/cssVars/index.js +2 -1
- package/legacy/index.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +13 -16
- package/modern/cssVars/createGetCssVar.js +2 -2
- package/modern/cssVars/cssVarsParser.js +4 -19
- package/modern/cssVars/getInitColorSchemeScript.js +7 -0
- package/modern/cssVars/index.js +2 -1
- package/modern/index.js +1 -1
- package/package.json +5 -5
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
package/index.js
CHANGED
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -12,7 +12,6 @@ import cssVarsParser from './cssVarsParser';
|
|
|
12
12
|
import ThemeProvider from '../ThemeProvider';
|
|
13
13
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
14
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
15
|
-
import createGetCssVar from './createGetCssVar';
|
|
16
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
17
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
@@ -32,9 +31,7 @@ export default function createCssVarsProvider(options) {
|
|
|
32
31
|
designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
33
32
|
_options$enableColorS = options.enableColorScheme,
|
|
34
33
|
designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
35
|
-
|
|
36
|
-
designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
|
|
37
|
-
shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
34
|
+
designSystemShouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
38
35
|
resolveTheme = options.resolveTheme;
|
|
39
36
|
|
|
40
37
|
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
@@ -57,8 +54,6 @@ export default function createCssVarsProvider(options) {
|
|
|
57
54
|
var children = _ref.children,
|
|
58
55
|
_ref$theme = _ref.theme,
|
|
59
56
|
themeProp = _ref$theme === void 0 ? defaultTheme : _ref$theme,
|
|
60
|
-
_ref$prefix = _ref.prefix,
|
|
61
|
-
prefix = _ref$prefix === void 0 ? designSystemPrefix : _ref$prefix,
|
|
62
57
|
_ref$modeStorageKey = _ref.modeStorageKey,
|
|
63
58
|
modeStorageKey = _ref$modeStorageKey === void 0 ? defaultModeStorageKey : _ref$modeStorageKey,
|
|
64
59
|
_ref$colorSchemeStora = _ref.colorSchemeStorageKey,
|
|
@@ -80,14 +75,17 @@ export default function createCssVarsProvider(options) {
|
|
|
80
75
|
_ref$colorSchemeNode = _ref.colorSchemeNode,
|
|
81
76
|
colorSchemeNode = _ref$colorSchemeNode === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _ref$colorSchemeNode,
|
|
82
77
|
_ref$colorSchemeSelec = _ref.colorSchemeSelector,
|
|
83
|
-
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec
|
|
78
|
+
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec,
|
|
79
|
+
_ref$shouldSkipGenera = _ref.shouldSkipGeneratingVar,
|
|
80
|
+
shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera;
|
|
84
81
|
var hasMounted = React.useRef(false);
|
|
85
82
|
|
|
86
83
|
var _themeProp$colorSchem = themeProp.colorSchemes,
|
|
87
84
|
colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
88
85
|
_themeProp$components = themeProp.components,
|
|
89
86
|
components = _themeProp$components === void 0 ? {} : _themeProp$components,
|
|
90
|
-
|
|
87
|
+
cssVarPrefix = themeProp.cssVarPrefix,
|
|
88
|
+
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components", "cssVarPrefix"]);
|
|
91
89
|
|
|
92
90
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
93
91
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
@@ -127,8 +125,7 @@ export default function createCssVarsProvider(options) {
|
|
|
127
125
|
var theme = restThemeProp;
|
|
128
126
|
|
|
129
127
|
var _cssVarsParser = cssVarsParser(theme, {
|
|
130
|
-
prefix:
|
|
131
|
-
basePrefix: designSystemPrefix,
|
|
128
|
+
prefix: cssVarPrefix,
|
|
132
129
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
133
130
|
}),
|
|
134
131
|
rootCss = _cssVarsParser.css,
|
|
@@ -138,9 +135,8 @@ export default function createCssVarsProvider(options) {
|
|
|
138
135
|
theme = _extends({}, parsedTheme, {
|
|
139
136
|
components: components,
|
|
140
137
|
colorSchemes: colorSchemes,
|
|
141
|
-
|
|
138
|
+
cssVarPrefix: cssVarPrefix,
|
|
142
139
|
vars: rootVars,
|
|
143
|
-
getCssVar: createGetCssVar(prefix),
|
|
144
140
|
getColorSchemeSelector: function getColorSchemeSelector(targetColorScheme) {
|
|
145
141
|
return "[".concat(attribute, "=\"").concat(targetColorScheme, "\"] &");
|
|
146
142
|
}
|
|
@@ -153,8 +149,7 @@ export default function createCssVarsProvider(options) {
|
|
|
153
149
|
scheme = _ref3[1];
|
|
154
150
|
|
|
155
151
|
var _cssVarsParser2 = cssVarsParser(scheme, {
|
|
156
|
-
prefix:
|
|
157
|
-
basePrefix: designSystemPrefix,
|
|
152
|
+
prefix: cssVarPrefix,
|
|
158
153
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
159
154
|
}),
|
|
160
155
|
css = _cssVarsParser2.css,
|
|
@@ -322,9 +317,9 @@ export default function createCssVarsProvider(options) {
|
|
|
322
317
|
modeStorageKey: PropTypes.string,
|
|
323
318
|
|
|
324
319
|
/**
|
|
325
|
-
* CSS
|
|
320
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
326
321
|
*/
|
|
327
|
-
|
|
322
|
+
shouldSkipGeneratingVar: PropTypes.func,
|
|
328
323
|
|
|
329
324
|
/**
|
|
330
325
|
* The window that attaches the 'storage' event listener
|
|
@@ -342,7 +337,8 @@ export default function createCssVarsProvider(options) {
|
|
|
342
337
|
return systemGetInitColorSchemeScript(_extends({
|
|
343
338
|
attribute: defaultAttribute,
|
|
344
339
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
345
|
-
modeStorageKey: defaultModeStorageKey
|
|
340
|
+
modeStorageKey: defaultModeStorageKey,
|
|
341
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
346
342
|
}, params));
|
|
347
343
|
};
|
|
348
344
|
|
|
@@ -27,11 +27,11 @@ export default function createGetCssVar() {
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
var getCssVar = function getCssVar(field) {
|
|
30
|
-
for (var _len2 = arguments.length,
|
|
31
|
-
|
|
30
|
+
for (var _len2 = arguments.length, fallbacks = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
31
|
+
fallbacks[_key2 - 1] = arguments[_key2];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0,
|
|
34
|
+
return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, fallbacks), ")");
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
return getCssVar;
|
|
@@ -103,13 +103,9 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
103
103
|
* @param {Object} theme
|
|
104
104
|
* @param {{
|
|
105
105
|
* prefix?: string,
|
|
106
|
-
* basePrefix?: string,
|
|
107
106
|
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
108
107
|
* }} options.
|
|
109
|
-
* `
|
|
110
|
-
* `prefix`: defined by application
|
|
111
|
-
*
|
|
112
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
108
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
113
109
|
*
|
|
114
110
|
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
115
111
|
*
|
|
@@ -120,17 +116,15 @@ var getCssValue = function getCssValue(keys, value) {
|
|
|
120
116
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
121
117
|
* }, { prefix: 'foo' })
|
|
122
118
|
*
|
|
123
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--
|
|
124
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
125
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--
|
|
119
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
120
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
121
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
126
122
|
*/
|
|
127
123
|
|
|
128
124
|
|
|
129
125
|
export default function cssVarsParser(theme, options) {
|
|
130
126
|
var _ref3 = options || {},
|
|
131
127
|
prefix = _ref3.prefix,
|
|
132
|
-
_ref3$basePrefix = _ref3.basePrefix,
|
|
133
|
-
basePrefix = _ref3$basePrefix === void 0 ? '' : _ref3$basePrefix,
|
|
134
128
|
shouldSkipGeneratingVar = _ref3.shouldSkipGeneratingVar;
|
|
135
129
|
|
|
136
130
|
var css = {};
|
|
@@ -138,16 +132,6 @@ export default function cssVarsParser(theme, options) {
|
|
|
138
132
|
var parsedTheme = {};
|
|
139
133
|
walkObjectDeep(theme, function (keys, value, arrayKeys) {
|
|
140
134
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
141
|
-
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
142
|
-
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
143
|
-
if (!basePrefix && prefix) {
|
|
144
|
-
value = value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
|
|
145
|
-
} else {
|
|
146
|
-
value = prefix ? value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
|
|
147
|
-
: value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
135
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
152
136
|
// only create css & var if `shouldSkipGeneratingVar` return false
|
|
153
137
|
var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
|
|
@@ -5,6 +5,8 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
+
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
9
|
+
enableColorScheme = _ref$enableColorSchem === void 0 ? true : _ref$enableColorSchem,
|
|
8
10
|
_ref$enableSystem = _ref.enableSystem,
|
|
9
11
|
enableSystem = _ref$enableSystem === void 0 ? false : _ref$enableSystem,
|
|
10
12
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
@@ -23,7 +25,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
23
25
|
return /*#__PURE__*/_jsx("script", {
|
|
24
26
|
// eslint-disable-next-line react/no-danger
|
|
25
27
|
dangerouslySetInnerHTML: {
|
|
26
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
28
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n cssColorScheme = 'dark';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n cssColorScheme = 'light';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n if (").concat(enableColorScheme, " && !!cssColorScheme) {\n ").concat(colorSchemeNode, ".style.setProperty('color-scheme', cssColorScheme);\n }\n } catch (e) {} })();")
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
}
|
package/legacy/cssVars/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
package/legacy/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes", "components"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
@@ -10,7 +10,6 @@ import cssVarsParser from './cssVarsParser';
|
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
11
11
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
12
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
13
|
-
import createGetCssVar from './createGetCssVar';
|
|
14
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
15
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
@@ -24,8 +23,7 @@ export default function createCssVarsProvider(options) {
|
|
|
24
23
|
defaultColorScheme: designSystemColorScheme,
|
|
25
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
26
25
|
enableColorScheme: designSystemEnableColorScheme = true,
|
|
27
|
-
|
|
28
|
-
shouldSkipGeneratingVar,
|
|
26
|
+
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
29
27
|
resolveTheme
|
|
30
28
|
} = options;
|
|
31
29
|
|
|
@@ -48,7 +46,6 @@ export default function createCssVarsProvider(options) {
|
|
|
48
46
|
function CssVarsProvider({
|
|
49
47
|
children,
|
|
50
48
|
theme: themeProp = defaultTheme,
|
|
51
|
-
prefix = designSystemPrefix,
|
|
52
49
|
modeStorageKey = defaultModeStorageKey,
|
|
53
50
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
54
51
|
attribute = defaultAttribute,
|
|
@@ -59,13 +56,15 @@ export default function createCssVarsProvider(options) {
|
|
|
59
56
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
60
57
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
61
58
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
62
|
-
colorSchemeSelector = ':root'
|
|
59
|
+
colorSchemeSelector = ':root',
|
|
60
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
63
61
|
}) {
|
|
64
62
|
const hasMounted = React.useRef(false);
|
|
65
63
|
|
|
66
64
|
const {
|
|
67
65
|
colorSchemes = {},
|
|
68
|
-
components = {}
|
|
66
|
+
components = {},
|
|
67
|
+
cssVarPrefix
|
|
69
68
|
} = themeProp,
|
|
70
69
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
71
70
|
|
|
@@ -110,16 +109,14 @@ export default function createCssVarsProvider(options) {
|
|
|
110
109
|
vars: rootVars,
|
|
111
110
|
parsedTheme
|
|
112
111
|
} = cssVarsParser(theme, {
|
|
113
|
-
prefix,
|
|
114
|
-
basePrefix: designSystemPrefix,
|
|
112
|
+
prefix: cssVarPrefix,
|
|
115
113
|
shouldSkipGeneratingVar
|
|
116
114
|
});
|
|
117
115
|
theme = _extends({}, parsedTheme, {
|
|
118
116
|
components,
|
|
119
117
|
colorSchemes,
|
|
120
|
-
|
|
118
|
+
cssVarPrefix,
|
|
121
119
|
vars: rootVars,
|
|
122
|
-
getCssVar: createGetCssVar(prefix),
|
|
123
120
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
124
121
|
});
|
|
125
122
|
const defaultColorSchemeStyleSheet = {};
|
|
@@ -130,8 +127,7 @@ export default function createCssVarsProvider(options) {
|
|
|
130
127
|
vars,
|
|
131
128
|
parsedTheme: parsedScheme
|
|
132
129
|
} = cssVarsParser(scheme, {
|
|
133
|
-
prefix,
|
|
134
|
-
basePrefix: designSystemPrefix,
|
|
130
|
+
prefix: cssVarPrefix,
|
|
135
131
|
shouldSkipGeneratingVar
|
|
136
132
|
});
|
|
137
133
|
theme.vars = deepmerge(theme.vars, vars);
|
|
@@ -295,9 +291,9 @@ export default function createCssVarsProvider(options) {
|
|
|
295
291
|
modeStorageKey: PropTypes.string,
|
|
296
292
|
|
|
297
293
|
/**
|
|
298
|
-
* CSS
|
|
294
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
299
295
|
*/
|
|
300
|
-
|
|
296
|
+
shouldSkipGeneratingVar: PropTypes.func,
|
|
301
297
|
|
|
302
298
|
/**
|
|
303
299
|
* The window that attaches the 'storage' event listener
|
|
@@ -314,7 +310,8 @@ export default function createCssVarsProvider(options) {
|
|
|
314
310
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
315
311
|
attribute: defaultAttribute,
|
|
316
312
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
317
|
-
modeStorageKey: defaultModeStorageKey
|
|
313
|
+
modeStorageKey: defaultModeStorageKey,
|
|
314
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
318
315
|
}, params));
|
|
319
316
|
|
|
320
317
|
return {
|
|
@@ -18,8 +18,8 @@ export default function createGetCssVar(prefix = '') {
|
|
|
18
18
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
const getCssVar = (field, ...
|
|
22
|
-
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...
|
|
21
|
+
const getCssVar = (field, ...fallbacks) => {
|
|
22
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return getCssVar;
|
|
@@ -88,13 +88,9 @@ const getCssValue = (keys, value) => {
|
|
|
88
88
|
* @param {Object} theme
|
|
89
89
|
* @param {{
|
|
90
90
|
* prefix?: string,
|
|
91
|
-
* basePrefix?: string,
|
|
92
91
|
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
93
92
|
* }} options.
|
|
94
|
-
* `
|
|
95
|
-
* `prefix`: defined by application
|
|
96
|
-
*
|
|
97
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
93
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
98
94
|
*
|
|
99
95
|
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
100
96
|
*
|
|
@@ -105,16 +101,15 @@ const getCssValue = (keys, value) => {
|
|
|
105
101
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
106
102
|
* }, { prefix: 'foo' })
|
|
107
103
|
*
|
|
108
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--
|
|
109
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
110
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--
|
|
104
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
105
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
106
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
111
107
|
*/
|
|
112
108
|
|
|
113
109
|
|
|
114
110
|
export default function cssVarsParser(theme, options) {
|
|
115
111
|
const {
|
|
116
112
|
prefix,
|
|
117
|
-
basePrefix = '',
|
|
118
113
|
shouldSkipGeneratingVar
|
|
119
114
|
} = options || {};
|
|
120
115
|
const css = {};
|
|
@@ -122,16 +117,6 @@ export default function cssVarsParser(theme, options) {
|
|
|
122
117
|
const parsedTheme = {};
|
|
123
118
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
124
119
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
125
|
-
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
126
|
-
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
127
|
-
if (!basePrefix && prefix) {
|
|
128
|
-
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
129
|
-
} else {
|
|
130
|
-
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
131
|
-
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
120
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
136
121
|
// only create css & var if `shouldSkipGeneratingVar` return false
|
|
137
122
|
const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
|
|
@@ -5,6 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
+
enableColorScheme = true,
|
|
8
9
|
enableSystem = false,
|
|
9
10
|
defaultLightColorScheme = 'light',
|
|
10
11
|
defaultDarkColorScheme = 'dark',
|
|
@@ -18,13 +19,16 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
19
|
dangerouslySetInnerHTML: {
|
|
19
20
|
__html: `(function() { try {
|
|
20
21
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
22
|
+
var cssColorScheme = mode;
|
|
21
23
|
var colorScheme = '';
|
|
22
24
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
23
25
|
// handle system mode
|
|
24
26
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
25
27
|
if (mql.matches) {
|
|
28
|
+
cssColorScheme = 'dark';
|
|
26
29
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
27
30
|
} else {
|
|
31
|
+
cssColorScheme = 'light';
|
|
28
32
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -37,6 +41,9 @@ export default function getInitColorSchemeScript(options) {
|
|
|
37
41
|
if (colorScheme) {
|
|
38
42
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
39
43
|
}
|
|
44
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
+
}
|
|
40
47
|
} catch (e) {} })();`
|
|
41
48
|
}
|
|
42
49
|
});
|
package/modern/cssVars/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.17.2",
|
|
47
|
-
"@mui/private-theming": "^5.8.
|
|
48
|
-
"@mui/styled-engine": "^5.8.
|
|
47
|
+
"@mui/private-theming": "^5.8.6",
|
|
48
|
+
"@mui/styled-engine": "^5.8.7",
|
|
49
49
|
"@mui/types": "^7.1.4",
|
|
50
|
-
"@mui/utils": "^5.8.
|
|
51
|
-
"clsx": "^1.
|
|
50
|
+
"@mui/utils": "^5.8.6",
|
|
51
|
+
"clsx": "^1.2.0",
|
|
52
52
|
"csstype": "^3.1.0",
|
|
53
53
|
"prop-types": "^15.8.1"
|
|
54
54
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|