Vision Palettes

Extra palettes for people who see colour differently (red–green, blue–yellow, monochrome, high contrast), generated, measured and picked by the visitor.

About one man in twelve and one woman in two hundred sees colour differently. On a palette built for typical vision, their success and danger can be the same colour, and a filled button can lose its label. Cortex does not fix that by changing your palette. It generates second palettes beside it, ships them in the same stylesheet, and lets each visitor pick the one that fits.

PaletteFor
red-greenprotanopia and deuteranopia — the common forms
blue-yellowtritanopia
monochromeachromatopsia: no colour at all, only lightness
high-contrastlow vision: aims for text at 7:1 (WCAG AAA), boundaries at 4.5:1

Your palette is never changed. A visitor who picks nothing sees exactly what you designed.

Turn them on

theme-config.json
{
  "seeds": { "primary": "#1D4ED8", "secondary": "#7C3AED", "neutral": "#334155" },
  "vision": { "variants": ["red-green", "blue-yellow", "monochrome", "high-contrast"] }
}

Rebuild theme.css. Each palette is now in it as a block on :root[data-vision="…"] that re-assigns the tokens it changes. The token names are the same — --fp-danger-9 is still --fp-danger-9 — so nothing in your CSS or components changes. All four palettes add about 1.6 KB gzip to the lean theme.

OptionDefaultWhat it does
variants[]The palettes to ship.
attribute"data-vision"The attribute on <html> that picks one. Any data-* name.
autoHighContrasttrueWith high-contrast, also apply it when the system asks for more contrast (prefers-contrast: more) and the page has not picked a palette.
output"inline""separate" writes each palette to its own stylesheet, so a visitor who picks nothing downloads nothing extra.

Let the visitor pick

Set the attribute on <html>. @flexpixels/ui, which is not published yet, has a fp-vision-switch element for this, to put beside the light/dark switch. It offers only the palettes your theme ships, remembers the choice, and follows it across tabs:

html
<fp-theme-switch></fp-theme-switch> <fp-vision-switch></fp-vision-switch>

Light/dark and vision are two separate choices: a visitor can be in the dark scheme and the red–green palette at once.

Without the component it is one line:

js
document.documentElement.dataset.vision = "red-green"; // "default" = your palette, chosen

"default" and no attribute differ in one way: with no attribute, the high-contrast palette follows the operating system’s contrast setting; "default" says the visitor chose your palette and turns that off.

With output: "separate", build each file with generateVisionCSS(config) and give the switch their URL:

html
<fp-vision-switch stylesheet="/theme.vision.{kind}.css"></fp-vision-switch>

How a palette is made

For each palette, Cortex searches for new seeds. It scores each candidate on a model of the fills as that palette’s visitor sees them (the Machado 2009 simulation for red–green and blue–yellow, lightness alone for monochrome), then measures the final palette on the theme it generates.

  • Status colours move freely, inside hues that keep their meaning. Danger stays between magenta and orange (330–60°), warning between orange and yellow (60–110°), success between green and teal (120–215°), info between cyan and violet (200–300°).
  • Your brand is only nudged, so the palette still looks like yours. For red–green and blue–yellow, primary and secondary move by at most 15° of hue and 0.08 of lightness (policy.brand changes both bounds). High contrast keeps their hue and moves lightness by up to 0.15, lowering chroma only where sRGB cannot show it; monochrome makes them grey and moves lightness by up to 0.15.
  • No floor is traded for distance. Every palette is a whole theme with every contrast guarantee of the colour contract. The search ranks candidates first by how many fills lose 4.5:1 against their text as the visitor sees them (7:1 for high contrast); a fill still under its floor is listed in the report. A page lit by ambient light is never made harder to read than yours.
  • The target is a distance: the closest pair of fills at ΔE2000 11 or more (8 for monochrome, where only lightness is left).

Every palette comes with a report: the closest pair before and after, the weakest fill, the colours moved, and anything still short of target, by name. A shortfall is reported, never hidden. With the engine’s default seeds (#4f46e5, #c026d3, #94a3b8) there are three: red–green keeps primary and secondary at ΔE 10.9 (both are brand colours, and the brand bounds stop them short), and high contrast leaves the neutral fill (neutral-9) at 6.01:1 in light and 5.53:1 in dark, because neutral’s step 9 sits on the shared ramp. Other seeds give other shortfalls; the report names them.

See it in the configurator

In the configurator, tick the palettes under Colour → Accessibility variants.

  • Palette in the preview toolbar shows the pages in one.
  • Simulate shows them as a visitor with protanopia, deuteranopia, tritanopia or achromatopsia sees them: try it on your own palette first, then on the adapted one.
  • The Tokens tab has the report.
  • Export offers each palette as its own theme-config.<kind>.json, a standalone theme.

From code and from agents

ts
import { mergeThemeConfig, visionPalettes, generateVisionCSS } from "@flexpixels/cortex";

const config = mergeThemeConfig(json);
for (const palette of visionPalettes(config, ["red-green", "monochrome"])) {
  console.log(palette.kind, palette.seeds, palette.report.met, palette.report.shortfalls);
}

The MCP server has the same: generate_vision_palettes returns each palette’s seeds and report and the snippet to add to theme-config.json. The combined @flexpixels/mcp server in the repository also has validate_contrast_pairing, which checks markup against every palette with vision: true; @flexpixels/cortex-mcp does not.

What it does not do

  • Tints are not pulled apart. The search separates the roles’ solid fills (step 9). Pale tints (steps 1–5) of two roles stay close for every visitor, so a status still needs an icon or a label, never colour alone.
  • Older browsers. The variant blocks need relative colour and light-dark(). A browser without them gets no theme colours at all unless the theme sets output.legacyFallback: true; with it, it shows the base palette’s static fallback, which is AA, and never a variant.
  • Forced colours win. Under Windows high contrast the system’s colours apply and no palette does.