You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1287,7 +1327,7 @@ the comment wrapper so the CSS parser can distinguish them from invalid CSS.
1287
1327
1288
1328
### Design Token Resolution (`webui-tokens`)
1289
1329
1290
-
The `webui-tokens` crate provides serve-time resolution of design token values. While the parser extracts token **names**into the protocol at build time, the token resolver loads token **values** from a theme file and generates CSS declarations for injection into state.
1330
+
The `webui-tokens` crate provides build/serve-time validation and resolution of design token values. While the parser extracts token **names**and `var()` fallback chains, the token crate owns the theme-coverage policy: `validate_chain_tokens` decides which chain candidates a theme must provide (literal-fallback chains are exempt) and `unthemed_literal_fallback_tokens` reports likely typos, while `resolve_tokens`generates CSS declarations for injection into state. The parser only adapts the resulting [`webui_tokens::TokenError`] into a structured `Diagnostic`.
1291
1331
1292
1332
#### Theme File Format
1293
1333
@@ -1309,27 +1349,42 @@ Token names omit the `--` prefix (matching the `protocol.tokens` format). Flat s
1.**Filter**: Only tokens in `protocol.tokens` are kept.
1318
-
2.**Dependency closure**: Token values referencing other tokens via `var(--x)` trigger transitive inclusion. Uses an iterative BFS expansion followed by DFS cycle detection.
1359
+
1.**Validate**: Every *required* token must exist in every theme. A token is required when it appears in at least one unresolved `var()` chain with no literal CSS fallback. Local and ancestor CSS definitions are removed before validation, so `--token-a: red; --foo: var(--token-a, var(--token-b))` requires `token-b` from the theme but not `token-a`. A literal-terminated chain such as `var(--brand, #000)` is exempt — `--brand` stays in `protocol.tokens`for runtime resolution (the theme value still wins when present) but does not fail the build when the theme omits it. The same token referenced once with a bare `var(--brand)` and once as `var(--brand, #000)` is still required (the bare usage has no fallback). Missing required tokens fail with `missing-theme-token`. Theme token values are trusted: unresolved or cyclic `var(--x)` references inside the theme remain browser CSS semantics rather than build failures.
1360
+
2.**Dependency closure**: Token values referencing other tokens via `var(--x)` trigger transitive inclusion when the referenced token is present in the same theme. Missing transitive references are left in the CSS value as authored.
1319
1361
3.**CSS generation**: Sorted `--name: value;` declarations. Output is deterministic.
1320
1362
4.**State injection**: Per-theme CSS strings are set on `state.tokens.<theme>`, where `/*{{{tokens.<theme>}}}*/` signals resolve them during rendering. These render-only token strings are omitted from the emitted `webui-data` client bootstrap.
1321
1363
1364
+
A token used **only** with a literal `var()` fallback and defined in no theme (e.g. a misspelled `var(--colr-brand, #000)`) is reported as a non-fatal `unthemed-token` warning in `BuildResult::warnings` (a `Vec<Diagnostic>`) rather than failing the build. These are warning-severity `Diagnostic`s carrying location, snippet, and a `did you mean …?` suggestion, so `webui build` and `webui serve` render them with the same layout as errors; Node receives their plain `Display` text.
1365
+
1322
1366
#### Package Resolution (`resolve_theme_path`)
1323
1367
1324
1368
The CLI `--theme` flag accepts a file path or an npm package name:
Package names are resolved by walking up from `search_root` looking for `node_modules/<pkg>/tokens.json`. Scoped packages (`@scope/name`) and explicit subpaths (`@scope/name/custom.json`) are supported.
1332
1377
1378
+
`BuildOptions::theme` accepts a loaded `TokenFile`. When present, `webui::build`
1379
+
validates parser-discovered unresolved tokens before protocol serialization and
1380
+
returns `WebUIError::Parse { source: ParserError::Template(..) }` when required
1381
+
tokens are missing from the theme. CLI `webui build --theme`, `webui serve
1382
+
--theme`, and Node `build({ theme })` all use this same build validation path.
1383
+
1384
+
When `webui serve --watch` hits one of these theme-token validation failures
1385
+
during an incremental rebuild, the failure is retained as the current dev-server
1386
+
state so refreshes keep showing the diagnostic until the next successful rebuild.
0 commit comments