@mui/system 5.10.13 → 5.10.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.
Files changed (185) hide show
  1. package/Box/Box.js +1 -10
  2. package/Box/index.js +0 -2
  3. package/CHANGELOG.md +132 -2
  4. package/Container/Container.js +2 -17
  5. package/Container/containerClasses.js +0 -3
  6. package/Container/createContainer.js +15 -37
  7. package/Container/index.js +0 -6
  8. package/Stack/Stack.js +1 -12
  9. package/Stack/createStack.js +10 -48
  10. package/Stack/index.js +0 -9
  11. package/Stack/stackClasses.js +0 -3
  12. package/ThemeProvider/ThemeProvider.js +2 -22
  13. package/ThemeProvider/index.js +0 -2
  14. package/Unstable_Grid/Grid.js +6 -42
  15. package/Unstable_Grid/createGrid.js +19 -49
  16. package/Unstable_Grid/gridClasses.js +8 -7
  17. package/Unstable_Grid/gridGenerator.d.ts +4 -3
  18. package/Unstable_Grid/gridGenerator.js +22 -63
  19. package/Unstable_Grid/index.js +0 -9
  20. package/borders.js +0 -14
  21. package/breakpoints.js +3 -32
  22. package/colorManipulator.js +13 -55
  23. package/compose.js +0 -7
  24. package/createBox.js +5 -20
  25. package/createStyled.js +27 -71
  26. package/createTheme/createBreakpoints.js +22 -37
  27. package/createTheme/createSpacing.js +4 -8
  28. package/createTheme/createTheme.js +6 -16
  29. package/createTheme/index.js +0 -2
  30. package/cssGrid.js +0 -21
  31. package/cssVars/createCssVarsProvider.js +33 -74
  32. package/cssVars/createGetCssVar.js +2 -7
  33. package/cssVars/cssVarsParser.js +3 -15
  34. package/cssVars/getInitColorSchemeScript.js +0 -6
  35. package/cssVars/index.js +0 -3
  36. package/cssVars/useCurrentColorScheme.js +20 -49
  37. package/display.js +0 -6
  38. package/esm/Box/Box.js +1 -6
  39. package/esm/Container/Container.js +3 -14
  40. package/esm/Container/createContainer.js +15 -25
  41. package/esm/Stack/Stack.js +1 -9
  42. package/esm/Stack/createStack.js +10 -29
  43. package/esm/ThemeProvider/ThemeProvider.js +2 -11
  44. package/esm/Unstable_Grid/Grid.js +6 -39
  45. package/esm/Unstable_Grid/createGrid.js +18 -35
  46. package/esm/Unstable_Grid/gridClasses.js +8 -4
  47. package/esm/Unstable_Grid/gridGenerator.js +20 -38
  48. package/esm/borders.js +0 -6
  49. package/esm/breakpoints.js +7 -22
  50. package/esm/colorManipulator.js +13 -43
  51. package/esm/compose.js +0 -5
  52. package/esm/createBox.js +5 -7
  53. package/esm/createStyled.js +27 -64
  54. package/esm/createTheme/createBreakpoints.js +22 -34
  55. package/esm/createTheme/createSpacing.js +4 -7
  56. package/esm/createTheme/createTheme.js +6 -9
  57. package/esm/cssGrid.js +0 -9
  58. package/esm/cssVars/createCssVarsProvider.js +33 -60
  59. package/esm/cssVars/createGetCssVar.js +2 -6
  60. package/esm/cssVars/cssVarsParser.js +3 -11
  61. package/esm/cssVars/useCurrentColorScheme.js +20 -44
  62. package/esm/getThemeValue.js +0 -2
  63. package/esm/index.js +3 -3
  64. package/esm/memoize.js +0 -1
  65. package/esm/merge.js +0 -3
  66. package/esm/palette.js +0 -3
  67. package/esm/propsToClassKey.js +4 -7
  68. package/esm/sizing.js +0 -5
  69. package/esm/spacing.js +3 -23
  70. package/esm/style.js +5 -22
  71. package/esm/styleFunctionSx/extendSxProp.js +3 -10
  72. package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
  73. package/esm/sx/sx.js +0 -2
  74. package/esm/useTheme.js +0 -2
  75. package/esm/useThemeProps/getThemeProps.js +0 -2
  76. package/esm/useThemeWithoutDefault.js +0 -3
  77. package/flexbox.js +0 -4
  78. package/getThemeValue.js +0 -14
  79. package/index.d.ts +2 -0
  80. package/index.js +16 -55
  81. package/legacy/Box/Box.js +1 -6
  82. package/legacy/Container/Container.js +3 -14
  83. package/legacy/Container/createContainer.js +29 -39
  84. package/legacy/Stack/Stack.js +1 -9
  85. package/legacy/Stack/createStack.js +17 -37
  86. package/legacy/ThemeProvider/ThemeProvider.js +3 -12
  87. package/legacy/Unstable_Grid/Grid.js +6 -39
  88. package/legacy/Unstable_Grid/createGrid.js +34 -53
  89. package/legacy/Unstable_Grid/gridGenerator.js +36 -58
  90. package/legacy/borders.js +0 -6
  91. package/legacy/breakpoints.js +9 -28
  92. package/legacy/colorManipulator.js +16 -48
  93. package/legacy/compose.js +0 -6
  94. package/legacy/createBox.js +9 -11
  95. package/legacy/createStyled.js +27 -68
  96. package/legacy/createTheme/createBreakpoints.js +20 -33
  97. package/legacy/createTheme/createSpacing.js +4 -9
  98. package/legacy/createTheme/createTheme.js +7 -13
  99. package/legacy/cssGrid.js +0 -9
  100. package/legacy/cssVars/createCssVarsProvider.js +98 -130
  101. package/legacy/cssVars/createGetCssVar.js +2 -10
  102. package/legacy/cssVars/cssVarsParser.js +7 -20
  103. package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
  104. package/legacy/cssVars/useCurrentColorScheme.js +43 -69
  105. package/legacy/getThemeValue.js +0 -3
  106. package/legacy/index.js +4 -4
  107. package/legacy/memoize.js +0 -1
  108. package/legacy/merge.js +0 -3
  109. package/legacy/palette.js +0 -3
  110. package/legacy/propsToClassKey.js +2 -5
  111. package/legacy/sizing.js +0 -5
  112. package/legacy/spacing.js +6 -27
  113. package/legacy/style.js +9 -27
  114. package/legacy/styleFunctionSx/extendSxProp.js +3 -11
  115. package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
  116. package/legacy/sx/sx.js +0 -2
  117. package/legacy/useTheme.js +0 -2
  118. package/legacy/useThemeProps/getThemeProps.js +2 -4
  119. package/legacy/useThemeProps/useThemeProps.js +2 -2
  120. package/legacy/useThemeWithoutDefault.js +0 -3
  121. package/memoize.js +0 -2
  122. package/merge.js +0 -5
  123. package/modern/Box/Box.js +1 -6
  124. package/modern/Container/Container.js +3 -14
  125. package/modern/Container/createContainer.js +15 -25
  126. package/modern/Stack/Stack.js +1 -9
  127. package/modern/Stack/createStack.js +10 -29
  128. package/modern/ThemeProvider/ThemeProvider.js +2 -11
  129. package/modern/Unstable_Grid/Grid.js +6 -39
  130. package/modern/Unstable_Grid/createGrid.js +18 -34
  131. package/modern/Unstable_Grid/gridClasses.js +8 -4
  132. package/modern/Unstable_Grid/gridGenerator.js +20 -36
  133. package/modern/borders.js +0 -6
  134. package/modern/breakpoints.js +7 -21
  135. package/modern/colorManipulator.js +13 -43
  136. package/modern/compose.js +0 -5
  137. package/modern/createBox.js +5 -7
  138. package/modern/createStyled.js +27 -63
  139. package/modern/createTheme/createBreakpoints.js +22 -34
  140. package/modern/createTheme/createSpacing.js +4 -7
  141. package/modern/createTheme/createTheme.js +6 -9
  142. package/modern/cssGrid.js +0 -9
  143. package/modern/cssVars/createCssVarsProvider.js +33 -60
  144. package/modern/cssVars/createGetCssVar.js +2 -6
  145. package/modern/cssVars/cssVarsParser.js +3 -11
  146. package/modern/cssVars/useCurrentColorScheme.js +20 -44
  147. package/modern/getThemeValue.js +0 -2
  148. package/modern/index.js +4 -4
  149. package/modern/memoize.js +0 -1
  150. package/modern/merge.js +0 -3
  151. package/modern/palette.js +0 -3
  152. package/modern/propsToClassKey.js +4 -7
  153. package/modern/sizing.js +0 -4
  154. package/modern/spacing.js +3 -22
  155. package/modern/style.js +5 -22
  156. package/modern/styleFunctionSx/extendSxProp.js +3 -10
  157. package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
  158. package/modern/sx/sx.js +0 -2
  159. package/modern/useTheme.js +0 -2
  160. package/modern/useThemeProps/getThemeProps.js +0 -2
  161. package/modern/useThemeWithoutDefault.js +0 -3
  162. package/package.json +6 -6
  163. package/palette.js +0 -6
  164. package/positions.js +0 -6
  165. package/propsToClassKey.js +4 -10
  166. package/responsivePropType.d.ts +3 -0
  167. package/responsivePropType.js +0 -3
  168. package/shadows.js +0 -3
  169. package/sizing.js +0 -11
  170. package/spacing.d.ts +14 -0
  171. package/spacing.js +3 -37
  172. package/style.d.ts +6 -0
  173. package/style.js +6 -27
  174. package/styleFunctionSx/extendSxProp.js +3 -15
  175. package/styleFunctionSx/index.js +0 -5
  176. package/styleFunctionSx/styleFunctionSx.js +3 -21
  177. package/styled.js +0 -3
  178. package/sx/index.js +0 -2
  179. package/sx/sx.js +0 -4
  180. package/typography.js +0 -4
  181. package/useTheme.js +0 -6
  182. package/useThemeProps/getThemeProps.js +0 -4
  183. package/useThemeProps/index.js +0 -3
  184. package/useThemeProps/useThemeProps.js +0 -4
  185. package/useThemeWithoutDefault.js +0 -4
@@ -26,23 +26,17 @@ export default function createCssVarsProvider(options) {
26
26
  resolveTheme,
27
27
  excludeVariablesFromRoot
28
28
  } = options;
29
-
30
29
  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]) {
31
30
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
32
31
  }
33
-
34
32
  const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
35
-
36
33
  const useColorScheme = () => {
37
34
  const value = React.useContext(ColorSchemeContext);
38
-
39
35
  if (!value) {
40
36
  throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : _formatMuiErrorMessage(19));
41
37
  }
42
-
43
38
  return value;
44
39
  };
45
-
46
40
  function CssVarsProvider({
47
41
  children,
48
42
  theme: themeProp = defaultTheme,
@@ -59,18 +53,17 @@ export default function createCssVarsProvider(options) {
59
53
  shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
60
54
  }) {
61
55
  const hasMounted = React.useRef(false);
62
-
63
56
  const {
64
- colorSchemes = {},
65
- components = {},
66
- cssVarPrefix
67
- } = themeProp,
68
- restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
69
-
57
+ colorSchemes = {},
58
+ components = {},
59
+ cssVarPrefix
60
+ } = themeProp,
61
+ restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
70
62
  const allColorSchemes = Object.keys(colorSchemes);
71
63
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
72
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
64
+ const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
73
65
 
66
+ // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
74
67
  const {
75
68
  mode,
76
69
  setMode,
@@ -88,35 +81,29 @@ export default function createCssVarsProvider(options) {
88
81
  defaultMode,
89
82
  storageWindow
90
83
  });
91
-
92
84
  const calculatedMode = (() => {
93
85
  if (!mode) {
94
86
  // This scope occurs on the server
95
87
  if (defaultMode === 'system') {
96
88
  return designSystemMode;
97
89
  }
98
-
99
90
  return defaultMode;
100
91
  }
101
-
102
92
  return mode;
103
93
  })();
104
-
105
94
  const calculatedColorScheme = (() => {
106
95
  if (!colorScheme) {
107
96
  // This scope occurs on the server
108
97
  if (calculatedMode === 'dark') {
109
98
  return defaultDarkColorScheme;
110
- } // use light color scheme, if default mode is 'light' | 'system'
111
-
112
-
99
+ }
100
+ // use light color scheme, if default mode is 'light' | 'system'
113
101
  return defaultLightColorScheme;
114
102
  }
115
-
116
103
  return colorScheme;
117
- })(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
118
-
104
+ })();
119
105
 
106
+ // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
120
107
  const {
121
108
  css: rootCss,
122
109
  vars: rootVars,
@@ -124,19 +111,20 @@ export default function createCssVarsProvider(options) {
124
111
  } = cssVarsParser(restThemeProp, {
125
112
  prefix: cssVarPrefix,
126
113
  shouldSkipGeneratingVar
127
- }); // 3. Start composing the theme object
114
+ });
128
115
 
129
- let theme = _extends({}, parsedTheme, {
116
+ // 3. Start composing the theme object
117
+ const theme = _extends({}, parsedTheme, {
130
118
  components,
131
119
  colorSchemes,
132
120
  cssVarPrefix,
133
121
  vars: rootVars,
134
122
  getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
135
- }); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
123
+ });
124
+
125
+ // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
136
126
  // The default color scheme stylesheet is constructed to have the least CSS specificity.
137
127
  // 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
-
140
128
  const defaultColorSchemeStyleSheet = {};
141
129
  const otherColorSchemesStyleSheet = {};
142
130
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -149,28 +137,29 @@ export default function createCssVarsProvider(options) {
149
137
  shouldSkipGeneratingVar
150
138
  });
151
139
  theme.vars = deepmerge(theme.vars, vars);
152
-
153
140
  if (key === calculatedColorScheme) {
154
141
  // 4.1 Merge the selected color scheme to the theme
155
- theme = _extends({}, theme, parsedScheme);
156
-
142
+ Object.keys(parsedScheme).forEach(schemeKey => {
143
+ if (parsedScheme[schemeKey] && typeof parsedScheme[schemeKey] === 'object') {
144
+ // shallow merge the 1st level structure of the theme.
145
+ theme[schemeKey] = _extends({}, theme[schemeKey], parsedScheme[schemeKey]);
146
+ } else {
147
+ theme[schemeKey] = parsedScheme[schemeKey];
148
+ }
149
+ });
157
150
  if (theme.palette) {
158
151
  theme.palette.colorScheme = key;
159
152
  }
160
153
  }
161
-
162
154
  const resolvedDefaultColorScheme = (() => {
163
155
  if (typeof defaultColorScheme === 'string') {
164
156
  return defaultColorScheme;
165
157
  }
166
-
167
158
  if (defaultMode === 'dark') {
168
159
  return defaultColorScheme.dark;
169
160
  }
170
-
171
161
  return defaultColorScheme.light;
172
162
  })();
173
-
174
163
  if (key === resolvedDefaultColorScheme) {
175
164
  if (excludeVariablesFromRoot) {
176
165
  const excludedVariables = {};
@@ -180,37 +169,36 @@ export default function createCssVarsProvider(options) {
180
169
  });
181
170
  defaultColorSchemeStyleSheet[`[${attribute}="${key}"]`] = excludedVariables;
182
171
  }
183
-
184
172
  defaultColorSchemeStyleSheet[`${colorSchemeSelector}, [${attribute}="${key}"]`] = css;
185
173
  } else {
186
174
  otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
187
175
  }
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.
176
+ });
190
177
 
178
+ // 5. Declaring effects
179
+ // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
191
180
  React.useEffect(() => {
192
181
  if (colorScheme && colorSchemeNode) {
193
182
  // attaches attribute to <html> because the css variables are attached to :root (html)
194
183
  colorSchemeNode.setAttribute(attribute, colorScheme);
195
184
  }
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
185
+ }, [colorScheme, attribute, colorSchemeNode]);
198
186
 
187
+ // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
188
+ // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
199
189
  React.useEffect(() => {
200
190
  let timer;
201
-
202
191
  if (disableTransitionOnChange && hasMounted.current && documentNode) {
203
192
  const css = documentNode.createElement('style');
204
193
  css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
205
- documentNode.head.appendChild(css); // Force browser repaint
194
+ documentNode.head.appendChild(css);
206
195
 
196
+ // Force browser repaint
207
197
  (() => window.getComputedStyle(documentNode.body))();
208
-
209
198
  timer = setTimeout(() => {
210
199
  documentNode.head.removeChild(css);
211
200
  }, 1);
212
201
  }
213
-
214
202
  return () => {
215
203
  clearTimeout(timer);
216
204
  };
@@ -247,69 +235,56 @@ export default function createCssVarsProvider(options) {
247
235
  })]
248
236
  });
249
237
  }
250
-
251
238
  process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
252
239
  /**
253
240
  * The body attribute name to attach colorScheme.
254
241
  */
255
242
  attribute: PropTypes.string,
256
-
257
243
  /**
258
244
  * The component tree.
259
245
  */
260
246
  children: PropTypes.node,
261
-
262
247
  /**
263
248
  * The node used to attach the color-scheme attribute
264
249
  */
265
250
  colorSchemeNode: PropTypes.any,
266
-
267
251
  /**
268
252
  * The CSS selector for attaching the generated custom properties
269
253
  */
270
254
  colorSchemeSelector: PropTypes.string,
271
-
272
255
  /**
273
256
  * localStorage key used to store `colorScheme`
274
257
  */
275
258
  colorSchemeStorageKey: PropTypes.string,
276
-
277
259
  /**
278
260
  * The initial color scheme used.
279
261
  */
280
262
  defaultColorScheme: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
281
-
282
263
  /**
283
264
  * The initial mode used.
284
265
  */
285
266
  defaultMode: PropTypes.string,
286
-
287
267
  /**
288
268
  * Disable CSS transitions when switching between modes or color schemes
289
269
  */
290
270
  disableTransitionOnChange: PropTypes.bool,
291
-
292
271
  /**
293
272
  * The document to attach the attribute to
294
273
  */
295
274
  documentNode: PropTypes.any,
296
-
297
275
  /**
298
276
  * The key in the local storage used to store current color scheme.
299
277
  */
300
278
  modeStorageKey: PropTypes.string,
301
-
302
279
  /**
303
280
  * A function to determine if the key, value should be attached as CSS Variable
304
281
  */
305
282
  shouldSkipGeneratingVar: PropTypes.func,
306
-
307
283
  /**
308
284
  * The window that attaches the 'storage' event listener
309
285
  * @default window
310
286
  */
311
287
  storageWindow: PropTypes.any,
312
-
313
288
  /**
314
289
  * The calculated theme object that will be passed through context.
315
290
  */
@@ -317,7 +292,6 @@ export default function createCssVarsProvider(options) {
317
292
  } : void 0;
318
293
  const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
319
294
  const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
320
-
321
295
  const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
322
296
  attribute: defaultAttribute,
323
297
  colorSchemeStorageKey: defaultColorSchemeStorageKey,
@@ -326,7 +300,6 @@ export default function createCssVarsProvider(options) {
326
300
  defaultDarkColorScheme,
327
301
  modeStorageKey: defaultModeStorageKey
328
302
  }, params));
329
-
330
303
  return {
331
304
  CssVarsProvider,
332
305
  useColorScheme,
@@ -7,20 +7,16 @@ export default function createGetCssVar(prefix = '') {
7
7
  if (!vars.length) {
8
8
  return '';
9
9
  }
10
-
11
10
  const value = vars[0];
12
-
13
11
  if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
14
12
  return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
15
13
  }
16
-
17
14
  return `, ${value}`;
18
- } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
19
-
15
+ }
20
16
 
17
+ // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
21
18
  const getCssVar = (field, ...fallbacks) => {
22
19
  return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
23
20
  };
24
-
25
21
  return getCssVar;
26
22
  }
@@ -28,11 +28,11 @@ export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
28
28
  if (!temp[k]) {
29
29
  temp[k] = arrayKeys.includes(k) ? [] : {};
30
30
  }
31
-
32
31
  temp = temp[k];
33
32
  }
34
33
  });
35
34
  };
35
+
36
36
  /**
37
37
  *
38
38
  * @param {Object} obj : source object
@@ -44,7 +44,6 @@ export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
44
44
  * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
45
45
  * // ['palette', 'primary', 'main'] '#000000'
46
46
  */
47
-
48
47
  export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
49
48
  function recurse(object, parentKeys = [], arrayKeys = []) {
50
49
  Object.entries(object).forEach(([key, value]) => {
@@ -59,29 +58,24 @@ export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
59
58
  }
60
59
  });
61
60
  }
62
-
63
61
  recurse(obj);
64
62
  };
65
-
66
63
  const getCssValue = (keys, value) => {
67
64
  if (typeof value === 'number') {
68
65
  if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
69
66
  // CSS property that are unitless
70
67
  return value;
71
68
  }
72
-
73
69
  const lastKey = keys[keys.length - 1];
74
-
75
70
  if (lastKey.toLowerCase().indexOf('opacity') >= 0) {
76
71
  // opacity values are unitless
77
72
  return value;
78
73
  }
79
-
80
74
  return `${value}px`;
81
75
  }
82
-
83
76
  return value;
84
77
  };
78
+
85
79
  /**
86
80
  * a function that parse theme and return { css, vars }
87
81
  *
@@ -105,8 +99,6 @@ const getCssValue = (keys, value) => {
105
99
  * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
106
100
  * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
107
101
  */
108
-
109
-
110
102
  export default function cssVarsParser(theme, options) {
111
103
  const {
112
104
  prefix,
@@ -126,10 +118,10 @@ export default function cssVarsParser(theme, options) {
126
118
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
127
119
  }
128
120
  }
129
-
130
121
  assignNestedKeys(parsedTheme, keys, value, arrayKeys);
131
122
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
132
123
  );
124
+
133
125
  return {
134
126
  css,
135
127
  vars,
@@ -4,63 +4,49 @@ import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from './ge
4
4
  export function getSystemMode(mode) {
5
5
  if (typeof window !== 'undefined' && mode === 'system') {
6
6
  const mql = window.matchMedia('(prefers-color-scheme: dark)');
7
-
8
7
  if (mql.matches) {
9
8
  return 'dark';
10
9
  }
11
-
12
10
  return 'light';
13
11
  }
14
-
15
12
  return undefined;
16
13
  }
17
-
18
14
  function processState(state, callback) {
19
15
  if (state.mode === 'light' || state.mode === 'system' && state.systemMode === 'light') {
20
16
  return callback('light');
21
17
  }
22
-
23
18
  if (state.mode === 'dark' || state.mode === 'system' && state.systemMode === 'dark') {
24
19
  return callback('dark');
25
20
  }
26
-
27
21
  return undefined;
28
22
  }
29
-
30
23
  export function getColorScheme(state) {
31
24
  return processState(state, mode => {
32
25
  if (mode === 'light') {
33
26
  return state.lightColorScheme;
34
27
  }
35
-
36
28
  if (mode === 'dark') {
37
29
  return state.darkColorScheme;
38
30
  }
39
-
40
31
  return undefined;
41
32
  });
42
33
  }
43
-
44
34
  function initializeValue(key, defaultValue) {
45
35
  if (typeof window === 'undefined') {
46
36
  return undefined;
47
37
  }
48
-
49
38
  let value;
50
-
51
39
  try {
52
40
  value = localStorage.getItem(key) || undefined;
53
-
54
41
  if (!value) {
55
42
  // the first time that user enters the site.
56
43
  localStorage.setItem(key, defaultValue);
57
44
  }
58
- } catch (e) {// Unsupported
45
+ } catch (e) {
46
+ // Unsupported
59
47
  }
60
-
61
48
  return value || defaultValue;
62
49
  }
63
-
64
50
  export default function useCurrentColorScheme(options) {
65
51
  const {
66
52
  defaultMode = 'light',
@@ -90,14 +76,12 @@ export default function useCurrentColorScheme(options) {
90
76
  // do nothing if mode does not change
91
77
  return currentState;
92
78
  }
93
-
94
79
  const newMode = !mode ? defaultMode : mode;
95
-
96
80
  try {
97
81
  localStorage.setItem(modeStorageKey, newMode);
98
- } catch (e) {// Unsupported
82
+ } catch (e) {
83
+ // Unsupported
99
84
  }
100
-
101
85
  return _extends({}, currentState, {
102
86
  mode: newMode,
103
87
  systemMode: getSystemMode(newMode)
@@ -110,9 +94,9 @@ export default function useCurrentColorScheme(options) {
110
94
  try {
111
95
  localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
112
96
  localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
113
- } catch (e) {// Unsupported
97
+ } catch (e) {
98
+ // Unsupported
114
99
  }
115
-
116
100
  return _extends({}, currentState, {
117
101
  lightColorScheme: defaultLightColorScheme,
118
102
  darkColorScheme: defaultDarkColorScheme
@@ -124,17 +108,15 @@ export default function useCurrentColorScheme(options) {
124
108
  } else {
125
109
  setState(currentState => {
126
110
  const newState = _extends({}, currentState);
127
-
128
111
  processState(currentState, mode => {
129
112
  try {
130
113
  localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
131
- } catch (e) {// Unsupported
114
+ } catch (e) {
115
+ // Unsupported
132
116
  }
133
-
134
117
  if (mode === 'light') {
135
118
  newState.lightColorScheme = value;
136
119
  }
137
-
138
120
  if (mode === 'dark') {
139
121
  newState.darkColorScheme = value;
140
122
  }
@@ -145,36 +127,32 @@ export default function useCurrentColorScheme(options) {
145
127
  } else {
146
128
  setState(currentState => {
147
129
  const newState = _extends({}, currentState);
148
-
149
130
  const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
150
131
  const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
151
-
152
132
  if (newLightColorScheme) {
153
133
  if (!joinedColorSchemes.includes(newLightColorScheme)) {
154
134
  console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
155
135
  } else {
156
136
  newState.lightColorScheme = newLightColorScheme;
157
-
158
137
  try {
159
138
  localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
160
- } catch (error) {// Unsupported
139
+ } catch (error) {
140
+ // Unsupported
161
141
  }
162
142
  }
163
143
  }
164
-
165
144
  if (newDarkColorScheme) {
166
145
  if (!joinedColorSchemes.includes(newDarkColorScheme)) {
167
146
  console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
168
147
  } else {
169
148
  newState.darkColorScheme = newDarkColorScheme;
170
-
171
149
  try {
172
150
  localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
173
- } catch (error) {// Unsupported
151
+ } catch (error) {
152
+ // Unsupported
174
153
  }
175
154
  }
176
155
  }
177
-
178
156
  return newState;
179
157
  });
180
158
  }
@@ -185,25 +163,27 @@ export default function useCurrentColorScheme(options) {
185
163
  systemMode: e != null && e.matches ? 'dark' : 'light'
186
164
  }));
187
165
  }
188
- }, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
166
+ }, [state.mode]);
189
167
 
168
+ // Ref hack to avoid adding handleMediaQuery as a dep
190
169
  const mediaListener = React.useRef(handleMediaQuery);
191
170
  mediaListener.current = handleMediaQuery;
192
171
  React.useEffect(() => {
193
- const handler = (...args) => mediaListener.current(...args); // Always listen to System preference
172
+ const handler = (...args) => mediaListener.current(...args);
194
173
 
174
+ // Always listen to System preference
175
+ const media = window.matchMedia('(prefers-color-scheme: dark)');
195
176
 
196
- const media = window.matchMedia('(prefers-color-scheme: dark)'); // Intentionally use deprecated listener methods to support iOS & old browsers
197
-
177
+ // Intentionally use deprecated listener methods to support iOS & old browsers
198
178
  media.addListener(handler);
199
179
  handler(media);
200
180
  return () => media.removeListener(handler);
201
- }, []); // Handle when localStorage has changed
181
+ }, []);
202
182
 
183
+ // Handle when localStorage has changed
203
184
  React.useEffect(() => {
204
185
  const handleStorage = event => {
205
186
  const value = event.newValue;
206
-
207
187
  if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
208
188
  // If the key is deleted, value will be null then reset color scheme to the default one.
209
189
  if (event.key.endsWith('light')) {
@@ -211,25 +191,21 @@ export default function useCurrentColorScheme(options) {
211
191
  light: value
212
192
  });
213
193
  }
214
-
215
194
  if (event.key.endsWith('dark')) {
216
195
  setColorScheme({
217
196
  dark: value
218
197
  });
219
198
  }
220
199
  }
221
-
222
200
  if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
223
201
  setMode(value || defaultMode);
224
202
  }
225
203
  };
226
-
227
204
  if (storageWindow) {
228
205
  // For syncing color-scheme changes between iframes
229
206
  storageWindow.addEventListener('storage', handleStorage);
230
207
  return () => storageWindow.removeEventListener('storage', handleStorage);
231
208
  }
232
-
233
209
  return undefined;
234
210
  }, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
235
211
  return _extends({}, state, {
@@ -38,7 +38,6 @@ export const propToStyleFunction = Object.keys(filterPropsMapping).reduce((acc,
38
38
  });
39
39
  return acc;
40
40
  }, {});
41
-
42
41
  function getThemeValue(prop, value, theme) {
43
42
  const inputProps = {
44
43
  [prop]: value,
@@ -49,5 +48,4 @@ function getThemeValue(prop, value, theme) {
49
48
  [prop]: value
50
49
  };
51
50
  }
52
-
53
51
  export default getThemeValue;
package/esm/index.js CHANGED
@@ -18,7 +18,7 @@ export { default as sizing } from './sizing';
18
18
  export * from './sizing';
19
19
  export { default as spacing } from './spacing';
20
20
  export * from './spacing';
21
- export { default as style, getPath } from './style';
21
+ export { default as style, getPath, getStyleValue } from './style';
22
22
  export { default as typography } from './typography';
23
23
  export * from './typography';
24
24
  export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
@@ -40,10 +40,10 @@ export * from './colorManipulator';
40
40
  export { default as ThemeProvider } from './ThemeProvider';
41
41
  export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
42
42
  export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
43
- /** ----------------- */
43
+ export { default as responsivePropType } from './responsivePropType';
44
44
 
45
+ /** ----------------- */
45
46
  /** Layout components */
46
-
47
47
  export { default as createContainer } from './Container/createContainer';
48
48
  export { default as Container } from './Container';
49
49
  export * from './Container';
package/esm/memoize.js CHANGED
@@ -4,7 +4,6 @@ export default function memoize(fn) {
4
4
  if (cache[arg] === undefined) {
5
5
  cache[arg] = fn(arg);
6
6
  }
7
-
8
7
  return cache[arg];
9
8
  };
10
9
  }
package/esm/merge.js CHANGED
@@ -1,13 +1,10 @@
1
1
  import { deepmerge } from '@mui/utils';
2
-
3
2
  function merge(acc, item) {
4
3
  if (!item) {
5
4
  return acc;
6
5
  }
7
-
8
6
  return deepmerge(acc, item, {
9
7
  clone: false // No need to clone deep, it's way faster.
10
-
11
8
  });
12
9
  }
13
10
 
package/esm/palette.js CHANGED
@@ -1,14 +1,11 @@
1
1
  import style from './style';
2
2
  import compose from './compose';
3
-
4
3
  function transform(value, userValue) {
5
4
  if (userValue === 'grey') {
6
5
  return userValue;
7
6
  }
8
-
9
7
  return value;
10
8
  }
11
-
12
9
  export const color = style({
13
10
  prop: 'color',
14
11
  themeKey: 'palette',