跪拜 Guibai
← All articles
Frontend · GitHub

Color Locked in Three Token Layers: Alioth's Multi-Brand Theme System

By 一条Go ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

A brand swap becomes a single generator input instead of a site-wide debugging hunt, because CI guards and generated artifacts catch regressions early. The unresolved SVG and Tailwind debts show tokenization only covers components that consume variables, a gap every multi-brand system will hit.

Summary

Multi-brand theming usually breaks in two structural ways: half the UI updates and half doesn't, or a brand switch makes button text unreadable. Alioth's web front end avoids both with a three-layer token system: layer 0 holds 15 brand palettes as :root[data-brand] selectors with 11-step color ramps and role colors; layer 1 maps brand roles to semantic variables like --primary; layer 2 maps those to component styles. Components only read semantic variables, so rebranding touches only layer 0.

Each brand color carries four distinct responsibilities: fill, foreground on fill, ink for text/icons, and focus ring. The generator derives all four from one brand hue in OKLCH space and bakes in WCAG contrast assertions, so an unreadable combination fails generation. Status colors (success, warning, danger) are decoupled from brand entirely to avoid confusion when brand hues collide with warning or success hues. Light/dark switching is driven by a class on <html> plus a data-brand attribute, not a media query, and a boot script in the head prevents first-frame flash by reading localStorage before stylesheets load.

Verification runs through generated artifacts and a conventions script: tokens:check compares generated CSS against the repo, and check-ui-conventions.mjs blocks new violations while ignoring legacy ones via a baseline file. Known debt remains: 169 Tailwind palette classes across 25 files, 181 instances of #1677ff inside unDraw SVGs that <img> can't recolor via CSS, and cross-device preference syncing that only uses localStorage. Manual checks cover button text, link/selected states, and focus rings; the design doc reports 360 contrast pairs across 15 brands × 2 modes × 12 semantic groups all pass, with a minimum of 4.55:1.

Takeaways
— Alioth's web front end ships 15 brand palettes, each with light and dark modes.
— Colors live in three layers: brand (11-step ramps plus role colors), semantic (mapping to --primary etc.), and component (only reads semantic variables).
— Components must never reference brand-level color steps directly; rebranding changes only layer 0.
— Each brand color splits into four roles: --primary (fill), --primary-foreground, --primary-ink (text/icons), and --ring (focus), because a single value fails somewhere under contrast requirements.
— Lemon yellow as fill hits 12:1 contrast with dark ink, but as text on white it drops to 1.5:1.
— Status colors (success #047857, warning #a34a06, danger #b42318) are fixed and not tied to brand to avoid confusion with brand hues.
— Light/dark mode uses an html class (light/dark) and data-brand for palette selection, not prefers-color-scheme, so users can override system preference.
— A boot script inline in <head> reads localStorage and sets class and data-brand before stylesheets load to prevent theme flash; it hardcodes the brand list and a placeholder background color.
— The brand token CSS and generated TypeScript are outputs of a generator script that works in OKLCH and fails on WCAG contrast violations.
— CI runs tokens:check to compare generated output with the repo, and check-ui-conventions.mjs blocks only new palette class or literal color violations via a baseline file.
— Documented tech debt: 169 Tailwind palette classes in 25 files, 181 #1677ff instances in 14 unDraw SVGs (SVGs via <img> can't read CSS variables), and no server-side preference sync.
— Manual verification steps: run tokens:check and check, then inspect button text, links/selection, and focus rings; 360 contrast pairs all pass with a minimum 4.55:1.
Conclusions

The decision to keep status colors out of the brand system is a deliberate tradeoff: visual consistency across brands loses to unambiguous semantics. Many design systems tie everything to brand, but Alioth argues that when warning and brand hues collide in hue space, users can't tell a brand accent from an alert.

The generator plus --check mode turns a CSS convention into a testable artifact, which makes hand-editing a single color value fail CI. That's more reliable than a 'don't edit by hand' comment.

The hardcoded brand list in the boot script shows that a clean abstraction (importable module) would cost a network request and break first-frame timing, so duplication with a consistency guard wins. Also the 169 Tailwind classes and 181 unDraw SVG colors are a reminder that tokenization only covers components that consume variables; images via <img> are a separate pipeline.

Concepts & terms
Three-layer token system
A design-token architecture split into brand (palette), semantic (role), and component (consumption) layers. Components only read semantic variables, so rebranding requires changing only the brand layer.
OKLCH
A perceptually uniform color space used by the generator to create 11-step color ramps with even perceived steps; contrast assertions run in this space.
WCAG contrast ratio
Measure of luminance difference between foreground and background, used to ensure text and UI elements meet readability thresholds (e.g., 4.5:1 for normal text, 3:1 for large text and focus rings).
data-brand
HTML attribute on the root element that selects which brand palette is active; combined with :root[data-brand='...'] CSS selectors to apply the right token values.
First-frame flash
A brief display of unstyled or wrong-theme colors while JavaScript loads; prevented by running a tiny inline script in <head> before stylesheets.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗