@unocss/transformer-directives 0.59.4 → 0.60.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 +31 -13
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { expandVariantGroup, notNull, regexScopePlaceholder, cssIdRE, toArray } from '@unocss/core';
|
|
2
2
|
import { generate, parse, clone, List, walk } from 'css-tree';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
function handleThemeFn({ code, uno, options }, node) {
|
|
6
|
-
const { throwOnMissing = true } = options;
|
|
7
|
-
const offset = node.value.loc.start.offset;
|
|
8
|
-
const str = code.original.slice(offset, node.value.loc.end.offset);
|
|
9
|
-
code.overwrite(offset, node.value.loc.end.offset, transformThemeFn(str, uno.config.theme, throwOnMissing));
|
|
10
|
-
}
|
|
3
|
+
import { transformThemeString, hasThemeFn } from '@unocss/rule-utils';
|
|
11
4
|
|
|
12
5
|
const screenRuleRE = /(@screen) (.+) /g;
|
|
13
6
|
function handleScreen({ code, uno }, node) {
|
|
@@ -79,10 +72,20 @@ async function handleApply(ctx, node) {
|
|
|
79
72
|
async function parseApply({ code, uno, offset, applyVariable }, node, childNode) {
|
|
80
73
|
const calcOffset = (pos) => offset ? pos + offset : pos;
|
|
81
74
|
let body;
|
|
82
|
-
if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw")
|
|
75
|
+
if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw") {
|
|
83
76
|
body = childNode.prelude.value.trim();
|
|
84
|
-
else if (childNode.type === "Declaration" && applyVariable.includes(childNode.property) && childNode.value.type === "
|
|
85
|
-
body = childNode.value.
|
|
77
|
+
} else if (childNode.type === "Declaration" && applyVariable.includes(childNode.property) && childNode.value.type === "Value") {
|
|
78
|
+
body = childNode.value.children.reduce((str, nodeItem) => {
|
|
79
|
+
switch (nodeItem.type) {
|
|
80
|
+
case "String":
|
|
81
|
+
return `${str} ${nodeItem.value}`;
|
|
82
|
+
case "Identifier":
|
|
83
|
+
return `${str} ${nodeItem.name}`;
|
|
84
|
+
default:
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
87
|
+
}, "").trim();
|
|
88
|
+
}
|
|
86
89
|
if (!body)
|
|
87
90
|
return;
|
|
88
91
|
if (/^(['"]).*\1$/.test(body))
|
|
@@ -139,6 +142,20 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
|
|
|
139
142
|
);
|
|
140
143
|
}
|
|
141
144
|
|
|
145
|
+
function handleFunction({ code, uno, options }, node) {
|
|
146
|
+
const { throwOnMissing = true } = options;
|
|
147
|
+
switch (node.name) {
|
|
148
|
+
case "theme": {
|
|
149
|
+
if (node.children.size !== 1)
|
|
150
|
+
throw new Error("theme() expect exact one argument");
|
|
151
|
+
const themeStr = node.children.first.value;
|
|
152
|
+
const value = transformThemeString(themeStr, uno.config.theme, throwOnMissing);
|
|
153
|
+
if (value)
|
|
154
|
+
code.overwrite(node.loc.start.offset, node.loc.end.offset, value);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
142
159
|
function transformerDirectives(options = {}) {
|
|
143
160
|
return {
|
|
144
161
|
name: "@unocss/transformer-directives",
|
|
@@ -164,6 +181,7 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
164
181
|
if (!hasApply && !hasThemeFn$1 && !hasScreen)
|
|
165
182
|
return;
|
|
166
183
|
const ast = parse(originalCode || code.original, {
|
|
184
|
+
parseCustomProperty: true,
|
|
167
185
|
parseAtrulePrelude: false,
|
|
168
186
|
positions: true,
|
|
169
187
|
filename
|
|
@@ -182,8 +200,8 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
182
200
|
const processNode = async (node, _item, _list) => {
|
|
183
201
|
if (hasScreen && node.type === "Atrule")
|
|
184
202
|
handleScreen(ctx, node);
|
|
185
|
-
if (
|
|
186
|
-
|
|
203
|
+
if (node.type === "Function")
|
|
204
|
+
handleFunction(ctx, node);
|
|
187
205
|
if (hasApply && node.type === "Rule")
|
|
188
206
|
await handleApply(ctx, node);
|
|
189
207
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.60.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": "^2.3.1",
|
|
36
|
-
"@unocss/
|
|
37
|
-
"@unocss/
|
|
36
|
+
"@unocss/rule-utils": "0.60.0",
|
|
37
|
+
"@unocss/core": "0.60.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"magic-string": "^0.30.10"
|