@mui/system 6.0.0-alpha.0 → 6.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +591 -6
  2. package/Container/Container.d.ts +1 -1
  3. package/Container/createContainer.js +39 -35
  4. package/RtlProvider/index.js +8 -11
  5. package/Stack/Stack.d.ts +1 -1
  6. package/Stack/createStack.d.ts +1 -1
  7. package/Stack/createStack.js +24 -26
  8. package/ThemeProvider/ThemeProvider.js +9 -5
  9. package/Unstable_Grid/Grid.d.ts +1 -1
  10. package/Unstable_Grid/createGrid.d.ts +1 -1
  11. package/Unstable_Grid/createGrid.js +21 -23
  12. package/Unstable_Grid/gridGenerator.js +20 -17
  13. package/breakpoints/breakpoints.js +26 -7
  14. package/createBox/createBox.js +9 -12
  15. package/createStyled/createStyled.js +56 -51
  16. package/createTheme/applyStyles.d.ts +1 -1
  17. package/createTheme/applyStyles.js +1 -1
  18. package/createTheme/createBreakpoints.js +24 -25
  19. package/createTheme/createSpacing.d.ts +2 -2
  20. package/createTheme/createSpacing.js +7 -8
  21. package/createTheme/createTheme.d.ts +2 -1
  22. package/createTheme/createTheme.js +20 -14
  23. package/cssContainerQueries/cssContainerQueries.d.ts +24 -0
  24. package/cssContainerQueries/cssContainerQueries.js +70 -0
  25. package/cssContainerQueries/index.d.ts +3 -0
  26. package/cssContainerQueries/index.js +2 -0
  27. package/cssContainerQueries/package.json +6 -0
  28. package/cssVars/createCssVarsProvider.d.ts +1 -1
  29. package/cssVars/createCssVarsProvider.js +20 -16
  30. package/cssVars/createCssVarsTheme.js +3 -3
  31. package/cssVars/cssVarsParser.d.ts +1 -1
  32. package/cssVars/cssVarsParser.js +3 -2
  33. package/cssVars/index.d.ts +2 -0
  34. package/cssVars/index.js +1 -0
  35. package/cssVars/prepareCssVars.js +30 -25
  36. package/cssVars/prepareTypographyVars.d.ts +8 -0
  37. package/cssVars/prepareTypographyVars.js +11 -0
  38. package/cssVars/useCurrentColorScheme.js +18 -11
  39. package/index.d.ts +2 -0
  40. package/index.js +2 -1
  41. package/modern/Container/createContainer.js +39 -35
  42. package/modern/RtlProvider/index.js +8 -11
  43. package/modern/Stack/createStack.js +24 -26
  44. package/modern/ThemeProvider/ThemeProvider.js +9 -5
  45. package/modern/Unstable_Grid/createGrid.js +21 -23
  46. package/modern/Unstable_Grid/gridGenerator.js +20 -17
  47. package/modern/breakpoints/breakpoints.js +26 -7
  48. package/modern/createBox/createBox.js +9 -12
  49. package/modern/createStyled/createStyled.js +56 -51
  50. package/modern/createTheme/applyStyles.js +1 -1
  51. package/modern/createTheme/createBreakpoints.js +24 -25
  52. package/modern/createTheme/createSpacing.js +7 -8
  53. package/modern/createTheme/createTheme.js +20 -14
  54. package/modern/cssContainerQueries/cssContainerQueries.js +70 -0
  55. package/modern/cssContainerQueries/index.js +2 -0
  56. package/modern/cssVars/createCssVarsProvider.js +20 -16
  57. package/modern/cssVars/createCssVarsTheme.js +3 -3
  58. package/modern/cssVars/cssVarsParser.js +3 -2
  59. package/modern/cssVars/index.js +1 -0
  60. package/modern/cssVars/prepareCssVars.js +30 -25
  61. package/modern/cssVars/prepareTypographyVars.js +11 -0
  62. package/modern/cssVars/useCurrentColorScheme.js +18 -11
  63. package/modern/index.js +2 -1
  64. package/modern/propsToClassKey/propsToClassKey.js +3 -5
  65. package/modern/spacing/spacing.js +24 -21
  66. package/modern/styleFunctionSx/defaultSxConfig.js +3 -0
  67. package/modern/styleFunctionSx/extendSxProp.js +14 -10
  68. package/modern/styleFunctionSx/styleFunctionSx.js +2 -1
  69. package/node/Container/createContainer.js +39 -35
  70. package/node/RtlProvider/index.js +8 -11
  71. package/node/Stack/createStack.js +24 -26
  72. package/node/ThemeProvider/ThemeProvider.js +9 -5
  73. package/node/Unstable_Grid/createGrid.js +23 -25
  74. package/node/Unstable_Grid/gridGenerator.js +20 -18
  75. package/node/breakpoints/breakpoints.js +26 -7
  76. package/node/createBox/createBox.js +9 -12
  77. package/node/createStyled/createStyled.js +58 -52
  78. package/node/createTheme/applyStyles.js +1 -1
  79. package/node/createTheme/createBreakpoints.js +24 -26
  80. package/node/createTheme/createSpacing.js +7 -8
  81. package/node/createTheme/createTheme.js +20 -14
  82. package/node/cssContainerQueries/cssContainerQueries.js +81 -0
  83. package/node/cssContainerQueries/index.js +32 -0
  84. package/node/cssVars/createCssVarsProvider.js +20 -16
  85. package/node/cssVars/createCssVarsTheme.js +3 -3
  86. package/node/cssVars/cssVarsParser.js +3 -2
  87. package/node/cssVars/index.js +7 -0
  88. package/node/cssVars/prepareCssVars.js +30 -25
  89. package/node/cssVars/prepareTypographyVars.js +17 -0
  90. package/node/cssVars/useCurrentColorScheme.js +18 -12
  91. package/node/index.js +9 -1
  92. package/node/propsToClassKey/propsToClassKey.js +3 -5
  93. package/node/spacing/spacing.js +24 -21
  94. package/node/styleFunctionSx/defaultSxConfig.js +3 -0
  95. package/node/styleFunctionSx/extendSxProp.js +14 -10
  96. package/node/styleFunctionSx/styleFunctionSx.js +2 -1
  97. package/package.json +6 -6
  98. package/propsToClassKey/propsToClassKey.js +3 -5
  99. package/spacing/spacing.js +24 -21
  100. package/styleFunctionSx/defaultSxConfig.js +3 -0
  101. package/styleFunctionSx/extendSxProp.js +14 -10
  102. package/styleFunctionSx/styleFunctionSx.js +2 -1
  103. package/legacy/Box/Box.js +0 -30
  104. package/legacy/Box/boxClasses.js +0 -3
  105. package/legacy/Box/index.js +0 -5
  106. package/legacy/Container/Container.js +0 -61
  107. package/legacy/Container/ContainerProps.js +0 -1
  108. package/legacy/Container/containerClasses.js +0 -7
  109. package/legacy/Container/createContainer.js +0 -140
  110. package/legacy/Container/index.js +0 -5
  111. package/legacy/GlobalStyles/GlobalStyles.js +0 -37
  112. package/legacy/GlobalStyles/index.js +0 -4
  113. package/legacy/RtlProvider/index.js +0 -22
  114. package/legacy/Stack/Stack.js +0 -62
  115. package/legacy/Stack/StackProps.js +0 -1
  116. package/legacy/Stack/createStack.js +0 -180
  117. package/legacy/Stack/index.js +0 -7
  118. package/legacy/Stack/stackClasses.js +0 -7
  119. package/legacy/ThemeProvider/ThemeProvider.js +0 -87
  120. package/legacy/ThemeProvider/index.js +0 -3
  121. package/legacy/Unstable_Grid/Grid.js +0 -177
  122. package/legacy/Unstable_Grid/GridProps.js +0 -1
  123. package/legacy/Unstable_Grid/createGrid.js +0 -184
  124. package/legacy/Unstable_Grid/gridClasses.js +0 -28
  125. package/legacy/Unstable_Grid/gridGenerator.js +0 -216
  126. package/legacy/Unstable_Grid/index.js +0 -8
  127. package/legacy/Unstable_Grid/traverseBreakpoints.js +0 -48
  128. package/legacy/borders/borders.js +0 -51
  129. package/legacy/borders/index.js +0 -4
  130. package/legacy/breakpoints/breakpoints.js +0 -162
  131. package/legacy/breakpoints/index.js +0 -4
  132. package/legacy/colorManipulator/colorManipulator.js +0 -356
  133. package/legacy/colorManipulator/index.js +0 -3
  134. package/legacy/compose/compose.js +0 -32
  135. package/legacy/compose/index.js +0 -3
  136. package/legacy/createBox/createBox.js +0 -38
  137. package/legacy/createBox/index.js +0 -3
  138. package/legacy/createStyled/createStyled.js +0 -250
  139. package/legacy/createStyled/index.js +0 -4
  140. package/legacy/createTheme/applyStyles.js +0 -73
  141. package/legacy/createTheme/createBreakpoints.js +0 -83
  142. package/legacy/createTheme/createSpacing.js +0 -36
  143. package/legacy/createTheme/createTheme.js +0 -49
  144. package/legacy/createTheme/index.js +0 -3
  145. package/legacy/createTheme/shape.js +0 -4
  146. package/legacy/cssGrid/cssGrid.js +0 -91
  147. package/legacy/cssGrid/index.js +0 -4
  148. package/legacy/cssVars/createCssVarsProvider.js +0 -335
  149. package/legacy/cssVars/createCssVarsTheme.js +0 -13
  150. package/legacy/cssVars/createGetCssVar.js +0 -30
  151. package/legacy/cssVars/cssVarsParser.js +0 -140
  152. package/legacy/cssVars/getInitColorSchemeScript.js +0 -28
  153. package/legacy/cssVars/index.js +0 -6
  154. package/legacy/cssVars/prepareCssVars.js +0 -92
  155. package/legacy/cssVars/useCurrentColorScheme.js +0 -237
  156. package/legacy/display/display.js +0 -29
  157. package/legacy/display/index.js +0 -4
  158. package/legacy/flexbox/flexbox.js +0 -43
  159. package/legacy/flexbox/index.js +0 -4
  160. package/legacy/getThemeValue/getThemeValue.js +0 -47
  161. package/legacy/getThemeValue/index.js +0 -4
  162. package/legacy/index.js +0 -72
  163. package/legacy/memoize/index.js +0 -3
  164. package/legacy/memoize/memoize.js +0 -9
  165. package/legacy/merge/index.js +0 -3
  166. package/legacy/merge/merge.js +0 -10
  167. package/legacy/palette/index.js +0 -4
  168. package/legacy/palette/palette.js +0 -26
  169. package/legacy/positions/index.js +0 -4
  170. package/legacy/positions/positions.js +0 -22
  171. package/legacy/propsToClassKey/index.js +0 -3
  172. package/legacy/propsToClassKey/propsToClassKey.js +0 -24
  173. package/legacy/responsivePropType/index.js +0 -3
  174. package/legacy/responsivePropType/responsivePropType.js +0 -3
  175. package/legacy/shadows/index.js +0 -3
  176. package/legacy/shadows/shadows.js +0 -6
  177. package/legacy/sizing/index.js +0 -4
  178. package/legacy/sizing/sizing.js +0 -65
  179. package/legacy/spacing/index.js +0 -4
  180. package/legacy/spacing/spacing.js +0 -158
  181. package/legacy/style/index.js +0 -4
  182. package/legacy/style/style.js +0 -73
  183. package/legacy/styleFunctionSx/defaultSxConfig.js +0 -293
  184. package/legacy/styleFunctionSx/extendSxProp.js +0 -45
  185. package/legacy/styleFunctionSx/index.js +0 -4
  186. package/legacy/styleFunctionSx/styleFunctionSx.js +0 -126
  187. package/legacy/styled/index.js +0 -3
  188. package/legacy/styled/styled.js +0 -3
  189. package/legacy/typography/index.js +0 -4
  190. package/legacy/typography/typography.js +0 -37
  191. package/legacy/useMediaQuery/index.js +0 -2
  192. package/legacy/useMediaQuery/useMediaQuery.js +0 -145
  193. package/legacy/useTheme/index.js +0 -4
  194. package/legacy/useTheme/useTheme.js +0 -10
  195. package/legacy/useThemeProps/getThemeProps.js +0 -10
  196. package/legacy/useThemeProps/index.js +0 -4
  197. package/legacy/useThemeProps/useThemeProps.js +0 -20
  198. package/legacy/useThemeWithoutDefault/index.js +0 -3
  199. package/legacy/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -13
@@ -1,8 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["ownerState"],
4
- _excluded2 = ["variants"],
5
- _excluded3 = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
6
1
  /* eslint-disable no-underscore-dangle */
7
2
  import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
8
3
  import { isPlainObject } from '@mui/utils/deepmerge';
@@ -47,31 +42,35 @@ function defaultOverridesResolver(slot) {
47
42
  }
48
43
  return (props, styles) => styles[slot];
49
44
  }
50
- function processStyleArg(callableStyle, _ref) {
51
- let {
52
- ownerState
53
- } = _ref,
54
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
55
- const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle(_extends({
56
- ownerState
57
- }, props)) : callableStyle;
45
+ function processStyleArg(callableStyle, {
46
+ ownerState,
47
+ ...props
48
+ }) {
49
+ const resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle({
50
+ ownerState,
51
+ ...props
52
+ }) : callableStyle;
58
53
  if (Array.isArray(resolvedStylesArg)) {
59
- return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, _extends({
60
- ownerState
61
- }, props)));
54
+ return resolvedStylesArg.flatMap(resolvedStyle => processStyleArg(resolvedStyle, {
55
+ ownerState,
56
+ ...props
57
+ }));
62
58
  }
59
+ const mergedState = {
60
+ ...props,
61
+ ...ownerState,
62
+ ownerState
63
+ };
63
64
  if (!!resolvedStylesArg && typeof resolvedStylesArg === 'object' && Array.isArray(resolvedStylesArg.variants)) {
64
65
  const {
65
- variants = []
66
- } = resolvedStylesArg,
67
- otherStyles = _objectWithoutPropertiesLoose(resolvedStylesArg, _excluded2);
66
+ variants = [],
67
+ ...otherStyles
68
+ } = resolvedStylesArg;
68
69
  let result = otherStyles;
69
70
  variants.forEach(variant => {
70
71
  let isMatch = true;
71
72
  if (typeof variant.props === 'function') {
72
- isMatch = variant.props(_extends({
73
- ownerState
74
- }, props, ownerState));
73
+ isMatch = variant.props(mergedState);
75
74
  } else {
76
75
  Object.keys(variant.props).forEach(key => {
77
76
  if (ownerState?.[key] !== variant.props[key] && props[key] !== variant.props[key]) {
@@ -83,9 +82,7 @@ function processStyleArg(callableStyle, _ref) {
83
82
  if (!Array.isArray(result)) {
84
83
  result = [result];
85
84
  }
86
- result.push(typeof variant.style === 'function' ? variant.style(_extends({
87
- ownerState
88
- }, props, ownerState)) : variant.style);
85
+ result.push(typeof variant.style === 'function' ? variant.style(mergedState) : variant.style);
89
86
  }
90
87
  });
91
88
  return result;
@@ -100,27 +97,29 @@ export default function createStyled(input = {}) {
100
97
  slotShouldForwardProp = shouldForwardProp
101
98
  } = input;
102
99
  const systemSx = props => {
103
- return styleFunctionSx(_extends({}, props, {
104
- theme: resolveTheme(_extends({}, props, {
100
+ return styleFunctionSx({
101
+ ...props,
102
+ theme: resolveTheme({
103
+ ...props,
105
104
  defaultTheme,
106
105
  themeId
107
- }))
108
- }));
106
+ })
107
+ });
109
108
  };
110
109
  systemSx.__mui_systemSx = true;
111
110
  return (tag, inputOptions = {}) => {
112
111
  // Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
113
112
  processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
114
113
  const {
115
- name: componentName,
116
- slot: componentSlot,
117
- skipVariantsResolver: inputSkipVariantsResolver,
118
- skipSx: inputSkipSx,
119
- // TODO v6: remove `lowercaseFirstLetter()` in the next major release
120
- // For more details: https://github.com/mui/material-ui/pull/37908
121
- overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot))
122
- } = inputOptions,
123
- options = _objectWithoutPropertiesLoose(inputOptions, _excluded3);
114
+ name: componentName,
115
+ slot: componentSlot,
116
+ skipVariantsResolver: inputSkipVariantsResolver,
117
+ skipSx: inputSkipSx,
118
+ // TODO v6: remove `lowercaseFirstLetter()` in the next major release
119
+ // For more details: https://github.com/mui/material-ui/pull/37908
120
+ overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot)),
121
+ ...options
122
+ } = inputOptions;
124
123
 
125
124
  // if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
126
125
  const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
@@ -149,22 +148,24 @@ export default function createStyled(input = {}) {
149
148
  // for string (html) tag, preserve the behavior in emotion & styled-components.
150
149
  shouldForwardPropOption = undefined;
151
150
  }
152
- const defaultStyledResolver = styledEngineStyled(tag, _extends({
151
+ const defaultStyledResolver = styledEngineStyled(tag, {
153
152
  shouldForwardProp: shouldForwardPropOption,
154
- label
155
- }, options));
153
+ label,
154
+ ...options
155
+ });
156
156
  const transformStyleArg = stylesArg => {
157
157
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
158
158
  // component stays as a function. This condition makes sure that we do not interpolate functions
159
159
  // which are basically components used as a selectors.
160
160
  if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
161
- return props => processStyleArg(stylesArg, _extends({}, props, {
161
+ return props => processStyleArg(stylesArg, {
162
+ ...props,
162
163
  theme: resolveTheme({
163
164
  theme: props.theme,
164
165
  defaultTheme,
165
166
  themeId
166
167
  })
167
- }));
168
+ });
168
169
  }
169
170
  return stylesArg;
170
171
  };
@@ -173,10 +174,11 @@ export default function createStyled(input = {}) {
173
174
  const expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
174
175
  if (componentName && overridesResolver) {
175
176
  expressionsWithDefaultTheme.push(props => {
176
- const theme = resolveTheme(_extends({}, props, {
177
+ const theme = resolveTheme({
178
+ ...props,
177
179
  defaultTheme,
178
180
  themeId
179
- }));
181
+ });
180
182
  if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
181
183
  return null;
182
184
  }
@@ -184,25 +186,28 @@ export default function createStyled(input = {}) {
184
186
  const resolvedStyleOverrides = {};
185
187
  // TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
186
188
  Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
187
- resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, _extends({}, props, {
189
+ resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, {
190
+ ...props,
188
191
  theme
189
- }));
192
+ });
190
193
  });
191
194
  return overridesResolver(props, resolvedStyleOverrides);
192
195
  });
193
196
  }
194
197
  if (componentName && !skipVariantsResolver) {
195
198
  expressionsWithDefaultTheme.push(props => {
196
- const theme = resolveTheme(_extends({}, props, {
199
+ const theme = resolveTheme({
200
+ ...props,
197
201
  defaultTheme,
198
202
  themeId
199
- }));
203
+ });
200
204
  const themeVariants = theme?.components?.[componentName]?.variants;
201
205
  return processStyleArg({
202
206
  variants: themeVariants
203
- }, _extends({}, props, {
207
+ }, {
208
+ ...props,
204
209
  theme
205
- }));
210
+ });
206
211
  });
207
212
  }
208
213
  if (!skipSx) {
@@ -6,7 +6,7 @@ export interface ApplyStyles<K extends string> {
6
6
  * A universal utility to style components with multiple color modes. Always use it from the theme object.
7
7
  * It works with:
8
8
  * - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
9
- * - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
9
+ * - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
10
10
  * - Zero-runtime engine
11
11
  *
12
12
  * Tips: Use an array over object spread and place `theme.applyStyles()` last.
@@ -2,7 +2,7 @@
2
2
  * A universal utility to style components with multiple color modes. Always use it from the theme object.
3
3
  * It works with:
4
4
  * - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
5
- * - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
5
+ * - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
6
6
  * - Zero-runtime engine
7
7
  *
8
8
  * Tips: Use an array over object spread and place `theme.applyStyles()` last.
@@ -1,6 +1,3 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["values", "unit", "step"];
4
1
  // Sorted ASC by size. That's important.
5
2
  // It can't be configured as it's used statically for propTypes.
6
3
  export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
@@ -12,32 +9,33 @@ const sortBreakpointsValues = values => {
12
9
  // Sort in ascending order
13
10
  breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
14
11
  return breakpointsAsArray.reduce((acc, obj) => {
15
- return _extends({}, acc, {
12
+ return {
13
+ ...acc,
16
14
  [obj.key]: obj.val
17
- });
15
+ };
18
16
  }, {});
19
17
  };
20
18
 
21
19
  // Keep in mind that @media is inclusive by the CSS specification.
22
20
  export default function createBreakpoints(breakpoints) {
23
21
  const {
24
- // The breakpoint **start** at this value.
25
- // For instance with the first breakpoint xs: [xs, sm).
26
- values = {
27
- xs: 0,
28
- // phone
29
- sm: 600,
30
- // tablet
31
- md: 900,
32
- // small laptop
33
- lg: 1200,
34
- // desktop
35
- xl: 1536 // large screen
36
- },
37
- unit = 'px',
38
- step = 5
39
- } = breakpoints,
40
- other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
22
+ // The breakpoint **start** at this value.
23
+ // For instance with the first breakpoint xs: [xs, sm).
24
+ values = {
25
+ xs: 0,
26
+ // phone
27
+ sm: 600,
28
+ // tablet
29
+ md: 900,
30
+ // small laptop
31
+ lg: 1200,
32
+ // desktop
33
+ xl: 1536 // large screen
34
+ },
35
+ unit = 'px',
36
+ step = 5,
37
+ ...other
38
+ } = breakpoints;
41
39
  const sortedValues = sortBreakpointsValues(values);
42
40
  const keys = Object.keys(sortedValues);
43
41
  function up(key) {
@@ -69,7 +67,7 @@ export default function createBreakpoints(breakpoints) {
69
67
  }
70
68
  return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
71
69
  }
72
- return _extends({
70
+ return {
73
71
  keys,
74
72
  values: sortedValues,
75
73
  up,
@@ -77,6 +75,7 @@ export default function createBreakpoints(breakpoints) {
77
75
  between,
78
76
  only,
79
77
  not,
80
- unit
81
- }, other);
78
+ unit,
79
+ ...other
80
+ };
82
81
  }
@@ -1,4 +1,4 @@
1
- export type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
1
+ export type SpacingOptions = number | string | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
2
  export type SpacingArgument = number | string;
3
3
  export interface Spacing {
4
4
  (): string;
@@ -7,4 +7,4 @@ export interface Spacing {
7
7
  (top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
8
8
  (top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
9
9
  }
10
- export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
10
+ export default function createSpacing(spacingInput?: SpacingOptions, transform?: Spacing | (() => undefined) | ((abs: string | number) => number)): Spacing;
@@ -3,18 +3,17 @@ import { createUnarySpacing } from '../spacing';
3
3
  // The different signatures imply different meaning for their arguments that can't be expressed structurally.
4
4
  // We express the difference with variable names.
5
5
 
6
- export default function createSpacing(spacingInput = 8) {
6
+ export default function createSpacing(spacingInput = 8,
7
+ // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
8
+ // Smaller components, such as icons, can align to a 4dp grid.
9
+ // https://m2.material.io/design/layout/understanding-layout.html
10
+ transform = createUnarySpacing({
11
+ spacing: spacingInput
12
+ })) {
7
13
  // Already transformed.
8
14
  if (spacingInput.mui) {
9
15
  return spacingInput;
10
16
  }
11
-
12
- // Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
13
- // Smaller components, such as icons, can align to a 4dp grid.
14
- // https://m2.material.io/design/layout/understanding-layout.html
15
- const transform = createUnarySpacing({
16
- spacing: spacingInput
17
- });
18
17
  const spacing = (...argsInput) => {
19
18
  if (process.env.NODE_ENV !== 'production') {
20
19
  if (!(argsInput.length <= 4)) {
@@ -4,6 +4,7 @@ import { Shape, ShapeOptions } from './shape';
4
4
  import { Spacing, SpacingOptions } from './createSpacing';
5
5
  import { SxConfig, SxProps } from '../styleFunctionSx';
6
6
  import { ApplyStyles } from './applyStyles';
7
+ import { CssContainerQueries } from '../cssContainerQueries';
7
8
 
8
9
  export { Breakpoint, BreakpointOverrides } from './createBreakpoints';
9
10
 
@@ -24,7 +25,7 @@ export interface ThemeOptions {
24
25
  unstable_sxConfig?: SxConfig;
25
26
  }
26
27
 
27
- export interface Theme {
28
+ export interface Theme extends CssContainerQueries {
28
29
  shape: Shape;
29
30
  breakpoints: Breakpoints;
30
31
  direction: Direction;
@@ -1,8 +1,6 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["breakpoints", "palette", "spacing", "shape"];
4
1
  import deepmerge from '@mui/utils/deepmerge';
5
2
  import createBreakpoints from './createBreakpoints';
3
+ import cssContainerQueries from '../cssContainerQueries';
6
4
  import shape from './shape';
7
5
  import createSpacing from './createSpacing';
8
6
  import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
@@ -10,12 +8,12 @@ import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
10
8
  import applyStyles from './applyStyles';
11
9
  function createTheme(options = {}, ...args) {
12
10
  const {
13
- breakpoints: breakpointsInput = {},
14
- palette: paletteInput = {},
15
- spacing: spacingInput,
16
- shape: shapeInput = {}
17
- } = options,
18
- other = _objectWithoutPropertiesLoose(options, _excluded);
11
+ breakpoints: breakpointsInput = {},
12
+ palette: paletteInput = {},
13
+ spacing: spacingInput,
14
+ shape: shapeInput = {},
15
+ ...other
16
+ } = options;
19
17
  const breakpoints = createBreakpoints(breakpointsInput);
20
18
  const spacing = createSpacing(spacingInput);
21
19
  let muiTheme = deepmerge({
@@ -23,15 +21,23 @@ function createTheme(options = {}, ...args) {
23
21
  direction: 'ltr',
24
22
  components: {},
25
23
  // Inject component definitions.
26
- palette: _extends({
27
- mode: 'light'
28
- }, paletteInput),
24
+ palette: {
25
+ mode: 'light',
26
+ ...paletteInput
27
+ },
29
28
  spacing,
30
- shape: _extends({}, shape, shapeInput)
29
+ shape: {
30
+ ...shape,
31
+ ...shapeInput
32
+ }
31
33
  }, other);
34
+ muiTheme = cssContainerQueries(muiTheme);
32
35
  muiTheme.applyStyles = applyStyles;
33
36
  muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
34
- muiTheme.unstable_sxConfig = _extends({}, defaultSxConfig, other?.unstable_sxConfig);
37
+ muiTheme.unstable_sxConfig = {
38
+ ...defaultSxConfig,
39
+ ...other?.unstable_sxConfig
40
+ };
35
41
  muiTheme.unstable_sx = function sx(props) {
36
42
  return styleFunctionSx({
37
43
  sx: props,
@@ -0,0 +1,24 @@
1
+ import { Breakpoints } from '../createTheme/createBreakpoints';
2
+ interface ContainerQueries {
3
+ up: Breakpoints['up'];
4
+ down: Breakpoints['down'];
5
+ between: Breakpoints['between'];
6
+ only: Breakpoints['only'];
7
+ not: Breakpoints['not'];
8
+ }
9
+ export interface CssContainerQueries {
10
+ containerQueries: ((name: string) => ContainerQueries) & ContainerQueries;
11
+ }
12
+ /**
13
+ * For using in `sx` prop to sort the breakpoint from low to high.
14
+ * Note: this function does not work and will not support multiple units.
15
+ * e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
16
+ * output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
17
+ */
18
+ export declare function sortContainerQueries(theme: Partial<CssContainerQueries>, css: Record<string, any>): Record<string, any>;
19
+ export declare function isCqShorthand(breakpointKeys: string[], value: string): boolean;
20
+ export declare function getContainerQuery(theme: CssContainerQueries, shorthand: string): string | null;
21
+ export default function cssContainerQueries<T extends {
22
+ breakpoints: Breakpoints;
23
+ }>(themeInput: T): T & CssContainerQueries;
24
+ export {};
@@ -0,0 +1,70 @@
1
+ import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
2
+ /**
3
+ * For using in `sx` prop to sort the breakpoint from low to high.
4
+ * Note: this function does not work and will not support multiple units.
5
+ * e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
6
+ * output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
7
+ */
8
+ export function sortContainerQueries(theme, css) {
9
+ if (!theme.containerQueries) {
10
+ return css;
11
+ }
12
+ const sorted = Object.keys(css).filter(key => key.startsWith('@container')).sort((a, b) => {
13
+ const regex = /min-width:\s*([0-9.]+)/;
14
+ return +(a.match(regex)?.[1] || 0) - +(b.match(regex)?.[1] || 0);
15
+ });
16
+ if (!sorted.length) {
17
+ return css;
18
+ }
19
+ return sorted.reduce((acc, key) => {
20
+ const value = css[key];
21
+ delete acc[key];
22
+ acc[key] = value;
23
+ return acc;
24
+ }, {
25
+ ...css
26
+ });
27
+ }
28
+ export function isCqShorthand(breakpointKeys, value) {
29
+ return value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
30
+ }
31
+ export function getContainerQuery(theme, shorthand) {
32
+ const matches = shorthand.match(/^@([^/]+)\/?(.+)?$/);
33
+ if (!matches) {
34
+ if (process.env.NODE_ENV !== 'production') {
35
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
36
+ For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.` : _formatMuiErrorMessage(21, `(${shorthand})`));
37
+ }
38
+ return null;
39
+ }
40
+ const [, containerQuery, containerName] = matches;
41
+ const value = Number.isNaN(+containerQuery) ? containerQuery : +containerQuery;
42
+ return theme.containerQueries(containerName).up(value);
43
+ }
44
+ export default function cssContainerQueries(themeInput) {
45
+ const toContainerQuery = (mediaQuery, name) => mediaQuery.replace('@media', name ? `@container ${name}` : '@container');
46
+ function attachCq(node, name) {
47
+ node.up = (...args) => toContainerQuery(themeInput.breakpoints.up(...args), name);
48
+ node.down = (...args) => toContainerQuery(themeInput.breakpoints.down(...args), name);
49
+ node.between = (...args) => toContainerQuery(themeInput.breakpoints.between(...args), name);
50
+ node.only = (...args) => toContainerQuery(themeInput.breakpoints.only(...args), name);
51
+ node.not = (...args) => {
52
+ const result = toContainerQuery(themeInput.breakpoints.not(...args), name);
53
+ if (result.includes('not all and')) {
54
+ // `@container` does not work with `not all and`, so need to invert the logic
55
+ return result.replace('not all and ', '').replace('min-width:', 'width<').replace('max-width:', 'width>');
56
+ }
57
+ return result;
58
+ };
59
+ }
60
+ const node = {};
61
+ const containerQueries = name => {
62
+ attachCq(node, name);
63
+ return node;
64
+ };
65
+ attachCq(containerQueries);
66
+ return {
67
+ ...themeInput,
68
+ containerQueries
69
+ };
70
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from './cssContainerQueries';
2
+ export { isCqShorthand, getContainerQuery, sortContainerQueries } from './cssContainerQueries';
3
+ export type { CssContainerQueries } from './cssContainerQueries';
@@ -0,0 +1,2 @@
1
+ export { default } from './cssContainerQueries';
2
+ export { isCqShorthand, getContainerQuery, sortContainerQueries } from './cssContainerQueries';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/cssContainerQueries/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -90,7 +90,7 @@ export interface CreateCssVarsProviderResult<
90
90
  disableStyleSheetGeneration?: boolean;
91
91
  }
92
92
  >,
93
- ) => React.ReactElement;
93
+ ) => React.ReactElement<any>;
94
94
  useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
95
95
  getInitColorSchemeScript: typeof getInitColorSchemeScript;
96
96
  }
@@ -1,7 +1,4 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
1
  import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
4
- const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
5
2
  import * as React from 'react';
6
3
  import PropTypes from 'prop-types';
7
4
  import { GlobalStyles } from '@mui/styled-engine';
@@ -65,13 +62,12 @@ export default function createCssVarsProvider(options) {
65
62
  const ctx = React.useContext(ColorSchemeContext);
66
63
  const nested = !!ctx && !disableNestedContext;
67
64
  const scopedTheme = themeProp[themeId];
68
- const _ref = scopedTheme || themeProp,
69
- {
70
- colorSchemes = {},
71
- components = {},
72
- cssVarPrefix
73
- } = _ref,
74
- restThemeProp = _objectWithoutPropertiesLoose(_ref, _excluded);
65
+ const {
66
+ colorSchemes = {},
67
+ components = {},
68
+ cssVarPrefix,
69
+ ...restThemeProp
70
+ } = scopedTheme || themeProp;
75
71
  const allColorSchemes = Object.keys(colorSchemes);
76
72
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
77
73
  const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
@@ -126,12 +122,16 @@ export default function createCssVarsProvider(options) {
126
122
  const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
127
123
 
128
124
  // 3. Start composing the theme object
129
- const theme = _extends({}, restThemeProp, {
125
+ const theme = {
126
+ ...restThemeProp,
130
127
  components,
131
128
  colorSchemes,
132
129
  cssVarPrefix,
133
130
  vars: themeVars
134
- });
131
+ };
132
+ if (typeof theme.generateSpacing === 'function') {
133
+ theme.spacing = theme.generateSpacing();
134
+ }
135
135
 
136
136
  // 4. Resolve the color scheme and merge it to the theme
137
137
  Object.entries(colorSchemes).forEach(([key, scheme]) => {
@@ -140,7 +140,10 @@ export default function createCssVarsProvider(options) {
140
140
  Object.keys(scheme).forEach(schemeKey => {
141
141
  if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
142
142
  // shallow merge the 1st level structure of the theme.
143
- theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
143
+ theme[schemeKey] = {
144
+ ...theme[schemeKey],
145
+ ...scheme[schemeKey]
146
+ };
144
147
  } else {
145
148
  theme[schemeKey] = scheme[schemeKey];
146
149
  }
@@ -296,14 +299,15 @@ export default function createCssVarsProvider(options) {
296
299
  } : void 0;
297
300
  const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
298
301
  const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
299
- const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
302
+ const getInitColorSchemeScript = params => systemGetInitColorSchemeScript({
300
303
  attribute: defaultAttribute,
301
304
  colorSchemeStorageKey: defaultColorSchemeStorageKey,
302
305
  defaultMode: designSystemMode,
303
306
  defaultLightColorScheme,
304
307
  defaultDarkColorScheme,
305
- modeStorageKey: defaultModeStorageKey
306
- }, params));
308
+ modeStorageKey: defaultModeStorageKey,
309
+ ...params
310
+ });
307
311
  return {
308
312
  CssVarsProvider,
309
313
  useColorScheme,
@@ -1,10 +1,10 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import prepareCssVars from './prepareCssVars';
3
2
  function createCssVarsTheme(theme) {
4
3
  const output = theme;
5
- const result = prepareCssVars(output, _extends({}, theme, {
4
+ const result = prepareCssVars(output, {
5
+ ...theme,
6
6
  prefix: theme.cssVarPrefix
7
- }));
7
+ });
8
8
  output.vars = result.vars;
9
9
  output.generateThemeVars = result.generateThemeVars;
10
10
  output.generateStyleSheets = result.generateStyleSheets;
@@ -30,7 +30,7 @@ export declare const assignNestedKeys: <T extends string | Record<string, any> |
30
30
  * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
31
  * // ['palette', 'primary', 'main'] '#000000'
32
32
  */
33
- export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
33
+ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: (keys: Array<string>) => boolean) => void;
34
34
  /**
35
35
  * a function that parse theme and return { css, vars }
36
36
  *
@@ -111,11 +111,12 @@ export default function cssVarsParser(theme, options) {
111
111
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
112
112
  // only create css & var if `shouldSkipGeneratingVar` return false
113
113
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
114
+ const resolvedValue = getCssValue(keys, value);
114
115
  Object.assign(css, {
115
- [cssVar]: getCssValue(keys, value)
116
+ [cssVar]: resolvedValue
116
117
  });
117
118
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
118
- assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
119
+ assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${resolvedValue})`, arrayKeys);
119
120
  }
120
121
  }
121
122
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
@@ -2,4 +2,6 @@ export { default } from './createCssVarsProvider';
2
2
  export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
3
  export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
4
4
  export { default as prepareCssVars } from './prepareCssVars';
5
+ export { default as prepareTypographyVars } from './prepareTypographyVars';
6
+ export type { ExtractTypographyTokens } from './prepareTypographyVars';
5
7
  export { default as createCssVarsTheme } from './createCssVarsTheme';