@unocss/transformer-directives 0.61.3 → 0.61.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 +17 -17
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { expandVariantGroup, notNull, regexScopePlaceholder, toArray, cssIdRE }
|
|
|
2
2
|
import { generate, parse, clone, List, walk } from 'css-tree';
|
|
3
3
|
import { transformThemeString, hasThemeFn } from '@unocss/rule-utils';
|
|
4
4
|
|
|
5
|
-
const screenRuleRE = /(@screen)
|
|
5
|
+
const screenRuleRE = /(@screen [^{]+)(.+)/g;
|
|
6
6
|
function handleScreen({ code, uno }, node) {
|
|
7
7
|
let breakpointName = "";
|
|
8
8
|
let prefix = "";
|
|
@@ -46,8 +46,8 @@ function handleScreen({ code, uno }, node) {
|
|
|
46
46
|
for (const match2 of matches) {
|
|
47
47
|
code.overwrite(
|
|
48
48
|
offset + match2.index,
|
|
49
|
-
offset + match2.index + match2[
|
|
50
|
-
`${generateMediaQuery(breakpointName, prefix)}
|
|
49
|
+
offset + match2.index + match2[1].length,
|
|
50
|
+
`${generateMediaQuery(breakpointName, prefix)}`
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -59,26 +59,24 @@ function calcMaxWidthBySize(size) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
async function handleApply(ctx, node) {
|
|
62
|
-
const { code, uno, options, filename
|
|
63
|
-
const calcOffset = (pos) => offset ? pos + offset : pos;
|
|
62
|
+
const { code, uno, options, filename } = ctx;
|
|
64
63
|
await Promise.all(
|
|
65
64
|
node.block.children.map(async (childNode) => {
|
|
66
65
|
if (childNode.type === "Raw")
|
|
67
|
-
return transformDirectives(code, uno, options, filename, childNode.value,
|
|
66
|
+
return transformDirectives(code, uno, options, filename, childNode.value, childNode.loc.start.offset);
|
|
68
67
|
await parseApply(ctx, node, childNode);
|
|
69
68
|
}).toArray()
|
|
70
69
|
);
|
|
71
70
|
}
|
|
72
|
-
async function parseApply({ code, uno,
|
|
73
|
-
const calcOffset = (pos) => offset ? pos + offset : pos;
|
|
71
|
+
async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
74
72
|
const original = code.original;
|
|
75
73
|
let body;
|
|
76
74
|
if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw") {
|
|
77
75
|
body = removeQuotes(childNode.prelude.value.trim());
|
|
78
76
|
} else if (childNode.type === "Declaration" && applyVariable.includes(childNode.property) && (childNode.value.type === "Value" || childNode.value.type === "Raw")) {
|
|
79
77
|
let rawValue = original.slice(
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
childNode.value.loc.start.offset,
|
|
79
|
+
childNode.value.loc.end.offset
|
|
82
80
|
).trim();
|
|
83
81
|
rawValue = removeQuotes(rawValue);
|
|
84
82
|
const items = rawValue.split(/\s+/g).filter(Boolean).map((i) => removeQuotes(i));
|
|
@@ -100,12 +98,13 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
100
98
|
}, []);
|
|
101
99
|
if (!utils.length)
|
|
102
100
|
return;
|
|
103
|
-
const simicolonOffset = original[
|
|
101
|
+
const simicolonOffset = original[childNode.loc.end.offset] === ";" ? 1 : 0;
|
|
104
102
|
for (const i of utils) {
|
|
105
103
|
const [, _selector, body2, parent] = i;
|
|
106
104
|
const selectorOrGroup = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
107
105
|
if (parent || selectorOrGroup && selectorOrGroup !== ".\\-") {
|
|
108
106
|
let newSelector = generate(node.prelude);
|
|
107
|
+
const className = code.slice(node.prelude.loc.start.offset, node.prelude.loc.end.offset);
|
|
109
108
|
if (selectorOrGroup && selectorOrGroup !== ".\\-") {
|
|
110
109
|
const ruleAST = parse(`${selectorOrGroup}{}`, {
|
|
111
110
|
context: "rule"
|
|
@@ -122,20 +121,20 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
122
121
|
});
|
|
123
122
|
newSelector = generate(prelude);
|
|
124
123
|
}
|
|
125
|
-
let css = `${newSelector}{${body2}}`;
|
|
124
|
+
let css = `${newSelector.replace(/.\\-/g, className)}{${body2}}`;
|
|
126
125
|
if (parent)
|
|
127
126
|
css = `${parent}{${css}}`;
|
|
128
|
-
code.appendLeft(
|
|
127
|
+
code.appendLeft(node.loc.end.offset, css);
|
|
129
128
|
} else {
|
|
130
129
|
if (body2.includes("@"))
|
|
131
130
|
code.appendRight(original.length + simicolonOffset, body2);
|
|
132
131
|
else
|
|
133
|
-
code.appendRight(
|
|
132
|
+
code.appendRight(childNode.loc.end.offset + simicolonOffset, body2);
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
code.remove(
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
childNode.loc.start.offset,
|
|
137
|
+
childNode.loc.end.offset + simicolonOffset
|
|
139
138
|
);
|
|
140
139
|
}
|
|
141
140
|
function removeQuotes(value) {
|
|
@@ -177,7 +176,8 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
177
176
|
parseCustomProperty: true,
|
|
178
177
|
parseAtrulePrelude: false,
|
|
179
178
|
positions: true,
|
|
180
|
-
filename
|
|
179
|
+
filename,
|
|
180
|
+
offset
|
|
181
181
|
});
|
|
182
182
|
if (ast.type !== "StyleSheet")
|
|
183
183
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.61.
|
|
4
|
+
"version": "0.61.5",
|
|
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": "^2.3.1",
|
|
36
|
-
"@unocss/core": "0.61.
|
|
37
|
-
"@unocss/rule-utils": "0.61.
|
|
36
|
+
"@unocss/core": "0.61.5",
|
|
37
|
+
"@unocss/rule-utils": "0.61.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"magic-string": "^0.30.10"
|