@whzxc/agent-design-gallery 0.14.1 → 0.16.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 (111) hide show
  1. package/README.md +29 -16
  2. package/package.json +2 -1
  3. package/public/access.css +15 -2
  4. package/public/app.js +1284 -521
  5. package/public/arrangement-worker.js +7 -7
  6. package/public/arrangement.js +35 -30
  7. package/public/assets.js +85 -48
  8. package/public/auth.js +59 -4
  9. package/public/boards.js +129 -0
  10. package/public/comment-anchors.js +50 -0
  11. package/public/comments.css +400 -0
  12. package/public/comments.js +1106 -0
  13. package/public/context-menu.js +97 -0
  14. package/public/frame-identity.js +51 -14
  15. package/public/hub.css +25 -3
  16. package/public/hub.html +10 -2
  17. package/public/hub.js +127 -23
  18. package/public/icons.js +9 -0
  19. package/public/index.html +26 -10
  20. package/public/instance-actions.js +9 -2
  21. package/public/layout.js +156 -86
  22. package/public/motion-flow.js +28 -0
  23. package/public/motion-identity.js +100 -0
  24. package/public/motion-paint.js +332 -0
  25. package/public/motion-scene.js +165 -0
  26. package/public/motion-specimens.js +335 -0
  27. package/public/player.css +270 -0
  28. package/public/player.js +753 -0
  29. package/public/recent-updates.js +535 -0
  30. package/public/selection.js +1 -1
  31. package/public/style.css +91 -154
  32. package/public/switcher.css +5 -4
  33. package/public/switcher.js +109 -34
  34. package/public/token-catalog.js +8 -3
  35. package/public/tokens.css +20 -1
  36. package/public/view-boards.css +131 -0
  37. package/public/view-boards.js +350 -0
  38. package/public/view-route.js +1 -2
  39. package/src/boards/board.mjs +30 -0
  40. package/src/boards/motion-board.mjs +202 -0
  41. package/src/boards/token-board.mjs +200 -0
  42. package/src/cli-output.mjs +10 -5
  43. package/src/cli.mjs +89 -35
  44. package/src/comments.mjs +293 -0
  45. package/src/http.mjs +7 -5
  46. package/src/hub/project-link.mjs +41 -0
  47. package/src/hub/registry.mjs +5 -0
  48. package/src/hub.mjs +14 -10
  49. package/src/link.mjs +13 -1
  50. package/src/recent-frames.mjs +295 -0
  51. package/src/recent-history.mjs +100 -0
  52. package/src/recent-job.mjs +63 -0
  53. package/src/recent-worker.mjs +171 -0
  54. package/src/server.mjs +285 -110
  55. package/src/service.mjs +46 -12
  56. package/src/toolkit/arch-git.mjs +8 -14
  57. package/src/toolkit/arch.mjs +3 -2
  58. package/src/toolkit/asset-rules.mjs +24 -1
  59. package/src/toolkit/browser.mjs +1 -13
  60. package/src/toolkit/build-store.mjs +9 -1
  61. package/src/toolkit/build-worker.mjs +6 -0
  62. package/src/toolkit/build.mjs +22 -16
  63. package/src/toolkit/commands.mjs +105 -9
  64. package/src/toolkit/compare.mjs +13 -11
  65. package/src/toolkit/config.mjs +2 -2
  66. package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
  67. package/src/toolkit/diff-inputs.mjs +97 -52
  68. package/src/toolkit/diff.mjs +198 -43
  69. package/src/toolkit/frame-declarations.mjs +36 -0
  70. package/src/toolkit/git-blobs.mjs +50 -0
  71. package/src/toolkit/impact-inputs.mjs +11 -19
  72. package/src/toolkit/impact-selection.mjs +27 -12
  73. package/src/toolkit/impact.mjs +49 -15
  74. package/src/toolkit/implementation-map.mjs +17 -6
  75. package/src/toolkit/input-generation.mjs +15 -0
  76. package/src/toolkit/inspect-output.mjs +1 -1
  77. package/src/toolkit/inspect.d.ts +9 -1
  78. package/src/toolkit/inspect.mjs +25 -1
  79. package/src/toolkit/motion-check.mjs +382 -0
  80. package/src/toolkit/motion-css.mjs +105 -0
  81. package/src/toolkit/motion-flows.mjs +95 -0
  82. package/src/toolkit/motion-impact.mjs +87 -0
  83. package/src/toolkit/motion-inventory.mjs +202 -0
  84. package/src/toolkit/motion-label.mjs +111 -0
  85. package/src/toolkit/motion-patterns.mjs +216 -0
  86. package/src/toolkit/motion-primitives.mjs +94 -0
  87. package/src/toolkit/motion-queries.mjs +169 -0
  88. package/src/toolkit/motion.mjs +300 -0
  89. package/src/toolkit/move-pairing.mjs +140 -0
  90. package/src/toolkit/owner.mjs +19 -6
  91. package/src/toolkit/play-endpoint.mjs +66 -0
  92. package/src/toolkit/project-index.mjs +4 -4
  93. package/src/toolkit/recent-structure.mjs +201 -0
  94. package/src/toolkit/results.mjs +3 -3
  95. package/src/toolkit/review-document.mjs +440 -0
  96. package/src/toolkit/review-embed-document.mjs +671 -0
  97. package/src/toolkit/review-filmstrip.mjs +76 -0
  98. package/src/toolkit/review-groups.mjs +29 -0
  99. package/src/toolkit/review-motion-card.mjs +51 -0
  100. package/src/toolkit/review-motion.mjs +159 -0
  101. package/src/toolkit/review-observation.mjs +131 -0
  102. package/src/toolkit/review-playback.js +123 -0
  103. package/src/toolkit/review-sheet.mjs +125 -0
  104. package/src/toolkit/review-specimens.mjs +60 -0
  105. package/src/toolkit/review.mjs +240 -0
  106. package/src/toolkit/runtime.mjs +8 -2
  107. package/src/toolkit/theme.mjs +16 -0
  108. package/src/viewer-cache.mjs +48 -12
  109. package/public/annotations.js +0 -816
  110. package/public/labels.js +0 -122
  111. package/src/annotations.mjs +0 -238
@@ -0,0 +1,535 @@
1
+ import { dataFetch } from './auth.js';
2
+ import { boardElement as node, frameKey } from './view-boards.js';
3
+
4
+ async function read(path, signal) {
5
+ const response = await dataFetch(path, { signal });
6
+ const result = await response.json();
7
+ if (!response.ok || result.error) throw Error(result.error || 'Cannot read project history.');
8
+ return result;
9
+ }
10
+
11
+ // history.state belongs to this navigation entry and survives reload. Local storage
12
+ // belongs to this browser profile. The lock orders checkpoint writes from its tabs.
13
+ const started = window.history.state?.adgVisitStarted ?? performance.timeOrigin;
14
+ let visitDirectory, pendingVisit;
15
+ const successfulVisits = new Set();
16
+ export function recordVisit(directory, refresh = false, successful = true) {
17
+ if (successful && !successfulVisits.has(directory)) {
18
+ successfulVisits.add(directory);
19
+ refresh = true;
20
+ }
21
+ if (!refresh && visitDirectory === directory && pendingVisit) return pendingVisit;
22
+ visitDirectory = directory;
23
+ pendingVisit = read('api/recent-visit')
24
+ .then(async ({ head, branch }) => {
25
+ if (!head || directory !== visitDirectory) return {};
26
+ const key = 'adg-visit:' + JSON.stringify([directory, branch]);
27
+ const capture = () => {
28
+ const entry = window.history.state ?? {};
29
+ const visits = entry.adgVisits ?? {};
30
+ if (key in visits) return { baseline: visits[key], branch };
31
+ const last = JSON.parse(localStorage.getItem(key) || 'null');
32
+ const baseline = last?.started > started ? last.previous : (last?.head ?? null);
33
+ if (!successfulVisits.has(directory)) return { baseline, branch };
34
+ if (!last || last.started < started)
35
+ localStorage.setItem(key, JSON.stringify({ started, head, previous: baseline }));
36
+ window.history.replaceState(
37
+ { ...entry, adgVisits: { ...visits, [key]: baseline }, adgVisitStarted: started },
38
+ ''
39
+ );
40
+ return { baseline, branch };
41
+ };
42
+ return navigator.locks ? navigator.locks.request(key, capture) : capture();
43
+ })
44
+ .catch(() => ({}));
45
+ return pendingVisit;
46
+ }
47
+
48
+ function boundaries() {
49
+ const day = new Date();
50
+ day.setHours(0, 0, 0, 0);
51
+ const week = new Date(day);
52
+ week.setDate(day.getDate() - ((day.getDay() + 6) % 7));
53
+ return { day: +day, week: +week };
54
+ }
55
+
56
+ export function createHistoryFilter(update) {
57
+ let request, timer, invalidation, directory, result, message, baseline, range, scope, frame;
58
+ let query, verifying, pendingPage, pageMessage, impact, impactLoading, impactError;
59
+ let cacheKey;
60
+ const visualStates = new Map();
61
+ const expanded = new Set();
62
+ const timestamp = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
63
+ function cancelVisual() {
64
+ verifying?.controller.abort();
65
+ verifying = null;
66
+ }
67
+ function close() {
68
+ if (verifying) visualStates.delete(verifying.period);
69
+ cancelVisual();
70
+ request?.abort();
71
+ request = null;
72
+ pendingPage = impactLoading = false;
73
+ clearTimeout(timer);
74
+ clearTimeout(invalidation);
75
+ }
76
+ async function open(nextDirectory, nextScope, nextFrame, nextRange, force = false) {
77
+ close();
78
+ if (nextDirectory !== directory) {
79
+ expanded.clear();
80
+ baseline = null;
81
+ }
82
+ range = nextRange ?? (nextDirectory === directory ? range : null) ?? 'latest';
83
+ directory = nextDirectory;
84
+ scope = nextScope;
85
+ frame = nextFrame;
86
+ const controller = (request = new AbortController());
87
+ const { signal } = controller;
88
+ const dates = boundaries();
89
+ const nextKey = JSON.stringify([directory, scope, frame, range, dates]);
90
+ const reuse = !force && cacheKey === nextKey && result?.available;
91
+ if (!reuse) {
92
+ cacheKey = null;
93
+ result = impact = null;
94
+ message = 'Finding recently changed frames…';
95
+ pageMessage = impactError = null;
96
+ visualStates.clear();
97
+ }
98
+ update();
99
+ try {
100
+ // The previous visit is needed only when filtering by its checkpoint.
101
+ const visit = recordVisit(directory, false, false);
102
+ if (range === 'visit') ({ baseline } = await visit);
103
+ else void visit.then(value => {
104
+ if (signal.aborted || baseline === value.baseline) return;
105
+ baseline = value.baseline;
106
+ update();
107
+ });
108
+ signal.throwIfAborted();
109
+ const params = new URLSearchParams(dates);
110
+ if (range === 'visit' && baseline) params.set('since', baseline);
111
+ query = params;
112
+ if (scope) params.set('scope', scope);
113
+ if (frame) params.set('frame', frame);
114
+ if (range === 'latest') params.set('latest', '1');
115
+ const validate = async () => {
116
+ try {
117
+ const state = await read('api/recent-state', signal);
118
+ if (!signal.aborted && (state.head !== result.head || state.branch !== result.branch ||
119
+ state.generation !== result.generation || JSON.stringify(boundaries()) !== JSON.stringify(dates))) {
120
+ void open(directory, scope, frame, range, true);
121
+ return;
122
+ }
123
+ } catch {
124
+ // Retry after the viewer connection returns.
125
+ }
126
+ if (!signal.aborted) timer = setTimeout(validate, 5000);
127
+ };
128
+ if (reuse) {
129
+ void validate();
130
+ return;
131
+ }
132
+ const response = await read('api/recent-frames?' + params, signal);
133
+ signal.throwIfAborted();
134
+ if (response.stale) {
135
+ invalidation = setTimeout(() => void open(directory, scope, frame, range, true), 200);
136
+ return;
137
+ }
138
+ result = response;
139
+ message = result.available ? result.notice : 'Recently updated is unavailable outside a Git project.';
140
+ if (result.notice) {
141
+ range = 'week';
142
+ }
143
+ if (result.available) void recordVisit(directory);
144
+ if (result.available) timer = setTimeout(validate, 5000);
145
+ if (!result.failures?.length && !result.notice) cacheKey = JSON.stringify([directory, scope, frame, range, dates]);
146
+ update();
147
+ } catch (error) {
148
+ if (!signal.aborted && !reuse) {
149
+ message = 'Incomplete coverage. ' + error.message;
150
+ update();
151
+ }
152
+ }
153
+ }
154
+ async function loadMore() {
155
+ if (pendingPage || !result?.hasMore || !request) return;
156
+ const { signal } = request;
157
+ pendingPage = true;
158
+ pageMessage = null;
159
+ update();
160
+ try {
161
+ const params = new URLSearchParams(query);
162
+ params.set('offset', result.rows.length);
163
+ params.set('snapshot', result.snapshot);
164
+ const next = await read('api/recent-frames?' + params, signal);
165
+ signal.throwIfAborted();
166
+ if (next.stale) {
167
+ void open(directory, scope, frame, range, true);
168
+ return;
169
+ }
170
+ result = { ...next, rows: [...result.rows, ...next.rows],
171
+ failures: [...new Set([...(result.failures ?? []), ...(next.failures ?? [])])] };
172
+ } catch (error) {
173
+ if (!signal.aborted) pageMessage = error.message;
174
+ } finally {
175
+ if (!signal.aborted) {
176
+ pendingPage = false;
177
+ update();
178
+ }
179
+ }
180
+ }
181
+ async function loadImpact() {
182
+ if (!request || impactLoading) return;
183
+ const { signal } = request;
184
+ impactLoading = true;
185
+ impactError = null;
186
+ update();
187
+ try {
188
+ const response = await read('api/recent-updates?' + query, signal);
189
+ signal.throwIfAborted();
190
+ if (response.stale || response.head !== result.head || response.generation !== result.generation) {
191
+ void open(directory, scope, frame, range, true);
192
+ return;
193
+ }
194
+ impact = response;
195
+ } catch (error) {
196
+ if (!signal.aborted) impactError = error.message;
197
+ } finally {
198
+ if (!signal.aborted) {
199
+ impactLoading = false;
200
+ update();
201
+ }
202
+ }
203
+ }
204
+ async function visualChanges(period) {
205
+ if (verifying?.period === period) {
206
+ cancelVisual();
207
+ visualStates.delete(period);
208
+ update();
209
+ return;
210
+ }
211
+ if (verifying) visualStates.delete(verifying.period);
212
+ cancelVisual();
213
+ const controller = new AbortController();
214
+ verifying = { period, controller };
215
+ const state = { message: 'Preparing visual comparison', verdicts: new Map() };
216
+ visualStates.set(period, state);
217
+ update();
218
+ try {
219
+ const params = new URLSearchParams(query);
220
+ params.set('from', period.base ?? '');
221
+ params.set('to', period.head ?? '');
222
+ params.set('generation', impact.generation);
223
+ const response = await dataFetch('api/recent-visual?' + params, { signal: controller.signal });
224
+ if (!response.ok) throw Error('Visual comparison unavailable.');
225
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
226
+ let pending = '',
227
+ finished = false;
228
+ function apply(line) {
229
+ if (!line.trim()) return;
230
+ const event = JSON.parse(line);
231
+ if (event.error) throw Error(event.error);
232
+ if (event.phase) {
233
+ state.message = event.phase + (event.total ? ' · ' + event.completed + ' / ' + event.total : '') + '…';
234
+ if (state.output) state.output.textContent = state.message;
235
+ for (const row of event.changes ?? []) {
236
+ for (const id of [identity(row), ...(row.former ? [identity(row.former)] : [])]) {
237
+ state.verdicts.set(id, row.status);
238
+ const label = state.labels?.get(id);
239
+ if (label) label.textContent = 'Visual comparison · ' + row.status;
240
+ }
241
+ }
242
+ } else if (event.result) {
243
+ if (event.result.stale) throw Error('Period changed. Refresh Recently updated.');
244
+ const checked = event.result.periods[0];
245
+ if (!checked) throw Error('Period unavailable.');
246
+ state.verdicts = new Map();
247
+ for (const row of checked.rows) {
248
+ state.verdicts.set(identity(row), row.status);
249
+ if (row.former) state.verdicts.set(identity(row.former), row.status);
250
+ }
251
+ state.complete = checked.complete;
252
+ state.message = checked.complete
253
+ ? 'Visual comparison complete · ' + checked.rows.length + ' changes'
254
+ : 'Visual coverage incomplete. ' + (checked.failures?.[0]?.message ?? '');
255
+ finished = true;
256
+ }
257
+ }
258
+ for (;;) {
259
+ const { value, done } = await reader.read();
260
+ controller.signal.throwIfAborted();
261
+ if (done) {
262
+ apply(pending);
263
+ break;
264
+ }
265
+ const lines = (pending + value).split('\n');
266
+ pending = lines.pop();
267
+ for (const line of lines) apply(line);
268
+ }
269
+ if (!finished) throw Error('Visual comparison ended early.');
270
+ } catch (error) {
271
+ if (controller.signal.aborted) return;
272
+ state.verdicts.clear();
273
+ state.message = error.message;
274
+ } finally {
275
+ if (verifying?.controller === controller) {
276
+ verifying = null;
277
+ update();
278
+ }
279
+ }
280
+ }
281
+ return {
282
+ open,
283
+ close,
284
+ invalidate() {
285
+ cacheKey = null;
286
+ if (!request) return;
287
+ clearTimeout(invalidation);
288
+ invalidation = setTimeout(() => void open(directory, scope, frame, range, true), 200);
289
+ },
290
+ render(container, { relative, frames, inScope, card }) {
291
+ const controls = node('div', 'recent-ranges');
292
+ controls.setAttribute('role', 'group');
293
+ controls.setAttribute('aria-label', 'History range');
294
+ for (const [id, title] of [['latest', 'Latest'], ['week', 'This week'], ['visit', 'Since my last visit']]) {
295
+ const button = node('button', '', title);
296
+ button.dataset.recentFocus = id;
297
+ button.setAttribute('aria-pressed', String(id === range));
298
+ button.disabled = id === 'visit' && !baseline;
299
+ button.onclick = () => void open(directory, scope, frame, id);
300
+ controls.append(button);
301
+ }
302
+ const children = [controls];
303
+ container.dataset.historyReady = String(!!result || !!message?.startsWith('Incomplete coverage'));
304
+ if (message) {
305
+ const status = node('p', 'view-board-status', message);
306
+ status.setAttribute('role', 'status');
307
+ children.push(status);
308
+ }
309
+ if (result?.available) {
310
+ const feed = node('section', 'view-board-section recent-feed');
311
+ feed.append(node('h2', '', 'Direct changes'));
312
+ const gallery = node('div', 'recent-frame-grid');
313
+ const removed = node('ul', 'recent-removed');
314
+ for (const row of result.rows) {
315
+ const source = relative(row.source);
316
+ const changeTime = new Date(row.time);
317
+ const time = node('time', '', timestamp.format(changeTime));
318
+ time.dateTime = changeTime.toISOString();
319
+ const subject = node('span', '', row.subject);
320
+ subject.title = row.subject;
321
+ const metadata = node('small', 'recent-change');
322
+ metadata.append(time, subject);
323
+ if (row.status === 'removed') {
324
+ if (!inScope(source, row.frame, row.chapter)) continue;
325
+ const item = node('li', '', source + ' · ' + row.frame);
326
+ item.append(metadata);
327
+ removed.append(item);
328
+ continue;
329
+ }
330
+ const ref = frames.get(frameKey(source, row.frame));
331
+ if (!ref) continue;
332
+ const badge = row.status === 'added' ? 'New' : row.status === 'moved' ? 'Moved' : 'Edited';
333
+ for (const period of impact?.periods ?? []) {
334
+ const visual = visualStates.get(period);
335
+ if (!visual || (row.commit
336
+ ? row.time > (period.lastTime ?? Infinity) || row.time < (period.firstTime ?? -Infinity) || !period.head
337
+ : period.head)) continue;
338
+ const label = visual.verdicts.get(identity(row));
339
+ if (label || visual.complete)
340
+ metadata.append(node('span', '', label ? 'Visual comparison · ' + label : 'Visually unchanged'));
341
+ }
342
+ const entry = card(ref, { badge, source: true });
343
+ entry.querySelector('.view-show-in-board').dataset.recentFocus = identity(row);
344
+ const caption = entry.querySelector('.view-frame-caption');
345
+ if (row.former) caption.append(node('small', 'view-source-name', 'From ' + relative(row.former.source) + ' · ' + row.former.frame));
346
+ caption.append(metadata);
347
+ gallery.append(entry);
348
+ }
349
+ if (gallery.childElementCount) feed.append(gallery);
350
+ if (removed.childElementCount)
351
+ feed.append(node('h3', 'recent-source-heading recent-removed-heading', 'Removed frames'), removed);
352
+ if (!gallery.childElementCount && !removed.childElementCount)
353
+ feed.append(node('p', 'view-board-status', 'No direct frame changes in this scope.'));
354
+ if (result.failures?.length)
355
+ feed.append(node('p', 'view-board-status', 'Incomplete history coverage. ' + result.failures[0]));
356
+ if (pageMessage) feed.append(node('p', 'view-board-status', pageMessage));
357
+ if (result.hasMore) {
358
+ const more = node('button', 'view-board-action recent-more', pendingPage ? 'Loading…' : 'Load more');
359
+ more.dataset.recentFocus = 'load-more';
360
+ more.setAttribute('aria-disabled', String(pendingPage));
361
+ more.onclick = () => void loadMore();
362
+ feed.append(more);
363
+ }
364
+ const impacts = node('section', 'view-board-section recent-impacts');
365
+ impacts.append(node('h2', '', range === 'latest' ? 'Shared and global impact this week' : 'Shared and global impact'));
366
+ if (!impact) {
367
+ const show = node('button', 'view-board-action', impactLoading ? 'Checking inputs…' : 'Show impact');
368
+ show.dataset.recentFocus = 'show-impact';
369
+ show.setAttribute('aria-disabled', String(impactLoading));
370
+ show.onclick = () => void loadImpact();
371
+ impacts.append(show);
372
+ if (impactError) impacts.append(node('p', 'view-board-status', impactError));
373
+ }
374
+ children.push(feed, impacts);
375
+ }
376
+ const redirects = new Map();
377
+ for (const period of impact?.periods ?? []) {
378
+ const periodKey = JSON.stringify([period.title, period.base, period.head]);
379
+ const section = node('section', 'view-board-section recent-period');
380
+ const header = node('header', 'view-section-heading');
381
+ const heading = node('div');
382
+ heading.append(node('h2', '', period.title));
383
+ if (period.globalCauses?.length)
384
+ heading.append(globalInputs(period.globalCauses, expanded, JSON.stringify([periodKey, 'global'])));
385
+ const visual = visualStates.get(period);
386
+ const action = node('button', 'view-board-action', verifying?.period === period ? 'Cancel comparison' : 'Visual changes');
387
+ action.setAttribute('aria-label', action.textContent + ' · ' + period.title);
388
+ action.dataset.recentFocus = periodKey;
389
+ action.onclick = () => void visualChanges(period);
390
+ header.append(heading, action);
391
+ section.append(header);
392
+ if (visual) {
393
+ visual.labels = new Map();
394
+ visual.output = node('small', 'recent-visual', visual.message);
395
+ visual.output.setAttribute('role', 'status');
396
+ section.append(visual.output);
397
+ }
398
+
399
+ const sources = new Map();
400
+ for (const row of period.rows) {
401
+ const id = identity(row);
402
+ const locator = redirects.has(id) ? redirects.get(id) : row;
403
+ const source = relative(locator?.source ?? row.source);
404
+ const ref = locator && frames.get(frameKey(source, locator.frame));
405
+ if (!ref || !locator || !row.causes?.length || row.status === 'removed') continue;
406
+ if (!sources.has(source)) sources.set(source, new Map());
407
+ const shared = sources.get(source);
408
+ const key = JSON.stringify(row.causes);
409
+ if (!shared.has(key)) shared.set(key, { causes: row.causes, frames: [] });
410
+ shared.get(key).frames.push({ row, ref });
411
+ }
412
+ for (const [source, shared] of sources) {
413
+ const group = node('section', 'recent-source');
414
+ group.append(node('h3', 'recent-source-heading view-source-name', source));
415
+ function grid(items) {
416
+ const gallery = node('div', 'recent-frame-grid');
417
+ for (const { row, ref } of items) {
418
+ const badge = 'Affected by shared input';
419
+ const frame = card(ref, { badge, source: false });
420
+ frame.querySelector('.view-show-in-board').dataset.recentFocus = JSON.stringify([periodKey, identity(row)]);
421
+ if (row.former) {
422
+ const former = node('small', 'view-source-name', 'From ' + relative(row.former.source) + ' · ' + row.former.frame);
423
+ former.title = former.textContent;
424
+ frame.querySelector('.view-frame-caption').append(former);
425
+ }
426
+ if (visual) {
427
+ const id = identity(row), oldId = row.former && identity(row.former);
428
+ const status = visual.verdicts.get(id) ?? visual.verdicts.get(oldId);
429
+ const annotation = node('small', 'recent-visual', status
430
+ ? 'Visual comparison · ' + status
431
+ : visual.complete ? 'Visually unchanged' : verifying?.period === period ? '' : 'Visual result unknown');
432
+ visual.labels.set(id, annotation);
433
+ if (oldId) visual.labels.set(oldId, annotation);
434
+ frame.querySelector('.view-frame-caption').append(annotation);
435
+ }
436
+ gallery.append(frame);
437
+ }
438
+ return gallery;
439
+ }
440
+ for (const [key, entry] of shared) {
441
+ const id = JSON.stringify([periodKey, source, key]);
442
+ const details = node('details', 'recent-shared');
443
+ const summary = node('summary', '', entry.causes.join(', ') + ' · ' + entry.frames.length +
444
+ (entry.frames.length === 1 ? ' affected frame' : ' affected frames'));
445
+ summary.dataset.recentFocus = id;
446
+ details.open = expanded.has(id);
447
+ details.append(summary);
448
+ const mount = () => {
449
+ if (details.open) {
450
+ expanded.add(id);
451
+ if (details.children.length === 1) details.append(grid(entry.frames));
452
+ } else {
453
+ expanded.delete(id);
454
+ }
455
+ };
456
+ mount();
457
+ details.ontoggle = mount;
458
+ group.append(details);
459
+ }
460
+ section.append(group);
461
+ }
462
+ if (!sources.size && !period.globalCauses?.length && period.complete)
463
+ section.append(node('p', 'recent-visual view-board-status', 'No matching changes in this scope.'));
464
+ for (const failure of period.failures ?? []) section.append(node('small', 'recent-visual', failure.message));
465
+ children.push(section);
466
+ // Traverse newest first to resolve historical names forward to the current frame.
467
+ const prior = new Map(redirects);
468
+ for (const row of period.rows) {
469
+ if (row.former) prior.set(identity(row.former), redirects.has(identity(row)) ? redirects.get(identity(row)) : row);
470
+ if (row.status === 'added' || row.status === 'removed' || row.former) prior.set(identity(row), null);
471
+ }
472
+ for (const [id, target] of prior) redirects.set(id, target);
473
+ }
474
+ const focus = container.contains(document.activeElement) ? document.activeElement.dataset.recentFocus : null;
475
+ container.replaceChildren(...children);
476
+ if (focus) container.querySelector('[data-recent-focus="' + CSS.escape(focus) + '"]')?.focus({ preventScroll: true });
477
+ }
478
+ };
479
+ }
480
+
481
+ function causePriority(file) {
482
+ const name = file.split('/').at(-1);
483
+ if (/^adg\.config\.[cm]?[jt]s$/.test(name)) return 0;
484
+ if (name === 'package.json') return 1;
485
+ if (/^(?:package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?)$/.test(name)) return 2;
486
+ return file.includes('/') ? 4 : 3;
487
+ }
488
+
489
+ function globalInputs(causes, expanded, id) {
490
+ const files = [...new Set(causes)];
491
+ const named = [...files].sort((a, b) => causePriority(a) - causePriority(b) ||
492
+ Number(a.includes('/')) - Number(b.includes('/')) || a.localeCompare(b)).slice(0, 2);
493
+ const remaining = files.length - named.length;
494
+ const details = node('details', 'recent-global');
495
+ const summary = node('summary', 'view-board-status');
496
+ summary.dataset.recentFocus = id;
497
+ summary.append(
498
+ node('span', '', 'Global inputs changed: ' + files.length + (files.length === 1 ? ' file' : ' files')),
499
+ node('span', 'recent-global-sample', ' (' + named.join(', ')),
500
+ node('span', '', (remaining ? ', +' + remaining : '') + ')')
501
+ );
502
+ details.open = expanded.has(id);
503
+ details.append(summary);
504
+ const showList = () => {
505
+ if (!details.open) {
506
+ expanded.delete(id);
507
+ return;
508
+ }
509
+ expanded.add(id);
510
+ if (details.children.length > 1) return;
511
+ const directories = new Map();
512
+ for (const file of files.sort((a, b) => a.localeCompare(b))) {
513
+ const separator = file.lastIndexOf('/');
514
+ const directory = separator < 0 ? '' : file.slice(0, separator);
515
+ if (!directories.has(directory)) directories.set(directory, []);
516
+ directories.get(directory).push(file.slice(separator + 1));
517
+ }
518
+ const groups = node('div', 'recent-global-list');
519
+ for (const directory of [...directories.keys()].sort((a, b) => a.localeCompare(b))) {
520
+ const group = node('section');
521
+ const list = node('ul');
522
+ for (const file of directories.get(directory)) list.append(node('li', '', file));
523
+ group.append(node('h3', 'view-source-name', directory || 'Project root'), list);
524
+ groups.append(group);
525
+ }
526
+ details.append(groups);
527
+ };
528
+ if (details.open) showList();
529
+ details.ontoggle = showList;
530
+ return details;
531
+ }
532
+
533
+ function identity({ source, frame }) {
534
+ return frameKey(source, frame);
535
+ }
@@ -10,7 +10,7 @@ export function hitSelection(assets, x, y, elements = true) {
10
10
  const part = asset.parts.find(p => (asset.component || p.id === crop.id) && contains(frameBox(asset,p), x,y));
11
11
  if (!part) return {asset, part:asset.component ? null : asset.parts.find(p=>p.id===crop.id)};
12
12
  const box = frameBox(asset,part);
13
- const element = elements ? [...(part.elements ?? [])].reverse().find(e => contains(e,x-box.x,y-box.y)) : null;
13
+ const element = elements ? part.elements?.findLast(e => !e.commentOnly && contains(e,x-box.x,y-box.y)) : null;
14
14
  return {asset, part, element};
15
15
  }
16
16
  return null;