@mui/system 5.15.6 → 5.15.8

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.
@@ -1,12 +1,12 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
4
  import _extends from "@babel/runtime/helpers/esm/extends";
5
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
6
  /* eslint-disable no-underscore-dangle */
6
7
  import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
7
- import { getDisplayName, unstable_capitalize as capitalize, isPlainObject, deepmerge } from '@mui/utils';
8
+ import { getDisplayName, unstable_capitalize as capitalize, isPlainObject } from '@mui/utils';
8
9
  import createTheme from './createTheme';
9
- import propsToClassKey from './propsToClassKey';
10
10
  import styleFunctionSx from './styleFunctionSx';
11
11
  function isEmpty(obj) {
12
12
  return Object.keys(obj).length === 0;
@@ -20,73 +20,6 @@ function isStringTag(tag) {
20
20
  // it's a lowercase character
21
21
  tag.charCodeAt(0) > 96;
22
22
  }
23
- var getStyleOverrides = function getStyleOverrides(name, theme) {
24
- if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
25
- return theme.components[name].styleOverrides;
26
- }
27
- return null;
28
- };
29
- var transformVariants = function transformVariants(variants) {
30
- var numOfCallbacks = 0;
31
- var variantsStyles = {};
32
- if (variants) {
33
- variants.forEach(function (definition) {
34
- var key = '';
35
- if (typeof definition.props === 'function') {
36
- key = "callback".concat(numOfCallbacks);
37
- numOfCallbacks += 1;
38
- } else {
39
- key = propsToClassKey(definition.props);
40
- }
41
- variantsStyles[key] = definition.style;
42
- });
43
- }
44
- return variantsStyles;
45
- };
46
- var getVariantStyles = function getVariantStyles(name, theme) {
47
- var variants = [];
48
- if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
49
- variants = theme.components[name].variants;
50
- }
51
- return transformVariants(variants);
52
- };
53
- var variantsResolver = function variantsResolver(props, styles, variants) {
54
- var _props$ownerState = props.ownerState,
55
- ownerState = _props$ownerState === void 0 ? {} : _props$ownerState;
56
- var variantsStyles = [];
57
- var numOfCallbacks = 0;
58
- if (variants) {
59
- variants.forEach(function (variant) {
60
- var isMatch = true;
61
- if (typeof variant.props === 'function') {
62
- var propsToCheck = _extends({}, props, ownerState);
63
- isMatch = variant.props(propsToCheck);
64
- } else {
65
- Object.keys(variant.props).forEach(function (key) {
66
- if (ownerState[key] !== variant.props[key] && props[key] !== variant.props[key]) {
67
- isMatch = false;
68
- }
69
- });
70
- }
71
- if (isMatch) {
72
- if (typeof variant.props === 'function') {
73
- variantsStyles.push(styles["callback".concat(numOfCallbacks)]);
74
- } else {
75
- variantsStyles.push(styles[propsToClassKey(variant.props)]);
76
- }
77
- }
78
- if (typeof variant.props === 'function') {
79
- numOfCallbacks += 1;
80
- }
81
- });
82
- }
83
- return variantsStyles;
84
- };
85
- var themeVariantsResolver = function themeVariantsResolver(props, styles, theme, name) {
86
- var _theme$components;
87
- var themeVariants = theme == null || (_theme$components = theme.components) == null || (_theme$components = _theme$components[name]) == null ? void 0 : _theme$components.variants;
88
- return variantsResolver(props, styles, themeVariants);
89
- };
90
23
 
91
24
  // Update /system/styled/#api in case if this changes
92
25
  export function shouldForwardProp(prop) {
@@ -113,28 +46,50 @@ function defaultOverridesResolver(slot) {
113
46
  return styles[slot];
114
47
  };
115
48
  }
116
- var muiStyledFunctionResolver = function muiStyledFunctionResolver(_ref2) {
117
- var styledArg = _ref2.styledArg,
118
- props = _ref2.props,
119
- defaultTheme = _ref2.defaultTheme,
120
- themeId = _ref2.themeId;
121
- var resolvedStyles = styledArg(_extends({}, props, {
122
- theme: resolveTheme(_extends({}, props, {
123
- defaultTheme: defaultTheme,
124
- themeId: themeId
125
- }))
126
- }));
127
- var optionalVariants;
128
- if (resolvedStyles && resolvedStyles.variants) {
129
- optionalVariants = resolvedStyles.variants;
130
- delete resolvedStyles.variants;
49
+ function processStyleArg(callableStyle, _ref2) {
50
+ var ownerState = _ref2.ownerState,
51
+ props = _objectWithoutProperties(_ref2, ["ownerState"]);
52
+ var resolvedStylesArg = typeof callableStyle === 'function' ? callableStyle(_extends({
53
+ ownerState: ownerState
54
+ }, props)) : callableStyle;
55
+ if (Array.isArray(resolvedStylesArg)) {
56
+ return resolvedStylesArg.flatMap(function (resolvedStyle) {
57
+ return processStyleArg(resolvedStyle, _extends({
58
+ ownerState: ownerState
59
+ }, props));
60
+ });
131
61
  }
132
- if (optionalVariants) {
133
- var variantsStyles = variantsResolver(props, transformVariants(optionalVariants), optionalVariants);
134
- return [resolvedStyles].concat(_toConsumableArray(variantsStyles));
62
+ if (!!resolvedStylesArg && _typeof(resolvedStylesArg) === 'object' && Array.isArray(resolvedStylesArg.variants)) {
63
+ var _resolvedStylesArg$va = resolvedStylesArg.variants,
64
+ variants = _resolvedStylesArg$va === void 0 ? [] : _resolvedStylesArg$va,
65
+ otherStyles = _objectWithoutProperties(resolvedStylesArg, ["variants"]);
66
+ var result = otherStyles;
67
+ variants.forEach(function (variant) {
68
+ var isMatch = true;
69
+ if (typeof variant.props === 'function') {
70
+ isMatch = variant.props(_extends({
71
+ ownerState: ownerState
72
+ }, props));
73
+ } else {
74
+ Object.keys(variant.props).forEach(function (key) {
75
+ if ((ownerState == null ? void 0 : ownerState[key]) !== variant.props[key] && props[key] !== variant.props[key]) {
76
+ isMatch = false;
77
+ }
78
+ });
79
+ }
80
+ if (isMatch) {
81
+ if (!Array.isArray(result)) {
82
+ result = [result];
83
+ }
84
+ result.push(typeof variant.style === 'function' ? variant.style(_extends({
85
+ ownerState: ownerState
86
+ }, props)) : variant.style);
87
+ }
88
+ });
89
+ return result;
135
90
  }
136
- return resolvedStyles;
137
- };
91
+ return resolvedStylesArg;
92
+ }
138
93
  export default function createStyled() {
139
94
  var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
140
95
  var themeId = input.themeId,
@@ -198,102 +153,65 @@ export default function createStyled() {
198
153
  shouldForwardProp: shouldForwardPropOption,
199
154
  label: label
200
155
  }, options));
201
- var muiStyledResolver = function muiStyledResolver(styleArg) {
202
- for (var _len = arguments.length, expressions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
203
- expressions[_key - 1] = arguments[_key];
204
- }
205
- var expressionsWithDefaultTheme = expressions ? expressions.map(function (stylesArg) {
206
- // On the server Emotion doesn't use React.forwardRef for creating components, so the created
207
- // component stays as a function. This condition makes sure that we do not interpolate functions
208
- // which are basically components used as a selectors.
209
- if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg) {
210
- return function (props) {
211
- return muiStyledFunctionResolver({
212
- styledArg: stylesArg,
213
- props: props,
214
- defaultTheme: defaultTheme,
215
- themeId: themeId
216
- });
217
- };
218
- }
219
- if (isPlainObject(stylesArg)) {
220
- var transformedStylesArg = stylesArg;
221
- var styledArgVariants;
222
- if (stylesArg && stylesArg.variants) {
223
- styledArgVariants = stylesArg.variants;
224
- delete transformedStylesArg.variants;
225
- transformedStylesArg = function transformedStylesArg(props) {
226
- var result = stylesArg;
227
- var variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
228
- variantStyles.forEach(function (variantStyle) {
229
- result = deepmerge(result, variantStyle);
230
- });
231
- return result;
232
- };
233
- }
234
- return transformedStylesArg;
235
- }
236
- return stylesArg;
237
- }) : [];
238
- var transformedStyleArg = styleArg;
239
- if (isPlainObject(styleArg)) {
240
- var styledArgVariants;
241
- if (styleArg && styleArg.variants) {
242
- styledArgVariants = styleArg.variants;
243
- delete transformedStyleArg.variants;
244
- transformedStyleArg = function transformedStyleArg(props) {
245
- var result = styleArg;
246
- var variantStyles = variantsResolver(props, transformVariants(styledArgVariants), styledArgVariants);
247
- variantStyles.forEach(function (variantStyle) {
248
- result = deepmerge(result, variantStyle);
249
- });
250
- return result;
251
- };
252
- }
253
- } else if (typeof styleArg === 'function' &&
156
+ var transformStyleArg = function transformStyleArg(stylesArg) {
254
157
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
255
158
  // component stays as a function. This condition makes sure that we do not interpolate functions
256
159
  // which are basically components used as a selectors.
257
- styleArg.__emotion_real !== styleArg) {
258
- // If the type is function, we need to define the default theme.
259
- transformedStyleArg = function transformedStyleArg(props) {
260
- return muiStyledFunctionResolver({
261
- styledArg: styleArg,
262
- props: props,
263
- defaultTheme: defaultTheme,
264
- themeId: themeId
265
- });
160
+ if (typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg || isPlainObject(stylesArg)) {
161
+ return function (props) {
162
+ return processStyleArg(stylesArg, _extends({}, props, {
163
+ theme: resolveTheme({
164
+ theme: props.theme,
165
+ defaultTheme: defaultTheme,
166
+ themeId: themeId
167
+ })
168
+ }));
266
169
  };
267
170
  }
171
+ return stylesArg;
172
+ };
173
+ var muiStyledResolver = function muiStyledResolver(styleArg) {
174
+ var transformedStyleArg = transformStyleArg(styleArg);
175
+ for (var _len = arguments.length, expressions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
176
+ expressions[_key - 1] = arguments[_key];
177
+ }
178
+ var expressionsWithDefaultTheme = expressions ? expressions.map(transformStyleArg) : [];
268
179
  if (componentName && overridesResolver) {
269
180
  expressionsWithDefaultTheme.push(function (props) {
270
181
  var theme = resolveTheme(_extends({}, props, {
271
182
  defaultTheme: defaultTheme,
272
183
  themeId: themeId
273
184
  }));
274
- var styleOverrides = getStyleOverrides(componentName, theme);
275
- if (styleOverrides) {
276
- var resolvedStyleOverrides = {};
277
- Object.entries(styleOverrides).forEach(function (_ref3) {
278
- var _ref4 = _slicedToArray(_ref3, 2),
279
- slotKey = _ref4[0],
280
- slotStyle = _ref4[1];
281
- resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
282
- theme: theme
283
- })) : slotStyle;
284
- });
285
- return overridesResolver(props, resolvedStyleOverrides);
185
+ if (!theme.components || !theme.components[componentName] || !theme.components[componentName].styleOverrides) {
186
+ return null;
286
187
  }
287
- return null;
188
+ var styleOverrides = theme.components[componentName].styleOverrides;
189
+ var resolvedStyleOverrides = {};
190
+ // TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
191
+ Object.entries(styleOverrides).forEach(function (_ref3) {
192
+ var _ref4 = _slicedToArray(_ref3, 2),
193
+ slotKey = _ref4[0],
194
+ slotStyle = _ref4[1];
195
+ resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, _extends({}, props, {
196
+ theme: theme
197
+ }));
198
+ });
199
+ return overridesResolver(props, resolvedStyleOverrides);
288
200
  });
289
201
  }
290
202
  if (componentName && !skipVariantsResolver) {
291
203
  expressionsWithDefaultTheme.push(function (props) {
204
+ var _theme$components;
292
205
  var theme = resolveTheme(_extends({}, props, {
293
206
  defaultTheme: defaultTheme,
294
207
  themeId: themeId
295
208
  }));
296
- return themeVariantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
209
+ var themeVariants = theme == null || (_theme$components = theme.components) == null || (_theme$components = _theme$components[componentName]) == null ? void 0 : _theme$components.variants;
210
+ return processStyleArg({
211
+ variants: themeVariants
212
+ }, _extends({}, props, {
213
+ theme: theme
214
+ }));
297
215
  });
298
216
  }
299
217
  if (!skipSx) {
@@ -0,0 +1,73 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ /**
3
+ * A universal utility to style components with multiple color modes. Always use it from the theme object.
4
+ * It works with:
5
+ * - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
6
+ * - [CSS theme variables](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/)
7
+ * - Zero-runtime engine
8
+ *
9
+ * Tips: Use an array over object spread and place `theme.applyStyles()` last.
10
+ *
11
+ * ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
12
+ *
13
+ * 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
14
+ *
15
+ * @example
16
+ * 1. using with `styled`:
17
+ * ```jsx
18
+ * const Component = styled('div')(({ theme }) => [
19
+ * { background: '#e5e5e5' },
20
+ * theme.applyStyles('dark', {
21
+ * background: '#1c1c1c',
22
+ * color: '#fff',
23
+ * }),
24
+ * ]);
25
+ * ```
26
+ *
27
+ * @example
28
+ * 2. using with `sx` prop:
29
+ * ```jsx
30
+ * <Box sx={theme => [
31
+ * { background: '#e5e5e5' },
32
+ * theme.applyStyles('dark', {
33
+ * background: '#1c1c1c',
34
+ * color: '#fff',
35
+ * }),
36
+ * ]}
37
+ * />
38
+ * ```
39
+ *
40
+ * @example
41
+ * 3. theming a component:
42
+ * ```jsx
43
+ * extendTheme({
44
+ * components: {
45
+ * MuiButton: {
46
+ * styleOverrides: {
47
+ * root: ({ theme }) => [
48
+ * { background: '#e5e5e5' },
49
+ * theme.applyStyles('dark', {
50
+ * background: '#1c1c1c',
51
+ * color: '#fff',
52
+ * }),
53
+ * ],
54
+ * },
55
+ * }
56
+ * }
57
+ * })
58
+ *```
59
+ */
60
+ export default function applyStyles(key, styles) {
61
+ // @ts-expect-error this is 'any' type
62
+ var theme = this;
63
+ if (theme.vars && typeof theme.getColorSchemeSelector === 'function') {
64
+ // If CssVarsProvider is used as a provider,
65
+ // returns '* :where([data-mui-color-scheme="light|dark"]) &'
66
+ var selector = theme.getColorSchemeSelector(key).replace(/(\[[^\]]+\])/, '*:where($1)');
67
+ return _defineProperty({}, selector, styles);
68
+ }
69
+ if (theme.palette.mode === key) {
70
+ return styles;
71
+ }
72
+ return {};
73
+ }
@@ -6,6 +6,7 @@ import shape from './shape';
6
6
  import createSpacing from './createSpacing';
7
7
  import styleFunctionSx from '../styleFunctionSx/styleFunctionSx';
8
8
  import defaultSxConfig from '../styleFunctionSx/defaultSxConfig';
9
+ import applyStyles from './applyStyles';
9
10
  function createTheme() {
10
11
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
12
  var _options$breakpoints = options.breakpoints,
@@ -29,6 +30,7 @@ function createTheme() {
29
30
  spacing: spacing,
30
31
  shape: _extends({}, shape, shapeInput)
31
32
  }, other);
33
+ muiTheme.applyStyles = applyStyles;
32
34
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
33
35
  args[_key - 1] = arguments[_key];
34
36
  }
@@ -1,2 +1,3 @@
1
1
  export { default } from './createTheme';
2
- export { default as private_createBreakpoints } from './createBreakpoints';
2
+ export { default as private_createBreakpoints } from './createBreakpoints';
3
+ export { default as unstable_applyStyles } from './applyStyles';
package/legacy/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
- * @mui/system v5.15.6
2
+ * @mui/system v5.15.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- 'use client';
9
-
10
8
  import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
11
9
  export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
12
10
  export { default as GlobalStyles } from './GlobalStyles';
@@ -323,4 +323,23 @@ export function private_safeEmphasize(color, coefficient, warning) {
323
323
  }
324
324
  return color;
325
325
  }
326
+ }
327
+
328
+ /**
329
+ * Blend a transparent overlay color with a background color, resulting in a single
330
+ * RGB color.
331
+ * @param {string} background - CSS color
332
+ * @param {string} overlay - CSS color
333
+ * @param {number} opacity - Opacity multiplier in the range 0 - 1
334
+ * @param {number} [gamma=1.0] - Gamma correction factor. For gamma-correct blending, 2.2 is usual.
335
+ */
336
+ export function blend(background, overlay, opacity, gamma = 1.0) {
337
+ const blendChannel = (b, o) => Math.round((b ** (1 / gamma) * (1 - opacity) + o ** (1 / gamma) * opacity) ** gamma);
338
+ const backgroundColor = decomposeColor(background);
339
+ const overlayColor = decomposeColor(overlay);
340
+ const rgb = [blendChannel(backgroundColor.values[0], overlayColor.values[0]), blendChannel(backgroundColor.values[1], overlayColor.values[1]), blendChannel(backgroundColor.values[2], overlayColor.values[2])];
341
+ return recomposeColor({
342
+ type: 'rgb',
343
+ values: rgb
344
+ });
326
345
  }