@unocss/transformer-directives 0.60.0 → 0.60.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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +27 -27
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -35,7 +35,7 @@ interface TransformerDirectivesContext {
|
|
|
35
35
|
offset?: number;
|
|
36
36
|
filename?: string;
|
|
37
37
|
}
|
|
38
|
+
|
|
38
39
|
declare function transformerDirectives(options?: TransformerDirectivesOptions): SourceCodeTransformer;
|
|
39
|
-
declare function transformDirectives(code: MagicString, uno: UnoGenerator, options: TransformerDirectivesOptions, filename?: string, originalCode?: string, offset?: number): Promise<void>;
|
|
40
40
|
|
|
41
|
-
export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default
|
|
41
|
+
export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface TransformerDirectivesContext {
|
|
|
35
35
|
offset?: number;
|
|
36
36
|
filename?: string;
|
|
37
37
|
}
|
|
38
|
+
|
|
38
39
|
declare function transformerDirectives(options?: TransformerDirectivesOptions): SourceCodeTransformer;
|
|
39
|
-
declare function transformDirectives(code: MagicString, uno: UnoGenerator, options: TransformerDirectivesOptions, filename?: string, originalCode?: string, offset?: number): Promise<void>;
|
|
40
40
|
|
|
41
|
-
export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default
|
|
41
|
+
export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expandVariantGroup, notNull, regexScopePlaceholder,
|
|
1
|
+
import { expandVariantGroup, notNull, regexScopePlaceholder, toArray, cssIdRE } from '@unocss/core';
|
|
2
2
|
import { generate, parse, clone, List, walk } from 'css-tree';
|
|
3
3
|
import { transformThemeString, hasThemeFn } from '@unocss/rule-utils';
|
|
4
4
|
|
|
@@ -71,25 +71,21 @@ async function handleApply(ctx, node) {
|
|
|
71
71
|
}
|
|
72
72
|
async function parseApply({ code, uno, offset, applyVariable }, node, childNode) {
|
|
73
73
|
const calcOffset = (pos) => offset ? pos + offset : pos;
|
|
74
|
+
const original = code.original;
|
|
74
75
|
let body;
|
|
75
76
|
if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw") {
|
|
76
|
-
body = childNode.prelude.value.trim();
|
|
77
|
+
body = removeQuotes(childNode.prelude.value.trim());
|
|
77
78
|
} else if (childNode.type === "Declaration" && applyVariable.includes(childNode.property) && childNode.value.type === "Value") {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return str;
|
|
86
|
-
}
|
|
87
|
-
}, "").trim();
|
|
79
|
+
let rawValue = original.slice(
|
|
80
|
+
calcOffset(childNode.value.loc.start.offset),
|
|
81
|
+
calcOffset(childNode.value.loc.end.offset)
|
|
82
|
+
).trim();
|
|
83
|
+
rawValue = removeQuotes(rawValue);
|
|
84
|
+
const items = rawValue.split(/\s+/g).filter(Boolean).map((i) => removeQuotes(i));
|
|
85
|
+
body = items.join(" ");
|
|
88
86
|
}
|
|
89
87
|
if (!body)
|
|
90
88
|
return;
|
|
91
|
-
if (/^(['"]).*\1$/.test(body))
|
|
92
|
-
body = body.slice(1, -1);
|
|
93
89
|
const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
|
|
94
90
|
const utils = (await Promise.all(
|
|
95
91
|
classNames.map((i) => uno.parseToken(i, "-"))
|
|
@@ -103,7 +99,7 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
103
99
|
}, []);
|
|
104
100
|
if (!utils.length)
|
|
105
101
|
return;
|
|
106
|
-
const simicolonOffset =
|
|
102
|
+
const simicolonOffset = original[calcOffset(childNode.loc.end.offset)] === ";" ? 1 : 0;
|
|
107
103
|
for (const i of utils) {
|
|
108
104
|
const [, _selector, body2, parent] = i;
|
|
109
105
|
const selectorOrGroup = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
@@ -131,7 +127,7 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
131
127
|
code.appendLeft(calcOffset(node.loc.end.offset), css);
|
|
132
128
|
} else {
|
|
133
129
|
if (body2.includes("@"))
|
|
134
|
-
code.appendRight(
|
|
130
|
+
code.appendRight(original.length + simicolonOffset, body2);
|
|
135
131
|
else
|
|
136
132
|
code.appendRight(calcOffset(childNode.loc.end.offset + simicolonOffset), body2);
|
|
137
133
|
}
|
|
@@ -141,6 +137,9 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
141
137
|
calcOffset(childNode.loc.end.offset + simicolonOffset)
|
|
142
138
|
);
|
|
143
139
|
}
|
|
140
|
+
function removeQuotes(value) {
|
|
141
|
+
return value.replace(/^(['"])(.*)\1$/, "$2");
|
|
142
|
+
}
|
|
144
143
|
|
|
145
144
|
function handleFunction({ code, uno, options }, node) {
|
|
146
145
|
const { throwOnMissing = true } = options;
|
|
@@ -156,16 +155,6 @@ function handleFunction({ code, uno, options }, node) {
|
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
function transformerDirectives(options = {}) {
|
|
160
|
-
return {
|
|
161
|
-
name: "@unocss/transformer-directives",
|
|
162
|
-
enforce: options?.enforce,
|
|
163
|
-
idFilter: (id) => cssIdRE.test(id),
|
|
164
|
-
transform: (code, id, ctx) => {
|
|
165
|
-
return transformDirectives(code, ctx.uno, options, id);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
158
|
async function transformDirectives(code, uno, options, filename, originalCode, offset) {
|
|
170
159
|
let { applyVariable } = options;
|
|
171
160
|
const varStyle = options.varStyle;
|
|
@@ -209,4 +198,15 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
209
198
|
await Promise.all(stack);
|
|
210
199
|
}
|
|
211
200
|
|
|
212
|
-
|
|
201
|
+
function transformerDirectives(options = {}) {
|
|
202
|
+
return {
|
|
203
|
+
name: "@unocss/transformer-directives",
|
|
204
|
+
enforce: options?.enforce,
|
|
205
|
+
idFilter: (id) => cssIdRE.test(id),
|
|
206
|
+
transform: (code, id, ctx) => {
|
|
207
|
+
return transformDirectives(code, ctx.uno, options, id);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { transformerDirectives as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.60.
|
|
4
|
+
"version": "0.60.2",
|
|
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/rule-utils": "0.60.
|
|
37
|
-
"@unocss/core": "0.60.
|
|
36
|
+
"@unocss/rule-utils": "0.60.2",
|
|
37
|
+
"@unocss/core": "0.60.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"magic-string": "^0.30.10"
|