(ColordClass)
| 42 | * https://www.w3.org/TR/WCAG20/ |
| 43 | */ |
| 44 | const a11yPlugin: Plugin = (ColordClass): void => { |
| 45 | /** |
| 46 | * Returns WCAG text color contrast requirement. |
| 47 | * Read explanation here https://webaim.org/resources/contrastchecker/ |
| 48 | */ |
| 49 | const getMinimalContrast = ({ level = "AA", size = "normal" }: ReadabilityOptions) => { |
| 50 | if (level === "AAA" && size === "normal") return 7; |
| 51 | if (level === "AA" && size === "large") return 3; |
| 52 | return 4.5; |
| 53 | }; |
| 54 | |
| 55 | ColordClass.prototype.luminance = function () { |
| 56 | return round(getLuminance(this.rgba), 2); |
| 57 | }; |
| 58 | |
| 59 | ColordClass.prototype.contrast = function (color2 = "#FFF") { |
| 60 | const instance2 = color2 instanceof ColordClass ? color2 : new ColordClass(color2); |
| 61 | return floor(getContrast(this.rgba, instance2.toRgb()), 2); |
| 62 | }; |
| 63 | |
| 64 | ColordClass.prototype.isReadable = function (color2 = "#FFF", options = {}) { |
| 65 | return this.contrast(color2) >= getMinimalContrast(options); |
| 66 | }; |
| 67 | }; |
| 68 | |
| 69 | export default a11yPlugin; |
nothing calls this directly
no test coverage detected
searching dependent graphs…