@mui/system 5.11.11 → 5.11.13
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.
- package/CHANGELOG.md +187 -2
- package/cssVars/createCssVarsProvider.d.ts +0 -50
- package/cssVars/createCssVarsProvider.js +8 -16
- package/cssVars/createCssVarsTheme.d.ts +13 -0
- package/cssVars/createCssVarsTheme.js +24 -0
- package/cssVars/createGetCssVar.js +1 -1
- package/cssVars/cssVarsParser.d.ts +3 -2
- package/cssVars/cssVarsParser.js +4 -1
- package/cssVars/index.d.ts +2 -0
- package/cssVars/index.js +15 -1
- package/cssVars/prepareCssVars.d.ts +14 -0
- package/cssVars/prepareCssVars.js +70 -0
- package/esm/cssVars/createCssVarsProvider.js +8 -16
- package/esm/cssVars/createCssVarsTheme.js +16 -0
- package/esm/cssVars/createGetCssVar.js +1 -1
- package/esm/cssVars/cssVarsParser.js +4 -1
- package/esm/cssVars/index.js +3 -1
- package/esm/cssVars/prepareCssVars.js +62 -0
- package/esm/index.js +3 -0
- package/esm/styleFunctionSx/defaultSxConfig.js +30 -3
- package/index.d.ts +3 -0
- package/index.js +25 -1
- package/legacy/cssVars/createCssVarsProvider.js +15 -21
- package/legacy/cssVars/createCssVarsTheme.js +13 -0
- package/legacy/cssVars/createGetCssVar.js +1 -1
- package/legacy/cssVars/cssVarsParser.js +4 -1
- package/legacy/cssVars/index.js +3 -1
- package/legacy/cssVars/prepareCssVars.js +59 -0
- package/legacy/index.js +4 -1
- package/legacy/styleFunctionSx/defaultSxConfig.js +29 -3
- package/modern/cssVars/createCssVarsProvider.js +8 -16
- package/modern/cssVars/createCssVarsTheme.js +16 -0
- package/modern/cssVars/createGetCssVar.js +1 -1
- package/modern/cssVars/cssVarsParser.js +4 -1
- package/modern/cssVars/index.js +3 -1
- package/modern/cssVars/prepareCssVars.js +62 -0
- package/modern/index.js +4 -1
- package/modern/styleFunctionSx/defaultSxConfig.js +28 -3
- package/package.json +3 -3
- package/styleFunctionSx/defaultSxConfig.js +30 -3
|
@@ -8,7 +8,7 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
const value = vars[0];
|
|
11
|
-
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
11
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
|
|
12
12
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
13
13
|
}
|
|
14
14
|
return `, ${value}`;
|
|
@@ -105,6 +105,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
105
105
|
} = options || {};
|
|
106
106
|
const css = {};
|
|
107
107
|
const vars = {};
|
|
108
|
+
const varsWithDefaults = {};
|
|
108
109
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
109
110
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
110
111
|
if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -114,6 +115,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
114
115
|
[cssVar]: getCssValue(keys, value)
|
|
115
116
|
});
|
|
116
117
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
118
|
+
assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
@@ -121,6 +123,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
121
123
|
|
|
122
124
|
return {
|
|
123
125
|
css,
|
|
124
|
-
vars
|
|
126
|
+
vars,
|
|
127
|
+
varsWithDefaults
|
|
125
128
|
};
|
|
126
129
|
}
|
package/esm/cssVars/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default } from './createCssVarsProvider';
|
|
2
|
-
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
3
|
+
export { default as prepareCssVars } from './prepareCssVars';
|
|
4
|
+
export { default as createCssVarsTheme } from './createCssVarsTheme';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
const _excluded = ["colorSchemes", "components"],
|
|
3
|
+
_excluded2 = ["light"];
|
|
4
|
+
import { deepmerge } from '@mui/utils';
|
|
5
|
+
import cssVarsParser from './cssVarsParser';
|
|
6
|
+
function prepareCssVars(theme, parserConfig) {
|
|
7
|
+
// @ts-ignore - ignore components do not exist
|
|
8
|
+
const {
|
|
9
|
+
colorSchemes = {}
|
|
10
|
+
} = theme,
|
|
11
|
+
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
12
|
+
const {
|
|
13
|
+
vars: rootVars,
|
|
14
|
+
css: rootCss,
|
|
15
|
+
varsWithDefaults: rootVarsWithDefaults
|
|
16
|
+
} = cssVarsParser(otherTheme, parserConfig);
|
|
17
|
+
let themeVars = rootVarsWithDefaults;
|
|
18
|
+
const colorSchemesMap = {};
|
|
19
|
+
const {
|
|
20
|
+
light
|
|
21
|
+
} = colorSchemes,
|
|
22
|
+
otherColorSchemes = _objectWithoutPropertiesLoose(colorSchemes, _excluded2);
|
|
23
|
+
Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
|
|
24
|
+
const {
|
|
25
|
+
vars,
|
|
26
|
+
css,
|
|
27
|
+
varsWithDefaults
|
|
28
|
+
} = cssVarsParser(scheme, parserConfig);
|
|
29
|
+
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
30
|
+
colorSchemesMap[key] = {
|
|
31
|
+
css,
|
|
32
|
+
vars
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
if (light) {
|
|
36
|
+
// light color scheme vars should be merged last to set as default
|
|
37
|
+
const {
|
|
38
|
+
css,
|
|
39
|
+
vars,
|
|
40
|
+
varsWithDefaults
|
|
41
|
+
} = cssVarsParser(light, parserConfig);
|
|
42
|
+
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
43
|
+
colorSchemesMap.light = {
|
|
44
|
+
css,
|
|
45
|
+
vars
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const generateCssVars = colorScheme => {
|
|
49
|
+
if (!colorScheme) {
|
|
50
|
+
return {
|
|
51
|
+
css: rootCss,
|
|
52
|
+
vars: rootVars
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return colorSchemesMap[colorScheme];
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
vars: themeVars,
|
|
59
|
+
generateCssVars
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export default prepareCssVars;
|
package/esm/index.js
CHANGED
|
@@ -45,6 +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
|
+
export { default as unstable_cssVarsParser } from './cssVars/cssVarsParser';
|
|
49
|
+
export { default as unstable_prepareCssVars } from './cssVars/prepareCssVars';
|
|
50
|
+
export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsTheme';
|
|
48
51
|
export { default as responsivePropType } from './responsivePropType';
|
|
49
52
|
|
|
50
53
|
/** ----------------- */
|
|
@@ -1,8 +1,32 @@
|
|
|
1
|
+
import { unstable_capitalize as capitalize } from '@mui/utils';
|
|
1
2
|
import { padding, margin } from '../spacing';
|
|
3
|
+
import { handleBreakpoints } from '../breakpoints';
|
|
2
4
|
import { borderRadius, borderTransform } from '../borders';
|
|
3
5
|
import { gap, rowGap, columnGap } from '../cssGrid';
|
|
4
6
|
import { paletteTransform } from '../palette';
|
|
5
7
|
import { maxWidth, sizingTransform } from '../sizing';
|
|
8
|
+
const createFontStyleFunction = prop => {
|
|
9
|
+
return props => {
|
|
10
|
+
if (props[prop] !== undefined && props[prop] !== null) {
|
|
11
|
+
const styleFromPropValue = propValue => {
|
|
12
|
+
var _props$theme$typograp, _props$prop;
|
|
13
|
+
let value = (_props$theme$typograp = props.theme.typography) == null ? void 0 : _props$theme$typograp[`${prop}${props[prop] === 'default' || props[prop] === prop ? '' : capitalize((_props$prop = props[prop]) == null ? void 0 : _props$prop.toString())}`];
|
|
14
|
+
if (!value) {
|
|
15
|
+
var _props$theme$typograp2, _props$theme$typograp3;
|
|
16
|
+
value = (_props$theme$typograp2 = props.theme.typography) == null ? void 0 : (_props$theme$typograp3 = _props$theme$typograp2[propValue]) == null ? void 0 : _props$theme$typograp3[prop];
|
|
17
|
+
}
|
|
18
|
+
if (!value) {
|
|
19
|
+
value = propValue;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
[prop]: value
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
return handleBreakpoints(props, props[prop], styleFromPropValue);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
6
30
|
const defaultSxConfig = {
|
|
7
31
|
// borders
|
|
8
32
|
border: {
|
|
@@ -261,16 +285,19 @@ const defaultSxConfig = {
|
|
|
261
285
|
boxSizing: {},
|
|
262
286
|
// typography
|
|
263
287
|
fontFamily: {
|
|
264
|
-
themeKey: 'typography'
|
|
288
|
+
themeKey: 'typography',
|
|
289
|
+
style: createFontStyleFunction('fontFamily')
|
|
265
290
|
},
|
|
266
291
|
fontSize: {
|
|
267
|
-
themeKey: 'typography'
|
|
292
|
+
themeKey: 'typography',
|
|
293
|
+
style: createFontStyleFunction('fontSize')
|
|
268
294
|
},
|
|
269
295
|
fontStyle: {
|
|
270
296
|
themeKey: 'typography'
|
|
271
297
|
},
|
|
272
298
|
fontWeight: {
|
|
273
|
-
themeKey: 'typography'
|
|
299
|
+
themeKey: 'typography',
|
|
300
|
+
style: createFontStyleFunction('fontWeight')
|
|
274
301
|
},
|
|
275
302
|
letterSpacing: {},
|
|
276
303
|
textTransform: {},
|
package/index.d.ts
CHANGED
|
@@ -166,6 +166,9 @@ export * from './ThemeProvider';
|
|
|
166
166
|
|
|
167
167
|
export { default as unstable_createCssVarsProvider, CreateCssVarsProviderResult } from './cssVars';
|
|
168
168
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
169
|
+
export { default as unstable_cssVarsParser } from './cssVars/cssVarsParser';
|
|
170
|
+
export { default as unstable_prepareCssVars } from './cssVars/prepareCssVars';
|
|
171
|
+
export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsTheme';
|
|
169
172
|
export * from './cssVars';
|
|
170
173
|
|
|
171
174
|
export { default as responsivePropType } from './responsivePropType';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.11.
|
|
2
|
+
* @mui/system v5.11.13
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -55,6 +55,9 @@ var _exportNames = {
|
|
|
55
55
|
ThemeProvider: true,
|
|
56
56
|
unstable_createCssVarsProvider: true,
|
|
57
57
|
unstable_createGetCssVar: true,
|
|
58
|
+
unstable_cssVarsParser: true,
|
|
59
|
+
unstable_prepareCssVars: true,
|
|
60
|
+
unstable_createCssVarsTheme: true,
|
|
58
61
|
responsivePropType: true,
|
|
59
62
|
createContainer: true,
|
|
60
63
|
Container: true,
|
|
@@ -284,6 +287,12 @@ Object.defineProperty(exports, "unstable_createCssVarsProvider", {
|
|
|
284
287
|
return _createCssVarsProvider.default;
|
|
285
288
|
}
|
|
286
289
|
});
|
|
290
|
+
Object.defineProperty(exports, "unstable_createCssVarsTheme", {
|
|
291
|
+
enumerable: true,
|
|
292
|
+
get: function () {
|
|
293
|
+
return _createCssVarsTheme.default;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
287
296
|
Object.defineProperty(exports, "unstable_createGetCssVar", {
|
|
288
297
|
enumerable: true,
|
|
289
298
|
get: function () {
|
|
@@ -296,6 +305,12 @@ Object.defineProperty(exports, "unstable_createStyleFunctionSx", {
|
|
|
296
305
|
return _styleFunctionSx.unstable_createStyleFunctionSx;
|
|
297
306
|
}
|
|
298
307
|
});
|
|
308
|
+
Object.defineProperty(exports, "unstable_cssVarsParser", {
|
|
309
|
+
enumerable: true,
|
|
310
|
+
get: function () {
|
|
311
|
+
return _cssVarsParser.default;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
299
314
|
Object.defineProperty(exports, "unstable_defaultSxConfig", {
|
|
300
315
|
enumerable: true,
|
|
301
316
|
get: function () {
|
|
@@ -314,6 +329,12 @@ Object.defineProperty(exports, "unstable_getThemeValue", {
|
|
|
314
329
|
return _getThemeValue.default;
|
|
315
330
|
}
|
|
316
331
|
});
|
|
332
|
+
Object.defineProperty(exports, "unstable_prepareCssVars", {
|
|
333
|
+
enumerable: true,
|
|
334
|
+
get: function () {
|
|
335
|
+
return _prepareCssVars.default;
|
|
336
|
+
}
|
|
337
|
+
});
|
|
317
338
|
Object.defineProperty(exports, "unstable_resolveBreakpointValues", {
|
|
318
339
|
enumerable: true,
|
|
319
340
|
get: function () {
|
|
@@ -486,6 +507,9 @@ Object.keys(_colorManipulator).forEach(function (key) {
|
|
|
486
507
|
var _ThemeProvider = _interopRequireDefault(require("./ThemeProvider"));
|
|
487
508
|
var _createCssVarsProvider = _interopRequireDefault(require("./cssVars/createCssVarsProvider"));
|
|
488
509
|
var _createGetCssVar = _interopRequireDefault(require("./cssVars/createGetCssVar"));
|
|
510
|
+
var _cssVarsParser = _interopRequireDefault(require("./cssVars/cssVarsParser"));
|
|
511
|
+
var _prepareCssVars = _interopRequireDefault(require("./cssVars/prepareCssVars"));
|
|
512
|
+
var _createCssVarsTheme = _interopRequireDefault(require("./cssVars/createCssVarsTheme"));
|
|
489
513
|
var _responsivePropType = _interopRequireDefault(require("./responsivePropType"));
|
|
490
514
|
var _createContainer = _interopRequireDefault(require("./Container/createContainer"));
|
|
491
515
|
var _Container = _interopRequireWildcard(require("./Container"));
|
|
@@ -9,7 +9,6 @@ import PropTypes from 'prop-types';
|
|
|
9
9
|
import { deepmerge } from '@mui/utils';
|
|
10
10
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
11
11
|
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
12
|
-
import cssVarsParser from './cssVarsParser';
|
|
13
12
|
import ThemeProvider from '../ThemeProvider';
|
|
14
13
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
15
14
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
@@ -30,7 +29,6 @@ export default function createCssVarsProvider(options) {
|
|
|
30
29
|
designSystemColorScheme = options.defaultColorScheme,
|
|
31
30
|
_options$disableTrans = options.disableTransitionOnChange,
|
|
32
31
|
designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
33
|
-
designSystemShouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
34
32
|
resolveTheme = options.resolveTheme,
|
|
35
33
|
excludeVariablesFromRoot = options.excludeVariablesFromRoot;
|
|
36
34
|
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
@@ -68,8 +66,6 @@ export default function createCssVarsProvider(options) {
|
|
|
68
66
|
colorSchemeNode = _ref$colorSchemeNode === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _ref$colorSchemeNode,
|
|
69
67
|
_ref$colorSchemeSelec = _ref.colorSchemeSelector,
|
|
70
68
|
colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec,
|
|
71
|
-
_ref$shouldSkipGenera = _ref.shouldSkipGeneratingVar,
|
|
72
|
-
shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera,
|
|
73
69
|
_ref$disableNestedCon = _ref.disableNestedContext,
|
|
74
70
|
disableNestedContext = _ref$disableNestedCon === void 0 ? false : _ref$disableNestedCon,
|
|
75
71
|
_ref$disableStyleShee = _ref.disableStyleSheetGeneration,
|
|
@@ -82,8 +78,15 @@ export default function createCssVarsProvider(options) {
|
|
|
82
78
|
colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
83
79
|
_themeProp$components = themeProp.components,
|
|
84
80
|
components = _themeProp$components === void 0 ? {} : _themeProp$components,
|
|
81
|
+
_themeProp$generateCs = themeProp.generateCssVars,
|
|
82
|
+
generateCssVars = _themeProp$generateCs === void 0 ? function () {
|
|
83
|
+
return {
|
|
84
|
+
vars: {},
|
|
85
|
+
css: {}
|
|
86
|
+
};
|
|
87
|
+
} : _themeProp$generateCs,
|
|
85
88
|
cssVarPrefix = themeProp.cssVarPrefix,
|
|
86
|
-
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components", "cssVarPrefix"]);
|
|
89
|
+
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"]);
|
|
87
90
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
88
91
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
89
92
|
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -134,12 +137,9 @@ export default function createCssVarsProvider(options) {
|
|
|
134
137
|
}();
|
|
135
138
|
|
|
136
139
|
// 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}),
|
|
141
|
-
rootCss = _cssVarsParser.css,
|
|
142
|
-
rootVars = _cssVarsParser.vars; // 3. Start composing the theme object
|
|
140
|
+
var _generateCssVars = generateCssVars(),
|
|
141
|
+
rootCss = _generateCssVars.css,
|
|
142
|
+
rootVars = _generateCssVars.vars; // 3. Start composing the theme object
|
|
143
143
|
var theme = _extends({}, restThemeProp, {
|
|
144
144
|
components: components,
|
|
145
145
|
colorSchemes: colorSchemes,
|
|
@@ -159,12 +159,9 @@ export default function createCssVarsProvider(options) {
|
|
|
159
159
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
160
160
|
key = _ref3[0],
|
|
161
161
|
scheme = _ref3[1];
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}),
|
|
166
|
-
css = _cssVarsParser2.css,
|
|
167
|
-
vars = _cssVarsParser2.vars;
|
|
162
|
+
var _generateCssVars2 = generateCssVars(key),
|
|
163
|
+
css = _generateCssVars2.css,
|
|
164
|
+
vars = _generateCssVars2.vars;
|
|
168
165
|
theme.vars = deepmerge(theme.vars, vars);
|
|
169
166
|
if (key === calculatedColorScheme) {
|
|
170
167
|
// 4.1 Merge the selected color scheme to the theme
|
|
@@ -203,6 +200,7 @@ export default function createCssVarsProvider(options) {
|
|
|
203
200
|
otherColorSchemesStyleSheet["".concat(colorSchemeSelector === ':root' ? '' : colorSchemeSelector, "[").concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
204
201
|
}
|
|
205
202
|
});
|
|
203
|
+
theme.vars = deepmerge(theme.vars, rootVars);
|
|
206
204
|
|
|
207
205
|
// 5. Declaring effects
|
|
208
206
|
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
@@ -329,10 +327,6 @@ export default function createCssVarsProvider(options) {
|
|
|
329
327
|
* The key in the local storage used to store current color scheme.
|
|
330
328
|
*/
|
|
331
329
|
modeStorageKey: PropTypes.string,
|
|
332
|
-
/**
|
|
333
|
-
* A function to determine if the key, value should be attached as CSS Variable
|
|
334
|
-
*/
|
|
335
|
-
shouldSkipGeneratingVar: PropTypes.func,
|
|
336
330
|
/**
|
|
337
331
|
* The window that attaches the 'storage' event listener
|
|
338
332
|
* @default window
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import prepareCssVars from './prepareCssVars';
|
|
4
|
+
function createCssVarsTheme(theme) {
|
|
5
|
+
var cssVarPrefix = theme.cssVarPrefix,
|
|
6
|
+
shouldSkipGeneratingVar = theme.shouldSkipGeneratingVar,
|
|
7
|
+
otherTheme = _objectWithoutProperties(theme, ["cssVarPrefix", "shouldSkipGeneratingVar"]);
|
|
8
|
+
return _extends({}, theme, prepareCssVars(otherTheme, {
|
|
9
|
+
prefix: cssVarPrefix,
|
|
10
|
+
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
export default createCssVarsTheme;
|
|
@@ -13,7 +13,7 @@ export default function createGetCssVar() {
|
|
|
13
13
|
return '';
|
|
14
14
|
}
|
|
15
15
|
var value = vars[0];
|
|
16
|
-
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
16
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
|
|
17
17
|
return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(value).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
|
|
18
18
|
}
|
|
19
19
|
return ", ".concat(value);
|
|
@@ -117,6 +117,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
117
117
|
shouldSkipGeneratingVar = _ref3.shouldSkipGeneratingVar;
|
|
118
118
|
var css = {};
|
|
119
119
|
var vars = {};
|
|
120
|
+
var varsWithDefaults = {};
|
|
120
121
|
walkObjectDeep(theme, function (keys, value, arrayKeys) {
|
|
121
122
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
122
123
|
if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -124,6 +125,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
124
125
|
var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
|
|
125
126
|
_extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
|
|
126
127
|
assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"), arrayKeys);
|
|
128
|
+
assignNestedKeys(varsWithDefaults, keys, "var(".concat(cssVar, ", ").concat(value, ")"), arrayKeys);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
}, function (keys) {
|
|
@@ -133,6 +135,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
133
135
|
|
|
134
136
|
return {
|
|
135
137
|
css: css,
|
|
136
|
-
vars: vars
|
|
138
|
+
vars: vars,
|
|
139
|
+
varsWithDefaults: varsWithDefaults
|
|
137
140
|
};
|
|
138
141
|
}
|
package/legacy/cssVars/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default } from './createCssVarsProvider';
|
|
2
|
-
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
3
|
+
export { default as prepareCssVars } from './prepareCssVars';
|
|
4
|
+
export { default as createCssVarsTheme } from './createCssVarsTheme';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import { deepmerge } from '@mui/utils';
|
|
4
|
+
import cssVarsParser from './cssVarsParser';
|
|
5
|
+
function prepareCssVars(theme, parserConfig) {
|
|
6
|
+
// @ts-ignore - ignore components do not exist
|
|
7
|
+
var _theme$colorSchemes = theme.colorSchemes,
|
|
8
|
+
colorSchemes = _theme$colorSchemes === void 0 ? {} : _theme$colorSchemes,
|
|
9
|
+
components = theme.components,
|
|
10
|
+
otherTheme = _objectWithoutProperties(theme, ["colorSchemes", "components"]);
|
|
11
|
+
var _cssVarsParser = cssVarsParser(otherTheme, parserConfig),
|
|
12
|
+
rootVars = _cssVarsParser.vars,
|
|
13
|
+
rootCss = _cssVarsParser.css,
|
|
14
|
+
rootVarsWithDefaults = _cssVarsParser.varsWithDefaults;
|
|
15
|
+
var themeVars = rootVarsWithDefaults;
|
|
16
|
+
var colorSchemesMap = {};
|
|
17
|
+
var light = colorSchemes.light,
|
|
18
|
+
otherColorSchemes = _objectWithoutProperties(colorSchemes, ["light"]);
|
|
19
|
+
Object.entries(otherColorSchemes || {}).forEach(function (_ref) {
|
|
20
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
21
|
+
key = _ref2[0],
|
|
22
|
+
scheme = _ref2[1];
|
|
23
|
+
var _cssVarsParser2 = cssVarsParser(scheme, parserConfig),
|
|
24
|
+
vars = _cssVarsParser2.vars,
|
|
25
|
+
css = _cssVarsParser2.css,
|
|
26
|
+
varsWithDefaults = _cssVarsParser2.varsWithDefaults;
|
|
27
|
+
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
28
|
+
colorSchemesMap[key] = {
|
|
29
|
+
css: css,
|
|
30
|
+
vars: vars
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
if (light) {
|
|
34
|
+
// light color scheme vars should be merged last to set as default
|
|
35
|
+
var _cssVarsParser3 = cssVarsParser(light, parserConfig),
|
|
36
|
+
css = _cssVarsParser3.css,
|
|
37
|
+
vars = _cssVarsParser3.vars,
|
|
38
|
+
varsWithDefaults = _cssVarsParser3.varsWithDefaults;
|
|
39
|
+
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
40
|
+
colorSchemesMap.light = {
|
|
41
|
+
css: css,
|
|
42
|
+
vars: vars
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var generateCssVars = function generateCssVars(colorScheme) {
|
|
46
|
+
if (!colorScheme) {
|
|
47
|
+
return {
|
|
48
|
+
css: rootCss,
|
|
49
|
+
vars: rootVars
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return colorSchemesMap[colorScheme];
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
vars: themeVars,
|
|
56
|
+
generateCssVars: generateCssVars
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export default prepareCssVars;
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/system v5.11.
|
|
2
|
+
* @mui/system v5.11.13
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -52,6 +52,9 @@ export * from './colorManipulator';
|
|
|
52
52
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
53
53
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
54
54
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
55
|
+
export { default as unstable_cssVarsParser } from './cssVars/cssVarsParser';
|
|
56
|
+
export { default as unstable_prepareCssVars } from './cssVars/prepareCssVars';
|
|
57
|
+
export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsTheme';
|
|
55
58
|
export { default as responsivePropType } from './responsivePropType';
|
|
56
59
|
|
|
57
60
|
/** ----------------- */
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { unstable_capitalize as capitalize } from '@mui/utils';
|
|
1
3
|
import { padding, margin } from '../spacing';
|
|
4
|
+
import { handleBreakpoints } from '../breakpoints';
|
|
2
5
|
import { borderRadius, borderTransform } from '../borders';
|
|
3
6
|
import { gap, rowGap, columnGap } from '../cssGrid';
|
|
4
7
|
import { paletteTransform } from '../palette';
|
|
5
8
|
import { maxWidth, sizingTransform } from '../sizing';
|
|
9
|
+
var createFontStyleFunction = function createFontStyleFunction(prop) {
|
|
10
|
+
return function (props) {
|
|
11
|
+
if (props[prop] !== undefined && props[prop] !== null) {
|
|
12
|
+
var styleFromPropValue = function styleFromPropValue(propValue) {
|
|
13
|
+
var _props$theme$typograp, _props$prop;
|
|
14
|
+
var value = (_props$theme$typograp = props.theme.typography) == null ? void 0 : _props$theme$typograp["".concat(prop).concat(props[prop] === 'default' || props[prop] === prop ? '' : capitalize((_props$prop = props[prop]) == null ? void 0 : _props$prop.toString()))];
|
|
15
|
+
if (!value) {
|
|
16
|
+
var _props$theme$typograp2, _props$theme$typograp3;
|
|
17
|
+
value = (_props$theme$typograp2 = props.theme.typography) == null ? void 0 : (_props$theme$typograp3 = _props$theme$typograp2[propValue]) == null ? void 0 : _props$theme$typograp3[prop];
|
|
18
|
+
}
|
|
19
|
+
if (!value) {
|
|
20
|
+
value = propValue;
|
|
21
|
+
}
|
|
22
|
+
return _defineProperty({}, prop, value);
|
|
23
|
+
};
|
|
24
|
+
return handleBreakpoints(props, props[prop], styleFromPropValue);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
6
29
|
var defaultSxConfig = {
|
|
7
30
|
// borders
|
|
8
31
|
border: {
|
|
@@ -263,16 +286,19 @@ var defaultSxConfig = {
|
|
|
263
286
|
boxSizing: {},
|
|
264
287
|
// typography
|
|
265
288
|
fontFamily: {
|
|
266
|
-
themeKey: 'typography'
|
|
289
|
+
themeKey: 'typography',
|
|
290
|
+
style: createFontStyleFunction('fontFamily')
|
|
267
291
|
},
|
|
268
292
|
fontSize: {
|
|
269
|
-
themeKey: 'typography'
|
|
293
|
+
themeKey: 'typography',
|
|
294
|
+
style: createFontStyleFunction('fontSize')
|
|
270
295
|
},
|
|
271
296
|
fontStyle: {
|
|
272
297
|
themeKey: 'typography'
|
|
273
298
|
},
|
|
274
299
|
fontWeight: {
|
|
275
|
-
themeKey: 'typography'
|
|
300
|
+
themeKey: 'typography',
|
|
301
|
+
style: createFontStyleFunction('fontWeight')
|
|
276
302
|
},
|
|
277
303
|
letterSpacing: {},
|
|
278
304
|
textTransform: {},
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
10
|
-
import cssVarsParser from './cssVarsParser';
|
|
11
10
|
import ThemeProvider from '../ThemeProvider';
|
|
12
11
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
@@ -23,7 +22,6 @@ export default function createCssVarsProvider(options) {
|
|
|
23
22
|
defaultMode: designSystemMode = 'light',
|
|
24
23
|
defaultColorScheme: designSystemColorScheme,
|
|
25
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
26
|
-
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
27
25
|
resolveTheme,
|
|
28
26
|
excludeVariablesFromRoot
|
|
29
27
|
} = options;
|
|
@@ -51,7 +49,6 @@ export default function createCssVarsProvider(options) {
|
|
|
51
49
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
52
50
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
53
51
|
colorSchemeSelector = ':root',
|
|
54
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
55
52
|
disableNestedContext = false,
|
|
56
53
|
disableStyleSheetGeneration = false
|
|
57
54
|
}) {
|
|
@@ -62,6 +59,10 @@ export default function createCssVarsProvider(options) {
|
|
|
62
59
|
const {
|
|
63
60
|
colorSchemes = {},
|
|
64
61
|
components = {},
|
|
62
|
+
generateCssVars = () => ({
|
|
63
|
+
vars: {},
|
|
64
|
+
css: {}
|
|
65
|
+
}),
|
|
65
66
|
cssVarPrefix
|
|
66
67
|
} = themeProp,
|
|
67
68
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
@@ -119,10 +120,7 @@ export default function createCssVarsProvider(options) {
|
|
|
119
120
|
const {
|
|
120
121
|
css: rootCss,
|
|
121
122
|
vars: rootVars
|
|
122
|
-
} =
|
|
123
|
-
prefix: cssVarPrefix,
|
|
124
|
-
shouldSkipGeneratingVar
|
|
125
|
-
});
|
|
123
|
+
} = generateCssVars();
|
|
126
124
|
|
|
127
125
|
// 3. Start composing the theme object
|
|
128
126
|
const theme = _extends({}, restThemeProp, {
|
|
@@ -142,10 +140,7 @@ export default function createCssVarsProvider(options) {
|
|
|
142
140
|
const {
|
|
143
141
|
css,
|
|
144
142
|
vars
|
|
145
|
-
} =
|
|
146
|
-
prefix: cssVarPrefix,
|
|
147
|
-
shouldSkipGeneratingVar
|
|
148
|
-
});
|
|
143
|
+
} = generateCssVars(key);
|
|
149
144
|
theme.vars = deepmerge(theme.vars, vars);
|
|
150
145
|
if (key === calculatedColorScheme) {
|
|
151
146
|
// 4.1 Merge the selected color scheme to the theme
|
|
@@ -184,6 +179,7 @@ export default function createCssVarsProvider(options) {
|
|
|
184
179
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
185
180
|
}
|
|
186
181
|
});
|
|
182
|
+
theme.vars = deepmerge(theme.vars, rootVars);
|
|
187
183
|
|
|
188
184
|
// 5. Declaring effects
|
|
189
185
|
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
@@ -308,10 +304,6 @@ export default function createCssVarsProvider(options) {
|
|
|
308
304
|
* The key in the local storage used to store current color scheme.
|
|
309
305
|
*/
|
|
310
306
|
modeStorageKey: PropTypes.string,
|
|
311
|
-
/**
|
|
312
|
-
* A function to determine if the key, value should be attached as CSS Variable
|
|
313
|
-
*/
|
|
314
|
-
shouldSkipGeneratingVar: PropTypes.func,
|
|
315
307
|
/**
|
|
316
308
|
* The window that attaches the 'storage' event listener
|
|
317
309
|
* @default window
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
|
|
4
|
+
import prepareCssVars from './prepareCssVars';
|
|
5
|
+
function createCssVarsTheme(theme) {
|
|
6
|
+
const {
|
|
7
|
+
cssVarPrefix,
|
|
8
|
+
shouldSkipGeneratingVar
|
|
9
|
+
} = theme,
|
|
10
|
+
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
11
|
+
return _extends({}, theme, prepareCssVars(otherTheme, {
|
|
12
|
+
prefix: cssVarPrefix,
|
|
13
|
+
shouldSkipGeneratingVar
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
export default createCssVarsTheme;
|
|
@@ -8,7 +8,7 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
const value = vars[0];
|
|
11
|
-
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
11
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
|
|
12
12
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
13
13
|
}
|
|
14
14
|
return `, ${value}`;
|