@unocss/transformer-directives 0.60.0 → 0.60.1
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 +24 -25
- 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
|
|
|
@@ -73,23 +73,18 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
73
73
|
const calcOffset = (pos) => offset ? pos + offset : pos;
|
|
74
74
|
let body;
|
|
75
75
|
if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw") {
|
|
76
|
-
body = childNode.prelude.value.trim();
|
|
76
|
+
body = removeQuotes(childNode.prelude.value.trim());
|
|
77
77
|
} 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();
|
|
78
|
+
let rawValue = code.original.slice(
|
|
79
|
+
calcOffset(childNode.value.loc.start.offset),
|
|
80
|
+
calcOffset(childNode.value.loc.end.offset)
|
|
81
|
+
);
|
|
82
|
+
rawValue = removeQuotes(rawValue);
|
|
83
|
+
const items = rawValue.split(/\s+/g).filter(Boolean).map((i) => removeQuotes(i));
|
|
84
|
+
body = items.join(" ");
|
|
88
85
|
}
|
|
89
86
|
if (!body)
|
|
90
87
|
return;
|
|
91
|
-
if (/^(['"]).*\1$/.test(body))
|
|
92
|
-
body = body.slice(1, -1);
|
|
93
88
|
const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
|
|
94
89
|
const utils = (await Promise.all(
|
|
95
90
|
classNames.map((i) => uno.parseToken(i, "-"))
|
|
@@ -141,6 +136,9 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
141
136
|
calcOffset(childNode.loc.end.offset + simicolonOffset)
|
|
142
137
|
);
|
|
143
138
|
}
|
|
139
|
+
function removeQuotes(value) {
|
|
140
|
+
return value.replace(/^(['"])(.*)\1$/, "$2");
|
|
141
|
+
}
|
|
144
142
|
|
|
145
143
|
function handleFunction({ code, uno, options }, node) {
|
|
146
144
|
const { throwOnMissing = true } = options;
|
|
@@ -156,16 +154,6 @@ function handleFunction({ code, uno, options }, node) {
|
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
156
|
|
|
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
157
|
async function transformDirectives(code, uno, options, filename, originalCode, offset) {
|
|
170
158
|
let { applyVariable } = options;
|
|
171
159
|
const varStyle = options.varStyle;
|
|
@@ -209,4 +197,15 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
209
197
|
await Promise.all(stack);
|
|
210
198
|
}
|
|
211
199
|
|
|
212
|
-
|
|
200
|
+
function transformerDirectives(options = {}) {
|
|
201
|
+
return {
|
|
202
|
+
name: "@unocss/transformer-directives",
|
|
203
|
+
enforce: options?.enforce,
|
|
204
|
+
idFilter: (id) => cssIdRE.test(id),
|
|
205
|
+
transform: (code, id, ctx) => {
|
|
206
|
+
return transformDirectives(code, ctx.uno, options, id);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
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.1",
|
|
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/
|
|
37
|
-
"@unocss/
|
|
36
|
+
"@unocss/core": "0.60.1",
|
|
37
|
+
"@unocss/rule-utils": "0.60.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"magic-string": "^0.30.10"
|