UNPKG

wcag-contrast

Version:

evaluate the wcag color contrast score for two colors

3 lines (2 loc) 956 B
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n.wcagContrast={})}(this,function(n){var e=.2126,t=.7152,r=.0722,i=1/12.92;function u(n){return Math.pow((n+.055)/1.055,2.4)}function o(n){var o=n[0]/255,a=n[1]/255,c=n[2]/255,f=o<=.03928?o*i:u(o),s=a<=.03928?a*i:u(a),p=c<=.03928?c*i:u(c);return f*e+s*t+p*r}function a(n){var e=255;8===(n=n.replace(/^#/,"")).length&&(e=parseInt(n.slice(6,8),16),n=n.substring(0,6)),4===n.length&&(e=parseInt(n.slice(3,4).repeat(2),16),n=n.substring(0,3)),3===n.length&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]);var t=parseInt(n,16);return[t>>16,t>>8&255,255&t,e]}function c(n,e){return(Math.max(n,e)+.05)/(Math.min(n,e)+.05)}function f(n,e){return c(o(n),o(e))}n.luminance=c,n.rgb=f,n.hex=function(n,e){return f(a(n),a(e))},n.score=function(n){return n>=7?"AAA":n>=4.5?"AA":n>=3?"AA Large":"Fail"}}); //# sourceMappingURL=index.umd.js.map