alibai 0.1.0 → 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.
- package/README.ja.md +115 -0
- package/README.ko.md +115 -0
- package/README.md +69 -105
- package/dist/report.js +7 -0
- package/dist/store.js +130 -33
- package/dist/viewer.js +66 -7
- package/package.json +5 -1
- package/viewer/evidence.js +480 -0
- package/viewer/index.html +1 -0
- package/viewer/messages.js +120 -0
- package/viewer/tokens.css +1 -1
- package/viewer/viewer.css +445 -95
- package/viewer/viewer.js +345 -88
package/viewer/viewer.js
CHANGED
|
@@ -5,6 +5,11 @@ const breadcrumb = document.getElementById("breadcrumb");
|
|
|
5
5
|
const theme = document.getElementById("theme");
|
|
6
6
|
const languages = document.getElementById("languages");
|
|
7
7
|
const languageButtons = languages.querySelectorAll("button");
|
|
8
|
+
const copyStatus = el("p", "copy-status");
|
|
9
|
+
copyStatus.setAttribute("role", "status");
|
|
10
|
+
document.body.append(copyStatus);
|
|
11
|
+
let copying = false;
|
|
12
|
+
let copyTimeout;
|
|
8
13
|
const themes = ["System", "Light", "Dark"];
|
|
9
14
|
let themeIndex = Math.max(0, themes.indexOf(readPreference("alibai-theme")));
|
|
10
15
|
const url = new URL(location.href);
|
|
@@ -14,6 +19,7 @@ let files;
|
|
|
14
19
|
let loadFailed = false;
|
|
15
20
|
let query = "";
|
|
16
21
|
let filter = "all";
|
|
22
|
+
const selections = new Map();
|
|
17
23
|
|
|
18
24
|
const verdicts = { pass: "holdsVerdict", fail: "brokenVerdict", info: "informational", open: "inProgress" };
|
|
19
25
|
const t = (key, values) => translate(locale, key, values);
|
|
@@ -51,6 +57,20 @@ function link(text, href, className) {
|
|
|
51
57
|
return node;
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
function iconControl(control, label, path) {
|
|
61
|
+
const namespace = "http://www.w3.org/2000/svg";
|
|
62
|
+
const svg = document.createElementNS(namespace, "svg");
|
|
63
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
64
|
+
svg.setAttribute("aria-hidden", "true");
|
|
65
|
+
const stroke = document.createElementNS(namespace, "path");
|
|
66
|
+
stroke.setAttribute("d", path);
|
|
67
|
+
svg.append(stroke);
|
|
68
|
+
control.append(svg);
|
|
69
|
+
control.setAttribute("aria-label", label);
|
|
70
|
+
control.title = label;
|
|
71
|
+
return control;
|
|
72
|
+
}
|
|
73
|
+
|
|
54
74
|
function timestamp(value, compact = false) {
|
|
55
75
|
if (!value) return el("span", "muted", t("notRecorded"));
|
|
56
76
|
const node = el("time", "mono", (compact ? formats.compact : formats.timestamp).format(new Date(value)));
|
|
@@ -84,12 +104,10 @@ function applyLocale() {
|
|
|
84
104
|
};
|
|
85
105
|
formats = {
|
|
86
106
|
compact: new Intl.DateTimeFormat(locale, date),
|
|
107
|
+
time: new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23", timeZone: "UTC" }),
|
|
87
108
|
timestamp: new Intl.DateTimeFormat(locale, { ...date, timeZoneName: "short" }),
|
|
88
109
|
count: new Intl.NumberFormat(locale),
|
|
89
110
|
percent: new Intl.NumberFormat(locale, { style: "percent" }),
|
|
90
|
-
seconds: new Intl.NumberFormat(locale, {
|
|
91
|
-
style: "unit", unit: "second", minimumFractionDigits: 3, maximumFractionDigits: 3, signDisplay: "always",
|
|
92
|
-
}),
|
|
93
111
|
};
|
|
94
112
|
document.documentElement.lang = locale;
|
|
95
113
|
document.querySelector(".logo").setAttribute("aria-label", t("homeLabel"));
|
|
@@ -116,6 +134,13 @@ for (const button of languageButtons) {
|
|
|
116
134
|
}
|
|
117
135
|
applyLocale();
|
|
118
136
|
|
|
137
|
+
function visibleRuns() {
|
|
138
|
+
const term = query.trim().toLowerCase();
|
|
139
|
+
return files.runs.filter((run) =>
|
|
140
|
+
(filter === "all" || run.verdict === filter) &&
|
|
141
|
+
[run.title, run.git.branch ?? ""].some((value) => value.toLowerCase().includes(term)));
|
|
142
|
+
}
|
|
143
|
+
|
|
119
144
|
function showList() {
|
|
120
145
|
const controls = el("div", "filters");
|
|
121
146
|
const search = el("input", "search");
|
|
@@ -157,10 +182,7 @@ function showList() {
|
|
|
157
182
|
|
|
158
183
|
function updateRows() {
|
|
159
184
|
for (const { key, button } of buttons) button.setAttribute("aria-pressed", String(key === filter));
|
|
160
|
-
const
|
|
161
|
-
const matching = files.runs.filter((run) =>
|
|
162
|
-
(filter === "all" || run.verdict === filter) &&
|
|
163
|
-
[run.title, run.git.branch ?? ""].some((value) => value.toLowerCase().includes(term)));
|
|
185
|
+
const matching = visibleRuns();
|
|
164
186
|
rows.replaceChildren(...matching.map((run) => {
|
|
165
187
|
const result = run.verdict ?? "open";
|
|
166
188
|
const exhibits = [...run.steps, ...run.checks];
|
|
@@ -254,20 +276,17 @@ function appendGitChanges(meta, git) {
|
|
|
254
276
|
}
|
|
255
277
|
}
|
|
256
278
|
|
|
257
|
-
function
|
|
279
|
+
function renderCaseSummary(run, exhibits, back) {
|
|
258
280
|
const title = heading(run.title);
|
|
259
|
-
const exhibits = timeline(run);
|
|
260
281
|
const result = run.verdict ?? "open";
|
|
261
282
|
const count = (result) => exhibits.filter(({ item }) => item.result === result).length;
|
|
262
|
-
const counts =
|
|
263
|
-
for (const [label, number, tone] of [
|
|
283
|
+
const counts = [
|
|
264
284
|
["passed", count("pass"), "pass"], ["failed", count("fail"), "fail"], ["exhibits", exhibits.length, ""],
|
|
265
|
-
]) {
|
|
266
|
-
|
|
267
|
-
}
|
|
285
|
+
].map(([label, number, tone]) => el("div", tone && number ? `count ${tone}` : "count",
|
|
286
|
+
el("b", "", formats.count.format(number)), el("span", "", t(label))));
|
|
268
287
|
const meta = el("dl", "meta");
|
|
269
288
|
const sha = (value) => {
|
|
270
|
-
const code = el("code", "", value?.slice(0, 12) ?? "—");
|
|
289
|
+
const code = el("code", "", (back ? value?.slice(0, 12) : value) ?? "—");
|
|
271
290
|
if (value) code.title = value;
|
|
272
291
|
return code;
|
|
273
292
|
};
|
|
@@ -275,29 +294,131 @@ function showCase(run) {
|
|
|
275
294
|
["branch", branchChip(run.git.branch)],
|
|
276
295
|
["commit", sha(run.git.headSha)],
|
|
277
296
|
["base", sha(run.git.baseSha)],
|
|
278
|
-
["worktree", t(run.git.dirty === undefined ? "notRecorded" : run.git.dirty ? "dirty" : "clean")],
|
|
297
|
+
...(back ? [["worktree", t(run.git.dirty === undefined ? "notRecorded" : run.git.dirty ? "dirty" : "clean")]] : []),
|
|
279
298
|
["platform", run.platform],
|
|
280
|
-
...(run.agent ? [["agent", run.agent]] : []),
|
|
299
|
+
...(run.agent || !back ? [["agent", run.agent ?? t("notRecorded")]] : []),
|
|
281
300
|
["started", timestamp(run.createdAt)],
|
|
282
301
|
...(run.verdict ? [["ended", timestamp(run.endedAt)]] : []),
|
|
283
302
|
]) {
|
|
284
303
|
meta.append(el("div", "", el("dt", "", t(label)), el("dd", "", value)));
|
|
285
304
|
}
|
|
286
|
-
appendGitChanges(meta, run.git);
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
305
|
+
if (back) appendGitChanges(meta, run.git);
|
|
306
|
+
const caseIdentity = el("div", "case-identity", el("p", "label", t("caseNumber", { id: run.id.slice(0, 8) })));
|
|
307
|
+
const caseHeader = el("header", "case-header", el("div", "case-heading", ...(back ? [back] : []), caseIdentity),
|
|
308
|
+
el("div", "counts", badge(result, verdicts[result]), ...counts));
|
|
309
|
+
const summary = el("section", "summary", caseHeader, title);
|
|
310
|
+
if (run.summary) summary.append(el("p", "note", run.summary));
|
|
311
|
+
summary.append(meta);
|
|
312
|
+
return { summary, title };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function showCase(run) {
|
|
316
|
+
const exhibits = timeline(run);
|
|
317
|
+
const cases = visibleRuns();
|
|
318
|
+
const position = cases.indexOf(run);
|
|
319
|
+
const arrow = (offset, label, path) => {
|
|
320
|
+
const neighbor = position < 0 ? undefined : cases[position + offset];
|
|
321
|
+
const control = neighbor ? link("", `#case/${neighbor.id}`, "icon-control") : el("button", "icon-control");
|
|
322
|
+
if (!neighbor) {
|
|
323
|
+
control.type = "button";
|
|
324
|
+
control.disabled = true;
|
|
325
|
+
}
|
|
326
|
+
return iconControl(control, t(label), path);
|
|
327
|
+
};
|
|
328
|
+
const navigation = el("nav", "case-navigation",
|
|
329
|
+
arrow(-1, "previousCase", "m15 5-7 7 7 7"),
|
|
330
|
+
el("span", "case-position mono", position < 0 ? "" : t("casePosition", {
|
|
331
|
+
current: formats.count.format(position + 1), total: formats.count.format(cases.length) })),
|
|
332
|
+
arrow(1, "nextCase", "m9 5 7 7-7 7"));
|
|
333
|
+
navigation.setAttribute("aria-label", t("caseNavigation"));
|
|
334
|
+
const back = iconControl(link("", "#", "icon-control case-back"), t("back"), "M19 12H5m7-7-7 7 7 7");
|
|
335
|
+
const { summary, title } = renderCaseSummary(run, exhibits, back);
|
|
336
|
+
const evidence = el("section", "evidence");
|
|
337
|
+
if (exhibits.length) showEvidence(evidence, run, exhibits);
|
|
338
|
+
else evidence.append(el("h2", "", t("timeline")), el("p", "empty", t("noExhibits")));
|
|
339
|
+
app.append(el("div", "case-detail", summary, navigation, evidence));
|
|
297
340
|
return title;
|
|
298
341
|
}
|
|
299
342
|
|
|
300
|
-
function
|
|
343
|
+
function showEvidence(evidence, run, exhibits) {
|
|
344
|
+
const selected = selections.get(run.id) ?? new Set();
|
|
345
|
+
selections.set(run.id, selected);
|
|
346
|
+
const all = el("input", "");
|
|
347
|
+
all.type = "checkbox";
|
|
348
|
+
const headCount = el("span", "head-count");
|
|
349
|
+
const toolbar = el("div", "evidence-head", el("h2", "", t("timeline")),
|
|
350
|
+
el("div", "evidence-tools", headCount, el("label", "select-all", all, t("selectAll"))));
|
|
351
|
+
const comments = loadComments(run.id).catch(() => null);
|
|
352
|
+
const boxes = [];
|
|
353
|
+
const list = el("ol", "timeline", ...exhibits.map((exhibit, index) => {
|
|
354
|
+
const { id } = exhibit.item;
|
|
355
|
+
const card = renderExhibit(run, exhibit, index);
|
|
356
|
+
const box = el("input", "");
|
|
357
|
+
box.type = "checkbox";
|
|
358
|
+
box.setAttribute("aria-label", t("selectExhibit", { exhibit: card.querySelector(".tag").textContent }));
|
|
359
|
+
card.querySelector(".exhibit-head").prepend(el("label", "exhibit-select", box));
|
|
360
|
+
box.addEventListener("change", () => {
|
|
361
|
+
if (box.checked) selected.add(id);
|
|
362
|
+
else selected.delete(id);
|
|
363
|
+
updateSelection();
|
|
364
|
+
});
|
|
365
|
+
boxes.push([id, box]);
|
|
366
|
+
card.append(renderCommentThread(run.id, id, comments));
|
|
367
|
+
return card;
|
|
368
|
+
}));
|
|
369
|
+
const count = el("span", "selection-count");
|
|
370
|
+
count.setAttribute("aria-live", "polite");
|
|
371
|
+
const clear = el("button", "clear-selection", t("clearSelection"));
|
|
372
|
+
clear.type = "button";
|
|
373
|
+
const html = el("button", "evidence-button primary report-html", t("htmlReport"));
|
|
374
|
+
const pdf = el("button", "evidence-button report-pdf", "PDF");
|
|
375
|
+
const exportStatus = el("p", "export-status");
|
|
376
|
+
exportStatus.setAttribute("role", "status");
|
|
377
|
+
const remote = el("div", "export-remote",
|
|
378
|
+
el("div", "remote-selection", count, clear), el("div", "report-actions", pdf, html), exportStatus);
|
|
379
|
+
remote.setAttribute("role", "group");
|
|
380
|
+
remote.setAttribute("aria-label", t("reportActions"));
|
|
381
|
+
let exporting = false;
|
|
382
|
+
function updateSelection() {
|
|
383
|
+
for (const [id, box] of boxes) box.checked = selected.has(id);
|
|
384
|
+
all.checked = selected.size === boxes.length;
|
|
385
|
+
all.indeterminate = selected.size > 0 && !all.checked;
|
|
386
|
+
count.textContent = t("selectedCount", { count: formats.count.format(selected.size) });
|
|
387
|
+
headCount.textContent = selected.size ? count.textContent : "";
|
|
388
|
+
remote.hidden = selected.size === 0;
|
|
389
|
+
html.disabled = pdf.disabled = exporting;
|
|
390
|
+
}
|
|
391
|
+
all.addEventListener("change", () => {
|
|
392
|
+
selected.clear();
|
|
393
|
+
if (all.checked) for (const [id] of boxes) selected.add(id);
|
|
394
|
+
updateSelection();
|
|
395
|
+
});
|
|
396
|
+
clear.addEventListener("click", () => {
|
|
397
|
+
selected.clear();
|
|
398
|
+
all.focus({ preventScroll: true });
|
|
399
|
+
updateSelection();
|
|
400
|
+
});
|
|
401
|
+
for (const [button, print] of [[html, false], [pdf, true]]) {
|
|
402
|
+
button.addEventListener("click", async () => {
|
|
403
|
+
exporting = true;
|
|
404
|
+
updateSelection();
|
|
405
|
+
exportStatus.textContent = t("preparingReport");
|
|
406
|
+
try {
|
|
407
|
+
await exportReport(run, exhibits, new Set(selected), print);
|
|
408
|
+
exportStatus.textContent = "";
|
|
409
|
+
} catch {
|
|
410
|
+
exportStatus.textContent = t("reportError");
|
|
411
|
+
} finally {
|
|
412
|
+
exporting = false;
|
|
413
|
+
updateSelection();
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
updateSelection();
|
|
418
|
+
evidence.append(toolbar, list, remote);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function renderExhibit(run, { kind, item }, index, reportImages) {
|
|
301
422
|
const isStep = kind === "ui";
|
|
302
423
|
const name = isStep ? item.action : item.target.split("(")[0].trim();
|
|
303
424
|
const title = isStep ? name : name.split(/[./\\:#›\s]+/).filter(Boolean).at(-1) ?? t("logicCheck");
|
|
@@ -306,80 +427,215 @@ function renderExhibit(run, { kind, item }, index) {
|
|
|
306
427
|
const header = el("header", "exhibit-head", el("span", "tag", t("exhibitNumber", { number })),
|
|
307
428
|
el("span", "kind mono", t(isStep ? "uiStep" : "logicCheck")), titleNode);
|
|
308
429
|
if (item.createdAt) {
|
|
309
|
-
const
|
|
310
|
-
const time = el("time", "exhibit-time mono", formats.seconds.format(seconds));
|
|
430
|
+
const time = el("time", "exhibit-time mono", formats.time.format(new Date(item.createdAt)));
|
|
311
431
|
time.dateTime = item.createdAt;
|
|
312
|
-
time.title = item.createdAt;
|
|
432
|
+
time.title = formats.timestamp.format(new Date(item.createdAt));
|
|
313
433
|
header.append(time);
|
|
314
434
|
}
|
|
315
435
|
header.append(badge(item.result, item.result));
|
|
316
|
-
const content = isStep ? renderScreenshots(run.id, item) : renderCheck(item);
|
|
436
|
+
const content = isStep ? renderScreenshots(run.id, item, reportImages) : renderCheck(item);
|
|
317
437
|
return el("li", `exhibit ${item.result}`, header, content);
|
|
318
438
|
}
|
|
319
439
|
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
440
|
+
async function screenshotPng(image) {
|
|
441
|
+
await image.decode();
|
|
442
|
+
if (new URL(image.src).pathname.toLowerCase().endsWith(".png")) {
|
|
443
|
+
const response = await fetch(image.src);
|
|
444
|
+
if (!response.ok) throw new Error("Screenshot unavailable");
|
|
445
|
+
return response.blob();
|
|
446
|
+
}
|
|
447
|
+
const canvas = el("canvas", "");
|
|
448
|
+
canvas.width = image.naturalWidth;
|
|
449
|
+
canvas.height = image.naturalHeight;
|
|
450
|
+
canvas.getContext("2d").drawImage(image, 0, 0);
|
|
451
|
+
return new Promise((resolve, reject) => {
|
|
452
|
+
canvas.toBlob((blob) => blob ? resolve(blob) : reject(new Error("PNG encoding failed")), "image/png");
|
|
453
|
+
});
|
|
454
|
+
}
|
|
324
455
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
456
|
+
function showCopyStatus(button, message, label) {
|
|
457
|
+
clearTimeout(copyTimeout);
|
|
458
|
+
copyStatus.textContent = t(message, { label });
|
|
459
|
+
const anchor = button.getBoundingClientRect();
|
|
460
|
+
const { width, height } = copyStatus.getBoundingClientRect();
|
|
461
|
+
const viewport = document.documentElement;
|
|
462
|
+
const gap = 8;
|
|
463
|
+
const below = anchor.bottom + gap;
|
|
464
|
+
const bottom = viewport.clientHeight - gap - height;
|
|
465
|
+
const top = below <= bottom ? below : anchor.top - gap - height;
|
|
466
|
+
copyStatus.style.top = `${Math.max(gap, Math.min(top, bottom))}px`;
|
|
467
|
+
copyStatus.style.left = `${Math.max(gap, Math.min(anchor.right, viewport.clientWidth - gap) - width)}px`;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
async function copyScreenshot(image, button, label) {
|
|
471
|
+
if (copying) {
|
|
472
|
+
showCopyStatus(button, "screenshotCopyBusy");
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
copying = true;
|
|
476
|
+
showCopyStatus(button, "screenshotCopyPending", label);
|
|
477
|
+
let png;
|
|
478
|
+
let message;
|
|
479
|
+
try {
|
|
480
|
+
// Start the clipboard write within the gesture, even when PNG data is still pending.
|
|
481
|
+
if (!navigator.clipboard?.write || !window.ClipboardItem) throw new Error("Image clipboard unavailable");
|
|
482
|
+
png = screenshotPng(image);
|
|
483
|
+
await navigator.clipboard.write([new ClipboardItem({ "image/png": png })]);
|
|
484
|
+
message = "screenshotCopied";
|
|
485
|
+
} catch {
|
|
486
|
+
png?.catch(() => {});
|
|
487
|
+
message = "screenshotCopyFailed";
|
|
488
|
+
} finally {
|
|
489
|
+
copying = false;
|
|
340
490
|
}
|
|
491
|
+
if (button.isConnected) showCopyStatus(button, message, label);
|
|
492
|
+
else copyStatus.textContent = "";
|
|
493
|
+
copyTimeout = setTimeout(() => { copyStatus.textContent = ""; }, 4000);
|
|
494
|
+
}
|
|
341
495
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
before: formats.percent.format(position), after: formats.percent.format(1 - position),
|
|
359
|
-
}));
|
|
360
|
-
};
|
|
361
|
-
slider.addEventListener("input", update);
|
|
362
|
-
update();
|
|
363
|
-
const captions = el("figcaption", "compare-captions",
|
|
364
|
-
el("span", "cap", t("before")), el("span", "cap", t("after")));
|
|
365
|
-
captions.setAttribute("aria-hidden", "true");
|
|
366
|
-
comparison.append(handle, slider);
|
|
367
|
-
screenshots.replaceChildren(el("figure", "comparison-figure", captions, comparison));
|
|
368
|
-
} else {
|
|
369
|
-
screenshots.replaceChildren(el("div", "single", ...sides.map((side) => {
|
|
370
|
-
const label = t(side);
|
|
371
|
-
return el("figure", "", el("figcaption", "label", label), el("div", "thumb", picture(side, label)));
|
|
372
|
-
})));
|
|
496
|
+
function screenshotUrl(runId, path) {
|
|
497
|
+
return `./screenshots/${runId}/${encodeURIComponent(path.split("/")[1])}`;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function renderScreenshots(runId, step, reportImages) {
|
|
501
|
+
const screenshots = el("div", "screenshots");
|
|
502
|
+
const pair = el("div", "screenshot-pair");
|
|
503
|
+
let toggle;
|
|
504
|
+
let comparison;
|
|
505
|
+
const pictures = ["before", "after"].map((side) => {
|
|
506
|
+
const label = t(side);
|
|
507
|
+
const thumb = el("div", "thumb");
|
|
508
|
+
pair.append(el("figure", "", el("figcaption", "label", label), thumb));
|
|
509
|
+
if (!step[side]) {
|
|
510
|
+
thumb.append(el("div", "missing", t("noScreenshot")));
|
|
511
|
+
return null;
|
|
373
512
|
}
|
|
374
|
-
|
|
513
|
+
|
|
514
|
+
if (reportImages) {
|
|
515
|
+
const source = reportImages.get(step[side]);
|
|
516
|
+
if (source) {
|
|
517
|
+
const image = el("img", "shot");
|
|
518
|
+
image.alt = t("screenshotAlt", { label, action: step.action });
|
|
519
|
+
image.src = source;
|
|
520
|
+
thumb.append(image);
|
|
521
|
+
} else thumb.append(el("div", "missing", t("screenshotError")));
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
let preview;
|
|
526
|
+
const unavailable = () => {
|
|
527
|
+
if (!enlarge.isConnected) return;
|
|
528
|
+
const focus = document.activeElement;
|
|
529
|
+
const restoreFocus = thumb.contains(focus) || focus === toggle || preview?.open || comparison?.open;
|
|
530
|
+
preview?.close();
|
|
531
|
+
comparison?.close();
|
|
532
|
+
comparison?.remove();
|
|
533
|
+
toggle?.remove();
|
|
534
|
+
thumb.replaceChildren(el("div", "missing", t("screenshotError")));
|
|
535
|
+
if (restoreFocus) screenshots.focus({ preventScroll: true });
|
|
536
|
+
};
|
|
537
|
+
const picture = () => {
|
|
538
|
+
const img = el("img", "shot");
|
|
539
|
+
img.alt = t("screenshotAlt", { label, action: step.action });
|
|
540
|
+
img.addEventListener("error", unavailable, { once: true });
|
|
541
|
+
img.src = screenshotUrl(runId, step[side]);
|
|
542
|
+
return img;
|
|
543
|
+
};
|
|
544
|
+
const image = picture();
|
|
545
|
+
const enlarge = el("button", "shot-open", image);
|
|
546
|
+
enlarge.type = "button";
|
|
547
|
+
enlarge.setAttribute("aria-label", t("enlargeScreenshot", { label, action: step.action }));
|
|
548
|
+
enlarge.setAttribute("aria-haspopup", "dialog");
|
|
549
|
+
enlarge.addEventListener("click", () => {
|
|
550
|
+
const dialog = screenshotDialog(image.alt, image.alt, "closeScreenshot",
|
|
551
|
+
el("div", "image-viewport", picture()));
|
|
552
|
+
preview = dialog;
|
|
553
|
+
dialog.addEventListener("close", () => dialog.remove(), { once: true });
|
|
554
|
+
showScreenshotDialog(screenshots, dialog, enlarge);
|
|
555
|
+
});
|
|
556
|
+
const copy = iconControl(el("button", "icon-control shot-copy"), t("copyScreenshot", { label, action: step.action }),
|
|
557
|
+
"M8 8h12v12H8z M16 8V4H4v12h4");
|
|
558
|
+
copy.type = "button";
|
|
559
|
+
copy.addEventListener("click", () => copyScreenshot(image, copy, label));
|
|
560
|
+
thumb.append(enlarge, copy);
|
|
561
|
+
return picture;
|
|
562
|
+
});
|
|
375
563
|
|
|
376
564
|
screenshots.tabIndex = -1;
|
|
377
565
|
screenshots.setAttribute("role", "group");
|
|
378
566
|
screenshots.setAttribute("aria-label", t("screenshots"));
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
567
|
+
screenshots.append(pair);
|
|
568
|
+
if (step.note) screenshots.append(el("p", "note", step.note));
|
|
569
|
+
if (pictures.every(Boolean)) {
|
|
570
|
+
toggle = iconControl(el("button", "icon-control compare-toggle"), t("showSlider"),
|
|
571
|
+
"M9 4H4v5m11-5h5v5m0 6v5h-5m-6 0H4v-5m8-11v16");
|
|
572
|
+
toggle.type = "button";
|
|
573
|
+
toggle.setAttribute("aria-haspopup", "dialog");
|
|
574
|
+
toggle.addEventListener("click", () => showScreenshotDialog(screenshots,
|
|
575
|
+
comparison ??= renderComparison(step.action, pictures.map((picture) => picture())), toggle));
|
|
576
|
+
// Without a note, the toggle joins the After caption instead of taking a row of its own.
|
|
577
|
+
if (step.note) screenshots.append(toggle);
|
|
578
|
+
else pair.querySelectorAll("figcaption")[1].append(toggle);
|
|
579
|
+
} else if (!reportImages) pair.classList.add("single");
|
|
580
|
+
return el("div", "exhibit-body", screenshots);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function showScreenshotDialog(container, dialog, trigger) {
|
|
584
|
+
if (!dialog.isConnected) {
|
|
585
|
+
dialog.addEventListener("close", () => {
|
|
586
|
+
// A close event can arrive after the comparison has reopened.
|
|
587
|
+
if (!dialog.open && trigger.isConnected) trigger.focus({ preventScroll: true });
|
|
588
|
+
});
|
|
589
|
+
container.append(dialog);
|
|
590
|
+
}
|
|
591
|
+
dialog.showModal();
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function screenshotDialog(label, title, closeLabel, ...content) {
|
|
595
|
+
const close = el("button", "dialog-close", t(closeLabel));
|
|
596
|
+
close.type = "button";
|
|
597
|
+
close.autofocus = true;
|
|
598
|
+
const dialog = el("dialog", "screenshot-dialog",
|
|
599
|
+
el("header", "compare-head", el("h2", "", title), close), ...content);
|
|
600
|
+
dialog.setAttribute("aria-label", label);
|
|
601
|
+
close.addEventListener("click", () => dialog.close());
|
|
602
|
+
return dialog;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function renderComparison(action, images) {
|
|
606
|
+
const label = t("comparison", { action });
|
|
607
|
+
const handle = el("span", "handle");
|
|
608
|
+
handle.setAttribute("aria-hidden", "true");
|
|
609
|
+
const slider = el("input", "");
|
|
610
|
+
slider.type = "range";
|
|
611
|
+
slider.min = "0";
|
|
612
|
+
slider.max = "100";
|
|
613
|
+
slider.value = "50";
|
|
614
|
+
slider.setAttribute("aria-label", label);
|
|
615
|
+
const [before, after] = images;
|
|
616
|
+
after.classList.add("after");
|
|
617
|
+
const comparison = el("div", "comparison", ...images, handle, slider);
|
|
618
|
+
const dialog = screenshotDialog(label, action, "closeComparison",
|
|
619
|
+
el("div", "compare-captions label", el("span", "", t("before")), el("span", "", t("after"))),
|
|
620
|
+
el("div", "compare-viewport", comparison));
|
|
621
|
+
dialog.classList.add("compare-dialog");
|
|
622
|
+
const update = () => {
|
|
623
|
+
comparison.style.setProperty("--position", `${slider.value}%`);
|
|
624
|
+
const position = Number(slider.value) / 100;
|
|
625
|
+
slider.setAttribute("aria-valuetext", t("position", {
|
|
626
|
+
before: formats.percent.format(position), after: formats.percent.format(1 - position),
|
|
627
|
+
}));
|
|
628
|
+
};
|
|
629
|
+
const sizeFrame = () => {
|
|
630
|
+
const width = Math.max(before.naturalWidth, after.naturalWidth);
|
|
631
|
+
const height = Math.max(before.naturalHeight, after.naturalHeight);
|
|
632
|
+
if (width && height) comparison.style.setProperty("--capture-ratio", width / height);
|
|
633
|
+
};
|
|
634
|
+
for (const image of images) image.addEventListener("load", sizeFrame);
|
|
635
|
+
sizeFrame();
|
|
636
|
+
slider.addEventListener("input", update);
|
|
637
|
+
update();
|
|
638
|
+
return dialog;
|
|
383
639
|
}
|
|
384
640
|
|
|
385
641
|
function renderCheck(check) {
|
|
@@ -406,6 +662,7 @@ function renderCheck(check) {
|
|
|
406
662
|
}
|
|
407
663
|
|
|
408
664
|
function render(moveFocus = false) {
|
|
665
|
+
copyStatus.textContent = "";
|
|
409
666
|
document.title = `${t("caseFiles")} · alibai`;
|
|
410
667
|
if (loadFailed) {
|
|
411
668
|
app.replaceChildren(heading(t("caseFiles")), el("p", "error", t("loadError")));
|