@getchomp/mcp 0.0.0-stage → 0.2.42
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.md +15 -2
- package/dist/conventionsReference.d.ts +84 -0
- package/dist/conventionsReference.js +313 -0
- package/dist/designSystem/astScanner.d.ts +153 -0
- package/dist/designSystem/astScanner.js +2014 -0
- package/dist/designSystem/baseline.d.ts +65 -0
- package/dist/designSystem/baseline.js +136 -0
- package/dist/designSystem/color.d.ts +35 -0
- package/dist/designSystem/color.js +265 -0
- package/dist/designSystem/config.d.ts +183 -0
- package/dist/designSystem/config.js +469 -0
- package/dist/designSystem/contrast.d.ts +55 -0
- package/dist/designSystem/contrast.js +377 -0
- package/dist/designSystem/cssParser.d.ts +63 -0
- package/dist/designSystem/cssParser.js +469 -0
- package/dist/designSystem/merges.d.ts +57 -0
- package/dist/designSystem/merges.js +94 -0
- package/dist/designSystem/preprocessors.d.ts +46 -0
- package/dist/designSystem/preprocessors.js +1108 -0
- package/dist/designSystem/presentation.d.ts +45 -0
- package/dist/designSystem/presentation.js +796 -0
- package/dist/designSystem/styleVectors.d.ts +27 -0
- package/dist/designSystem/styleVectors.js +484 -0
- package/dist/designSystem/tokens.d.ts +39 -0
- package/dist/designSystem/tokens.js +409 -0
- package/dist/designSystem/topology.d.ts +64 -0
- package/dist/designSystem/topology.js +254 -0
- package/dist/designSystem/types.d.ts +857 -0
- package/dist/designSystem/types.js +113 -0
- package/dist/designSystem/typography.d.ts +25 -0
- package/dist/designSystem/typography.js +244 -0
- package/dist/designSystem/uiShapes.d.ts +74 -0
- package/dist/designSystem/uiShapes.js +285 -0
- package/dist/designSystem/valueClusters.d.ts +76 -0
- package/dist/designSystem/valueClusters.js +281 -0
- package/dist/designSystemPlugin.d.ts +321 -0
- package/dist/designSystemPlugin.js +4730 -0
- package/dist/enrichNodesPlugin.d.ts +160 -0
- package/dist/enrichNodesPlugin.js +957 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1298 -0
- package/dist/intelligence.d.ts +502 -0
- package/dist/intelligence.js +3058 -0
- package/dist/pluginRunner.d.ts +364 -0
- package/dist/pluginRunner.js +1096 -0
- package/dist/plugins/design-system/index.d.ts +14 -0
- package/dist/plugins/design-system/index.js +241 -0
- package/dist/plugins/enrich-nodes/index.d.ts +388 -0
- package/dist/plugins/enrich-nodes/index.js +697 -0
- package/dist/plugins/index.d.ts +15 -0
- package/dist/plugins/index.js +20 -0
- package/dist/plugins/local-shims/index.d.ts +121 -0
- package/dist/plugins/local-shims/index.js +237 -0
- package/dist/shimsPlugin.d.ts +134 -0
- package/dist/shimsPlugin.js +1392 -0
- package/package.json +38 -3
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/presentation.ts
|
|
3
|
+
*
|
|
4
|
+
* Builds the Plugin Presentation Contract (`@getchomp/core` → `pluginPresentation.ts`) for the
|
|
5
|
+
* design-system plugin: what the HUD card and the package / component inspector sections show.
|
|
6
|
+
* The UI renders this generically; nothing here knows about React and nothing in the UI knows
|
|
7
|
+
* about design-system payload keys ([PAT-VIS-36], [PAT-DS-11]).
|
|
8
|
+
*
|
|
9
|
+
* Every number is traceable: findings carry counts, truncation is stated (`totalCount`),
|
|
10
|
+
* and "no evidence" is `null` / "n/a", never zero.
|
|
11
|
+
*/
|
|
12
|
+
import { PLUGIN_PRESENTATION_PAYLOAD_KEY, PLUGIN_PRESENTATION_VERSION, capForPresentation, } from "@getchomp/core";
|
|
13
|
+
const LIST_CAP = 40;
|
|
14
|
+
const VISIBLE = 6;
|
|
15
|
+
function ratioTone(v) {
|
|
16
|
+
if (v === null)
|
|
17
|
+
return "muted";
|
|
18
|
+
return v >= 80 ? "good" : v >= 60 ? "warn" : "bad";
|
|
19
|
+
}
|
|
20
|
+
function pctMetric(id, label, value, hint, rawItems, emptyText) {
|
|
21
|
+
const { items, totalCount } = capForPresentation(rawItems, LIST_CAP);
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
label,
|
|
25
|
+
value,
|
|
26
|
+
unit: "%",
|
|
27
|
+
tone: ratioTone(value),
|
|
28
|
+
hint: value === null ? `No evidence in this package: ${hint}` : hint,
|
|
29
|
+
...(items.length > 0
|
|
30
|
+
? { items, maxVisible: VISIBLE, totalCount }
|
|
31
|
+
: { emptyText }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function gradeBadge(score, grade) {
|
|
35
|
+
if (score === null || grade === "N/A") {
|
|
36
|
+
return {
|
|
37
|
+
text: "N/A",
|
|
38
|
+
tone: "muted",
|
|
39
|
+
tooltip: "Not enough evidence to grade: fewer than two pillars could be measured.",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
text: `${score}/100 (${grade})`,
|
|
44
|
+
tone: ratioTone(score),
|
|
45
|
+
tooltip: "Mean of the measured pillars (token adherence, atom adoption, dryness, encapsulation).",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function formatStylingConvention(c) {
|
|
49
|
+
switch (c) {
|
|
50
|
+
case "css-classes":
|
|
51
|
+
return "CSS";
|
|
52
|
+
case "css-modules":
|
|
53
|
+
return "CSS Modules";
|
|
54
|
+
case "css-in-js":
|
|
55
|
+
return "CSS-in-JS";
|
|
56
|
+
case "pixi-canvas":
|
|
57
|
+
return "Canvas 2D";
|
|
58
|
+
case "inline-style":
|
|
59
|
+
return "Inline";
|
|
60
|
+
default:
|
|
61
|
+
return "Tailwind";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function formatComposabilityKind(kind) {
|
|
65
|
+
switch (kind) {
|
|
66
|
+
case "outer-margin-on-reusable":
|
|
67
|
+
case "root-margin":
|
|
68
|
+
return "Outer margin";
|
|
69
|
+
case "fixed-dimension-on-reusable":
|
|
70
|
+
case "fixed-width":
|
|
71
|
+
return "Fixed width";
|
|
72
|
+
case "cross-tier-upward-import":
|
|
73
|
+
case "forbidden-import":
|
|
74
|
+
return "Cross-layer import";
|
|
75
|
+
default:
|
|
76
|
+
return kind;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function packageView(report, shortKey) {
|
|
80
|
+
const pkg = report.system.packages.find((p) => {
|
|
81
|
+
const label = p.name?.replace(/^@[^/]+\//, "") ?? p.dir.split("/").pop() ?? p.dir;
|
|
82
|
+
return p.frontend && label === shortKey;
|
|
83
|
+
});
|
|
84
|
+
const dir = pkg?.dir;
|
|
85
|
+
return {
|
|
86
|
+
key: shortKey,
|
|
87
|
+
dir,
|
|
88
|
+
components: report.components.filter((c) => c.packageName === shortKey),
|
|
89
|
+
inPackageFile: (f) => dir === undefined || dir === "." || f.startsWith(`${dir}/`),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Package-level presentation
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
export function buildPackagePresentation(report, shortKey, packageScore, pillars, _baseline, _records) {
|
|
96
|
+
const view = packageView(report, shortKey);
|
|
97
|
+
const comps = view.components;
|
|
98
|
+
const labels = new Set(comps.map((c) => c.label));
|
|
99
|
+
const byLabel = new Map();
|
|
100
|
+
for (const c of comps)
|
|
101
|
+
byLabel.set(c.label, c);
|
|
102
|
+
// ---- per-package finding collections ----
|
|
103
|
+
const arbitrary = comps.flatMap((c) => c.arbitraryTailwind);
|
|
104
|
+
const primitives = comps.flatMap((c) => c.primitiveScaleSkips);
|
|
105
|
+
const inlineLits = comps.flatMap((c) => c.inlineStyleLiterals);
|
|
106
|
+
const canvasLits = comps.flatMap((c) => c.canvasProvenance.literals);
|
|
107
|
+
const tsLits = comps.flatMap((c) => c.literalValues.filter((l) => l.surface !== "tailwind-arbitrary"));
|
|
108
|
+
const cssLits = report.diagnostics.hardcodedCssLiterals.filter((l) => view.inPackageFile(l.filePath));
|
|
109
|
+
const bypassed = report.atomicConsolidation.flatMap((a) => a.instances
|
|
110
|
+
.filter((i) => view.inPackageFile(i.filePath))
|
|
111
|
+
.map((i) => ({
|
|
112
|
+
atomTarget: a.atomName,
|
|
113
|
+
bypassingComponent: i.componentName,
|
|
114
|
+
filePath: i.filePath,
|
|
115
|
+
lineNumber: i.lineNumber,
|
|
116
|
+
snippet: i.snippet,
|
|
117
|
+
recommendation: a.existingSharedComponent
|
|
118
|
+
? `Use the shared <${a.existingSharedComponent.name}> (${a.existingSharedComponent.filePath}).`
|
|
119
|
+
: `Extract a shared <${a.atomName}> atom.`,
|
|
120
|
+
})));
|
|
121
|
+
const invariants = comps.flatMap((c) => c.invariantViolations);
|
|
122
|
+
const composability = comps.flatMap((c) => c.composabilityIssues);
|
|
123
|
+
const overrides = report.alignmentAudit.callSiteOverrides.filter((o) => labels.has(o.parentComponent));
|
|
124
|
+
const clones = report.dryAudit.structuralJsxClones.filter((g) => g.occurrences.some((o) => labels.has(o.componentName)));
|
|
125
|
+
const twins = report.alignmentAudit.parallelTwins.filter((t) => t.components.some((c) => labels.has(c.label)));
|
|
126
|
+
const undef = report.diagnostics.undefinedTokens.filter((u) => u.occurrences.some((o) => view.inPackageFile(o.filePath)));
|
|
127
|
+
const contrastFailures = report.diagnostics.contrastFailures;
|
|
128
|
+
const hardcodedCount = inlineLits.length + canvasLits.length + tsLits.length + cssLits.length;
|
|
129
|
+
const issueCount = hardcodedCount +
|
|
130
|
+
arbitrary.length +
|
|
131
|
+
primitives.length +
|
|
132
|
+
bypassed.length +
|
|
133
|
+
invariants.length +
|
|
134
|
+
composability.length +
|
|
135
|
+
undef.length +
|
|
136
|
+
contrastFailures.length +
|
|
137
|
+
clones.length +
|
|
138
|
+
twins.length +
|
|
139
|
+
overrides.length;
|
|
140
|
+
// ---- 1. High-level line items for "Token usage" ----
|
|
141
|
+
const tokenItems = [];
|
|
142
|
+
for (const u of undef) {
|
|
143
|
+
tokenItems.push({
|
|
144
|
+
label: u.name,
|
|
145
|
+
detail: `Undefined token · ${u.occurrenceCount} ${u.occurrenceCount === 1 ? "use" : "uses"}`,
|
|
146
|
+
tone: "bad",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
for (const cf of contrastFailures) {
|
|
150
|
+
tokenItems.push({
|
|
151
|
+
label: `${cf.foregroundToken} / ${cf.backgroundToken}`,
|
|
152
|
+
detail: "Low contrast",
|
|
153
|
+
tone: "bad",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const compTokenFindings = [];
|
|
157
|
+
for (const c of comps) {
|
|
158
|
+
const arbCount = c.arbitraryTailwind.length;
|
|
159
|
+
const primCount = c.primitiveScaleSkips.length;
|
|
160
|
+
const litCount = c.inlineStyleLiterals.length +
|
|
161
|
+
c.canvasProvenance.literals.length +
|
|
162
|
+
c.literalValues.filter((l) => l.surface !== "tailwind-arbitrary").length +
|
|
163
|
+
c.invariantViolations.length;
|
|
164
|
+
const total = arbCount + primCount + litCount;
|
|
165
|
+
if (total === 0)
|
|
166
|
+
continue;
|
|
167
|
+
const parts = [];
|
|
168
|
+
if (arbCount > 0)
|
|
169
|
+
parts.push(`${arbCount} Tailwind`);
|
|
170
|
+
if (primCount > 0)
|
|
171
|
+
parts.push(`${primCount} palette`);
|
|
172
|
+
if (litCount > 0)
|
|
173
|
+
parts.push(`${litCount} hardcoded`);
|
|
174
|
+
compTokenFindings.push({
|
|
175
|
+
count: total,
|
|
176
|
+
item: {
|
|
177
|
+
label: c.label,
|
|
178
|
+
detail: parts.join(" · "),
|
|
179
|
+
tone: "warn",
|
|
180
|
+
entityId: c.entityId,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
compTokenFindings.sort((a, b) => b.count - a.count);
|
|
185
|
+
for (const entry of compTokenFindings) {
|
|
186
|
+
tokenItems.push(entry.item);
|
|
187
|
+
}
|
|
188
|
+
const cssByFile = new Map();
|
|
189
|
+
for (const l of cssLits) {
|
|
190
|
+
const base = l.filePath.split("/").pop() ?? l.filePath;
|
|
191
|
+
cssByFile.set(base, (cssByFile.get(base) ?? 0) + 1);
|
|
192
|
+
}
|
|
193
|
+
for (const [file, count] of [...cssByFile.entries()].sort((a, b) => b[1] - a[1])) {
|
|
194
|
+
tokenItems.push({
|
|
195
|
+
label: file,
|
|
196
|
+
detail: `${count} hardcoded CSS`,
|
|
197
|
+
tone: "warn",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// ---- 2. High-level line items for "Shared component reuse" ----
|
|
201
|
+
const atomItems = [];
|
|
202
|
+
const atoms = report.atomicConsolidation.filter((a) => a.instances.some((i) => view.inPackageFile(i.filePath)));
|
|
203
|
+
for (const a of atoms) {
|
|
204
|
+
const rawInPkg = a.instances.filter((i) => view.inPackageFile(i.filePath));
|
|
205
|
+
if (rawInPkg.length === 0)
|
|
206
|
+
continue;
|
|
207
|
+
const hostNames = [...new Set(rawInPkg.map((i) => i.componentName))];
|
|
208
|
+
const where = hostNames.length <= 2
|
|
209
|
+
? hostNames.join(", ")
|
|
210
|
+
: `${hostNames.slice(0, 2).join(", ")} +${hostNames.length - 2}`;
|
|
211
|
+
const sharedEntityId = a.existingSharedComponent
|
|
212
|
+
? byLabel.get(a.existingSharedComponent.name)?.entityId
|
|
213
|
+
: undefined;
|
|
214
|
+
atomItems.push({
|
|
215
|
+
label: a.existingSharedComponent?.name ?? a.atomName,
|
|
216
|
+
detail: `${rawInPkg.length} raw in ${where}`,
|
|
217
|
+
tone: "warn",
|
|
218
|
+
...(sharedEntityId ? { entityId: sharedEntityId } : {}),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// ---- 3. High-level line items for "No duplicate UI" ----
|
|
222
|
+
const duplicateItems = [];
|
|
223
|
+
for (const t of twins) {
|
|
224
|
+
duplicateItems.push({
|
|
225
|
+
label: t.components.map((c) => c.label).join(", "),
|
|
226
|
+
detail: `Similar ${t.concept.toLowerCase()}`,
|
|
227
|
+
tone: "info",
|
|
228
|
+
entityId: t.components[0]?.entityId,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
for (const g of clones) {
|
|
232
|
+
const cleanName = g.suggestedComponentName.replace(/^Repeated/, "") || g.suggestedComponentName;
|
|
233
|
+
const hosts = [...new Set(g.occurrences.map((o) => o.componentName))];
|
|
234
|
+
const where = hosts.length <= 2
|
|
235
|
+
? hosts.join(", ")
|
|
236
|
+
: `${hosts.slice(0, 2).join(", ")} +${hosts.length - 2}`;
|
|
237
|
+
const firstComp = byLabel.get(g.occurrences[0]?.componentName ?? "");
|
|
238
|
+
duplicateItems.push({
|
|
239
|
+
label: cleanName,
|
|
240
|
+
detail: `${g.occurrenceCount}× in ${where}`,
|
|
241
|
+
tone: "info",
|
|
242
|
+
...(firstComp ? { entityId: firstComp.entityId } : {}),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
// ---- 4. High-level line items for "Clean component props" ----
|
|
246
|
+
const propItems = [];
|
|
247
|
+
const overrideGroups = new Map();
|
|
248
|
+
for (const o of overrides) {
|
|
249
|
+
const key = `${o.parentComponent}→${o.childComponent}`;
|
|
250
|
+
const prev = overrideGroups.get(key);
|
|
251
|
+
if (prev) {
|
|
252
|
+
prev.count++;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
overrideGroups.set(key, {
|
|
256
|
+
parent: o.parentComponent,
|
|
257
|
+
child: o.childComponent,
|
|
258
|
+
count: 1,
|
|
259
|
+
entityId: byLabel.get(o.parentComponent)?.entityId,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
for (const g of overrideGroups.values()) {
|
|
264
|
+
propItems.push({
|
|
265
|
+
label: `${g.parent} → ${g.child}`,
|
|
266
|
+
detail: g.count > 1 ? `Style override (×${g.count})` : "Style override",
|
|
267
|
+
tone: "warn",
|
|
268
|
+
...(g.entityId ? { entityId: g.entityId } : {}),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
for (const c of comps) {
|
|
272
|
+
if (c.composabilityIssues.length === 0)
|
|
273
|
+
continue;
|
|
274
|
+
const kinds = [
|
|
275
|
+
...new Set(c.composabilityIssues.map((i) => formatComposabilityKind(i.kind))),
|
|
276
|
+
];
|
|
277
|
+
propItems.push({
|
|
278
|
+
label: c.label,
|
|
279
|
+
detail: kinds.join(" · "),
|
|
280
|
+
tone: "warn",
|
|
281
|
+
entityId: c.entityId,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const metrics = [
|
|
285
|
+
pctMetric("tokenAdherence", "Token usage", pillars.tokenAdherence, "Share of styling decisions routed through tokens instead of hardcoded literals.", tokenItems, pillars.tokenAdherence === null
|
|
286
|
+
? "No styling decisions detected in this package."
|
|
287
|
+
: "All styling uses design tokens."),
|
|
288
|
+
pctMetric("atomAdoption", "Shared component reuse", pillars.atomAdoption, "Shared-atom call sites vs raw elements that should be that atom.", atomItems, pillars.atomAdoption === null
|
|
289
|
+
? "No shared atom candidates detected in this package."
|
|
290
|
+
: "All primitives use shared components."),
|
|
291
|
+
pctMetric("dryness", "No duplicate UI", pillars.dryness, "Share of components outside any repeated-structure or parallel-component group.", duplicateItems, pillars.dryness === null
|
|
292
|
+
? "Not enough components to evaluate duplication."
|
|
293
|
+
: "No duplicate UI or similar components."),
|
|
294
|
+
pctMetric("encapsulation", "Clean component props", pillars.encapsulation, "Share of component call sites without style / literal overrides.", propItems, pillars.encapsulation === null
|
|
295
|
+
? "No component call sites to evaluate."
|
|
296
|
+
: "All component call sites use clean props."),
|
|
297
|
+
];
|
|
298
|
+
const inventory = [
|
|
299
|
+
["Pages", comps.filter((c) => c.atomicTier === "ROUTE" || c.atomicTier === "TEMPLATE").length],
|
|
300
|
+
["Organisms", comps.filter((c) => c.atomicTier === "ORGANISM").length],
|
|
301
|
+
["Molecules", comps.filter((c) => c.atomicTier === "MOLECULE").length],
|
|
302
|
+
["Atoms", comps.filter((c) => c.atomicTier === "ATOM").length],
|
|
303
|
+
];
|
|
304
|
+
const nonZeroInventory = inventory.filter(([, n]) => n > 0);
|
|
305
|
+
const pkgStylings = [
|
|
306
|
+
...new Set(comps.flatMap((c) => c.stylingConventions.map(formatStylingConvention))),
|
|
307
|
+
];
|
|
308
|
+
const basicItems = [
|
|
309
|
+
{
|
|
310
|
+
label: "Components",
|
|
311
|
+
value: nonZeroInventory.length > 0
|
|
312
|
+
? nonZeroInventory.map(([l, n]) => `${n} ${l}`).join(" · ")
|
|
313
|
+
: `${comps.length} components`,
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
label: "Tokens",
|
|
317
|
+
value: report.summary.totalDefinedTokens === 0
|
|
318
|
+
? "0 defined tokens"
|
|
319
|
+
: `${report.summary.totalDefinedTokens} (${[
|
|
320
|
+
report.summary.primitiveTokenCount > 0 ? `${report.summary.primitiveTokenCount} primitive` : "",
|
|
321
|
+
report.summary.semanticTokenCount > 0 ? `${report.summary.semanticTokenCount} semantic` : "",
|
|
322
|
+
report.summary.componentTokenCount > 0 ? `${report.summary.componentTokenCount} component` : "",
|
|
323
|
+
report.summary.themeBridgeTokenCount > 0 ? `${report.summary.themeBridgeTokenCount} @theme` : "",
|
|
324
|
+
]
|
|
325
|
+
.filter(Boolean)
|
|
326
|
+
.join(" · ")})`,
|
|
327
|
+
},
|
|
328
|
+
...(pkgStylings.length > 0
|
|
329
|
+
? [{ label: "Styling", value: pkgStylings.join(" · ") }]
|
|
330
|
+
: []),
|
|
331
|
+
];
|
|
332
|
+
const sections = [
|
|
333
|
+
{
|
|
334
|
+
id: "design-system",
|
|
335
|
+
title: "Design system",
|
|
336
|
+
priority: 1,
|
|
337
|
+
blocks: [
|
|
338
|
+
{ kind: "keyValue", items: basicItems },
|
|
339
|
+
{ kind: "metrics", items: metrics },
|
|
340
|
+
],
|
|
341
|
+
},
|
|
342
|
+
];
|
|
343
|
+
const spotlightViews = buildSpotlightViewsForPackage(shortKey, comps, bypassed, overrides, clones, twins);
|
|
344
|
+
return {
|
|
345
|
+
version: PLUGIN_PRESENTATION_VERSION,
|
|
346
|
+
generatedAt: new Date().toISOString(),
|
|
347
|
+
summary: {
|
|
348
|
+
status: issueCount === 0 ? "ok" : "warn",
|
|
349
|
+
badge: gradeBadge(packageScore.score, packageScore.grade),
|
|
350
|
+
issueCount,
|
|
351
|
+
metrics,
|
|
352
|
+
...(spotlightViews.length > 0 ? { views: spotlightViews } : {}),
|
|
353
|
+
},
|
|
354
|
+
sections,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function buildSpotlightViewsForPackage(shortKey, comps, bypassed, overrides, clones, twins) {
|
|
358
|
+
const byLabel = new Map();
|
|
359
|
+
for (const c of comps)
|
|
360
|
+
byLabel.set(c.label, c);
|
|
361
|
+
const views = [];
|
|
362
|
+
// 1. One-off Tailwind / primitive scale skips
|
|
363
|
+
{
|
|
364
|
+
const nodes = [];
|
|
365
|
+
const annotations = {};
|
|
366
|
+
let totalCount = 0;
|
|
367
|
+
for (const c of comps) {
|
|
368
|
+
const arb = c.arbitraryTailwind;
|
|
369
|
+
const prim = c.primitiveScaleSkips;
|
|
370
|
+
const count = arb.length + prim.length;
|
|
371
|
+
if (count === 0)
|
|
372
|
+
continue;
|
|
373
|
+
totalCount += count;
|
|
374
|
+
nodes.push(c.entityId);
|
|
375
|
+
const samples = [
|
|
376
|
+
...arb.slice(0, 3).map((a) => a.className),
|
|
377
|
+
...prim.slice(0, 2).map((p) => p.tokenOrClass),
|
|
378
|
+
].slice(0, 3);
|
|
379
|
+
annotations[c.entityId] = `${count} one-off Tailwind class${count === 1 ? "" : "es"} (${samples.join(", ")})`;
|
|
380
|
+
}
|
|
381
|
+
if (nodes.length > 0) {
|
|
382
|
+
views.push({
|
|
383
|
+
id: "arbitrary-tailwind",
|
|
384
|
+
title: "One-off Tailwind values",
|
|
385
|
+
description: `${totalCount} bracketed or unscaled class${totalCount === 1 ? "" : "es"} across ${nodes.length} component${nodes.length === 1 ? "" : "s"}`,
|
|
386
|
+
badge: { text: `${totalCount}`, tone: "warn" },
|
|
387
|
+
highlightNodeIds: nodes,
|
|
388
|
+
viewLevel: "package",
|
|
389
|
+
packageName: shortKey,
|
|
390
|
+
nodeAnnotations: annotations,
|
|
391
|
+
layer: "L1_DESIGN_SYSTEM",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
// 2. Hardcoded colors & sizes (inline styles, TS literals, canvas literals, prop color literals)
|
|
396
|
+
{
|
|
397
|
+
const nodes = [];
|
|
398
|
+
const annotations = {};
|
|
399
|
+
let totalCount = 0;
|
|
400
|
+
for (const c of comps) {
|
|
401
|
+
const tsLits = c.literalValues.filter((l) => l.surface !== "tailwind-arbitrary");
|
|
402
|
+
const count = c.inlineStyleLiterals.length +
|
|
403
|
+
c.canvasProvenance.literals.length +
|
|
404
|
+
tsLits.length +
|
|
405
|
+
c.invariantViolations.length;
|
|
406
|
+
if (count === 0)
|
|
407
|
+
continue;
|
|
408
|
+
totalCount += count;
|
|
409
|
+
nodes.push(c.entityId);
|
|
410
|
+
const samples = [
|
|
411
|
+
...c.invariantViolations.slice(0, 2).map((v) => `${v.prop}="${v.value}"`),
|
|
412
|
+
...c.inlineStyleLiterals.slice(0, 2).map((l) => `${l.property}: ${l.value}`),
|
|
413
|
+
...tsLits.slice(0, 2).map((l) => l.value),
|
|
414
|
+
...c.canvasProvenance.literals.slice(0, 2).map((l) => l.value),
|
|
415
|
+
].slice(0, 3);
|
|
416
|
+
annotations[c.entityId] = `${count} hardcoded literal${count === 1 ? "" : "s"} (${samples.join(", ")})`;
|
|
417
|
+
}
|
|
418
|
+
if (nodes.length > 0) {
|
|
419
|
+
views.push({
|
|
420
|
+
id: "hardcoded-literals",
|
|
421
|
+
title: "Hardcoded colors & sizes",
|
|
422
|
+
description: `${totalCount} inline or literal value${totalCount === 1 ? "" : "s"} across ${nodes.length} component${nodes.length === 1 ? "" : "s"}`,
|
|
423
|
+
badge: { text: `${totalCount}`, tone: "warn" },
|
|
424
|
+
highlightNodeIds: nodes,
|
|
425
|
+
viewLevel: "package",
|
|
426
|
+
packageName: shortKey,
|
|
427
|
+
nodeAnnotations: annotations,
|
|
428
|
+
layer: "L1_DESIGN_SYSTEM",
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// 3. Raw HTML instead of shared components
|
|
433
|
+
{
|
|
434
|
+
const byComp = new Map();
|
|
435
|
+
for (const b of bypassed) {
|
|
436
|
+
const comp = byLabel.get(b.bypassingComponent);
|
|
437
|
+
if (!comp)
|
|
438
|
+
continue;
|
|
439
|
+
const list = byComp.get(comp.entityId) ?? [];
|
|
440
|
+
list.push(b.atomTarget);
|
|
441
|
+
byComp.set(comp.entityId, list);
|
|
442
|
+
}
|
|
443
|
+
if (byComp.size > 0) {
|
|
444
|
+
const nodes = [...byComp.keys()];
|
|
445
|
+
const annotations = {};
|
|
446
|
+
let totalCount = 0;
|
|
447
|
+
for (const [entityId, atoms] of byComp) {
|
|
448
|
+
totalCount += atoms.length;
|
|
449
|
+
const uniqueAtoms = [...new Set(atoms)];
|
|
450
|
+
annotations[entityId] = `${atoms.length} raw element${atoms.length === 1 ? "" : "s"} instead of shared ${uniqueAtoms.map((a) => `<${a}>`).join(", ")}`;
|
|
451
|
+
}
|
|
452
|
+
views.push({
|
|
453
|
+
id: "shared-atoms",
|
|
454
|
+
title: "Raw HTML instead of shared components",
|
|
455
|
+
description: `${totalCount} raw element${totalCount === 1 ? "" : "s"} across ${nodes.length} component${nodes.length === 1 ? "" : "s"}`,
|
|
456
|
+
badge: { text: `${totalCount}`, tone: "warn" },
|
|
457
|
+
highlightNodeIds: nodes,
|
|
458
|
+
viewLevel: "package",
|
|
459
|
+
packageName: shortKey,
|
|
460
|
+
nodeAnnotations: annotations,
|
|
461
|
+
layer: "L1_DESIGN_SYSTEM",
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
// 4. Prop & layout overrides
|
|
466
|
+
{
|
|
467
|
+
const nodes = [];
|
|
468
|
+
const annotations = {};
|
|
469
|
+
let totalCount = 0;
|
|
470
|
+
for (const c of comps) {
|
|
471
|
+
const compOverrides = overrides.filter((o) => o.parentComponent === c.label);
|
|
472
|
+
const count = c.composabilityIssues.length + compOverrides.length;
|
|
473
|
+
if (count === 0)
|
|
474
|
+
continue;
|
|
475
|
+
totalCount += count;
|
|
476
|
+
nodes.push(c.entityId);
|
|
477
|
+
const notes = [
|
|
478
|
+
...c.composabilityIssues.slice(0, 2).map((i) => i.detail),
|
|
479
|
+
...compOverrides.slice(0, 2).map((o) => `Overrides <${o.childComponent}>`),
|
|
480
|
+
].slice(0, 2);
|
|
481
|
+
annotations[c.entityId] = notes.join(" · ");
|
|
482
|
+
}
|
|
483
|
+
if (nodes.length > 0) {
|
|
484
|
+
views.push({
|
|
485
|
+
id: "prop-composability",
|
|
486
|
+
title: "Prop & layout overrides",
|
|
487
|
+
description: `${totalCount} composability or call-site override issue${totalCount === 1 ? "" : "s"} across ${nodes.length} component${nodes.length === 1 ? "" : "s"}`,
|
|
488
|
+
badge: { text: `${totalCount}`, tone: "warn" },
|
|
489
|
+
highlightNodeIds: nodes,
|
|
490
|
+
viewLevel: "package",
|
|
491
|
+
packageName: shortKey,
|
|
492
|
+
nodeAnnotations: annotations,
|
|
493
|
+
layer: "L1_DESIGN_SYSTEM",
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
// 5. Duplicate markup & parallel components
|
|
498
|
+
{
|
|
499
|
+
const annotations = {};
|
|
500
|
+
const nodeSet = new Set();
|
|
501
|
+
for (const t of twins) {
|
|
502
|
+
for (const member of t.components) {
|
|
503
|
+
if (!byLabel.has(member.label))
|
|
504
|
+
continue;
|
|
505
|
+
nodeSet.add(member.entityId);
|
|
506
|
+
annotations[member.entityId] = `${t.concept}: ${t.recommendation}`;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
for (const g of clones) {
|
|
510
|
+
for (const occ of g.occurrences) {
|
|
511
|
+
const comp = byLabel.get(occ.componentName);
|
|
512
|
+
if (!comp)
|
|
513
|
+
continue;
|
|
514
|
+
nodeSet.add(comp.entityId);
|
|
515
|
+
const prev = annotations[comp.entityId];
|
|
516
|
+
const msg = `Repeated <${g.suggestedComponentName}> × ${g.occurrenceCount}`;
|
|
517
|
+
annotations[comp.entityId] = prev ? `${prev} · ${msg}` : msg;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (nodeSet.size > 0) {
|
|
521
|
+
const nodes = [...nodeSet];
|
|
522
|
+
const groupCount = twins.length + clones.length;
|
|
523
|
+
views.push({
|
|
524
|
+
id: "duplicate-ui",
|
|
525
|
+
title: "Duplicate markup & parallel components",
|
|
526
|
+
description: `${groupCount} consolidation group${groupCount === 1 ? "" : "s"} across ${nodes.length} component${nodes.length === 1 ? "" : "s"}`,
|
|
527
|
+
badge: { text: `${groupCount}`, tone: "info" },
|
|
528
|
+
highlightNodeIds: nodes,
|
|
529
|
+
viewLevel: "package",
|
|
530
|
+
packageName: shortKey,
|
|
531
|
+
nodeAnnotations: annotations,
|
|
532
|
+
layer: "L1_DESIGN_SYSTEM",
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return views;
|
|
537
|
+
}
|
|
538
|
+
// ---------------------------------------------------------------------------
|
|
539
|
+
// Component-level presentation (Node Inspector — simple Label / Value rows)
|
|
540
|
+
// ---------------------------------------------------------------------------
|
|
541
|
+
export function buildComponentPresentation(profile, report) {
|
|
542
|
+
const tierLabel = profile.atomicTier === "ROUTE"
|
|
543
|
+
? "Page"
|
|
544
|
+
: profile.atomicTier.charAt(0) + profile.atomicTier.slice(1).toLowerCase();
|
|
545
|
+
const kvItems = [
|
|
546
|
+
{ label: "Layer", value: tierLabel },
|
|
547
|
+
];
|
|
548
|
+
const styling = profile.stylingConventions.map(formatStylingConvention);
|
|
549
|
+
if (styling.length > 0) {
|
|
550
|
+
kvItems.push({ label: "Styling", value: styling.join(" · ") });
|
|
551
|
+
}
|
|
552
|
+
if (profile.tokensConsumed.length > 0) {
|
|
553
|
+
kvItems.push({
|
|
554
|
+
label: "Tokens",
|
|
555
|
+
value: profile.tokensConsumed.join(", "),
|
|
556
|
+
mono: true,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
// ---- Findings rendered in the same Label / Value visual system ----
|
|
560
|
+
let issueCount = 0;
|
|
561
|
+
if (profile.arbitraryTailwind.length > 0) {
|
|
562
|
+
issueCount += profile.arbitraryTailwind.length;
|
|
563
|
+
const uniqueClasses = [
|
|
564
|
+
...new Set(profile.arbitraryTailwind.map((a) => a.className)),
|
|
565
|
+
];
|
|
566
|
+
kvItems.push({
|
|
567
|
+
label: "One-off Tailwind",
|
|
568
|
+
value: uniqueClasses.join(", "),
|
|
569
|
+
mono: true,
|
|
570
|
+
tone: "warn",
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
if (profile.primitiveScaleSkips.length > 0) {
|
|
574
|
+
issueCount += profile.primitiveScaleSkips.length;
|
|
575
|
+
const uniqueSkips = [
|
|
576
|
+
...new Set(profile.primitiveScaleSkips.map((p) => p.tokenOrClass)),
|
|
577
|
+
];
|
|
578
|
+
kvItems.push({
|
|
579
|
+
label: "Raw palette",
|
|
580
|
+
value: uniqueSkips.join(", "),
|
|
581
|
+
mono: true,
|
|
582
|
+
tone: "warn",
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
const nonTwLiterals = profile.literalValues.filter((x) => x.surface !== "tailwind-arbitrary");
|
|
586
|
+
const literalCount = profile.inlineStyleLiterals.length +
|
|
587
|
+
nonTwLiterals.length +
|
|
588
|
+
profile.canvasProvenance.literals.length +
|
|
589
|
+
profile.invariantViolations.length;
|
|
590
|
+
if (literalCount > 0) {
|
|
591
|
+
issueCount += literalCount;
|
|
592
|
+
const uniqueLits = [
|
|
593
|
+
...new Set([
|
|
594
|
+
...profile.invariantViolations.map((v) => `${v.prop}="${v.value}"`),
|
|
595
|
+
...profile.inlineStyleLiterals.map((l) => `${l.property}: ${l.value}`),
|
|
596
|
+
...nonTwLiterals.map((l) => l.value),
|
|
597
|
+
...profile.canvasProvenance.literals.map((l) => String(l.value)),
|
|
598
|
+
]),
|
|
599
|
+
];
|
|
600
|
+
kvItems.push({
|
|
601
|
+
label: "Hardcoded values",
|
|
602
|
+
value: uniqueLits.join(", "),
|
|
603
|
+
mono: true,
|
|
604
|
+
tone: "warn",
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
const rawAtoms = [];
|
|
608
|
+
for (const a of report.atomicConsolidation) {
|
|
609
|
+
const matches = a.instances.filter((x) => x.componentName === profile.label);
|
|
610
|
+
if (matches.length > 0) {
|
|
611
|
+
issueCount += matches.length;
|
|
612
|
+
const targetName = a.existingSharedComponent?.name ?? a.atomName;
|
|
613
|
+
rawAtoms.push(matches.length > 1 ? `${targetName} (×${matches.length})` : targetName);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (rawAtoms.length > 0) {
|
|
617
|
+
kvItems.push({
|
|
618
|
+
label: "Shared atoms",
|
|
619
|
+
value: `Raw ${rawAtoms.join(", ")}`,
|
|
620
|
+
tone: "warn",
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
if (profile.undefinedTokens.length > 0) {
|
|
624
|
+
issueCount += profile.undefinedTokens.length;
|
|
625
|
+
kvItems.push({
|
|
626
|
+
label: "Undefined tokens",
|
|
627
|
+
value: profile.undefinedTokens.map((u) => u.name).join(", "),
|
|
628
|
+
mono: true,
|
|
629
|
+
tone: "bad",
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
const compOverrides = report.alignmentAudit.callSiteOverrides.filter((x) => x.parentComponent === profile.label);
|
|
633
|
+
if (profile.composabilityIssues.length > 0 || compOverrides.length > 0) {
|
|
634
|
+
issueCount += profile.composabilityIssues.length + compOverrides.length;
|
|
635
|
+
const notes = [
|
|
636
|
+
...new Set([
|
|
637
|
+
...compOverrides.map((o) => `Overrides <${o.childComponent}>`),
|
|
638
|
+
...profile.composabilityIssues.map((c) => formatComposabilityKind(c.kind)),
|
|
639
|
+
]),
|
|
640
|
+
];
|
|
641
|
+
kvItems.push({
|
|
642
|
+
label: "Prop overrides",
|
|
643
|
+
value: notes.join(" · "),
|
|
644
|
+
tone: "warn",
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
const compTwins = report.alignmentAudit.parallelTwins.filter((x) => x.components.some((c) => c.entityId === profile.entityId));
|
|
648
|
+
if (compTwins.length > 0) {
|
|
649
|
+
issueCount += compTwins.length;
|
|
650
|
+
const twinLabels = compTwins.map((t) => {
|
|
651
|
+
const others = t.components
|
|
652
|
+
.filter((c) => c.entityId !== profile.entityId)
|
|
653
|
+
.map((c) => c.label)
|
|
654
|
+
.join(", ");
|
|
655
|
+
return `${others} (${t.concept})`;
|
|
656
|
+
});
|
|
657
|
+
kvItems.push({
|
|
658
|
+
label: "Similar UI",
|
|
659
|
+
value: twinLabels.join(" · "),
|
|
660
|
+
tone: "info",
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
const compClones = report.dryAudit.structuralJsxClones.filter((x) => x.occurrences.some((o) => o.componentName === profile.label));
|
|
664
|
+
if (compClones.length > 0) {
|
|
665
|
+
issueCount += compClones.length;
|
|
666
|
+
const cloneLabels = compClones.map((g) => {
|
|
667
|
+
const cleanName = g.suggestedComponentName.replace(/^Repeated/, "") ||
|
|
668
|
+
g.suggestedComponentName;
|
|
669
|
+
return `${cleanName} (×${g.occurrenceCount})`;
|
|
670
|
+
});
|
|
671
|
+
kvItems.push({
|
|
672
|
+
label: "Repeated UI",
|
|
673
|
+
value: cloneLabels.join(" · "),
|
|
674
|
+
tone: "info",
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (profile.magicSpacingUtilities.length > 0) {
|
|
678
|
+
issueCount += profile.magicSpacingUtilities.length;
|
|
679
|
+
const uniqueMagic = [...new Set(profile.magicSpacingUtilities.map((m) => m.className))];
|
|
680
|
+
kvItems.push({
|
|
681
|
+
label: "Magic spacing",
|
|
682
|
+
value: uniqueMagic.join(", "),
|
|
683
|
+
mono: true,
|
|
684
|
+
tone: "warn",
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
if (profile.undefinedCssClasses.length > 0) {
|
|
688
|
+
issueCount += profile.undefinedCssClasses.length;
|
|
689
|
+
kvItems.push({
|
|
690
|
+
label: "Undefined CSS",
|
|
691
|
+
value: profile.undefinedCssClasses.join(", "),
|
|
692
|
+
mono: true,
|
|
693
|
+
tone: "bad",
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
if (profile.nestedInteractive.length > 0) {
|
|
697
|
+
issueCount += profile.nestedInteractive.length;
|
|
698
|
+
kvItems.push({
|
|
699
|
+
label: "Nested interactive",
|
|
700
|
+
value: profile.nestedInteractive.map((n) => `${n.outerTag} > ${n.innerTag}`).join(", "),
|
|
701
|
+
tone: "warn",
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
if (profile.siblingAtomOverlaps.length > 0) {
|
|
705
|
+
issueCount += profile.siblingAtomOverlaps.length;
|
|
706
|
+
kvItems.push({
|
|
707
|
+
label: "Overlapping atom",
|
|
708
|
+
value: profile.siblingAtomOverlaps.map((o) => `Overlaps <${o.atomTarget}>`).join(", "),
|
|
709
|
+
tone: "warn",
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
const warnShapes = profile.unextractedShapes.filter((s) => s.tone === "warn");
|
|
713
|
+
if (warnShapes.length > 0) {
|
|
714
|
+
issueCount += warnShapes.length;
|
|
715
|
+
kvItems.push({
|
|
716
|
+
label: "Unextracted UI",
|
|
717
|
+
value: [...new Set(warnShapes.map((s) => s.shapeKind))].join(", "),
|
|
718
|
+
tone: "warn",
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
const subtreeIssueCount = profile.health?.subtreeIssueCount ?? 0;
|
|
722
|
+
const descendantOffenders = profile.health?.descendantOffenders ?? [];
|
|
723
|
+
const hasSignal = issueCount > 0 ||
|
|
724
|
+
subtreeIssueCount > 0 ||
|
|
725
|
+
styling.length > 0 ||
|
|
726
|
+
profile.tokensConsumed.length > 0 ||
|
|
727
|
+
profile.atomicTier !== "UTILITY";
|
|
728
|
+
if (!hasSignal)
|
|
729
|
+
return null;
|
|
730
|
+
const badge = issueCount > 0
|
|
731
|
+
? {
|
|
732
|
+
text: `${issueCount} finding${issueCount === 1 ? "" : "s"}`,
|
|
733
|
+
tone: "warn",
|
|
734
|
+
}
|
|
735
|
+
: subtreeIssueCount > 0
|
|
736
|
+
? {
|
|
737
|
+
text: `Aligned · ${subtreeIssueCount} in subtree`,
|
|
738
|
+
tone: "info",
|
|
739
|
+
}
|
|
740
|
+
: { text: "Aligned", tone: "good" };
|
|
741
|
+
const blocks = [{ kind: "keyValue", items: kvItems }];
|
|
742
|
+
if (descendantOffenders.length > 0) {
|
|
743
|
+
blocks.push({
|
|
744
|
+
kind: "list",
|
|
745
|
+
title: "Subtree findings",
|
|
746
|
+
totalCount: descendantOffenders.length,
|
|
747
|
+
items: descendantOffenders.slice(0, VISIBLE).map((off) => ({
|
|
748
|
+
label: off.label,
|
|
749
|
+
detail: `${off.directIssueCount} finding${off.directIssueCount === 1 ? "" : "s"} · score ${off.directScore}`,
|
|
750
|
+
tone: off.directScore < 60 ? "bad" : "warn",
|
|
751
|
+
entityId: off.entityId,
|
|
752
|
+
filePath: off.filePath,
|
|
753
|
+
})),
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
return {
|
|
757
|
+
version: PLUGIN_PRESENTATION_VERSION,
|
|
758
|
+
generatedAt: new Date().toISOString(),
|
|
759
|
+
summary: {
|
|
760
|
+
status: issueCount === 0 ? "ok" : "warn",
|
|
761
|
+
badge,
|
|
762
|
+
issueCount,
|
|
763
|
+
},
|
|
764
|
+
sections: [
|
|
765
|
+
{
|
|
766
|
+
id: "design-system",
|
|
767
|
+
title: "Design system",
|
|
768
|
+
priority: 1,
|
|
769
|
+
blocks,
|
|
770
|
+
},
|
|
771
|
+
],
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Attaches `payload.presentation` to the overlays produced by `analyzeRepositoryDesignSystem`.
|
|
776
|
+
* Package overlays get the rich package view; component overlays get their own findings.
|
|
777
|
+
*/
|
|
778
|
+
export function attachDesignSystemPresentations(report, overlays, baseline, records, measuresFor) {
|
|
779
|
+
const byEntity = new Map(report.components.map((c) => [c.entityId, c]));
|
|
780
|
+
for (const ov of overlays) {
|
|
781
|
+
const payload = (ov.payload ?? {});
|
|
782
|
+
let presentation = null;
|
|
783
|
+
if (payload.isPackageOverlay === true && typeof payload.packageShortKey === "string") {
|
|
784
|
+
const m = measuresFor(payload.packageShortKey);
|
|
785
|
+
presentation = buildPackagePresentation(report, payload.packageShortKey, { score: m.score, grade: m.grade, notes: m.notes }, m.pillars, baseline, records);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
const profile = byEntity.get(ov.entityId);
|
|
789
|
+
if (profile)
|
|
790
|
+
presentation = buildComponentPresentation(profile, report);
|
|
791
|
+
}
|
|
792
|
+
if (presentation) {
|
|
793
|
+
ov.payload = { ...payload, [PLUGIN_PRESENTATION_PAYLOAD_KEY]: presentation };
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|