Skip to main content

Crate webui_tokens

Crate webui_tokens 

Source
Expand description

Design token loading, filtering, and CSS generation for WebUI.

Loads token values from JSON files, filters them against the protocol’s token list, follows present transitive var(--x) dependencies for tokens in each theme, and generates per-theme CSS declaration strings ready for state injection. Theme token internals are trusted: unresolved or cyclic dependencies remain browser CSS semantics rather than build failures.

§Token file format

Single multi-theme JSON:

{
  "themes": {
    "light": { "surface-page": "#ffffff", "text-primary": "#111827" },
    "dark":  { "surface-page": "#171717", "text-primary": "#fafafa" }
  }
}

Or flat single-theme JSON (treated as a single "default" theme):

{ "surface-page": "#ffffff", "text-primary": "#111827" }

Structs§

CssFallbackChain
A CSS var() fallback chain that needs theme or local CSS coverage.
ResolvedTokens
Result of resolving tokens: per-theme CSS strings.
TokenFile
Loaded token themes — maps theme name → (token name → CSS value).

Enums§

TokenError
Errors that can occur during token loading, resolution, or CSS generation.

Functions§

extract_var_references
Extract var(--name) references from a CSS value string.
inject_into_state
Inject resolved token CSS into a JSON state value under state.tokens.
inject_token_css
Inject pre-resolved per-theme CSS strings into a JSON state value.
load_token_file
Load a multi-theme token file.
parse_token_content
Parse token JSON content into a TokenFile.
resolve_theme_path
Resolve a --theme value to a file path on disk.
resolve_tokens
Resolve tokens for all themes against the protocol’s token candidate list.
unthemed_literal_fallback_tokens
CSS tokens used only with a literal var() fallback and defined in no theme — likely typos.
validate_chain_tokens
Validate the tokens required by parser var() fallback chains against a theme.
validate_required_tokens
Validate that every required token exists in every theme.

Type Aliases§

Result
Result type alias for token operations.