@kcuf/mere-color
Version:
Mere color utils for generating, manipulation, a11y purposes.
12 lines (11 loc) • 425 B
JavaScript
import _round from 'lodash/round';
/**
* Compute contrast according to two luminance values.
*/
export default function computeContrast(fgcLuminance, bgcLuminance) {
if (fgcLuminance < 0 || bgcLuminance < 0) {
return -1;
}
return _round(fgcLuminance > bgcLuminance ? (fgcLuminance + 0.05) / (bgcLuminance + 0.05) : (bgcLuminance + 0.05) / (fgcLuminance + 0.05), 3);
}
//# sourceMappingURL=compute-contrast.js.map