cvdsafe

v0.2.0
io.github.vince-gonzalez/cvdsafe Checked 2 days ago Published 3 months ago

Check if a palette or image is colorblind-safe, generate safe palettes, check WCAG contrast.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

checkPalette Check a color palette for colorblind-safety

Check whether a set of colors stays distinguishable for people with color-vision deficiency (colorblindness). Simulates protanopia, deuteranopia and tritanopia and flags the pairs whose perceptual difference collapses under simulation. A screening aid, not a legal accessibility (ADA/WCAG) audit.

ParameterTypeDescription
colors *arrayHex colors to check together, e.g. ["#d7191c","#1a9641","#2166ac"]

simulateColor Simulate a color under colorblindness

Return how a single hex color appears to someone with a given type of color blindness (protan, deutan, or tritan).

ParameterTypeDescription
color *stringHex color, e.g. #d7191c
type *stringColor-vision deficiency type

fixPalette Fix a palette to be colorblind-safe

Take a set of colors that fails the colorblind-safety check and return an adjusted set that passes, staying as close to the originals as possible. Conflicting colors are separated in lightness (the axis color-vision deficiency preserves). Returns the new colors, how far each moved, and whether it fully passes.

ParameterTypeDescription
colors *arrayHex colors to fix, e.g. ["#d7191c","#1a9641"]

checkContrast Check text/background contrast against WCAG

Check whether a foreground color is legible on a background color per WCAG 2.x contrast ratios. Returns the ratio (1-21) and whether it passes AA and AAA. Set large=true for text >=18pt (or 14pt bold). This is the legibility axis, separate from color-blindness.

ParameterTypeDescription
background *stringBackground hex color, e.g. #ffffff
foreground *stringText/foreground hex color, e.g. #767676
largebooleanTrue if text is >=18pt or 14pt bold (default false)

checkImage Check an image for colorblind-safety

Check whether the colors in an image, chart, screenshot or mockup stay distinguishable for people with color-vision deficiency. Extracts the image's dominant colors, simulates protanopia, deuteranopia and tritanopia, and flags the color pairs that collapse into each other — each with how much of the image's area those colors cover, so a conflict between two large regions ranks above one between two specks. Reads PNG and JPEG. Pass `path` for a local file, or a base64 `dataUri`. Set returnSimulated=true to also get back the image as a deuteranope sees it. A screening aid, not a legal (ADA/WCA…

ParameterTypeDescription
dataUristringBase64 data URI of the image, if you don't have a file path
maxColorsintegerHow many dominant colors to extract and test (default 12)
pathstringPath to a local PNG or JPEG file, e.g. ./dashboard.png
returnSimulatedbooleanAlso return the image recolored as a deuteranope sees it (default false)
simulateTypestringWhich deficiency to render when returnSimulated is set (default deutan)

generateSafePalette Generate a colorblind-safe palette

Return N colorblind-safe hex colors — distinct to each other under protanopia, deuteranopia and tritanopia. Seeded with the Okabe-Ito palette and safely extended above eight. Use when asked for accessible / colorblind-safe / colorblind-friendly colors for a chart, plot, map or UI. Never returns an unsafe color.

ParameterTypeDescription
count *integerHow many colorblind-safe colors to return