@mui/system 6.0.0-alpha.1 → 6.0.0-alpha.3

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 (128) hide show
  1. package/CHANGELOG.md +114 -2
  2. package/Container/Container.d.ts +1 -1
  3. package/Stack/Stack.d.ts +1 -1
  4. package/Stack/createStack.d.ts +1 -1
  5. package/Unstable_Grid/Grid.d.ts +1 -1
  6. package/Unstable_Grid/createGrid.d.ts +1 -1
  7. package/breakpoints/breakpoints.js +19 -1
  8. package/createTheme/createTheme.d.ts +2 -1
  9. package/createTheme/createTheme.js +2 -0
  10. package/cssContainerQueries/cssContainerQueries.d.ts +24 -0
  11. package/cssContainerQueries/cssContainerQueries.js +68 -0
  12. package/cssContainerQueries/index.d.ts +3 -0
  13. package/cssContainerQueries/index.js +2 -0
  14. package/cssContainerQueries/package.json +6 -0
  15. package/cssVars/cssVarsParser.d.ts +1 -1
  16. package/index.d.ts +2 -0
  17. package/index.js +2 -1
  18. package/modern/breakpoints/breakpoints.js +19 -1
  19. package/modern/createTheme/createTheme.js +2 -0
  20. package/modern/cssContainerQueries/cssContainerQueries.js +68 -0
  21. package/modern/cssContainerQueries/index.js +2 -0
  22. package/modern/index.js +2 -1
  23. package/modern/styleFunctionSx/styleFunctionSx.js +2 -1
  24. package/node/breakpoints/breakpoints.js +19 -1
  25. package/node/createTheme/createTheme.js +2 -0
  26. package/node/cssContainerQueries/cssContainerQueries.js +79 -0
  27. package/node/cssContainerQueries/index.js +32 -0
  28. package/node/index.js +9 -1
  29. package/node/styleFunctionSx/styleFunctionSx.js +2 -1
  30. package/package.json +5 -5
  31. package/styleFunctionSx/styleFunctionSx.js +2 -1
  32. package/legacy/Box/Box.js +0 -30
  33. package/legacy/Box/boxClasses.js +0 -3
  34. package/legacy/Box/index.js +0 -5
  35. package/legacy/Container/Container.js +0 -61
  36. package/legacy/Container/ContainerProps.js +0 -1
  37. package/legacy/Container/containerClasses.js +0 -7
  38. package/legacy/Container/createContainer.js +0 -140
  39. package/legacy/Container/index.js +0 -5
  40. package/legacy/GlobalStyles/GlobalStyles.js +0 -37
  41. package/legacy/GlobalStyles/index.js +0 -4
  42. package/legacy/RtlProvider/index.js +0 -22
  43. package/legacy/Stack/Stack.js +0 -62
  44. package/legacy/Stack/StackProps.js +0 -1
  45. package/legacy/Stack/createStack.js +0 -180
  46. package/legacy/Stack/index.js +0 -7
  47. package/legacy/Stack/stackClasses.js +0 -7
  48. package/legacy/ThemeProvider/ThemeProvider.js +0 -87
  49. package/legacy/ThemeProvider/index.js +0 -3
  50. package/legacy/Unstable_Grid/Grid.js +0 -177
  51. package/legacy/Unstable_Grid/GridProps.js +0 -1
  52. package/legacy/Unstable_Grid/createGrid.js +0 -184
  53. package/legacy/Unstable_Grid/gridClasses.js +0 -28
  54. package/legacy/Unstable_Grid/gridGenerator.js +0 -216
  55. package/legacy/Unstable_Grid/index.js +0 -8
  56. package/legacy/Unstable_Grid/traverseBreakpoints.js +0 -48
  57. package/legacy/borders/borders.js +0 -51
  58. package/legacy/borders/index.js +0 -4
  59. package/legacy/breakpoints/breakpoints.js +0 -162
  60. package/legacy/breakpoints/index.js +0 -4
  61. package/legacy/colorManipulator/colorManipulator.js +0 -356
  62. package/legacy/colorManipulator/index.js +0 -3
  63. package/legacy/compose/compose.js +0 -32
  64. package/legacy/compose/index.js +0 -3
  65. package/legacy/createBox/createBox.js +0 -38
  66. package/legacy/createBox/index.js +0 -3
  67. package/legacy/createStyled/createStyled.js +0 -250
  68. package/legacy/createStyled/index.js +0 -4
  69. package/legacy/createTheme/applyStyles.js +0 -73
  70. package/legacy/createTheme/createBreakpoints.js +0 -83
  71. package/legacy/createTheme/createSpacing.js +0 -32
  72. package/legacy/createTheme/createTheme.js +0 -49
  73. package/legacy/createTheme/index.js +0 -3
  74. package/legacy/createTheme/shape.js +0 -4
  75. package/legacy/cssGrid/cssGrid.js +0 -91
  76. package/legacy/cssGrid/index.js +0 -4
  77. package/legacy/cssVars/createCssVarsProvider.js +0 -338
  78. package/legacy/cssVars/createCssVarsTheme.js +0 -13
  79. package/legacy/cssVars/createGetCssVar.js +0 -30
  80. package/legacy/cssVars/cssVarsParser.js +0 -141
  81. package/legacy/cssVars/getInitColorSchemeScript.js +0 -28
  82. package/legacy/cssVars/index.js +0 -6
  83. package/legacy/cssVars/prepareCssVars.js +0 -92
  84. package/legacy/cssVars/useCurrentColorScheme.js +0 -237
  85. package/legacy/display/display.js +0 -29
  86. package/legacy/display/index.js +0 -4
  87. package/legacy/flexbox/flexbox.js +0 -43
  88. package/legacy/flexbox/index.js +0 -4
  89. package/legacy/getThemeValue/getThemeValue.js +0 -47
  90. package/legacy/getThemeValue/index.js +0 -4
  91. package/legacy/index.js +0 -72
  92. package/legacy/memoize/index.js +0 -3
  93. package/legacy/memoize/memoize.js +0 -9
  94. package/legacy/merge/index.js +0 -3
  95. package/legacy/merge/merge.js +0 -10
  96. package/legacy/palette/index.js +0 -4
  97. package/legacy/palette/palette.js +0 -26
  98. package/legacy/positions/index.js +0 -4
  99. package/legacy/positions/positions.js +0 -22
  100. package/legacy/propsToClassKey/index.js +0 -3
  101. package/legacy/propsToClassKey/propsToClassKey.js +0 -24
  102. package/legacy/responsivePropType/index.js +0 -3
  103. package/legacy/responsivePropType/responsivePropType.js +0 -3
  104. package/legacy/shadows/index.js +0 -3
  105. package/legacy/shadows/shadows.js +0 -6
  106. package/legacy/sizing/index.js +0 -4
  107. package/legacy/sizing/sizing.js +0 -65
  108. package/legacy/spacing/index.js +0 -4
  109. package/legacy/spacing/spacing.js +0 -161
  110. package/legacy/style/index.js +0 -4
  111. package/legacy/style/style.js +0 -73
  112. package/legacy/styleFunctionSx/defaultSxConfig.js +0 -293
  113. package/legacy/styleFunctionSx/extendSxProp.js +0 -45
  114. package/legacy/styleFunctionSx/index.js +0 -4
  115. package/legacy/styleFunctionSx/styleFunctionSx.js +0 -126
  116. package/legacy/styled/index.js +0 -3
  117. package/legacy/styled/styled.js +0 -3
  118. package/legacy/typography/index.js +0 -4
  119. package/legacy/typography/typography.js +0 -37
  120. package/legacy/useMediaQuery/index.js +0 -2
  121. package/legacy/useMediaQuery/useMediaQuery.js +0 -145
  122. package/legacy/useTheme/index.js +0 -4
  123. package/legacy/useTheme/useTheme.js +0 -10
  124. package/legacy/useThemeProps/getThemeProps.js +0 -10
  125. package/legacy/useThemeProps/index.js +0 -4
  126. package/legacy/useThemeProps/useThemeProps.js +0 -20
  127. package/legacy/useThemeWithoutDefault/index.js +0 -3
  128. package/legacy/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -13
@@ -1,338 +0,0 @@
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 _typeof from "@babel/runtime/helpers/esm/typeof";
5
- import _formatMuiErrorMessage from "@mui/utils/formatMuiErrorMessage";
6
- import * as React from 'react';
7
- import PropTypes from 'prop-types';
8
- import { GlobalStyles } from '@mui/styled-engine';
9
- import { useTheme as muiUseTheme } from '@mui/private-theming';
10
- import ThemeProvider from '../ThemeProvider';
11
- import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
12
- import useCurrentColorScheme from './useCurrentColorScheme';
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
15
- export default function createCssVarsProvider(options) {
16
- var themeId = options.themeId,
17
- _options$theme = options.theme,
18
- defaultTheme = _options$theme === void 0 ? {} : _options$theme,
19
- _options$attribute = options.attribute,
20
- defaultAttribute = _options$attribute === void 0 ? DEFAULT_ATTRIBUTE : _options$attribute,
21
- _options$modeStorageK = options.modeStorageKey,
22
- defaultModeStorageKey = _options$modeStorageK === void 0 ? DEFAULT_MODE_STORAGE_KEY : _options$modeStorageK,
23
- _options$colorSchemeS = options.colorSchemeStorageKey,
24
- defaultColorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS,
25
- _options$defaultMode = options.defaultMode,
26
- designSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
27
- designSystemColorScheme = options.defaultColorScheme,
28
- _options$disableTrans = options.disableTransitionOnChange,
29
- designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
30
- resolveTheme = options.resolveTheme;
31
- 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]) {
32
- console.error("MUI: `".concat(designSystemColorScheme, "` does not exist in `theme.colorSchemes`."));
33
- }
34
- var ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
35
- if (process.env.NODE_ENV !== 'production') {
36
- ColorSchemeContext.displayName = 'ColorSchemeContext';
37
- }
38
- var useColorScheme = function useColorScheme() {
39
- var value = React.useContext(ColorSchemeContext);
40
- if (!value) {
41
- throw new Error(process.env.NODE_ENV !== "production" ? "MUI: `useColorScheme` must be called under <CssVarsProvider />" : _formatMuiErrorMessage(19));
42
- }
43
- return value;
44
- };
45
- function CssVarsProvider(props) {
46
- var _restThemeProp$genera, _theme$generateStyleS;
47
- var children = props.children,
48
- _props$theme = props.theme,
49
- themeProp = _props$theme === void 0 ? defaultTheme : _props$theme,
50
- _props$modeStorageKey = props.modeStorageKey,
51
- modeStorageKey = _props$modeStorageKey === void 0 ? defaultModeStorageKey : _props$modeStorageKey,
52
- _props$colorSchemeSto = props.colorSchemeStorageKey,
53
- colorSchemeStorageKey = _props$colorSchemeSto === void 0 ? defaultColorSchemeStorageKey : _props$colorSchemeSto,
54
- _props$attribute = props.attribute,
55
- attribute = _props$attribute === void 0 ? defaultAttribute : _props$attribute,
56
- _props$defaultMode = props.defaultMode,
57
- defaultMode = _props$defaultMode === void 0 ? designSystemMode : _props$defaultMode,
58
- _props$defaultColorSc = props.defaultColorScheme,
59
- defaultColorScheme = _props$defaultColorSc === void 0 ? designSystemColorScheme : _props$defaultColorSc,
60
- _props$disableTransit = props.disableTransitionOnChange,
61
- disableTransitionOnChange = _props$disableTransit === void 0 ? designSystemTransitionOnChange : _props$disableTransit,
62
- _props$storageWindow = props.storageWindow,
63
- storageWindow = _props$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _props$storageWindow,
64
- _props$documentNode = props.documentNode,
65
- documentNode = _props$documentNode === void 0 ? typeof document === 'undefined' ? undefined : document : _props$documentNode,
66
- _props$colorSchemeNod = props.colorSchemeNode,
67
- colorSchemeNode = _props$colorSchemeNod === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _props$colorSchemeNod,
68
- _props$colorSchemeSel = props.colorSchemeSelector,
69
- colorSchemeSelector = _props$colorSchemeSel === void 0 ? ':root' : _props$colorSchemeSel,
70
- _props$disableNestedC = props.disableNestedContext,
71
- disableNestedContext = _props$disableNestedC === void 0 ? false : _props$disableNestedC,
72
- _props$disableStyleSh = props.disableStyleSheetGeneration,
73
- disableStyleSheetGeneration = _props$disableStyleSh === void 0 ? false : _props$disableStyleSh;
74
- var hasMounted = React.useRef(false);
75
- var upperTheme = muiUseTheme();
76
- var ctx = React.useContext(ColorSchemeContext);
77
- var nested = !!ctx && !disableNestedContext;
78
- var scopedTheme = themeProp[themeId];
79
- var _ref = scopedTheme || themeProp,
80
- _ref$colorSchemes = _ref.colorSchemes,
81
- colorSchemes = _ref$colorSchemes === void 0 ? {} : _ref$colorSchemes,
82
- _ref$components = _ref.components,
83
- components = _ref$components === void 0 ? {} : _ref$components,
84
- cssVarPrefix = _ref.cssVarPrefix,
85
- restThemeProp = _objectWithoutProperties(_ref, ["colorSchemes", "components", "cssVarPrefix"]);
86
- var allColorSchemes = Object.keys(colorSchemes);
87
- var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
88
- var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
89
-
90
- // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
91
- var _useCurrentColorSchem = useCurrentColorScheme({
92
- supportedColorSchemes: allColorSchemes,
93
- defaultLightColorScheme: defaultLightColorScheme,
94
- defaultDarkColorScheme: defaultDarkColorScheme,
95
- modeStorageKey: modeStorageKey,
96
- colorSchemeStorageKey: colorSchemeStorageKey,
97
- defaultMode: defaultMode,
98
- storageWindow: storageWindow
99
- }),
100
- stateMode = _useCurrentColorSchem.mode,
101
- setMode = _useCurrentColorSchem.setMode,
102
- systemMode = _useCurrentColorSchem.systemMode,
103
- lightColorScheme = _useCurrentColorSchem.lightColorScheme,
104
- darkColorScheme = _useCurrentColorSchem.darkColorScheme,
105
- stateColorScheme = _useCurrentColorSchem.colorScheme,
106
- setColorScheme = _useCurrentColorSchem.setColorScheme;
107
- var mode = stateMode;
108
- var colorScheme = stateColorScheme;
109
- if (nested) {
110
- mode = ctx.mode;
111
- colorScheme = ctx.colorScheme;
112
- }
113
- var calculatedMode = function () {
114
- if (mode) {
115
- return mode;
116
- }
117
- // This scope occurs on the server
118
- if (defaultMode === 'system') {
119
- return designSystemMode;
120
- }
121
- return defaultMode;
122
- }();
123
- var calculatedColorScheme = function () {
124
- if (!colorScheme) {
125
- // This scope occurs on the server
126
- if (calculatedMode === 'dark') {
127
- return defaultDarkColorScheme;
128
- }
129
- // use light color scheme, if default mode is 'light' | 'system'
130
- return defaultLightColorScheme;
131
- }
132
- return colorScheme;
133
- }();
134
-
135
- // 2. get the `vars` object that refers to the CSS custom properties
136
- var themeVars = ((_restThemeProp$genera = restThemeProp.generateThemeVars) == null ? void 0 : _restThemeProp$genera.call(restThemeProp)) || restThemeProp.vars;
137
-
138
- // 3. Start composing the theme object
139
- var theme = _extends({}, restThemeProp, {
140
- components: components,
141
- colorSchemes: colorSchemes,
142
- cssVarPrefix: cssVarPrefix,
143
- vars: themeVars
144
- });
145
- if (typeof theme.generateSpacing === 'function') {
146
- theme.spacing = theme.generateSpacing();
147
- }
148
-
149
- // 4. Resolve the color scheme and merge it to the theme
150
- Object.entries(colorSchemes).forEach(function (_ref2) {
151
- var _ref3 = _slicedToArray(_ref2, 2),
152
- key = _ref3[0],
153
- scheme = _ref3[1];
154
- if (key === calculatedColorScheme) {
155
- // 4.1 Merge the selected color scheme to the theme
156
- Object.keys(scheme).forEach(function (schemeKey) {
157
- if (scheme[schemeKey] && _typeof(scheme[schemeKey]) === 'object') {
158
- // shallow merge the 1st level structure of the theme.
159
- theme[schemeKey] = _extends({}, theme[schemeKey], scheme[schemeKey]);
160
- } else {
161
- theme[schemeKey] = scheme[schemeKey];
162
- }
163
- });
164
- if (theme.palette) {
165
- theme.palette.colorScheme = key;
166
- }
167
- }
168
- });
169
- var resolvedDefaultColorScheme = function () {
170
- if (typeof defaultColorScheme === 'string') {
171
- return defaultColorScheme;
172
- }
173
- if (defaultMode === 'dark') {
174
- return defaultColorScheme.dark;
175
- }
176
- return defaultColorScheme.light;
177
- }();
178
- themeProp.defaultColorScheme = resolvedDefaultColorScheme;
179
- themeProp.colorSchemeSelector = colorSchemeSelector;
180
- themeProp.attribute = attribute;
181
- if (!theme.getColorSchemeSelector) {
182
- theme.getColorSchemeSelector = function (targetColorScheme) {
183
- return "[".concat(attribute, "=\"").concat(targetColorScheme, "\"] &");
184
- };
185
- }
186
-
187
- // 5. Declaring effects
188
- // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
189
- React.useEffect(function () {
190
- if (colorScheme && colorSchemeNode) {
191
- // attaches attribute to <html> because the css variables are attached to :root (html)
192
- colorSchemeNode.setAttribute(attribute, colorScheme);
193
- }
194
- }, [colorScheme, attribute, colorSchemeNode]);
195
-
196
- // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
197
- // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
198
- React.useEffect(function () {
199
- var timer;
200
- if (disableTransitionOnChange && hasMounted.current && documentNode) {
201
- var css = documentNode.createElement('style');
202
- css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
203
- documentNode.head.appendChild(css);
204
-
205
- // Force browser repaint
206
- (function () {
207
- return window.getComputedStyle(documentNode.body);
208
- })();
209
- timer = setTimeout(function () {
210
- documentNode.head.removeChild(css);
211
- }, 1);
212
- }
213
- return function () {
214
- clearTimeout(timer);
215
- };
216
- }, [colorScheme, disableTransitionOnChange, documentNode]);
217
- React.useEffect(function () {
218
- hasMounted.current = true;
219
- return function () {
220
- hasMounted.current = false;
221
- };
222
- }, []);
223
- var contextValue = React.useMemo(function () {
224
- return {
225
- allColorSchemes: allColorSchemes,
226
- colorScheme: colorScheme,
227
- darkColorScheme: darkColorScheme,
228
- lightColorScheme: lightColorScheme,
229
- mode: mode,
230
- setColorScheme: setColorScheme,
231
- setMode: setMode,
232
- systemMode: systemMode
233
- };
234
- }, [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode]);
235
- var shouldGenerateStyleSheet = true;
236
- if (disableStyleSheetGeneration || nested && (upperTheme == null ? void 0 : upperTheme.cssVarPrefix) === cssVarPrefix) {
237
- shouldGenerateStyleSheet = false;
238
- }
239
- var element = /*#__PURE__*/_jsxs(React.Fragment, {
240
- children: [shouldGenerateStyleSheet && /*#__PURE__*/_jsx(React.Fragment, {
241
- children: (((_theme$generateStyleS = theme.generateStyleSheets) == null ? void 0 : _theme$generateStyleS.call(theme)) || []).map(function (styles, index) {
242
- return /*#__PURE__*/_jsx(GlobalStyles, {
243
- styles: styles
244
- }, index);
245
- })
246
- }), /*#__PURE__*/_jsx(ThemeProvider, {
247
- themeId: scopedTheme ? themeId : undefined,
248
- theme: resolveTheme ? resolveTheme(theme) : theme,
249
- children: children
250
- })]
251
- });
252
- if (nested) {
253
- return element;
254
- }
255
- return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
256
- value: contextValue,
257
- children: element
258
- });
259
- }
260
- process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
261
- /**
262
- * The body attribute name to attach colorScheme.
263
- */
264
- attribute: PropTypes.string,
265
- /**
266
- * The component tree.
267
- */
268
- children: PropTypes.node,
269
- /**
270
- * The node used to attach the color-scheme attribute
271
- */
272
- colorSchemeNode: PropTypes.any,
273
- /**
274
- * The CSS selector for attaching the generated custom properties
275
- */
276
- colorSchemeSelector: PropTypes.string,
277
- /**
278
- * localStorage key used to store `colorScheme`
279
- */
280
- colorSchemeStorageKey: PropTypes.string,
281
- /**
282
- * The initial color scheme used.
283
- */
284
- defaultColorScheme: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
285
- /**
286
- * The initial mode used.
287
- */
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,
299
- /**
300
- * Disable CSS transitions when switching between modes or color schemes.
301
- */
302
- disableTransitionOnChange: PropTypes.bool,
303
- /**
304
- * The document to attach the attribute to.
305
- */
306
- documentNode: PropTypes.any,
307
- /**
308
- * The key in the local storage used to store current color scheme.
309
- */
310
- modeStorageKey: PropTypes.string,
311
- /**
312
- * The window that attaches the 'storage' event listener.
313
- * @default window
314
- */
315
- storageWindow: PropTypes.any,
316
- /**
317
- * The calculated theme object that will be passed through context.
318
- */
319
- theme: PropTypes.object
320
- } : void 0;
321
- var defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
322
- var defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
323
- var getInitColorSchemeScript = function getInitColorSchemeScript(params) {
324
- return systemGetInitColorSchemeScript(_extends({
325
- attribute: defaultAttribute,
326
- colorSchemeStorageKey: defaultColorSchemeStorageKey,
327
- defaultMode: designSystemMode,
328
- defaultLightColorScheme: defaultLightColorScheme,
329
- defaultDarkColorScheme: defaultDarkColorScheme,
330
- modeStorageKey: defaultModeStorageKey
331
- }, params));
332
- };
333
- return {
334
- CssVarsProvider: CssVarsProvider,
335
- useColorScheme: useColorScheme,
336
- getInitColorSchemeScript: getInitColorSchemeScript
337
- };
338
- }
@@ -1,13 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import prepareCssVars from './prepareCssVars';
3
- function createCssVarsTheme(theme) {
4
- var output = theme;
5
- var result = prepareCssVars(output, _extends({}, theme, {
6
- prefix: theme.cssVarPrefix
7
- }));
8
- output.vars = result.vars;
9
- output.generateThemeVars = result.generateThemeVars;
10
- output.generateStyleSheets = result.generateStyleSheets;
11
- return output;
12
- }
13
- export default createCssVarsTheme;
@@ -1,30 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- /**
3
- * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
4
- * and they does not need to remember the prefix (defined once).
5
- */
6
- export default function createGetCssVar() {
7
- var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
8
- function appendVar() {
9
- for (var _len = arguments.length, vars = new Array(_len), _key = 0; _key < _len; _key++) {
10
- vars[_key] = arguments[_key];
11
- }
12
- if (!vars.length) {
13
- return '';
14
- }
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))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
17
- return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(value).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
18
- }
19
- return ", ".concat(value);
20
- }
21
-
22
- // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
23
- var getCssVar = function getCssVar(field) {
24
- for (var _len2 = arguments.length, fallbacks = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
25
- fallbacks[_key2 - 1] = arguments[_key2];
26
- }
27
- return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, fallbacks), ")");
28
- };
29
- return getCssVar;
30
- }
@@ -1,141 +0,0 @@
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
- * This function create an object from keys, value and then assign to target
8
- *
9
- * @param {Object} obj : the target object to be assigned
10
- * @param {string[]} keys
11
- * @param {string | number} value
12
- *
13
- * @example
14
- * const source = {}
15
- * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
16
- * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
17
- *
18
- * @example
19
- * const source = { palette: { primary: 'var(--palette-primary)' } }
20
- * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
21
- * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
22
- */
23
- export var assignNestedKeys = function assignNestedKeys(obj, keys, value) {
24
- var arrayKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
25
- var temp = obj;
26
- keys.forEach(function (k, index) {
27
- if (index === keys.length - 1) {
28
- if (Array.isArray(temp)) {
29
- temp[Number(k)] = value;
30
- } else if (temp && _typeof(temp) === 'object') {
31
- temp[k] = value;
32
- }
33
- } else if (temp && _typeof(temp) === 'object') {
34
- if (!temp[k]) {
35
- temp[k] = arrayKeys.includes(k) ? [] : {};
36
- }
37
- temp = temp[k];
38
- }
39
- });
40
- };
41
-
42
- /**
43
- *
44
- * @param {Object} obj : source object
45
- * @param {Function} callback : a function that will be called when
46
- * - the deepest key in source object is reached
47
- * - the value of the deepest key is NOT `undefined` | `null`
48
- *
49
- * @example
50
- * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
51
- * // ['palette', 'primary', 'main'] '#000000'
52
- */
53
- export var walkObjectDeep = function walkObjectDeep(obj, callback, shouldSkipPaths) {
54
- function recurse(object) {
55
- var parentKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
56
- var arrayKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
57
- Object.entries(object).forEach(function (_ref) {
58
- var _ref2 = _slicedToArray(_ref, 2),
59
- key = _ref2[0],
60
- value = _ref2[1];
61
- if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([].concat(_toConsumableArray(parentKeys), [key]))) {
62
- if (value !== undefined && value !== null) {
63
- if (_typeof(value) === 'object' && Object.keys(value).length > 0) {
64
- recurse(value, [].concat(_toConsumableArray(parentKeys), [key]), Array.isArray(value) ? [].concat(_toConsumableArray(arrayKeys), [key]) : arrayKeys);
65
- } else {
66
- callback([].concat(_toConsumableArray(parentKeys), [key]), value, arrayKeys);
67
- }
68
- }
69
- }
70
- });
71
- }
72
- recurse(obj);
73
- };
74
- var getCssValue = function getCssValue(keys, value) {
75
- if (typeof value === 'number') {
76
- if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(function (prop) {
77
- return keys.includes(prop);
78
- })) {
79
- // CSS property that are unitless
80
- return value;
81
- }
82
- var lastKey = keys[keys.length - 1];
83
- if (lastKey.toLowerCase().indexOf('opacity') >= 0) {
84
- // opacity values are unitless
85
- return value;
86
- }
87
- return "".concat(value, "px");
88
- }
89
- return value;
90
- };
91
-
92
- /**
93
- * a function that parse theme and return { css, vars }
94
- *
95
- * @param {Object} theme
96
- * @param {{
97
- * prefix?: string,
98
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
99
- * }} options.
100
- * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
101
- *
102
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
103
- *
104
- * @example
105
- * const { css, vars } = parser({
106
- * fontSize: 12,
107
- * lineHeight: 1.2,
108
- * palette: { primary: { 500: 'var(--color)' } }
109
- * }, { prefix: 'foo' })
110
- *
111
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
112
- * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
113
- */
114
- export default function cssVarsParser(theme, options) {
115
- var _ref3 = options || {},
116
- prefix = _ref3.prefix,
117
- shouldSkipGeneratingVar = _ref3.shouldSkipGeneratingVar;
118
- var css = {};
119
- var vars = {};
120
- var varsWithDefaults = {};
121
- walkObjectDeep(theme, function (keys, value, arrayKeys) {
122
- if (typeof value === 'string' || typeof value === 'number') {
123
- if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
124
- // only create css & var if `shouldSkipGeneratingVar` return false
125
- var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
126
- var resolvedValue = getCssValue(keys, value);
127
- _extends(css, _defineProperty({}, cssVar, resolvedValue));
128
- assignNestedKeys(vars, keys, "var(".concat(cssVar, ")"), arrayKeys);
129
- assignNestedKeys(varsWithDefaults, keys, "var(".concat(cssVar, ", ").concat(resolvedValue, ")"), arrayKeys);
130
- }
131
- }
132
- }, function (keys) {
133
- return keys[0] === 'vars';
134
- } // skip 'vars/*' paths
135
- );
136
- return {
137
- css: css,
138
- vars: vars,
139
- varsWithDefaults: varsWithDefaults
140
- };
141
- }
@@ -1,28 +0,0 @@
1
- import * as React from 'react';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- export var DEFAULT_MODE_STORAGE_KEY = 'mode';
4
- export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
5
- export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
6
- export default function getInitColorSchemeScript(options) {
7
- var _ref = options || {},
8
- _ref$defaultMode = _ref.defaultMode,
9
- defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
10
- _ref$defaultLightColo = _ref.defaultLightColorScheme,
11
- defaultLightColorScheme = _ref$defaultLightColo === void 0 ? 'light' : _ref$defaultLightColo,
12
- _ref$defaultDarkColor = _ref.defaultDarkColorScheme,
13
- defaultDarkColorScheme = _ref$defaultDarkColor === void 0 ? 'dark' : _ref$defaultDarkColor,
14
- _ref$modeStorageKey = _ref.modeStorageKey,
15
- modeStorageKey = _ref$modeStorageKey === void 0 ? DEFAULT_MODE_STORAGE_KEY : _ref$modeStorageKey,
16
- _ref$colorSchemeStora = _ref.colorSchemeStorageKey,
17
- colorSchemeStorageKey = _ref$colorSchemeStora === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _ref$colorSchemeStora,
18
- _ref$attribute = _ref.attribute,
19
- attribute = _ref$attribute === void 0 ? DEFAULT_ATTRIBUTE : _ref$attribute,
20
- _ref$colorSchemeNode = _ref.colorSchemeNode,
21
- colorSchemeNode = _ref$colorSchemeNode === void 0 ? 'document.documentElement' : _ref$colorSchemeNode;
22
- return /*#__PURE__*/_jsx("script", {
23
- // eslint-disable-next-line react/no-danger
24
- dangerouslySetInnerHTML: {
25
- __html: "(function() {\ntry {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var colorScheme = '';\n if (mode === 'system') {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n} catch(e){}})();")
26
- }
27
- }, "mui-color-scheme-init");
28
- }
@@ -1,6 +0,0 @@
1
- 'use client';
2
-
3
- export { default } from './createCssVarsProvider';
4
- export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
5
- export { default as prepareCssVars } from './prepareCssVars';
6
- export { default as createCssVarsTheme } from './createCssVarsTheme';
@@ -1,92 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
5
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
- import deepmerge from '@mui/utils/deepmerge';
7
- import cssVarsParser from './cssVarsParser';
8
- function prepareCssVars(theme) {
9
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
- var getSelector = _ref.getSelector,
11
- parserConfig = _objectWithoutProperties(_ref, ["getSelector"]);
12
- // @ts-ignore - ignore components do not exist
13
- var _theme$colorSchemes = theme.colorSchemes,
14
- colorSchemes = _theme$colorSchemes === void 0 ? {} : _theme$colorSchemes,
15
- components = theme.components,
16
- _theme$defaultColorSc = theme.defaultColorScheme,
17
- defaultColorScheme = _theme$defaultColorSc === void 0 ? 'light' : _theme$defaultColorSc,
18
- otherTheme = _objectWithoutProperties(theme, ["colorSchemes", "components", "defaultColorScheme"]);
19
- var _cssVarsParser = cssVarsParser(otherTheme, parserConfig),
20
- rootVars = _cssVarsParser.vars,
21
- rootCss = _cssVarsParser.css,
22
- rootVarsWithDefaults = _cssVarsParser.varsWithDefaults;
23
- var themeVars = rootVarsWithDefaults;
24
- var colorSchemesMap = {};
25
- var defaultScheme = colorSchemes[defaultColorScheme],
26
- otherColorSchemes = _objectWithoutProperties(colorSchemes, [defaultColorScheme].map(_toPropertyKey));
27
- Object.entries(otherColorSchemes || {}).forEach(function (_ref2) {
28
- var _ref3 = _slicedToArray(_ref2, 2),
29
- key = _ref3[0],
30
- scheme = _ref3[1];
31
- var _cssVarsParser2 = cssVarsParser(scheme, parserConfig),
32
- vars = _cssVarsParser2.vars,
33
- css = _cssVarsParser2.css,
34
- varsWithDefaults = _cssVarsParser2.varsWithDefaults;
35
- themeVars = deepmerge(themeVars, varsWithDefaults);
36
- colorSchemesMap[key] = {
37
- css: css,
38
- vars: vars
39
- };
40
- });
41
- if (defaultScheme) {
42
- // default color scheme vars should be merged last to set as default
43
- var _cssVarsParser3 = cssVarsParser(defaultScheme, parserConfig),
44
- _css = _cssVarsParser3.css,
45
- vars = _cssVarsParser3.vars,
46
- varsWithDefaults = _cssVarsParser3.varsWithDefaults;
47
- themeVars = deepmerge(themeVars, varsWithDefaults);
48
- colorSchemesMap[defaultColorScheme] = {
49
- css: _css,
50
- vars: vars
51
- };
52
- }
53
- var generateThemeVars = function generateThemeVars() {
54
- var vars = _extends({}, rootVars);
55
- Object.entries(colorSchemesMap).forEach(function (_ref4) {
56
- var _ref5 = _slicedToArray(_ref4, 2),
57
- schemeVars = _ref5[1].vars;
58
- vars = deepmerge(vars, schemeVars);
59
- });
60
- return vars;
61
- };
62
- var generateStyleSheets = function generateStyleSheets() {
63
- var stylesheets = [];
64
- var colorScheme = theme.defaultColorScheme || 'light';
65
- function insertStyleSheet(selector, css) {
66
- if (Object.keys(css).length) {
67
- stylesheets.push(typeof selector === 'string' ? _defineProperty({}, selector, _extends({}, css)) : selector);
68
- }
69
- }
70
- insertStyleSheet((getSelector == null ? void 0 : getSelector(undefined, _extends({}, rootCss))) || ':root', rootCss);
71
- var defaultSchemeVal = colorSchemesMap[colorScheme],
72
- rest = _objectWithoutProperties(colorSchemesMap, [colorScheme].map(_toPropertyKey));
73
- if (defaultSchemeVal) {
74
- // default color scheme has to come before other color schemes
75
- var _css2 = defaultSchemeVal.css;
76
- insertStyleSheet((getSelector == null ? void 0 : getSelector(colorScheme, _extends({}, _css2))) || "[".concat(theme.attribute || 'data-color-scheme', "=\"").concat(colorScheme, "\"]"), _css2);
77
- }
78
- Object.entries(rest).forEach(function (_ref7) {
79
- var _ref8 = _slicedToArray(_ref7, 2),
80
- key = _ref8[0],
81
- css = _ref8[1].css;
82
- insertStyleSheet((getSelector == null ? void 0 : getSelector(key, _extends({}, css))) || "[".concat(theme.attribute || 'data-color-scheme', "=\"").concat(key, "\"]"), css);
83
- });
84
- return stylesheets;
85
- };
86
- return {
87
- vars: themeVars,
88
- generateThemeVars: generateThemeVars,
89
- generateStyleSheets: generateStyleSheets
90
- };
91
- }
92
- export default prepareCssVars;