@unocss/inspector 0.54.3 → 0.55.1

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