You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
const _excluded = ["colorSchemes", "components"],
|
|
_excluded2 = ["light"];
|
|
import { deepmerge } from '@mui/utils';
|
|
import cssVarsParser from './cssVarsParser';
|
|
function prepareCssVars(theme, parserConfig) {
|
|
// @ts-ignore - ignore components do not exist
|
|
const {
|
|
colorSchemes = {}
|
|
} = theme,
|
|
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
const {
|
|
vars: rootVars,
|
|
css: rootCss,
|
|
varsWithDefaults: rootVarsWithDefaults
|
|
} = cssVarsParser(otherTheme, parserConfig);
|
|
let themeVars = rootVarsWithDefaults;
|
|
const colorSchemesMap = {};
|
|
const {
|
|
light
|
|
} = colorSchemes,
|
|
otherColorSchemes = _objectWithoutPropertiesLoose(colorSchemes, _excluded2);
|
|
Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
|
|
const {
|
|
vars,
|
|
css,
|
|
varsWithDefaults
|
|
} = cssVarsParser(scheme, parserConfig);
|
|
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
colorSchemesMap[key] = {
|
|
css,
|
|
vars
|
|
};
|
|
});
|
|
if (light) {
|
|
// light color scheme vars should be merged last to set as default
|
|
const {
|
|
css,
|
|
vars,
|
|
varsWithDefaults
|
|
} = cssVarsParser(light, parserConfig);
|
|
themeVars = deepmerge(themeVars, varsWithDefaults);
|
|
colorSchemesMap.light = {
|
|
css,
|
|
vars
|
|
};
|
|
}
|
|
const generateCssVars = colorScheme => {
|
|
if (!colorScheme) {
|
|
return {
|
|
css: _extends({}, rootCss),
|
|
vars: rootVars
|
|
};
|
|
}
|
|
return {
|
|
css: _extends({}, colorSchemesMap[colorScheme].css),
|
|
vars: colorSchemesMap[colorScheme].vars
|
|
};
|
|
};
|
|
return {
|
|
vars: themeVars,
|
|
generateCssVars
|
|
};
|
|
}
|
|
export default prepareCssVars; |