@unocss/transformer-directives 66.6.6 → 66.6.7
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 +18 -25
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { cssIdRE, expandVariantGroup, notNull, regexScopePlaceholder, toArray } from "@unocss/core";
|
|
2
2
|
import { calcMaxWidthBySize, hasIconFn, hasThemeFn, transformThemeFn, transformThemeString } from "@unocss/rule-utils";
|
|
3
3
|
import { List, clone, generate, parse, walk } from "css-tree";
|
|
4
|
-
|
|
5
4
|
//#region src/apply.ts
|
|
6
5
|
async function handleApply(ctx, node) {
|
|
7
6
|
const { code, uno, options, filename } = ctx;
|
|
@@ -31,7 +30,7 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
31
30
|
if (!utils.length) return;
|
|
32
31
|
let semicolonOffset = original[childNode.loc.end.offset] === ";" ? 1 : original[childNode.loc.end.offset] === "@" ? -1 : 0;
|
|
33
32
|
for (const i of utils) {
|
|
34
|
-
const [, _selector, body
|
|
33
|
+
const [, _selector, body, parent, meta] = i;
|
|
35
34
|
const selectorOrGroup = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
36
35
|
if (parent || selectorOrGroup && selectorOrGroup !== ".\\-" || meta?.noMerge) {
|
|
37
36
|
let newSelector = generate(node.prelude);
|
|
@@ -44,23 +43,23 @@ async function parseApply({ code, uno, applyVariable }, node, childNode) {
|
|
|
44
43
|
const selectorListAst = clone(ruleAST.prelude);
|
|
45
44
|
const classSelectors = new List();
|
|
46
45
|
selectorListAst?.children?.forEach((selectorAst) => {
|
|
47
|
-
classSelectors.appendList(selectorAst?.children?.filter((i
|
|
46
|
+
classSelectors.appendList(selectorAst?.children?.filter((i) => i.type === "ClassSelector" && i.name === "\\-"));
|
|
48
47
|
});
|
|
49
|
-
classSelectors.forEach((i
|
|
48
|
+
classSelectors.forEach((i) => Object.assign(i, clone(child)));
|
|
50
49
|
Object.assign(child, selectorListAst);
|
|
51
50
|
});
|
|
52
51
|
newSelector = generate(prelude);
|
|
53
52
|
}
|
|
54
|
-
let css = `${newSelector.includes(".\\-") ? className.split(",").map((e) => newSelector.replace(/.\\-/g, e.trim())).join(",") : newSelector}{${body
|
|
53
|
+
let css = `${newSelector.includes(".\\-") ? className.split(",").map((e) => newSelector.replace(/.\\-/g, e.trim())).join(",") : newSelector}{${body}}`;
|
|
55
54
|
if (parent) if (parent.includes(" $$ ")) {
|
|
56
55
|
const [first, ...parentSelectors] = parent.split(" $$ ").reverse();
|
|
57
|
-
css = `${parentSelectors.reduce((p, c, i
|
|
56
|
+
css = `${parentSelectors.reduce((p, c, i) => i === parentSelectors.length - 1 ? `${p}{${c}{${css}}}${"}".repeat(i)}` : `${p}{${c}`, first)}`;
|
|
58
57
|
} else if (parent === ".\\-") css = `${className}{${css}}`;
|
|
59
58
|
else css = `${parent}{${css}}`;
|
|
60
59
|
semicolonOffset = 0;
|
|
61
60
|
code.appendLeft(node.loc.end.offset, css);
|
|
62
|
-
} else if (body
|
|
63
|
-
else code.appendRight(childNode.loc.end.offset + semicolonOffset, body
|
|
61
|
+
} else if (body.includes("@")) code.appendRight(original.length, body);
|
|
62
|
+
else code.appendRight(childNode.loc.end.offset + semicolonOffset, body);
|
|
64
63
|
}
|
|
65
64
|
code.remove(childNode.loc.start.offset, childNode.loc.end.offset + semicolonOffset);
|
|
66
65
|
}
|
|
@@ -70,7 +69,6 @@ function removeQuotes(value) {
|
|
|
70
69
|
function removeComments(value) {
|
|
71
70
|
return value.replace(/(\/\*(?:.|\n)*?\*\/)|(\/\/.*)/g, "");
|
|
72
71
|
}
|
|
73
|
-
|
|
74
72
|
//#endregion
|
|
75
73
|
//#region src/icon.ts
|
|
76
74
|
async function transformIconString(uno, icon, color) {
|
|
@@ -91,8 +89,8 @@ async function transformIconString(uno, icon, color) {
|
|
|
91
89
|
customizations: {
|
|
92
90
|
...customizations,
|
|
93
91
|
trimCustomSvg: true,
|
|
94
|
-
async iconCustomizer(collection, icon
|
|
95
|
-
await customizations.iconCustomizer?.(collection, icon
|
|
92
|
+
async iconCustomizer(collection, icon, props) {
|
|
93
|
+
await customizations.iconCustomizer?.(collection, icon, props);
|
|
96
94
|
if (unit) {
|
|
97
95
|
if (!props.width) props.width = `${scale}${unit}`;
|
|
98
96
|
if (!props.height) props.height = `${scale}${unit}`;
|
|
@@ -107,7 +105,6 @@ async function transformIconString(uno, icon, color) {
|
|
|
107
105
|
if (parsed) return `url("data:image/svg+xml;utf8,${color ? api.encodeSvgForCss(parsed.svg).replace(/currentcolor/gi, color) : api.encodeSvgForCss(parsed.svg)}")`;
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
|
-
|
|
111
108
|
//#endregion
|
|
112
109
|
//#region src/functions.ts
|
|
113
110
|
async function handleFunction({ code, uno, options }, node) {
|
|
@@ -129,7 +126,7 @@ async function handleFunction({ code, uno, options }, node) {
|
|
|
129
126
|
break;
|
|
130
127
|
}
|
|
131
128
|
case "icon": {
|
|
132
|
-
const params = node.children.toArray().filter((node
|
|
129
|
+
const params = node.children.toArray().filter((node) => node.type === "String").map((node) => node.value);
|
|
133
130
|
if (params.length === 0) throw new Error("icon() expects at least one argument");
|
|
134
131
|
let [icon, color] = params;
|
|
135
132
|
if (color) color = encodeURIComponent(transformThemeFn(color, uno.config.theme, throwOnMissing));
|
|
@@ -139,7 +136,6 @@ async function handleFunction({ code, uno, options }, node) {
|
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
|
-
|
|
143
139
|
//#endregion
|
|
144
140
|
//#region src/screen.ts
|
|
145
141
|
const screenRuleRE = /(@screen [^{]+)(.+)/g;
|
|
@@ -166,11 +162,11 @@ function handleScreen({ code, uno }, node) {
|
|
|
166
162
|
size,
|
|
167
163
|
idx
|
|
168
164
|
]);
|
|
169
|
-
const generateMediaQuery = (breakpointName
|
|
170
|
-
const [, size, idx] = variantEntries.find((i) => i[0] === breakpointName
|
|
171
|
-
if (prefix
|
|
172
|
-
else if (prefix
|
|
173
|
-
else throw new Error(`breakpoint variant not supported: ${prefix
|
|
165
|
+
const generateMediaQuery = (breakpointName, prefix) => {
|
|
166
|
+
const [, size, idx] = variantEntries.find((i) => i[0] === breakpointName);
|
|
167
|
+
if (prefix) if (prefix === "lt") return `@media (max-width: ${calcMaxWidthBySize(size)})`;
|
|
168
|
+
else if (prefix === "at") return `@media (min-width: ${size})${variantEntries[idx + 1] ? ` and (max-width: ${calcMaxWidthBySize(variantEntries[idx + 1][1])})` : ""}`;
|
|
169
|
+
else throw new Error(`breakpoint variant not supported: ${prefix}`);
|
|
174
170
|
return `@media (min-width: ${size})`;
|
|
175
171
|
};
|
|
176
172
|
if (!variantEntries.find((i) => i[0] === breakpointName)) throw new Error(`breakpoint ${breakpointName} not found`);
|
|
@@ -178,9 +174,8 @@ function handleScreen({ code, uno }, node) {
|
|
|
178
174
|
const str = code.original.slice(offset, node.loc.end.offset);
|
|
179
175
|
const matches = Array.from(str.matchAll(screenRuleRE));
|
|
180
176
|
if (!matches.length) return;
|
|
181
|
-
for (const match
|
|
177
|
+
for (const match of matches) code.overwrite(offset + match.index, offset + match.index + match[1].length, `${generateMediaQuery(breakpointName, prefix)}`);
|
|
182
178
|
}
|
|
183
|
-
|
|
184
179
|
//#endregion
|
|
185
180
|
//#region src/transform.ts
|
|
186
181
|
async function transformDirectives(code, uno, options, filename, originalCode, offset) {
|
|
@@ -195,7 +190,7 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
195
190
|
];
|
|
196
191
|
}
|
|
197
192
|
applyVariable = toArray(applyVariable || []);
|
|
198
|
-
const isHasApply = (code
|
|
193
|
+
const isHasApply = (code) => code.includes("@apply") || applyVariable.some((s) => code.includes(s));
|
|
199
194
|
const parseCode = originalCode || code.original;
|
|
200
195
|
const hasApply = isHasApply(parseCode);
|
|
201
196
|
const hasScreen = parseCode.includes("@screen");
|
|
@@ -234,7 +229,6 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
|
|
|
234
229
|
if (newCode !== oldCode) code.update(0, code.original.length, newCode);
|
|
235
230
|
}
|
|
236
231
|
}
|
|
237
|
-
|
|
238
232
|
//#endregion
|
|
239
233
|
//#region src/index.ts
|
|
240
234
|
function transformerDirectives(options = {}) {
|
|
@@ -247,6 +241,5 @@ function transformerDirectives(options = {}) {
|
|
|
247
241
|
}
|
|
248
242
|
};
|
|
249
243
|
}
|
|
250
|
-
|
|
251
244
|
//#endregion
|
|
252
|
-
export { transformerDirectives as default };
|
|
245
|
+
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": "66.6.
|
|
4
|
+
"version": "66.6.7",
|
|
5
5
|
"description": "UnoCSS transformer for `@apply` directive",
|
|
6
6
|
"author": "hannoeru <me@hanlee.co>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"css-tree": "^3.1.0",
|
|
32
|
-
"@unocss/core": "66.6.
|
|
33
|
-
"@unocss/rule-utils": "66.6.
|
|
32
|
+
"@unocss/core": "66.6.7",
|
|
33
|
+
"@unocss/rule-utils": "66.6.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"magic-string": "^0.30.21"
|