@mui/system 5.4.3 → 5.5.1

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.
@@ -85,19 +85,20 @@ const getCssValue = (keys, value) => {
85
85
  * `basePrefix`: defined by design system.
86
86
  * `prefix`: defined by application
87
87
  *
88
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
88
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
89
89
  *
90
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
90
+ * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
91
91
  *
92
92
  * @example
93
- * const { css, vars } = parser({
93
+ * const { css, vars, parsedTheme } = parser({
94
94
  * fontSize: 12,
95
95
  * lineHeight: 1.2,
96
- * palette: { primary: { 500: '#000000' } }
97
- * })
96
+ * palette: { primary: { 500: 'var(--color)' } }
97
+ * }, { prefix: 'foo' })
98
98
  *
99
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
100
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
99
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
100
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
101
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
101
102
  */
102
103
 
103
104
 
@@ -109,21 +110,17 @@ export default function cssVarsParser(theme, options) {
109
110
  } = options || {};
110
111
  const css = {};
111
112
  const vars = {};
112
- walkObjectDeep(theme, (keys, val, scope) => {
113
- if (typeof val === 'string' || typeof val === 'number') {
114
- let value = val;
115
-
113
+ const parsedTheme = {};
114
+ walkObjectDeep(theme, (keys, value) => {
115
+ if (typeof value === 'string' || typeof value === 'number') {
116
116
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
117
- // replace the value of the `scope` object with the prefix or remove basePrefix from the value
117
+ // for CSS variable, apply prefix or remove basePrefix from the variable
118
118
  if (!basePrefix && prefix) {
119
119
  value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
120
120
  } else {
121
121
  value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
122
122
  : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
123
- } // scope is the deepest object in the tree, keys is the theme path keys
124
-
125
-
126
- scope[keys.slice(-1)[0]] = value;
123
+ }
127
124
  }
128
125
 
129
126
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
@@ -135,10 +132,13 @@ export default function cssVarsParser(theme, options) {
135
132
  assignNestedKeys(vars, keys, `var(${cssVar})`);
136
133
  }
137
134
  }
135
+
136
+ assignNestedKeys(parsedTheme, keys, value);
138
137
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
139
138
  );
140
139
  return {
141
140
  css,
142
- vars
141
+ vars,
142
+ parsedTheme
143
143
  };
144
144
  }
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.4.3
1
+ /** @license MUI v5.5.1
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.4.3",
3
+ "version": "5.5.1",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -43,13 +43,13 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@babel/runtime": "^7.17.0",
47
- "@mui/private-theming": "^5.4.2",
48
- "@mui/styled-engine": "^5.4.2",
49
- "@mui/types": "^7.1.2",
50
- "@mui/utils": "^5.4.2",
46
+ "@babel/runtime": "^7.17.2",
47
+ "@mui/private-theming": "^5.4.4",
48
+ "@mui/styled-engine": "^5.4.4",
49
+ "@mui/types": "^7.1.3",
50
+ "@mui/utils": "^5.4.4",
51
51
  "clsx": "^1.1.1",
52
- "csstype": "^3.0.10",
52
+ "csstype": "^3.0.11",
53
53
  "prop-types": "^15.7.2"
54
54
  },
55
55
  "sideEffects": false,
@@ -24,6 +24,18 @@ export interface CSSSelectorObject<Theme extends object = {}> {
24
24
  [cssSelector: string]: ((theme: Theme) => SystemStyleObject<Theme>) | SystemStyleObject<Theme>;
25
25
  }
26
26
 
27
+ type CssVariableType = string | number;
28
+
29
+ /**
30
+ * Map all nested selectors and CSS variables.
31
+ */
32
+ export interface CSSSelectorObjectOrCssVariables<Theme extends object = {}> {
33
+ [cssSelectorOrVariable: string]:
34
+ | ((theme: Theme) => SystemStyleObject<Theme> | string | number)
35
+ | SystemStyleObject<Theme>
36
+ | CssVariableType;
37
+ }
38
+
27
39
  /**
28
40
  * Map of all available CSS properties (including aliases) and their raw value.
29
41
  * Only used internally to map CSS properties to input types (responsive value,
@@ -48,8 +60,7 @@ export type SystemCssProperties<Theme extends object = {}> = {
48
60
  export type SystemStyleObject<Theme extends object = {}> =
49
61
  | SystemCssProperties<Theme>
50
62
  | CSSPseudoSelectorProps<Theme>
51
- | CSSSelectorObject<Theme>
52
- | { [cssVariable: string]: string | number }
63
+ | CSSSelectorObjectOrCssVariables<Theme>
53
64
  | null;
54
65
 
55
66
  /**
@@ -1 +1 @@
1
- export {};
1
+ export {};