@kgdiff/viewer 0.0.0-stage → 0.2.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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/compute-loader.d.ts +13 -0
  4. package/dist/compute-loader.d.ts.map +1 -0
  5. package/dist/compute-loader.js +46 -0
  6. package/dist/compute-loader.js.map +1 -0
  7. package/dist/compute.d.ts +8 -0
  8. package/dist/compute.d.ts.map +1 -0
  9. package/dist/compute.js +8 -0
  10. package/dist/compute.js.map +1 -0
  11. package/dist/controller.d.ts +199 -0
  12. package/dist/controller.d.ts.map +1 -0
  13. package/dist/controller.js +1254 -0
  14. package/dist/controller.js.map +1 -0
  15. package/dist/dom.d.ts +32 -0
  16. package/dist/dom.d.ts.map +1 -0
  17. package/dist/dom.js +105 -0
  18. package/dist/dom.js.map +1 -0
  19. package/dist/element.d.ts +43 -0
  20. package/dist/element.d.ts.map +1 -0
  21. package/dist/element.js +656 -0
  22. package/dist/element.js.map +1 -0
  23. package/dist/framing.d.ts +45 -0
  24. package/dist/framing.d.ts.map +1 -0
  25. package/dist/framing.js +107 -0
  26. package/dist/framing.js.map +1 -0
  27. package/dist/hash-sync.d.ts +18 -0
  28. package/dist/hash-sync.d.ts.map +1 -0
  29. package/dist/hash-sync.js +45 -0
  30. package/dist/hash-sync.js.map +1 -0
  31. package/dist/i18n.d.ts +222 -0
  32. package/dist/i18n.d.ts.map +1 -0
  33. package/dist/i18n.js +434 -0
  34. package/dist/i18n.js.map +1 -0
  35. package/dist/icons.d.ts +37 -0
  36. package/dist/icons.d.ts.map +1 -0
  37. package/dist/icons.js +36 -0
  38. package/dist/icons.js.map +1 -0
  39. package/dist/index.d.ts +151 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +41 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/keyboard.d.ts +64 -0
  44. package/dist/keyboard.d.ts.map +1 -0
  45. package/dist/keyboard.js +95 -0
  46. package/dist/keyboard.js.map +1 -0
  47. package/dist/list-model.d.ts +35 -0
  48. package/dist/list-model.d.ts.map +1 -0
  49. package/dist/list-model.js +70 -0
  50. package/dist/list-model.js.map +1 -0
  51. package/dist/payload.d.ts +10 -0
  52. package/dist/payload.d.ts.map +1 -0
  53. package/dist/payload.js +138 -0
  54. package/dist/payload.js.map +1 -0
  55. package/dist/pipeline.d.ts +31 -0
  56. package/dist/pipeline.d.ts.map +1 -0
  57. package/dist/pipeline.js +122 -0
  58. package/dist/pipeline.js.map +1 -0
  59. package/dist/prefs.d.ts +18 -0
  60. package/dist/prefs.d.ts.map +1 -0
  61. package/dist/prefs.js +38 -0
  62. package/dist/prefs.js.map +1 -0
  63. package/dist/registry.d.ts +3 -0
  64. package/dist/registry.d.ts.map +1 -0
  65. package/dist/registry.js +3 -0
  66. package/dist/registry.js.map +1 -0
  67. package/dist/renderer-port.d.ts +14 -0
  68. package/dist/renderer-port.d.ts.map +1 -0
  69. package/dist/renderer-port.js +16 -0
  70. package/dist/renderer-port.js.map +1 -0
  71. package/dist/replay.d.ts +55 -0
  72. package/dist/replay.d.ts.map +1 -0
  73. package/dist/replay.js +147 -0
  74. package/dist/replay.js.map +1 -0
  75. package/dist/review-store.d.ts +30 -0
  76. package/dist/review-store.d.ts.map +1 -0
  77. package/dist/review-store.js +120 -0
  78. package/dist/review-store.js.map +1 -0
  79. package/dist/search.d.ts +25 -0
  80. package/dist/search.d.ts.map +1 -0
  81. package/dist/search.js +90 -0
  82. package/dist/search.js.map +1 -0
  83. package/dist/standalone/kgdiff-viewer-compute.js +1 -0
  84. package/dist/standalone/kgdiff-viewer.js +5 -0
  85. package/dist/standalone-compute.d.ts +2 -0
  86. package/dist/standalone-compute.d.ts.map +1 -0
  87. package/dist/standalone-compute.js +8 -0
  88. package/dist/standalone-compute.js.map +1 -0
  89. package/dist/standalone.d.ts +2 -0
  90. package/dist/standalone.d.ts.map +1 -0
  91. package/dist/standalone.js +18 -0
  92. package/dist/standalone.js.map +1 -0
  93. package/dist/styles.d.ts +11 -0
  94. package/dist/styles.d.ts.map +1 -0
  95. package/dist/styles.js +622 -0
  96. package/dist/styles.js.map +1 -0
  97. package/dist/text-diff.d.ts +44 -0
  98. package/dist/text-diff.d.ts.map +1 -0
  99. package/dist/text-diff.js +261 -0
  100. package/dist/text-diff.js.map +1 -0
  101. package/dist/ui/context.d.ts +32 -0
  102. package/dist/ui/context.d.ts.map +1 -0
  103. package/dist/ui/context.js +49 -0
  104. package/dist/ui/context.js.map +1 -0
  105. package/dist/ui/detail.d.ts +9 -0
  106. package/dist/ui/detail.d.ts.map +1 -0
  107. package/dist/ui/detail.js +609 -0
  108. package/dist/ui/detail.js.map +1 -0
  109. package/dist/ui/header.d.ts +14 -0
  110. package/dist/ui/header.d.ts.map +1 -0
  111. package/dist/ui/header.js +195 -0
  112. package/dist/ui/header.js.map +1 -0
  113. package/dist/ui/popovers.d.ts +20 -0
  114. package/dist/ui/popovers.d.ts.map +1 -0
  115. package/dist/ui/popovers.js +180 -0
  116. package/dist/ui/popovers.js.map +1 -0
  117. package/dist/ui/sidebar.d.ts +25 -0
  118. package/dist/ui/sidebar.d.ts.map +1 -0
  119. package/dist/ui/sidebar.js +609 -0
  120. package/dist/ui/sidebar.js.map +1 -0
  121. package/dist/ui/stage.d.ts +18 -0
  122. package/dist/ui/stage.d.ts.map +1 -0
  123. package/dist/ui/stage.js +664 -0
  124. package/dist/ui/stage.js.map +1 -0
  125. package/package.json +58 -3
  126. package/src/compute-loader.ts +58 -0
  127. package/src/compute.ts +7 -0
  128. package/src/controller.ts +1393 -0
  129. package/src/dom.ts +131 -0
  130. package/src/element.ts +697 -0
  131. package/src/framing.ts +150 -0
  132. package/src/hash-sync.ts +54 -0
  133. package/src/i18n.ts +467 -0
  134. package/src/icons.ts +48 -0
  135. package/src/index.ts +171 -0
  136. package/src/keyboard.ts +128 -0
  137. package/src/list-model.ts +86 -0
  138. package/src/payload.ts +165 -0
  139. package/src/pipeline.ts +179 -0
  140. package/src/prefs.ts +55 -0
  141. package/src/registry.ts +2 -0
  142. package/src/renderer-port.ts +31 -0
  143. package/src/replay.ts +163 -0
  144. package/src/review-store.ts +125 -0
  145. package/src/search.ts +113 -0
  146. package/src/standalone-compute.ts +8 -0
  147. package/src/standalone.ts +18 -0
  148. package/src/styles.ts +633 -0
  149. package/src/text-diff.ts +263 -0
  150. package/src/ui/context.ts +70 -0
  151. package/src/ui/detail.ts +929 -0
  152. package/src/ui/header.ts +278 -0
  153. package/src/ui/popovers.ts +251 -0
  154. package/src/ui/sidebar.ts +752 -0
  155. package/src/ui/stage.ts +853 -0
@@ -0,0 +1,664 @@
1
+ /**
2
+ * The canvas area and its floating chrome: replay caption and transport, swipe divider,
3
+ * changes-only context stepper, legend, zoom controls + minimap, hover tooltip and the
4
+ * loading / identical / error / empty states. Overlays never cover the current hunk: the
5
+ * element reserves their space through the renderer's safe area.
6
+ */
7
+ import { KgdiffError } from '@kgdiff/core';
8
+ import { attr, h, icon, iconButton, relabel, replace, replaceKeepingFocus, setText, } from '../dom.js';
9
+ import { FAMILIES } from '../styles.js';
10
+ import { sceneHunkGlyph } from './context.js';
11
+ const TICK_W = 1000;
12
+ /** Legend swatch: the node cue of each family (docs/visual-language.md §Meaning families). */
13
+ function swatch(family) {
14
+ const v = (name) => `var(--kg-${name})`;
15
+ const c = family === 'neutral' ? v('neutral') : v(family);
16
+ let body;
17
+ switch (family) {
18
+ case 'added':
19
+ body = `<circle cx="11" cy="11" r="8.5" fill="none" stroke="${c}" stroke-opacity=".35" stroke-width="2"/><circle cx="11" cy="11" r="5" fill="${c}"/>`;
20
+ break;
21
+ case 'removed':
22
+ body = `<circle cx="11" cy="11" r="5.25" fill="none" stroke="${c}" stroke-width="1.5" stroke-dasharray="3 2.5"/>`;
23
+ break;
24
+ case 'identity':
25
+ body = `<circle cx="11" cy="11" r="9.5" fill="none" stroke="${c}" stroke-opacity=".3" stroke-width="1.5"/><circle cx="11" cy="11" r="7.25" fill="none" stroke="${c}" stroke-width="1.5"/><circle cx="11" cy="11" r="4.25" fill="${c}"/>`;
26
+ break;
27
+ case 'content':
28
+ case 'structure':
29
+ body = `<circle cx="11" cy="11" r="7.75" fill="none" stroke="${c}" stroke-width="1.5"/><circle cx="11" cy="11" r="4.5" fill="${c}"/>`;
30
+ break;
31
+ default:
32
+ body = `<circle cx="11" cy="11" r="3.5" fill="${c}"/>`;
33
+ }
34
+ const tpl = document.createElement('template');
35
+ tpl.innerHTML = `<svg class="swatch" viewBox="0 0 22 22" aria-hidden="true" focusable="false">${body}</svg>`;
36
+ return tpl.content.firstElementChild;
37
+ }
38
+ export class Stage {
39
+ el;
40
+ canvasHost;
41
+ minimapHost;
42
+ #chrome;
43
+ #liveCanvasLabel;
44
+ // Replay
45
+ #caption;
46
+ #transport;
47
+ #playButton;
48
+ #prevButton;
49
+ #nextButton;
50
+ #scrubber;
51
+ #fill;
52
+ #knob;
53
+ #ticks;
54
+ #scrubTip;
55
+ #pos;
56
+ #speed;
57
+ #finished;
58
+ // Swipe
59
+ #swipe;
60
+ #divider;
61
+ #chipBefore;
62
+ #chipAfter;
63
+ // Changes
64
+ #stepper;
65
+ #hopButtons = [];
66
+ #expandButton;
67
+ // Chrome
68
+ #legend;
69
+ #legendHead;
70
+ #legendBody;
71
+ #zoomIn;
72
+ #zoomOut;
73
+ #fitButton;
74
+ #mapCluster;
75
+ tooltip;
76
+ #state;
77
+ #pointer = null;
78
+ #scrubbing = null;
79
+ #dragging = null;
80
+ #legendOpen = null;
81
+ #stateKey = '';
82
+ #ctx;
83
+ constructor(ctx) {
84
+ this.#ctx = ctx;
85
+ const c = ctx.controller;
86
+ this.canvasHost = h('div', { class: 'stage' });
87
+ this.#liveCanvasLabel = h('div', { class: 'sr-only' });
88
+ // Replay caption + transport
89
+ this.#caption = h('div', {
90
+ class: 'caption card',
91
+ 'aria-hidden': 'true',
92
+ 'data-empty': 'true',
93
+ });
94
+ this.#prevButton = iconButton('skip-back', '', () => c.stepReplay(-1), { class: 'icon-btn' });
95
+ this.#playButton = iconButton('play', '', () => c.togglePlay(), { class: 'icon-btn play' });
96
+ this.#nextButton = iconButton('skip-forward', '', () => c.stepReplay(1), { class: 'icon-btn' });
97
+ this.#fill = h('div', { class: 'fill' });
98
+ this.#knob = h('div', { class: 'knob' });
99
+ this.#ticks = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
100
+ this.#ticks.setAttribute('class', 'ticks');
101
+ this.#ticks.setAttribute('viewBox', `0 0 ${TICK_W} 14`);
102
+ this.#ticks.setAttribute('preserveAspectRatio', 'none');
103
+ this.#ticks.setAttribute('aria-hidden', 'true');
104
+ this.#scrubTip = h('div', { class: 'scrub-tip card', hidden: true });
105
+ this.#scrubber = h('div', {
106
+ class: 'scrubber',
107
+ role: 'slider',
108
+ tabindex: '0',
109
+ 'aria-valuemin': '0',
110
+ }, h('div', { class: 'track' }, this.#fill), this.#ticks, this.#knob, this.#scrubTip);
111
+ this.#bindScrubber();
112
+ this.#pos = h('span', { class: 'pos', 'aria-hidden': 'true' });
113
+ this.#speed = h('button', {
114
+ type: 'button',
115
+ class: 'speed',
116
+ onclick: () => c.cycleSpeed(),
117
+ });
118
+ this.#transport = h('div', { class: 'transport card', role: 'toolbar' }, this.#prevButton, this.#playButton, this.#nextButton, this.#scrubber, this.#pos, this.#speed);
119
+ this.#finished = h('div', { class: 'finished card', role: 'status', hidden: true });
120
+ // Swipe
121
+ this.#chipBefore = h('div', { class: 'side-chip before chip card' });
122
+ this.#chipAfter = h('div', { class: 'side-chip after chip card' });
123
+ this.#divider = h('div', {
124
+ class: 'divider',
125
+ role: 'slider',
126
+ tabindex: '0',
127
+ 'aria-valuemin': '0',
128
+ 'aria-valuemax': '100',
129
+ 'aria-orientation': 'horizontal',
130
+ }, h('span', { class: 'handle', 'aria-hidden': 'true' }, icon('chevron-left'), icon('chevron-right')));
131
+ this.#bindDivider();
132
+ this.#swipe = h('div', { class: 'swipe', hidden: true }, this.#chipBefore, this.#chipAfter, this.#divider);
133
+ // Changes-only context stepper
134
+ const opts = h('span', { class: 'opts', role: 'radiogroup' });
135
+ for (let n = 0; n <= 2; n++) {
136
+ const b = h('button', {
137
+ type: 'button',
138
+ class: 'opt',
139
+ role: 'radio',
140
+ text: String(n),
141
+ onclick: () => c.setHops(n),
142
+ });
143
+ this.#hopButtons.push(b);
144
+ opts.appendChild(b);
145
+ }
146
+ opts.addEventListener('keydown', (e) => {
147
+ if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')
148
+ return;
149
+ e.preventDefault();
150
+ e.stopPropagation();
151
+ const next = Math.max(0, Math.min(2, c.hops + (e.key === 'ArrowRight' ? 1 : -1)));
152
+ c.setHops(next);
153
+ this.#hopButtons[next]?.focus();
154
+ });
155
+ this.#expandButton = h('button', { type: 'button', class: 'expand', onclick: () => c.expandNearest() }, icon('plus'), h('span', { class: 'n' }));
156
+ this.#stepper = h('div', { class: 'stepper card float top-left', hidden: true }, h('span', { class: 'label' }), opts, this.#expandButton);
157
+ // Legend
158
+ this.#legendHead = h('button', {
159
+ type: 'button',
160
+ class: 'legend-head',
161
+ onclick: () => this.#setLegend(!(this.#legendOpen ?? true)),
162
+ }, h('span', { class: 'lbl' }), icon('chevron-down'));
163
+ this.#legendBody = h('div', { class: 'legend-body', id: 'kg-legend' });
164
+ attr(this.#legendHead, 'aria-controls', 'kg-legend');
165
+ this.#legend = h('div', { class: 'legend card float bottom-left', 'data-open': 'true' }, this.#legendHead, this.#legendBody);
166
+ // Zoom + minimap
167
+ this.#zoomIn = iconButton('plus', '', () => c.zoom(1));
168
+ this.#zoomOut = iconButton('minus', '', () => c.zoom(-1));
169
+ this.#fitButton = iconButton('fit', '', () => void c.fit());
170
+ this.minimapHost = h('div', { class: 'minimap-host' });
171
+ this.#mapCluster = h('div', { class: 'map-cluster float bottom-right' }, h('div', { class: 'zoom-bar card', role: 'toolbar' }, this.#zoomIn, this.#zoomOut, this.#fitButton), this.minimapHost);
172
+ this.tooltip = h('div', { class: 'tooltip card', role: 'tooltip', 'data-open': 'false' });
173
+ this.#state = h('div', { class: 'state', hidden: true });
174
+ this.#chrome = h('div', { class: 'chrome' }, this.#swipe, this.#caption, this.#stepper, this.#legend, this.#mapCluster, this.#finished, this.#transport, this.tooltip);
175
+ this.el = h('main', { class: 'stage-wrap' }, this.canvasHost, this.#liveCanvasLabel, this.#chrome, this.#state);
176
+ this.el.addEventListener('pointermove', (e) => {
177
+ const r = this.el.getBoundingClientRect();
178
+ this.#pointer = { x: e.clientX - r.left, y: e.clientY - r.top };
179
+ if (this.tooltip.dataset.open === 'true')
180
+ this.#placeTooltip();
181
+ });
182
+ this.el.addEventListener('pointerleave', () => {
183
+ this.#pointer = null;
184
+ c.clearHover();
185
+ });
186
+ }
187
+ /**
188
+ * The canvas size and the floating chrome currently drawn over it (canvas-relative rects),
189
+ * for framing fits and flights around it.
190
+ */
191
+ chromeLayout() {
192
+ const r = this.el.getBoundingClientRect();
193
+ const obstacles = [];
194
+ const parts = [
195
+ this.#legend,
196
+ this.#mapCluster,
197
+ this.#transport,
198
+ this.#finished,
199
+ this.#stepper,
200
+ this.#chipBefore,
201
+ this.#chipAfter,
202
+ ];
203
+ if (this.#caption.dataset.empty !== 'true')
204
+ parts.push(this.#caption);
205
+ for (const el of parts) {
206
+ if (el.hidden)
207
+ continue;
208
+ const b = el.getBoundingClientRect();
209
+ if (b.width <= 0 || b.height <= 0)
210
+ continue;
211
+ obstacles.push({ x: b.left - r.left, y: b.top - r.top, width: b.width, height: b.height });
212
+ }
213
+ return { width: r.width, height: r.height, obstacles };
214
+ }
215
+ /** Whether the stage is tall enough to show the legend expanded by default. */
216
+ #defaultLegendOpen() {
217
+ const hgt = this.el.clientHeight;
218
+ return hgt === 0 || hgt >= 560;
219
+ }
220
+ #setLegend(open) {
221
+ this.#legendOpen = open;
222
+ attr(this.#legend, 'data-open', String(open));
223
+ attr(this.#legendHead, 'aria-expanded', String(open));
224
+ }
225
+ update(topics) {
226
+ const c = this.#ctx.controller;
227
+ const tr = this.#ctx.tr();
228
+ const all = topics.has('status') || topics.has('data') || topics.has('locale');
229
+ if (all) {
230
+ this.#renderLabels(tr);
231
+ this.#renderState(tr);
232
+ this.#renderTicks();
233
+ this.#renderCanvasLabel(tr);
234
+ if (this.#legendOpen === null)
235
+ this.#setLegend(this.#defaultLegendOpen());
236
+ }
237
+ if (all || topics.has('mode') || topics.has('focus') || topics.has('selection')) {
238
+ this.#renderMode(tr);
239
+ }
240
+ if (all || topics.has('mode') || topics.has('replay'))
241
+ this.#renderReplay(tr);
242
+ if (all || topics.has('mode') || topics.has('swipe'))
243
+ this.#renderSwipe();
244
+ if (all || topics.has('hover') || topics.has('selection') || topics.has('focus')) {
245
+ this.#renderTooltip(tr);
246
+ }
247
+ if (topics.has('theme'))
248
+ this.#renderTicks();
249
+ const ready = c.status === 'ready';
250
+ this.#chrome.hidden = !ready;
251
+ }
252
+ #renderLabels(tr) {
253
+ relabel(this.#prevButton, `${tr.t('detail.prev')} (←)`);
254
+ relabel(this.#nextButton, `${tr.t('detail.next')} (→)`);
255
+ attr(this.#transport, 'aria-label', tr.t('replay.label'));
256
+ attr(this.#scrubber, 'aria-label', tr.t('replay.scrubber'));
257
+ setText(this.#chipBefore, tr.t('detail.before'));
258
+ setText(this.#chipAfter, tr.t('detail.after'));
259
+ attr(this.#divider, 'aria-label', tr.t('swipe.divider'));
260
+ setText(this.#stepper.querySelector('.label'), tr.t('focus.context'));
261
+ attr(this.#stepper.querySelector('.opts'), 'aria-label', tr.t('focus.hops'));
262
+ setText(this.#legendHead.querySelector('.lbl'), tr.t('legend.title'));
263
+ attr(this.#legendHead, 'aria-label', tr.t('legend.toggle'));
264
+ relabel(this.#zoomIn, `${tr.t('action.zoomIn')} (+)`);
265
+ relabel(this.#zoomOut, `${tr.t('action.zoomOut')} (−)`);
266
+ relabel(this.#fitButton, `${tr.t('action.fit')} (F)`);
267
+ attr(this.minimapHost, 'aria-label', tr.t('minimap.label'));
268
+ attr(this.minimapHost, 'title', tr.t('minimap.label'));
269
+ const fams = [...FAMILIES, 'neutral'];
270
+ replace(this.#legendBody, fams.map((f) => h('div', { class: 'legend-row', 'data-family': f, title: tr.t(`familyHint.${f}`) }, swatch(f), h('span', { class: 'name', text: tr.t(`family.${f}`) }))));
271
+ }
272
+ #renderCanvasLabel(tr) {
273
+ const stats = this.#ctx.controller.diff?.stats;
274
+ const canvas = this.canvasHost.querySelector('canvas');
275
+ if (!stats)
276
+ return;
277
+ const label = tr.t('aria.canvas', {
278
+ nb: stats.before.nodes,
279
+ eb: stats.before.edges,
280
+ na: stats.after.nodes,
281
+ ea: stats.after.edges,
282
+ changes: tr.plural('aria.changes', this.#ctx.controller.hunkCount),
283
+ });
284
+ if (canvas)
285
+ attr(canvas, 'aria-label', label);
286
+ setText(this.#liveCanvasLabel, '');
287
+ }
288
+ #renderMode(tr) {
289
+ const c = this.#ctx.controller;
290
+ const mode = c.mode;
291
+ this.#stepper.hidden = mode !== 'changes';
292
+ this.#hopButtons.forEach((b, n) => {
293
+ attr(b, 'aria-checked', String(n === c.hops));
294
+ b.tabIndex = n === c.hops ? 0 : -1;
295
+ attr(b, 'aria-label', `${tr.t('focus.hops')}: ${n}`);
296
+ });
297
+ const group = c.focus?.collapsed[c.nearestGroup()];
298
+ this.#expandButton.hidden = !group;
299
+ if (group) {
300
+ const usable = c.canExpand(c.nearestGroup()) || group.nodes.length > 0;
301
+ this.#expandButton.disabled = !usable;
302
+ setText(this.#expandButton.querySelector('.n'), tr.num(group.count));
303
+ relabel(this.#expandButton, `${usable ? tr.t('focus.expandNearest') : tr.t('focus.expandUnavailable')}: ${group.label} (E)`);
304
+ }
305
+ this.#transport.hidden = mode !== 'replay';
306
+ this.#caption.hidden = mode !== 'replay';
307
+ this.#swipe.hidden = mode !== 'swipe';
308
+ }
309
+ #renderReplay(tr) {
310
+ const c = this.#ctx.controller;
311
+ const clock = c.clock;
312
+ const scene = c.scene;
313
+ if (c.mode !== 'replay' || !clock || !scene) {
314
+ this.#finished.hidden = true;
315
+ return;
316
+ }
317
+ const p = clock.progress;
318
+ this.#fill.style.transform = `scaleX(${p})`;
319
+ this.#knob.style.left = `${p * 100}%`;
320
+ const position = clock.position();
321
+ const total = clock.total;
322
+ setText(this.#pos, tr.t('replay.position', { i: position, n: total }));
323
+ attr(this.#scrubber, 'aria-valuemax', String(Math.round(clock.duration)));
324
+ attr(this.#scrubber, 'aria-valuenow', String(Math.round(clock.t)));
325
+ attr(this.#scrubber, 'aria-valuetext', tr.t('replay.position', { i: position, n: total }));
326
+ const playing = clock.playing;
327
+ const playLabel = `${tr.t(playing ? 'replay.pause' : 'replay.play')} (Space)`;
328
+ if (this.#playButton.dataset.state !== String(playing)) {
329
+ this.#playButton.dataset.state = String(playing);
330
+ replace(this.#playButton, icon(playing ? 'pause' : 'play'));
331
+ }
332
+ relabel(this.#playButton, playLabel);
333
+ setText(this.#speed, `${clock.speed}×`);
334
+ relabel(this.#speed, tr.t('replay.speed', { s: `${clock.speed}×` }));
335
+ this.#prevButton.disabled = clock.t <= 0;
336
+ this.#nextButton.disabled = clock.t >= clock.duration;
337
+ // Caption: the playing hunk (or chapter), else the last one played.
338
+ let key = '';
339
+ let content = [];
340
+ if (clock.t <= 0) {
341
+ // Nothing has played yet: the canvas shows the before version.
342
+ }
343
+ else if (clock.timeline.mode === 'chapters') {
344
+ const target = clock.activeTarget();
345
+ const ch = target.index >= 0 ? clock.timeline.chapters[target.index] : undefined;
346
+ if (ch) {
347
+ key = `c${target.index}`;
348
+ const first = scene.hunks[ch.hunks[0] ?? -1];
349
+ content = [
350
+ h('span', {
351
+ class: 'glyph-box',
352
+ 'data-family': first?.family ?? 'neutral',
353
+ text: first ? sceneHunkGlyph(first) : '·',
354
+ }),
355
+ h('span', { class: 'text', text: tr.t(`phase.${ch.phase}`) }),
356
+ h('span', { class: 'count', text: tr.num(ch.hunks.length) }),
357
+ ];
358
+ }
359
+ }
360
+ else {
361
+ let hIndex = clock.activeHunk();
362
+ if (hIndex < 0 && position > 0)
363
+ hIndex = clock.timeline.windows[position - 1]?.hunk ?? -1;
364
+ const hunk = hIndex >= 0 ? scene.hunks[hIndex] : undefined;
365
+ if (hunk) {
366
+ key = `h${hIndex}|${position}`;
367
+ content = [
368
+ h('span', { class: 'glyph-box', 'data-family': hunk.family, text: sceneHunkGlyph(hunk) }),
369
+ h('span', { class: 'text', text: hunk.title, title: hunk.title }),
370
+ h('span', { class: 'count', text: `${position} / ${total}` }),
371
+ ];
372
+ }
373
+ }
374
+ if (this.#caption.dataset.key !== key) {
375
+ this.#caption.dataset.key = key;
376
+ attr(this.#caption, 'data-empty', String(key === ''));
377
+ replace(this.#caption, ...content);
378
+ }
379
+ const finished = clock.finished;
380
+ this.#finished.hidden = !finished;
381
+ if (finished && this.#finished.childElementCount === 0) {
382
+ replace(this.#finished, icon('check-circle'), h('span', { text: tr.t('replay.finished') }), h('button', { type: 'button', class: 'btn', onclick: () => c.restart() }, icon('restart'), tr.t('replay.restart')));
383
+ }
384
+ else if (!finished && this.#finished.childElementCount > 0) {
385
+ // Restart was pressed from the pill: keep focus in the transport.
386
+ replaceKeepingFocus(this.#ctx.root, this.#finished, this.#playButton);
387
+ }
388
+ }
389
+ #renderTicks() {
390
+ const c = this.#ctx.controller;
391
+ const clock = c.clock;
392
+ const scene = c.scene;
393
+ while (this.#ticks.firstChild)
394
+ this.#ticks.removeChild(this.#ticks.firstChild);
395
+ if (!clock || !scene || clock.duration <= 0)
396
+ return;
397
+ const paths = new Map();
398
+ for (const w of clock.timeline.windows) {
399
+ const fam = scene.hunks[w.hunk]?.family;
400
+ if (!fam)
401
+ continue;
402
+ const x = ((w.start / clock.duration) * TICK_W).toFixed(1);
403
+ let list = paths.get(fam);
404
+ if (!list) {
405
+ list = [];
406
+ paths.set(fam, list);
407
+ }
408
+ list.push(`M${x} 2V12`);
409
+ }
410
+ for (const [fam, d] of paths) {
411
+ const p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
412
+ p.setAttribute('d', d.join(''));
413
+ p.setAttribute('stroke', `var(--kg-${fam})`);
414
+ p.setAttribute('stroke-width', '2');
415
+ p.setAttribute('stroke-linecap', 'round');
416
+ p.setAttribute('vector-effect', 'non-scaling-stroke');
417
+ this.#ticks.appendChild(p);
418
+ }
419
+ }
420
+ #bindScrubber() {
421
+ const timeAt = (clientX) => {
422
+ const clock = this.#ctx.controller.clock;
423
+ const r = this.#scrubber.getBoundingClientRect();
424
+ if (!clock || r.width <= 0)
425
+ return 0;
426
+ return Math.max(0, Math.min(1, (clientX - r.left) / r.width)) * clock.duration;
427
+ };
428
+ this.#scrubber.addEventListener('pointerdown', (e) => {
429
+ this.#scrubbing = e.pointerId;
430
+ this.#scrubber.setPointerCapture?.(e.pointerId);
431
+ this.#ctx.controller.pause();
432
+ this.#ctx.controller.seek(timeAt(e.clientX));
433
+ });
434
+ this.#scrubber.addEventListener('pointermove', (e) => {
435
+ if (this.#scrubbing === e.pointerId)
436
+ this.#ctx.controller.seek(timeAt(e.clientX));
437
+ this.#showScrubTip(e.clientX, timeAt(e.clientX));
438
+ });
439
+ const end = (e) => {
440
+ if (this.#scrubbing === e.pointerId)
441
+ this.#scrubbing = null;
442
+ };
443
+ this.#scrubber.addEventListener('pointerup', end);
444
+ this.#scrubber.addEventListener('pointercancel', end);
445
+ this.#scrubber.addEventListener('pointerleave', () => {
446
+ this.#scrubTip.hidden = true;
447
+ });
448
+ this.#scrubber.addEventListener('keydown', (e) => {
449
+ const c = this.#ctx.controller;
450
+ if (e.key === 'Home')
451
+ c.seek(0);
452
+ else if (e.key === 'End')
453
+ c.seek(c.clock?.duration ?? 0);
454
+ else
455
+ return;
456
+ e.preventDefault();
457
+ e.stopPropagation();
458
+ });
459
+ }
460
+ #showScrubTip(clientX, t) {
461
+ const c = this.#ctx.controller;
462
+ const clock = c.clock;
463
+ const scene = c.scene;
464
+ if (!clock || !scene)
465
+ return;
466
+ // Nearest window start: the tick under the pointer.
467
+ let best = -1;
468
+ let bestD = Number.POSITIVE_INFINITY;
469
+ for (const w of clock.timeline.windows) {
470
+ const d = Math.abs(w.start - t);
471
+ if (d < bestD) {
472
+ bestD = d;
473
+ best = w.hunk;
474
+ }
475
+ }
476
+ const hunk = scene.hunks[best];
477
+ if (!hunk) {
478
+ this.#scrubTip.hidden = true;
479
+ return;
480
+ }
481
+ const r = this.#scrubber.getBoundingClientRect();
482
+ this.#scrubTip.hidden = false;
483
+ this.#scrubTip.style.left = `${clientX - r.left}px`;
484
+ if (this.#scrubTip.dataset.hunk !== hunk.id) {
485
+ this.#scrubTip.dataset.hunk = hunk.id;
486
+ replace(this.#scrubTip, h('span', { class: 'glyph-box', 'data-family': hunk.family, text: sceneHunkGlyph(hunk) }), h('span', { text: hunk.title }));
487
+ }
488
+ }
489
+ #renderSwipe() {
490
+ const c = this.#ctx.controller;
491
+ if (c.mode !== 'swipe')
492
+ return;
493
+ const pct = c.split * 100;
494
+ this.#divider.style.left = `${pct}%`;
495
+ attr(this.#divider, 'aria-valuenow', String(Math.round(pct)));
496
+ attr(this.#divider, 'aria-valuetext', `${Math.round(pct)}%`);
497
+ }
498
+ #bindDivider() {
499
+ const splitAt = (clientX) => {
500
+ const r = this.el.getBoundingClientRect();
501
+ return r.width > 0 ? (clientX - r.left) / r.width : 0.5;
502
+ };
503
+ this.#divider.addEventListener('pointerdown', (e) => {
504
+ e.preventDefault();
505
+ this.#dragging = e.pointerId;
506
+ this.#divider.setPointerCapture?.(e.pointerId);
507
+ this.#divider.classList.add('dragging');
508
+ this.#divider.focus({ preventScroll: true });
509
+ });
510
+ this.#divider.addEventListener('pointermove', (e) => {
511
+ if (this.#dragging === e.pointerId)
512
+ this.#ctx.controller.setSplit(splitAt(e.clientX));
513
+ });
514
+ const end = (e) => {
515
+ if (this.#dragging !== e.pointerId)
516
+ return;
517
+ this.#dragging = null;
518
+ this.#divider.classList.remove('dragging');
519
+ };
520
+ this.#divider.addEventListener('pointerup', end);
521
+ this.#divider.addEventListener('pointercancel', end);
522
+ this.#divider.addEventListener('dblclick', () => this.#ctx.controller.setSplit(0.5));
523
+ this.#divider.addEventListener('keydown', (e) => {
524
+ const c = this.#ctx.controller;
525
+ const to = {
526
+ Home: 0,
527
+ End: 1,
528
+ PageUp: c.split - 0.1,
529
+ PageDown: c.split + 0.1,
530
+ };
531
+ const next = to[e.key];
532
+ if (next === undefined)
533
+ return;
534
+ e.preventDefault();
535
+ e.stopPropagation();
536
+ c.setSplit(next);
537
+ });
538
+ }
539
+ // ─── Tooltip ─────────────────────────────────────────────────────────────
540
+ #renderTooltip(tr) {
541
+ const c = this.#ctx.controller;
542
+ const scene = c.scene;
543
+ const diff = c.diff;
544
+ if (!scene || !diff || this.#dragging !== null) {
545
+ attr(this.tooltip, 'data-open', 'false');
546
+ return;
547
+ }
548
+ const parts = [];
549
+ let family = 'neutral';
550
+ if (c.hoverNode >= 0) {
551
+ const sn = scene.nodes[c.hoverNode];
552
+ const un = sn ? diff.index.node(sn.id) : undefined;
553
+ if (!sn || !un)
554
+ return;
555
+ family = sn.family;
556
+ const hunk = sn.hunk >= 0 ? scene.hunks[sn.hunk] : undefined;
557
+ const rekey = un.facets.find((f) => f.kind === 'rekey');
558
+ const degree = Math.max(un.degree.before, un.degree.after);
559
+ parts.push(h('div', { class: 't-label', text: sn.label }), sn.labelBefore ? h('div', { class: 't-old', text: sn.labelBefore }) : null, h('div', {
560
+ class: 't-id',
561
+ text: rekey && rekey.kind === 'rekey' ? `${rekey.from} → ${rekey.to}` : sn.id,
562
+ }), h('div', { class: 't-status', 'data-family': family }, h('span', { class: 'dot' }), sn.status === 'unchanged'
563
+ ? tr.t('status.unchanged')
564
+ : `${tr.t(`status.${sn.status}`)} · ${tr.t(`family.${family}`)}`), h('div', {
565
+ class: 't-sum',
566
+ text: hunk ? hunk.title : tr.plural('tooltip.relations', degree),
567
+ }), h('div', { class: 't-hint', text: tr.t('tooltip.select') }));
568
+ }
569
+ else if (c.hoverEdge >= 0) {
570
+ const se = scene.edges[c.hoverEdge];
571
+ if (!se)
572
+ return;
573
+ family = se.family;
574
+ const s = scene.nodes[se.s]?.label ?? '';
575
+ const t = scene.nodes[se.t]?.label ?? '';
576
+ const hunk = se.hunk >= 0 ? scene.hunks[se.hunk] : undefined;
577
+ parts.push(h('div', { class: 't-label', text: `${s} —${se.label}→ ${t}` }), se.labelBefore ? h('div', { class: 't-old', text: se.labelBefore }) : null, h('div', { class: 't-status', 'data-family': family }, h('span', { class: 'dot' }), tr.t(`status.${se.status}`)), hunk ? h('div', { class: 't-sum', text: hunk.title }) : null);
578
+ }
579
+ else if (c.hoverGroup >= 0) {
580
+ const g = c.focus?.collapsed[c.hoverGroup];
581
+ if (!g)
582
+ return;
583
+ parts.push(h('div', { class: 't-label', text: g.label }), h('div', {
584
+ class: 't-hint',
585
+ text: tr.t(c.canExpand(c.hoverGroup) ? 'focus.expand' : 'focus.expandUnavailable'),
586
+ }));
587
+ }
588
+ if (parts.length === 0) {
589
+ attr(this.tooltip, 'data-open', 'false');
590
+ return;
591
+ }
592
+ replace(this.tooltip, ...parts);
593
+ attr(this.tooltip, 'data-open', 'true');
594
+ this.#placeTooltip();
595
+ }
596
+ #placeTooltip() {
597
+ const p = this.#pointer;
598
+ if (!p) {
599
+ attr(this.tooltip, 'data-open', 'false');
600
+ return;
601
+ }
602
+ const w = this.tooltip.offsetWidth;
603
+ const hgt = this.tooltip.offsetHeight;
604
+ const W = this.el.clientWidth;
605
+ const H = this.el.clientHeight;
606
+ let x = p.x + 16;
607
+ let y = p.y + 18;
608
+ if (x + w > W - 8)
609
+ x = Math.max(8, p.x - w - 12);
610
+ if (y + hgt > H - 8)
611
+ y = Math.max(8, p.y - hgt - 12);
612
+ this.tooltip.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
613
+ }
614
+ // ─── States ──────────────────────────────────────────────────────────────
615
+ #renderState(tr) {
616
+ const c = this.#ctx.controller;
617
+ const stats = c.diff?.stats;
618
+ let key = c.status;
619
+ if (c.status === 'loading')
620
+ key += `|${c.step}|${c.steps.join(',')}`;
621
+ if (c.status === 'ready')
622
+ key += stats?.identical ? '|identical' : '';
623
+ key += `|${tr.locale}`;
624
+ if (c.status === 'error')
625
+ key += `|${c.error?.message}`;
626
+ if (key === this.#stateKey)
627
+ return;
628
+ this.#stateKey = key;
629
+ this.#state.classList.remove('blocking');
630
+ if (c.status === 'ready' && !stats?.identical) {
631
+ this.#state.hidden = true;
632
+ replace(this.#state);
633
+ return;
634
+ }
635
+ this.#state.hidden = false;
636
+ if (c.status === 'loading') {
637
+ this.#state.classList.add('blocking');
638
+ const current = c.step ? c.steps.indexOf(c.step) : -1;
639
+ replace(this.#state, h('div', { class: 'skeleton-grid', 'aria-hidden': 'true' }), h('div', { class: 'state-card card', role: 'status', 'aria-live': 'polite' }, h('h2', { text: tr.t('state.loading') }), h('ol', { class: 'steps' }, c.steps.map((s, i) => h('li', { 'data-state': i < current ? 'done' : i === current ? 'active' : 'pending' }, h('span', { class: 'mark', 'aria-hidden': 'true' }, i < current ? icon('check') : null), h('span', { text: `${tr.t(`step.${s}`)}${i === current ? '…' : ''}` }))))));
640
+ }
641
+ else if (c.status === 'error') {
642
+ this.#state.classList.add('blocking');
643
+ const err = c.error;
644
+ const code = err instanceof KgdiffError ? err.code : err?.name;
645
+ const details = [code ? `[${code}]` : '', err?.message ?? '', err?.stack ?? '']
646
+ .filter(Boolean)
647
+ .join('\n');
648
+ replace(this.#state, h('div', { class: 'state-card card error', role: 'alert' }, h('div', { class: 'state-icon' }, icon('alert')), h('h2', { text: tr.t('state.error.title') }), h('p', { text: err?.message ?? '' }), h('details', null, h('summary', { text: tr.t('state.error.details') }), h('pre', { text: details }))));
649
+ }
650
+ else if (c.status === 'ready' && stats?.identical) {
651
+ replace(this.#state, h('div', { class: 'state-card card ok', role: 'status' }, h('div', { class: 'state-icon' }, icon('check-circle')), h('h2', { text: tr.t('state.identical.title') }), h('p', {
652
+ text: tr.t('state.identical.body', {
653
+ nodes: tr.plural('count.nodes', stats.after.nodes),
654
+ edges: tr.plural('count.edges', stats.after.edges),
655
+ }),
656
+ })));
657
+ }
658
+ else {
659
+ this.#state.classList.add('blocking');
660
+ replace(this.#state, h('div', { class: 'state-card' }, h('div', { class: 'state-icon' }, icon('overlay')), h('h2', { text: tr.t('state.empty.title') }), h('p', { text: tr.t('state.empty.body') })));
661
+ }
662
+ }
663
+ }
664
+ //# sourceMappingURL=stage.js.map