Expand description
Shared resolution step — style packs, fonts, and contrast math.
This module is the single owner of token semantics for BOTH render
targets: render_html (websites) consumes these functions for its CSS
emission, and render_native projects the same resolved values across
the FFI as a NativeTheme. The 0025 style-pack property — “preview
cannot drift from the pack” — holds only because resolution happens
exactly once, here, in Rust. Never reimplement pack→value mapping in
Swift/Kotlin/JS.
The --ws-* token contract (style-pack rendering annex v0):
packs re-set ONLY these tokens; packs change visuals, never layout.
Defaults are the “Surf Simple” pack and must stay in lockstep with
assets/surfdoc.css :root (drift-tested in render_html).
The pack registry here mirrors the production injection tables in
repos/surf frontend/src/sites/container.rs (STYLE_PACKS). The
container remains the web injection point; this module is the canonical
semantic owner for native targets and any future consolidation.
Structs§
- Resolved
Theme - A document’s fully resolved presentation: pack tokens with the pack
applied, accent + derived WCAG colors, and font stacks. Computed once;
render_htmlemits it as CSS variables,render_nativeships it across the FFI asNativeTheme. - WsTokens
- The resolved
--ws-*token values for one style pack. Values are the exact CSS strings the web renderer emits; native targets parse the px fields into numeric form viaNativeTheme.
Constants§
- COMIC_
TOKENS - Comic — the dramatic second voice that proves the contract: tight radii,
comic-thick borders, hard-offset panel shadows, flat hero ink, a light
diagonal hatch texture. Values mirror the
comicpack in the surf container’sSTYLE_PACKS. - DEFAULT_
ACCENT - Platform default accent (
--accentinassets/surfdoc.css:root). - DEFAULT_
STYLE_ PACK - Default style-pack key. Mirrors
DEFAULT_STYLE_PACKin the surf container (0025 DEFAULT). - SURF_
SIMPLE_ TOKENS - Surf Simple — the zero-pack default. MUST stay byte-equal to the
:rootdeclarations inassets/surfdoc.css(drift-tested below and inrender_html); injecting nothing on web yields exactly these values.
Functions§
- accent_
ink_ color - Derive an accent ink — the accent adjusted until it reads as normal TEXT at WCAG AA (≥ 4.5:1) against the theme’s surfaces (BR-SITE-A11Y).
- contrast_
ratio - WCAG 2.x contrast ratio between two hex colors (1.0..=21.0). Unparseable input yields 0.0 (so “is this AA?” checks fail loudly).
- resolve_
style_ pack - Resolve a style-pack key to its token set. Unknown keys (DB drift, forward-compat) fall back to Surf Simple — a stale pack value can never break a render.
- resolve_
theme - Resolve a theme from site-level inputs. All inputs optional;
Noneyields the platform defaults (Surf Simple pack,#2563ebaccent, system fonts).