@mui/system 5.10.13 → 5.10.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Box/Box.js +1 -10
- package/Box/index.js +0 -2
- package/CHANGELOG.md +132 -2
- package/Container/Container.js +2 -17
- package/Container/containerClasses.js +0 -3
- package/Container/createContainer.js +15 -37
- package/Container/index.js +0 -6
- package/Stack/Stack.js +1 -12
- package/Stack/createStack.js +10 -48
- package/Stack/index.js +0 -9
- package/Stack/stackClasses.js +0 -3
- package/ThemeProvider/ThemeProvider.js +2 -22
- package/ThemeProvider/index.js +0 -2
- package/Unstable_Grid/Grid.js +6 -42
- package/Unstable_Grid/createGrid.js +19 -49
- package/Unstable_Grid/gridClasses.js +8 -7
- package/Unstable_Grid/gridGenerator.d.ts +4 -3
- package/Unstable_Grid/gridGenerator.js +22 -63
- package/Unstable_Grid/index.js +0 -9
- package/borders.js +0 -14
- package/breakpoints.js +3 -32
- package/colorManipulator.js +13 -55
- package/compose.js +0 -7
- package/createBox.js +5 -20
- package/createStyled.js +27 -71
- package/createTheme/createBreakpoints.js +22 -37
- package/createTheme/createSpacing.js +4 -8
- package/createTheme/createTheme.js +6 -16
- package/createTheme/index.js +0 -2
- package/cssGrid.js +0 -21
- package/cssVars/createCssVarsProvider.js +33 -74
- package/cssVars/createGetCssVar.js +2 -7
- package/cssVars/cssVarsParser.js +3 -15
- package/cssVars/getInitColorSchemeScript.js +0 -6
- package/cssVars/index.js +0 -3
- package/cssVars/useCurrentColorScheme.js +20 -49
- package/display.js +0 -6
- package/esm/Box/Box.js +1 -6
- package/esm/Container/Container.js +3 -14
- package/esm/Container/createContainer.js +15 -25
- package/esm/Stack/Stack.js +1 -9
- package/esm/Stack/createStack.js +10 -29
- package/esm/ThemeProvider/ThemeProvider.js +2 -11
- package/esm/Unstable_Grid/Grid.js +6 -39
- package/esm/Unstable_Grid/createGrid.js +18 -35
- package/esm/Unstable_Grid/gridClasses.js +8 -4
- package/esm/Unstable_Grid/gridGenerator.js +20 -38
- package/esm/borders.js +0 -6
- package/esm/breakpoints.js +7 -22
- package/esm/colorManipulator.js +13 -43
- package/esm/compose.js +0 -5
- package/esm/createBox.js +5 -7
- package/esm/createStyled.js +27 -64
- package/esm/createTheme/createBreakpoints.js +22 -34
- package/esm/createTheme/createSpacing.js +4 -7
- package/esm/createTheme/createTheme.js +6 -9
- package/esm/cssGrid.js +0 -9
- package/esm/cssVars/createCssVarsProvider.js +33 -60
- package/esm/cssVars/createGetCssVar.js +2 -6
- package/esm/cssVars/cssVarsParser.js +3 -11
- package/esm/cssVars/useCurrentColorScheme.js +20 -44
- package/esm/getThemeValue.js +0 -2
- package/esm/index.js +3 -3
- package/esm/memoize.js +0 -1
- package/esm/merge.js +0 -3
- package/esm/palette.js +0 -3
- package/esm/propsToClassKey.js +4 -7
- package/esm/sizing.js +0 -5
- package/esm/spacing.js +3 -23
- package/esm/style.js +5 -22
- package/esm/styleFunctionSx/extendSxProp.js +3 -10
- package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
- package/esm/sx/sx.js +0 -2
- package/esm/useTheme.js +0 -2
- package/esm/useThemeProps/getThemeProps.js +0 -2
- package/esm/useThemeWithoutDefault.js +0 -3
- package/flexbox.js +0 -4
- package/getThemeValue.js +0 -14
- package/index.d.ts +2 -0
- package/index.js +16 -55
- package/legacy/Box/Box.js +1 -6
- package/legacy/Container/Container.js +3 -14
- package/legacy/Container/createContainer.js +29 -39
- package/legacy/Stack/Stack.js +1 -9
- package/legacy/Stack/createStack.js +17 -37
- package/legacy/ThemeProvider/ThemeProvider.js +3 -12
- package/legacy/Unstable_Grid/Grid.js +6 -39
- package/legacy/Unstable_Grid/createGrid.js +34 -53
- package/legacy/Unstable_Grid/gridGenerator.js +36 -58
- package/legacy/borders.js +0 -6
- package/legacy/breakpoints.js +9 -28
- package/legacy/colorManipulator.js +16 -48
- package/legacy/compose.js +0 -6
- package/legacy/createBox.js +9 -11
- package/legacy/createStyled.js +27 -68
- package/legacy/createTheme/createBreakpoints.js +20 -33
- package/legacy/createTheme/createSpacing.js +4 -9
- package/legacy/createTheme/createTheme.js +7 -13
- package/legacy/cssGrid.js +0 -9
- package/legacy/cssVars/createCssVarsProvider.js +98 -130
- package/legacy/cssVars/createGetCssVar.js +2 -10
- package/legacy/cssVars/cssVarsParser.js +7 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
- package/legacy/cssVars/useCurrentColorScheme.js +43 -69
- package/legacy/getThemeValue.js +0 -3
- package/legacy/index.js +4 -4
- package/legacy/memoize.js +0 -1
- package/legacy/merge.js +0 -3
- package/legacy/palette.js +0 -3
- package/legacy/propsToClassKey.js +2 -5
- package/legacy/sizing.js +0 -5
- package/legacy/spacing.js +6 -27
- package/legacy/style.js +9 -27
- package/legacy/styleFunctionSx/extendSxProp.js +3 -11
- package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
- package/legacy/sx/sx.js +0 -2
- package/legacy/useTheme.js +0 -2
- package/legacy/useThemeProps/getThemeProps.js +2 -4
- package/legacy/useThemeProps/useThemeProps.js +2 -2
- package/legacy/useThemeWithoutDefault.js +0 -3
- package/memoize.js +0 -2
- package/merge.js +0 -5
- package/modern/Box/Box.js +1 -6
- package/modern/Container/Container.js +3 -14
- package/modern/Container/createContainer.js +15 -25
- package/modern/Stack/Stack.js +1 -9
- package/modern/Stack/createStack.js +10 -29
- package/modern/ThemeProvider/ThemeProvider.js +2 -11
- package/modern/Unstable_Grid/Grid.js +6 -39
- package/modern/Unstable_Grid/createGrid.js +18 -34
- package/modern/Unstable_Grid/gridClasses.js +8 -4
- package/modern/Unstable_Grid/gridGenerator.js +20 -36
- package/modern/borders.js +0 -6
- package/modern/breakpoints.js +7 -21
- package/modern/colorManipulator.js +13 -43
- package/modern/compose.js +0 -5
- package/modern/createBox.js +5 -7
- package/modern/createStyled.js +27 -63
- package/modern/createTheme/createBreakpoints.js +22 -34
- package/modern/createTheme/createSpacing.js +4 -7
- package/modern/createTheme/createTheme.js +6 -9
- package/modern/cssGrid.js +0 -9
- package/modern/cssVars/createCssVarsProvider.js +33 -60
- package/modern/cssVars/createGetCssVar.js +2 -6
- package/modern/cssVars/cssVarsParser.js +3 -11
- package/modern/cssVars/useCurrentColorScheme.js +20 -44
- package/modern/getThemeValue.js +0 -2
- package/modern/index.js +4 -4
- package/modern/memoize.js +0 -1
- package/modern/merge.js +0 -3
- package/modern/palette.js +0 -3
- package/modern/propsToClassKey.js +4 -7
- package/modern/sizing.js +0 -4
- package/modern/spacing.js +3 -22
- package/modern/style.js +5 -22
- package/modern/styleFunctionSx/extendSxProp.js +3 -10
- package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
- package/modern/sx/sx.js +0 -2
- package/modern/useTheme.js +0 -2
- package/modern/useThemeProps/getThemeProps.js +0 -2
- package/modern/useThemeWithoutDefault.js +0 -3
- package/package.json +6 -6
- package/palette.js +0 -6
- package/positions.js +0 -6
- package/propsToClassKey.js +4 -10
- package/responsivePropType.d.ts +3 -0
- package/responsivePropType.js +0 -3
- package/shadows.js +0 -3
- package/sizing.js +0 -11
- package/spacing.d.ts +14 -0
- package/spacing.js +3 -37
- package/style.d.ts +6 -0
- package/style.js +6 -27
- package/styleFunctionSx/extendSxProp.js +3 -15
- package/styleFunctionSx/index.js +0 -5
- package/styleFunctionSx/styleFunctionSx.js +3 -21
- package/styled.js +0 -3
- package/sx/index.js +0 -2
- package/sx/sx.js +0 -4
- package/typography.js +0 -4
- package/useTheme.js +0 -6
- package/useThemeProps/getThemeProps.js +0 -4
- package/useThemeProps/index.js +0 -3
- package/useThemeProps/useThemeProps.js +0 -4
- package/useThemeWithoutDefault.js +0 -4
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.DISABLE_CSS_TRANSITION = void 0;
|
|
9
8
|
exports.default = createCssVarsProvider;
|
|
10
|
-
|
|
11
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
-
|
|
13
10
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
14
|
-
|
|
15
11
|
var _utils = require("@mui/utils");
|
|
16
|
-
|
|
17
12
|
var React = _interopRequireWildcard(require("react"));
|
|
18
|
-
|
|
19
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
20
|
-
|
|
21
14
|
var _styledEngine = require("@mui/styled-engine");
|
|
22
|
-
|
|
23
15
|
var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
|
|
24
|
-
|
|
25
16
|
var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
|
|
26
|
-
|
|
27
17
|
var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
|
|
28
|
-
|
|
29
18
|
var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
|
|
30
|
-
|
|
31
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
32
|
-
|
|
33
20
|
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
34
|
-
|
|
35
21
|
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); }
|
|
36
|
-
|
|
37
22
|
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; }
|
|
38
|
-
|
|
39
23
|
const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
40
24
|
exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
|
|
41
|
-
|
|
42
25
|
function createCssVarsProvider(options) {
|
|
43
26
|
const {
|
|
44
27
|
theme: defaultTheme = {},
|
|
@@ -52,23 +35,17 @@ function createCssVarsProvider(options) {
|
|
|
52
35
|
resolveTheme,
|
|
53
36
|
excludeVariablesFromRoot
|
|
54
37
|
} = options;
|
|
55
|
-
|
|
56
38
|
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]) {
|
|
57
39
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
58
40
|
}
|
|
59
|
-
|
|
60
41
|
const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
|
|
61
|
-
|
|
62
42
|
const useColorScheme = () => {
|
|
63
43
|
const value = React.useContext(ColorSchemeContext);
|
|
64
|
-
|
|
65
44
|
if (!value) {
|
|
66
45
|
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : (0, _utils.formatMuiErrorMessage)(19));
|
|
67
46
|
}
|
|
68
|
-
|
|
69
47
|
return value;
|
|
70
48
|
};
|
|
71
|
-
|
|
72
49
|
function CssVarsProvider({
|
|
73
50
|
children,
|
|
74
51
|
theme: themeProp = defaultTheme,
|
|
@@ -86,15 +63,16 @@ function createCssVarsProvider(options) {
|
|
|
86
63
|
}) {
|
|
87
64
|
const hasMounted = React.useRef(false);
|
|
88
65
|
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
colorSchemes = {},
|
|
67
|
+
components = {},
|
|
68
|
+
cssVarPrefix
|
|
69
|
+
} = themeProp,
|
|
70
|
+
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
|
|
94
71
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
95
72
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
96
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
73
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
97
74
|
|
|
75
|
+
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
98
76
|
const {
|
|
99
77
|
mode,
|
|
100
78
|
setMode,
|
|
@@ -112,35 +90,29 @@ function createCssVarsProvider(options) {
|
|
|
112
90
|
defaultMode,
|
|
113
91
|
storageWindow
|
|
114
92
|
});
|
|
115
|
-
|
|
116
93
|
const calculatedMode = (() => {
|
|
117
94
|
if (!mode) {
|
|
118
95
|
// This scope occurs on the server
|
|
119
96
|
if (defaultMode === 'system') {
|
|
120
97
|
return designSystemMode;
|
|
121
98
|
}
|
|
122
|
-
|
|
123
99
|
return defaultMode;
|
|
124
100
|
}
|
|
125
|
-
|
|
126
101
|
return mode;
|
|
127
102
|
})();
|
|
128
|
-
|
|
129
103
|
const calculatedColorScheme = (() => {
|
|
130
104
|
if (!colorScheme) {
|
|
131
105
|
// This scope occurs on the server
|
|
132
106
|
if (calculatedMode === 'dark') {
|
|
133
107
|
return defaultDarkColorScheme;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
108
|
+
}
|
|
109
|
+
// use light color scheme, if default mode is 'light' | 'system'
|
|
137
110
|
return defaultLightColorScheme;
|
|
138
111
|
}
|
|
139
|
-
|
|
140
112
|
return colorScheme;
|
|
141
|
-
})();
|
|
142
|
-
|
|
113
|
+
})();
|
|
143
114
|
|
|
115
|
+
// 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
144
116
|
const {
|
|
145
117
|
css: rootCss,
|
|
146
118
|
vars: rootVars,
|
|
@@ -148,18 +120,20 @@ function createCssVarsProvider(options) {
|
|
|
148
120
|
} = (0, _cssVarsParser.default)(restThemeProp, {
|
|
149
121
|
prefix: cssVarPrefix,
|
|
150
122
|
shouldSkipGeneratingVar
|
|
151
|
-
});
|
|
123
|
+
});
|
|
152
124
|
|
|
153
|
-
|
|
125
|
+
// 3. Start composing the theme object
|
|
126
|
+
const theme = (0, _extends2.default)({}, parsedTheme, {
|
|
154
127
|
components,
|
|
155
128
|
colorSchemes,
|
|
156
129
|
cssVarPrefix,
|
|
157
130
|
vars: rootVars,
|
|
158
131
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
159
|
-
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
160
135
|
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
161
136
|
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
162
|
-
|
|
163
137
|
const defaultColorSchemeStyleSheet = {};
|
|
164
138
|
const otherColorSchemesStyleSheet = {};
|
|
165
139
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -172,28 +146,29 @@ function createCssVarsProvider(options) {
|
|
|
172
146
|
shouldSkipGeneratingVar
|
|
173
147
|
});
|
|
174
148
|
theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
|
|
175
|
-
|
|
176
149
|
if (key === calculatedColorScheme) {
|
|
177
150
|
// 4.1 Merge the selected color scheme to the theme
|
|
178
|
-
|
|
179
|
-
|
|
151
|
+
Object.keys(parsedScheme).forEach(schemeKey => {
|
|
152
|
+
if (parsedScheme[schemeKey] && typeof parsedScheme[schemeKey] === 'object') {
|
|
153
|
+
// shallow merge the 1st level structure of the theme.
|
|
154
|
+
theme[schemeKey] = (0, _extends2.default)({}, theme[schemeKey], parsedScheme[schemeKey]);
|
|
155
|
+
} else {
|
|
156
|
+
theme[schemeKey] = parsedScheme[schemeKey];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
180
159
|
if (theme.palette) {
|
|
181
160
|
theme.palette.colorScheme = key;
|
|
182
161
|
}
|
|
183
162
|
}
|
|
184
|
-
|
|
185
163
|
const resolvedDefaultColorScheme = (() => {
|
|
186
164
|
if (typeof defaultColorScheme === 'string') {
|
|
187
165
|
return defaultColorScheme;
|
|
188
166
|
}
|
|
189
|
-
|
|
190
167
|
if (defaultMode === 'dark') {
|
|
191
168
|
return defaultColorScheme.dark;
|
|
192
169
|
}
|
|
193
|
-
|
|
194
170
|
return defaultColorScheme.light;
|
|
195
171
|
})();
|
|
196
|
-
|
|
197
172
|
if (key === resolvedDefaultColorScheme) {
|
|
198
173
|
if (excludeVariablesFromRoot) {
|
|
199
174
|
const excludedVariables = {};
|
|
@@ -203,37 +178,36 @@ function createCssVarsProvider(options) {
|
|
|
203
178
|
});
|
|
204
179
|
defaultColorSchemeStyleSheet[`[${attribute}="${key}"]`] = excludedVariables;
|
|
205
180
|
}
|
|
206
|
-
|
|
207
181
|
defaultColorSchemeStyleSheet[`${colorSchemeSelector}, [${attribute}="${key}"]`] = css;
|
|
208
182
|
} else {
|
|
209
183
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
210
184
|
}
|
|
211
|
-
});
|
|
212
|
-
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
185
|
+
});
|
|
213
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.
|
|
214
189
|
React.useEffect(() => {
|
|
215
190
|
if (colorScheme && colorSchemeNode) {
|
|
216
191
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
217
192
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
218
193
|
}
|
|
219
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
220
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
194
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
221
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
|
|
222
198
|
React.useEffect(() => {
|
|
223
199
|
let timer;
|
|
224
|
-
|
|
225
200
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
226
201
|
const css = documentNode.createElement('style');
|
|
227
202
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
228
|
-
documentNode.head.appendChild(css);
|
|
203
|
+
documentNode.head.appendChild(css);
|
|
229
204
|
|
|
205
|
+
// Force browser repaint
|
|
230
206
|
(() => window.getComputedStyle(documentNode.body))();
|
|
231
|
-
|
|
232
207
|
timer = setTimeout(() => {
|
|
233
208
|
documentNode.head.removeChild(css);
|
|
234
209
|
}, 1);
|
|
235
210
|
}
|
|
236
|
-
|
|
237
211
|
return () => {
|
|
238
212
|
clearTimeout(timer);
|
|
239
213
|
};
|
|
@@ -270,69 +244,56 @@ function createCssVarsProvider(options) {
|
|
|
270
244
|
})]
|
|
271
245
|
});
|
|
272
246
|
}
|
|
273
|
-
|
|
274
247
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
275
248
|
/**
|
|
276
249
|
* The body attribute name to attach colorScheme.
|
|
277
250
|
*/
|
|
278
251
|
attribute: _propTypes.default.string,
|
|
279
|
-
|
|
280
252
|
/**
|
|
281
253
|
* The component tree.
|
|
282
254
|
*/
|
|
283
255
|
children: _propTypes.default.node,
|
|
284
|
-
|
|
285
256
|
/**
|
|
286
257
|
* The node used to attach the color-scheme attribute
|
|
287
258
|
*/
|
|
288
259
|
colorSchemeNode: _propTypes.default.any,
|
|
289
|
-
|
|
290
260
|
/**
|
|
291
261
|
* The CSS selector for attaching the generated custom properties
|
|
292
262
|
*/
|
|
293
263
|
colorSchemeSelector: _propTypes.default.string,
|
|
294
|
-
|
|
295
264
|
/**
|
|
296
265
|
* localStorage key used to store `colorScheme`
|
|
297
266
|
*/
|
|
298
267
|
colorSchemeStorageKey: _propTypes.default.string,
|
|
299
|
-
|
|
300
268
|
/**
|
|
301
269
|
* The initial color scheme used.
|
|
302
270
|
*/
|
|
303
271
|
defaultColorScheme: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
|
|
304
|
-
|
|
305
272
|
/**
|
|
306
273
|
* The initial mode used.
|
|
307
274
|
*/
|
|
308
275
|
defaultMode: _propTypes.default.string,
|
|
309
|
-
|
|
310
276
|
/**
|
|
311
277
|
* Disable CSS transitions when switching between modes or color schemes
|
|
312
278
|
*/
|
|
313
279
|
disableTransitionOnChange: _propTypes.default.bool,
|
|
314
|
-
|
|
315
280
|
/**
|
|
316
281
|
* The document to attach the attribute to
|
|
317
282
|
*/
|
|
318
283
|
documentNode: _propTypes.default.any,
|
|
319
|
-
|
|
320
284
|
/**
|
|
321
285
|
* The key in the local storage used to store current color scheme.
|
|
322
286
|
*/
|
|
323
287
|
modeStorageKey: _propTypes.default.string,
|
|
324
|
-
|
|
325
288
|
/**
|
|
326
289
|
* A function to determine if the key, value should be attached as CSS Variable
|
|
327
290
|
*/
|
|
328
291
|
shouldSkipGeneratingVar: _propTypes.default.func,
|
|
329
|
-
|
|
330
292
|
/**
|
|
331
293
|
* The window that attaches the 'storage' event listener
|
|
332
294
|
* @default window
|
|
333
295
|
*/
|
|
334
296
|
storageWindow: _propTypes.default.any,
|
|
335
|
-
|
|
336
297
|
/**
|
|
337
298
|
* The calculated theme object that will be passed through context.
|
|
338
299
|
*/
|
|
@@ -340,7 +301,6 @@ function createCssVarsProvider(options) {
|
|
|
340
301
|
} : void 0;
|
|
341
302
|
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
342
303
|
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
343
|
-
|
|
344
304
|
const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)((0, _extends2.default)({
|
|
345
305
|
attribute: defaultAttribute,
|
|
346
306
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
@@ -349,7 +309,6 @@ function createCssVarsProvider(options) {
|
|
|
349
309
|
defaultDarkColorScheme,
|
|
350
310
|
modeStorageKey: defaultModeStorageKey
|
|
351
311
|
}, params));
|
|
352
|
-
|
|
353
312
|
return {
|
|
354
313
|
CssVarsProvider,
|
|
355
314
|
useColorScheme,
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = createGetCssVar;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
10
9
|
* and they does not need to remember the prefix (defined once).
|
|
@@ -14,20 +13,16 @@ function createGetCssVar(prefix = '') {
|
|
|
14
13
|
if (!vars.length) {
|
|
15
14
|
return '';
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
const value = vars[0];
|
|
19
|
-
|
|
20
17
|
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
21
18
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return `, ${value}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
21
|
+
}
|
|
27
22
|
|
|
23
|
+
// AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
28
24
|
const getCssVar = (field, ...fallbacks) => {
|
|
29
25
|
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
|
|
30
26
|
};
|
|
31
|
-
|
|
32
27
|
return getCssVar;
|
|
33
28
|
}
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.assignNestedKeys = void 0;
|
|
7
7
|
exports.default = cssVarsParser;
|
|
8
8
|
exports.walkObjectDeep = void 0;
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* This function create an object from keys, value and then assign to target
|
|
12
11
|
*
|
|
@@ -37,11 +36,11 @@ const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
|
37
36
|
if (!temp[k]) {
|
|
38
37
|
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
temp = temp[k];
|
|
42
40
|
}
|
|
43
41
|
});
|
|
44
42
|
};
|
|
43
|
+
|
|
45
44
|
/**
|
|
46
45
|
*
|
|
47
46
|
* @param {Object} obj : source object
|
|
@@ -53,10 +52,7 @@ const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
|
53
52
|
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
54
53
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
55
54
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
55
|
exports.assignNestedKeys = assignNestedKeys;
|
|
59
|
-
|
|
60
56
|
const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
61
57
|
function recurse(object, parentKeys = [], arrayKeys = []) {
|
|
62
58
|
Object.entries(object).forEach(([key, value]) => {
|
|
@@ -71,31 +67,25 @@ const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
|
71
67
|
}
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
recurse(obj);
|
|
76
71
|
};
|
|
77
|
-
|
|
78
72
|
exports.walkObjectDeep = walkObjectDeep;
|
|
79
|
-
|
|
80
73
|
const getCssValue = (keys, value) => {
|
|
81
74
|
if (typeof value === 'number') {
|
|
82
75
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
|
|
83
76
|
// CSS property that are unitless
|
|
84
77
|
return value;
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
const lastKey = keys[keys.length - 1];
|
|
88
|
-
|
|
89
80
|
if (lastKey.toLowerCase().indexOf('opacity') >= 0) {
|
|
90
81
|
// opacity values are unitless
|
|
91
82
|
return value;
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
return `${value}px`;
|
|
95
85
|
}
|
|
96
|
-
|
|
97
86
|
return value;
|
|
98
87
|
};
|
|
88
|
+
|
|
99
89
|
/**
|
|
100
90
|
* a function that parse theme and return { css, vars }
|
|
101
91
|
*
|
|
@@ -119,8 +109,6 @@ const getCssValue = (keys, value) => {
|
|
|
119
109
|
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
120
110
|
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
121
111
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
112
|
function cssVarsParser(theme, options) {
|
|
125
113
|
const {
|
|
126
114
|
prefix,
|
|
@@ -140,10 +128,10 @@ function cssVarsParser(theme, options) {
|
|
|
140
128
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
141
129
|
}
|
|
142
130
|
}
|
|
143
|
-
|
|
144
131
|
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
145
132
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
146
133
|
);
|
|
134
|
+
|
|
147
135
|
return {
|
|
148
136
|
css,
|
|
149
137
|
vars,
|
|
@@ -5,22 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DEFAULT_MODE_STORAGE_KEY = exports.DEFAULT_COLOR_SCHEME_STORAGE_KEY = exports.DEFAULT_ATTRIBUTE = void 0;
|
|
7
7
|
exports.default = getInitColorSchemeScript;
|
|
8
|
-
|
|
9
8
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
|
|
11
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
-
|
|
13
10
|
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); }
|
|
14
|
-
|
|
15
11
|
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; }
|
|
16
|
-
|
|
17
12
|
const DEFAULT_MODE_STORAGE_KEY = 'mode';
|
|
18
13
|
exports.DEFAULT_MODE_STORAGE_KEY = DEFAULT_MODE_STORAGE_KEY;
|
|
19
14
|
const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
20
15
|
exports.DEFAULT_COLOR_SCHEME_STORAGE_KEY = DEFAULT_COLOR_SCHEME_STORAGE_KEY;
|
|
21
16
|
const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
22
17
|
exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
23
|
-
|
|
24
18
|
function getInitColorSchemeScript(options) {
|
|
25
19
|
const {
|
|
26
20
|
defaultMode = 'light',
|
package/cssVars/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -17,7 +16,5 @@ Object.defineProperty(exports, "getInitColorSchemeScript", {
|
|
|
17
16
|
return _getInitColorSchemeScript.default;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
|
|
22
|
-
|
|
23
20
|
var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
|