@popcorn245/cornfield 0.42.0 → 0.43.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/contrast.js CHANGED
@@ -23,7 +23,8 @@ 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';
26
+ import { MIN_SHAPE_DELTA_E, NODE_SHAPES, NODE_THEMES } from './schema.js';
27
+ import { deltaE2000 } from './delta-e.js';
27
28
  import { LAYER_KEY_RE, MAX_KEY, 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';
@@ -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/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',
@@ -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');
@@ -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
  });
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module explorer/edge-key
3
+ *
4
+ * The Key in the Layers menu (spec 0008 D7): each kind of line drawn as the map draws it, with its real style and end mark, not a coloured dot.
5
+ * A pure function of the constants the renderers draw from (scene.js ARROW, END_SHAPES, USAGE_DASH, PROPOSED_DASH), so the Key and the map
6
+ * cannot drift apart. Every word here is fixed text: nothing from the map reaches it.
7
+ */
8
+
9
+ import { ARROW, END_SHAPES, PROPOSED_DASH, USAGE_DASH } from './scene.js';
10
+
11
+ const W = 44; // the swatch's width and height (px)
12
+ const H = 16;
13
+ const MID = H / 2;
14
+ const X0 = 2;
15
+ const TIP = W - 3;
16
+
17
+ /** The end mark of each family, as SVG path data with its tip at (tx, MID), in the same units the map draws it in (ARROW, END_SHAPES) */
18
+ const mark = (kind, tx) => {
19
+ const back = ARROW.length * Math.cos(ARROW.spread);
20
+ const side = ARROW.length * Math.sin(ARROW.spread);
21
+ if (kind === 'triangle') return `<path d="M${tx} ${MID} L${tx - back} ${MID - side} L${tx - back} ${MID + side} Z" fill="currentColor"/>`;
22
+ if (kind === 'chevron') return `<path d="M${tx - back} ${MID - side} L${tx} ${MID} L${tx - back} ${MID + side}" fill="none" stroke="currentColor" stroke-width="${END_SHAPES.strokeWidth}"/>`;
23
+ if (kind === 'bar') return `<path d="M${tx - 1} ${MID - END_SHAPES.barHalf} V${MID + END_SHAPES.barHalf}" fill="none" stroke="currentColor" stroke-width="${END_SHAPES.strokeWidth}"/>`;
24
+ if (kind === 'diamond') {
25
+ const h = END_SHAPES.diamondHalf;
26
+ const a = END_SHAPES.diamondAcross;
27
+ return `<path d="M${tx} ${MID} L${tx - h} ${MID - a} L${tx - 2 * h} ${MID} L${tx - h} ${MID + a} Z" fill="none" stroke="currentColor" stroke-width="${END_SHAPES.strokeWidth}"/>`;
28
+ }
29
+ return '';
30
+ };
31
+
32
+ /** A swatch: a line of `width`, with `dash` (or solid), an end mark, and `ticks` across its middle */
33
+ export function keySwatch({ end = null, dash = null, width = 1.6, ticks = 0 } = {}) {
34
+ const stop = end ? TIP - (end === 'triangle' || end === 'chevron' ? 1 : end === 'diamond' ? 2 * END_SHAPES.diamondHalf : 1) : TIP;
35
+ const line = `<path d="M${X0} ${MID} H${stop}" fill="none" stroke="currentColor" stroke-width="${width}"${dash ? ` stroke-dasharray="${dash.join(' ')}"` : ''}/>`;
36
+ let tickPaths = '';
37
+ for (let i = 0; i < ticks; i++) {
38
+ const x = (X0 + stop) / 2 + (i - (ticks - 1) / 2) * END_SHAPES.tickGap;
39
+ tickPaths += `<path d="M${x} ${MID - END_SHAPES.tickHalf} V${MID + END_SHAPES.tickHalf}" fill="none" stroke="currentColor" stroke-width="${END_SHAPES.tickWidth}"/>`;
40
+ }
41
+ return `<svg class="hx-key-line" data-corn="swatch" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" aria-hidden="true" focusable="false">${line}${tickPaths}${end ? mark(end, TIP) : ''}</svg>`;
42
+ }
43
+
44
+ /** The rows of the Key: [swatch options, the words] */
45
+ export const KEY_ROWS = Object.freeze([
46
+ [{ width: 1.4 }, 'Owns: a parent and what it holds'],
47
+ [{ dash: USAGE_DASH, width: 1.6 }, 'Uses loosely: dotted'],
48
+ [{ dash: PROPOSED_DASH, end: 'chevron' }, 'Proposed, not built: dashed, with its kind’s mark'],
49
+ [{ end: 'chevron' }, 'Data: flow, reads, writes (towards the page is a read)'],
50
+ [{ end: 'triangle' }, 'Services: calls, triggers, delivers'],
51
+ [{ end: 'bar' }, 'Places: runs on'],
52
+ [{ end: 'diamond' }, 'Tokens: uses, extends'],
53
+ ]);
54
+
55
+ /** The Key's markup (the section's own title and its rows) */
56
+ export function edgeKeyHtml() {
57
+ const rows = KEY_ROWS.map(([opts, words]) => `<div class="hx-legend-row"><span class="hx-legend-swatch hx-legend-swatch--wide">${keySwatch(opts)}</span><span>${words}</span></div>`).join('');
58
+ return `<div class="hx-menu-title" data-corn="menu-title"><span>Key</span></div>${rows}<p class="hx-faint hx-key-note">A line says its kind in words when it is lit.</p>`;
59
+ }
@@ -299,8 +299,6 @@ h1, h2, h3, p { margin: 0; }
299
299
  .hx-legend-label { display: flex; align-items: center; gap: var(--corn-space-3); font-weight: 500; }
300
300
  .hx-legend-swatch { width: 16px; flex: none; display: inline-flex; justify-content: center; }
301
301
  .hx-swatch-line { display: inline-block; width: 16px; height: 2px; border-radius: var(--corn-radius-xs); }
302
- .hx-swatch-solid { background: color-mix(in srgb, var(--corn-text) 55%, transparent); }
303
- .hx-swatch-dashed { height: 0; background: none; border-top: var(--corn-border-strong) dashed var(--corn-text-2); }
304
302
  .hx-swatch-indigo { border-top-color: var(--corn-accent-text); }
305
303
 
306
304
  /* ---- stage: canvas, hint, states --------------------------------------------------------- */
@@ -714,12 +712,6 @@ h2.hx-proposal-name { margin: 0; }
714
712
  .hx-player-as[hidden], .hx-player-verdict[hidden], .hx-player-check[hidden] { display: none; }
715
713
 
716
714
  /* ---- cloud nodes (spec 0031, CLOUD-06): the panel's badges, plan and Used by; the `when` line styles -- */
717
- /* The `when` swatches mirror cloud-model.js WHEN_STYLES (run solid, deploy dashed, renew dotted; red, amber, violet) */
718
- .hx-swatch-when { width: 18px; height: 2px; border-radius: 0; color: var(--corn-text-2); background: currentColor; }
719
- .hx-swatch-when--run { color: var(--corn-removed); }
720
- .hx-swatch-when--deploy { color: var(--corn-changed); background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px); }
721
- .hx-swatch-when--renew { color: var(--corn-edit); background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); }
722
- .hx-swatch-when--plain { color: var(--corn-text-2); } /* the legend: the map draws every call in the calls colour, so only the pattern is the key */
723
715
  .hx-cloud-browser { color: var(--corn-text-3); font-size: var(--corn-text-sm); }
724
716
 
725
717
  /* ---- a panel glyph (MAP-01) ----------------------------------------------------------------------
@@ -1421,6 +1413,33 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
1421
1413
  .hx-dock > .hx-drawer[data-sheet-state="expanded"], .hx-dock > .hx-forge[data-sheet-state="expanded"] { max-height: min(var(--hx-sheet-cap, 60dvh), 60dvh); }
1422
1414
  }
1423
1415
 
1416
+ /* ---------------------------------------------------------------------------
1417
+ The node panel's lines (spec 0008 D5 and D6): the lit lines by kind, the switch, and Frame them
1418
+ --------------------------------------------------------------------------- */
1419
+ .hx-lines { display: flex; flex-direction: column; gap: var(--corn-space-2); }
1420
+ .hx-lines .hx-chips { padding-top: 0; }
1421
+ .hx-lines-kind { display: inline-flex; align-items: baseline; gap: var(--corn-space-1); min-height: 28px; padding: 0 var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: none; color: var(--corn-text-2); font: inherit; font-size: var(--corn-text-xs); font-weight: 600; cursor: pointer; }
1422
+ .hx-lines-kind:hover { background: var(--corn-surface-3); color: var(--corn-text); }
1423
+ .hx-lines-kind[aria-pressed="true"] { border-color: var(--corn-accent); background: var(--corn-accent-soft); color: var(--corn-accent-text); }
1424
+ .hx-lines-kind:focus-visible, .hx-lines-switch input:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
1425
+ .hx-lines-count { font-variant-numeric: tabular-nums; color: var(--corn-text-3); }
1426
+ .hx-lines-list { display: flex; flex-direction: column; align-items: flex-start; gap: calc(var(--corn-space-1) / 2); }
1427
+ .hx-lines-list .hx-linkbtn { margin-left: 0; text-align: left; overflow-wrap: anywhere; }
1428
+ .hx-lines-switch { display: flex; align-items: center; gap: var(--corn-space-2); min-height: 28px; font-size: var(--corn-text-sm); color: var(--corn-text-2); cursor: pointer; }
1429
+ .hx-lines-reach { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-3); font-size: var(--corn-text-sm); color: var(--corn-text-2); font-variant-numeric: tabular-nums; }
1430
+ @media (max-width: 767px), (pointer: coarse) {
1431
+ .hx-lines-kind, .hx-lines-switch, .hx-lines-list .hx-linkbtn, .hx-lines-reach .hx-btn { min-height: 44px; }
1432
+ .hx-lines-switch input { width: 24px; height: 24px; }
1433
+ }
1434
+
1435
+ /* ---------------------------------------------------------------------------
1436
+ The Key (spec 0008 D7, edge-key.js): each kind of line drawn with its real style and end mark. The map says the kind by line style
1437
+ and mark, never by colour alone, so the swatches are one ink; a `when` is told by ticks (cloud-model.js WHEN_STYLES)
1438
+ --------------------------------------------------------------------------- */
1439
+ .hx-legend-swatch--wide { width: 44px; justify-content: flex-start; color: var(--corn-text-2); }
1440
+ .hx-key-line { display: block; overflow: visible; }
1441
+ .hx-key-note { margin: var(--corn-space-1) 0 0; font-size: var(--corn-text-xs); }
1442
+
1424
1443
  /* ===== Spec 0007: the decision. The line above Approve, the question asked in place, the hold with Undo, a landing that waits, what a send back carried ===== */
1425
1444
  .hx-decision-line { margin: 0; color: var(--corn-text-2); font-size: var(--corn-text-sm); line-height: 1.45; }
1426
1445
  .hx-decision-line[hidden], .hx-review-ask[hidden], .hx-hold[hidden], .hx-review-landing[hidden], .hx-sent-edits[hidden] { display: none; }
package/explorer/flows.js CHANGED
@@ -142,8 +142,6 @@ export function renderFlowLegend() {
142
142
  <span>Data Flow</span>
143
143
  </div>
144
144
  ${Object.values(FLOW_STYLES).map((s) => row(`<span data-corn="swatch" class="hx-swatch-line" style="background:${themed(s.color, state.theme)}"></span>`, s.label)).join('')}
145
- ${row('<span data-corn="swatch" class="hx-swatch-line hx-swatch-solid"></span>', '<span class="hx-faint">Solid: live today</span>')}
146
- ${row('<span data-corn="swatch" class="hx-swatch-line hx-swatch-dashed"></span>', '<span class="hx-faint">Dashed: proposed</span>')}
147
145
  </div>`;
148
146
  }
149
147
 
@@ -69,7 +69,7 @@
69
69
  import { state, nodeById, escHtml, touchScene, onSceneTouch } from './state.js';
70
70
  import { render, isNodeVisible } from './render.js';
71
71
  import { selectNode, repaintThreads } from './panels.js';
72
- import { announce, centreOn } from './keyboard.js';
72
+ import { announce } from './keyboard.js';
73
73
  import { trapTab } from './focusables.js';
74
74
  import { isPhone, registerSheet, expandSheet, collapseSheet, showSheet, refreshStubs } from './sheets.js';
75
75
  import { relativeTime } from './review-model.js';
@@ -2349,8 +2349,7 @@ function onClick(e) {
2349
2349
  if (nodeBtn) {
2350
2350
  const node = nodeById(nodeBtn.dataset.forgeNode);
2351
2351
  if (!node) return;
2352
- selectNode(node);
2353
- centreOn(node);
2352
+ selectNode(node, { frame: true });
2354
2353
  if (isPhone()) collapseSheet('forge'); // the map and the node's sheet are what is wanted now
2355
2354
  announce(`${node.label}, ${node.type}`);
2356
2355
  return;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @module explorer/glyphs
3
+ *
4
+ * The built-in glyph of each node type (spec 0008 D8): a small monochrome picture drawn in the middle of a node once it is 14 px across on screen,
5
+ * where the white core dot is. It tells types of one silhouette apart beyond their colour. Both renderers draw the same picture, made once here as
6
+ * a small transparent image (like kind-letters.js), and by the same rule:
7
+ *
8
+ * a theme's icon for the node (`theme.icons`) > a finer kind's letters (spec 0009, kind-letters.js) > the type's glyph > the white core dot
9
+ *
10
+ * Canvas 2D draws the image with `drawImage` where an icon would go; WebGL uploads it as a texture and draws it in the icon pass, grouped by
11
+ * `glyph:<type>|<ink>`. The glyphs are a fixed set (one per type in core/schema.js, nothing a map holds), in two inks at most per type
12
+ * (white or dark, whichever reads on the node's fill; or the theme's `--corn-map-glyph`), so the textures are few and bounded.
13
+ */
14
+
15
+ import { NODE_THEMES } from '../core/schema.js';
16
+ import { parseColor } from './theme-model.js';
17
+
18
+ /** A node is at least this many px across (on screen) before its glyph is drawn: smaller, no glyph reads and the silhouette does the work */
19
+ export const GLYPH_MIN_PX = 14;
20
+ /** The glyph's box, as a fraction of the node's radius across (a square centred on the node, like an icon) */
21
+ export const GLYPH_RATIO = 1.2;
22
+ const SIDE = 96;
23
+ const GRID = 24; // the glyphs are drawn on a 24 by 24 grid
24
+ const KEY_PREFIX = 'glyph:';
25
+ /** The two inks the glyph takes when the theme does not set `--corn-map-glyph`: white on a deep fill, dark on a pale one */
26
+ export const INK_LIGHT = '#ffffff';
27
+ export const INK_DARK = '#0b1220';
28
+ /** The most glyph images made: types times inks is far under it; a theme that sets many colours at once cannot grow it */
29
+ export const MAX_GLYPH_IMAGES = 64;
30
+
31
+ /** Types that have a glyph: the built-in ones. A type a project invents has none (it keeps the white core dot) */
32
+ export const GLYPH_TYPES = Object.freeze(Object.keys(NODE_THEMES));
33
+ export const hasGlyph = (type) => typeof type === 'string' && Object.hasOwn(NODE_THEMES, type);
34
+
35
+ /** The key a glyph goes under in the renderers' icon tables */
36
+ export const glyphKey = (type, ink) => `${KEY_PREFIX}${type}|${ink}`;
37
+ export const isGlyphKey = (key) => typeof key === 'string' && key.startsWith(KEY_PREFIX);
38
+ /** @returns {{type: string, ink: string}} */
39
+ export function glyphOfKey(key) {
40
+ const rest = key.slice(KEY_PREFIX.length);
41
+ const at = rest.indexOf('|');
42
+ return { type: rest.slice(0, at), ink: rest.slice(at + 1) };
43
+ }
44
+
45
+ const luminanceOf = ([r, g, b]) => {
46
+ const lin = (c) => { const v = c / 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
47
+ return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
48
+ };
49
+ const ratioOf = (a, b) => { const [hi, lo] = a > b ? [a, b] : [b, a]; return (hi + 0.05) / (lo + 0.05); };
50
+
51
+ /** The ink that reads on a fill: white or dark, whichever has the higher contrast (the glyph is at least 3:1 on every fill of the default palette: a test holds it) */
52
+ export function inkFor(fill) {
53
+ const lum = luminanceOf(parseColor(fill));
54
+ return ratioOf(1, lum) >= ratioOf(luminanceOf(parseColor(INK_DARK)), lum) ? INK_LIGHT : INK_DARK;
55
+ }
56
+
57
+ /** The ink a node's glyph is drawn in: the theme's (`--corn-map-glyph`, in the style's `values`), else the one that reads on its fill */
58
+ export const glyphInk = (node, style) => (style && style.values && style.values['--corn-map-glyph']) || inkFor(node.color);
59
+
60
+ /** Whether a node's glyph is drawn at this zoom: it has one, no icon or letters replace it, and it is wide enough on screen */
61
+ export const showsGlyph = (node, zoom) => !!node.glyph && !node.icon && !node.letters && node.r * 2 * zoom >= GLYPH_MIN_PX;
62
+
63
+ /** The glyph of each type: a function that adds its strokes and fills to a 24 by 24 grid (`ink` is already the fill and stroke style) */
64
+ const PATHS = {
65
+ root: (c) => { ring(c, 12, 12, 8); dot(c, 12, 12, 3.2); },
66
+ app: (c) => { c.beginPath(); c.rect(3.5, 5, 17, 14); c.stroke(); line(c, 3.5, 9.5, 20.5, 9.5); },
67
+ page: (c) => { c.beginPath(); c.rect(6, 3.5, 12, 17); c.stroke(); line(c, 9, 9, 15, 9); line(c, 9, 12.5, 15, 12.5); line(c, 9, 16, 13, 16); },
68
+ pkg: (c) => { c.beginPath(); c.rect(4, 7, 16, 13); c.stroke(); line(c, 4, 12, 20, 12); line(c, 12, 7, 12, 12); },
69
+ core: (c) => { ring(c, 12, 12, 8.2); dot(c, 12, 12, 4); },
70
+ token: (c) => { for (const [x, y] of [[5, 5], [13, 5], [5, 13], [13, 13]]) { c.fillRect(x, y, 6, 6); } },
71
+ atom: (c) => { c.beginPath(); c.ellipse(12, 12, 9.5, 4, -0.5, 0, Math.PI * 2); c.stroke(); dot(c, 12, 12, 3); },
72
+ molecule: (c) => { line(c, 7, 16, 17, 8); dot(c, 7, 16, 4); dot(c, 17, 8, 4); },
73
+ tool: (c) => { line(c, 12, 4, 12, 20); line(c, 4, 12, 20, 12); },
74
+ rom: (c) => { c.beginPath(); c.arc(12, 12, 7.5, 0.4, Math.PI * 1.6); c.stroke(); c.beginPath(); c.moveTo(14.5, 2.5); c.lineTo(20, 5.5); c.lineTo(14, 8.5); c.closePath(); c.fill(); },
75
+ service: (c) => { c.beginPath(); c.moveTo(13.5, 2.5); c.lineTo(6, 13.5); c.lineTo(11.5, 13.5); c.lineTo(10, 21.5); c.lineTo(18, 9.5); c.lineTo(12.5, 9.5); c.closePath(); c.fill(); },
76
+ store: (c) => { c.beginPath(); c.ellipse(12, 6.5, 7.5, 3, 0, 0, Math.PI * 2); c.stroke(); line(c, 4.5, 6.5, 4.5, 17.5); line(c, 19.5, 6.5, 19.5, 17.5); c.beginPath(); c.ellipse(12, 17.5, 7.5, 3, 0, 0, Math.PI); c.stroke(); },
77
+ table: (c) => { c.beginPath(); c.rect(4, 5, 16, 14); c.stroke(); line(c, 4, 10, 20, 10); line(c, 12, 10, 12, 19); },
78
+ external: (c) => { line(c, 7, 17, 17, 7); c.beginPath(); c.moveTo(9.5, 6.5); c.lineTo(17.5, 6.5); c.lineTo(17.5, 14.5); c.stroke(); },
79
+ stack: (c) => { for (const y of [4.5, 10.5, 16.5]) c.fillRect(4, y, 16, 3.5); },
80
+ machine: (c) => { c.beginPath(); c.rect(3.5, 4.5, 17, 11); c.stroke(); line(c, 12, 15.5, 12, 19.5); line(c, 7.5, 19.5, 16.5, 19.5); },
81
+ container: (c) => { c.beginPath(); c.rect(4, 4, 16, 16); c.stroke(); c.fillRect(8.5, 8.5, 7, 7); },
82
+ device: (c) => { c.beginPath(); c.rect(7.5, 3, 9, 18); c.stroke(); dot(c, 12, 17.5, 1.3); },
83
+ floor: (c) => { c.beginPath(); c.moveTo(3.5, 20.5); c.lineTo(3.5, 15.5); c.lineTo(9, 15.5); c.lineTo(9, 10.5); c.lineTo(14.5, 10.5); c.lineTo(14.5, 5.5); c.lineTo(20.5, 5.5); c.stroke(); },
84
+ room: (c) => { c.beginPath(); c.rect(6.5, 3.5, 11, 17); c.stroke(); dot(c, 14.5, 12.5, 1.4); },
85
+ persona: (c) => { dot(c, 12, 8, 3.8); c.beginPath(); c.arc(12, 21, 8, Math.PI * 1.15, Math.PI * 1.85); c.stroke(); },
86
+ };
87
+ function line(c, x1, y1, x2, y2) { c.beginPath(); c.moveTo(x1, y1); c.lineTo(x2, y2); c.stroke(); }
88
+ function ring(c, x, y, r) { c.beginPath(); c.arc(x, y, r, 0, Math.PI * 2); c.stroke(); }
89
+ function dot(c, x, y, r) { c.beginPath(); c.arc(x, y, r, 0, Math.PI * 2); c.fill(); }
90
+
91
+ /** Draws a glyph on a 2D context sized `side` px, in `ink` (the tone was chosen against the node's fill, so the glyph needs no halo; it sits over the white core dot) */
92
+ export function drawGlyph(ctx, type, side, ink) {
93
+ const draw = PATHS[type];
94
+ if (!draw) return;
95
+ const k = side / GRID;
96
+ ctx.save();
97
+ ctx.scale(k, k);
98
+ ctx.lineWidth = 2.4;
99
+ ctx.lineCap = 'round';
100
+ ctx.lineJoin = 'round';
101
+ ctx.strokeStyle = ink;
102
+ ctx.fillStyle = ink;
103
+ draw(ctx);
104
+ ctx.restore();
105
+ }
106
+
107
+ const images = new Map();
108
+ /** Lets the images go (a test starts afresh with it) */
109
+ export const forgetGlyphImages = () => images.clear();
110
+
111
+ /**
112
+ * The image of a type's glyph in an ink, made once (null where there is no canvas to draw one on, as in a test without a browser, and for a type with no glyph).
113
+ * @param {string} type
114
+ * @param {string} ink a CSS colour
115
+ * @returns {CanvasImageSource | null}
116
+ */
117
+ export function glyphImage(type, ink) {
118
+ if (!hasGlyph(type) || typeof ink !== 'string') return null;
119
+ const key = glyphKey(type, ink);
120
+ if (images.has(key)) return images.get(key);
121
+ if (images.size >= MAX_GLYPH_IMAGES) return null;
122
+ let image = null;
123
+ try {
124
+ const canvas = typeof OffscreenCanvas !== 'undefined' ? new OffscreenCanvas(SIDE, SIDE) : typeof document !== 'undefined' ? Object.assign(document.createElement('canvas'), { width: SIDE, height: SIDE }) : null;
125
+ const ctx = canvas && canvas.getContext && canvas.getContext('2d');
126
+ if (ctx && ctx.stroke) { drawGlyph(ctx, type, SIDE, ink); image = canvas; }
127
+ } catch { image = null; }
128
+ images.set(key, image);
129
+ return image;
130
+ }
@@ -778,8 +778,8 @@ export const CLOUD_LINE_ALPHA = { run: 0.9, deploy: 0.25, renew: 0.9 };
778
778
  /** A line an outage travels, as outage-model.js `paintOutage` draws a walked edge */
779
779
  const OUTAGE_LINE = { alpha: 0.9, width: 2.2 };
780
780
  const WHENS = Object.keys(WHEN_STYLES);
781
- /** The `when` a drawn call is for, read off its dash (scene.js draws it with `whenDash`) */
782
- const whenOfDrawn = (e) => WHENS.find((w) => String(WHEN_STYLES[w].dash) === String(e.dash)) || 'run';
781
+ /** The `when` a drawn call is for, read off its ticks (scene.js draws it with `whenTicks`) */
782
+ const whenOfDrawn = (e) => WHENS.find((w) => WHEN_STYLES[w].ticks === (e.ticks || 0)) || 'run';
783
783
 
784
784
  /**
785
785
  * The Cloud band's lines, after the scene is built: with nothing selected, `deploy` lines quiet and the rest at full;