Skip to content

feat: add a colour palette generator and colour checks - #149

Merged
ViktorMikhalkin merged 23 commits into
mainfrom
loop/issue-140
Dec 2, 2026
Merged

ViktorMikhalkin merged 23 commits into
mainfrom
loop/issue-140

Conversation

@ViktorMikhalkin

@ViktorMikhalkin ViktorMikhalkin commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What changes for users

Add the independent @metronforge/concept-map/color entry with palette,
checkColors and ColorError. Hosts can generate deterministic light and dark
themes, keep exact layer colours or accents, check an existing theme, and emit
CSS rules with toCss.

Each theme has neutral background, node, text and border roles, categorical
layer colours, and one accent reserved for the current step. Text needs WCAG
contrast of 4.5:1 and meaningful lines need 3:1. Layer pairs and layer–accent
pairs are checked in OKLab under normal vision and three Machado simulations.
Distances below 0.04 are hard defects; below 0.06 are advice. Ghost text and
lines keep floors of 2:1 and 1.3:1 and the ghost < normal ≤ current contrast
order. WCAG contrast is the only contrast measure. Strict checking throws on hard defects;
invalid hex colours name the affected path.

APCA code, its public metric and its tests were removed before publication
because its licence restrictions are incompatible with the MIT package.
The raw catalogue and research-only scripts were removed too. The full research
and its scripts remain on archive/colour-catalogue-140 at commit 040827a.
A findings summary retains the counts and default defect. Three scripts
reproduce that summary and the palette reports, using frozen book inputs
restored from the archive into an ignored cache. No script writes the raw
catalogue into the tracked evidence folder.

Why

Normal text contrast alone misses colours that become alike under a colour
vision deficiency. The frozen book inventory gives these findings:

Finding Light Dark
Layer–accent hard confusion 18/82 pairs 8/82 pairs
Layer–accent hard confusion under one simulation alone 18/82, deuteranopia 8/82, tritanopia
Layer–layer hard confusion 41/123 pairs 21/123 pairs
Hard layer pairs that pass the normal-vision hard band 39/123 pairs 19/123 pairs
Lane labels below 4.5:1 0/67 labels 0/67 labels

These are repeated role-pair cases across maps, not independent colours or
readers. All ten examples and 18 of 23 book maps use at most four layers, so
four-layer separation matters most.

The generator scores all four vision models. The comparison enumerates every
subset of the book's nine existing layer ids for each count and selects the
subset with the greatest worst distance, keeping the book accent. Generated
palettes beat even this strongest reference at every count from two to six.
The fixed-accent variant keeps the book's exact accent on the generated bases.

Layers Book best light / dark Generated light / dark Generated with book accent light / dark
2 0.087886 / 0.081334 0.212478 / 0.144391 0.184557 / 0.155332
3 0.048920 / 0.055116 0.135026 / 0.117923 0.161292 / 0.128888
4 0.039602 / 0.042278 0.113704 / 0.103254 0.124394 / 0.115422
5 0.032105 / 0.025725 0.092164 / 0.103491 0.098991 / 0.087978
6 0.015611 / 0.022466 0.097307 / 0.087231 0.070091 / 0.076822

Each number is the minimum across all layer pairs, layer–accent pairs and
all four vision models. All 20 generated comparison themes have no hard defects.
The reproducible report includes each model separately and the selected book
subset, rather than assuming that normal vision predicts the simulations.

The light search includes L=0.30 because the original grid missed its four-layer
target. Out-of-gamut generated accents reduce chroma; layer candidates outside
sRGB are rejected. No checker thresholds change. Default four-, six- and
eight-layer results exceed all six prototype targets.

Evidence

  • npm run verify: passes completely, including formatting, lint, types,
    dependency rules, build, schema, 172 test files / 1,478 tests, API reports,
    contract guards, size limits, package checks and demo build. The previous
    sandbox subprocess failures are absent; architecture tests pass unchanged.
  • npx vitest run --exclude test/unit/architecture.test.ts: 171 files and
    1,470 tests pass as an additional check. Source and API reports have no APCA.
  • node scripts/colour-findings.mjs --check: 60 finding counts, 24 layer
    distribution rows and the known default defect reproduce. An independent
    comparison matches every count against the archived reports. A stale-count
    probe fails as expected, and check mode preserves all three evidence files.
  • node scripts/colour-palette.mjs --check: 28 theme/fixed-layer cases and
    two fixed-accent fallbacks pass without hard defects.
  • node scripts/colour-palette-comparison.mjs --check: 10 best book subsets
    and 20 generated themes; all generated worst distances beat the reference.
    All 30 table rows are unchanged by the catalogue removal.
  • npm run size -- --json: colour entry 3,416 B gzip, limit 3,518 B
    (102 B margin, below 3%). APCA removal saved 143 B. Catalogue removal changes
    none of the 12 entry sizes. Element/player/server/root remain
    32,976 / 16,959 / 4,385 / 16,915 B.
  • Removed 884 raw catalogue files (2,143,525 B) and reduced the remaining colour
    scripts from 13 to three. The 271-line findings script keeps its report
    template and reproduction instructions beside the calculations.
  • Full Chromium: all 176 tests pass against the finished demo build.
    The initial concurrent run passed 174/176; two module fetches failed while
    verification replaced the demo output. Running after the build resolves both.
    No browser tests or checks changed. Fresh logs:
    /tmp/colour-140-iteration-1-verify.log and
    /tmp/colour-140-iteration-1-chromium-final.log.
  • No runtime rendering or CSS changes; no screenshots required.

Not done

The raw catalogue is excluded from this branch and remains preserved on
archive/colour-catalogue-140 at 040827a; that branch was not touched.
All local acceptance checks pass, including the full Chromium suite and the
unchanged architecture tests.

Lane labels still use the current drawing. Moving them to neutral text with a
layer swatch is a separate visible change: generated layer colours promise
line contrast, not lane-label text contrast. The current fallback/accent pair's
hard tritanopia defect (0.036455690) remains recorded and pinned by a test;
replacing defaults is separate. One-layer generation with an exact accent
already supplies candidates for that work.

Fixed host colours are preserved, so arbitrary supplied colours can still
fail checks. Combined painted states and route-dependent token contrast remain
outside the completed catalogue scope. The colour entry checks supplied roles;
it does not inspect the CSS cascade or SVG. Firefox and WebKit were not run
locally because no browser-specific behaviour changes; CI remains the check
across all three browsers before merge.

Changelog

BEGIN_COMMIT_OVERRIDE
feat: add a colour palette generator and colour checks
END_COMMIT_OVERRIDE

@ViktorMikhalkin
ViktorMikhalkin marked this pull request as ready for review December 2, 2026 23:49
@ViktorMikhalkin
ViktorMikhalkin merged commit ceca1f7 into main Dec 2, 2026
7 checks passed
@ViktorMikhalkin
ViktorMikhalkin deleted the loop/issue-140 branch December 2, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant