@md-code/component-uniqueness 0.1.3 → 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 (188) 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 -60
  157. package/config.js +0 -362
  158. package/decision-maker.js +0 -109
  159. package/filter/drop-child-element.js +0 -13
  160. package/filter/drop-usages.js +0 -13
  161. package/filter/missing-component.js +0 -68
  162. package/index.js +0 -184
  163. package/logger.js +0 -44
  164. package/main.js +0 -539
  165. package/matcher/a11y.js +0 -65
  166. package/matcher/behavior.js +0 -31
  167. package/matcher/framework/index.js +0 -15
  168. package/matcher/framework/react.js +0 -25
  169. package/matcher/index.js +0 -36
  170. package/matcher/name.js +0 -132
  171. package/matcher/structure.js +0 -208
  172. package/normalize/candidate.js +0 -22
  173. package/normalize/dom.js +0 -167
  174. package/normalize/framework.js +0 -129
  175. package/normalize/style-resolver.js +0 -24
  176. package/normalize/style.js +0 -175
  177. package/normalize/words.js +0 -40
  178. package/playgrounds/angular.js +0 -11
  179. package/playgrounds/framework-entrypoint.js +0 -90
  180. package/playgrounds/react.js +0 -997
  181. package/playgrounds/scss.js +0 -7
  182. package/playgrounds/style-entrypoint.js +0 -78
  183. package/playgrounds/styled-components.js +0 -138
  184. package/playgrounds/tailwind.js +0 -186
  185. package/playgrounds/vue.js +0 -11
  186. package/plugin.js +0 -3
  187. package/report.js +0 -159
  188. package/utils.js +0 -92
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- const { styledDeclarations, available: styledAvailable } = require("../playgrounds/styled-components.js");
4
- const { cssTextToStyles } = require("./style.js");
5
-
6
- const declarationsCache = new WeakMap();
7
-
8
- const declarationsOf = (sf) => {
9
- if (!declarationsCache.has(sf)) declarationsCache.set(sf, styledDeclarations(sf));
10
- return declarationsCache.get(sf);
11
- };
12
-
13
- const buildStyledResolver = () => {
14
- if (!styledAvailable()) return null;
15
- return (tag, sf) => {
16
- if (!sf || !tag) return null;
17
- const info = declarationsOf(sf).get(tag);
18
- if (!info) return null;
19
- const { css, unresolved } = cssTextToStyles(info.cssText);
20
- return { baseTag: info.baseTag, componentRef: info.componentRef, styleObj: css, unresolved: [...unresolved, ...info.unresolved] };
21
- };
22
- };
23
-
24
- module.exports = { buildStyledResolver };
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- const { entries, keys } = require("remeda");
4
-
5
- const LAYOUT_PROPS = new Set([
6
- "display",
7
- "position",
8
- "top",
9
- "right",
10
- "bottom",
11
- "left",
12
- "z-index",
13
- "flex-direction",
14
- "flex-wrap",
15
- "flex-grow",
16
- "flex-shrink",
17
- "flex-basis",
18
- "flex",
19
- "align-items",
20
- "align-self",
21
- "justify-content",
22
- "gap",
23
- "row-gap",
24
- "column-gap",
25
- "grid-template-columns",
26
- "grid-template-rows",
27
- "grid-template-areas",
28
- "grid-auto-columns",
29
- "grid-auto-rows",
30
- "grid-auto-flow",
31
- "grid-column",
32
- "grid-column-start",
33
- "grid-column-end",
34
- "grid-row",
35
- "grid-row-start",
36
- "grid-row-end",
37
- "grid-area",
38
- "grid-gap",
39
- "width",
40
- "min-width",
41
- "max-width",
42
- "height",
43
- "min-height",
44
- "max-height",
45
- "aspect-ratio",
46
- "margin",
47
- "margin-top",
48
- "margin-right",
49
- "margin-bottom",
50
- "margin-left",
51
- "margin-inline",
52
- "margin-inline-start",
53
- "margin-inline-end",
54
- "margin-block",
55
- "margin-block-start",
56
- "margin-block-end",
57
- "padding",
58
- "padding-top",
59
- "padding-right",
60
- "padding-bottom",
61
- "padding-left",
62
- "padding-inline",
63
- "padding-inline-start",
64
- "padding-inline-end",
65
- "padding-block",
66
- "padding-block-start",
67
- "padding-block-end",
68
- "overflow",
69
- "overflow-x",
70
- "overflow-y",
71
- "overflow-wrap",
72
- "text-overflow",
73
- "white-space",
74
- "font-size",
75
- "box-sizing",
76
- "object-fit",
77
- "object-position",
78
- "transform",
79
- "translate",
80
- "scale",
81
- "rotate",
82
- "order",
83
- "visibility",
84
- "float",
85
- "clear",
86
- "inset",
87
- "inset-block",
88
- "inset-block-start",
89
- "inset-block-end",
90
- "inset-inline",
91
- "inset-inline-start",
92
- "inset-inline-end",
93
- "contain",
94
- "contain-intrinsic-size",
95
- ]);
96
-
97
- const isLayoutProp = (prop) => LAYOUT_PROPS.has(prop);
98
-
99
- const UNRESOLVED_VALUE_RE = /var\(|url\(|@import|calc\(\s*var\(/i;
100
-
101
- const cssTextToStyles = (text) => {
102
- const css = {};
103
- const unresolved = [];
104
- if (typeof text !== "string") return { css, unresolved };
105
- const clean = text.replace(/\/\*[\s\S]*?\*\//g, "");
106
- for (const decl of clean.split(";")) {
107
- const idx = decl.indexOf(":");
108
- if (idx < 0) continue;
109
- const prop = decl.slice(0, idx).trim();
110
- const value = decl.slice(idx + 1).trim();
111
- if (!prop || !value) continue;
112
- if (prop.startsWith("@") || prop.startsWith("$") || value.includes("{")) continue;
113
- if (!/^[a-zA-Z-]+$/.test(prop)) continue;
114
- const p = prop.toLowerCase();
115
- if (UNRESOLVED_VALUE_RE.test(value)) {
116
- unresolved.push(`${p}: ${value}`);
117
- continue;
118
- }
119
- if (!Object.prototype.hasOwnProperty.call(css, p)) css[p] = [];
120
- if (!css[p].includes(value)) css[p].push(value);
121
- }
122
- return { css, unresolved };
123
- };
124
-
125
- const camelToKebab = (name) => String(name).replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
126
-
127
- const styleObjectToText = (obj) => {
128
- const parts = [];
129
- for (const [k, v] of entries(obj || {})) {
130
- if (v === undefined || v === null) continue;
131
- const val = Array.isArray(v) ? v.join(", ") : String(v);
132
- parts.push(`${camelToKebab(k)}: ${val}`);
133
- }
134
- return parts.join("; ");
135
- };
136
-
137
- const mergeStyles = (a, b) => {
138
- const out = {};
139
- for (const [prop, values] of entries(a)) out[prop] = [...values];
140
- for (const [prop, values] of entries(b)) {
141
- if (!Object.prototype.hasOwnProperty.call(out, prop)) {
142
- out[prop] = [...values];
143
- continue;
144
- }
145
- for (const v of values) {
146
- if (!out[prop].includes(v)) out[prop].push(v);
147
- }
148
- }
149
- return out;
150
- };
151
-
152
- const mergeProfiles = (a, b) => ({
153
- css: mergeStyles(a.css, b.css),
154
- unresolved: [...a.unresolved, ...b.unresolved],
155
- });
156
-
157
- const stylesSimilarity = (a, b, label) => {
158
- const A = new Set(keys(a));
159
- const B = new Set(keys(b));
160
- const inter = [...A].filter((p) => B.has(p));
161
- const union = A.size + B.size - inter.length;
162
- const score = union === 0 ? 0 : inter.length / union;
163
- return score;
164
- };
165
-
166
- module.exports = {
167
- LAYOUT_PROPS,
168
- isLayoutProp,
169
- cssTextToStyles,
170
- camelToKebab,
171
- styleObjectToText,
172
- mergeStyles,
173
- mergeProfiles,
174
- stylesSimilarity,
175
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- const pascalWords = (s) => String(s || "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean);
4
-
5
- const GENERIC_WORDS = new Set([
6
- "button",
7
- "field",
8
- "input",
9
- "select",
10
- "box",
11
- "list",
12
- "item",
13
- "row",
14
- "cell",
15
- "icon",
16
- "label",
17
- "value",
18
- "text",
19
- "data",
20
- "info",
21
- "meta",
22
- "main",
23
- "base",
24
- "option",
25
- "panel",
26
- "view",
27
- "form",
28
- "card",
29
- "tag",
30
- "chip",
31
- "badge",
32
- "menu",
33
- "bar",
34
- "grid",
35
- "table",
36
- "section",
37
- "state",
38
- ]);
39
-
40
- module.exports = { pascalWords, GENERIC_WORDS };
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- const parseComponents = () => [];
4
-
5
- const resolveCss = () => ({ css: "", unresolved: [] });
6
-
7
- module.exports = {
8
- parseComponents,
9
- resolveCss,
10
- available: () => false,
11
- };
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- const { normalizeOptions } = require("../config.js");
4
- const { buildStylesheet } = require("./style-entrypoint.js");
5
- const { buildStyledResolver } = require("../normalize/style-resolver.js");
6
-
7
- let styledResolver = null;
8
- const withStyledResolver = (opts) => {
9
- if (!styledResolver) styledResolver = buildStyledResolver();
10
- return styledResolver ? { ...opts, styledResolver } : opts;
11
- };
12
-
13
- const PLAYGROUNDS = {
14
- react: () => require("./react.js"),
15
- angular: () => require("./angular.js"),
16
- vue: () => require("./vue.js"),
17
- };
18
-
19
- const cache = new Map();
20
-
21
- const getPlayground = (framework) => {
22
- const key = String(framework || "react").toLowerCase();
23
- if (!cache.has(key)) {
24
- const loader = PLAYGROUNDS[key] || PLAYGROUNDS.react;
25
- cache.set(key, loader());
26
- }
27
- return cache.get(key);
28
- };
29
-
30
- const getFramework = (opts) => normalizeOptions(opts).framework;
31
-
32
- const parseComponents = (fileAbs, canonicalNames, opts) => {
33
- const pg = getPlayground(getFramework(opts));
34
- if (!pg.available || !pg.available()) return [];
35
- return pg.parseComponents(fileAbs, canonicalNames, withStyledResolver(opts));
36
- };
37
-
38
- const parseElements = (fileAbs, canonicalNames, opts) => {
39
- const pg = getPlayground(getFramework(opts));
40
- if (!pg.available || !pg.available() || !pg.parseElements) return [];
41
- return pg.parseElements(fileAbs, canonicalNames, withStyledResolver(opts));
42
- };
43
-
44
- const parseParts = (fileAbs, canonicalNames, opts) => {
45
- const pg = getPlayground(getFramework(opts));
46
- if (!pg.available || !pg.available() || !pg.parseParts) return [];
47
- return pg.parseParts(fileAbs, canonicalNames, withStyledResolver(opts));
48
- };
49
-
50
- const resolveCss = (tree, opts) => {
51
- const pg = getPlayground(getFramework(opts));
52
- if (!pg.resolveCss) return { css: "", unresolved: [] };
53
- return pg.resolveCss(tree);
54
- };
55
-
56
- const classTokensOf = (tree, out = new Set()) => {
57
- if (!tree) return out;
58
- if (tree.className) for (const token of String(tree.className).split(/\s+/)) if (token) out.add(token);
59
- for (const child of tree.children || []) classTokensOf(child, out);
60
- return out;
61
- };
62
-
63
- const render = (tree, opts) => {
64
- const pg = getPlayground(getFramework(opts));
65
- if (!pg.render) return { tree: null, available: false };
66
- const stylesheet = buildStylesheet([...classTokensOf(tree)], opts);
67
- return pg.render(tree, { stylesheet });
68
- };
69
-
70
- const rawClassTokens = (tree) => {
71
- const out = new Set();
72
- const visit = (n) => {
73
- if (!n) return;
74
- if (typeof n.className === "string") for (const token of n.className.split(/\s+/)) if (token) out.add(token);
75
- for (const child of n.children || []) visit(child);
76
- };
77
- visit(tree);
78
- return out;
79
- };
80
-
81
- module.exports = {
82
- getPlayground,
83
- getFramework,
84
- parseComponents,
85
- parseElements,
86
- parseParts,
87
- resolveCss,
88
- render,
89
- rawClassTokens,
90
- };