a11y.d.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { AnyColor } from "../types";
  2. import { Plugin } from "../extend";
  3. interface ReadabilityOptions {
  4. level?: "AA" | "AAA";
  5. size?: "normal" | "large";
  6. }
  7. declare module "../colord" {
  8. interface Colord {
  9. /**
  10. * Returns the relative luminance of a color,
  11. * normalized to 0 for darkest black and 1 for lightest white.
  12. * https://www.w3.org/TR/WCAG20/#relativeluminancedef
  13. * https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_Colors_and_Luminance
  14. */
  15. luminance(): number;
  16. /**
  17. * Calculates a contrast ratio for a color pair.
  18. * This luminance difference is expressed as a ratio ranging
  19. * from 1 (e.g. white on white) to 21 (e.g., black on a white).
  20. * WCAG requires a ratio of at least 4.5 for normal text and 3 for large text.
  21. * https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  22. * https://webaim.org/articles/contrast/
  23. */
  24. contrast(color2?: AnyColor | Colord): number;
  25. /**
  26. * Checks that a background and text color pair conforms to WCAG 2.0 requirements.
  27. * https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  28. */
  29. isReadable(color2?: AnyColor | Colord, options?: ReadabilityOptions): boolean;
  30. }
  31. }
  32. /**
  33. * A plugin adding accessibility and color contrast utilities.
  34. * Follows Web Content Accessibility Guidelines 2.0.
  35. * https://www.w3.org/TR/WCAG20/
  36. */
  37. declare const a11yPlugin: Plugin;
  38. export default a11yPlugin;