Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
08f58e3
refactor: add colour measurements for palette checks
ViktorMikhalkin Dec 2, 2026
df3c2f3
feat: add core checks for host colour themes
ViktorMikhalkin Dec 2, 2026
88e0586
docs: catalogue local map colours and layer counts
ViktorMikhalkin Dec 2, 2026
b45a38c
docs: catalogue book map colours in both themes
ViktorMikhalkin Dec 2, 2026
5c238b7
docs: measure contrast of local ghost marks
ViktorMikhalkin Dec 2, 2026
ce69361
docs: catalogue book ghost colours in both themes
ViktorMikhalkin Dec 2, 2026
e1c957d
docs: measure current map colours and contrast order
ViktorMikhalkin Dec 2, 2026
98d8647
feat: report informational APCA contrast for host colours
ViktorMikhalkin Dec 2, 2026
eb08d53
docs: report contrast for ghost and current colours
ViktorMikhalkin Dec 2, 2026
392f92e
docs: measure normal and ghost frame colours
ViktorMikhalkin Dec 2, 2026
5fd1809
docs: catalogue status text and special node colours
ViktorMikhalkin Dec 2, 2026
344aad5
docs: count colour conflicts and layer usage
ViktorMikhalkin Dec 2, 2026
93ff56c
docs: count contrast and order findings for painted colours
ViktorMikhalkin Dec 2, 2026
76f6662
feat(color): generate distinct layer colours for both themes
ViktorMikhalkin Dec 2, 2026
3983d22
feat: preserve host accents when generating layer colours
ViktorMikhalkin Dec 2, 2026
aa5589f
feat: expose colour palettes and checks with css output
ViktorMikhalkin Dec 2, 2026
ec6418b
docs: catalogue persistent failure node colours
ViktorMikhalkin Dec 2, 2026
7755417
docs: count contrast failures on failure nodes
ViktorMikhalkin Dec 2, 2026
bc7edf4
docs: record token and glow colour contrast
ViktorMikhalkin Dec 2, 2026
ebfd583
docs: count token contrast findings across colour sets
ViktorMikhalkin Dec 2, 2026
040827a
feat: add a colour palette generator and colour checks
ViktorMikhalkin Dec 2, 2026
e0f07ef
chore: remove apca from the published colour checks
ViktorMikhalkin Dec 2, 2026
77611ca
docs: retain colour findings without the raw catalogue
ViktorMikhalkin Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dependency-cruiser.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
module.exports = {
forbidden: [
{
name: "color-only-color",
severity: "error",
from: { path: "^src/color/" },
to: { path: "^src/", pathNot: "^src/color/" },
},
{
name: "color-is-independent",
severity: "error",
from: { path: "^src/", pathNot: "^src/color/" },
to: { path: "^src/color/" },
},
{
name: "dom-no-element",
severity: "error",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ output/

# Agent loop state (scripts/agent-loop)
.loop/

# Archived colour research inputs
.cache/colour/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ source-map.schema.json
etc
test/fixtures
CHANGELOG.md

.cache/colour
7 changes: 7 additions & 0 deletions .size-limit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// Size Limit externalizes peer dependencies by default. Measure actual consumer bytes.
// Margin = min(1000 B, 3% of measured gzip), rounded down.
const cases = [
{
name: "colour palette and checks (without DOM or Zod)",
path: "dist/color/index.js",
gzip: true,
// Measured 3416 B + 102 B margin.
limit: "3518 B",
},
{
name: "web component (pre-resolved map; with Zod)",
path: "dist/element.js",
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ and [automatic layout](docs/LAYOUT.md).
Framework examples: [React](docs/frameworks/react.md),
[Vue](docs/frameworks/vue.md), and [Svelte](docs/frameworks/svelte.md).

## Choose and check colours

Generate light and dark palettes or check host colours with the independent
[`@metronforge/concept-map/color` entry](docs/COLOR.md). It emits CSS custom
properties without loading the player, layout engines or Zod.

All ten examples and 18 of 23 book maps use at most four layers. The measured
lane labels pass text contrast, but some layer pairs and layer–accent pairs
become hard to tell apart under simulated colour vision deficiencies. The
generator checks all four vision models. Its two- through six-layer palettes
beat the book's existing colours, including when the book accent stays fixed.
See the [comparison and measured distances](docs/evidence/colour/palette-comparison.md).
Applying a palette is an explicit host choice; lane labels and CSS defaults
are unchanged.

## Lay out on the server

Install the optional engine with `npm install @dagrejs/dagre`. Read the source
Expand Down
61 changes: 61 additions & 0 deletions docs/COLOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Colour palettes and checks

Import the independent core entry in Node or a browser:

```ts
import {
palette,
checkColors,
ColorError,
} from "@metronforge/concept-map/color";

const p = palette(["client", "server", "queue"], {
fixed: { light: { server: "#753646" } },
accentHue: 255,
});
const css = p.toCss({ light: ".map-ui", dark: "[data-theme=dark] .map-ui" });
const report = checkColors(p.light);
```

`p.light` and `p.dark` each contain neutral `base` roles (`bg`, `node`, `fg`,
`mutedFg`, `border`), one reserved `accent`, and a `layers` record. The search
is deterministic for the same ordered layer ids and options. Ids must be unique
and follow the map identifier grammar: a letter, then letters, digits, `_` or `-`.
Empty lists are allowed. Generated colours are lower-case six-digit sRGB hex.
Fixed colours retain their spelling and participate in the search. They are
not repaired; check the result when supplying host colours.

`accentHue` is an OKLCH angle in degrees (default 255; whole turns wrap).
To preserve an exact host accent, pass `accent: { light: "#285bb5" }` and/or
`accent.dark`. Its measured hue determines the layer exclusion window in that
theme. The generator accepts `#rgb` and `#rrggbb`, as does the checker.

`toCss` returns two rules using the supplied selectors verbatim. It emits the
existing background, node, foreground, muted foreground, border, accent and
per-layer custom properties. Add the text to a host stylesheet. It does not
apply styles or change the library's defaults. Selectors are trusted stylesheet
source supplied by the host.

`checkColors(theme)` returns `defects` and `metrics`. It checks opaque colours:
text needs WCAG contrast 4.5:1, meaningful lines need 3:1, and layer–layer and
layer–accent distances use the minimum OKLab distance across normal vision
and Machado protanopia, deuteranopia and tritanopia simulations. Distances below
0.04 are hard defects; below 0.06 are advice. More than six layers adds advice.
Optional `ghost: { text, line }` roles need 2:1 and 1.3:1 respectively and must
keep ghost contrast below normal contrast, with normal no higher than current.

Invalid colour values throw `ColorError` with a `path`. With
`checkColors(theme, { strict: true })`, hard defects also throw `ColorError`,
with the full report on `error.report`. Advice alone never throws.

Layer colours are intended for lines and marks with area. Lane labels still
use layer colours in the current renderer and can require more contrast than
these palettes guarantee. Moving lane labels to the text colour and adding a
swatch is a separate drawing change. Painted states, transparency and status
colours also need their own checks; this entry does not inspect CSS or SVG.
Today's fallback layer and accent have a known hard distance defect, recorded
in the [colour findings](evidence/colour/README.md). Generating a
palette does not silently replace those defaults.

See the [generated palette measurements](evidence/colour/palette.md) for
2–8-layer results, fixed-colour cases, targets and search decisions.
34 changes: 34 additions & 0 deletions docs/CSS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ There is no built-in layer list or special case for a layer named `app`.
}
```

## Generate or check a host palette

The independent `@metronforge/concept-map/color` entry generates neutral base
roles, layer colours and a reserved current-step accent for light and dark themes:

```ts
import { palette, checkColors } from "@metronforge/concept-map/color";

const p = palette(["service", "guest"]);
const css = p.toCss({ light: ".map-ui", dark: "[data-theme=dark] .map-ui" });
const report = checkColors(p.light);
```

Add `css` to the host stylesheet. The two rules set `--cmap-bg`, `--cmap-node`,
`--cmap-fg`, `--cmap-muted-fg`, `--cmap-border`, `--cmap-accent` and each
`--cmap-layer-<id>`. Other properties above keep their existing values. Selectors
are trusted stylesheet text. The function returns text and does not insert it.

The checker requires 4.5:1 for text roles and 3:1 for meaningful lines. It
measures layer–layer and layer–accent separation under normal vision and three
colour vision deficiency simulations: below 0.04 OKLab distance is a hard
defect, below 0.06 is advice. APCA Lc is informational. Host colours can be
checked directly; fixed generator colours remain as supplied and may fail.
See [the colour API](COLOR.md) for fixed colours, exact accents and strict errors.

The measured book lane labels pass text contrast; its colour pairs can still
be confused under simulation. Generated layers are intended for lines and
marks with area, so lane labels need a separate drawing change before they
can use these palettes without their own text contrast check. Today's fallback
layer and accent retain their recorded hard separation defect. Generating CSS
does not replace the defaults automatically.

## Existing host integration

The old named properties (for example `--cmap-<old-layer>`) and internal aliases
(for example `--client`), and concept references to `--pw-*`, are removed.
Hosts can map existing colours to `--cmap-layer-<id>` themselves. `--c` and
Expand Down
6 changes: 3 additions & 3 deletions docs/adr/0030-perceptual-colour.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Status: accepted (approved by the author by merging the pull request that set
this status). The author chose a generator in the library, and WCAG 2 as the
hard norm with APCA for information only; the ghost rules were delegated.
hard norm; the ghost rules were delegated.

## Context

Expand Down Expand Up @@ -58,8 +58,8 @@ layer hues.
OKLab. Colours are emitted as sRGB hex for compatibility.

**Contrast.** WCAG 2.2 is the hard norm: 4.5:1 for text (1.4.3), 3:1 for
lines and marks that carry meaning (1.4.11). APCA Lc values are reported for
information only, because WCAG 3 is a draft.
lines and marks that carry meaning (1.4.11).
APCA was dropped for licence reasons; WCAG contrast is the only contrast measure.

**Not colour alone (1.4.1).** Every layer keeps a text label. Lane labels
use the text colour; the layer colour moves to marks with area (lane tint,
Expand Down
172 changes: 172 additions & 0 deletions docs/evidence/colour/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Colour findings and palette measurements

The raw catalogue and its original research scripts are preserved on
`archive/colour-catalogue-140`, commit `040827a`. They are deliberately excluded
from this branch. The frozen book inputs record stylesheet and map hashes in
`book-input/provenance.json`; the site checkout was read only. These are source
colour measurements, not a deployed-site or browser-cascade audit.

## Reproduce

From the repository root, restore only the archived inputs to the ignored cache:

```sh
mkdir -p .cache/colour/archive
git archive 040827a docs/evidence/colour/catalogue/book-input | tar -x -C .cache/colour/archive
npm run build
node scripts/colour-findings.mjs --check
node scripts/colour-palette.mjs --check
node scripts/colour-palette-comparison.mjs --check
npm run size
```

Omit `--check` to update the corresponding summary, never the raw catalogue.
`scripts/colour-findings.mjs` reproduces every number in the two tables below
and the default defect. It reads the archived book inputs and current local
examples and CSS. To inspect historical raw rows, use `git show
040827a:docs/evidence/colour/catalogue/patterns/opaque.md` and
`git show 040827a:docs/evidence/colour/catalogue/patterns/layers.md`.
The archive also holds the painted-state reports and their reproduction scripts;
those broader research inventories are not required by these summaries.

## Counted findings

Counts are role-pair cases repeated across map, host and theme contexts, not
independent colours, readers or visible-object counts. Local includes defaults,
standalone examples and comparison hosts; light and dark reuse the same colours
because these hosts have no dark override. Book themes have separate colours.
Lane text is checked against its 6% layer / 94% background fill in encoded sRGB.

| Context | Finding | Affected cases |
| -------------------------------- | ------------------------------------------- | -------------- |
| book light | layer–accent hard | 18 out of 82 |
| book light | layer–accent advice only | 16 out of 82 |
| book light | layer–accent hard only under simulation | 18 out of 82 |
| book light | layer–accent hard under protanopia alone | 0 out of 82 |
| book light | layer–accent hard under deuteranopia alone | 18 out of 82 |
| book light | layer–accent hard under tritanopia alone | 0 out of 82 |
| book light | layer–layer hard | 41 out of 123 |
| book light | layer–layer advice only | 25 out of 123 |
| book light | layer–layer hard only under simulation | 39 out of 123 |
| book light | layer–layer hard under protanopia alone | 0 out of 123 |
| book light | layer–layer hard under deuteranopia alone | 10 out of 123 |
| book light | layer–layer hard under tritanopia alone | 25 out of 123 |
| book light | lane text below 4.5:1 | 0 out of 67 |
| book light | opaque role contrast below its minimum | 0 out of 348 |
| book light | contexts with more than six declared layers | 0 out of 23 |
| local (including defaults) light | layer–accent hard | 21 out of 21 |
| local (including defaults) light | layer–accent advice only | 0 out of 21 |
| local (including defaults) light | layer–accent hard only under simulation | 21 out of 21 |
| local (including defaults) light | layer–accent hard under protanopia alone | 0 out of 21 |
| local (including defaults) light | layer–accent hard under deuteranopia alone | 0 out of 21 |
| local (including defaults) light | layer–accent hard under tritanopia alone | 21 out of 21 |
| local (including defaults) light | layer–layer hard | 3 out of 3 |
| local (including defaults) light | layer–layer advice only | 0 out of 3 |
| local (including defaults) light | layer–layer hard only under simulation | 0 out of 3 |
| local (including defaults) light | layer–layer hard under protanopia alone | 0 out of 3 |
| local (including defaults) light | layer–layer hard under deuteranopia alone | 0 out of 3 |
| local (including defaults) light | layer–layer hard under tritanopia alone | 0 out of 3 |
| local (including defaults) light | lane text below 4.5:1 | 0 out of 3 |
| local (including defaults) light | opaque role contrast below its minimum | 0 out of 186 |
| local (including defaults) light | contexts with more than six declared layers | 0 out of 18 |
| book dark | layer–accent hard | 8 out of 82 |
| book dark | layer–accent advice only | 10 out of 82 |
| book dark | layer–accent hard only under simulation | 8 out of 82 |
| book dark | layer–accent hard under protanopia alone | 0 out of 82 |
| book dark | layer–accent hard under deuteranopia alone | 0 out of 82 |
| book dark | layer–accent hard under tritanopia alone | 8 out of 82 |
| book dark | layer–layer hard | 21 out of 123 |
| book dark | layer–layer advice only | 49 out of 123 |
| book dark | layer–layer hard only under simulation | 19 out of 123 |
| book dark | layer–layer hard under protanopia alone | 3 out of 123 |
| book dark | layer–layer hard under deuteranopia alone | 6 out of 123 |
| book dark | layer–layer hard under tritanopia alone | 10 out of 123 |
| book dark | lane text below 4.5:1 | 0 out of 67 |
| book dark | opaque role contrast below its minimum | 0 out of 348 |
| book dark | contexts with more than six declared layers | 0 out of 23 |
| local (including defaults) dark | layer–accent hard | 21 out of 21 |
| local (including defaults) dark | layer–accent advice only | 0 out of 21 |
| local (including defaults) dark | layer–accent hard only under simulation | 21 out of 21 |
| local (including defaults) dark | layer–accent hard under protanopia alone | 0 out of 21 |
| local (including defaults) dark | layer–accent hard under deuteranopia alone | 0 out of 21 |
| local (including defaults) dark | layer–accent hard under tritanopia alone | 21 out of 21 |
| local (including defaults) dark | layer–layer hard | 3 out of 3 |
| local (including defaults) dark | layer–layer advice only | 0 out of 3 |
| local (including defaults) dark | layer–layer hard only under simulation | 0 out of 3 |
| local (including defaults) dark | layer–layer hard under protanopia alone | 0 out of 3 |
| local (including defaults) dark | layer–layer hard under deuteranopia alone | 0 out of 3 |
| local (including defaults) dark | layer–layer hard under tritanopia alone | 0 out of 3 |
| local (including defaults) dark | lane text below 4.5:1 | 0 out of 3 |
| local (including defaults) dark | opaque role contrast below its minimum | 0 out of 186 |
| local (including defaults) dark | contexts with more than six declared layers | 0 out of 18 |

Hard means worst OKLab distance below 0.04; advice only is 0.04 to below 0.06.
Simulation-only hard pairs pass the normal-vision hard band, but may fail under
several simulations. A failure under one simulation alone passes the hard band
under normal vision and both other simulations. No checker bands were changed.

Book lane text contrast fails in 0 out of 67 cases per theme. The main problem
is colour confusion: book layer–accent failures occur under deuteranopia alone
in light and tritanopia alone in dark. Many layer–layer hard failures also pass
normal vision. Normal text contrast therefore cannot stand in for these checks.

## Layer counts

Each source map is counted once. Used means referenced by nodes, lanes or
concept groups. Book fixtures are not counted again alongside source maps.

| Inventory | Layers | Range | Affected maps |
| ----------- | -------- | ------------- | ------------- |
| examples | declared | exactly 1 | 7 out of 10 |
| examples | declared | exactly 2 | 3 out of 10 |
| examples | declared | at most four | 10 out of 10 |
| examples | declared | more than six | 0 out of 10 |
| examples | used | exactly 1 | 7 out of 10 |
| examples | used | exactly 2 | 3 out of 10 |
| examples | used | at most four | 10 out of 10 |
| examples | used | more than six | 0 out of 10 |
| book source | declared | exactly 1 | 2 out of 23 |
| book source | declared | exactly 2 | 2 out of 23 |
| book source | declared | exactly 3 | 6 out of 23 |
| book source | declared | exactly 4 | 8 out of 23 |
| book source | declared | exactly 5 | 4 out of 23 |
| book source | declared | exactly 6 | 1 out of 23 |
| book source | declared | at most four | 18 out of 23 |
| book source | declared | more than six | 0 out of 23 |
| book source | used | exactly 1 | 2 out of 23 |
| book source | used | exactly 2 | 2 out of 23 |
| book source | used | exactly 3 | 6 out of 23 |
| book source | used | exactly 4 | 8 out of 23 |
| book source | used | exactly 5 | 4 out of 23 |
| book source | used | exactly 6 | 1 out of 23 |
| book source | used | at most four | 18 out of 23 |
| book source | used | more than six | 0 out of 23 |

All examples and most book maps use at most four layers, making four-layer
separation the priority. The generator still measures the larger counts.

## Known default defect

The library fallback `#526a8a` and accent `#285bb5` have exactly one hard
checker defect, `indistinct`, and no others. The same defaults apply in both
modes. Their four distances, reproduced by `scripts/colour-findings.mjs`, are:

| Normal | Protanopia | Deuteranopia | Tritanopia | Worst model |
| ----------- | ----------- | ------------ | ----------- | ----------- |
| 0.099688426 | 0.096414599 | 0.111558507 | 0.036455690 | tritanopia |

A unit test pins this defect. Replacing the CSS defaults is separate work.

## Generated results and scope

[Palette measurements](palette.md), produced by `scripts/colour-palette.mjs`,
cover two through eight layers with and without one fixed layer, plus one-layer
fixed-accent fallback candidates. [Book comparison](palette-comparison.md),
produced by `scripts/colour-palette-comparison.mjs`, covers two through six
layers under all four vision models, with generated and exact book accents.
That script reads the same archived theme inputs. Gzip size comes from
`npm run size`; the colour entry has its own limit.

APCA was removed for licence reasons; WCAG contrast is the only contrast
measure. Lane-label rendering, CSS defaults and SVG remain unchanged. Combined
painted states and route-dependent token contrast are outside this task.
Loading
Loading