MCPcopy
hub / github.com/omgovich/colord / a11yPlugin

Function a11yPlugin

src/plugins/a11y.ts:44–67  ·  view source on GitHub ↗
(ColordClass)

Source from the content-addressed store, hash-verified

42 * https://www.w3.org/TR/WCAG20/
43 */
44const 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
69export default a11yPlugin;

Callers

nothing calls this directly

Calls 7

roundFunction · 0.90
getLuminanceFunction · 0.90
floorFunction · 0.90
getContrastFunction · 0.90
getMinimalContrastFunction · 0.85
toRgbMethod · 0.80
contrastMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…