|
19 | 19 |
|
20 | 20 | let showCode = $state(false); |
21 | 21 |
|
22 | | - const themeCode = $derived.by(() => { |
| 22 | + function buildThemeCode( |
| 23 | + fullThemeIndex: number, |
| 24 | + colorThemeIndex: number, |
| 25 | + typographyThemeIndex: number, |
| 26 | + enabledExtras: boolean[], |
| 27 | + rawCss: string, |
| 28 | + ) { |
23 | 29 | 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 | + } |
26 | 34 | } 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 | + } |
31 | 41 | } |
32 | 42 | 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); |
34 | 44 | } |
35 | 45 | const imports = files |
36 | 46 | .map((f) => `\timport "contain-css-svelte/vars/${f}";`) |
37 | 47 | .join("\n"); |
38 | 48 | let code = "<scri" + `pt>\n${imports}\n</scri` + "pt>"; |
39 | | - if (themeState.rawCss) { |
| 49 | + if (rawCss) { |
40 | 50 | code += |
41 | 51 | "\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` + |
43 | 53 | "le>"; |
44 | 54 | } |
45 | 55 | 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 | + ); |
47 | 67 |
|
48 | 68 | let { includeBlurb = true } = $props(); |
49 | 69 | </script> |
|
0 commit comments