@unocss/postcss 0.50.0 → 0.50.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.cjs +133 -87
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +133 -87
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
|
16
16
|
|
|
17
17
|
const defaultIncludeGlobs = ["**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}"];
|
|
18
18
|
|
|
19
|
-
function parseApply(root, uno, directiveName) {
|
|
19
|
+
async function parseApply(root, uno, directiveName) {
|
|
20
20
|
root.walkAtRules(directiveName, async (rule) => {
|
|
21
21
|
if (!rule.parent)
|
|
22
22
|
return;
|
|
@@ -77,10 +77,10 @@ function parseApply(root, uno, directiveName) {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const themeFnRE = (directiveName) => new RegExp(`${directiveName}\\((.*?)\\)`, "g");
|
|
81
|
+
async function parseTheme(root, uno, directiveName) {
|
|
82
82
|
root.walkDecls((decl) => {
|
|
83
|
-
const matches = Array.from(decl.value.matchAll(themeFnRE));
|
|
83
|
+
const matches = Array.from(decl.value.matchAll(themeFnRE(directiveName)));
|
|
84
84
|
if (!matches.length)
|
|
85
85
|
return;
|
|
86
86
|
for (const match of matches) {
|
|
@@ -111,7 +111,7 @@ function parseTheme(root, uno, directiveName) {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
function parseScreen(root, uno, directiveName) {
|
|
114
|
+
async function parseScreen(root, uno, directiveName) {
|
|
115
115
|
root.walkAtRules(directiveName, async (rule) => {
|
|
116
116
|
let breakpointName = "";
|
|
117
117
|
let prefix = "";
|
|
@@ -158,105 +158,151 @@ function calcMaxWidthBySize(size) {
|
|
|
158
158
|
return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
function unocss(
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
function unocss(options = {}) {
|
|
162
|
+
core.warnOnce(
|
|
163
|
+
"`@unocss/postcss` package is in an experimental state right now. It doesn't follow semver, and may introduce breaking changes in patch versions."
|
|
164
|
+
);
|
|
165
|
+
const {
|
|
166
|
+
cwd = process.cwd(),
|
|
167
|
+
directiveMap = {
|
|
168
|
+
apply: "apply",
|
|
169
|
+
theme: "theme",
|
|
170
|
+
screen: "screen",
|
|
171
|
+
unocss: "unocss"
|
|
172
|
+
},
|
|
173
|
+
content,
|
|
174
|
+
configOrPath
|
|
175
|
+
} = options;
|
|
164
176
|
const fileMap = /* @__PURE__ */ new Map();
|
|
165
177
|
const fileClassMap = /* @__PURE__ */ new Map();
|
|
166
178
|
const classes = /* @__PURE__ */ new Set();
|
|
179
|
+
const targetCache = /* @__PURE__ */ new Set();
|
|
167
180
|
const config$1 = config.loadConfig(cwd, configOrPath);
|
|
168
181
|
let uno;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
);
|
|
182
|
+
let promises$1 = [];
|
|
183
|
+
let last_config_mtime = 0;
|
|
184
|
+
const targetRE = new RegExp(Object.values(directiveMap).join("|"));
|
|
172
185
|
return {
|
|
173
|
-
postcssPlugin:
|
|
186
|
+
postcssPlugin: directiveMap.unocss,
|
|
174
187
|
plugins: [
|
|
175
188
|
async function(root, result) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
if (!result.opts.from?.split("?")[0].endsWith(".css"))
|
|
190
|
+
return;
|
|
191
|
+
let isTarget = false;
|
|
192
|
+
if (targetRE.test(root.toString())) {
|
|
193
|
+
if (!targetCache.has(result.opts.from)) {
|
|
194
|
+
root.walkAtRules((rule) => {
|
|
195
|
+
if (rule.name === directiveMap.unocss || rule.name === directiveMap.apply || rule.name === directiveMap.theme || rule.name === directiveMap.screen)
|
|
196
|
+
isTarget = true;
|
|
197
|
+
});
|
|
198
|
+
if (!isTarget) {
|
|
199
|
+
const themeFn = themeFnRE(directiveMap.theme);
|
|
200
|
+
root.walkDecls((decl) => {
|
|
201
|
+
if (themeFn.test(decl.value))
|
|
202
|
+
isTarget = true;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
isTarget = true;
|
|
207
|
+
}
|
|
208
|
+
} else if (targetCache.has(result.opts.from)) {
|
|
209
|
+
targetCache.delete(result.opts.from);
|
|
210
|
+
}
|
|
211
|
+
if (!isTarget)
|
|
212
|
+
return;
|
|
213
|
+
else
|
|
214
|
+
targetCache.add(result.opts.from);
|
|
215
|
+
try {
|
|
216
|
+
const cfg = await config$1;
|
|
217
|
+
if (!uno) {
|
|
218
|
+
uno = core.createGenerator(cfg.config);
|
|
219
|
+
} else if (cfg.sources.length) {
|
|
220
|
+
const config_mtime = (await promises.stat(cfg.sources[0])).mtimeMs;
|
|
221
|
+
if (config_mtime > last_config_mtime) {
|
|
222
|
+
uno = core.createGenerator((await config.loadConfig(cwd, configOrPath)).config);
|
|
223
|
+
last_config_mtime = config_mtime;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
throw new Error(`UnoCSS config not found: ${error.message}`);
|
|
228
|
+
}
|
|
184
229
|
const globs = content?.filter((v) => typeof v === "string") ?? defaultIncludeGlobs;
|
|
185
230
|
const rawContent = content?.filter((v) => typeof v === "object") ?? [];
|
|
186
231
|
const entries = await fg__default(globs, {
|
|
187
232
|
cwd,
|
|
188
233
|
dot: true,
|
|
189
234
|
absolute: true,
|
|
190
|
-
ignore: ["**/{.git,node_modules}/**"]
|
|
235
|
+
ignore: ["**/{.git,node_modules}/**"],
|
|
236
|
+
stats: true
|
|
191
237
|
});
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}),
|
|
208
|
-
...entries.map(async (file) => {
|
|
209
|
-
result.messages.push({
|
|
210
|
-
type: "dependency",
|
|
211
|
-
plugin: "unocss",
|
|
212
|
-
file,
|
|
213
|
-
parent: result.opts.from
|
|
214
|
-
});
|
|
215
|
-
const { mtimeMs } = await promises.stat(file);
|
|
216
|
-
if (fileMap.has(file) && mtimeMs <= fileMap.get(file))
|
|
217
|
-
return;
|
|
218
|
-
else
|
|
219
|
-
fileMap.set(file, mtimeMs);
|
|
220
|
-
const content2 = await promises.readFile(file, "utf8");
|
|
221
|
-
const { matched } = await uno.generate(content2, {
|
|
222
|
-
id: file
|
|
223
|
-
});
|
|
224
|
-
fileClassMap.set(file, matched);
|
|
225
|
-
})
|
|
226
|
-
]
|
|
227
|
-
);
|
|
228
|
-
for (const set of fileClassMap.values()) {
|
|
229
|
-
for (const candidate of set)
|
|
238
|
+
result.messages.push({
|
|
239
|
+
type: "dependency",
|
|
240
|
+
plugin: directiveMap.unocss,
|
|
241
|
+
file: result.opts.from,
|
|
242
|
+
parent: result.opts.from
|
|
243
|
+
});
|
|
244
|
+
await parseApply(root, uno, directiveMap.apply);
|
|
245
|
+
await parseTheme(root, uno, directiveMap.theme);
|
|
246
|
+
await parseScreen(root, uno, directiveMap.screen);
|
|
247
|
+
promises$1.push(
|
|
248
|
+
...rawContent.map(async (v) => {
|
|
249
|
+
const { matched } = await uno.generate(v.raw, {
|
|
250
|
+
id: `unocss.${v.extension}`
|
|
251
|
+
});
|
|
252
|
+
for (const candidate of matched)
|
|
230
253
|
classes.add(candidate);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
});
|
|
256
|
-
rule.replaceWith(css);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
254
|
+
}),
|
|
255
|
+
...entries.map(async ({ path: file, mtimeMs }) => {
|
|
256
|
+
result.messages.push({
|
|
257
|
+
type: "dependency",
|
|
258
|
+
plugin: directiveMap.unocss,
|
|
259
|
+
file,
|
|
260
|
+
parent: result.opts.from
|
|
261
|
+
});
|
|
262
|
+
if (fileMap.has(file) && mtimeMs <= fileMap.get(file))
|
|
263
|
+
return;
|
|
264
|
+
else
|
|
265
|
+
fileMap.set(file, mtimeMs);
|
|
266
|
+
const content2 = await promises.readFile(file, "utf8");
|
|
267
|
+
const { matched } = await uno.generate(content2, {
|
|
268
|
+
id: file
|
|
269
|
+
});
|
|
270
|
+
fileClassMap.set(file, matched);
|
|
271
|
+
})
|
|
272
|
+
);
|
|
273
|
+
await Promise.all(promises$1);
|
|
274
|
+
promises$1 = [];
|
|
275
|
+
for (const set of fileClassMap.values()) {
|
|
276
|
+
for (const candidate of set)
|
|
277
|
+
classes.add(candidate);
|
|
259
278
|
}
|
|
279
|
+
const c = await uno.generate(classes);
|
|
280
|
+
classes.clear();
|
|
281
|
+
const excludes = [];
|
|
282
|
+
root.walkAtRules(directiveMap.unocss, (rule) => {
|
|
283
|
+
if (rule.params) {
|
|
284
|
+
const source = rule.source;
|
|
285
|
+
const layers = rule.params.split(",").map((v) => v.trim());
|
|
286
|
+
const css = postcss__default.parse(
|
|
287
|
+
layers.map((i) => (i === "all" ? c.getLayers() : c.getLayer(i)) || "").filter(Boolean).join("\n")
|
|
288
|
+
);
|
|
289
|
+
css.walkDecls((declaration) => {
|
|
290
|
+
declaration.source = source;
|
|
291
|
+
});
|
|
292
|
+
rule.replaceWith(css);
|
|
293
|
+
excludes.push(rule.params);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
root.walkAtRules(directiveMap.unocss, (rule) => {
|
|
297
|
+
if (!rule.params) {
|
|
298
|
+
const source = rule.source;
|
|
299
|
+
const css = postcss__default.parse(c.getLayers(void 0, excludes) || "");
|
|
300
|
+
css.walkDecls((declaration) => {
|
|
301
|
+
declaration.source = source;
|
|
302
|
+
});
|
|
303
|
+
rule.replaceWith(css);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
260
306
|
}
|
|
261
307
|
]
|
|
262
308
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -10,12 +10,13 @@ interface UnoPostcssPluginOptions {
|
|
|
10
10
|
apply: string;
|
|
11
11
|
screen: string;
|
|
12
12
|
theme: string;
|
|
13
|
+
unocss: string;
|
|
13
14
|
};
|
|
14
15
|
cwd?: string;
|
|
15
16
|
configOrPath?: string | UserConfig;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
declare function unocss(
|
|
19
|
+
declare function unocss(options?: UnoPostcssPluginOptions): {
|
|
19
20
|
postcssPlugin: string;
|
|
20
21
|
plugins: ((root: Root, result: Result) => Promise<void>)[];
|
|
21
22
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import MagicString from 'magic-string';
|
|
|
8
8
|
|
|
9
9
|
const defaultIncludeGlobs = ["**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}"];
|
|
10
10
|
|
|
11
|
-
function parseApply(root, uno, directiveName) {
|
|
11
|
+
async function parseApply(root, uno, directiveName) {
|
|
12
12
|
root.walkAtRules(directiveName, async (rule) => {
|
|
13
13
|
if (!rule.parent)
|
|
14
14
|
return;
|
|
@@ -69,10 +69,10 @@ function parseApply(root, uno, directiveName) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const themeFnRE = (directiveName) => new RegExp(`${directiveName}\\((.*?)\\)`, "g");
|
|
73
|
+
async function parseTheme(root, uno, directiveName) {
|
|
74
74
|
root.walkDecls((decl) => {
|
|
75
|
-
const matches = Array.from(decl.value.matchAll(themeFnRE));
|
|
75
|
+
const matches = Array.from(decl.value.matchAll(themeFnRE(directiveName)));
|
|
76
76
|
if (!matches.length)
|
|
77
77
|
return;
|
|
78
78
|
for (const match of matches) {
|
|
@@ -103,7 +103,7 @@ function parseTheme(root, uno, directiveName) {
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function parseScreen(root, uno, directiveName) {
|
|
106
|
+
async function parseScreen(root, uno, directiveName) {
|
|
107
107
|
root.walkAtRules(directiveName, async (rule) => {
|
|
108
108
|
let breakpointName = "";
|
|
109
109
|
let prefix = "";
|
|
@@ -150,105 +150,151 @@ function calcMaxWidthBySize(size) {
|
|
|
150
150
|
return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function unocss(
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
function unocss(options = {}) {
|
|
154
|
+
warnOnce(
|
|
155
|
+
"`@unocss/postcss` package is in an experimental state right now. It doesn't follow semver, and may introduce breaking changes in patch versions."
|
|
156
|
+
);
|
|
157
|
+
const {
|
|
158
|
+
cwd = process.cwd(),
|
|
159
|
+
directiveMap = {
|
|
160
|
+
apply: "apply",
|
|
161
|
+
theme: "theme",
|
|
162
|
+
screen: "screen",
|
|
163
|
+
unocss: "unocss"
|
|
164
|
+
},
|
|
165
|
+
content,
|
|
166
|
+
configOrPath
|
|
167
|
+
} = options;
|
|
156
168
|
const fileMap = /* @__PURE__ */ new Map();
|
|
157
169
|
const fileClassMap = /* @__PURE__ */ new Map();
|
|
158
170
|
const classes = /* @__PURE__ */ new Set();
|
|
171
|
+
const targetCache = /* @__PURE__ */ new Set();
|
|
159
172
|
const config = loadConfig(cwd, configOrPath);
|
|
160
173
|
let uno;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
174
|
+
let promises = [];
|
|
175
|
+
let last_config_mtime = 0;
|
|
176
|
+
const targetRE = new RegExp(Object.values(directiveMap).join("|"));
|
|
164
177
|
return {
|
|
165
|
-
postcssPlugin:
|
|
178
|
+
postcssPlugin: directiveMap.unocss,
|
|
166
179
|
plugins: [
|
|
167
180
|
async function(root, result) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
181
|
+
if (!result.opts.from?.split("?")[0].endsWith(".css"))
|
|
182
|
+
return;
|
|
183
|
+
let isTarget = false;
|
|
184
|
+
if (targetRE.test(root.toString())) {
|
|
185
|
+
if (!targetCache.has(result.opts.from)) {
|
|
186
|
+
root.walkAtRules((rule) => {
|
|
187
|
+
if (rule.name === directiveMap.unocss || rule.name === directiveMap.apply || rule.name === directiveMap.theme || rule.name === directiveMap.screen)
|
|
188
|
+
isTarget = true;
|
|
189
|
+
});
|
|
190
|
+
if (!isTarget) {
|
|
191
|
+
const themeFn = themeFnRE(directiveMap.theme);
|
|
192
|
+
root.walkDecls((decl) => {
|
|
193
|
+
if (themeFn.test(decl.value))
|
|
194
|
+
isTarget = true;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
isTarget = true;
|
|
199
|
+
}
|
|
200
|
+
} else if (targetCache.has(result.opts.from)) {
|
|
201
|
+
targetCache.delete(result.opts.from);
|
|
202
|
+
}
|
|
203
|
+
if (!isTarget)
|
|
204
|
+
return;
|
|
205
|
+
else
|
|
206
|
+
targetCache.add(result.opts.from);
|
|
207
|
+
try {
|
|
208
|
+
const cfg = await config;
|
|
209
|
+
if (!uno) {
|
|
210
|
+
uno = createGenerator(cfg.config);
|
|
211
|
+
} else if (cfg.sources.length) {
|
|
212
|
+
const config_mtime = (await stat(cfg.sources[0])).mtimeMs;
|
|
213
|
+
if (config_mtime > last_config_mtime) {
|
|
214
|
+
uno = createGenerator((await loadConfig(cwd, configOrPath)).config);
|
|
215
|
+
last_config_mtime = config_mtime;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
throw new Error(`UnoCSS config not found: ${error.message}`);
|
|
220
|
+
}
|
|
176
221
|
const globs = content?.filter((v) => typeof v === "string") ?? defaultIncludeGlobs;
|
|
177
222
|
const rawContent = content?.filter((v) => typeof v === "object") ?? [];
|
|
178
223
|
const entries = await fg(globs, {
|
|
179
224
|
cwd,
|
|
180
225
|
dot: true,
|
|
181
226
|
absolute: true,
|
|
182
|
-
ignore: ["**/{.git,node_modules}/**"]
|
|
227
|
+
ignore: ["**/{.git,node_modules}/**"],
|
|
228
|
+
stats: true
|
|
183
229
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}),
|
|
200
|
-
...entries.map(async (file) => {
|
|
201
|
-
result.messages.push({
|
|
202
|
-
type: "dependency",
|
|
203
|
-
plugin: "unocss",
|
|
204
|
-
file,
|
|
205
|
-
parent: result.opts.from
|
|
206
|
-
});
|
|
207
|
-
const { mtimeMs } = await stat(file);
|
|
208
|
-
if (fileMap.has(file) && mtimeMs <= fileMap.get(file))
|
|
209
|
-
return;
|
|
210
|
-
else
|
|
211
|
-
fileMap.set(file, mtimeMs);
|
|
212
|
-
const content2 = await readFile(file, "utf8");
|
|
213
|
-
const { matched } = await uno.generate(content2, {
|
|
214
|
-
id: file
|
|
215
|
-
});
|
|
216
|
-
fileClassMap.set(file, matched);
|
|
217
|
-
})
|
|
218
|
-
]
|
|
219
|
-
);
|
|
220
|
-
for (const set of fileClassMap.values()) {
|
|
221
|
-
for (const candidate of set)
|
|
230
|
+
result.messages.push({
|
|
231
|
+
type: "dependency",
|
|
232
|
+
plugin: directiveMap.unocss,
|
|
233
|
+
file: result.opts.from,
|
|
234
|
+
parent: result.opts.from
|
|
235
|
+
});
|
|
236
|
+
await parseApply(root, uno, directiveMap.apply);
|
|
237
|
+
await parseTheme(root, uno, directiveMap.theme);
|
|
238
|
+
await parseScreen(root, uno, directiveMap.screen);
|
|
239
|
+
promises.push(
|
|
240
|
+
...rawContent.map(async (v) => {
|
|
241
|
+
const { matched } = await uno.generate(v.raw, {
|
|
242
|
+
id: `unocss.${v.extension}`
|
|
243
|
+
});
|
|
244
|
+
for (const candidate of matched)
|
|
222
245
|
classes.add(candidate);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
248
|
-
rule.replaceWith(css);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
246
|
+
}),
|
|
247
|
+
...entries.map(async ({ path: file, mtimeMs }) => {
|
|
248
|
+
result.messages.push({
|
|
249
|
+
type: "dependency",
|
|
250
|
+
plugin: directiveMap.unocss,
|
|
251
|
+
file,
|
|
252
|
+
parent: result.opts.from
|
|
253
|
+
});
|
|
254
|
+
if (fileMap.has(file) && mtimeMs <= fileMap.get(file))
|
|
255
|
+
return;
|
|
256
|
+
else
|
|
257
|
+
fileMap.set(file, mtimeMs);
|
|
258
|
+
const content2 = await readFile(file, "utf8");
|
|
259
|
+
const { matched } = await uno.generate(content2, {
|
|
260
|
+
id: file
|
|
261
|
+
});
|
|
262
|
+
fileClassMap.set(file, matched);
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
await Promise.all(promises);
|
|
266
|
+
promises = [];
|
|
267
|
+
for (const set of fileClassMap.values()) {
|
|
268
|
+
for (const candidate of set)
|
|
269
|
+
classes.add(candidate);
|
|
251
270
|
}
|
|
271
|
+
const c = await uno.generate(classes);
|
|
272
|
+
classes.clear();
|
|
273
|
+
const excludes = [];
|
|
274
|
+
root.walkAtRules(directiveMap.unocss, (rule) => {
|
|
275
|
+
if (rule.params) {
|
|
276
|
+
const source = rule.source;
|
|
277
|
+
const layers = rule.params.split(",").map((v) => v.trim());
|
|
278
|
+
const css = postcss.parse(
|
|
279
|
+
layers.map((i) => (i === "all" ? c.getLayers() : c.getLayer(i)) || "").filter(Boolean).join("\n")
|
|
280
|
+
);
|
|
281
|
+
css.walkDecls((declaration) => {
|
|
282
|
+
declaration.source = source;
|
|
283
|
+
});
|
|
284
|
+
rule.replaceWith(css);
|
|
285
|
+
excludes.push(rule.params);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
root.walkAtRules(directiveMap.unocss, (rule) => {
|
|
289
|
+
if (!rule.params) {
|
|
290
|
+
const source = rule.source;
|
|
291
|
+
const css = postcss.parse(c.getLayers(void 0, excludes) || "");
|
|
292
|
+
css.walkDecls((declaration) => {
|
|
293
|
+
declaration.source = source;
|
|
294
|
+
});
|
|
295
|
+
rule.replaceWith(css);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
252
298
|
}
|
|
253
299
|
]
|
|
254
300
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/postcss",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.2",
|
|
4
4
|
"description": "PostCSS plugin for UnoCSS",
|
|
5
5
|
"author": "sibbng <sibbngheid@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"postcss": "^8.4.21"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@unocss/config": "0.50.
|
|
40
|
-
"@unocss/core": "0.50.
|
|
39
|
+
"@unocss/config": "0.50.2",
|
|
40
|
+
"@unocss/core": "0.50.2",
|
|
41
41
|
"css-tree": "^2.3.1",
|
|
42
42
|
"fast-glob": "^3.2.12",
|
|
43
|
-
"magic-string": "^0.
|
|
43
|
+
"magic-string": "^0.30.0",
|
|
44
44
|
"postcss": "^8.4.21"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|