cornfield 0.43.0 → 0.45.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.
@@ -16,6 +16,8 @@
16
16
  * --corn-map-font the font list of every label on the map (a list of families, `auto` for the map's own)
17
17
  * --corn-map-edge-width the width of an ordinary line, in map px (`auto` keeps each line's own; the focus's and the marks' keep their proportion)
18
18
  * --corn-map-label-min the smallest a label is drawn on screen, in px (11 by default; below 9px it is ignored; a hub's title is 2 more)
19
+ * --corn-map-grey what a review greys (the nodes and lines a proposal does not involve) is drawn in: a colour, or `auto` for each one's own tone with its hue taken away
20
+ * --corn-map-grey-alpha how much of a greyed node is left: a number from 0.1 to 1 (`auto` is 0.45); its lines are faded in the same proportion
19
21
  * --corn-map-glow the soft glow round nodes, lines and packets: a factor (`0` none, `1` as drawn, `auto` as drawn)
20
22
  *
21
23
  * `auto` (the default of every one of them but the width and the collision) means "keep what the map draws without a theme": the
@@ -35,8 +37,10 @@
35
37
 
36
38
  import { NODE_THEMES } from '../core/schema.js';
37
39
  import { parseColor } from './theme-model.js';
38
- import { LABEL_MIN_FLOOR, looksFor } from './scene.js';
39
- import { iconKeyShape, iconKeysFor, mapGroupToken, mapKindToken } from '../core/layers.js';
40
+ import { cssColor, rgbaText } from './css-color.js';
41
+ export { cssColor };
42
+ import { GREY_ALPHA, LABEL_MIN_FLOOR, looksFor } from './scene.js';
43
+ import { iconKeyShape, iconKeysFor, mapFillNames, mapGroupToken, mapKindToken } from '../core/layers.js';
40
44
 
41
45
  /** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
42
46
  export const MAP_KINDS = Object.freeze(Object.keys(NODE_THEMES));
@@ -55,6 +59,10 @@ export const FONT_TOKEN = '--corn-map-font';
55
59
  export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
56
60
  export const GLOW_TOKEN = '--corn-map-glow';
57
61
  export const LABEL_MIN_TOKEN = '--corn-map-label-min';
62
+ export const GREY_TOKEN = '--corn-map-grey';
63
+ export const GREY_ALPHA_TOKEN = '--corn-map-grey-alpha';
64
+ /** The least a greyed node may be left at: under it the map would vanish (a value below is read as `auto`) */
65
+ export const MIN_GREY_ALPHA = 0.1;
58
66
  /** The ink of a node's glyph and of a finer kind's letters (spec 0008 D8); `auto` is the white or the dark that reads on the node's fill (glyphs.js) */
59
67
  export const GLYPH_TOKEN = '--corn-map-glyph';
60
68
  /** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
@@ -89,86 +97,18 @@ export const MAP_COLOR_TOKENS = Object.freeze([
89
97
  LABEL_TOKEN,
90
98
  LABEL_HALO_TOKEN,
91
99
  GLYPH_TOKEN,
100
+ GREY_TOKEN,
92
101
  ...MAP_EDGE_KINDS.map(edgeToken),
93
102
  ...MAP_MARKS.map(stateToken),
94
103
  ...MAP_STATES.map(stateToken),
95
104
  ]);
96
105
  /** Every map token */
97
- export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN];
106
+ export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN, GREY_ALPHA_TOKEN];
98
107
 
99
108
  // ---------------------------------------------------------------------------
100
109
  // Reading a token
101
110
  // ---------------------------------------------------------------------------
102
111
 
103
- let probe;
104
- const normalised = new Map();
105
-
106
- /** A canvas context to normalise a colour the way the browser reads it (`hsl()`, a name, `color-mix()`), or null where there is none */
107
- function probeContext() {
108
- if (probe !== undefined) return probe;
109
- probe = null;
110
- try { if (typeof document !== 'undefined') probe = document.createElement('canvas').getContext('2d', { willReadFrequently: true }) || null; } catch { probe = null; }
111
- return probe;
112
- }
113
-
114
- /**
115
- * 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.
116
- * @param {string} value
117
- * @returns {string | null}
118
- */
119
- export function cssColor(value) {
120
- const s = typeof value === 'string' ? value.trim() : '';
121
- if (!s || s.toLowerCase() === 'auto') return null;
122
- if (inRange(s)) return s;
123
- if (/^transparent$/i.test(s)) return 'rgba(0, 0, 0, 0)';
124
- if (normalised.has(s)) return normalised.get(s);
125
- let out = null;
126
- const ctx = isColor(s) && !/currentcolor/i.test(s) ? probeContext() : null; // a canvas has no current colour: it would read as black
127
- if (ctx) {
128
- try {
129
- // The browser's own reading: a value it refuses leaves fillStyle as it was, so two different starting colours tell a refusal
130
- // from a colour that happens to equal the first one
131
- const read = (from) => { ctx.fillStyle = from; ctx.fillStyle = s; return String(ctx.fillStyle); };
132
- const a = read('#010203');
133
- const got = a !== '#010203' ? a : read('#040506') !== '#040506' ? a : null;
134
- // A colour the browser keeps in another space (`oklch()`, `color(display-p3 ...)`) is read back as the sRGB pixel it paints
135
- out = got === null ? null : parseable(got) ? got : pixelOf(ctx, s);
136
- } catch { out = null; }
137
- }
138
- normalised.set(s, out);
139
- return out;
140
- }
141
-
142
- /** 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 */
143
- function isColor(s) {
144
- try { return typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || CSS.supports('color', s); } catch { return false; }
145
- }
146
-
147
- /** `#rgb`, `#rrggbb`, `rgb()` or `rgba()` with every channel in range: what both renderers read as written */
148
- function inRange(s) {
149
- if (!parseable(s)) return false;
150
- // The numbers as written: parseColor clamps them, and an out-of-range channel must go to the browser to be read
151
- const nums = /^rgba?\(/i.test(s.trim()) ? s.slice(s.indexOf('(') + 1, s.lastIndexOf(')')).split(',').map(Number) : null;
152
- if (nums && (nums.slice(0, 3).some((c) => !(c >= 0 && c <= 255)) || (nums.length > 3 && !(nums[3] > 0 && nums[3] <= 1)))) return false;
153
- const [r, g, b, a] = parseColor(s);
154
- return [r, g, b].every((c) => Number.isFinite(c) && c >= 0 && c <= 255) && Number.isFinite(a) && a > 0 && a <= 1;
155
- }
156
- /** The forms parseColor (theme-model.js) reads; anything else is normalised by the browser first */
157
- 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;
158
- const parseable = (s) => COLOR_RE.test(s.trim());
159
-
160
- /** The sRGB pixel `css` paints, as `rgba()` (or null when the context cannot be read) */
161
- function pixelOf(ctx, css) {
162
- if (!ctx.getImageData || !ctx.fillRect) return null;
163
- ctx.clearRect(0, 0, 1, 1);
164
- ctx.fillStyle = css;
165
- ctx.fillRect(0, 0, 1, 1);
166
- const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
167
- return rgbaText(r, g, b, a / 255);
168
- }
169
-
170
- const rgbaText = (r, g, b, a) => `rgba(${r}, ${g}, ${b}, ${+a.toFixed(3)})`;
171
-
172
112
  /** `token` as the colour of something that was `original`: the token's colour, with the original's own alpha kept (a faint line stays faint) */
173
113
  export function withAlphaOf(token, original) {
174
114
  const [r, g, b, a] = parseColor(token);
@@ -228,12 +168,19 @@ function factorOf(value) {
228
168
  return Number.isFinite(n) && n >= 0 && n <= MAX_GLOW ? n : null;
229
169
  }
230
170
 
171
+ /** The greyed node's opacity: a number from MIN_GREY_ALPHA to 1, or null for `auto` and anything else */
172
+ function greyAlphaOf(value) {
173
+ const m = /^\s*(\d*\.?\d+)\s*$/.exec(String(value ?? ''));
174
+ const n = m ? parseFloat(m[1]) : NaN;
175
+ return Number.isFinite(n) && n >= MIN_GREY_ALPHA && n <= 1 ? n : null;
176
+ }
177
+
231
178
  /**
232
179
  * The tokens as the page computes them.
233
180
  * @param {(name: string) => string} read the value of a custom property
234
181
  * @param {string[]} [extra] more colour tokens to read: those of the finer kinds and project layers on the map (`setMapSubjects`)
235
- * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null, labelMin: number | null}}
236
- * `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth`, `glow` and `labelMin` are null at `auto` or when the value is not one
182
+ * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null, labelMin: number | null, greyAlpha: number | null}}
183
+ * `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth`, `glow`, `labelMin` and `greyAlpha` are null at `auto` or when the value is not one
237
184
  */
238
185
  export function readMapTokens(read, extra = []) {
239
186
  const values = {};
@@ -249,6 +196,7 @@ export function readMapTokens(read, extra = []) {
249
196
  edgeWidth: pxOf(read(EDGE_WIDTH_TOKEN), MAX_EDGE_WIDTH),
250
197
  glow: factorOf(read(GLOW_TOKEN)),
251
198
  labelMin: labelMinOf(read(LABEL_MIN_TOKEN)),
199
+ greyAlpha: greyAlphaOf(read(GREY_ALPHA_TOKEN)),
252
200
  };
253
201
  }
254
202
 
@@ -318,12 +266,13 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
318
266
  * @property {number | null} edgeWidth an ordinary line's width in px (`--corn-map-edge-width`), null at `auto`
319
267
  * @property {number | null} glow the glow factor (`--corn-map-glow`), null at `auto`
320
268
  * @property {number | null} labelMin the smallest label size in px (`--corn-map-label-min`), null at `auto` or under 9px
269
+ * @property {number | null} greyAlpha how much of a greyed node is left (`--corn-map-grey-alpha`), null at `auto` or when it is not a number from 0.1 to 1
321
270
  * @property {ReturnType<typeof createIconStore> | null} icons
322
271
  * @property {boolean} pixelated sample icons without smoothing
323
272
  * @property {boolean} plain nothing to apply: no colour set, no icon loaded (the scene is drawn as it is)
324
273
  */
325
274
 
326
- const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null, labelMin: null };
275
+ const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null, labelMin: null, greyAlpha: null };
327
276
  let tokens = NO_TOKENS;
328
277
  let icons = null;
329
278
  let pixelated = false;
@@ -332,8 +281,8 @@ let current = compose();
332
281
  const listeners = new Set();
333
282
 
334
283
  function compose() {
335
- const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null && tokens.labelMin === null;
336
- return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, labelMin: tokens.labelMin, icons, pixelated, plain });
284
+ const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null && tokens.labelMin === null && tokens.greyAlpha === null;
285
+ return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, labelMin: tokens.labelMin, greyAlpha: tokens.greyAlpha, icons, pixelated, plain });
337
286
  }
338
287
 
339
288
  function changed() {
@@ -456,6 +405,12 @@ export function watchMapStyle(doc) {
456
405
 
457
406
  const firstOf = (values, names) => { for (const n of names) if (values[n]) return values[n]; return null; };
458
407
 
408
+ /** The tokens that can fill a node, most specific first (core/layers.js `mapFillNames`, the one place the order is written) */
409
+ export const fillNames = mapFillNames;
410
+
411
+ /** The theme's fill for a node of that kind, layer, type and group (`values` of a style), or null: the node then draws its own colour (`auto`) */
412
+ export const fillOf = (values, node) => firstOf(values, fillNames(node));
413
+
459
414
  /** A line's shape in the theme: its width scaled to `--corn-map-edge-width`, its glow and its packet's by `--corn-map-glow` (nothing at `auto`) */
460
415
  function shapeEdge(e, style) {
461
416
  const scale = style.edgeWidth == null ? 1 : style.edgeWidth / BASE_EDGE_WIDTH;
@@ -482,26 +437,43 @@ function styleEdge(e, style, painted) {
482
437
  return shapeEdge(out, style);
483
438
  }
484
439
 
440
+ /** A colour with its hue taken away: the grey of the same lightness, alpha kept. Both renderers read the same `rgb()` */
441
+ export function greyOf(color) {
442
+ const [r, g, b, a] = parseColor(color);
443
+ const l = Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b);
444
+ return a >= 1 ? `rgb(${l}, ${l}, ${l})` : rgbaText(l, l, l, a);
445
+ }
446
+
485
447
  function compute(scene, style) {
486
448
  const { values } = style;
449
+ const greyToken = values[GREY_TOKEN];
450
+ const fade = style.greyAlpha == null ? 1 : style.greyAlpha / GREY_ALPHA;
451
+ const toGrey = (c) => (greyToken ? withAlphaOf(greyToken, c) : greyOf(c));
487
452
  const label = values[LABEL_TOKEN];
488
453
  const stroke = values[STROKE_TOKEN];
489
454
  const painted = scene.painted || { nodes: new Set(), edges: new Set() };
490
455
  const nodes = scene.nodes.map((n) => {
491
456
  // Which fill wins, most specific first (spec 0009 D6): the finer kind, the project layer, the type, the starting layer
492
- const fill = !painted.nodes.has(n.id) && firstOf(values, [kindToken(n.type, n.kind), n.layer ? mapGroupToken(n.layer) : null, nodeToken(n.type), groupToken(n.group || n.type)].filter(Boolean));
457
+ const fill = !painted.nodes.has(n.id) && fillOf(values, n);
493
458
  const icon = style.icons ? iconKeysFor(n.type, n.kind, n.layer).find((k) => style.icons.get(k)) || null : null; // the same order: kind, layer, type
494
459
  const glows = style.glow != null && style.glow !== 1 && n.glow > 0;
495
- if (!fill && !label && !stroke && !icon && !glows) return n;
460
+ const grey = !!n.greyed && !painted.nodes.has(n.id); // a review greys what the change does not involve; a colour a painter gave means something and stays
461
+ if (!fill && !label && !stroke && !icon && !glows && !grey) return n;
496
462
  const out = { ...n };
497
463
  if (glows) out.glow = n.glow * style.glow;
498
464
  if (fill) out.color = fill;
499
465
  if (label) out.labelColor = withAlphaOf(label, n.labelColor);
500
- if (stroke && style.strokeWidth > 0) out.stroke = { color: stroke, width: style.strokeWidth };
501
- if (icon) out.icon = icon;
466
+ if (stroke && style.strokeWidth > 0) out.stroke = { color: grey ? toGrey(stroke) : stroke, width: style.strokeWidth };
467
+ if (icon && !grey) out.icon = icon; // a picture has its own hues: a greyed node keeps its silhouette, glyph and letters
468
+ if (grey) { out.color = toGrey(out.color); out.alpha = Math.min(1, n.alpha * fade); }
502
469
  return out;
503
470
  });
504
- const out = { ...scene, nodes, edges: scene.edges.map((e) => styleEdge(e, style, painted.edges)) };
471
+ const edges = scene.edges.map((e) => {
472
+ const styled = styleEdge(e, style, painted.edges);
473
+ if (!e.greyed || painted.edges.has(e.key)) return styled;
474
+ return { ...styled, color: toGrey(styled.color), glowColor: null, alpha: Math.min(1, styled.alpha * fade) };
475
+ });
476
+ const out = { ...scene, nodes, edges };
505
477
  if (style.font) out.labelFont = style.font; // every label's font list (labels.js reads `scene.labelFont`)
506
478
  if (style.labelMin != null) out.labelMin = style.labelMin; // the smallest label on screen (labels.js reads `scene.labelMin`)
507
479
  const halo = values[LABEL_HALO_TOKEN];
@@ -521,7 +493,7 @@ const sceneMemo = new WeakMap();
521
493
  * @param {MapStyle} [style]
522
494
  */
523
495
  export function styledScene(scene, style = current) {
524
- if (!style || style.plain) return scene;
496
+ if (!style || (style.plain && !scene.greying)) return scene; // a review's greying is applied even with no theme
525
497
  const hit = sceneMemo.get(scene);
526
498
  if (hit && hit.version === style.version) return hit.out;
527
499
  const out = compute(scene, style);
@@ -23,6 +23,7 @@ import { render, getScene, fitGraphToViewport, fitPadding, isNodeVisible, ensure
23
23
  import { frameNodes, largestGroup, READ_ZOOM, FRAME_ZOOM_MIN } from './camera.js';
24
24
  import { setMap } from './view.js';
25
25
  import { closeDrawer, selectNode } from './panels.js';
26
+ import { beginReview, endReview, renderLayerToggles, reviewLayersLine, setWholeMap } from './layers.js';
26
27
  import { edgePoint, looksFor } from './scene.js';
27
28
  import { onThemeChange } from './theme.js';
28
29
  import { looksWith, onMapStyleChange } from './map-style.js';
@@ -126,7 +127,7 @@ export async function openProposal(slug, source = null) {
126
127
  const sha256 = res.headers.get('X-Proposal-Sha256'); // the version on screen: a review names it, so a push since is refused, not approved unseen
127
128
  showProposal(item, { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true, sha256 });
128
129
  // said once, here: a proposal opens on a person's asking, never on a background refresh
129
- announce(reviewOpenedLine($('proposal-title').textContent));
130
+ announce([reviewOpenedLine($('proposal-title').textContent), reviewLayersLine()].filter(Boolean).join(' ')); // and, once, which layers the review hid
130
131
  return true;
131
132
  } catch (err) {
132
133
  console.error('Opening the proposal failed', err);
@@ -157,6 +158,7 @@ let openToken = 0;
157
158
  */
158
159
  export function showProposal(proposal, { slug = null, source = null, pinSource = false, view, fit = true, sha256 = null } = {}) {
159
160
  state.proposal = proposal;
161
+ beginReview(); // the map narrows to the change: a review of its own, the viewer's layers untouched (layers.js, layer-model.js)
160
162
  state.proposalSlug = slug;
161
163
  state.proposalSource = source;
162
164
  state.proposalSha256 = typeof sha256 === 'string' && /^[0-9a-f]{64}$/.test(sha256) ? sha256 : null;
@@ -190,6 +192,7 @@ export function rebuildProposalMap(effective = hooks.effective ? hooks.effective
190
192
  }
191
193
  swapMap(applied.nodes, applied.edges);
192
194
  renderBar(); // first: the fit below leaves out what the bar covers, so the bar must be laid out
195
+ renderLayerToggles(); // the menu follows the layers the change touches
193
196
  if (fit) fitToChange();
194
197
  render();
195
198
  ensureFlowLoop();
@@ -204,6 +207,7 @@ export function closeProposal() {
204
207
  state.proposalSource = null;
205
208
  state.proposalSha256 = null;
206
209
  state.proposalErrors = [];
210
+ endReview(); // the viewer's own layers are what is drawn again, exactly as they were
207
211
  swapMap(state.baseNodes.map((n) => ({ ...n })), state.baseEdges);
208
212
  fitGraphToViewport(fitPadding());
209
213
  render();
@@ -387,6 +391,14 @@ export function renderBar() {
387
391
  btn.classList.toggle('is-on', on);
388
392
  }
389
393
 
394
+ const whole = $('proposal-whole'); // the switch is the review's: off at every opening, kept across Before, Diff and After
395
+ if (whole) { // the pressed look is the one the bar's other chosen buttons have (it holds on hover)
396
+ const on = !!(state.review && state.review.whole);
397
+ whole.setAttribute('aria-pressed', String(on));
398
+ whole.title = t('showWholeMap'); // the words are short ("Whole map"); the tooltip says it in full, as its name does
399
+ whole.classList.toggle('hx-btn--active', on);
400
+ }
401
+
390
402
  const errors = state.proposalErrors || [];
391
403
  const box = $('proposal-errors');
392
404
  box.hidden = errors.length === 0;
@@ -611,6 +623,7 @@ const ACTIONS = {
611
623
  'toggle-proposals-menu': () => toggleMenu(),
612
624
  'open-proposal': (el) => openProposal(el.dataset.slug, el.dataset.source || null),
613
625
  'close-proposal': () => closeProposal(),
626
+ 'proposal-whole': () => { setWholeMap(!(state.review && state.review.whole)); renderBar(); }, // "Show the whole map": announced by layers.js, the focus stays on the switch
614
627
  'proposal-view': (el) => { setProposalView(el.dataset.view); toggleMode(false); },
615
628
  'toggle-proposal-mode': () => toggleMode(),
616
629
  'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
@@ -21,6 +21,8 @@ import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
21
21
  // Visibility and focus (decided in scene.js, kept here under their old names)
22
22
  // ---------------------------------------------------------------------------
23
23
  export const isNodeVisible = (node) => nodeVisible(state, node);
24
+ /** Whether the viewer's own layers show the node, whatever a review has hidden (what-if's list of the other end of an edge) */
25
+ export const isNodeVisibleToViewer = (node) => nodeVisible(state, node, { viewer: true });
24
26
 
25
27
  /** The focus subgraph: the selected node and every node one edge away (selection-model.js); the switch and the kind come from the state */
26
28
  export const getActiveSubgraph = (selected, edges = viewEdges(), opts = { throughChildren: !!state.throughChildren, kind: state.selectedKind || null }) => activeSubgraph(selected, edges, opts);
@@ -14,6 +14,7 @@
14
14
  */
15
15
 
16
16
  import { state } from './state.js';
17
+ import { layerOn } from './layer-model.js';
17
18
  import { render, onPaint } from './render.js';
18
19
  import { overlayOf } from './runs-model.js';
19
20
  import { flowReduceMotion } from './flows.js';
@@ -40,7 +41,7 @@ const reducedMotion = () => (reduce === null ? flowReduceMotion : reduce);
40
41
  export function setReducedMotionForTests(on) { reduce = on; }
41
42
 
42
43
  /** Whether the layer is on */
43
- export const runsLayerOn = () => state.activeLayers[RUNS_LAYER] !== false;
44
+ export const runsLayerOn = () => layerOn(state, RUNS_LAYER); // the viewer's layer, or the review's (layer-model.js)
44
45
 
45
46
  /** Hands the map the runs the API listed: what pulses and what collides is worked out here, and the map is drawn again */
46
47
  export function setRunsOnMap(runs) {
@@ -30,9 +30,9 @@ import { createPlayer, cameraFor, parseSpeed, SPEED_CHOICES, SPEED_KEY } from '.
30
30
  import { edgeKey } from '../core/proposal.js';
31
31
  import { checksVersion, closeChecks, decorateSnapshot, openChecks, paintChecks } from './check.js';
32
32
  import { blastRadius, outageLayers, outageScenario } from './outage-model.js';
33
- import { toggleLayer, LAYER_DEFS } from './layers.js';
33
+ import { setLayer, clearStepLayers, LAYER_DEFS } from './layers.js';
34
34
  import { externalLayer } from './cloud-model.js';
35
- import { projectLayerKey, shownByProposal } from './layer-model.js';
35
+ import { layerOn, layersOf, projectLayerKey, shownByProposal } from './layer-model.js';
36
36
  import { announce } from './keyboard.js';
37
37
  import { t } from './strings.js';
38
38
  import { currentStepSentence } from './scenario-list-model.js';
@@ -135,7 +135,7 @@ function giveFocusBack() {
135
135
  function showOutageLayers(scenario) {
136
136
  if (!scenario || !Array.isArray(scenario.down) || !scenario.down.length) return;
137
137
  outageLayers(blastRadius(scenario.down, state.nodes, state.edges), state.nodes)
138
- .forEach((key) => { if (state.activeLayers[key] === false) toggleLayer(key); });
138
+ .forEach((key) => { if (!layerOn(state, key)) setLayer(key, true, { scenario: true }); });
139
139
  }
140
140
 
141
141
  /**
@@ -144,12 +144,13 @@ function showOutageLayers(scenario) {
144
144
  */
145
145
  export function layersHiding(node) {
146
146
  if (!node || state.view === 'dataflow' || state.view === 'house') return [];
147
- const on = (key) => state.activeLayers[key] !== false;
147
+ const layers = layersOf(state); // what is drawn: the viewer's layers, or the review's (layer-model.js)
148
+ const on = (key) => layers[key] !== false;
148
149
  const t = node.type;
149
150
  if (t === 'root' || shownByProposal(state, node)) return []; // a proposal's own nodes are drawn whatever their layer says (spec 0009 D3)
150
151
  const project = projectLayerKey(state, node); // a project layer that takes the node decides alone (spec 0009 D3), as scene.js layerShows has it
151
152
  if (project) return on(project) ? [] : [project];
152
- if (t === 'core') return [...(on('core') ? [] : ['core']), ...(state.activeLayers.pkg || state.activeLayers.atom ? [] : ['pkg'])];
153
+ if (t === 'core') return [...(on('core') ? [] : ['core']), ...(layers.pkg || layers.atom ? [] : ['pkg'])];
153
154
  if (t === 'store') return ['flow', 'store'].filter((k) => !on(k));
154
155
  if (t === 'rom') return ['rom', 'flow'].filter((k) => !on(k));
155
156
  if (t === 'floor' || t === 'room') return on('house') ? [] : ['house'];
@@ -169,7 +170,7 @@ function showStepLayers(scenario) {
169
170
  const keys = [];
170
171
  for (const id of stepNodeIds(scenario)) for (const key of layersHiding(byId.get(id))) if (!keys.includes(key)) keys.push(key);
171
172
  if (!keys.length) return;
172
- for (const key of keys) { if (key === 'pkg') state.activeLayers.pkg = false; toggleLayer(key); }
173
+ for (const key of keys) setLayer(key, true, { scenario: true }); // on, for the review too (state.review.step): stopping the scenario takes it off again
173
174
  const names = keys.map((key) => (LAYER_DEFS.find((l) => l.key === key) || (state.projectLayers || []).find((l) => l.key === key) || { label: key }).label);
174
175
  announce(`Turned on ${names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : names[0]} to show this scenario's steps.`);
175
176
  }
@@ -187,6 +188,7 @@ export const getPlayer = () => player;
187
188
  /** Ends the scenario without touching the picture: for callers that rebuild it themselves (selecting a node, switching view). `keepChecks` while another scenario is about to start */
188
189
  export function clearScenario({ keepChecks = false, closing = false } = {}) {
189
190
  const had = !!player || !!state.scenario;
191
+ if (had) clearStepLayers(); // the layers this scenario turned on for a review go off with it: the focused view comes back
190
192
  player = null;
191
193
  glide = null;
192
194
  signature = '';
package/explorer/scene.js CHANGED
@@ -171,15 +171,16 @@ import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-m
171
171
  import { decorateHouseScene, houseEdgeStyle, houseShowsNode, houseViewEdges } from './house-model.js';
172
172
  import { paintVerdict } from './check-model.js';
173
173
  import { externalLayer, whenTicks } from './cloud-model.js';
174
- import { lettersOf, projectLayerKey, shownByProposal } from './layer-model.js';
175
- import { shapeOf } from '../core/schema.js';
174
+ import { greying, lettersOf, projectLayerKey, shownByProposal, layersOf } from './layer-model.js';
175
+ import { NODE_THEMES, shapeOf } from '../core/schema.js';
176
176
  import { hasGlyph } from './glyphs.js';
177
177
  import { outageFor, paintOutage } from './outage-model.js';
178
178
  import { paintForge } from './forge-panel-model.js';
179
179
  import { lightColor, lightenScene, parseColor } from './theme-model.js';
180
180
  import { matchIds } from './search-model.js';
181
+ import { nodeColor } from './css-color.js';
181
182
  import { activeSubgraph, kindEdgeWord } from './selection-model.js';
182
- import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
183
+ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, GREY_ALPHA, GREY_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
183
184
 
184
185
  // ---------------------------------------------------------------------------
185
186
  // Constants every renderer shares, so the looks cannot drift apart
@@ -274,21 +275,25 @@ const LIGHT_LOOKS = Object.freeze({
274
275
  export const MARK_MIN_PX = { ring: 1.8, edge: 1.6, gap: 4 };
275
276
  /** How bright what a proposal does not touch is in the Diff view: dim, but still plainly there */
276
277
  export const PROPOSAL_DIM_ALPHA = 0.28;
278
+ export { GREY_ALPHA }; // how much of a greyed node is left (diff-marks.js): its colour is taken away at draw time (map-style.js `--corn-map-grey`), a greyed line is faded as Diff fades one (PROPOSAL_DIM_ALPHA)
277
279
 
278
280
  // ---------------------------------------------------------------------------
279
281
  // Visibility and focus (moved unchanged from render.js)
280
282
  // ---------------------------------------------------------------------------
281
- export function isNodeVisible(state, node) {
283
+ /**
284
+ * Whether the map draws a node. `viewer`: as the viewer's own layers say, whatever a review has hidden (a list of what could be picked while the review
285
+ * narrows the map, such as the other end of a what-if edge: the edge, once drawn, brings its two ends' layers on).
286
+ */
287
+ export function isNodeVisible(state, node, { viewer = false } = {}) {
282
288
  if (state.proposal && !showsNode(state.proposalView || 'diff', node)) return false; // Before hides what is added, After what is removed
283
289
  if (state.view === 'dataflow') return !!state.flow && state.flow.ids.has(node.id);
284
290
  if (state.view === 'house') return houseShowsNode(state, node); // the House view (spec 0029, PHY-11) draws its own set: house-model.js
285
291
  if (node.type === 'root') return true;
286
- return layerShows(state, node) || shownByProposal(state, node); // a proposal's own nodes are drawn whatever their layer says (spec 0009 D3)
292
+ return layerShows(state, node, viewer ? state.activeLayers : layersOf(state)) || shownByProposal(state, node); // a proposal's own nodes are drawn whatever their layer says (spec 0009 D3)
287
293
  }
288
294
 
289
295
  /** Whether the Layers menu has the node's layer on: a project layer that takes it decides alone, else its starting layer, with the rules each type has */
290
- export function layerShows(state, node) {
291
- const { activeLayers } = state;
296
+ export function layerShows(state, node, activeLayers = layersOf(state)) { // the viewer's layers, or a review's (layer-model.js `layersOf`): the one place that decides
292
297
  const project = projectLayerKey(state, node);
293
298
  if (project) return activeLayers[project] !== false;
294
299
  if (node.type === 'core') return (activeLayers.pkg || activeLayers.atom) && activeLayers.core !== false; // its own row in Layers, and Packages or Atoms
@@ -461,10 +466,11 @@ const FLOW_LIKE = ['flow', 'reads', 'writes', 'runs-on', 'calls', 'triggers', 'd
461
466
  const proposalView = (state) => (state.proposal ? state.proposalView || 'diff' : null);
462
467
 
463
468
  /** Puts a proposal mark on a scene edge: its colour, dash and weight; in Diff what is not marked fades back */
464
- function styleForProposal(edge, mark, view, gone = false) {
469
+ function styleForProposal(edge, mark, view, gone = false, grey = false) {
465
470
  edge.mark = mark;
466
471
  if (mark === 'none') {
467
- if (view === 'diff') { edge.alpha *= PROPOSAL_DIM_ALPHA; edge.glow = 0; edge.packet = null; }
472
+ if (view === 'diff' || grey) { edge.alpha *= PROPOSAL_DIM_ALPHA; edge.glow = 0; edge.packet = null; } // Before and After fade it too while a review greys it
473
+ if (grey) edge.greyed = true; // its colour is taken away at draw time (map-style.js)
468
474
  return;
469
475
  }
470
476
  const look = MARK[mark];
@@ -476,7 +482,9 @@ function styleForProposal(edge, mark, view, gone = false) {
476
482
  }
477
483
 
478
484
  function buildEdges(state, subgraph, reduceMotion) {
479
- const { nodes, activeLayers } = state;
485
+ const { nodes } = state;
486
+ const activeLayers = layersOf(state);
487
+ const grey = greying(state);
480
488
  const byId = new Map(nodes.map((n) => [n.id, n]));
481
489
  const preset = state.view === 'dataflow';
482
490
  const out = [];
@@ -536,7 +544,7 @@ function buildEdges(state, subgraph, reduceMotion) {
536
544
  if (preset || FLOW_LIKE.includes(edge.kind)) flow(edge, source, target);
537
545
  else out.push(linkEdge(edge, source, target, subgraph));
538
546
  }
539
- for (let i = first; i < out.length; i++) styleForProposal(out[i], mark, view, mark === 'edit' && applied.editOp === 'removed');
547
+ for (let i = first; i < out.length; i++) styleForProposal(out[i], mark, view, mark === 'edit' && applied.editOp === 'removed', grey);
540
548
  });
541
549
  return out;
542
550
  }
@@ -547,13 +555,21 @@ function buildEdges(state, subgraph, reduceMotion) {
547
555
  /** A node's group: its layer in the Layers menu (layers.js), one per kind but for the rooms and floors (House) and the outside nodes (Cloud, or the Public web) */
548
556
  export const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
549
557
 
558
+ /**
559
+ * A node's fill before any theme token: its own `color` when that is a colour the browser reads, else its type's fill in NODE_THEMES (the
560
+ * built-in the map's fill order ends on, core/layers.js `mapFillNames`). Checked here, once, so WebGL and Canvas 2D are given the same valid
561
+ * fill and project data never reaches a shader or a `fillStyle` unchecked. The Layers menu's dot of a project layer reads it too (layers.js).
562
+ */
563
+ export const fillOfNode = (node) => nodeColor(node.color) ?? (NODE_THEMES[node.type] || NODE_THEMES.external).color;
564
+
550
565
  function buildNodes(state, subgraph) {
551
566
  const { nodes, selectedNode, searchQuery } = state;
552
567
  const found = searchQuery ? matchIds(nodes, searchQuery) : null; // what the search finds: label, id, file, type, kind (search-model.js)
553
568
  const searching = !!found && nodes.some((n) => found.has(n.id) && isNodeVisible(state, n)); // with no match on the map nothing dims: it would only be a blank map
554
569
  const out = [];
555
570
  const view = proposalView(state);
556
- const focus = view === 'diff' ? touchedIds(nodes, viewEdgesOf(state)) : null;
571
+ const grey = greying(state); // a review greys what the change does not involve, in Before and After as in Diff
572
+ const focus = view === 'diff' || (view && grey) ? touchedIds(nodes, viewEdgesOf(state)) : null;
557
573
 
558
574
  nodes.forEach((node) => {
559
575
  if (!isNodeVisible(state, node)) return;
@@ -571,7 +587,8 @@ function buildNodes(state, subgraph) {
571
587
  // A search's matches are what the reader asked for: a selection's focus does not dim them, so each keeps its label (spec 0008 D4)
572
588
  let alpha = subgraph && !connected && !(searching && match) ? DIM_ALPHA : 1;
573
589
  if (searching && !match && !selected && !(subgraph && connected)) alpha = DIM_ALPHA; // a search dims what it did not find, as a focus does
574
- if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, PROPOSAL_DIM_ALPHA);
590
+ const greyed = grey && !!focus && !focus.touched.has(node.id);
591
+ if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, greyed ? GREY_ALPHA : PROPOSAL_DIM_ALPHA);
575
592
  if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
576
593
  const big = shown.type === 'root' || shown.type === 'app';
577
594
  // A finer kind (spec 0009): its letters, drawn in the node's core by the renderers (kind-letters.js), and the project layer that takes the node
@@ -586,19 +603,21 @@ function buildNodes(state, subgraph) {
586
603
  hitR: shown.r * SHAPE_REACH[shapeOf(shown.type)], // the disc a click or tap hits: as far as the silhouette reaches (spatial.js)
587
604
  ...(hasGlyph(shown.type) ? { glyph: shown.type } : {}), // its built-in glyph, drawn where the core dot is once the node is wide enough (glyphs.js)
588
605
  ...(layer ? { layer } : {}),
589
- x: node.x, y: node.y, r: shown.r, color: shown.color,
606
+ x: node.x, y: node.y, r: shown.r, color: fillOfNode(shown),
590
607
  alpha,
591
608
  glow: connected && alpha >= 0.5 ? (big ? 15 : 9) : 0,
592
609
  halo: match ? 'match' : selected ? 'selected' : child ? 'child' : 'none',
593
610
  mark,
611
+ ...(greyed ? { greyed: true } : {}), // not involved in the change: its colour is taken away at draw time, glyph and letters stay (map-style.js)
594
612
  selected, match, current, connected,
595
613
  degree: node.degree || 0,
596
614
  label: shown.label,
597
- labelSize: big ? 12 : 11,
598
- labelBold: big,
599
- labelAlpha: focus && !focus.touched.has(node.id) && !(subgraph && !connected) ? Math.max(alpha, DIFF_LABEL_ALPHA) : alpha, // a label the diff dims stays 3:1
615
+ labelSize: big && !greyed ? 12 : 11, // a greyed node's label recedes (issue #232): plain, at the least size, placed last (labels.js)
616
+ labelBold: big && !greyed,
617
+ labelAlpha: greyed && !(subgraph && !connected) ? GREY_LABEL_ALPHA[state.theme === 'light' ? 'light' : 'dark'] // a greyed node's label: at the dimmed-label floor on either ground
618
+ : focus && !focus.touched.has(node.id) && !(subgraph && !connected) ? Math.max(alpha, DIFF_LABEL_ALPHA) : alpha, // a label the diff dims stays 3:1
600
619
  labelColor: connected ? '#f8fafc' : 'rgba(255, 255, 255, 0.3)',
601
- labelKeep: LANDMARK_TYPES.includes(shown.type) || selected || match || mark !== 'none' || !!(subgraph && connected),
620
+ labelKeep: (LANDMARK_TYPES.includes(shown.type) && !greyed) || selected || match || mark !== 'none' || !!(subgraph && connected),
602
621
  labelStrike: !!look && (look.strike || gone),
603
622
  live: !!node.live,
604
623
  box: node.box || null,
@@ -725,6 +744,7 @@ export function buildScene(state, opts = {}) {
725
744
  };
726
745
  if (state.view === 'house') decorateHouseScene(scene, state); // its bands and tray as lanes, rooms unlabelled (house-model.js)
727
746
  if (state.scenario) emphasiseScenario(scene, state.scenario, opts);
747
+ scene.greying = scene.nodes.some((n) => n.greyed) || scene.edges.some((e) => e.greyed);
728
748
  const colours = { nodes: scene.nodes.map((n) => n.color), edges: scene.edges.map((e) => e.color) };
729
749
  if (state.scenario) paintOutage(scene, outageFor(state.scenario, state.nodes, state.edges)); // CLOUD-07: red, amber, violet by when the outage bites
730
750
  if (state.scenario) paintVerdict(scene, state.scenario); // PHY-10: red, green or amber by the step's permission check
@@ -23,7 +23,7 @@ import { isPhone, visibleMapRect } from './sheets.js';
23
23
  import { announce } from './keyboard.js';
24
24
  import { flyTo } from './fly.js';
25
25
  import { groupOf } from './scene.js';
26
- import { projectLayerKey } from './layer-model.js';
26
+ import { layerOn, projectLayerKey } from './layer-model.js';
27
27
  import { noMatchText, showSearchStatus, updateSearchStatus } from './search-status.js';
28
28
  import { countText, moreLine, noMatchLine, searchNodes, stepIndex } from './search-model.js';
29
29
 
@@ -176,7 +176,7 @@ function showLayerOf(node) {
176
176
  const tries = [projectLayerKey(state, node), groupOf(node), node.type === 'store' || node.type === 'rom' ? 'flow' : null, node.type === 'core' ? 'pkg' : null, node.type === 'core' ? 'core' : null];
177
177
  for (const key of tries) {
178
178
  if (isNodeVisible(node)) return;
179
- if (key && state.activeLayers[key] === false) toggleLayer(key);
179
+ if (key && !layerOn(state, key)) toggleLayer(key);
180
180
  }
181
181
  }
182
182
 
package/explorer/state.js CHANGED
@@ -71,6 +71,14 @@ export const state = {
71
71
  layerOrder: [],
72
72
  layerDefaults: {},
73
73
 
74
+ /**
75
+ * The review of the open proposal, which narrows the map to the change (issue #232; explorer/layer-model.js `layersOf`): null with no proposal open,
76
+ * else `{ whole, manual, step, rev }`. `whole`: "Show the whole map" is on, the map is as Diff always was. `manual`: layers the reviewer turned on or
77
+ * off by hand in this review, `step`: the ones a playing scenario turned on (both `{ key: boolean }`). `rev` moves with each change.
78
+ * None of it is the viewer's: `activeLayers` and the saved choices (layers.js) are never written while it is set.
79
+ */
80
+ review: null,
81
+
74
82
  /**
75
83
  * The map as the last `setMap` (view.js) was handed it, before the live layer is laid in: the base
76
84
  * copies, or a proposal applied over them. `nodes` and `edges` are these plus the live ones.
@@ -115,6 +115,13 @@
115
115
  --corn-space-5: 16px;
116
116
  --corn-space-6: 24px;
117
117
 
118
+ /* Density (issue #200). The one height of a control in a bar (the header, the proposal bar, the decision foot, the player, the Work panel's top row):
119
+ 32px at a desk, 44px on a phone (the media query after the light blocks). The padding of a panel's body, which the Work panel and the node panel share,
120
+ and the least height of a panel's head: a control and a step of padding */
121
+ --corn-control-height: 32px;
122
+ --corn-panel-pad: calc(var(--corn-space-5) + var(--corn-space-1));
123
+ --corn-panel-head-height: calc(var(--corn-control-height) + var(--corn-space-3));
124
+
118
125
  /* The House view's plan: the house's outline and each room's */
119
126
  --corn-house-line: color-mix(in srgb, var(--corn-hue-lime) 18%, transparent);
120
127
  --corn-house-room: color-mix(in srgb, var(--corn-hue-lime) 45%, transparent);
@@ -140,6 +147,9 @@
140
147
  /* The smallest a map label is drawn on screen (spec 0008): auto is 11px; a theme may raise it, not lower it. A hub's title is 2px more */
141
148
  --corn-map-label-min: auto;
142
149
  --corn-map-glyph: auto;
150
+ /* What a review greys (the nodes and lines a proposal does not involve): a colour (auto: each one's own tone, its hue taken away) and how much of a node is left (auto: 0.45; 0.1 to 1) */
151
+ --corn-map-grey: auto;
152
+ --corn-map-grey-alpha: auto;
143
153
  /* Diff, selection and focus */
144
154
  --corn-map-added: auto;
145
155
  --corn-map-changed: auto;
@@ -302,6 +312,11 @@
302
312
  color-scheme: light;
303
313
  }
304
314
 
315
+ /* A phone's density: controls are 44px tall (the target), and a panel pads by 16px under 640px. explorer.css floors a phone's control at 44px whatever
316
+ a brand sets (max(44px, …)); a brand that sets --corn-panel-pad on :root sets a phone's too, unless it sets it again under the same query */
317
+ @media (max-width: 767px) { :root { --corn-control-height: 44px; } }
318
+ @media (max-width: 639px) { :root { --corn-panel-pad: var(--corn-space-5); } }
319
+
305
320
  /* ==========================================================================
306
321
  The old --hx-* names, as aliases of the tokens above, for one release (scene.js, proposal.js and plugin
307
322
  CSS still read them). They go in the next minor: write --corn-* in new CSS. proposal.js writes
@@ -21,7 +21,7 @@
21
21
  */
22
22
 
23
23
  import { state, touchScene, onSceneTouch, nameOf, nodeById, escHtml } from './state.js';
24
- import { render, isNodeVisible } from './render.js';
24
+ import { render, isNodeVisible, isNodeVisibleToViewer } from './render.js';
25
25
  import { hooks, rebuildProposalMap, closeProposal, focusChange } from './proposal.js';
26
26
  import { t } from './strings.js';
27
27
  import { getPlayer, playScenario, stopScenario, tickScenario } from './scenario-ui.js';
@@ -637,7 +637,7 @@ function removalIndex(op, match) {
637
637
  const EDGE_TO_MAX = 300;
638
638
  function edgeToHtml(n) {
639
639
  const others = state.nodes
640
- .filter((o) => o.id !== n.id && isNodeVisible(o) && kindOfMark(o) !== 'removed')
640
+ .filter((o) => o.id !== n.id && isNodeVisibleToViewer(o) && kindOfMark(o) !== 'removed') // a review narrows the map, but what the viewer has on can be picked: the edge brings its ends' layers on
641
641
  .sort((a, b) => String(a.label).localeCompare(String(b.label)))
642
642
  .slice(0, EDGE_TO_MAX);
643
643
  if (!others.length) return '';