@zenuml/core 3.46.0 → 3.46.2

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 (60) hide show
  1. package/.claude/skills/dia-scoring/SKILL.md +139 -0
  2. package/.claude/skills/dia-scoring/agents/openai.yaml +7 -0
  3. package/.claude/skills/dia-scoring/references/selectors-and-keys.md +253 -0
  4. package/.claude/skills/land-pr/SKILL.md +98 -0
  5. package/.claude/skills/ship-branch/SKILL.md +81 -0
  6. package/.claude/skills/submit-branch/SKILL.md +76 -0
  7. package/.claude/skills/validate-branch/SKILL.md +54 -0
  8. package/CLAUDE.md +1 -1
  9. package/bun.lock +25 -11
  10. package/cy/canonical-history.html +908 -0
  11. package/cy/compare-case.html +357 -0
  12. package/cy/compare-cases.js +824 -0
  13. package/cy/compare.html +35 -0
  14. package/cy/diff-algorithm.js +199 -0
  15. package/cy/element-report.html +705 -0
  16. package/cy/icons-test.html +29 -0
  17. package/cy/legacy-vs-html.html +291 -0
  18. package/cy/native-diff-ext/background.js +60 -0
  19. package/cy/native-diff-ext/bridge.js +26 -0
  20. package/cy/native-diff-ext/content.js +194 -0
  21. package/cy/parity-test.html +122 -0
  22. package/cy/return-in-nested-if.html +29 -0
  23. package/cy/svg-preview.html +56 -0
  24. package/cy/svg-test.html +21 -0
  25. package/cy/theme-default-test.html +28 -0
  26. package/dist/stats.html +1 -1
  27. package/dist/zenuml.esm.mjs +16352 -15223
  28. package/dist/zenuml.js +701 -575
  29. package/docs/ship-branch-skill-plan.md +134 -0
  30. package/docs/superpowers/plans/2026-03-23-svg-parity-features.md +283 -0
  31. package/index.html +568 -73
  32. package/package.json +15 -4
  33. package/scripts/analyze-compare-case/collect-data.mjs +991 -0
  34. package/scripts/analyze-compare-case/config.mjs +102 -0
  35. package/scripts/analyze-compare-case/geometry.mjs +101 -0
  36. package/scripts/analyze-compare-case/native-diff.mjs +224 -0
  37. package/scripts/analyze-compare-case/output.mjs +74 -0
  38. package/scripts/analyze-compare-case/panel-diff.mjs +114 -0
  39. package/scripts/analyze-compare-case/report.mjs +157 -0
  40. package/scripts/analyze-compare-case/residual-scopes.mjs +325 -0
  41. package/scripts/analyze-compare-case/scoring.mjs +816 -0
  42. package/scripts/analyze-compare-case.mjs +149 -0
  43. package/scripts/snapshot-dual.js +34 -34
  44. package/skills/dia-scoring/SKILL.md +129 -0
  45. package/skills/dia-scoring/agents/openai.yaml +7 -0
  46. package/skills/dia-scoring/references/selectors-and-keys.md +253 -0
  47. package/test-setup.ts +8 -0
  48. package/types/index.d.ts +56 -0
  49. package/vite.config.ts +4 -0
  50. package/dist/10029-icon-service-Function-Apps-ObflOLuF.js +0 -5
  51. package/dist/Res_AWS-Identity-Access-Management_IAM-Access-Analyzer_48-BPq60XMY.js +0 -11
  52. package/dist/Res_AWS-Lambda_Lambda-Function_48-Co38UB_2.js +0 -12
  53. package/dist/Res_Amazon-EC2_Instance_48-CRaqbNUl.js +0 -12
  54. package/dist/Res_Amazon-Simple-Notification-Service_Topic_48-q13mxUeM.js +0 -11
  55. package/dist/Res_Amazon-Simple-Queue-Service_Queue_48-D2-8gbFw.js +0 -11
  56. package/dist/Robustness_Diagram_Boundary-nYnmTPs8.js +0 -10
  57. package/dist/Robustness_Diagram_Control-DLNLoMxd.js +0 -11
  58. package/dist/Robustness_Diagram_Entity-Be3kcbIE.js +0 -11
  59. package/dist/actor-BMj_HFpo.js +0 -11
  60. package/dist/database-BKHQQWQK.js +0 -8
@@ -0,0 +1,157 @@
1
+ /*
2
+ * What this file does:
3
+ * Assembles the final report object from scored sections and residual attribution.
4
+ *
5
+ * High-level flow:
6
+ * - Pulls in semantic scoring results and residual hotspot attribution.
7
+ * - Builds the JSON report shape consumed by scripts and humans.
8
+ * - Produces concise summary lines for labels, numbers, arrows, icons, boxes,
9
+ * and residual scopes so the CLI can print a readable digest.
10
+ *
11
+ * This module is the boundary between raw analysis results and final report shape.
12
+ *
13
+ * Example input:
14
+ * `caseName`, extracted geometry, and the analyzer's local diff image.
15
+ *
16
+ * Example output:
17
+ * A single report object with JSON-friendly sections plus terminal summary arrays
18
+ * such as `summary`, `arrow_summary`, and `residual_scope_summary`.
19
+ */
20
+ import { buildResidualScopes } from "./residual-scopes.mjs";
21
+ import { buildScoredSections } from "./scoring.mjs";
22
+
23
+ function formatLetterSummary(letter) {
24
+ if (letter.dx == null || letter.dy == null) {
25
+ return `${letter.grapheme}: ambiguous`;
26
+ }
27
+ const dx = letter.dx.toFixed(2);
28
+ const dy = letter.dy.toFixed(2);
29
+ return `${letter.grapheme}: dx=${dx}px dy=${dy}px`;
30
+ }
31
+
32
+ function formatSectionSummary(prefix, item) {
33
+ const notes = [];
34
+ if (item.owner_text) {
35
+ notes.push(`owner=${item.owner_text}`);
36
+ }
37
+ if (item.html_text && item.svg_text && item.html_text !== item.svg_text) {
38
+ notes.push(`text_mismatch(html=${item.html_text} svg=${item.svg_text})`);
39
+ }
40
+ const noteSuffix = notes.length > 0 ? ` [${notes.join("; ")}]` : "";
41
+ if (!item.letters || item.letters.length === 0) {
42
+ return `${prefix}:${item.key.kind}:${item.key.text}${noteSuffix} -> ambiguous`;
43
+ }
44
+ return `${prefix}:${item.key.kind}:${item.key.text}${noteSuffix} -> ${item.letters.map(formatLetterSummary).join(", ")}`;
45
+ }
46
+
47
+ function formatArrowSummary(arrow) {
48
+ if (arrow.status !== "ok") {
49
+ return "ambiguous";
50
+ }
51
+ const parts = [
52
+ `left_dx=${arrow.left_dx.toFixed(2)}px`,
53
+ `right_dx=${arrow.right_dx.toFixed(2)}px`,
54
+ `width_dx=${arrow.width_dx.toFixed(2)}px`,
55
+ ];
56
+ if (arrow.key?.kind === "self") {
57
+ parts.push(`top_dy=${arrow.top_dy.toFixed(2)}px`);
58
+ parts.push(`bottom_dy=${arrow.bottom_dy.toFixed(2)}px`);
59
+ parts.push(`height_dy=${arrow.height_dy.toFixed(2)}px`);
60
+ }
61
+ return parts.join(" ");
62
+ }
63
+
64
+ function formatParticipantIconSummary(icon) {
65
+ const notes = [];
66
+ if (icon.label_text) {
67
+ notes.push(`label=${icon.label_text}`);
68
+ }
69
+ if (icon.anchor_kind) {
70
+ notes.push(`anchor=${icon.anchor_kind}`);
71
+ }
72
+ if (icon.presence && icon.presence.html !== icon.presence.svg) {
73
+ notes.push(`presence_mismatch(html=${icon.presence.html} svg=${icon.presence.svg})`);
74
+ }
75
+ const noteSuffix = notes.length > 0 ? ` [${notes.join("; ")}]` : "";
76
+ if (icon.status !== "ok") {
77
+ return `icon:${icon.name}${noteSuffix} -> ambiguous`;
78
+ }
79
+ return `icon:${icon.name}${noteSuffix} -> icon_dx=${icon.icon_dx.toFixed(2)}px icon_dy=${icon.icon_dy.toFixed(2)}px relative_dx=${icon.relative_dx.toFixed(2)}px relative_dy=${icon.relative_dy.toFixed(2)}px`;
80
+ }
81
+
82
+ function formatParticipantBoxSummary(box) {
83
+ if (box.status !== "ok") {
84
+ return `participant-box:${box.name} -> ambiguous`;
85
+ }
86
+ return `participant-box:${box.name} -> dx=${box.dx.toFixed(2)}px dy=${box.dy.toFixed(2)}px dw=${box.dw.toFixed(2)}px dh=${box.dh.toFixed(2)}px`;
87
+ }
88
+
89
+ function formatParticipantColorSummary(color) {
90
+ if (color.status !== "ok") {
91
+ return `participant-color:${color.name} -> ambiguous`;
92
+ }
93
+ return `participant-color:${color.name} -> bg(html=${color.html_background_color} svg=${color.svg_background_color}) text(html=${color.html_text_color} svg=${color.svg_text_color}) stereotype(html=${color.html_stereotype_color} svg=${color.svg_stereotype_color})`;
94
+ }
95
+
96
+ function formatGroupSummary(group) {
97
+ if (group.status !== "ok") {
98
+ return `participant-group:${group.name} -> ambiguous`;
99
+ }
100
+ const namePart = group.name_dx === null || group.name_dy === null
101
+ ? "name=ambiguous"
102
+ : `name_dx=${group.name_dx.toFixed(2)}px name_dy=${group.name_dy.toFixed(2)}px`;
103
+ return `participant-group:${group.name} -> dx=${group.dx.toFixed(2)}px dy=${group.dy.toFixed(2)}px dw=${group.dw.toFixed(2)}px dh=${group.dh.toFixed(2)}px ${namePart}`;
104
+ }
105
+
106
+ function formatOccurrenceSummary(occ) {
107
+ if (occ.status !== "ok") {
108
+ return `occurrence:${occ.participant}#${occ.idx} -> ambiguous`;
109
+ }
110
+ return `occurrence:${occ.participant}#${occ.idx} -> dx=${occ.dx.toFixed(2)}px dy=${occ.dy.toFixed(2)}px dw=${occ.dw.toFixed(2)}px dh=${occ.dh.toFixed(2)}px`;
111
+ }
112
+
113
+ function formatFragmentDividerSummary(div) {
114
+ if (div.status !== "ok") {
115
+ return `fragment-divider:#${div.idx} -> ambiguous`;
116
+ }
117
+ return `fragment-divider:#${div.idx} -> dx=${div.dx.toFixed(2)}px dy=${div.dy.toFixed(2)}px dw=${div.dw.toFixed(2)}px`;
118
+ }
119
+
120
+ export function buildReport(caseName, extracted, diffImage) {
121
+ const sections = buildScoredSections(extracted, diffImage);
122
+ const residualScopes = buildResidualScopes(extracted, diffImage);
123
+
124
+ return {
125
+ case: caseName,
126
+ labels: sections.labels,
127
+ numbers: sections.numbers,
128
+ arrows: sections.arrows,
129
+ participant_labels: sections.participantLabels,
130
+ participant_stereotypes: sections.participantStereotypes,
131
+ participant_icons: sections.participantIcons,
132
+ participant_boxes: sections.participantBoxes,
133
+ participant_colors: sections.participantColors,
134
+ comments: sections.comments,
135
+ participant_groups: sections.groups,
136
+ occurrences: sections.occurrences,
137
+ fragment_dividers: sections.fragmentDividers,
138
+ dividers: sections.dividers,
139
+ residual_scopes: residualScopes.scopes,
140
+ summary: sections.labels.map((label) => formatSectionSummary("label", label)),
141
+ number_summary: sections.numbers.map((number) => formatSectionSummary("number", number)),
142
+ arrow_summary: sections.arrows.map((arrow) => `arrow:${arrow.key.text} -> ${formatArrowSummary(arrow)}`),
143
+ participant_label_summary: sections.participantLabels.map((label) => formatSectionSummary("participant-label", label)),
144
+ participant_stereotype_summary: sections.participantStereotypes.map((label) => formatSectionSummary("participant-stereotype", label)),
145
+ participant_icon_summary: sections.participantIcons.map((icon) => formatParticipantIconSummary(icon)),
146
+ participant_box_summary: sections.participantBoxes.map((box) => formatParticipantBoxSummary(box)),
147
+ participant_color_summary: sections.participantColors.map((color) => formatParticipantColorSummary(color)),
148
+ comment_summary: sections.comments.map((comment) => formatSectionSummary("comment", comment)),
149
+ participant_group_summary: sections.groups.map((group) => formatGroupSummary(group)),
150
+ occurrence_summary: sections.occurrences.map((occ) => formatOccurrenceSummary(occ)),
151
+ fragment_divider_summary: sections.fragmentDividers.map((div) => formatFragmentDividerSummary(div)),
152
+ divider_summary: sections.dividers.map((d) => `divider:"${d.label}" dy=${d.dy ?? "?"} ${d.status}`),
153
+ residual_scope_summary: residualScopes.summary,
154
+ residual_scope_html_only_top: residualScopes.html_only_top,
155
+ residual_scope_svg_only_top: residualScopes.svg_only_top,
156
+ };
157
+ }
@@ -0,0 +1,325 @@
1
+ /*
2
+ * What this file does:
3
+ * Groups remaining diff pixels into residual hotspots and attributes them to nearby elements.
4
+ *
5
+ * High-level flow:
6
+ * - Scans the analyzer's local diff for connected html-only and svg-only clusters.
7
+ * - Builds candidate scope items from labels, arrows, participant headers, icons,
8
+ * boxes, and frame-level containers.
9
+ * - Picks the nearest and most specific target on each side for each cluster.
10
+ * - Produces concise residual summaries for terminal and JSON output.
11
+ *
12
+ * This module explains "where the remaining diff seems to belong" after the
13
+ * semantic scoring step.
14
+ *
15
+ * Example input:
16
+ * Extracted geometry plus a diff image containing `html-only` and `svg-only` pixels.
17
+ *
18
+ * Example output:
19
+ * `{ scopes, summary, html_only_top, svg_only_top }`
20
+ * with each scope carrying a bbox, centroid, and nearest HTML/SVG targets.
21
+ */
22
+ import { area, intersectionArea, rectBottom, rectRight, round } from "./geometry.mjs";
23
+
24
+ function scopePriority(category) {
25
+ switch (category) {
26
+ case "participant-icon":
27
+ return 8;
28
+ case "participant-stereotype":
29
+ case "label":
30
+ case "number":
31
+ case "comment":
32
+ case "participant-label":
33
+ return 7;
34
+ case "arrow":
35
+ case "fragment-divider":
36
+ return 6;
37
+ case "occurrence":
38
+ case "participant-box":
39
+ case "participant-group":
40
+ return 5;
41
+ case "frame-border":
42
+ return 2;
43
+ case "diagram-root":
44
+ return 1;
45
+ default:
46
+ return 0;
47
+ }
48
+ }
49
+
50
+ function pointInRect(point, rect) {
51
+ return point.x >= rect.x && point.x <= rectRight(rect) && point.y >= rect.y && point.y <= rectBottom(rect);
52
+ }
53
+
54
+ function distanceToRect(point, rect) {
55
+ const dx = point.x < rect.x ? rect.x - point.x : point.x > rectRight(rect) ? point.x - rectRight(rect) : 0;
56
+ const dy = point.y < rect.y ? rect.y - point.y : point.y > rectBottom(rect) ? point.y - rectBottom(rect) : 0;
57
+ return Math.hypot(dx, dy);
58
+ }
59
+
60
+ function formatScopeName(item) {
61
+ if (item.owner_text && item.text && item.owner_text !== item.text) {
62
+ return `${item.owner_text}:${item.text}`;
63
+ }
64
+ return item.name ?? item.text ?? item.kind ?? item.category ?? "unknown";
65
+ }
66
+
67
+ function buildScopeItems(side, extracted) {
68
+ const items = [];
69
+
70
+ function push(category, name, box, extra = {}) {
71
+ if (!box || box.w <= 0 || box.h <= 0) {
72
+ return;
73
+ }
74
+ items.push({
75
+ side,
76
+ category,
77
+ name,
78
+ box,
79
+ ...extra,
80
+ });
81
+ }
82
+
83
+ const sideKey = side === "html" ? "html" : "svg";
84
+ const labels = side === "html" ? extracted.htmlLabels : extracted.svgLabels;
85
+ const numbers = side === "html" ? extracted.htmlNumbers : extracted.svgNumbers;
86
+ const arrows = side === "html" ? extracted.htmlArrows : extracted.svgArrows;
87
+ const participants = side === "html" ? extracted.htmlParticipants : extracted.svgParticipants;
88
+ const comments = side === "html" ? extracted.htmlComments : extracted.svgComments;
89
+ const groups = side === "html" ? extracted.htmlGroups : extracted.svgGroups;
90
+ const occurrences = side === "html" ? (extracted.htmlOccurrences || []) : (extracted.svgOccurrences || []);
91
+ const fragmentDividers = side === "html" ? (extracted.htmlFragmentDividers || []) : (extracted.svgFragmentDividers || []);
92
+
93
+ for (const label of labels) {
94
+ push("label", formatScopeName(label), label.box, {
95
+ kind: label.kind,
96
+ text: label.text,
97
+ owner_text: label.ownerText ?? null,
98
+ });
99
+ }
100
+ for (const number of numbers) {
101
+ push("number", formatScopeName(number), number.box, {
102
+ kind: number.kind,
103
+ text: number.text,
104
+ owner_text: number.ownerText ?? null,
105
+ });
106
+ }
107
+ for (const arrow of arrows) {
108
+ push("arrow", formatScopeName(arrow), arrow.box, {
109
+ kind: arrow.kind,
110
+ text: arrow.text,
111
+ owner_text: arrow.labelText ?? null,
112
+ });
113
+ }
114
+ for (const comment of comments) {
115
+ push("comment", formatScopeName(comment), comment.box, {
116
+ kind: comment.kind,
117
+ text: comment.text,
118
+ });
119
+ }
120
+ for (const participant of participants) {
121
+ push("participant-box", participant.name, participant.participantBox, {
122
+ kind: "participant",
123
+ text: participant.labelText ?? participant.name,
124
+ owner_text: participant.name,
125
+ });
126
+ push("participant-label", participant.name, participant.labelBox, {
127
+ kind: "participant",
128
+ text: participant.labelText ?? participant.name,
129
+ owner_text: participant.name,
130
+ });
131
+ push("participant-stereotype", participant.name, participant.stereotypeBox, {
132
+ kind: "participant",
133
+ text: participant.stereotypeText ?? participant.name,
134
+ owner_text: participant.name,
135
+ });
136
+ push("participant-icon", participant.name, participant.iconBox, {
137
+ kind: "participant",
138
+ text: participant.labelText ?? participant.name,
139
+ owner_text: participant.name,
140
+ });
141
+ }
142
+ for (const group of groups) {
143
+ push("participant-group", group.name || "group", group.box, {
144
+ kind: "group",
145
+ text: group.name,
146
+ });
147
+ }
148
+ for (const occ of occurrences) {
149
+ push("occurrence", `${occ.participant}#${occ.idx}`, occ.box, {
150
+ kind: "occurrence",
151
+ text: occ.participant,
152
+ owner_text: occ.participant,
153
+ });
154
+ }
155
+ for (const div of fragmentDividers) {
156
+ push("fragment-divider", `divider#${div.idx}`, { x: div.x, y: div.y, w: div.width, h: 1 }, {
157
+ kind: "divider",
158
+ text: div.label || `divider#${div.idx}`,
159
+ });
160
+ }
161
+
162
+ if (sideKey === "html") {
163
+ push("diagram-root", "html-root", extracted.htmlRootBox, { kind: "root" });
164
+ } else {
165
+ push("frame-border", "frame-border", extracted.svgFrameBorderBox, { kind: "frame" });
166
+ push("diagram-root", "svg-root", extracted.svgRootBox, { kind: "root" });
167
+ }
168
+
169
+ return items;
170
+ }
171
+
172
+ function buildDiffClusters(diffImage, targetClass) {
173
+ const visited = new Uint8Array(diffImage.width * diffImage.height);
174
+ const clusters = [];
175
+ const offsets = [-1, 0, 1, 0, -1];
176
+
177
+ for (let index = 0; index < diffImage.classData.length; index++) {
178
+ if (visited[index] || diffImage.classData[index] !== targetClass) {
179
+ continue;
180
+ }
181
+ visited[index] = 1;
182
+ const queue = [index];
183
+ let head = 0;
184
+ let size = 0;
185
+ let sumX = 0;
186
+ let sumY = 0;
187
+ let left = diffImage.width;
188
+ let top = diffImage.height;
189
+ let right = -1;
190
+ let bottom = -1;
191
+
192
+ while (head < queue.length) {
193
+ const current = queue[head++];
194
+ const x = current % diffImage.width;
195
+ const y = Math.floor(current / diffImage.width);
196
+ size++;
197
+ sumX += x + 0.5;
198
+ sumY += y + 0.5;
199
+ left = Math.min(left, x);
200
+ top = Math.min(top, y);
201
+ right = Math.max(right, x);
202
+ bottom = Math.max(bottom, y);
203
+
204
+ for (let dir = 0; dir < 4; dir++) {
205
+ const nx = x + offsets[dir];
206
+ const ny = y + offsets[dir + 1];
207
+ if (nx < 0 || nx >= diffImage.width || ny < 0 || ny >= diffImage.height) {
208
+ continue;
209
+ }
210
+ const nextIndex = ny * diffImage.width + nx;
211
+ if (visited[nextIndex] || diffImage.classData[nextIndex] !== targetClass) {
212
+ continue;
213
+ }
214
+ visited[nextIndex] = 1;
215
+ queue.push(nextIndex);
216
+ }
217
+ }
218
+
219
+ clusters.push({
220
+ class: targetClass === 2 ? "html-only" : "svg-only",
221
+ size,
222
+ bbox: {
223
+ x: left,
224
+ y: top,
225
+ w: right - left + 1,
226
+ h: bottom - top + 1,
227
+ },
228
+ centroid: {
229
+ x: sumX / size,
230
+ y: sumY / size,
231
+ },
232
+ });
233
+ }
234
+
235
+ return clusters.sort((a, b) => b.size - a.size);
236
+ }
237
+
238
+ function pickScopeTarget(cluster, items) {
239
+ const centroid = cluster.centroid;
240
+ let best = null;
241
+ let bestScore = -Infinity;
242
+
243
+ for (const item of items) {
244
+ const contains = pointInRect(centroid, item.box);
245
+ const distance = distanceToRect(centroid, item.box);
246
+ const overlap = intersectionArea(cluster.bbox, item.box);
247
+ const score = (contains ? 10000 : 0)
248
+ + overlap * 10
249
+ - distance * 100
250
+ + scopePriority(item.category) * 1000
251
+ - area(item.box) * 0.01;
252
+
253
+ if (score > bestScore) {
254
+ bestScore = score;
255
+ best = {
256
+ category: item.category,
257
+ name: item.name,
258
+ kind: item.kind ?? null,
259
+ text: item.text ?? null,
260
+ owner_text: item.owner_text ?? null,
261
+ contains_centroid: contains,
262
+ overlap_area: round(overlap),
263
+ distance: round(distance),
264
+ box: {
265
+ x: round(item.box.x),
266
+ y: round(item.box.y),
267
+ w: round(item.box.w),
268
+ h: round(item.box.h),
269
+ },
270
+ };
271
+ }
272
+ }
273
+
274
+ return best;
275
+ }
276
+
277
+ function formatResidualScopeSummary(scope) {
278
+ const htmlTarget = scope.html_target
279
+ ? `${scope.html_target.category}:${scope.html_target.name}`
280
+ : "none";
281
+ const svgTarget = scope.svg_target
282
+ ? `${scope.svg_target.category}:${scope.svg_target.name}`
283
+ : "none";
284
+ return `${scope.class}:${scope.size}px @ (${scope.centroid.x.toFixed(1)},${scope.centroid.y.toFixed(1)}) -> html=${htmlTarget} svg=${svgTarget}`;
285
+ }
286
+
287
+ export function buildResidualScopes(extracted, diffImage) {
288
+ const htmlItems = buildScopeItems("html", extracted);
289
+ const svgItems = buildScopeItems("svg", extracted);
290
+ const clusters = [
291
+ ...buildDiffClusters(diffImage, 2),
292
+ ...buildDiffClusters(diffImage, 3),
293
+ ].sort((a, b) => b.size - a.size);
294
+
295
+ const residualScopes = clusters.map((cluster, index) => ({
296
+ rank: index + 1,
297
+ class: cluster.class,
298
+ size: cluster.size,
299
+ centroid: {
300
+ x: round(cluster.centroid.x),
301
+ y: round(cluster.centroid.y),
302
+ },
303
+ bbox: {
304
+ x: round(cluster.bbox.x),
305
+ y: round(cluster.bbox.y),
306
+ w: round(cluster.bbox.w),
307
+ h: round(cluster.bbox.h),
308
+ },
309
+ html_target: pickScopeTarget(cluster, htmlItems),
310
+ svg_target: pickScopeTarget(cluster, svgItems),
311
+ }));
312
+
313
+ const byClass = residualScopes.reduce((acc, scope) => {
314
+ acc[scope.class] = acc[scope.class] || [];
315
+ acc[scope.class].push(scope);
316
+ return acc;
317
+ }, {});
318
+
319
+ return {
320
+ scopes: residualScopes,
321
+ summary: residualScopes.slice(0, 20).map((scope) => formatResidualScopeSummary(scope)),
322
+ html_only_top: (byClass["html-only"] || []).slice(0, 10),
323
+ svg_only_top: (byClass["svg-only"] || []).slice(0, 10),
324
+ };
325
+ }