@unocss/postcss 0.56.5 → 0.57.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.cjs +7 -46
- package/dist/index.mjs +7 -45
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -7,16 +7,14 @@ const fg = require('fast-glob');
|
|
|
7
7
|
const postcss = require('postcss');
|
|
8
8
|
const core = require('@unocss/core');
|
|
9
9
|
const config = require('@unocss/config');
|
|
10
|
-
const cssTree = require('css-tree');
|
|
11
10
|
const ruleUtils = require('@unocss/rule-utils');
|
|
12
|
-
const
|
|
11
|
+
const cssTree = require('css-tree');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
14
|
|
|
16
15
|
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
17
16
|
const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
|
|
18
17
|
const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
19
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
20
18
|
|
|
21
19
|
const defaultFilesystemGlobs = [
|
|
22
20
|
"**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}"
|
|
@@ -85,45 +83,9 @@ async function parseApply(root, uno, directiveName) {
|
|
|
85
83
|
});
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
function
|
|
89
|
-
return new RegExp(`${directiveName}\\((.*?)\\)`, "g");
|
|
90
|
-
}
|
|
91
|
-
async function parseTheme(root, uno, directiveName) {
|
|
86
|
+
async function parseTheme(root, uno) {
|
|
92
87
|
root.walkDecls((decl) => {
|
|
93
|
-
|
|
94
|
-
if (!matches.length)
|
|
95
|
-
return;
|
|
96
|
-
for (const match of matches) {
|
|
97
|
-
const rawArg = match[1].trim();
|
|
98
|
-
if (!rawArg)
|
|
99
|
-
throw new Error(`${directiveName}() expect exact one argument, but got 0`);
|
|
100
|
-
const [rawKey, alpha] = rawArg.slice(1, -1).split("/");
|
|
101
|
-
let value = uno.config.theme;
|
|
102
|
-
const keys = rawKey.trim().split(".");
|
|
103
|
-
keys.every((key) => {
|
|
104
|
-
if (value[key] != null)
|
|
105
|
-
value = value[key];
|
|
106
|
-
else if (value[+key] != null)
|
|
107
|
-
value = value[+key];
|
|
108
|
-
else
|
|
109
|
-
return false;
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
112
|
-
if (typeof value === "string") {
|
|
113
|
-
if (alpha) {
|
|
114
|
-
const color = ruleUtils.parseCssColor(value);
|
|
115
|
-
if (color)
|
|
116
|
-
value = ruleUtils.colorToString(color, alpha);
|
|
117
|
-
}
|
|
118
|
-
const code = new MagicString__default(decl.value);
|
|
119
|
-
code.overwrite(
|
|
120
|
-
match.index,
|
|
121
|
-
match.index + match[0].length,
|
|
122
|
-
value
|
|
123
|
-
);
|
|
124
|
-
decl.value = code.toString();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
88
|
+
decl.value = ruleUtils.transformThemeFn(decl.value, uno.config.theme);
|
|
127
89
|
});
|
|
128
90
|
}
|
|
129
91
|
|
|
@@ -146,9 +108,9 @@ async function parseScreen(root, uno, directiveName) {
|
|
|
146
108
|
breakpoints = uno.userConfig.theme.breakpoints;
|
|
147
109
|
if (!breakpoints)
|
|
148
110
|
breakpoints = uno.config.theme.breakpoints;
|
|
149
|
-
return breakpoints;
|
|
111
|
+
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]) => ({ point, size })) : void 0;
|
|
150
112
|
};
|
|
151
|
-
const variantEntries =
|
|
113
|
+
const variantEntries = (resolveBreakpoints() ?? []).map(({ point, size }, idx) => [point, size, idx]);
|
|
152
114
|
const generateMediaQuery = (breakpointName2, prefix2) => {
|
|
153
115
|
const [, size, idx] = variantEntries.find((i) => i[0] === breakpointName2);
|
|
154
116
|
if (prefix2) {
|
|
@@ -212,9 +174,8 @@ function unocss(options = {}) {
|
|
|
212
174
|
return false;
|
|
213
175
|
});
|
|
214
176
|
if (!isTarget) {
|
|
215
|
-
const themeFn = themeFnRE(directiveMap.theme);
|
|
216
177
|
root.walkDecls((decl) => {
|
|
217
|
-
if (
|
|
178
|
+
if (ruleUtils.hasThemeFn(decl.value)) {
|
|
218
179
|
isTarget = true;
|
|
219
180
|
return false;
|
|
220
181
|
}
|
|
@@ -251,7 +212,7 @@ function unocss(options = {}) {
|
|
|
251
212
|
stats: true
|
|
252
213
|
});
|
|
253
214
|
await parseApply(root, uno, directiveMap.apply);
|
|
254
|
-
await parseTheme(root, uno
|
|
215
|
+
await parseTheme(root, uno);
|
|
255
216
|
await parseScreen(root, uno, directiveMap.screen);
|
|
256
217
|
promises$1.push(
|
|
257
218
|
...plainContent.map(async (c2, idx) => {
|
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,8 @@ import fg from 'fast-glob';
|
|
|
5
5
|
import postcss from 'postcss';
|
|
6
6
|
import { expandVariantGroup, notNull, regexScopePlaceholder, createGenerator } from '@unocss/core';
|
|
7
7
|
import { loadConfig } from '@unocss/config';
|
|
8
|
+
import { transformThemeFn, hasThemeFn } from '@unocss/rule-utils';
|
|
8
9
|
import { parse, generate, clone } from 'css-tree';
|
|
9
|
-
import { parseCssColor, colorToString } from '@unocss/rule-utils';
|
|
10
|
-
import MagicString from 'magic-string';
|
|
11
10
|
|
|
12
11
|
const defaultFilesystemGlobs = [
|
|
13
12
|
"**/*.{html,js,ts,jsx,tsx,vue,svelte,astro,elm,php,phtml,mdx,md}"
|
|
@@ -76,45 +75,9 @@ async function parseApply(root, uno, directiveName) {
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
function
|
|
80
|
-
return new RegExp(`${directiveName}\\((.*?)\\)`, "g");
|
|
81
|
-
}
|
|
82
|
-
async function parseTheme(root, uno, directiveName) {
|
|
78
|
+
async function parseTheme(root, uno) {
|
|
83
79
|
root.walkDecls((decl) => {
|
|
84
|
-
|
|
85
|
-
if (!matches.length)
|
|
86
|
-
return;
|
|
87
|
-
for (const match of matches) {
|
|
88
|
-
const rawArg = match[1].trim();
|
|
89
|
-
if (!rawArg)
|
|
90
|
-
throw new Error(`${directiveName}() expect exact one argument, but got 0`);
|
|
91
|
-
const [rawKey, alpha] = rawArg.slice(1, -1).split("/");
|
|
92
|
-
let value = uno.config.theme;
|
|
93
|
-
const keys = rawKey.trim().split(".");
|
|
94
|
-
keys.every((key) => {
|
|
95
|
-
if (value[key] != null)
|
|
96
|
-
value = value[key];
|
|
97
|
-
else if (value[+key] != null)
|
|
98
|
-
value = value[+key];
|
|
99
|
-
else
|
|
100
|
-
return false;
|
|
101
|
-
return true;
|
|
102
|
-
});
|
|
103
|
-
if (typeof value === "string") {
|
|
104
|
-
if (alpha) {
|
|
105
|
-
const color = parseCssColor(value);
|
|
106
|
-
if (color)
|
|
107
|
-
value = colorToString(color, alpha);
|
|
108
|
-
}
|
|
109
|
-
const code = new MagicString(decl.value);
|
|
110
|
-
code.overwrite(
|
|
111
|
-
match.index,
|
|
112
|
-
match.index + match[0].length,
|
|
113
|
-
value
|
|
114
|
-
);
|
|
115
|
-
decl.value = code.toString();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
80
|
+
decl.value = transformThemeFn(decl.value, uno.config.theme);
|
|
118
81
|
});
|
|
119
82
|
}
|
|
120
83
|
|
|
@@ -137,9 +100,9 @@ async function parseScreen(root, uno, directiveName) {
|
|
|
137
100
|
breakpoints = uno.userConfig.theme.breakpoints;
|
|
138
101
|
if (!breakpoints)
|
|
139
102
|
breakpoints = uno.config.theme.breakpoints;
|
|
140
|
-
return breakpoints;
|
|
103
|
+
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]) => ({ point, size })) : void 0;
|
|
141
104
|
};
|
|
142
|
-
const variantEntries =
|
|
105
|
+
const variantEntries = (resolveBreakpoints() ?? []).map(({ point, size }, idx) => [point, size, idx]);
|
|
143
106
|
const generateMediaQuery = (breakpointName2, prefix2) => {
|
|
144
107
|
const [, size, idx] = variantEntries.find((i) => i[0] === breakpointName2);
|
|
145
108
|
if (prefix2) {
|
|
@@ -203,9 +166,8 @@ function unocss(options = {}) {
|
|
|
203
166
|
return false;
|
|
204
167
|
});
|
|
205
168
|
if (!isTarget) {
|
|
206
|
-
const themeFn = themeFnRE(directiveMap.theme);
|
|
207
169
|
root.walkDecls((decl) => {
|
|
208
|
-
if (
|
|
170
|
+
if (hasThemeFn(decl.value)) {
|
|
209
171
|
isTarget = true;
|
|
210
172
|
return false;
|
|
211
173
|
}
|
|
@@ -242,7 +204,7 @@ function unocss(options = {}) {
|
|
|
242
204
|
stats: true
|
|
243
205
|
});
|
|
244
206
|
await parseApply(root, uno, directiveMap.apply);
|
|
245
|
-
await parseTheme(root, uno
|
|
207
|
+
await parseTheme(root, uno);
|
|
246
208
|
await parseScreen(root, uno, directiveMap.screen);
|
|
247
209
|
promises.push(
|
|
248
210
|
...plainContent.map(async (c2, idx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/postcss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "PostCSS plugin for UnoCSS",
|
|
5
5
|
"author": "sibbng <sibbngheid@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"css-tree": "^2.3.1",
|
|
40
40
|
"fast-glob": "^3.3.1",
|
|
41
|
-
"magic-string": "^0.30.
|
|
42
|
-
"postcss": "^8.4.
|
|
43
|
-
"@unocss/config": "0.
|
|
44
|
-
"@unocss/core": "0.
|
|
45
|
-
"@unocss/rule-utils": "0.
|
|
41
|
+
"magic-string": "^0.30.5",
|
|
42
|
+
"postcss": "^8.4.31",
|
|
43
|
+
"@unocss/config": "0.57.0",
|
|
44
|
+
"@unocss/core": "0.57.0",
|
|
45
|
+
"@unocss/rule-utils": "0.57.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "unbuild",
|