Skip to main content
Module

x/a11y_color_contrast/mod.ts

A TypeScript package to calculate WCAG 2.0/3.0 and APCA color contrasts
Latest
import * as a11yColorContrast from "https://deno.land/x/a11y_color_contrast@v0.2.0/mod.ts";

Functions

This function calculates the contrast value between two colors based on WCAG contrast readability criteria. The first color is the foreground color and the second the background color (defaulting to pure white, "#fff" / [255, 255, 255]).

From a Lc value, interpolate and calculate the approriate font sizes.

With a given Lc value, a list or a specific font size and if desired the font weights considered, does the Lc value satisfy the required minimum Lc value for the font.

Convert from a RGB object to a RGB triplet.

Flooring that allows for arbitrary precision.

A utility function for looking up the contrast data for a font size.

A utility function for looking what font sizes work for a specific, supported contrast.

Parse a string into a RGB color. Invalid input will return a [NaN, NaN, NaN] RGB triplet. If the input can be malformed, check after parsing with the isValidColor function.

Checks if any of the values in an RGB triplet is NaN

Rounding that allows for arbitrary precision.

Convert a RGB triplet into its hex string representation.

This function calculates the contrast and whether two colors used together are readable based on WCAG readability criteria. The first color is the foreground color and the second the background color (defaulting to pure white, "#FFF" / [255, 255, 255]).

This function calculates the contrast value between two colors based on WCAG contrast readability criteria. The first color is the foreground color and the second the background color (defaulting to pure white, "#fff" / [255, 255, 255]).

This function determines whether two colors used together are readable based on WCAG readability criteria. The first color is the foreground color and the second the background color (defaulting to pure white, "#fff" / [255, 255, 255]).

Type Aliases

Type alias for a RGB triplet (an array of only three numbers);

Utility type for when you have RGB colors in an object.

Modifiers for a Lc rating:

The Lc rating of a contrast value: