cornfield 0.44.0 → 0.46.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
@@ -37,7 +39,7 @@ import { NODE_THEMES } from '../core/schema.js';
37
39
  import { parseColor } from './theme-model.js';
38
40
  import { cssColor, rgbaText } from './css-color.js';
39
41
  export { cssColor };
40
- import { LABEL_MIN_FLOOR, looksFor } from './scene.js';
42
+ import { GREY_ALPHA, LABEL_MIN_FLOOR, looksFor } from './scene.js';
41
43
  import { iconKeyShape, iconKeysFor, mapFillNames, mapGroupToken, mapKindToken } from '../core/layers.js';
42
44
 
43
45
  /** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
@@ -57,6 +59,10 @@ export const FONT_TOKEN = '--corn-map-font';
57
59
  export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
58
60
  export const GLOW_TOKEN = '--corn-map-glow';
59
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;
60
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) */
61
67
  export const GLYPH_TOKEN = '--corn-map-glyph';
62
68
  /** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
@@ -91,12 +97,13 @@ export const MAP_COLOR_TOKENS = Object.freeze([
91
97
  LABEL_TOKEN,
92
98
  LABEL_HALO_TOKEN,
93
99
  GLYPH_TOKEN,
100
+ GREY_TOKEN,
94
101
  ...MAP_EDGE_KINDS.map(edgeToken),
95
102
  ...MAP_MARKS.map(stateToken),
96
103
  ...MAP_STATES.map(stateToken),
97
104
  ]);
98
105
  /** Every map token */
99
- 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];
100
107
 
101
108
  // ---------------------------------------------------------------------------
102
109
  // Reading a token
@@ -161,12 +168,19 @@ function factorOf(value) {
161
168
  return Number.isFinite(n) && n >= 0 && n <= MAX_GLOW ? n : null;
162
169
  }
163
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
+
164
178
  /**
165
179
  * The tokens as the page computes them.
166
180
  * @param {(name: string) => string} read the value of a custom property
167
181
  * @param {string[]} [extra] more colour tokens to read: those of the finer kinds and project layers on the map (`setMapSubjects`)
168
- * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null, labelMin: number | null}}
169
- * `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
170
184
  */
171
185
  export function readMapTokens(read, extra = []) {
172
186
  const values = {};
@@ -182,6 +196,7 @@ export function readMapTokens(read, extra = []) {
182
196
  edgeWidth: pxOf(read(EDGE_WIDTH_TOKEN), MAX_EDGE_WIDTH),
183
197
  glow: factorOf(read(GLOW_TOKEN)),
184
198
  labelMin: labelMinOf(read(LABEL_MIN_TOKEN)),
199
+ greyAlpha: greyAlphaOf(read(GREY_ALPHA_TOKEN)),
185
200
  };
186
201
  }
187
202
 
@@ -251,12 +266,13 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
251
266
  * @property {number | null} edgeWidth an ordinary line's width in px (`--corn-map-edge-width`), null at `auto`
252
267
  * @property {number | null} glow the glow factor (`--corn-map-glow`), null at `auto`
253
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
254
270
  * @property {ReturnType<typeof createIconStore> | null} icons
255
271
  * @property {boolean} pixelated sample icons without smoothing
256
272
  * @property {boolean} plain nothing to apply: no colour set, no icon loaded (the scene is drawn as it is)
257
273
  */
258
274
 
259
- 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 };
260
276
  let tokens = NO_TOKENS;
261
277
  let icons = null;
262
278
  let pixelated = false;
@@ -265,8 +281,8 @@ let current = compose();
265
281
  const listeners = new Set();
266
282
 
267
283
  function compose() {
268
- const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null && tokens.labelMin === null;
269
- 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 });
270
286
  }
271
287
 
272
288
  function changed() {
@@ -421,8 +437,18 @@ function styleEdge(e, style, painted) {
421
437
  return shapeEdge(out, style);
422
438
  }
423
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
+
424
447
  function compute(scene, style) {
425
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));
426
452
  const label = values[LABEL_TOKEN];
427
453
  const stroke = values[STROKE_TOKEN];
428
454
  const painted = scene.painted || { nodes: new Set(), edges: new Set() };
@@ -431,16 +457,23 @@ function compute(scene, style) {
431
457
  const fill = !painted.nodes.has(n.id) && fillOf(values, n);
432
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
433
459
  const glows = style.glow != null && style.glow !== 1 && n.glow > 0;
434
- 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;
435
462
  const out = { ...n };
436
463
  if (glows) out.glow = n.glow * style.glow;
437
464
  if (fill) out.color = fill;
438
465
  if (label) out.labelColor = withAlphaOf(label, n.labelColor);
439
- if (stroke && style.strokeWidth > 0) out.stroke = { color: stroke, width: style.strokeWidth };
440
- 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); }
441
469
  return out;
442
470
  });
443
- 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 };
444
477
  if (style.font) out.labelFont = style.font; // every label's font list (labels.js reads `scene.labelFont`)
445
478
  if (style.labelMin != null) out.labelMin = style.labelMin; // the smallest label on screen (labels.js reads `scene.labelMin`)
446
479
  const halo = values[LABEL_HALO_TOKEN];
@@ -460,7 +493,7 @@ const sceneMemo = new WeakMap();
460
493
  * @param {MapStyle} [style]
461
494
  */
462
495
  export function styledScene(scene, style = current) {
463
- 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
464
497
  const hit = sceneMemo.get(scene);
465
498
  if (hit && hit.version === style.version) return hit.out;
466
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,7 +171,7 @@ 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';
174
+ import { greying, lettersOf, projectLayerKey, shownByProposal, layersOf } from './layer-model.js';
175
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';
@@ -180,7 +180,7 @@ import { lightColor, lightenScene, parseColor } from './theme-model.js';
180
180
  import { matchIds } from './search-model.js';
181
181
  import { nodeColor } from './css-color.js';
182
182
  import { activeSubgraph, kindEdgeWord } from './selection-model.js';
183
- 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';
184
184
 
185
185
  // ---------------------------------------------------------------------------
186
186
  // Constants every renderer shares, so the looks cannot drift apart
@@ -275,21 +275,25 @@ const LIGHT_LOOKS = Object.freeze({
275
275
  export const MARK_MIN_PX = { ring: 1.8, edge: 1.6, gap: 4 };
276
276
  /** How bright what a proposal does not touch is in the Diff view: dim, but still plainly there */
277
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)
278
279
 
279
280
  // ---------------------------------------------------------------------------
280
281
  // Visibility and focus (moved unchanged from render.js)
281
282
  // ---------------------------------------------------------------------------
282
- 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 } = {}) {
283
288
  if (state.proposal && !showsNode(state.proposalView || 'diff', node)) return false; // Before hides what is added, After what is removed
284
289
  if (state.view === 'dataflow') return !!state.flow && state.flow.ids.has(node.id);
285
290
  if (state.view === 'house') return houseShowsNode(state, node); // the House view (spec 0029, PHY-11) draws its own set: house-model.js
286
291
  if (node.type === 'root') return true;
287
- 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)
288
293
  }
289
294
 
290
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 */
291
- export function layerShows(state, node) {
292
- 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
293
297
  const project = projectLayerKey(state, node);
294
298
  if (project) return activeLayers[project] !== false;
295
299
  if (node.type === 'core') return (activeLayers.pkg || activeLayers.atom) && activeLayers.core !== false; // its own row in Layers, and Packages or Atoms
@@ -462,10 +466,11 @@ const FLOW_LIKE = ['flow', 'reads', 'writes', 'runs-on', 'calls', 'triggers', 'd
462
466
  const proposalView = (state) => (state.proposal ? state.proposalView || 'diff' : null);
463
467
 
464
468
  /** Puts a proposal mark on a scene edge: its colour, dash and weight; in Diff what is not marked fades back */
465
- function styleForProposal(edge, mark, view, gone = false) {
469
+ function styleForProposal(edge, mark, view, gone = false, grey = false) {
466
470
  edge.mark = mark;
467
471
  if (mark === 'none') {
468
- 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)
469
474
  return;
470
475
  }
471
476
  const look = MARK[mark];
@@ -477,7 +482,9 @@ function styleForProposal(edge, mark, view, gone = false) {
477
482
  }
478
483
 
479
484
  function buildEdges(state, subgraph, reduceMotion) {
480
- const { nodes, activeLayers } = state;
485
+ const { nodes } = state;
486
+ const activeLayers = layersOf(state);
487
+ const grey = greying(state);
481
488
  const byId = new Map(nodes.map((n) => [n.id, n]));
482
489
  const preset = state.view === 'dataflow';
483
490
  const out = [];
@@ -537,7 +544,7 @@ function buildEdges(state, subgraph, reduceMotion) {
537
544
  if (preset || FLOW_LIKE.includes(edge.kind)) flow(edge, source, target);
538
545
  else out.push(linkEdge(edge, source, target, subgraph));
539
546
  }
540
- 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);
541
548
  });
542
549
  return out;
543
550
  }
@@ -561,7 +568,8 @@ function buildNodes(state, subgraph) {
561
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
562
569
  const out = [];
563
570
  const view = proposalView(state);
564
- 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;
565
573
 
566
574
  nodes.forEach((node) => {
567
575
  if (!isNodeVisible(state, node)) return;
@@ -579,7 +587,8 @@ function buildNodes(state, subgraph) {
579
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)
580
588
  let alpha = subgraph && !connected && !(searching && match) ? DIM_ALPHA : 1;
581
589
  if (searching && !match && !selected && !(subgraph && connected)) alpha = DIM_ALPHA; // a search dims what it did not find, as a focus does
582
- 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);
583
592
  if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
584
593
  const big = shown.type === 'root' || shown.type === 'app';
585
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
@@ -599,14 +608,16 @@ function buildNodes(state, subgraph) {
599
608
  glow: connected && alpha >= 0.5 ? (big ? 15 : 9) : 0,
600
609
  halo: match ? 'match' : selected ? 'selected' : child ? 'child' : 'none',
601
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)
602
612
  selected, match, current, connected,
603
613
  degree: node.degree || 0,
604
614
  label: shown.label,
605
- labelSize: big ? 12 : 11,
606
- labelBold: big,
607
- 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
608
619
  labelColor: connected ? '#f8fafc' : 'rgba(255, 255, 255, 0.3)',
609
- 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),
610
621
  labelStrike: !!look && (look.strike || gone),
611
622
  live: !!node.live,
612
623
  box: node.box || null,
@@ -733,6 +744,7 @@ export function buildScene(state, opts = {}) {
733
744
  };
734
745
  if (state.view === 'house') decorateHouseScene(scene, state); // its bands and tray as lanes, rooms unlabelled (house-model.js)
735
746
  if (state.scenario) emphasiseScenario(scene, state.scenario, opts);
747
+ scene.greying = scene.nodes.some((n) => n.greyed) || scene.edges.some((e) => e.greyed);
736
748
  const colours = { nodes: scene.nodes.map((n) => n.color), edges: scene.edges.map((e) => e.color) };
737
749
  if (state.scenario) paintOutage(scene, outageFor(state.scenario, state.nodes, state.edges)); // CLOUD-07: red, amber, violet by when the outage bites
738
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.
@@ -147,6 +147,9 @@
147
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 */
148
148
  --corn-map-label-min: auto;
149
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;
150
153
  /* Diff, selection and focus */
151
154
  --corn-map-added: auto;
152
155
  --corn-map-changed: auto;
@@ -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 '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.44.0",
3
+ "version": "0.46.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",
package/server/auth.js CHANGED
@@ -42,6 +42,7 @@ import { createCipheriv, createDecipheriv, createHash, createHmac, hkdfSync, ran
42
42
  import { createForge as defaultCreateForge, isMaintainer, ForgeError } from './forge.js';
43
43
  import { githubApiUrl } from './forge-github.js';
44
44
  import { sameOrigin } from './proposals.js';
45
+ import { absoluteUrl, listedReturn } from './embed.js';
45
46
  import { revokeOwnerTokens } from './review-tokens.js';
46
47
  import { appNameOf, brandImages } from '../core/brand.js';
47
48
  import { brandHead, escapeHtml, themeHead, themeHtmlTag } from './page-head.js';
@@ -326,10 +327,14 @@ export function safeReturn(raw) {
326
327
  return back;
327
328
  }
328
329
 
329
- /** The sign-in start, with the way back (checked by safeReturn) when there is one */
330
+ /**
331
+ * The sign-in start, with the way back when there is one: a path (checked by safeReturn) as `return`, or an absolute URL the caller has
332
+ * already had checked (it comes from a signed state cookie) as `returnTo`, which /auth/start checks again against the listed origins
333
+ */
330
334
  const startHref = (returnTo) => {
331
335
  const back = safeReturn(returnTo);
332
- return `/auth/start${back && back !== '/' ? `?return=${encodeURIComponent(back)}` : ''}`;
336
+ if (back) return `/auth/start${back !== '/' ? `?return=${encodeURIComponent(back)}` : ''}`;
337
+ return typeof returnTo === 'string' && absoluteUrl(returnTo) ? `/auth/start?returnTo=${encodeURIComponent(returnTo)}` : '/auth/start';
333
338
  };
334
339
 
335
340
  /** A proposal slug, as `?proposal=` names one (core/proposal.js: kebab case); at most 100 characters */
@@ -442,6 +447,24 @@ export function createAuth(config, { env = process.env, now = Date.now, fetch: d
442
447
  const SESSION_COOKIE = secure ? '__Host-cornfield' : 'cornfield';
443
448
  const STATE_COOKIE = secure ? '__Host-cornfield-oauth' : 'cornfield-oauth';
444
449
  const publicHost = publicUrl.hostname;
450
+ // The sibling origins a sign-in may end on (config `embed.origins`, server/embed.js)
451
+ const embedOrigins = config.embed?.origins ?? [];
452
+ /**
453
+ * Where a sign-in may end, as it is kept and followed: a same-origin path (safeReturn: its rules are unchanged), or an absolute URL, which is
454
+ * honoured only when its origin is this server's own (it is cut down to its path and query, then checked as a path) or exactly a listed one
455
+ * (kept as the URL parser reads it). Anything else is null, and the sign-in ends where it always has: on `/`. With no origin listed an
456
+ * absolute URL is never one (the sign-in is what it was before `embed.origins`).
457
+ * @param {unknown} raw
458
+ * @returns {string | null}
459
+ */
460
+ const wayBack = (raw) => {
461
+ const path = safeReturn(raw);
462
+ if (path) return path;
463
+ if (!embedOrigins.length) return null;
464
+ const u = absoluteUrl(raw);
465
+ if (!u) return null;
466
+ return u.origin === publicUrl.origin ? safeReturn(`${u.pathname}${u.search}`) : listedReturn(raw, embedOrigins);
467
+ };
445
468
  /** @type {import('node:sqlite').DatabaseSync | null} */
446
469
  let db = null;
447
470
  /** @type {Promise<import('node:sqlite').DatabaseSync> | null} */
@@ -476,10 +499,11 @@ export function createAuth(config, { env = process.env, now = Date.now, fetch: d
476
499
  };
477
500
  /** Where a sign-in ends: the checked way back as an absolute URL on the public origin, or `/` */
478
501
  const landAt = (back) => {
479
- const path = safeReturn(back);
502
+ const path = wayBack(back);
480
503
  if (!path) return '/';
481
504
  const to = new URL(path, publicUrl);
482
- return to.origin === publicUrl.origin ? to.href : '/';
505
+ // A listed origin's URL is absolute and stays as checked; a path is made absolute on the public origin
506
+ return to.origin === publicUrl.origin || embedOrigins.includes(to.origin) ? to.href : '/';
483
507
  };
484
508
  const clearSession = cookie(SESSION_COOKIE, '', { maxAge: 0, secure });
485
509
  const clearState = cookie(STATE_COOKIE, '', { maxAge: 0, secure });
@@ -580,8 +604,9 @@ export function createAuth(config, { env = process.env, now = Date.now, fetch: d
580
604
  const state = random();
581
605
  const verifier = random();
582
606
  const expires = now() + STATE_MS;
583
- // The way back is signed with the state: a 5th part, base64url (no dots), empty for none
584
- const back = safeReturn(url.searchParams.get('return'));
607
+ // The way back is signed with the state: a 5th part, base64url (no dots), empty for none. `returnTo` is an absolute URL (own or a listed
608
+ // origin); when it is none of those, or no origin is listed, the sign-in goes on as if it had not been sent, with `return` (a path) as before
609
+ const back = (embedOrigins.length ? wayBack(url.searchParams.get('returnTo')) : null) ?? safeReturn(url.searchParams.get('return'));
585
610
  const payload = `${state}.${verifier}.${expires}.${back ? b64url(Buffer.from(back)) : ''}`;
586
611
  const q = new URLSearchParams({ client_id: clientId, redirect_uri: redirectUri, response_type: 'code', state, code_challenge: b64url(createHash('sha256').update(verifier).digest()), code_challenge_method: 'S256' });
587
612
  if (endpoints.scope) q.set('scope', endpoints.scope);
@@ -599,7 +624,7 @@ export function createAuth(config, { env = process.env, now = Date.now, fetch: d
599
624
  if (!sameText(mac, macOf(keys.mac, `state:${state}.${verifier}.${expires}.${back}`))) return { error: 'The sign-in was started in another browser, or too long ago.' };
600
625
  if (!(Number(expires) > now())) return { error: 'The sign-in took too long.' };
601
626
  if (!sameText(state, url.searchParams.get('state') || '')) return { error: 'The sign-in came back with an answer to another request.' };
602
- return { verifier, returnTo: safeReturn(back ? Buffer.from(back, 'base64url').toString('utf8') : '') };
627
+ return { verifier, returnTo: wayBack(back ? Buffer.from(back, 'base64url').toString('utf8') : '') };
603
628
  }
604
629
 
605
630
  /**