@popcorn245/cornfield 0.42.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/color.js CHANGED
@@ -14,14 +14,36 @@
14
14
  * toHex([r,g,b]) '#rrggbb'
15
15
  *
16
16
  * Read: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` / `rgba()` and `hsl()` / `hsla()` (comma or space syntax, an optional `/ alpha`,
17
- * percentages), `transparent`, the basic colour names, and `color-mix(in srgb, A p%, B [p%])` (of any of these, nested). Anything else
18
- * (`oklch()`, `var()`, `calc()`, `currentcolor`, `auto`) is not read, nor a `color-mix()` nested more than MAX_MIX_DEPTH deep, nor text over MAX_COLOR_CHARS.
17
+ * percentages), `transparent`, the 148 CSS named colours, and `color-mix(in srgb, A p%, B [p%])` (of any of these, nested). Anything else
18
+ * (`oklch()`, `hwb()`, `lab()`, `color()`, the system colours, `var()`, `calc()`, `currentcolor`, `auto`) is not read, nor a `color-mix()` nested more than MAX_MIX_DEPTH deep, nor text over MAX_COLOR_CHARS.
19
19
  */
20
20
 
21
+ /** The 148 CSS named colours (CSS Color 4), as a browser reads them: a name the map draws is a name validate reads */
21
22
  const NAMED = Object.freeze({
22
- black: '#000000', white: '#ffffff', red: '#ff0000', lime: '#00ff00', blue: '#0000ff', yellow: '#ffff00', cyan: '#00ffff', aqua: '#00ffff',
23
- magenta: '#ff00ff', fuchsia: '#ff00ff', gray: '#808080', grey: '#808080', silver: '#c0c0c0', maroon: '#800000', olive: '#808000',
24
- green: '#008000', purple: '#800080', teal: '#008080', navy: '#000080', orange: '#ffa500',
23
+ aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4',
24
+ black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0',
25
+ chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff',
26
+ darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgreen: '#006400', darkgrey: '#a9a9a9',
27
+ darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000',
28
+ darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f',
29
+ darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray: '#696969', dimgrey: '#696969',
30
+ dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc',
31
+ ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', green: '#008000', greenyellow: '#adff2f', grey: '#808080',
32
+ honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa',
33
+ lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff',
34
+ lightgoldenrodyellow: '#fafad2', lightgray: '#d3d3d3', lightgreen: '#90ee90', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a',
35
+ lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de',
36
+ lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000',
37
+ mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371',
38
+ mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970',
39
+ mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000',
40
+ olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98',
41
+ paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd',
42
+ powderblue: '#b0e0e6', purple: '#800080', rebeccapurple: '#663399', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1',
43
+ saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0',
44
+ skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f',
45
+ steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee',
46
+ wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32',
25
47
  });
26
48
 
27
49
  /** How deep `color-mix()` may nest: deeper is not read (a hostile stylesheet cannot make the parser crawl or overflow the stack) */
@@ -71,10 +93,18 @@ function hslToRgb(h, s, l) {
71
93
  return [f(0) * 255, f(8) * 255, f(4) * 255];
72
94
  }
73
95
 
74
- /** The arguments of rgb()/hsl(), comma or space syntax, as [a, b, c, alpha?] strings; null when the shape is wrong */
96
+ /**
97
+ * The arguments of rgb()/hsl() as [a, b, c, alpha?] strings, in one of the two shapes a browser reads: commas throughout (`1, 2, 3, 0.5`), or
98
+ * spaces with the alpha after a slash (`1 2 3 / 0.5`). Null for any other shape (`1 2 3 4`, `1, 2 3`), which the browser does not draw either.
99
+ */
75
100
  function fnParts(args) {
76
- const parts = args.trim().split(/\s*[,/]\s*|\s+/).filter(Boolean);
77
- return parts.length === 3 || parts.length === 4 ? parts : null;
101
+ const t = args.trim();
102
+ if (t.includes(',')) {
103
+ const parts = t.split(/\s*,\s*/);
104
+ return (parts.length === 3 || parts.length === 4) && parts.every((p) => p && !/[\s/]/.test(p)) ? parts : null;
105
+ }
106
+ const m = /^(\S+)\s+(\S+)\s+([^\s/]+)(?:\s*\/\s*(\S+))?$/.exec(t);
107
+ return m && !m.slice(1, 4).some((p) => p.includes('/')) ? m.slice(1, m[4] === undefined ? 4 : 5) : null;
78
108
  }
79
109
 
80
110
  /** @returns {number[] | null} */
package/core/contrast.js CHANGED
@@ -23,8 +23,9 @@ import path from 'node:path';
23
23
  import { fileURLToPath } from 'node:url';
24
24
  import { MAX_MIX_DEPTH, readColor, over, toHex, luminance, ratio, splitTop } from './color.js';
25
25
  import { MAX_THEME_BYTES, cssProblems, withoutComments } from './theme.js';
26
- import { NODE_THEMES } from './schema.js';
27
- import { LAYER_KEY_RE, MAX_KEY, parseKindToken } from './layers.js';
26
+ import { MIN_SHAPE_DELTA_E, NODE_SHAPES, NODE_THEMES } from './schema.js';
27
+ import { deltaE2000 } from './delta-e.js';
28
+ import { LAYER_KEY_RE, MAX_KEY, mapFillNames, parseKindToken } from './layers.js';
28
29
  import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, markOpacity } from '../explorer/diff-marks.js';
29
30
  import { lightColor } from '../explorer/theme-model.js';
30
31
 
@@ -310,7 +311,7 @@ function origin(props, name) {
310
311
  return at;
311
312
  }
312
313
 
313
- const READS = 'hex, rgb(), hsl(), color-mix(in srgb, …), transparent and the basic colour names';
314
+ const READS = 'hex, rgb(), hsl(), color-mix(in srgb, …), transparent and the CSS named colours';
314
315
 
315
316
  /**
316
317
  * A token (`--corn-text`) or a value (`color-mix(…)`) as `[r, g, b, a]`, or `{ problem }` naming the custom property that could not
@@ -528,7 +529,7 @@ function mapFindings(props, theme, mode, grounds, extra = []) {
528
529
  const strokeOn = isColor(stroke.color) && !(Number.parseFloat(widthText) === 0);
529
530
  for (const type of Object.keys(NODE_THEMES)) {
530
531
  for (const group of MAP_GROUPS_OF(type)) {
531
- const names = [`--corn-map-node-${type}`, `--corn-map-group-${group}`];
532
+ const names = mapFillNames({ type, group }); // the map's own order (a kind and a project layer are checked on their own, below)
532
533
  let name = null;
533
534
  let fill = null;
534
535
  let problem = null;
@@ -555,6 +556,18 @@ function mapFindings(props, theme, mode, grounds, extra = []) {
555
556
  out.push({ ...base, fg: '--corn-map-stroke', bg: weakest.on, min: MAP_FILL_MIN, kind: 'ui', use: `the outline that carries the fill of ${anOf(label)} ${label} node, which is ${fmt(f.ratio)} on its own`, fgValue: onGround.fgValue, bgValue: weakest.value, ratio: weakest.r });
556
557
  }
557
558
  }
559
+ // The ink of a glyph and of a finer kind's letters (spec 0008 D8), when the theme sets one: against every fill it can sit on (`auto` picks white or dark per fill, which a test holds)
560
+ const glyph = mapToken(props, '--corn-map-glyph');
561
+ if (glyph.problem) out.push({ ...base, fg: '--corn-map-glyph', bg: GROUND, min: MAP_FILL_MIN, kind: 'ui', use: 'the ink of a node\'s glyph', problem: glyph.problem });
562
+ else if (glyph.color) {
563
+ for (const type of Object.keys(NODE_THEMES)) {
564
+ const fill = mapFillOf(props, type, mode);
565
+ if (!fill || !isColor(fill.color)) continue;
566
+ const bg = over(fill.color, ground);
567
+ const ink = over(glyph.color, bg);
568
+ out.push({ ...base, fg: '--corn-map-glyph', bg: fill.name, min: MAP_FILL_MIN, kind: 'ui', use: `the glyph on ${anOf(type)} ${type} node`, fgValue: toHex(ink), bgValue: toHex(bg), ratio: ratio(luminance(ink), luminance(bg)) });
569
+ }
570
+ }
558
571
  // The tokens a theme sets for a finer kind (`--corn-map-kind-<type>-<kind>`) and a project layer (`--corn-map-group-<key>`): the same fill
559
572
  // check, for each one the theme sets (an `auto` one draws the type's own colour, which is checked above)
560
573
  for (const name of extra) {
@@ -727,6 +740,56 @@ export function mapExtraTokens(sheets) {
727
740
  return [...declaredProps(sheets)].filter((n) => parseKindToken(n) || projectGroupOf(n)).sort();
728
741
  }
729
742
 
743
+ // ---------------------------------------------------------------------------
744
+ // The map's palette (spec 0008 D8): types that share a silhouette are told apart by colour alone, so they are kept apart
745
+ // ---------------------------------------------------------------------------
746
+
747
+ /** The colour a type's node is drawn in for one page state: its token, else its group's, else its own from core/schema.js (deepened on the light ground); null when it cannot be read */
748
+ function mapFillOf(props, type, mode) {
749
+ for (const group of MAP_GROUPS_OF(type)) {
750
+ for (const name of [`--corn-map-node-${type}`, `--corn-map-group-${group}`]) {
751
+ const t = mapToken(props, name);
752
+ if (t.color) return { color: t.color, name };
753
+ if (t.problem) return null;
754
+ }
755
+ }
756
+ return { color: readColor(mode === 'light' ? lightColor(NODE_THEMES[type].color) : NODE_THEMES[type].color), name: `--corn-map-node-${type}` };
757
+ }
758
+
759
+ /**
760
+ * The pairs of node types that share a silhouette and are under MIN_SHAPE_DELTA_E apart (CIEDE2000) in one theme, on the dark ground and the light.
761
+ * The default palette has none (a test holds it); a theme that sets map colours may.
762
+ * @param {{ theme: string, sheets: string[], name?: string }[]} themes
763
+ * @returns {{ theme: string, mode: string, a: string, b: string, shape: string, deltaE: number }[]}
764
+ */
765
+ export function paletteProblems(themes) {
766
+ const out = [];
767
+ for (const { theme, sheets, name } of themes) {
768
+ for (const mode of ['light', 'dark']) {
769
+ const props = resolveProps(sheets, { mode, system: mode, name });
770
+ const types = Object.keys(NODE_SHAPES).filter((t) => Object.hasOwn(NODE_THEMES, t));
771
+ const fills = new Map(types.map((t) => [t, mapFillOf(props, t, mode)]));
772
+ for (let i = 0; i < types.length; i++) {
773
+ for (let j = i + 1; j < types.length; j++) {
774
+ const [a, b] = [types[i], types[j]];
775
+ if (NODE_SHAPES[a] !== NODE_SHAPES[b]) continue;
776
+ const [fa, fb] = [fills.get(a), fills.get(b)];
777
+ if (!fa || !fb || !isColor(fa.color) || !isColor(fb.color)) continue;
778
+ const d = deltaE2000(fa.color.slice(0, 3), fb.color.slice(0, 3));
779
+ if (d < MIN_SHAPE_DELTA_E) out.push({ theme, mode, a, b, shape: NODE_SHAPES[a], deltaE: d, tokens: [fa.name, fb.name] });
780
+ }
781
+ }
782
+ }
783
+ }
784
+ return out;
785
+ }
786
+
787
+ /** One line for a palette finding: the two types, their tokens and how far apart they are */
788
+ export function describePalette(f) {
789
+ const who = f.theme === 'standard' ? 'standard theme' : `named theme "${f.theme}"`;
790
+ return `${who} (${f.mode}): ${f.a} (${f.tokens[0]}) and ${f.b} (${f.tokens[1]}) share the ${f.shape} silhouette and are ΔE ${f.deltaE.toFixed(1)} apart, under ${MIN_SHAPE_DELTA_E}: the map tells them apart by colour alone, so give one of them a colour further from the other.`;
791
+ }
792
+
730
793
  /** The pairs under their minimum: { fails, unresolved } */
731
794
  export function contrastProblems(themes) {
732
795
  const all = checkSheets(themes);
@@ -805,5 +868,7 @@ export function checkThemeContrast(config) {
805
868
  const lines = fails.map((f) => `theme contrast: ${describeFinding(f)}`);
806
869
  const warnings = unresolved.map((f) => `theme contrast: ${describeFinding(f)}`);
807
870
  const summary = contrastSummary(themes, total, fails.length, unresolved.length);
808
- return (config.theme || {}).contrast === 'warn' ? { errors: [], warnings: [...lines, ...warnings], summary } : { errors: lines, warnings, summary };
871
+ // Types of one silhouette too close in colour (spec 0008 D8): a warning, never an error: a brand picks its own colours
872
+ const palette = paletteProblems(themes).map((f) => `theme map colours: ${describePalette(f)}`);
873
+ return (config.theme || {}).contrast === 'warn' ? { errors: [], warnings: [...lines, ...warnings, ...palette], summary } : { errors: lines, warnings: [...warnings, ...palette], summary };
809
874
  }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @module core/delta-e
3
+ *
4
+ * Colour distance as the eye reads it: CIEDE2000 (ΔE00, Sharma, Wu and Dalal 2005) between two sRGB colours. Pure, no imports. The map holds the
5
+ * built-in palette to it (core/schema.js `MIN_SHAPE_DELTA_E`, spec 0008 D8): two node types that share a silhouette are told apart by colour,
6
+ * so their colours must be far enough apart to be.
7
+ */
8
+
9
+ const toLinear = (c) => { const v = c / 255; return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
10
+
11
+ /** sRGB `[r, g, b]` (0..255) to CIE L*a*b* under D65 */
12
+ export function toLab([r, g, b]) {
13
+ const [lr, lg, lb] = [toLinear(r), toLinear(g), toLinear(b)];
14
+ const x = (0.4124564 * lr + 0.3575761 * lg + 0.1804375 * lb) / 0.95047;
15
+ const y = 0.2126729 * lr + 0.7151522 * lg + 0.072175 * lb;
16
+ const z = (0.0193339 * lr + 0.119192 * lg + 0.9503041 * lb) / 1.08883;
17
+ const f = (t) => (t > 216 / 24389 ? Math.cbrt(t) : (24389 / 27 * t + 16) / 116);
18
+ const [fx, fy, fz] = [f(x), f(y), f(z)];
19
+ return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];
20
+ }
21
+
22
+ const rad = (d) => (d * Math.PI) / 180;
23
+ const deg = (r) => (r * 180) / Math.PI;
24
+
25
+ /** CIEDE2000 between two L*a*b* colours */
26
+ export function deltaE2000Lab(lab1, lab2) {
27
+ const [L1, a1, b1] = lab1;
28
+ const [L2, a2, b2] = lab2;
29
+ const C1 = Math.hypot(a1, b1);
30
+ const C2 = Math.hypot(a2, b2);
31
+ const Cbar = (C1 + C2) / 2;
32
+ const G = 0.5 * (1 - Math.sqrt(Cbar ** 7 / (Cbar ** 7 + 25 ** 7)));
33
+ const a1p = (1 + G) * a1;
34
+ const a2p = (1 + G) * a2;
35
+ const C1p = Math.hypot(a1p, b1);
36
+ const C2p = Math.hypot(a2p, b2);
37
+ const hp = (b, a) => (b === 0 && a === 0 ? 0 : (deg(Math.atan2(b, a)) + 360) % 360);
38
+ const h1p = hp(b1, a1p);
39
+ const h2p = hp(b2, a2p);
40
+ const dLp = L2 - L1;
41
+ const dCp = C2p - C1p;
42
+ let dhp = 0;
43
+ if (C1p * C2p !== 0) {
44
+ dhp = h2p - h1p;
45
+ if (dhp > 180) dhp -= 360; else if (dhp < -180) dhp += 360;
46
+ }
47
+ const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(rad(dhp / 2));
48
+ const Lbp = (L1 + L2) / 2;
49
+ const Cbp = (C1p + C2p) / 2;
50
+ let hbp = h1p + h2p;
51
+ if (C1p * C2p !== 0) {
52
+ if (Math.abs(h1p - h2p) <= 180) hbp /= 2;
53
+ else hbp = (h1p + h2p < 360 ? hbp + 360 : hbp - 360) / 2;
54
+ }
55
+ const T = 1 - 0.17 * Math.cos(rad(hbp - 30)) + 0.24 * Math.cos(rad(2 * hbp)) + 0.32 * Math.cos(rad(3 * hbp + 6)) - 0.2 * Math.cos(rad(4 * hbp - 63));
56
+ const dTheta = 30 * Math.exp(-(((hbp - 275) / 25) ** 2));
57
+ const Rc = 2 * Math.sqrt(Cbp ** 7 / (Cbp ** 7 + 25 ** 7));
58
+ const Sl = 1 + (0.015 * (Lbp - 50) ** 2) / Math.sqrt(20 + (Lbp - 50) ** 2);
59
+ const Sc = 1 + 0.045 * Cbp;
60
+ const Sh = 1 + 0.015 * Cbp * T;
61
+ const Rt = -Math.sin(rad(2 * dTheta)) * Rc;
62
+ return Math.sqrt((dLp / Sl) ** 2 + (dCp / Sc) ** 2 + (dHp / Sh) ** 2 + Rt * (dCp / Sc) * (dHp / Sh));
63
+ }
64
+
65
+ /** CIEDE2000 between two sRGB colours given as `[r, g, b]` (0..255) */
66
+ export const deltaE2000 = (rgb1, rgb2) => deltaE2000Lab(toLab(rgb1), toLab(rgb2));
package/core/layers.js CHANGED
@@ -88,6 +88,14 @@ const TYPE_SET = new Set(NODE_TYPES);
88
88
  export const mapKindToken = (type, kind) => (TYPE_SET.has(type) && typeof kind === 'string' && kind.length <= MAX_KIND_NAME && KIND_NAME_RE.test(kind) ? `--corn-map-kind-${type}-${kind}` : null);
89
89
  /** `--corn-map-group-<key>` for a layer key that passes LAYER_KEY_RE, else null */
90
90
  export const mapGroupToken = (key) => (typeof key === 'string' && key.length <= MAX_KEY && LAYER_KEY_RE.test(key) ? `--corn-map-group-${key}` : null);
91
+ /**
92
+ * The tokens that can fill a node, most specific first (spec 0009 D6): its finer kind, its project layer, its type, its starting group. The one
93
+ * place the order is written: the map (explorer/map-style.js `fillOf`), the Layers menu's dots and `cornfield validate`'s contrast check
94
+ * (core/contrast.js) all read it.
95
+ * @param {{type: string, kind?: unknown, layer?: string | null, group?: string}} node
96
+ * @returns {string[]}
97
+ */
98
+ export const mapFillNames = ({ type, kind, layer, group }) => [mapKindToken(type, kind), layer ? mapGroupToken(layer) : null, `--corn-map-node-${type}`, `--corn-map-group-${group || type}`].filter(Boolean);
91
99
  /** Reads a kind token's name back: `{ type, kind }`, or null (the type is the part before the first "-") */
92
100
  export function parseKindToken(name) {
93
101
  const m = /^--corn-map-kind-([a-z]+)-([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(String(name));
@@ -8,6 +8,8 @@
8
8
 
9
9
  import { declaredProps, expand, projectGroupOf, resolveProps, themesToCheck } from './contrast.js';
10
10
  import { iconKeyShape, parseKindToken } from './layers.js';
11
+ import { readColor } from './color.js';
12
+ import { MAX_NODE_COLOR_CHARS } from '../explorer/css-color.js';
11
13
  import { EDGE_WIDTH_TOKEN, FONT_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN, MAX_EDGE_WIDTH, MAX_GLOW, MAX_LABEL_MIN, readMapTokens } from '../explorer/map-style.js';
12
14
 
13
15
  const WANTS = {
@@ -86,3 +88,84 @@ export function layerTokenWarnings(config, map) {
86
88
  }
87
89
  return out;
88
90
  }
91
+
92
+ /** How many node colours are named one by one, per kind of line: past this, one line counts the rest */
93
+ export const MAX_NODE_COLOR_WARNINGS = 10;
94
+ const SHOWN_CHARS = 40;
95
+
96
+ /** What JSON leaves as it is but a terminal must not get raw: DEL and the C1 controls, and the invisible and bidirectional marks */
97
+ const UNSEEN = new RegExp('[\\u007f-\\u009f\\u00ad\\u061c\\u200b-\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2060-\\u206f\\ufeff\\ufff9-\\ufffb]', 'g');
98
+
99
+ /**
100
+ * Project text as a terminal may print it: JSON-quoted (so a line break, an escape character and every other C0 control is `\n`, `\u001b`,
101
+ * ...), cut to `max` characters, and with the controls JSON leaves alone made visible too (DEL, the C1 controls such as U+009B, which some
102
+ * terminals read as an escape, and the invisible and bidirectional marks that could make a line read as something it is not).
103
+ * @param {unknown} v
104
+ * @param {number} [max]
105
+ * @returns {string}
106
+ */
107
+ export function quoted(v, max = SHOWN_CHARS) {
108
+ let t;
109
+ try { t = typeof v === 'string' ? v : JSON.stringify(v) ?? String(v); } catch { t = String(v); }
110
+ const chars = Array.from(t);
111
+ if (chars.length > max) t = `${chars.slice(0, max).join('')}...`;
112
+ return JSON.stringify(t).replace(UNSEEN, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
113
+ }
114
+
115
+ /** Colour functions a current browser reads that core/color.js does not work out (it reads rgb() and hsl() only in their plainer forms) */
116
+ const UNCHECKED_FN = /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\(/i;
117
+ /** The CSS system colours (CSS Color 4, with the deprecated ones browsers still read): the map draws them, in the colour the device gives */
118
+ const SYSTEM_COLORS = new Set(('accentcolor accentcolortext activetext buttonborder buttonface buttontext canvas canvastext field fieldtext graytext highlight '
119
+ + 'highlighttext linktext mark marktext selecteditem selecteditemtext visitedtext activeborder activecaption appworkspace background buttonhighlight '
120
+ + 'buttonshadow captiontext inactiveborder inactivecaption inactivecaptiontext infobackground infotext menu menutext scrollbar threeddarkshadow '
121
+ + 'threedface threedhighlight threedlightshadow threedshadow window windowframe windowtext').split(' '));
122
+
123
+ /**
124
+ * How `cornfield validate` can speak of a node's own `color`, which the map checks in the browser (explorer/css-color.js `nodeColor`):
125
+ * - `ok`: core/color.js reads it (hex, rgb(), hsl(), the 148 names, transparent, color-mix in srgb), so the browser does too;
126
+ * - `unchecked`: the shape of a colour a current browser reads that core/color.js cannot work out (`oklch()`, `lab()`, `hwb()`, `color()`,
127
+ * `color-mix()` in another space, rgb()/hsl() in a newer form, a system colour): the map draws it if it is valid, else the type's fill;
128
+ * - `bad`: no browser's map draws it (a typo, `#12345`, an empty string, a number, `currentcolor`, `var()`, `light-dark()`, which a canvas
129
+ * does not read, text over MAX_NODE_COLOR_CHARS): the map draws the type's fill.
130
+ * @param {unknown} value a node's `color`, not undefined
131
+ * @returns {'ok' | 'unchecked' | 'bad'}
132
+ */
133
+ export function nodeColorClass(value) {
134
+ if (typeof value !== 'string' || value.length > MAX_NODE_COLOR_CHARS) return 'bad';
135
+ const s = value.trim();
136
+ if (!s || /currentcolor|light-dark\(|var\(|env\(|attr\(/i.test(s)) return 'bad'; // the map never draws these (explorer/css-color.js)
137
+ if (readColor(s)) return 'ok';
138
+ if (UNCHECKED_FN.test(s) && s.endsWith(')')) return 'unchecked';
139
+ return SYSTEM_COLORS.has(s.toLowerCase()) ? 'unchecked' : 'bad';
140
+ }
141
+
142
+ const nodesWithColor = (map, kind) => ((map && map.nodes) || []).filter((n) => n && n.color !== undefined && nodeColorClass(n.color) === kind);
143
+ const capped = (nodes, line, rest) => {
144
+ const out = nodes.slice(0, MAX_NODE_COLOR_WARNINGS).map(line);
145
+ if (nodes.length > MAX_NODE_COLOR_WARNINGS) out.push(rest(nodes.length - MAX_NODE_COLOR_WARNINGS, nodes.length));
146
+ return out;
147
+ };
148
+
149
+ /**
150
+ * A warning per node whose own `color` no browser's map draws (nodeColorClass `bad`): the map draws that node in its type's fill instead
151
+ * (explorer/scene.js `buildNodes`). The id and the value are printed as quoted text (`quoted`), at most MAX_NODE_COLOR_WARNINGS lines, then a count.
152
+ * @param {{ nodes?: { id?: unknown, color?: unknown }[] } | null} map the committed map
153
+ * @returns {string[]}
154
+ */
155
+ export function nodeColorWarnings(map) {
156
+ return capped(nodesWithColor(map, 'bad'),
157
+ (n) => `node ${quoted(n.id)} has color ${quoted(n.color)}, which is not a colour the map reads: it draws in its type's fill. Write #rrggbb, rgb(), rgba() or hsl().`,
158
+ (more, all) => `${more} more nodes have a color the map does not read (${all} in all): they draw in their type's fill.`);
159
+ }
160
+
161
+ /**
162
+ * A note per node whose own `color` validate cannot check (nodeColorClass `unchecked`: `oklch()`, `lab()`, a system colour, ...). Not a
163
+ * warning: a current browser draws a valid one, and only an invalid one falls back to the type's fill. Same form and cap as the warnings.
164
+ * @param {{ nodes?: { id?: unknown, color?: unknown }[] } | null} map the committed map
165
+ * @returns {string[]}
166
+ */
167
+ export function nodeColorNotes(map) {
168
+ return capped(nodesWithColor(map, 'unchecked'),
169
+ (n) => `node ${quoted(n.id)} has color ${quoted(n.color)}, which validate cannot check: a current browser draws it if it is a valid colour, else the node draws in its type's fill.`,
170
+ (more, all) => `${more} more nodes have a color validate cannot check (${all} in all).`);
171
+ }
package/core/schema.js CHANGED
@@ -12,20 +12,20 @@ export const DERIVED_FLOW = 'api';
12
12
 
13
13
  export const NODE_THEMES = {
14
14
  root: { color: '#f59e0b', r: 28 },
15
- app: { color: '#6366f1', r: 24 },
15
+ app: { color: '#5168ec', r: 24 },
16
16
  page: { color: '#38bdf8', r: 18 }, // Mandatory Sky Blue for all pages
17
- pkg: { color: '#06b6d4', r: 24 }, // Vibrant Cyan for Packages / Libraries
17
+ pkg: { color: '#0f8293', r: 24 }, // Cyan for Packages / Libraries, deep enough to sit 15 ΔE from page and core (MIN_SHAPE_DELTA_E)
18
18
  core: { color: '#14b8a6', r: 20 },
19
- token: { color: '#ec4899', r: 20 },
20
- atom: { color: '#10b981', r: 19 },
19
+ token: { color: '#ef409b', r: 20 },
20
+ atom: { color: '#108d4e', r: 19 },
21
21
  molecule: { color: '#a855f7', r: 21 },
22
22
  tool: { color: '#f43f5e', r: 19 },
23
23
  store: { color: '#fb923c', r: 20 }, // Storage tiers & data-flow endpoints (ADR 0020)
24
24
  table: { color: '#fde047', r: 18 }, // One model table; pages read and write it
25
- rom: { color: '#f0abfc', r: 19 }, // Render on Mutation pipeline stage
25
+ rom: { color: '#c398c6', r: 19 }, // Render on Mutation pipeline stage
26
26
  service: { color: '#84cc16', r: 20 }, // An API module that runs on a timer, a webhook or a change hook (MAP-03)
27
27
  external: { color: '#94a3b8', r: 21 }, // An outside system the API calls or that calls it
28
- stack: { color: '#a8a29e', r: 22 }, // One docker-compose stack: its containers, ports and the domains it serves (MAP-06)
28
+ stack: { color: '#b49fa0', r: 22 }, // One docker-compose stack: its containers, ports and the domains it serves (MAP-06)
29
29
  // The physical world (spec 0029). Derived from code: machine, container, persona, and a device with a `file`
30
30
  machine: { color: '#78716c', r: 26 }, // A computer the code runs on, by hostname
31
31
  container: { color: '#d6d3d1', r: 12 }, // One service of a stack
@@ -33,9 +33,31 @@ export const NODE_THEMES = {
33
33
  device: { color: '#2dd4bf', r: 14 }, // A camera, phone, NFC tag or Home Assistant device; `kind` says which (DEVICE_KINDS)
34
34
  // Live only: drawn from the live layer, never in topology.json (LIVE_TYPES)
35
35
  floor: { color: '#a3e635', r: 20 }, // A level of the house
36
- room: { color: '#bef264', r: 16 }, // A room, with its box on the floor plan
36
+ room: { color: '#f7ed81', r: 16 }, // A room, with its box on the floor plan (yellow beside the floor's lime: one silhouette, 15 ΔE apart)
37
37
  };
38
38
 
39
+ /**
40
+ * The silhouette each node type is drawn in (spec 0008 D8), so a type reads at 6 px where no glyph does: a circle for code, a rounded square for
41
+ * data, a hexagon for what is outside, a square for where things run, a diamond for people. A type this table does not know is a circle.
42
+ * The silhouette is not a token: it says what a node is. Colour tells the types of one silhouette apart, so they are kept far apart (below).
43
+ */
44
+ export const NODE_SHAPES = Object.freeze({
45
+ root: 'circle', app: 'circle', page: 'circle', pkg: 'circle', core: 'circle', token: 'circle', atom: 'circle', molecule: 'circle', tool: 'circle', rom: 'circle', service: 'circle',
46
+ store: 'rounded-square', table: 'rounded-square',
47
+ external: 'hexagon',
48
+ stack: 'square', machine: 'square', container: 'square', device: 'square', floor: 'square', room: 'square',
49
+ persona: 'diamond',
50
+ });
51
+ /** The silhouettes, in the order the renderers number them (0 is the circle) */
52
+ export const SHAPES = Object.freeze(['circle', 'rounded-square', 'hexagon', 'square', 'diamond']);
53
+ /** The silhouette of a node type: `circle` for one the table does not know (a type is project data, so it only selects from the table) */
54
+ export const shapeOf = (type) => (typeof type === 'string' && Object.hasOwn(NODE_SHAPES, type) ? NODE_SHAPES[type] : 'circle');
55
+ /**
56
+ * How far apart (CIEDE2000, core/delta-e.js) two types of one silhouette must be, on the dark ground and on the light one. The default palette is held to it
57
+ * by a test; `cornfield validate` warns when a theme's own map colours break it.
58
+ */
59
+ export const MIN_SHAPE_DELTA_E = 15;
60
+
39
61
  /** Kinds of data-flow edge (edge.kind === 'flow'); see docs/adr/0020 */
40
62
  export const FLOW_KINDS = ['outbox', 'changes', 'trigger', 'sync', 'model', 'rom', 'read', 'build', DERIVED_FLOW];
41
63
 
package/core/strings.js CHANGED
@@ -90,6 +90,8 @@ export const STRINGS = Object.freeze({
90
90
  openRoute: 'Open route',
91
91
  startRun: 'Start a run',
92
92
  copySpec: 'Copy Spec',
93
+ frame: 'Frame them',
94
+ throughChildren: "Include its children's lines",
93
95
  // The hint, loading and errors
94
96
  hintInspect: 'Click a node to see what it is',
95
97
  hintInspectTouch: 'Tap a node to see what it is',
package/core/validate.js CHANGED
@@ -24,7 +24,7 @@ import { deriveTopology } from './derive.js';
24
24
  import { missingPaths, planSync } from './sync.js';
25
25
  import { repoPaths, repoReader } from './repo.js';
26
26
  import { checkThemeContrast } from './contrast.js';
27
- import { layerTokenWarnings, mapTokenWarnings } from './map-tokens.js';
27
+ import { layerTokenWarnings, mapTokenWarnings, nodeColorNotes, nodeColorWarnings, quoted } from './map-tokens.js';
28
28
  import { layersMapWarnings } from './layers.js';
29
29
  import { BRAND_IMAGE_KEYS, brandAssetFile } from './brand.js';
30
30
  import { MAX_THEME_BYTES, cssProblems, cssUrls, themeAssetFile, themeFileUrl, themeFiles, themeIconFileProblems, themeUrlTarget } from './theme.js';
@@ -113,7 +113,7 @@ export function validateTopology(topology, { requireExternalKind = true } = {})
113
113
  errors.push(`Node "${node.id}" has unknown type: "${node.type}". Valid types: ${Object.keys(NODE_THEMES).join(', ')}`);
114
114
  } else {
115
115
  if (node.type === 'page') {
116
- if (node.color !== NODE_THEMES.page.color) errors.push(`Page node "${node.id}" has color "${node.color}". All pages use "${NODE_THEMES.page.color}".`);
116
+ if (node.color !== NODE_THEMES.page.color) errors.push(`Page node "${node.id}" has color ${quoted(node.color)}. All pages use "${NODE_THEMES.page.color}".`);
117
117
  if (typeof node.label !== 'string' || !node.label.startsWith('/')) errors.push(`Page node "${node.id}" label "${node.label}" must start with a slash route (e.g. "/cart"). Put the file in 'file'.`);
118
118
  else if (node.label.includes('.html')) errors.push(`Page node "${node.id}" label "${node.label}" contains ".html". Use a clean route label and put the file in 'file'.`);
119
119
  if (node.render) {
@@ -288,6 +288,8 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
288
288
  if (contrast.summary) notes.push(contrast.summary);
289
289
  warnings.push(...mapTokenWarnings(config)); // a map font, line width or glow the map cannot read draws as auto
290
290
  warnings.push(...layerTokenWarnings(config, topology)); // a kind token, a group token or an icon for a kind or layer that is not there
291
+ warnings.push(...nodeColorWarnings(topology)); // a node whose own colour the map cannot read draws in its type's fill
292
+ notes.push(...nodeColorNotes(topology)); // a node colour only a browser can work out (oklch(), lab(), ...): said, not warned
291
293
  warnings.push(...layersMapWarnings(config.layers, topology)); // a project layer that matches nothing, or whose every node an earlier layer took
292
294
  errors.push(...validateCloudNodes(topology, config.root));
293
295
  errors.push(...validateProposalFiles(topology, path.join(config.root, config.proposals), config.root));
@@ -10,14 +10,15 @@ export const CAP = 5;
10
10
  let counter = 0;
11
11
 
12
12
  /**
13
- * The items as HTML, folded after CAP when there are more.
13
+ * The items as HTML, folded after `cap` (CAP by default) when there are more.
14
14
  * @param {string[]} items already-escaped HTML, one per item
15
+ * @param {number} [cap]
15
16
  */
16
- export function capped(items) {
17
- if (items.length <= CAP + 1) return items.join(''); // "and 1 more" saves nothing
17
+ export function capped(items, cap = CAP) {
18
+ if (items.length <= cap + 1) return items.join(''); // "and 1 more" saves nothing
18
19
  const id = `hx-more-${++counter}`;
19
- const rest = items.length - CAP;
20
- return `${items.slice(0, CAP).join('')}<div class="hx-more" id="${id}" hidden>${items.slice(CAP).join('')}</div><button data-corn="more" data-corn-kind="quiet" type="button" class="hx-btn hx-btn--quiet hx-textact hx-more-btn" data-more="${id}" data-rest="${rest}" aria-expanded="false" aria-controls="${id}">and ${rest} more</button>`;
20
+ const rest = items.length - cap;
21
+ return `${items.slice(0, cap).join('')}<div class="hx-more" id="${id}" hidden>${items.slice(cap).join('')}</div><button data-corn="more" data-corn-kind="quiet" type="button" class="hx-btn hx-btn--quiet hx-textact hx-more-btn" data-more="${id}" data-rest="${rest}" aria-expanded="false" aria-controls="${id}">and ${rest} more</button>`;
21
22
  }
22
23
 
23
24
  /** Opens or folds the list a "more" button belongs to; true when the click was one */
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Cloud on the map, the explorer's pure half (spec 0031 sections 1 and 6, CLOUD-06): no DOM, no state.
5
5
  *
6
- * - `WHEN_STYLES`, `whenOf`, `whenDash`: when an outage of a cloud service bites, read from a `calls` edge's
7
- * `when` (absent = `run`), and how each looks: on the map (`dash`: solid, dashed, dotted), in the legend
6
+ * - `WHEN_STYLES`, `whenOf`, `whenTicks`: when an outage of a cloud service bites, read from a `calls` edge's
7
+ * `when` (absent = `run`), and how each looks: on the map (`ticks`: none, one, two), in the legend
8
8
  * (`legend`), in the panel (`title`, `color`). The one place these live: scene.js, the legend, the panel and
9
9
  * the House view's Cloud band (CLOUD-08) all read them here; the outage colours (CLOUD-07) are `color`.
10
10
  * - `externalLayer(node)`: the Layers key of an `external` node, `cloud` or `web` (the public web, spec D3).
@@ -23,16 +23,19 @@ import { capped } from './capped.js';
23
23
  * mark's), null for solid; `color` is the panel's and an outage scenario's for that group.
24
24
  */
25
25
  export const WHEN_STYLES = {
26
- run: { title: 'Breaks now', legend: 'Solid: breaks as soon as it is down', dash: null, color: '#f87171' },
27
- deploy: { title: 'Breaks at the next deploy', legend: 'Dashed: breaks at the next deploy, rebuild or first run', dash: [9, 5], color: '#fbbf24' },
28
- renew: { title: 'Breaks at the next certificate renewal', legend: 'Dotted: breaks at the next certificate renewal', dash: [2, 4], color: '#a78bfa' },
26
+ run: { title: 'Breaks now', legend: 'No tick: breaks as soon as it is down', ticks: 0, color: '#f87171' },
27
+ deploy: { title: 'Breaks at the next deploy', legend: 'One tick: breaks at the next deploy, rebuild or first run', ticks: 1, color: '#fbbf24' },
28
+ renew: { title: 'Breaks at the next certificate renewal', legend: 'Two ticks: breaks at the next certificate renewal', ticks: 2, color: '#a78bfa' },
29
29
  };
30
30
 
31
31
  /** A `calls` edge's `when`: `run` when absent (or not one of the three) */
32
32
  export const whenOf = (edge) => (edge && Object.hasOwn(WHEN_STYLES, edge.when) ? edge.when : 'run');
33
33
 
34
- /** The dash a `calls` edge is drawn with for its `when` (null = solid); any other kind of edge is not styled by it */
35
- export const whenDash = (edge) => (edge && edge.kind === 'calls' ? WHEN_STYLES[whenOf(edge)].dash : null);
34
+ /**
35
+ * The tick marks a `calls` edge carries at its middle for its `when` (spec 0008 D7): none, one for the next deploy, two for the next renewal. A dash
36
+ * means only "proposed" on the map, so `when` is told by ticks; any other kind of edge has none
37
+ */
38
+ export const whenTicks = (edge) => (edge && edge.kind === 'calls' ? WHEN_STYLES[whenOf(edge)].ticks : 0);
36
39
 
37
40
  /** The Layers key of an outside node: the public web (kind `web`) is its own; every other external is Cloud */
38
41
  export const externalLayer = (node) => (node && node.kind === 'web' ? 'web' : 'cloud');
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @module explorer/css-color
3
+ *
4
+ * A CSS colour as the renderers can use it, read once here so every reader (the map's tokens in map-style.js, a node's own
5
+ * colour in scene.js) agrees on what a colour is. The text is project or theme data: it only ever leaves here as `#rrggbb`,
6
+ * `rgb()` or `rgba()` that this file built or checked, never as the text it was given.
7
+ */
8
+
9
+ import { parseColor } from './theme-model.js';
10
+ import { readColor } from '../core/color.js';
11
+
12
+ let probe;
13
+ const normalised = new Map();
14
+
15
+ /** A canvas context to normalise a colour the way the browser reads it (`hsl()`, a name, `color-mix()`), or null where there is none */
16
+ function probeContext() {
17
+ if (probe !== undefined) return probe;
18
+ probe = null;
19
+ try { if (typeof document !== 'undefined') probe = document.createElement('canvas').getContext('2d', { willReadFrequently: true }) || null; } catch { probe = null; }
20
+ return probe;
21
+ }
22
+
23
+ /**
24
+ * A token's value as a colour the renderers can use (`#rrggbb`, `rgb()`, `rgba()`), or null for `auto`, empty, or anything that is not a colour.
25
+ * @param {string} value
26
+ * @returns {string | null}
27
+ */
28
+ export function cssColor(value) {
29
+ const s = typeof value === 'string' ? value.trim() : '';
30
+ if (!s || s.toLowerCase() === 'auto') return null;
31
+ if (inRange(s)) return s;
32
+ if (/^transparent$/i.test(s)) return 'rgba(0, 0, 0, 0)';
33
+ if (normalised.has(s)) return normalised.get(s);
34
+ let out = null;
35
+ const ctx = isColor(s) && !/currentcolor/i.test(s) ? probeContext() : null; // a canvas has no current colour: it would read as black
36
+ if (ctx) {
37
+ try {
38
+ // The browser's own reading: a value it refuses leaves fillStyle as it was, so two different starting colours tell a refusal
39
+ // from a colour that happens to equal the first one
40
+ const read = (from) => { ctx.fillStyle = from; ctx.fillStyle = s; return String(ctx.fillStyle); };
41
+ const a = read('#010203');
42
+ const got = a !== '#010203' ? a : read('#040506') !== '#040506' ? a : null;
43
+ // A colour the browser keeps in another space (`oklch()`, `color(display-p3 ...)`) is read back as the sRGB pixel it paints
44
+ out = got === null ? null : parseable(got) ? got : pixelOf(ctx, s);
45
+ } catch { out = null; }
46
+ }
47
+ normalised.set(s, out);
48
+ return out;
49
+ }
50
+
51
+ /** Whether CSS itself reads `s` as a colour (a canvas is more lenient: it takes `rgb(1.2.3, 0, 0)`); true where the page cannot say */
52
+ function isColor(s) {
53
+ try { return typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || CSS.supports('color', s); } catch { return false; }
54
+ }
55
+
56
+ /** `#rgb`, `#rrggbb`, `rgb()` or `rgba()` with every channel in range: what both renderers read as written */
57
+ function inRange(s) {
58
+ if (!parseable(s)) return false;
59
+ // The numbers as written: parseColor clamps them, and an out-of-range channel must go to the browser to be read
60
+ const nums = /^rgba?\(/i.test(s.trim()) ? s.slice(s.indexOf('(') + 1, s.lastIndexOf(')')).split(',').map(Number) : null;
61
+ if (nums && (nums.slice(0, 3).some((c) => !(c >= 0 && c <= 255)) || (nums.length > 3 && !(nums[3] > 0 && nums[3] <= 1)))) return false;
62
+ const [r, g, b, a] = parseColor(s);
63
+ return [r, g, b].every((c) => Number.isFinite(c) && c >= 0 && c <= 255) && Number.isFinite(a) && a > 0 && a <= 1;
64
+ }
65
+ /** The forms parseColor (theme-model.js) reads; anything else is normalised by the browser first */
66
+ const COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$|^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(?:,\s*[\d.]+\s*)?\)$/i;
67
+ const parseable = (s) => COLOR_RE.test(s.trim());
68
+
69
+ /** The sRGB pixel `css` paints, as `rgba()` (or null when the context cannot be read) */
70
+ function pixelOf(ctx, css) {
71
+ if (!ctx.getImageData || !ctx.fillRect) return null;
72
+ ctx.clearRect(0, 0, 1, 1);
73
+ ctx.fillStyle = css;
74
+ ctx.fillRect(0, 0, 1, 1);
75
+ const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
76
+ return rgbaText(r, g, b, a / 255);
77
+ }
78
+
79
+ export const rgbaText = (r, g, b, a) => `rgba(${r}, ${g}, ${b}, ${+a.toFixed(3)})`;
80
+
81
+
82
+ /** The longest colour a node may carry: every real colour is far shorter, and a longer text is never handed to the browser to read */
83
+ export const MAX_NODE_COLOR_CHARS = 200;
84
+
85
+ /**
86
+ * A node's own `color` (project data) as a colour both renderers draw the same, or null when it is not one: a typo, `#12345`, an empty
87
+ * string, a number, `null`, a value with a quote or `url(`, text over MAX_NODE_COLOR_CHARS. The caller then uses the node type's fill.
88
+ * Where the page has no canvas to read with (Node, the tests), the forms core/color.js reads are kept as written.
89
+ * @param {unknown} value
90
+ * @returns {string | null}
91
+ */
92
+ export function nodeColor(value) {
93
+ if (typeof value !== 'string' || value.length > MAX_NODE_COLOR_CHARS) return null;
94
+ const s = value.trim();
95
+ if (!s || /^(?:auto|currentcolor)$/i.test(s)) return null;
96
+ const c = cssColor(s);
97
+ if (c) return c;
98
+ return probeContext() === null && readColor(s) ? s : null;
99
+ }
@@ -31,5 +31,7 @@ export const MARK_SHAPES = Object.freeze({
31
31
  added: Object.freeze({ ringDash: Object.freeze([5, 4]), edgeDash: Object.freeze([7, 5]), strike: false }), // a dashed ring
32
32
  changed: Object.freeze({ ringDash: null, edgeDash: null, strike: false }), // a plain solid ring
33
33
  removed: Object.freeze({ ringDash: null, edgeDash: Object.freeze([3, 4]), strike: true }), // a faded ring, struck through
34
- edit: Object.freeze({ ringDash: Object.freeze([2, 5]), edgeDash: Object.freeze([2, 5]), strike: false }), // a dotted ring: short marks, wide gaps (a 1.5/3.5 dot blurred into a solid ring at 1x)
34
+ // a dotted ring: short marks, wide gaps (a 1.5/3.5 dot blurred into a solid ring at 1x); its line is long-dashed: dashed, as everything not built is
35
+ // (spec 0008 D7), and not dotted, which is a usage link's (a lit one is lilac too)
36
+ edit: Object.freeze({ ringDash: Object.freeze([2, 5]), edgeDash: Object.freeze([12, 4]), strike: false }),
35
37
  });