UNPKG

colorjs.io

Version:

Let’s get serious about color

21 lines (15 loc) 571 B
// WCAG 2.0 contrast https://www.w3.org/TR/WCAG20-TECHS/G18.html // Simple contrast, with fixed 5% viewing flare contribution // Symmetric, does not matter which is foreground and which is background import getColor from "../getColor.js"; import {getLuminance} from "../luminance.js"; export default function contrastWCAG21 (color1, color2) { color1 = getColor(color1); color2 = getColor(color2); let Y1 = Math.max(getLuminance(color1), 0); let Y2 = Math.max(getLuminance(color2), 0); if (Y2 > Y1) { [Y1, Y2] = [Y2, Y1]; } return (Y1 + .05) / (Y2 + .05); }