UNPKG

@peculiar/color

Version:

Library for color manipulation and conversion in JavaScript.

16 lines 635 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getContrastRatio = void 0; var get_luminance_1 = require("./get_luminance"); /** * Calculates the contrast ratio between two colors. * * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests */ function getContrastRatio(foreground, background) { var lumA = (0, get_luminance_1.getLuminance)(foreground); var lumB = (0, get_luminance_1.getLuminance)(background); return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05); } exports.getContrastRatio = getContrastRatio; //# sourceMappingURL=get_contrast_ratio.js.map