Skip to main content

Module contrast

Module contrast 

Source
Expand description

WCAG 2.1 contrast primitives. Cases 1, 4, and 5 all measure against these — implement once, correctly.

relative_luminance works on linearized sRGB; the conversion lives in color::linear_srgb_of so this file does not duplicate the gamma curve.

Constants§

AA_LARGE_TEXT
AA threshold for large text (>= 18pt regular / 14pt bold).
AA_NON_TEXT
AA threshold for UI components, icons, borders.
AA_TEXT
AA threshold for normal-sized text.
DARK_BG
Page background for the future dark mode (§8 — emitted today even though the framework is light-only).
LIGHT_BG
Page background the engine measures the light-mode palette against.
TEXT_ON_DARK
Default near-white text used on dark surfaces.
TEXT_ON_LIGHT
Default near-black text used on light surfaces.

Functions§

contrast_ratio
WCAG 2.1 contrast ratio. Range 1.0..=21.0 — identical colors give 1.0, black-on-white gives 21.0.
relative_luminance
WCAG 2.1 relative luminance of an sRGB color, range 0.0..=1.0.