@unocss/transformer-directives 66.7.4 → 66.7.5
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 +13 -4
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -21,10 +21,16 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
21
21
|
if (!body) return;
|
|
22
22
|
body = removeComments(body);
|
|
23
23
|
const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
|
|
24
|
+
const properties = /* @__PURE__ */ new Map();
|
|
24
25
|
const utils = (await Promise.all(classNames.map((i) => uno.parseToken(i, "-")))).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
|
+
if (item[4]?.layer === "properties") {
|
|
27
|
+
properties.set(item[1], item[2]);
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
25
30
|
const target = acc.find((i) => i[1] === item[1] && i[3] === item[3]);
|
|
26
|
-
if (target)
|
|
27
|
-
|
|
31
|
+
if (target) {
|
|
32
|
+
if (!target[2].includes(item[2])) target[2] += item[2];
|
|
33
|
+
} else acc.push([...item]);
|
|
28
34
|
return acc;
|
|
29
35
|
}, []);
|
|
30
36
|
if (!utils.length) return;
|
|
@@ -32,11 +38,12 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
32
38
|
for (const i of utils) {
|
|
33
39
|
const [, _selector, body, parent, meta] = i;
|
|
34
40
|
const selectorOrGroup = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
35
|
-
|
|
41
|
+
const shouldUseSelector = selectorOrGroup && selectorOrGroup !== ".\\-";
|
|
42
|
+
if (parent || shouldUseSelector || meta?.noMerge) {
|
|
36
43
|
let newSelector = generate(node.prelude);
|
|
37
44
|
const className = code.slice(node.prelude.loc.start.offset, node.prelude.loc.end.offset);
|
|
38
45
|
if (meta?.noMerge) newSelector = selectorOrGroup;
|
|
39
|
-
else if (
|
|
46
|
+
else if (shouldUseSelector) {
|
|
40
47
|
const ruleAST = parse(`${selectorOrGroup}{}`, { context: "rule" });
|
|
41
48
|
const prelude = clone(node.prelude);
|
|
42
49
|
prelude.children?.forEach((child) => {
|
|
@@ -61,6 +68,8 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
61
68
|
} else if (body.includes("@")) code.appendRight(original.length, body);
|
|
62
69
|
else code.appendRight(childNode.loc.end.offset + semicolonOffset, body);
|
|
63
70
|
}
|
|
71
|
+
const propertyCss = Array.from(properties).sort(([a], [b]) => a.localeCompare(b)).map(([property, value]) => `${property}{${value}}`).join("");
|
|
72
|
+
code.appendLeft(0, propertyCss);
|
|
64
73
|
code.remove(childNode.loc.start.offset, childNode.loc.end.offset + semicolonOffset);
|
|
65
74
|
}
|
|
66
75
|
function removeQuotes(value) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.7.
|
|
4
|
+
"version": "66.7.5",
|
|
5
5
|
"description": "UnoCSS transformer for `@apply` directive",
|
|
6
6
|
"author": "hannoeru <me@hanlee.co>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"css-tree": "^3.2.1",
|
|
32
|
-
"@unocss/core": "66.7.
|
|
33
|
-
"@unocss/rule-utils": "66.7.
|
|
32
|
+
"@unocss/core": "66.7.5",
|
|
33
|
+
"@unocss/rule-utils": "66.7.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"magic-string": "^0.30.21"
|