@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,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.available = exports.resolveClasses = void 0;
|
|
4
|
+
const resolveClasses = (classes) => {
|
|
5
|
+
return { css: {}, unresolved: [...(classes || [])] };
|
|
6
|
+
};
|
|
7
|
+
exports.resolveClasses = resolveClasses;
|
|
8
|
+
const available = () => false;
|
|
9
|
+
exports.available = available;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const getPlayground: (styleSystem: any) => any;
|
|
2
|
+
declare const getStyleSystem: (opts: any) => string;
|
|
3
|
+
declare const normalizeStyles: (className: any, styleObj: any, opts: any, label: any) => Promise<{
|
|
4
|
+
css: any;
|
|
5
|
+
unresolved: any;
|
|
6
|
+
}>;
|
|
7
|
+
declare const normalizeStylesSync: (className: any, styleObj: any, opts: any, label: any) => {
|
|
8
|
+
css: any;
|
|
9
|
+
unresolved: any;
|
|
10
|
+
};
|
|
11
|
+
declare const buildStylesheet: (classes: any, opts: any) => string;
|
|
12
|
+
declare const whenReady: (opts: any) => Promise<void>;
|
|
13
|
+
export { normalizeStyles, normalizeStylesSync, getStyleSystem, getPlayground, buildStylesheet, whenReady };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whenReady = exports.buildStylesheet = exports.getPlayground = exports.getStyleSystem = exports.normalizeStylesSync = exports.normalizeStyles = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
const style_js_1 = require("../normalize/style.js");
|
|
7
|
+
// Style playgrounds pull in tailwind/scss compilers: load on demand.
|
|
8
|
+
const lazyRequire = (0, node_module_1.createRequire)(__filename);
|
|
9
|
+
const PLAYGROUNDS = {
|
|
10
|
+
tailwind: () => lazyRequire("./tailwind.js"),
|
|
11
|
+
scss: () => lazyRequire("./scss.js"),
|
|
12
|
+
"styled-components": () => lazyRequire("./styled-components.js"),
|
|
13
|
+
styled: () => lazyRequire("./styled-components.js"),
|
|
14
|
+
};
|
|
15
|
+
const cache = new Map();
|
|
16
|
+
const getPlayground = (styleSystem) => {
|
|
17
|
+
const key = String(styleSystem || "tailwind").toLowerCase();
|
|
18
|
+
if (!cache.has(key)) {
|
|
19
|
+
const loader = PLAYGROUNDS[key] || PLAYGROUNDS.tailwind;
|
|
20
|
+
cache.set(key, loader());
|
|
21
|
+
}
|
|
22
|
+
return cache.get(key);
|
|
23
|
+
};
|
|
24
|
+
exports.getPlayground = getPlayground;
|
|
25
|
+
const getStyleSystem = (opts) => (0, config_js_1.normalizeOptions)(opts).styleSystem;
|
|
26
|
+
exports.getStyleSystem = getStyleSystem;
|
|
27
|
+
const normalizeStyles = async (className, styleObj, opts, label) => {
|
|
28
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (typeof className === "string" && className.trim()) {
|
|
31
|
+
const tw = await pg.resolveClasses(className.trim().split(/\s+/));
|
|
32
|
+
parts.push(tw);
|
|
33
|
+
}
|
|
34
|
+
if (styleObj && typeof styleObj === "object") {
|
|
35
|
+
parts.push((0, style_js_1.cssTextToStyles)((0, style_js_1.styleObjectToText)(styleObj)));
|
|
36
|
+
}
|
|
37
|
+
if (parts.length === 0)
|
|
38
|
+
return { css: {}, unresolved: [] };
|
|
39
|
+
const merged = parts.reduce(style_js_1.mergeProfiles, { css: {}, unresolved: [] });
|
|
40
|
+
return { css: merged.css, unresolved: merged.unresolved };
|
|
41
|
+
};
|
|
42
|
+
exports.normalizeStyles = normalizeStyles;
|
|
43
|
+
const normalizeStylesSync = (className, styleObj, opts, label) => {
|
|
44
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
45
|
+
const parts = [];
|
|
46
|
+
if (typeof className === "string" && className.trim()) {
|
|
47
|
+
const tw = pg.resolveClassesSync(className.trim().split(/\s+/));
|
|
48
|
+
parts.push(tw);
|
|
49
|
+
}
|
|
50
|
+
if (styleObj && typeof styleObj === "object") {
|
|
51
|
+
parts.push((0, style_js_1.cssTextToStyles)((0, style_js_1.styleObjectToText)(styleObj)));
|
|
52
|
+
}
|
|
53
|
+
if (parts.length === 0)
|
|
54
|
+
return { css: {}, unresolved: [] };
|
|
55
|
+
const merged = parts.reduce(style_js_1.mergeProfiles, { css: {}, unresolved: [] });
|
|
56
|
+
return { css: merged.css, unresolved: merged.unresolved };
|
|
57
|
+
};
|
|
58
|
+
exports.normalizeStylesSync = normalizeStylesSync;
|
|
59
|
+
const escapeClass = (cls) => cls.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
|
|
60
|
+
const buildStylesheet = (classes, opts) => {
|
|
61
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
62
|
+
if (!pg.classStyles)
|
|
63
|
+
return "";
|
|
64
|
+
const { byClass } = pg.classStyles(classes);
|
|
65
|
+
const rules = [];
|
|
66
|
+
for (const [cls, decls] of Object.entries(byClass)) {
|
|
67
|
+
if (cls.includes(":"))
|
|
68
|
+
continue;
|
|
69
|
+
const body = Object.entries(decls)
|
|
70
|
+
.map(([prop, values]) => `${prop}:${values[values.length - 1]}`)
|
|
71
|
+
.join(";");
|
|
72
|
+
rules.push(`.${escapeClass(cls)}{${body}}`);
|
|
73
|
+
}
|
|
74
|
+
return rules.join("\n");
|
|
75
|
+
};
|
|
76
|
+
exports.buildStylesheet = buildStylesheet;
|
|
77
|
+
const whenReady = async (opts) => {
|
|
78
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
79
|
+
if (pg.ready)
|
|
80
|
+
await pg.ready;
|
|
81
|
+
};
|
|
82
|
+
exports.whenReady = whenReady;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const getPlayground: (styleSystem: any) => any;
|
|
2
|
+
declare const getStyleSystem: (opts: any) => string;
|
|
3
|
+
declare const normalizeStyles: (className: any, styleObj: any, opts: any, label: any) => Promise<{
|
|
4
|
+
css: any;
|
|
5
|
+
unresolved: any;
|
|
6
|
+
}>;
|
|
7
|
+
declare const normalizeStylesSync: (className: any, styleObj: any, opts: any, label: any) => {
|
|
8
|
+
css: any;
|
|
9
|
+
unresolved: any;
|
|
10
|
+
};
|
|
11
|
+
declare const buildStylesheet: (classes: any, opts: any) => string;
|
|
12
|
+
declare const whenReady: (opts: any) => Promise<void>;
|
|
13
|
+
export { normalizeStyles, normalizeStylesSync, getStyleSystem, getPlayground, buildStylesheet, whenReady };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whenReady = exports.buildStylesheet = exports.getPlayground = exports.getStyleSystem = exports.normalizeStylesSync = exports.normalizeStyles = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
const style_js_1 = require("../normalize/style.js");
|
|
7
|
+
// Style playgrounds pull in tailwind/scss compilers: load on demand.
|
|
8
|
+
const lazyRequire = (0, node_module_1.createRequire)(__filename);
|
|
9
|
+
const PLAYGROUNDS = {
|
|
10
|
+
tailwind: () => lazyRequire("./tailwind.js"),
|
|
11
|
+
scss: () => lazyRequire("./scss.js"),
|
|
12
|
+
"styled-components": () => lazyRequire("./styled-components.js"),
|
|
13
|
+
styled: () => lazyRequire("./styled-components.js"),
|
|
14
|
+
};
|
|
15
|
+
const cache = new Map();
|
|
16
|
+
const getPlayground = (styleSystem) => {
|
|
17
|
+
const key = String(styleSystem || "tailwind").toLowerCase();
|
|
18
|
+
if (!cache.has(key)) {
|
|
19
|
+
const loader = PLAYGROUNDS[key] || PLAYGROUNDS.tailwind;
|
|
20
|
+
cache.set(key, loader());
|
|
21
|
+
}
|
|
22
|
+
return cache.get(key);
|
|
23
|
+
};
|
|
24
|
+
exports.getPlayground = getPlayground;
|
|
25
|
+
const getStyleSystem = (opts) => (0, config_js_1.normalizeOptions)(opts).styleSystem;
|
|
26
|
+
exports.getStyleSystem = getStyleSystem;
|
|
27
|
+
const normalizeStyles = async (className, styleObj, opts, label) => {
|
|
28
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (typeof className === "string" && className.trim()) {
|
|
31
|
+
const tw = await pg.resolveClasses(className.trim().split(/\s+/));
|
|
32
|
+
parts.push(tw);
|
|
33
|
+
}
|
|
34
|
+
if (styleObj && typeof styleObj === "object") {
|
|
35
|
+
parts.push((0, style_js_1.cssTextToStyles)((0, style_js_1.styleObjectToText)(styleObj)));
|
|
36
|
+
}
|
|
37
|
+
if (parts.length === 0)
|
|
38
|
+
return { css: {}, unresolved: [] };
|
|
39
|
+
const merged = parts.reduce(style_js_1.mergeProfiles, { css: {}, unresolved: [] });
|
|
40
|
+
return { css: merged.css, unresolved: merged.unresolved };
|
|
41
|
+
};
|
|
42
|
+
exports.normalizeStyles = normalizeStyles;
|
|
43
|
+
const normalizeStylesSync = (className, styleObj, opts, label) => {
|
|
44
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
45
|
+
const parts = [];
|
|
46
|
+
if (typeof className === "string" && className.trim()) {
|
|
47
|
+
const tw = pg.resolveClassesSync(className.trim().split(/\s+/));
|
|
48
|
+
parts.push(tw);
|
|
49
|
+
}
|
|
50
|
+
if (styleObj && typeof styleObj === "object") {
|
|
51
|
+
parts.push((0, style_js_1.cssTextToStyles)((0, style_js_1.styleObjectToText)(styleObj)));
|
|
52
|
+
}
|
|
53
|
+
if (parts.length === 0)
|
|
54
|
+
return { css: {}, unresolved: [] };
|
|
55
|
+
const merged = parts.reduce(style_js_1.mergeProfiles, { css: {}, unresolved: [] });
|
|
56
|
+
return { css: merged.css, unresolved: merged.unresolved };
|
|
57
|
+
};
|
|
58
|
+
exports.normalizeStylesSync = normalizeStylesSync;
|
|
59
|
+
const escapeClass = (cls) => cls.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
|
|
60
|
+
const buildStylesheet = (classes, opts) => {
|
|
61
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
62
|
+
if (!pg.classStyles)
|
|
63
|
+
return "";
|
|
64
|
+
const { byClass } = pg.classStyles(classes);
|
|
65
|
+
const rules = [];
|
|
66
|
+
for (const [cls, decls] of Object.entries(byClass)) {
|
|
67
|
+
if (cls.includes(":"))
|
|
68
|
+
continue;
|
|
69
|
+
const body = Object.entries(decls)
|
|
70
|
+
.map(([prop, values]) => `${prop}:${values[values.length - 1]}`)
|
|
71
|
+
.join(";");
|
|
72
|
+
rules.push(`.${escapeClass(cls)}{${body}}`);
|
|
73
|
+
}
|
|
74
|
+
return rules.join("\n");
|
|
75
|
+
};
|
|
76
|
+
exports.buildStylesheet = buildStylesheet;
|
|
77
|
+
const whenReady = async (opts) => {
|
|
78
|
+
const pg = getPlayground(getStyleSystem(opts));
|
|
79
|
+
if (pg.ready)
|
|
80
|
+
await pg.ready;
|
|
81
|
+
};
|
|
82
|
+
exports.whenReady = whenReady;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.available = exports.resolveClasses = exports.styledDeclarations = void 0;
|
|
27
|
+
const ts = __importStar(require("typescript"));
|
|
28
|
+
const MAX_LITERAL_DEPTH = 4;
|
|
29
|
+
const MAX_LITERAL_COUNT = 12;
|
|
30
|
+
const stringLiterals = (node, out, depth = 0) => {
|
|
31
|
+
if (!node || depth > MAX_LITERAL_DEPTH || out.length >= MAX_LITERAL_COUNT)
|
|
32
|
+
return;
|
|
33
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
34
|
+
out.push(node.text);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (ts.isNumericLiteral(node)) {
|
|
38
|
+
out.push(node.text);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
42
|
+
stringLiterals(node.expression, out, depth + 1);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (ts.isTemplateExpression(node)) {
|
|
46
|
+
if (node.head.text)
|
|
47
|
+
out.push(node.head.text);
|
|
48
|
+
for (const span of node.templateSpans) {
|
|
49
|
+
if (span.literal.text)
|
|
50
|
+
out.push(span.literal.text);
|
|
51
|
+
stringLiterals(span.expression, out, depth + 1);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (ts.isCallExpression(node)) {
|
|
56
|
+
for (const arg of node.arguments)
|
|
57
|
+
stringLiterals(arg, out, depth + 1);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (ts.isConditionalExpression(node)) {
|
|
61
|
+
stringLiterals(node.whenTrue, out, depth + 1);
|
|
62
|
+
stringLiterals(node.whenFalse, out, depth + 1);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
66
|
+
stringLiterals(node.left, out, depth + 1);
|
|
67
|
+
stringLiterals(node.right, out, depth + 1);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const localDeclarations = (sf) => {
|
|
72
|
+
const map = new Map();
|
|
73
|
+
const visit = (node) => {
|
|
74
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && !map.has(node.name.text)) {
|
|
75
|
+
map.set(node.name.text, node.initializer);
|
|
76
|
+
}
|
|
77
|
+
ts.forEachChild(node, visit);
|
|
78
|
+
};
|
|
79
|
+
visit(sf);
|
|
80
|
+
return map;
|
|
81
|
+
};
|
|
82
|
+
const literalOf = (expr, decls, depth = 0) => {
|
|
83
|
+
if (!expr || depth > 3)
|
|
84
|
+
return null;
|
|
85
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr))
|
|
86
|
+
return expr.text;
|
|
87
|
+
if (ts.isNumericLiteral(expr))
|
|
88
|
+
return expr.text;
|
|
89
|
+
if (ts.isParenthesizedExpression(expr))
|
|
90
|
+
return literalOf(expr.expression, decls, depth + 1);
|
|
91
|
+
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
92
|
+
let body = expr.body;
|
|
93
|
+
if (ts.isBlock(body)) {
|
|
94
|
+
const ret = body.statements.find((s) => ts.isReturnStatement(s) && s.expression);
|
|
95
|
+
if (!ret)
|
|
96
|
+
return null;
|
|
97
|
+
body = ret.expression;
|
|
98
|
+
}
|
|
99
|
+
return literalOf(body, decls, depth + 1);
|
|
100
|
+
}
|
|
101
|
+
if (ts.isIdentifier(expr)) {
|
|
102
|
+
const decl = decls.get(expr.text);
|
|
103
|
+
if (!decl)
|
|
104
|
+
return null;
|
|
105
|
+
return literalOf(decl, decls, depth + 1);
|
|
106
|
+
}
|
|
107
|
+
if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {
|
|
108
|
+
const decl = decls.get(expr.expression.text);
|
|
109
|
+
if (!decl)
|
|
110
|
+
return null;
|
|
111
|
+
return literalOf(decl, decls, depth + 1);
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
const templateToCss = (template, decls, sf) => {
|
|
116
|
+
const unresolved = [];
|
|
117
|
+
if (ts.isNoSubstitutionTemplateLiteral(template))
|
|
118
|
+
return { cssText: template.text, unresolved };
|
|
119
|
+
if (!ts.isTemplateExpression(template))
|
|
120
|
+
return { cssText: "", unresolved };
|
|
121
|
+
let text = template.head.text;
|
|
122
|
+
for (const span of template.templateSpans) {
|
|
123
|
+
const value = literalOf(span.expression, decls);
|
|
124
|
+
if (value !== null) {
|
|
125
|
+
text += value;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const strs = [];
|
|
129
|
+
stringLiterals(span.expression, strs);
|
|
130
|
+
if (strs.length > 0)
|
|
131
|
+
text += strs.join(" ");
|
|
132
|
+
else
|
|
133
|
+
unresolved.push(span.expression.getText(sf));
|
|
134
|
+
}
|
|
135
|
+
text += span.literal.text;
|
|
136
|
+
}
|
|
137
|
+
return { cssText: text, unresolved };
|
|
138
|
+
};
|
|
139
|
+
const styledTagInfo = (tag) => {
|
|
140
|
+
if (ts.isPropertyAccessExpression(tag) && ts.isIdentifier(tag.expression) && tag.expression.text === "styled" && ts.isIdentifier(tag.name)) {
|
|
141
|
+
return { baseTag: tag.name.text, componentRef: null };
|
|
142
|
+
}
|
|
143
|
+
if (ts.isCallExpression(tag) && ts.isIdentifier(tag.expression) && tag.expression.text === "styled" && tag.arguments.length === 1 && ts.isIdentifier(tag.arguments[0])) {
|
|
144
|
+
return { baseTag: null, componentRef: tag.arguments[0].text };
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
};
|
|
148
|
+
const styledDeclarations = (sf) => {
|
|
149
|
+
const out = new Map();
|
|
150
|
+
const decls = localDeclarations(sf);
|
|
151
|
+
// Where each imported name comes from, so `styled(Image)` can be mapped to the
|
|
152
|
+
// HTML the external component renders (next/image → img).
|
|
153
|
+
const importSpec = new Map();
|
|
154
|
+
for (const stmt of sf.statements) {
|
|
155
|
+
if (!ts.isImportDeclaration(stmt) || !stmt.importClause || !ts.isStringLiteral(stmt.moduleSpecifier))
|
|
156
|
+
continue;
|
|
157
|
+
const spec = stmt.moduleSpecifier.text;
|
|
158
|
+
const clause = stmt.importClause;
|
|
159
|
+
if (clause.name)
|
|
160
|
+
importSpec.set(clause.name.text, spec);
|
|
161
|
+
const named = clause.namedBindings;
|
|
162
|
+
if (named && ts.isNamedImports(named))
|
|
163
|
+
for (const el of named.elements)
|
|
164
|
+
importSpec.set(el.name.text, spec);
|
|
165
|
+
}
|
|
166
|
+
const visit = (node) => {
|
|
167
|
+
if (ts.isVariableStatement(node)) {
|
|
168
|
+
for (const d of node.declarationList.declarations) {
|
|
169
|
+
if (!ts.isIdentifier(d.name) || !d.initializer || !ts.isTaggedTemplateExpression(d.initializer))
|
|
170
|
+
continue;
|
|
171
|
+
const info = styledTagInfo(d.initializer.tag);
|
|
172
|
+
if (!info)
|
|
173
|
+
continue;
|
|
174
|
+
const { cssText, unresolved } = templateToCss(d.initializer.template, decls, sf);
|
|
175
|
+
const externalSpec = info.componentRef ? importSpec.get(info.componentRef) ?? null : null;
|
|
176
|
+
out.set(d.name.text, { baseTag: info.baseTag, componentRef: info.componentRef, externalSpec, cssText, unresolved });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
ts.forEachChild(node, visit);
|
|
180
|
+
};
|
|
181
|
+
visit(sf);
|
|
182
|
+
return out;
|
|
183
|
+
};
|
|
184
|
+
exports.styledDeclarations = styledDeclarations;
|
|
185
|
+
const resolveClasses = (classes) => {
|
|
186
|
+
return { css: {}, unresolved: [...(classes || [])] };
|
|
187
|
+
};
|
|
188
|
+
exports.resolveClasses = resolveClasses;
|
|
189
|
+
const available = () => true;
|
|
190
|
+
exports.available = available;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const ready: Promise<void>;
|
|
2
|
+
declare const resolveClasses: (classes: any) => Promise<{
|
|
3
|
+
css: any;
|
|
4
|
+
unresolved: any[];
|
|
5
|
+
}>;
|
|
6
|
+
declare const classStyles: (classes: any) => {
|
|
7
|
+
byClass: any;
|
|
8
|
+
unresolved: any[];
|
|
9
|
+
};
|
|
10
|
+
declare const resolveClassesSync: (classes: any) => {
|
|
11
|
+
css: {};
|
|
12
|
+
unresolved: any[];
|
|
13
|
+
};
|
|
14
|
+
declare const available: () => boolean;
|
|
15
|
+
export { resolveClasses, resolveClassesSync, classStyles, ready, available };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.available = exports.ready = exports.classStyles = exports.resolveClassesSync = exports.resolveClasses = void 0;
|
|
27
|
+
const fs = __importStar(require("node:fs"));
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
29
|
+
const node_module_1 = require("node:module");
|
|
30
|
+
// tailwindcss is optional and heavy: resolve/load it lazily.
|
|
31
|
+
const lazyRequire = (0, node_module_1.createRequire)(__filename);
|
|
32
|
+
let compiled = null;
|
|
33
|
+
let failed = false;
|
|
34
|
+
let designSystem = null;
|
|
35
|
+
const ready = Promise.resolve()
|
|
36
|
+
.then(() => lazyRequire("tailwindcss").__unstable__loadDesignSystem("@import \"tailwindcss\";", {
|
|
37
|
+
from: path.join(__dirname, "probe.css"),
|
|
38
|
+
loadStylesheet: (id, base) => {
|
|
39
|
+
if (id === "tailwindcss") {
|
|
40
|
+
const cssPath = lazyRequire.resolve("tailwindcss/index.css");
|
|
41
|
+
return { path: cssPath, base: path.dirname(cssPath), content: fs.readFileSync(cssPath, "utf8") };
|
|
42
|
+
}
|
|
43
|
+
return { path: id, base: base || "", content: "" };
|
|
44
|
+
},
|
|
45
|
+
}))
|
|
46
|
+
.then((ds) => {
|
|
47
|
+
designSystem = ds;
|
|
48
|
+
})
|
|
49
|
+
.catch(() => { });
|
|
50
|
+
exports.ready = ready;
|
|
51
|
+
const compileOnce = async () => {
|
|
52
|
+
if (compiled)
|
|
53
|
+
return compiled;
|
|
54
|
+
if (failed)
|
|
55
|
+
return null;
|
|
56
|
+
try {
|
|
57
|
+
const { compile } = lazyRequire("tailwindcss");
|
|
58
|
+
const cssPath = lazyRequire.resolve("tailwindcss/index.css");
|
|
59
|
+
compiled = await compile("@import \"tailwindcss\";", {
|
|
60
|
+
from: path.join(__dirname, "probe.css"),
|
|
61
|
+
loadStylesheet: async (id, base) => {
|
|
62
|
+
if (id === "tailwindcss") {
|
|
63
|
+
return { path: cssPath, base: path.dirname(cssPath), content: fs.readFileSync(cssPath, "utf8") };
|
|
64
|
+
}
|
|
65
|
+
return { path: id, base: base || "", content: "" };
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return compiled;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
failed = true;
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const extractClass = (sel) => {
|
|
76
|
+
if (sel.startsWith("."))
|
|
77
|
+
sel = sel.slice(1);
|
|
78
|
+
let name = "";
|
|
79
|
+
for (let i = 0; i < sel.length; i++) {
|
|
80
|
+
const ch = sel[i];
|
|
81
|
+
if (ch === "\\") {
|
|
82
|
+
name += sel[i + 1] ?? "";
|
|
83
|
+
i++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ch === ":" || ch === " " || ch === "," || ch === "[" || ch === "{" || ch === ".")
|
|
87
|
+
break;
|
|
88
|
+
name += ch;
|
|
89
|
+
}
|
|
90
|
+
return name;
|
|
91
|
+
};
|
|
92
|
+
const parseCss = (css) => {
|
|
93
|
+
const vars = new Map();
|
|
94
|
+
for (const m of css.matchAll(/--([a-z0-9-]+)\s*:\s*([^;{}]+);/g))
|
|
95
|
+
vars.set(m[1], m[2].trim());
|
|
96
|
+
const map = {};
|
|
97
|
+
const layerIdx = css.indexOf("@layer utilities");
|
|
98
|
+
const layer = layerIdx >= 0 ? css.slice(layerIdx) : css;
|
|
99
|
+
const ruleRe = /([.#][^{]+)\{([^{}]*)\}/g;
|
|
100
|
+
let m;
|
|
101
|
+
while ((m = ruleRe.exec(layer))) {
|
|
102
|
+
const sel = m[1].trim();
|
|
103
|
+
if (!sel.startsWith("."))
|
|
104
|
+
continue;
|
|
105
|
+
const cls = extractClass(sel);
|
|
106
|
+
if (!cls)
|
|
107
|
+
continue;
|
|
108
|
+
const styles = {};
|
|
109
|
+
for (const d of m[2].split(";")) {
|
|
110
|
+
const idx = d.indexOf(":");
|
|
111
|
+
if (idx < 0)
|
|
112
|
+
continue;
|
|
113
|
+
const prop = d.slice(0, idx).trim().toLowerCase();
|
|
114
|
+
let value = d.slice(idx + 1).trim();
|
|
115
|
+
if (!prop || !value)
|
|
116
|
+
continue;
|
|
117
|
+
if (value.startsWith("var(")) {
|
|
118
|
+
const vm = value.match(/^var\(\s*--([a-z0-9-]+)/);
|
|
119
|
+
if (vm && vars.has(vm[1]))
|
|
120
|
+
value = vars.get(vm[1]);
|
|
121
|
+
}
|
|
122
|
+
if (!Object.prototype.hasOwnProperty.call(styles, prop))
|
|
123
|
+
styles[prop] = [];
|
|
124
|
+
if (!styles[prop].includes(value))
|
|
125
|
+
styles[prop].push(value);
|
|
126
|
+
}
|
|
127
|
+
const pairs = Object.entries(styles).map(([prop, values]) => [prop, values.join(" ")]);
|
|
128
|
+
if (pairs.length > 0)
|
|
129
|
+
map[cls] = pairs;
|
|
130
|
+
}
|
|
131
|
+
return map;
|
|
132
|
+
};
|
|
133
|
+
const resolveClasses = async (classes) => {
|
|
134
|
+
const list = [...new Set(classes || [])];
|
|
135
|
+
const out = await compileOnce();
|
|
136
|
+
if (!out)
|
|
137
|
+
return { css: {}, unresolved: list };
|
|
138
|
+
const cssText = await out.build(list);
|
|
139
|
+
const map = parseCss(cssText);
|
|
140
|
+
const css = {};
|
|
141
|
+
const unresolved = [];
|
|
142
|
+
for (const cls of list) {
|
|
143
|
+
const pairs = map[cls];
|
|
144
|
+
if (pairs && pairs.length > 0) {
|
|
145
|
+
for (const [prop, value] of pairs) {
|
|
146
|
+
css[prop] = css[prop] || [];
|
|
147
|
+
if (!css[prop].includes(value))
|
|
148
|
+
css[prop].push(value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
unresolved.push(cls);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { css, unresolved };
|
|
156
|
+
};
|
|
157
|
+
exports.resolveClasses = resolveClasses;
|
|
158
|
+
const parseBlock = (block, vars, styles) => {
|
|
159
|
+
const ruleRe = /([.#][^{]+)\{([^{}]*)\}/g;
|
|
160
|
+
let m;
|
|
161
|
+
while ((m = ruleRe.exec(block))) {
|
|
162
|
+
const sel = m[1].trim();
|
|
163
|
+
if (!sel.startsWith("."))
|
|
164
|
+
continue;
|
|
165
|
+
const cls = extractClass(sel);
|
|
166
|
+
if (!cls)
|
|
167
|
+
continue;
|
|
168
|
+
for (const d of m[2].split(";")) {
|
|
169
|
+
const idx = d.indexOf(":");
|
|
170
|
+
if (idx < 0)
|
|
171
|
+
continue;
|
|
172
|
+
const prop = d.slice(0, idx).trim().toLowerCase();
|
|
173
|
+
let value = d.slice(idx + 1).trim();
|
|
174
|
+
if (!prop || !value)
|
|
175
|
+
continue;
|
|
176
|
+
if (value.startsWith("var(")) {
|
|
177
|
+
const vm = value.match(/^var\(\s*--([a-z0-9-]+)/);
|
|
178
|
+
if (vm && vars.has(vm[1]))
|
|
179
|
+
value = vars.get(vm[1]);
|
|
180
|
+
}
|
|
181
|
+
if (!Object.prototype.hasOwnProperty.call(styles, cls))
|
|
182
|
+
styles[cls] = {};
|
|
183
|
+
if (!Object.prototype.hasOwnProperty.call(styles[cls], prop))
|
|
184
|
+
styles[cls][prop] = [];
|
|
185
|
+
if (!styles[cls][prop].includes(value))
|
|
186
|
+
styles[cls][prop].push(value);
|
|
187
|
+
}
|
|
188
|
+
const inner = m[2];
|
|
189
|
+
if (inner.includes("{"))
|
|
190
|
+
parseBlock(inner, vars, styles);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const substituteVars = (value, depth = 0) => value.replace(/var\(--([a-z0-9-]+)\)/g, (match, name) => {
|
|
194
|
+
if (depth >= 4)
|
|
195
|
+
return match;
|
|
196
|
+
const resolved = designSystem.theme.resolve(null, [`--${name}`]);
|
|
197
|
+
return resolved && String(resolved) !== match ? substituteVars(String(resolved), depth + 1) : match;
|
|
198
|
+
});
|
|
199
|
+
// Tokens the design system cannot parse (e.g. a `$preset` prop name leaked
|
|
200
|
+
// from a template literal) make it throw an uncaught DOMException inside its
|
|
201
|
+
// own promise chain — the sync catch below cannot see it, and the design
|
|
202
|
+
// system is left wedged: every later candidatesToCss call hangs forever.
|
|
203
|
+
// So such tokens must be filtered out BEFORE the call, not caught after.
|
|
204
|
+
const cssSafeToken = (t) => /^[a-zA-Z0-9_&[\]:.\-*]+$/.test(t) && !t.includes("$") && !t.includes("@");
|
|
205
|
+
const classStyles = (classes) => {
|
|
206
|
+
const list = [...new Set(classes || [])];
|
|
207
|
+
if (!designSystem)
|
|
208
|
+
return { byClass: {}, unresolved: list };
|
|
209
|
+
const unsafe = list.filter((t) => !cssSafeToken(t));
|
|
210
|
+
const list2 = list.filter(cssSafeToken);
|
|
211
|
+
if (list2.length === 0)
|
|
212
|
+
return { byClass: {}, unresolved: list };
|
|
213
|
+
let out;
|
|
214
|
+
try {
|
|
215
|
+
out = designSystem.candidatesToCss(list2);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return { byClass: {}, unresolved: list };
|
|
219
|
+
}
|
|
220
|
+
const vars = new Map();
|
|
221
|
+
for (const m of String(out).matchAll(/--([a-z0-9-]+)\s*:\s*([^;{}]+);/g))
|
|
222
|
+
vars.set(m[1], m[2].trim());
|
|
223
|
+
const styles = {};
|
|
224
|
+
for (const b of out)
|
|
225
|
+
if (typeof b === "string")
|
|
226
|
+
parseBlock(b, vars, styles);
|
|
227
|
+
const byClass = {};
|
|
228
|
+
const unresolved = [];
|
|
229
|
+
for (const cls of list) {
|
|
230
|
+
const decls = styles[cls];
|
|
231
|
+
if (decls && Object.keys(decls).length > 0) {
|
|
232
|
+
byClass[cls] = Object.fromEntries(Object.entries(decls).map(([prop, values]) => [prop, values.map((value) => substituteVars(value))]));
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
unresolved.push(cls);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { byClass, unresolved };
|
|
239
|
+
};
|
|
240
|
+
exports.classStyles = classStyles;
|
|
241
|
+
const resolveClassesSync = (classes) => {
|
|
242
|
+
const { byClass, unresolved } = classStyles(classes);
|
|
243
|
+
const css = {};
|
|
244
|
+
for (const decls of Object.values(byClass)) {
|
|
245
|
+
for (const [prop, values] of Object.entries(decls)) {
|
|
246
|
+
css[prop] = css[prop] || [];
|
|
247
|
+
const joined = values.join(" ");
|
|
248
|
+
if (!css[prop].includes(joined))
|
|
249
|
+
css[prop].push(joined);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { css, unresolved };
|
|
253
|
+
};
|
|
254
|
+
exports.resolveClassesSync = resolveClassesSync;
|
|
255
|
+
const available = () => true;
|
|
256
|
+
exports.available = available;
|