@unocss/postcss 0.59.0 → 0.59.2
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/esm.mjs +70 -60
- package/package.json +4 -4
package/dist/esm.mjs
CHANGED
|
@@ -13,66 +13,70 @@ const defaultFilesystemGlobs = [
|
|
|
13
13
|
];
|
|
14
14
|
|
|
15
15
|
async function parseApply(root, uno, directiveName) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
classNames.map((
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
target[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (selector && selector !== ".\\-") {
|
|
43
|
-
const selectorAST = parse(selector, {
|
|
44
|
-
context: "selector"
|
|
16
|
+
const promises = [];
|
|
17
|
+
root.walkAtRules(directiveName, (rule) => {
|
|
18
|
+
promises.push((async () => {
|
|
19
|
+
if (!rule.parent)
|
|
20
|
+
return;
|
|
21
|
+
const source = rule.source;
|
|
22
|
+
const classNames = expandVariantGroup(rule.params).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
|
|
23
|
+
const utils = (await Promise.all(
|
|
24
|
+
classNames.map((i) => uno.parseToken(i, "-"))
|
|
25
|
+
)).filter(notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
|
|
26
|
+
const target = acc.find((i) => i[1] === item[1] && i[3] === item[3]);
|
|
27
|
+
if (target)
|
|
28
|
+
target[2] += item[2];
|
|
29
|
+
else
|
|
30
|
+
acc.push([...item]);
|
|
31
|
+
return acc;
|
|
32
|
+
}, []);
|
|
33
|
+
if (!utils.length)
|
|
34
|
+
return;
|
|
35
|
+
const parentAfterNodes = [];
|
|
36
|
+
for (const i of utils) {
|
|
37
|
+
const [, _selector, body, parent] = i;
|
|
38
|
+
const selector = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
39
|
+
if (parent || selector && selector !== ".\\-") {
|
|
40
|
+
const node = parse(rule.parent.toString(), {
|
|
41
|
+
context: "rule"
|
|
45
42
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
let newSelector = generate(node.prelude);
|
|
44
|
+
if (selector && selector !== ".\\-") {
|
|
45
|
+
const selectorAST = parse(selector, {
|
|
46
|
+
context: "selector"
|
|
47
|
+
});
|
|
48
|
+
const prelude = clone(node.prelude);
|
|
49
|
+
prelude.children.forEach((child) => {
|
|
50
|
+
const parentSelectorAst = clone(selectorAST);
|
|
51
|
+
parentSelectorAst.children.forEach((i2) => {
|
|
52
|
+
if (i2.type === "ClassSelector" && i2.name === "\\-")
|
|
53
|
+
Object.assign(i2, clone(child));
|
|
54
|
+
});
|
|
55
|
+
Object.assign(child, parentSelectorAst);
|
|
52
56
|
});
|
|
53
|
-
|
|
57
|
+
newSelector = generate(prelude);
|
|
58
|
+
}
|
|
59
|
+
let css = `${newSelector}{${body}}`;
|
|
60
|
+
if (parent)
|
|
61
|
+
css = `${parent}{${css}}`;
|
|
62
|
+
const css_parsed = postcss.parse(css);
|
|
63
|
+
css_parsed.walkDecls((declaration) => {
|
|
64
|
+
declaration.source = source;
|
|
54
65
|
});
|
|
55
|
-
|
|
66
|
+
parentAfterNodes.push(css_parsed);
|
|
67
|
+
} else {
|
|
68
|
+
const css = postcss.parse(body);
|
|
69
|
+
css.walkDecls((declaration) => {
|
|
70
|
+
declaration.source = source;
|
|
71
|
+
});
|
|
72
|
+
rule.parent.append(css);
|
|
56
73
|
}
|
|
57
|
-
let css = `${newSelector}{${body}}`;
|
|
58
|
-
if (parent)
|
|
59
|
-
css = `${parent}{${css}}`;
|
|
60
|
-
const css_parsed = postcss.parse(css);
|
|
61
|
-
css_parsed.walkDecls((declaration) => {
|
|
62
|
-
declaration.source = source;
|
|
63
|
-
});
|
|
64
|
-
parentAfterNodes.push(css_parsed);
|
|
65
|
-
} else {
|
|
66
|
-
const css = postcss.parse(body);
|
|
67
|
-
css.walkDecls((declaration) => {
|
|
68
|
-
declaration.source = source;
|
|
69
|
-
});
|
|
70
|
-
rule.parent.append(css);
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
rule.parent.after(parentAfterNodes);
|
|
76
|
+
rule.remove();
|
|
77
|
+
})());
|
|
75
78
|
});
|
|
79
|
+
await Promise.all(promises);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
async function parseTheme(root, uno) {
|
|
@@ -212,8 +216,14 @@ function createPlugin(options) {
|
|
|
212
216
|
const { matched } = await uno.generate(c2.code, { id: c2.id ?? `__plain_content_${idx}__` });
|
|
213
217
|
for (const candidate of matched)
|
|
214
218
|
classes.add(candidate);
|
|
215
|
-
})
|
|
216
|
-
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
await Promise.all(promises);
|
|
222
|
+
promises = [];
|
|
223
|
+
const BATCH_SIZE = 500;
|
|
224
|
+
for (let i = 0; i < entries.length; i += BATCH_SIZE) {
|
|
225
|
+
const batch = entries.slice(i, i + BATCH_SIZE);
|
|
226
|
+
promises.push(...batch.map(async ({ path: file, mtimeMs }) => {
|
|
217
227
|
result.messages.push({
|
|
218
228
|
type: "dependency",
|
|
219
229
|
plugin: directiveMap.unocss,
|
|
@@ -229,10 +239,10 @@ function createPlugin(options) {
|
|
|
229
239
|
id: file
|
|
230
240
|
});
|
|
231
241
|
fileClassMap.set(file, matched);
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
242
|
+
}));
|
|
243
|
+
await Promise.all(promises);
|
|
244
|
+
promises = [];
|
|
245
|
+
}
|
|
236
246
|
for (const set of fileClassMap.values()) {
|
|
237
247
|
for (const candidate of set)
|
|
238
248
|
classes.add(candidate);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/postcss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.59.
|
|
4
|
+
"version": "0.59.2",
|
|
5
5
|
"description": "PostCSS plugin for UnoCSS",
|
|
6
6
|
"author": "sibbng <sibbngheid@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"fast-glob": "^3.3.2",
|
|
59
59
|
"magic-string": "^0.30.9",
|
|
60
60
|
"postcss": "^8.4.38",
|
|
61
|
-
"@unocss/
|
|
62
|
-
"@unocss/
|
|
63
|
-
"@unocss/
|
|
61
|
+
"@unocss/config": "0.59.2",
|
|
62
|
+
"@unocss/core": "0.59.2",
|
|
63
|
+
"@unocss/rule-utils": "0.59.2"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "unbuild",
|