@mui/system 5.10.8 → 5.10.10

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +208 -19
  2. package/Unstable_Grid/createGrid.js +1 -1
  3. package/Unstable_Grid/gridGenerator.d.ts +3 -1
  4. package/Unstable_Grid/gridGenerator.js +16 -2
  5. package/cssVars/createCssVarsProvider.d.ts +0 -5
  6. package/cssVars/createCssVarsProvider.js +45 -44
  7. package/cssVars/cssVarsParser.js +1 -1
  8. package/cssVars/getInitColorSchemeScript.d.ts +0 -5
  9. package/cssVars/getInitColorSchemeScript.js +0 -4
  10. package/esm/Unstable_Grid/createGrid.js +2 -2
  11. package/esm/Unstable_Grid/gridGenerator.js +11 -0
  12. package/esm/cssVars/createCssVarsProvider.js +47 -45
  13. package/esm/cssVars/cssVarsParser.js +1 -1
  14. package/esm/cssVars/getInitColorSchemeScript.js +0 -4
  15. package/esm/palette.js +15 -3
  16. package/esm/style.js +1 -1
  17. package/index.js +1 -1
  18. package/legacy/Unstable_Grid/createGrid.js +2 -2
  19. package/legacy/Unstable_Grid/gridGenerator.js +17 -0
  20. package/legacy/cssVars/createCssVarsProvider.js +45 -47
  21. package/legacy/cssVars/cssVarsParser.js +1 -1
  22. package/legacy/cssVars/getInitColorSchemeScript.js +1 -3
  23. package/legacy/index.js +1 -1
  24. package/legacy/palette.js +15 -3
  25. package/legacy/style.js +1 -1
  26. package/modern/Unstable_Grid/createGrid.js +2 -2
  27. package/modern/Unstable_Grid/gridGenerator.js +11 -0
  28. package/modern/cssVars/createCssVarsProvider.js +47 -45
  29. package/modern/cssVars/cssVarsParser.js +1 -1
  30. package/modern/cssVars/getInitColorSchemeScript.js +0 -4
  31. package/modern/index.js +1 -1
  32. package/modern/palette.js +15 -3
  33. package/modern/style.js +1 -1
  34. package/package.json +3 -3
  35. package/palette.js +14 -3
  36. package/style.d.ts +4 -1
  37. package/style.js +1 -1
@@ -4,7 +4,7 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
4
4
  const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
- import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
7
+ import { deepmerge } from '@mui/utils';
8
8
  import { GlobalStyles } from '@mui/styled-engine';
9
9
  import cssVarsParser from './cssVarsParser';
10
10
  import ThemeProvider from '../ThemeProvider';
@@ -19,10 +19,9 @@ export default function createCssVarsProvider(options) {
19
19
  attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
20
20
  modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
21
21
  colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
22
- defaultMode: desisgnSystemMode = 'light',
22
+ defaultMode: designSystemMode = 'light',
23
23
  defaultColorScheme: designSystemColorScheme,
24
24
  disableTransitionOnChange: designSystemTransitionOnChange = false,
25
- enableColorScheme: designSystemEnableColorScheme = true,
26
25
  shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
27
26
  resolveTheme,
28
27
  excludeVariablesFromRoot
@@ -50,10 +49,9 @@ export default function createCssVarsProvider(options) {
50
49
  modeStorageKey = defaultModeStorageKey,
51
50
  colorSchemeStorageKey = defaultColorSchemeStorageKey,
52
51
  attribute = defaultAttribute,
53
- defaultMode = desisgnSystemMode,
52
+ defaultMode = designSystemMode,
54
53
  defaultColorScheme = designSystemColorScheme,
55
54
  disableTransitionOnChange = designSystemTransitionOnChange,
56
- enableColorScheme = designSystemEnableColorScheme,
57
55
  storageWindow = typeof window === 'undefined' ? undefined : window,
58
56
  documentNode = typeof document === 'undefined' ? undefined : document,
59
57
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
@@ -71,7 +69,8 @@ export default function createCssVarsProvider(options) {
71
69
 
72
70
  const allColorSchemes = Object.keys(colorSchemes);
73
71
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
74
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
72
+ const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
73
+
75
74
  const {
76
75
  mode,
77
76
  setMode,
@@ -90,36 +89,54 @@ export default function createCssVarsProvider(options) {
90
89
  storageWindow
91
90
  });
92
91
 
93
- const resolvedColorScheme = (() => {
92
+ const calculatedMode = (() => {
93
+ if (!mode) {
94
+ // This scope occurs on the server
95
+ if (defaultMode === 'system') {
96
+ return designSystemMode;
97
+ }
98
+
99
+ return defaultMode;
100
+ }
101
+
102
+ return mode;
103
+ })();
104
+
105
+ const calculatedColorScheme = (() => {
94
106
  if (!colorScheme) {
95
107
  // This scope occurs on the server
96
- if (defaultMode === 'dark') {
108
+ if (calculatedMode === 'dark') {
97
109
  return defaultDarkColorScheme;
98
- } // use light color scheme, if default mode is 'light' | 'auto'
110
+ } // use light color scheme, if default mode is 'light' | 'system'
99
111
 
100
112
 
101
113
  return defaultLightColorScheme;
102
114
  }
103
115
 
104
116
  return colorScheme;
105
- })();
117
+ })(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
118
+
106
119
 
107
- let theme = restThemeProp;
108
120
  const {
109
121
  css: rootCss,
110
122
  vars: rootVars,
111
123
  parsedTheme
112
- } = cssVarsParser(theme, {
124
+ } = cssVarsParser(restThemeProp, {
113
125
  prefix: cssVarPrefix,
114
126
  shouldSkipGeneratingVar
115
- });
116
- theme = _extends({}, parsedTheme, {
127
+ }); // 3. Start composing the theme object
128
+
129
+ let theme = _extends({}, parsedTheme, {
117
130
  components,
118
131
  colorSchemes,
119
132
  cssVarPrefix,
120
133
  vars: rootVars,
121
134
  getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
122
- });
135
+ }); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
136
+ // The default color scheme stylesheet is constructed to have the least CSS specificity.
137
+ // 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.
138
+
139
+
123
140
  const defaultColorSchemeStyleSheet = {};
124
141
  const otherColorSchemesStyleSheet = {};
125
142
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -133,13 +150,12 @@ export default function createCssVarsProvider(options) {
133
150
  });
134
151
  theme.vars = deepmerge(theme.vars, vars);
135
152
 
136
- if (key === resolvedColorScheme) {
153
+ if (key === calculatedColorScheme) {
154
+ // 4.1 Merge the selected color scheme to the theme
137
155
  theme = _extends({}, theme, parsedScheme);
138
156
 
139
157
  if (theme.palette) {
140
- // assign runtime mode & colorScheme
141
- theme.palette.mode = mode;
142
- theme.palette.colorScheme = resolvedColorScheme;
158
+ theme.palette.colorScheme = key;
143
159
  }
144
160
  }
145
161
 
@@ -169,35 +185,21 @@ export default function createCssVarsProvider(options) {
169
185
  } else {
170
186
  otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
171
187
  }
172
- });
188
+ }); // 5. Declaring effects
189
+ // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
190
+
173
191
  React.useEffect(() => {
174
192
  if (colorScheme && colorSchemeNode) {
175
193
  // attaches attribute to <html> because the css variables are attached to :root (html)
176
194
  colorSchemeNode.setAttribute(attribute, colorScheme);
177
195
  }
178
- }, [colorScheme, attribute, colorSchemeNode]);
179
- useEnhancedEffect(() => {
180
- if (!mode || !enableColorScheme || !colorSchemeNode) {
181
- return undefined;
182
- }
183
-
184
- const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
185
-
186
- if (mode === 'system') {
187
- colorSchemeNode.style.setProperty('color-scheme', systemMode);
188
- } else {
189
- colorSchemeNode.style.setProperty('color-scheme', mode);
190
- }
196
+ }, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
197
+ // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
191
198
 
192
- return () => {
193
- colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
194
- };
195
- }, [mode, systemMode, enableColorScheme, colorSchemeNode]);
196
199
  React.useEffect(() => {
197
200
  let timer;
198
201
 
199
202
  if (disableTransitionOnChange && hasMounted.current && documentNode) {
200
- // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
201
203
  const css = documentNode.createElement('style');
202
204
  css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
203
205
  documentNode.head.appendChild(css); // Force browser repaint
@@ -222,6 +224,7 @@ export default function createCssVarsProvider(options) {
222
224
  return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
223
225
  value: {
224
226
  mode,
227
+ systemMode,
225
228
  setMode,
226
229
  lightColorScheme,
227
230
  darkColorScheme,
@@ -290,11 +293,6 @@ export default function createCssVarsProvider(options) {
290
293
  */
291
294
  documentNode: PropTypes.any,
292
295
 
293
- /**
294
- * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
295
- */
296
- enableColorScheme: PropTypes.bool,
297
-
298
296
  /**
299
297
  * The key in the local storage used to store current color scheme.
300
298
  */
@@ -316,12 +314,16 @@ export default function createCssVarsProvider(options) {
316
314
  */
317
315
  theme: PropTypes.object
318
316
  } : void 0;
317
+ const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
318
+ const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
319
319
 
320
320
  const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
321
321
  attribute: defaultAttribute,
322
322
  colorSchemeStorageKey: defaultColorSchemeStorageKey,
323
- modeStorageKey: defaultModeStorageKey,
324
- enableColorScheme: designSystemEnableColorScheme
323
+ defaultMode: designSystemMode,
324
+ defaultLightColorScheme,
325
+ defaultDarkColorScheme,
326
+ modeStorageKey: defaultModeStorageKey
325
327
  }, params));
326
328
 
327
329
  return {
@@ -117,7 +117,7 @@ export default function cssVarsParser(theme, options) {
117
117
  const parsedTheme = {};
118
118
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
119
119
  if (typeof value === 'string' || typeof value === 'number') {
120
- if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
120
+ if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
121
121
  // only create css & var if `shouldSkipGeneratingVar` return false
122
122
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
123
123
  Object.assign(css, {
@@ -5,7 +5,6 @@ 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,
9
8
  defaultMode = 'light',
10
9
  defaultLightColorScheme = 'light',
11
10
  defaultDarkColorScheme = 'dark',
@@ -41,9 +40,6 @@ export default function getInitColorSchemeScript(options) {
41
40
  if (colorScheme) {
42
41
  ${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
43
42
  }
44
- if (${enableColorScheme} && !!cssColorScheme) {
45
- ${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
46
- }
47
43
  } catch (e) {} })();`
48
44
  }
49
45
  });
package/esm/palette.js CHANGED
@@ -1,17 +1,29 @@
1
1
  import style from './style';
2
2
  import compose from './compose';
3
+
4
+ function transform(value, userValue) {
5
+ if (userValue === 'grey') {
6
+ return userValue;
7
+ }
8
+
9
+ return value;
10
+ }
11
+
3
12
  export const color = style({
4
13
  prop: 'color',
5
- themeKey: 'palette'
14
+ themeKey: 'palette',
15
+ transform
6
16
  });
7
17
  export const bgcolor = style({
8
18
  prop: 'bgcolor',
9
19
  cssProperty: 'backgroundColor',
10
- themeKey: 'palette'
20
+ themeKey: 'palette',
21
+ transform
11
22
  });
12
23
  export const backgroundColor = style({
13
24
  prop: 'backgroundColor',
14
- themeKey: 'palette'
25
+ themeKey: 'palette',
26
+ transform
15
27
  });
16
28
  const palette = compose(color, bgcolor, backgroundColor);
17
29
  export default palette;
package/esm/style.js CHANGED
@@ -36,7 +36,7 @@ function getValue(themeMapping, transform, propValueFinal, userValue = propValue
36
36
  }
37
37
 
38
38
  if (transform) {
39
- value = transform(value);
39
+ value = transform(value, userValue);
40
40
  }
41
41
 
42
42
  return value;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.8
1
+ /** @license MUI v5.10.10
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -11,7 +11,7 @@ import useThemePropsSystem from '../useThemeProps';
11
11
  import useTheme from '../useTheme';
12
12
  import { extendSxProp } from '../styleFunctionSx';
13
13
  import createTheme from '../createTheme';
14
- import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
14
+ import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  var defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
17
17
 
@@ -49,7 +49,7 @@ export default function createGrid() {
49
49
  wrap = ownerState.wrap,
50
50
  gridSize = ownerState.gridSize;
51
51
  var slots = {
52
- root: ['root', container && 'container', direction !== 'row' && "direction-xs-".concat(String(direction)), wrap !== 'wrap' && "wrap-xs-".concat(String(wrap))].concat(_toConsumableArray(generateSizeClassNames(gridSize)), _toConsumableArray(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : []))
52
+ root: ['root', container && 'container', wrap !== 'wrap' && "wrap-xs-".concat(String(wrap))].concat(_toConsumableArray(generateDirectionClasses(direction)), _toConsumableArray(generateSizeClassNames(gridSize)), _toConsumableArray(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : []))
53
53
  };
54
54
  return composeClasses(slots, function (slot) {
55
55
  return generateUtilityClass(componentName, slot);
@@ -242,4 +242,21 @@ export var generateSpacingClassNames = function generateSpacingClassNames(spacin
242
242
  }
243
243
 
244
244
  return [];
245
+ };
246
+ export var generateDirectionClasses = function generateDirectionClasses(direction) {
247
+ if (direction === undefined) {
248
+ return [];
249
+ }
250
+
251
+ if (_typeof(direction) === 'object') {
252
+ return Object.entries(direction).map(function (_ref12) {
253
+ var _ref13 = _slicedToArray(_ref12, 2),
254
+ key = _ref13[0],
255
+ value = _ref13[1];
256
+
257
+ return "direction-".concat(key, "-").concat(value);
258
+ });
259
+ }
260
+
261
+ return ["direction-xs-".concat(String(direction))];
245
262
  };
@@ -6,7 +6,7 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
6
6
  import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
7
7
  import * as React from 'react';
8
8
  import PropTypes from 'prop-types';
9
- import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
9
+ import { deepmerge } from '@mui/utils';
10
10
  import { GlobalStyles } from '@mui/styled-engine';
11
11
  import cssVarsParser from './cssVarsParser';
12
12
  import ThemeProvider from '../ThemeProvider';
@@ -25,12 +25,10 @@ export default function createCssVarsProvider(options) {
25
25
  _options$colorSchemeS = options.colorSchemeStorageKey,
26
26
  defaultColorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS,
27
27
  _options$defaultMode = options.defaultMode,
28
- desisgnSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
28
+ designSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
29
29
  designSystemColorScheme = options.defaultColorScheme,
30
30
  _options$disableTrans = options.disableTransitionOnChange,
31
31
  designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
32
- _options$enableColorS = options.enableColorScheme,
33
- designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
34
32
  designSystemShouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
35
33
  resolveTheme = options.resolveTheme,
36
34
  excludeVariablesFromRoot = options.excludeVariablesFromRoot;
@@ -62,13 +60,11 @@ export default function createCssVarsProvider(options) {
62
60
  _ref$attribute = _ref.attribute,
63
61
  attribute = _ref$attribute === void 0 ? defaultAttribute : _ref$attribute,
64
62
  _ref$defaultMode = _ref.defaultMode,
65
- defaultMode = _ref$defaultMode === void 0 ? desisgnSystemMode : _ref$defaultMode,
63
+ defaultMode = _ref$defaultMode === void 0 ? designSystemMode : _ref$defaultMode,
66
64
  _ref$defaultColorSche = _ref.defaultColorScheme,
67
65
  defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche,
68
66
  _ref$disableTransitio = _ref.disableTransitionOnChange,
69
67
  disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
70
- _ref$enableColorSchem = _ref.enableColorScheme,
71
- enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem,
72
68
  _ref$storageWindow = _ref.storageWindow,
73
69
  storageWindow = _ref$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _ref$storageWindow,
74
70
  _ref$documentNode = _ref.documentNode,
@@ -90,7 +86,7 @@ export default function createCssVarsProvider(options) {
90
86
 
91
87
  var allColorSchemes = Object.keys(colorSchemes);
92
88
  var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
93
- var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
89
+ var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
94
90
 
95
91
  var _useCurrentColorSchem = useCurrentColorScheme({
96
92
  supportedColorSchemes: allColorSchemes,
@@ -109,31 +105,44 @@ export default function createCssVarsProvider(options) {
109
105
  colorScheme = _useCurrentColorSchem.colorScheme,
110
106
  setColorScheme = _useCurrentColorSchem.setColorScheme;
111
107
 
112
- var resolvedColorScheme = function () {
108
+ var calculatedMode = function () {
109
+ if (!mode) {
110
+ // This scope occurs on the server
111
+ if (defaultMode === 'system') {
112
+ return designSystemMode;
113
+ }
114
+
115
+ return defaultMode;
116
+ }
117
+
118
+ return mode;
119
+ }();
120
+
121
+ var calculatedColorScheme = function () {
113
122
  if (!colorScheme) {
114
123
  // This scope occurs on the server
115
- if (defaultMode === 'dark') {
124
+ if (calculatedMode === 'dark') {
116
125
  return defaultDarkColorScheme;
117
- } // use light color scheme, if default mode is 'light' | 'auto'
126
+ } // use light color scheme, if default mode is 'light' | 'system'
118
127
 
119
128
 
120
129
  return defaultLightColorScheme;
121
130
  }
122
131
 
123
132
  return colorScheme;
124
- }();
133
+ }(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
125
134
 
126
- var theme = restThemeProp;
127
135
 
128
- var _cssVarsParser = cssVarsParser(theme, {
136
+ var _cssVarsParser = cssVarsParser(restThemeProp, {
129
137
  prefix: cssVarPrefix,
130
138
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
131
139
  }),
132
140
  rootCss = _cssVarsParser.css,
133
141
  rootVars = _cssVarsParser.vars,
134
- parsedTheme = _cssVarsParser.parsedTheme;
142
+ parsedTheme = _cssVarsParser.parsedTheme; // 3. Start composing the theme object
135
143
 
136
- theme = _extends({}, parsedTheme, {
144
+
145
+ var theme = _extends({}, parsedTheme, {
137
146
  components: components,
138
147
  colorSchemes: colorSchemes,
139
148
  cssVarPrefix: cssVarPrefix,
@@ -141,7 +150,11 @@ export default function createCssVarsProvider(options) {
141
150
  getColorSchemeSelector: function getColorSchemeSelector(targetColorScheme) {
142
151
  return "[".concat(attribute, "=\"").concat(targetColorScheme, "\"] &");
143
152
  }
144
- });
153
+ }); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
154
+ // The default color scheme stylesheet is constructed to have the least CSS specificity.
155
+ // 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.
156
+
157
+
145
158
  var defaultColorSchemeStyleSheet = {};
146
159
  var otherColorSchemesStyleSheet = {};
147
160
  Object.entries(colorSchemes).forEach(function (_ref2) {
@@ -159,13 +172,12 @@ export default function createCssVarsProvider(options) {
159
172
 
160
173
  theme.vars = deepmerge(theme.vars, vars);
161
174
 
162
- if (key === resolvedColorScheme) {
175
+ if (key === calculatedColorScheme) {
176
+ // 4.1 Merge the selected color scheme to the theme
163
177
  theme = _extends({}, theme, parsedScheme);
164
178
 
165
179
  if (theme.palette) {
166
- // assign runtime mode & colorScheme
167
- theme.palette.mode = mode;
168
- theme.palette.colorScheme = resolvedColorScheme;
180
+ theme.palette.colorScheme = key;
169
181
  }
170
182
  }
171
183
 
@@ -195,35 +207,21 @@ export default function createCssVarsProvider(options) {
195
207
  } else {
196
208
  otherColorSchemesStyleSheet["".concat(colorSchemeSelector === ':root' ? '' : colorSchemeSelector, "[").concat(attribute, "=\"").concat(key, "\"]")] = css;
197
209
  }
198
- });
210
+ }); // 5. Declaring effects
211
+ // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
212
+
199
213
  React.useEffect(function () {
200
214
  if (colorScheme && colorSchemeNode) {
201
215
  // attaches attribute to <html> because the css variables are attached to :root (html)
202
216
  colorSchemeNode.setAttribute(attribute, colorScheme);
203
217
  }
204
- }, [colorScheme, attribute, colorSchemeNode]);
205
- useEnhancedEffect(function () {
206
- if (!mode || !enableColorScheme || !colorSchemeNode) {
207
- return undefined;
208
- }
218
+ }, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
219
+ // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
209
220
 
210
- var priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
211
-
212
- if (mode === 'system') {
213
- colorSchemeNode.style.setProperty('color-scheme', systemMode);
214
- } else {
215
- colorSchemeNode.style.setProperty('color-scheme', mode);
216
- }
217
-
218
- return function () {
219
- colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
220
- };
221
- }, [mode, systemMode, enableColorScheme, colorSchemeNode]);
222
221
  React.useEffect(function () {
223
222
  var timer;
224
223
 
225
224
  if (disableTransitionOnChange && hasMounted.current && documentNode) {
226
- // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
227
225
  var css = documentNode.createElement('style');
228
226
  css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
229
227
  documentNode.head.appendChild(css); // Force browser repaint
@@ -250,6 +248,7 @@ export default function createCssVarsProvider(options) {
250
248
  return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
251
249
  value: {
252
250
  mode: mode,
251
+ systemMode: systemMode,
253
252
  setMode: setMode,
254
253
  lightColorScheme: lightColorScheme,
255
254
  darkColorScheme: darkColorScheme,
@@ -316,11 +315,6 @@ export default function createCssVarsProvider(options) {
316
315
  */
317
316
  documentNode: PropTypes.any,
318
317
 
319
- /**
320
- * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
321
- */
322
- enableColorScheme: PropTypes.bool,
323
-
324
318
  /**
325
319
  * The key in the local storage used to store current color scheme.
326
320
  */
@@ -342,13 +336,17 @@ export default function createCssVarsProvider(options) {
342
336
  */
343
337
  theme: PropTypes.object
344
338
  } : void 0;
339
+ var defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
340
+ var defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
345
341
 
346
342
  var getInitColorSchemeScript = function getInitColorSchemeScript(params) {
347
343
  return systemGetInitColorSchemeScript(_extends({
348
344
  attribute: defaultAttribute,
349
345
  colorSchemeStorageKey: defaultColorSchemeStorageKey,
350
- modeStorageKey: defaultModeStorageKey,
351
- enableColorScheme: designSystemEnableColorScheme
346
+ defaultMode: designSystemMode,
347
+ defaultLightColorScheme: defaultLightColorScheme,
348
+ defaultDarkColorScheme: defaultDarkColorScheme,
349
+ modeStorageKey: defaultModeStorageKey
352
350
  }, params));
353
351
  };
354
352
 
@@ -132,7 +132,7 @@ export default function cssVarsParser(theme, options) {
132
132
  var parsedTheme = {};
133
133
  walkObjectDeep(theme, function (keys, value, arrayKeys) {
134
134
  if (typeof value === 'string' || typeof value === 'number') {
135
- if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
135
+ if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
136
136
  // only create css & var if `shouldSkipGeneratingVar` return false
137
137
  var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
138
138
 
@@ -5,8 +5,6 @@ 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,
10
8
  _ref$defaultMode = _ref.defaultMode,
11
9
  defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
12
10
  _ref$defaultLightColo = _ref.defaultLightColorScheme,
@@ -25,7 +23,7 @@ export default function getInitColorSchemeScript(options) {
25
23
  return /*#__PURE__*/_jsx("script", {
26
24
  // eslint-disable-next-line react/no-danger
27
25
  dangerouslySetInnerHTML: {
28
- __html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system') {\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) {} })();")
26
+ __html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system') {\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 } catch (e) {} })();")
29
27
  }
30
28
  });
31
29
  }
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.8
1
+ /** @license MUI v5.10.10
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/legacy/palette.js CHANGED
@@ -1,17 +1,29 @@
1
1
  import style from './style';
2
2
  import compose from './compose';
3
+
4
+ function transform(value, userValue) {
5
+ if (userValue === 'grey') {
6
+ return userValue;
7
+ }
8
+
9
+ return value;
10
+ }
11
+
3
12
  export var color = style({
4
13
  prop: 'color',
5
- themeKey: 'palette'
14
+ themeKey: 'palette',
15
+ transform: transform
6
16
  });
7
17
  export var bgcolor = style({
8
18
  prop: 'bgcolor',
9
19
  cssProperty: 'backgroundColor',
10
- themeKey: 'palette'
20
+ themeKey: 'palette',
21
+ transform: transform
11
22
  });
12
23
  export var backgroundColor = style({
13
24
  prop: 'backgroundColor',
14
- themeKey: 'palette'
25
+ themeKey: 'palette',
26
+ transform: transform
15
27
  });
16
28
  var palette = compose(color, bgcolor, backgroundColor);
17
29
  export default palette;
package/legacy/style.js CHANGED
@@ -42,7 +42,7 @@ function getValue(themeMapping, transform, propValueFinal) {
42
42
  }
43
43
 
44
44
  if (transform) {
45
- value = transform(value);
45
+ value = transform(value, userValue);
46
46
  }
47
47
 
48
48
  return value;
@@ -10,7 +10,7 @@ import useThemePropsSystem from '../useThemeProps';
10
10
  import useTheme from '../useTheme';
11
11
  import { extendSxProp } from '../styleFunctionSx';
12
12
  import createTheme from '../createTheme';
13
- import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
13
+ import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
16
16
 
@@ -47,7 +47,7 @@ export default function createGrid(options = {}) {
47
47
  gridSize
48
48
  } = ownerState;
49
49
  const slots = {
50
- root: ['root', container && 'container', direction !== 'row' && `direction-xs-${String(direction)}`, wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
50
+ root: ['root', container && 'container', wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateDirectionClasses(direction), ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
51
51
  };
52
52
  return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
53
53
  };
@@ -229,4 +229,15 @@ export const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') =>
229
229
  }
230
230
 
231
231
  return [];
232
+ };
233
+ export const generateDirectionClasses = direction => {
234
+ if (direction === undefined) {
235
+ return [];
236
+ }
237
+
238
+ if (typeof direction === 'object') {
239
+ return Object.entries(direction).map(([key, value]) => `direction-${key}-${value}`);
240
+ }
241
+
242
+ return [`direction-xs-${String(direction)}`];
232
243
  };