Skip to main content

Module contrast

Module contrast 

Source
Expand description

Contrast checks: the token pairs that must stay legible, and the WCAG 2.x ratios they must reach.

Structs§

Failure
A pair under its required ratio, or with a token missing.
Pair
A foreground token over a background token.
Separation
Two slots of the categorical palette told apart too little.

Enums§

Level
The level a theme is checked at.
PairKind
What a pair is: text to read, or a user-interface part to see.
Vision
How a colour is seen, for telling the categorical palette’s slots apart.

Constants§

CATEGORY_ADJACENT
Between two slots next to each other in the categorical palette (series 1 and 2 of a chart), with full colour vision.
CATEGORY_ANY
Between any two slots of the categorical palette, with full colour vision: a scatter or a legend puts any two side by side.
CATEGORY_CVD_ADJACENT
Between two slots next to each other, with protanopia or deuteranopia.
OVER_IMAGES
The pairs drawn over an image, whose background is translucent: the background is painted over black and over white (an image’s darkest and brightest pixels) and the foreground must read on both. check checks them with PAIRS, reporting the poorer of the two ratios.
PAIRS
Every pair checked, listed by hand: where text is drawn and where a control must be seen. Decorative borders (border.default) are not in it.

Functions§

check
Checks every pair of PAIRS and OVER_IMAGES at a level; empty when all pass.
check_category
Checks that the categorical palette’s slots are told apart: every two at CATEGORY_ANY and neighbours at CATEGORY_ADJACENT with full colour vision, neighbours at CATEGORY_CVD_ADJACENT with protanopia and deuteranopia. Empty when all pass. Their contrast with the surfaces is in PAIRS.
contrast_ratio
The WCAG 2.x contrast ratio of a foreground over a background, from 1 to 21. A translucent foreground is first painted over the background; the background is taken as opaque.
delta_e
The perceptual distance between two colours, as seen with vision: the Euclidean distance in OKLab, times 100 (ΔE OK). About 2 is the smallest difference seen side by side; categorical palettes aim for 15 and more between neighbours.
over_image_ratio
The ratio of a pair of OVER_IMAGES in a theme, if both tokens are colours: its background painted over black and over white, the poorer of the two.
pair_ratio
The ratio of one pair in a theme, if both tokens are colours.