@unocss/inspector 0.54.2 → 0.55.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/client/assets/_id_-078e4b04.js +1 -0
- package/dist/client/assets/index-aa90c21a.css +1 -0
- package/dist/client/assets/index-afbd59da.js +283 -0
- package/dist/client/assets/{repl-2fcfd783.js → repl-1b107e05.js} +2 -2
- package/dist/client/index.html +2 -2
- package/dist/index.cjs +975 -4
- package/dist/index.mjs +975 -4
- package/package.json +3 -3
- package/dist/client/assets/_id_-95c6bf52.js +0 -1
- package/dist/client/assets/index-85b85ec4.css +0 -1
- package/dist/client/assets/index-9d41d1d5.js +0 -283
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,978 @@
|
|
|
1
1
|
import { dirname, resolve } from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import sirv from 'sirv';
|
|
4
|
+
import { escapeSelector, createValueHandler, isString, escapeRegExp, CountableSet, BetterMap } from '@unocss/core';
|
|
4
5
|
import gzipSize from 'gzip-size';
|
|
5
6
|
|
|
6
7
|
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
7
8
|
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
8
9
|
const SKIP_COMMENT_RE = new RegExp(`(//\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(//\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
9
10
|
|
|
11
|
+
const basePositionMap = [
|
|
12
|
+
"top",
|
|
13
|
+
"top center",
|
|
14
|
+
"top left",
|
|
15
|
+
"top right",
|
|
16
|
+
"bottom",
|
|
17
|
+
"bottom center",
|
|
18
|
+
"bottom left",
|
|
19
|
+
"bottom right",
|
|
20
|
+
"left",
|
|
21
|
+
"left center",
|
|
22
|
+
"left top",
|
|
23
|
+
"left bottom",
|
|
24
|
+
"right",
|
|
25
|
+
"right center",
|
|
26
|
+
"right top",
|
|
27
|
+
"right bottom",
|
|
28
|
+
"center",
|
|
29
|
+
"center top",
|
|
30
|
+
"center bottom",
|
|
31
|
+
"center left",
|
|
32
|
+
"center right",
|
|
33
|
+
"center center"
|
|
34
|
+
];
|
|
35
|
+
Object.assign(
|
|
36
|
+
{},
|
|
37
|
+
...basePositionMap.map((p) => ({ [p.replace(/ /, "-")]: p })),
|
|
38
|
+
...basePositionMap.map((p) => ({ [p.replace(/\b(\w)\w+/g, "$1").replace(/ /, "")]: p }))
|
|
39
|
+
);
|
|
40
|
+
const globalKeywords = [
|
|
41
|
+
"inherit",
|
|
42
|
+
"initial",
|
|
43
|
+
"revert",
|
|
44
|
+
"revert-layer",
|
|
45
|
+
"unset"
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const numberWithUnitRE = /^(-?\d*(?:\.\d+)?)(px|pt|pc|%|r?(?:em|ex|lh|cap|ch|ic)|(?:[sld]?v|cq)(?:[whib]|min|max)|in|cm|mm|rpx)?$/i;
|
|
49
|
+
const numberRE = /^(-?\d*(?:\.\d+)?)$/i;
|
|
50
|
+
const unitOnlyRE = /^(px)$/i;
|
|
51
|
+
|
|
52
|
+
const cssProps = [
|
|
53
|
+
"color",
|
|
54
|
+
"border-color",
|
|
55
|
+
"background-color",
|
|
56
|
+
"flex-grow",
|
|
57
|
+
"flex",
|
|
58
|
+
"flex-shrink",
|
|
59
|
+
"caret-color",
|
|
60
|
+
"font",
|
|
61
|
+
"gap",
|
|
62
|
+
"opacity",
|
|
63
|
+
"visibility",
|
|
64
|
+
"z-index",
|
|
65
|
+
"font-weight",
|
|
66
|
+
"zoom",
|
|
67
|
+
"text-shadow",
|
|
68
|
+
"transform",
|
|
69
|
+
"box-shadow",
|
|
70
|
+
"background-position",
|
|
71
|
+
"left",
|
|
72
|
+
"right",
|
|
73
|
+
"top",
|
|
74
|
+
"bottom",
|
|
75
|
+
"object-position",
|
|
76
|
+
"max-height",
|
|
77
|
+
"min-height",
|
|
78
|
+
"max-width",
|
|
79
|
+
"min-width",
|
|
80
|
+
"height",
|
|
81
|
+
"width",
|
|
82
|
+
"border-width",
|
|
83
|
+
"margin",
|
|
84
|
+
"padding",
|
|
85
|
+
"outline-width",
|
|
86
|
+
"outline-offset",
|
|
87
|
+
"font-size",
|
|
88
|
+
"line-height",
|
|
89
|
+
"text-indent",
|
|
90
|
+
"vertical-align",
|
|
91
|
+
"border-spacing",
|
|
92
|
+
"letter-spacing",
|
|
93
|
+
"word-spacing",
|
|
94
|
+
"stroke",
|
|
95
|
+
"filter",
|
|
96
|
+
"backdrop-filter",
|
|
97
|
+
"fill",
|
|
98
|
+
"mask",
|
|
99
|
+
"mask-size",
|
|
100
|
+
"mask-border",
|
|
101
|
+
"clip-path",
|
|
102
|
+
"clip",
|
|
103
|
+
"border-radius"
|
|
104
|
+
];
|
|
105
|
+
function round(n) {
|
|
106
|
+
return n.toFixed(10).replace(/\.0+$/, "").replace(/(\.\d+?)0+$/, "$1");
|
|
107
|
+
}
|
|
108
|
+
function numberWithUnit(str) {
|
|
109
|
+
const match = str.match(numberWithUnitRE);
|
|
110
|
+
if (!match)
|
|
111
|
+
return;
|
|
112
|
+
const [, n, unit] = match;
|
|
113
|
+
const num = Number.parseFloat(n);
|
|
114
|
+
if (unit && !Number.isNaN(num))
|
|
115
|
+
return `${round(num)}${unit}`;
|
|
116
|
+
}
|
|
117
|
+
function auto(str) {
|
|
118
|
+
if (str === "auto" || str === "a")
|
|
119
|
+
return "auto";
|
|
120
|
+
}
|
|
121
|
+
function rem(str) {
|
|
122
|
+
if (str.match(unitOnlyRE))
|
|
123
|
+
return `1${str}`;
|
|
124
|
+
const match = str.match(numberWithUnitRE);
|
|
125
|
+
if (!match)
|
|
126
|
+
return;
|
|
127
|
+
const [, n, unit] = match;
|
|
128
|
+
const num = Number.parseFloat(n);
|
|
129
|
+
if (!Number.isNaN(num)) {
|
|
130
|
+
if (num === 0)
|
|
131
|
+
return "0";
|
|
132
|
+
return unit ? `${round(num)}${unit}` : `${round(num / 4)}rem`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function px(str) {
|
|
136
|
+
if (str.match(unitOnlyRE))
|
|
137
|
+
return `1${str}`;
|
|
138
|
+
const match = str.match(numberWithUnitRE);
|
|
139
|
+
if (!match)
|
|
140
|
+
return;
|
|
141
|
+
const [, n, unit] = match;
|
|
142
|
+
const num = Number.parseFloat(n);
|
|
143
|
+
if (!Number.isNaN(num)) {
|
|
144
|
+
if (num === 0)
|
|
145
|
+
return "0";
|
|
146
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}px`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function number(str) {
|
|
150
|
+
if (!numberRE.test(str))
|
|
151
|
+
return;
|
|
152
|
+
const num = Number.parseFloat(str);
|
|
153
|
+
if (!Number.isNaN(num))
|
|
154
|
+
return round(num);
|
|
155
|
+
}
|
|
156
|
+
function percent(str) {
|
|
157
|
+
if (str.endsWith("%"))
|
|
158
|
+
str = str.slice(0, -1);
|
|
159
|
+
if (!numberRE.test(str))
|
|
160
|
+
return;
|
|
161
|
+
const num = Number.parseFloat(str);
|
|
162
|
+
if (!Number.isNaN(num))
|
|
163
|
+
return `${round(num / 100)}`;
|
|
164
|
+
}
|
|
165
|
+
function fraction(str) {
|
|
166
|
+
if (str === "full")
|
|
167
|
+
return "100%";
|
|
168
|
+
const [left, right] = str.split("/");
|
|
169
|
+
const num = Number.parseFloat(left) / Number.parseFloat(right);
|
|
170
|
+
if (!Number.isNaN(num)) {
|
|
171
|
+
if (num === 0)
|
|
172
|
+
return "0";
|
|
173
|
+
return `${round(num * 100)}%`;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const bracketTypeRe = /^\[(color|length|position|quoted|string):/i;
|
|
177
|
+
function bracketWithType(str, requiredType) {
|
|
178
|
+
if (str && str.startsWith("[") && str.endsWith("]")) {
|
|
179
|
+
let base;
|
|
180
|
+
let hintedType;
|
|
181
|
+
const match = str.match(bracketTypeRe);
|
|
182
|
+
if (!match) {
|
|
183
|
+
base = str.slice(1, -1);
|
|
184
|
+
} else {
|
|
185
|
+
if (!requiredType)
|
|
186
|
+
hintedType = match[1];
|
|
187
|
+
base = str.slice(match[0].length, -1);
|
|
188
|
+
}
|
|
189
|
+
if (!base)
|
|
190
|
+
return;
|
|
191
|
+
if (base === '=""')
|
|
192
|
+
return;
|
|
193
|
+
if (base.startsWith("--"))
|
|
194
|
+
base = `var(${base})`;
|
|
195
|
+
let curly = 0;
|
|
196
|
+
for (const i of base) {
|
|
197
|
+
if (i === "[") {
|
|
198
|
+
curly += 1;
|
|
199
|
+
} else if (i === "]") {
|
|
200
|
+
curly -= 1;
|
|
201
|
+
if (curly < 0)
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (curly)
|
|
206
|
+
return;
|
|
207
|
+
switch (hintedType) {
|
|
208
|
+
case "string":
|
|
209
|
+
return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_");
|
|
210
|
+
case "quoted":
|
|
211
|
+
return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(["\\])/g, "\\$1").replace(/^(.+)$/, '"$1"');
|
|
212
|
+
}
|
|
213
|
+
return base.replace(/(url\(.*?\))/g, (v) => v.replace(/_/g, "\\_")).replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(?:calc|clamp|max|min)\((.*)/g, (match2) => {
|
|
214
|
+
const vars = [];
|
|
215
|
+
return match2.replace(/var\((--.+?)[,)]/g, (match3, g1) => {
|
|
216
|
+
vars.push(g1);
|
|
217
|
+
return match3.replace(g1, "--un-calc");
|
|
218
|
+
}).replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ").replace(/--un-calc/g, () => vars.shift());
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function bracket(str) {
|
|
223
|
+
return bracketWithType(str);
|
|
224
|
+
}
|
|
225
|
+
function bracketOfColor(str) {
|
|
226
|
+
return bracketWithType(str, "color");
|
|
227
|
+
}
|
|
228
|
+
function bracketOfLength(str) {
|
|
229
|
+
return bracketWithType(str, "length");
|
|
230
|
+
}
|
|
231
|
+
function bracketOfPosition(str) {
|
|
232
|
+
return bracketWithType(str, "position");
|
|
233
|
+
}
|
|
234
|
+
function cssvar(str) {
|
|
235
|
+
if (str.match(/^\$[^\s'"`;{}]/))
|
|
236
|
+
return `var(--${escapeSelector(str.slice(1))})`;
|
|
237
|
+
}
|
|
238
|
+
function time(str) {
|
|
239
|
+
const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
|
|
240
|
+
if (!match)
|
|
241
|
+
return;
|
|
242
|
+
const [, n, unit] = match;
|
|
243
|
+
const num = Number.parseFloat(n);
|
|
244
|
+
if (!Number.isNaN(num)) {
|
|
245
|
+
if (num === 0 && !unit)
|
|
246
|
+
return "0s";
|
|
247
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}ms`;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function degree(str) {
|
|
251
|
+
const match = str.match(/^(-?[0-9.]+)(deg|rad|grad|turn)?$/i);
|
|
252
|
+
if (!match)
|
|
253
|
+
return;
|
|
254
|
+
const [, n, unit] = match;
|
|
255
|
+
const num = Number.parseFloat(n);
|
|
256
|
+
if (!Number.isNaN(num)) {
|
|
257
|
+
if (num === 0)
|
|
258
|
+
return "0";
|
|
259
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}deg`;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function global(str) {
|
|
263
|
+
if (globalKeywords.includes(str))
|
|
264
|
+
return str;
|
|
265
|
+
}
|
|
266
|
+
function properties(str) {
|
|
267
|
+
if (str.split(",").every((prop) => cssProps.includes(prop)))
|
|
268
|
+
return str;
|
|
269
|
+
}
|
|
270
|
+
function position(str) {
|
|
271
|
+
if (["top", "left", "right", "bottom", "center"].includes(str))
|
|
272
|
+
return str;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const valueHandlers = {
|
|
276
|
+
__proto__: null,
|
|
277
|
+
numberWithUnit: numberWithUnit,
|
|
278
|
+
auto: auto,
|
|
279
|
+
rem: rem,
|
|
280
|
+
px: px,
|
|
281
|
+
number: number,
|
|
282
|
+
percent: percent,
|
|
283
|
+
fraction: fraction,
|
|
284
|
+
bracket: bracket,
|
|
285
|
+
bracketOfColor: bracketOfColor,
|
|
286
|
+
bracketOfLength: bracketOfLength,
|
|
287
|
+
bracketOfPosition: bracketOfPosition,
|
|
288
|
+
cssvar: cssvar,
|
|
289
|
+
time: time,
|
|
290
|
+
degree: degree,
|
|
291
|
+
global: global,
|
|
292
|
+
properties: properties,
|
|
293
|
+
position: position
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const handler = createValueHandler(valueHandlers);
|
|
297
|
+
const h = handler;
|
|
298
|
+
|
|
299
|
+
function getThemeColor(theme, colors) {
|
|
300
|
+
let obj = theme.colors;
|
|
301
|
+
let index = -1;
|
|
302
|
+
for (const c of colors) {
|
|
303
|
+
index += 1;
|
|
304
|
+
if (obj && typeof obj !== "string") {
|
|
305
|
+
const camel = colors.slice(index).join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase());
|
|
306
|
+
if (obj[camel])
|
|
307
|
+
return obj[camel];
|
|
308
|
+
if (obj[c]) {
|
|
309
|
+
obj = obj[c];
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
return obj;
|
|
316
|
+
}
|
|
317
|
+
function splitShorthand(body, type) {
|
|
318
|
+
const split = body.split(/(?:\/|:)/);
|
|
319
|
+
if (split[0] === `[${type}`) {
|
|
320
|
+
return [
|
|
321
|
+
split.slice(0, 2).join(":"),
|
|
322
|
+
split[2]
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
return split;
|
|
326
|
+
}
|
|
327
|
+
function parseColor$1(body, theme) {
|
|
328
|
+
const [main, opacity] = splitShorthand(body, "color");
|
|
329
|
+
const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
|
|
330
|
+
const [name] = colors;
|
|
331
|
+
if (!name)
|
|
332
|
+
return;
|
|
333
|
+
let color;
|
|
334
|
+
const bracket = h.bracketOfColor(main);
|
|
335
|
+
const bracketOrMain = bracket || main;
|
|
336
|
+
if (h.numberWithUnit(bracketOrMain))
|
|
337
|
+
return;
|
|
338
|
+
if (bracketOrMain.match(/^#[\da-fA-F]+/g))
|
|
339
|
+
color = bracketOrMain;
|
|
340
|
+
else if (bracketOrMain.match(/^hex-[\da-fA-F]+/g))
|
|
341
|
+
color = `#${bracketOrMain.slice(4)}`;
|
|
342
|
+
else if (main.startsWith("$"))
|
|
343
|
+
color = h.cssvar(main);
|
|
344
|
+
color = color || bracket;
|
|
345
|
+
if (!color) {
|
|
346
|
+
const colorData = getThemeColor(theme, [main]);
|
|
347
|
+
if (typeof colorData === "string")
|
|
348
|
+
color = colorData;
|
|
349
|
+
}
|
|
350
|
+
let no = "DEFAULT";
|
|
351
|
+
if (!color) {
|
|
352
|
+
let colorData;
|
|
353
|
+
const [scale] = colors.slice(-1);
|
|
354
|
+
if (scale.match(/^\d+$/)) {
|
|
355
|
+
no = scale;
|
|
356
|
+
colorData = getThemeColor(theme, colors.slice(0, -1));
|
|
357
|
+
if (!colorData || typeof colorData === "string")
|
|
358
|
+
color = void 0;
|
|
359
|
+
else
|
|
360
|
+
color = colorData[no];
|
|
361
|
+
} else {
|
|
362
|
+
colorData = getThemeColor(theme, colors);
|
|
363
|
+
if (!colorData && colors.length <= 2) {
|
|
364
|
+
[, no = no] = colors;
|
|
365
|
+
colorData = getThemeColor(theme, [name]);
|
|
366
|
+
}
|
|
367
|
+
if (typeof colorData === "string")
|
|
368
|
+
color = colorData;
|
|
369
|
+
else if (no && colorData)
|
|
370
|
+
color = colorData[no];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
opacity,
|
|
375
|
+
name,
|
|
376
|
+
no,
|
|
377
|
+
color,
|
|
378
|
+
cssColor: parseCssColor(color),
|
|
379
|
+
alpha: h.bracket.cssvar.percent(opacity ?? "")
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function getComponent(str, open, close, separators) {
|
|
383
|
+
if (str === "")
|
|
384
|
+
return;
|
|
385
|
+
if (isString(separators))
|
|
386
|
+
separators = [separators];
|
|
387
|
+
if (separators.length === 0)
|
|
388
|
+
return;
|
|
389
|
+
const l = str.length;
|
|
390
|
+
let parenthesis = 0;
|
|
391
|
+
for (let i = 0; i < l; i++) {
|
|
392
|
+
switch (str[i]) {
|
|
393
|
+
case open:
|
|
394
|
+
parenthesis++;
|
|
395
|
+
break;
|
|
396
|
+
case close:
|
|
397
|
+
if (--parenthesis < 0)
|
|
398
|
+
return;
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
for (const separator of separators) {
|
|
402
|
+
const separatorLength = separator.length;
|
|
403
|
+
if (separatorLength && separator === str.slice(i, i + separatorLength) && parenthesis === 0) {
|
|
404
|
+
if (i === 0 || i === l - separatorLength)
|
|
405
|
+
return;
|
|
406
|
+
return [
|
|
407
|
+
str.slice(0, i),
|
|
408
|
+
str.slice(i + separatorLength)
|
|
409
|
+
];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return [
|
|
415
|
+
str,
|
|
416
|
+
""
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
function getComponents(str, separators, limit) {
|
|
420
|
+
limit = limit ?? 10;
|
|
421
|
+
const components = [];
|
|
422
|
+
let i = 0;
|
|
423
|
+
while (str !== "") {
|
|
424
|
+
if (++i > limit)
|
|
425
|
+
return;
|
|
426
|
+
const componentPair = getComponent(str, "(", ")", separators);
|
|
427
|
+
if (!componentPair)
|
|
428
|
+
return;
|
|
429
|
+
const [component, rest] = componentPair;
|
|
430
|
+
components.push(component);
|
|
431
|
+
str = rest;
|
|
432
|
+
}
|
|
433
|
+
if (components.length > 0)
|
|
434
|
+
return components;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
|
|
438
|
+
const alphaPlaceholders = ["%alpha", "<alpha-value>"];
|
|
439
|
+
new RegExp(alphaPlaceholders.map((v) => escapeRegExp(v)).join("|"));
|
|
440
|
+
function parseCssColor(str = "") {
|
|
441
|
+
const color = parseColor(str);
|
|
442
|
+
if (color == null || color === false)
|
|
443
|
+
return;
|
|
444
|
+
const { type: casedType, components, alpha } = color;
|
|
445
|
+
const type = casedType.toLowerCase();
|
|
446
|
+
if (components.length === 0)
|
|
447
|
+
return;
|
|
448
|
+
if (["rgba", "hsla"].includes(type) && alpha == null)
|
|
449
|
+
return;
|
|
450
|
+
if (cssColorFunctions.includes(type) && ![1, 3].includes(components.length))
|
|
451
|
+
return;
|
|
452
|
+
return {
|
|
453
|
+
type,
|
|
454
|
+
components: components.map((c) => typeof c === "string" ? c.trim() : c),
|
|
455
|
+
alpha: typeof alpha === "string" ? alpha.trim() : alpha
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function parseColor(str) {
|
|
459
|
+
if (!str)
|
|
460
|
+
return;
|
|
461
|
+
let color = parseHexColor(str);
|
|
462
|
+
if (color != null)
|
|
463
|
+
return color;
|
|
464
|
+
color = cssColorKeyword(str);
|
|
465
|
+
if (color != null)
|
|
466
|
+
return color;
|
|
467
|
+
color = parseCssCommaColorFunction(str);
|
|
468
|
+
if (color != null)
|
|
469
|
+
return color;
|
|
470
|
+
color = parseCssSpaceColorFunction(str);
|
|
471
|
+
if (color != null)
|
|
472
|
+
return color;
|
|
473
|
+
color = parseCssColorFunction(str);
|
|
474
|
+
if (color != null)
|
|
475
|
+
return color;
|
|
476
|
+
}
|
|
477
|
+
function parseHexColor(str) {
|
|
478
|
+
const [, body] = str.match(/^#([\da-f]+)$/i) || [];
|
|
479
|
+
if (!body)
|
|
480
|
+
return;
|
|
481
|
+
switch (body.length) {
|
|
482
|
+
case 3:
|
|
483
|
+
case 4:
|
|
484
|
+
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
485
|
+
return {
|
|
486
|
+
type: "rgb",
|
|
487
|
+
components: digits.slice(0, 3),
|
|
488
|
+
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
489
|
+
};
|
|
490
|
+
case 6:
|
|
491
|
+
case 8:
|
|
492
|
+
const value = Number.parseInt(body, 16);
|
|
493
|
+
return {
|
|
494
|
+
type: "rgb",
|
|
495
|
+
components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
|
|
496
|
+
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function cssColorKeyword(str) {
|
|
501
|
+
const color = {
|
|
502
|
+
rebeccapurple: [102, 51, 153, 1]
|
|
503
|
+
}[str];
|
|
504
|
+
if (color != null) {
|
|
505
|
+
return {
|
|
506
|
+
type: "rgb",
|
|
507
|
+
components: color.slice(0, 3),
|
|
508
|
+
alpha: color[3]
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function parseCssCommaColorFunction(color) {
|
|
513
|
+
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
514
|
+
if (!match)
|
|
515
|
+
return;
|
|
516
|
+
const [, type, componentString] = match;
|
|
517
|
+
const components = getComponents(componentString, ",", 5);
|
|
518
|
+
if (components) {
|
|
519
|
+
if ([3, 4].includes(components.length)) {
|
|
520
|
+
return {
|
|
521
|
+
type,
|
|
522
|
+
components: components.slice(0, 3),
|
|
523
|
+
alpha: components[3]
|
|
524
|
+
};
|
|
525
|
+
} else if (components.length !== 1) {
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
531
|
+
function parseCssSpaceColorFunction(color) {
|
|
532
|
+
const match = color.match(cssColorFunctionsRe);
|
|
533
|
+
if (!match)
|
|
534
|
+
return;
|
|
535
|
+
const [, fn, componentString] = match;
|
|
536
|
+
const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
|
|
537
|
+
if (parsed) {
|
|
538
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
539
|
+
return {
|
|
540
|
+
type,
|
|
541
|
+
components,
|
|
542
|
+
alpha
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function parseCssColorFunction(color) {
|
|
547
|
+
const match = color.match(/^color\((.+)\)$/);
|
|
548
|
+
if (!match)
|
|
549
|
+
return;
|
|
550
|
+
const parsed = parseCssSpaceColorValues(match[1]);
|
|
551
|
+
if (parsed) {
|
|
552
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
553
|
+
return {
|
|
554
|
+
type,
|
|
555
|
+
components,
|
|
556
|
+
alpha
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function parseCssSpaceColorValues(componentString) {
|
|
561
|
+
const components = getComponents(componentString, " ");
|
|
562
|
+
if (!components)
|
|
563
|
+
return;
|
|
564
|
+
let totalComponents = components.length;
|
|
565
|
+
if (components[totalComponents - 2] === "/") {
|
|
566
|
+
return {
|
|
567
|
+
components: components.slice(0, totalComponents - 2),
|
|
568
|
+
alpha: components[totalComponents - 1]
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
572
|
+
const removed = components.splice(totalComponents - 2);
|
|
573
|
+
components.push(removed.join(" "));
|
|
574
|
+
--totalComponents;
|
|
575
|
+
}
|
|
576
|
+
const withAlpha = getComponents(components[totalComponents - 1], "/", 2);
|
|
577
|
+
if (!withAlpha)
|
|
578
|
+
return;
|
|
579
|
+
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
|
|
580
|
+
return { components };
|
|
581
|
+
const alpha = withAlpha.pop();
|
|
582
|
+
components[totalComponents - 1] = withAlpha.join("/");
|
|
583
|
+
return {
|
|
584
|
+
components,
|
|
585
|
+
alpha
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const staticUtilities = {
|
|
590
|
+
"box-border": "boxSizing",
|
|
591
|
+
"box-content": "boxSizing",
|
|
592
|
+
"b": "border",
|
|
593
|
+
"border": "border",
|
|
594
|
+
"rounded": "border",
|
|
595
|
+
"block": "display",
|
|
596
|
+
"inline-block": "display",
|
|
597
|
+
"inline": "display",
|
|
598
|
+
"flex": "display",
|
|
599
|
+
"inline-flex": "display",
|
|
600
|
+
"table": "display",
|
|
601
|
+
"table-caption": "display",
|
|
602
|
+
"table-cell": "display",
|
|
603
|
+
"table-column": "display",
|
|
604
|
+
"table-column-group": "display",
|
|
605
|
+
"table-footer-group": "display",
|
|
606
|
+
"table-header-group": "display",
|
|
607
|
+
"table-row-group": "display",
|
|
608
|
+
"table-row": "display",
|
|
609
|
+
"flow-root": "display",
|
|
610
|
+
"grid": "display",
|
|
611
|
+
"inline-grid": "display",
|
|
612
|
+
"contents": "display",
|
|
613
|
+
"hidden": "display",
|
|
614
|
+
"float-right": "float",
|
|
615
|
+
"float-left": "float",
|
|
616
|
+
"float-none": "float",
|
|
617
|
+
"clear-left": "clear",
|
|
618
|
+
"clear-right": "clear",
|
|
619
|
+
"clear-both": "clear",
|
|
620
|
+
"clear-none": "clear",
|
|
621
|
+
"object-contain": "objectFit",
|
|
622
|
+
"object-cover": "objectFit",
|
|
623
|
+
"object-fill": "objectFit",
|
|
624
|
+
"object-none": "objectFit",
|
|
625
|
+
"object-scale-down": "objectFit",
|
|
626
|
+
"overflow-auto": "overflow",
|
|
627
|
+
"overflow-hidden": "overflow",
|
|
628
|
+
"overflow-visible": "overflow",
|
|
629
|
+
"overflow-scroll": "overflow",
|
|
630
|
+
"overflow-x-auto": "overflow",
|
|
631
|
+
"overflow-y-auto": "overflow",
|
|
632
|
+
"overflow-x-hidden": "overflow",
|
|
633
|
+
"overflow-y-hidden": "overflow",
|
|
634
|
+
"overflow-x-visible": "overflow",
|
|
635
|
+
"overflow-y-visible": "overflow",
|
|
636
|
+
"overflow-x-scroll": "overflow",
|
|
637
|
+
"overflow-y-scroll": "overflow",
|
|
638
|
+
"of-auto": "overflow",
|
|
639
|
+
"of-hidden": "overflow",
|
|
640
|
+
"of-visible": "overflow",
|
|
641
|
+
"of-scroll": "overflow",
|
|
642
|
+
"of-x-auto": "overflow",
|
|
643
|
+
"of-y-auto": "overflow",
|
|
644
|
+
"of-x-hidden": "overflow",
|
|
645
|
+
"of-y-hidden": "overflow",
|
|
646
|
+
"of-x-visible": "overflow",
|
|
647
|
+
"of-y-visible": "overflow",
|
|
648
|
+
"of-x-scroll": "overflow",
|
|
649
|
+
"of-y-scroll": "overflow",
|
|
650
|
+
"overscroll-auto": "overscrollBehavior",
|
|
651
|
+
"overscroll-contain": "overscrollBehavior",
|
|
652
|
+
"overscroll-none": "overscrollBehavior",
|
|
653
|
+
"overscroll-y-auto": "overscrollBehavior",
|
|
654
|
+
"overscroll-y-contain": "overscrollBehavior",
|
|
655
|
+
"overscroll-y-none": "overscrollBehavior",
|
|
656
|
+
"overscroll-x-auto": "overscrollBehavior",
|
|
657
|
+
"overscroll-x-contain": "overscrollBehavior",
|
|
658
|
+
"overscroll-x-none": "overscrollBehavior",
|
|
659
|
+
"static": "position",
|
|
660
|
+
"fixed": "position",
|
|
661
|
+
"absolute": "position",
|
|
662
|
+
"relative": "position",
|
|
663
|
+
"sticky": "position",
|
|
664
|
+
"visible": "visibility",
|
|
665
|
+
"invisible": "visibility",
|
|
666
|
+
"flex-row": "flex",
|
|
667
|
+
"flex-row-reverse": "flex",
|
|
668
|
+
"flex-col": "flex",
|
|
669
|
+
"flex-col-reverse": "flex",
|
|
670
|
+
"flex-wrap": "flex",
|
|
671
|
+
"flex-wrap-reverse": "flex",
|
|
672
|
+
"flex-nowrap": "flex",
|
|
673
|
+
"col-auto": "grid",
|
|
674
|
+
"row-auto": "grid",
|
|
675
|
+
"grid-flow-row": "grid",
|
|
676
|
+
"grid-flow-col": "grid",
|
|
677
|
+
"grid-flow-row-dense": "grid",
|
|
678
|
+
"grid-flow-col-dense": "grid",
|
|
679
|
+
"justify-start": "justifyContent",
|
|
680
|
+
"justify-end": "justifyContent",
|
|
681
|
+
"justify-center": "justifyContent",
|
|
682
|
+
"justify-between": "justifyContent",
|
|
683
|
+
"justify-around": "justifyContent",
|
|
684
|
+
"justify-evenly": "justifyContent",
|
|
685
|
+
"justify-items-auto": "justifyItems",
|
|
686
|
+
"justify-items-start": "justifyItems",
|
|
687
|
+
"justify-items-end": "justifyItems",
|
|
688
|
+
"justify-items-center": "justifyItems",
|
|
689
|
+
"justify-items-stretch": "justifyItems",
|
|
690
|
+
"justify-self-auto": "justifySelf",
|
|
691
|
+
"justify-self-start": "justifySelf",
|
|
692
|
+
"justify-self-end": "justifySelf",
|
|
693
|
+
"justify-self-center": "justifySelf",
|
|
694
|
+
"justify-self-stretch": "justifySelf",
|
|
695
|
+
"content-center": "alignContent",
|
|
696
|
+
"content-start": "alignContent",
|
|
697
|
+
"content-end": "alignContent",
|
|
698
|
+
"content-between": "alignContent",
|
|
699
|
+
"content-around": "alignContent",
|
|
700
|
+
"content-evenly": "alignContent",
|
|
701
|
+
"items-start": "alignItems",
|
|
702
|
+
"items-end": "alignItems",
|
|
703
|
+
"items-center": "alignItems",
|
|
704
|
+
"items-baseline": "alignItems",
|
|
705
|
+
"items-stretch": "alignItems",
|
|
706
|
+
"self-auto": "alignSelf",
|
|
707
|
+
"self-start": "alignSelf",
|
|
708
|
+
"self-end": "alignSelf",
|
|
709
|
+
"self-center": "alignSelf",
|
|
710
|
+
"self-stretch": "alignSelf",
|
|
711
|
+
"place-content-center": "placeContent",
|
|
712
|
+
"place-content-start": "placeContent",
|
|
713
|
+
"place-content-end": "placeContent",
|
|
714
|
+
"place-content-between": "placeContent",
|
|
715
|
+
"place-content-around": "placeContent",
|
|
716
|
+
"place-content-evenly": "placeContent",
|
|
717
|
+
"place-content-stretch": "placeContent",
|
|
718
|
+
"place-items-auto": "placeItems",
|
|
719
|
+
"place-items-start": "placeItems",
|
|
720
|
+
"place-items-end": "placeItems",
|
|
721
|
+
"place-items-center": "placeItems",
|
|
722
|
+
"place-items-stretch": "placeItems",
|
|
723
|
+
"place-self-auto": "placeSelf",
|
|
724
|
+
"place-self-start": "placeSelf",
|
|
725
|
+
"place-self-end": "placeSelf",
|
|
726
|
+
"place-self-center": "placeSelf",
|
|
727
|
+
"place-self-stretch": "placeSelf",
|
|
728
|
+
"antialiased": "fontSmoothing",
|
|
729
|
+
"subpixel-antialiased": "font",
|
|
730
|
+
"italic": "font",
|
|
731
|
+
"not-italic": "font",
|
|
732
|
+
"normal-nums": "font",
|
|
733
|
+
"ordinal": "font",
|
|
734
|
+
"slashed-zero": "font",
|
|
735
|
+
"lining-nums": "font",
|
|
736
|
+
"oldstyle-nums": "font",
|
|
737
|
+
"proportional-nums": "font",
|
|
738
|
+
"tabular-nums": "font",
|
|
739
|
+
"diagonal-fractions": "font",
|
|
740
|
+
"stacked-fractions": "font",
|
|
741
|
+
"list-inside": "listStylePosition",
|
|
742
|
+
"list-outside": "listStylePosition",
|
|
743
|
+
"text-left": "textAlign",
|
|
744
|
+
"text-center": "textAlign",
|
|
745
|
+
"text-right": "textAlign",
|
|
746
|
+
"text-justify": "textAlign",
|
|
747
|
+
"underline": "textDecoration",
|
|
748
|
+
"line-through": "textDecoration",
|
|
749
|
+
"no-underline": "textDecoration",
|
|
750
|
+
"uppercase": "textTransform",
|
|
751
|
+
"lowercase": "textTransform",
|
|
752
|
+
"capitalize": "textTransform",
|
|
753
|
+
"normal-case": "textTransform",
|
|
754
|
+
"truncate": "textOverflow",
|
|
755
|
+
"overflow-ellipsis": "textOverflow",
|
|
756
|
+
"overflow-clip": "textOverflow",
|
|
757
|
+
"align-baseline": "verticalAlign",
|
|
758
|
+
"align-top": "verticalAlign",
|
|
759
|
+
"align-middle": "verticalAlign",
|
|
760
|
+
"align-bottom": "verticalAlign",
|
|
761
|
+
"align-text-top": "verticalAlign",
|
|
762
|
+
"align-text-bottom": "verticalAlign",
|
|
763
|
+
"whitespace-normal": "whitespace",
|
|
764
|
+
"whitespace-nowrap": "whitespace",
|
|
765
|
+
"whitespace-pre": "whitespace",
|
|
766
|
+
"whitespace-pre-line": "whitespace",
|
|
767
|
+
"whitespace-pre-wrap": "whitespace",
|
|
768
|
+
"ws-normal": "whitespace",
|
|
769
|
+
"ws-nowrap": "whitespace",
|
|
770
|
+
"ws-pre": "whitespace",
|
|
771
|
+
"ws-pre-line": "whitespace",
|
|
772
|
+
"ws-pre-wrap": "whitespace",
|
|
773
|
+
"break-normal": "wordBreak",
|
|
774
|
+
"break-words": "wordBreak",
|
|
775
|
+
"break-all": "wordBreak",
|
|
776
|
+
"bg-fixed": "background",
|
|
777
|
+
"bg-local": "background",
|
|
778
|
+
"bg-scroll": "background",
|
|
779
|
+
"bg-clip-border": "background",
|
|
780
|
+
"bg-clip-padding": "background",
|
|
781
|
+
"bg-clip-content": "background",
|
|
782
|
+
"bg-clip-text": "background",
|
|
783
|
+
"bg-repeat": "background",
|
|
784
|
+
"bg-no-repeat": "background",
|
|
785
|
+
"bg-repeat-x": "background",
|
|
786
|
+
"bg-repeat-y": "background",
|
|
787
|
+
"bg-repeat-round": "background",
|
|
788
|
+
"bg-repeat-space": "background",
|
|
789
|
+
"border-solid": "border",
|
|
790
|
+
"border-dashed": "border",
|
|
791
|
+
"border-dotted": "border",
|
|
792
|
+
"border-double": "border",
|
|
793
|
+
"border-none": "border",
|
|
794
|
+
"border-collapse": "border",
|
|
795
|
+
"border-separate": "border",
|
|
796
|
+
"table-auto": "table",
|
|
797
|
+
"table-fixed": "table",
|
|
798
|
+
"transform": "transform",
|
|
799
|
+
"transform-gpu": "transform",
|
|
800
|
+
"transform-none": "transform",
|
|
801
|
+
"appearance-none": "appearance",
|
|
802
|
+
"pointer-events-none": "pointerEvents",
|
|
803
|
+
"pointer-events-auto": "pointerEvents",
|
|
804
|
+
"resize-none": "resize",
|
|
805
|
+
"resize-y": "resize",
|
|
806
|
+
"resize-x": "resize",
|
|
807
|
+
"resize": "resize",
|
|
808
|
+
"select-none": "userSelect",
|
|
809
|
+
"select-text": "userSelect",
|
|
810
|
+
"select-all": "userSelect",
|
|
811
|
+
"select-auto": "userSelect",
|
|
812
|
+
"fill-current": "fill",
|
|
813
|
+
"stroke-current": "stroke",
|
|
814
|
+
"sr-only": "accessibility",
|
|
815
|
+
"not-sr-only": "accessibility",
|
|
816
|
+
"filter": "filter",
|
|
817
|
+
"invert": "filter"
|
|
818
|
+
};
|
|
819
|
+
const dynamicUtilities = {
|
|
820
|
+
container: "container",
|
|
821
|
+
space: "space",
|
|
822
|
+
divide: "divide",
|
|
823
|
+
bg: "background",
|
|
824
|
+
from: "gradientColor",
|
|
825
|
+
via: "gradientColor",
|
|
826
|
+
to: "gradientColor",
|
|
827
|
+
border: "border",
|
|
828
|
+
b: "border",
|
|
829
|
+
rounded: "borderRadius",
|
|
830
|
+
cursor: "cursor",
|
|
831
|
+
flex: "flex",
|
|
832
|
+
shrink: "flex",
|
|
833
|
+
order: "order",
|
|
834
|
+
font: "font",
|
|
835
|
+
h: "size",
|
|
836
|
+
leading: "lineHeight",
|
|
837
|
+
list: "listStyleType",
|
|
838
|
+
m: "margin",
|
|
839
|
+
my: "margin",
|
|
840
|
+
mx: "margin",
|
|
841
|
+
mt: "margin",
|
|
842
|
+
mr: "margin",
|
|
843
|
+
mb: "margin",
|
|
844
|
+
ml: "margin",
|
|
845
|
+
min: "size",
|
|
846
|
+
max: "size",
|
|
847
|
+
object: "objectPosition",
|
|
848
|
+
op: "opacity",
|
|
849
|
+
opacity: "opacity",
|
|
850
|
+
outline: "outline",
|
|
851
|
+
p: "padding",
|
|
852
|
+
py: "padding",
|
|
853
|
+
px: "padding",
|
|
854
|
+
pt: "padding",
|
|
855
|
+
pr: "padding",
|
|
856
|
+
pb: "padding",
|
|
857
|
+
pl: "padding",
|
|
858
|
+
placeholder: "placeholder",
|
|
859
|
+
inset: "inset",
|
|
860
|
+
top: "position",
|
|
861
|
+
right: "position",
|
|
862
|
+
bottom: "position",
|
|
863
|
+
left: "position",
|
|
864
|
+
shadow: "boxShadow",
|
|
865
|
+
ring: "ring",
|
|
866
|
+
fill: "fill",
|
|
867
|
+
stroke: "stroke",
|
|
868
|
+
text: "text",
|
|
869
|
+
tracking: "letterSpacing",
|
|
870
|
+
w: "size",
|
|
871
|
+
z: "zIndex",
|
|
872
|
+
gap: "gap",
|
|
873
|
+
auto: "grid",
|
|
874
|
+
grid: "grid",
|
|
875
|
+
col: "grid",
|
|
876
|
+
row: "grid",
|
|
877
|
+
origin: "transform",
|
|
878
|
+
scale: "transform",
|
|
879
|
+
rotate: "transform",
|
|
880
|
+
translate: "transform",
|
|
881
|
+
skew: "transform",
|
|
882
|
+
transition: "animation",
|
|
883
|
+
ease: "animation",
|
|
884
|
+
duration: "animation",
|
|
885
|
+
delay: "animation",
|
|
886
|
+
animate: "animation",
|
|
887
|
+
filter: "filter",
|
|
888
|
+
backdrop: "filter",
|
|
889
|
+
invert: "filter"
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
function getSelectorCategory(selector) {
|
|
893
|
+
return staticUtilities[selector] || Object.entries(dynamicUtilities).find(([name]) => new RegExp(`^${name}+(-.+|[0-9]+)$`).test(selector))?.[1];
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
const ignoredColors = [
|
|
897
|
+
"transparent",
|
|
898
|
+
"current",
|
|
899
|
+
"currentColor",
|
|
900
|
+
"inherit",
|
|
901
|
+
"initial",
|
|
902
|
+
"unset",
|
|
903
|
+
"none"
|
|
904
|
+
];
|
|
905
|
+
function uniq(array) {
|
|
906
|
+
return [...new Set(array)];
|
|
907
|
+
}
|
|
908
|
+
async function analyzer(modules, ctx) {
|
|
909
|
+
const matched = [];
|
|
910
|
+
const colors = [];
|
|
911
|
+
const tokensInfo = /* @__PURE__ */ new Map();
|
|
912
|
+
await Promise.all(modules.map(async (code, id) => {
|
|
913
|
+
const result = await ctx.uno.generate(code, { id, extendedInfo: true, preflights: false });
|
|
914
|
+
for (const [key, value] of result.matched.entries()) {
|
|
915
|
+
const prev = tokensInfo.get(key);
|
|
916
|
+
tokensInfo.set(key, {
|
|
917
|
+
data: value.data,
|
|
918
|
+
count: prev?.modules?.length ? value.count + prev.count : value.count,
|
|
919
|
+
modules: uniq([...prev?.modules || [], id])
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
}));
|
|
923
|
+
for (const [rawSelector, { data, count, modules: _modules }] of tokensInfo.entries()) {
|
|
924
|
+
const ruleContext = data[data.length - 1][5];
|
|
925
|
+
const ruleMeta = data[data.length - 1][4];
|
|
926
|
+
const baseSelector = ruleContext?.currentSelector;
|
|
927
|
+
const variants = ruleContext?.variants?.map((v) => v.name).filter(Boolean);
|
|
928
|
+
const layer = ruleMeta?.layer || "default";
|
|
929
|
+
if (baseSelector) {
|
|
930
|
+
const category = layer !== "default" ? layer : getSelectorCategory(baseSelector);
|
|
931
|
+
const body = baseSelector.replace(/^ring-offset|outline-solid|outline-dotted/, "head").replace(/^\w+-/, "");
|
|
932
|
+
const parsedColor = parseColor$1(body, ctx.uno.config.theme);
|
|
933
|
+
if (parsedColor?.color && !ignoredColors.includes(parsedColor?.color)) {
|
|
934
|
+
const existing = colors.find((c) => c.name === parsedColor.name && c.no === parsedColor.no);
|
|
935
|
+
if (existing) {
|
|
936
|
+
existing.count += count;
|
|
937
|
+
existing.modules = uniq([...existing.modules, ..._modules]);
|
|
938
|
+
} else {
|
|
939
|
+
colors.push({
|
|
940
|
+
name: parsedColor.name,
|
|
941
|
+
no: parsedColor.no,
|
|
942
|
+
color: parsedColor.color,
|
|
943
|
+
count,
|
|
944
|
+
modules: _modules
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (category) {
|
|
949
|
+
matched.push({
|
|
950
|
+
name: rawSelector,
|
|
951
|
+
rawSelector,
|
|
952
|
+
baseSelector,
|
|
953
|
+
category,
|
|
954
|
+
variants,
|
|
955
|
+
count,
|
|
956
|
+
ruleMeta,
|
|
957
|
+
modules: _modules
|
|
958
|
+
});
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
matched.push({
|
|
963
|
+
name: rawSelector,
|
|
964
|
+
rawSelector,
|
|
965
|
+
category: "other",
|
|
966
|
+
count,
|
|
967
|
+
modules: _modules
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
return {
|
|
971
|
+
matched,
|
|
972
|
+
colors
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
|
|
10
976
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
11
977
|
function UnocssInspector(ctx) {
|
|
12
978
|
async function configureServer(server) {
|
|
@@ -40,10 +1006,13 @@ function UnocssInspector(ctx) {
|
|
|
40
1006
|
res.end();
|
|
41
1007
|
return;
|
|
42
1008
|
}
|
|
43
|
-
const
|
|
1009
|
+
const tokens = new CountableSet();
|
|
1010
|
+
await ctx.uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
1011
|
+
const result = await ctx.uno.generate(tokens, { id, extendedInfo: true, preflights: false });
|
|
1012
|
+
const analyzed = await analyzer(new BetterMap([[id, code]]), ctx);
|
|
44
1013
|
const mod = {
|
|
45
1014
|
...result,
|
|
46
|
-
|
|
1015
|
+
...analyzed,
|
|
47
1016
|
gzipSize: await gzipSize(result.css),
|
|
48
1017
|
code,
|
|
49
1018
|
id
|
|
@@ -68,10 +1037,12 @@ function UnocssInspector(ctx) {
|
|
|
68
1037
|
return;
|
|
69
1038
|
}
|
|
70
1039
|
if (req.url.startsWith("/overview")) {
|
|
71
|
-
const result = await ctx.uno.generate(ctx.tokens);
|
|
1040
|
+
const result = await ctx.uno.generate(ctx.tokens, { preflights: false });
|
|
1041
|
+
const analyzed = await analyzer(ctx.modules, ctx);
|
|
72
1042
|
const mod = {
|
|
73
1043
|
...result,
|
|
74
|
-
|
|
1044
|
+
colors: analyzed.colors.map((s) => ({ ...s, modules: [...s.modules] })),
|
|
1045
|
+
matched: analyzed.matched.map((s) => ({ ...s, modules: [...s.modules] })),
|
|
75
1046
|
gzipSize: await gzipSize(result.css)
|
|
76
1047
|
};
|
|
77
1048
|
res.setHeader("Content-Type", "application/json");
|