dbsd_kczx/src/logics/theme/index.ts

28 lines
772 B
TypeScript
Raw Normal View History

2021-10-20 14:32:09 +08:00
import { getThemeColors, generateColors } from '../../../build/config/themeConfig';
import { replaceStyleVariables } from 'vite-plugin-theme/es/client';
import { mixLighten, mixDarken, tinycolor } from 'vite-plugin-theme/es/colorUtils';
export async function changeTheme(color: string) {
const colors = generateColors({
mixDarken,
mixLighten,
tinycolor,
color,
});
2022-03-10 09:47:29 +08:00
let res = await replaceStyleVariables({
2021-10-20 14:32:09 +08:00
colorVariables: [...getThemeColors(color), ...colors],
});
2022-06-10 10:44:44 +08:00
fixDark();
return res;
2021-10-20 14:32:09 +08:00
}
2022-03-10 09:47:29 +08:00
// 【LOWCOD-2262】修复黑暗模式下切换皮肤无效的问题
async function fixDark() {
2022-06-10 10:44:44 +08:00
let el = document.getElementById('__VITE_PLUGIN_THEME__');
2022-03-10 09:47:29 +08:00
if (el) {
2022-06-10 10:44:44 +08:00
el.innerHTML = el.innerHTML.replace(/\\["']dark\\["']/g, `'dark'`);
2022-03-10 09:47:29 +08:00
}
2022-06-10 10:44:44 +08:00
}