UNPKG

contrastrast

Version:

A lightweight tool that parses color strings and recommends text contrast based on WCAG Standards

23 lines (22 loc) 836 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.textContrast = textContrast; const constants_js_1 = require("../constants.js"); const contrastRatio_js_1 = require("./contrastRatio.js"); function textContrast(foreground, background, options = {}) { const { returnDetails = false } = options; const ratio = (0, contrastRatio_js_1.contrastRatio)(foreground, background); if (!returnDetails) { return ratio; } const passes = { AA_NORMAL: ratio >= constants_js_1.WCAG_LEVELS["AA"]["normal"], AA_LARGE: ratio >= constants_js_1.WCAG_LEVELS["AA"]["large"], AAA_NORMAL: ratio >= constants_js_1.WCAG_LEVELS["AAA"]["normal"], AAA_LARGE: ratio >= constants_js_1.WCAG_LEVELS["AAA"]["large"], }; return { ratio, passes, }; }