@unocss/postcss 0.56.4 → 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 -49
- package/dist/index.mjs +8 -49
- 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) {
|
|
@@ -175,9 +137,6 @@ function calcMaxWidthBySize(size) {
|
|
|
175
137
|
}
|
|
176
138
|
|
|
177
139
|
function unocss(options = {}) {
|
|
178
|
-
core.warnOnce(
|
|
179
|
-
"`@unocss/postcss` package is in an experimental state right now. It doesn't follow semver, and may introduce breaking changes in patch versions."
|
|
180
|
-
);
|
|
181
140
|
const {
|
|
182
141
|
cwd = process__default.cwd(),
|
|
183
142
|
configOrPath
|
|
@@ -215,9 +174,8 @@ function unocss(options = {}) {
|
|
|
215
174
|
return false;
|
|
216
175
|
});
|
|
217
176
|
if (!isTarget) {
|
|
218
|
-
const themeFn = themeFnRE(directiveMap.theme);
|
|
219
177
|
root.walkDecls((decl) => {
|
|
220
|
-
if (
|
|
178
|
+
if (ruleUtils.hasThemeFn(decl.value)) {
|
|
221
179
|
isTarget = true;
|
|
222
180
|
return false;
|
|
223
181
|
}
|
|
@@ -254,7 +212,7 @@ function unocss(options = {}) {
|
|
|
254
212
|
stats: true
|
|
255
213
|
});
|
|
256
214
|
await parseApply(root, uno, directiveMap.apply);
|
|
257
|
-
await parseTheme(root, uno
|
|
215
|
+
await parseTheme(root, uno);
|
|
258
216
|
await parseScreen(root, uno, directiveMap.screen);
|
|
259
217
|
promises$1.push(
|
|
260
218
|
...plainContent.map(async (c2, idx) => {
|
package/dist/index.mjs
CHANGED
|
@@ -3,11 +3,10 @@ import { normalize } from 'node:path';
|
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
5
|
import postcss from 'postcss';
|
|
6
|
-
import { expandVariantGroup, notNull, regexScopePlaceholder,
|
|
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) {
|
|
@@ -166,9 +129,6 @@ function calcMaxWidthBySize(size) {
|
|
|
166
129
|
}
|
|
167
130
|
|
|
168
131
|
function unocss(options = {}) {
|
|
169
|
-
warnOnce(
|
|
170
|
-
"`@unocss/postcss` package is in an experimental state right now. It doesn't follow semver, and may introduce breaking changes in patch versions."
|
|
171
|
-
);
|
|
172
132
|
const {
|
|
173
133
|
cwd = process.cwd(),
|
|
174
134
|
configOrPath
|
|
@@ -206,9 +166,8 @@ function unocss(options = {}) {
|
|
|
206
166
|
return false;
|
|
207
167
|
});
|
|
208
168
|
if (!isTarget) {
|
|
209
|
-
const themeFn = themeFnRE(directiveMap.theme);
|
|
210
169
|
root.walkDecls((decl) => {
|
|
211
|
-
if (
|
|
170
|
+
if (hasThemeFn(decl.value)) {
|
|
212
171
|
isTarget = true;
|
|
213
172
|
return false;
|
|
214
173
|
}
|
|
@@ -245,7 +204,7 @@ function unocss(options = {}) {
|
|
|
245
204
|
stats: true
|
|
246
205
|
});
|
|
247
206
|
await parseApply(root, uno, directiveMap.apply);
|
|
248
|
-
await parseTheme(root, uno
|
|
207
|
+
await parseTheme(root, uno);
|
|
249
208
|
await parseScreen(root, uno, directiveMap.screen);
|
|
250
209
|
promises.push(
|
|
251
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",
|