cornfield 0.60.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.
@@ -41,3 +41,45 @@
41
41
  .hx-run-tag { position: absolute; left: 0; top: calc(var(--r) + 4px); transform: translateX(-50%); white-space: nowrap; padding: calc(var(--corn-space-1) / 2) var(--corn-space-2); border-radius: var(--corn-radius-pill); border: var(--corn-border) solid var(--corn-map-collision); background: color-mix(in srgb, var(--corn-ground) 80%, transparent); color: var(--corn-map-collision); font-size: var(--corn-text-xs); font-weight: 700; }
42
42
  .hx-run-swatch { display: inline-block; width: 14px; height: 14px; flex: none; box-sizing: border-box; border-radius: 50%; border: var(--corn-border-strong) solid var(--corn-added); }
43
43
  .hx-run-swatch--collision { border: var(--corn-border-strong) dashed var(--corn-map-collision); }
44
+
45
+ /* The History layer (spec 0014 D3, history.js): a halo round each node the history changed; its width how often (--w), its colour how lately */
46
+ .hx-history-halos { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
47
+ .hx-history-halos[hidden] { display: none; }
48
+ .hx-history-halo { position: absolute; width: 0; height: 0; --r: 12px; --w: 2px; --halo: var(--corn-history-old); }
49
+ .hx-history-halo::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(--w) solid var(--halo); opacity: 0.7; }
50
+ .hx-history-halo[data-band="week"], .hx-history-swatch[data-band="week"] { --halo: var(--corn-history-week); }
51
+ .hx-history-halo[data-band="month"], .hx-history-swatch[data-band="month"] { --halo: var(--corn-history-month); }
52
+ .hx-history-halo[data-band="old"], .hx-history-swatch[data-band="old"] { --halo: var(--corn-history-old); }
53
+ .hx-history-swatch { --halo: var(--corn-text-3); display: inline-block; width: 14px; height: 14px; flex: none; box-sizing: border-box; border-radius: 50%; border: var(--corn-border-strong) solid var(--halo); }
54
+ .hx-history-swatch--wide { border-width: calc(var(--corn-border-strong) * 2); }
55
+ /* The bar while a spec is picked: what it reached, and the way back to the whole map */
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
+ .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
+ }
@@ -93,6 +93,7 @@ export function layerRows(inst) {
93
93
  const project = state.projectLayers.filter((l) => held.has(l.key)).map((l) => ({ key: l.key, label: l.label, desc: l.desc || '', project: true, ...projectDot(l) }));
94
94
  // A starting row a project layer has taken every node from goes (spec 0009 D7, example 3); with no project layer, every starting row stays, as it always was
95
95
  const starting = LAYER_DEFS.filter((l) => !l.overlay && (held.has(l.key) || !left.has(l.key))).map(dotted);
96
+ const halos = state.historyRow && state.historyRow(); // the History layer's row, when the config has history on (history.js): an overlay, off to start
96
97
  const badges = state.workRow && state.workRow(); // the Work layer's row, when the page has a forge and somebody is signed in (work-view.js): an overlay, off to start
97
98
  const known = new Set([...LAYER_DEFS.map((l) => l.key), ...state.projectLayers.map((l) => l.key)]);
98
99
  const extra = [];
@@ -101,7 +102,7 @@ export function layerRows(inst) {
101
102
  known.add(key);
102
103
  extra.push({ key, label: key.charAt(0).toUpperCase() + key.slice(1), color: rowColor(inst, { type: key, group: key }, NO_COLOR), desc: `Nodes of the type ${key}` });
103
104
  });
104
- return { layers: [...orderRows(project, starting, state.layerOrder), ...extra], overlays: [...LAYER_DEFS.filter((l) => l.overlay).map(dotted), ...(badges ? [badges] : [])] };
105
+ return { layers: [...orderRows(project, starting, state.layerOrder), ...extra], overlays: [...LAYER_DEFS.filter((l) => l.overlay).map(dotted), ...(badges ? [badges] : []), ...(halos ? [halos] : [])] };
105
106
  }
106
107
 
107
108
  // ---------------------------------------------------------------------------
@@ -141,6 +142,7 @@ export function setProjectLayers(inst, raw) {
141
142
  for (const l of LAYER_DEFS) defaults[l.key] = !STARTS_OFF.has(l.key);
142
143
  for (const l of cfg.add) defaults[l.key] = true;
143
144
  defaults['work-badges'] = false;
145
+ defaults['history-halos'] = false; // the History layer (history-model.js HISTORY_LAYER)
144
146
  for (const k of cfg.off) defaults[k] = false;
145
147
  state.layerDefaults = defaults;
146
148
  const mem = memoryOf(inst);
@@ -10,6 +10,15 @@
10
10
  * trailHtml(commit, ctx) a commit's trail: `Spec 0012 → Issue #283 → PR #284 → 0281cba`, a gap dashed (`no spec`, `no issue`)
11
11
  * historySectionHtml(node, ctx) the node panel's History section
12
12
  * specReach(history, spec) the nodes a spec's commits touched, and how many commits named it
13
+ * heatOf(history, at) the History layer (spec 0014 D3): per node, how often it changed and how lately, as of a commit
14
+ * haloWidth(count, max) a halo's width on screen (px) for how often its node changed
15
+ * historyRowOf(status, heat) the Layers menu's row under Overlays
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
13
22
  */
14
23
 
15
24
  import { escapeHtml as esc } from '../core/text.js';
@@ -153,7 +162,7 @@ export function historySectionHtml(node, ctx) {
153
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>` : '';
154
163
  const shown = ctx.all ? t.commits : t.commits.slice(0, HISTORY_CAP);
155
164
  const rows = shown.map((c) => `<li class="hx-history-commit" data-corn="row">`
156
- + `<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>`
157
166
  + `<div class="hx-history-subject">${esc(c.subject)}</div>`
158
167
  + trailHtml(c, ctx)
159
168
  + '</li>');
@@ -176,3 +185,135 @@ export function specReach(history, spec) {
176
185
  }
177
186
  return { nodes, commits };
178
187
  }
188
+
189
+ /** The History layer's key in the Layers menu and `state.activeLayers` (spec 0014 D3): an overlay, off to start */
190
+ export const HISTORY_LAYER = 'history-halos';
191
+ /** The most halos drawn at once */
192
+ export const MAX_HALOS = 600;
193
+ /** How lately a node changed, as of the timeline's commit: within a week, within a month (30 days), or before */
194
+ export const HALO_BANDS = Object.freeze(['week', 'month', 'old']);
195
+ const DAY_MS = 86_400_000;
196
+ const bandOf = (days) => (days <= 7 ? 'week' : days <= 30 ? 'month' : 'old');
197
+
198
+ /**
199
+ * Each node's heat as of a commit: how many commits up to it changed the node, the last of them, and how many days before the commit that was.
200
+ * The age is counted from the commit's own date, not today's, so a replay reads as it did then.
201
+ * @param {{ commits: { date: string }[], nodes: Record<string, { commits: number[] }> } | null} history
202
+ * @param {number | null} [at] a commit's index; the newest when it is left out or out of range
203
+ * @returns {{ at: number, nodes: Map<string, { count: number, last: number, days: number, band: 'week' | 'month' | 'old' }>, max: number }}
204
+ */
205
+ export function heatOf(history, at = null) {
206
+ const commits = (history && history.commits) || [];
207
+ const nodes = new Map();
208
+ if (!commits.length) return { at: -1, nodes, max: 0 };
209
+ const i = Number.isInteger(at) && at >= 0 && at < commits.length ? at : commits.length - 1;
210
+ const now = Date.parse(commits[i].date);
211
+ let max = 0;
212
+ for (const [id, e] of Object.entries(history.nodes || {})) {
213
+ let count = 0;
214
+ let last = -1;
215
+ for (const k of (e && e.commits) || []) { if (k > i) break; count++; last = k; }
216
+ if (!count) continue;
217
+ const days = Math.max(0, (now - Date.parse(commits[last].date)) / DAY_MS);
218
+ nodes.set(id, { count, last, days, band: bandOf(days) });
219
+ if (count > max) max = count;
220
+ }
221
+ return { at: i, nodes, max };
222
+ }
223
+
224
+ /** A halo's width on screen (px): from 1.5 for a node changed once to 6 for the most changed on the map (by the square root, so a few busy nodes do not flatten the rest) */
225
+ export const haloWidth = (count, max) => (max > 0 && count > 0 ? Math.round((1.5 + 4.5 * Math.sqrt(Math.min(count, max) / max)) * 10) / 10 : 0);
226
+
227
+ /**
228
+ * The Layers menu's row for the History layer: its count in words while the history is read.
229
+ * @param {'idle' | 'loading' | 'ready' | 'error'} status
230
+ * @param {{ nodes: Map<string, unknown> } | null} heat
231
+ * @param {string} color the dot's colour
232
+ */
233
+ export function historyRowOf(status, heat, color) {
234
+ const n = heat ? heat.nodes.size : 0;
235
+ const countText = status === 'ready' ? `${n} ${n === 1 ? 'node' : 'nodes'}` : status === 'loading' ? 'reading…' : status === 'error' ? 'not read' : 'not read yet';
236
+ return { key: HISTORY_LAYER, label: 'History', color, overlay: true, countText, desc: 'A halo round each node the history changed: the wider, the more often; pink this week, violet this month, grey before. Picking a spec in a node\'s History lights what it reached.' };
237
+ }
238
+
239
+ /**
240
+ * The bar on the map while a spec is picked (spec 0014 D3): the spec, a link to its file on the forge when there is one, what it reached, and how to show the whole map again.
241
+ * @param {{ spec: string, nodes: Set<string>, commits: number }} pick
242
+ * @param {{ links: ReturnType<typeof forgeLinks>, specs: ReturnType<typeof specFiles> }} ctx
243
+ */
244
+ export function specBarHtml(pick, { links, specs }) {
245
+ const spec = specs && specs.get(pick.spec);
246
+ const href = spec && links ? links.file(spec.file) : null;
247
+ const name = href ? `<a class="hx-link" data-corn="text-link" href="${esc(href)}" target="_blank" rel="noreferrer">Spec ${esc(pick.spec)}</a>` : `<b>Spec ${esc(pick.spec)}</b>`;
248
+ const label = spec ? ` · ${esc(spec.label)}` : '';
249
+ const c = pick.commits;
250
+ const n = pick.nodes.size;
251
+ return `<span class="hx-history-bar-text">${name}${label}: ${c} ${c === 1 ? 'commit' : 'commits'}, ${n} ${n === 1 ? 'node' : 'nodes'}</span>`
252
+ + `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn-kind="quiet" data-history-unpick>Show the whole map</button>`;
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
+ }
@@ -3,7 +3,12 @@
3
3
  *
4
4
  * A node's history on an instance (spec 0014 D2): reads `GET /api/history` (core/history.js) once, the first time the node panel asks, and
5
5
  * answers the panel's History section; picking a spec lights every node its commits touched (`state.historyPick`, which scene.js dims around).
6
- * Nothing is fetched while the config says `history: false`, and the panel then has no History section.
6
+ * Nothing is fetched while the config says `history: false`, and the panel then has no History section, the Layers menu no History row.
7
+ *
8
+ * The History layer (spec 0014 D3): a row under Overlays, off to start and remembered like the others. While it is on, each node the history changed
9
+ * wears a halo, its width how often and its colour how lately (as of the timeline's commit, `state.historyAt`, else the newest). A DOM layer over the map,
10
+ * like the runs' marks, decoration for the eye (`aria-hidden`): the words are the node panel's History section. While a spec is picked a bar on the map
11
+ * names it, what it reached, and how to show the whole map again.
7
12
  *
8
13
  * initHistory(inst, config) once, with the client config (`history`, `forge`); returns how to stop
9
14
  *
@@ -12,11 +17,17 @@
12
17
  * history:pick spec | null (emit) light what that spec reached, or nothing; picking the lit spec again ends it
13
18
  * history:all (none) (emit) the section lists every commit, not only the newest
14
19
  * history:changed (none) (emitted) the read ended, or a pick changed: the open panel draws its History section again
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
15
23
  */
16
24
 
17
25
  import { credentialed } from './engine/connection.js';
18
26
  import { announce } from './engine/keyboard.js';
19
- import { forgeLinks, historySectionHtml, specFiles, specReach } from './history-model.js';
27
+ import { onLayersChange, redrawLayers } from './engine/layers.js';
28
+ import { layerOn } from './layer-model.js';
29
+ import { createReplay } from './history-replay.js';
30
+ import { HISTORY_LAYER, MAX_HALOS, forgeLinks, haloWidth, heatOf, historyRowOf, historySectionHtml, specBarHtml, specFiles, specReach } from './history-model.js';
20
31
 
21
32
  /** Where the server answers the history (server/server.js) */
22
33
  export const HISTORY_PATH = '/api/history';
@@ -27,13 +38,113 @@ export const HISTORY_PATH = '/api/history';
27
38
  * @returns {() => void}
28
39
  */
29
40
  export function initHistory(inst, config) {
41
+ /** The dot of the Layers menu's row: this week's halo colour, as the theme has it */
42
+ const haloColor = () => {
43
+ const read = inst.tokenReader();
44
+ return (read && read('--corn-history-week').trim()) || 'currentColor';
45
+ };
30
46
  const { state } = inst;
31
47
  const on = !!(config && config.history === true);
32
48
  const mem = { status: on ? 'idle' : 'off', history: null, error: '', all: false, node: null, links: forgeLinks(config && config.forge), specs: null };
33
49
  const stops = [];
50
+ const halos = new Map(); // the halo elements by node id, kept between frames
51
+ let heat = null; // heatOf, for the history and the commit it was worked out for
52
+ let placed = '';
53
+ let layerEl = null;
54
+ let barEl = null;
55
+
56
+ const stage = () => (state.canvas && state.canvas.parentElement) || null;
57
+ // Off until the layers have their defaults (a layer with no entry reads as on), and never in the Work view
58
+ const haloOn = () => mem.status !== 'off' && !state.workRows && Object.hasOwn(state.layerDefaults || {}, HISTORY_LAYER) && layerOn(state, HISTORY_LAYER);
59
+ const heatNow = () => {
60
+ if (mem.status !== 'ready') return null;
61
+ const at = Number.isInteger(state.historyAt) ? state.historyAt : null;
62
+ if (!heat || heat.of !== mem.history || heat.asked !== at) heat = { of: mem.history, asked: at, ...heatOf(mem.history, at) };
63
+ return heat;
64
+ };
65
+
66
+ function clearHalos() {
67
+ for (const el of halos.values()) el.remove();
68
+ halos.clear();
69
+ placed = '';
70
+ if (layerEl) layerEl.hidden = true;
71
+ }
72
+
73
+ /** Puts a halo on each node the history changed, at the camera: only their place changes on a pan */
74
+ function syncHalos(scene, camera) {
75
+ const h = haloOn() ? heatNow() : null;
76
+ if (!h || !h.nodes.size) { if (halos.size || (layerEl && !layerEl.hidden)) clearHalos(); return; }
77
+ const key = `${scene.version}|${camera.x}|${camera.y}|${camera.zoom}|${h.at}`;
78
+ if (key === placed && layerEl && layerEl.isConnected) return;
79
+ const host = stage();
80
+ if (!host) return;
81
+ if (!layerEl || !layerEl.isConnected) {
82
+ layerEl = inst.doc.createElement('div');
83
+ layerEl.className = 'hx-history-halos';
84
+ layerEl.setAttribute('aria-hidden', 'true');
85
+ host.append(layerEl);
86
+ halos.clear();
87
+ }
88
+ placed = key;
89
+ layerEl.hidden = false;
90
+ const seen = new Set();
91
+ for (const node of scene.nodes) {
92
+ if (seen.size >= MAX_HALOS) break;
93
+ const it = h.nodes.get(node.id);
94
+ if (!it || !(node.alpha > 0.2)) continue;
95
+ seen.add(node.id);
96
+ let el = halos.get(node.id);
97
+ if (!el) {
98
+ el = inst.doc.createElement('span');
99
+ el.className = 'hx-history-halo';
100
+ el.dataset.node = node.id;
101
+ layerEl.append(el);
102
+ halos.set(node.id, el);
103
+ }
104
+ const w = haloWidth(it.count, h.max);
105
+ el.dataset.band = it.band;
106
+ el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
107
+ el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
108
+ el.style.setProperty('--r', `${(Math.max(6, node.r * camera.zoom) + 3 + w / 2).toFixed(1)}px`);
109
+ el.style.setProperty('--w', `${w}px`);
110
+ }
111
+ for (const [id, el] of halos) if (!seen.has(id)) { el.remove(); halos.delete(id); }
112
+ }
34
113
 
35
- async function load() {
36
- if (mem.status !== 'idle') return;
114
+ /** The bar on the map while a spec is picked */
115
+ function paintBar() {
116
+ const pickNow = state.historyPick;
117
+ if (!pickNow) { if (barEl) { barEl.remove(); barEl = null; } return; }
118
+ const host = stage();
119
+ if (!host) return;
120
+ if (!barEl || !barEl.isConnected) {
121
+ barEl = inst.doc.createElement('div');
122
+ barEl.className = 'hx-history-bar glass';
123
+ barEl.setAttribute('role', 'group');
124
+ barEl.setAttribute('aria-label', 'Picked spec');
125
+ barEl.addEventListener('click', (e) => { if (e.target.closest('[data-history-unpick]')) pick(null); });
126
+ host.append(barEl);
127
+ }
128
+ if (!mem.specs) mem.specs = specFiles(state.nodes);
129
+ barEl.innerHTML = specBarHtml(pickNow, { links: mem.links, specs: mem.specs });
130
+ }
131
+
132
+ /** The layer went on or off, or the read ended: the row's count, the legend and the halos follow */
133
+ function layerChanged() {
134
+ const on = haloOn();
135
+ if (on && mem.status === 'idle') load();
136
+ inst.emit('history:legend', { active: on && mem.status === 'ready' });
137
+ if (!on) clearHalos();
138
+ placed = '';
139
+ if (inst.map) inst.map.render();
140
+ }
141
+
142
+ let reading = null;
143
+ function load() {
144
+ if (mem.status === 'idle') reading = read();
145
+ return reading || Promise.resolve();
146
+ }
147
+ async function read() {
37
148
  mem.status = 'loading';
38
149
  try {
39
150
  const res = await credentialed(inst)(HISTORY_PATH);
@@ -46,6 +157,8 @@ export function initHistory(inst, config) {
46
157
  mem.error = inst.offline() ? 'You are offline, so the history could not be read.' : String(err && err.message ? err.message : err);
47
158
  }
48
159
  inst.emit('history:changed');
160
+ redrawLayers(inst); // the row's count
161
+ layerChanged();
49
162
  }
50
163
 
51
164
  function pick(spec) {
@@ -55,14 +168,41 @@ export function initHistory(inst, config) {
55
168
  announce(inst, 'Showing the whole map again');
56
169
  } else {
57
170
  const { nodes, commits } = specReach(mem.history, spec);
58
- state.historyPick = { spec, nodes };
171
+ state.historyPick = { spec, nodes, commits };
59
172
  announce(inst, `Spec ${spec}: ${commits} ${commits === 1 ? 'commit' : 'commits'} reached ${nodes.size} ${nodes.size === 1 ? 'node' : 'nodes'}; the rest is dimmed`);
60
173
  }
61
174
  inst.touchScene();
175
+ paintBar();
62
176
  if (inst.map) inst.map.render();
63
177
  inst.emit('history:changed');
64
178
  }
65
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
+
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; });
198
+ // The Layers menu's row under Overlays (engine/layers.js `layerRows`), in the colour of this week's halo
199
+ state.historyRow = () => historyRowOf(mem.status, mem.status === 'ready' ? heatNow() : null, haloColor());
200
+ stops.push(onLayersChange(inst, layerChanged));
201
+ if (inst.map) stops.push(inst.map.onPaint((scene, camera) => syncHalos(scene, camera)));
202
+ stops.push(inst.on('history:at', () => { placed = ''; if (inst.map) inst.map.render(); redrawLayers(inst); }));
203
+ if (haloOn()) layerChanged();
204
+ }
205
+
66
206
  stops.push(inst.on('history:section', (node) => {
67
207
  if (mem.status === 'off' || !node || typeof node.id !== 'string') return undefined;
68
208
  if (mem.node !== node.id) { mem.node = node.id; mem.all = false; } // "Show all" is for the node it was pressed on
@@ -74,5 +214,12 @@ export function initHistory(inst, config) {
74
214
  // A selection cleared (the bare map, Escape, Close) ends a pick too: nothing on screen would say why the map is dim
75
215
  stops.push(inst.on('selection', () => { if (!state.selectedNode && state.historyPick) pick(null); }));
76
216
  stops.push(inst.on('history:all', () => { mem.all = true; inst.emit('history:changed'); }));
77
- return () => { stops.forEach((s) => s()); if (state.historyPick) { state.historyPick = null; inst.touchScene(); } };
217
+ return () => {
218
+ stops.forEach((s) => s());
219
+ clearHalos();
220
+ if (layerEl) layerEl.remove();
221
+ if (barEl) barEl.remove();
222
+ state.historyRow = null;
223
+ if (state.historyPick) { state.historyPick = null; inst.touchScene(); }
224
+ };
78
225
  }
@@ -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">
@@ -87,6 +90,13 @@
87
90
  <div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--flight" aria-hidden="true"></span><span>In flight: a pulsing ring (still under reduced motion)</span></div>
88
91
  <div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--collision" aria-hidden="true"></span><span>Collision: dashed ring, ⚠ and the words, where two open runs change one node</span></div>
89
92
  </div>
93
+ <div class="hx-menu-section" data-corn="menu-section" part="menu-section" hidden>
94
+ <div class="hx-menu-title" data-corn="menu-title" part="menu-title"><span>History</span></div>
95
+ <div class="hx-legend-row"><span class="hx-history-swatch hx-history-swatch--wide" aria-hidden="true"></span><span>A wider halo: changed more often</span></div>
96
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="week" aria-hidden="true"></span><span>Changed this week</span></div>
97
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="month" aria-hidden="true"></span><span>Changed this month</span></div>
98
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="old" aria-hidden="true"></span><span>Not for over a month (as of the timeline's commit)</span></div>
99
+ </div>
90
100
  <div class="hx-menu-section" data-corn="menu-section" part="menu-section" hidden>
91
101
  <div class="hx-menu-title" data-corn="menu-title" part="menu-title"><span>Proposal marks</span></div>
92
102
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added" data-corn="mark-dot" part="mark-dot" data-corn-state="added"></span><span>Added: dashed ring</span></div>
@@ -45,6 +45,9 @@ export function createState() {
45
45
  searchQuery: '',
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
+ 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 }
50
+ historyRow: null, // the History layer's row in the Layers menu (history.js), while the config has history on
48
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 */
49
52
  searchCurrent: null,
50
53
  /** The id of the node the pointer is on (input.js): a node with no label is named by a chip while it is */
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
  };
@@ -61,6 +61,13 @@ export const markup = () => ({
61
61
  <div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--flight" aria-hidden="true"></span><span>In flight: a pulsing ring (still under reduced motion)</span></div>
62
62
  <div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--collision" aria-hidden="true"></span><span>Collision: dashed ring, ⚠ and the words, where two open runs change one node</span></div>
63
63
  </div>
64
+ <div id="history-legend" class="hx-menu-section" data-corn="menu-section" hidden>
65
+ <div class="hx-menu-title" data-corn="menu-title"><span>History</span></div>
66
+ <div class="hx-legend-row"><span class="hx-history-swatch hx-history-swatch--wide" aria-hidden="true"></span><span>A wider halo: changed more often</span></div>
67
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="week" aria-hidden="true"></span><span>Changed this week</span></div>
68
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="month" aria-hidden="true"></span><span>Changed this month</span></div>
69
+ <div class="hx-legend-row"><span class="hx-history-swatch" data-band="old" aria-hidden="true"></span><span>Not for over a month (as of the timeline's commit)</span></div>
70
+ </div>
64
71
  <div id="proposal-legend" class="hx-menu-section" data-corn="menu-section" hidden>
65
72
  <div class="hx-menu-title" data-corn="menu-title"><span>Proposal marks</span></div>
66
73
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added" data-corn="mark-dot" data-corn-state="added"></span><span>Added: dashed ring</span></div>
@@ -316,7 +323,8 @@ export function mount(root, inst, options = {}) {
316
323
  scope.on('layers:redraw', renderLayerToggles);
317
324
  scope.on('theme', renderLayerToggles); // the dots and the legends are drawn in the theme's colours
318
325
  scope.on('view', syncView);
319
- scope.on('runs:map', ({ active }) => { const legend = own('runs-legend'); if (legend) legend.hidden = !active; }); // runs are on the map (the Work list): the legend says what each mark is
326
+ scope.on('runs:map', ({ active }) => { const legend = own('runs-legend'); if (legend) legend.hidden = !active; });
327
+ scope.on('history:legend', ({ active }) => { const legend = own('history-legend'); if (legend) legend.hidden = !active; }); // the History layer is drawn (history.js): what a halo's width and colour say // runs are on the map (the Work list): the legend says what each mark is
320
328
  // The marks legend is there while a proposal is open (the proposal's bar says so: engine/proposal.js)
321
329
  const showLegend = (open) => { const legend = own('proposal-legend'); if (legend) legend.hidden = !open; };
322
330
  scope.on('proposal:draw', ({ open }) => showLegend(open));
@@ -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);
@@ -203,6 +203,10 @@
203
203
  --corn-work-edge-work: auto;
204
204
  --corn-work-edge-code: auto;
205
205
  --corn-work-edge-adds: auto;
206
+ /* The History layer (spec 0014 D3): a node's halo, by how lately it changed as of the timeline's commit */
207
+ --corn-history-week: #f472b6;
208
+ --corn-history-month: #a78bfa;
209
+ --corn-history-old: #94a3b8;
206
210
  /* Node fill by group */
207
211
  --corn-map-group-app: auto;
208
212
  --corn-map-group-pkg: auto;
@@ -256,6 +260,9 @@
256
260
  --corn-info: #03679e;
257
261
 
258
262
  --corn-added: #197c6f;
263
+ --corn-history-week: #be185d;
264
+ --corn-history-month: #6d28d9;
265
+ --corn-history-old: #64748b;
259
266
  --corn-changed: #8f6703;
260
267
  --corn-removed: #e20b0b;
261
268
  --corn-edit: #6839f6;
@@ -305,6 +312,9 @@
305
312
  --corn-info: #03679e;
306
313
 
307
314
  --corn-added: #197c6f;
315
+ --corn-history-week: #be185d;
316
+ --corn-history-month: #6d28d9;
317
+ --corn-history-old: #64748b;
308
318
  --corn-changed: #8f6703;
309
319
  --corn-removed: #e20b0b;
310
320
  --corn-edit: #6839f6;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.60.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)",