@una-ui/extractor-vue-script-edge 0.64.0-29260635.86853d3 → 0.64.0-29262088.1cb0816
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/dist/index.mjs +81 -34
- package/package.json +10 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import traverseDefault from '@babel/traverse';
|
|
1
2
|
import { defaultSplitRE } from '@unocss/core';
|
|
3
|
+
import { parse } from '@vue/compiler-sfc';
|
|
4
|
+
import { parseModule } from 'magicast';
|
|
5
|
+
import { parsePath } from 'ufo';
|
|
2
6
|
|
|
7
|
+
const traverse = "default" in traverseDefault ? traverseDefault.default : traverseDefault;
|
|
3
8
|
function generateSelectors(prefix, values) {
|
|
4
9
|
prefix = prefix.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
5
10
|
return values.filter((v) => Boolean(v) && v !== ":").map((v) => `[${prefix}~="${v}"]`);
|
|
@@ -8,50 +13,92 @@ function normalizePrefixes(prefixes) {
|
|
|
8
13
|
const camelCasePrefixes = prefixes.map((prefix) => prefix.replace(/-([a-z])/g, (_, c) => c.toUpperCase()));
|
|
9
14
|
return [.../* @__PURE__ */ new Set([...prefixes, ...camelCasePrefixes])];
|
|
10
15
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
function getLiteralValue(node) {
|
|
17
|
+
if (node.type === "ConditionalExpression") {
|
|
18
|
+
return [node.consequent, node.alternate].map(getLiteralValue);
|
|
19
|
+
}
|
|
20
|
+
if (node.type === "StringLiteral") {
|
|
21
|
+
return node.value;
|
|
22
|
+
}
|
|
23
|
+
if (node.type === "TemplateLiteral") {
|
|
24
|
+
if (node.expressions.length > 0) {
|
|
25
|
+
return void 0;
|
|
21
26
|
}
|
|
27
|
+
return node.quasis.map((q) => q.value.cooked).join("");
|
|
22
28
|
}
|
|
23
|
-
|
|
29
|
+
if (node.type === "ObjectExpression") {
|
|
30
|
+
return getObjectLiteralValue(node);
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
function getObjectLiteralValue(node) {
|
|
35
|
+
return Object.fromEntries(
|
|
36
|
+
node.properties.filter((prop) => prop.type === "ObjectProperty").filter((prop) => prop.key.type === "Identifier").map((prop) => {
|
|
37
|
+
const key = prop.key.name;
|
|
38
|
+
return [key, getLiteralValue(prop.value)];
|
|
39
|
+
})
|
|
40
|
+
);
|
|
24
41
|
}
|
|
25
|
-
function
|
|
42
|
+
function discoverVariants(node, prefixes) {
|
|
26
43
|
const result = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
traverse(node, {
|
|
45
|
+
noScope: true,
|
|
46
|
+
// scope doesn't work for some reason.
|
|
47
|
+
enter({ node: node2 }) {
|
|
48
|
+
if (node2.type === "ObjectExpression") {
|
|
49
|
+
const object = getObjectLiteralValue(node2);
|
|
50
|
+
for (let [key, value] of Object.entries(object)) {
|
|
51
|
+
if (prefixes.includes(key) && value) {
|
|
52
|
+
if (!Array.isArray(value)) {
|
|
53
|
+
value = [value];
|
|
54
|
+
}
|
|
55
|
+
for (let v of value) {
|
|
56
|
+
if (typeof v === "object" && v !== null && "default" in v) {
|
|
57
|
+
v = v.default;
|
|
58
|
+
}
|
|
59
|
+
if (typeof v !== "string") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
result.push([key, v]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (node2.type === "AssignmentPattern") {
|
|
68
|
+
const { left, right } = node2;
|
|
69
|
+
if (left.type === "Identifier" && right.type === "StringLiteral") {
|
|
70
|
+
const prefix = left.name;
|
|
71
|
+
const value = right.value;
|
|
72
|
+
if (prefixes.includes(prefix)) {
|
|
73
|
+
result.push([prefix, value]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
42
77
|
}
|
|
43
|
-
}
|
|
44
|
-
return result
|
|
78
|
+
});
|
|
79
|
+
return result.flatMap(([key, v]) => {
|
|
80
|
+
const values = v.split(defaultSplitRE);
|
|
81
|
+
return generateSelectors(key, values);
|
|
82
|
+
});
|
|
45
83
|
}
|
|
46
84
|
function extractorVueScript(options) {
|
|
47
85
|
return {
|
|
48
86
|
name: "@una-ui/extractor-vue-script",
|
|
49
87
|
order: 0,
|
|
50
|
-
async extract({ code }) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
88
|
+
async extract({ code, id }) {
|
|
89
|
+
const cleanPath = parsePath(id).pathname;
|
|
90
|
+
if (cleanPath.endsWith(".vue")) {
|
|
91
|
+
const sfc = parse(code, {
|
|
92
|
+
filename: cleanPath
|
|
93
|
+
});
|
|
94
|
+
code = sfc.descriptor.scriptSetup?.content || sfc.descriptor.script?.content || "";
|
|
95
|
+
}
|
|
96
|
+
const { $ast: node } = parseModule(code, {
|
|
97
|
+
sourceFileName: id
|
|
98
|
+
});
|
|
99
|
+
const prefixes = normalizePrefixes(options?.prefixes ?? []);
|
|
100
|
+
const regularResults = discoverVariants(node, prefixes);
|
|
101
|
+
return [...new Set(regularResults)];
|
|
55
102
|
}
|
|
56
103
|
};
|
|
57
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@una-ui/extractor-vue-script-edge",
|
|
3
|
-
"version": "0.64.0-
|
|
3
|
+
"version": "0.64.0-29262088.1cb0816",
|
|
4
4
|
"description": "Unocss extractor for Vue script",
|
|
5
5
|
"author": "Phojie Rengel <phojrengel@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,16 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@babel/parser": "^7.28.3",
|
|
39
|
+
"@babel/traverse": "^7.28.3",
|
|
40
|
+
"@vue/compiler-sfc": "^3.5.18",
|
|
41
|
+
"magicast": "^0.3.5",
|
|
42
|
+
"ufo": "^1.6.1"
|
|
43
|
+
},
|
|
37
44
|
"devDependencies": {
|
|
45
|
+
"@babel/types": "^7.28.2",
|
|
46
|
+
"@types/babel__traverse": "^7.28.0",
|
|
38
47
|
"@unocss/core": "^66.4.2",
|
|
39
48
|
"vitest": "^3.2.4"
|
|
40
49
|
},
|