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