@unocss/postcss 66.1.2 → 66.1.4

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.
Files changed (2) hide show
  1. package/dist/esm.mjs +29 -18
  2. package/package.json +4 -4
package/dist/esm.mjs CHANGED
@@ -3,7 +3,7 @@ import { normalize } from 'node:path';
3
3
  import process from 'node:process';
4
4
  import { expandVariantGroup, notNull, regexScopePlaceholder, createGenerator } from '@unocss/core';
5
5
  import { createRecoveryConfigLoader } from '@unocss/config';
6
- import { transformThemeFn, hasThemeFn } from '@unocss/rule-utils';
6
+ import { calcMaxWidthBySize, transformThemeFn, hasThemeFn } from '@unocss/rule-utils';
7
7
  import postcss from 'postcss';
8
8
  import { glob } from 'tinyglobby';
9
9
  import { parse, generate, clone } from 'css-tree';
@@ -118,12 +118,6 @@ async function parseScreen(root, uno, directiveName) {
118
118
  rule.params = `${generateMediaQuery(breakpointName, prefix)}`;
119
119
  });
120
120
  }
121
- function calcMaxWidthBySize(size) {
122
- const value = size.match(/^-?\d+\.?\d*/)?.[0] || "";
123
- const unit = size.slice(value.length);
124
- const maxWidth = Number.parseFloat(value) - 0.1;
125
- return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
126
- }
127
121
 
128
122
  async function parseTheme(root, uno) {
129
123
  root.walkDecls((decl) => {
@@ -253,22 +247,39 @@ function createPlugin(options) {
253
247
  classes.clear();
254
248
  const excludes = [];
255
249
  root.walkAtRules(directiveMap.unocss, (rule) => {
250
+ const source = rule.source;
256
251
  if (rule.params) {
257
- const source = rule.source;
258
- const layers = rule.params.split(",").map((v) => v.trim());
259
- const css = postcss.parse(
260
- layers.map((i) => (i === "all" ? c.getLayers() : c.getLayer(i)) || "").filter(Boolean).join("\n")
261
- );
252
+ const excludeLayers = [];
253
+ const includeLayers = [];
254
+ for (const layer of rule.params.split(",")) {
255
+ const name = layer.trim();
256
+ if (!name)
257
+ continue;
258
+ if (name.startsWith("!")) {
259
+ if (name.slice(1)) {
260
+ excludeLayers.push(name.slice(1));
261
+ }
262
+ } else {
263
+ includeLayers.push(name);
264
+ }
265
+ }
266
+ if (excludeLayers.length > 0 && includeLayers.length > 0) {
267
+ console.warn(`Warning: Mixing normal and negated layer names in "@${directiveMap.unocss} ${rule.params}" is not recommended.`);
268
+ }
269
+ let result2 = "";
270
+ if (includeLayers.length > 0) {
271
+ result2 = includeLayers.map((i) => (i === "all" ? c.getLayers() : c.getLayer(i)) || "").filter(Boolean).join("\n");
272
+ excludes.push(...includeLayers);
273
+ } else if (excludeLayers.length > 0) {
274
+ result2 = c.getLayers(void 0, excludeLayers) || "";
275
+ excludes.push(...excludeLayers);
276
+ }
277
+ const css = postcss.parse(result2);
262
278
  css.walkDecls((declaration) => {
263
279
  declaration.source = source;
264
280
  });
265
281
  rule.replaceWith(css);
266
- excludes.push(rule.params);
267
- }
268
- });
269
- root.walkAtRules(directiveMap.unocss, (rule) => {
270
- if (!rule.params) {
271
- const source = rule.source;
282
+ } else {
272
283
  const css = postcss.parse(c.getLayers(void 0, excludes) || "");
273
284
  css.walkDecls((declaration) => {
274
285
  declaration.source = source;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/postcss",
3
3
  "type": "module",
4
- "version": "66.1.2",
4
+ "version": "66.1.4",
5
5
  "description": "PostCSS plugin for UnoCSS",
6
6
  "author": "sibbng <sibbngheid@gmail.com>",
7
7
  "license": "MIT",
@@ -57,9 +57,9 @@
57
57
  "css-tree": "^3.1.0",
58
58
  "postcss": "^8.5.3",
59
59
  "tinyglobby": "^0.2.13",
60
- "@unocss/config": "66.1.2",
61
- "@unocss/core": "66.1.2",
62
- "@unocss/rule-utils": "66.1.2"
60
+ "@unocss/config": "66.1.4",
61
+ "@unocss/core": "66.1.4",
62
+ "@unocss/rule-utils": "66.1.4"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "unbuild",