Refactor
parent
6730af3d20
commit
23fbb68f52
|
@ -49,6 +49,9 @@ export default {
|
||||||
getBaseThemeCSS(baseCTheme, params, theme) {
|
getBaseThemeCSS(baseCTheme, params, theme) {
|
||||||
return BaseThemeStyle.getBaseC(this.name, baseCTheme, params, theme);
|
return BaseThemeStyle.getBaseC(this.name, baseCTheme, params, theme);
|
||||||
},
|
},
|
||||||
|
getColorSchemeOption(colorScheme) {
|
||||||
|
return BaseThemeStyle.getColorSchemeOption(colorScheme);
|
||||||
|
},
|
||||||
getStyleSheet(extendedCSS = '', props = {}) {
|
getStyleSheet(extendedCSS = '', props = {}) {
|
||||||
if (this.css) {
|
if (this.css) {
|
||||||
const _css = ObjectUtils.minifyCSS(`${this.css}${extendedCSS}`);
|
const _css = ObjectUtils.minifyCSS(`${this.css}${extendedCSS}`);
|
||||||
|
|
|
@ -91,32 +91,15 @@ export default {
|
||||||
this._loadGlobalStyles();
|
this._loadGlobalStyles();
|
||||||
this._hook('onBeforeMount');
|
this._hook('onBeforeMount');
|
||||||
|
|
||||||
// @todo
|
// apply colorScheme settings
|
||||||
const { colorScheme } = this.$globalThemeOptions || {};
|
const { colorScheme } = this.$globalThemeOptions || {};
|
||||||
|
|
||||||
let colorSchemeOption = {
|
|
||||||
light: {
|
|
||||||
class: '',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
dark: {
|
|
||||||
class: 'p-dark',
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (colorScheme) {
|
if (colorScheme) {
|
||||||
if (ObjectUtils.isObject(colorScheme)) {
|
const colorSchemeOption = BaseStyle.getColorSchemeOption(colorScheme);
|
||||||
colorSchemeOption.light = { ...colorSchemeOption.light, ...colorScheme.light };
|
const isClient = DomHandler.isClient();
|
||||||
colorSchemeOption.dark = { ...colorSchemeOption.dark, ...colorScheme.dark };
|
|
||||||
} else {
|
|
||||||
colorSchemeOption.light = { ...colorSchemeOption.light, default: colorScheme !== 'auto' && colorScheme !== 'dark' };
|
|
||||||
colorSchemeOption.dark = { ...colorSchemeOption.dark, default: colorScheme === 'dark' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const isAuto = !colorSchemeOption.light?.default && !colorSchemeOption.dark?.default;
|
const isAuto = !colorSchemeOption.light?.default && !colorSchemeOption.dark?.default;
|
||||||
const isDark = isAuto ? window.matchMedia('(prefers-color-scheme: dark)') : colorSchemeOption.dark?.default;
|
const isDark = isAuto && isClient ? window.matchMedia('(prefers-color-scheme: dark)') : colorSchemeOption.dark?.default;
|
||||||
const defaultDocument = DomHandler.isClient() ? window.document : undefined;
|
const defaultDocument = isClient ? window.document : undefined;
|
||||||
|
|
||||||
Theme.setColorMode(isDark ? 'dark' : 'light');
|
Theme.setColorMode(isDark ? 'dark' : 'light');
|
||||||
|
|
||||||
|
|
|
@ -80,14 +80,8 @@ export default {
|
||||||
|
|
||||||
return css.join('');
|
return css.join('');
|
||||||
},
|
},
|
||||||
_toVariables(theme, options) {
|
getColorSchemeOption(colorScheme) {
|
||||||
return toVariables(theme, { prefix: options?.prefix });
|
let options = {
|
||||||
},
|
|
||||||
_transformCSS(name, css, mode, type, options = {}) {
|
|
||||||
const { layer, colorScheme } = options;
|
|
||||||
|
|
||||||
if (type !== 'style') {
|
|
||||||
let colorSchemeOption = {
|
|
||||||
light: {
|
light: {
|
||||||
class: '',
|
class: '',
|
||||||
rule: `:root{[CSS]}`,
|
rule: `:root{[CSS]}`,
|
||||||
|
@ -102,14 +96,25 @@ export default {
|
||||||
|
|
||||||
if (colorScheme) {
|
if (colorScheme) {
|
||||||
if (ObjectUtils.isObject(colorScheme)) {
|
if (ObjectUtils.isObject(colorScheme)) {
|
||||||
colorSchemeOption.light = { ...colorSchemeOption.light, ...colorScheme.light };
|
options.light = { ...options.light, ...colorScheme.light };
|
||||||
colorSchemeOption.dark = { ...colorSchemeOption.dark, ...colorScheme.dark };
|
options.dark = { ...options.dark, ...colorScheme.dark };
|
||||||
} else {
|
} else {
|
||||||
colorSchemeOption.light = { ...colorSchemeOption.light, default: colorScheme !== 'auto' && colorScheme !== 'dark' };
|
options.light = { ...options.light, default: colorScheme !== 'auto' && colorScheme !== 'dark' };
|
||||||
colorSchemeOption.dark = { ...colorSchemeOption.dark, default: colorScheme === 'dark' };
|
options.dark = { ...options.dark, default: colorScheme === 'dark' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
},
|
||||||
|
_toVariables(theme, options) {
|
||||||
|
return toVariables(theme, { prefix: options?.prefix });
|
||||||
|
},
|
||||||
|
_transformCSS(name, css, mode, type, options = {}) {
|
||||||
|
const { layer, colorScheme } = options;
|
||||||
|
|
||||||
|
if (type !== 'style') {
|
||||||
|
const colorSchemeOption = this.getColorSchemeOption(colorScheme);
|
||||||
|
|
||||||
mode = mode === 'dark' ? 'dark' : 'light';
|
mode = mode === 'dark' ? 'dark' : 'light';
|
||||||
css = colorSchemeOption[mode]?.rule?.replace('[CSS]', css);
|
css = colorSchemeOption[mode]?.rule?.replace('[CSS]', css);
|
||||||
}
|
}
|
||||||
|
@ -117,12 +122,10 @@ export default {
|
||||||
if (layer) {
|
if (layer) {
|
||||||
let layerOptions = {
|
let layerOptions = {
|
||||||
name: 'primevue'
|
name: 'primevue'
|
||||||
//order: '@layer'
|
//order: 'primevue'
|
||||||
};
|
};
|
||||||
|
|
||||||
const _layer = ObjectUtils.isObject(layer) ? layer.name : layer;
|
ObjectUtils.isObject(layer) && (layerOptions.name = ObjectUtils.getItemValue(layer.name, { name, type }));
|
||||||
|
|
||||||
layerOptions.name = ObjectUtils.getItemValue(_layer, { name, type });
|
|
||||||
css = ObjectUtils.isNotEmpty(layerOptions.name) ? SharedUtils.object.getRule(`@layer ${layerOptions.name}`, css) : css;
|
css = ObjectUtils.isNotEmpty(layerOptions.name) ? SharedUtils.object.getRule(`@layer ${layerOptions.name}`, css) : css;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue