UNPKG

@react-md/utils

Version:
18 lines 767 B
import { getLuminance } from "./getLuminance"; /** * Gets the contrast ratio between a background color and a foreground color. * * @see https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests * * @param background - The background color * @param foreground - The foreground color. This is normally the `color` css * value. * @returns the contrast ratio between the background and foreground colors. */ export function getContrastRatio(background, foreground) { var backgroundLuminance = getLuminance(background) + 0.05; var foregroundLuminance = getLuminance(foreground) + 0.05; return (Math.max(backgroundLuminance, foregroundLuminance) / Math.min(backgroundLuminance, foregroundLuminance)); } //# sourceMappingURL=getContrastRatio.js.map