@setoelkahfi / svara / commits / 6f46d69

optimized stylesheet loading

mellbacon committed Apr 28, 2023 at 03:05 UTC 6f46d6930d06ca064b4ff288ec890fa98891304f
1 file changed +6 -3
src/config/themehandler.ts
+6 -3
@@ -10,6 +10,7 @@ export function getThemes() {
10 return themelist;
11 }
12
13 +const stylesheet = document.styleSheets[1].cssRules[0] as CSSStyleRule;
14 export async function loadTheme(name: string) {
15 let json = await import(`../config/themes/${name.toLowerCase()}-theme.json`);
16 const theme = Object.entries(json.theme);
@@ -20,9 +21,11 @@ export async function loadTheme(name: string) {
21 const value = property[1];
22
23 const cssValue = `${category}-${name}`;
23 - if (getComputedStyle(document.documentElement).getPropertyValue(`--${cssValue}`)) {
24 - document.documentElement.style.setProperty(`--${cssValue}`, value);
25 - //console.log(cssValue + ": " + value);
24 +
25 + for (const style of stylesheet.style) {
26 + if (style === `--${cssValue}`) {
27 + stylesheet.style.setProperty(`--${cssValue}`, value);
28 + }
29 }
30 }
31 }