@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
package/dist/config.js ADDED
@@ -0,0 +1,402 @@
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.loadDynamicCatalog = exports.loadCatalog = exports.loadRegistry = exports.resolveAgainst = exports.loadJson = exports.RULE_SHORT = exports.RULE_NAME = exports.loadRuleOptions = exports.folderRank = exports.isIgnored = exports.inCanonicalDir = exports.canSeeCanon = exports.inComponentsFolder = exports.normalizeFolders = exports.normalizeOptions = exports.findRepoRoot = exports.ACTION_ATTR_NAMES = exports.DEFAULT_ROOT_MARKERS = exports.DEFAULT_IGNORE_DIRS = exports.DEFAULT_EXTS = exports.DEFAULT_EXCLUDE = void 0;
27
+ const fs = __importStar(require("node:fs"));
28
+ const path = __importStar(require("node:path"));
29
+ const node_url_1 = require("node:url");
30
+ const minimatch_1 = require("minimatch");
31
+ const DEFAULT_EXCLUDE = [
32
+ "*.stories.*",
33
+ "*.test.*",
34
+ "*.spec.*",
35
+ "*.d.ts",
36
+ "**/__tests__/**",
37
+ ];
38
+ exports.DEFAULT_EXCLUDE = DEFAULT_EXCLUDE;
39
+ const DEFAULT_EXTS = [".tsx", ".ts", ".jsx", ".js"];
40
+ exports.DEFAULT_EXTS = DEFAULT_EXTS;
41
+ // The walker does not read .gitignore, so common build-artifact names must be
42
+ // listed here explicitly ("out" is the default VS Code extension build dir).
43
+ const DEFAULT_IGNORE_DIRS = ["node_modules", "dist", "build", "out", "coverage"];
44
+ exports.DEFAULT_IGNORE_DIRS = DEFAULT_IGNORE_DIRS;
45
+ const DEFAULT_ROOT_MARKERS = [".git"];
46
+ exports.DEFAULT_ROOT_MARKERS = DEFAULT_ROOT_MARKERS;
47
+ const findRepoRoot = (startDir, markers = DEFAULT_ROOT_MARKERS) => {
48
+ const markerSet = new Set(markers);
49
+ let dir = path.resolve(startDir);
50
+ for (;;) {
51
+ if (fs.existsSync(path.join(dir, "package.json")) &&
52
+ fs.readdirSync(dir).some((name) => markerSet.has(name))) {
53
+ return dir;
54
+ }
55
+ const parent = path.dirname(dir);
56
+ if (parent === dir)
57
+ return null;
58
+ dir = parent;
59
+ }
60
+ };
61
+ exports.findRepoRoot = findRepoRoot;
62
+ const ACTION_ATTR_NAMES = new Set([
63
+ "onClick",
64
+ "onMouseDown",
65
+ "onMouseUp",
66
+ "onMouseEnter",
67
+ "onMouseLeave",
68
+ "onMouseMove",
69
+ "onTouchStart",
70
+ "onTouchEnd",
71
+ "onTouchMove",
72
+ "onFocus",
73
+ "onBlur",
74
+ "onChange",
75
+ "onInput",
76
+ "onSubmit",
77
+ "onKeyDown",
78
+ "onKeyUp",
79
+ "onKeyPress",
80
+ "onDragStart",
81
+ "onDragEnd",
82
+ "onDrop",
83
+ "onDragOver",
84
+ "onDoubleClick",
85
+ "onContextMenu",
86
+ ]);
87
+ exports.ACTION_ATTR_NAMES = ACTION_ATTR_NAMES;
88
+ const SUPPORTED_FRAMEWORKS = new Set(["react", "angular", "vue"]);
89
+ const resolveFramework = (f) => {
90
+ const s = String(f || "react").trim().toLowerCase();
91
+ return SUPPORTED_FRAMEWORKS.has(s) ? s : "react";
92
+ };
93
+ const SUPPORTED_STYLE_SYSTEMS = new Set(["tailwind", "scss", "styled-components"]);
94
+ const resolveStyleSystem = (s) => {
95
+ const k = String(s || "tailwind").trim().toLowerCase();
96
+ return SUPPORTED_STYLE_SYSTEMS.has(k) ? k : "tailwind";
97
+ };
98
+ const normalizeFolders = (folders) => {
99
+ return (folders || []).map((f) => {
100
+ const raw = f && typeof f === "object" ? f.path : f;
101
+ let s = String(raw).trim().split(path.sep).join("/");
102
+ while (s.startsWith("./"))
103
+ s = s.slice(2);
104
+ if (!s.endsWith("/"))
105
+ s += "/";
106
+ return s;
107
+ });
108
+ };
109
+ exports.normalizeFolders = normalizeFolders;
110
+ const normalizeOptions = (opts) => {
111
+ const o = opts && typeof opts === "object" ? opts : {};
112
+ const rootMarkers = o.rootMarkers || DEFAULT_ROOT_MARKERS;
113
+ const root = o.root || findRepoRoot(process.cwd(), rootMarkers);
114
+ return {
115
+ root,
116
+ registry: o.registry || null,
117
+ registryPath: o.registryPath || "reports/component-registry.json",
118
+ catalog: o.catalog || null,
119
+ // `exportPath` is THE name for "where this rule writes its catalog",
120
+ // shared by every rule in the family; `catalogPath` is its old name.
121
+ exportPath: o.exportPath || o.catalogPath || "reports/component-catalog.json",
122
+ includeDynamic: o.includeDynamic === true,
123
+ dynamicCatalog: o.dynamicCatalog || null,
124
+ dynamicCatalogPath: o.dynamicCatalogPath || "reports/component-catalog-dynamic.json",
125
+ rawHtml: o.rawHtml === true,
126
+ parts: o.parts === true,
127
+ framework: resolveFramework(o.framework),
128
+ tsconfig: typeof o.tsconfig === "string" ? o.tsconfig : null,
129
+ styleSystem: resolveStyleSystem(o.styleSystem),
130
+ weights: o.weights && typeof o.weights === "object" ? o.weights : null,
131
+ thresholds: o.thresholds && typeof o.thresholds === "object" ? o.thresholds : null,
132
+ componentsFolder: normalizeFolders(o.componentsFolder || []),
133
+ include: o.include || [],
134
+ exclude: o.exclude || DEFAULT_EXCLUDE,
135
+ exts: o.exts || DEFAULT_EXTS,
136
+ ignoreDirs: o.ignoreDirs ? [...new Set([...DEFAULT_IGNORE_DIRS, ...o.ignoreDirs])] : DEFAULT_IGNORE_DIRS,
137
+ rootMarkers,
138
+ compareAll: o.compareAll === true,
139
+ proposeFromLib: o.proposeFromLib === true,
140
+ cache: o.cache !== false,
141
+ };
142
+ };
143
+ exports.normalizeOptions = normalizeOptions;
144
+ const folderRank = (folders) => {
145
+ const map = new Map();
146
+ (folders || []).forEach((f, i) => {
147
+ const isObj = f && typeof f === "object";
148
+ const raw = isObj ? f.path : f;
149
+ let s = String(raw).trim().split(path.sep).join("/");
150
+ while (s.startsWith("./"))
151
+ s = s.slice(2);
152
+ if (!s.endsWith("/"))
153
+ s += "/";
154
+ const r = isObj && typeof f.rank === "number" ? f.rank : i;
155
+ if (!map.has(s))
156
+ map.set(s, r);
157
+ });
158
+ return map;
159
+ };
160
+ exports.folderRank = folderRank;
161
+ const inComponentsFolder = (relPath, componentsFolder) => {
162
+ return componentsFolder.some((d) => relPath.startsWith(d));
163
+ };
164
+ exports.inComponentsFolder = inComponentsFolder;
165
+ const layerOf = (relPath, componentsFolder) => {
166
+ return componentsFolder.findIndex((d) => relPath.startsWith(d));
167
+ };
168
+ const canSeeCanon = (appPath, canonPath, componentsFolder, compareAll = false) => {
169
+ // compareAll mode: every file sees every canon in the catalog, so a
170
+ // single-layer componentsFolder (all files in layer 0) still flags duplicates.
171
+ if (compareAll)
172
+ return true;
173
+ const appLayer = layerOf(appPath, componentsFolder);
174
+ return appLayer < 0 || layerOf(canonPath, componentsFolder) < appLayer;
175
+ };
176
+ exports.canSeeCanon = canSeeCanon;
177
+ const inCanonicalDir = (relPath, dirs) => {
178
+ return dirs.some((d) => relPath === d || relPath.startsWith(d + "/"));
179
+ };
180
+ exports.inCanonicalDir = inCanonicalDir;
181
+ const compileMatcher = (pattern) => {
182
+ if (pattern instanceof RegExp)
183
+ return (p) => pattern.test(p);
184
+ if (typeof pattern !== "string" || pattern.length === 0)
185
+ return null;
186
+ if (pattern.startsWith("/") && pattern.endsWith("/") && pattern.length > 2) {
187
+ try {
188
+ const re = new RegExp(pattern.slice(1, -1));
189
+ return (p) => re.test(p);
190
+ }
191
+ catch {
192
+ return null;
193
+ }
194
+ }
195
+ if (pattern.startsWith("^") && pattern.endsWith("$")) {
196
+ try {
197
+ const re = new RegExp(pattern);
198
+ return (p) => re.test(p);
199
+ }
200
+ catch {
201
+ return null;
202
+ }
203
+ }
204
+ return (p) => (0, minimatch_1.minimatch)(p, pattern);
205
+ };
206
+ const matchesPath = (m, relPath) => {
207
+ if (m(relPath))
208
+ return true;
209
+ const base = relPath.slice(relPath.lastIndexOf("/") + 1);
210
+ return base !== relPath && m(base);
211
+ };
212
+ const isIgnored = (relPath, include, exclude) => {
213
+ for (const pattern of exclude || []) {
214
+ const m = compileMatcher(pattern);
215
+ if (m && matchesPath(m, relPath))
216
+ return true;
217
+ }
218
+ if (include && include.length > 0) {
219
+ return !include.some((pattern) => {
220
+ const m = compileMatcher(pattern);
221
+ return m ? matchesPath(m, relPath) : false;
222
+ });
223
+ }
224
+ return false;
225
+ };
226
+ exports.isIgnored = isIgnored;
227
+ const RULE_NAME = "md-code/component-uniqueness";
228
+ exports.RULE_NAME = RULE_NAME;
229
+ const RULE_SHORT = "md-code";
230
+ exports.RULE_SHORT = RULE_SHORT;
231
+ const FLAT_CANDIDATES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts"];
232
+ const LEGACY_CANDIDATES = [".eslintrc.js", ".eslintrc.cjs", ".eslintrc.json", ".eslintrc.yaml", ".eslintrc.yml"];
233
+ const loadModule = (file) => {
234
+ const src = fs.readFileSync(file, "utf8");
235
+ if (file.endsWith(".json"))
236
+ return Promise.resolve(JSON.parse(src));
237
+ if (/^\s*(exports?\s+(default|const|let|var)|import\s)/m.test(src)) {
238
+ return Promise.resolve(`${(0, node_url_1.pathToFileURL)(file).href}`).then(s => __importStar(require(s))).catch((esmErr) => {
239
+ try {
240
+ return require(file);
241
+ }
242
+ catch {
243
+ throw esmErr;
244
+ }
245
+ });
246
+ }
247
+ return Promise.resolve().then(() => require(file));
248
+ };
249
+ const pickOptions = (v) => {
250
+ if (v === undefined || v === null)
251
+ return null;
252
+ if (Array.isArray(v))
253
+ return v[1] && typeof v[1] === "object" ? v[1] : {};
254
+ if (typeof v === "object")
255
+ return v;
256
+ return {};
257
+ };
258
+ const isRuleKey = (key) => typeof key === "string" && (key === RULE_NAME || key === RULE_SHORT || key === "component-uniqueness" || key.endsWith("/component-uniqueness"));
259
+ const ruleValue = (rules) => {
260
+ for (const [key, v] of Object.entries(rules)) {
261
+ if (!isRuleKey(key))
262
+ continue;
263
+ if (v === undefined || v === null)
264
+ continue;
265
+ return v;
266
+ }
267
+ return null;
268
+ };
269
+ const pluginRuleValue = (plugins) => {
270
+ for (const plugin of Object.values(plugins || {})) {
271
+ if (!plugin || typeof plugin !== "object")
272
+ continue;
273
+ const v = ruleValue(plugin.rules || {});
274
+ if (v !== null && v !== undefined)
275
+ return v;
276
+ }
277
+ return null;
278
+ };
279
+ const loadFlatOptions = async (file) => {
280
+ const mod = await loadModule(file);
281
+ const list = mod && mod.default !== undefined ? mod.default : mod;
282
+ if (!Array.isArray(list))
283
+ return null;
284
+ for (const entry of list) {
285
+ if (!entry || typeof entry !== "object")
286
+ continue;
287
+ const v = (entry.rules && ruleValue(entry.rules)) || (entry.plugins && pluginRuleValue(entry.plugins)) || null;
288
+ if (v === undefined || v === null)
289
+ continue;
290
+ return pickOptions(v);
291
+ }
292
+ return null;
293
+ };
294
+ const loadLegacyOptions = async (file) => {
295
+ const mod = await loadModule(file);
296
+ const v = ruleValue((mod && mod.rules) || {});
297
+ return v === undefined || v === null ? null : pickOptions(v);
298
+ };
299
+ const loadRuleOptions = async (dir, explicitFile = null) => {
300
+ if (explicitFile) {
301
+ const file = path.isAbsolute(explicitFile) ? explicitFile : path.resolve(dir, explicitFile);
302
+ if (!fs.existsSync(file))
303
+ return null;
304
+ if (file.endsWith(".json")) {
305
+ const options = pickOptions(JSON.parse(fs.readFileSync(file, "utf8")));
306
+ return options ? { options, source: file } : null;
307
+ }
308
+ try {
309
+ const isFlat = path.basename(file).startsWith("eslint.config");
310
+ const options = isFlat ? await loadFlatOptions(file) : pickOptions(await loadModule(file));
311
+ return options ? { options, source: file } : null;
312
+ }
313
+ catch {
314
+ return null;
315
+ }
316
+ }
317
+ let d = dir;
318
+ for (;;) {
319
+ const standalone = path.join(d, "md-code-component-uniqueness.config.js");
320
+ if (fs.existsSync(standalone)) {
321
+ const mod = await loadModule(standalone);
322
+ const options = mod && mod.default !== undefined ? mod.default : mod;
323
+ if (options && typeof options === "object")
324
+ return { options, source: standalone };
325
+ }
326
+ for (const name of FLAT_CANDIDATES) {
327
+ const file = path.join(d, name);
328
+ if (!fs.existsSync(file))
329
+ continue;
330
+ try {
331
+ const options = await loadFlatOptions(file);
332
+ if (options)
333
+ return { options, source: file };
334
+ }
335
+ catch { }
336
+ }
337
+ for (const name of LEGACY_CANDIDATES) {
338
+ const file = path.join(d, name);
339
+ if (!fs.existsSync(file))
340
+ continue;
341
+ try {
342
+ const options = await loadLegacyOptions(file);
343
+ if (options)
344
+ return { options, source: file };
345
+ }
346
+ catch { }
347
+ }
348
+ const parent = path.dirname(d);
349
+ if (parent === d)
350
+ break;
351
+ d = parent;
352
+ }
353
+ return null;
354
+ };
355
+ exports.loadRuleOptions = loadRuleOptions;
356
+ const jsonCache = new Map();
357
+ const loadJson = (absPath, label) => {
358
+ if (jsonCache.has(absPath))
359
+ return jsonCache.get(absPath).value;
360
+ let entry = { loaded: false, value: null, warned: false };
361
+ try {
362
+ const raw = fs.readFileSync(absPath, "utf8");
363
+ const parsed = JSON.parse(raw);
364
+ entry.value = parsed && typeof parsed === "object" ? parsed : null;
365
+ entry.loaded = true;
366
+ }
367
+ catch (err) {
368
+ entry.value = null;
369
+ entry.loaded = false;
370
+ const reason = err && err.code === "ENOENT" ? "file not found" : `could not be read/parsed (${err && err.message ? err.message : err})`;
371
+ if (!entry.warned) {
372
+ entry.warned = true;
373
+ const rel = path.isAbsolute(absPath) ? absPath : path.resolve(absPath);
374
+ console.warn(`[component-uniqueness] ${label} ${reason} at ${rel}. ` +
375
+ `The ${label} is disabled for this run. ` +
376
+ `Generate it first (see the package README) or pass it via the rule options.`);
377
+ }
378
+ }
379
+ jsonCache.set(absPath, entry);
380
+ return entry.value;
381
+ };
382
+ exports.loadJson = loadJson;
383
+ const resolveAgainst = (p, root) => (path.isAbsolute(p) ? p : path.join(root, p));
384
+ exports.resolveAgainst = resolveAgainst;
385
+ const loadRegistry = (config) => {
386
+ if (config.registry)
387
+ return config.registry;
388
+ return loadJson(resolveAgainst(config.registryPath, config.root), "component registry");
389
+ };
390
+ exports.loadRegistry = loadRegistry;
391
+ const loadCatalog = (config) => {
392
+ if (config.catalog)
393
+ return config.catalog;
394
+ return loadJson(resolveAgainst(config.exportPath, config.root), "component catalog");
395
+ };
396
+ exports.loadCatalog = loadCatalog;
397
+ const loadDynamicCatalog = (config) => {
398
+ if (config.dynamicCatalog)
399
+ return config.dynamicCatalog;
400
+ return loadJson(resolveAgainst(config.dynamicCatalogPath, config.root), "dynamic component catalog");
401
+ };
402
+ exports.loadDynamicCatalog = loadDynamicCatalog;
@@ -0,0 +1,55 @@
1
+ declare const SIGNAL: Readonly<{
2
+ Structure: "structure";
3
+ Styles: "styles";
4
+ Behavior: "behavior";
5
+ A11y: "a11y";
6
+ Framework: "framework";
7
+ Name: "name";
8
+ }>;
9
+ declare const SIGNAL_ORDER: readonly ("structure" | "styles" | "behavior" | "a11y" | "framework" | "name")[];
10
+ declare const TIER: Readonly<{
11
+ Duplicate: "duplicate";
12
+ Similar: "similar";
13
+ }>;
14
+ declare const TIER_ORDER: readonly ("duplicate" | "similar")[];
15
+ declare const KIND: Readonly<{
16
+ Duplicate: "duplicate";
17
+ Similar: "similar";
18
+ Missing: "missing";
19
+ RawHtml: "rawhtml";
20
+ Part: "part";
21
+ Dropped: "dropped";
22
+ }>;
23
+ declare const KIND_LIST: readonly ("duplicate" | "similar" | "missing" | "rawhtml" | "part" | "dropped")[];
24
+ declare const CODE: Readonly<{
25
+ Duplicate: "duplicate";
26
+ Similar: "similar";
27
+ Missing: "missing";
28
+ RawHtml: "rawHtml";
29
+ Part: "part";
30
+ FilteredOut: "filteredOut";
31
+ Confidence: "confidence";
32
+ Headline: "headline";
33
+ }>;
34
+ declare const WARN_PREFIX = "[component-uniqueness] ";
35
+ declare const SIDE: Readonly<{
36
+ App: "app";
37
+ Canon: "canon";
38
+ }>;
39
+ declare const MARK: Readonly<{
40
+ Same: "same";
41
+ Differs: "differs";
42
+ }>;
43
+ declare const ACTION: Readonly<{
44
+ UseCanonical: "use-canonical";
45
+ ExtractComponent: "extract-component";
46
+ ReplaceRawHtml: "replace-raw-html";
47
+ None: "none";
48
+ }>;
49
+ declare const TONE: Readonly<{
50
+ Agree: "agree";
51
+ Disagree: "disagree";
52
+ Veto: "veto";
53
+ Off: "off";
54
+ }>;
55
+ export { SIGNAL, SIGNAL_ORDER, TIER, TIER_ORDER, KIND, KIND_LIST, CODE, WARN_PREFIX, SIDE, MARK, ACTION, TONE };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TONE = exports.ACTION = exports.MARK = exports.SIDE = exports.WARN_PREFIX = exports.CODE = exports.KIND_LIST = exports.KIND = exports.TIER_ORDER = exports.TIER = exports.SIGNAL_ORDER = exports.SIGNAL = void 0;
4
+ // The ONE vocabulary of the component report. Every word the tool says — a
5
+ // signal name, a verdict, a repair verb — is written here once and read back by
6
+ // the terminal report, the HTML page and the log, so "structure 0.80" in a
7
+ // message and the blue bar in the picture are the same thing. The engine
8
+ // (matcher, decision-maker) keeps its own numeric knobs; this file is only WORDS.
9
+ // ═══ 1. The five comparison signals ═════════════════════════════════════════
10
+ // Components are compared by their DOM structure + CSS, their behaviour (events),
11
+ // their accessibility profile, their framework profile (props / child components)
12
+ // and their name. Unlike entities, `name` IS a signal here: the engine weights it.
13
+ const SIGNAL = Object.freeze({
14
+ Structure: "structure",
15
+ Styles: "styles",
16
+ Behavior: "behavior",
17
+ A11y: "a11y",
18
+ Framework: "framework",
19
+ Name: "name",
20
+ });
21
+ exports.SIGNAL = SIGNAL;
22
+ const SIGNAL_ORDER = Object.freeze([SIGNAL.Structure, SIGNAL.Styles, SIGNAL.Behavior, SIGNAL.A11y, SIGNAL.Framework, SIGNAL.Name]);
23
+ exports.SIGNAL_ORDER = SIGNAL_ORDER;
24
+ // ═══ 2. Tiers (two, as the engine decides) ══════════════════════════════════
25
+ const TIER = Object.freeze({
26
+ Duplicate: "duplicate",
27
+ Similar: "similar",
28
+ });
29
+ exports.TIER = TIER;
30
+ const TIER_ORDER = Object.freeze([TIER.Duplicate, TIER.Similar]);
31
+ exports.TIER_ORDER = TIER_ORDER;
32
+ // ═══ 3. Kinds of finding ════════════════════════════════════════════════════
33
+ const KIND = Object.freeze({
34
+ Duplicate: "duplicate",
35
+ Similar: "similar",
36
+ Missing: "missing",
37
+ RawHtml: "rawhtml",
38
+ Part: "part",
39
+ Dropped: "dropped",
40
+ });
41
+ exports.KIND = KIND;
42
+ const KIND_LIST = Object.freeze([KIND.Duplicate, KIND.Similar, KIND.Missing, KIND.RawHtml, KIND.Part, KIND.Dropped]);
43
+ exports.KIND_LIST = KIND_LIST;
44
+ // ═══ 4. Sentence codes — the only source of any verdict/message ═════════════
45
+ const CODE = Object.freeze({
46
+ Duplicate: "duplicate",
47
+ Similar: "similar",
48
+ Missing: "missing",
49
+ RawHtml: "rawHtml",
50
+ Part: "part",
51
+ FilteredOut: "filteredOut",
52
+ Confidence: "confidence",
53
+ Headline: "headline",
54
+ });
55
+ exports.CODE = CODE;
56
+ const WARN_PREFIX = "[component-uniqueness] ";
57
+ exports.WARN_PREFIX = WARN_PREFIX;
58
+ // ═══ 5. Sides of a comparison ═══════════════════════════════════════════════
59
+ // Components compare an app (local) component against a canonical one.
60
+ const SIDE = Object.freeze({
61
+ App: "app",
62
+ Canon: "canon",
63
+ });
64
+ exports.SIDE = SIDE;
65
+ // ═══ 6. Per-row annotation state (the diff gutter) ══════════════════════════
66
+ const MARK = Object.freeze({
67
+ Same: "same",
68
+ Differs: "differs",
69
+ });
70
+ exports.MARK = MARK;
71
+ // ═══ 7. Actions a repair can carry ══════════════════════════════════════════
72
+ const ACTION = Object.freeze({
73
+ UseCanonical: "use-canonical",
74
+ ExtractComponent: "extract-component",
75
+ ReplaceRawHtml: "replace-raw-html",
76
+ None: "none",
77
+ });
78
+ exports.ACTION = ACTION;
79
+ // ═══ 8. Tone of a "why" line ════════════════════════════════════════════════
80
+ const TONE = Object.freeze({
81
+ Agree: "agree",
82
+ Disagree: "disagree",
83
+ Veto: "veto",
84
+ Off: "off",
85
+ });
86
+ exports.TONE = TONE;
@@ -0,0 +1,39 @@
1
+ declare const DEFAULT_WEIGHTS: {
2
+ name: number;
3
+ structure: number;
4
+ styles: number;
5
+ behavior: number;
6
+ a11y: number;
7
+ framework: number;
8
+ };
9
+ declare const DEFAULT_THRESHOLDS: {
10
+ duplicate: number;
11
+ similar: number;
12
+ };
13
+ declare const clamp01: (x: any) => number;
14
+ declare const resolveWeights: (opts: any) => {
15
+ name: any;
16
+ structure: any;
17
+ styles: any;
18
+ behavior: any;
19
+ a11y: any;
20
+ framework: any;
21
+ };
22
+ declare const resolveThresholds: (opts: any) => {
23
+ duplicate: any;
24
+ similar: any;
25
+ };
26
+ declare const decide: (candidate: any, canon: any, ctx: any) => {
27
+ isDuplicate: boolean;
28
+ confidence: number;
29
+ tier: any;
30
+ reason: string;
31
+ signals: any;
32
+ thresholds: {
33
+ duplicate: any;
34
+ similar: any;
35
+ };
36
+ weights: any;
37
+ };
38
+ declare const bestOf: (matches: any) => any;
39
+ export { decide, bestOf, resolveWeights, resolveThresholds, clamp01, DEFAULT_WEIGHTS, DEFAULT_THRESHOLDS, };