@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.
- 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 -60
- package/config.js +0 -362
- package/decision-maker.js +0 -109
- package/filter/drop-child-element.js +0 -13
- package/filter/drop-usages.js +0 -13
- package/filter/missing-component.js +0 -68
- package/index.js +0 -184
- package/logger.js +0 -44
- package/main.js +0 -539
- 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 -208
- package/normalize/candidate.js +0 -22
- package/normalize/dom.js +0 -167
- package/normalize/framework.js +0 -129
- 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 -997
- 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 -159
- package/utils.js +0 -92
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stylesSimilarity = exports.mergeProfiles = exports.mergeStyles = exports.styleObjectToText = exports.camelToKebab = exports.cssTextToStyles = exports.isLayoutProp = exports.LAYOUT_PROPS = void 0;
|
|
4
|
+
const remeda_1 = require("remeda");
|
|
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
|
+
exports.LAYOUT_PROPS = LAYOUT_PROPS;
|
|
97
|
+
const isLayoutProp = (prop) => LAYOUT_PROPS.has(prop);
|
|
98
|
+
exports.isLayoutProp = isLayoutProp;
|
|
99
|
+
const UNRESOLVED_VALUE_RE = /var\(|url\(|@import|calc\(\s*var\(/i;
|
|
100
|
+
const cssTextToStyles = (text) => {
|
|
101
|
+
const css = {};
|
|
102
|
+
const unresolved = [];
|
|
103
|
+
if (typeof text !== "string")
|
|
104
|
+
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)
|
|
109
|
+
continue;
|
|
110
|
+
const prop = decl.slice(0, idx).trim();
|
|
111
|
+
const value = decl.slice(idx + 1).trim();
|
|
112
|
+
if (!prop || !value)
|
|
113
|
+
continue;
|
|
114
|
+
if (prop.startsWith("@") || prop.startsWith("$") || value.includes("{"))
|
|
115
|
+
continue;
|
|
116
|
+
if (!/^[a-zA-Z-]+$/.test(prop))
|
|
117
|
+
continue;
|
|
118
|
+
const p = prop.toLowerCase();
|
|
119
|
+
if (UNRESOLVED_VALUE_RE.test(value)) {
|
|
120
|
+
unresolved.push(`${p}: ${value}`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!Object.prototype.hasOwnProperty.call(css, p))
|
|
124
|
+
css[p] = [];
|
|
125
|
+
if (!css[p].includes(value))
|
|
126
|
+
css[p].push(value);
|
|
127
|
+
}
|
|
128
|
+
return { css, unresolved };
|
|
129
|
+
};
|
|
130
|
+
exports.cssTextToStyles = cssTextToStyles;
|
|
131
|
+
const camelToKebab = (name) => String(name).replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
132
|
+
exports.camelToKebab = camelToKebab;
|
|
133
|
+
const styleObjectToText = (obj) => {
|
|
134
|
+
const parts = [];
|
|
135
|
+
for (const [k, v] of (0, remeda_1.entries)(obj || {})) {
|
|
136
|
+
if (v === undefined || v === null)
|
|
137
|
+
continue;
|
|
138
|
+
const val = Array.isArray(v) ? v.join(", ") : String(v);
|
|
139
|
+
parts.push(`${camelToKebab(k)}: ${val}`);
|
|
140
|
+
}
|
|
141
|
+
return parts.join("; ");
|
|
142
|
+
};
|
|
143
|
+
exports.styleObjectToText = styleObjectToText;
|
|
144
|
+
const mergeStyles = (a, b) => {
|
|
145
|
+
const out = {};
|
|
146
|
+
for (const [prop, values] of (0, remeda_1.entries)(a))
|
|
147
|
+
out[prop] = [...values];
|
|
148
|
+
for (const [prop, values] of (0, remeda_1.entries)(b)) {
|
|
149
|
+
if (!Object.prototype.hasOwnProperty.call(out, prop)) {
|
|
150
|
+
out[prop] = [...values];
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
for (const v of values) {
|
|
154
|
+
if (!out[prop].includes(v))
|
|
155
|
+
out[prop].push(v);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
};
|
|
160
|
+
exports.mergeStyles = mergeStyles;
|
|
161
|
+
const mergeProfiles = (a, b) => ({
|
|
162
|
+
css: mergeStyles(a.css, b.css),
|
|
163
|
+
unresolved: [...a.unresolved, ...b.unresolved],
|
|
164
|
+
});
|
|
165
|
+
exports.mergeProfiles = mergeProfiles;
|
|
166
|
+
const stylesSimilarity = (a, b, label) => {
|
|
167
|
+
const A = new Set((0, remeda_1.keys)(a));
|
|
168
|
+
const B = new Set((0, remeda_1.keys)(b));
|
|
169
|
+
const inter = [...A].filter((p) => B.has(p));
|
|
170
|
+
const union = A.size + B.size - inter.length;
|
|
171
|
+
const score = union === 0 ? 0 : inter.length / union;
|
|
172
|
+
return score;
|
|
173
|
+
};
|
|
174
|
+
exports.stylesSimilarity = stylesSimilarity;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GENERIC_WORDS = exports.pascalWords = void 0;
|
|
4
|
+
const pascalWords = (s) => String(s || "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
5
|
+
exports.pascalWords = pascalWords;
|
|
6
|
+
const GENERIC_WORDS = new Set([
|
|
7
|
+
"button",
|
|
8
|
+
"field",
|
|
9
|
+
"input",
|
|
10
|
+
"select",
|
|
11
|
+
"box",
|
|
12
|
+
"list",
|
|
13
|
+
"item",
|
|
14
|
+
"row",
|
|
15
|
+
"cell",
|
|
16
|
+
"icon",
|
|
17
|
+
"label",
|
|
18
|
+
"value",
|
|
19
|
+
"text",
|
|
20
|
+
"data",
|
|
21
|
+
"info",
|
|
22
|
+
"meta",
|
|
23
|
+
"main",
|
|
24
|
+
"base",
|
|
25
|
+
"option",
|
|
26
|
+
"panel",
|
|
27
|
+
"view",
|
|
28
|
+
"form",
|
|
29
|
+
"card",
|
|
30
|
+
"tag",
|
|
31
|
+
"chip",
|
|
32
|
+
"badge",
|
|
33
|
+
"menu",
|
|
34
|
+
"bar",
|
|
35
|
+
"grid",
|
|
36
|
+
"table",
|
|
37
|
+
"section",
|
|
38
|
+
"state",
|
|
39
|
+
]);
|
|
40
|
+
exports.GENERIC_WORDS = GENERIC_WORDS;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@md-code/component-uniqueness",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "ESLint rule and CLI that find duplicate components, raw HTML that should be a canonical component, and copied parts of components, by comparing structure, CSS, behavior, accessibility and framework profile.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "DrBoria <dr.boria@gmail.com>",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/DrBoria/component-uniqueness/issues"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/DrBoria/component-uniqueness#readme",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"eslint",
|
|
14
|
+
"eslintplugin",
|
|
15
|
+
"eslint-plugin",
|
|
16
|
+
"duplicate-components",
|
|
17
|
+
"design-system"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/DrBoria/component-uniqueness.git"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"bin": {
|
|
29
|
+
"component-uniqueness": "dist/main.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/",
|
|
33
|
+
"README.md",
|
|
34
|
+
"CHANGELOG.md"
|
|
35
|
+
],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./dist/index.js",
|
|
38
|
+
"./plugin": "./dist/index.js",
|
|
39
|
+
"./config": "./dist/config.js",
|
|
40
|
+
"./report": "./dist/report/index.js",
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"jsdom": "^29.1.1",
|
|
45
|
+
"minimatch": "^9.0.4",
|
|
46
|
+
"remeda": "^2.50.0",
|
|
47
|
+
"tailwindcss": "^4.3.3",
|
|
48
|
+
"ts-morph": "^24.0.0",
|
|
49
|
+
"typescript": ">=5.5.0 <7"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
53
|
+
"build": "npm run clean && tsc -p tsconfig.json && npm run prebuild:report",
|
|
54
|
+
"prebuild:report": "node scripts/build-report-bundle.mjs",
|
|
55
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
56
|
+
"gen:catalog": "node dist/main.js",
|
|
57
|
+
"overview": "node dist/main.js --overview",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"lint": "eslint .",
|
|
60
|
+
"prepublishOnly": "npm run build && vitest run --no-file-parallelism"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"eslint": ">=8.40.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@emotion/react": "^11.0.0",
|
|
67
|
+
"@emotion/styled": "^11.0.0",
|
|
68
|
+
"@md-code/report-shared": "workspace:*",
|
|
69
|
+
"@md-code/components": "^0.0.1",
|
|
70
|
+
"@md-code/sections": "^0.0.1",
|
|
71
|
+
"@md/styles": "workspace:*",
|
|
72
|
+
"@mui/icons-material": "^7.0.0",
|
|
73
|
+
"@mui/material": "^7.0.0",
|
|
74
|
+
"@types/node": "^26.6.6",
|
|
75
|
+
"@types/react": "^19.3.0",
|
|
76
|
+
"@types/react-dom": "^19.3.0",
|
|
77
|
+
"@typescript-eslint/parser": "8.56.0",
|
|
78
|
+
"esbuild": "^0.28.2",
|
|
79
|
+
"prismjs": "^1.30.0",
|
|
80
|
+
"react": "^19.0.0",
|
|
81
|
+
"react-dom": "^19.0.0",
|
|
82
|
+
"styled-components": "^6.1.0",
|
|
83
|
+
"vitest": "^4.1.0"
|
|
84
|
+
},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.available = exports.resolveCss = exports.parseComponents = void 0;
|
|
4
|
+
const parseComponents = () => [];
|
|
5
|
+
exports.parseComponents = parseComponents;
|
|
6
|
+
const resolveCss = () => ({ css: "", unresolved: [] });
|
|
7
|
+
exports.resolveCss = resolveCss;
|
|
8
|
+
const available = () => false;
|
|
9
|
+
exports.available = available;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const getPlayground: (framework: any) => any;
|
|
2
|
+
declare const getFramework: (opts: any) => string;
|
|
3
|
+
declare const parseComponents: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
4
|
+
declare const setLiveSource: (fileAbs: any, text: any, opts: any) => void;
|
|
5
|
+
declare const parseElements: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
6
|
+
declare const parseParts: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
7
|
+
declare const resolveCss: (tree: any, opts: any) => any;
|
|
8
|
+
declare const render: (tree: any, opts: any) => any;
|
|
9
|
+
declare const rawClassTokens: (tree: any) => Set<unknown>;
|
|
10
|
+
export { getPlayground, getFramework, parseComponents, setLiveSource, parseElements, parseParts, resolveCss, render, rawClassTokens, };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rawClassTokens = exports.render = exports.resolveCss = exports.parseParts = exports.parseElements = exports.setLiveSource = exports.parseComponents = exports.getFramework = exports.getPlayground = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
const style_entrypoint_js_1 = require("./style-entrypoint.js");
|
|
7
|
+
const style_resolver_js_1 = require("../normalize/style-resolver.js");
|
|
8
|
+
let styledResolver = null;
|
|
9
|
+
const withStyledResolver = (opts) => {
|
|
10
|
+
if (!styledResolver)
|
|
11
|
+
styledResolver = (0, style_resolver_js_1.buildStyledResolver)();
|
|
12
|
+
return styledResolver ? { ...opts, styledResolver } : opts;
|
|
13
|
+
};
|
|
14
|
+
// Playgrounds are heavy (jsdom, TypeScript AST): load one only when its
|
|
15
|
+
// framework is actually seen, so the ESLint rule stays cheap.
|
|
16
|
+
const lazyRequire = (0, node_module_1.createRequire)(__filename);
|
|
17
|
+
const PLAYGROUNDS = {
|
|
18
|
+
react: () => lazyRequire("./react.js"),
|
|
19
|
+
angular: () => lazyRequire("./angular.js"),
|
|
20
|
+
vue: () => lazyRequire("./vue.js"),
|
|
21
|
+
};
|
|
22
|
+
const cache = new Map();
|
|
23
|
+
const getPlayground = (framework) => {
|
|
24
|
+
const key = String(framework || "react").toLowerCase();
|
|
25
|
+
if (!cache.has(key)) {
|
|
26
|
+
const loader = PLAYGROUNDS[key] || PLAYGROUNDS.react;
|
|
27
|
+
cache.set(key, loader());
|
|
28
|
+
}
|
|
29
|
+
return cache.get(key);
|
|
30
|
+
};
|
|
31
|
+
exports.getPlayground = getPlayground;
|
|
32
|
+
const getFramework = (opts) => (0, config_js_1.normalizeOptions)(opts).framework;
|
|
33
|
+
exports.getFramework = getFramework;
|
|
34
|
+
const parseComponents = (fileAbs, canonicalNames, opts) => {
|
|
35
|
+
const pg = getPlayground(getFramework(opts));
|
|
36
|
+
if (!pg.available || !pg.available())
|
|
37
|
+
return [];
|
|
38
|
+
return pg.parseComponents(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
39
|
+
};
|
|
40
|
+
exports.parseComponents = parseComponents;
|
|
41
|
+
const setLiveSource = (fileAbs, text, opts) => {
|
|
42
|
+
const pg = getPlayground(getFramework(opts));
|
|
43
|
+
if (pg.setLiveSource)
|
|
44
|
+
pg.setLiveSource(fileAbs, text);
|
|
45
|
+
};
|
|
46
|
+
exports.setLiveSource = setLiveSource;
|
|
47
|
+
const parseElements = (fileAbs, canonicalNames, opts) => {
|
|
48
|
+
const pg = getPlayground(getFramework(opts));
|
|
49
|
+
if (!pg.available || !pg.available() || !pg.parseElements)
|
|
50
|
+
return [];
|
|
51
|
+
return pg.parseElements(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
52
|
+
};
|
|
53
|
+
exports.parseElements = parseElements;
|
|
54
|
+
const parseParts = (fileAbs, canonicalNames, opts) => {
|
|
55
|
+
const pg = getPlayground(getFramework(opts));
|
|
56
|
+
if (!pg.available || !pg.available() || !pg.parseParts)
|
|
57
|
+
return [];
|
|
58
|
+
return pg.parseParts(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
59
|
+
};
|
|
60
|
+
exports.parseParts = parseParts;
|
|
61
|
+
const resolveCss = (tree, opts) => {
|
|
62
|
+
const pg = getPlayground(getFramework(opts));
|
|
63
|
+
if (!pg.resolveCss)
|
|
64
|
+
return { css: "", unresolved: [] };
|
|
65
|
+
return pg.resolveCss(tree);
|
|
66
|
+
};
|
|
67
|
+
exports.resolveCss = resolveCss;
|
|
68
|
+
const classTokensOf = (tree, out = new Set()) => {
|
|
69
|
+
if (!tree)
|
|
70
|
+
return out;
|
|
71
|
+
if (tree.className)
|
|
72
|
+
for (const token of String(tree.className).split(/\s+/))
|
|
73
|
+
if (token)
|
|
74
|
+
out.add(token);
|
|
75
|
+
for (const child of tree.children || [])
|
|
76
|
+
classTokensOf(child, out);
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
const render = (tree, opts) => {
|
|
80
|
+
const pg = getPlayground(getFramework(opts));
|
|
81
|
+
if (!pg.render)
|
|
82
|
+
return { tree: null, available: false };
|
|
83
|
+
const stylesheet = (0, style_entrypoint_js_1.buildStylesheet)([...classTokensOf(tree)], opts);
|
|
84
|
+
return pg.render(tree, { stylesheet });
|
|
85
|
+
};
|
|
86
|
+
exports.render = render;
|
|
87
|
+
const rawClassTokens = (tree) => {
|
|
88
|
+
const out = new Set();
|
|
89
|
+
const visit = (n) => {
|
|
90
|
+
if (!n)
|
|
91
|
+
return;
|
|
92
|
+
if (typeof n.className === "string")
|
|
93
|
+
for (const token of n.className.split(/\s+/))
|
|
94
|
+
if (token)
|
|
95
|
+
out.add(token);
|
|
96
|
+
for (const child of n.children || [])
|
|
97
|
+
visit(child);
|
|
98
|
+
};
|
|
99
|
+
visit(tree);
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
exports.rawClassTokens = rawClassTokens;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const getPlayground: (framework: any) => any;
|
|
2
|
+
declare const getFramework: (opts: any) => string;
|
|
3
|
+
declare const parseComponents: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
4
|
+
declare const setLiveSource: (fileAbs: any, text: any, opts: any) => void;
|
|
5
|
+
declare const parseElements: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
6
|
+
declare const parseParts: (fileAbs: any, canonicalNames: any, opts: any) => any;
|
|
7
|
+
declare const resolveCss: (tree: any, opts: any) => any;
|
|
8
|
+
declare const render: (tree: any, opts: any) => any;
|
|
9
|
+
declare const rawClassTokens: (tree: any) => Set<unknown>;
|
|
10
|
+
export { getPlayground, getFramework, parseComponents, setLiveSource, parseElements, parseParts, resolveCss, render, rawClassTokens, };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rawClassTokens = exports.render = exports.resolveCss = exports.parseParts = exports.parseElements = exports.setLiveSource = exports.parseComponents = exports.getFramework = exports.getPlayground = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
const style_js_1 = require("./style.js");
|
|
7
|
+
const resolver_js_1 = require("../normalize/resolver.js");
|
|
8
|
+
let styledResolver = null;
|
|
9
|
+
const withStyledResolver = (opts) => {
|
|
10
|
+
if (!styledResolver)
|
|
11
|
+
styledResolver = (0, resolver_js_1.buildStyledResolver)();
|
|
12
|
+
return styledResolver ? { ...opts, styledResolver } : opts;
|
|
13
|
+
};
|
|
14
|
+
// Playgrounds are heavy (jsdom, TypeScript AST): load one only when its
|
|
15
|
+
// framework is actually seen, so the ESLint rule stays cheap.
|
|
16
|
+
const lazyRequire = (0, node_module_1.createRequire)(__filename);
|
|
17
|
+
const PLAYGROUNDS = {
|
|
18
|
+
react: () => lazyRequire("./react.js"),
|
|
19
|
+
angular: () => lazyRequire("./angular.js"),
|
|
20
|
+
vue: () => lazyRequire("./vue.js"),
|
|
21
|
+
};
|
|
22
|
+
const cache = new Map();
|
|
23
|
+
const getPlayground = (framework) => {
|
|
24
|
+
const key = String(framework || "react").toLowerCase();
|
|
25
|
+
if (!cache.has(key)) {
|
|
26
|
+
const loader = PLAYGROUNDS[key] || PLAYGROUNDS.react;
|
|
27
|
+
cache.set(key, loader());
|
|
28
|
+
}
|
|
29
|
+
return cache.get(key);
|
|
30
|
+
};
|
|
31
|
+
exports.getPlayground = getPlayground;
|
|
32
|
+
const getFramework = (opts) => (0, config_js_1.normalizeOptions)(opts).framework;
|
|
33
|
+
exports.getFramework = getFramework;
|
|
34
|
+
const parseComponents = (fileAbs, canonicalNames, opts) => {
|
|
35
|
+
const pg = getPlayground(getFramework(opts));
|
|
36
|
+
if (!pg.available || !pg.available())
|
|
37
|
+
return [];
|
|
38
|
+
return pg.parseComponents(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
39
|
+
};
|
|
40
|
+
exports.parseComponents = parseComponents;
|
|
41
|
+
const setLiveSource = (fileAbs, text, opts) => {
|
|
42
|
+
const pg = getPlayground(getFramework(opts));
|
|
43
|
+
if (pg.setLiveSource)
|
|
44
|
+
pg.setLiveSource(fileAbs, text);
|
|
45
|
+
};
|
|
46
|
+
exports.setLiveSource = setLiveSource;
|
|
47
|
+
const parseElements = (fileAbs, canonicalNames, opts) => {
|
|
48
|
+
const pg = getPlayground(getFramework(opts));
|
|
49
|
+
if (!pg.available || !pg.available() || !pg.parseElements)
|
|
50
|
+
return [];
|
|
51
|
+
return pg.parseElements(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
52
|
+
};
|
|
53
|
+
exports.parseElements = parseElements;
|
|
54
|
+
const parseParts = (fileAbs, canonicalNames, opts) => {
|
|
55
|
+
const pg = getPlayground(getFramework(opts));
|
|
56
|
+
if (!pg.available || !pg.available() || !pg.parseParts)
|
|
57
|
+
return [];
|
|
58
|
+
return pg.parseParts(fileAbs, canonicalNames, withStyledResolver(opts));
|
|
59
|
+
};
|
|
60
|
+
exports.parseParts = parseParts;
|
|
61
|
+
const resolveCss = (tree, opts) => {
|
|
62
|
+
const pg = getPlayground(getFramework(opts));
|
|
63
|
+
if (!pg.resolveCss)
|
|
64
|
+
return { css: "", unresolved: [] };
|
|
65
|
+
return pg.resolveCss(tree);
|
|
66
|
+
};
|
|
67
|
+
exports.resolveCss = resolveCss;
|
|
68
|
+
const classTokensOf = (tree, out = new Set()) => {
|
|
69
|
+
if (!tree)
|
|
70
|
+
return out;
|
|
71
|
+
if (tree.className)
|
|
72
|
+
for (const token of String(tree.className).split(/\s+/))
|
|
73
|
+
if (token)
|
|
74
|
+
out.add(token);
|
|
75
|
+
for (const child of tree.children || [])
|
|
76
|
+
classTokensOf(child, out);
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
const render = (tree, opts) => {
|
|
80
|
+
const pg = getPlayground(getFramework(opts));
|
|
81
|
+
if (!pg.render)
|
|
82
|
+
return { tree: null, available: false };
|
|
83
|
+
const stylesheet = (0, style_js_1.buildStylesheet)([...classTokensOf(tree)], opts);
|
|
84
|
+
return pg.render(tree, { stylesheet });
|
|
85
|
+
};
|
|
86
|
+
exports.render = render;
|
|
87
|
+
const rawClassTokens = (tree) => {
|
|
88
|
+
const out = new Set();
|
|
89
|
+
const visit = (n) => {
|
|
90
|
+
if (!n)
|
|
91
|
+
return;
|
|
92
|
+
if (typeof n.className === "string")
|
|
93
|
+
for (const token of n.className.split(/\s+/))
|
|
94
|
+
if (token)
|
|
95
|
+
out.add(token);
|
|
96
|
+
for (const child of n.children || [])
|
|
97
|
+
visit(child);
|
|
98
|
+
};
|
|
99
|
+
visit(tree);
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
exports.rawClassTokens = rawClassTokens;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const setLiveSource: (fileAbs: any, text: any) => void;
|
|
2
|
+
declare const parseElements: (fileAbs: any, canonicalNames: any, opts: any) => any[];
|
|
3
|
+
declare const parseParts: (fileAbs: any, canonicalNames: any, opts: any) => any[];
|
|
4
|
+
declare const parseComponents: (fileAbs: any, canonicalNames: any, opts: any) => any[];
|
|
5
|
+
declare const render: (tree: any, extra: any) => {
|
|
6
|
+
tree: any;
|
|
7
|
+
available: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const resolveCss: (css: any, unresolved: any, ctx: any) => {
|
|
10
|
+
css: any;
|
|
11
|
+
unresolved: any;
|
|
12
|
+
};
|
|
13
|
+
declare const available: () => boolean;
|
|
14
|
+
export { parseComponents, parseElements, parseParts, render, resolveCss, setLiveSource, available };
|