Something went wrong. Try again.
message board on atproto atchan.net
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import { THEMES, type Theme } from './themes.js'
export function theme_declarations(theme: Theme, indent = ''): string { const tokens = Object.entries(theme.tokens).map( ([token, value]) => `${indent}--color-${token.replaceAll('_', '-')}: ${value};` ) return [`${indent}color-scheme: ${theme.scheme};`, ...tokens].join('\n')}
function indent(css: string): string { return css .split('\n') .map((line) => (line ? `\t${line}` : line)) .join('\n')}
function declarations(theme: Theme): string { return theme_declarations(theme, '\t')}
export function build_theme_css(): string { const light = THEMES.map( (theme) => `[data-theme-light='${theme.id}'],\n[data-theme-sample='${theme.id}'] {\n${declarations(theme)}\n}` ).join('\n\n')
const dark = THEMES.map((theme) => indent(`[data-theme-dark='${theme.id}'] {\n${declarations(theme)}\n}`) ).join('\n\n')
const themes = `${light}\n\n@media screen and (prefers-color-scheme: dark) {\n${dark}\n}`
return `@layer theme {\n${indent(themes)}\n}\n`}