@unocss/transformer-directives 66.1.0-beta.8 → 66.1.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/dist/index.mjs +16 -3
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -66,8 +66,14 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
66
66
|
newSelector = generate(prelude);
|
|
67
67
|
}
|
|
68
68
|
let css = `${newSelector.replace(/.\\-/g, className)}{${body2}}`;
|
|
69
|
-
if (parent)
|
|
70
|
-
|
|
69
|
+
if (parent) {
|
|
70
|
+
if (parent.includes(" $$ ")) {
|
|
71
|
+
const [first, ...parentSelectors] = parent.split(" $$ ").reverse();
|
|
72
|
+
css = `${parentSelectors.reduce((p, c, i2) => i2 === parentSelectors.length - 1 ? `${p}{${c}{${css}}}${"}".repeat(i2)}` : `${p}{${c}`, first)}`;
|
|
73
|
+
} else {
|
|
74
|
+
css = `${parent}{${css}}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
71
77
|
semicolonOffset = 0;
|
|
72
78
|
code.appendLeft(node.loc.end.offset, css);
|
|
73
79
|
} else {
|
|
@@ -238,8 +244,9 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
238
244
|
applyVariable = ["--at-apply", "--uno-apply", "--uno"];
|
|
239
245
|
}
|
|
240
246
|
applyVariable = toArray(applyVariable || []);
|
|
247
|
+
const isHasApply = (code2) => code2.includes("@apply") || applyVariable.some((s) => code2.includes(s));
|
|
241
248
|
const parseCode = originalCode || code.original;
|
|
242
|
-
const hasApply =
|
|
249
|
+
const hasApply = isHasApply(parseCode);
|
|
243
250
|
const hasScreen = parseCode.includes("@screen");
|
|
244
251
|
const hasFn = hasThemeFn(parseCode) || hasIconFn(parseCode);
|
|
245
252
|
if (!hasApply && !hasFn && !hasScreen)
|
|
@@ -270,6 +277,12 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
270
277
|
};
|
|
271
278
|
walk(ast, (...args) => stack.push(processNode(...args)));
|
|
272
279
|
await Promise.all(stack);
|
|
280
|
+
const oldCode = code.toString();
|
|
281
|
+
if (!isHasApply(oldCode)) {
|
|
282
|
+
const newCode = oldCode.replace(/[^{}]*\{\s*\}\s*/g, "");
|
|
283
|
+
if (newCode !== oldCode)
|
|
284
|
+
code.update(0, code.original.length, newCode);
|
|
285
|
+
}
|
|
273
286
|
}
|
|
274
287
|
|
|
275
288
|
function transformerDirectives(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.1.0
|
|
4
|
+
"version": "66.1.0",
|
|
5
5
|
"description": "UnoCSS transformer for `@apply` directive",
|
|
6
6
|
"author": "hannoeru <me@hanlee.co>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"css-tree": "^3.1.0",
|
|
36
|
-
"@unocss/
|
|
37
|
-
"@unocss/
|
|
36
|
+
"@unocss/rule-utils": "66.1.0",
|
|
37
|
+
"@unocss/core": "66.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"magic-string": "^0.30.17"
|