@mui/system 5.0.1 → 5.0.5

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 (61) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +281 -0
  3. package/LICENSE +21 -21
  4. package/borders.js +1 -1
  5. package/breakpoints.js +4 -3
  6. package/colorManipulator.js +8 -8
  7. package/createStyled.d.ts +16 -215
  8. package/createStyled.js +1 -1
  9. package/createTheme/createBreakpoints.d.ts +53 -6
  10. package/createTheme/createBreakpoints.js +1 -1
  11. package/createTheme/createSpacing.d.ts +10 -10
  12. package/cssVars/createCssVarsProvider.d.ts +81 -0
  13. package/cssVars/createCssVarsProvider.js +206 -0
  14. package/cssVars/createCssVarsProvider.spec.d.ts +1 -0
  15. package/cssVars/cssVarsParser.d.ts +57 -0
  16. package/cssVars/cssVarsParser.js +126 -0
  17. package/cssVars/getInitColorSchemeScript.d.ts +7 -0
  18. package/cssVars/getInitColorSchemeScript.js +38 -0
  19. package/cssVars/index.d.ts +2 -0
  20. package/cssVars/index.js +15 -0
  21. package/cssVars/package.json +6 -0
  22. package/display.js +1 -1
  23. package/esm/cssVars/createCssVarsProvider.js +188 -0
  24. package/esm/cssVars/cssVarsParser.js +112 -0
  25. package/esm/cssVars/getInitColorSchemeScript.js +21 -0
  26. package/esm/cssVars/index.js +1 -0
  27. package/esm/index.js +2 -1
  28. package/esm/spacing.js +2 -2
  29. package/esm/styleFunctionSx/styleFunctionSx.js +6 -6
  30. package/flexbox.js +1 -1
  31. package/getThemeValue.js +1 -1
  32. package/grid.js +1 -1
  33. package/index.d.ts +6 -0
  34. package/index.js +77 -68
  35. package/index.spec.d.ts +1 -1
  36. package/legacy/cssVars/createCssVarsProvider.js +202 -0
  37. package/legacy/cssVars/cssVarsParser.js +125 -0
  38. package/legacy/cssVars/getInitColorSchemeScript.js +18 -0
  39. package/legacy/cssVars/index.js +1 -0
  40. package/legacy/index.js +3 -2
  41. package/legacy/spacing.js +2 -2
  42. package/legacy/styleFunctionSx/styleFunctionSx.js +6 -6
  43. package/modern/cssVars/createCssVarsProvider.js +188 -0
  44. package/modern/cssVars/cssVarsParser.js +112 -0
  45. package/modern/cssVars/getInitColorSchemeScript.js +21 -0
  46. package/modern/cssVars/index.js +1 -0
  47. package/modern/index.js +3 -2
  48. package/modern/spacing.js +2 -2
  49. package/modern/styleFunctionSx/styleFunctionSx.js +6 -6
  50. package/package.json +2 -2
  51. package/palette.js +1 -1
  52. package/positions.js +1 -1
  53. package/sizing.js +1 -1
  54. package/spacing.d.ts +12 -0
  55. package/spacing.js +5 -5
  56. package/style.d.ts +2 -2
  57. package/style.js +1 -1
  58. package/styleFunctionSx/styleFunctionSx.d.ts +8 -3
  59. package/styleFunctionSx/styleFunctionSx.js +6 -6
  60. package/typography.js +1 -1
  61. package/useTheme.js +1 -1
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.0.1
1
+ /** @license MUI v5.0.5
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.
@@ -47,18 +47,13 @@ var _exportNames = {
47
47
  getThemeProps: true,
48
48
  useTheme: true,
49
49
  useThemeWithoutDefault: true,
50
- ThemeProvider: true
50
+ ThemeProvider: true,
51
+ unstable_createCssVarsProvider: true
51
52
  };
52
- Object.defineProperty(exports, "css", {
53
- enumerable: true,
54
- get: function () {
55
- return _styledEngine.css;
56
- }
57
- });
58
- Object.defineProperty(exports, "keyframes", {
53
+ Object.defineProperty(exports, "Box", {
59
54
  enumerable: true,
60
55
  get: function () {
61
- return _styledEngine.keyframes;
56
+ return _Box.default;
62
57
  }
63
58
  });
64
59
  Object.defineProperty(exports, "GlobalStyles", {
@@ -73,6 +68,12 @@ Object.defineProperty(exports, "StyledEngineProvider", {
73
68
  return _styledEngine.StyledEngineProvider;
74
69
  }
75
70
  });
71
+ Object.defineProperty(exports, "ThemeProvider", {
72
+ enumerable: true,
73
+ get: function () {
74
+ return _ThemeProvider.default;
75
+ }
76
+ });
76
77
  Object.defineProperty(exports, "borders", {
77
78
  enumerable: true,
78
79
  get: function () {
@@ -85,130 +86,136 @@ Object.defineProperty(exports, "breakpoints", {
85
86
  return _breakpoints.default;
86
87
  }
87
88
  });
88
- Object.defineProperty(exports, "handleBreakpoints", {
89
+ Object.defineProperty(exports, "compose", {
89
90
  enumerable: true,
90
91
  get: function () {
91
- return _breakpoints.handleBreakpoints;
92
+ return _compose.default;
92
93
  }
93
94
  });
94
- Object.defineProperty(exports, "mergeBreakpointsInOrder", {
95
+ Object.defineProperty(exports, "createBox", {
95
96
  enumerable: true,
96
97
  get: function () {
97
- return _breakpoints.mergeBreakpointsInOrder;
98
+ return _createBox.default;
98
99
  }
99
100
  });
100
- Object.defineProperty(exports, "unstable_resolveBreakpointValues", {
101
+ Object.defineProperty(exports, "createBreakpoints", {
101
102
  enumerable: true,
102
103
  get: function () {
103
- return _breakpoints.resolveBreakpointValues;
104
+ return _createBreakpoints.default;
104
105
  }
105
106
  });
106
- Object.defineProperty(exports, "compose", {
107
+ Object.defineProperty(exports, "createSpacing", {
107
108
  enumerable: true,
108
109
  get: function () {
109
- return _compose.default;
110
+ return _createSpacing.default;
110
111
  }
111
112
  });
112
- Object.defineProperty(exports, "display", {
113
+ Object.defineProperty(exports, "createStyled", {
113
114
  enumerable: true,
114
115
  get: function () {
115
- return _display.default;
116
+ return _createStyled.default;
116
117
  }
117
118
  });
118
- Object.defineProperty(exports, "flexbox", {
119
+ Object.defineProperty(exports, "createTheme", {
119
120
  enumerable: true,
120
121
  get: function () {
121
- return _flexbox.default;
122
+ return _createTheme.default;
122
123
  }
123
124
  });
124
- Object.defineProperty(exports, "grid", {
125
+ Object.defineProperty(exports, "css", {
125
126
  enumerable: true,
126
127
  get: function () {
127
- return _grid.default;
128
+ return _styledEngine.css;
128
129
  }
129
130
  });
130
- Object.defineProperty(exports, "palette", {
131
+ Object.defineProperty(exports, "display", {
131
132
  enumerable: true,
132
133
  get: function () {
133
- return _palette.default;
134
+ return _display.default;
134
135
  }
135
136
  });
136
- Object.defineProperty(exports, "positions", {
137
+ Object.defineProperty(exports, "flexbox", {
137
138
  enumerable: true,
138
139
  get: function () {
139
- return _positions.default;
140
+ return _flexbox.default;
140
141
  }
141
142
  });
142
- Object.defineProperty(exports, "shadows", {
143
+ Object.defineProperty(exports, "getPath", {
143
144
  enumerable: true,
144
145
  get: function () {
145
- return _shadows.default;
146
+ return _style.getPath;
146
147
  }
147
148
  });
148
- Object.defineProperty(exports, "sizing", {
149
+ Object.defineProperty(exports, "getThemeProps", {
149
150
  enumerable: true,
150
151
  get: function () {
151
- return _sizing.default;
152
+ return _useThemeProps.getThemeProps;
152
153
  }
153
154
  });
154
- Object.defineProperty(exports, "spacing", {
155
+ Object.defineProperty(exports, "grid", {
155
156
  enumerable: true,
156
157
  get: function () {
157
- return _spacing.default;
158
+ return _grid.default;
158
159
  }
159
160
  });
160
- Object.defineProperty(exports, "style", {
161
+ Object.defineProperty(exports, "handleBreakpoints", {
161
162
  enumerable: true,
162
163
  get: function () {
163
- return _style.default;
164
+ return _breakpoints.handleBreakpoints;
164
165
  }
165
166
  });
166
- Object.defineProperty(exports, "getPath", {
167
+ Object.defineProperty(exports, "keyframes", {
167
168
  enumerable: true,
168
169
  get: function () {
169
- return _style.getPath;
170
+ return _styledEngine.keyframes;
170
171
  }
171
172
  });
172
- Object.defineProperty(exports, "typography", {
173
+ Object.defineProperty(exports, "mergeBreakpointsInOrder", {
173
174
  enumerable: true,
174
175
  get: function () {
175
- return _typography.default;
176
+ return _breakpoints.mergeBreakpointsInOrder;
176
177
  }
177
178
  });
178
- Object.defineProperty(exports, "unstable_styleFunctionSx", {
179
+ Object.defineProperty(exports, "palette", {
179
180
  enumerable: true,
180
181
  get: function () {
181
- return _styleFunctionSx.default;
182
+ return _palette.default;
182
183
  }
183
184
  });
184
- Object.defineProperty(exports, "unstable_extendSxProp", {
185
+ Object.defineProperty(exports, "positions", {
185
186
  enumerable: true,
186
187
  get: function () {
187
- return _styleFunctionSx.extendSxProp;
188
+ return _positions.default;
188
189
  }
189
190
  });
190
- Object.defineProperty(exports, "unstable_getThemeValue", {
191
+ Object.defineProperty(exports, "shadows", {
191
192
  enumerable: true,
192
193
  get: function () {
193
- return _getThemeValue.default;
194
+ return _shadows.default;
194
195
  }
195
196
  });
196
- Object.defineProperty(exports, "Box", {
197
+ Object.defineProperty(exports, "shape", {
197
198
  enumerable: true,
198
199
  get: function () {
199
- return _Box.default;
200
+ return _shape.default;
200
201
  }
201
202
  });
202
- Object.defineProperty(exports, "createBox", {
203
+ Object.defineProperty(exports, "sizing", {
203
204
  enumerable: true,
204
205
  get: function () {
205
- return _createBox.default;
206
+ return _sizing.default;
206
207
  }
207
208
  });
208
- Object.defineProperty(exports, "createStyled", {
209
+ Object.defineProperty(exports, "spacing", {
209
210
  enumerable: true,
210
211
  get: function () {
211
- return _createStyled.default;
212
+ return _spacing.default;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, "style", {
216
+ enumerable: true,
217
+ get: function () {
218
+ return _style.default;
212
219
  }
213
220
  });
214
221
  Object.defineProperty(exports, "styled", {
@@ -217,40 +224,40 @@ Object.defineProperty(exports, "styled", {
217
224
  return _styled.default;
218
225
  }
219
226
  });
220
- Object.defineProperty(exports, "createTheme", {
227
+ Object.defineProperty(exports, "typography", {
221
228
  enumerable: true,
222
229
  get: function () {
223
- return _createTheme.default;
230
+ return _typography.default;
224
231
  }
225
232
  });
226
- Object.defineProperty(exports, "createBreakpoints", {
233
+ Object.defineProperty(exports, "unstable_createCssVarsProvider", {
227
234
  enumerable: true,
228
235
  get: function () {
229
- return _createBreakpoints.default;
236
+ return _createCssVarsProvider.default;
230
237
  }
231
238
  });
232
- Object.defineProperty(exports, "createSpacing", {
239
+ Object.defineProperty(exports, "unstable_extendSxProp", {
233
240
  enumerable: true,
234
241
  get: function () {
235
- return _createSpacing.default;
242
+ return _styleFunctionSx.extendSxProp;
236
243
  }
237
244
  });
238
- Object.defineProperty(exports, "shape", {
245
+ Object.defineProperty(exports, "unstable_getThemeValue", {
239
246
  enumerable: true,
240
247
  get: function () {
241
- return _shape.default;
248
+ return _getThemeValue.default;
242
249
  }
243
250
  });
244
- Object.defineProperty(exports, "useThemeProps", {
251
+ Object.defineProperty(exports, "unstable_resolveBreakpointValues", {
245
252
  enumerable: true,
246
253
  get: function () {
247
- return _useThemeProps.default;
254
+ return _breakpoints.resolveBreakpointValues;
248
255
  }
249
256
  });
250
- Object.defineProperty(exports, "getThemeProps", {
257
+ Object.defineProperty(exports, "unstable_styleFunctionSx", {
251
258
  enumerable: true,
252
259
  get: function () {
253
- return _useThemeProps.getThemeProps;
260
+ return _styleFunctionSx.default;
254
261
  }
255
262
  });
256
263
  Object.defineProperty(exports, "useTheme", {
@@ -259,16 +266,16 @@ Object.defineProperty(exports, "useTheme", {
259
266
  return _useTheme.default;
260
267
  }
261
268
  });
262
- Object.defineProperty(exports, "useThemeWithoutDefault", {
269
+ Object.defineProperty(exports, "useThemeProps", {
263
270
  enumerable: true,
264
271
  get: function () {
265
- return _useThemeWithoutDefault.default;
272
+ return _useThemeProps.default;
266
273
  }
267
274
  });
268
- Object.defineProperty(exports, "ThemeProvider", {
275
+ Object.defineProperty(exports, "useThemeWithoutDefault", {
269
276
  enumerable: true,
270
277
  get: function () {
271
- return _ThemeProvider.default;
278
+ return _useThemeWithoutDefault.default;
272
279
  }
273
280
  });
274
281
 
@@ -450,6 +457,8 @@ Object.keys(_colorManipulator).forEach(function (key) {
450
457
 
451
458
  var _ThemeProvider = _interopRequireDefault(require("./ThemeProvider"));
452
459
 
460
+ var _createCssVarsProvider = _interopRequireDefault(require("./cssVars/createCssVarsProvider"));
461
+
453
462
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
454
463
 
455
464
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -0,0 +1,202 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
5
+ import * as React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import { GlobalStyles } from '@mui/styled-engine';
8
+ import { deepmerge } from '@mui/utils';
9
+ import cssVarsParser from './cssVarsParser';
10
+ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_STORAGE_KEY } from './getInitColorSchemeScript';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+
14
+ var resolveMode = function resolveMode(key, fallback, supportedColorSchemes) {
15
+ if (typeof window === 'undefined') {
16
+ return undefined;
17
+ }
18
+
19
+ var value;
20
+
21
+ try {
22
+ value = localStorage.getItem(key) || undefined;
23
+
24
+ if (!supportedColorSchemes.includes(value)) {
25
+ value = undefined;
26
+ }
27
+ } catch (e) {// Unsupported
28
+ }
29
+
30
+ return value || fallback;
31
+ };
32
+
33
+ export default function createCssVarsProvider(ThemeContext, options) {
34
+ var _options$theme = options.theme,
35
+ baseTheme = _options$theme === void 0 ? {} : _options$theme,
36
+ designSystemColorScheme = options.defaultColorScheme,
37
+ _options$prefix = options.prefix,
38
+ designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix;
39
+
40
+ if (!baseTheme.colorSchemes || !baseTheme.colorSchemes[designSystemColorScheme]) {
41
+ console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
42
+ }
43
+
44
+ var ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
45
+
46
+ var useColorScheme = function useColorScheme() {
47
+ var value = React.useContext(ColorSchemeContext);
48
+
49
+ if (!value) {
50
+ throw new Error(process.env.NODE_ENV !== "production" ? "MUI: `useColorScheme` must be called under <CssVarsProvider />" : _formatMuiErrorMessage(19));
51
+ }
52
+
53
+ return value;
54
+ };
55
+
56
+ function CssVarsProvider(_ref) {
57
+ var children = _ref.children,
58
+ _ref$theme = _ref.theme,
59
+ themeProp = _ref$theme === void 0 ? {} : _ref$theme,
60
+ _ref$prefix = _ref.prefix,
61
+ prefix = _ref$prefix === void 0 ? designSystemPrefix : _ref$prefix,
62
+ _ref$storageKey = _ref.storageKey,
63
+ storageKey = _ref$storageKey === void 0 ? DEFAULT_STORAGE_KEY : _ref$storageKey,
64
+ _ref$attribute = _ref.attribute,
65
+ attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
66
+ _ref$defaultColorSche = _ref.defaultColorScheme,
67
+ defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche;
68
+
69
+ var _baseTheme$colorSchem = baseTheme.colorSchemes,
70
+ baseColorSchemes = _baseTheme$colorSchem === void 0 ? {} : _baseTheme$colorSchem,
71
+ restBaseTheme = _objectWithoutProperties(baseTheme, ["colorSchemes"]);
72
+
73
+ var _themeProp$colorSchem = themeProp.colorSchemes,
74
+ colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
75
+ restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
76
+
77
+ var mergedTheme = deepmerge(restBaseTheme, restThemeProp);
78
+ var colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
79
+ var allColorSchemes = Object.keys(colorSchemes);
80
+ var joinedColorSchemes = allColorSchemes.join(',');
81
+
82
+ var _React$useState = React.useState(function () {
83
+ return resolveMode(storageKey, defaultColorScheme, allColorSchemes);
84
+ }),
85
+ colorScheme = _React$useState[0],
86
+ setColorScheme = _React$useState[1];
87
+
88
+ var resolvedColorScheme = colorScheme || defaultColorScheme;
89
+
90
+ var _cssVarsParser = cssVarsParser(mergedTheme, {
91
+ prefix: prefix
92
+ }),
93
+ rootCss = _cssVarsParser.css,
94
+ rootVars = _cssVarsParser.vars;
95
+
96
+ mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
97
+ vars: rootVars
98
+ });
99
+ var styleSheet = {};
100
+ Object.entries(colorSchemes).forEach(function (_ref2) {
101
+ var _ref3 = _slicedToArray(_ref2, 2),
102
+ key = _ref3[0],
103
+ scheme = _ref3[1];
104
+
105
+ var _cssVarsParser2 = cssVarsParser(scheme, {
106
+ prefix: prefix
107
+ }),
108
+ css = _cssVarsParser2.css,
109
+ vars = _cssVarsParser2.vars;
110
+
111
+ if (key === resolvedColorScheme) {
112
+ mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
113
+ }
114
+
115
+ if (key === defaultColorScheme) {
116
+ styleSheet[':root'] = deepmerge(rootCss, css);
117
+ } else {
118
+ styleSheet["[".concat(attribute, "=\"").concat(key, "\"]")] = css;
119
+ }
120
+ });
121
+ React.useEffect(function () {
122
+ if (colorScheme) {
123
+ document.body.setAttribute(attribute, colorScheme);
124
+ localStorage.setItem(storageKey, colorScheme);
125
+ }
126
+ }, [colorScheme, attribute, storageKey]); // local storage modified in the context of another document
127
+
128
+ React.useEffect(function () {
129
+ var handleStorage = function handleStorage(event) {
130
+ var storageColorScheme = event.newValue;
131
+
132
+ if (event.key === storageKey && joinedColorSchemes.match(storageColorScheme)) {
133
+ if (storageColorScheme) {
134
+ setColorScheme(storageColorScheme);
135
+ }
136
+ }
137
+ };
138
+
139
+ window.addEventListener('storage', handleStorage);
140
+ return function () {
141
+ return window.removeEventListener('storage', handleStorage);
142
+ };
143
+ }, [setColorScheme, storageKey, joinedColorSchemes]);
144
+ var wrappedSetColorScheme = React.useCallback(function (val) {
145
+ if (typeof val === 'string' && !allColorSchemes.includes(val)) {
146
+ console.error("`".concat(val, "` does not exist in `theme.colorSchemes`."));
147
+ } else {
148
+ setColorScheme(val);
149
+ }
150
+ }, [setColorScheme, allColorSchemes]);
151
+ return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
152
+ value: {
153
+ colorScheme: colorScheme,
154
+ setColorScheme: wrappedSetColorScheme,
155
+ allColorSchemes: allColorSchemes
156
+ },
157
+ children: [/*#__PURE__*/_jsx(GlobalStyles, {
158
+ styles: styleSheet
159
+ }), /*#__PURE__*/_jsx(ThemeContext.Provider, {
160
+ value: mergedTheme,
161
+ children: children
162
+ })]
163
+ });
164
+ }
165
+
166
+ process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
167
+ /**
168
+ * The body attribute name to attach colorScheme.
169
+ */
170
+ attribute: PropTypes.string,
171
+
172
+ /**
173
+ * Your component tree.
174
+ */
175
+ children: PropTypes.node,
176
+
177
+ /**
178
+ * The initial color scheme used.
179
+ */
180
+ defaultColorScheme: PropTypes.string,
181
+
182
+ /**
183
+ * css variable prefix
184
+ */
185
+ prefix: PropTypes.string,
186
+
187
+ /**
188
+ * The key in the local storage used to store current color scheme.
189
+ */
190
+ storageKey: PropTypes.string,
191
+
192
+ /**
193
+ * The calculated theme object that will be passed through context.
194
+ */
195
+ theme: PropTypes.object
196
+ } : void 0;
197
+ return {
198
+ CssVarsProvider: CssVarsProvider,
199
+ useColorScheme: useColorScheme,
200
+ getInitColorSchemeScript: getInitColorSchemeScript
201
+ };
202
+ }
@@ -0,0 +1,125 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
6
+
7
+ /**
8
+ * This function create an object from keys, value and then assign to target
9
+ *
10
+ * @param {Object} obj : the target object to be assigned
11
+ * @param {string[]} keys
12
+ * @param {string | number} value
13
+ *
14
+ * @example
15
+ * const source = {}
16
+ * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
17
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
18
+ *
19
+ * @example
20
+ * const source = { palette: { primary: 'var(--palette-primary)' } }
21
+ * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
22
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
23
+ */
24
+ export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
25
+ var temp = obj;
26
+ keys.forEach(function (k, index) {
27
+ if (index === keys.length - 1) {
28
+ if (temp && _typeof(temp) === 'object') {
29
+ temp[k] = value;
30
+ }
31
+ } else if (temp && _typeof(temp) === 'object') {
32
+ if (!temp[k]) {
33
+ temp[k] = {};
34
+ }
35
+
36
+ temp = temp[k];
37
+ }
38
+ });
39
+ };
40
+ /**
41
+ *
42
+ * @param {Object} obj : source object
43
+ * @param {Function} callback : a function that will be called when
44
+ * - the deepest key in source object is reached
45
+ * - the value of the deepest key is NOT `undefined` | `null`
46
+ *
47
+ * @example
48
+ * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
49
+ * // ['palette', 'primary', 'main'] '#000000'
50
+ */
51
+
52
+ export var walkObjectDeep = function walkObjectDeep(obj, callback) {
53
+ function recurse(object) {
54
+ var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
55
+ Object.entries(object).forEach(function (_ref) {
56
+ var _ref2 = _slicedToArray(_ref, 2),
57
+ key = _ref2[0],
58
+ value = _ref2[1];
59
+
60
+ if (value !== undefined && value !== null) {
61
+ if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
62
+ recurse(value, [].concat(_toConsumableArray(parentKeys), [key]));
63
+ } else {
64
+ callback([].concat(_toConsumableArray(parentKeys), [key]), value);
65
+ }
66
+ }
67
+ });
68
+ }
69
+
70
+ recurse(obj);
71
+ };
72
+
73
+ var getCssValue = function getCssValue(keys, value) {
74
+ if (typeof value === 'number') {
75
+ if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(function (prop) {
76
+ return keys.includes(prop);
77
+ })) {
78
+ // css property that are unitless
79
+ return value;
80
+ }
81
+
82
+ return "".concat(value, "px");
83
+ }
84
+
85
+ return value;
86
+ };
87
+ /**
88
+ * a function that parse theme and return { css, vars }
89
+ *
90
+ * @param {Object} theme
91
+ * @param {{ prefix?: string }} options
92
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
93
+ *
94
+ * @example
95
+ * const { css, vars } = parser({
96
+ * fontSize: 12,
97
+ * lineHeight: 1.2,
98
+ * palette: { primary: { 500: '#000000' } }
99
+ * })
100
+ *
101
+ * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
102
+ * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
103
+ */
104
+
105
+
106
+ export default function cssVarsParser(obj, options) {
107
+ var _ref3 = options || {},
108
+ prefix = _ref3.prefix;
109
+
110
+ var css = {};
111
+ var vars = {};
112
+ walkObjectDeep(obj, function (keys, value) {
113
+ if (typeof value === 'string' || typeof value === 'number') {
114
+ var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
115
+
116
+ _extends(css, _defineProperty({}, cssVar, getCssValue(keys, value)));
117
+
118
+ assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"));
119
+ }
120
+ });
121
+ return {
122
+ css: css,
123
+ vars: vars
124
+ };
125
+ }
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var DEFAULT_STORAGE_KEY = 'mui-color-scheme';
4
+ export var DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
5
+ export default function getInitColorSchemeScript(options) {
6
+ var _ref = options || {},
7
+ _ref$storageKey = _ref.storageKey,
8
+ storageKey = _ref$storageKey === void 0 ? DEFAULT_STORAGE_KEY : _ref$storageKey,
9
+ _ref$attribute = _ref.attribute,
10
+ attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute;
11
+
12
+ return /*#__PURE__*/_jsx("script", {
13
+ // eslint-disable-next-line react/no-danger
14
+ dangerouslySetInnerHTML: {
15
+ __html: "(function() { try {\n var colorScheme = localStorage.getItem('".concat(storageKey, "');\n if (colorScheme) {\n document.body.setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
16
+ }
17
+ });
18
+ }
@@ -0,0 +1 @@
1
+ export { default } from './createCssVarsProvider';
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.0.1
1
+ /** @license MUI v5.0.5
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.
@@ -41,4 +41,5 @@ export { default as useThemeProps, getThemeProps } from './useThemeProps';
41
41
  export { default as useTheme } from './useTheme';
42
42
  export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
43
43
  export * from './colorManipulator';
44
- export { default as ThemeProvider } from './ThemeProvider';
44
+ export { default as ThemeProvider } from './ThemeProvider';
45
+ export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
package/legacy/spacing.js CHANGED
@@ -46,8 +46,8 @@ var getCssProperties = memoize(function (prop) {
46
46
  return property + dir;
47
47
  }) : [property + direction];
48
48
  });
49
- var marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY'];
50
- var paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY'];
49
+ var marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd'];
50
+ var paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
51
51
  var spacingKeys = [].concat(marginKeys, paddingKeys);
52
52
  export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
53
53
  var themeSpacing = getPath(theme, themeKey) || defaultValue;