bestContrastWith
bestContrastWith( target, scope, { direction?, readableOn?, not? } )
- color WCAG ratio
- size value ratio
- text style font-size ratio
Change either ink and every contrast is checked again.
The member with the highest contrast against a target: the WCAG ratio for colors, the ratio between two values for sizes and text styles, so a heading can be the style that stands out most from the body. The check is part of the rule, so you don't redo it after every redesign.
const ink = book.addScope('ink');
ink.set('a', color('#172c4f'));
ink.set('b', color('#f3d36b'));
// on every surface: whichever ink reads best
ui.set('label', bestContrastWith(
ref('ui.surface'), ref('ink'),
))