@mui/system 5.10.13 → 5.10.14

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 (206) hide show
  1. package/Box/Box.js +1 -10
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/Box/index.js +0 -2
  4. package/CHANGELOG.md +70 -2
  5. package/Container/Container.d.ts +13 -13
  6. package/Container/Container.js +2 -17
  7. package/Container/ContainerProps.d.ts +40 -40
  8. package/Container/containerClasses.d.ts +22 -22
  9. package/Container/containerClasses.js +0 -3
  10. package/Container/createContainer.d.ts +18 -18
  11. package/Container/createContainer.js +15 -37
  12. package/Container/index.js +0 -6
  13. package/Stack/Stack.d.ts +13 -13
  14. package/Stack/Stack.js +1 -12
  15. package/Stack/StackProps.d.ts +42 -42
  16. package/Stack/createStack.d.ts +21 -21
  17. package/Stack/createStack.js +10 -48
  18. package/Stack/index.d.ts +5 -5
  19. package/Stack/index.js +0 -9
  20. package/Stack/stackClasses.d.ts +8 -8
  21. package/Stack/stackClasses.js +0 -3
  22. package/ThemeProvider/ThemeProvider.js +2 -22
  23. package/ThemeProvider/index.js +0 -2
  24. package/Unstable_Grid/Grid.d.ts +12 -12
  25. package/Unstable_Grid/Grid.js +6 -42
  26. package/Unstable_Grid/GridProps.d.ts +162 -162
  27. package/Unstable_Grid/createGrid.d.ts +11 -11
  28. package/Unstable_Grid/createGrid.js +19 -49
  29. package/Unstable_Grid/gridClasses.d.ts +20 -20
  30. package/Unstable_Grid/gridClasses.js +8 -7
  31. package/Unstable_Grid/gridGenerator.d.ts +29 -28
  32. package/Unstable_Grid/gridGenerator.js +22 -63
  33. package/Unstable_Grid/index.d.ts +5 -5
  34. package/Unstable_Grid/index.js +0 -9
  35. package/borders.js +0 -14
  36. package/breakpoints.js +3 -32
  37. package/colorManipulator.js +13 -55
  38. package/compose.js +0 -7
  39. package/createBox.js +5 -20
  40. package/createBox.spec.d.ts +1 -1
  41. package/createStyled.js +27 -71
  42. package/createTheme/createBreakpoints.js +22 -37
  43. package/createTheme/createSpacing.d.ts +10 -10
  44. package/createTheme/createSpacing.js +4 -8
  45. package/createTheme/createTheme.js +6 -16
  46. package/createTheme/index.js +0 -2
  47. package/cssGrid.js +0 -21
  48. package/cssVars/createCssVarsProvider.js +24 -72
  49. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  50. package/cssVars/createGetCssVar.d.ts +5 -5
  51. package/cssVars/createGetCssVar.js +2 -7
  52. package/cssVars/cssVarsParser.d.ts +65 -65
  53. package/cssVars/cssVarsParser.js +3 -15
  54. package/cssVars/getInitColorSchemeScript.d.ts +42 -42
  55. package/cssVars/getInitColorSchemeScript.js +0 -6
  56. package/cssVars/index.d.ts +3 -3
  57. package/cssVars/index.js +0 -3
  58. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  59. package/cssVars/useCurrentColorScheme.js +20 -49
  60. package/display.js +0 -6
  61. package/esm/Box/Box.js +1 -6
  62. package/esm/Container/Container.js +3 -14
  63. package/esm/Container/createContainer.js +15 -25
  64. package/esm/Stack/Stack.js +1 -9
  65. package/esm/Stack/createStack.js +10 -29
  66. package/esm/ThemeProvider/ThemeProvider.js +2 -11
  67. package/esm/Unstable_Grid/Grid.js +6 -39
  68. package/esm/Unstable_Grid/createGrid.js +18 -35
  69. package/esm/Unstable_Grid/gridClasses.js +8 -4
  70. package/esm/Unstable_Grid/gridGenerator.js +20 -38
  71. package/esm/borders.js +0 -6
  72. package/esm/breakpoints.js +7 -22
  73. package/esm/colorManipulator.js +13 -43
  74. package/esm/compose.js +0 -5
  75. package/esm/createBox.js +5 -7
  76. package/esm/createStyled.js +27 -64
  77. package/esm/createTheme/createBreakpoints.js +22 -34
  78. package/esm/createTheme/createSpacing.js +4 -7
  79. package/esm/createTheme/createTheme.js +6 -9
  80. package/esm/cssGrid.js +0 -9
  81. package/esm/cssVars/createCssVarsProvider.js +24 -58
  82. package/esm/cssVars/createGetCssVar.js +2 -6
  83. package/esm/cssVars/cssVarsParser.js +3 -11
  84. package/esm/cssVars/useCurrentColorScheme.js +20 -44
  85. package/esm/getThemeValue.js +0 -2
  86. package/esm/index.js +1 -2
  87. package/esm/memoize.js +0 -1
  88. package/esm/merge.js +0 -3
  89. package/esm/palette.js +0 -3
  90. package/esm/propsToClassKey.js +4 -7
  91. package/esm/sizing.js +0 -5
  92. package/esm/spacing.js +3 -23
  93. package/esm/style.js +2 -19
  94. package/esm/styleFunctionSx/extendSxProp.js +3 -10
  95. package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
  96. package/esm/sx/sx.js +0 -2
  97. package/esm/useTheme.js +0 -2
  98. package/esm/useThemeProps/getThemeProps.js +0 -2
  99. package/esm/useThemeWithoutDefault.js +0 -3
  100. package/flexbox.js +0 -4
  101. package/getThemeValue.js +0 -14
  102. package/index.js +1 -55
  103. package/index.spec.d.ts +1 -1
  104. package/legacy/Box/Box.js +1 -6
  105. package/legacy/Container/Container.js +3 -14
  106. package/legacy/Container/createContainer.js +29 -39
  107. package/legacy/Stack/Stack.js +1 -9
  108. package/legacy/Stack/createStack.js +17 -37
  109. package/legacy/ThemeProvider/ThemeProvider.js +3 -12
  110. package/legacy/Unstable_Grid/Grid.js +6 -39
  111. package/legacy/Unstable_Grid/createGrid.js +34 -53
  112. package/legacy/Unstable_Grid/gridGenerator.js +36 -58
  113. package/legacy/borders.js +0 -6
  114. package/legacy/breakpoints.js +9 -28
  115. package/legacy/colorManipulator.js +16 -48
  116. package/legacy/compose.js +0 -6
  117. package/legacy/createBox.js +9 -11
  118. package/legacy/createStyled.js +27 -68
  119. package/legacy/createTheme/createBreakpoints.js +20 -33
  120. package/legacy/createTheme/createSpacing.js +4 -9
  121. package/legacy/createTheme/createTheme.js +7 -13
  122. package/legacy/cssGrid.js +0 -9
  123. package/legacy/cssVars/createCssVarsProvider.js +90 -129
  124. package/legacy/cssVars/createGetCssVar.js +2 -10
  125. package/legacy/cssVars/cssVarsParser.js +7 -20
  126. package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
  127. package/legacy/cssVars/useCurrentColorScheme.js +43 -69
  128. package/legacy/getThemeValue.js +0 -3
  129. package/legacy/index.js +2 -3
  130. package/legacy/memoize.js +0 -1
  131. package/legacy/merge.js +0 -3
  132. package/legacy/palette.js +0 -3
  133. package/legacy/propsToClassKey.js +2 -5
  134. package/legacy/sizing.js +0 -5
  135. package/legacy/spacing.js +6 -27
  136. package/legacy/style.js +6 -24
  137. package/legacy/styleFunctionSx/extendSxProp.js +3 -11
  138. package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
  139. package/legacy/sx/sx.js +0 -2
  140. package/legacy/useTheme.js +0 -2
  141. package/legacy/useThemeProps/getThemeProps.js +2 -4
  142. package/legacy/useThemeProps/useThemeProps.js +2 -2
  143. package/legacy/useThemeWithoutDefault.js +0 -3
  144. package/memoize.js +0 -2
  145. package/merge.js +0 -5
  146. package/modern/Box/Box.js +1 -6
  147. package/modern/Container/Container.js +3 -14
  148. package/modern/Container/createContainer.js +15 -25
  149. package/modern/Stack/Stack.js +1 -9
  150. package/modern/Stack/createStack.js +10 -29
  151. package/modern/ThemeProvider/ThemeProvider.js +2 -11
  152. package/modern/Unstable_Grid/Grid.js +6 -39
  153. package/modern/Unstable_Grid/createGrid.js +18 -34
  154. package/modern/Unstable_Grid/gridClasses.js +8 -4
  155. package/modern/Unstable_Grid/gridGenerator.js +20 -36
  156. package/modern/borders.js +0 -6
  157. package/modern/breakpoints.js +7 -21
  158. package/modern/colorManipulator.js +13 -43
  159. package/modern/compose.js +0 -5
  160. package/modern/createBox.js +5 -7
  161. package/modern/createStyled.js +27 -63
  162. package/modern/createTheme/createBreakpoints.js +22 -34
  163. package/modern/createTheme/createSpacing.js +4 -7
  164. package/modern/createTheme/createTheme.js +6 -9
  165. package/modern/cssGrid.js +0 -9
  166. package/modern/cssVars/createCssVarsProvider.js +24 -58
  167. package/modern/cssVars/createGetCssVar.js +2 -6
  168. package/modern/cssVars/cssVarsParser.js +3 -11
  169. package/modern/cssVars/useCurrentColorScheme.js +20 -44
  170. package/modern/getThemeValue.js +0 -2
  171. package/modern/index.js +2 -3
  172. package/modern/memoize.js +0 -1
  173. package/modern/merge.js +0 -3
  174. package/modern/palette.js +0 -3
  175. package/modern/propsToClassKey.js +4 -7
  176. package/modern/sizing.js +0 -4
  177. package/modern/spacing.js +3 -22
  178. package/modern/style.js +2 -19
  179. package/modern/styleFunctionSx/extendSxProp.js +3 -10
  180. package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
  181. package/modern/sx/sx.js +0 -2
  182. package/modern/useTheme.js +0 -2
  183. package/modern/useThemeProps/getThemeProps.js +0 -2
  184. package/modern/useThemeWithoutDefault.js +0 -3
  185. package/package.json +6 -6
  186. package/palette.js +0 -6
  187. package/positions.js +0 -6
  188. package/propsToClassKey.js +4 -10
  189. package/responsivePropType.js +0 -3
  190. package/shadows.js +0 -3
  191. package/sizing.js +0 -11
  192. package/spacing.js +3 -37
  193. package/style.js +2 -24
  194. package/styleFunctionSx/extendSxProp.js +3 -15
  195. package/styleFunctionSx/index.js +0 -5
  196. package/styleFunctionSx/styleFunctionSx.js +3 -21
  197. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  198. package/styled.js +0 -3
  199. package/sx/index.js +0 -2
  200. package/sx/sx.js +0 -4
  201. package/typography.js +0 -4
  202. package/useTheme.js +0 -6
  203. package/useThemeProps/getThemeProps.js +0 -4
  204. package/useThemeProps/index.js +0 -3
  205. package/useThemeProps/useThemeProps.js +0 -4
  206. package/useThemeWithoutDefault.js +0 -4
@@ -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?.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/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.10.13
1
+ /** @license MUI v5.10.14
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.
@@ -45,10 +45,9 @@ export * from './colorManipulator';
45
45
  export { default as ThemeProvider } from './ThemeProvider';
46
46
  export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
47
47
  export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
48
- /** ----------------- */
49
48
 
49
+ /** ----------------- */
50
50
  /** Layout components */
51
-
52
51
  export { default as createContainer } from './Container/createContainer';
53
52
  export { default as Container } from './Container';
54
53
  export * from './Container';
package/modern/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/modern/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/modern/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',
@@ -1,23 +1,20 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  const _excluded = ["variant"];
3
3
  import { unstable_capitalize as capitalize } from '@mui/utils';
4
-
5
4
  function isEmpty(string) {
6
5
  return string.length === 0;
7
6
  }
7
+
8
8
  /**
9
9
  * Generates string classKey based on the properties provided. It starts with the
10
10
  * variant if defined, and then it appends all other properties in alphabetical order.
11
11
  * @param {object} props - the properties for which the classKey should be created.
12
12
  */
13
-
14
-
15
13
  export default function propsToClassKey(props) {
16
14
  const {
17
- variant
18
- } = props,
19
- other = _objectWithoutPropertiesLoose(props, _excluded);
20
-
15
+ variant
16
+ } = props,
17
+ other = _objectWithoutPropertiesLoose(props, _excluded);
21
18
  let classKey = variant || '';
22
19
  Object.keys(other).sort().forEach(key => {
23
20
  if (key === 'color') {
package/modern/sizing.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import style from './style';
2
2
  import compose from './compose';
3
3
  import { handleBreakpoints, values as breakpointsValues } from './breakpoints';
4
-
5
4
  function transform(value) {
6
5
  return value <= 1 && value !== 0 ? `${value * 100}%` : value;
7
6
  }
8
-
9
7
  export const width = style({
10
8
  prop: 'width',
11
9
  transform
@@ -18,10 +16,8 @@ export const maxWidth = props => {
18
16
  maxWidth: breakpoint || transform(propValue)
19
17
  };
20
18
  };
21
-
22
19
  return handleBreakpoints(props, props.maxWidth, styleFromPropValue);
23
20
  }
24
-
25
21
  return null;
26
22
  };
27
23
  maxWidth.filterProps = ['maxWidth'];
package/modern/spacing.js CHANGED
@@ -20,10 +20,11 @@ const aliases = {
20
20
  marginY: 'my',
21
21
  paddingX: 'px',
22
22
  paddingY: 'py'
23
- }; // memoize() impact:
23
+ };
24
+
25
+ // memoize() impact:
24
26
  // From 300,000 ops/sec
25
27
  // To 350,000 ops/sec
26
-
27
28
  const getCssProperties = memoize(prop => {
28
29
  // It's not a shorthand notation.
29
30
  if (prop.length > 2) {
@@ -33,7 +34,6 @@ const getCssProperties = memoize(prop => {
33
34
  return [prop];
34
35
  }
35
36
  }
36
-
37
37
  const [a, b] = prop.split('');
38
38
  const property = properties[a];
39
39
  const direction = directions[b] || '';
@@ -44,29 +44,24 @@ const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddin
44
44
  const spacingKeys = [...marginKeys, ...paddingKeys];
45
45
  export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
46
46
  const themeSpacing = getPath(theme, themeKey, false) ?? defaultValue;
47
-
48
47
  if (typeof themeSpacing === 'number') {
49
48
  return abs => {
50
49
  if (typeof abs === 'string') {
51
50
  return abs;
52
51
  }
53
-
54
52
  if (process.env.NODE_ENV !== 'production') {
55
53
  if (typeof abs !== 'number') {
56
54
  console.error(`MUI: Expected ${propName} argument to be a number or a string, got ${abs}.`);
57
55
  }
58
56
  }
59
-
60
57
  return themeSpacing * abs;
61
58
  };
62
59
  }
63
-
64
60
  if (Array.isArray(themeSpacing)) {
65
61
  return abs => {
66
62
  if (typeof abs === 'string') {
67
63
  return abs;
68
64
  }
69
-
70
65
  if (process.env.NODE_ENV !== 'production') {
71
66
  if (!Number.isInteger(abs)) {
72
67
  console.error([`MUI: The \`theme.${themeKey}\` array type cannot be combined with non integer values.` + `You should either use an integer value that can be used as index, or define the \`theme.${themeKey}\` as a number.`].join('\n'));
@@ -74,19 +69,15 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
74
69
  console.error([`MUI: The value provided (${abs}) overflows.`, `The supported values are: ${JSON.stringify(themeSpacing)}.`, `${abs} > ${themeSpacing.length - 1}, you need to add the missing values.`].join('\n'));
75
70
  }
76
71
  }
77
-
78
72
  return themeSpacing[abs];
79
73
  };
80
74
  }
81
-
82
75
  if (typeof themeSpacing === 'function') {
83
76
  return themeSpacing;
84
77
  }
85
-
86
78
  if (process.env.NODE_ENV !== 'production') {
87
79
  console.error([`MUI: The \`theme.${themeKey}\` value (${themeSpacing}) is invalid.`, 'It should be a number, an array or a function.'].join('\n'));
88
80
  }
89
-
90
81
  return () => undefined;
91
82
  }
92
83
  export function createUnarySpacing(theme) {
@@ -96,18 +87,14 @@ export function getValue(transformer, propValue) {
96
87
  if (typeof propValue === 'string' || propValue == null) {
97
88
  return propValue;
98
89
  }
99
-
100
90
  const abs = Math.abs(propValue);
101
91
  const transformed = transformer(abs);
102
-
103
92
  if (propValue >= 0) {
104
93
  return transformed;
105
94
  }
106
-
107
95
  if (typeof transformed === 'number') {
108
96
  return -transformed;
109
97
  }
110
-
111
98
  return `-${transformed}`;
112
99
  }
113
100
  export function getStyleFromPropValue(cssProperties, transformer) {
@@ -116,25 +103,21 @@ export function getStyleFromPropValue(cssProperties, transformer) {
116
103
  return acc;
117
104
  }, {});
118
105
  }
119
-
120
106
  function resolveCssProperty(props, keys, prop, transformer) {
121
107
  // Using a hash computation over an array iteration could be faster, but with only 28 items,
122
108
  // it's doesn't worth the bundle size.
123
109
  if (keys.indexOf(prop) === -1) {
124
110
  return null;
125
111
  }
126
-
127
112
  const cssProperties = getCssProperties(prop);
128
113
  const styleFromPropValue = getStyleFromPropValue(cssProperties, transformer);
129
114
  const propValue = props[prop];
130
115
  return handleBreakpoints(props, propValue, styleFromPropValue);
131
116
  }
132
-
133
117
  function style(props, keys) {
134
118
  const transformer = createUnarySpacing(props.theme);
135
119
  return Object.keys(props).map(prop => resolveCssProperty(props, keys, prop, transformer)).reduce(merge, {});
136
120
  }
137
-
138
121
  export function margin(props) {
139
122
  return style(props, marginKeys);
140
123
  }
@@ -151,11 +134,9 @@ padding.propTypes = process.env.NODE_ENV !== 'production' ? paddingKeys.reduce((
151
134
  return obj;
152
135
  }, {}) : {};
153
136
  padding.filterProps = paddingKeys;
154
-
155
137
  function spacing(props) {
156
138
  return style(props, spacingKeys);
157
139
  }
158
-
159
140
  spacing.propTypes = process.env.NODE_ENV !== 'production' ? spacingKeys.reduce((obj, key) => {
160
141
  obj[key] = responsivePropType;
161
142
  return obj;
package/modern/style.js CHANGED
@@ -4,29 +4,24 @@ import { handleBreakpoints } from './breakpoints';
4
4
  export function getPath(obj, path, checkVars = true) {
5
5
  if (!path || typeof path !== 'string') {
6
6
  return null;
7
- } // Check if CSS variables are used
8
-
7
+ }
9
8
 
9
+ // Check if CSS variables are used
10
10
  if (obj && obj.vars && checkVars) {
11
11
  const val = `vars.${path}`.split('.').reduce((acc, item) => acc && acc[item] ? acc[item] : null, obj);
12
-
13
12
  if (val != null) {
14
13
  return val;
15
14
  }
16
15
  }
17
-
18
16
  return path.split('.').reduce((acc, item) => {
19
17
  if (acc && acc[item] != null) {
20
18
  return acc[item];
21
19
  }
22
-
23
20
  return null;
24
21
  }, obj);
25
22
  }
26
-
27
23
  function getValue(themeMapping, transform, propValueFinal, userValue = propValueFinal) {
28
24
  let value;
29
-
30
25
  if (typeof themeMapping === 'function') {
31
26
  value = themeMapping(propValueFinal);
32
27
  } else if (Array.isArray(themeMapping)) {
@@ -34,14 +29,11 @@ function getValue(themeMapping, transform, propValueFinal, userValue = propValue
34
29
  } else {
35
30
  value = getPath(themeMapping, propValueFinal) || userValue;
36
31
  }
37
-
38
32
  if (transform) {
39
33
  value = transform(value, userValue);
40
34
  }
41
-
42
35
  return value;
43
36
  }
44
-
45
37
  function style(options) {
46
38
  const {
47
39
  prop,
@@ -49,41 +41,32 @@ function style(options) {
49
41
  themeKey,
50
42
  transform
51
43
  } = options;
52
-
53
44
  const fn = props => {
54
45
  if (props[prop] == null) {
55
46
  return null;
56
47
  }
57
-
58
48
  const propValue = props[prop];
59
49
  const theme = props.theme;
60
50
  const themeMapping = getPath(theme, themeKey) || {};
61
-
62
51
  const styleFromPropValue = propValueFinal => {
63
52
  let value = getValue(themeMapping, transform, propValueFinal);
64
-
65
53
  if (propValueFinal === value && typeof propValueFinal === 'string') {
66
54
  // Haven't found value
67
55
  value = getValue(themeMapping, transform, `${prop}${propValueFinal === 'default' ? '' : capitalize(propValueFinal)}`, propValueFinal);
68
56
  }
69
-
70
57
  if (cssProperty === false) {
71
58
  return value;
72
59
  }
73
-
74
60
  return {
75
61
  [cssProperty]: value
76
62
  };
77
63
  };
78
-
79
64
  return handleBreakpoints(props, propValue, styleFromPropValue);
80
65
  };
81
-
82
66
  fn.propTypes = process.env.NODE_ENV !== 'production' ? {
83
67
  [prop]: responsivePropType
84
68
  } : {};
85
69
  fn.filterProps = [prop];
86
70
  return fn;
87
71
  }
88
-
89
72
  export default style;
@@ -3,7 +3,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["sx"];
4
4
  import { isPlainObject } from '@mui/utils';
5
5
  import { propToStyleFunction } from '../getThemeValue';
6
-
7
6
  const splitProps = props => {
8
7
  const result = {
9
8
  systemProps: {},
@@ -18,35 +17,29 @@ const splitProps = props => {
18
17
  });
19
18
  return result;
20
19
  };
21
-
22
20
  export default function extendSxProp(props) {
23
21
  const {
24
- sx: inSx
25
- } = props,
26
- other = _objectWithoutPropertiesLoose(props, _excluded);
27
-
22
+ sx: inSx
23
+ } = props,
24
+ other = _objectWithoutPropertiesLoose(props, _excluded);
28
25
  const {
29
26
  systemProps,
30
27
  otherProps
31
28
  } = splitProps(other);
32
29
  let finalSx;
33
-
34
30
  if (Array.isArray(inSx)) {
35
31
  finalSx = [systemProps, ...inSx];
36
32
  } else if (typeof inSx === 'function') {
37
33
  finalSx = (...args) => {
38
34
  const result = inSx(...args);
39
-
40
35
  if (!isPlainObject(result)) {
41
36
  return systemProps;
42
37
  }
43
-
44
38
  return _extends({}, systemProps, result);
45
39
  };
46
40
  } else {
47
41
  finalSx = _extends({}, systemProps, inSx);
48
42
  }
49
-
50
43
  return _extends({}, otherProps, {
51
44
  sx: finalSx
52
45
  });
@@ -1,18 +1,16 @@
1
1
  import merge from '../merge';
2
2
  import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
3
3
  import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
4
-
5
4
  function objectsHaveSameKeys(...objects) {
6
5
  const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
7
6
  const union = new Set(allKeys);
8
7
  return objects.every(object => union.size === Object.keys(object).length);
9
8
  }
10
-
11
9
  function callIfFn(maybeFn, arg) {
12
10
  return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
13
- } // eslint-disable-next-line @typescript-eslint/naming-convention
14
-
11
+ }
15
12
 
13
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16
14
  export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
17
15
  const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
18
16
  styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
@@ -20,7 +18,6 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
20
18
  });
21
19
  return acc;
22
20
  }, {});
23
-
24
21
  function getThemeValue(prop, value, theme) {
25
22
  const inputProps = {
26
23
  [prop]: value,
@@ -31,43 +28,36 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
31
28
  [prop]: value
32
29
  };
33
30
  }
34
-
35
31
  function styleFunctionSx(props) {
36
32
  const {
37
33
  sx,
38
34
  theme = {}
39
35
  } = props || {};
40
-
41
36
  if (!sx) {
42
37
  return null; // Emotion & styled-components will neglect null
43
38
  }
39
+
44
40
  /*
45
41
  * Receive `sxInput` as object or callback
46
42
  * and then recursively check keys & values to create media query object styles.
47
43
  * (the result will be used in `styled`)
48
44
  */
49
-
50
-
51
45
  function traverse(sxInput) {
52
46
  let sxObject = sxInput;
53
-
54
47
  if (typeof sxInput === 'function') {
55
48
  sxObject = sxInput(theme);
56
49
  } else if (typeof sxInput !== 'object') {
57
50
  // value
58
51
  return sxInput;
59
52
  }
60
-
61
53
  if (!sxObject) {
62
54
  return null;
63
55
  }
64
-
65
56
  const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
66
57
  const breakpointsKeys = Object.keys(emptyBreakpoints);
67
58
  let css = emptyBreakpoints;
68
59
  Object.keys(sxObject).forEach(styleKey => {
69
60
  const value = callIfFn(sxObject[styleKey], theme);
70
-
71
61
  if (value !== null && value !== undefined) {
72
62
  if (typeof value === 'object') {
73
63
  if (propToStyleFunction[styleKey]) {
@@ -78,7 +68,6 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
78
68
  }, value, x => ({
79
69
  [styleKey]: x
80
70
  }));
81
-
82
71
  if (objectsHaveSameKeys(breakpointsValues, value)) {
83
72
  css[styleKey] = styleFunctionSx({
84
73
  sx: value,
@@ -95,10 +84,8 @@ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultSty
95
84
  });
96
85
  return removeUnusedBreakpoints(breakpointsKeys, css);
97
86
  }
98
-
99
87
  return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
100
88
  }
101
-
102
89
  return styleFunctionSx;
103
90
  }
104
91
  const styleFunctionSx = unstable_createStyleFunctionSx();