ExcessibilityStorybook.Color (excessibility_storybook v0.1.0)

Copy Markdown View Source

CSS color parsing and contrast math.

Colors are {r, g, b} tuples of gamma-encoded sRGB in 0.0..1.0. Out-of-gamut oklch values are clipped per channel, which is what browsers do too.

Summary

Functions

APCA lightness contrast (Lc), apca-w3 0.0.98G-4g. Order matters: text first. Positive is dark text on light, negative is light text on dark.

WCAG 2.x contrast ratio, 1.0..21.0. Order doesn't matter.

Types

rgb()

@type rgb() :: {float(), float(), float()}

Functions

apca_lc(text, background)

@spec apca_lc(rgb(), rgb()) :: float()

APCA lightness contrast (Lc), apca-w3 0.0.98G-4g. Order matters: text first. Positive is dark text on light, negative is light text on dark.

parse(css)

@spec parse(String.t()) :: {:ok, rgb()} | :error

wcag_ratio(a, b)

@spec wcag_ratio(rgb(), rgb()) :: float()

WCAG 2.x contrast ratio, 1.0..21.0. Order doesn't matter.