burgee
API reference

burgee/contrast

Every export of burgee/contrast, with its signature and doc comment: mix, ratio, check, report, fieldColorAt, auditBurgee and 3 more, plus 2 types.

Contrast, as a thing the package checks rather than a thing someone remembers.

import { mix, ratio, check, … } from 'burgee/contrast';

Functions

auditBurgee

Every contrast relationship a burgee has to survive.

function auditBurgee(brand: AuditInput, grounds?: readonly string[]): ContrastFinding[];
ParameterType
brandAuditInput
grounds (optional)readonly string[]

Returns ContrastFinding[]

check

function check(what: string, a: string, b: string, required?: 3): ContrastFinding;
ParameterType
whatstring
astring
bstring
required (optional)3

Returns ContrastFinding

contrast

The WCAG contrast ratio between two colours. Order does not matter.

function contrast(a: string, b: string): number;
ParameterType
astring
bstring

Returns number

fieldColorAt

The field colour at a point along the gradient axis, for stops given in order.

function fieldColorAt(stops: ReadonlyArray<{
    offset: number;
    color: string;
}>, at: number): string;
ParameterType
stopsReadonlyArray<{ offset: number; color: string; }>
atnumber

Returns string

luminance

WCAG relative luminance.

function luminance(hex: string): number;
ParameterType
hexstring

Returns number

mix

Mix two colours in sRGB. Enough for reading a gradient stop, not for colour science.

function mix(a: string, b: string, t: number): string;
ParameterType
astring
bstring
tnumber

Returns string

ratio

Round to 2dp for reporting, without pretending to more precision than that — roundel's round2.

function ratio(a: string, b: string): number;
ParameterType
astring
bstring

Returns number

report

One line per finding, aligned, for a terminal or a failing test.

function report(findings: readonly ContrastFinding[]): string;
ParameterType
findingsreadonly ContrastFinding[]

Returns string

Constants

AA

The floors WCAG 2.2 sets, as ratios.

const AA: {
    /** Body text against its background. */
    readonly TEXT: 4.5;
    /** Large text, UI components, and meaningful parts of a graphic. */
    readonly GRAPHIC: 3;
};

Interfaces

AuditInput

interface AuditInput {
    mark: {
        lead: string;
        follow: string;
    };
    field: ReadonlyArray<{
        offset: number;
        color: string;
    }>;
    bordure?: {
        color: string;
        width: number;
    } | ReadonlyArray<{
        color: string;
        width: number;
    }>;
}

ContrastFinding

interface ContrastFinding {
    /** What was compared, in the words someone fixing it would use. */
    what: string;
    a: string;
    b: string;
    ratio: number;
    required: number;
    passes: boolean;
}

On this page