@whzxc/agent-design-gallery 0.14.1 → 0.15.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 (62) hide show
  1. package/README.md +26 -16
  2. package/package.json +1 -1
  3. package/public/access.css +15 -2
  4. package/public/app.js +708 -483
  5. package/public/arrangement-worker.js +7 -7
  6. package/public/arrangement.js +35 -30
  7. package/public/assets.js +60 -38
  8. package/public/auth.js +59 -4
  9. package/public/boards.js +124 -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 +26 -2
  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 +2 -0
  19. package/public/index.html +13 -9
  20. package/public/instance-actions.js +9 -2
  21. package/public/layout.js +156 -86
  22. package/public/selection.js +1 -1
  23. package/public/style.css +74 -152
  24. package/public/switcher.css +5 -4
  25. package/public/switcher.js +109 -34
  26. package/public/token-catalog.js +8 -3
  27. package/public/tokens.css +14 -1
  28. package/public/view-route.js +0 -1
  29. package/src/boards/board.mjs +30 -0
  30. package/src/boards/token-board.mjs +196 -0
  31. package/src/cli-output.mjs +8 -5
  32. package/src/cli.mjs +49 -29
  33. package/src/comments.mjs +293 -0
  34. package/src/http.mjs +2 -3
  35. package/src/hub/project-link.mjs +41 -0
  36. package/src/hub/registry.mjs +5 -0
  37. package/src/hub.mjs +14 -10
  38. package/src/link.mjs +13 -1
  39. package/src/server.mjs +57 -93
  40. package/src/service.mjs +46 -12
  41. package/src/toolkit/arch.mjs +3 -2
  42. package/src/toolkit/asset-rules.mjs +24 -1
  43. package/src/toolkit/commands.mjs +12 -7
  44. package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
  45. package/src/toolkit/diff-inputs.mjs +66 -30
  46. package/src/toolkit/diff.mjs +181 -39
  47. package/src/toolkit/impact-selection.mjs +25 -10
  48. package/src/toolkit/impact.mjs +32 -12
  49. package/src/toolkit/move-pairing.mjs +140 -0
  50. package/src/toolkit/project-index.mjs +2 -2
  51. package/src/toolkit/results.mjs +1 -1
  52. package/src/toolkit/review-document.mjs +435 -0
  53. package/src/toolkit/review-groups.mjs +29 -0
  54. package/src/toolkit/review-observation.mjs +131 -0
  55. package/src/toolkit/review-sheet.mjs +117 -0
  56. package/src/toolkit/review-specimens.mjs +60 -0
  57. package/src/toolkit/review.mjs +140 -0
  58. package/src/toolkit/runtime.mjs +1 -1
  59. package/src/toolkit/theme.mjs +16 -0
  60. package/public/annotations.js +0 -816
  61. package/public/labels.js +0 -122
  62. package/src/annotations.mjs +0 -238
@@ -0,0 +1,140 @@
1
+ import path from 'node:path';
2
+ import { relative, sourceDirectories, sourceFeature } from './project.mjs';
3
+ import { frameOwners } from './source-facts.mjs';
4
+
5
+ function sourcePaths(config) {
6
+ const design = relative(config, config.design), layers = sourceDirectories(config);
7
+ const designPath = source => path.posix.relative(design, source);
8
+ return { designPath, featurePath: source => sourceFeature(designPath(source), layers) };
9
+ }
10
+
11
+ function sourceRelations(inputs) {
12
+ const renames = new Map(inputs.renames?.map(rename => [rename.before, rename.after]));
13
+ const before = sourcePaths(inputs.before.config), after = sourcePaths(inputs.after.config);
14
+ const owned = new Map();
15
+ const partNames = (row, { designPath, featurePath }, frame) => {
16
+ if (!owned.has(row)) {
17
+ const source = designPath(row.source), feature = featurePath(row.source);
18
+ const owners = frame.owners ?? frameOwners(frame.html ?? '');
19
+ owned.set(row, new Set(owners.filter(owner =>
20
+ owner.source === source || (feature !== source && owner.source.startsWith(feature + '/')),
21
+ ).map(owner => owner.export)));
22
+ }
23
+ return owned.get(row);
24
+ };
25
+ return [
26
+ (old, current) => renames.get(old.source) === current.source,
27
+ (old, current) => {
28
+ const feature = after.featurePath(current.source);
29
+ return feature !== after.designPath(current.source) && before.designPath(old.source) === feature + '.tsx';
30
+ },
31
+ (old, current) => {
32
+ const currentParts = partNames(current, after, current.after);
33
+ return [...partNames(old, before, old.before)].some(name => currentParts.has(name));
34
+ },
35
+ ];
36
+ }
37
+
38
+ /** Strongest relation wins. Only mutually unique endpoints pair within each tier. */
39
+ export async function pairFrameMoves(rows, inputs, fingerprint, themes = ['light', 'dark']) {
40
+ const additions = rows.filter(row => row.status === 'added');
41
+ const removals = rows.filter(row => row.status === 'removed');
42
+ if (!additions.length || !removals.length) return rows;
43
+ const added = new Map(), pending = new Set();
44
+ for (const row of additions) {
45
+ const group = added.get(row.frame) ?? [];
46
+ group.push(row);
47
+ added.set(row.frame, group);
48
+ }
49
+ for (const old of removals) {
50
+ for (const current of added.get(old.frame) ?? []) {
51
+ if (old.source !== current.source) pending.add({ old, current });
52
+ }
53
+ }
54
+ const removed = new Set(), paired = new Map(), ambiguous = new Map();
55
+ const addCandidate = (row, candidate) => {
56
+ const candidates = ambiguous.get(row) ?? [];
57
+ candidates.push({ source: candidate.source, frame: candidate.frame });
58
+ ambiguous.set(row, candidates);
59
+ };
60
+ function resolve(edges, related) {
61
+ const candidates = [...edges].filter(({ old, current }) => related(old, current));
62
+ const left = new Map(), right = new Map();
63
+ for (const { old, current } of candidates) {
64
+ left.set(old, (left.get(old) ?? 0) + 1);
65
+ right.set(current, (right.get(current) ?? 0) + 1);
66
+ }
67
+ for (const { old, current } of candidates) {
68
+ if (left.get(old) === 1 && right.get(current) === 1) {
69
+ removed.add(old);
70
+ paired.set(current, {
71
+ ...current, before: old.before, previousSource: old.source, previousFrame: old.frame, status: 'matched',
72
+ matchKind: 'exact', matchCandidates: [],
73
+ change: { kind: 'direct', causes: [old.source, current.source].sort() },
74
+ });
75
+ } else {
76
+ addCandidate(old, current);
77
+ addCandidate(current, old);
78
+ }
79
+ }
80
+ // A weaker relation must not pick a winner among stronger ambiguous candidates.
81
+ for (const edge of edges) if (left.has(edge.old) || right.has(edge.current)) edges.delete(edge);
82
+ }
83
+
84
+ const relations = sourceRelations(inputs);
85
+ const fingerprints = new Map(themes.map(theme => [theme, new Map()]));
86
+ async function capture(candidates, theme) {
87
+ const saved = fingerprints.get(theme);
88
+ const missing = [...new Set(candidates)].filter(row => !saved.has(row));
89
+ if (missing.length) {
90
+ const captured = await fingerprint(missing, theme);
91
+ for (const row of missing) saved.set(row, captured.get(row));
92
+ }
93
+ return saved;
94
+ }
95
+ const endpoints = edges => [...edges].flatMap(({ old, current }) => [old, current]);
96
+ const identical = saved => (old, current) => saved.get(old) !== undefined && saved.get(old) === saved.get(current);
97
+
98
+ for (const related of relations) resolve(pending, related);
99
+ if (pending.size) {
100
+ const sameFirst = identical(await capture(endpoints(pending), themes[0]));
101
+ for (const edge of pending) if (!sameFirst(edge.old, edge.current)) pending.delete(edge);
102
+ if (pending.size) resolve(pending, identical(await capture(endpoints(pending), themes[1])));
103
+ }
104
+
105
+ const oldUnpaired = removals.filter(row => !removed.has(row));
106
+ const currentUnpaired = additions.filter(row => !paired.has(row));
107
+ if (oldUnpaired.length && currentUnpaired.length) {
108
+ const first = await capture([...oldUnpaired, ...currentUnpaired], themes[0]);
109
+ const byRender = new Map();
110
+ for (const current of currentUnpaired) {
111
+ const key = first.get(current);
112
+ if (key === undefined) continue;
113
+ const group = byRender.get(key) ?? [];
114
+ group.push(current);
115
+ byRender.set(key, group);
116
+ }
117
+ const renamed = new Set();
118
+ for (const old of oldUnpaired) {
119
+ for (const current of byRender.get(first.get(old)) ?? []) {
120
+ if (old.frame !== current.frame) renamed.add({ old, current });
121
+ }
122
+ }
123
+ if (renamed.size) {
124
+ const sameSecond = identical(await capture(endpoints(renamed), themes[1]));
125
+ for (const edge of renamed) if (!sameSecond(edge.old, edge.current)) renamed.delete(edge);
126
+ for (const related of relations) resolve(renamed, related);
127
+ resolve(renamed, () => true);
128
+ }
129
+ }
130
+ const identity = ({ source, frame }) => JSON.stringify([source, frame]);
131
+ const moved = new Set([...removed, ...paired.keys()].map(identity));
132
+ return rows.flatMap(row => {
133
+ if (removed.has(row)) return [];
134
+ if (paired.has(row)) return [paired.get(row)];
135
+ const entries = [...row.matchCandidates, ...(ambiguous.get(row) ?? [])];
136
+ const candidates = new Map(entries.map(candidate => [identity(candidate), candidate]).filter(([key]) => !moved.has(key)));
137
+ if (!ambiguous.has(row) && candidates.size === row.matchCandidates.length) return [row];
138
+ return [{ ...row, matchCandidates: [...candidates.values()], matchKind: candidates.size ? 'renamed_or_unknown' : 'unmatched' }];
139
+ });
140
+ }
@@ -184,8 +184,8 @@ export async function openProjectIndex(config, { stateDirectory = defaultStateDi
184
184
  try { text = await readFile(path.join(config.root, side), 'utf8'); } catch (error) { if (error.code !== 'ENOENT') throw error; }
185
185
  return cached('architecture', { source, text }, () => ({ source, sidecar: side, ...sidecar(text) }));
186
186
  },
187
- async relationships({ facts: supplied, projectPaths = false } = {}) {
188
- const assets = await Promise.all(inventory.tsx.map(async source => {
187
+ async relationships({ facts: supplied, projectPaths = false, sources = inventory.tsx } = {}) {
188
+ const assets = await Promise.all(sources.map(async source => {
189
189
  const facts = supplied?.get(source) ?? await this.source(source);
190
190
  if (projectPaths) return { path: source, imports: facts.imports };
191
191
  const designRelative = file => path.relative(config.design, path.join(config.root, file)).split(path.sep).join('/');
@@ -5,7 +5,7 @@ import { CliError, classifyError } from '../cli-output.mjs';
5
5
  /** @typedef {Location & {code: string, message: string}} Finding */
6
6
  /** @typedef {{project: string, readOnly: boolean, complete: boolean, impact: object | null, sources: string[], summary: {sources: number, frames: number, evaluations: number, problems: number}, findings: Finding[]}} CheckData */
7
7
  /** @typedef {{source: string, frame: string, theme: Theme, path: string, scale: number, width: number, height: number, pixelWidth: number, pixelHeight: number}} Capture */
8
- /** @typedef {{project: string, outputDirectory: string, complete: boolean, impact: object | null, base: {rev: string, sha: string} | null, captures: Capture[], deleted: string[]}} RenderData */
8
+ /** @typedef {{project: string, outputDirectory: string, complete: boolean, impact: object | null, base: {rev: string, sha: string} | null, themes: Theme[], captures: Capture[], deleted: string[]}} RenderData */
9
9
  /** @typedef {{source: string, frame: string, fixture: string, theme: Theme, settled: boolean, size: {design: [number, number], implementation: [number, number]}, matched: number, offBy2px: {text: string, dx: number, dy: number, dw: number, off: number}[], missing: string[], extra: string[], paths: {design: string, implementation: string, overlay: string, report: string, html: string}}} Comparison */
10
10
  /** @typedef {{project: string, complete: boolean, all: boolean, comparisons: Comparison[], skipped: {source: string, frame: string, reason: 'no_fixture'}[], summary: {frames: number, matched: number, offsets: number, missing: number, extra: number}, indexPath: string | null, summaryPath: string | null}} CompareData */
11
11
 
@@ -0,0 +1,435 @@
1
+ import { createHash } from 'node:crypto';
2
+
3
+ const escape = value => String(value ?? '').replace(/[&<>"']/g, char => ({
4
+ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;',
5
+ })[char]);
6
+ const label = ({ source, frame }) => `${source.replace(/^design\//, '').replace(/\.tsx$/, '')}#${frame}`;
7
+ const key = ({ source, frame }) => JSON.stringify([source, frame]);
8
+ const short = revision => revision?.slice(0, 10) ?? '—';
9
+ const countLabel = count => `${count} ${count === 1 ? 'frame' : 'frames'}`;
10
+ const icons = {
11
+ expand: '<svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 4H4v4m12-4h4v4m0 8v4h-4m-8 0H4v-4"/></svg>',
12
+ external: '<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 17 17 7M7 7h10v10"/></svg>',
13
+ close: '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="m6 6 12 12M6 18 18 6"/></svg>',
14
+ };
15
+
16
+ function originLabel(origin) {
17
+ const parts = [origin.layer, origin.chapter, origin.title].filter(Boolean);
18
+ return parts.map(part => `<span>${escape(part)}</span>`).join('<span class="crumb-separator" aria-hidden="true">/</span>');
19
+ }
20
+
21
+ function originHtml(origin) {
22
+ const content = `<span class="breadcrumbs">${originLabel(origin)}</span><strong>${escape(origin.frame)}${origin.href ? icons.external : ''}</strong>`;
23
+ return origin.href ? `<a class="origin" href="${escape(origin.href)}" target="_blank" rel="noopener" title="Open in ADG">${content}</a>` : `<span class="origin">${content}</span>`;
24
+ }
25
+
26
+ export function reviewDocument(report, { properties, styles, templates }) {
27
+ const { title, theme, base, head, cards, counts, groups, removed, moved, failures } = report;
28
+ const byKey = new Map(cards.map(card => [key(card), card]));
29
+ const added = cards.filter(card => card.status === 'added');
30
+ const direct = cards.filter(card => card.status === 'changed' && card.change?.kind !== 'inherited');
31
+ const cssText = value => value.replace(/<\/style/gi, '<\\/style');
32
+ const sections = [
33
+ { id: 'added', title: 'Added', count: counts.added, html: () => added.map(card => cardHtml(card)).join('') },
34
+ { id: 'direct', title: 'Direct changes', count: counts.direct, html: () => direct.map(card => cardHtml(card)).join('') },
35
+ { id: 'inherited', title: 'Inherited changes', count: counts.inherited, html: () => groups.map((group, index) => inheritedHtml(group, index, byKey)).join('') },
36
+ { id: 'removed', title: 'Removed', count: counts.removed, html: () => namesHtml(removed.map(frame => originHtml(frame.origin))) },
37
+ { id: 'moved', title: 'Moved', count: counts.moved, html: () => namesHtml(moved.map(({ before, after }) =>
38
+ `${originHtml(before)}<span aria-hidden="true">→</span>${originHtml(after)}`)) },
39
+ ].filter(section => section.count > 0);
40
+ const script = `(${mountPreviews.toString()})();`;
41
+ const hash = createHash('sha256').update(script).digest('base64');
42
+ const metadata = JSON.stringify(cards.map(({ before, after, difference }) => ({ before, after, difference: Boolean(difference) })));
43
+ return `<!doctype html>
44
+ <html lang="en" data-theme="${theme}">
45
+ <head>
46
+ <meta charset="utf-8">
47
+ <meta name="viewport" content="width=device-width, initial-scale=1">
48
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-${hash}'; style-src 'unsafe-inline'; img-src data:; font-src data:; base-uri 'none'; form-action 'none'">
49
+ <title>${escape(title)} · Design review</title>
50
+ <style>${cssText(properties.join('\n'))}${documentStyles}</style>
51
+ </head>
52
+ <body>
53
+ <header id="top" class="masthead">
54
+ <div class="shell masthead-inner">
55
+ <h1 title="${escape(title)} · Design review">${escape(title)} <span>Review</span></h1>
56
+ <div class="revisions" aria-label="Compared revisions">
57
+ <code title="Base ${escape(base)}">${short(base)}</code><span class="revision-arrow" aria-hidden="true">→</span>
58
+ <code title="Working tree ${escape(head)}">${short(head)}</code>
59
+ </div>
60
+ <span class="theme-label">${theme === 'dark' ? 'Dark' : 'Light'} theme</span>
61
+ </div>
62
+ </header>
63
+ <div class="shell layout">
64
+ <main>
65
+ ${failures.length ? `<section class="failures" role="alert"><h2>Some sources could not be built</h2><ul>${failures.map(failure =>
66
+ `<li><code>${escape(failure.source)}</code> (${escape(failure.side)}) · ${escape(failure.message)}</li>`).join('')}</ul></section>` : ''}
67
+ ${sections.map(({ id, title, count, html }) => `<section id="${id}" data-section="${id}" aria-labelledby="heading-${id}">
68
+ <header class="section-head"><h2 id="heading-${id}">${title}</h2><span>${countLabel(count)}</span></header>
69
+ <div class="section-body">${html()}</div>
70
+ </section>`).join('')}
71
+ ${sections.length ? '' : '<p>No changed frames.</p>'}
72
+ </main>
73
+ </div>
74
+ <dialog id="frame-zoom" aria-labelledby="zoom-title">
75
+ <header class="zoom-header">
76
+ <div id="zoom-title"></div>
77
+ <div class="zoom-actions" aria-label="Zoom controls">
78
+ <button type="button" data-zoom="out" aria-label="Zoom out">−</button>
79
+ <output id="zoom-scale"></output>
80
+ <button type="button" data-zoom="in" aria-label="Zoom in">+</button>
81
+ <button type="button" data-zoom="fit">Fit</button>
82
+ <button type="button" data-zoom="actual">100%</button>
83
+ <button type="button" data-zoom="close" aria-label="Close enlarged frame">${icons.close}</button>
84
+ </div>
85
+ </header>
86
+ <div class="zoom-modes" role="group" aria-label="Frame comparison" id="zoom-modes"></div>
87
+ <div class="zoom-panes" id="zoom-panes"></div>
88
+ </dialog>
89
+ <script id="review-data" type="application/json">${metadata}</script>
90
+ ${styles.map((style, index) => `<template id="style-${index}"><style>${cssText(style)}</style></template>`).join('\n')}
91
+ ${templates.join('\n')}
92
+ ${cards.filter(card => card.difference).map(card => `<template id="difference-${card.index}"><img src="${escape(card.difference)}" alt="Changed pixels in ${escape(label(card))}"></template>`).join('\n')}
93
+ <script>${script}</script>
94
+ </body>
95
+ </html>`;
96
+ }
97
+
98
+ function namesHtml(items) {
99
+ return `<ul class="names">${items.map(item => `<li>${item}</li>`).join('')}</ul>`;
100
+ }
101
+
102
+ function cardHtml(card, role) {
103
+ const id = `review-${card.index}`;
104
+ const added = card.status === 'added';
105
+ const panes = added ? ['after'] : ['before', 'after', ...(card.difference ? ['difference'] : [])];
106
+ const size = (preview) => `${Math.round(preview.width)} × ${Math.round(preview.height)}`;
107
+ const dimensions = card.after ? (card.before && size(card.before) !== size(card.after)
108
+ ? `${size(card.before)} → ${size(card.after)}` : size(card.after)) : '';
109
+ return `<article class="frame-card" id="${id}" data-card="${card.index}" data-status="${card.status}"
110
+ data-source="${escape(card.source)}" data-frame="${escape(card.frame)}" ${role ? `data-role="${role.toLowerCase()}"` : ''} aria-labelledby="${id}-title">
111
+ <header class="card-head">
112
+ <h3 id="${id}-title">${originHtml(card.origin)}</h3>
113
+ <div class="card-meta">${role ? `<span class="role-label">${role}</span>` : ''}${dimensions ? `<span class="dimensions" aria-label="Frame size in CSS pixels">${dimensions}</span>` : ''}
114
+ <button type="button" class="enlarge" data-enlarge="${added ? 'after' : 'compare'}" aria-label="Enlarge ${escape(card.origin.frame)}">${icons.expand}<span>Enlarge</span></button>
115
+ </div>
116
+ </header>
117
+ <div class="panes" style="--panes:${panes.length}">
118
+ ${panes.map(side => `<figure data-side="${side}"><figcaption>
119
+ <span>${side[0].toUpperCase() + side.slice(1)}</span>
120
+ ${side === 'before' && card.previousOrigin ? `<small>${escape(card.previousOrigin.title)} · ${escape(card.previousOrigin.frame)}</small>` : ''}
121
+ ${side === 'difference' && card.differentPixels ? `<small>${card.differentPixels.toLocaleString('en-US')} px changed</small>` : ''}
122
+ </figcaption><div class="stage">${card[side] ? `<button type="button" class="pane-trigger" data-enlarge="${side}" aria-label="Enlarge ${side} · ${escape(card.origin.frame)}" title="Enlarge ${side}">${icons.expand}</button>` : '<span class="absent">Absent at base</span>'}</div></figure>`).join('')}
123
+ </div>
124
+ </article>`;
125
+ }
126
+
127
+ function inheritedHtml(group, index, byKey) {
128
+ const representative = key(group.representative);
129
+ const outliers = group.outliers.map(key).filter(value => value !== representative);
130
+ const featured = new Set([representative, ...outliers]);
131
+ const rest = group.frames.map(key).filter(value => !featured.has(value));
132
+ return `<section class="inherited-group" data-group="${index}" aria-labelledby="group-${index}">
133
+ <header class="group-head"><h3 id="group-${index}">${group.causes.length ? group.causes.map(cause => `<code>${escape(cause)}</code>`).join('') : 'Shared dependencies'}</h3><span>${countLabel(group.frames.length)}</span></header>
134
+ <div class="group-body">
135
+ ${cardHtml(byKey.get(representative), 'Representative')}
136
+ ${outliers.map(value => cardHtml(byKey.get(value), 'Outlier')).join('')}
137
+ ${rest.length ? `<details><summary>${countLabel(rest.length)} more</summary><div class="members">${rest.map(value => cardHtml(byKey.get(value))).join('')}</div></details>` : ''}
138
+ </div>
139
+ </section>`;
140
+ }
141
+
142
+ function mountPreviews() {
143
+ const data = JSON.parse(document.getElementById('review-data').textContent);
144
+ const cards = [...document.querySelectorAll('[data-card]')];
145
+ const sheetCache = new Map();
146
+ const pending = new Set();
147
+ const zoom = document.getElementById('frame-zoom');
148
+ const modes = document.getElementById('zoom-modes');
149
+ const zoomPanes = document.getElementById('zoom-panes');
150
+ const zoomTitle = document.getElementById('zoom-title');
151
+ const zoomScale = document.getElementById('zoom-scale');
152
+ const zoomNames = { compare: 'Compare', before: 'Before', after: 'After', difference: 'Difference' };
153
+ let activeZoom;
154
+ function specimen(preview) {
155
+ const host = document.createElement('div');
156
+ host.className = 'specimen';
157
+ const width = Math.ceil(preview.width), height = Math.ceil(preview.height);
158
+ host.style.width = width + 'px';
159
+ host.style.height = height + 'px';
160
+ for (const [unit, value] of Object.entries({ vw: width, vh: height, vmin: Math.min(width, height), vmax: Math.max(width, height) })) {
161
+ host.style.setProperty('--review-' + unit, value / 100 + 'px');
162
+ }
163
+ if (!sheetCache.has(preview.style)) {
164
+ const sheet = new CSSStyleSheet();
165
+ const css = document.getElementById('style-' + preview.style).content.firstElementChild.textContent;
166
+ sheet.replaceSync('review-document,review-body{display:block}review-document{min-height:100%}' + css);
167
+ sheetCache.set(preview.style, sheet);
168
+ }
169
+ const root = host.attachShadow({ mode: 'open' });
170
+ root.adoptedStyleSheets = [sheetCache.get(preview.style)];
171
+ root.append(document.getElementById('frame-' + preview.template).content.cloneNode(true));
172
+ return host;
173
+ }
174
+
175
+ function makePlane(index, side) {
176
+ const plane = document.createElement('div');
177
+ plane.className = 'plane';
178
+ if (side === 'difference') plane.append(document.getElementById('difference-' + index).content.cloneNode(true));
179
+ else plane.append(specimen(data[index][side]));
180
+ return plane;
181
+ }
182
+
183
+ function sizesFor(preview, side) {
184
+ const pair = side === 'difference' || side === 'compare';
185
+ const frames = pair ? [preview.before, preview.after].filter(Boolean) : [preview[side]];
186
+ return { width: Math.ceil(Math.max(...frames.map(frame => frame.width))), height: Math.ceil(Math.max(...frames.map(frame => frame.height))) };
187
+ }
188
+
189
+ function fit(card) {
190
+ const { before, after } = data[Number(card.dataset.card)];
191
+ const stages = [...card.querySelectorAll('.stage')];
192
+ const width = Math.ceil(Math.max(before?.width ?? 0, after?.width ?? 0));
193
+ const height = Math.ceil(Math.max(before?.height ?? 0, after?.height ?? 0));
194
+ const available = Math.min(...stages.map(stage => stage.clientWidth)) - 28;
195
+ if (!width || !height || available <= 0) return;
196
+ const scale = Math.min(1, available / width, 360 / height);
197
+ card.style.setProperty('--preview-scale', scale);
198
+ card.style.setProperty('--plane-width', Math.ceil(width * scale) + 'px');
199
+ card.style.setProperty('--plane-height', Math.ceil(height * scale) + 'px');
200
+ }
201
+
202
+ function mount(card) {
203
+ if (card.dataset.mounted || card.closest('details:not([open])')) return;
204
+ card.dataset.mounted = 'true';
205
+ const index = Number(card.dataset.card), preview = data[index];
206
+ const decodes = [];
207
+ for (const pane of card.querySelectorAll('[data-side]')) {
208
+ const side = pane.dataset.side;
209
+ if (!preview[side]) continue;
210
+ const plane = makePlane(index, side);
211
+ const images = plane.firstElementChild.shadowRoot?.querySelectorAll('img') ?? plane.querySelectorAll('img');
212
+ decodes.push(...[...images].map(image => image.decode()));
213
+ pane.querySelector('.stage').prepend(plane);
214
+ }
215
+ fit(card);
216
+ Promise.allSettled([document.fonts.ready, ...decodes]).then(() => {
217
+ requestAnimationFrame(() => requestAnimationFrame(() => { card.dataset.ready = 'true'; }));
218
+ });
219
+ }
220
+
221
+ let queued = false;
222
+ const near = new IntersectionObserver(entries => {
223
+ for (const entry of entries) {
224
+ if (entry.isIntersecting) pending.add(entry.target);
225
+ else pending.delete(entry.target);
226
+ }
227
+ if (!queued && pending.size) {
228
+ queued = true;
229
+ requestAnimationFrame(() => {
230
+ queued = false;
231
+ for (const card of pending) {
232
+ mount(card);
233
+ if (card.dataset.mounted) near.unobserve(card);
234
+ }
235
+ pending.clear();
236
+ });
237
+ }
238
+ }, { rootMargin: '280px 0px' });
239
+ const sizes = new ResizeObserver(entries => { for (const entry of entries) fit(entry.target); });
240
+ for (const card of cards) { fit(card); sizes.observe(card); near.observe(card); }
241
+
242
+ function fitZoom() {
243
+ if (!zoom.open || !activeZoom) return;
244
+ const preview = data[activeZoom.index];
245
+ const { width, height } = sizesFor(preview, activeZoom.mode);
246
+ const stages = [...zoomPanes.querySelectorAll('.zoom-stage')];
247
+ const fit = Math.max(.02, Math.min(2, ...stages.flatMap(stage => [(stage.clientWidth - 18) / width, (stage.clientHeight - 18) / height])));
248
+ const scale = activeZoom.scale ?? fit;
249
+ activeZoom.shown = scale;
250
+ zoomScale.value = Math.round(scale * 100) + '%';
251
+ zoomPanes.style.setProperty('--preview-scale', scale);
252
+ zoomPanes.style.setProperty('--plane-width', Math.ceil(width * scale) + 'px');
253
+ zoomPanes.style.setProperty('--plane-height', Math.ceil(height * scale) + 'px');
254
+ }
255
+
256
+ function showMode(mode) {
257
+ activeZoom.mode = mode;
258
+ activeZoom.scale = null;
259
+ for (const button of modes.children) button.setAttribute('aria-pressed', String(button.dataset.mode === mode));
260
+ const sides = mode === 'compare' ? activeZoom.sides : [mode];
261
+ zoomPanes.style.setProperty('--zoom-panes', sides.length);
262
+ zoomPanes.replaceChildren(...sides.map(side => {
263
+ const pane = document.createElement('figure');
264
+ pane.dataset.side = side;
265
+ const caption = document.createElement('figcaption');
266
+ caption.textContent = zoomNames[side];
267
+ const stage = document.createElement('div'), surface = document.createElement('div');
268
+ stage.className = 'zoom-stage';
269
+ surface.className = 'zoom-surface';
270
+ stage.setAttribute('tabindex', '0');
271
+ stage.setAttribute('aria-label', zoomNames[side] + ' preview');
272
+ surface.append(makePlane(activeZoom.index, side));
273
+ stage.append(surface);
274
+ pane.append(caption, stage);
275
+ return pane;
276
+ }));
277
+ fitZoom();
278
+ }
279
+
280
+ function openZoom(card, control) {
281
+ const index = Number(card.dataset.card);
282
+ const sides = ['before', 'after', 'difference'].filter(side => data[index][side]);
283
+ const allowed = sides.length > 1 ? ['compare', ...sides] : sides;
284
+ activeZoom = { index, sides, control };
285
+ zoomTitle.replaceChildren(card.querySelector('.origin').cloneNode(true));
286
+ modes.replaceChildren(...allowed.map(mode => {
287
+ const button = document.createElement('button');
288
+ button.type = 'button';
289
+ button.dataset.mode = mode;
290
+ button.textContent = zoomNames[mode];
291
+ button.addEventListener('click', () => showMode(mode));
292
+ return button;
293
+ }));
294
+ modes.hidden = allowed.length === 1;
295
+ zoom.showModal();
296
+ showMode(allowed.includes(control.dataset.enlarge) ? control.dataset.enlarge : allowed[0]);
297
+ zoom.querySelector('[data-zoom="close"]').focus();
298
+ document.documentElement.classList.add('zoom-open');
299
+ }
300
+
301
+ for (const card of cards) card.addEventListener('click', event => {
302
+ const control = event.target.closest('[data-enlarge]');
303
+ if (control) openZoom(card, control);
304
+ });
305
+ zoom.querySelector('.zoom-actions').addEventListener('click', event => {
306
+ const control = event.target.closest('[data-zoom]');
307
+ if (!control || !activeZoom) return;
308
+ const { zoom: action } = control.dataset;
309
+ if (action === 'close') { zoom.close(); return; }
310
+ if (action === 'fit') activeZoom.scale = null;
311
+ if (action === 'actual') activeZoom.scale = 1;
312
+ if (action === 'in') activeZoom.scale = Math.min(4, activeZoom.shown * 1.25);
313
+ if (action === 'out') activeZoom.scale = Math.max(.02, activeZoom.shown / 1.25);
314
+ fitZoom();
315
+ });
316
+ zoom.addEventListener('close', () => {
317
+ document.documentElement.classList.remove('zoom-open');
318
+ zoomPanes.replaceChildren();
319
+ activeZoom?.control.focus();
320
+ activeZoom = null;
321
+ });
322
+ const zoomSizes = new ResizeObserver(fitZoom);
323
+ zoomSizes.observe(zoomPanes);
324
+
325
+ function revealAnchor() {
326
+ const target = document.getElementById(location.hash.slice(1));
327
+ const group = target?.closest('details');
328
+ if (group && !group.open) {
329
+ group.open = true;
330
+ requestAnimationFrame(() => target.scrollIntoView());
331
+ }
332
+ }
333
+ window.addEventListener('hashchange', revealAnchor);
334
+ revealAnchor();
335
+ }
336
+
337
+ const documentStyles = `
338
+ :root{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color-scheme:light;
339
+ --page:#f4f5f7;--top:#fff;--panel:#fff;--group:#eef0f3;--well:#edf0f4;--line:#d8dde5;--ink:#171d27;--muted:#596679;
340
+ --accent:#284b9e;--nav-tint:#e7edf9;--positive:#266844;--warning:#8b4c18;}
341
+ :root[data-theme="dark"]{color-scheme:dark;--page:#11141a;--top:#181c24;--panel:#1b2029;--group:#151a22;--well:#101319;
342
+ --line:#313a49;--ink:#eff3f9;--muted:#a5b0c2;--accent:#afc4ff;--nav-tint:#232e47;--positive:#8ed2ab;--warning:#f0bb80;}
343
+ *,*::before,*::after{box-sizing:border-box}
344
+ body{margin:0;background:var(--page);color:var(--ink);font-size:14px;line-height:1.5}
345
+ h1,h2,h3,p,ul,figure{margin:0} a{color:inherit;text-decoration:none}
346
+ code,.dimensions,#zoom-scale{font:12px/1.5 ui-monospace,"SF Mono",Menlo,monospace}
347
+ :focus-visible{outline:2px solid var(--accent);outline-offset:3px}
348
+ .shell{max-width:1680px;margin-inline:auto;padding-inline:clamp(16px,2.6vw,42px)}
349
+ .masthead{background:var(--top);border-bottom:1px solid var(--line)}
350
+ .masthead-inner{min-height:55px;padding-block:8px;display:grid;grid-template-columns:minmax(0,1fr) auto auto;align-items:center;gap:14px}
351
+ h1{min-width:0;font-size:17px;letter-spacing:-.025em;line-height:1.3;font-weight:670;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
352
+ h1 span{font-size:13px;font-weight:500;letter-spacing:0;color:var(--muted);margin-left:7px}
353
+ .revisions{display:flex;align-items:center;gap:9px;color:var(--muted);font-size:12px;white-space:nowrap}
354
+ .revisions code{color:var(--muted)}
355
+ .revision-arrow{color:var(--accent)}
356
+ .theme-label{line-height:1;white-space:nowrap;color:var(--muted);border-left:1px solid var(--line);padding-left:14px;font-size:11px}
357
+ .layout{padding-block:21px 72px}
358
+ main{min-width:0;display:grid;gap:42px}
359
+ [data-section],.frame-card{scroll-margin-top:24px}
360
+ .section-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin-bottom:13px;padding-bottom:10px;border-bottom:1px solid var(--line)}
361
+ .section-head h2{font-size:22px;letter-spacing:-.025em;font-weight:650}
362
+ #added .section-head h2{color:var(--positive)}
363
+ .section-head>span,.group-head>span{color:var(--muted);font-size:12px;white-space:nowrap}
364
+ .section-body,.members,.group-body{display:grid;gap:14px;min-width:0}
365
+ #added .section-body{grid-template-columns:repeat(2,minmax(0,1fr));align-items:stretch}
366
+ #added .frame-card,#added .panes figure{display:flex;flex-direction:column}
367
+ #added .panes{flex:1;align-items:stretch}
368
+ #added .stage{flex:1}
369
+ .frame-card,.inherited-group{border:1px solid var(--line);border-radius:11px;min-width:0;overflow:hidden}
370
+ .frame-card{background:var(--panel);--plane-height:0px}
371
+ .frame-card:target{border-color:var(--accent)}
372
+ .card-head{padding:11px 13px;min-height:60px;display:flex;justify-content:space-between;align-items:center;gap:8px 14px;border-bottom:1px solid var(--line)}
373
+ .card-head h3{min-width:0}
374
+ .origin{display:grid;gap:3px;min-width:0;overflow-wrap:anywhere}
375
+ .origin strong{color:var(--ink);font-size:15px;font-weight:640;line-height:1.25}
376
+ .origin strong svg{display:inline-block;vertical-align:-2px;margin-left:5px;color:var(--accent)}
377
+ a.origin:hover strong{color:var(--accent)}
378
+ .breadcrumbs{display:flex;align-items:baseline;flex-wrap:wrap;gap:1px 7px;color:var(--muted);font-size:11px;font-weight:500;line-height:1.3}
379
+ .crumb-separator{color:var(--muted);opacity:.65}
380
+ .card-meta{display:flex;gap:7px 10px;align-items:center;flex-wrap:wrap;justify-content:flex-end;color:var(--muted);flex:none}
381
+ .dimensions{font-size:11px;white-space:nowrap}
382
+ .role-label{font-size:10px;color:var(--accent);border:1px solid var(--line);border-radius:999px;padding:0 6px}
383
+ [data-role="outlier"] .role-label{color:var(--warning)}
384
+ button{font:inherit;color:inherit}
385
+ .enlarge,.zoom-actions button,.zoom-modes button{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:30px;padding:4px 9px;
386
+ border:1px solid var(--line);border-radius:6px;background:var(--panel);color:var(--ink);cursor:pointer;font-size:12px;white-space:nowrap}
387
+ .enlarge:hover,.zoom-actions button:hover,.zoom-modes button:hover,.zoom-modes button[aria-pressed="true"]{background:var(--nav-tint);color:var(--accent)}
388
+ .panes{display:grid;grid-template-columns:repeat(var(--panes),minmax(0,1fr));gap:10px;padding:11px 12px 12px;align-items:start}
389
+ .panes figure{min-width:0}
390
+ figcaption{display:flex;justify-content:space-between;align-items:baseline;gap:4px 8px;flex-wrap:wrap;font-size:11px;font-weight:630;color:var(--muted);padding:0 1px 6px}
391
+ figcaption small{font-size:10px;font-weight:400;font-variant-numeric:tabular-nums}
392
+ .stage{position:relative;display:grid;place-items:center;min-height:max(128px,calc(24px + var(--plane-height)));overflow:hidden;border:1px solid var(--line);border-radius:7px;background:var(--well)}
393
+ .pane-trigger{display:block;position:absolute;inset:0;border:0;background:transparent;color:var(--ink);cursor:zoom-in}
394
+ .pane-trigger svg{position:absolute;top:7px;right:7px;box-sizing:content-box;border:1px solid var(--line);border-radius:6px;padding:5px;background:var(--panel);opacity:0}
395
+ .pane-trigger:hover svg,.pane-trigger:focus-visible svg{opacity:1}
396
+ .pane-trigger:focus-visible{outline-offset:-3px}
397
+ .plane{position:relative;width:var(--plane-width);height:var(--plane-height)}
398
+ .plane>img{display:block;width:100%;height:100%;object-fit:contain;object-position:top left}
399
+ .specimen{position:absolute;inset:0 auto auto 0;overflow:hidden;transform:scale(var(--preview-scale));transform-origin:top left;font:16px/normal "Times New Roman",serif;color:initial}
400
+ .absent{color:var(--muted);font-size:12px}
401
+ .inherited-group{background:var(--group)}
402
+ .group-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:13px 15px;border-bottom:1px solid var(--line)}
403
+ .group-head h3{display:flex;flex-wrap:wrap;gap:5px 10px;min-width:0;font-size:13px}
404
+ .group-head code{color:var(--accent);overflow-wrap:anywhere}
405
+ .group-body{padding:12px}
406
+ details{min-width:0}
407
+ summary{cursor:pointer;color:var(--accent);font-size:12px;padding:6px 4px}
408
+ .members{margin-top:7px}
409
+ .names{list-style:none;padding:10px 13px;display:grid;gap:9px;border:1px solid var(--line);border-radius:9px;background:var(--panel)}
410
+ .names li{display:flex;gap:9px;flex-wrap:wrap;overflow-wrap:anywhere}
411
+ .failures{padding:14px 17px;border:1px solid var(--warning);border-radius:9px}
412
+ .failures h2{font-size:16px;color:var(--warning)}
413
+ .zoom-open{overflow:hidden}
414
+ #frame-zoom{padding:0;color:var(--ink);background:var(--top);border:1px solid var(--line);border-radius:12px;width:min(1640px,calc(100% - 34px));
415
+ height:calc(100% - 34px);max-width:none;max-height:none;overflow:hidden}
416
+ #frame-zoom[open]{display:flex;flex-direction:column}
417
+ #frame-zoom::backdrop{background:rgb(5 8 13 / 78%)}
418
+ .zoom-header{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:12px 15px;border-bottom:1px solid var(--line)}
419
+ #zoom-title{min-width:0}
420
+ .zoom-actions{display:flex;align-items:center;gap:6px;flex:none}
421
+ .zoom-actions button[data-zoom="close"]{margin-left:4px;min-width:32px}
422
+ #zoom-scale{min-width:38px;text-align:center;color:var(--muted)}
423
+ .zoom-modes{display:flex;gap:5px;flex-wrap:wrap;padding:9px 15px 0}
424
+ .zoom-modes[hidden]{display:none}
425
+ .zoom-modes button{min-height:28px}
426
+ .zoom-panes{min-height:0;flex:1;display:grid;grid-template-columns:repeat(var(--zoom-panes,1),minmax(0,1fr));gap:10px;padding:12px 15px 15px}
427
+ .zoom-panes figure{display:flex;flex-direction:column;min-width:0;min-height:0}
428
+ .zoom-stage{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;background:var(--well);border:1px solid var(--line);border-radius:7px}
429
+ .zoom-surface{width:max(100%,calc(var(--plane-width) + 16px));min-height:max(100%,calc(var(--plane-height) + 16px));display:grid;place-items:center}
430
+ @media(max-width:1000px){.card-head{flex-wrap:wrap}.card-meta{justify-content:flex-start}}
431
+ @media(max-width:760px){.layout{padding-top:14px}.panes{gap:7px}.section-head h2{font-size:20px}.zoom-header{flex-wrap:wrap}}
432
+ @media(max-width:540px){.panes,#added .section-body{grid-template-columns:minmax(0,1fr)}.theme-label{display:none}.masthead-inner{grid-template-columns:minmax(0,1fr) auto;gap:8px}
433
+ .revisions{gap:5px}.revisions code{font-size:9px}h1{font-size:15px}h1 span{font-size:11px}.card-meta{width:100%}.enlarge{margin-left:auto}
434
+ .group-body{padding:9px}.section-head{margin-bottom:10px}.zoom-panes{grid-template-columns:1fr}.zoom-actions{flex-wrap:wrap}}
435
+ `;
@@ -0,0 +1,29 @@
1
+ /** Group inherited changes without copying their frame entries or image payloads. */
2
+ export function groupReview(review) {
3
+ const changed = review.sections?.changed ?? [];
4
+ const byCause = new Map();
5
+ let direct = 0;
6
+ for (const frame of changed) {
7
+ if (frame.change?.kind !== 'inherited') {
8
+ direct++;
9
+ continue;
10
+ }
11
+ const causes = [...new Set(frame.change.causes)].sort();
12
+ const key = JSON.stringify(causes);
13
+ if (!byCause.has(key)) byCause.set(key, { causes, frames: [] });
14
+ byCause.get(key).frames.push(frame);
15
+ }
16
+ const area = frame => Math.max(0, ...frame.themes.map(row => row.differentPixels ?? 0));
17
+ const groups = [...byCause.values()].map(group => {
18
+ // Preserve source order for equal areas, including the two middle members.
19
+ const ordered = group.frames.map(frame => ({ frame, area: area(frame) }))
20
+ .sort((a, b) => a.area - b.area);
21
+ const middle = Math.floor(ordered.length / 2);
22
+ const medianArea = ordered.length % 2 ? ordered[middle].area
23
+ : (ordered[middle - 1].area + ordered[middle].area) / 2;
24
+ const representative = group.frames.reduce((selected, frame) =>
25
+ Math.abs(area(frame) - medianArea) < Math.abs(area(selected) - medianArea) ? frame : selected);
26
+ return { ...group, representative, outliers: group.frames.filter(frame => area(frame) > 2 * medianArea), medianArea };
27
+ });
28
+ return { ...review, counts: { ...review.counts, direct, inherited: changed.length - direct }, groups };
29
+ }