cornfield 0.61.0 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/explorer/css/map.css +28 -0
- package/explorer/history-model.js +72 -1
- package/explorer/history-replay.js +310 -0
- package/explorer/history.js +28 -6
- package/explorer/index.html +3 -0
- package/explorer/instance-state.js +1 -0
- package/explorer/page.js +4 -0
- package/explorer/pieces/node-panel.js +2 -0
- package/explorer/scene.js +30 -0
- package/package.json +1 -1
package/explorer/css/map.css
CHANGED
|
@@ -55,3 +55,31 @@
|
|
|
55
55
|
/* The bar while a spec is picked: what it reached, and the way back to the whole map */
|
|
56
56
|
.hx-history-bar { position: absolute; top: var(--corn-space-3); left: 50%; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: var(--corn-space-3); max-width: calc(100% - var(--corn-space-6)); padding: var(--corn-space-1) var(--corn-space-3); border-radius: var(--corn-radius-pill); font-size: var(--corn-text-sm); color: var(--corn-text); }
|
|
57
57
|
.hx-history-bar-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
58
|
+
|
|
59
|
+
/* Replay (spec 0014 D1, history-replay.js): the timeline strip along the bottom of the map, and the pulse on what a commit changed */
|
|
60
|
+
.hx-replay-btn[aria-pressed="true"] { background: var(--corn-surface-3); color: var(--corn-text); border-color: var(--corn-accent); }
|
|
61
|
+
.hx-timeline { position: absolute; left: var(--corn-space-4); right: var(--corn-space-4); bottom: var(--corn-space-4); z-index: 3; display: flex; flex-direction: column; gap: var(--corn-space-1); padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius); color: var(--corn-text); font-size: var(--corn-text-sm); }
|
|
62
|
+
.hx-timeline-bar { display: flex; align-items: center; gap: var(--corn-space-2); }
|
|
63
|
+
.hx-timeline-btn { min-width: 28px; height: 26px; padding: 0 var(--corn-space-2); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); font: inherit; cursor: pointer; }
|
|
64
|
+
.hx-timeline-btn:hover:not(:disabled) { background: var(--corn-surface-3); }
|
|
65
|
+
.hx-timeline-btn:disabled { opacity: 0.4; cursor: default; }
|
|
66
|
+
.hx-timeline-btn:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
|
|
67
|
+
.hx-timeline-count { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
|
|
68
|
+
.hx-timeline-track { position: relative; height: 34px; }
|
|
69
|
+
.hx-timeline-marks { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
70
|
+
.hx-timeline-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; background: transparent; appearance: none; -webkit-appearance: none; cursor: pointer; }
|
|
71
|
+
.hx-timeline-range::-webkit-slider-runnable-track { height: 100%; background: transparent; }
|
|
72
|
+
.hx-timeline-range::-moz-range-track { height: 100%; background: transparent; }
|
|
73
|
+
.hx-timeline-range::-webkit-slider-thumb { -webkit-appearance: none; width: 3px; height: 34px; border-radius: var(--corn-radius-pill); background: var(--corn-text); }
|
|
74
|
+
.hx-timeline-range::-moz-range-thumb { width: 3px; height: 34px; border: 0; border-radius: var(--corn-radius-pill); background: var(--corn-text); }
|
|
75
|
+
.hx-timeline-range:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
|
|
76
|
+
.hx-timeline-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2); min-width: 0; }
|
|
77
|
+
.hx-timeline-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50%; }
|
|
78
|
+
.hx-replay-pulses { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
|
|
79
|
+
.hx-replay-pulse { position: absolute; width: 0; height: 0; --r: 12px; }
|
|
80
|
+
.hx-replay-pulse::before { content: ""; position: absolute; left: calc(var(--r) * -1); top: calc(var(--r) * -1); width: calc(var(--r) * 2); height: calc(var(--r) * 2); box-sizing: border-box; border-radius: 50%; border: var(--corn-border-strong) solid var(--corn-history-week); animation: hx-replay-pulse 0.9s ease-out 1 forwards; }
|
|
81
|
+
@keyframes hx-replay-pulse { 0% { transform: scale(0.9); opacity: 1; } 100% { transform: scale(1.7); opacity: 0; } }
|
|
82
|
+
.hx-replay-pulses.is-static .hx-replay-pulse::before { animation: none; }
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
.hx-replay-pulse::before { animation: none !important; }
|
|
85
|
+
}
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
* haloWidth(count, max) a halo's width on screen (px) for how often its node changed
|
|
15
15
|
* historyRowOf(status, heat) the Layers menu's row under Overlays
|
|
16
16
|
* specBarHtml(pick, ctx) the bar on the map while a spec is picked: `Spec 0012 · Work as a view: 6 commits, 72 nodes`
|
|
17
|
+
* commitKind(subject) feat, fix, docs or other: a timeline mark's colour
|
|
18
|
+
* replayFrame(history, edges, at) Replay (spec 0014 D1): what the map holds at a commit, what was born at it and what it changed
|
|
19
|
+
* replayCount(frame, total) the count in the corner: `212 nodes · 340 edges · commit 45 of 132 · 3 born`
|
|
20
|
+
* stepWords(frame, ctx) what a step says to a screen reader
|
|
21
|
+
* speedMs(total, speed) how long a commit stays on screen while Replay plays
|
|
17
22
|
*/
|
|
18
23
|
|
|
19
24
|
import { escapeHtml as esc } from '../core/text.js';
|
|
@@ -157,7 +162,7 @@ export function historySectionHtml(node, ctx) {
|
|
|
157
162
|
const issues = t.issues.length ? `<p class="hx-history-issues">Issues: ${t.issues.map((i) => { const href = ctx.links && ctx.links.issue(i); return href ? `<a class="hx-link" data-corn="text-link" href="${esc(href)}" target="_blank" rel="noreferrer">#${esc(i)}</a>` : `#${esc(i)}`; }).join(', ')}</p>` : '';
|
|
158
163
|
const shown = ctx.all ? t.commits : t.commits.slice(0, HISTORY_CAP);
|
|
159
164
|
const rows = shown.map((c) => `<li class="hx-history-commit" data-corn="row">`
|
|
160
|
-
+ `<div class="hx-row-meta">${esc(dayOf(c.date, ctx.locale))} · ${c.nodes.length} ${c.nodes.length === 1 ? 'node' : 'nodes'}${t.born && c.index === t.born.index ? ' · <span class="hx-history-born">born here</span>' : ''}</div>`
|
|
165
|
+
+ `<div class="hx-row-meta">${esc(dayOf(c.date, ctx.locale))} · ${c.nodes.length} ${c.nodes.length === 1 ? 'node' : 'nodes'}${t.born && c.index === t.born.index ? ' · <span class="hx-history-born">born here</span>' : ''} · <button type="button" class="hx-textbtn" data-corn-kind="quiet" data-history-at="${c.index}" aria-label="Replay the map at this commit: ${esc(c.subject)}">Replay here</button></div>`
|
|
161
166
|
+ `<div class="hx-history-subject">${esc(c.subject)}</div>`
|
|
162
167
|
+ trailHtml(c, ctx)
|
|
163
168
|
+ '</li>');
|
|
@@ -246,3 +251,69 @@ export function specBarHtml(pick, { links, specs }) {
|
|
|
246
251
|
return `<span class="hx-history-bar-text">${name}${label}: ${c} ${c === 1 ? 'commit' : 'commits'}, ${n} ${n === 1 ? 'node' : 'nodes'}</span>`
|
|
247
252
|
+ `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn-kind="quiet" data-history-unpick>Show the whole map</button>`;
|
|
248
253
|
}
|
|
254
|
+
|
|
255
|
+
/** A commit's kind, from its conventional title: `feat`, `fix`, `docs`, or `other` */
|
|
256
|
+
export function commitKind(subject) {
|
|
257
|
+
const m = /^(\w+)(?:\([^)]*\))?!?:/.exec(String(subject || ''));
|
|
258
|
+
const k = m ? m[1].toLowerCase() : '';
|
|
259
|
+
return k === 'feat' || k === 'fix' || k === 'docs' ? k : 'other';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The parent of each node, by its ownership edge (no kind, not dashed): where a node buds from */
|
|
263
|
+
export function parentsOf(edges) {
|
|
264
|
+
const out = new Map();
|
|
265
|
+
for (const e of edges || []) if (e && !e.dashed && !e.kind && e.from !== e.to && !out.has(e.to)) out.set(e.to, e.from);
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The map at a commit (spec 0014 D1): every node born by then (a node the history does not hold, newer than it, is always there), the edges
|
|
271
|
+
* between them, the nodes born at this commit and those it changed.
|
|
272
|
+
* @param {{ commits: object[], nodes: Record<string, { born: number }> }} history
|
|
273
|
+
* @param {{ from: string, to: string }[]} edges the map's edges
|
|
274
|
+
* @param {number} at a commit's index
|
|
275
|
+
*/
|
|
276
|
+
export function replayFrame(history, edges, at) {
|
|
277
|
+
const commits = history.commits;
|
|
278
|
+
const i = Math.max(0, Math.min(commits.length - 1, Number.isInteger(at) ? at : commits.length - 1));
|
|
279
|
+
const hidden = new Set();
|
|
280
|
+
const born = [];
|
|
281
|
+
for (const [id, e] of Object.entries(history.nodes || {})) {
|
|
282
|
+
if (e.born > i) hidden.add(id);
|
|
283
|
+
else if (e.born === i) born.push(id);
|
|
284
|
+
}
|
|
285
|
+
const all = Object.keys(history.nodes || {}).length;
|
|
286
|
+
const shownEdges = (edges || []).filter((e) => !hidden.has(e.from) && !hidden.has(e.to)).length;
|
|
287
|
+
const commit = commits[i];
|
|
288
|
+
return { at: i, total: commits.length, commit, hidden, born: born.sort(), changed: (commit && commit.nodes) || [], nodes: all - hidden.size, edges: shownEdges };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The count in the corner of the timeline */
|
|
292
|
+
export function replayCount(f) {
|
|
293
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
294
|
+
return `${plural(f.nodes, 'node', 'nodes')} · ${plural(f.edges, 'edge', 'edges')} · commit ${f.at + 1} of ${f.total}${f.born.length ? ` · ${f.born.length} born` : ''}`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* What a step says to a screen reader: the commit, then what was born and what changed, by name (the first few).
|
|
299
|
+
* @param {ReturnType<typeof replayFrame>} f
|
|
300
|
+
* @param {{ labelOf: (id: string) => string, locale?: string }} ctx
|
|
301
|
+
*/
|
|
302
|
+
export function stepWords(f, { labelOf, locale }) {
|
|
303
|
+
const c = f.commit || {};
|
|
304
|
+
const names = (ids) => {
|
|
305
|
+
const first = ids.slice(0, 3).map(labelOf);
|
|
306
|
+
return ids.length > 3 ? `${first.join(', ')} and ${ids.length - 3} more` : first.length > 1 ? `${first.slice(0, -1).join(', ')} and ${first[first.length - 1]}` : first.join('');
|
|
307
|
+
};
|
|
308
|
+
const parts = [`Commit ${f.at + 1} of ${f.total}, ${dayOf(c.date, locale)}: ${c.subject || ''}.`];
|
|
309
|
+
if (f.born.length) parts.push(`Born: ${names(f.born)}.`);
|
|
310
|
+
const changed = f.changed.filter((id) => !f.born.includes(id));
|
|
311
|
+
if (changed.length) parts.push(`Changed: ${names(changed)}.`);
|
|
312
|
+
parts.push(`${f.nodes} ${f.nodes === 1 ? 'node' : 'nodes'} on the map.`);
|
|
313
|
+
return parts.join(' ');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The speeds Replay plays at */
|
|
317
|
+
export const SPEEDS = Object.freeze([1, 2, 4]);
|
|
318
|
+
/** How long a commit stays on screen while Replay plays (ms): the whole history in about 40 seconds at 1×, never under 40 ms or over 700 ms a commit */
|
|
319
|
+
export const speedMs = (total, speed = 1) => Math.max(40, Math.min(700, 40_000 / Math.max(1, total))) / (SPEEDS.includes(speed) ? speed : 1);
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/history-replay
|
|
3
|
+
*
|
|
4
|
+
* Replay (spec 0014 D1): the map grows on a timeline, commit by commit, like cells in a dish. The layout is today's and never moves; at a commit
|
|
5
|
+
* the map holds only the nodes born by then and the lines between them (`state.replay`, which scene.js reads). A node being born buds out of its
|
|
6
|
+
* parent and settles into its place; the nodes a commit changed pulse once. Under reduced motion nothing buds or pulses: nodes simply appear,
|
|
7
|
+
* and a changed node wears a still ring for its step.
|
|
8
|
+
*
|
|
9
|
+
* The timeline is a strip along the bottom of the map: one mark per commit (its height how many nodes it touched, its colour its kind), the
|
|
10
|
+
* playhead, Play or Pause, a step back and forward, three speeds, Now (back to the map as it is), the commit at the playhead as a trail, and a
|
|
11
|
+
* count. The playhead is a range input, so the keyboard has it whole (arrows, Home, End, Page keys); a step says what was born and what changed.
|
|
12
|
+
*
|
|
13
|
+
* createReplay(inst, source) -> { start(at?), stop(), open(), repaint(), destroy() }
|
|
14
|
+
*
|
|
15
|
+
* `source` is history.js's: `{ ready(), history(), load(), links, specs() }`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { announce } from './engine/keyboard.js';
|
|
19
|
+
import { SPEEDS, commitKind, dayOf, parentsOf, replayCount, replayFrame, speedMs, stepWords, trailHtml } from './history-model.js';
|
|
20
|
+
import { escapeHtml as esc } from '../core/text.js';
|
|
21
|
+
|
|
22
|
+
/** How long a node takes to bud out of its parent (ms) */
|
|
23
|
+
export const BUD_MS = 520;
|
|
24
|
+
/** The tokens a mark is drawn in, by the commit's kind; a picked spec's commits get a dot in the last */
|
|
25
|
+
const MARK_TOKENS = { feat: '--corn-added', fix: '--corn-warn', docs: '--corn-accent', other: '--corn-text-3', spec: '--corn-history-week' };
|
|
26
|
+
const ease = (t) => 1 - (1 - t) ** 3;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {ReturnType<typeof import('./instance.js').createInstance>} inst
|
|
30
|
+
* @param {{ ready: () => boolean, history: () => object, load: () => Promise<void>, links: object | null, specs: () => Map<string, object> }} source
|
|
31
|
+
*/
|
|
32
|
+
export function createReplay(inst, source) {
|
|
33
|
+
const { state } = inst;
|
|
34
|
+
let strip = null;
|
|
35
|
+
let pulses = null;
|
|
36
|
+
let frame = null;
|
|
37
|
+
let parents = new Map();
|
|
38
|
+
let playing = false;
|
|
39
|
+
let speed = 1;
|
|
40
|
+
let acc = 0;
|
|
41
|
+
let last = null;
|
|
42
|
+
/** @type {Map<string, { x: number, y: number, start: number | null }>} the nodes budding, from where */
|
|
43
|
+
const buds = new Map();
|
|
44
|
+
let pulsedAt = -1;
|
|
45
|
+
let offFrames = null;
|
|
46
|
+
let offPaint = null;
|
|
47
|
+
|
|
48
|
+
const open = () => !!state.replay;
|
|
49
|
+
const byId = (id) => state.nodes.find((n) => n.id === id);
|
|
50
|
+
const labelOf = (id) => { const n = byId(id); return n ? String(n.label || n.id) : id; };
|
|
51
|
+
const stage = () => (state.canvas && state.canvas.parentElement) || null;
|
|
52
|
+
const button = () => inst.el('replay-btn');
|
|
53
|
+
|
|
54
|
+
function wire() {
|
|
55
|
+
if (!inst.map) return;
|
|
56
|
+
if (!offFrames) offFrames = inst.map.addFrameClient({ wants: () => open() && (playing || buds.size > 0), tick });
|
|
57
|
+
if (!offPaint) offPaint = inst.map.onPaint((scene, camera) => placePulses(scene, camera));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Each frame: the playhead moves on while playing, and the buds grow */
|
|
61
|
+
function tick(now) {
|
|
62
|
+
if (!open()) return;
|
|
63
|
+
const dt = last === null ? 16 : Math.min(now - last, 250);
|
|
64
|
+
last = now;
|
|
65
|
+
if (playing) {
|
|
66
|
+
acc += dt;
|
|
67
|
+
const each = speedMs(frame.total, speed);
|
|
68
|
+
while (acc >= each && playing) {
|
|
69
|
+
acc -= each;
|
|
70
|
+
if (frame.at >= frame.total - 1) { setPlaying(false); announce(inst, `The end: ${replayCount(frame)}`); break; }
|
|
71
|
+
go(frame.at + 1, { bud: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (buds.size) {
|
|
75
|
+
const bud = new Map();
|
|
76
|
+
for (const [id, b] of buds) {
|
|
77
|
+
if (b.start === null) b.start = now;
|
|
78
|
+
const t = (now - b.start) / BUD_MS;
|
|
79
|
+
if (t >= 1) buds.delete(id); else bud.set(id, { x: b.x, y: b.y, t: ease(t) });
|
|
80
|
+
}
|
|
81
|
+
state.replay.bud = bud;
|
|
82
|
+
inst.touchScene();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Moves the playhead to a commit. `bud`: a step forward, so what was born there buds (a jump or a scrub just shows it). `say`: a screen reader hears the step.
|
|
88
|
+
*/
|
|
89
|
+
function go(at, { bud = false, say = false } = {}) {
|
|
90
|
+
const h = source.history();
|
|
91
|
+
frame = replayFrame(h, state.edges, at);
|
|
92
|
+
if (!bud || inst.reducedMotion) buds.clear();
|
|
93
|
+
else {
|
|
94
|
+
for (const id of frame.born) {
|
|
95
|
+
const p = byId(parents.get(id));
|
|
96
|
+
if (p && !frame.hidden.has(p.id)) buds.set(id, { x: p.x, y: p.y, start: null });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
state.replay = { at: frame.at, hidden: frame.hidden, bud: new Map([...buds].map(([id, b]) => [id, { x: b.x, y: b.y, t: 0 }])) };
|
|
100
|
+
state.historyAt = frame.at;
|
|
101
|
+
paintStrip();
|
|
102
|
+
inst.touchScene();
|
|
103
|
+
inst.emit('history:at');
|
|
104
|
+
if (inst.map) { inst.map.render(); inst.map.ensureFlowLoop(); }
|
|
105
|
+
if (say) announce(inst, stepWords(frame, { labelOf }));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function setPlaying(on) {
|
|
109
|
+
playing = !!on && !!frame && frame.at < frame.total - 1;
|
|
110
|
+
acc = 0;
|
|
111
|
+
last = null;
|
|
112
|
+
paintControls();
|
|
113
|
+
if (playing && inst.map) inst.map.ensureFlowLoop();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// The strip
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
function buildStrip() {
|
|
120
|
+
const host = stage();
|
|
121
|
+
if (!host) return;
|
|
122
|
+
if (strip && strip.isConnected) return;
|
|
123
|
+
strip = inst.doc.createElement('div');
|
|
124
|
+
strip.className = 'hx-timeline glass';
|
|
125
|
+
strip.setAttribute('role', 'group');
|
|
126
|
+
strip.setAttribute('aria-label', 'Replay the map\'s history');
|
|
127
|
+
strip.innerHTML = `<div class="hx-timeline-bar">
|
|
128
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn" data-replay="back" aria-label="Step back a commit" title="Step back a commit">‹</button>
|
|
129
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn hx-timeline-play" data-replay="play" aria-label="Play">▶</button>
|
|
130
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn" data-replay="forward" aria-label="Step forward a commit" title="Step forward a commit">›</button>
|
|
131
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn hx-timeline-speed" data-replay="speed" aria-label="Speed 1×" title="Speed">1×</button>
|
|
132
|
+
<span class="hx-timeline-count hx-faint" aria-live="off"></span>
|
|
133
|
+
<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn-kind="quiet" data-replay="now" title="Back to the map as it is now">Now</button>
|
|
134
|
+
</div>
|
|
135
|
+
<div class="hx-timeline-track">
|
|
136
|
+
<canvas class="hx-timeline-marks" aria-hidden="true"></canvas>
|
|
137
|
+
<input type="range" data-corn="control" class="hx-timeline-range" min="0" max="0" step="1" value="0" aria-label="Commit">
|
|
138
|
+
</div>
|
|
139
|
+
<div class="hx-timeline-line"></div>`;
|
|
140
|
+
strip.addEventListener('click', onClick);
|
|
141
|
+
const range = strip.querySelector('.hx-timeline-range');
|
|
142
|
+
range.addEventListener('input', () => { setPlaying(false); go(Number(range.value)); });
|
|
143
|
+
range.addEventListener('change', () => { if (frame) announce(inst, stepWords(frame, { labelOf })); });
|
|
144
|
+
host.append(strip);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function onClick(e) {
|
|
148
|
+
const b = e.target.closest('[data-replay]');
|
|
149
|
+
if (!b || !frame) return;
|
|
150
|
+
const what = b.getAttribute('data-replay');
|
|
151
|
+
if (what === 'play') setPlaying(!playing);
|
|
152
|
+
else if (what === 'back') { setPlaying(false); go(frame.at - 1, { say: true }); }
|
|
153
|
+
else if (what === 'forward') { setPlaying(false); go(frame.at + 1, { bud: true, say: true }); }
|
|
154
|
+
else if (what === 'speed') { speed = SPEEDS[(SPEEDS.indexOf(speed) + 1) % SPEEDS.length]; acc = 0; paintControls(); announce(inst, `Speed ${speed}×`); }
|
|
155
|
+
else if (what === 'now') stop();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function paintControls() {
|
|
159
|
+
if (!strip) return;
|
|
160
|
+
const play = strip.querySelector('[data-replay="play"]');
|
|
161
|
+
play.textContent = playing ? '❚❚' : '▶';
|
|
162
|
+
play.setAttribute('aria-label', playing ? 'Pause' : 'Play');
|
|
163
|
+
const sp = strip.querySelector('[data-replay="speed"]');
|
|
164
|
+
sp.textContent = `${speed}×`;
|
|
165
|
+
sp.setAttribute('aria-label', `Speed ${speed}×`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function paintStrip() {
|
|
169
|
+
if (!strip || !frame) return;
|
|
170
|
+
const c = frame.commit || {};
|
|
171
|
+
const range = strip.querySelector('.hx-timeline-range');
|
|
172
|
+
range.max = String(frame.total - 1);
|
|
173
|
+
range.value = String(frame.at);
|
|
174
|
+
range.setAttribute('aria-valuetext', `Commit ${frame.at + 1} of ${frame.total}, ${dayOf(c.date)}: ${c.subject || ''}`);
|
|
175
|
+
strip.querySelector('.hx-timeline-count').textContent = replayCount(frame);
|
|
176
|
+
strip.querySelector('[data-replay="back"]').disabled = frame.at <= 0;
|
|
177
|
+
strip.querySelector('[data-replay="forward"]').disabled = frame.at >= frame.total - 1;
|
|
178
|
+
strip.querySelector('.hx-timeline-line').innerHTML = `<span class="hx-faint">${esc(dayOf(c.date))}</span> <span class="hx-timeline-subject">${esc(c.subject || '')}</span> ${trailHtml(c, { links: source.links, specs: source.specs() })}`;
|
|
179
|
+
paintControls();
|
|
180
|
+
paintMarks();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The marks: one per commit, its height how many nodes it touched, its colour its kind; those after the playhead faint; a picked spec's commits dotted */
|
|
184
|
+
function paintMarks() {
|
|
185
|
+
const canvas = strip && strip.querySelector('.hx-timeline-marks');
|
|
186
|
+
if (!canvas || !frame) return;
|
|
187
|
+
const w = canvas.clientWidth || 0;
|
|
188
|
+
const hgt = canvas.clientHeight || 0;
|
|
189
|
+
let ctx = null;
|
|
190
|
+
try { ctx = w && hgt ? canvas.getContext('2d') : null; } catch { ctx = null; }
|
|
191
|
+
if (!ctx) return;
|
|
192
|
+
const ratio = (inst.doc.defaultView && inst.doc.defaultView.devicePixelRatio) || 1;
|
|
193
|
+
canvas.width = Math.round(w * ratio);
|
|
194
|
+
canvas.height = Math.round(hgt * ratio);
|
|
195
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
196
|
+
ctx.clearRect(0, 0, w, hgt);
|
|
197
|
+
const read = inst.tokenReader();
|
|
198
|
+
const colour = (k) => (read && read(MARK_TOKENS[k]).trim()) || 'gray';
|
|
199
|
+
const colours = Object.fromEntries(Object.keys(MARK_TOKENS).map((k) => [k, colour(k)]));
|
|
200
|
+
const commits = source.history().commits;
|
|
201
|
+
const n = commits.length;
|
|
202
|
+
const most = Math.max(1, ...commits.map((x) => (x.nodes ? x.nodes.length : 0)));
|
|
203
|
+
const pick = state.historyPick ? state.historyPick.spec : null;
|
|
204
|
+
const step = n > 1 ? (w - 4) / (n - 1) : 0;
|
|
205
|
+
const barW = Math.max(1, Math.min(4, step * 0.7));
|
|
206
|
+
for (let i = 0; i < n; i++) {
|
|
207
|
+
const x = 2 + i * step;
|
|
208
|
+
const k = commits[i].nodes ? commits[i].nodes.length : 0;
|
|
209
|
+
const h = Math.max(2, (hgt - 8) * Math.sqrt(k / most));
|
|
210
|
+
ctx.globalAlpha = i <= frame.at ? 1 : 0.3;
|
|
211
|
+
ctx.fillStyle = colours[commitKind(commits[i].subject)];
|
|
212
|
+
ctx.fillRect(x - barW / 2, hgt - h, barW, h);
|
|
213
|
+
if (pick && commits[i].specs && commits[i].specs.includes(pick)) {
|
|
214
|
+
ctx.globalAlpha = 1;
|
|
215
|
+
ctx.fillStyle = colours.spec;
|
|
216
|
+
ctx.beginPath();
|
|
217
|
+
ctx.arc(x, 3, 2.5, 0, Math.PI * 2);
|
|
218
|
+
ctx.fill();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
ctx.globalAlpha = 1;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
// The pulses: a ring on each node the commit at the playhead changed, once
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
function placePulses(scene, camera) {
|
|
228
|
+
if (!open() || !frame) { if (pulses) { pulses.remove(); pulses = null; } return; }
|
|
229
|
+
const host = stage();
|
|
230
|
+
if (!host) return;
|
|
231
|
+
if (!pulses || !pulses.isConnected) {
|
|
232
|
+
pulses = inst.doc.createElement('div');
|
|
233
|
+
pulses.className = 'hx-replay-pulses';
|
|
234
|
+
pulses.setAttribute('aria-hidden', 'true');
|
|
235
|
+
host.append(pulses);
|
|
236
|
+
pulsedAt = -1;
|
|
237
|
+
}
|
|
238
|
+
pulses.classList.toggle('is-static', !!inst.reducedMotion);
|
|
239
|
+
if (pulsedAt !== frame.at) { pulses.innerHTML = ''; pulsedAt = frame.at; }
|
|
240
|
+
const want = new Set(frame.changed);
|
|
241
|
+
const have = new Map([...pulses.children].map((el) => [el.dataset.node, el]));
|
|
242
|
+
for (const node of scene.nodes) {
|
|
243
|
+
if (!want.has(node.id)) continue;
|
|
244
|
+
let el = have.get(node.id);
|
|
245
|
+
if (!el) {
|
|
246
|
+
el = inst.doc.createElement('span');
|
|
247
|
+
el.className = 'hx-replay-pulse';
|
|
248
|
+
el.dataset.node = node.id;
|
|
249
|
+
if (frame.born.includes(node.id)) el.dataset.born = '';
|
|
250
|
+
pulses.append(el);
|
|
251
|
+
}
|
|
252
|
+
el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
|
|
253
|
+
el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
|
|
254
|
+
el.style.setProperty('--r', `${(Math.max(6, node.r * camera.zoom) + 4).toFixed(1)}px`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ---------------------------------------------------------------------------
|
|
259
|
+
// Opening and closing
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
async function start(at = 0) {
|
|
262
|
+
if (state.view !== 'orbit') return;
|
|
263
|
+
if (!source.ready()) {
|
|
264
|
+
announce(inst, 'Reading the history…');
|
|
265
|
+
await source.load();
|
|
266
|
+
if (!source.ready()) { announce(inst, 'The history could not be read, so there is nothing to replay.'); return; }
|
|
267
|
+
}
|
|
268
|
+
const h = source.history();
|
|
269
|
+
if (!h.commits.length) { announce(inst, 'The history has no commit to replay.'); return; }
|
|
270
|
+
parents = parentsOf(state.edges);
|
|
271
|
+
wire();
|
|
272
|
+
buildStrip();
|
|
273
|
+
const btn = button();
|
|
274
|
+
if (btn) btn.setAttribute('aria-pressed', 'true');
|
|
275
|
+
go(at, { say: true });
|
|
276
|
+
setPlaying(!inst.reducedMotion && at === 0);
|
|
277
|
+
if (strip) strip.querySelector(playing ? '[data-replay="play"]' : '.hx-timeline-range').focus();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function stop() {
|
|
281
|
+
if (!open()) return;
|
|
282
|
+
const had = strip && strip.contains(inst.active());
|
|
283
|
+
setPlaying(false);
|
|
284
|
+
buds.clear();
|
|
285
|
+
state.replay = null;
|
|
286
|
+
state.historyAt = null;
|
|
287
|
+
frame = null;
|
|
288
|
+
if (strip) { strip.remove(); strip = null; }
|
|
289
|
+
if (pulses) { pulses.remove(); pulses = null; }
|
|
290
|
+
const btn = button();
|
|
291
|
+
if (btn) { btn.setAttribute('aria-pressed', 'false'); if (had) btn.focus(); }
|
|
292
|
+
inst.touchScene();
|
|
293
|
+
inst.emit('history:at');
|
|
294
|
+
if (inst.map) inst.map.render();
|
|
295
|
+
announce(inst, 'Back to the map as it is now');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
start,
|
|
300
|
+
stop,
|
|
301
|
+
open,
|
|
302
|
+
/** The strip again: a pick changed (its commits' dots), or the theme */
|
|
303
|
+
repaint: () => paintStrip(),
|
|
304
|
+
destroy() {
|
|
305
|
+
stop();
|
|
306
|
+
if (offFrames) { offFrames(); offFrames = null; }
|
|
307
|
+
if (offPaint) { offPaint(); offPaint = null; }
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
package/explorer/history.js
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
* history:all (none) (emit) the section lists every commit, not only the newest
|
|
19
19
|
* history:changed (none) (emitted) the read ended, or a pick changed: the open panel draws its History section again
|
|
20
20
|
* history:legend { active } (emitted) the History layer is drawn: the Layers menu shows its legend
|
|
21
|
+
* history:replay at? (emit) open Replay (history-replay.js) at a commit, or close it when it is open and no commit is named
|
|
22
|
+
* history:at (none) (emitted) the timeline's commit moved (`state.historyAt`): the halos follow it
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
import { credentialed } from './engine/connection.js';
|
|
24
26
|
import { announce } from './engine/keyboard.js';
|
|
25
27
|
import { onLayersChange, redrawLayers } from './engine/layers.js';
|
|
26
28
|
import { layerOn } from './layer-model.js';
|
|
29
|
+
import { createReplay } from './history-replay.js';
|
|
27
30
|
import { HISTORY_LAYER, MAX_HALOS, forgeLinks, haloWidth, heatOf, historyRowOf, historySectionHtml, specBarHtml, specFiles, specReach } from './history-model.js';
|
|
28
31
|
|
|
29
32
|
/** Where the server answers the history (server/server.js) */
|
|
@@ -37,10 +40,8 @@ export const HISTORY_PATH = '/api/history';
|
|
|
37
40
|
export function initHistory(inst, config) {
|
|
38
41
|
/** The dot of the Layers menu's row: this week's halo colour, as the theme has it */
|
|
39
42
|
const haloColor = () => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const v = root && view && view.getComputedStyle ? view.getComputedStyle(root).getPropertyValue('--corn-history-week').trim() : '';
|
|
43
|
-
return v || 'currentColor';
|
|
43
|
+
const read = inst.tokenReader();
|
|
44
|
+
return (read && read('--corn-history-week').trim()) || 'currentColor';
|
|
44
45
|
};
|
|
45
46
|
const { state } = inst;
|
|
46
47
|
const on = !!(config && config.history === true);
|
|
@@ -138,8 +139,12 @@ export function initHistory(inst, config) {
|
|
|
138
139
|
if (inst.map) inst.map.render();
|
|
139
140
|
}
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
let reading = null;
|
|
143
|
+
function load() {
|
|
144
|
+
if (mem.status === 'idle') reading = read();
|
|
145
|
+
return reading || Promise.resolve();
|
|
146
|
+
}
|
|
147
|
+
async function read() {
|
|
143
148
|
mem.status = 'loading';
|
|
144
149
|
try {
|
|
145
150
|
const res = await credentialed(inst)(HISTORY_PATH);
|
|
@@ -172,7 +177,24 @@ export function initHistory(inst, config) {
|
|
|
172
177
|
inst.emit('history:changed');
|
|
173
178
|
}
|
|
174
179
|
|
|
180
|
+
const replay = mem.status === 'off' ? null : createReplay(inst, {
|
|
181
|
+
ready: () => mem.status === 'ready',
|
|
182
|
+
history: () => mem.history,
|
|
183
|
+
load,
|
|
184
|
+
links: mem.links,
|
|
185
|
+
specs: () => { if (!mem.specs) mem.specs = specFiles(state.nodes); return mem.specs; },
|
|
186
|
+
});
|
|
187
|
+
|
|
175
188
|
if (mem.status !== 'off') {
|
|
189
|
+
const btn = inst.el('replay-btn');
|
|
190
|
+
if (btn) btn.hidden = false;
|
|
191
|
+
stops.push(inst.on('history:replay', (at) => {
|
|
192
|
+
if (Number.isInteger(at)) { if (replay.open()) replay.stop(); replay.start(at); return; }
|
|
193
|
+
if (replay.open()) replay.stop(); else replay.start(0);
|
|
194
|
+
}));
|
|
195
|
+
stops.push(inst.on('view', () => { if (state.view !== 'orbit' && replay.open()) replay.stop(); }));
|
|
196
|
+
stops.push(inst.on('history:changed', () => { if (replay.open()) replay.repaint(); }));
|
|
197
|
+
stops.push(() => { replay.destroy(); if (btn) btn.hidden = true; });
|
|
176
198
|
// The Layers menu's row under Overlays (engine/layers.js `layerRows`), in the colour of this week's halo
|
|
177
199
|
state.historyRow = () => historyRowOf(mem.status, mem.status === 'ready' ? heatNow() : null, haloColor());
|
|
178
200
|
stops.push(onLayersChange(inst, layerChanged));
|
package/explorer/index.html
CHANGED
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
</button>
|
|
64
64
|
</div>
|
|
65
65
|
|
|
66
|
+
<!-- Replay (spec 0014 D1, explorer/history-replay.js): the map grows on a timeline, commit by commit; shown when the config has history on -->
|
|
67
|
+
<button type="button" id="replay-btn" class="hx-layers-chip hx-replay-btn" data-action="history-replay" data-corn-kind="secondary" aria-pressed="false" hidden title="Replay the map's history, commit by commit">Replay</button>
|
|
68
|
+
|
|
66
69
|
<!-- The Layers chip: how many of the layers are on; it opens the layers menu. On a phone it sits on the map, top left. It is a piece (explorer/pieces/layers.js): page.js mounts it here. Until then a stand-in (its markup without ids) holds its place, so the first paint has the chip and nothing moves when the piece comes; test/explorer/page-pieces.test.js keeps the two the same -->
|
|
67
70
|
<!--corn-placeholder:layers/menu-->
|
|
68
71
|
<div class="hx-menu-wrap hx-layers">
|
|
@@ -46,6 +46,7 @@ export function createState() {
|
|
|
46
46
|
/** The spec picked in a node's History (history.js, spec 0014 D3): `{ spec, nodes }`, the nodes its commits touched, lit while the rest dims; or null */
|
|
47
47
|
historyPick: null,
|
|
48
48
|
historyAt: null, // the timeline's commit (spec 0014 D1), an index into the history; null is the newest
|
|
49
|
+
replay: null, // Replay (history-replay.js, spec 0014 D1): { at, hidden: Set of the nodes not born yet, bud: Map of the nodes budding }
|
|
49
50
|
historyRow: null, // the History layer's row in the Layers menu (history.js), while the config has history on
|
|
50
51
|
/** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
|
|
51
52
|
searchCurrent: null,
|
package/explorer/page.js
CHANGED
|
@@ -116,6 +116,10 @@ const ACTIONS = {
|
|
|
116
116
|
setView(state.view === 'dataflow' ? 'orbit' : 'dataflow');
|
|
117
117
|
},
|
|
118
118
|
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
119
|
+
'history-replay': () => { // Replay (spec 0014 D1) runs on the Map view: from another view it goes there first
|
|
120
|
+
if (state.view !== 'orbit') { closeDrawer(); setView('orbit'); }
|
|
121
|
+
inst.emit('history:replay');
|
|
122
|
+
},
|
|
119
123
|
'retry': () => loadTopology(),
|
|
120
124
|
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
|
121
125
|
};
|
|
@@ -408,6 +408,8 @@ export function mount(root, inst, options = {}) {
|
|
|
408
408
|
const spec = e.target.closest && e.target.closest('[data-history-spec]');
|
|
409
409
|
if (spec) { inst.emit('history:pick', spec.dataset.historySpec); return true; }
|
|
410
410
|
if (e.target.closest && e.target.closest('[data-history-all]')) { inst.emit('history:all'); return true; }
|
|
411
|
+
const at = e.target.closest && e.target.closest('[data-history-at]');
|
|
412
|
+
if (at) { inst.emit('history:replay', Number(at.dataset.historyAt)); return true; } // the timeline moves to the commit (spec 0014 D2)
|
|
411
413
|
return false;
|
|
412
414
|
}
|
|
413
415
|
|
package/explorer/scene.js
CHANGED
|
@@ -290,6 +290,7 @@ export function isNodeVisible(state, node, { viewer = false } = {}) {
|
|
|
290
290
|
if (state.view === 'work') return node.hidden !== true; // the Work view (spec 0012): its layers set `hidden` on the nodes (work-view.js)
|
|
291
291
|
if (state.view === 'dataflow') return !!state.flow && state.flow.ids.has(node.id);
|
|
292
292
|
if (state.view === 'house') return houseShowsNode(state, node); // the House view (spec 0029, PHY-11) draws its own set: house-model.js
|
|
293
|
+
if (state.replay && state.replay.hidden.has(node.id)) return false; // Replay (history-replay.js, spec 0014 D1): a node not yet born at the timeline's commit
|
|
293
294
|
if (node.type === 'root') return true;
|
|
294
295
|
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)
|
|
295
296
|
}
|
|
@@ -736,6 +737,34 @@ export function emphasiseScenario(scene, scn, opts = {}) {
|
|
|
736
737
|
* @param {{reduceMotion?: boolean}} [opts] `reduceMotion`: describe no packets (prefers-reduced-motion)
|
|
737
738
|
* @returns {Scene}
|
|
738
739
|
*/
|
|
740
|
+
/**
|
|
741
|
+
* Replay's budding (spec 0014 D1): a node being born grows out of its parent and settles into its place. `bud` holds, by node id, where it buds
|
|
742
|
+
* from and how far it has come (`t`, 0 to 1, eased); its lines follow it. The layout itself never moves.
|
|
743
|
+
* @param {{ nodes: object[], edges: object[] }} scene
|
|
744
|
+
* @param {Map<string, { x: number, y: number, t: number }>} bud
|
|
745
|
+
*/
|
|
746
|
+
export function budScene(scene, bud) {
|
|
747
|
+
const at = new Map();
|
|
748
|
+
for (const n of scene.nodes) {
|
|
749
|
+
const b = bud.get(n.id);
|
|
750
|
+
if (!b) continue;
|
|
751
|
+
const t = Math.max(0, Math.min(1, b.t));
|
|
752
|
+
n.x = b.x + (n.x - b.x) * t;
|
|
753
|
+
n.y = b.y + (n.y - b.y) * t;
|
|
754
|
+
n.r *= Math.max(0.15, t);
|
|
755
|
+
n.alpha *= Math.max(0.2, t);
|
|
756
|
+
at.set(n.id, n);
|
|
757
|
+
}
|
|
758
|
+
for (const e of scene.edges) {
|
|
759
|
+
const a = at.get(e.from);
|
|
760
|
+
const z = at.get(e.to);
|
|
761
|
+
if (!a && !z) continue;
|
|
762
|
+
if (a) { e.x1 = a.x; e.y1 = a.y; e.r1 = a.r; }
|
|
763
|
+
if (z) { e.x2 = z.x; e.y2 = z.y; e.r2 = z.r; }
|
|
764
|
+
if (e.curve) e.curve = { cx: (e.x1 + e.x2) / 2, cy: (e.y1 + e.y2) / 2 };
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
739
768
|
export function buildScene(state, opts = {}) {
|
|
740
769
|
const preset = state.view === 'dataflow';
|
|
741
770
|
const subgraph = state.scenario ? scenarioSubgraph(state) : state.selectedNode ? getActiveSubgraph(state.selectedNode, viewEdgesOf(state), { throughChildren: !!state.throughChildren, kind: state.selectedKind || null }) : null;
|
|
@@ -752,6 +781,7 @@ export function buildScene(state, opts = {}) {
|
|
|
752
781
|
theme: 'dark',
|
|
753
782
|
version: state.sceneVersion || 0,
|
|
754
783
|
};
|
|
784
|
+
if (state.replay && state.replay.bud && state.replay.bud.size) budScene(scene, state.replay.bud);
|
|
755
785
|
if (state.view === 'house') decorateHouseScene(scene, state); // its bands and tray as lanes, rooms unlabelled (house-model.js)
|
|
756
786
|
if (state.view === 'work' && state.workLanes) scene.decor.lanes = state.workLanes; // its lanes and their titles (work-model.js)
|
|
757
787
|
if (state.scenario) emphasiseScenario(scene, state.scenario, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.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)",
|