@mui/system 5.10.15 → 5.10.17

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.
@@ -1,4 +1,4 @@
1
- declare type NestedRecord<V = any> = {
1
+ type NestedRecord<V = any> = {
2
2
  [k: string | number]: NestedRecord<V> | V;
3
3
  };
4
4
  /**
@@ -41,10 +41,10 @@ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, ca
41
41
  * }} options.
42
42
  * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
43
43
  *
44
- * @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.
44
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
45
45
  *
46
46
  * @example
47
- * const { css, vars, parsedTheme } = parser({
47
+ * const { css, vars } = parser({
48
48
  * fontSize: 12,
49
49
  * lineHeight: 1.2,
50
50
  * palette: { primary: { 500: 'var(--color)' } }
@@ -52,7 +52,6 @@ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, ca
52
52
  *
53
53
  * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
54
54
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
55
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
56
55
  */
57
56
  export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
58
57
  prefix?: string;
@@ -60,6 +59,5 @@ export default function cssVarsParser<T extends Record<string, any>>(theme: T, o
60
59
  }): {
61
60
  css: Record<string, string | number>;
62
61
  vars: NestedRecord<string>;
63
- parsedTheme: T;
64
62
  };
65
63
  export {};
@@ -96,10 +96,10 @@ const getCssValue = (keys, value) => {
96
96
  * }} options.
97
97
  * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
98
98
  *
99
- * @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.
99
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
100
100
  *
101
101
  * @example
102
- * const { css, vars, parsedTheme } = parser({
102
+ * const { css, vars } = parser({
103
103
  * fontSize: 12,
104
104
  * lineHeight: 1.2,
105
105
  * palette: { primary: { 500: 'var(--color)' } }
@@ -107,7 +107,6 @@ const getCssValue = (keys, value) => {
107
107
  *
108
108
  * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
109
109
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
110
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
111
110
  */
112
111
  function cssVarsParser(theme, options) {
113
112
  const {
@@ -116,7 +115,6 @@ function cssVarsParser(theme, options) {
116
115
  } = options || {};
117
116
  const css = {};
118
117
  const vars = {};
119
- const parsedTheme = {};
120
118
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
121
119
  if (typeof value === 'string' || typeof value === 'number') {
122
120
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
@@ -128,13 +126,11 @@ function cssVarsParser(theme, options) {
128
126
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
129
127
  }
130
128
  }
131
- assignNestedKeys(parsedTheme, keys, value, arrayKeys);
132
129
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
133
130
  );
134
131
 
135
132
  return {
136
133
  css,
137
- vars,
138
- parsedTheme
134
+ vars
139
135
  };
140
136
  }
@@ -1,5 +1,5 @@
1
- export declare type Mode = 'light' | 'dark' | 'system';
2
- export declare type SystemMode = Exclude<Mode, 'system'>;
1
+ export type Mode = 'light' | 'dark' | 'system';
2
+ export type SystemMode = Exclude<Mode, 'system'>;
3
3
  export interface State<SupportedColorScheme extends string> {
4
4
  /**
5
5
  * User selected mode.
@@ -19,7 +19,7 @@ export interface State<SupportedColorScheme extends string> {
19
19
  */
20
20
  darkColorScheme: SupportedColorScheme;
21
21
  }
22
- export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
22
+ export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
23
  /**
24
24
  * The current application color scheme. It is always `undefined` on the server.
25
25
  */
@@ -90,6 +90,16 @@ export const colorChannel = color => {
90
90
  const decomposedColor = decomposeColor(color);
91
91
  return decomposedColor.values.slice(0, 3).map((val, idx) => decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? `${val}%` : val).join(' ');
92
92
  };
93
+ export const private_safeColorChannel = (color, warning) => {
94
+ try {
95
+ return colorChannel(color);
96
+ } catch (error) {
97
+ if (warning && process.env.NODE_ENV !== 'production') {
98
+ console.warn(warning);
99
+ }
100
+ return color;
101
+ }
102
+ };
93
103
 
94
104
  /**
95
105
  * Converts a color object with type and values to a string.
@@ -220,6 +230,16 @@ export function alpha(color, value) {
220
230
  }
221
231
  return recomposeColor(color);
222
232
  }
233
+ export function private_safeAlpha(color, value, warning) {
234
+ try {
235
+ return alpha(color, value);
236
+ } catch (error) {
237
+ if (warning && process.env.NODE_ENV !== 'production') {
238
+ console.warn(warning);
239
+ }
240
+ return color;
241
+ }
242
+ }
223
243
 
224
244
  /**
225
245
  * Darkens a color.
@@ -239,6 +259,16 @@ export function darken(color, coefficient) {
239
259
  }
240
260
  return recomposeColor(color);
241
261
  }
262
+ export function private_safeDarken(color, coefficient, warning) {
263
+ try {
264
+ return darken(color, coefficient);
265
+ } catch (error) {
266
+ if (warning && process.env.NODE_ENV !== 'production') {
267
+ console.warn(warning);
268
+ }
269
+ return color;
270
+ }
271
+ }
242
272
 
243
273
  /**
244
274
  * Lightens a color.
@@ -262,6 +292,16 @@ export function lighten(color, coefficient) {
262
292
  }
263
293
  return recomposeColor(color);
264
294
  }
295
+ export function private_safeLighten(color, coefficient, warning) {
296
+ try {
297
+ return lighten(color, coefficient);
298
+ } catch (error) {
299
+ if (warning && process.env.NODE_ENV !== 'production') {
300
+ console.warn(warning);
301
+ }
302
+ return color;
303
+ }
304
+ }
265
305
 
266
306
  /**
267
307
  * Darken or lighten a color, depending on its luminance.
@@ -272,4 +312,14 @@ export function lighten(color, coefficient) {
272
312
  */
273
313
  export function emphasize(color, coefficient = 0.15) {
274
314
  return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
315
+ }
316
+ export function private_safeEmphasize(color, coefficient, warning) {
317
+ try {
318
+ return private_safeEmphasize(color, coefficient);
319
+ } catch (error) {
320
+ if (warning && process.env.NODE_ENV !== 'production') {
321
+ console.warn(warning);
322
+ }
323
+ return color;
324
+ }
275
325
  }
@@ -6,6 +6,7 @@ import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { deepmerge } from '@mui/utils';
8
8
  import { GlobalStyles } from '@mui/styled-engine';
9
+ import { useTheme as muiUseTheme } from '@mui/private-theming';
9
10
  import cssVarsParser from './cssVarsParser';
10
11
  import ThemeProvider from '../ThemeProvider';
11
12
  import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
@@ -50,9 +51,14 @@ export default function createCssVarsProvider(options) {
50
51
  documentNode = typeof document === 'undefined' ? undefined : document,
51
52
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
52
53
  colorSchemeSelector = ':root',
53
- shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
54
+ shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
55
+ disableNestedContext = false,
56
+ disableStyleSheetGeneration = false
54
57
  }) {
55
58
  const hasMounted = React.useRef(false);
59
+ const upperTheme = muiUseTheme();
60
+ const ctx = React.useContext(ColorSchemeContext);
61
+ const nested = !!ctx && !disableNestedContext;
56
62
  const {
57
63
  colorSchemes = {},
58
64
  components = {},
@@ -65,12 +71,12 @@ export default function createCssVarsProvider(options) {
65
71
 
66
72
  // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
67
73
  const {
68
- mode,
74
+ mode: stateMode,
69
75
  setMode,
70
76
  systemMode,
71
77
  lightColorScheme,
72
78
  darkColorScheme,
73
- colorScheme,
79
+ colorScheme: stateColorScheme,
74
80
  setColorScheme
75
81
  } = useCurrentColorScheme({
76
82
  supportedColorSchemes: allColorSchemes,
@@ -81,6 +87,12 @@ export default function createCssVarsProvider(options) {
81
87
  defaultMode,
82
88
  storageWindow
83
89
  });
90
+ let mode = stateMode;
91
+ let colorScheme = stateColorScheme;
92
+ if (nested) {
93
+ mode = ctx.mode;
94
+ colorScheme = ctx.colorScheme;
95
+ }
84
96
  const calculatedMode = (() => {
85
97
  if (!mode) {
86
98
  // This scope occurs on the server
@@ -106,15 +118,14 @@ export default function createCssVarsProvider(options) {
106
118
  // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
107
119
  const {
108
120
  css: rootCss,
109
- vars: rootVars,
110
- parsedTheme
121
+ vars: rootVars
111
122
  } = cssVarsParser(restThemeProp, {
112
123
  prefix: cssVarPrefix,
113
124
  shouldSkipGeneratingVar
114
125
  });
115
126
 
116
127
  // 3. Start composing the theme object
117
- const theme = _extends({}, parsedTheme, {
128
+ const theme = _extends({}, restThemeProp, {
118
129
  components,
119
130
  colorSchemes,
120
131
  cssVarPrefix,
@@ -130,8 +141,7 @@ export default function createCssVarsProvider(options) {
130
141
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
131
142
  const {
132
143
  css,
133
- vars,
134
- parsedTheme: parsedScheme
144
+ vars
135
145
  } = cssVarsParser(scheme, {
136
146
  prefix: cssVarPrefix,
137
147
  shouldSkipGeneratingVar
@@ -139,12 +149,12 @@ export default function createCssVarsProvider(options) {
139
149
  theme.vars = deepmerge(theme.vars, vars);
140
150
  if (key === calculatedColorScheme) {
141
151
  // 4.1 Merge the selected color scheme to the theme
142
- Object.keys(parsedScheme).forEach(schemeKey => {
143
- if (parsedScheme[schemeKey] && typeof parsedScheme[schemeKey] === 'object') {
152
+ Object.keys(scheme).forEach(schemeKey => {
153
+ if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
144
154
  // shallow merge the 1st level structure of the theme.
145
- theme[schemeKey] = _extends({}, theme[schemeKey], parsedScheme[schemeKey]);
155
+ theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
146
156
  } else {
147
- theme[schemeKey] = parsedScheme[schemeKey];
157
+ theme[schemeKey] = scheme[schemeKey];
148
158
  }
149
159
  });
150
160
  if (theme.palette) {
@@ -219,21 +229,33 @@ export default function createCssVarsProvider(options) {
219
229
  setColorScheme,
220
230
  allColorSchemes
221
231
  }), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
222
- return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
223
- value: contextValue,
224
- children: [/*#__PURE__*/_jsx(GlobalStyles, {
225
- styles: {
226
- [colorSchemeSelector]: rootCss
227
- }
228
- }), /*#__PURE__*/_jsx(GlobalStyles, {
229
- styles: defaultColorSchemeStyleSheet
230
- }), /*#__PURE__*/_jsx(GlobalStyles, {
231
- styles: otherColorSchemesStyleSheet
232
+ let shouldGenerateStyleSheet = true;
233
+ if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
234
+ shouldGenerateStyleSheet = false;
235
+ }
236
+ const element = /*#__PURE__*/_jsxs(React.Fragment, {
237
+ children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
238
+ children: [/*#__PURE__*/_jsx(GlobalStyles, {
239
+ styles: {
240
+ [colorSchemeSelector]: rootCss
241
+ }
242
+ }), /*#__PURE__*/_jsx(GlobalStyles, {
243
+ styles: defaultColorSchemeStyleSheet
244
+ }), /*#__PURE__*/_jsx(GlobalStyles, {
245
+ styles: otherColorSchemesStyleSheet
246
+ })]
232
247
  }), /*#__PURE__*/_jsx(ThemeProvider, {
233
248
  theme: resolveTheme ? resolveTheme(theme) : theme,
234
249
  children: children
235
250
  })]
236
251
  });
252
+ if (nested) {
253
+ return element;
254
+ }
255
+ return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
256
+ value: contextValue,
257
+ children: element
258
+ });
237
259
  }
238
260
  process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
239
261
  /**
@@ -264,6 +286,16 @@ export default function createCssVarsProvider(options) {
264
286
  * The initial mode used.
265
287
  */
266
288
  defaultMode: PropTypes.string,
289
+ /**
290
+ * If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
291
+ */
292
+ disableNestedContext: PropTypes.bool,
293
+ /**
294
+ * If `true`, the style sheet won't be generated.
295
+ *
296
+ * This is useful for controlling nested CssVarsProvider behavior.
297
+ */
298
+ disableStyleSheetGeneration: PropTypes.bool,
267
299
  /**
268
300
  * Disable CSS transitions when switching between modes or color schemes
269
301
  */
@@ -86,10 +86,10 @@ const getCssValue = (keys, value) => {
86
86
  * }} options.
87
87
  * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
88
88
  *
89
- * @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.
89
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
90
90
  *
91
91
  * @example
92
- * const { css, vars, parsedTheme } = parser({
92
+ * const { css, vars } = parser({
93
93
  * fontSize: 12,
94
94
  * lineHeight: 1.2,
95
95
  * palette: { primary: { 500: 'var(--color)' } }
@@ -97,7 +97,6 @@ const getCssValue = (keys, value) => {
97
97
  *
98
98
  * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
99
99
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
100
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
101
100
  */
102
101
  export default function cssVarsParser(theme, options) {
103
102
  const {
@@ -106,7 +105,6 @@ export default function cssVarsParser(theme, options) {
106
105
  } = options || {};
107
106
  const css = {};
108
107
  const vars = {};
109
- const parsedTheme = {};
110
108
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
111
109
  if (typeof value === 'string' || typeof value === 'number') {
112
110
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
@@ -118,13 +116,11 @@ export default function cssVarsParser(theme, options) {
118
116
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
119
117
  }
120
118
  }
121
- assignNestedKeys(parsedTheme, keys, value, arrayKeys);
122
119
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
123
120
  );
124
121
 
125
122
  return {
126
123
  css,
127
- vars,
128
- parsedTheme
124
+ vars
129
125
  };
130
126
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.15
1
+ /** @license MUI v5.10.17
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.
@@ -96,6 +96,16 @@ export var colorChannel = function colorChannel(color) {
96
96
  return decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? "".concat(val, "%") : val;
97
97
  }).join(' ');
98
98
  };
99
+ export var private_safeColorChannel = function private_safeColorChannel(color, warning) {
100
+ try {
101
+ return colorChannel(color);
102
+ } catch (error) {
103
+ if (warning && process.env.NODE_ENV !== 'production') {
104
+ console.warn(warning);
105
+ }
106
+ return color;
107
+ }
108
+ };
99
109
 
100
110
  /**
101
111
  * Converts a color object with type and values to a string.
@@ -227,6 +237,16 @@ export function alpha(color, value) {
227
237
  }
228
238
  return recomposeColor(color);
229
239
  }
240
+ export function private_safeAlpha(color, value, warning) {
241
+ try {
242
+ return alpha(color, value);
243
+ } catch (error) {
244
+ if (warning && process.env.NODE_ENV !== 'production') {
245
+ console.warn(warning);
246
+ }
247
+ return color;
248
+ }
249
+ }
230
250
 
231
251
  /**
232
252
  * Darkens a color.
@@ -246,6 +266,16 @@ export function darken(color, coefficient) {
246
266
  }
247
267
  return recomposeColor(color);
248
268
  }
269
+ export function private_safeDarken(color, coefficient, warning) {
270
+ try {
271
+ return darken(color, coefficient);
272
+ } catch (error) {
273
+ if (warning && process.env.NODE_ENV !== 'production') {
274
+ console.warn(warning);
275
+ }
276
+ return color;
277
+ }
278
+ }
249
279
 
250
280
  /**
251
281
  * Lightens a color.
@@ -269,6 +299,16 @@ export function lighten(color, coefficient) {
269
299
  }
270
300
  return recomposeColor(color);
271
301
  }
302
+ export function private_safeLighten(color, coefficient, warning) {
303
+ try {
304
+ return lighten(color, coefficient);
305
+ } catch (error) {
306
+ if (warning && process.env.NODE_ENV !== 'production') {
307
+ console.warn(warning);
308
+ }
309
+ return color;
310
+ }
311
+ }
272
312
 
273
313
  /**
274
314
  * Darken or lighten a color, depending on its luminance.
@@ -280,4 +320,14 @@ export function lighten(color, coefficient) {
280
320
  export function emphasize(color) {
281
321
  var coefficient = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.15;
282
322
  return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
323
+ }
324
+ export function private_safeEmphasize(color, coefficient, warning) {
325
+ try {
326
+ return private_safeEmphasize(color, coefficient);
327
+ } catch (error) {
328
+ if (warning && process.env.NODE_ENV !== 'production') {
329
+ console.warn(warning);
330
+ }
331
+ return color;
332
+ }
283
333
  }
@@ -8,6 +8,7 @@ import * as React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { deepmerge } from '@mui/utils';
10
10
  import { GlobalStyles } from '@mui/styled-engine';
11
+ import { useTheme as muiUseTheme } from '@mui/private-theming';
11
12
  import cssVarsParser from './cssVarsParser';
12
13
  import ThemeProvider from '../ThemeProvider';
13
14
  import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
@@ -68,8 +69,15 @@ export default function createCssVarsProvider(options) {
68
69
  _ref$colorSchemeSelec = _ref.colorSchemeSelector,
69
70
  colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec,
70
71
  _ref$shouldSkipGenera = _ref.shouldSkipGeneratingVar,
71
- shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera;
72
+ shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera,
73
+ _ref$disableNestedCon = _ref.disableNestedContext,
74
+ disableNestedContext = _ref$disableNestedCon === void 0 ? false : _ref$disableNestedCon,
75
+ _ref$disableStyleShee = _ref.disableStyleSheetGeneration,
76
+ disableStyleSheetGeneration = _ref$disableStyleShee === void 0 ? false : _ref$disableStyleShee;
72
77
  var hasMounted = React.useRef(false);
78
+ var upperTheme = muiUseTheme();
79
+ var ctx = React.useContext(ColorSchemeContext);
80
+ var nested = !!ctx && !disableNestedContext;
73
81
  var _themeProp$colorSchem = themeProp.colorSchemes,
74
82
  colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
75
83
  _themeProp$components = themeProp.components,
@@ -90,13 +98,19 @@ export default function createCssVarsProvider(options) {
90
98
  defaultMode: defaultMode,
91
99
  storageWindow: storageWindow
92
100
  }),
93
- mode = _useCurrentColorSchem.mode,
101
+ stateMode = _useCurrentColorSchem.mode,
94
102
  setMode = _useCurrentColorSchem.setMode,
95
103
  systemMode = _useCurrentColorSchem.systemMode,
96
104
  lightColorScheme = _useCurrentColorSchem.lightColorScheme,
97
105
  darkColorScheme = _useCurrentColorSchem.darkColorScheme,
98
- colorScheme = _useCurrentColorSchem.colorScheme,
106
+ stateColorScheme = _useCurrentColorSchem.colorScheme,
99
107
  setColorScheme = _useCurrentColorSchem.setColorScheme;
108
+ var mode = stateMode;
109
+ var colorScheme = stateColorScheme;
110
+ if (nested) {
111
+ mode = ctx.mode;
112
+ colorScheme = ctx.colorScheme;
113
+ }
100
114
  var calculatedMode = function () {
101
115
  if (!mode) {
102
116
  // This scope occurs on the server
@@ -125,9 +139,8 @@ export default function createCssVarsProvider(options) {
125
139
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
126
140
  }),
127
141
  rootCss = _cssVarsParser.css,
128
- rootVars = _cssVarsParser.vars,
129
- parsedTheme = _cssVarsParser.parsedTheme; // 3. Start composing the theme object
130
- var theme = _extends({}, parsedTheme, {
142
+ rootVars = _cssVarsParser.vars; // 3. Start composing the theme object
143
+ var theme = _extends({}, restThemeProp, {
131
144
  components: components,
132
145
  colorSchemes: colorSchemes,
133
146
  cssVarPrefix: cssVarPrefix,
@@ -151,17 +164,16 @@ export default function createCssVarsProvider(options) {
151
164
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
152
165
  }),
153
166
  css = _cssVarsParser2.css,
154
- vars = _cssVarsParser2.vars,
155
- parsedScheme = _cssVarsParser2.parsedTheme;
167
+ vars = _cssVarsParser2.vars;
156
168
  theme.vars = deepmerge(theme.vars, vars);
157
169
  if (key === calculatedColorScheme) {
158
170
  // 4.1 Merge the selected color scheme to the theme
159
- Object.keys(parsedScheme).forEach(function (schemeKey) {
160
- if (parsedScheme[schemeKey] && _typeof(parsedScheme[schemeKey]) === 'object') {
171
+ Object.keys(scheme).forEach(function (schemeKey) {
172
+ if (scheme[schemeKey] && _typeof(scheme[schemeKey]) === 'object') {
161
173
  // shallow merge the 1st level structure of the theme.
162
- theme[schemeKey] = _extends({}, theme[schemeKey], parsedScheme[schemeKey]);
174
+ theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
163
175
  } else {
164
- theme[schemeKey] = parsedScheme[schemeKey];
176
+ theme[schemeKey] = scheme[schemeKey];
165
177
  }
166
178
  });
167
179
  if (theme.palette) {
@@ -240,19 +252,31 @@ export default function createCssVarsProvider(options) {
240
252
  allColorSchemes: allColorSchemes
241
253
  };
242
254
  }, [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
243
- return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
244
- value: contextValue,
245
- children: [/*#__PURE__*/_jsx(GlobalStyles, {
246
- styles: _defineProperty({}, colorSchemeSelector, rootCss)
247
- }), /*#__PURE__*/_jsx(GlobalStyles, {
248
- styles: defaultColorSchemeStyleSheet
249
- }), /*#__PURE__*/_jsx(GlobalStyles, {
250
- styles: otherColorSchemesStyleSheet
255
+ var shouldGenerateStyleSheet = true;
256
+ if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
257
+ shouldGenerateStyleSheet = false;
258
+ }
259
+ var element = /*#__PURE__*/_jsxs(React.Fragment, {
260
+ children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
261
+ children: [/*#__PURE__*/_jsx(GlobalStyles, {
262
+ styles: _defineProperty({}, colorSchemeSelector, rootCss)
263
+ }), /*#__PURE__*/_jsx(GlobalStyles, {
264
+ styles: defaultColorSchemeStyleSheet
265
+ }), /*#__PURE__*/_jsx(GlobalStyles, {
266
+ styles: otherColorSchemesStyleSheet
267
+ })]
251
268
  }), /*#__PURE__*/_jsx(ThemeProvider, {
252
269
  theme: resolveTheme ? resolveTheme(theme) : theme,
253
270
  children: children
254
271
  })]
255
272
  });
273
+ if (nested) {
274
+ return element;
275
+ }
276
+ return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
277
+ value: contextValue,
278
+ children: element
279
+ });
256
280
  }
257
281
  process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
258
282
  /**
@@ -283,6 +307,16 @@ export default function createCssVarsProvider(options) {
283
307
  * The initial mode used.
284
308
  */
285
309
  defaultMode: PropTypes.string,
310
+ /**
311
+ * If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
312
+ */
313
+ disableNestedContext: PropTypes.bool,
314
+ /**
315
+ * If `true`, the style sheet won't be generated.
316
+ *
317
+ * This is useful for controlling nested CssVarsProvider behavior.
318
+ */
319
+ disableStyleSheetGeneration: PropTypes.bool,
286
320
  /**
287
321
  * Disable CSS transitions when switching between modes or color schemes
288
322
  */
@@ -99,10 +99,10 @@ var getCssValue = function getCssValue(keys, value) {
99
99
  * }} options.
100
100
  * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
101
101
  *
102
- * @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.
102
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
103
103
  *
104
104
  * @example
105
- * const { css, vars, parsedTheme } = parser({
105
+ * const { css, vars } = parser({
106
106
  * fontSize: 12,
107
107
  * lineHeight: 1.2,
108
108
  * palette: { primary: { 500: 'var(--color)' } }
@@ -110,7 +110,6 @@ var getCssValue = function getCssValue(keys, value) {
110
110
  *
111
111
  * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
112
112
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
113
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
114
113
  */
115
114
  export default function cssVarsParser(theme, options) {
116
115
  var _ref3 = options || {},
@@ -118,7 +117,6 @@ export default function cssVarsParser(theme, options) {
118
117
  shouldSkipGeneratingVar = _ref3.shouldSkipGeneratingVar;
119
118
  var css = {};
120
119
  var vars = {};
121
- var parsedTheme = {};
122
120
  walkObjectDeep(theme, function (keys, value, arrayKeys) {
123
121
  if (typeof value === 'string' || typeof value === 'number') {
124
122
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
@@ -128,7 +126,6 @@ export default function cssVarsParser(theme, options) {
128
126
  assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"), arrayKeys);
129
127
  }
130
128
  }
131
- assignNestedKeys(parsedTheme, keys, value, arrayKeys);
132
129
  }, function (keys) {
133
130
  return keys[0] === 'vars';
134
131
  } // skip 'vars/*' paths
@@ -136,7 +133,6 @@ export default function cssVarsParser(theme, options) {
136
133
 
137
134
  return {
138
135
  css: css,
139
- vars: vars,
140
- parsedTheme: parsedTheme
136
+ vars: vars
141
137
  };
142
138
  }
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.15
1
+ /** @license MUI v5.10.17
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.