@mui/system 5.10.15 → 5.10.17
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 +121 -1
- package/Container/ContainerProps.d.ts +1 -1
- package/Container/containerClasses.d.ts +1 -1
- package/Container/createContainer.d.ts +1 -1
- package/Stack/StackProps.d.ts +1 -1
- package/Stack/stackClasses.d.ts +1 -1
- package/Unstable_Grid/GridProps.d.ts +8 -8
- package/Unstable_Grid/gridClasses.d.ts +1 -1
- package/colorManipulator.d.ts +10 -0
- package/colorManipulator.js +57 -1
- package/createTheme/createSpacing.d.ts +2 -2
- package/cssVars/createCssVarsProvider.d.ts +66 -8
- package/cssVars/createCssVarsProvider.js +54 -22
- package/cssVars/cssVarsParser.d.ts +3 -5
- package/cssVars/cssVarsParser.js +3 -7
- package/cssVars/useCurrentColorScheme.d.ts +3 -3
- package/esm/colorManipulator.js +50 -0
- package/esm/cssVars/createCssVarsProvider.js +54 -22
- package/esm/cssVars/cssVarsParser.js +3 -7
- package/index.js +1 -1
- package/legacy/colorManipulator.js +50 -0
- package/legacy/cssVars/createCssVarsProvider.js +54 -20
- package/legacy/cssVars/cssVarsParser.js +3 -7
- package/legacy/index.js +1 -1
- package/modern/colorManipulator.js +50 -0
- package/modern/cssVars/createCssVarsProvider.js +54 -22
- package/modern/cssVars/cssVarsParser.js +3 -7
- package/modern/index.js +1 -1
- package/package.json +5 -5
|
@@ -90,6 +90,16 @@ export const colorChannel = color => {
|
|
|
90
90
|
const decomposedColor = decomposeColor(color);
|
|
91
91
|
return decomposedColor.values.slice(0, 3).map((val, idx) => decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? `${val}%` : val).join(' ');
|
|
92
92
|
};
|
|
93
|
+
export const private_safeColorChannel = (color, warning) => {
|
|
94
|
+
try {
|
|
95
|
+
return colorChannel(color);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
98
|
+
console.warn(warning);
|
|
99
|
+
}
|
|
100
|
+
return color;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
93
103
|
|
|
94
104
|
/**
|
|
95
105
|
* Converts a color object with type and values to a string.
|
|
@@ -220,6 +230,16 @@ export function alpha(color, value) {
|
|
|
220
230
|
}
|
|
221
231
|
return recomposeColor(color);
|
|
222
232
|
}
|
|
233
|
+
export function private_safeAlpha(color, value, warning) {
|
|
234
|
+
try {
|
|
235
|
+
return alpha(color, value);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
238
|
+
console.warn(warning);
|
|
239
|
+
}
|
|
240
|
+
return color;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
223
243
|
|
|
224
244
|
/**
|
|
225
245
|
* Darkens a color.
|
|
@@ -239,6 +259,16 @@ export function darken(color, coefficient) {
|
|
|
239
259
|
}
|
|
240
260
|
return recomposeColor(color);
|
|
241
261
|
}
|
|
262
|
+
export function private_safeDarken(color, coefficient, warning) {
|
|
263
|
+
try {
|
|
264
|
+
return darken(color, coefficient);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
267
|
+
console.warn(warning);
|
|
268
|
+
}
|
|
269
|
+
return color;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
242
272
|
|
|
243
273
|
/**
|
|
244
274
|
* Lightens a color.
|
|
@@ -262,6 +292,16 @@ export function lighten(color, coefficient) {
|
|
|
262
292
|
}
|
|
263
293
|
return recomposeColor(color);
|
|
264
294
|
}
|
|
295
|
+
export function private_safeLighten(color, coefficient, warning) {
|
|
296
|
+
try {
|
|
297
|
+
return lighten(color, coefficient);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
300
|
+
console.warn(warning);
|
|
301
|
+
}
|
|
302
|
+
return color;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
265
305
|
|
|
266
306
|
/**
|
|
267
307
|
* Darken or lighten a color, depending on its luminance.
|
|
@@ -272,4 +312,14 @@ export function lighten(color, coefficient) {
|
|
|
272
312
|
*/
|
|
273
313
|
export function emphasize(color, coefficient = 0.15) {
|
|
274
314
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
315
|
+
}
|
|
316
|
+
export function private_safeEmphasize(color, coefficient, warning) {
|
|
317
|
+
try {
|
|
318
|
+
return private_safeEmphasize(color, coefficient);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (warning && process.env.NODE_ENV !== 'production') {
|
|
321
|
+
console.warn(warning);
|
|
322
|
+
}
|
|
323
|
+
return color;
|
|
324
|
+
}
|
|
275
325
|
}
|
|
@@ -6,6 +6,7 @@ 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
|
+
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
9
10
|
import cssVarsParser from './cssVarsParser';
|
|
10
11
|
import ThemeProvider from '../ThemeProvider';
|
|
11
12
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
@@ -50,9 +51,14 @@ export default function createCssVarsProvider(options) {
|
|
|
50
51
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
51
52
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
52
53
|
colorSchemeSelector = ':root',
|
|
53
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
54
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
55
|
+
disableNestedContext = false,
|
|
56
|
+
disableStyleSheetGeneration = false
|
|
54
57
|
}) {
|
|
55
58
|
const hasMounted = React.useRef(false);
|
|
59
|
+
const upperTheme = muiUseTheme();
|
|
60
|
+
const ctx = React.useContext(ColorSchemeContext);
|
|
61
|
+
const nested = !!ctx && !disableNestedContext;
|
|
56
62
|
const {
|
|
57
63
|
colorSchemes = {},
|
|
58
64
|
components = {},
|
|
@@ -65,12 +71,12 @@ export default function createCssVarsProvider(options) {
|
|
|
65
71
|
|
|
66
72
|
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
67
73
|
const {
|
|
68
|
-
mode,
|
|
74
|
+
mode: stateMode,
|
|
69
75
|
setMode,
|
|
70
76
|
systemMode,
|
|
71
77
|
lightColorScheme,
|
|
72
78
|
darkColorScheme,
|
|
73
|
-
colorScheme,
|
|
79
|
+
colorScheme: stateColorScheme,
|
|
74
80
|
setColorScheme
|
|
75
81
|
} = useCurrentColorScheme({
|
|
76
82
|
supportedColorSchemes: allColorSchemes,
|
|
@@ -81,6 +87,12 @@ export default function createCssVarsProvider(options) {
|
|
|
81
87
|
defaultMode,
|
|
82
88
|
storageWindow
|
|
83
89
|
});
|
|
90
|
+
let mode = stateMode;
|
|
91
|
+
let colorScheme = stateColorScheme;
|
|
92
|
+
if (nested) {
|
|
93
|
+
mode = ctx.mode;
|
|
94
|
+
colorScheme = ctx.colorScheme;
|
|
95
|
+
}
|
|
84
96
|
const calculatedMode = (() => {
|
|
85
97
|
if (!mode) {
|
|
86
98
|
// This scope occurs on the server
|
|
@@ -106,15 +118,14 @@ export default function createCssVarsProvider(options) {
|
|
|
106
118
|
// 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
107
119
|
const {
|
|
108
120
|
css: rootCss,
|
|
109
|
-
vars: rootVars
|
|
110
|
-
parsedTheme
|
|
121
|
+
vars: rootVars
|
|
111
122
|
} = cssVarsParser(restThemeProp, {
|
|
112
123
|
prefix: cssVarPrefix,
|
|
113
124
|
shouldSkipGeneratingVar
|
|
114
125
|
});
|
|
115
126
|
|
|
116
127
|
// 3. Start composing the theme object
|
|
117
|
-
const theme = _extends({},
|
|
128
|
+
const theme = _extends({}, restThemeProp, {
|
|
118
129
|
components,
|
|
119
130
|
colorSchemes,
|
|
120
131
|
cssVarPrefix,
|
|
@@ -130,8 +141,7 @@ export default function createCssVarsProvider(options) {
|
|
|
130
141
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
131
142
|
const {
|
|
132
143
|
css,
|
|
133
|
-
vars
|
|
134
|
-
parsedTheme: parsedScheme
|
|
144
|
+
vars
|
|
135
145
|
} = cssVarsParser(scheme, {
|
|
136
146
|
prefix: cssVarPrefix,
|
|
137
147
|
shouldSkipGeneratingVar
|
|
@@ -139,12 +149,12 @@ export default function createCssVarsProvider(options) {
|
|
|
139
149
|
theme.vars = deepmerge(theme.vars, vars);
|
|
140
150
|
if (key === calculatedColorScheme) {
|
|
141
151
|
// 4.1 Merge the selected color scheme to the theme
|
|
142
|
-
Object.keys(
|
|
143
|
-
if (
|
|
152
|
+
Object.keys(scheme).forEach(schemeKey => {
|
|
153
|
+
if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
|
|
144
154
|
// shallow merge the 1st level structure of the theme.
|
|
145
|
-
theme[schemeKey] = _extends({}, theme[schemeKey],
|
|
155
|
+
theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
|
|
146
156
|
} else {
|
|
147
|
-
theme[schemeKey] =
|
|
157
|
+
theme[schemeKey] = scheme[schemeKey];
|
|
148
158
|
}
|
|
149
159
|
});
|
|
150
160
|
if (theme.palette) {
|
|
@@ -219,21 +229,33 @@ export default function createCssVarsProvider(options) {
|
|
|
219
229
|
setColorScheme,
|
|
220
230
|
allColorSchemes
|
|
221
231
|
}), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
let shouldGenerateStyleSheet = true;
|
|
233
|
+
if (disableStyleSheetGeneration || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
|
|
234
|
+
shouldGenerateStyleSheet = false;
|
|
235
|
+
}
|
|
236
|
+
const element = /*#__PURE__*/_jsxs(React.Fragment, {
|
|
237
|
+
children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
238
|
+
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
239
|
+
styles: {
|
|
240
|
+
[colorSchemeSelector]: rootCss
|
|
241
|
+
}
|
|
242
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
243
|
+
styles: defaultColorSchemeStyleSheet
|
|
244
|
+
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
245
|
+
styles: otherColorSchemesStyleSheet
|
|
246
|
+
})]
|
|
232
247
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
233
248
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
234
249
|
children: children
|
|
235
250
|
})]
|
|
236
251
|
});
|
|
252
|
+
if (nested) {
|
|
253
|
+
return element;
|
|
254
|
+
}
|
|
255
|
+
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
|
256
|
+
value: contextValue,
|
|
257
|
+
children: element
|
|
258
|
+
});
|
|
237
259
|
}
|
|
238
260
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
239
261
|
/**
|
|
@@ -264,6 +286,16 @@ export default function createCssVarsProvider(options) {
|
|
|
264
286
|
* The initial mode used.
|
|
265
287
|
*/
|
|
266
288
|
defaultMode: PropTypes.string,
|
|
289
|
+
/**
|
|
290
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
291
|
+
*/
|
|
292
|
+
disableNestedContext: PropTypes.bool,
|
|
293
|
+
/**
|
|
294
|
+
* If `true`, the style sheet won't be generated.
|
|
295
|
+
*
|
|
296
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
297
|
+
*/
|
|
298
|
+
disableStyleSheetGeneration: PropTypes.bool,
|
|
267
299
|
/**
|
|
268
300
|
* Disable CSS transitions when switching between modes or color schemes
|
|
269
301
|
*/
|
|
@@ -86,10 +86,10 @@ const getCssValue = (keys, value) => {
|
|
|
86
86
|
* }} options.
|
|
87
87
|
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
88
88
|
*
|
|
89
|
-
* @returns {{ css: Object, vars: Object
|
|
89
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
|
|
90
90
|
*
|
|
91
91
|
* @example
|
|
92
|
-
* const { css, vars
|
|
92
|
+
* const { css, vars } = parser({
|
|
93
93
|
* fontSize: 12,
|
|
94
94
|
* lineHeight: 1.2,
|
|
95
95
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
@@ -97,7 +97,6 @@ const getCssValue = (keys, value) => {
|
|
|
97
97
|
*
|
|
98
98
|
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
99
99
|
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
100
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
101
100
|
*/
|
|
102
101
|
export default function cssVarsParser(theme, options) {
|
|
103
102
|
const {
|
|
@@ -106,7 +105,6 @@ export default function cssVarsParser(theme, options) {
|
|
|
106
105
|
} = options || {};
|
|
107
106
|
const css = {};
|
|
108
107
|
const vars = {};
|
|
109
|
-
const parsedTheme = {};
|
|
110
108
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
111
109
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
112
110
|
if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -118,13 +116,11 @@ export default function cssVarsParser(theme, options) {
|
|
|
118
116
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
122
119
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
123
120
|
);
|
|
124
121
|
|
|
125
122
|
return {
|
|
126
123
|
css,
|
|
127
|
-
vars
|
|
128
|
-
parsedTheme
|
|
124
|
+
vars
|
|
129
125
|
};
|
|
130
126
|
}
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.20.1",
|
|
47
|
-
"@mui/private-theming": "^5.10.
|
|
48
|
-
"@mui/styled-engine": "^5.10.
|
|
49
|
-
"@mui/types": "^7.2.
|
|
50
|
-
"@mui/utils": "^5.10.
|
|
47
|
+
"@mui/private-theming": "^5.10.16",
|
|
48
|
+
"@mui/styled-engine": "^5.10.16",
|
|
49
|
+
"@mui/types": "^7.2.2",
|
|
50
|
+
"@mui/utils": "^5.10.16",
|
|
51
51
|
"clsx": "^1.2.1",
|
|
52
52
|
"csstype": "^3.1.1",
|
|
53
53
|
"prop-types": "^15.8.1"
|