@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.
Files changed (189) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +202 -0
  3. package/README.md +21 -3
  4. package/dist/config.d.ts +50 -0
  5. package/dist/config.js +402 -0
  6. package/dist/constants.d.ts +55 -0
  7. package/dist/constants.js +86 -0
  8. package/dist/decision-maker.d.ts +39 -0
  9. package/dist/decision-maker.js +119 -0
  10. package/dist/filter/child-element.d.ts +3 -0
  11. package/dist/filter/child-element.js +17 -0
  12. package/dist/filter/missing-component.d.ts +10 -0
  13. package/dist/filter/missing-component.js +96 -0
  14. package/dist/filter/no-structure.d.ts +3 -0
  15. package/dist/filter/no-structure.js +16 -0
  16. package/dist/filter/usages.d.ts +3 -0
  17. package/dist/filter/usages.js +14 -0
  18. package/dist/index.d.ts +105 -0
  19. package/dist/index.js +244 -0
  20. package/dist/lib-registry.d.ts +4 -0
  21. package/dist/lib-registry.js +376 -0
  22. package/dist/logger.d.ts +7 -0
  23. package/dist/logger.js +70 -0
  24. package/dist/main.d.ts +25 -0
  25. package/dist/main.js +666 -0
  26. package/dist/matcher/a11y.d.ts +19 -0
  27. package/dist/matcher/a11y.js +311 -0
  28. package/dist/matcher/behavior.d.ts +10 -0
  29. package/dist/matcher/behavior.js +32 -0
  30. package/dist/matcher/css-matching.d.ts +18 -0
  31. package/dist/matcher/css-matching.js +159 -0
  32. package/dist/matcher/framework/index.d.ts +2 -0
  33. package/dist/matcher/framework/index.js +37 -0
  34. package/dist/matcher/framework/react.d.ts +12 -0
  35. package/dist/matcher/framework/react.js +70 -0
  36. package/dist/matcher/index.d.ts +64 -0
  37. package/dist/matcher/index.js +38 -0
  38. package/dist/matcher/name.d.ts +15 -0
  39. package/dist/matcher/name.js +154 -0
  40. package/dist/matcher/structure.d.ts +22 -0
  41. package/dist/matcher/structure.js +329 -0
  42. package/dist/matcher/styles.d.ts +20 -0
  43. package/dist/matcher/styles.js +49 -0
  44. package/dist/normalize/candidate.d.ts +3 -0
  45. package/dist/normalize/candidate.js +21 -0
  46. package/dist/normalize/dom.d.ts +22 -0
  47. package/dist/normalize/dom.js +180 -0
  48. package/dist/normalize/external-html.d.ts +5 -0
  49. package/dist/normalize/external-html.js +40 -0
  50. package/dist/normalize/framework.d.ts +20 -0
  51. package/dist/normalize/framework.js +130 -0
  52. package/dist/normalize/resolver.d.ts +7 -0
  53. package/dist/normalize/resolver.js +28 -0
  54. package/dist/normalize/style-resolver.d.ts +7 -0
  55. package/dist/normalize/style-resolver.js +28 -0
  56. package/dist/normalize/style.d.ts +15 -0
  57. package/dist/normalize/style.js +174 -0
  58. package/dist/normalize/words.d.ts +3 -0
  59. package/dist/normalize/words.js +40 -0
  60. package/dist/package.json +88 -0
  61. package/dist/playgrounds/angular.d.ts +7 -0
  62. package/dist/playgrounds/angular.js +9 -0
  63. package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
  64. package/dist/playgrounds/framework-entrypoint.js +102 -0
  65. package/dist/playgrounds/framework.d.ts +10 -0
  66. package/dist/playgrounds/framework.js +102 -0
  67. package/dist/playgrounds/react.d.ts +14 -0
  68. package/dist/playgrounds/react.js +1288 -0
  69. package/dist/playgrounds/scss.d.ts +6 -0
  70. package/dist/playgrounds/scss.js +9 -0
  71. package/dist/playgrounds/style-entrypoint.d.ts +13 -0
  72. package/dist/playgrounds/style-entrypoint.js +82 -0
  73. package/dist/playgrounds/style.d.ts +13 -0
  74. package/dist/playgrounds/style.js +82 -0
  75. package/dist/playgrounds/styled-components.d.ts +7 -0
  76. package/dist/playgrounds/styled-components.js +190 -0
  77. package/dist/playgrounds/tailwind.d.ts +15 -0
  78. package/dist/playgrounds/tailwind.js +256 -0
  79. package/dist/playgrounds/vue.d.ts +7 -0
  80. package/dist/playgrounds/vue.js +9 -0
  81. package/dist/report/asks.d.ts +27 -0
  82. package/dist/report/asks.js +28 -0
  83. package/dist/report/cli-report.d.ts +7 -0
  84. package/dist/report/cli-report.js +187 -0
  85. package/dist/report/codes/index.d.ts +37 -0
  86. package/dist/report/codes/index.js +31 -0
  87. package/dist/report/errorTypes/index.d.ts +92 -0
  88. package/dist/report/errorTypes/index.js +186 -0
  89. package/dist/report/evidence.d.ts +2 -0
  90. package/dist/report/evidence.js +8 -0
  91. package/dist/report/explain.d.ts +27 -0
  92. package/dist/report/explain.js +76 -0
  93. package/dist/report/index.d.ts +2 -0
  94. package/dist/report/index.js +24 -0
  95. package/dist/report/matchers/a11y/model.d.ts +20 -0
  96. package/dist/report/matchers/a11y/model.js +14 -0
  97. package/dist/report/matchers/a11y/text.d.ts +2 -0
  98. package/dist/report/matchers/a11y/text.js +22 -0
  99. package/dist/report/matchers/behavior/model.d.ts +20 -0
  100. package/dist/report/matchers/behavior/model.js +12 -0
  101. package/dist/report/matchers/behavior/text.d.ts +2 -0
  102. package/dist/report/matchers/behavior/text.js +22 -0
  103. package/dist/report/matchers/framework/model.d.ts +10 -0
  104. package/dist/report/matchers/framework/model.js +39 -0
  105. package/dist/report/matchers/framework/text.d.ts +2 -0
  106. package/dist/report/matchers/framework/text.js +26 -0
  107. package/dist/report/matchers/index.d.ts +5 -0
  108. package/dist/report/matchers/index.js +97 -0
  109. package/dist/report/matchers/name/model.d.ts +20 -0
  110. package/dist/report/matchers/name/model.js +30 -0
  111. package/dist/report/matchers/name/text.d.ts +2 -0
  112. package/dist/report/matchers/name/text.js +17 -0
  113. package/dist/report/matchers/set-model.d.ts +31 -0
  114. package/dist/report/matchers/set-model.js +42 -0
  115. package/dist/report/matchers/structure/model.d.ts +10 -0
  116. package/dist/report/matchers/structure/model.js +58 -0
  117. package/dist/report/matchers/structure/text.d.ts +2 -0
  118. package/dist/report/matchers/structure/text.js +40 -0
  119. package/dist/report/matchers/styles/model.d.ts +11 -0
  120. package/dist/report/matchers/styles/model.js +36 -0
  121. package/dist/report/matchers/styles/text.d.ts +2 -0
  122. package/dist/report/matchers/styles/text.js +40 -0
  123. package/dist/report/user-report/build/bundle.d.ts +3 -0
  124. package/dist/report/user-report/build/bundle.js +185 -0
  125. package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
  126. package/dist/report/user-report/data/collect.d.ts +68 -0
  127. package/dist/report/user-report/data/collect.js +150 -0
  128. package/dist/report/user-report/data/folders.d.ts +3 -0
  129. package/dist/report/user-report/data/folders.js +73 -0
  130. package/dist/report/user-report/data/groups.d.ts +13 -0
  131. package/dist/report/user-report/data/groups.js +76 -0
  132. package/dist/report/user-report/data/links.d.ts +39 -0
  133. package/dist/report/user-report/data/links.js +222 -0
  134. package/dist/report/user-report/data/snapshot.d.ts +9 -0
  135. package/dist/report/user-report/data/snapshot.js +180 -0
  136. package/dist/report/user-report/data/source.d.ts +13 -0
  137. package/dist/report/user-report/data/source.js +58 -0
  138. package/dist/report/user-report/data/word.d.ts +3 -0
  139. package/dist/report/user-report/data/word.js +32 -0
  140. package/dist/report/user-report/html/shell.d.ts +2 -0
  141. package/dist/report/user-report/html/shell.js +27 -0
  142. package/dist/report/user-report/index.d.ts +7 -0
  143. package/dist/report/user-report/index.js +47 -0
  144. package/dist/report/vocabulary/evidence.d.ts +48 -0
  145. package/dist/report/vocabulary/evidence.js +66 -0
  146. package/dist/report/vocabulary/format.d.ts +4 -0
  147. package/dist/report/vocabulary/format.js +20 -0
  148. package/dist/report/vocabulary/labels.d.ts +134 -0
  149. package/dist/report/vocabulary/labels.js +87 -0
  150. package/dist/report/vocabulary/phrases.d.ts +20 -0
  151. package/dist/report/vocabulary/phrases.js +34 -0
  152. package/dist/self-catalog.d.ts +4 -0
  153. package/dist/self-catalog.js +179 -0
  154. package/dist/utils.d.ts +6 -0
  155. package/dist/utils.js +125 -0
  156. package/package.json +86 -71
  157. package/config.js +0 -372
  158. package/decision-maker.js +0 -109
  159. package/filter/drop-child-element.js +0 -14
  160. package/filter/drop-no-structure.js +0 -13
  161. package/filter/drop-usages.js +0 -13
  162. package/filter/missing-component.js +0 -100
  163. package/index.js +0 -184
  164. package/logger.js +0 -44
  165. package/main.js +0 -584
  166. package/matcher/a11y.js +0 -65
  167. package/matcher/behavior.js +0 -31
  168. package/matcher/framework/index.js +0 -15
  169. package/matcher/framework/react.js +0 -25
  170. package/matcher/index.js +0 -36
  171. package/matcher/name.js +0 -132
  172. package/matcher/structure.js +0 -242
  173. package/normalize/candidate.js +0 -22
  174. package/normalize/dom.js +0 -187
  175. package/normalize/framework.js +0 -110
  176. package/normalize/style-resolver.js +0 -24
  177. package/normalize/style.js +0 -175
  178. package/normalize/words.js +0 -40
  179. package/playgrounds/angular.js +0 -11
  180. package/playgrounds/framework-entrypoint.js +0 -90
  181. package/playgrounds/react.js +0 -998
  182. package/playgrounds/scss.js +0 -7
  183. package/playgrounds/style-entrypoint.js +0 -78
  184. package/playgrounds/styled-components.js +0 -138
  185. package/playgrounds/tailwind.js +0 -186
  186. package/playgrounds/vue.js +0 -11
  187. package/plugin.js +0 -3
  188. package/report.js +0 -162
  189. package/utils.js +0 -92
@@ -0,0 +1,68 @@
1
+ declare const spanForPlace: (repoRoot: any, item: any) => {
2
+ name: any;
3
+ path: any;
4
+ line: any;
5
+ startLine: any;
6
+ endLine: any;
7
+ lines: any[];
8
+ missing: boolean;
9
+ };
10
+ declare const collectOverviewData: ({ comp, repoRoot, config, candidates, generatedAt }: any) => {
11
+ meta: {
12
+ tool: string;
13
+ version: string;
14
+ repoRoot: any;
15
+ repoName: string;
16
+ generatedAt: any;
17
+ scanRoots: any;
18
+ weights: any;
19
+ thresholds: any;
20
+ filesScanned: any;
21
+ canonCount: any;
22
+ appCount: any;
23
+ roots: any[];
24
+ };
25
+ stats: {
26
+ findings: number;
27
+ duplicates: number;
28
+ similar: number;
29
+ missing: number;
30
+ rawHtml: number;
31
+ parts: number;
32
+ dropped: number;
33
+ pairs: number;
34
+ groups: number;
35
+ folders: any;
36
+ };
37
+ byKind: {
38
+ value: any;
39
+ count: any;
40
+ }[];
41
+ signals: {
42
+ key: "structure" | "styles" | "behavior" | "a11y" | "framework" | "name";
43
+ label: string;
44
+ short: string;
45
+ color: string;
46
+ what: string;
47
+ }[];
48
+ findings: any[];
49
+ pairs: any[];
50
+ groups: {
51
+ id: string;
52
+ kind: "missing";
53
+ name: any;
54
+ canonical: any;
55
+ members: any[];
56
+ findingIds: any;
57
+ count: number;
58
+ maxConfidence: number;
59
+ minConfidence: number;
60
+ duplicates: number;
61
+ }[];
62
+ folders: any;
63
+ decisions: {
64
+ weights: any;
65
+ thresholds: any;
66
+ };
67
+ };
68
+ export { collectOverviewData, spanForPlace };
@@ -0,0 +1,150 @@
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.spanForPlace = exports.collectOverviewData = void 0;
27
+ // Assemble the ONE JSON payload the overview renders.
28
+ //
29
+ // The MODEL states facts only: the two source spans (raw lines), the SEMANTIC
30
+ // links (which token matches which, per signal), the per-signal scores, the
31
+ // decision and the CLI block. It computes NO diff, NO character range, NO mark —
32
+ // code-diff does all of that in the browser from these facts. The HTML file is
33
+ // self-contained: openable from disk, no server, no network, no sidecar files.
34
+ const path = __importStar(require("node:path"));
35
+ const pkg = __importStar(require("../../../package.json"));
36
+ const decision_maker_1 = require("../../../decision-maker");
37
+ const errorTypes_1 = require("../../errorTypes");
38
+ const cli_report_1 = require("../../cli-report");
39
+ const labels_1 = require("../../vocabulary/labels");
40
+ const groups_1 = require("./groups");
41
+ const folders_1 = require("./folders");
42
+ const source = __importStar(require("./source"));
43
+ const matchers_1 = require("../../matchers");
44
+ const links_1 = require("./links");
45
+ const snapshot_1 = require("./snapshot");
46
+ const constants_1 = require("../../../constants");
47
+ // A pair (duplicate/similar) and a copied part are shown side-by-side; a missing
48
+ // cluster, raw-html element and filtered-out pair are informational rows.
49
+ const DIFFABLE = new Set([constants_1.KIND.Duplicate, constants_1.KIND.Similar, constants_1.KIND.Part]);
50
+ const abs = (repoRoot, relPath) => (path.isAbsolute(relPath) ? relPath : path.resolve(repoRoot, relPath));
51
+ const spanForPlace = (repoRoot, item) => {
52
+ if (!item || !item.path)
53
+ return null;
54
+ const span = source.spanOf(abs(repoRoot, item.path), item.line, item.endLine ?? item.line);
55
+ return { name: item.name ?? null, path: item.path, line: item.line ?? span.startLine, startLine: span.startLine, endLine: span.endLine, lines: span.lines.map((l) => l.text), missing: span.missing };
56
+ };
57
+ exports.spanForPlace = spanForPlace;
58
+ // The CLI block for a pair: the single string the terminal prints for it.
59
+ const cliText = (finding, candidates) => (0, cli_report_1.findingText)(finding, candidates);
60
+ const buildPair = ({ finding, repoRoot, candidates }) => {
61
+ const left = spanForPlace(repoRoot, finding.left);
62
+ const right = spanForPlace(repoRoot, finding.right);
63
+ if (!left || !right || left.missing || right.missing)
64
+ return null;
65
+ const leftComp = candidates.get(`${finding.left.path}#${finding.left.name}`);
66
+ const rightComp = candidates.get(`${finding.right?.path}#${finding.right?.name}`);
67
+ // The matcher models read the ENGINE decision (signals keyed by name), not the
68
+ // explained one (signals as an array of rows for the panel).
69
+ const analysis = (0, matchers_1.analyze)(leftComp, rightComp, finding.evidence?.engine ?? null);
70
+ const links = (0, links_1.linksBySignal)(analysis, left, right);
71
+ // The expanded HTML snapshot and the screen-reader view of each side: the
72
+ // material the Structure and Accessibility boards draw in their middle columns.
73
+ const snapshots = { left: (0, snapshot_1.snapshotOf)(leftComp, left), right: (0, snapshot_1.snapshotOf)(rightComp, right) };
74
+ return {
75
+ findingId: finding.id,
76
+ kind: finding.kind,
77
+ columns: [{ path: finding.left.path }, { path: finding.right?.path }],
78
+ left,
79
+ right,
80
+ links,
81
+ analysis,
82
+ snapshots,
83
+ cli: cliText(finding, candidates),
84
+ };
85
+ };
86
+ const countBy = (findings, key) => {
87
+ const map = new Map();
88
+ for (const finding of findings)
89
+ map.set(finding[key], (map.get(finding[key]) ?? 0) + 1);
90
+ return [...map.entries()].map(([value, count]) => ({ value, count }));
91
+ };
92
+ const collectOverviewData = ({ comp, repoRoot, config = {}, candidates = [], generatedAt }) => {
93
+ const findings = (0, errorTypes_1.describeComp)(comp);
94
+ const candidateMap = new Map(candidates.map((c) => [`${c.path}#${c.name}`, c]));
95
+ const pairs = [];
96
+ const pairsById = new Map();
97
+ for (const finding of findings) {
98
+ if (!DIFFABLE.has(finding.kind))
99
+ continue;
100
+ const pair = buildPair({ finding, repoRoot, candidates: candidateMap });
101
+ if (!pair)
102
+ continue;
103
+ pairs.push(pair);
104
+ pairsById.set(finding.id, pair.findingId);
105
+ }
106
+ const withPair = findings.map((finding) => ({ ...finding, hasPair: pairsById.has(finding.id) }));
107
+ withPair.sort((a, b) => (b.confidence ?? 0) - (a.confidence ?? 0));
108
+ const groups = (0, groups_1.buildGroups)(withPair);
109
+ const folders = (0, folders_1.buildFolders)(withPair);
110
+ const folderCount = (node) => 1 + node.children.reduce((sum, child) => sum + folderCount(child), 0);
111
+ const roots = new Set(findings.map((f) => (f.left?.path ?? "").split("/")[0]).filter(Boolean));
112
+ const weights = { ...decision_maker_1.DEFAULT_WEIGHTS, ...(config.weights ?? {}) };
113
+ const thresholds = { ...decision_maker_1.DEFAULT_THRESHOLDS, ...(config.thresholds ?? {}) };
114
+ return {
115
+ meta: {
116
+ tool: pkg.name,
117
+ version: pkg.version,
118
+ repoRoot,
119
+ repoName: path.basename(repoRoot),
120
+ generatedAt: generatedAt ?? new Date().toISOString(),
121
+ scanRoots: config.componentsFolder ?? [],
122
+ weights,
123
+ thresholds,
124
+ filesScanned: comp.files ?? 0,
125
+ canonCount: comp.canonCount ?? 0,
126
+ appCount: comp.appCount ?? 0,
127
+ roots: [...roots],
128
+ },
129
+ stats: {
130
+ findings: withPair.length,
131
+ duplicates: withPair.filter((f) => f.kind === constants_1.KIND.Duplicate).length,
132
+ similar: withPair.filter((f) => f.kind === constants_1.KIND.Similar).length,
133
+ missing: withPair.filter((f) => f.kind === constants_1.KIND.Missing).length,
134
+ rawHtml: withPair.filter((f) => f.kind === constants_1.KIND.RawHtml).length,
135
+ parts: withPair.filter((f) => f.kind === constants_1.KIND.Part).length,
136
+ dropped: withPair.filter((f) => f.kind === constants_1.KIND.Dropped).length,
137
+ pairs: pairs.length,
138
+ groups: groups.length,
139
+ folders: folderCount(folders),
140
+ },
141
+ byKind: countBy(withPair, "kind"),
142
+ signals: labels_1.SIGNALS.map((s) => ({ key: s.key, label: s.label, short: s.short, color: s.color, what: s.what })),
143
+ findings: withPair,
144
+ pairs,
145
+ groups,
146
+ folders,
147
+ decisions: { weights, thresholds },
148
+ };
149
+ };
150
+ exports.collectOverviewData = collectOverviewData;
@@ -0,0 +1,3 @@
1
+ declare const dirOf: (relPath: any) => string;
2
+ declare const buildFolders: (findings: any) => any;
3
+ export { buildFolders, dirOf };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dirOf = exports.buildFolders = void 0;
4
+ const constants_1 = require("../../../constants");
5
+ // The report BY FOLDER. Findings are rolled up into the directory tree they live
6
+ // in — every folder carries the count of each kind of finding BELOW it. Only the
7
+ // LOCAL (app) side counts here: the canonical component is the answer, not the
8
+ // problem.
9
+ const emptyCounts = () => Object.fromEntries([...constants_1.KIND_LIST.map((k) => [k, 0]), ["total", 0]]);
10
+ const dirOf = (relPath) => {
11
+ const clean = String(relPath ?? "").replace(/\\/g, "/");
12
+ const idx = clean.lastIndexOf("/");
13
+ return idx === -1 ? "." : clean.slice(0, idx) || ".";
14
+ };
15
+ exports.dirOf = dirOf;
16
+ const makeNode = (dirPath) => ({
17
+ path: dirPath,
18
+ name: dirPath === "." ? "(root)" : dirPath.split("/").pop(),
19
+ depth: dirPath === "." ? 0 : dirPath.split("/").length,
20
+ counts: emptyCounts(),
21
+ childDirs: new Map(),
22
+ children: [],
23
+ findings: [],
24
+ });
25
+ const ensureNode = (tree, dirPath) => {
26
+ if (!dirPath || dirPath === ".")
27
+ return tree;
28
+ const parts = dirPath.split("/");
29
+ let node = tree;
30
+ let walked = "";
31
+ for (const part of parts) {
32
+ walked = walked ? `${walked}/${part}` : part;
33
+ if (!node.childDirs.has(walked))
34
+ node.childDirs.set(walked, makeNode(walked));
35
+ node = node.childDirs.get(walked);
36
+ }
37
+ return node;
38
+ };
39
+ const bump = (tree, dirPath, kind) => {
40
+ if (tree.counts[kind] != null)
41
+ tree.counts[kind] += 1;
42
+ tree.counts.total += 1;
43
+ let walked = "";
44
+ for (const part of String(dirPath).split("/").filter((p) => p && p !== ".")) {
45
+ walked = walked ? `${walked}/${part}` : part;
46
+ const node = ensureNode(tree, walked);
47
+ if (node.counts[kind] != null)
48
+ node.counts[kind] += 1;
49
+ node.counts.total += 1;
50
+ }
51
+ };
52
+ const finalize = (node) => ({
53
+ path: node.path,
54
+ name: node.name,
55
+ depth: node.depth,
56
+ counts: node.counts,
57
+ findings: node.findings,
58
+ children: [...node.childDirs.values()].sort((a, b) => a.path.localeCompare(b.path)).map(finalize),
59
+ });
60
+ const buildFolders = (findings) => {
61
+ const tree = makeNode(".");
62
+ for (const finding of findings) {
63
+ const dirPath = dirOf(finding.left?.path);
64
+ const node = ensureNode(tree, dirPath);
65
+ node.findings.push(finding.id);
66
+ bump(tree, dirPath, finding.kind);
67
+ }
68
+ const root = finalize(tree);
69
+ const isEmpty = (node) => node.counts.total === 0 && node.children.every(isEmpty);
70
+ const walk = (node) => (isEmpty(node) ? null : { ...node, children: node.children.map(walk).filter(Boolean) });
71
+ return walk(root) ?? { ...root, children: [] };
72
+ };
73
+ exports.buildFolders = buildFolders;
@@ -0,0 +1,13 @@
1
+ declare const buildGroups: (findings: any) => {
2
+ id: string;
3
+ kind: "missing";
4
+ name: any;
5
+ canonical: any;
6
+ members: any[];
7
+ findingIds: any;
8
+ count: number;
9
+ maxConfidence: number;
10
+ minConfidence: number;
11
+ duplicates: number;
12
+ }[];
13
+ export { buildGroups };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGroups = void 0;
4
+ const constants_1 = require("../../../constants");
5
+ // Grouping components BY SIMILARITY. A group is a CONNECTED COMPONENT of the
6
+ // pair graph: every component reachable from another through a duplicate/similar
7
+ // pair belongs to the same group. Members carry the per-pair numbers so the
8
+ // group row can show the strongest and weakest link.
9
+ const placeKey = (place) => `${place?.path ?? ""}#${place?.name ?? ""}`;
10
+ const memberOf = (place, finding) => ({
11
+ findingId: finding.id,
12
+ name: place?.name ?? "—",
13
+ path: place?.path ?? null,
14
+ line: place?.line ?? null,
15
+ confidence: finding.confidence,
16
+ tier: finding.tier,
17
+ side: place?.side ?? constants_1.SIDE.App,
18
+ });
19
+ const buildGroups = (findings) => {
20
+ const parent = new Map();
21
+ const find = (x) => {
22
+ if (!parent.has(x))
23
+ parent.set(x, x);
24
+ let root = x;
25
+ while (parent.get(root) !== root)
26
+ root = parent.get(root);
27
+ let cur = x;
28
+ while (parent.get(cur) !== root) {
29
+ const next = parent.get(cur);
30
+ parent.set(cur, root);
31
+ cur = next;
32
+ }
33
+ return root;
34
+ };
35
+ const union = (a, b) => {
36
+ const ra = find(a);
37
+ const rb = find(b);
38
+ if (ra !== rb)
39
+ parent.set(ra, rb);
40
+ };
41
+ const pairs = findings.filter((f) => f.kind === constants_1.KIND.Duplicate || f.kind === constants_1.KIND.Similar);
42
+ for (const f of pairs)
43
+ union(placeKey(f.left), placeKey(f.right));
44
+ const components = new Map();
45
+ for (const f of pairs) {
46
+ const root = find(placeKey(f.left));
47
+ if (!components.has(root))
48
+ components.set(root, { members: new Map(), findingIds: [] });
49
+ const comp = components.get(root);
50
+ comp.findingIds.push(f.id);
51
+ for (const place of [f.left, f.right]) {
52
+ const key = placeKey(place);
53
+ if (!comp.members.has(key))
54
+ comp.members.set(key, memberOf(place, f));
55
+ }
56
+ }
57
+ const groups = [...components.entries()].map(([root, comp]) => {
58
+ const members = [...comp.members.values()];
59
+ const confidences = members.map((m) => m.confidence).filter((c) => Number.isFinite(c));
60
+ const name = members.map((m) => m.name).sort()[0] ?? "—";
61
+ return {
62
+ id: `group:${root}`,
63
+ kind: constants_1.KIND.Missing,
64
+ name,
65
+ canonical: null,
66
+ members,
67
+ findingIds: comp.findingIds,
68
+ count: members.length,
69
+ maxConfidence: confidences.length ? Math.max(...confidences) : null,
70
+ minConfidence: confidences.length ? Math.min(...confidences) : null,
71
+ duplicates: members.filter((m) => m.tier === constants_1.TIER.Duplicate).length,
72
+ };
73
+ });
74
+ return groups.filter((g) => g.count >= 2).sort((a, b) => (b.maxConfidence ?? 0) - (a.maxConfidence ?? 0) || b.count - a.count || a.name.localeCompare(b.name));
75
+ };
76
+ exports.buildGroups = buildGroups;
@@ -0,0 +1,39 @@
1
+ declare const structureLinks: (model: any) => any[];
2
+ declare const behaviorLinks: (model: any, left: any, right: any) => any[];
3
+ declare const a11yLinks: (model: any) => any[];
4
+ declare const frameworkLinks: (model: any) => any[];
5
+ declare const nameLinks: (model: any) => {
6
+ connectionId: string;
7
+ label: any;
8
+ tone: string;
9
+ leftColumn: string;
10
+ rightColumn: string;
11
+ left: {
12
+ name: any;
13
+ };
14
+ right: {
15
+ name: any;
16
+ };
17
+ }[];
18
+ declare const stylesLinks: (model: any) => any[];
19
+ declare const linksBySignal: (analysis: any, left: any, right: any) => {
20
+ structure: any[];
21
+ styles: any[];
22
+ behavior: any[];
23
+ a11y: any[];
24
+ framework: any[];
25
+ name: {
26
+ connectionId: string;
27
+ label: any;
28
+ tone: string;
29
+ leftColumn: string;
30
+ rightColumn: string;
31
+ left: {
32
+ name: any;
33
+ };
34
+ right: {
35
+ name: any;
36
+ };
37
+ }[];
38
+ };
39
+ export { linksBySignal, structureLinks, stylesLinks, behaviorLinks, a11yLinks, frameworkLinks, nameLinks };
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nameLinks = exports.frameworkLinks = exports.a11yLinks = exports.behaviorLinks = exports.stylesLinks = exports.structureLinks = exports.linksBySignal = void 0;
4
+ // SEMANTIC member links — WHAT corresponds, never WHERE the characters are.
5
+ //
6
+ // The model decides which token on the left is the same as which on the right
7
+ // (a shared event, a shared prop, a shared ARIA attribute, the root tag, the
8
+ // component name). It hands these to code-diff as `MemberLink`s; code-diff
9
+ // locates the names in the rows and computes the marks and twins. No character
10
+ // range is computed here — that is the view's job.
11
+ //
12
+ // Each signal highlights a DIFFERENT part of the component, so the tabs are not
13
+ // the same picture:
14
+ //
15
+ // structure the root tag (and the matched chain's tags)
16
+ // behavior the shared event handler names (onClick…)
17
+ // a11y the shared ARIA attributes / test ids
18
+ // framework the shared props and child-component names
19
+ // name the component names themselves
20
+ const word_1 = require("./word");
21
+ const dom_1 = require("../../../normalize/dom");
22
+ const evidence_1 = require("../../evidence");
23
+ // THE COLOR MODEL: a correspondence is a duplicate (red) at ANY percent — the
24
+ // label carries the percent when it is partial; a member on ONE side only is
25
+ // 100% unique (green), drawn as a stub lane with its absent end null.
26
+ const pctLabel = (word, degree) => (degree >= 1 ? word : `${word} · ${(0, evidence_1.percentOf)(degree)}%`);
27
+ // One link per row of a set model. A shared token is red (100% — the token IS
28
+ // the same on both sides); a token on one side only keeps ONLY its own end, so
29
+ // resolveLanes draws a green stub with the inter-line continuation.
30
+ const setLinks = (model, kind, label) => {
31
+ if (!model || !model.rows)
32
+ return [];
33
+ const links = [];
34
+ for (const row of model.rows) {
35
+ const shared = row.shared === true;
36
+ links.push({
37
+ connectionId: `same:${kind}:${row.name}`,
38
+ label,
39
+ tone: shared ? "same" : "differs",
40
+ leftColumn: "0",
41
+ rightColumn: "1",
42
+ left: row.left ? { name: row.left.name, key: row.name } : null,
43
+ right: row.right ? { name: row.right.name, key: row.name } : null,
44
+ });
45
+ }
46
+ return links;
47
+ };
48
+ // The root tags correspond as containers at their tag affinity (div ≡ section
49
+ // = 75%): a partial duplicate, red with that percent. A tag on one side only is
50
+ // a green stub.
51
+ const structureLinks = (model) => {
52
+ if (!model || !model.rows)
53
+ return [];
54
+ const word = (0, word_1.wordOf)("root tags", 1);
55
+ const links = [];
56
+ for (const row of model.rows) {
57
+ if (!row.left && !row.right)
58
+ continue;
59
+ const shared = row.shared === true;
60
+ const degree = shared ? (0, dom_1.tagAffinity)(row.left?.name, row.right?.name) : 0;
61
+ links.push({
62
+ connectionId: `same:structure:${row.name}`,
63
+ label: shared ? pctLabel(word, degree) : word,
64
+ tone: shared ? "same" : "differs",
65
+ leftColumn: "0",
66
+ rightColumn: "1",
67
+ left: row.left ? { name: row.left.name, key: row.name } : null,
68
+ right: row.right ? { name: row.right.name, key: row.name } : null,
69
+ });
70
+ }
71
+ return links;
72
+ };
73
+ exports.structureLinks = structureLinks;
74
+ const behaviorLinks = (model, left, right) => {
75
+ if (!model || !model.rows)
76
+ return [];
77
+ const label = (0, word_1.wordOf)("events", model?.sharedCount ?? 0);
78
+ const links = [];
79
+ for (const row of model.rows) {
80
+ // Anchor on the handler as it is WRITTEN in each side's source — `onClick`
81
+ // (React), `(click)` (Angular), `@click` (Vue) or `onclick` (plain HTML) —
82
+ // so the ribbon underlines the actual action, not a bare event name that
83
+ // never appears in the code. An event on one side only keeps ONLY its own
84
+ // end (a green stub).
85
+ const shared = row.shared === true;
86
+ const leftName = handlerNameOf(left, row.name) ?? row.name;
87
+ const rightName = handlerNameOf(right, row.name) ?? row.name;
88
+ links.push({
89
+ connectionId: `same:behavior:${row.name}`,
90
+ label,
91
+ tone: shared ? "same" : "differs",
92
+ leftColumn: "0",
93
+ rightColumn: "1",
94
+ left: row.left ? { name: leftName, key: row.name } : null,
95
+ right: row.right ? { name: rightName, key: row.name } : null,
96
+ });
97
+ }
98
+ return links;
99
+ };
100
+ exports.behaviorLinks = behaviorLinks;
101
+ // The attribute name a side writes for an event, read from its own source lines.
102
+ // React `onClick`, Angular `(click)`, Vue `@click`/`v-on:click`, plain `onclick`.
103
+ const handlerNameOf = (side, event) => {
104
+ const lines = side?.lines ?? [];
105
+ const camel = `on${event[0]?.toUpperCase()}${event.slice(1)}`;
106
+ const candidates = [camel, `(${event})`, `@${event}`, `v-on:${event}`, `on${event}`];
107
+ for (const line of lines) {
108
+ for (const name of candidates) {
109
+ if (String(line).includes(name))
110
+ return name;
111
+ }
112
+ }
113
+ return null;
114
+ };
115
+ // ARIA tokens are written `role:button` / `aria-label:…`; the source carries the
116
+ // attribute name (the part before the colon). Anchor on that name.
117
+ const a11yLinks = (model) => {
118
+ if (!model || !model.rows)
119
+ return [];
120
+ const label = (0, word_1.wordOf)("a11y tokens", model.sharedCount ?? 0);
121
+ const links = [];
122
+ for (const row of model.rows) {
123
+ const shared = row.shared === true;
124
+ const attr = String(row.name).split(":")[0];
125
+ links.push({
126
+ connectionId: `same:a11y:${row.name}`,
127
+ label,
128
+ tone: shared ? "same" : "differs",
129
+ leftColumn: "0",
130
+ rightColumn: "1",
131
+ left: row.left ? { name: attr, key: row.name } : null,
132
+ right: row.right ? { name: attr, key: row.name } : null,
133
+ });
134
+ }
135
+ return links;
136
+ };
137
+ exports.a11yLinks = a11yLinks;
138
+ // The FRAMEWORK links: one per matched component USAGE, anchored on the exact
139
+ // source line the parser reported (`<Button …>`), never a text search that could
140
+ // land on a comment or a parameter. The label says which component is reused.
141
+ const frameworkLinks = (model) => {
142
+ if (!model || !model.rows)
143
+ return [];
144
+ const word = (0, word_1.wordOf)("component usage", 1);
145
+ const links = [];
146
+ for (const row of model.rows) {
147
+ if (!row.left && !row.right)
148
+ continue;
149
+ const shared = row.shared === true;
150
+ // The usage corresponds; the props it passes may not. No shared prop is a
151
+ // partial duplicate (50%), red — not a unique member.
152
+ const degree = row.same ? 1 : 0.5;
153
+ links.push({
154
+ connectionId: `same:framework:${row.name}:${row.left?.line ?? ""}:${row.right?.line ?? ""}`,
155
+ label: shared ? pctLabel(word, degree) : word,
156
+ tone: shared ? "same" : "differs",
157
+ leftColumn: "0",
158
+ rightColumn: "1",
159
+ left: row.left ? { name: row.name, key: row.name, line: row.left.line ?? undefined } : null,
160
+ right: row.right ? { name: row.name, key: row.name, line: row.right.line ?? undefined } : null,
161
+ });
162
+ }
163
+ return links;
164
+ };
165
+ exports.frameworkLinks = frameworkLinks;
166
+ const nameLinks = (model) => {
167
+ if (!model || !model.rows || !model.hasEvidence)
168
+ return [];
169
+ const row = model.rows[0];
170
+ if (!row?.left || !row?.right)
171
+ return [];
172
+ return [
173
+ {
174
+ connectionId: "same:name",
175
+ label: pctLabel("component names", model.score ?? 0),
176
+ tone: "same",
177
+ leftColumn: "0",
178
+ rightColumn: "1",
179
+ left: { name: row.left.name },
180
+ right: { name: row.right.name },
181
+ },
182
+ ];
183
+ };
184
+ exports.nameLinks = nameLinks;
185
+ // The STYLES links: one per CSS property that corresponds on a matched node pair.
186
+ // The name is the property (`cursor`, `display`); the board locates it in the
187
+ // snapshot's style column. A property present on both sides with different
188
+ // values is a partial duplicate (50%), red; a property on one side only is a
189
+ // green stub.
190
+ const stylesLinks = (model) => {
191
+ if (!model || !model.rows)
192
+ return [];
193
+ const word = (0, word_1.wordOf)("style properties", 1);
194
+ const links = [];
195
+ for (const row of model.rows) {
196
+ if (!row.left && !row.right)
197
+ continue;
198
+ const shared = row.shared === true;
199
+ const degree = row.same ? 1 : 0.5;
200
+ links.push({
201
+ connectionId: `same:styles:${row.tag}:${row.name}`,
202
+ label: shared ? pctLabel(word, degree) : word,
203
+ tone: shared ? "same" : "differs",
204
+ leftColumn: "0",
205
+ rightColumn: "1",
206
+ left: row.left ? { name: row.name, key: `${row.tag}:${row.name}` } : null,
207
+ right: row.right ? { name: row.name, key: `${row.tag}:${row.name}` } : null,
208
+ });
209
+ }
210
+ return links;
211
+ };
212
+ exports.stylesLinks = stylesLinks;
213
+ // All links per signal, keyed by the SIGNAL the tab selects.
214
+ const linksBySignal = (analysis, left, right) => ({
215
+ structure: structureLinks(analysis.structure),
216
+ styles: stylesLinks(analysis.styles),
217
+ behavior: behaviorLinks(analysis.behavior, left, right),
218
+ a11y: a11yLinks(analysis.a11y),
219
+ framework: frameworkLinks(analysis.framework),
220
+ name: nameLinks(analysis.name),
221
+ });
222
+ exports.linksBySignal = linksBySignal;
@@ -0,0 +1,9 @@
1
+ declare const accessibleNameOf: (node: any) => any;
2
+ declare const statesOf: (node: any) => any[];
3
+ declare const roleOf: (node: any) => any;
4
+ declare const snapshotOf: (candidate: any, span: any) => {
5
+ html: any[];
6
+ reader: any[];
7
+ available: boolean;
8
+ };
9
+ export { snapshotOf, accessibleNameOf, roleOf, statesOf };