Snippet

WCAG self-correction algorithm

A small JS/PHP pair that given any (foreground, background) returns the nearest variant that passes AA / AAA contrast.

A small JS/PHP pair that, given any foreground and background colour, returns the nearest variant that passes WCAG AA (4.5:1) or AAA (7:1) contrast — the exact self-correction this theme uses to keep derived palettes legible.

What’s in it

wcag-contrast.php and a matching wcag-contrast.js: relative_luminance(), contrast_ratio(), and pick_on_color() (auto-nudges the foreground until it clears the target), each with a runnable self-check.