@unocss/postcss 66.6.0 → 66.6.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.cjs +20 -0
- package/dist/{esm.d.cts → index.d.cts} +11 -3
- package/package.json +13 -20
- package/dist/esm.cjs +0 -284
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
function unocss(options = {}) {
|
|
5
|
+
var _options$directiveMap;
|
|
6
|
+
let promise;
|
|
7
|
+
return {
|
|
8
|
+
postcssPlugin: ((_options$directiveMap = options.directiveMap) === null || _options$directiveMap === void 0 ? void 0 : _options$directiveMap.unocss) || "unocss",
|
|
9
|
+
plugins: [async (root, result) => {
|
|
10
|
+
if (!promise) promise = import("@unocss/postcss/esm").then((r) => r.createPlugin(options));
|
|
11
|
+
return await (await promise)(root, result);
|
|
12
|
+
}]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
unocss.postcss = true;
|
|
16
|
+
unocss.default = unocss;
|
|
17
|
+
var src_default = unocss;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.default = src_default;
|
|
@@ -17,7 +17,15 @@ interface UnoPostcssPluginOptions {
|
|
|
17
17
|
configOrPath?: string | UserConfig;
|
|
18
18
|
}
|
|
19
19
|
//#endregion
|
|
20
|
-
//#region src/
|
|
21
|
-
declare function
|
|
20
|
+
//#region src/index.d.ts
|
|
21
|
+
declare function unocss(options?: UnoPostcssPluginOptions): {
|
|
22
|
+
postcssPlugin: string;
|
|
23
|
+
plugins: ((root: Root, result: Result) => Promise<void>)[];
|
|
24
|
+
};
|
|
25
|
+
declare namespace unocss {
|
|
26
|
+
export var postcss: boolean;
|
|
27
|
+
var _a: typeof unocss;
|
|
28
|
+
export { _a as default };
|
|
29
|
+
}
|
|
22
30
|
//#endregion
|
|
23
|
-
export {
|
|
31
|
+
export { UnoPostcssPluginOptions, unocss as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/postcss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.6.
|
|
4
|
+
"version": "66.6.1",
|
|
5
5
|
"description": "PostCSS plugin for UnoCSS",
|
|
6
6
|
"author": "sibbng <sibbngheid@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -19,27 +19,20 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"default": "./dist/index.mjs"
|
|
25
|
-
},
|
|
26
|
-
"require": {
|
|
27
|
-
"types": "./dist/index.d.cts",
|
|
28
|
-
"default": "./dist/index.cjs"
|
|
29
|
-
}
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.mjs"
|
|
30
24
|
},
|
|
31
|
-
"./esm":
|
|
32
|
-
|
|
33
|
-
"default": "./dist/esm.mjs"
|
|
34
|
-
}
|
|
25
|
+
"./esm": "./dist/esm.mjs",
|
|
26
|
+
"./package.json": "./package.json"
|
|
35
27
|
},
|
|
36
|
-
"main": "dist/index.cjs",
|
|
37
|
-
"module": "dist/index.mjs",
|
|
38
|
-
"types": "dist/index.d.
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.mjs",
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
39
31
|
"typesVersions": {
|
|
40
32
|
"*": {
|
|
41
33
|
"*": [
|
|
42
|
-
"dist
|
|
34
|
+
"./dist/*.d.mts",
|
|
35
|
+
"./dist/*.d.cts",
|
|
43
36
|
"./*"
|
|
44
37
|
]
|
|
45
38
|
}
|
|
@@ -57,9 +50,9 @@
|
|
|
57
50
|
"css-tree": "^3.1.0",
|
|
58
51
|
"postcss": "^8.5.6",
|
|
59
52
|
"tinyglobby": "^0.2.15",
|
|
60
|
-
"@unocss/config": "66.6.
|
|
61
|
-
"@unocss/core": "66.6.
|
|
62
|
-
"@unocss/rule-utils": "66.6.
|
|
53
|
+
"@unocss/config": "66.6.1",
|
|
54
|
+
"@unocss/core": "66.6.1",
|
|
55
|
+
"@unocss/rule-utils": "66.6.1"
|
|
63
56
|
},
|
|
64
57
|
"scripts": {
|
|
65
58
|
"build": "tsdown --config-loader unrun",
|
package/dist/esm.cjs
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
let node_fs_promises = require("node:fs/promises");
|
|
29
|
-
let node_path = require("node:path");
|
|
30
|
-
let node_process = require("node:process");
|
|
31
|
-
node_process = __toESM(node_process);
|
|
32
|
-
let _unocss_core = require("@unocss/core");
|
|
33
|
-
let _unocss_config = require("@unocss/config");
|
|
34
|
-
let _unocss_rule_utils = require("@unocss/rule-utils");
|
|
35
|
-
let postcss = require("postcss");
|
|
36
|
-
postcss = __toESM(postcss);
|
|
37
|
-
let tinyglobby = require("tinyglobby");
|
|
38
|
-
let css_tree = require("css-tree");
|
|
39
|
-
|
|
40
|
-
//#region ../../virtual-shared/integration/src/defaults.ts
|
|
41
|
-
const defaultFilesystemGlobs = ["**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md,marko}"];
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/apply.ts
|
|
45
|
-
async function parseApply(root, uno, directiveName) {
|
|
46
|
-
const promises = [];
|
|
47
|
-
root.walkAtRules(directiveName, (rule) => {
|
|
48
|
-
promises.push((async () => {
|
|
49
|
-
if (!rule.parent) return;
|
|
50
|
-
const source = rule.source;
|
|
51
|
-
const classNames = (0, _unocss_core.expandVariantGroup)(rule.params).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
|
|
52
|
-
const utils = (await Promise.all(classNames.map((i) => uno.parseToken(i, "-")))).filter(_unocss_core.notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
|
|
53
|
-
const target = acc.find((i) => i[1] === item[1] && i[3] === item[3]);
|
|
54
|
-
if (target) target[2] += item[2];
|
|
55
|
-
else acc.push([...item]);
|
|
56
|
-
return acc;
|
|
57
|
-
}, []);
|
|
58
|
-
if (!utils.length) return;
|
|
59
|
-
const parentAfterNodes = [];
|
|
60
|
-
for (const i of utils) {
|
|
61
|
-
const [, _selector, body, parent] = i;
|
|
62
|
-
const selector = (_selector === null || _selector === void 0 ? void 0 : _selector.replace(_unocss_core.regexScopePlaceholder, " ")) || _selector;
|
|
63
|
-
if (parent || selector && selector !== ".\\-" && !selector.startsWith("@property")) {
|
|
64
|
-
const node = (0, css_tree.parse)(rule.parent.toString(), { context: "rule" });
|
|
65
|
-
let newSelector = (0, css_tree.generate)(node.prelude);
|
|
66
|
-
if (selector && selector !== ".\\-") {
|
|
67
|
-
const selectorAST = (0, css_tree.parse)(selector, { context: "selector" });
|
|
68
|
-
const prelude = (0, css_tree.clone)(node.prelude);
|
|
69
|
-
prelude.children.forEach((child) => {
|
|
70
|
-
const parentSelectorAst = (0, css_tree.clone)(selectorAST);
|
|
71
|
-
parentSelectorAst.children.forEach((i$1) => {
|
|
72
|
-
if (i$1.type === "ClassSelector" && i$1.name === "\\-") Object.assign(i$1, (0, css_tree.clone)(child));
|
|
73
|
-
});
|
|
74
|
-
Object.assign(child, parentSelectorAst);
|
|
75
|
-
});
|
|
76
|
-
newSelector = (0, css_tree.generate)(prelude);
|
|
77
|
-
}
|
|
78
|
-
let css = `${newSelector}{${body}}`;
|
|
79
|
-
if (parent) css = `${parent}{${css}}`;
|
|
80
|
-
const css_parsed = postcss.default.parse(css);
|
|
81
|
-
css_parsed.walkDecls((declaration) => {
|
|
82
|
-
declaration.source = source;
|
|
83
|
-
});
|
|
84
|
-
parentAfterNodes.push(...css_parsed.nodes);
|
|
85
|
-
} else {
|
|
86
|
-
const css = postcss.default.parse(body);
|
|
87
|
-
css.walkDecls((declaration) => {
|
|
88
|
-
declaration.source = source;
|
|
89
|
-
});
|
|
90
|
-
rule.parent.insertAfter(rule, css);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
rule.parent.after(parentAfterNodes);
|
|
94
|
-
rule.remove();
|
|
95
|
-
})());
|
|
96
|
-
});
|
|
97
|
-
await Promise.all(promises);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/screen.ts
|
|
102
|
-
async function parseScreen(root, uno, directiveName) {
|
|
103
|
-
root.walkAtRules(directiveName, async (rule) => {
|
|
104
|
-
let breakpointName = "";
|
|
105
|
-
let prefix = "";
|
|
106
|
-
if (rule.params) breakpointName = rule.params.trim();
|
|
107
|
-
if (!breakpointName) return;
|
|
108
|
-
const match = breakpointName.match(/^(?:(lt|at)-)?(\w+)$/);
|
|
109
|
-
if (match) {
|
|
110
|
-
prefix = match[1];
|
|
111
|
-
breakpointName = match[2];
|
|
112
|
-
}
|
|
113
|
-
const resolveBreakpoints = () => {
|
|
114
|
-
const key = uno.config.presets.some((p) => p.name === "@unocss/preset-wind4") ? "breakpoint" : "breakpoints";
|
|
115
|
-
const breakpoints = uno.config.theme[key];
|
|
116
|
-
return breakpoints ? Object.entries(breakpoints).sort((a, b) => Number.parseInt(a[1].replace(/[a-z]+/gi, "")) - Number.parseInt(b[1].replace(/[a-z]+/gi, ""))).map(([point, size]) => ({
|
|
117
|
-
point,
|
|
118
|
-
size
|
|
119
|
-
})) : void 0;
|
|
120
|
-
};
|
|
121
|
-
const variantEntries = (resolveBreakpoints() ?? []).map(({ point, size }, idx) => [
|
|
122
|
-
point,
|
|
123
|
-
size,
|
|
124
|
-
idx
|
|
125
|
-
]);
|
|
126
|
-
const generateMediaQuery = (breakpointName$1, prefix$1) => {
|
|
127
|
-
const [, size, idx] = variantEntries.find((i) => i[0] === breakpointName$1);
|
|
128
|
-
if (prefix$1) if (prefix$1 === "lt") return `(max-width: ${(0, _unocss_rule_utils.calcMaxWidthBySize)(size)})`;
|
|
129
|
-
else if (prefix$1 === "at") return `(min-width: ${size})${variantEntries[idx + 1] ? ` and (max-width: ${(0, _unocss_rule_utils.calcMaxWidthBySize)(variantEntries[idx + 1][1])})` : ""}`;
|
|
130
|
-
else throw new Error(`breakpoint variant not supported: ${prefix$1}`);
|
|
131
|
-
return `(min-width: ${size})`;
|
|
132
|
-
};
|
|
133
|
-
if (!variantEntries.find((i) => i[0] === breakpointName)) throw new Error(`breakpoint ${breakpointName} not found`);
|
|
134
|
-
rule.name = "media";
|
|
135
|
-
rule.params = `${generateMediaQuery(breakpointName, prefix)}`;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/theme.ts
|
|
141
|
-
async function parseTheme(root, uno) {
|
|
142
|
-
root.walkDecls((decl) => {
|
|
143
|
-
decl.value = (0, _unocss_rule_utils.transformThemeFn)(decl.value, uno.config.theme);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/esm.ts
|
|
149
|
-
function createPlugin(options) {
|
|
150
|
-
const { cwd = node_process.default.cwd(), configOrPath } = options;
|
|
151
|
-
const directiveMap = Object.assign({
|
|
152
|
-
apply: "apply",
|
|
153
|
-
theme: "theme",
|
|
154
|
-
screen: "screen",
|
|
155
|
-
unocss: "unocss"
|
|
156
|
-
}, options.directiveMap || {});
|
|
157
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
158
|
-
const fileClassMap = /* @__PURE__ */ new Map();
|
|
159
|
-
const classes = /* @__PURE__ */ new Set();
|
|
160
|
-
const targetCache = /* @__PURE__ */ new Set();
|
|
161
|
-
const loadConfig = (0, _unocss_config.createRecoveryConfigLoader)();
|
|
162
|
-
const config = loadConfig(cwd, configOrPath);
|
|
163
|
-
let uno;
|
|
164
|
-
let promises = [];
|
|
165
|
-
let last_config_mtime = 0;
|
|
166
|
-
const targetRE = new RegExp(Object.values(directiveMap).join("|"));
|
|
167
|
-
return async function plugin(root, result) {
|
|
168
|
-
var _result$opts$from, _uno$config$content, _uno$config$content2;
|
|
169
|
-
const from = (_result$opts$from = result.opts.from) === null || _result$opts$from === void 0 ? void 0 : _result$opts$from.split("?")[0];
|
|
170
|
-
if (!from) return;
|
|
171
|
-
let isTarget = targetCache.has(from);
|
|
172
|
-
const isScanTarget = root.toString().includes(`@${directiveMap.unocss}`);
|
|
173
|
-
if (targetRE.test(root.toString())) {
|
|
174
|
-
if (!isTarget) {
|
|
175
|
-
root.walkAtRules((rule) => {
|
|
176
|
-
if (rule.name === directiveMap.unocss || rule.name === directiveMap.apply || rule.name === directiveMap.screen) isTarget = true;
|
|
177
|
-
if (isTarget) return false;
|
|
178
|
-
});
|
|
179
|
-
if (!isTarget) root.walkDecls((decl) => {
|
|
180
|
-
if ((0, _unocss_rule_utils.hasThemeFn)(decl.value)) {
|
|
181
|
-
isTarget = true;
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
else targetCache.add(from);
|
|
186
|
-
}
|
|
187
|
-
} else if (targetCache.has(from)) targetCache.delete(from);
|
|
188
|
-
if (!isTarget) return;
|
|
189
|
-
try {
|
|
190
|
-
const cfg = await config;
|
|
191
|
-
if (!uno) uno = await (0, _unocss_core.createGenerator)(cfg.config);
|
|
192
|
-
else if (cfg.sources.length) {
|
|
193
|
-
const config_mtime = (await (0, node_fs_promises.stat)(cfg.sources[0])).mtimeMs;
|
|
194
|
-
if (config_mtime > last_config_mtime) {
|
|
195
|
-
uno = await (0, _unocss_core.createGenerator)((await loadConfig()).config);
|
|
196
|
-
last_config_mtime = config_mtime;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} catch (error) {
|
|
200
|
-
throw new Error(`UnoCSS config not found: ${error.message}`);
|
|
201
|
-
}
|
|
202
|
-
const globs = ((_uno$config$content = uno.config.content) === null || _uno$config$content === void 0 ? void 0 : _uno$config$content.filesystem) ?? defaultFilesystemGlobs;
|
|
203
|
-
const needCheckNodeMoudules = globs.some((i) => i.includes("node_modules"));
|
|
204
|
-
const plainContent = ((_uno$config$content2 = uno.config.content) === null || _uno$config$content2 === void 0 ? void 0 : _uno$config$content2.inline) ?? [];
|
|
205
|
-
const entries = await (0, tinyglobby.glob)(isScanTarget ? globs : [from], {
|
|
206
|
-
cwd,
|
|
207
|
-
absolute: true,
|
|
208
|
-
ignore: needCheckNodeMoudules ? void 0 : ["**/node_modules/**"],
|
|
209
|
-
expandDirectories: false
|
|
210
|
-
});
|
|
211
|
-
await parseApply(root, uno, directiveMap.apply);
|
|
212
|
-
await parseTheme(root, uno);
|
|
213
|
-
await parseScreen(root, uno, directiveMap.screen);
|
|
214
|
-
promises.push(...plainContent.map(async (c$1, idx) => {
|
|
215
|
-
if (typeof c$1 === "function") c$1 = await c$1();
|
|
216
|
-
if (typeof c$1 === "string") c$1 = { code: c$1 };
|
|
217
|
-
const { matched } = await uno.generate(c$1.code, { id: c$1.id ?? `__plain_content_${idx}__` });
|
|
218
|
-
for (const candidate of matched) classes.add(candidate);
|
|
219
|
-
}));
|
|
220
|
-
await Promise.all(promises);
|
|
221
|
-
promises = [];
|
|
222
|
-
const BATCH_SIZE = 500;
|
|
223
|
-
for (let i = 0; i < entries.length; i += BATCH_SIZE) {
|
|
224
|
-
const batch = entries.slice(i, i + BATCH_SIZE);
|
|
225
|
-
promises.push(...batch.map(async (file) => {
|
|
226
|
-
result.messages.push({
|
|
227
|
-
type: "dependency",
|
|
228
|
-
plugin: directiveMap.unocss,
|
|
229
|
-
file: (0, node_path.normalize)(file),
|
|
230
|
-
parent: from
|
|
231
|
-
});
|
|
232
|
-
const { mtimeMs } = await (0, node_fs_promises.stat)(file);
|
|
233
|
-
if (fileMap.has(file) && mtimeMs <= fileMap.get(file)) return;
|
|
234
|
-
fileMap.set(file, mtimeMs);
|
|
235
|
-
const content = await (0, node_fs_promises.readFile)(file, "utf8");
|
|
236
|
-
const { matched } = await uno.generate(content, { id: file });
|
|
237
|
-
fileClassMap.set(file, matched);
|
|
238
|
-
}));
|
|
239
|
-
await Promise.all(promises);
|
|
240
|
-
promises = [];
|
|
241
|
-
}
|
|
242
|
-
for (const set of fileClassMap.values()) for (const candidate of set) classes.add(candidate);
|
|
243
|
-
const c = await uno.generate(classes);
|
|
244
|
-
classes.clear();
|
|
245
|
-
const excludes = [];
|
|
246
|
-
root.walkAtRules(directiveMap.unocss, (rule) => {
|
|
247
|
-
const source = rule.source;
|
|
248
|
-
if (rule.params) {
|
|
249
|
-
const excludeLayers = [];
|
|
250
|
-
const includeLayers = [];
|
|
251
|
-
for (const layer of rule.params.split(",")) {
|
|
252
|
-
const name = layer.trim();
|
|
253
|
-
if (!name) continue;
|
|
254
|
-
if (name.startsWith("!")) {
|
|
255
|
-
if (name.slice(1)) excludeLayers.push(name.slice(1));
|
|
256
|
-
} else includeLayers.push(name);
|
|
257
|
-
}
|
|
258
|
-
if (excludeLayers.length > 0 && includeLayers.length > 0) console.warn(`Warning: Mixing normal and negated layer names in "@${directiveMap.unocss} ${rule.params}" is not recommended.`);
|
|
259
|
-
let result$1 = "";
|
|
260
|
-
if (includeLayers.length > 0) {
|
|
261
|
-
result$1 = includeLayers.map((i) => (i === "all" ? c.getLayers() : c.getLayer(i)) || "").filter(Boolean).join("\n");
|
|
262
|
-
excludes.push(...includeLayers);
|
|
263
|
-
} else if (excludeLayers.length > 0) {
|
|
264
|
-
result$1 = c.getLayers(void 0, excludeLayers) || "";
|
|
265
|
-
excludes.push(...excludeLayers);
|
|
266
|
-
}
|
|
267
|
-
const css = postcss.default.parse(result$1);
|
|
268
|
-
css.walkDecls((declaration) => {
|
|
269
|
-
declaration.source = source;
|
|
270
|
-
});
|
|
271
|
-
rule.replaceWith(css);
|
|
272
|
-
} else {
|
|
273
|
-
const css = postcss.default.parse(c.getLayers(void 0, excludes) || "");
|
|
274
|
-
css.walkDecls((declaration) => {
|
|
275
|
-
declaration.source = source;
|
|
276
|
-
});
|
|
277
|
-
rule.replaceWith(css);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
//#endregion
|
|
284
|
-
exports.createPlugin = createPlugin;
|