@md-code/component-uniqueness 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +202 -0
- package/README.md +21 -3
- package/dist/config.d.ts +50 -0
- package/dist/config.js +402 -0
- package/dist/constants.d.ts +55 -0
- package/dist/constants.js +86 -0
- package/dist/decision-maker.d.ts +39 -0
- package/dist/decision-maker.js +119 -0
- package/dist/filter/child-element.d.ts +3 -0
- package/dist/filter/child-element.js +17 -0
- package/dist/filter/missing-component.d.ts +10 -0
- package/dist/filter/missing-component.js +96 -0
- package/dist/filter/no-structure.d.ts +3 -0
- package/dist/filter/no-structure.js +16 -0
- package/dist/filter/usages.d.ts +3 -0
- package/dist/filter/usages.js +14 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +244 -0
- package/dist/lib-registry.d.ts +4 -0
- package/dist/lib-registry.js +376 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +70 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.js +666 -0
- package/dist/matcher/a11y.d.ts +19 -0
- package/dist/matcher/a11y.js +311 -0
- package/dist/matcher/behavior.d.ts +10 -0
- package/dist/matcher/behavior.js +32 -0
- package/dist/matcher/css-matching.d.ts +18 -0
- package/dist/matcher/css-matching.js +159 -0
- package/dist/matcher/framework/index.d.ts +2 -0
- package/dist/matcher/framework/index.js +37 -0
- package/dist/matcher/framework/react.d.ts +12 -0
- package/dist/matcher/framework/react.js +70 -0
- package/dist/matcher/index.d.ts +64 -0
- package/dist/matcher/index.js +38 -0
- package/dist/matcher/name.d.ts +15 -0
- package/dist/matcher/name.js +154 -0
- package/dist/matcher/structure.d.ts +22 -0
- package/dist/matcher/structure.js +329 -0
- package/dist/matcher/styles.d.ts +20 -0
- package/dist/matcher/styles.js +49 -0
- package/dist/normalize/candidate.d.ts +3 -0
- package/dist/normalize/candidate.js +21 -0
- package/dist/normalize/dom.d.ts +22 -0
- package/dist/normalize/dom.js +180 -0
- package/dist/normalize/external-html.d.ts +5 -0
- package/dist/normalize/external-html.js +40 -0
- package/dist/normalize/framework.d.ts +20 -0
- package/dist/normalize/framework.js +130 -0
- package/dist/normalize/resolver.d.ts +7 -0
- package/dist/normalize/resolver.js +28 -0
- package/dist/normalize/style-resolver.d.ts +7 -0
- package/dist/normalize/style-resolver.js +28 -0
- package/dist/normalize/style.d.ts +15 -0
- package/dist/normalize/style.js +174 -0
- package/dist/normalize/words.d.ts +3 -0
- package/dist/normalize/words.js +40 -0
- package/dist/package.json +88 -0
- package/dist/playgrounds/angular.d.ts +7 -0
- package/dist/playgrounds/angular.js +9 -0
- package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
- package/dist/playgrounds/framework-entrypoint.js +102 -0
- package/dist/playgrounds/framework.d.ts +10 -0
- package/dist/playgrounds/framework.js +102 -0
- package/dist/playgrounds/react.d.ts +14 -0
- package/dist/playgrounds/react.js +1288 -0
- package/dist/playgrounds/scss.d.ts +6 -0
- package/dist/playgrounds/scss.js +9 -0
- package/dist/playgrounds/style-entrypoint.d.ts +13 -0
- package/dist/playgrounds/style-entrypoint.js +82 -0
- package/dist/playgrounds/style.d.ts +13 -0
- package/dist/playgrounds/style.js +82 -0
- package/dist/playgrounds/styled-components.d.ts +7 -0
- package/dist/playgrounds/styled-components.js +190 -0
- package/dist/playgrounds/tailwind.d.ts +15 -0
- package/dist/playgrounds/tailwind.js +256 -0
- package/dist/playgrounds/vue.d.ts +7 -0
- package/dist/playgrounds/vue.js +9 -0
- package/dist/report/asks.d.ts +27 -0
- package/dist/report/asks.js +28 -0
- package/dist/report/cli-report.d.ts +7 -0
- package/dist/report/cli-report.js +187 -0
- package/dist/report/codes/index.d.ts +37 -0
- package/dist/report/codes/index.js +31 -0
- package/dist/report/errorTypes/index.d.ts +92 -0
- package/dist/report/errorTypes/index.js +186 -0
- package/dist/report/evidence.d.ts +2 -0
- package/dist/report/evidence.js +8 -0
- package/dist/report/explain.d.ts +27 -0
- package/dist/report/explain.js +76 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +24 -0
- package/dist/report/matchers/a11y/model.d.ts +20 -0
- package/dist/report/matchers/a11y/model.js +14 -0
- package/dist/report/matchers/a11y/text.d.ts +2 -0
- package/dist/report/matchers/a11y/text.js +22 -0
- package/dist/report/matchers/behavior/model.d.ts +20 -0
- package/dist/report/matchers/behavior/model.js +12 -0
- package/dist/report/matchers/behavior/text.d.ts +2 -0
- package/dist/report/matchers/behavior/text.js +22 -0
- package/dist/report/matchers/framework/model.d.ts +10 -0
- package/dist/report/matchers/framework/model.js +39 -0
- package/dist/report/matchers/framework/text.d.ts +2 -0
- package/dist/report/matchers/framework/text.js +26 -0
- package/dist/report/matchers/index.d.ts +5 -0
- package/dist/report/matchers/index.js +97 -0
- package/dist/report/matchers/name/model.d.ts +20 -0
- package/dist/report/matchers/name/model.js +30 -0
- package/dist/report/matchers/name/text.d.ts +2 -0
- package/dist/report/matchers/name/text.js +17 -0
- package/dist/report/matchers/set-model.d.ts +31 -0
- package/dist/report/matchers/set-model.js +42 -0
- package/dist/report/matchers/structure/model.d.ts +10 -0
- package/dist/report/matchers/structure/model.js +58 -0
- package/dist/report/matchers/structure/text.d.ts +2 -0
- package/dist/report/matchers/structure/text.js +40 -0
- package/dist/report/matchers/styles/model.d.ts +11 -0
- package/dist/report/matchers/styles/model.js +36 -0
- package/dist/report/matchers/styles/text.d.ts +2 -0
- package/dist/report/matchers/styles/text.js +40 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +185 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
- package/dist/report/user-report/data/collect.d.ts +68 -0
- package/dist/report/user-report/data/collect.js +150 -0
- package/dist/report/user-report/data/folders.d.ts +3 -0
- package/dist/report/user-report/data/folders.js +73 -0
- package/dist/report/user-report/data/groups.d.ts +13 -0
- package/dist/report/user-report/data/groups.js +76 -0
- package/dist/report/user-report/data/links.d.ts +39 -0
- package/dist/report/user-report/data/links.js +222 -0
- package/dist/report/user-report/data/snapshot.d.ts +9 -0
- package/dist/report/user-report/data/snapshot.js +180 -0
- package/dist/report/user-report/data/source.d.ts +13 -0
- package/dist/report/user-report/data/source.js +58 -0
- package/dist/report/user-report/data/word.d.ts +3 -0
- package/dist/report/user-report/data/word.js +32 -0
- package/dist/report/user-report/html/shell.d.ts +2 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +7 -0
- package/dist/report/user-report/index.js +47 -0
- package/dist/report/vocabulary/evidence.d.ts +48 -0
- package/dist/report/vocabulary/evidence.js +66 -0
- package/dist/report/vocabulary/format.d.ts +4 -0
- package/dist/report/vocabulary/format.js +20 -0
- package/dist/report/vocabulary/labels.d.ts +134 -0
- package/dist/report/vocabulary/labels.js +87 -0
- package/dist/report/vocabulary/phrases.d.ts +20 -0
- package/dist/report/vocabulary/phrases.js +34 -0
- package/dist/self-catalog.d.ts +4 -0
- package/dist/self-catalog.js +179 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +125 -0
- package/package.json +86 -71
- package/config.js +0 -372
- package/decision-maker.js +0 -109
- package/filter/drop-child-element.js +0 -14
- package/filter/drop-no-structure.js +0 -13
- package/filter/drop-usages.js +0 -13
- package/filter/missing-component.js +0 -100
- package/index.js +0 -184
- package/logger.js +0 -44
- package/main.js +0 -584
- package/matcher/a11y.js +0 -65
- package/matcher/behavior.js +0 -31
- package/matcher/framework/index.js +0 -15
- package/matcher/framework/react.js +0 -25
- package/matcher/index.js +0 -36
- package/matcher/name.js +0 -132
- package/matcher/structure.js +0 -242
- package/normalize/candidate.js +0 -22
- package/normalize/dom.js +0 -187
- package/normalize/framework.js +0 -110
- package/normalize/style-resolver.js +0 -24
- package/normalize/style.js +0 -175
- package/normalize/words.js +0 -40
- package/playgrounds/angular.js +0 -11
- package/playgrounds/framework-entrypoint.js +0 -90
- package/playgrounds/react.js +0 -998
- package/playgrounds/scss.js +0 -7
- package/playgrounds/style-entrypoint.js +0 -78
- package/playgrounds/styled-components.js +0 -138
- package/playgrounds/tailwind.js +0 -186
- package/playgrounds/vue.js +0 -11
- package/plugin.js +0 -3
- package/report.js +0 -162
- package/utils.js +0 -92
package/normalize/framework.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { INTERACTIVE_TAGS, isPascalCase } = require("./dom.js");
|
|
4
|
-
|
|
5
|
-
const EVENT_PREFIX = /^(on|ng|v-on:|@)/;
|
|
6
|
-
|
|
7
|
-
const isEventName = (name) => EVENT_PREFIX.test(String(name || ""));
|
|
8
|
-
|
|
9
|
-
const eventNameOf = (name) => {
|
|
10
|
-
const raw = String(name || "");
|
|
11
|
-
if (raw.startsWith("on")) return raw.slice(2).toLowerCase();
|
|
12
|
-
if (raw.startsWith("ng")) return raw.slice(2).toLowerCase();
|
|
13
|
-
if (raw.startsWith("v-on:")) return raw.slice(5).toLowerCase();
|
|
14
|
-
if (raw.startsWith("@")) return raw.slice(1).toLowerCase();
|
|
15
|
-
return raw.toLowerCase();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const walk = (tree, visit) => {
|
|
19
|
-
if (!tree) return;
|
|
20
|
-
visit(tree);
|
|
21
|
-
for (const child of tree.children || []) walk(child, visit);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const propsOf = (tree) => {
|
|
25
|
-
const out = new Set();
|
|
26
|
-
walk(tree, (node) => {
|
|
27
|
-
for (const name of Object.keys(node.attrs || {})) {
|
|
28
|
-
if (isEventName(name)) continue;
|
|
29
|
-
out.add(name);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return [...out].sort();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const eventsOf = (tree) => {
|
|
36
|
-
const out = new Set();
|
|
37
|
-
walk(tree, (node) => {
|
|
38
|
-
if (INTERACTIVE_TAGS.has(node.tag)) out.add("click");
|
|
39
|
-
for (const name of Object.keys(node.attrs || {})) {
|
|
40
|
-
if (isEventName(name)) out.add(eventNameOf(name));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return [...out].sort();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const namesOf = (tree) => {
|
|
47
|
-
const out = [];
|
|
48
|
-
walk(tree, (node) => {
|
|
49
|
-
if (node.tag && isPascalCase(node.tag)) out.push(node.tag);
|
|
50
|
-
});
|
|
51
|
-
return out;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const normalizeFramework = (tree, label) => {
|
|
55
|
-
const profile = {
|
|
56
|
-
props: propsOf(tree),
|
|
57
|
-
events: eventsOf(tree),
|
|
58
|
-
names: namesOf(tree),
|
|
59
|
-
open: !!(tree && tree.spread),
|
|
60
|
-
};
|
|
61
|
-
return profile;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const jaccard = (a, b) => {
|
|
65
|
-
const A = new Set(a || []);
|
|
66
|
-
const B = new Set(b || []);
|
|
67
|
-
if (A.size === 0 || B.size === 0) return 0;
|
|
68
|
-
let inter = 0;
|
|
69
|
-
for (const item of A) if (B.has(item)) inter += 1;
|
|
70
|
-
const union = A.size + B.size - inter;
|
|
71
|
-
return union === 0 ? 0 : inter / union;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const shared = (a, b) => {
|
|
75
|
-
const B = new Set(b || []);
|
|
76
|
-
return [...new Set(a || [])].filter((item) => B.has(item)).sort();
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const smallSetDiscount = (arrA, arrB) => {
|
|
80
|
-
const A = new Set(arrA || []);
|
|
81
|
-
const B = new Set(arrB || []);
|
|
82
|
-
const inter = [...A].filter((x) => B.has(x)).length;
|
|
83
|
-
const union = A.size + B.size - inter;
|
|
84
|
-
return union === 0 ? 1 : Math.min(1, union / 2);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const frameworkSimilarity = (a, b, label) => {
|
|
88
|
-
const A = a || { props: [], events: [], names: [] };
|
|
89
|
-
const B = b || { props: [], events: [], names: [] };
|
|
90
|
-
const props = jaccard(A.props, B.props) * smallSetDiscount(A.props, B.props);
|
|
91
|
-
const events = jaccard(A.events, B.events) * smallSetDiscount(A.events, B.events);
|
|
92
|
-
const names = jaccard(A.names, B.names);
|
|
93
|
-
const parts = [];
|
|
94
|
-
if (A.props.length || B.props.length) parts.push({ w: 0.5, v: props });
|
|
95
|
-
if (A.events.length || B.events.length) parts.push({ w: 0.2, v: events });
|
|
96
|
-
if (A.names.length || B.names.length) parts.push({ w: 0.3, v: names });
|
|
97
|
-
const totalW = parts.reduce((sum, part) => sum + part.w, 0);
|
|
98
|
-
const score = totalW === 0 ? 0 : parts.reduce((sum, part) => sum + part.w * part.v, 0) / totalW;
|
|
99
|
-
return { score, props, events, names };
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
module.exports = {
|
|
103
|
-
normalizeFramework,
|
|
104
|
-
frameworkSimilarity,
|
|
105
|
-
propsOf,
|
|
106
|
-
eventsOf,
|
|
107
|
-
namesOf,
|
|
108
|
-
isEventName,
|
|
109
|
-
eventNameOf,
|
|
110
|
-
};
|
|
@@ -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 };
|
package/normalize/style.js
DELETED
|
@@ -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
|
-
};
|
package/normalize/words.js
DELETED
|
@@ -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 };
|
package/playgrounds/angular.js
DELETED
|
@@ -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
|
-
};
|