@mui/system 7.0.0 → 7.0.2

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 (130) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/cssVars/cssVarsParser.d.ts +1 -1
  3. package/esm/cssVars/cssVarsParser.d.ts +1 -1
  4. package/esm/index.js +1 -1
  5. package/esm/memoTheme.d.ts +1 -1
  6. package/esm/useThemeProps/getThemeProps.d.ts +0 -5
  7. package/esm/version/index.js +2 -2
  8. package/index.js +1 -1
  9. package/memoTheme.d.ts +1 -1
  10. package/modern/cssVars/cssVarsParser.d.ts +1 -1
  11. package/modern/memoTheme.d.ts +1 -1
  12. package/modern/useThemeProps/getThemeProps.d.ts +0 -5
  13. package/package.json +6 -14
  14. package/useThemeProps/getThemeProps.d.ts +0 -5
  15. package/version/index.js +2 -2
  16. package/modern/Box/Box.js +0 -30
  17. package/modern/Box/boxClasses.js +0 -3
  18. package/modern/Box/index.js +0 -3
  19. package/modern/Container/Container.js +0 -61
  20. package/modern/Container/ContainerProps.js +0 -1
  21. package/modern/Container/containerClasses.js +0 -7
  22. package/modern/Container/createContainer.js +0 -149
  23. package/modern/Container/index.js +0 -3
  24. package/modern/DefaultPropsProvider/DefaultPropsProvider.js +0 -64
  25. package/modern/DefaultPropsProvider/index.js +0 -1
  26. package/modern/GlobalStyles/GlobalStyles.js +0 -37
  27. package/modern/GlobalStyles/index.js +0 -2
  28. package/modern/Grid/Grid.js +0 -106
  29. package/modern/Grid/GridProps.js +0 -1
  30. package/modern/Grid/createGrid.js +0 -155
  31. package/modern/Grid/deleteLegacyGridProps.js +0 -41
  32. package/modern/Grid/gridClasses.js +0 -19
  33. package/modern/Grid/gridGenerator.js +0 -193
  34. package/modern/Grid/index.js +0 -7
  35. package/modern/Grid/traverseBreakpoints.js +0 -42
  36. package/modern/InitColorSchemeScript/InitColorSchemeScript.js +0 -78
  37. package/modern/InitColorSchemeScript/index.js +0 -1
  38. package/modern/RtlProvider/index.js +0 -24
  39. package/modern/Stack/Stack.js +0 -62
  40. package/modern/Stack/StackProps.js +0 -1
  41. package/modern/Stack/createStack.js +0 -173
  42. package/modern/Stack/index.js +0 -5
  43. package/modern/Stack/stackClasses.js +0 -7
  44. package/modern/ThemeProvider/ThemeProvider.js +0 -97
  45. package/modern/ThemeProvider/index.js +0 -1
  46. package/modern/borders/borders.js +0 -49
  47. package/modern/borders/index.js +0 -2
  48. package/modern/breakpoints/breakpoints.js +0 -171
  49. package/modern/breakpoints/index.js +0 -2
  50. package/modern/colorManipulator/colorManipulator.js +0 -349
  51. package/modern/colorManipulator/index.js +0 -1
  52. package/modern/compose/compose.js +0 -24
  53. package/modern/compose/index.js +0 -1
  54. package/modern/createBox/createBox.js +0 -35
  55. package/modern/createBox/index.js +0 -1
  56. package/modern/createBreakpoints/createBreakpoints.js +0 -81
  57. package/modern/createBreakpoints/index.js +0 -3
  58. package/modern/createStyled/createStyled.js +0 -276
  59. package/modern/createStyled/index.js +0 -2
  60. package/modern/createTheme/applyStyles.js +0 -87
  61. package/modern/createTheme/createSpacing.js +0 -31
  62. package/modern/createTheme/createTheme.js +0 -49
  63. package/modern/createTheme/index.js +0 -3
  64. package/modern/createTheme/shape.js +0 -4
  65. package/modern/cssContainerQueries/cssContainerQueries.js +0 -69
  66. package/modern/cssContainerQueries/index.js +0 -2
  67. package/modern/cssGrid/cssGrid.js +0 -85
  68. package/modern/cssGrid/index.js +0 -2
  69. package/modern/cssVars/createCssVarsProvider.js +0 -338
  70. package/modern/cssVars/createCssVarsTheme.js +0 -21
  71. package/modern/cssVars/createGetCssVar.js +0 -22
  72. package/modern/cssVars/cssVarsParser.js +0 -129
  73. package/modern/cssVars/getColorSchemeSelector.js +0 -26
  74. package/modern/cssVars/index.js +0 -5
  75. package/modern/cssVars/localStorageManager.js +0 -51
  76. package/modern/cssVars/prepareCssVars.js +0 -153
  77. package/modern/cssVars/prepareTypographyVars.js +0 -11
  78. package/modern/cssVars/useCurrentColorScheme.js +0 -228
  79. package/modern/display/display.js +0 -27
  80. package/modern/display/index.js +0 -2
  81. package/modern/flexbox/flexbox.js +0 -43
  82. package/modern/flexbox/index.js +0 -2
  83. package/modern/getThemeValue/getThemeValue.js +0 -51
  84. package/modern/getThemeValue/index.js +0 -2
  85. package/modern/index.js +0 -75
  86. package/modern/memoTheme.js +0 -28
  87. package/modern/memoize/index.js +0 -1
  88. package/modern/memoize/memoize.js +0 -9
  89. package/modern/merge/index.js +0 -1
  90. package/modern/merge/merge.js +0 -10
  91. package/modern/package.json +0 -1
  92. package/modern/palette/index.js +0 -2
  93. package/modern/palette/palette.js +0 -26
  94. package/modern/positions/index.js +0 -2
  95. package/modern/positions/positions.js +0 -22
  96. package/modern/preprocessStyles.js +0 -25
  97. package/modern/propsToClassKey/index.js +0 -1
  98. package/modern/propsToClassKey/propsToClassKey.js +0 -25
  99. package/modern/responsivePropType/index.js +0 -1
  100. package/modern/responsivePropType/responsivePropType.js +0 -3
  101. package/modern/shadows/index.js +0 -1
  102. package/modern/shadows/shadows.js +0 -6
  103. package/modern/sizing/index.js +0 -2
  104. package/modern/sizing/sizing.js +0 -64
  105. package/modern/spacing/index.js +0 -2
  106. package/modern/spacing/spacing.js +0 -157
  107. package/modern/style/index.js +0 -2
  108. package/modern/style/style.js +0 -75
  109. package/modern/styleFunctionSx/AliasesCSSProperties.js +0 -1
  110. package/modern/styleFunctionSx/OverwriteCSSProperties.js +0 -1
  111. package/modern/styleFunctionSx/StandardCssProperties.js +0 -1
  112. package/modern/styleFunctionSx/defaultSxConfig.js +0 -294
  113. package/modern/styleFunctionSx/extendSxProp.js +0 -51
  114. package/modern/styleFunctionSx/index.js +0 -4
  115. package/modern/styleFunctionSx/styleFunctionSx.js +0 -127
  116. package/modern/styled/index.js +0 -1
  117. package/modern/styled/styled.js +0 -3
  118. package/modern/typography/index.js +0 -2
  119. package/modern/typography/typography.js +0 -37
  120. package/modern/useMediaQuery/index.js +0 -2
  121. package/modern/useMediaQuery/useMediaQuery.js +0 -118
  122. package/modern/useTheme/index.js +0 -2
  123. package/modern/useTheme/useTheme.js +0 -9
  124. package/modern/useThemeProps/getThemeProps.js +0 -12
  125. package/modern/useThemeProps/index.js +0 -2
  126. package/modern/useThemeProps/useThemeProps.js +0 -20
  127. package/modern/useThemeWithoutDefault/index.js +0 -1
  128. package/modern/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -12
  129. package/modern/version/index.js +0 -6
  130. package/tsconfig.build.tsbuildinfo +0 -1
@@ -1,338 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import PropTypes from 'prop-types';
5
- import { GlobalStyles } from '@mui/styled-engine';
6
- import { useTheme as muiUseTheme } from '@mui/private-theming';
7
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
8
- import ThemeProvider from "../ThemeProvider/index.js";
9
- import InitColorSchemeScript, { DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from "../InitColorSchemeScript/InitColorSchemeScript.js";
10
- import useCurrentColorScheme from "./useCurrentColorScheme.js";
11
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
- export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
13
- export default function createCssVarsProvider(options) {
14
- const {
15
- themeId,
16
- /**
17
- * This `theme` object needs to follow a certain structure to
18
- * be used correctly by the finel `CssVarsProvider`. It should have a
19
- * `colorSchemes` key with the light and dark (and any other) palette.
20
- * It should also ideally have a vars object created using `prepareCssVars`.
21
- */
22
- theme: defaultTheme = {},
23
- modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
24
- colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
25
- disableTransitionOnChange: designSystemTransitionOnChange = false,
26
- defaultColorScheme,
27
- resolveTheme
28
- } = options;
29
- const defaultContext = {
30
- allColorSchemes: [],
31
- colorScheme: undefined,
32
- darkColorScheme: undefined,
33
- lightColorScheme: undefined,
34
- mode: undefined,
35
- setColorScheme: () => {},
36
- setMode: () => {},
37
- systemMode: undefined
38
- };
39
- const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
40
- if (process.env.NODE_ENV !== 'production') {
41
- ColorSchemeContext.displayName = 'ColorSchemeContext';
42
- }
43
- const useColorScheme = () => React.useContext(ColorSchemeContext) || defaultContext;
44
- const defaultColorSchemes = {};
45
- const defaultComponents = {};
46
- function CssVarsProvider(props) {
47
- const {
48
- children,
49
- theme: themeProp,
50
- modeStorageKey = defaultModeStorageKey,
51
- colorSchemeStorageKey = defaultColorSchemeStorageKey,
52
- disableTransitionOnChange = designSystemTransitionOnChange,
53
- storageManager,
54
- storageWindow = typeof window === 'undefined' ? undefined : window,
55
- documentNode = typeof document === 'undefined' ? undefined : document,
56
- colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
57
- disableNestedContext = false,
58
- disableStyleSheetGeneration = false,
59
- defaultMode: initialMode = 'system',
60
- forceThemeRerender = false,
61
- noSsr
62
- } = props;
63
- const hasMounted = React.useRef(false);
64
- const upperTheme = muiUseTheme();
65
- const ctx = React.useContext(ColorSchemeContext);
66
- const nested = !!ctx && !disableNestedContext;
67
- const initialTheme = React.useMemo(() => {
68
- if (themeProp) {
69
- return themeProp;
70
- }
71
- return typeof defaultTheme === 'function' ? defaultTheme() : defaultTheme;
72
- }, [themeProp]);
73
- const scopedTheme = initialTheme[themeId];
74
- const restThemeProp = scopedTheme || initialTheme;
75
- const {
76
- colorSchemes = defaultColorSchemes,
77
- components = defaultComponents,
78
- cssVarPrefix
79
- } = restThemeProp;
80
- const joinedColorSchemes = Object.keys(colorSchemes).filter(k => !!colorSchemes[k]).join(',');
81
- const allColorSchemes = React.useMemo(() => joinedColorSchemes.split(','), [joinedColorSchemes]);
82
- const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
83
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
84
- const defaultMode = colorSchemes[defaultLightColorScheme] && colorSchemes[defaultDarkColorScheme] ? initialMode : colorSchemes[restThemeProp.defaultColorScheme]?.palette?.mode || restThemeProp.palette?.mode;
85
-
86
- // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
87
- const {
88
- mode: stateMode,
89
- setMode,
90
- systemMode,
91
- lightColorScheme,
92
- darkColorScheme,
93
- colorScheme: stateColorScheme,
94
- setColorScheme
95
- } = useCurrentColorScheme({
96
- supportedColorSchemes: allColorSchemes,
97
- defaultLightColorScheme,
98
- defaultDarkColorScheme,
99
- modeStorageKey,
100
- colorSchemeStorageKey,
101
- defaultMode,
102
- storageManager,
103
- storageWindow,
104
- noSsr
105
- });
106
- let mode = stateMode;
107
- let colorScheme = stateColorScheme;
108
- if (nested) {
109
- mode = ctx.mode;
110
- colorScheme = ctx.colorScheme;
111
- }
112
- if (process.env.NODE_ENV !== 'production') {
113
- if (forceThemeRerender && !restThemeProp.vars) {
114
- console.warn(['MUI: The `forceThemeRerender` prop should only be used with CSS theme variables.', 'Note that it will slow down the app when changing between modes, so only do this when you cannot find a better solution.'].join('\n'));
115
- }
116
- }
117
-
118
- // `colorScheme` is undefined on the server and hydration phase
119
- let calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
120
- if (restThemeProp.vars && !forceThemeRerender) {
121
- calculatedColorScheme = restThemeProp.defaultColorScheme;
122
- }
123
- const memoTheme = React.useMemo(() => {
124
- // 2. get the `vars` object that refers to the CSS custom properties
125
- const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
126
-
127
- // 3. Start composing the theme object
128
- const theme = {
129
- ...restThemeProp,
130
- components,
131
- colorSchemes,
132
- cssVarPrefix,
133
- vars: themeVars
134
- };
135
- if (typeof theme.generateSpacing === 'function') {
136
- theme.spacing = theme.generateSpacing();
137
- }
138
-
139
- // 4. Resolve the color scheme and merge it to the theme
140
- if (calculatedColorScheme) {
141
- const scheme = colorSchemes[calculatedColorScheme];
142
- if (scheme && typeof scheme === 'object') {
143
- // 4.1 Merge the selected color scheme to the theme
144
- Object.keys(scheme).forEach(schemeKey => {
145
- if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
146
- // shallow merge the 1st level structure of the theme.
147
- theme[schemeKey] = {
148
- ...theme[schemeKey],
149
- ...scheme[schemeKey]
150
- };
151
- } else {
152
- theme[schemeKey] = scheme[schemeKey];
153
- }
154
- });
155
- }
156
- }
157
- return resolveTheme ? resolveTheme(theme) : theme;
158
- }, [restThemeProp, calculatedColorScheme, components, colorSchemes, cssVarPrefix]);
159
-
160
- // 5. Declaring effects
161
- // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
162
- const colorSchemeSelector = restThemeProp.colorSchemeSelector;
163
- useEnhancedEffect(() => {
164
- if (colorScheme && colorSchemeNode && colorSchemeSelector && colorSchemeSelector !== 'media') {
165
- const selector = colorSchemeSelector;
166
- let rule = colorSchemeSelector;
167
- if (selector === 'class') {
168
- rule = `.%s`;
169
- }
170
- if (selector === 'data') {
171
- rule = `[data-%s]`;
172
- }
173
- if (selector?.startsWith('data-') && !selector.includes('%s')) {
174
- // 'data-mui-color-scheme' -> '[data-mui-color-scheme="%s"]'
175
- rule = `[${selector}="%s"]`;
176
- }
177
- if (rule.startsWith('.')) {
178
- colorSchemeNode.classList.remove(...allColorSchemes.map(scheme => rule.substring(1).replace('%s', scheme)));
179
- colorSchemeNode.classList.add(rule.substring(1).replace('%s', colorScheme));
180
- } else {
181
- const matches = rule.replace('%s', colorScheme).match(/\[([^\]]+)\]/);
182
- if (matches) {
183
- const [attr, value] = matches[1].split('=');
184
- if (!value) {
185
- // for attributes like `data-theme-dark`, `data-theme-light`
186
- // remove all the existing data attributes before setting the new one
187
- allColorSchemes.forEach(scheme => {
188
- colorSchemeNode.removeAttribute(attr.replace(colorScheme, scheme));
189
- });
190
- }
191
- colorSchemeNode.setAttribute(attr, value ? value.replace(/"|'/g, '') : '');
192
- } else {
193
- colorSchemeNode.setAttribute(rule, colorScheme);
194
- }
195
- }
196
- }
197
- }, [colorScheme, colorSchemeSelector, colorSchemeNode, allColorSchemes]);
198
-
199
- // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
200
- // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
201
- React.useEffect(() => {
202
- let timer;
203
- if (disableTransitionOnChange && hasMounted.current && documentNode) {
204
- const css = documentNode.createElement('style');
205
- css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
206
- documentNode.head.appendChild(css);
207
-
208
- // Force browser repaint
209
- (() => window.getComputedStyle(documentNode.body))();
210
- timer = setTimeout(() => {
211
- documentNode.head.removeChild(css);
212
- }, 1);
213
- }
214
- return () => {
215
- clearTimeout(timer);
216
- };
217
- }, [colorScheme, disableTransitionOnChange, documentNode]);
218
- React.useEffect(() => {
219
- hasMounted.current = true;
220
- return () => {
221
- hasMounted.current = false;
222
- };
223
- }, []);
224
- const contextValue = React.useMemo(() => ({
225
- allColorSchemes,
226
- colorScheme,
227
- darkColorScheme,
228
- lightColorScheme,
229
- mode,
230
- setColorScheme,
231
- setMode: process.env.NODE_ENV === 'production' ? setMode : newMode => {
232
- if (memoTheme.colorSchemeSelector === 'media') {
233
- console.error(['MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).', 'To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.', 'To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually'].join('\n'));
234
- }
235
- setMode(newMode);
236
- },
237
- systemMode
238
- }), [allColorSchemes, colorScheme, darkColorScheme, lightColorScheme, mode, setColorScheme, setMode, systemMode, memoTheme.colorSchemeSelector]);
239
- let shouldGenerateStyleSheet = true;
240
- if (disableStyleSheetGeneration || restThemeProp.cssVariables === false || nested && upperTheme?.cssVarPrefix === cssVarPrefix) {
241
- shouldGenerateStyleSheet = false;
242
- }
243
- const element = /*#__PURE__*/_jsxs(React.Fragment, {
244
- children: [/*#__PURE__*/_jsx(ThemeProvider, {
245
- themeId: scopedTheme ? themeId : undefined,
246
- theme: memoTheme,
247
- children: children
248
- }), shouldGenerateStyleSheet && /*#__PURE__*/_jsx(GlobalStyles, {
249
- styles: memoTheme.generateStyleSheets?.() || []
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 component tree.
263
- */
264
- children: PropTypes.node,
265
- /**
266
- * The node used to attach the color-scheme attribute
267
- */
268
- colorSchemeNode: PropTypes.any,
269
- /**
270
- * localStorage key used to store `colorScheme`
271
- */
272
- colorSchemeStorageKey: PropTypes.string,
273
- /**
274
- * The default mode when the storage is empty,
275
- * require the theme to have `colorSchemes` with light and dark.
276
- */
277
- defaultMode: PropTypes.string,
278
- /**
279
- * If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
280
- */
281
- disableNestedContext: PropTypes.bool,
282
- /**
283
- * If `true`, the style sheet won't be generated.
284
- *
285
- * This is useful for controlling nested CssVarsProvider behavior.
286
- */
287
- disableStyleSheetGeneration: PropTypes.bool,
288
- /**
289
- * Disable CSS transitions when switching between modes or color schemes.
290
- */
291
- disableTransitionOnChange: PropTypes.bool,
292
- /**
293
- * The document to attach the attribute to.
294
- */
295
- documentNode: PropTypes.any,
296
- /**
297
- * If `true`, theme values are recalculated when the mode changes.
298
- */
299
- forceThemeRerender: PropTypes.bool,
300
- /**
301
- * The key in the local storage used to store current color scheme.
302
- */
303
- modeStorageKey: PropTypes.string,
304
- /**
305
- * If `true`, the mode will be the same value as the storage without an extra rerendering after the hydration.
306
- * You should use this option in conjuction with `InitColorSchemeScript` component.
307
- */
308
- noSsr: PropTypes.bool,
309
- /**
310
- * The storage manager to be used for storing the mode and color scheme
311
- * @default using `window.localStorage`
312
- */
313
- storageManager: PropTypes.func,
314
- /**
315
- * The window that attaches the 'storage' event listener.
316
- * @default window
317
- */
318
- storageWindow: PropTypes.any,
319
- /**
320
- * The calculated theme object that will be passed through context.
321
- */
322
- theme: PropTypes.object
323
- } : void 0;
324
- const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
325
- const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
326
- const getInitColorSchemeScript = params => InitColorSchemeScript({
327
- colorSchemeStorageKey: defaultColorSchemeStorageKey,
328
- defaultLightColorScheme,
329
- defaultDarkColorScheme,
330
- modeStorageKey: defaultModeStorageKey,
331
- ...params
332
- });
333
- return {
334
- CssVarsProvider,
335
- useColorScheme,
336
- getInitColorSchemeScript
337
- };
338
- }
@@ -1,21 +0,0 @@
1
- import prepareCssVars from "./prepareCssVars.js";
2
- import { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
3
- import { DEFAULT_ATTRIBUTE } from "../InitColorSchemeScript/InitColorSchemeScript.js";
4
- function createCssVarsTheme({
5
- colorSchemeSelector = `[${DEFAULT_ATTRIBUTE}="%s"]`,
6
- ...theme
7
- }) {
8
- const output = theme;
9
- const result = prepareCssVars(output, {
10
- ...theme,
11
- prefix: theme.cssVarPrefix,
12
- colorSchemeSelector
13
- });
14
- output.vars = result.vars;
15
- output.generateThemeVars = result.generateThemeVars;
16
- output.generateStyleSheets = result.generateStyleSheets;
17
- output.colorSchemeSelector = colorSchemeSelector;
18
- output.getColorSchemeSelector = createGetColorSchemeSelector(colorSchemeSelector);
19
- return output;
20
- }
21
- export default createCssVarsTheme;
@@ -1,22 +0,0 @@
1
- /**
2
- * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
- * and they does not need to remember the prefix (defined once).
4
- */
5
- export default function createGetCssVar(prefix = '') {
6
- function appendVar(...vars) {
7
- if (!vars.length) {
8
- return '';
9
- }
10
- const value = vars[0];
11
- if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
12
- return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
13
- }
14
- return `, ${value}`;
15
- }
16
-
17
- // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
18
- const getCssVar = (field, ...fallbacks) => {
19
- return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
20
- };
21
- return getCssVar;
22
- }
@@ -1,129 +0,0 @@
1
- /**
2
- * This function create an object from keys, value and then assign to target
3
- *
4
- * @param {Object} obj : the target object to be assigned
5
- * @param {string[]} keys
6
- * @param {string | number} value
7
- *
8
- * @example
9
- * const source = {}
10
- * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
11
- * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
12
- *
13
- * @example
14
- * const source = { palette: { primary: 'var(--palette-primary)' } }
15
- * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
16
- * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
17
- */
18
- export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
19
- let temp = obj;
20
- keys.forEach((k, index) => {
21
- if (index === keys.length - 1) {
22
- if (Array.isArray(temp)) {
23
- temp[Number(k)] = value;
24
- } else if (temp && typeof temp === 'object') {
25
- temp[k] = value;
26
- }
27
- } else if (temp && typeof temp === 'object') {
28
- if (!temp[k]) {
29
- temp[k] = arrayKeys.includes(k) ? [] : {};
30
- }
31
- temp = temp[k];
32
- }
33
- });
34
- };
35
-
36
- /**
37
- *
38
- * @param {Object} obj : source object
39
- * @param {Function} callback : a function that will be called when
40
- * - the deepest key in source object is reached
41
- * - the value of the deepest key is NOT `undefined` | `null`
42
- *
43
- * @example
44
- * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
45
- * // ['palette', 'primary', 'main'] '#000000'
46
- */
47
- export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
48
- function recurse(object, parentKeys = [], arrayKeys = []) {
49
- Object.entries(object).forEach(([key, value]) => {
50
- if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
51
- if (value !== undefined && value !== null) {
52
- if (typeof value === 'object' && Object.keys(value).length > 0) {
53
- recurse(value, [...parentKeys, key], Array.isArray(value) ? [...arrayKeys, key] : arrayKeys);
54
- } else {
55
- callback([...parentKeys, key], value, arrayKeys);
56
- }
57
- }
58
- }
59
- });
60
- }
61
- recurse(obj);
62
- };
63
- const getCssValue = (keys, value) => {
64
- if (typeof value === 'number') {
65
- if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
66
- // CSS property that are unitless
67
- return value;
68
- }
69
- const lastKey = keys[keys.length - 1];
70
- if (lastKey.toLowerCase().includes('opacity')) {
71
- // opacity values are unitless
72
- return value;
73
- }
74
- return `${value}px`;
75
- }
76
- return value;
77
- };
78
-
79
- /**
80
- * a function that parse theme and return { css, vars }
81
- *
82
- * @param {Object} theme
83
- * @param {{
84
- * prefix?: string,
85
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
86
- * }} options.
87
- * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
88
- *
89
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
90
- *
91
- * @example
92
- * const { css, vars } = parser({
93
- * fontSize: 12,
94
- * lineHeight: 1.2,
95
- * palette: { primary: { 500: 'var(--color)' } }
96
- * }, { prefix: 'foo' })
97
- *
98
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
99
- * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
100
- */
101
- export default function cssVarsParser(theme, options) {
102
- const {
103
- prefix,
104
- shouldSkipGeneratingVar
105
- } = options || {};
106
- const css = {};
107
- const vars = {};
108
- const varsWithDefaults = {};
109
- walkObjectDeep(theme, (keys, value, arrayKeys) => {
110
- if (typeof value === 'string' || typeof value === 'number') {
111
- if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
112
- // only create css & var if `shouldSkipGeneratingVar` return false
113
- const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
114
- const resolvedValue = getCssValue(keys, value);
115
- Object.assign(css, {
116
- [cssVar]: resolvedValue
117
- });
118
- assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
119
- assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${resolvedValue})`, arrayKeys);
120
- }
121
- }
122
- }, keys => keys[0] === 'vars' // skip 'vars/*' paths
123
- );
124
- return {
125
- css,
126
- vars,
127
- varsWithDefaults
128
- };
129
- }
@@ -1,26 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- export function createGetColorSchemeSelector(selector) {
3
- return function getColorSchemeSelector(colorScheme) {
4
- if (selector === 'media') {
5
- if (process.env.NODE_ENV !== 'production') {
6
- if (colorScheme !== 'light' && colorScheme !== 'dark') {
7
- console.error(`MUI: @media (prefers-color-scheme) supports only 'light' or 'dark', but receive '${colorScheme}'.`);
8
- }
9
- }
10
- return `@media (prefers-color-scheme: ${colorScheme})`;
11
- }
12
- if (selector) {
13
- if (selector.startsWith('data-') && !selector.includes('%s')) {
14
- return `[${selector}="${colorScheme}"] &`;
15
- }
16
- if (selector === 'class') {
17
- return `.${colorScheme} &`;
18
- }
19
- if (selector === 'data') {
20
- return `[data-${colorScheme}] &`;
21
- }
22
- return `${selector.replace('%s', colorScheme)} &`;
23
- }
24
- return '&';
25
- };
26
- }
@@ -1,5 +0,0 @@
1
- export { default } from "./createCssVarsProvider.js";
2
- export { default as prepareCssVars } from "./prepareCssVars.js";
3
- export { default as prepareTypographyVars } from "./prepareTypographyVars.js";
4
- export { default as createCssVarsTheme } from "./createCssVarsTheme.js";
5
- export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
@@ -1,51 +0,0 @@
1
- function noop() {}
2
- const localStorageManager = ({
3
- key,
4
- storageWindow
5
- }) => {
6
- if (!storageWindow && typeof window !== 'undefined') {
7
- storageWindow = window;
8
- }
9
- return {
10
- get(defaultValue) {
11
- if (typeof window === 'undefined') {
12
- return undefined;
13
- }
14
- if (!storageWindow) {
15
- return defaultValue;
16
- }
17
- let value;
18
- try {
19
- value = storageWindow.localStorage.getItem(key);
20
- } catch {
21
- // Unsupported
22
- }
23
- return value || defaultValue;
24
- },
25
- set: value => {
26
- if (storageWindow) {
27
- try {
28
- storageWindow.localStorage.setItem(key, value);
29
- } catch {
30
- // Unsupported
31
- }
32
- }
33
- },
34
- subscribe: handler => {
35
- if (!storageWindow) {
36
- return noop;
37
- }
38
- const listener = event => {
39
- const value = event.newValue;
40
- if (event.key === key) {
41
- handler(value);
42
- }
43
- };
44
- storageWindow.addEventListener('storage', listener);
45
- return () => {
46
- storageWindow.removeEventListener('storage', listener);
47
- };
48
- }
49
- };
50
- };
51
- export default localStorageManager;