@md-code/component-uniqueness 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +202 -0
- package/README.md +21 -3
- package/dist/config.d.ts +50 -0
- package/dist/config.js +402 -0
- package/dist/constants.d.ts +55 -0
- package/dist/constants.js +86 -0
- package/dist/decision-maker.d.ts +39 -0
- package/dist/decision-maker.js +119 -0
- package/dist/filter/child-element.d.ts +3 -0
- package/dist/filter/child-element.js +17 -0
- package/dist/filter/missing-component.d.ts +10 -0
- package/dist/filter/missing-component.js +96 -0
- package/dist/filter/no-structure.d.ts +3 -0
- package/dist/filter/no-structure.js +16 -0
- package/dist/filter/usages.d.ts +3 -0
- package/dist/filter/usages.js +14 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +244 -0
- package/dist/lib-registry.d.ts +4 -0
- package/dist/lib-registry.js +376 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +70 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.js +666 -0
- package/dist/matcher/a11y.d.ts +19 -0
- package/dist/matcher/a11y.js +311 -0
- package/dist/matcher/behavior.d.ts +10 -0
- package/dist/matcher/behavior.js +32 -0
- package/dist/matcher/css-matching.d.ts +18 -0
- package/dist/matcher/css-matching.js +159 -0
- package/dist/matcher/framework/index.d.ts +2 -0
- package/dist/matcher/framework/index.js +37 -0
- package/dist/matcher/framework/react.d.ts +12 -0
- package/dist/matcher/framework/react.js +70 -0
- package/dist/matcher/index.d.ts +64 -0
- package/dist/matcher/index.js +38 -0
- package/dist/matcher/name.d.ts +15 -0
- package/dist/matcher/name.js +154 -0
- package/dist/matcher/structure.d.ts +22 -0
- package/dist/matcher/structure.js +329 -0
- package/dist/matcher/styles.d.ts +20 -0
- package/dist/matcher/styles.js +49 -0
- package/dist/normalize/candidate.d.ts +3 -0
- package/dist/normalize/candidate.js +21 -0
- package/dist/normalize/dom.d.ts +22 -0
- package/dist/normalize/dom.js +180 -0
- package/dist/normalize/external-html.d.ts +5 -0
- package/dist/normalize/external-html.js +40 -0
- package/dist/normalize/framework.d.ts +20 -0
- package/dist/normalize/framework.js +130 -0
- package/dist/normalize/resolver.d.ts +7 -0
- package/dist/normalize/resolver.js +28 -0
- package/dist/normalize/style-resolver.d.ts +7 -0
- package/dist/normalize/style-resolver.js +28 -0
- package/dist/normalize/style.d.ts +15 -0
- package/dist/normalize/style.js +174 -0
- package/dist/normalize/words.d.ts +3 -0
- package/dist/normalize/words.js +40 -0
- package/dist/package.json +88 -0
- package/dist/playgrounds/angular.d.ts +7 -0
- package/dist/playgrounds/angular.js +9 -0
- package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
- package/dist/playgrounds/framework-entrypoint.js +102 -0
- package/dist/playgrounds/framework.d.ts +10 -0
- package/dist/playgrounds/framework.js +102 -0
- package/dist/playgrounds/react.d.ts +14 -0
- package/dist/playgrounds/react.js +1288 -0
- package/dist/playgrounds/scss.d.ts +6 -0
- package/dist/playgrounds/scss.js +9 -0
- package/dist/playgrounds/style-entrypoint.d.ts +13 -0
- package/dist/playgrounds/style-entrypoint.js +82 -0
- package/dist/playgrounds/style.d.ts +13 -0
- package/dist/playgrounds/style.js +82 -0
- package/dist/playgrounds/styled-components.d.ts +7 -0
- package/dist/playgrounds/styled-components.js +190 -0
- package/dist/playgrounds/tailwind.d.ts +15 -0
- package/dist/playgrounds/tailwind.js +256 -0
- package/dist/playgrounds/vue.d.ts +7 -0
- package/dist/playgrounds/vue.js +9 -0
- package/dist/report/asks.d.ts +27 -0
- package/dist/report/asks.js +28 -0
- package/dist/report/cli-report.d.ts +7 -0
- package/dist/report/cli-report.js +187 -0
- package/dist/report/codes/index.d.ts +37 -0
- package/dist/report/codes/index.js +31 -0
- package/dist/report/errorTypes/index.d.ts +92 -0
- package/dist/report/errorTypes/index.js +186 -0
- package/dist/report/evidence.d.ts +2 -0
- package/dist/report/evidence.js +8 -0
- package/dist/report/explain.d.ts +27 -0
- package/dist/report/explain.js +76 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +24 -0
- package/dist/report/matchers/a11y/model.d.ts +20 -0
- package/dist/report/matchers/a11y/model.js +14 -0
- package/dist/report/matchers/a11y/text.d.ts +2 -0
- package/dist/report/matchers/a11y/text.js +22 -0
- package/dist/report/matchers/behavior/model.d.ts +20 -0
- package/dist/report/matchers/behavior/model.js +12 -0
- package/dist/report/matchers/behavior/text.d.ts +2 -0
- package/dist/report/matchers/behavior/text.js +22 -0
- package/dist/report/matchers/framework/model.d.ts +10 -0
- package/dist/report/matchers/framework/model.js +39 -0
- package/dist/report/matchers/framework/text.d.ts +2 -0
- package/dist/report/matchers/framework/text.js +26 -0
- package/dist/report/matchers/index.d.ts +5 -0
- package/dist/report/matchers/index.js +97 -0
- package/dist/report/matchers/name/model.d.ts +20 -0
- package/dist/report/matchers/name/model.js +30 -0
- package/dist/report/matchers/name/text.d.ts +2 -0
- package/dist/report/matchers/name/text.js +17 -0
- package/dist/report/matchers/set-model.d.ts +31 -0
- package/dist/report/matchers/set-model.js +42 -0
- package/dist/report/matchers/structure/model.d.ts +10 -0
- package/dist/report/matchers/structure/model.js +58 -0
- package/dist/report/matchers/structure/text.d.ts +2 -0
- package/dist/report/matchers/structure/text.js +40 -0
- package/dist/report/matchers/styles/model.d.ts +11 -0
- package/dist/report/matchers/styles/model.js +36 -0
- package/dist/report/matchers/styles/text.d.ts +2 -0
- package/dist/report/matchers/styles/text.js +40 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +185 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
- package/dist/report/user-report/data/collect.d.ts +68 -0
- package/dist/report/user-report/data/collect.js +150 -0
- package/dist/report/user-report/data/folders.d.ts +3 -0
- package/dist/report/user-report/data/folders.js +73 -0
- package/dist/report/user-report/data/groups.d.ts +13 -0
- package/dist/report/user-report/data/groups.js +76 -0
- package/dist/report/user-report/data/links.d.ts +39 -0
- package/dist/report/user-report/data/links.js +222 -0
- package/dist/report/user-report/data/snapshot.d.ts +9 -0
- package/dist/report/user-report/data/snapshot.js +180 -0
- package/dist/report/user-report/data/source.d.ts +13 -0
- package/dist/report/user-report/data/source.js +58 -0
- package/dist/report/user-report/data/word.d.ts +3 -0
- package/dist/report/user-report/data/word.js +32 -0
- package/dist/report/user-report/html/shell.d.ts +2 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +7 -0
- package/dist/report/user-report/index.js +47 -0
- package/dist/report/vocabulary/evidence.d.ts +48 -0
- package/dist/report/vocabulary/evidence.js +66 -0
- package/dist/report/vocabulary/format.d.ts +4 -0
- package/dist/report/vocabulary/format.js +20 -0
- package/dist/report/vocabulary/labels.d.ts +134 -0
- package/dist/report/vocabulary/labels.js +87 -0
- package/dist/report/vocabulary/phrases.d.ts +20 -0
- package/dist/report/vocabulary/phrases.js +34 -0
- package/dist/self-catalog.d.ts +4 -0
- package/dist/self-catalog.js +179 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +125 -0
- package/package.json +86 -71
- package/config.js +0 -372
- package/decision-maker.js +0 -109
- package/filter/drop-child-element.js +0 -14
- package/filter/drop-no-structure.js +0 -13
- package/filter/drop-usages.js +0 -13
- package/filter/missing-component.js +0 -100
- package/index.js +0 -184
- package/logger.js +0 -44
- package/main.js +0 -584
- package/matcher/a11y.js +0 -65
- package/matcher/behavior.js +0 -31
- package/matcher/framework/index.js +0 -15
- package/matcher/framework/react.js +0 -25
- package/matcher/index.js +0 -36
- package/matcher/name.js +0 -132
- package/matcher/structure.js +0 -242
- package/normalize/candidate.js +0 -22
- package/normalize/dom.js +0 -187
- package/normalize/framework.js +0 -110
- package/normalize/style-resolver.js +0 -24
- package/normalize/style.js +0 -175
- package/normalize/words.js +0 -40
- package/playgrounds/angular.js +0 -11
- package/playgrounds/framework-entrypoint.js +0 -90
- package/playgrounds/react.js +0 -998
- package/playgrounds/scss.js +0 -7
- package/playgrounds/style-entrypoint.js +0 -78
- package/playgrounds/styled-components.js +0 -138
- package/playgrounds/tailwind.js +0 -186
- package/playgrounds/vue.js +0 -11
- package/plugin.js +0 -3
- package/report.js +0 -162
- package/utils.js +0 -92
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEST_ID_WEIGHT = exports.announcementsOf = exports.classify = exports.tokensOf = exports.matchA11y = void 0;
|
|
4
|
+
// ── ACCESSIBILITY MATCH · what a screen reader ANNOUNCES ────────────────────
|
|
5
|
+
//
|
|
6
|
+
// Two components are accessibility duplicates when a screen reader announces
|
|
7
|
+
// the SAME things: the same roles with the same accessible names and states.
|
|
8
|
+
// The comparison is semantic, not a bag of attribute strings:
|
|
9
|
+
//
|
|
10
|
+
// • a real <button> and a <div role="button" tabIndex={0}> announce the same
|
|
11
|
+
// role — the implicit role of the tag counts exactly like an explicit one;
|
|
12
|
+
// • the accessible NAME is compared by value: aria-label vs the text the
|
|
13
|
+
// element wraps are the same name when they say the same words;
|
|
14
|
+
// • states are compared by value: aria-pressed="true" ≠ aria-expanded="true",
|
|
15
|
+
// so two pixel-identical toggles that announce different states are NOT
|
|
16
|
+
// accessibility duplicates;
|
|
17
|
+
// • aria-hidden / role="presentation" nodes are silent — they announce nothing
|
|
18
|
+
// and cannot create (or destroy) a correspondence.
|
|
19
|
+
//
|
|
20
|
+
// The raw token lists (`role:button`, `aria-label:Close`) remain as evidence and
|
|
21
|
+
// as the applicability gate for callers that only have the token surface.
|
|
22
|
+
const TEST_ID_WEIGHT = 0.5;
|
|
23
|
+
exports.TEST_ID_WEIGHT = TEST_ID_WEIGHT;
|
|
24
|
+
const parseToken = (token) => {
|
|
25
|
+
const t = String(token || "").toLowerCase();
|
|
26
|
+
const m = t.match(/^(role|aria-[\w-]+)(?::(.*))?$/);
|
|
27
|
+
if (m)
|
|
28
|
+
return { name: m[1], value: m[2] || "" };
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const classify = (token) => {
|
|
32
|
+
const t = String(token || "").toLowerCase();
|
|
33
|
+
if (t.startsWith("data-test") || t.startsWith("data-testid") || t.startsWith("data-test-id"))
|
|
34
|
+
return "testid";
|
|
35
|
+
const p = parseToken(t);
|
|
36
|
+
if (p)
|
|
37
|
+
return "a11y";
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
exports.classify = classify;
|
|
41
|
+
const tokensOf = (c, kind) => {
|
|
42
|
+
const s = new Set();
|
|
43
|
+
for (const t of c.a11y || []) {
|
|
44
|
+
if (classify(t) === kind)
|
|
45
|
+
s.add(String(t).toLowerCase());
|
|
46
|
+
}
|
|
47
|
+
return s;
|
|
48
|
+
};
|
|
49
|
+
exports.tokensOf = tokensOf;
|
|
50
|
+
const jaccard = (a, b) => {
|
|
51
|
+
if (a.size === 0 || b.size === 0)
|
|
52
|
+
return 0;
|
|
53
|
+
let inter = 0;
|
|
54
|
+
for (const t of a)
|
|
55
|
+
if (b.has(t))
|
|
56
|
+
inter += 1;
|
|
57
|
+
const union = a.size + b.size - inter;
|
|
58
|
+
return union === 0 ? 0 : inter / union;
|
|
59
|
+
};
|
|
60
|
+
// ── The semantic surface: one entry per ANNOUNCED node ─────────────────────
|
|
61
|
+
const IMPLICIT_ROLE = {
|
|
62
|
+
button: "button",
|
|
63
|
+
a: "link",
|
|
64
|
+
select: "combobox",
|
|
65
|
+
textarea: "textbox",
|
|
66
|
+
img: "img",
|
|
67
|
+
nav: "navigation",
|
|
68
|
+
main: "main",
|
|
69
|
+
header: "banner",
|
|
70
|
+
footer: "contentinfo",
|
|
71
|
+
aside: "complementary",
|
|
72
|
+
form: "form",
|
|
73
|
+
fieldset: "group",
|
|
74
|
+
h1: "heading",
|
|
75
|
+
h2: "heading",
|
|
76
|
+
h3: "heading",
|
|
77
|
+
h4: "heading",
|
|
78
|
+
h5: "heading",
|
|
79
|
+
h6: "heading",
|
|
80
|
+
ul: "list",
|
|
81
|
+
ol: "list",
|
|
82
|
+
li: "listitem",
|
|
83
|
+
table: "table",
|
|
84
|
+
dialog: "dialog",
|
|
85
|
+
option: "option",
|
|
86
|
+
progress: "progressbar",
|
|
87
|
+
};
|
|
88
|
+
const INPUT_ROLE = {
|
|
89
|
+
button: "button",
|
|
90
|
+
submit: "button",
|
|
91
|
+
reset: "button",
|
|
92
|
+
checkbox: "checkbox",
|
|
93
|
+
radio: "radio",
|
|
94
|
+
range: "slider",
|
|
95
|
+
number: "spinbutton",
|
|
96
|
+
search: "searchbox",
|
|
97
|
+
email: "textbox",
|
|
98
|
+
tel: "textbox",
|
|
99
|
+
url: "textbox",
|
|
100
|
+
password: "textbox",
|
|
101
|
+
text: "textbox",
|
|
102
|
+
};
|
|
103
|
+
const STATE_ATTRS = ["aria-expanded", "aria-checked", "aria-selected", "aria-disabled", "aria-pressed", "aria-required", "aria-invalid", "aria-current", "aria-level"];
|
|
104
|
+
const norm = (v) => String(v ?? "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
105
|
+
const roleOf = (node) => {
|
|
106
|
+
const attrs = node.attrs || {};
|
|
107
|
+
if (attrs.role)
|
|
108
|
+
return norm(attrs.role);
|
|
109
|
+
const tag = String(node.tag || "").toLowerCase();
|
|
110
|
+
if (tag === "input")
|
|
111
|
+
return INPUT_ROLE[norm(attrs.type) || "text"] || "textbox";
|
|
112
|
+
if (tag === "a")
|
|
113
|
+
return attrs.href !== undefined ? "link" : null;
|
|
114
|
+
return IMPLICIT_ROLE[tag] ?? null;
|
|
115
|
+
};
|
|
116
|
+
// The accessible name: aria-label wins, then aria-labelledby (resolved against
|
|
117
|
+
// the tree's own ids), then alt/title, then the text the node wraps.
|
|
118
|
+
const textOf = (node) => (node.children || [])
|
|
119
|
+
.filter((child) => child.tag === "text")
|
|
120
|
+
.map((child) => String(child.text || "").trim())
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.join(" ");
|
|
123
|
+
// Tags whose accessible name may come from their CONTENT (ARIA name-from-content).
|
|
124
|
+
// A structural container (div / section / dl / li …) is NOT named by the text it
|
|
125
|
+
// wraps — only an explicit aria-label / aria-labelledby / title names it. Letting
|
|
126
|
+
// containers inherit descendant text invents announcements ("dl named 'amount
|
|
127
|
+
// due'") that no screen reader makes.
|
|
128
|
+
const NAME_FROM_CONTENT = new Set(["button", "a", "h1", "h2", "h3", "h4", "h5", "h6", "label", "legend", "option", "summary", "figcaption", "caption", "th", "td", "dt", "dd", "p", "span", "strong", "em", "b", "i", "code", "pre", "blockquote", "q", "cite", "abbr", "mark", "small", "sub", "sup", "u", "s", "kbd", "samp", "var", "time", "data", "output", "progress", "meter", "li"]);
|
|
129
|
+
const nameOf = (node, byId) => {
|
|
130
|
+
const attrs = node.attrs || {};
|
|
131
|
+
if (attrs["aria-label"])
|
|
132
|
+
return norm(attrs["aria-label"]);
|
|
133
|
+
if (attrs["aria-labelledby"]) {
|
|
134
|
+
const ids = String(attrs["aria-labelledby"]).split(/\s+/).filter(Boolean);
|
|
135
|
+
const parts = ids.map((id) => {
|
|
136
|
+
const target = byId.get(id);
|
|
137
|
+
return target ? textOf(target) || nameOf(target, byId) : "";
|
|
138
|
+
}).filter(Boolean);
|
|
139
|
+
if (parts.length > 0)
|
|
140
|
+
return norm(parts.join(" "));
|
|
141
|
+
}
|
|
142
|
+
if (attrs.alt)
|
|
143
|
+
return norm(attrs.alt);
|
|
144
|
+
if (attrs.title)
|
|
145
|
+
return norm(attrs.title);
|
|
146
|
+
const tag = String(node.tag || "").toLowerCase();
|
|
147
|
+
if (!NAME_FROM_CONTENT.has(tag))
|
|
148
|
+
return null;
|
|
149
|
+
const wrapped = textOf(node);
|
|
150
|
+
if (wrapped)
|
|
151
|
+
return norm(wrapped);
|
|
152
|
+
// A control with no text of its own may be named by a descendant (a button
|
|
153
|
+
// wrapping a span, an img with alt inside a link).
|
|
154
|
+
for (const child of node.children || []) {
|
|
155
|
+
if (child.tag === "text" || child.tag === "fragment" || child.tag === "children")
|
|
156
|
+
continue;
|
|
157
|
+
const inner = nameOf(child, byId);
|
|
158
|
+
if (inner)
|
|
159
|
+
return inner;
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
const statesOf = (node) => {
|
|
164
|
+
const attrs = node.attrs || {};
|
|
165
|
+
const out = [];
|
|
166
|
+
for (const name of STATE_ATTRS) {
|
|
167
|
+
const v = attrs[name];
|
|
168
|
+
if (v !== undefined && v !== null && v !== false)
|
|
169
|
+
out.push(`${name}=${norm(v) || "true"}`);
|
|
170
|
+
}
|
|
171
|
+
if (attrs.disabled === true || attrs.disabled === "true" || attrs.disabled === "")
|
|
172
|
+
out.push("disabled=true");
|
|
173
|
+
return out.sort();
|
|
174
|
+
};
|
|
175
|
+
const isSilent = (node) => {
|
|
176
|
+
const attrs = node.attrs || {};
|
|
177
|
+
return attrs["aria-hidden"] === true || attrs["aria-hidden"] === "true" || norm(attrs.role) === "presentation" || norm(attrs.role) === "none";
|
|
178
|
+
};
|
|
179
|
+
// Flatten the expanded tree into announced entries: { role, name, states, tag }.
|
|
180
|
+
// A silent node announces nothing itself, but its children still do.
|
|
181
|
+
const announcementsOf = (tree) => {
|
|
182
|
+
const out = [];
|
|
183
|
+
if (!tree)
|
|
184
|
+
return out;
|
|
185
|
+
const byId = new Map();
|
|
186
|
+
const index = (n) => {
|
|
187
|
+
if (!n)
|
|
188
|
+
return;
|
|
189
|
+
if (n.attrs && n.attrs.id)
|
|
190
|
+
byId.set(String(n.attrs.id), n);
|
|
191
|
+
for (const c of n.children || [])
|
|
192
|
+
index(c);
|
|
193
|
+
};
|
|
194
|
+
index(tree);
|
|
195
|
+
const walk = (n) => {
|
|
196
|
+
if (!n)
|
|
197
|
+
return;
|
|
198
|
+
if (n.tag === "fragment" || n.tag === "children") {
|
|
199
|
+
for (const c of n.children || [])
|
|
200
|
+
walk(c);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (n.tag === "text")
|
|
204
|
+
return;
|
|
205
|
+
if (!isSilent(n)) {
|
|
206
|
+
const role = roleOf(n);
|
|
207
|
+
const name = nameOf(n, byId);
|
|
208
|
+
const states = statesOf(n);
|
|
209
|
+
if (role || name || states.length > 0)
|
|
210
|
+
out.push({ role: role || "", name: name || "", states, tag: String(n.tag || "") });
|
|
211
|
+
}
|
|
212
|
+
for (const c of n.children || [])
|
|
213
|
+
walk(c);
|
|
214
|
+
};
|
|
215
|
+
walk(tree);
|
|
216
|
+
return out;
|
|
217
|
+
};
|
|
218
|
+
exports.announcementsOf = announcementsOf;
|
|
219
|
+
// One entry's correspondence to another: the role must agree (an unnamed node
|
|
220
|
+
// of the same role still corresponds), the name and states are compared by
|
|
221
|
+
// value. A different accessible NAME means a different widget — two buttons
|
|
222
|
+
// labelled "Close dialog" and "Primary action" are not the same control, so the
|
|
223
|
+
// match is weak. Pixel-identical widgets that announce different things are not
|
|
224
|
+
// duplicates.
|
|
225
|
+
const entrySim = (a, b) => {
|
|
226
|
+
if (a.role && b.role && a.role !== b.role)
|
|
227
|
+
return 0;
|
|
228
|
+
if (!a.role && !b.role && a.name !== b.name)
|
|
229
|
+
return 0;
|
|
230
|
+
let score = 1;
|
|
231
|
+
if (a.name && b.name)
|
|
232
|
+
score = a.name === b.name ? 1 : 0.2;
|
|
233
|
+
else if (a.name || b.name)
|
|
234
|
+
score = 0.5;
|
|
235
|
+
const sa = a.states.join("|");
|
|
236
|
+
const sb = b.states.join("|");
|
|
237
|
+
if (sa || sb)
|
|
238
|
+
score = Math.min(score, sa === sb ? 1 : 0.4);
|
|
239
|
+
return score;
|
|
240
|
+
};
|
|
241
|
+
// In-order alignment (LCS-style DP) of the two announcement lists: each entry
|
|
242
|
+
// takes the best compatible counterpart that keeps document order. The score is
|
|
243
|
+
// the aligned similarity over the LARGER list, so extra announcements on one
|
|
244
|
+
// side lower it instead of disappearing.
|
|
245
|
+
const alignScore = (A, B) => {
|
|
246
|
+
if (A.length === 0 || B.length === 0)
|
|
247
|
+
return { score: 0, matched: 0 };
|
|
248
|
+
const n = A.length;
|
|
249
|
+
const m = B.length;
|
|
250
|
+
const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
251
|
+
for (let i = n - 1; i >= 0; i -= 1) {
|
|
252
|
+
for (let j = m - 1; j >= 0; j -= 1) {
|
|
253
|
+
const s = entrySim(A[i], B[j]);
|
|
254
|
+
const take = s > 0 ? s + dp[i + 1][j + 1] : -1;
|
|
255
|
+
dp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1], take);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return { score: dp[0][0] / Math.max(n, m), matched: dp[0][0] };
|
|
259
|
+
};
|
|
260
|
+
const matchA11y = (candidate, canon) => {
|
|
261
|
+
const candA = tokensOf(candidate, "a11y");
|
|
262
|
+
const canonA = tokensOf(canon, "a11y");
|
|
263
|
+
const candT = tokensOf(candidate, "testid");
|
|
264
|
+
const canonT = tokensOf(canon, "testid");
|
|
265
|
+
const testSim = jaccard(candT, canonT);
|
|
266
|
+
// The semantic comparison when both sides have an expanded tree AND BOTH
|
|
267
|
+
// carry explicit accessibility markup (role / aria-* tokens). A component
|
|
268
|
+
// with NO a11y tokens is not an accessibility participant: comparing its
|
|
269
|
+
// implicit landmark roles against another's explicit contract would invent
|
|
270
|
+
// evidence and re-distribute weight onto a signal the author never wrote.
|
|
271
|
+
const candTree = candidate.tree || (candidate.dom && candidate.dom.tree);
|
|
272
|
+
const canonTree = canon.tree || (canon.dom && canon.dom.tree);
|
|
273
|
+
let a11ySim;
|
|
274
|
+
let form;
|
|
275
|
+
let candAnn = [];
|
|
276
|
+
let canonAnn = [];
|
|
277
|
+
if (candTree && canonTree && candA.size > 0 && canonA.size > 0) {
|
|
278
|
+
candAnn = announcementsOf(candTree);
|
|
279
|
+
canonAnn = announcementsOf(canonTree);
|
|
280
|
+
a11ySim = alignScore(candAnn, canonAnn).score;
|
|
281
|
+
form = "semantic";
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
a11ySim = jaccard(candA, canonA);
|
|
285
|
+
form = "tokens";
|
|
286
|
+
}
|
|
287
|
+
const parts = [];
|
|
288
|
+
if (candA.size > 0 || canonA.size > 0)
|
|
289
|
+
parts.push({ w: 1 - TEST_ID_WEIGHT, v: a11ySim });
|
|
290
|
+
if (candT.size > 0 || canonT.size > 0)
|
|
291
|
+
parts.push({ w: TEST_ID_WEIGHT, v: testSim });
|
|
292
|
+
const totalW = parts.reduce((s, p) => s + p.w, 0);
|
|
293
|
+
const score = totalW === 0 ? 0 : parts.reduce((s, p) => s + p.w * p.v, 0) / totalW;
|
|
294
|
+
const evidence = {
|
|
295
|
+
candidateA11y: [...candA].sort(),
|
|
296
|
+
canonicalA11y: [...canonA].sort(),
|
|
297
|
+
candidateTestId: [...candT].sort(),
|
|
298
|
+
canonicalTestId: [...canonT].sort(),
|
|
299
|
+
a11ySimilarity: a11ySim,
|
|
300
|
+
testIdSimilarity: testSim,
|
|
301
|
+
form,
|
|
302
|
+
...(form === "semantic"
|
|
303
|
+
? {
|
|
304
|
+
candidateAnnouncements: candAnn.map((e) => `${e.role || e.tag}${e.name ? ` "${e.name}"` : ""}${e.states.length ? ` [${e.states.join(",")}]` : ""}`),
|
|
305
|
+
canonicalAnnouncements: canonAnn.map((e) => `${e.role || e.tag}${e.name ? ` "${e.name}"` : ""}${e.states.length ? ` [${e.states.join(",")}]` : ""}`),
|
|
306
|
+
}
|
|
307
|
+
: {}),
|
|
308
|
+
};
|
|
309
|
+
return { score, evidence };
|
|
310
|
+
};
|
|
311
|
+
exports.matchA11y = matchA11y;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchBehavior = void 0;
|
|
4
|
+
const jaccard = (a, b) => {
|
|
5
|
+
if (a.size === 0 || b.size === 0)
|
|
6
|
+
return 0;
|
|
7
|
+
let inter = 0;
|
|
8
|
+
for (const t of a)
|
|
9
|
+
if (b.has(t))
|
|
10
|
+
inter += 1;
|
|
11
|
+
const union = a.size + b.size - inter;
|
|
12
|
+
return union === 0 ? 0 : inter / union;
|
|
13
|
+
};
|
|
14
|
+
const matchBehavior = (candidate, canon) => {
|
|
15
|
+
const candA = new Set((candidate.framework && candidate.framework.events) || []);
|
|
16
|
+
const canonA = new Set((canon.framework && canon.framework.events) || []);
|
|
17
|
+
const shared = new Set([...candA].filter((event) => canonA.has(event)));
|
|
18
|
+
const base = jaccard(candA, canonA);
|
|
19
|
+
const union = candA.size + canonA.size - shared.size;
|
|
20
|
+
const smallSetDiscount = Math.min(1, union / 2);
|
|
21
|
+
const score = base * smallSetDiscount;
|
|
22
|
+
return {
|
|
23
|
+
score,
|
|
24
|
+
evidence: {
|
|
25
|
+
candidateEvents: [...candA].sort(),
|
|
26
|
+
canonicalEvents: [...canonA].sort(),
|
|
27
|
+
sharedEvents: [...shared].sort(),
|
|
28
|
+
smallSetDiscount: Math.round(smallSetDiscount * 100) / 100,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.matchBehavior = matchBehavior;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const TEXT_TAGS: Set<string>;
|
|
2
|
+
declare const CONTAINER_TAGS: Set<string>;
|
|
3
|
+
declare const POSITIONED_VALUES: Set<string>;
|
|
4
|
+
declare const roleOf: (tag: any, css: any) => {
|
|
5
|
+
isText: boolean;
|
|
6
|
+
isContainer: boolean;
|
|
7
|
+
positioned: boolean;
|
|
8
|
+
hasSurface: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const relevantProps: (tag: any, css: any) => Set<string>;
|
|
11
|
+
declare const normalizeValue: (value: any) => string;
|
|
12
|
+
declare const compareCss: (tagA: any, cssA: any, tagB: any, cssB: any) => {
|
|
13
|
+
rows: any[];
|
|
14
|
+
same: number;
|
|
15
|
+
total: number;
|
|
16
|
+
score: number;
|
|
17
|
+
};
|
|
18
|
+
export { roleOf, relevantProps, compareCss, normalizeValue, TEXT_TAGS, CONTAINER_TAGS, POSITIONED_VALUES };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POSITIONED_VALUES = exports.CONTAINER_TAGS = exports.TEXT_TAGS = exports.normalizeValue = exports.compareCss = exports.relevantProps = exports.roleOf = void 0;
|
|
4
|
+
// ── CSS MATCHING · which styles matter for which element ───────────────────
|
|
5
|
+
//
|
|
6
|
+
// Two buttons are both buttons — but is one blue and the other red? Does one
|
|
7
|
+
// have `cursor: pointer` and the other not? Styles are compared per ELEMENT
|
|
8
|
+
// ROLE: what matters for a text element is not what matters for a container.
|
|
9
|
+
//
|
|
10
|
+
// text (button, span, b, strong, i, em, label, a, headings, icon…)
|
|
11
|
+
// → typography (font, size, weight, style), color, cursor,
|
|
12
|
+
// text-decoration, text-transform, letter-spacing
|
|
13
|
+
// container (div, span-as-box, main, section, header, footer, nav, aside,
|
|
14
|
+
// fieldset, form, ul, li…)
|
|
15
|
+
// → layout: display, flex/grid, gap, width/height, margin, padding,
|
|
16
|
+
// overflow, box-sizing
|
|
17
|
+
// positioned (ANY element with position: relative / absolute / fixed / sticky)
|
|
18
|
+
// → the container set PLUS the offsets: top, right, bottom, left,
|
|
19
|
+
// z-index, inset
|
|
20
|
+
// surface (anything carrying a background / border / shadow / texture)
|
|
21
|
+
// → background, border, radius, shadow, opacity, outline
|
|
22
|
+
//
|
|
23
|
+
// A property is compared only when it is RELEVANT to the element's role; an
|
|
24
|
+
// irrelevant difference (a container's font-size) is not evidence either way.
|
|
25
|
+
// Values are normalized before comparison (case, whitespace, `0px` ≡ `0`).
|
|
26
|
+
const TEXT_TAGS = new Set([
|
|
27
|
+
"button", "a", "span", "b", "strong", "i", "em", "u", "s", "small", "sub", "sup",
|
|
28
|
+
"label", "h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "pre", "kbd", "samp",
|
|
29
|
+
"var", "cite", "q", "abbr", "mark", "time", "legend", "summary", "figcaption",
|
|
30
|
+
"input", "textarea", "select", "option",
|
|
31
|
+
]);
|
|
32
|
+
exports.TEXT_TAGS = TEXT_TAGS;
|
|
33
|
+
const CONTAINER_TAGS = new Set([
|
|
34
|
+
"div", "main", "section", "header", "footer", "nav", "aside", "article",
|
|
35
|
+
"fieldset", "form", "ul", "ol", "li", "dl", "dt", "dd", "table", "thead",
|
|
36
|
+
"tbody", "tfoot", "tr", "td", "th", "figure", "dialog", "details", "menu",
|
|
37
|
+
"address", "hgroup", "search", "picture", "span",
|
|
38
|
+
]);
|
|
39
|
+
exports.CONTAINER_TAGS = CONTAINER_TAGS;
|
|
40
|
+
// Typography: how the text LOOKS.
|
|
41
|
+
const TYPOGRAPHY = [
|
|
42
|
+
"font", "font-family", "font-size", "font-weight", "font-style", "font-variant",
|
|
43
|
+
"line-height", "letter-spacing", "word-spacing", "text-align", "text-decoration",
|
|
44
|
+
"text-decoration-line", "text-decoration-color", "text-decoration-style",
|
|
45
|
+
"text-transform", "text-indent", "text-shadow", "white-space", "writing-mode",
|
|
46
|
+
];
|
|
47
|
+
// Color & texture: how the surface LOOKS.
|
|
48
|
+
const COLOR = ["color", "caret-color", "accent-color"];
|
|
49
|
+
const SURFACE = [
|
|
50
|
+
"background", "background-color", "background-image", "background-size",
|
|
51
|
+
"background-position", "background-repeat", "background-blend-mode",
|
|
52
|
+
"border", "border-width", "border-style", "border-color",
|
|
53
|
+
"border-top", "border-right", "border-bottom", "border-left",
|
|
54
|
+
"border-top-width", "border-top-style", "border-top-color",
|
|
55
|
+
"border-right-width", "border-right-style", "border-right-color",
|
|
56
|
+
"border-bottom-width", "border-bottom-style", "border-bottom-color",
|
|
57
|
+
"border-left-width", "border-left-style", "border-left-color",
|
|
58
|
+
"border-radius", "border-top-left-radius", "border-top-right-radius",
|
|
59
|
+
"border-bottom-left-radius", "border-bottom-right-radius",
|
|
60
|
+
"box-shadow", "outline", "outline-width", "outline-style", "outline-color",
|
|
61
|
+
"opacity", "filter", "backdrop-filter", "mix-blend-mode",
|
|
62
|
+
];
|
|
63
|
+
// Layout: where the box SITSS and how big it is.
|
|
64
|
+
const LAYOUT = [
|
|
65
|
+
"display", "flex", "flex-direction", "flex-wrap", "flex-grow", "flex-shrink",
|
|
66
|
+
"flex-basis", "flex-flow", "align-items", "align-self", "align-content",
|
|
67
|
+
"justify-content", "justify-items", "justify-self", "gap", "row-gap", "column-gap",
|
|
68
|
+
"grid", "grid-template", "grid-template-columns", "grid-template-rows",
|
|
69
|
+
"grid-template-areas", "grid-auto-columns", "grid-auto-rows", "grid-auto-flow",
|
|
70
|
+
"grid-column", "grid-row", "grid-area", "grid-gap",
|
|
71
|
+
"width", "min-width", "max-width", "height", "min-height", "max-height",
|
|
72
|
+
"aspect-ratio", "box-sizing", "overflow", "overflow-x", "overflow-y",
|
|
73
|
+
"margin", "margin-top", "margin-right", "margin-bottom", "margin-left",
|
|
74
|
+
"margin-inline", "margin-block", "padding", "padding-top", "padding-right",
|
|
75
|
+
"padding-bottom", "padding-left", "padding-inline", "padding-block",
|
|
76
|
+
"float", "clear", "order", "visibility", "object-fit", "object-position",
|
|
77
|
+
"transform", "translate", "scale", "rotate",
|
|
78
|
+
];
|
|
79
|
+
// Offsets: only meaningful once the element is POSITIONED.
|
|
80
|
+
const OFFSETS = [
|
|
81
|
+
"position", "top", "right", "bottom", "left", "z-index",
|
|
82
|
+
"inset", "inset-block", "inset-inline",
|
|
83
|
+
];
|
|
84
|
+
// Interaction affordances: a button without cursor:pointer is a different button.
|
|
85
|
+
const INTERACTION = ["cursor", "pointer-events", "user-select", "touch-action"];
|
|
86
|
+
const POSITIONED_VALUES = new Set(["relative", "absolute", "fixed", "sticky"]);
|
|
87
|
+
exports.POSITIONED_VALUES = POSITIONED_VALUES;
|
|
88
|
+
// The role of an element decides which property groups are compared.
|
|
89
|
+
const roleOf = (tag, css) => {
|
|
90
|
+
const t = String(tag || "").toLowerCase();
|
|
91
|
+
const position = String((css || {}).position || "").toLowerCase();
|
|
92
|
+
const positioned = POSITIONED_VALUES.has(position);
|
|
93
|
+
const isText = TEXT_TAGS.has(t);
|
|
94
|
+
const isContainer = CONTAINER_TAGS.has(t) && !isText;
|
|
95
|
+
const hasSurface = SURFACE.some((prop) => (css || {})[prop] !== undefined);
|
|
96
|
+
return { isText, isContainer, positioned, hasSurface };
|
|
97
|
+
};
|
|
98
|
+
exports.roleOf = roleOf;
|
|
99
|
+
// The properties that MATTER for one element: the union of the groups its role
|
|
100
|
+
// activates. `position` itself is always relevant (it changes the role).
|
|
101
|
+
const relevantProps = (tag, css) => {
|
|
102
|
+
const role = roleOf(tag, css);
|
|
103
|
+
const props = new Set(["position"]);
|
|
104
|
+
if (role.isText) {
|
|
105
|
+
for (const p of TYPOGRAPHY)
|
|
106
|
+
props.add(p);
|
|
107
|
+
for (const p of COLOR)
|
|
108
|
+
props.add(p);
|
|
109
|
+
for (const p of INTERACTION)
|
|
110
|
+
props.add(p);
|
|
111
|
+
}
|
|
112
|
+
if (role.isContainer || role.positioned) {
|
|
113
|
+
for (const p of LAYOUT)
|
|
114
|
+
props.add(p);
|
|
115
|
+
}
|
|
116
|
+
if (role.positioned) {
|
|
117
|
+
for (const p of OFFSETS)
|
|
118
|
+
props.add(p);
|
|
119
|
+
}
|
|
120
|
+
if (role.hasSurface || role.isText) {
|
|
121
|
+
for (const p of SURFACE)
|
|
122
|
+
props.add(p);
|
|
123
|
+
}
|
|
124
|
+
// A positioned text element still sits somewhere: give it the layout set too.
|
|
125
|
+
if (role.positioned && role.isText) {
|
|
126
|
+
for (const p of LAYOUT)
|
|
127
|
+
props.add(p);
|
|
128
|
+
}
|
|
129
|
+
return props;
|
|
130
|
+
};
|
|
131
|
+
exports.relevantProps = relevantProps;
|
|
132
|
+
// Normalize a value so `0px` ≡ `0`, `RED` ≡ `red`, `1px solid` ≡ `1px solid`.
|
|
133
|
+
const normalizeValue = (value) => String(value ?? "")
|
|
134
|
+
.toLowerCase()
|
|
135
|
+
.replace(/\s+/g, " ")
|
|
136
|
+
.replace(/\b0(px|em|rem|%|vh|vw)\b/g, "0")
|
|
137
|
+
.trim();
|
|
138
|
+
exports.normalizeValue = normalizeValue;
|
|
139
|
+
// Compare the styles of two matched nodes. Only RELEVANT properties count; a
|
|
140
|
+
// property present on one side only is a difference (one button has a shadow,
|
|
141
|
+
// the other does not). Returns the per-property verdicts and an agreement score.
|
|
142
|
+
const compareCss = (tagA, cssA, tagB, cssB) => {
|
|
143
|
+
const a = cssA || {};
|
|
144
|
+
const b = cssB || {};
|
|
145
|
+
const relevant = new Set([...relevantProps(tagA, a), ...relevantProps(tagB, b)]);
|
|
146
|
+
const props = [...relevant].filter((p) => a[p] !== undefined || b[p] !== undefined).sort();
|
|
147
|
+
const rows = [];
|
|
148
|
+
let same = 0;
|
|
149
|
+
for (const prop of props) {
|
|
150
|
+
const va = a[prop] === undefined ? null : normalizeValue(a[prop]);
|
|
151
|
+
const vb = b[prop] === undefined ? null : normalizeValue(b[prop]);
|
|
152
|
+
const equal = va !== null && vb !== null && va === vb;
|
|
153
|
+
if (equal)
|
|
154
|
+
same += 1;
|
|
155
|
+
rows.push({ prop, left: va, right: vb, same: equal });
|
|
156
|
+
}
|
|
157
|
+
return { rows, same, total: props.length, score: props.length === 0 ? 1 : same / props.length };
|
|
158
|
+
};
|
|
159
|
+
exports.compareCss = compareCss;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getFrameworkMatcher = void 0;
|
|
27
|
+
const react = __importStar(require("./react.js"));
|
|
28
|
+
const REGISTRY = {
|
|
29
|
+
react,
|
|
30
|
+
};
|
|
31
|
+
const getFrameworkMatcher = (framework) => {
|
|
32
|
+
if (!framework)
|
|
33
|
+
return react;
|
|
34
|
+
const key = String(framework).toLowerCase();
|
|
35
|
+
return REGISTRY[key] || react;
|
|
36
|
+
};
|
|
37
|
+
exports.getFrameworkMatcher = getFrameworkMatcher;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const matchFramework: (candidate: any, canon: any) => {
|
|
2
|
+
score: number;
|
|
3
|
+
evidence: {
|
|
4
|
+
candidateUsages: any;
|
|
5
|
+
canonicalUsages: any;
|
|
6
|
+
sharedComponents: unknown[];
|
|
7
|
+
pairs: any[];
|
|
8
|
+
nameSimilarity: number;
|
|
9
|
+
passedPropSimilarity: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export { matchFramework };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchFramework = void 0;
|
|
4
|
+
// The FRAMEWORK signal: which components each side USES, and what props it
|
|
5
|
+
// PASSES to them. Usage against usage — a `Button` used with `onClick` on both
|
|
6
|
+
// sides is the same framework fact. The props a component ACCEPTS in its
|
|
7
|
+
// parameter list are NOT compared here (that is a different question).
|
|
8
|
+
const matchFramework = (candidate, canon) => {
|
|
9
|
+
const candUsages = (candidate.framework && candidate.framework.usages) || [];
|
|
10
|
+
const canonUsages = (canon.framework && canon.framework.usages) || [];
|
|
11
|
+
// Match usages by component name, in order (a name used twice pairs by occurrence).
|
|
12
|
+
const pairs = [];
|
|
13
|
+
const used = new Set();
|
|
14
|
+
let cursor = 0;
|
|
15
|
+
for (const a of candUsages) {
|
|
16
|
+
let found = -1;
|
|
17
|
+
for (let j = cursor; j < canonUsages.length; j += 1) {
|
|
18
|
+
if (!used.has(j) && canonUsages[j].name === a.name) {
|
|
19
|
+
found = j;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (found === -1) {
|
|
24
|
+
for (let j = 0; j < cursor; j += 1) {
|
|
25
|
+
if (!used.has(j) && canonUsages[j].name === a.name) {
|
|
26
|
+
found = j;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (found >= 0) {
|
|
32
|
+
used.add(found);
|
|
33
|
+
cursor = found + 1;
|
|
34
|
+
pairs.push({ left: a, right: canonUsages[found] });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const candNames = new Set(candUsages.map((u) => u.name));
|
|
38
|
+
const canonNames = new Set(canonUsages.map((u) => u.name));
|
|
39
|
+
const sharedNames = [...candNames].filter((n) => canonNames.has(n));
|
|
40
|
+
const unionNames = new Set([...candNames, ...canonNames]);
|
|
41
|
+
const nameSim = unionNames.size === 0 ? 0 : sharedNames.length / unionNames.size;
|
|
42
|
+
let propSame = 0;
|
|
43
|
+
let propTotal = 0;
|
|
44
|
+
const details = [];
|
|
45
|
+
for (const pair of pairs) {
|
|
46
|
+
const a = new Set(pair.left.props || []);
|
|
47
|
+
const b = new Set(pair.right.props || []);
|
|
48
|
+
const inter = [...a].filter((p) => b.has(p)).length;
|
|
49
|
+
const uni = new Set([...a, ...b]).size;
|
|
50
|
+
propSame += inter;
|
|
51
|
+
propTotal += uni;
|
|
52
|
+
details.push({ name: pair.left.name, leftLine: pair.left.line, rightLine: pair.right.line, sharedProps: [...a].filter((p) => b.has(p)).sort(), leftProps: [...a].sort(), rightProps: [...b].sort() });
|
|
53
|
+
}
|
|
54
|
+
const propSim = propTotal === 0 ? 0 : propSame / propTotal;
|
|
55
|
+
// Names dominate (using the same component is the fact); passed props refine it.
|
|
56
|
+
// No shared usage at all → no framework evidence, score 0 (never a free 0.3).
|
|
57
|
+
const score = pairs.length === 0 ? 0 : 0.7 * nameSim + 0.3 * propSim;
|
|
58
|
+
return {
|
|
59
|
+
score,
|
|
60
|
+
evidence: {
|
|
61
|
+
candidateUsages: candUsages.map((u) => u.name),
|
|
62
|
+
canonicalUsages: canonUsages.map((u) => u.name),
|
|
63
|
+
sharedComponents: sharedNames.sort(),
|
|
64
|
+
pairs: details,
|
|
65
|
+
nameSimilarity: nameSim,
|
|
66
|
+
passedPropSimilarity: propSim,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.matchFramework = matchFramework;
|