Class Theme.Builder
- Enclosing class:
- Theme
Theme.-
Method Summary
Modifier and TypeMethodDescriptionDeclares an alias token: a name whose value is a live reference to another--jc-*token.build()Builds the immutableTheme, resolving everyvar(--jc-name)reference to a concrete literal.Adds (or overrides) a dark accent token: a literal applied on top of the shared dark neutral layer when the page is in the dark scheme.Adds (or overrides) a single CSS custom-property token.
-
Method Details
-
token
Adds (or overrides) a single CSS custom-property token.The value may be either a literal or a
var(--jc-name)reference to another known token:- A literal is validated eagerly here by
CssValueGrammar's accept-known-safe allowlist grammar after normalization (trim → reject C0/C1/DEL → strip comments → rejecturl(in any spelling → grammar). - A value that, after that same normalization belt, matches
var(--jc-name)is recognized as a reference and stored unresolved — it is resolved to a concrete literal atbuild()time (its target may not be defined yet, e.g. a forward reference).var()is never aCssValueGrammarvalue shape; it is Theme-layer syntax recognized one layer above the grammar.
CssValueEscaper(seeConsoleChromeMixin).A declared name in the reserved
--jc-chrome-*namespace thatTheme.OPENdoes not already declare is rejected.- Parameters:
name- The token name. Must not benull and must match^--jc-[a-z0-9-]+$.value- The CSS value — a literal, or avar(--jc-name)reference.- Returns:
- This object.
- Throws:
IllegalArgumentException- If the name is not in the legal shape (full-stringString.matches(...), notfind(...)—"--jc-foo;--bar"must REJECT even though"--jc-foo"matches as a leading substring), if the value contains a control character or aurl(production, or if the value is neither avar(--jc-name)reference nor one of the allowlisted CSS value shapes. A reference whose target is unknown, cyclic, or too deeply chained is instead reported atbuild()time.
- A literal is validated eagerly here by
-
dark
Adds (or overrides) a dark accent token: a literal applied on top of the shared dark neutral layer when the page is in the dark scheme.The name and value go through the same guards as
token(String, String), with one difference: the value must be a literal. Avar()reference is rejected, because the only thing it could resolve against is the light palette, which would bake the wrong value into the dark scheme.- Parameters:
name- The token name. Must match^--jc-[a-z0-9-]+$.value- The CSS literal.- Returns:
- This object.
- Throws:
IllegalArgumentException- If the name is malformed or in the reserved--jc-chrome-*namespace without being aTheme.OPENtoken, or if the value is avar()reference or is not one of the allowlisted CSS value shapes.
-
alias
Declares an alias token: a name whose value is a live reference to another--jc-*token.The target must be exactly one
var(--jc-name)reference, with no fallback, no surrounding value and no second reference. It is stored after the shared normalization belt (trim and comment strip, with control characters rejected on the raw value) and emitted verbatim. Nothing dangerous is representable in that shape, so an alias needs no escaper. A literal belongs intoken(String, String). Avar()given totoken()is resolved to its literal at build time; one given here is not.A name may be declared by only one channel:
build()rejects a name given to bothtoken()andalias(), in either order.Example:
// Follows --jc-card-bg live, including any later override of it. builder .alias("--jc-tab-bar-bg" ,"var(--jc-card-bg)" );// Rejected: a literal belongs in token(), not alias(). builder .alias("--jc-tab-bar-bg" ,"#fff" );A declared name in the reserved
--jc-chrome-*namespace thatTheme.OPENdoes not already declare is rejected.- Parameters:
name- The alias name. Must match^--jc-[a-z0-9-]+$.target- The reference. Must be a singlevar(--jc-name).- Returns:
- This object.
- Throws:
IllegalArgumentException- If the name or the target is malformed.
-
build
Builds the immutableTheme, resolving everyvar(--jc-name)reference to a concrete literal.Resolution scope is this builder's own tokens, shadowing
Theme.OPEN's tokens (exact shadowing: a name defined on this builder wins outright, even if resolving that entry then fails — there is no silent fall-through toTheme.OPEN's value for a shadowed name). Resolution runs on a copy of the token map, so a failedbuild()leaves this builder unchanged and retryable.Rejects a name declared by both
token(String, String)andalias(String, String).- Returns:
- A new
Themewhose every token value is a resolved six-shape literal (the substringvar(appears in none of them). - Throws:
IllegalArgumentException- If a reference names an unknown token, forms a cycle (the message carries the cycle path), or exceeds the resolution depth cap.
-