Skip to content

Commit debef4b

Browse files
committed
Fix theme selector code block
1 parent 4afa2e9 commit debef4b

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

src/routes/Themes.svelte

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,51 @@
1919
2020
let showCode = $state(false);
2121
22-
const themeCode = $derived.by(() => {
22+
function buildThemeCode(
23+
fullThemeIndex: number,
24+
colorThemeIndex: number,
25+
typographyThemeIndex: number,
26+
enabledExtras: boolean[],
27+
rawCss: string,
28+
) {
2329
const files: string[] = ["defaults.css"];
24-
if (usingFullTheme) {
25-
files.push(fullThemes[themeState.fullTheme].file);
30+
if (fullThemeIndex !== 0) {
31+
if (fullThemes[fullThemeIndex].file) {
32+
files.push(fullThemes[fullThemeIndex].file);
33+
}
2634
} else {
27-
if (colorThemes[themeState.colorTheme].file)
28-
files.push(colorThemes[themeState.colorTheme].file);
29-
if (typographyThemes[themeState.typographyTheme].file)
30-
files.push(typographyThemes[themeState.typographyTheme].file);
35+
if (colorThemes[colorThemeIndex].file) {
36+
files.push(colorThemes[colorThemeIndex].file);
37+
}
38+
if (typographyThemes[typographyThemeIndex].file) {
39+
files.push(typographyThemes[typographyThemeIndex].file);
40+
}
3141
}
3242
for (let i = 0; i < extraThemes.length; i++) {
33-
if (themeState.enabledExtras[i]) files.push(extraThemes[i].file);
43+
if (enabledExtras[i]) files.push(extraThemes[i].file);
3444
}
3545
const imports = files
3646
.map((f) => `\timport "contain-css-svelte/vars/${f}";`)
3747
.join("\n");
3848
let code = "<scri" + `pt>\n${imports}\n</scri` + "pt>";
39-
if (themeState.rawCss) {
49+
if (rawCss) {
4050
code +=
4151
"\n\n<sty" +
42-
`le>\n:root {\n\t${themeState.rawCss.replace(/\n/g, "\n\t")}\n}\n</sty` +
52+
`le>\n:root {\n\t${rawCss.replace(/\n/g, "\n\t")}\n}\n</sty` +
4353
"le>";
4454
}
4555
return code;
46-
});
56+
}
57+
58+
const themeCode = $derived(
59+
buildThemeCode(
60+
themeState.fullTheme,
61+
themeState.colorTheme,
62+
themeState.typographyTheme,
63+
[...themeState.enabledExtras],
64+
themeState.rawCss,
65+
),
66+
);
4767
4868
let { includeBlurb = true } = $props();
4969
</script>

0 commit comments

Comments
 (0)