(tweaks: Record<string, string> | undefined)
| 165 | * Unknown/invalid entries are skipped; returns '' when nothing is set. |
| 166 | */ |
| 167 | export function buildTweaksCss(tweaks: Record<string, string> | undefined): string { |
| 168 | if (!tweaks) return '' |
| 169 | const decls: string[] = [] |
| 170 | for (const t of TWEAKABLE_TOKENS) { |
| 171 | const raw = tweaks[t.slug] |
| 172 | if (raw == null || raw === '') continue |
| 173 | if (t.kind === 'preset') { |
| 174 | const vars = t.presets?.[raw] |
| 175 | if (vars) { |
| 176 | for (const [cssVar, value] of Object.entries(vars)) decls.push(` ${cssVar}: ${value};`) |
| 177 | } |
| 178 | } else { |
| 179 | const rgb = parseColor(raw) |
| 180 | if (rgb) decls.push(` ${t.token}: ${rgb.join(' ')};`) |
| 181 | } |
| 182 | } |
| 183 | return decls.length ? `:root[data-theme] {\n${decls.join('\n')}\n}\n` : '' |
| 184 | } |
no test coverage detected