Documentation
¶
Overview ¶
Package theme handles theme discovery, loading, token resolution, and CSS generation.
Index ¶
- func DefaultDarkTokens() map[string]string
- func DefaultTokens() map[string]string
- func DeriveTokens(tokens map[string]string) map[string]string
- func GenerateCSS(lightTokens, darkTokens map[string]string) string
- func GenerateLightDarkCSS(lightTokens, darkTokens map[string]string) string
- func GenerateStyleTag(lightTokens, darkTokens map[string]string) htmltemplate.HTML
- func KnownTokens() map[string]bool
- func ResolveDarkTokens(defaults map[string]string, t *Theme, presetName string, ...) map[string]string
- func ResolveTokens(defaults map[string]string, t *Theme, presetName string, ...) map[string]string
- func SuggestToken(unknown string, known map[string]bool) string
- func ValidateOverrides(label string, overrides map[string]string, known map[string]bool) error
- type Preset
- type Theme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDarkTokens ¶
DefaultDarkTokens returns the hardcoded default dark-mode token overrides. These mirror the semantic remaps previously in dark.css, making all dark-mode values reachable via theme.dark_overrides in sarde.yaml.
func DefaultTokens ¶
DefaultTokens returns the hardcoded default light-mode tokens. This is layer 0 — the absolute fallback ensuring every expected CSS variable exists even with no theme.yaml.
func DeriveTokens ¶
DeriveTokens auto-generates variant tokens from the accent color. When accent is a valid hex color, it derives:
- accent-hover: 10% darker
- accent-high: 20% lighter (for dark mode emphasis)
- accent-low: rgba() at 10% opacity (for subtle backgrounds)
Derivation is skipped if a key already exists (user overrides win). Non-hex accent values are skipped gracefully.
func GenerateCSS ¶
GenerateCSS produces CSS custom property blocks for light and dark modes. All token keys are prefixed with --sd- and sorted alphabetically.
func GenerateLightDarkCSS ¶
GenerateLightDarkCSS produces a @supports block that uses the CSS light-dark() function for tokens that have both a light and dark value. This is emitted as progressive enhancement — browsers that support light-dark() use it, others ignore the @supports block and fall back to the legacy two-block output.
func GenerateStyleTag ¶
func GenerateStyleTag(lightTokens, darkTokens map[string]string) htmltemplate.HTML
GenerateStyleTag wraps the generated CSS in a <style> element. It emits both the legacy two-block output (baseline) and a light-dark() @supports block (progressive enhancement for modern browsers).
func KnownTokens ¶
KnownTokens returns the set of all valid --sd-* token names (without the prefix). This must stay in sync with tokens.css — the TestKnownTokens_MatchesCSS test enforces this.
func ResolveDarkTokens ¶
func ResolveDarkTokens(defaults map[string]string, t *Theme, presetName string, overrides map[string]string) map[string]string
ResolveDarkTokens merges dark-mode tokens through the 4-layer cascade.
func ResolveTokens ¶
func ResolveTokens(defaults map[string]string, t *Theme, presetName string, overrides map[string]string) map[string]string
ResolveTokens merges light-mode tokens through the 4-layer cascade. Order (last wins): defaults → theme.Tokens → preset.Tokens → overrides.
func SuggestToken ¶
SuggestToken returns the closest known token name if the edit distance is ≤ 2.
Types ¶
type Preset ¶
type Preset struct {
Name string `yaml:"name"`
Tokens map[string]string `yaml:"tokens"`
DarkTokens map[string]string `yaml:"dark_tokens"`
}
Preset represents a theme preset variation (e.g., "ocean", "forest").
type Theme ¶
type Theme struct {
Name string `yaml:"name"`
Slug string `yaml:"slug"`
Version string `yaml:"version"`
Author string `yaml:"author"`
Description string `yaml:"description"`
License string `yaml:"license"`
Tokens map[string]string `yaml:"tokens"`
DarkTokens map[string]string `yaml:"dark_tokens"`
Presets map[string]Preset `yaml:"presets"`
}
Theme represents a loaded theme with its configuration and token definitions.
func LoadFromDir ¶
LoadFromDir loads a theme from a filesystem directory. Returns (nil, nil) if theme.yaml does not exist.