in src/utils/utils.js [95:113]
export function getColorContrast(foreground, background) {
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
const backgroundLuminance = relativeLuminance(rgbFromHex(background)) + 0.05;
const foregroundLuminance = relativeLuminance(rgbFromHex(foreground)) + 0.05;
let score = backgroundLuminance / foregroundLuminance;
if (foregroundLuminance > backgroundLuminance) {
score = 1 / score;
}
const level = CONTRAST_LEVELS.find(({ min, max }) => {
return score >= min && score < max;
});
return {
score: (Math.round(score * 10) / 10).toFixed(1),
level,
};
}