@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
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchStyles = void 0;
4
+ // ── STYLES MATCHER ─────────────────────────────────────────────────────────
5
+ //
6
+ // Structure says "a button matches a button". Styles asks the next question:
7
+ // is it the SAME button — same color, same cursor, same padding? The node pairs
8
+ // are the STRUCTURE matcher's best chain (the same correspondence the verdict
9
+ // already trusts); each pair is then compared on the CSS properties that MATTER
10
+ // for its element role (matcher/css-matching.ts): typography for text, layout
11
+ // for containers, offsets for positioned elements, surface for backgrounds.
12
+ //
13
+ // Styles never invents its own alignment: a weak structure chain yields few
14
+ // pairs, so styles cannot inflate a match the structure already doubted.
15
+ const css_matching_js_1 = require("./css-matching.js");
16
+ const structure_js_1 = require("./structure.js");
17
+ const matchStyles = (candidate, canon) => {
18
+ const left = candidate.dom && candidate.dom.tree;
19
+ const right = canon.dom && canon.dom.tree;
20
+ if (!left || !right)
21
+ return { score: 0, applicable: false, evidence: { pairs: 0 } };
22
+ const pairs = (0, structure_js_1.bestChain)(left, right).pairs;
23
+ const details = [];
24
+ let totalProps = 0;
25
+ let sameProps = 0;
26
+ for (const [a, b] of pairs) {
27
+ const cmp = (0, css_matching_js_1.compareCss)(a.tag, a.css, b.tag, b.css);
28
+ totalProps += cmp.total;
29
+ sameProps += cmp.same;
30
+ details.push({ tag: a.tag, same: cmp.same, total: cmp.total, score: cmp.score, rows: cmp.rows });
31
+ }
32
+ const applicable = totalProps > 0;
33
+ // A single shared property is weak evidence, not full agreement: discount
34
+ // small property sets the same way the behavior signal discounts small event
35
+ // sets, so one `font-size` cannot carry a styles score of 1.0.
36
+ const smallSetDiscount = Math.min(1, totalProps / 3);
37
+ const score = totalProps === 0 ? 0 : (sameProps / totalProps) * smallSetDiscount;
38
+ return {
39
+ score,
40
+ applicable,
41
+ evidence: {
42
+ pairs: pairs.length,
43
+ properties: totalProps,
44
+ agreeing: sameProps,
45
+ details,
46
+ },
47
+ };
48
+ };
49
+ exports.matchStyles = matchStyles;
@@ -0,0 +1,3 @@
1
+ declare const buildCandidate: (comp: any, config: any) => any;
2
+ declare const buildElementCandidate: (element: any, config: any) => any;
3
+ export { buildCandidate, buildElementCandidate };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildElementCandidate = exports.buildCandidate = void 0;
4
+ const dom_js_1 = require("./dom.js");
5
+ const framework_js_1 = require("./framework.js");
6
+ const framework_js_2 = require("../playgrounds/framework.js");
7
+ const buildCandidate = (comp, config) => ({
8
+ ...comp,
9
+ dom: (0, dom_js_1.normalizeDom)(comp.tree, config, comp.name),
10
+ framework: (0, framework_js_1.normalizeFramework)(comp.rawTree || comp.tree, comp.name),
11
+ rawClasses: [...(0, framework_js_2.rawClassTokens)(comp.rawTree || comp.tree)],
12
+ });
13
+ exports.buildCandidate = buildCandidate;
14
+ const buildElementCandidate = (element, config) => {
15
+ const framework = (0, framework_js_1.normalizeFramework)(element.tree, element.name);
16
+ if (framework.events.length === 0 && element.a11y.length === 0)
17
+ return null;
18
+ const dom = (0, dom_js_1.normalizeDom)(element.tree, config, element.name);
19
+ return { ...element, partial: true, dom, framework: { ...framework, names: [] }, rawClasses: [...(0, framework_js_2.rawClassTokens)(element.tree)] };
20
+ };
21
+ exports.buildElementCandidate = buildElementCandidate;
@@ -0,0 +1,22 @@
1
+ declare const HTML_TAGS: Set<string>;
2
+ declare const INTERACTIVE_TAGS: Set<string>;
3
+ declare const NON_SEMANTIC_TAGS: Set<string>;
4
+ declare const SEMANTIC_CONTAINER_TAGS: Set<string>;
5
+ declare const GENERIC_CONTAINER_TAGS: Set<string>;
6
+ declare const tagAffinity: (a: any, b: any) => 0 | 1 | 0.75;
7
+ declare const isPascalCase: (name: any) => boolean;
8
+ declare const isHtmlTag: (tag: any) => boolean;
9
+ declare const styleObjectToCssText: (obj: any) => string;
10
+ declare const normalizeDom: (tree: any, opts: any, label: any) => {
11
+ tree: {
12
+ tag: any;
13
+ text: any;
14
+ interactive: boolean;
15
+ css: {
16
+ [k: string]: unknown;
17
+ };
18
+ children: any;
19
+ };
20
+ available: any;
21
+ };
22
+ export { HTML_TAGS, INTERACTIVE_TAGS, NON_SEMANTIC_TAGS, SEMANTIC_CONTAINER_TAGS, GENERIC_CONTAINER_TAGS, tagAffinity, isPascalCase, isHtmlTag, styleObjectToCssText, normalizeDom, };
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeDom = exports.styleObjectToCssText = exports.isHtmlTag = exports.isPascalCase = exports.tagAffinity = exports.GENERIC_CONTAINER_TAGS = exports.SEMANTIC_CONTAINER_TAGS = exports.NON_SEMANTIC_TAGS = exports.INTERACTIVE_TAGS = exports.HTML_TAGS = void 0;
4
+ const framework_js_1 = require("../playgrounds/framework.js");
5
+ const style_js_1 = require("./style.js");
6
+ const HTML_TAGS = new Set([
7
+ "html",
8
+ "head",
9
+ "body",
10
+ "div",
11
+ "span",
12
+ "a",
13
+ "p",
14
+ "main",
15
+ "section",
16
+ "header",
17
+ "footer",
18
+ "nav",
19
+ "aside",
20
+ "article",
21
+ "ul",
22
+ "ol",
23
+ "li",
24
+ "table",
25
+ "thead",
26
+ "tbody",
27
+ "tr",
28
+ "td",
29
+ "th",
30
+ "form",
31
+ "label",
32
+ "input",
33
+ "button",
34
+ "select",
35
+ "textarea",
36
+ "img",
37
+ "figure",
38
+ "figcaption",
39
+ "svg",
40
+ "path",
41
+ "circle",
42
+ "rect",
43
+ "g",
44
+ "pre",
45
+ "code",
46
+ "strong",
47
+ "em",
48
+ "small",
49
+ "h1",
50
+ "h2",
51
+ "h3",
52
+ "h4",
53
+ "h5",
54
+ "h6",
55
+ "hr",
56
+ "br",
57
+ "i",
58
+ "b",
59
+ "u",
60
+ "s",
61
+ "sub",
62
+ "sup",
63
+ "blockquote",
64
+ "details",
65
+ "summary",
66
+ "dialog",
67
+ "canvas",
68
+ "video",
69
+ "audio",
70
+ "source",
71
+ "track",
72
+ "map",
73
+ "area",
74
+ "dl",
75
+ "dt",
76
+ "dd",
77
+ "fieldset",
78
+ "legend",
79
+ "data",
80
+ "output",
81
+ "progress",
82
+ "meter",
83
+ "time",
84
+ "mark",
85
+ "abbr",
86
+ "ruby",
87
+ "rt",
88
+ "rp",
89
+ "wbr",
90
+ "bdi",
91
+ "bdo",
92
+ "template",
93
+ "slot",
94
+ "picture",
95
+ "base",
96
+ "link",
97
+ "meta",
98
+ "style",
99
+ "title",
100
+ "script",
101
+ "noscript",
102
+ "address",
103
+ "hgroup",
104
+ "search",
105
+ "menu",
106
+ "kbd",
107
+ "samp",
108
+ "var",
109
+ "dfn",
110
+ "cite",
111
+ "q",
112
+ "del",
113
+ "ins",
114
+ "caption",
115
+ "col",
116
+ "colgroup",
117
+ "tfoot",
118
+ "optgroup",
119
+ "option",
120
+ "datalist",
121
+ "iframe",
122
+ "embed",
123
+ "object",
124
+ "math",
125
+ ]);
126
+ exports.HTML_TAGS = HTML_TAGS;
127
+ const INTERACTIVE_TAGS = new Set(["a", "area", "audio", "button", "details", "embed", "iframe", "input", "label", "optgroup", "option", "select", "summary", "textarea", "video"]);
128
+ exports.INTERACTIVE_TAGS = INTERACTIVE_TAGS;
129
+ const NON_SEMANTIC_TAGS = new Set(["div", "span"]);
130
+ exports.NON_SEMANTIC_TAGS = NON_SEMANTIC_TAGS;
131
+ const SEMANTIC_CONTAINER_TAGS = new Set(["section", "header", "footer", "article", "aside", "nav"]);
132
+ exports.SEMANTIC_CONTAINER_TAGS = SEMANTIC_CONTAINER_TAGS;
133
+ const GENERIC_CONTAINER_TAGS = new Set([...NON_SEMANTIC_TAGS, ...SEMANTIC_CONTAINER_TAGS]);
134
+ exports.GENERIC_CONTAINER_TAGS = GENERIC_CONTAINER_TAGS;
135
+ const TAG_SYNONYMS = new Map([
136
+ ["b", "strong"],
137
+ ["strong", "b"],
138
+ ["i", "em"],
139
+ ["em", "i"],
140
+ ]);
141
+ const tagAffinity = (a, b) => {
142
+ const ta = String(a || "").toLowerCase();
143
+ const tb = String(b || "").toLowerCase();
144
+ if (ta === tb)
145
+ return 1;
146
+ if (TAG_SYNONYMS.get(ta) === tb)
147
+ return 1;
148
+ if (GENERIC_CONTAINER_TAGS.has(ta) && GENERIC_CONTAINER_TAGS.has(tb))
149
+ return 0.75;
150
+ return 0;
151
+ };
152
+ exports.tagAffinity = tagAffinity;
153
+ const isPascalCase = (name) => /^[A-Z][A-Za-z0-9]*$/.test(name);
154
+ exports.isPascalCase = isPascalCase;
155
+ const isHtmlTag = (tag) => HTML_TAGS.has(String(tag || ""));
156
+ exports.isHtmlTag = isHtmlTag;
157
+ const styleObjectToCssText = (obj) => {
158
+ const parts = [];
159
+ for (const [k, v] of Object.entries(obj || {})) {
160
+ if (Array.isArray(v))
161
+ parts.push(`${k}: ${v.join("; ")}`);
162
+ else
163
+ parts.push(`${k}: ${v}`);
164
+ }
165
+ return parts.join("; ");
166
+ };
167
+ exports.styleObjectToCssText = styleObjectToCssText;
168
+ const layoutOnly = (node) => ({
169
+ tag: node.tag,
170
+ text: node.text || undefined,
171
+ interactive: !!node.interactive,
172
+ css: Object.fromEntries(Object.entries(node.css || {}).filter(([prop]) => (0, style_js_1.isLayoutProp)(prop))),
173
+ children: (node.children || []).map(layoutOnly),
174
+ });
175
+ const normalizeDom = (tree, opts, label) => {
176
+ const rendered = (0, framework_js_1.render)(tree, opts);
177
+ const domTree = rendered.available && rendered.tree ? layoutOnly(rendered.tree) : null;
178
+ return { tree: domTree, available: rendered.available };
179
+ };
180
+ exports.normalizeDom = normalizeDom;
@@ -0,0 +1,5 @@
1
+ declare const IMAGE_PACKAGES: Set<string>;
2
+ declare const LINK_PACKAGES: Set<string>;
3
+ declare const externalTagOf: (spec: any, exported: any) => "img" | "a" | "svg";
4
+ declare const knownRenderTag: (name: any) => string;
5
+ export { externalTagOf, knownRenderTag, IMAGE_PACKAGES, LINK_PACKAGES };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LINK_PACKAGES = exports.IMAGE_PACKAGES = exports.knownRenderTag = exports.externalTagOf = void 0;
4
+ // ── EXTERNAL COMPONENTS → the HTML they render ─────────────────────────────
5
+ //
6
+ // Some components come from packages we cannot unfold statically (next/image,
7
+ // lucide-react). They still render REAL HTML, and the snapshot must show that
8
+ // HTML, not the wrapper name. This is the one place that knows what a known
9
+ // external component becomes:
10
+ //
11
+ // next/image, next-image-export-optimizer → <img>
12
+ // next/link → <a>
13
+ // lucide-react (any icon), LucideIcon → <svg>
14
+ //
15
+ // A component not listed here stays as its own tag (we do not invent HTML).
16
+ const IMAGE_PACKAGES = new Set(["next/image", "next-image-export-optimizer", "next/legacy/image"]);
17
+ exports.IMAGE_PACKAGES = IMAGE_PACKAGES;
18
+ const LINK_PACKAGES = new Set(["next/link"]);
19
+ exports.LINK_PACKAGES = LINK_PACKAGES;
20
+ // The HTML tag an external module's default/named export renders, or null.
21
+ const externalTagOf = (spec, exported) => {
22
+ if (!spec)
23
+ return null;
24
+ if (IMAGE_PACKAGES.has(spec))
25
+ return "img";
26
+ if (LINK_PACKAGES.has(spec))
27
+ return "a";
28
+ if (spec === "lucide-react")
29
+ return "svg";
30
+ return null;
31
+ };
32
+ exports.externalTagOf = externalTagOf;
33
+ // A local wrapper component that is known to render a specific HTML element even
34
+ // though its body is dynamic (it picks an icon at runtime). Keyed by component
35
+ // name; the value is the tag it renders.
36
+ const KNOWN_RENDER = new Map([
37
+ ["LucideIcon", "svg"],
38
+ ]);
39
+ const knownRenderTag = (name) => KNOWN_RENDER.get(name) ?? null;
40
+ exports.knownRenderTag = knownRenderTag;
@@ -0,0 +1,20 @@
1
+ declare const isEventName: (name: any) => boolean;
2
+ declare const eventNameOf: (name: any) => string;
3
+ declare const propsOf: (tree: any) => unknown[];
4
+ declare const eventsOf: (tree: any) => unknown[];
5
+ declare const namesOf: (tree: any) => any[];
6
+ declare const usagesOf: (tree: any) => any[];
7
+ declare const normalizeFramework: (tree: any, label: any) => {
8
+ props: unknown[];
9
+ events: unknown[];
10
+ names: any[];
11
+ usages: any[];
12
+ open: boolean;
13
+ };
14
+ declare const frameworkSimilarity: (a: any, b: any, label: any) => {
15
+ score: number;
16
+ props: number;
17
+ events: number;
18
+ names: number;
19
+ };
20
+ export { normalizeFramework, frameworkSimilarity, propsOf, eventsOf, namesOf, usagesOf, isEventName, eventNameOf, };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eventNameOf = exports.isEventName = exports.usagesOf = exports.namesOf = exports.eventsOf = exports.propsOf = exports.frameworkSimilarity = exports.normalizeFramework = void 0;
4
+ const dom_js_1 = require("./dom.js");
5
+ const EVENT_PREFIX = /^(on|ng|v-on:|@)/;
6
+ const isEventName = (name) => EVENT_PREFIX.test(String(name || ""));
7
+ exports.isEventName = isEventName;
8
+ const eventNameOf = (name) => {
9
+ const raw = String(name || "");
10
+ if (raw.startsWith("on"))
11
+ return raw.slice(2).toLowerCase();
12
+ if (raw.startsWith("ng"))
13
+ return raw.slice(2).toLowerCase();
14
+ if (raw.startsWith("v-on:"))
15
+ return raw.slice(5).toLowerCase();
16
+ if (raw.startsWith("@"))
17
+ return raw.slice(1).toLowerCase();
18
+ return raw.toLowerCase();
19
+ };
20
+ exports.eventNameOf = eventNameOf;
21
+ const walk = (tree, visit) => {
22
+ if (!tree)
23
+ return;
24
+ visit(tree);
25
+ for (const child of tree.children || [])
26
+ walk(child, visit);
27
+ };
28
+ const propsOf = (tree) => {
29
+ const out = new Set();
30
+ walk(tree, (node) => {
31
+ for (const name of Object.keys(node.attrs || {})) {
32
+ if (isEventName(name))
33
+ continue;
34
+ out.add(name);
35
+ }
36
+ });
37
+ return [...out].sort();
38
+ };
39
+ exports.propsOf = propsOf;
40
+ const eventsOf = (tree) => {
41
+ const out = new Set();
42
+ walk(tree, (node) => {
43
+ if (dom_js_1.INTERACTIVE_TAGS.has(node.tag))
44
+ out.add("click");
45
+ for (const name of Object.keys(node.attrs || {})) {
46
+ if (isEventName(name))
47
+ out.add(eventNameOf(name));
48
+ }
49
+ });
50
+ return [...out].sort();
51
+ };
52
+ exports.eventsOf = eventsOf;
53
+ const namesOf = (tree) => {
54
+ const out = [];
55
+ walk(tree, (node) => {
56
+ if (node.tag && (0, dom_js_1.isPascalCase)(node.tag))
57
+ out.push(node.tag);
58
+ });
59
+ return out;
60
+ };
61
+ exports.namesOf = namesOf;
62
+ // Every COMPONENT usage in the tree: the name it was written as, the props
63
+ // PASSED to it (non-event attributes), and the source line. This is the material
64
+ // the framework signal compares — usage against usage, never accepted params.
65
+ const usagesOf = (tree) => {
66
+ const out = [];
67
+ walk(tree, (node) => {
68
+ if (!node.component)
69
+ return;
70
+ out.push({
71
+ name: node.component,
72
+ props: [...(node.passedProps || [])].sort(),
73
+ line: node.line ?? null,
74
+ });
75
+ });
76
+ return out;
77
+ };
78
+ exports.usagesOf = usagesOf;
79
+ const normalizeFramework = (tree, label) => {
80
+ const profile = {
81
+ props: propsOf(tree),
82
+ events: eventsOf(tree),
83
+ names: namesOf(tree),
84
+ usages: usagesOf(tree),
85
+ open: !!(tree && tree.spread),
86
+ };
87
+ return profile;
88
+ };
89
+ exports.normalizeFramework = normalizeFramework;
90
+ const jaccard = (a, b) => {
91
+ const A = new Set(a || []);
92
+ const B = new Set(b || []);
93
+ if (A.size === 0 || B.size === 0)
94
+ return 0;
95
+ let inter = 0;
96
+ for (const item of A)
97
+ if (B.has(item))
98
+ inter += 1;
99
+ const union = A.size + B.size - inter;
100
+ return union === 0 ? 0 : inter / union;
101
+ };
102
+ const shared = (a, b) => {
103
+ const B = new Set(b || []);
104
+ return [...new Set(a || [])].filter((item) => B.has(item)).sort();
105
+ };
106
+ const smallSetDiscount = (arrA, arrB) => {
107
+ const A = new Set(arrA || []);
108
+ const B = new Set(arrB || []);
109
+ const inter = [...A].filter((x) => B.has(x)).length;
110
+ const union = A.size + B.size - inter;
111
+ return union === 0 ? 1 : Math.min(1, union / 2);
112
+ };
113
+ const frameworkSimilarity = (a, b, label) => {
114
+ const A = a || { props: [], events: [], names: [] };
115
+ const B = b || { props: [], events: [], names: [] };
116
+ const props = jaccard(A.props, B.props) * smallSetDiscount(A.props, B.props);
117
+ const events = jaccard(A.events, B.events) * smallSetDiscount(A.events, B.events);
118
+ const names = jaccard(A.names, B.names);
119
+ const parts = [];
120
+ if (A.props.length || B.props.length)
121
+ parts.push({ w: 0.5, v: props });
122
+ if (A.events.length || B.events.length)
123
+ parts.push({ w: 0.2, v: events });
124
+ if (A.names.length || B.names.length)
125
+ parts.push({ w: 0.3, v: names });
126
+ const totalW = parts.reduce((sum, part) => sum + part.w, 0);
127
+ const score = totalW === 0 ? 0 : parts.reduce((sum, part) => sum + part.w * part.v, 0) / totalW;
128
+ return { score, props, events, names };
129
+ };
130
+ exports.frameworkSimilarity = frameworkSimilarity;
@@ -0,0 +1,7 @@
1
+ declare const buildStyledResolver: () => (tag: any, sf: any) => {
2
+ baseTag: any;
3
+ componentRef: any;
4
+ styleObj: {};
5
+ unresolved: any[];
6
+ };
7
+ export { buildStyledResolver };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStyledResolver = void 0;
4
+ const styled_components_js_1 = require("../playgrounds/styled-components.js");
5
+ const style_js_1 = require("./style.js");
6
+ const external_html_js_1 = require("./external-html.js");
7
+ const declarationsCache = new WeakMap();
8
+ const declarationsOf = (sf) => {
9
+ if (!declarationsCache.has(sf))
10
+ declarationsCache.set(sf, (0, styled_components_js_1.styledDeclarations)(sf));
11
+ return declarationsCache.get(sf);
12
+ };
13
+ const buildStyledResolver = () => {
14
+ if (!(0, styled_components_js_1.available)())
15
+ return null;
16
+ return (tag, sf) => {
17
+ if (!sf || !tag)
18
+ return null;
19
+ const info = declarationsOf(sf).get(tag);
20
+ if (!info)
21
+ return null;
22
+ const { css, unresolved } = (0, style_js_1.cssTextToStyles)(info.cssText);
23
+ // `styled(Image)` where Image is next/image: the base is the HTML it renders.
24
+ const externalBase = info.componentRef ? (0, external_html_js_1.externalTagOf)(info.externalSpec, info.componentRef) : null;
25
+ return { baseTag: info.baseTag || externalBase, componentRef: externalBase ? null : info.componentRef, styleObj: css, unresolved: [...unresolved, ...info.unresolved] };
26
+ };
27
+ };
28
+ exports.buildStyledResolver = buildStyledResolver;
@@ -0,0 +1,7 @@
1
+ declare const buildStyledResolver: () => (tag: any, sf: any) => {
2
+ baseTag: any;
3
+ componentRef: any;
4
+ styleObj: {};
5
+ unresolved: any[];
6
+ };
7
+ export { buildStyledResolver };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStyledResolver = void 0;
4
+ const styled_components_js_1 = require("../playgrounds/styled-components.js");
5
+ const style_js_1 = require("./style.js");
6
+ const external_html_js_1 = require("./external-html.js");
7
+ const declarationsCache = new WeakMap();
8
+ const declarationsOf = (sf) => {
9
+ if (!declarationsCache.has(sf))
10
+ declarationsCache.set(sf, (0, styled_components_js_1.styledDeclarations)(sf));
11
+ return declarationsCache.get(sf);
12
+ };
13
+ const buildStyledResolver = () => {
14
+ if (!(0, styled_components_js_1.available)())
15
+ return null;
16
+ return (tag, sf) => {
17
+ if (!sf || !tag)
18
+ return null;
19
+ const info = declarationsOf(sf).get(tag);
20
+ if (!info)
21
+ return null;
22
+ const { css, unresolved } = (0, style_js_1.cssTextToStyles)(info.cssText);
23
+ // `styled(Image)` where Image is next/image: the base is the HTML it renders.
24
+ const externalBase = info.componentRef ? (0, external_html_js_1.externalTagOf)(info.externalSpec, info.componentRef) : null;
25
+ return { baseTag: info.baseTag || externalBase, componentRef: externalBase ? null : info.componentRef, styleObj: css, unresolved: [...unresolved, ...info.unresolved] };
26
+ };
27
+ };
28
+ exports.buildStyledResolver = buildStyledResolver;
@@ -0,0 +1,15 @@
1
+ declare const LAYOUT_PROPS: Set<string>;
2
+ declare const isLayoutProp: (prop: any) => boolean;
3
+ declare const cssTextToStyles: (text: any) => {
4
+ css: {};
5
+ unresolved: any[];
6
+ };
7
+ declare const camelToKebab: (name: any) => string;
8
+ declare const styleObjectToText: (obj: any) => string;
9
+ declare const mergeStyles: (a: any, b: any) => {};
10
+ declare const mergeProfiles: (a: any, b: any) => {
11
+ css: {};
12
+ unresolved: any[];
13
+ };
14
+ declare const stylesSimilarity: (a: any, b: any, label: any) => number;
15
+ export { LAYOUT_PROPS, isLayoutProp, cssTextToStyles, camelToKebab, styleObjectToText, mergeStyles, mergeProfiles, stylesSimilarity, };