cornfield 0.34.2 → 0.34.3
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 +62 -0
- package/core/proposal.js +10 -3
- package/explorer/check.js +6 -1
- package/explorer/diff-marks.js +35 -0
- package/explorer/explorer.css +17 -2
- package/explorer/focusables.js +35 -0
- package/explorer/forge-panel.js +3 -14
- package/explorer/index.html +3 -3
- package/explorer/mockups.js +3 -9
- package/explorer/plugins.js +11 -2
- package/explorer/proposal-model.js +27 -3
- package/explorer/proposal.js +9 -4
- package/explorer/renderer-canvas2d.js +23 -5
- package/explorer/review-model.js +8 -3
- package/explorer/review-tokens.js +2 -7
- package/explorer/review.js +8 -4
- package/explorer/scenario-ui.js +7 -3
- package/explorer/scene.js +8 -7
- package/explorer/theme-model.js +13 -6
- package/explorer/tokens.css +10 -10
- package/explorer/whatif.js +10 -3
- package/package.json +1 -1
- package/server/proposals.js +1 -1
package/core/contrast.js
CHANGED
|
@@ -23,6 +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 { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, markOpacity } from '../explorer/diff-marks.js';
|
|
27
|
+
import { lightColor } from '../explorer/theme-model.js';
|
|
26
28
|
|
|
27
29
|
/** WCAG 2.1 AA: text, and large text and user-interface parts */
|
|
28
30
|
export const MIN_TEXT = 4.5;
|
|
@@ -397,6 +399,9 @@ export const UI_PAIRS = Object.freeze([
|
|
|
397
399
|
...['--corn-ok', '--corn-edit-text', '--corn-bad', '--corn-warn', '--corn-text-3'].flatMap((fg) => ['--corn-surface-2', '--corn-surface-3'].map((bg) => [fg, bg, 'a state pill\'s border'])),
|
|
398
400
|
]);
|
|
399
401
|
|
|
402
|
+
/** The dots that name a diff mark in the bar, the change list and the legend (explorer.css `.hx-mark-dot--*`), each a ring on the ground */
|
|
403
|
+
const DIFF_DOT_PAIRS = Object.freeze(['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-${m}`, GROUND, `the ${m} mark's dot`]));
|
|
404
|
+
|
|
400
405
|
/**
|
|
401
406
|
* Every pair that is read against each other: `{ fg, bg, min, kind, use? }`, `fg` and `bg` each a token or a CSS colour value. A pair
|
|
402
407
|
* listed twice is checked once, at the higher minimum. How a translucent `bg` is composited: see checkState.
|
|
@@ -415,6 +420,7 @@ export function contrastPairs() {
|
|
|
415
420
|
for (const bg of SOLID_FILLS) add(GROUND, bg, MIN_TEXT, 'text');
|
|
416
421
|
for (const [fg, bg] of PAINTED_TEXT) add(fg, bg, MIN_TEXT, 'text');
|
|
417
422
|
for (const [fg, bg, use] of UI_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
|
|
423
|
+
for (const [fg, bg, use] of DIFF_DOT_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
|
|
418
424
|
return [...pairs.values()];
|
|
419
425
|
}
|
|
420
426
|
|
|
@@ -500,6 +506,62 @@ function checkState(props, theme, mode) {
|
|
|
500
506
|
const { image, ...rest } = worst;
|
|
501
507
|
out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
|
|
502
508
|
}
|
|
509
|
+
out.push(...diffMapFindings(props, theme, mode, grounds, isColor(g) ? over(g, canvas) : null));
|
|
510
|
+
return out;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// ---------------------------------------------------------------------------
|
|
514
|
+
// The map's diff marks and dimmed labels (0.34 review, F19 and F23)
|
|
515
|
+
//
|
|
516
|
+
// The canvas draws a proposal's marks in `--corn-map-added|changed|removed|edit` (`auto` is the default look, explorer/diff-marks.js)
|
|
517
|
+
// and a label a diff dims at DIFF_LABEL_ALPHA. Each is read at 3:1 against every ground the map draws: the ground, each glow of
|
|
518
|
+
// `--corn-ground-image` at its strongest, and all of them laid over each other (the darkest and the lightest the map shows), at the
|
|
519
|
+
// opacity it is drawn at (a removed mark is faded, an edge is never fainter than EDGE_MIN_ALPHA). Nothing here reads node fills:
|
|
520
|
+
// those are another check.
|
|
521
|
+
// ---------------------------------------------------------------------------
|
|
522
|
+
|
|
523
|
+
/** Every ground the map can show: the page ground, each glow at its peak over it, and all the glows stacked */
|
|
524
|
+
function mapGrounds(grounds, base, props) {
|
|
525
|
+
const out = grounds.map((x) => ({ ...x }));
|
|
526
|
+
if (base && props.has('--corn-ground-image')) {
|
|
527
|
+
const r = expand('var(--corn-ground-image)', props);
|
|
528
|
+
if ('text' in r) {
|
|
529
|
+
let stack = base;
|
|
530
|
+
for (const layer of layerTexts(r.text).slice(0, 16)) {
|
|
531
|
+
let peak = null;
|
|
532
|
+
for (const c of colorsIn(layer, 0)) if (!peak || c[3] > peak[3]) peak = c;
|
|
533
|
+
if (peak && peak[3] > 0) stack = over(peak, stack);
|
|
534
|
+
}
|
|
535
|
+
if (stack !== base) out.push({ color: stack, image: true });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return out;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** The pairs the map's diff marks make: `[token, default colour (auto), opacity, what it is]` */
|
|
542
|
+
const DIFF_MAP_PAIRS = (mode) => [
|
|
543
|
+
...['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-map-${m}`, DIFF_MARK_COLORS[mode][m], markOpacity(m), `the ${m} mark on the map, drawn at ${Math.round(markOpacity(m) * 100)}% opacity`]),
|
|
544
|
+
['--corn-map-label', mode === 'light' ? lightColor('#f8fafc', 'text') : '#f8fafc', DIFF_LABEL_ALPHA, `a label the diff dims, drawn at ${Math.round(DIFF_LABEL_ALPHA * 100)}% opacity`],
|
|
545
|
+
];
|
|
546
|
+
|
|
547
|
+
function diffMapFindings(props, theme, mode, grounds, base) {
|
|
548
|
+
const out = [];
|
|
549
|
+
const list = mapGrounds(grounds, base, props);
|
|
550
|
+
for (const [token, auto, opacity, use] of DIFF_MAP_PAIRS(mode)) {
|
|
551
|
+
const finding = { theme, mode, fg: token, bg: GROUND, min: MIN_UI, kind: 'ui', use };
|
|
552
|
+
const raw = (props.get(token) || 'auto').trim();
|
|
553
|
+
const fg0 = raw.toLowerCase() === 'auto' ? readColor(auto) : resolveColor(props, token);
|
|
554
|
+
if (!isColor(fg0)) { out.push({ ...finding, problem: fg0 ? fg0.problem : `${token} is not a colour cornfield reads` }); continue; }
|
|
555
|
+
if (!list.length) continue;
|
|
556
|
+
let worst = null;
|
|
557
|
+
for (const { color: ground, image } of list) {
|
|
558
|
+
const fg = over([fg0[0], fg0[1], fg0[2], fg0[3] * opacity], ground);
|
|
559
|
+
const r = ratio(luminance(fg), luminance(ground));
|
|
560
|
+
if (!worst || r < worst.ratio) worst = { fgValue: toHex(fg), bgValue: toHex(ground), ratio: r, image };
|
|
561
|
+
}
|
|
562
|
+
const { image, ...rest } = worst;
|
|
563
|
+
out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
|
|
564
|
+
}
|
|
503
565
|
return out;
|
|
504
566
|
}
|
|
505
567
|
|
package/core/proposal.js
CHANGED
|
@@ -721,11 +721,18 @@ export function proposalProblems(topology, proposal) {
|
|
|
721
721
|
/**
|
|
722
722
|
* The numbers behind the counts chip ("3 added · 1 changed · 1 removed"): nodes and edges counted together.
|
|
723
723
|
* @param {object} proposal
|
|
724
|
-
*
|
|
724
|
+
* `nodes` and `edges` give the same counts apart, for the words that say what is counted.
|
|
725
|
+
* @param {object} proposal
|
|
726
|
+
* @returns {{ added: number, changed: number, removed: number, scenarios: number, nodes: { added: number, changed: number, removed: number }, edges: { added: number, changed: number, removed: number } }}
|
|
725
727
|
*/
|
|
726
728
|
export function summarize(proposal) {
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
+
const of = (group) => ({ added: asList(group?.add).length, changed: asList(group?.change).length, removed: asList(group?.remove).length });
|
|
730
|
+
const nodes = of(proposal?.nodes);
|
|
731
|
+
const edges = of(proposal?.edges);
|
|
732
|
+
return {
|
|
733
|
+
added: nodes.added + edges.added, changed: nodes.changed + edges.changed, removed: nodes.removed + edges.removed,
|
|
734
|
+
scenarios: asList(proposal?.scenarios).length, nodes, edges,
|
|
735
|
+
};
|
|
729
736
|
}
|
|
730
737
|
|
|
731
738
|
/**
|
package/explorer/check.js
CHANGED
|
@@ -195,6 +195,9 @@ function summary() {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
/** Paints the step's state on the bar: called with every bar update */
|
|
198
|
+
/** The words last written into each player's check line (paintChecks) */
|
|
199
|
+
const lineHtml = new WeakMap();
|
|
200
|
+
|
|
198
201
|
export function paintChecks(bar, snap) {
|
|
199
202
|
if (!bar || !current) return;
|
|
200
203
|
if (!bar.querySelector('.hx-player-as')) {
|
|
@@ -214,7 +217,9 @@ export function paintChecks(bar, snap) {
|
|
|
214
217
|
pill.textContent = words.pill;
|
|
215
218
|
pill.title = words.line;
|
|
216
219
|
line.dataset.tone = words.tone;
|
|
217
|
-
|
|
220
|
+
// painted every frame: the live line is rewritten only when its words change, so a verdict is said once
|
|
221
|
+
const html = `${escHtml(words.line)}${words.detail ? ` <span class="hx-player-check-detail">${escHtml(words.detail)}</span>` : ''}`;
|
|
222
|
+
if (lineHtml.get(line) !== html) { lineHtml.set(line, html); line.innerHTML = html; }
|
|
218
223
|
}
|
|
219
224
|
fillMenu(row.querySelector('[data-check=as]'));
|
|
220
225
|
row.querySelector('[data-check=recheck]').disabled = current.answer.status === 'pending';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/diff-marks
|
|
3
|
+
*
|
|
4
|
+
* What the map draws for a proposal's diff marks, as plain data with no imports, so the scene (scene.js), the renderers and the
|
|
5
|
+
* contrast check (core/contrast.js, for `cornfield validate`) read one list. The colours are the defaults behind `--corn-map-added|
|
|
6
|
+
* changed|removed|edit: auto`, and the same hexes are `--corn-added|changed|removed|edit` in tokens.css (the dots in the bar).
|
|
7
|
+
*
|
|
8
|
+
* Every mark is at least 3:1 (WCAG 1.4.11) against the darkest and lightest ground the map draws, at the opacity it is drawn at:
|
|
9
|
+
* an edge never fainter than EDGE_MIN_ALPHA, and a removed mark at REMOVED_ALPHA over that. A label a diff dims is drawn at
|
|
10
|
+
* DIFF_LABEL_ALPHA: de-emphasised, never hidden (3:1 as well).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The default mark colours, for the dark and the light ground */
|
|
14
|
+
export const DIFF_MARK_COLORS = Object.freeze({
|
|
15
|
+
dark: Object.freeze({ added: '#2dd4bf', changed: '#fbbf24', removed: '#fa9292', edit: '#b49cfb' }),
|
|
16
|
+
light: Object.freeze({ added: '#197c6f', changed: '#8f6703', removed: '#e20b0b', edit: '#6839f6' }),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** How much of a removed node and its edge is left: faded, but still 3:1 */
|
|
20
|
+
export const REMOVED_ALPHA = 0.85;
|
|
21
|
+
/** The least opacity a mark's edge is drawn at (scene.js lifts an edge to this before the mark's own fade) */
|
|
22
|
+
export const EDGE_MIN_ALPHA = 0.9;
|
|
23
|
+
/** The opacity each mark is drawn at at its faintest (an edge; a what-if edit that removes something is faded like a removal): the contrast check measures this */
|
|
24
|
+
export const markOpacity = (mark) => EDGE_MIN_ALPHA * (mark === 'removed' || mark === 'edit' ? REMOVED_ALPHA : 1);
|
|
25
|
+
|
|
26
|
+
/** The opacity of the label of a node a diff dims (the node itself is at PROPOSAL_DIM_ALPHA) */
|
|
27
|
+
export const DIFF_LABEL_ALPHA = 0.6;
|
|
28
|
+
|
|
29
|
+
/** How a mark differs without colour: the ring's dash (`null` is solid) and whether it is struck through. Four marks, four styles. */
|
|
30
|
+
export const MARK_SHAPES = Object.freeze({
|
|
31
|
+
added: Object.freeze({ ringDash: Object.freeze([5, 4]), edgeDash: Object.freeze([7, 5]), strike: false }), // a dashed ring
|
|
32
|
+
changed: Object.freeze({ ringDash: null, edgeDash: null, strike: false }), // a plain solid ring
|
|
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)
|
|
35
|
+
});
|
package/explorer/explorer.css
CHANGED
|
@@ -428,8 +428,8 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
|
|
|
428
428
|
.hx-legend-row .hx-mark-dot, .hx-change-row .hx-mark-dot { margin-right: 0; }
|
|
429
429
|
.hx-mark-dot--added { border-color: var(--corn-added); border-style: dashed; }
|
|
430
430
|
.hx-mark-dot--changed { border-color: var(--corn-changed); }
|
|
431
|
-
.hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent);
|
|
432
|
-
.hx-mark-dot--edit { border-color: var(--corn-edit); }
|
|
431
|
+
.hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent); }
|
|
432
|
+
.hx-mark-dot--edit { border-color: var(--corn-edit); border-style: dotted; } /* a dotted ring: not the changed mark's solid one, with or without colour */
|
|
433
433
|
|
|
434
434
|
/* The panel's proposal block: why, and what changes */
|
|
435
435
|
.hx-proposal-sec { padding: var(--corn-space-3) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-left-width: var(--corn-border-strong); border-radius: var(--corn-radius-sm); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); margin: 0 0 var(--corn-space-2); font-family: var(--corn-font); }
|
|
@@ -1053,3 +1053,18 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1053
1053
|
|
|
1054
1054
|
/* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
|
|
1055
1055
|
.hx-fact-v { overflow-wrap: break-word; word-break: normal; }
|
|
1056
|
+
|
|
1057
|
+
/* ---------------------------------------------------------------------------
|
|
1058
|
+
Target sizes (0.34 review, F57): a thumb target is 44x44 (hit area, the drawn size may be smaller), and a change row is
|
|
1059
|
+
28px at a desk. Phone width or a coarse pointer. test/explorer/target-size.test.js holds this list.
|
|
1060
|
+
--------------------------------------------------------------------------- */
|
|
1061
|
+
.hx-change-row { min-height: 28px; }
|
|
1062
|
+
.hx-run .hx-link { display: inline-flex; align-items: center; min-height: 24px; } /* a run card's links sit on lines 14px apart: 24px at a desk (WCAG 2.5.8) */
|
|
1063
|
+
@media (max-width: 767px), (pointer: coarse) {
|
|
1064
|
+
.hx-change-row, .hx-toggle-row, .hx-textbtn, .hx-player-speed, .hx-player .hx-close,
|
|
1065
|
+
.hx-confirm .hx-btn, .hx-confirm .hx-forge-input, .hx-confirm .hx-forge-select, .hx-mobile-search .hx-input { min-height: 44px; }
|
|
1066
|
+
.hx-textbtn, .hx-player-speed, .hx-player .hx-close, .hx-confirm .hx-btn { min-width: 44px; }
|
|
1067
|
+
.hx-proposal-chip { flex-wrap: wrap; white-space: normal; text-align: left; } /* the counts say what they count, so they are longer: they wrap rather than clip */
|
|
1068
|
+
.hx-sheet-handle { height: 44px; } /* the grip is drawn the same; the button itself is 44px (a hit area stretched past it is clipped by the sheet above, and covers its title below) */
|
|
1069
|
+
.hx-run .hx-link, .hx-forge-check .hx-link { display: inline-flex; align-items: center; min-height: 44px; }
|
|
1070
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one list of what the keyboard can stop on, shared by every dialog that keeps the focus inside itself
|
|
3
|
+
* (Review tokens, Start an agent, the confirm step, the mockup window). A trap that names its own selector leaves
|
|
4
|
+
* something out (the Kind of token select once), so they all ask here.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Every control a Tab can land on: links, buttons, fields, selects, summaries, frames and anything with a tabindex that is not -1 */
|
|
8
|
+
export const FOCUSABLE = 'a[href], button, input:not([type="hidden"]), select, textarea, summary, iframe, [contenteditable="true"], [tabindex]:not([tabindex="-1"])';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The stops inside `root`, in DOM order: not disabled, not hidden, not inert and not under a hidden or inert ancestor.
|
|
12
|
+
* @param {Element} root
|
|
13
|
+
* @returns {HTMLElement[]}
|
|
14
|
+
*/
|
|
15
|
+
export function focusableIn(root) {
|
|
16
|
+
if (!root) return [];
|
|
17
|
+
return [...root.querySelectorAll(FOCUSABLE)].filter((el) => !el.disabled && !el.closest('[hidden], [inert]') && el.getAttribute('tabindex') !== '-1');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Keeps a Tab inside `root`: from the last stop it goes to the first, and Shift+Tab the other way round.
|
|
22
|
+
* @param {KeyboardEvent} e a keydown; nothing happens unless it is a Tab
|
|
23
|
+
* @param {Element} root
|
|
24
|
+
* @returns {boolean} whether it handled the key
|
|
25
|
+
*/
|
|
26
|
+
export function trapTab(e, root) {
|
|
27
|
+
if (e.key !== 'Tab') return false;
|
|
28
|
+
const stops = focusableIn(root);
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
if (!stops.length) return true;
|
|
31
|
+
const at = stops.indexOf(document.activeElement);
|
|
32
|
+
const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at === -1 || at === stops.length - 1 ? 0 : at + 1);
|
|
33
|
+
stops[next].focus();
|
|
34
|
+
return true;
|
|
35
|
+
}
|
package/explorer/forge-panel.js
CHANGED
|
@@ -70,6 +70,7 @@ 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
72
|
import { announce, centreOn } from './keyboard.js';
|
|
73
|
+
import { trapTab } from './focusables.js';
|
|
73
74
|
import { isPhone, registerSheet, expandSheet, collapseSheet } from './sheets.js';
|
|
74
75
|
import { relativeTime } from './review-model.js';
|
|
75
76
|
import { LAYER_DEFS, toggleLayer } from './layers.js';
|
|
@@ -1584,13 +1585,7 @@ function onConfirmKey(e) {
|
|
|
1584
1585
|
if (!ui.busy) closeConfirm();
|
|
1585
1586
|
return;
|
|
1586
1587
|
}
|
|
1587
|
-
|
|
1588
|
-
const buttons = [...confirmEl().querySelectorAll('button:not([disabled])')];
|
|
1589
|
-
if (!buttons.length) { e.preventDefault(); return; }
|
|
1590
|
-
const at = buttons.indexOf(document.activeElement);
|
|
1591
|
-
const next = e.shiftKey ? (at <= 0 ? buttons.length - 1 : at - 1) : (at === -1 || at === buttons.length - 1 ? 0 : at + 1);
|
|
1592
|
-
e.preventDefault();
|
|
1593
|
-
buttons[next].focus();
|
|
1588
|
+
trapTab(e, confirmEl());
|
|
1594
1589
|
}
|
|
1595
1590
|
|
|
1596
1591
|
function onConfirmClick(e) {
|
|
@@ -1784,13 +1779,7 @@ function onAgentKey(e) {
|
|
|
1784
1779
|
if (!ui.agent || !ui.agent.posting) closeAgent();
|
|
1785
1780
|
return;
|
|
1786
1781
|
}
|
|
1787
|
-
|
|
1788
|
-
const fields = [...agentEl().querySelectorAll('select, textarea, input, button')].filter((el) => !el.disabled && !el.closest('[hidden]'));
|
|
1789
|
-
if (!fields.length) { e.preventDefault(); return; }
|
|
1790
|
-
const at = fields.indexOf(document.activeElement);
|
|
1791
|
-
const next = e.shiftKey ? (at <= 0 ? fields.length - 1 : at - 1) : (at === -1 || at === fields.length - 1 ? 0 : at + 1);
|
|
1792
|
-
e.preventDefault();
|
|
1793
|
-
fields[next].focus();
|
|
1782
|
+
trapTab(e, agentEl());
|
|
1794
1783
|
}
|
|
1795
1784
|
|
|
1796
1785
|
function onAgentClick(e) {
|
package/explorer/index.html
CHANGED
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
<div id="proposal-legend" class="hx-menu-section" hidden>
|
|
75
75
|
<div class="hx-menu-title"><span>Proposal marks</span></div>
|
|
76
76
|
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added"></span><span>Added: dashed ring</span></div>
|
|
77
|
-
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed:
|
|
78
|
-
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed:
|
|
79
|
-
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit:
|
|
77
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed: solid ring</span></div>
|
|
78
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed: faded ring, label struck through</span></div>
|
|
79
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit: dotted ring</span></div>
|
|
80
80
|
</div>
|
|
81
81
|
|
|
82
82
|
<div class="hx-menu-section">
|
package/explorer/mockups.js
CHANGED
|
@@ -24,6 +24,7 @@ import { hooks } from './proposal.js';
|
|
|
24
24
|
import { mockupsOf } from '../core/proposal.js';
|
|
25
25
|
import { mockupsFor, mockupsSectionHtml, stateWords } from './mockups-model.js';
|
|
26
26
|
import { cornState } from './corn-state.js';
|
|
27
|
+
import { focusableIn, trapTab } from './focusables.js';
|
|
27
28
|
|
|
28
29
|
const $ = (id) => document.getElementById(id);
|
|
29
30
|
|
|
@@ -79,8 +80,6 @@ export async function refreshMockups() {
|
|
|
79
80
|
// The window
|
|
80
81
|
// ---------------------------------------------------------------------------
|
|
81
82
|
|
|
82
|
-
const FOCUSABLE = 'button, [href], iframe, [tabindex]:not([tabindex="-1"])';
|
|
83
|
-
|
|
84
83
|
/** Shuts the window and gives the focus back to the button that opened it */
|
|
85
84
|
export function closeMockup() {
|
|
86
85
|
if (!dialog) return;
|
|
@@ -99,13 +98,8 @@ function onKey(e) {
|
|
|
99
98
|
e.stopPropagation();
|
|
100
99
|
closeMockup();
|
|
101
100
|
} else if (e.key === 'Tab') {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at < 0 || at === stops.length - 1 ? 0 : at + 1);
|
|
105
|
-
if (stops.length) {
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
stops[next].focus();
|
|
108
|
-
}
|
|
101
|
+
// the frame is a stop too, though it holds the focus rather than a tabindex
|
|
102
|
+
if (focusableIn(dialog).length) trapTab(e, dialog);
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
105
|
|
package/explorer/plugins.js
CHANGED
|
@@ -48,14 +48,22 @@ function brandImage(doc, src, kind, alt = '') {
|
|
|
48
48
|
return img;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** The brand button's name starts with what it shows (the title, or the wordmark's alt), so "click Big map" works (WCAG 2.5.3) */
|
|
52
|
+
function nameBrandButton(doc) {
|
|
53
|
+
const button = doc.getElementById('cf-brand');
|
|
54
|
+
const text = doc.getElementById('cf-title');
|
|
55
|
+
if (!button || !text) return;
|
|
56
|
+
const img = text.querySelector && text.querySelector('img');
|
|
57
|
+
const shown = (text.textContent || '').trim() || (img && img.getAttribute('alt')) || '';
|
|
58
|
+
if (shown) button.setAttribute('aria-label', `${shown}: reset the view`);
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
/**
|
|
52
62
|
* The repo's brand in the header (docs/config.md#brand): the logo takes the brand mark's place and the wordmark the title text, inside
|
|
53
63
|
* the same button, so its accessible name stays. The header text stays the repo's own title; `appName` replaces "cornfield" where
|
|
54
64
|
* cornfield names itself: the button's accessible name and the page's heading (the tab title and the manifest are the server's).
|
|
55
65
|
*/
|
|
56
66
|
function applyBrand(doc, brand, title) {
|
|
57
|
-
const button = doc.getElementById('cf-brand');
|
|
58
|
-
if (button && brand.appName) button.setAttribute('aria-label', `${brand.appName}: reset the view`);
|
|
59
67
|
const text = doc.getElementById('cf-title');
|
|
60
68
|
if (brand.logo && typeof doc.createElement === 'function') {
|
|
61
69
|
const mark = doc.getElementById('cf-mark');
|
|
@@ -105,6 +113,7 @@ export function applyBranding(doc, config) {
|
|
|
105
113
|
const heading = doc.getElementById('cf-heading');
|
|
106
114
|
if (heading && config.title) heading.textContent = `${config.title}: the map`;
|
|
107
115
|
if (config.brand) applyBrand(doc, config.brand, config.title);
|
|
116
|
+
nameBrandButton(doc);
|
|
108
117
|
initThemePicker(doc, config.theme);
|
|
109
118
|
paintAccount(doc, config);
|
|
110
119
|
}
|
|
@@ -101,11 +101,12 @@ export function touchedIds(nodes, edges) {
|
|
|
101
101
|
// ---------------------------------------------------------------------------
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
* "
|
|
104
|
+
* "4 nodes, 2 edges added · 1 node changed" (the bar's words, without the scenarios), or "3 added · 1 changed" for counts
|
|
105
|
+
* without the split: zero counts are left out; nothing at all reads "No changes".
|
|
105
106
|
* @param {{added?:number, changed?:number, removed?:number}} counts `summarize(proposal)`
|
|
106
107
|
*/
|
|
107
108
|
export function chipText(counts) {
|
|
108
|
-
const parts =
|
|
109
|
+
const parts = barCounts({ ...counts, scenarios: 0 }).filter((c) => c.mark).map((c) => c.text.replace(/^\+/, ''));
|
|
109
110
|
return parts.length ? parts.join(' · ') : 'No changes';
|
|
110
111
|
}
|
|
111
112
|
|
|
@@ -117,11 +118,34 @@ export function chipText(counts) {
|
|
|
117
118
|
*/
|
|
118
119
|
export function barCounts(counts) {
|
|
119
120
|
const n = (k) => counts?.[k] || 0;
|
|
120
|
-
|
|
121
|
+
// with the split (`summarize` gives it) the chip says what it counts: "4 nodes, 2 edges added"; without, the bare number
|
|
122
|
+
const unit = (k, word) => `${k} ${word}${k === 1 ? '' : 's'}`;
|
|
123
|
+
const what = (m) => {
|
|
124
|
+
const ns = counts?.nodes?.[m] || 0;
|
|
125
|
+
const es = counts?.edges?.[m] || 0;
|
|
126
|
+
if (!counts?.nodes || ns + es !== n(m)) return `${m === 'added' ? '+' : ''}${n(m)} ${m}`;
|
|
127
|
+
return `${[ns && unit(ns, 'node'), es && unit(es, 'edge')].filter(Boolean).join(', ')} ${m}`;
|
|
128
|
+
};
|
|
129
|
+
const parts = MARKS.filter((m) => n(m) > 0).map((m) => ({ mark: m, text: what(m) }));
|
|
121
130
|
if (n('scenarios') > 0) parts.push({ mark: null, text: `${n('scenarios')} ${n('scenarios') === 1 ? 'scenario' : 'scenarios'}` });
|
|
122
131
|
return parts.length ? parts : [{ mark: null, text: 'No changes' }];
|
|
123
132
|
}
|
|
124
133
|
|
|
134
|
+
/** What a screen reader hears when a view is picked: "Diff view" */
|
|
135
|
+
export const viewWords = (view) => `${view === 'before' ? 'Before' : view === 'after' ? 'After' : 'Diff'} view`;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What it hears when a proposal has loaded: its title and counts, and the view it is in
|
|
139
|
+
* ("Proposal Alerts: 4 nodes and 2 edges added, 1 node changed, 3 scenarios. Diff view.": in speech a comma would split a part in two).
|
|
140
|
+
* @param {string} title
|
|
141
|
+
* @param {object} counts `summarize(proposal)`
|
|
142
|
+
* @param {'before'|'diff'|'after'} view
|
|
143
|
+
*/
|
|
144
|
+
export const openedWords = (title, counts, view) => `Proposal ${title}: ${barCounts(counts).map((c) => c.text.replace(/^\+/, '').replace(', ', ' and ')).join(', ')}. ${viewWords(view)}.`;
|
|
145
|
+
|
|
146
|
+
/** What a click on a change row did: the node (or edge) the camera went to, and what the proposal does to it */
|
|
147
|
+
export const jumpWords = (markWord, name) => `${name}, ${String(markWord).toLowerCase()}. The map is on it.`;
|
|
148
|
+
|
|
125
149
|
const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
126
150
|
|
|
127
151
|
/**
|
package/explorer/proposal.js
CHANGED
|
@@ -27,12 +27,13 @@ import { edgePoint, looksFor } from './scene.js';
|
|
|
27
27
|
import { onThemeChange } from './theme.js';
|
|
28
28
|
import { looksWith, onMapStyleChange } from './map-style.js';
|
|
29
29
|
import {
|
|
30
|
-
PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds,
|
|
30
|
+
PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds, viewWords, openedWords, jumpWords,
|
|
31
31
|
sourceChip, pullNumberOf, notFoundWords, otherCopies, malformedLinkWords,
|
|
32
32
|
} from './proposal-model.js';
|
|
33
33
|
import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
|
|
34
34
|
import { reviewWords } from './review-model.js';
|
|
35
35
|
import { collapseSheet, visibleMapRect, isPhone } from './sheets.js';
|
|
36
|
+
import { announce } from './keyboard.js';
|
|
36
37
|
import { t } from './strings.js';
|
|
37
38
|
|
|
38
39
|
const $ = (id) => document.getElementById(id);
|
|
@@ -113,6 +114,8 @@ export async function openProposal(slug, source = null) {
|
|
|
113
114
|
}
|
|
114
115
|
const found = res.headers.get('X-Proposal-Source');
|
|
115
116
|
showProposal(await res.json(), { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
|
|
117
|
+
// said once, here: a proposal opens on a person's asking, never on a background refresh
|
|
118
|
+
announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView));
|
|
116
119
|
return true;
|
|
117
120
|
} catch (err) {
|
|
118
121
|
console.error('Opening the proposal failed', err);
|
|
@@ -196,7 +199,7 @@ export function closeProposal() {
|
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
/** Switches between Before, Diff and After; no node moves. Entering Diff fits the camera to the change. */
|
|
199
|
-
export function setProposalView(view) {
|
|
202
|
+
export function setProposalView(view, { quiet = false } = {}) {
|
|
200
203
|
if (!state.proposal || !PROPOSAL_VIEWS.includes(view) || state.proposalView === view) return;
|
|
201
204
|
state.proposalView = view;
|
|
202
205
|
touchScene();
|
|
@@ -205,6 +208,7 @@ export function setProposalView(view) {
|
|
|
205
208
|
render();
|
|
206
209
|
renderBar();
|
|
207
210
|
syncAddress();
|
|
211
|
+
if (!quiet) announce(viewWords(view));
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
/** Hands the map new nodes and edges, keeping the selection on the same node */
|
|
@@ -408,13 +412,14 @@ function focusChange(kind, key) {
|
|
|
408
412
|
if (!item) return;
|
|
409
413
|
const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
|
|
410
414
|
if (!ends.length) return;
|
|
411
|
-
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff'); // Before or After hides what it removes or adds
|
|
415
|
+
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff', { quiet: true }); // Before or After hides what it removes or adds
|
|
412
416
|
if (kind === 'edge') showEdgePanel(item);
|
|
413
417
|
else selectNode(item);
|
|
414
418
|
// The panel is open now, so what it covers is known
|
|
415
419
|
const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
|
|
416
420
|
if (cam) Object.assign(state.camera, cam);
|
|
417
421
|
render();
|
|
422
|
+
announce(jumpWords(MARK_WORDS[item.mark] || item.mark, kind === 'edge' ? `${nameOf(item.from)} to ${nameOf(item.to)}` : item.label));
|
|
418
423
|
}
|
|
419
424
|
|
|
420
425
|
// ---------------------------------------------------------------------------
|
|
@@ -723,7 +728,7 @@ export async function initProposals() {
|
|
|
723
728
|
return false;
|
|
724
729
|
}
|
|
725
730
|
const ok = await openProposal(asked.slug, asked.source);
|
|
726
|
-
if (ok && asked.view) setProposalView(asked.view);
|
|
731
|
+
if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView)); }
|
|
727
732
|
return ok;
|
|
728
733
|
}
|
|
729
734
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* labels are the label layer's (labels.js), one transparent canvas over the map for either renderer.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { CORE_RATIO, ARROW, MARK_MIN_PX, looksFor, packetPoint } from './scene.js';
|
|
11
|
+
import { CORE_RATIO, ARROW, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
|
|
12
12
|
import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
|
|
13
13
|
|
|
14
14
|
const TAU = Math.PI * 2;
|
|
@@ -88,6 +88,18 @@ function drawEdge(ctx, edge, timeMs, zoom, withPacket = true) {
|
|
|
88
88
|
ctx.stroke();
|
|
89
89
|
ctx.setLineDash([]);
|
|
90
90
|
|
|
91
|
+
// A removed edge is struck across at its midpoint, as the WebGL tips pass draws it
|
|
92
|
+
if (edge.mark === 'removed') {
|
|
93
|
+
const mid = edgePoint(edge, 0.5);
|
|
94
|
+
const len = Math.hypot(edge.x2 - edge.x1, edge.y2 - edge.y1);
|
|
95
|
+
const [dx, dy] = len > 0 ? [(edge.x2 - edge.x1) / len, (edge.y2 - edge.y1) / len] : [1, 0];
|
|
96
|
+
ctx.beginPath();
|
|
97
|
+
ctx.moveTo(mid.x - dy * EDGE_STRIKE.halfLength, mid.y + dx * EDGE_STRIKE.halfLength);
|
|
98
|
+
ctx.lineTo(mid.x + dy * EDGE_STRIKE.halfLength, mid.y - dx * EDGE_STRIKE.halfLength);
|
|
99
|
+
ctx.lineWidth = Math.max(EDGE_STRIKE.width, 1.5 / zoom);
|
|
100
|
+
ctx.stroke();
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
// Arrowhead along the curve's end tangent
|
|
92
104
|
if (edge.arrow) {
|
|
93
105
|
const { cx, cy } = edge.curve || { cx: edge.x1, cy: edge.y1 };
|
|
@@ -154,17 +166,23 @@ function drawNode(ctx, node, zoom, looks, style) {
|
|
|
154
166
|
ctx.stroke();
|
|
155
167
|
}
|
|
156
168
|
|
|
157
|
-
// A proposal's mark: a ring just outside the node
|
|
169
|
+
// A proposal's mark: a ring just outside the node in the mark's own dash, at the node's alpha (a removed node's ring is as faded
|
|
170
|
+
// as the node, as the WebGL shader draws it and as the contrast check measures it), and for removed a strike through the node
|
|
158
171
|
const mark = looks.mark[node.mark];
|
|
159
172
|
if (mark) {
|
|
160
|
-
|
|
161
|
-
circle(ctx, node.x, node.y,
|
|
173
|
+
const rr = node.r + Math.max(mark.ringR, MARK_MIN_PX.gap / zoom);
|
|
174
|
+
circle(ctx, node.x, node.y, rr);
|
|
162
175
|
ctx.strokeStyle = mark.color;
|
|
163
176
|
ctx.lineWidth = Math.max(mark.ringWidth, MARK_MIN_PX.ring / zoom);
|
|
164
177
|
ctx.setLineDash(mark.ringDash || []);
|
|
165
178
|
ctx.stroke();
|
|
166
179
|
ctx.setLineDash([]);
|
|
167
|
-
|
|
180
|
+
if (node.mark === 'removed') {
|
|
181
|
+
ctx.beginPath();
|
|
182
|
+
ctx.moveTo(node.x - rr, node.y);
|
|
183
|
+
ctx.lineTo(node.x + rr, node.y);
|
|
184
|
+
ctx.stroke();
|
|
185
|
+
}
|
|
168
186
|
}
|
|
169
187
|
|
|
170
188
|
// The node circle, glowing, with a white core dot
|
package/explorer/review-model.js
CHANGED
|
@@ -46,9 +46,14 @@ const VERDICT_WORDS = { approved: 'Approved', notes: 'Sent back' };
|
|
|
46
46
|
* @param {number} nowMs
|
|
47
47
|
*/
|
|
48
48
|
export function reviewWords(review, nowMs) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const { verdict, when } = reviewParts(review, nowMs);
|
|
50
|
+
return when ? `${verdict} ${when}` : verdict;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The same line in two parts, `{ verdict: 'Approved', when: '3 minutes ago' }`: the bar says the verdict (a live region) and shows the time beside it */
|
|
54
|
+
export function reviewParts(review, nowMs) {
|
|
55
|
+
if (!review || !VERDICT_WORDS[review.verdict]) return { verdict: '', when: '' };
|
|
56
|
+
return { verdict: VERDICT_WORDS[review.verdict], when: relativeTime(review.at, nowMs) || '' };
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/** Why a proposal cannot be sent back yet: it needs a note. Null when it can be. */
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { escHtml } from './state.js';
|
|
22
22
|
import { announce } from './keyboard.js';
|
|
23
|
+
import { trapTab } from './focusables.js';
|
|
23
24
|
import { tokensUrl, introWords, DEFAULT_DAYS, MAX_DAYS, makeRequest, revokeUrl, tokenLine, errorWords } from './review-tokens-model.js';
|
|
24
25
|
|
|
25
26
|
const $ = (id) => document.getElementById(id);
|
|
@@ -178,13 +179,7 @@ function onClick(e) {
|
|
|
178
179
|
function onKey(e) {
|
|
179
180
|
e.stopPropagation();
|
|
180
181
|
if (e.key === 'Escape') { e.preventDefault(); closeTokens(); return; }
|
|
181
|
-
|
|
182
|
-
const items = [...dialog().querySelectorAll('button:not([disabled]), input:not([disabled])')].filter((el) => !el.closest('[hidden]'));
|
|
183
|
-
if (!items.length) { e.preventDefault(); return; }
|
|
184
|
-
const at = items.indexOf(document.activeElement);
|
|
185
|
-
const next = e.shiftKey ? (at <= 0 ? items.length - 1 : at - 1) : (at === -1 || at === items.length - 1 ? 0 : at + 1);
|
|
186
|
-
e.preventDefault();
|
|
187
|
-
items[next].focus();
|
|
182
|
+
trapTab(e, dialog());
|
|
188
183
|
}
|
|
189
184
|
|
|
190
185
|
/**
|
package/explorer/review.js
CHANGED
|
@@ -28,7 +28,7 @@ import { expandSheet, isPhone } from './sheets.js';
|
|
|
28
28
|
import { hooks } from './proposal.js';
|
|
29
29
|
import { refreshMockups } from './mockups.js';
|
|
30
30
|
import { getEdits, clearEdits } from './whatif.js';
|
|
31
|
-
import {
|
|
31
|
+
import { reviewParts, sendBackProblem, reviewBody, editsHint, isReviewable, NOT_ON_A_PR } from './review-model.js';
|
|
32
32
|
import { t } from './strings.js';
|
|
33
33
|
|
|
34
34
|
const $ = (id) => document.getElementById(id);
|
|
@@ -69,7 +69,7 @@ function mount() {
|
|
|
69
69
|
root.className = 'hx-review';
|
|
70
70
|
root.dataset.corn = 'review-bar';
|
|
71
71
|
root.innerHTML = `
|
|
72
|
-
<p class="hx-review-status" data-review-status role="status"
|
|
72
|
+
<p class="hx-review-status" data-review-status hidden><span data-review-verdict role="status"></span><span data-review-when></span></p>
|
|
73
73
|
<div class="hx-review-form" id="review-form" data-review-form hidden>
|
|
74
74
|
<label class="hx-review-label" for="review-note"></label>
|
|
75
75
|
<textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000"></textarea>
|
|
@@ -96,9 +96,13 @@ function mount() {
|
|
|
96
96
|
/** Everything the review shows, from `ui` */
|
|
97
97
|
function paint() {
|
|
98
98
|
if (!root) return;
|
|
99
|
+
// Only the verdict is a live region, written when it changes: the time beside it ticks every TICK_MS and is never said again
|
|
99
100
|
const status = q('[data-review-status]');
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const { verdict, when } = reviewParts(ui.review, now());
|
|
102
|
+
const said = q('[data-review-verdict]');
|
|
103
|
+
if (said.textContent !== verdict) said.textContent = verdict;
|
|
104
|
+
q('[data-review-when]').textContent = when ? ` ${when}` : '';
|
|
105
|
+
status.hidden = !verdict;
|
|
102
106
|
// Off for good (not a spec PR's copy) is `disabled`, and the reason is the line next to it, which the buttons point at. While a review is being posted the button
|
|
103
107
|
// only says it is busy (`aria-disabled`): a `disabled` button drops the focus to the page.
|
|
104
108
|
for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) {
|
package/explorer/scenario-ui.js
CHANGED
|
@@ -32,6 +32,7 @@ import { edgeKey } from '../core/proposal.js';
|
|
|
32
32
|
import { checksVersion, closeChecks, decorateSnapshot, openChecks, paintChecks } from './check.js';
|
|
33
33
|
import { blastRadius, outageLayers, outageScenario } from './outage-model.js';
|
|
34
34
|
import { toggleLayer } from './layers.js';
|
|
35
|
+
import { announce } from './keyboard.js';
|
|
35
36
|
|
|
36
37
|
/** A frame that arrives later than this (a tab that was hidden) counts as this long */
|
|
37
38
|
const MAX_FRAME_MS = 250;
|
|
@@ -272,6 +273,7 @@ function act(action) {
|
|
|
272
273
|
if (action === 'scenario-toggle') {
|
|
273
274
|
const s = player.snapshot();
|
|
274
275
|
if (s.playing) player.pause(); else player.play();
|
|
276
|
+
announce(s.playing ? 'Paused' : s.done ? 'Playing again' : s.index > 0 || s.progress > 0 ? 'Resumed' : 'Playing');
|
|
275
277
|
} else if (action === 'scenario-prev') player.prev();
|
|
276
278
|
else if (action === 'scenario-next') player.next();
|
|
277
279
|
else return;
|
|
@@ -284,9 +286,11 @@ let lastFill = -1;
|
|
|
284
286
|
function updateBar(snap) {
|
|
285
287
|
if (!bar) return;
|
|
286
288
|
const q = (cls) => bar.querySelector(cls);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
// this runs every frame: a live region is written only when its words change, so a step is said once, not once a frame
|
|
290
|
+
const put = (cls, text) => { const el = q(cls); if (el.textContent !== text) el.textContent = text; };
|
|
291
|
+
put('.hx-player-title', snap.title);
|
|
292
|
+
put('.hx-player-count', `${Math.min(snap.index + 1, Math.max(snap.total, 1))} of ${snap.total}`);
|
|
293
|
+
put('.hx-player-step', snap.current.text);
|
|
290
294
|
const toggle = q('[data-action=scenario-toggle]');
|
|
291
295
|
toggle.textContent = snap.playing ? 'Pause' : snap.done ? 'Play again' : 'Play';
|
|
292
296
|
toggle.disabled = snap.total === 0 || snap.manual;
|
package/explorer/scene.js
CHANGED
|
@@ -166,6 +166,7 @@ import { externalLayer, whenDash } from './cloud-model.js';
|
|
|
166
166
|
import { outageFor, paintOutage } from './outage-model.js';
|
|
167
167
|
import { paintForge } from './forge-panel-model.js';
|
|
168
168
|
import { lightColor, lightenScene, parseColor } from './theme-model.js';
|
|
169
|
+
import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
|
|
169
170
|
|
|
170
171
|
// ---------------------------------------------------------------------------
|
|
171
172
|
// Constants every renderer shares, so the looks cannot drift apart
|
|
@@ -200,10 +201,10 @@ const PACKET = { color: '#ffffff', radius: 3.5, glow: 10, cycleMs: 2600 };
|
|
|
200
201
|
* `alpha` fades a removed node and its edge; `strike` strikes its label through (`labelStrike`).
|
|
201
202
|
*/
|
|
202
203
|
export const MARK = {
|
|
203
|
-
added: { color:
|
|
204
|
-
changed: { color:
|
|
205
|
-
removed: { color:
|
|
206
|
-
edit: { color:
|
|
204
|
+
added: { ...MARK_SHAPES.added, color: DIFF_MARK_COLORS.dark.added, ringR: 9, ringWidth: 2, edgeWidth: 2.2, alpha: 1 },
|
|
205
|
+
changed: { ...MARK_SHAPES.changed, color: DIFF_MARK_COLORS.dark.changed, ringR: 9, ringWidth: 2.5, edgeWidth: 2.4, alpha: 1 },
|
|
206
|
+
removed: { ...MARK_SHAPES.removed, color: DIFF_MARK_COLORS.dark.removed, ringR: 9, ringWidth: 2, edgeWidth: 2, alpha: REMOVED_ALPHA },
|
|
207
|
+
edit: { ...MARK_SHAPES.edit, color: DIFF_MARK_COLORS.dark.edit, ringR: 9, ringWidth: 3, edgeWidth: 2.4, alpha: 1 }, // dotted: not the same ring as a change
|
|
207
208
|
};
|
|
208
209
|
/**
|
|
209
210
|
* The looks a renderer draws itself, per theme (MAP-01): the halos, the mark rings, the core dot and the
|
|
@@ -224,7 +225,7 @@ const lightLook = (look) => {
|
|
|
224
225
|
const DARK_LOOKS = Object.freeze({ halo: HALO, mark: MARK, core: CORE_COLOR, labelOutline: LABEL_OUTLINE });
|
|
225
226
|
const LIGHT_LOOKS = Object.freeze({
|
|
226
227
|
halo: Object.fromEntries(Object.entries(HALO).map(([k, v]) => [k, lightLook(v)])),
|
|
227
|
-
mark: Object.fromEntries(Object.entries(MARK).map(([k, v]) => [k,
|
|
228
|
+
mark: Object.fromEntries(Object.entries(MARK).map(([k, v]) => [k, { ...v, color: DIFF_MARK_COLORS.light[k] }])), // chosen to be 3:1 over the light ground and its glow (diff-marks.js)
|
|
228
229
|
core: CORE_COLOR, // the white dot stays white: it sits on the node's own (deepened) colour, not on the ground
|
|
229
230
|
labelOutline: { node: { color: 'rgba(244, 246, 250, 0.9)', width: 3.5 }, edge: { color: 'rgba(244, 246, 250, 0.92)', width: 3 } },
|
|
230
231
|
});
|
|
@@ -467,7 +468,7 @@ function styleForProposal(edge, mark, view, gone = false) {
|
|
|
467
468
|
edge.color = look.color;
|
|
468
469
|
edge.dash = gone ? MARK.removed.edgeDash : look.edgeDash; // an edge a what-if edit removes: violet, but dotted and faded like any removal
|
|
469
470
|
edge.width = Math.max(edge.width, look.edgeWidth);
|
|
470
|
-
if (edge.alpha >= 0.1) edge.alpha = Math.max(edge.alpha,
|
|
471
|
+
if (edge.alpha >= 0.1) edge.alpha = Math.max(edge.alpha, EDGE_MIN_ALPHA) * (gone ? MARK.removed.alpha : look.alpha); // not under the selection's deep dimming
|
|
471
472
|
if (edge.glow) edge.glowColor = look.color;
|
|
472
473
|
}
|
|
473
474
|
|
|
@@ -578,7 +579,7 @@ function buildNodes(state, subgraph) {
|
|
|
578
579
|
label: shown.label,
|
|
579
580
|
labelSize: big ? 12 : 11,
|
|
580
581
|
labelBold: big,
|
|
581
|
-
labelAlpha: alpha,
|
|
582
|
+
labelAlpha: focus && !focus.touched.has(node.id) && !(subgraph && !connected) ? Math.max(alpha, DIFF_LABEL_ALPHA) : alpha, // a label the diff dims stays 3:1
|
|
582
583
|
labelColor: connected ? '#f8fafc' : 'rgba(255, 255, 255, 0.3)',
|
|
583
584
|
labelKeep: LANDMARK_TYPES.includes(shown.type) || selected || match || mark !== 'none' || !!(subgraph && connected),
|
|
584
585
|
labelStrike: !!look && (look.strike || gone),
|
package/explorer/theme-model.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { parseColor, luminance, ratio, contrast } from '../core/color.js';
|
|
31
|
+
import { DIFF_MARK_COLORS } from './diff-marks.js';
|
|
31
32
|
|
|
32
33
|
export const THEME_CHOICES = ['system', 'light', 'dark'];
|
|
33
34
|
/** Where the choice is kept in the browser (theme.js); `?theme=` in the address wins over it, without being kept */
|
|
@@ -186,12 +187,18 @@ export function lightenScene(scene) {
|
|
|
186
187
|
n.labelColor = lightColor(n.labelColor, 'text');
|
|
187
188
|
}
|
|
188
189
|
for (const e of scene.edges) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
if (e.mark && e.mark !== 'none') {
|
|
191
|
+
// A proposal's mark keeps the light colour chosen for it (diff-marks.js) and the opacity scene.js gave it, with no gain:
|
|
192
|
+
// those were chosen together to be 3:1 at that opacity, and the contrast check (markOpacity) measures exactly that
|
|
193
|
+
e.color = DIFF_MARK_COLORS.dark[e.mark] === e.color ? DIFF_MARK_COLORS.light[e.mark] : lightColor(e.color);
|
|
194
|
+
} else {
|
|
195
|
+
// A thin dark line on a light ground reads weaker than a thin light one on a dark ground at the same
|
|
196
|
+
// alpha (the contrast ratio is lower): a faded or translucent line gets LINE_GAIN more, capped at opaque
|
|
197
|
+
if (e.alpha < 1) e.alpha = Math.min(1, e.alpha * LINE_GAIN);
|
|
198
|
+
e.color = lightColor(e.color);
|
|
199
|
+
const [r, g, b, a] = parseColor(e.color);
|
|
200
|
+
if (a > 0 && a < 1) e.color = css([r, g, b], Math.min(1, a * LINE_GAIN));
|
|
201
|
+
}
|
|
195
202
|
if (e.glowColor) e.glowColor = lightColor(e.glowColor);
|
|
196
203
|
if (e.label) e.label = { ...e.label, color: lightColor(e.label.color, 'text') };
|
|
197
204
|
if (e.packet) e.packet = { ...e.packet, color: lightColor(e.packet.color), glowColor: lightColor(e.packet.glowColor) };
|
package/explorer/tokens.css
CHANGED
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
/* Diff: what a proposal adds, changes, removes and edits (the map draws the same four) */
|
|
55
55
|
--corn-added: #2dd4bf;
|
|
56
56
|
--corn-changed: #fbbf24;
|
|
57
|
-
--corn-removed: #
|
|
58
|
-
--corn-edit: #
|
|
57
|
+
--corn-removed: #fa9292;
|
|
58
|
+
--corn-edit: #b49cfb;
|
|
59
59
|
/* The same as text: mixed toward the text colour, so it reads on either ground */
|
|
60
60
|
--corn-added-text: color-mix(in srgb, var(--corn-added) 60%, var(--corn-text));
|
|
61
61
|
--corn-edit-text: color-mix(in srgb, var(--corn-edit) 60%, var(--corn-text));
|
|
@@ -212,10 +212,10 @@
|
|
|
212
212
|
--corn-bad: #b91c1c;
|
|
213
213
|
--corn-info: #03679e;
|
|
214
214
|
|
|
215
|
-
--corn-added: #
|
|
216
|
-
--corn-changed: #
|
|
217
|
-
--corn-removed: #
|
|
218
|
-
--corn-edit: #
|
|
215
|
+
--corn-added: #197c6f;
|
|
216
|
+
--corn-changed: #8f6703;
|
|
217
|
+
--corn-removed: #e20b0b;
|
|
218
|
+
--corn-edit: #6839f6;
|
|
219
219
|
|
|
220
220
|
--corn-hue-orange: #c2410c;
|
|
221
221
|
--corn-hue-fuchsia: #a21caf;
|
|
@@ -261,10 +261,10 @@
|
|
|
261
261
|
--corn-bad: #b91c1c;
|
|
262
262
|
--corn-info: #03679e;
|
|
263
263
|
|
|
264
|
-
--corn-added: #
|
|
265
|
-
--corn-changed: #
|
|
266
|
-
--corn-removed: #
|
|
267
|
-
--corn-edit: #
|
|
264
|
+
--corn-added: #197c6f;
|
|
265
|
+
--corn-changed: #8f6703;
|
|
266
|
+
--corn-removed: #e20b0b;
|
|
267
|
+
--corn-edit: #6839f6;
|
|
268
268
|
|
|
269
269
|
--corn-hue-orange: #c2410c;
|
|
270
270
|
--corn-hue-fuchsia: #a21caf;
|
package/explorer/whatif.js
CHANGED
|
@@ -25,6 +25,7 @@ import { render, isNodeVisible } from './render.js';
|
|
|
25
25
|
import { hooks, rebuildProposalMap, closeProposal } from './proposal.js';
|
|
26
26
|
import { getPlayer, playScenario, stopScenario, tickScenario } from './scenario-ui.js';
|
|
27
27
|
import { kindOfMark } from './proposal-model.js';
|
|
28
|
+
import { announce } from './keyboard.js';
|
|
28
29
|
import { edgeKey } from '../core/proposal.js';
|
|
29
30
|
import * as M from './whatif-model.js';
|
|
30
31
|
|
|
@@ -197,15 +198,21 @@ function doIntent(intent, where) {
|
|
|
197
198
|
|
|
198
199
|
export function undoEdit() {
|
|
199
200
|
if (!state.proposal || !M.canUndo(state.whatIf)) return false;
|
|
200
|
-
|
|
201
|
+
const edit = state.whatIf.edits[state.whatIf.edits.length - 1];
|
|
202
|
+
return step(M.undo(state.whatIf), edit, 'Undid');
|
|
201
203
|
}
|
|
202
204
|
export function redoEdit() {
|
|
203
205
|
if (!state.proposal || !M.canRedo(state.whatIf)) return false;
|
|
204
|
-
|
|
206
|
+
const edit = state.whatIf.undone[state.whatIf.undone.length - 1];
|
|
207
|
+
return step(M.redo(state.whatIf), edit, 'Redid');
|
|
205
208
|
}
|
|
206
|
-
|
|
209
|
+
/** Applies an undo or a redo, and says which edit it was ("Undid: Added the service “X”"); names are read where the node exists (before for an add, after for a remove) */
|
|
210
|
+
function step(whatIf, edit, verb) {
|
|
207
211
|
clearMessages();
|
|
212
|
+
const words = () => M.describeEdit(edit, { nameOf, scenarioTitle: (id) => (scenariosOf(state.effectiveProposal || state.proposal).find((s) => s.id === id) || { title: id }).title });
|
|
213
|
+
const before = words();
|
|
208
214
|
apply({ whatIf, effective: M.evaluate(base(), state.proposal, whatIf.edits).effective });
|
|
215
|
+
announce(`${verb}: ${/^remove/.test(edit.op) ? words() : before}`);
|
|
209
216
|
return true;
|
|
210
217
|
}
|
|
211
218
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.3",
|
|
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/proposals.js
CHANGED
|
@@ -168,7 +168,7 @@ function describeProposal(slug, source, proposal, topology) {
|
|
|
168
168
|
summary: object ? text(proposal.summary) : '',
|
|
169
169
|
spec: object && typeof proposal.spec === 'string' ? proposal.spec : null,
|
|
170
170
|
source,
|
|
171
|
-
counts: summarize(proposal),
|
|
171
|
+
counts: summarize(proposal), // the totals, and `nodes` and `edges` apart, so the list can say what it counts
|
|
172
172
|
errors: topology ? proposalProblems(topology, proposal).errors.length : null,
|
|
173
173
|
};
|
|
174
174
|
}
|