Skip to main content

Crate bern_theme

Crate bern_theme 

Source
Expand description

Bern Theme Algorithm v5.

The theme kernel generates semantic colors and control recipes for targets whose UI framework has no complete light/dark system of its own (Web, GPUI) and for anything Bern draws itself. Native targets use their framework’s colors and never call it.

Snapshot = generate(seed, mode, contrast policy, ALGORITHM_VERSION)

Generation is deterministic and pure: it reads no platform state. Each role starts from a target lightness in OKLCH (seed hue for brand roles, a fixed neutral hue for surfaces and text, fixed hues for status), is mapped into sRGB by lowering chroma, and is then moved to the nearest lightness at which every pairing declared for it meets its contrast level, measured on the final 8-bit colors. A role no lightness can satisfy falls back to a neutral and is reported, never emitted silently.

Structs§

Check
A declared foreground and background pairing and its measured ratio.
Oklch
Perceptual lightness l (0–1), chroma c and hue h in degrees.
Recipe
RecipeState
The slots of one control state, as (slot, token).
Snapshot
The resolved theme for one seed, mode and contrast policy.
Srgb
An 8-bit sRGB color, the only encoding snapshots emit.
Token
One emitted color. alpha is 255 except for overlays such as scrim.

Enums§

ContrastPolicy
Contrast policy, from the platform’s contrast preference.
Mode

Constants§

ALGORITHM_VERSION
Version of the generation rules; a change may alter emitted colors.
DARK_ON_ACCENT_ABOVE
Luminance above which the native targets put near-black instead of white on an accent fill (SwiftUI, GTK, Compose and WinUI 3 alike).
DEFAULT_SEED
Bern’s built-in brand seed, used when an application declares none.
RECIPES
SCHEMA_VERSION
Version of the snapshot layout.

Functions§

contrast
(Y lighter + 0.05) / (Y darker + 0.05).
generate
Generate the snapshot for a brand seed (Bern’s default when None), a resolved mode and a contrast policy.
native_accent
An accent of style! as the native targets show it in mode, whose controls take it as their tint and put the foreground of DARK_ON_ACCENT_ABOVE on its fills. The chosen color is kept when it stands out from every surface of the mode at the graphic level and that foreground reads on it at the same level; otherwise it moves to the nearest lightness of its hue that does. A bright green or a pale pink darkens in light mode and stays as chosen in dark mode, carrying dark text; a red or a blue that already reads is never changed.