index.ts 788 B

123456789101112131415161718192021222324252627
  1. import { getThemeColors, generateColors } from '../../../build/config/themeConfig';
  2. import { replaceStyleVariables } from '@rys-fe/vite-plugin-theme/es/client';
  3. import { mixLighten, mixDarken, tinycolor } from '@rys-fe/vite-plugin-theme/es/colorUtils';
  4. export async function changeTheme(color: string) {
  5. const colors = generateColors({
  6. mixDarken,
  7. mixLighten,
  8. tinycolor,
  9. color,
  10. });
  11. let res = await replaceStyleVariables({
  12. colorVariables: [...getThemeColors(color), ...colors],
  13. });
  14. fixDark();
  15. return res;
  16. }
  17. // 【LOWCOD-2262】修复黑暗模式下切换皮肤无效的问题
  18. async function fixDark() {
  19. let el = document.getElementById('__VITE_PLUGIN_THEME__');
  20. if (el) {
  21. el.innerHTML = el.innerHTML.replace(/\\["']dark\\["']/g, `'dark'`);
  22. }
  23. }