@mui/system 5.4.1 → 5.4.2

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 (60) hide show
  1. package/Box/Box.d.ts +1 -1
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +65 -0
  4. package/createBox.d.ts +2 -0
  5. package/createBox.js +3 -2
  6. package/createBox.spec.d.ts +1 -1
  7. package/createStyled.d.ts +2 -1
  8. package/createStyled.js +7 -5
  9. package/createTheme/createBreakpoints.js +21 -6
  10. package/createTheme/createSpacing.d.ts +10 -10
  11. package/cssVars/createCssVarsProvider.d.ts +7 -0
  12. package/cssVars/createCssVarsProvider.js +4 -2
  13. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  14. package/cssVars/createGetCssVar.d.ts +5 -5
  15. package/cssVars/createGetCssVar.js +7 -1
  16. package/cssVars/cssVarsParser.d.ts +68 -68
  17. package/cssVars/cssVarsParser.js +4 -3
  18. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  19. package/cssVars/index.d.ts +2 -2
  20. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  21. package/esm/createBox.js +3 -2
  22. package/esm/createStyled.js +5 -3
  23. package/esm/createTheme/createBreakpoints.js +20 -4
  24. package/esm/cssVars/createCssVarsProvider.js +4 -2
  25. package/esm/cssVars/createGetCssVar.js +7 -1
  26. package/esm/cssVars/cssVarsParser.js +4 -3
  27. package/esm/getThemeValue.js +1 -1
  28. package/esm/index.js +1 -1
  29. package/esm/styleFunctionSx/index.js +1 -0
  30. package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
  31. package/getThemeValue.js +2 -1
  32. package/index.d.ts +1 -0
  33. package/index.js +8 -1
  34. package/index.spec.d.ts +1 -1
  35. package/legacy/createBox.js +4 -2
  36. package/legacy/createStyled.js +6 -3
  37. package/legacy/createTheme/createBreakpoints.js +23 -4
  38. package/legacy/cssVars/createCssVarsProvider.js +4 -2
  39. package/legacy/cssVars/createGetCssVar.js +7 -1
  40. package/legacy/cssVars/cssVarsParser.js +4 -3
  41. package/legacy/getThemeValue.js +1 -1
  42. package/legacy/index.js +2 -2
  43. package/legacy/styleFunctionSx/index.js +1 -0
  44. package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
  45. package/modern/createBox.js +3 -2
  46. package/modern/createStyled.js +5 -3
  47. package/modern/createTheme/createBreakpoints.js +20 -4
  48. package/modern/cssVars/createCssVarsProvider.js +4 -2
  49. package/modern/cssVars/createGetCssVar.js +7 -1
  50. package/modern/cssVars/cssVarsParser.js +4 -3
  51. package/modern/getThemeValue.js +1 -1
  52. package/modern/index.js +2 -2
  53. package/modern/styleFunctionSx/index.js +1 -0
  54. package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
  55. package/package.json +5 -5
  56. package/style.d.ts +1 -1
  57. package/styleFunctionSx/index.js +12 -2
  58. package/styleFunctionSx/styleFunctionSx.d.ts +12 -1
  59. package/styleFunctionSx/styleFunctionSx.js +79 -54
  60. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -6,8 +6,8 @@ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesR
6
6
  import styledEngineStyled from '@mui/styled-engine';
7
7
  import { getDisplayName } from '@mui/utils';
8
8
  import createTheme from './createTheme';
9
- import styleFunctionSx from './styleFunctionSx';
10
9
  import propsToClassKey from './propsToClassKey';
10
+ import defaultStyleFunctionSx from './styleFunctionSx';
11
11
 
12
12
  function isEmpty(obj) {
13
13
  return Object.keys(obj).length === 0;
@@ -61,7 +61,8 @@ const variantsResolver = (props, styles, theme, name) => {
61
61
  }
62
62
 
63
63
  return variantsStyles;
64
- };
64
+ }; // Update /system/styled/#api in case if this changes
65
+
65
66
 
66
67
  export function shouldForwardProp(prop) {
67
68
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -76,7 +77,8 @@ export default function createStyled(input = {}) {
76
77
  const {
77
78
  defaultTheme = systemDefaultTheme,
78
79
  rootShouldForwardProp = shouldForwardProp,
79
- slotShouldForwardProp = shouldForwardProp
80
+ slotShouldForwardProp = shouldForwardProp,
81
+ styleFunctionSx = defaultStyleFunctionSx
80
82
  } = input;
81
83
  return (tag, inputOptions = {}) => {
82
84
  const {
@@ -1,9 +1,24 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["values", "unit", "step"];
4
4
  // Sorted ASC by size. That's important.
5
5
  // It can't be configured as it's used statically for propTypes.
6
- export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
6
+ export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
7
+
8
+ const sortBreakpointsValues = values => {
9
+ const breakpointsAsArray = Object.keys(values).map(key => ({
10
+ key,
11
+ val: values[key]
12
+ })) || []; // Sort in ascending order
13
+
14
+ breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
15
+ return breakpointsAsArray.reduce((acc, obj) => {
16
+ return _extends({}, acc, {
17
+ [obj.key]: obj.val
18
+ });
19
+ }, {});
20
+ }; // Keep in mind that @media is inclusive by the CSS specification.
21
+
7
22
 
8
23
  export default function createBreakpoints(breakpoints) {
9
24
  const {
@@ -26,7 +41,8 @@ export default function createBreakpoints(breakpoints) {
26
41
  } = breakpoints,
27
42
  other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
28
43
 
29
- const keys = Object.keys(values);
44
+ const sortedValues = sortBreakpointsValues(values);
45
+ const keys = Object.keys(sortedValues);
30
46
 
31
47
  function up(key) {
32
48
  const value = typeof values[key] === 'number' ? values[key] : key;
@@ -68,7 +84,7 @@ export default function createBreakpoints(breakpoints) {
68
84
 
69
85
  return _extends({
70
86
  keys,
71
- values,
87
+ values: sortedValues,
72
88
  up,
73
89
  down,
74
90
  between,
@@ -28,7 +28,8 @@ export default function createCssVarsProvider(options) {
28
28
  disableTransitionOnChange = false,
29
29
  enableColorScheme = true,
30
30
  prefix: designSystemPrefix = '',
31
- shouldSkipGeneratingVar
31
+ shouldSkipGeneratingVar,
32
+ resolveTheme
32
33
  } = options;
33
34
  const systemSpacing = createSpacing(baseTheme.spacing);
34
35
  const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
@@ -125,6 +126,7 @@ export default function createCssVarsProvider(options) {
125
126
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
126
127
  components,
127
128
  colorSchemes,
129
+ prefix,
128
130
  vars: rootVars,
129
131
  spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
130
132
  breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
@@ -226,7 +228,7 @@ export default function createCssVarsProvider(options) {
226
228
  }), /*#__PURE__*/_jsx(GlobalStyles, {
227
229
  styles: styleSheet
228
230
  }), /*#__PURE__*/_jsx(ThemeProvider, {
229
- theme: mergedTheme,
231
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
230
232
  children: children
231
233
  })]
232
234
  });
@@ -8,7 +8,13 @@ export default function createGetCssVar(prefix = '') {
8
8
  return '';
9
9
  }
10
10
 
11
- return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
11
+ const value = vars[0];
12
+
13
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
14
+ return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
15
+ }
16
+
17
+ return `, ${value}`;
12
18
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
13
19
 
14
20
 
@@ -113,12 +113,13 @@ export default function cssVarsParser(theme, options) {
113
113
  if (typeof val === 'string' || typeof val === 'number') {
114
114
  let value = val;
115
115
 
116
- if (typeof value === 'string' && value.startsWith('var')) {
116
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
117
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
118
118
  if (!basePrefix && prefix) {
119
- value = value.replace(/var\(--/g, `var(--${prefix}-`);
119
+ value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
120
  } else {
121
- value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
121
+ value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
+ : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
122
123
  } // scope is the deepest object in the tree, keys is the theme path keys
123
124
 
124
125
 
@@ -20,7 +20,7 @@ const filterPropsMapping = {
20
20
  spacing: spacing.filterProps,
21
21
  typography: typography.filterProps
22
22
  };
23
- const styleFunctionMapping = {
23
+ export const styleFunctionMapping = {
24
24
  borders,
25
25
  display,
26
26
  flexbox,
package/esm/index.js CHANGED
@@ -21,7 +21,7 @@ export * from './spacing';
21
21
  export { default as style, getPath } from './style';
22
22
  export { default as typography } from './typography';
23
23
  export * from './typography';
24
- export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
24
+ export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
25
25
  export { default as experimental_sx } from './sx';
26
26
  export { default as unstable_getThemeValue } from './getThemeValue';
27
27
  export { default as Box } from './Box';
@@ -1,2 +1,3 @@
1
1
  export { default } from './styleFunctionSx';
2
+ export { unstable_createStyleFunctionSx } from './styleFunctionSx';
2
3
  export { default as extendSxProp } from './extendSxProp';
@@ -1,5 +1,5 @@
1
1
  import merge from '../merge';
2
- import getThemeValue, { propToStyleFunction } from '../getThemeValue';
2
+ import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
3
3
  import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
4
4
 
5
5
  function objectsHaveSameKeys(...objects) {
@@ -10,70 +10,97 @@ function objectsHaveSameKeys(...objects) {
10
10
 
11
11
  function callIfFn(maybeFn, arg) {
12
12
  return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
13
- }
13
+ } // eslint-disable-next-line @typescript-eslint/naming-convention
14
14
 
15
- function styleFunctionSx(props) {
16
- const {
17
- sx,
18
- theme = {}
19
- } = props || {};
20
15
 
21
- if (!sx) {
22
- return null; // emotion & styled-components will neglect null
23
- }
24
- /*
25
- * Receive `sxInput` as object or callback
26
- * and then recursively check keys & values to create media query object styles.
27
- * (the result will be used in `styled`)
28
- */
16
+ export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
17
+ const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
18
+ styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
19
+ acc[propName] = styleFunctionMapping[styleFnName];
20
+ });
21
+ return acc;
22
+ }, {});
29
23
 
24
+ function getThemeValue(prop, value, theme) {
25
+ const inputProps = {
26
+ [prop]: value,
27
+ theme
28
+ };
29
+ const styleFunction = propToStyleFunction[prop];
30
+ return styleFunction ? styleFunction(inputProps) : {
31
+ [prop]: value
32
+ };
33
+ }
30
34
 
31
- function traverse(sxInput) {
32
- let sxObject = sxInput;
35
+ function styleFunctionSx(props) {
36
+ const {
37
+ sx,
38
+ theme = {}
39
+ } = props || {};
33
40
 
34
- if (typeof sxInput === 'function') {
35
- sxObject = sxInput(theme);
36
- } else if (typeof sxInput !== 'object') {
37
- // value
38
- return sxInput;
41
+ if (!sx) {
42
+ return null; // emotion & styled-components will neglect null
39
43
  }
44
+ /*
45
+ * Receive `sxInput` as object or callback
46
+ * and then recursively check keys & values to create media query object styles.
47
+ * (the result will be used in `styled`)
48
+ */
40
49
 
41
- const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
42
- const breakpointsKeys = Object.keys(emptyBreakpoints);
43
- let css = emptyBreakpoints;
44
- Object.keys(sxObject).forEach(styleKey => {
45
- const value = callIfFn(sxObject[styleKey], theme);
46
50
 
47
- if (value !== null && value !== undefined) {
48
- if (typeof value === 'object') {
49
- if (propToStyleFunction[styleKey]) {
50
- css = merge(css, getThemeValue(styleKey, value, theme));
51
- } else {
52
- const breakpointsValues = handleBreakpoints({
53
- theme
54
- }, value, x => ({
55
- [styleKey]: x
56
- }));
57
-
58
- if (objectsHaveSameKeys(breakpointsValues, value)) {
59
- css[styleKey] = styleFunctionSx({
60
- sx: value,
61
- theme
62
- });
51
+ function traverse(sxInput) {
52
+ let sxObject = sxInput;
53
+
54
+ if (typeof sxInput === 'function') {
55
+ sxObject = sxInput(theme);
56
+ } else if (typeof sxInput !== 'object') {
57
+ // value
58
+ return sxInput;
59
+ }
60
+
61
+ if (!sxObject) {
62
+ return null;
63
+ }
64
+
65
+ const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
66
+ const breakpointsKeys = Object.keys(emptyBreakpoints);
67
+ let css = emptyBreakpoints;
68
+ Object.keys(sxObject).forEach(styleKey => {
69
+ const value = callIfFn(sxObject[styleKey], theme);
70
+
71
+ if (value !== null && value !== undefined) {
72
+ if (typeof value === 'object') {
73
+ if (propToStyleFunction[styleKey]) {
74
+ css = merge(css, getThemeValue(styleKey, value, theme));
63
75
  } else {
64
- css = merge(css, breakpointsValues);
76
+ const breakpointsValues = handleBreakpoints({
77
+ theme
78
+ }, value, x => ({
79
+ [styleKey]: x
80
+ }));
81
+
82
+ if (objectsHaveSameKeys(breakpointsValues, value)) {
83
+ css[styleKey] = styleFunctionSx({
84
+ sx: value,
85
+ theme
86
+ });
87
+ } else {
88
+ css = merge(css, breakpointsValues);
89
+ }
65
90
  }
91
+ } else {
92
+ css = merge(css, getThemeValue(styleKey, value, theme));
66
93
  }
67
- } else {
68
- css = merge(css, getThemeValue(styleKey, value, theme));
69
94
  }
70
- }
71
- });
72
- return removeUnusedBreakpoints(breakpointsKeys, css);
95
+ });
96
+ return removeUnusedBreakpoints(breakpointsKeys, css);
97
+ }
98
+
99
+ return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
73
100
  }
74
101
 
75
- return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
102
+ return styleFunctionSx;
76
103
  }
77
-
104
+ const styleFunctionSx = unstable_createStyleFunctionSx();
78
105
  styleFunctionSx.filterProps = ['sx'];
79
106
  export default styleFunctionSx;
package/getThemeValue.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.propToStyleFunction = exports.default = void 0;
8
+ exports.styleFunctionMapping = exports.propToStyleFunction = exports.default = void 0;
9
9
 
10
10
  var _borders = _interopRequireDefault(require("./borders"));
11
11
 
@@ -51,6 +51,7 @@ const styleFunctionMapping = {
51
51
  spacing: _spacing.default,
52
52
  typography: _typography.default
53
53
  };
54
+ exports.styleFunctionMapping = styleFunctionMapping;
54
55
  const propToStyleFunction = Object.keys(filterPropsMapping).reduce((acc, styleFnName) => {
55
56
  filterPropsMapping[styleFnName].forEach(propName => {
56
57
  acc[propName] = styleFunctionMapping[styleFnName];
package/index.d.ts CHANGED
@@ -118,6 +118,7 @@ export * from './spacing';
118
118
 
119
119
  export {
120
120
  default as unstable_styleFunctionSx,
121
+ unstable_createStyleFunctionSx,
121
122
  extendSxProp as unstable_extendSxProp,
122
123
  } from './styleFunctionSx';
123
124
  export * from './styleFunctionSx';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.1
1
+ /** @license MUI v5.4.2
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.
@@ -33,6 +33,7 @@ var _exportNames = {
33
33
  getPath: true,
34
34
  typography: true,
35
35
  unstable_styleFunctionSx: true,
36
+ unstable_createStyleFunctionSx: true,
36
37
  unstable_extendSxProp: true,
37
38
  experimental_sx: true,
38
39
  unstable_getThemeValue: true,
@@ -250,6 +251,12 @@ Object.defineProperty(exports, "unstable_createGetCssVar", {
250
251
  return _createGetCssVar.default;
251
252
  }
252
253
  });
254
+ Object.defineProperty(exports, "unstable_createStyleFunctionSx", {
255
+ enumerable: true,
256
+ get: function () {
257
+ return _styleFunctionSx.unstable_createStyleFunctionSx;
258
+ }
259
+ });
253
260
  Object.defineProperty(exports, "unstable_extendSxProp", {
254
261
  enumerable: true,
255
262
  get: function () {
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import clsx from 'clsx';
6
6
  import styled from '@mui/styled-engine';
7
- import styleFunctionSx, { extendSxProp } from './styleFunctionSx';
7
+ import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
8
8
  import useTheme from './useTheme';
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  export default function createBox() {
@@ -12,7 +12,9 @@ export default function createBox() {
12
12
  var defaultTheme = options.defaultTheme,
13
13
  _options$defaultClass = options.defaultClassName,
14
14
  defaultClassName = _options$defaultClass === void 0 ? 'MuiBox-root' : _options$defaultClass,
15
- generateClassName = options.generateClassName;
15
+ generateClassName = options.generateClassName,
16
+ _options$styleFunctio = options.styleFunctionSx,
17
+ styleFunctionSx = _options$styleFunctio === void 0 ? defaultStyleFunctionSx : _options$styleFunctio;
16
18
  var BoxRoot = styled('div')(styleFunctionSx);
17
19
  var Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
18
20
  var theme = useTheme(defaultTheme);
@@ -5,8 +5,8 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
5
5
  import styledEngineStyled from '@mui/styled-engine';
6
6
  import { getDisplayName } from '@mui/utils';
7
7
  import createTheme from './createTheme';
8
- import styleFunctionSx from './styleFunctionSx';
9
8
  import propsToClassKey from './propsToClassKey';
9
+ import defaultStyleFunctionSx from './styleFunctionSx';
10
10
 
11
11
  function isEmpty(obj) {
12
12
  return Object.keys(obj).length === 0;
@@ -59,7 +59,8 @@ var variantsResolver = function variantsResolver(props, styles, theme, name) {
59
59
  }
60
60
 
61
61
  return variantsStyles;
62
- };
62
+ }; // Update /system/styled/#api in case if this changes
63
+
63
64
 
64
65
  export function shouldForwardProp(prop) {
65
66
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -77,7 +78,9 @@ export default function createStyled() {
77
78
  _input$rootShouldForw = input.rootShouldForwardProp,
78
79
  rootShouldForwardProp = _input$rootShouldForw === void 0 ? shouldForwardProp : _input$rootShouldForw,
79
80
  _input$slotShouldForw = input.slotShouldForwardProp,
80
- slotShouldForwardProp = _input$slotShouldForw === void 0 ? shouldForwardProp : _input$slotShouldForw;
81
+ slotShouldForwardProp = _input$slotShouldForw === void 0 ? shouldForwardProp : _input$slotShouldForw,
82
+ _input$styleFunctionS = input.styleFunctionSx,
83
+ styleFunctionSx = _input$styleFunctionS === void 0 ? defaultStyleFunctionSx : _input$styleFunctionS;
81
84
  return function (tag) {
82
85
  var inputOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
83
86
 
@@ -1,8 +1,26 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
4
  // Sorted ASC by size. That's important.
4
5
  // It can't be configured as it's used statically for propTypes.
5
- export var breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
6
+ export var breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
7
+
8
+ var sortBreakpointsValues = function sortBreakpointsValues(values) {
9
+ var breakpointsAsArray = Object.keys(values).map(function (key) {
10
+ return {
11
+ key: key,
12
+ val: values[key]
13
+ };
14
+ }) || []; // Sort in ascending order
15
+
16
+ breakpointsAsArray.sort(function (breakpoint1, breakpoint2) {
17
+ return breakpoint1.val - breakpoint2.val;
18
+ });
19
+ return breakpointsAsArray.reduce(function (acc, obj) {
20
+ return _extends({}, acc, _defineProperty({}, obj.key, obj.val));
21
+ }, {});
22
+ }; // Keep in mind that @media is inclusive by the CSS specification.
23
+
6
24
 
7
25
  export default function createBreakpoints(breakpoints) {
8
26
  var _breakpoints$values = breakpoints.values,
@@ -24,7 +42,8 @@ export default function createBreakpoints(breakpoints) {
24
42
  step = _breakpoints$step === void 0 ? 5 : _breakpoints$step,
25
43
  other = _objectWithoutProperties(breakpoints, ["values", "unit", "step"]);
26
44
 
27
- var keys = Object.keys(values);
45
+ var sortedValues = sortBreakpointsValues(values);
46
+ var keys = Object.keys(sortedValues);
28
47
 
29
48
  function up(key) {
30
49
  var value = typeof values[key] === 'number' ? values[key] : key;
@@ -66,7 +85,7 @@ export default function createBreakpoints(breakpoints) {
66
85
 
67
86
  return _extends({
68
87
  keys: keys,
69
- values: values,
88
+ values: sortedValues,
70
89
  up: up,
71
90
  down: down,
72
91
  between: between,
@@ -31,7 +31,8 @@ export default function createCssVarsProvider(options) {
31
31
  enableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
32
32
  _options$prefix = options.prefix,
33
33
  designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
34
- shouldSkipGeneratingVar = options.shouldSkipGeneratingVar;
34
+ shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
35
+ resolveTheme = options.resolveTheme;
35
36
  var systemSpacing = createSpacing(baseTheme.spacing);
36
37
  var systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
37
38
 
@@ -131,6 +132,7 @@ export default function createCssVarsProvider(options) {
131
132
  mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
132
133
  components: components,
133
134
  colorSchemes: colorSchemes,
135
+ prefix: prefix,
134
136
  vars: rootVars,
135
137
  spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
136
138
  breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
@@ -238,7 +240,7 @@ export default function createCssVarsProvider(options) {
238
240
  }), /*#__PURE__*/_jsx(GlobalStyles, {
239
241
  styles: styleSheet
240
242
  }), /*#__PURE__*/_jsx(ThemeProvider, {
241
- theme: mergedTheme,
243
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
242
244
  children: children
243
245
  })]
244
246
  });
@@ -16,7 +16,13 @@ export default function createGetCssVar() {
16
16
  return '';
17
17
  }
18
18
 
19
- return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(vars[0]).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
19
+ var value = vars[0];
20
+
21
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
22
+ return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(value).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
23
+ }
24
+
25
+ return ", ".concat(value);
20
26
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
21
27
 
22
28
 
@@ -127,12 +127,13 @@ export default function cssVarsParser(theme, options) {
127
127
  if (typeof val === 'string' || typeof val === 'number') {
128
128
  var _value = val;
129
129
 
130
- if (typeof _value === 'string' && _value.startsWith('var')) {
130
+ if (typeof _value === 'string' && _value.match(/var\(\s*--/)) {
131
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
132
132
  if (!basePrefix && prefix) {
133
- _value = _value.replace(/var\(--/g, "var(--".concat(prefix, "-"));
133
+ _value = _value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
134
134
  } else {
135
- _value = prefix ? _value.replace(new RegExp(basePrefix, 'g'), prefix) : _value.replace(new RegExp("".concat(basePrefix, "-"), 'g'), '');
135
+ _value = prefix ? _value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
136
+ : _value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
136
137
  } // scope is the deepest object in the tree, keys is the theme path keys
137
138
 
138
139
 
@@ -21,7 +21,7 @@ var filterPropsMapping = {
21
21
  spacing: spacing.filterProps,
22
22
  typography: typography.filterProps
23
23
  };
24
- var styleFunctionMapping = {
24
+ export var styleFunctionMapping = {
25
25
  borders: borders,
26
26
  display: display,
27
27
  flexbox: flexbox,
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.1
1
+ /** @license MUI v5.4.2
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.
@@ -26,7 +26,7 @@ export * from './spacing';
26
26
  export { default as style, getPath } from './style';
27
27
  export { default as typography } from './typography';
28
28
  export * from './typography';
29
- export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
29
+ export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
30
30
  export { default as experimental_sx } from './sx';
31
31
  export { default as unstable_getThemeValue } from './getThemeValue';
32
32
  export { default as Box } from './Box';
@@ -1,2 +1,3 @@
1
1
  export { default } from './styleFunctionSx';
2
+ export { unstable_createStyleFunctionSx } from './styleFunctionSx';
2
3
  export { default as extendSxProp } from './extendSxProp';