@unocss/inspector 66.5.10 → 66.5.11

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.mjs CHANGED
@@ -1,946 +1,1238 @@
1
- import { dirname, resolve } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { escapeSelector, CountableSet, BetterMap } from '@unocss/core';
4
- import { green, bold, cyan } from 'colorette';
5
- import gzipSize from 'gzip-size';
6
- import sirv from 'sirv';
7
- import { createValueHandler, parseCssColor, getStringComponent } from '@unocss/rule-utils';
1
+ import { dirname, resolve } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { BetterMap, CountableSet, escapeSelector, toArray } from "@unocss/core";
4
+ import { bold, cyan, green } from "colorette";
5
+ import gzipSize from "gzip-size";
6
+ import sirv from "sirv";
7
+ import { colorOpacityToString, colorToString, createValueHandler, getStringComponent, getStringComponents, parseCssColor } from "@unocss/rule-utils";
8
8
 
9
+ //#region rolldown:runtime
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __exportAll = (all, symbols) => {
15
+ let target = {};
16
+ for (var name in all) {
17
+ __defProp(target, name, {
18
+ get: all[name],
19
+ enumerable: true
20
+ });
21
+ }
22
+ if (symbols) {
23
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
24
+ }
25
+ return target;
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
30
+ key = keys[i];
31
+ if (!__hasOwnProp.call(to, key) && key !== except) {
32
+ __defProp(to, key, {
33
+ get: ((k) => from[k]).bind(null, key),
34
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
35
+ });
36
+ }
37
+ }
38
+ }
39
+ return to;
40
+ };
41
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
42
+
43
+ //#endregion
44
+ //#region ../../virtual-shared/integration/src/constants.ts
9
45
  const SKIP_START_COMMENT = "@unocss-skip-start";
10
46
  const SKIP_END_COMMENT = "@unocss-skip-end";
11
- 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");
47
+ 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");
12
48
 
49
+ //#endregion
50
+ //#region ../../packages-presets/preset-mini/src/_utils/mappings.ts
51
+ const directionMap = {
52
+ "l": ["-left"],
53
+ "r": ["-right"],
54
+ "t": ["-top"],
55
+ "b": ["-bottom"],
56
+ "s": ["-inline-start"],
57
+ "e": ["-inline-end"],
58
+ "x": ["-left", "-right"],
59
+ "y": ["-top", "-bottom"],
60
+ "": [""],
61
+ "bs": ["-block-start"],
62
+ "be": ["-block-end"],
63
+ "is": ["-inline-start"],
64
+ "ie": ["-inline-end"],
65
+ "block": ["-block-start", "-block-end"],
66
+ "inline": ["-inline-start", "-inline-end"]
67
+ };
68
+ const insetMap = {
69
+ ...directionMap,
70
+ s: ["-inset-inline-start"],
71
+ start: ["-inset-inline-start"],
72
+ e: ["-inset-inline-end"],
73
+ end: ["-inset-inline-end"],
74
+ bs: ["-inset-block-start"],
75
+ be: ["-inset-block-end"],
76
+ is: ["-inset-inline-start"],
77
+ ie: ["-inset-inline-end"],
78
+ block: ["-inset-block-start", "-inset-block-end"],
79
+ inline: ["-inset-inline-start", "-inset-inline-end"]
80
+ };
81
+ const cornerMap = {
82
+ "l": ["-top-left", "-bottom-left"],
83
+ "r": ["-top-right", "-bottom-right"],
84
+ "t": ["-top-left", "-top-right"],
85
+ "b": ["-bottom-left", "-bottom-right"],
86
+ "tl": ["-top-left"],
87
+ "lt": ["-top-left"],
88
+ "tr": ["-top-right"],
89
+ "rt": ["-top-right"],
90
+ "bl": ["-bottom-left"],
91
+ "lb": ["-bottom-left"],
92
+ "br": ["-bottom-right"],
93
+ "rb": ["-bottom-right"],
94
+ "": [""],
95
+ "bs": ["-start-start", "-start-end"],
96
+ "be": ["-end-start", "-end-end"],
97
+ "s": ["-end-start", "-start-start"],
98
+ "is": ["-end-start", "-start-start"],
99
+ "e": ["-start-end", "-end-end"],
100
+ "ie": ["-start-end", "-end-end"],
101
+ "ss": ["-start-start"],
102
+ "bs-is": ["-start-start"],
103
+ "is-bs": ["-start-start"],
104
+ "se": ["-start-end"],
105
+ "bs-ie": ["-start-end"],
106
+ "ie-bs": ["-start-end"],
107
+ "es": ["-end-start"],
108
+ "be-is": ["-end-start"],
109
+ "is-be": ["-end-start"],
110
+ "ee": ["-end-end"],
111
+ "be-ie": ["-end-end"],
112
+ "ie-be": ["-end-end"]
113
+ };
114
+ const xyzMap = {
115
+ "x": ["-x"],
116
+ "y": ["-y"],
117
+ "z": ["-z"],
118
+ "": ["-x", "-y"]
119
+ };
120
+ const xyzArray = [
121
+ "x",
122
+ "y",
123
+ "z"
124
+ ];
13
125
  const basePositionMap = [
14
- "top",
15
- "top center",
16
- "top left",
17
- "top right",
18
- "bottom",
19
- "bottom center",
20
- "bottom left",
21
- "bottom right",
22
- "left",
23
- "left center",
24
- "left top",
25
- "left bottom",
26
- "right",
27
- "right center",
28
- "right top",
29
- "right bottom",
30
- "center",
31
- "center top",
32
- "center bottom",
33
- "center left",
34
- "center right",
35
- "center center"
126
+ "top",
127
+ "top center",
128
+ "top left",
129
+ "top right",
130
+ "bottom",
131
+ "bottom center",
132
+ "bottom left",
133
+ "bottom right",
134
+ "left",
135
+ "left center",
136
+ "left top",
137
+ "left bottom",
138
+ "right",
139
+ "right center",
140
+ "right top",
141
+ "right bottom",
142
+ "center",
143
+ "center top",
144
+ "center bottom",
145
+ "center left",
146
+ "center right",
147
+ "center center"
36
148
  ];
37
- Object.assign(
38
- {},
39
- ...basePositionMap.map((p) => ({ [p.replace(/ /, "-")]: p })),
40
- ...basePositionMap.map((p) => ({ [p.replace(/\b(\w)\w+/g, "$1").replace(/ /, "")]: p }))
41
- );
149
+ const positionMap = Object.assign({}, ...basePositionMap.map((p) => ({ [p.replace(/ /, "-")]: p })), ...basePositionMap.map((p) => ({ [p.replace(/\b(\w)\w+/g, "$1").replace(/ /, "")]: p })));
42
150
  const globalKeywords = [
43
- "inherit",
44
- "initial",
45
- "revert",
46
- "revert-layer",
47
- "unset"
151
+ "inherit",
152
+ "initial",
153
+ "revert",
154
+ "revert-layer",
155
+ "unset"
48
156
  ];
157
+ const cssMathFnRE = /^(calc|clamp|min|max)\s*\((.+)\)(.*)/;
158
+ const cssVarFnRE = /^(var)\s*\((.+)\)(.*)/;
49
159
 
160
+ //#endregion
161
+ //#region ../../packages-presets/preset-mini/src/_utils/handlers/regex.ts
50
162
  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;
51
163
  const numberRE = /^(-?\d*(?:\.\d+)?)$/;
52
164
  const unitOnlyRE = /^(px|[sld]?v[wh])$/i;
53
165
  const unitOnlyMap = {
54
- px: 1,
55
- vw: 100,
56
- vh: 100,
57
- svw: 100,
58
- svh: 100,
59
- dvw: 100,
60
- dvh: 100,
61
- lvh: 100,
62
- lvw: 100
166
+ px: 1,
167
+ vw: 100,
168
+ vh: 100,
169
+ svw: 100,
170
+ svh: 100,
171
+ dvw: 100,
172
+ dvh: 100,
173
+ lvh: 100,
174
+ lvw: 100
63
175
  };
64
176
  const bracketTypeRe = /^\[(color|image|length|size|position|quoted|string):/i;
177
+ const splitComma = /,(?![^()]*\))/g;
65
178
 
179
+ //#endregion
180
+ //#region ../../packages-presets/preset-mini/src/_utils/handlers/handlers.ts
181
+ var handlers_exports = /* @__PURE__ */ __exportAll({
182
+ auto: () => auto,
183
+ bracket: () => bracket,
184
+ bracketOfColor: () => bracketOfColor,
185
+ bracketOfLength: () => bracketOfLength,
186
+ bracketOfPosition: () => bracketOfPosition,
187
+ cssvar: () => cssvar,
188
+ degree: () => degree,
189
+ fraction: () => fraction,
190
+ global: () => global,
191
+ number: () => number,
192
+ numberWithUnit: () => numberWithUnit,
193
+ percent: () => percent,
194
+ position: () => position,
195
+ properties: () => properties,
196
+ px: () => px,
197
+ rem: () => rem,
198
+ time: () => time
199
+ });
66
200
  const cssProps = [
67
- // basic props
68
- "color",
69
- "border-color",
70
- "background-color",
71
- "outline-color",
72
- "text-decoration-color",
73
- "flex-grow",
74
- "flex",
75
- "flex-shrink",
76
- "caret-color",
77
- "font",
78
- "gap",
79
- "opacity",
80
- "visibility",
81
- "z-index",
82
- "font-weight",
83
- "zoom",
84
- "text-shadow",
85
- "transform",
86
- "box-shadow",
87
- "border",
88
- // positions
89
- "background-position",
90
- "left",
91
- "right",
92
- "top",
93
- "bottom",
94
- "object-position",
95
- // sizes
96
- "max-height",
97
- "min-height",
98
- "max-width",
99
- "min-width",
100
- "height",
101
- "width",
102
- "border-width",
103
- "margin",
104
- "padding",
105
- "outline-width",
106
- "outline-offset",
107
- "font-size",
108
- "line-height",
109
- "text-indent",
110
- "vertical-align",
111
- "border-spacing",
112
- "letter-spacing",
113
- "word-spacing",
114
- // enhances
115
- "stroke",
116
- "filter",
117
- "backdrop-filter",
118
- "fill",
119
- "mask",
120
- "mask-size",
121
- "mask-border",
122
- "clip-path",
123
- "clip",
124
- "border-radius"
201
+ "color",
202
+ "border-color",
203
+ "background-color",
204
+ "outline-color",
205
+ "text-decoration-color",
206
+ "flex-grow",
207
+ "flex",
208
+ "flex-shrink",
209
+ "caret-color",
210
+ "font",
211
+ "gap",
212
+ "opacity",
213
+ "visibility",
214
+ "z-index",
215
+ "font-weight",
216
+ "zoom",
217
+ "text-shadow",
218
+ "transform",
219
+ "box-shadow",
220
+ "border",
221
+ "background-position",
222
+ "left",
223
+ "right",
224
+ "top",
225
+ "bottom",
226
+ "object-position",
227
+ "max-height",
228
+ "min-height",
229
+ "max-width",
230
+ "min-width",
231
+ "height",
232
+ "width",
233
+ "border-width",
234
+ "margin",
235
+ "padding",
236
+ "outline-width",
237
+ "outline-offset",
238
+ "font-size",
239
+ "line-height",
240
+ "text-indent",
241
+ "vertical-align",
242
+ "border-spacing",
243
+ "letter-spacing",
244
+ "word-spacing",
245
+ "stroke",
246
+ "filter",
247
+ "backdrop-filter",
248
+ "fill",
249
+ "mask",
250
+ "mask-size",
251
+ "mask-border",
252
+ "clip-path",
253
+ "clip",
254
+ "border-radius"
125
255
  ];
126
256
  function round(n) {
127
- return +n.toFixed(10);
257
+ return +n.toFixed(10);
128
258
  }
129
259
  function numberWithUnit(str) {
130
- const match = str.match(numberWithUnitRE);
131
- if (!match)
132
- return;
133
- const [, n, unit] = match;
134
- const num = Number.parseFloat(n);
135
- if (unit && !Number.isNaN(num))
136
- return `${round(num)}${unit}`;
260
+ const match = str.match(numberWithUnitRE);
261
+ if (!match) return;
262
+ const [, n, unit] = match;
263
+ const num = Number.parseFloat(n);
264
+ if (unit && !Number.isNaN(num)) return `${round(num)}${unit}`;
137
265
  }
138
266
  function auto(str) {
139
- if (str === "auto" || str === "a")
140
- return "auto";
267
+ if (str === "auto" || str === "a") return "auto";
141
268
  }
142
269
  function rem(str) {
143
- if (!str)
144
- return;
145
- if (unitOnlyRE.test(str))
146
- return `${unitOnlyMap[str]}${str}`;
147
- const match = str.match(numberWithUnitRE);
148
- if (!match)
149
- return;
150
- const [, n, unit] = match;
151
- const num = Number.parseFloat(n);
152
- if (!Number.isNaN(num)) {
153
- if (num === 0)
154
- return "0";
155
- return unit ? `${round(num)}${unit}` : `${round(num / 4)}rem`;
156
- }
270
+ if (!str) return;
271
+ if (unitOnlyRE.test(str)) return `${unitOnlyMap[str]}${str}`;
272
+ const match = str.match(numberWithUnitRE);
273
+ if (!match) return;
274
+ const [, n, unit] = match;
275
+ const num = Number.parseFloat(n);
276
+ if (!Number.isNaN(num)) {
277
+ if (num === 0) return "0";
278
+ return unit ? `${round(num)}${unit}` : `${round(num / 4)}rem`;
279
+ }
157
280
  }
158
281
  function px(str) {
159
- if (unitOnlyRE.test(str))
160
- return `${unitOnlyMap[str]}${str}`;
161
- const match = str.match(numberWithUnitRE);
162
- if (!match)
163
- return;
164
- const [, n, unit] = match;
165
- const num = Number.parseFloat(n);
166
- if (!Number.isNaN(num))
167
- return unit ? `${round(num)}${unit}` : `${round(num)}px`;
282
+ if (unitOnlyRE.test(str)) return `${unitOnlyMap[str]}${str}`;
283
+ const match = str.match(numberWithUnitRE);
284
+ if (!match) return;
285
+ const [, n, unit] = match;
286
+ const num = Number.parseFloat(n);
287
+ if (!Number.isNaN(num)) return unit ? `${round(num)}${unit}` : `${round(num)}px`;
168
288
  }
169
289
  function number(str) {
170
- if (!numberRE.test(str))
171
- return;
172
- const num = Number.parseFloat(str);
173
- if (!Number.isNaN(num))
174
- return round(num);
290
+ if (!numberRE.test(str)) return;
291
+ const num = Number.parseFloat(str);
292
+ if (!Number.isNaN(num)) return round(num);
175
293
  }
176
294
  function percent(str) {
177
- if (str.endsWith("%"))
178
- str = str.slice(0, -1);
179
- if (!numberRE.test(str))
180
- return;
181
- const num = Number.parseFloat(str);
182
- if (!Number.isNaN(num))
183
- return `${round(num / 100)}`;
295
+ if (str.endsWith("%")) str = str.slice(0, -1);
296
+ if (!numberRE.test(str)) return;
297
+ const num = Number.parseFloat(str);
298
+ if (!Number.isNaN(num)) return `${round(num / 100)}`;
184
299
  }
185
300
  function fraction(str) {
186
- if (!str)
187
- return;
188
- if (str === "full")
189
- return "100%";
190
- const [left, right] = str.split("/");
191
- const num = Number.parseFloat(left) / Number.parseFloat(right);
192
- if (!Number.isNaN(num)) {
193
- if (num === 0)
194
- return "0";
195
- return `${round(num * 100)}%`;
196
- }
301
+ if (!str) return;
302
+ if (str === "full") return "100%";
303
+ const [left, right] = str.split("/");
304
+ const num = Number.parseFloat(left) / Number.parseFloat(right);
305
+ if (!Number.isNaN(num)) {
306
+ if (num === 0) return "0";
307
+ return `${round(num * 100)}%`;
308
+ }
197
309
  }
198
310
  function bracketWithType(str, requiredType) {
199
- if (str && str.startsWith("[") && str.endsWith("]")) {
200
- let base;
201
- let hintedType;
202
- const match = str.match(bracketTypeRe);
203
- if (!match) {
204
- base = str.slice(1, -1);
205
- } else {
206
- if (!requiredType)
207
- hintedType = match[1];
208
- base = str.slice(match[0].length, -1);
209
- }
210
- if (!base)
211
- return;
212
- if (base === '=""')
213
- return;
214
- if (base.startsWith("--"))
215
- base = `var(${base})`;
216
- let curly = 0;
217
- for (const i of base) {
218
- if (i === "[") {
219
- curly += 1;
220
- } else if (i === "]") {
221
- curly -= 1;
222
- if (curly < 0)
223
- return;
224
- }
225
- }
226
- if (curly)
227
- return;
228
- switch (hintedType) {
229
- case "string":
230
- return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_");
231
- case "quoted":
232
- return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(["\\])/g, "\\$1").replace(/^(.+)$/, '"$1"');
233
- }
234
- return base.replace(/(url\(.*?\))/g, (v) => v.replace(/_/g, "\\_")).replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(?:calc|clamp|max|min)\((.*)/g, (match2) => {
235
- const vars = [];
236
- return match2.replace(/var\((--.+?)[,)]/g, (match3, g1) => {
237
- vars.push(g1);
238
- return match3.replace(g1, "--un-calc");
239
- }).replace(/(-?\d*\.?\d(?!-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ").replace(/--un-calc/g, () => vars.shift());
240
- });
241
- }
311
+ if (str && str.startsWith("[") && str.endsWith("]")) {
312
+ let base;
313
+ let hintedType;
314
+ const match = str.match(bracketTypeRe);
315
+ if (!match) base = str.slice(1, -1);
316
+ else {
317
+ if (!requiredType) hintedType = match[1];
318
+ base = str.slice(match[0].length, -1);
319
+ }
320
+ if (!base) return;
321
+ if (base === "=\"\"") return;
322
+ if (base.startsWith("--")) base = `var(${base})`;
323
+ let curly = 0;
324
+ for (const i of base) if (i === "[") curly += 1;
325
+ else if (i === "]") {
326
+ curly -= 1;
327
+ if (curly < 0) return;
328
+ }
329
+ if (curly) return;
330
+ switch (hintedType) {
331
+ case "string": return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_");
332
+ case "quoted": return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(["\\])/g, "\\$1").replace(/^(.+)$/, "\"$1\"");
333
+ }
334
+ return base.replace(/(url\(.*?\))/g, (v) => v.replace(/_/g, "\\_")).replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(?:calc|clamp|max|min)\((.*)/g, (match$1) => {
335
+ const vars = [];
336
+ return match$1.replace(/var\((--.+?)[,)]/g, (match$2, g1) => {
337
+ vars.push(g1);
338
+ return match$2.replace(g1, "--un-calc");
339
+ }).replace(/(-?\d*\.?\d(?!-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ").replace(/--un-calc/g, () => vars.shift());
340
+ });
341
+ }
242
342
  }
243
343
  function bracket(str) {
244
- return bracketWithType(str);
344
+ return bracketWithType(str);
245
345
  }
246
346
  function bracketOfColor(str) {
247
- return bracketWithType(str, "color");
347
+ return bracketWithType(str, "color");
248
348
  }
249
349
  function bracketOfLength(str) {
250
- return bracketWithType(str, "length");
350
+ return bracketWithType(str, "length");
251
351
  }
252
352
  function bracketOfPosition(str) {
253
- return bracketWithType(str, "position");
353
+ return bracketWithType(str, "position");
254
354
  }
255
355
  function cssvar(str) {
256
- if (/^\$[^\s'"`;{}]/.test(str)) {
257
- const [name, defaultValue] = str.slice(1).split(",");
258
- return `var(--${escapeSelector(name)}${defaultValue ? `, ${defaultValue}` : ""})`;
259
- }
356
+ if (/^\$[^\s'"`;{}]/.test(str)) {
357
+ const [name, defaultValue] = str.slice(1).split(",");
358
+ return `var(--${escapeSelector(name)}${defaultValue ? `, ${defaultValue}` : ""})`;
359
+ }
260
360
  }
261
361
  function time(str) {
262
- const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
263
- if (!match)
264
- return;
265
- const [, n, unit] = match;
266
- const num = Number.parseFloat(n);
267
- if (!Number.isNaN(num)) {
268
- if (num === 0 && !unit)
269
- return "0s";
270
- return unit ? `${round(num)}${unit}` : `${round(num)}ms`;
271
- }
362
+ const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
363
+ if (!match) return;
364
+ const [, n, unit] = match;
365
+ const num = Number.parseFloat(n);
366
+ if (!Number.isNaN(num)) {
367
+ if (num === 0 && !unit) return "0s";
368
+ return unit ? `${round(num)}${unit}` : `${round(num)}ms`;
369
+ }
272
370
  }
273
371
  function degree(str) {
274
- const match = str.match(/^(-?[0-9.]+)(deg|rad|grad|turn)?$/i);
275
- if (!match)
276
- return;
277
- const [, n, unit] = match;
278
- const num = Number.parseFloat(n);
279
- if (!Number.isNaN(num)) {
280
- if (num === 0)
281
- return "0deg";
282
- return unit ? `${round(num)}${unit}` : `${round(num)}deg`;
283
- }
372
+ const match = str.match(/^(-?[0-9.]+)(deg|rad|grad|turn)?$/i);
373
+ if (!match) return;
374
+ const [, n, unit] = match;
375
+ const num = Number.parseFloat(n);
376
+ if (!Number.isNaN(num)) {
377
+ if (num === 0) return "0deg";
378
+ return unit ? `${round(num)}${unit}` : `${round(num)}deg`;
379
+ }
284
380
  }
285
381
  function global(str) {
286
- if (globalKeywords.includes(str))
287
- return str;
382
+ if (globalKeywords.includes(str)) return str;
288
383
  }
289
384
  function properties(str) {
290
- if (str.split(",").every((prop) => cssProps.includes(prop)))
291
- return str;
385
+ if (str.split(",").every((prop) => cssProps.includes(prop))) return str;
292
386
  }
293
387
  function position(str) {
294
- if (["top", "left", "right", "bottom", "center"].includes(str))
295
- return str;
388
+ if ([
389
+ "top",
390
+ "left",
391
+ "right",
392
+ "bottom",
393
+ "center"
394
+ ].includes(str)) return str;
296
395
  }
297
396
 
298
- const valueHandlers = {
299
- __proto__: null,
300
- auto: auto,
301
- bracket: bracket,
302
- bracketOfColor: bracketOfColor,
303
- bracketOfLength: bracketOfLength,
304
- bracketOfPosition: bracketOfPosition,
305
- cssvar: cssvar,
306
- degree: degree,
307
- fraction: fraction,
308
- global: global,
309
- number: number,
310
- numberWithUnit: numberWithUnit,
311
- percent: percent,
312
- position: position,
313
- properties: properties,
314
- px: px,
315
- rem: rem,
316
- time: time
317
- };
318
-
319
- const handler = createValueHandler(valueHandlers);
397
+ //#endregion
398
+ //#region ../../packages-presets/preset-mini/src/_utils/handlers/index.ts
399
+ const handler = createValueHandler(handlers_exports);
320
400
  const h = handler;
321
401
 
402
+ //#endregion
403
+ //#region ../../packages-presets/preset-mini/src/_utils/utilities.ts
404
+ const CONTROL_MINI_NO_NEGATIVE = "$$mini-no-negative";
405
+ /**
406
+ * Provide {@link DynamicMatcher} function returning spacing definition. See spacing rules.
407
+ *
408
+ * @param propertyPrefix - Property for the css value to be created. Postfix will be appended according to direction matched.
409
+ * @see {@link directionMap}
410
+ */
411
+ function directionSize(propertyPrefix) {
412
+ return ([_, direction, size], { theme }) => {
413
+ const v = theme.spacing?.[size || "DEFAULT"] ?? h.bracket.cssvar.global.auto.fraction.rem(size);
414
+ if (v != null) return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, v]);
415
+ else if (size?.startsWith("-")) {
416
+ const v$1 = theme.spacing?.[size.slice(1)];
417
+ if (v$1 != null) return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, `calc(${v$1} * -1)`]);
418
+ }
419
+ };
420
+ }
322
421
  function getThemeColorForKey(theme, colors, key = "colors") {
323
- let obj = theme[key];
324
- let index = -1;
325
- for (const c of colors) {
326
- index += 1;
327
- if (obj && typeof obj !== "string") {
328
- const camel = colors.slice(index).join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase());
329
- if (obj[camel])
330
- return obj[camel];
331
- if (obj[c]) {
332
- obj = obj[c];
333
- continue;
334
- }
335
- }
336
- return void 0;
337
- }
338
- return obj;
422
+ const obj = theme[key];
423
+ function deepGet(current, path) {
424
+ if (path.length === 0) return current;
425
+ if (!current || typeof current !== "object") return void 0;
426
+ for (let i = path.length; i > 0; i--) {
427
+ const flatKey = path.slice(0, i).join("-");
428
+ const value = current[flatKey.replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase())] ?? current[flatKey];
429
+ if (value != null) {
430
+ if (i === path.length) return value;
431
+ return deepGet(value, path.slice(i));
432
+ }
433
+ }
434
+ }
435
+ return deepGet(obj, colors);
339
436
  }
437
+ /**
438
+ * Obtain color from theme by camel-casing colors.
439
+ */
340
440
  function getThemeColor(theme, colors, key) {
341
- return getThemeColorForKey(theme, colors, key) || getThemeColorForKey(theme, colors, "colors");
441
+ return getThemeColorForKey(theme, colors, key) || getThemeColorForKey(theme, colors, "colors");
342
442
  }
443
+ /**
444
+ * Split utility shorthand delimited by / or :
445
+ */
343
446
  function splitShorthand(body, type) {
344
- const [front, rest] = getStringComponent(body, "[", "]", ["/", ":"]) ?? [];
345
- if (front != null) {
346
- const match = (front.match(bracketTypeRe) ?? [])[1];
347
- if (match == null || match === type)
348
- return [front, rest];
349
- }
447
+ const [front, rest] = getStringComponent(body, "[", "]", ["/", ":"]) ?? [];
448
+ if (front != null) {
449
+ const match = (front.match(bracketTypeRe) ?? [])[1];
450
+ if (match == null || match === type) return [front, rest];
451
+ }
350
452
  }
453
+ /**
454
+ * Parse color string into {@link ParsedColorValue} (if possible). Color value will first be matched to theme object before parsing.
455
+ * See also color.tests.ts for more examples.
456
+ *
457
+ * @example Parseable strings:
458
+ * 'red' // From theme, if 'red' is available
459
+ * 'red-100' // From theme, plus scale
460
+ * 'red-100/20' // From theme, plus scale/opacity
461
+ * '[rgb(100 2 3)]/[var(--op)]' // Bracket with rgb color and bracket with opacity
462
+ *
463
+ * @param body - Color string to be parsed.
464
+ * @param theme - {@link Theme} object.
465
+ * @return object if string is parseable.
466
+ */
351
467
  function parseColor(body, theme, key) {
352
- const split = splitShorthand(body, "color");
353
- if (!split)
354
- return;
355
- const [main, opacity] = split;
356
- const colors = main.replace(/([a-z])(\d)/g, "$1-$2").split(/-/g);
357
- const [name] = colors;
358
- if (!name)
359
- return;
360
- let color;
361
- const bracket = h.bracketOfColor(main);
362
- const bracketOrMain = bracket || main;
363
- if (h.numberWithUnit(bracketOrMain))
364
- return;
365
- if (/^#[\da-f]+$/i.test(bracketOrMain))
366
- color = bracketOrMain;
367
- else if (/^hex-[\da-fA-F]+$/.test(bracketOrMain))
368
- color = `#${bracketOrMain.slice(4)}`;
369
- else if (main.startsWith("$"))
370
- color = h.cssvar(main);
371
- color = color || bracket;
372
- if (!color) {
373
- const colorData = getThemeColor(theme, [main], key);
374
- if (typeof colorData === "string")
375
- color = colorData;
376
- }
377
- let no = "DEFAULT";
378
- if (!color) {
379
- let keys = colors;
380
- let _no;
381
- const [scale] = colors.slice(-1);
382
- if (/^\d+$/.test(scale)) {
383
- no = _no = scale;
384
- keys = colors.slice(0, -1);
385
- }
386
- const colorData = getThemeColor(theme, keys, key);
387
- if (typeof colorData === "object") {
388
- color = colorData[_no ?? no];
389
- } else if (typeof colorData === "string" && !_no) {
390
- color = colorData;
391
- }
392
- }
393
- return {
394
- opacity,
395
- name,
396
- no,
397
- color,
398
- cssColor: parseCssColor(color),
399
- alpha: h.bracket.cssvar.percent(opacity ?? "")
400
- };
468
+ const split = splitShorthand(body, "color");
469
+ if (!split) return;
470
+ const [main, opacity] = split;
471
+ const colors = main.replace(/([a-z])(\d)/g, "$1-$2").split(/-/g);
472
+ const [name] = colors;
473
+ if (!name) return;
474
+ let color;
475
+ const bracket$1 = h.bracketOfColor(main);
476
+ const bracketOrMain = bracket$1 || main;
477
+ if (h.numberWithUnit(bracketOrMain)) return;
478
+ if (/^#[\da-f]+$/i.test(bracketOrMain)) color = bracketOrMain;
479
+ else if (/^hex-[\da-fA-F]+$/.test(bracketOrMain)) color = `#${bracketOrMain.slice(4)}`;
480
+ else if (main.startsWith("$")) color = h.cssvar(main);
481
+ color = color || bracket$1;
482
+ if (!color) {
483
+ const colorData = getThemeColor(theme, [main], key);
484
+ if (typeof colorData === "string") color = colorData;
485
+ }
486
+ let no = "DEFAULT";
487
+ if (!color) {
488
+ let keys = colors;
489
+ let _no;
490
+ const [scale] = colors.slice(-1);
491
+ if (/^\d+$/.test(scale)) {
492
+ no = _no = scale;
493
+ keys = colors.slice(0, -1);
494
+ }
495
+ const colorData = getThemeColor(theme, keys, key);
496
+ if (typeof colorData === "object") color = colorData[_no ?? no];
497
+ else if (typeof colorData === "string" && !_no) color = colorData;
498
+ }
499
+ return {
500
+ opacity,
501
+ name,
502
+ no,
503
+ color,
504
+ cssColor: parseCssColor(color),
505
+ alpha: h.bracket.cssvar.percent(opacity ?? "")
506
+ };
401
507
  }
508
+ /**
509
+ * Provide {@link DynamicMatcher} function to produce color value matched from rule.
510
+ *
511
+ * @see {@link parseColor}
512
+ *
513
+ * @example Resolving 'red' from theme:
514
+ * colorResolver('background-color', 'background')('', 'red')
515
+ * return { 'background-color': '#f12' }
516
+ *
517
+ * @example Resolving 'red-100' from theme:
518
+ * colorResolver('background-color', 'background')('', 'red-100')
519
+ * return { '--un-background-opacity': '1', 'background-color': 'rgb(254 226 226 / var(--un-background-opacity))' }
520
+ *
521
+ * @example Resolving 'red-100/20' from theme:
522
+ * colorResolver('background-color', 'background')('', 'red-100/20')
523
+ * return { 'background-color': 'rgb(204 251 241 / 0.22)' }
524
+ *
525
+ * @example Resolving 'hex-124':
526
+ * colorResolver('color', 'text')('', 'hex-124')
527
+ * return { '--un-text-opacity': '1', 'color': 'rgb(17 34 68 / var(--un-text-opacity))' }
528
+ *
529
+ * @param property - Property for the css value to be created.
530
+ * @param varName - Base name for the opacity variable.
531
+ * @param [key] - Theme key to select the color from.
532
+ * @param [shouldPass] - Function to decide whether to pass the css.
533
+ * @return object.
534
+ */
535
+ function colorResolver(property, varName, key, shouldPass) {
536
+ return ([, body], { theme, generator }) => {
537
+ const data = parseColor(body ?? "", theme, key);
538
+ if (!data) return;
539
+ const { alpha, color, cssColor } = data;
540
+ const rawColorComment = generator.config.envMode === "dev" && color ? ` /* ${color} */` : "";
541
+ const css = {};
542
+ if (cssColor) if (alpha != null) css[property] = colorToString(cssColor, alpha) + rawColorComment;
543
+ else {
544
+ const opacityVar = `--un-${varName}-opacity`;
545
+ const result = colorToString(cssColor, `var(${opacityVar})`);
546
+ if (result.includes(opacityVar)) css[opacityVar] = colorOpacityToString(cssColor);
547
+ css[property] = result + rawColorComment;
548
+ }
549
+ else if (color) if (alpha != null) css[property] = colorToString(color, alpha) + rawColorComment;
550
+ else {
551
+ const opacityVar = `--un-${varName}-opacity`;
552
+ const result = colorToString(color, `var(${opacityVar})`);
553
+ if (result.includes(opacityVar)) css[opacityVar] = 1;
554
+ css[property] = result + rawColorComment;
555
+ }
556
+ if (shouldPass?.(css) !== false) return css;
557
+ };
558
+ }
559
+ function colorableShadows(shadows, colorVar) {
560
+ const colored = [];
561
+ shadows = toArray(shadows);
562
+ for (let i = 0; i < shadows.length; i++) {
563
+ const components = getStringComponents(shadows[i], " ", 6);
564
+ if (!components || components.length < 3) return shadows;
565
+ let isInset = false;
566
+ const pos = components.indexOf("inset");
567
+ if (pos !== -1) {
568
+ components.splice(pos, 1);
569
+ isInset = true;
570
+ }
571
+ let colorVarValue = "";
572
+ const lastComp = components.at(-1);
573
+ if (parseCssColor(components.at(0))) {
574
+ const color = parseCssColor(components.shift());
575
+ if (color) colorVarValue = `, ${colorToString(color)}`;
576
+ } else if (parseCssColor(lastComp)) {
577
+ const color = parseCssColor(components.pop());
578
+ if (color) colorVarValue = `, ${colorToString(color)}`;
579
+ } else if (lastComp && lastComp.startsWith("var(")) colorVarValue = `, ${components.pop()}`;
580
+ colored.push(`${isInset ? "inset " : ""}${components.join(" ")} var(${colorVar}${colorVarValue})`);
581
+ }
582
+ return colored;
583
+ }
584
+ function hasParseableColor(color, theme, key) {
585
+ return color != null && !!parseColor(color, theme, key)?.color;
586
+ }
587
+ const reLetters = /[a-z]+/gi;
588
+ const resolvedBreakpoints = /* @__PURE__ */ new WeakMap();
589
+ function resolveBreakpoints({ theme, generator }, key = "breakpoints") {
590
+ const breakpoints = (generator?.userConfig?.theme)?.[key] || theme[key];
591
+ if (!breakpoints) return void 0;
592
+ if (resolvedBreakpoints.has(theme)) return resolvedBreakpoints.get(theme);
593
+ const resolved = Object.entries(breakpoints).sort((a, b) => Number.parseInt(a[1].replace(reLetters, "")) - Number.parseInt(b[1].replace(reLetters, ""))).map(([point, size]) => ({
594
+ point,
595
+ size
596
+ }));
597
+ resolvedBreakpoints.set(theme, resolved);
598
+ return resolved;
599
+ }
600
+ function resolveVerticalBreakpoints(context) {
601
+ return resolveBreakpoints(context, "verticalBreakpoints");
602
+ }
603
+ function makeGlobalStaticRules(prefix, property) {
604
+ return globalKeywords.map((keyword) => [`${prefix}-${keyword}`, { [property ?? prefix]: keyword }]);
605
+ }
606
+ function isCSSMathFn(value) {
607
+ return value != null && cssMathFnRE.test(value);
608
+ }
609
+ function isSize(str) {
610
+ if (str[0] === "[" && str.slice(-1) === "]") str = str.slice(1, -1);
611
+ return cssMathFnRE.test(str) || numberWithUnitRE.test(str);
612
+ }
613
+ function transformXYZ(d, v, name) {
614
+ const values = v.split(splitComma);
615
+ if (d || !d && values.length === 1) return xyzMap[d].map((i) => [`--un-${name}${i}`, v]);
616
+ return values.map((v$1, i) => [`--un-${name}-${xyzArray[i]}`, v$1]);
617
+ }
618
+
619
+ //#endregion
620
+ //#region ../../packages-presets/preset-mini/src/_utils/index.ts
621
+ var _utils_exports = /* @__PURE__ */ __exportAll({
622
+ CONTROL_MINI_NO_NEGATIVE: () => CONTROL_MINI_NO_NEGATIVE,
623
+ colorResolver: () => colorResolver,
624
+ colorableShadows: () => colorableShadows,
625
+ cornerMap: () => cornerMap,
626
+ cssMathFnRE: () => cssMathFnRE,
627
+ cssVarFnRE: () => cssVarFnRE,
628
+ directionMap: () => directionMap,
629
+ directionSize: () => directionSize,
630
+ globalKeywords: () => globalKeywords,
631
+ h: () => h,
632
+ handler: () => handler,
633
+ hasParseableColor: () => hasParseableColor,
634
+ insetMap: () => insetMap,
635
+ isCSSMathFn: () => isCSSMathFn,
636
+ isSize: () => isSize,
637
+ makeGlobalStaticRules: () => makeGlobalStaticRules,
638
+ parseColor: () => parseColor,
639
+ positionMap: () => positionMap,
640
+ resolveBreakpoints: () => resolveBreakpoints,
641
+ resolveVerticalBreakpoints: () => resolveVerticalBreakpoints,
642
+ splitShorthand: () => splitShorthand,
643
+ transformXYZ: () => transformXYZ,
644
+ valueHandlers: () => handlers_exports,
645
+ xyzArray: () => xyzArray,
646
+ xyzMap: () => xyzMap
647
+ });
648
+ import * as import__unocss_rule_utils from "@unocss/rule-utils";
649
+ __reExport(_utils_exports, import__unocss_rule_utils);
650
+
651
+ //#endregion
652
+ //#region ../../packages-presets/preset-mini/src/utils.ts
653
+ var utils_exports = /* @__PURE__ */ __exportAll({
654
+ CONTROL_MINI_NO_NEGATIVE: () => CONTROL_MINI_NO_NEGATIVE,
655
+ colorResolver: () => colorResolver,
656
+ colorableShadows: () => colorableShadows,
657
+ cornerMap: () => cornerMap,
658
+ cssMathFnRE: () => cssMathFnRE,
659
+ cssVarFnRE: () => cssVarFnRE,
660
+ directionMap: () => directionMap,
661
+ directionSize: () => directionSize,
662
+ globalKeywords: () => globalKeywords,
663
+ h: () => h,
664
+ handler: () => handler,
665
+ hasParseableColor: () => hasParseableColor,
666
+ insetMap: () => insetMap,
667
+ isCSSMathFn: () => isCSSMathFn,
668
+ isSize: () => isSize,
669
+ makeGlobalStaticRules: () => makeGlobalStaticRules,
670
+ parseColor: () => parseColor,
671
+ positionMap: () => positionMap,
672
+ resolveBreakpoints: () => resolveBreakpoints,
673
+ resolveVerticalBreakpoints: () => resolveVerticalBreakpoints,
674
+ splitShorthand: () => splitShorthand,
675
+ transformXYZ: () => transformXYZ,
676
+ valueHandlers: () => handlers_exports,
677
+ xyzArray: () => xyzArray,
678
+ xyzMap: () => xyzMap
679
+ });
680
+ __reExport(utils_exports, _utils_exports);
402
681
 
682
+ //#endregion
683
+ //#region src/categories.ts
403
684
  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"
685
+ "box-border": "boxSizing",
686
+ "box-content": "boxSizing",
687
+ "b": "border",
688
+ "border": "border",
689
+ "rounded": "border",
690
+ "block": "display",
691
+ "inline-block": "display",
692
+ "inline": "display",
693
+ "flex": "display",
694
+ "inline-flex": "display",
695
+ "table": "display",
696
+ "table-caption": "display",
697
+ "table-cell": "display",
698
+ "table-column": "display",
699
+ "table-column-group": "display",
700
+ "table-footer-group": "display",
701
+ "table-header-group": "display",
702
+ "table-row-group": "display",
703
+ "table-row": "display",
704
+ "flow-root": "display",
705
+ "grid": "display",
706
+ "inline-grid": "display",
707
+ "contents": "display",
708
+ "hidden": "display",
709
+ "float-right": "float",
710
+ "float-left": "float",
711
+ "float-none": "float",
712
+ "clear-left": "clear",
713
+ "clear-right": "clear",
714
+ "clear-both": "clear",
715
+ "clear-none": "clear",
716
+ "object-contain": "objectFit",
717
+ "object-cover": "objectFit",
718
+ "object-fill": "objectFit",
719
+ "object-none": "objectFit",
720
+ "object-scale-down": "objectFit",
721
+ "overflow-auto": "overflow",
722
+ "overflow-hidden": "overflow",
723
+ "overflow-visible": "overflow",
724
+ "overflow-scroll": "overflow",
725
+ "overflow-x-auto": "overflow",
726
+ "overflow-y-auto": "overflow",
727
+ "overflow-x-hidden": "overflow",
728
+ "overflow-y-hidden": "overflow",
729
+ "overflow-x-visible": "overflow",
730
+ "overflow-y-visible": "overflow",
731
+ "overflow-x-scroll": "overflow",
732
+ "overflow-y-scroll": "overflow",
733
+ "of-auto": "overflow",
734
+ "of-hidden": "overflow",
735
+ "of-visible": "overflow",
736
+ "of-scroll": "overflow",
737
+ "of-x-auto": "overflow",
738
+ "of-y-auto": "overflow",
739
+ "of-x-hidden": "overflow",
740
+ "of-y-hidden": "overflow",
741
+ "of-x-visible": "overflow",
742
+ "of-y-visible": "overflow",
743
+ "of-x-scroll": "overflow",
744
+ "of-y-scroll": "overflow",
745
+ "overscroll-auto": "overscrollBehavior",
746
+ "overscroll-contain": "overscrollBehavior",
747
+ "overscroll-none": "overscrollBehavior",
748
+ "overscroll-y-auto": "overscrollBehavior",
749
+ "overscroll-y-contain": "overscrollBehavior",
750
+ "overscroll-y-none": "overscrollBehavior",
751
+ "overscroll-x-auto": "overscrollBehavior",
752
+ "overscroll-x-contain": "overscrollBehavior",
753
+ "overscroll-x-none": "overscrollBehavior",
754
+ "static": "position",
755
+ "fixed": "position",
756
+ "absolute": "position",
757
+ "relative": "position",
758
+ "sticky": "position",
759
+ "visible": "visibility",
760
+ "invisible": "visibility",
761
+ "flex-row": "flex",
762
+ "flex-row-reverse": "flex",
763
+ "flex-col": "flex",
764
+ "flex-col-reverse": "flex",
765
+ "flex-wrap": "flex",
766
+ "flex-wrap-reverse": "flex",
767
+ "flex-nowrap": "flex",
768
+ "col-auto": "grid",
769
+ "row-auto": "grid",
770
+ "grid-flow-row": "grid",
771
+ "grid-flow-col": "grid",
772
+ "grid-flow-row-dense": "grid",
773
+ "grid-flow-col-dense": "grid",
774
+ "justify-start": "justifyContent",
775
+ "justify-end": "justifyContent",
776
+ "justify-center": "justifyContent",
777
+ "justify-between": "justifyContent",
778
+ "justify-around": "justifyContent",
779
+ "justify-evenly": "justifyContent",
780
+ "justify-left": "justifyContent",
781
+ "justify-right": "justifyContent",
782
+ "justify-items-auto": "justifyItems",
783
+ "justify-items-start": "justifyItems",
784
+ "justify-items-end": "justifyItems",
785
+ "justify-items-center": "justifyItems",
786
+ "justify-items-stretch": "justifyItems",
787
+ "justify-self-auto": "justifySelf",
788
+ "justify-self-start": "justifySelf",
789
+ "justify-self-end": "justifySelf",
790
+ "justify-self-center": "justifySelf",
791
+ "justify-self-stretch": "justifySelf",
792
+ "content-center": "alignContent",
793
+ "content-start": "alignContent",
794
+ "content-end": "alignContent",
795
+ "content-between": "alignContent",
796
+ "content-around": "alignContent",
797
+ "content-evenly": "alignContent",
798
+ "items-start": "alignItems",
799
+ "items-end": "alignItems",
800
+ "items-center": "alignItems",
801
+ "items-baseline": "alignItems",
802
+ "items-stretch": "alignItems",
803
+ "self-auto": "alignSelf",
804
+ "self-start": "alignSelf",
805
+ "self-end": "alignSelf",
806
+ "self-center": "alignSelf",
807
+ "self-stretch": "alignSelf",
808
+ "place-content-center": "placeContent",
809
+ "place-content-start": "placeContent",
810
+ "place-content-end": "placeContent",
811
+ "place-content-between": "placeContent",
812
+ "place-content-around": "placeContent",
813
+ "place-content-evenly": "placeContent",
814
+ "place-content-stretch": "placeContent",
815
+ "place-items-auto": "placeItems",
816
+ "place-items-start": "placeItems",
817
+ "place-items-end": "placeItems",
818
+ "place-items-center": "placeItems",
819
+ "place-items-stretch": "placeItems",
820
+ "place-self-auto": "placeSelf",
821
+ "place-self-start": "placeSelf",
822
+ "place-self-end": "placeSelf",
823
+ "place-self-center": "placeSelf",
824
+ "place-self-stretch": "placeSelf",
825
+ "antialiased": "fontSmoothing",
826
+ "subpixel-antialiased": "font",
827
+ "italic": "font",
828
+ "not-italic": "font",
829
+ "normal-nums": "font",
830
+ "ordinal": "font",
831
+ "slashed-zero": "font",
832
+ "lining-nums": "font",
833
+ "oldstyle-nums": "font",
834
+ "proportional-nums": "font",
835
+ "tabular-nums": "font",
836
+ "diagonal-fractions": "font",
837
+ "stacked-fractions": "font",
838
+ "list-inside": "listStylePosition",
839
+ "list-outside": "listStylePosition",
840
+ "text-left": "textAlign",
841
+ "text-center": "textAlign",
842
+ "text-right": "textAlign",
843
+ "text-justify": "textAlign",
844
+ "underline": "textDecoration",
845
+ "line-through": "textDecoration",
846
+ "no-underline": "textDecoration",
847
+ "uppercase": "textTransform",
848
+ "lowercase": "textTransform",
849
+ "capitalize": "textTransform",
850
+ "normal-case": "textTransform",
851
+ "truncate": "textOverflow",
852
+ "overflow-ellipsis": "textOverflow",
853
+ "overflow-clip": "textOverflow",
854
+ "align-baseline": "verticalAlign",
855
+ "align-top": "verticalAlign",
856
+ "align-middle": "verticalAlign",
857
+ "align-bottom": "verticalAlign",
858
+ "align-text-top": "verticalAlign",
859
+ "align-text-bottom": "verticalAlign",
860
+ "whitespace-normal": "whitespace",
861
+ "whitespace-nowrap": "whitespace",
862
+ "whitespace-pre": "whitespace",
863
+ "whitespace-pre-line": "whitespace",
864
+ "whitespace-pre-wrap": "whitespace",
865
+ "ws-normal": "whitespace",
866
+ "ws-nowrap": "whitespace",
867
+ "ws-pre": "whitespace",
868
+ "ws-pre-line": "whitespace",
869
+ "ws-pre-wrap": "whitespace",
870
+ "break-normal": "wordBreak",
871
+ "break-words": "wordBreak",
872
+ "break-all": "wordBreak",
873
+ "bg-fixed": "background",
874
+ "bg-local": "background",
875
+ "bg-scroll": "background",
876
+ "bg-clip-border": "background",
877
+ "bg-clip-padding": "background",
878
+ "bg-clip-content": "background",
879
+ "bg-clip-text": "background",
880
+ "bg-repeat": "background",
881
+ "bg-no-repeat": "background",
882
+ "bg-repeat-x": "background",
883
+ "bg-repeat-y": "background",
884
+ "bg-repeat-round": "background",
885
+ "bg-repeat-space": "background",
886
+ "border-solid": "border",
887
+ "border-dashed": "border",
888
+ "border-dotted": "border",
889
+ "border-double": "border",
890
+ "border-none": "border",
891
+ "border-collapse": "border",
892
+ "border-separate": "border",
893
+ "table-auto": "table",
894
+ "table-fixed": "table",
895
+ "transform": "transform",
896
+ "transform-gpu": "transform",
897
+ "transform-none": "transform",
898
+ "appearance-none": "appearance",
899
+ "pointer-events-none": "pointerEvents",
900
+ "pointer-events-auto": "pointerEvents",
901
+ "resize-none": "resize",
902
+ "resize-y": "resize",
903
+ "resize-x": "resize",
904
+ "resize": "resize",
905
+ "select-none": "userSelect",
906
+ "select-text": "userSelect",
907
+ "select-all": "userSelect",
908
+ "select-auto": "userSelect",
909
+ "fill-current": "fill",
910
+ "stroke-current": "stroke",
911
+ "sr-only": "accessibility",
912
+ "not-sr-only": "accessibility",
913
+ "filter": "filter",
914
+ "invert": "filter"
634
915
  };
635
916
  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"
917
+ container: "container",
918
+ space: "space",
919
+ divide: "divide",
920
+ bg: "background",
921
+ from: "gradientColor",
922
+ via: "gradientColor",
923
+ to: "gradientColor",
924
+ border: "border",
925
+ b: "border",
926
+ rounded: "borderRadius",
927
+ cursor: "cursor",
928
+ flex: "flex",
929
+ shrink: "flex",
930
+ order: "order",
931
+ font: "font",
932
+ h: "size",
933
+ leading: "lineHeight",
934
+ list: "listStyleType",
935
+ m: "margin",
936
+ my: "margin",
937
+ mx: "margin",
938
+ mt: "margin",
939
+ mr: "margin",
940
+ mb: "margin",
941
+ ml: "margin",
942
+ min: "size",
943
+ max: "size",
944
+ object: "objectPosition",
945
+ op: "opacity",
946
+ opacity: "opacity",
947
+ outline: "outline",
948
+ p: "padding",
949
+ py: "padding",
950
+ px: "padding",
951
+ pt: "padding",
952
+ pr: "padding",
953
+ pb: "padding",
954
+ pl: "padding",
955
+ placeholder: "placeholder",
956
+ inset: "inset",
957
+ top: "position",
958
+ right: "position",
959
+ bottom: "position",
960
+ left: "position",
961
+ shadow: "boxShadow",
962
+ ring: "ring",
963
+ fill: "fill",
964
+ stroke: "stroke",
965
+ text: "text",
966
+ tracking: "letterSpacing",
967
+ w: "size",
968
+ z: "zIndex",
969
+ gap: "gap",
970
+ auto: "grid",
971
+ grid: "grid",
972
+ col: "grid",
973
+ row: "grid",
974
+ origin: "transform",
975
+ scale: "transform",
976
+ rotate: "transform",
977
+ translate: "transform",
978
+ skew: "transform",
979
+ transition: "animation",
980
+ ease: "animation",
981
+ duration: "animation",
982
+ delay: "animation",
983
+ animate: "animation",
984
+ filter: "filter",
985
+ backdrop: "filter",
986
+ invert: "filter"
706
987
  };
707
988
 
989
+ //#endregion
990
+ //#region src/utils.ts
708
991
  function getSelectorCategory(selector) {
709
- return staticUtilities[selector] || Object.entries(dynamicUtilities).find(([name]) => new RegExp(`^${name}+(-.+|[0-9]+)$`).test(selector))?.[1];
992
+ return staticUtilities[selector] || Object.entries(dynamicUtilities).find(([name]) => (/* @__PURE__ */ new RegExp(`^${name}+(-.+|[0-9]+)$`)).test(selector))?.[1];
710
993
  }
711
994
 
995
+ //#endregion
996
+ //#region src/analyzer.ts
712
997
  const ignoredColors = [
713
- "transparent",
714
- "current",
715
- "currentColor",
716
- "inherit",
717
- "initial",
718
- "unset",
719
- "none"
998
+ "transparent",
999
+ "current",
1000
+ "currentColor",
1001
+ "inherit",
1002
+ "initial",
1003
+ "unset",
1004
+ "none"
720
1005
  ];
721
1006
  function uniq(array) {
722
- return [...new Set(array)];
1007
+ return [...new Set(array)];
723
1008
  }
724
1009
  async function analyzer(modules, ctx) {
725
- const matched = [];
726
- const icons = [];
727
- const colors = [];
728
- const tokensInfo = /* @__PURE__ */ new Map();
729
- await Promise.all(modules.map(async (code, id) => {
730
- const result = await ctx.uno.generate(code, { id, extendedInfo: true, preflights: false });
731
- for (const [key, value] of result.matched.entries()) {
732
- const prev = tokensInfo.get(key);
733
- tokensInfo.set(key, {
734
- data: value.data,
735
- count: prev?.modules?.length ? value.count + prev.count : value.count,
736
- modules: uniq([...prev?.modules || [], id])
737
- });
738
- }
739
- }));
740
- for (const [rawSelector, { data, count, modules: _modules }] of tokensInfo.entries()) {
741
- const ruleContext = data[data.length - 1][5];
742
- const ruleMeta = data[data.length - 1][4];
743
- const body = data.map((d) => d[2]).join("\n---\n");
744
- const baseSelector = ruleContext?.currentSelector;
745
- const variants = ruleContext?.variants?.map((v) => v.name).filter(Boolean);
746
- const layer = ruleMeta?.layer || "default";
747
- if (baseSelector) {
748
- const category = layer !== "default" ? layer : getSelectorCategory(baseSelector);
749
- const body2 = baseSelector.replace(/^ring-offset|outline-solid|outline-dotted/, "head").replace(/^\w+-/, "");
750
- if (category === "icons") {
751
- const existing = icons.find((i) => i.baseSelector === baseSelector);
752
- if (existing) {
753
- existing.count += count;
754
- existing.modules = uniq([...existing.modules, ..._modules]);
755
- } else {
756
- icons.push({
757
- name: rawSelector,
758
- rawSelector,
759
- baseSelector,
760
- category,
761
- variants,
762
- count,
763
- ruleMeta,
764
- modules: _modules,
765
- body: body2
766
- });
767
- }
768
- continue;
769
- }
770
- const parsedColor = parseColor(body2, ctx.uno.config.theme, "colors");
771
- if (parsedColor?.color && !ignoredColors.includes(parsedColor?.color)) {
772
- const existing = colors.find((c) => c.name === parsedColor.name && c.no === parsedColor.no);
773
- if (existing) {
774
- existing.count += count;
775
- existing.modules = uniq([...existing.modules, ..._modules]);
776
- } else {
777
- colors.push({
778
- name: parsedColor.name,
779
- no: parsedColor.no,
780
- color: parsedColor.color,
781
- count,
782
- modules: _modules,
783
- rawSelector,
784
- category: category || "",
785
- variants,
786
- body: body2
787
- });
788
- }
789
- }
790
- if (category) {
791
- matched.push({
792
- name: rawSelector,
793
- rawSelector,
794
- baseSelector,
795
- category,
796
- variants,
797
- count,
798
- ruleMeta,
799
- modules: _modules,
800
- body: body2
801
- });
802
- continue;
803
- }
804
- }
805
- matched.push({
806
- name: rawSelector,
807
- rawSelector,
808
- category: "other",
809
- count,
810
- modules: _modules,
811
- body
812
- });
813
- }
814
- return {
815
- matched,
816
- colors,
817
- icons
818
- };
1010
+ const matched = [];
1011
+ const icons = [];
1012
+ const colors = [];
1013
+ const tokensInfo = /* @__PURE__ */ new Map();
1014
+ await Promise.all(modules.map(async (code, id) => {
1015
+ const result = await ctx.uno.generate(code, {
1016
+ id,
1017
+ extendedInfo: true,
1018
+ preflights: false
1019
+ });
1020
+ for (const [key, value] of result.matched.entries()) {
1021
+ const prev = tokensInfo.get(key);
1022
+ tokensInfo.set(key, {
1023
+ data: value.data,
1024
+ count: prev?.modules?.length ? value.count + prev.count : value.count,
1025
+ modules: uniq([...prev?.modules || [], id])
1026
+ });
1027
+ }
1028
+ }));
1029
+ for (const [rawSelector, { data, count, modules: _modules }] of tokensInfo.entries()) {
1030
+ const ruleContext = data[data.length - 1][5];
1031
+ const ruleMeta = data[data.length - 1][4];
1032
+ const body = data.map((d) => d[2]).join("\n---\n");
1033
+ const baseSelector = ruleContext?.currentSelector;
1034
+ const variants = ruleContext?.variants?.map((v) => v.name).filter(Boolean);
1035
+ const layer = ruleMeta?.layer || "default";
1036
+ if (baseSelector) {
1037
+ const category = layer !== "default" ? layer : getSelectorCategory(baseSelector);
1038
+ const body$1 = baseSelector.replace(/^ring-offset|outline-solid|outline-dotted/, "head").replace(/^\w+-/, "");
1039
+ if (category === "icons") {
1040
+ const existing = icons.find((i) => i.baseSelector === baseSelector);
1041
+ if (existing) {
1042
+ existing.count += count;
1043
+ existing.modules = uniq([...existing.modules, ..._modules]);
1044
+ } else icons.push({
1045
+ name: rawSelector,
1046
+ rawSelector,
1047
+ baseSelector,
1048
+ category,
1049
+ variants,
1050
+ count,
1051
+ ruleMeta,
1052
+ modules: _modules,
1053
+ body: body$1
1054
+ });
1055
+ continue;
1056
+ }
1057
+ const parsedColor = parseColor(body$1, ctx.uno.config.theme, "colors");
1058
+ if (parsedColor?.color && !ignoredColors.includes(parsedColor?.color)) {
1059
+ const existing = colors.find((c) => c.name === parsedColor.name && c.no === parsedColor.no);
1060
+ if (existing) {
1061
+ existing.count += count;
1062
+ existing.modules = uniq([...existing.modules, ..._modules]);
1063
+ } else colors.push({
1064
+ name: parsedColor.name,
1065
+ no: parsedColor.no,
1066
+ color: parsedColor.color,
1067
+ count,
1068
+ modules: _modules,
1069
+ rawSelector,
1070
+ category: category || "",
1071
+ variants,
1072
+ body: body$1
1073
+ });
1074
+ }
1075
+ if (category) {
1076
+ matched.push({
1077
+ name: rawSelector,
1078
+ rawSelector,
1079
+ baseSelector,
1080
+ category,
1081
+ variants,
1082
+ count,
1083
+ ruleMeta,
1084
+ modules: _modules,
1085
+ body: body$1
1086
+ });
1087
+ continue;
1088
+ }
1089
+ }
1090
+ matched.push({
1091
+ name: rawSelector,
1092
+ rawSelector,
1093
+ category: "other",
1094
+ count,
1095
+ modules: _modules,
1096
+ body
1097
+ });
1098
+ }
1099
+ return {
1100
+ matched,
1101
+ colors,
1102
+ icons
1103
+ };
819
1104
  }
820
1105
 
1106
+ //#endregion
1107
+ //#region src/index.ts
821
1108
  const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
822
1109
  function UnocssInspector(ctx) {
823
- const baseUrl = "__unocss";
824
- async function configureServer(server) {
825
- await ctx.ready;
826
- server.middlewares.use(`/${baseUrl}`, sirv(resolve(_dirname, "../dist/client"), {
827
- single: true,
828
- dev: true
829
- }));
830
- server.middlewares.use(`/${baseUrl}_api`, async (req, res, next) => {
831
- if (!req.url)
832
- return next();
833
- if (req.url === "/") {
834
- const info = {
835
- version: ctx.uno.version,
836
- // use the resolved config from the dev server
837
- root: server.config.root,
838
- modules: Array.from(ctx.modules.keys()),
839
- config: ctx.uno.config,
840
- configSources: (await ctx.ready).sources
841
- };
842
- res.setHeader("Content-Type", "application/json");
843
- res.write(JSON.stringify(info, getCircularReplacer(), 2));
844
- res.end();
845
- return;
846
- }
847
- if (req.url.startsWith("/module")) {
848
- const query = new URLSearchParams(req.url.slice(8));
849
- const id = query.get("id") || "";
850
- const code = ctx.modules.get(id);
851
- if (code == null) {
852
- res.statusCode = 404;
853
- res.end();
854
- return;
855
- }
856
- const tokens = new CountableSet();
857
- await ctx.uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
858
- const result = await ctx.uno.generate(tokens, { id, extendedInfo: true, preflights: false });
859
- const analyzed = await analyzer(new BetterMap([[id, code]]), ctx);
860
- const mod = {
861
- ...result,
862
- ...analyzed,
863
- layers: result.layers.map((name) => ({ name, css: result.getLayer(name) })),
864
- gzipSize: await gzipSize(result.css),
865
- code,
866
- id
867
- };
868
- res.setHeader("Content-Type", "application/json");
869
- res.write(JSON.stringify(mod, null, 2));
870
- res.end();
871
- return;
872
- }
873
- if (req.url.startsWith("/repl")) {
874
- const query = new URLSearchParams(req.url.slice(5));
875
- const token = query.get("token") || "";
876
- const includeSafelist = JSON.parse(query.get("safelist") ?? "false");
877
- const result = await ctx.uno.generate(token, { preflights: false, safelist: includeSafelist });
878
- const mod = {
879
- ...result,
880
- matched: Array.from(result.matched)
881
- };
882
- res.setHeader("Content-Type", "application/json");
883
- res.write(JSON.stringify(mod, null, 2));
884
- res.end();
885
- return;
886
- }
887
- if (req.url.startsWith("/overview")) {
888
- const result = await ctx.uno.generate(ctx.tokens, { preflights: false });
889
- const analyzed = await analyzer(ctx.modules, ctx);
890
- const mod = {
891
- ...result,
892
- ...analyzed,
893
- gzipSize: await gzipSize(result.css),
894
- layers: result.layers.map((name) => ({ name, css: result.getLayer(name) }))
895
- };
896
- res.setHeader("Content-Type", "application/json");
897
- res.write(JSON.stringify(mod, null, 2));
898
- res.end();
899
- return;
900
- }
901
- next();
902
- });
903
- const _printUrls = server.printUrls;
904
- const colorUrl = (url) => cyan(url.replace(/:(\d+)\//, (_, port) => `:${bold(port)}/`));
905
- server.printUrls = () => {
906
- _printUrls();
907
- for (const localUrl of server.resolvedUrls?.local ?? []) {
908
- const appUrl = localUrl.endsWith("/") ? localUrl : `${localUrl}/`;
909
- const serverUrl = server.config.base && appUrl.endsWith(server.config.base) ? appUrl.slice(0, -server.config.base.length) : appUrl.slice(0, -1);
910
- const inspectorUrl = `${serverUrl}/${baseUrl}/`;
911
- console.log(` ${green("\u279C")} ${bold("UnoCSS Inspector")}: ${colorUrl(`${inspectorUrl}`)}`);
912
- }
913
- };
914
- }
915
- return {
916
- name: "unocss:inspector",
917
- apply: "serve",
918
- configureServer,
919
- devtools: {
920
- setup(ctx2) {
921
- ctx2.docks.register({
922
- id: "unocss",
923
- title: "UnoCSS",
924
- icon: "https://unocss.dev/logo.svg",
925
- type: "iframe",
926
- url: `/${baseUrl}`
927
- });
928
- }
929
- }
930
- };
1110
+ const baseUrl = "__unocss";
1111
+ async function configureServer(server) {
1112
+ await ctx.ready;
1113
+ server.middlewares.use(`/${baseUrl}`, sirv(resolve(_dirname, "../dist/client"), {
1114
+ single: true,
1115
+ dev: true
1116
+ }));
1117
+ server.middlewares.use(`/${baseUrl}_api`, async (req, res, next) => {
1118
+ if (!req.url) return next();
1119
+ if (req.url === "/") {
1120
+ const info = {
1121
+ version: ctx.uno.version,
1122
+ root: server.config.root,
1123
+ modules: Array.from(ctx.modules.keys()),
1124
+ config: ctx.uno.config,
1125
+ configSources: (await ctx.ready).sources
1126
+ };
1127
+ res.setHeader("Content-Type", "application/json");
1128
+ res.write(JSON.stringify(info, getCircularReplacer(), 2));
1129
+ res.end();
1130
+ return;
1131
+ }
1132
+ if (req.url.startsWith("/module")) {
1133
+ const id = new URLSearchParams(req.url.slice(8)).get("id") || "";
1134
+ const code = ctx.modules.get(id);
1135
+ if (code == null) {
1136
+ res.statusCode = 404;
1137
+ res.end();
1138
+ return;
1139
+ }
1140
+ const tokens = new CountableSet();
1141
+ await ctx.uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
1142
+ const result = await ctx.uno.generate(tokens, {
1143
+ id,
1144
+ extendedInfo: true,
1145
+ preflights: false
1146
+ });
1147
+ const analyzed = await analyzer(new BetterMap([[id, code]]), ctx);
1148
+ const mod = {
1149
+ ...result,
1150
+ ...analyzed,
1151
+ layers: result.layers.map((name) => ({
1152
+ name,
1153
+ css: result.getLayer(name)
1154
+ })),
1155
+ gzipSize: await gzipSize(result.css),
1156
+ code,
1157
+ id
1158
+ };
1159
+ res.setHeader("Content-Type", "application/json");
1160
+ res.write(JSON.stringify(mod, null, 2));
1161
+ res.end();
1162
+ return;
1163
+ }
1164
+ if (req.url.startsWith("/repl")) {
1165
+ const query = new URLSearchParams(req.url.slice(5));
1166
+ const token = query.get("token") || "";
1167
+ const includeSafelist = JSON.parse(query.get("safelist") ?? "false");
1168
+ const result = await ctx.uno.generate(token, {
1169
+ preflights: false,
1170
+ safelist: includeSafelist
1171
+ });
1172
+ const mod = {
1173
+ ...result,
1174
+ matched: Array.from(result.matched)
1175
+ };
1176
+ res.setHeader("Content-Type", "application/json");
1177
+ res.write(JSON.stringify(mod, null, 2));
1178
+ res.end();
1179
+ return;
1180
+ }
1181
+ if (req.url.startsWith("/overview")) {
1182
+ const result = await ctx.uno.generate(ctx.tokens, { preflights: false });
1183
+ const analyzed = await analyzer(ctx.modules, ctx);
1184
+ const mod = {
1185
+ ...result,
1186
+ ...analyzed,
1187
+ gzipSize: await gzipSize(result.css),
1188
+ layers: result.layers.map((name) => ({
1189
+ name,
1190
+ css: result.getLayer(name)
1191
+ }))
1192
+ };
1193
+ res.setHeader("Content-Type", "application/json");
1194
+ res.write(JSON.stringify(mod, null, 2));
1195
+ res.end();
1196
+ return;
1197
+ }
1198
+ next();
1199
+ });
1200
+ const _printUrls = server.printUrls;
1201
+ const colorUrl = (url) => cyan(url.replace(/:(\d+)\//, (_, port) => `:${bold(port)}/`));
1202
+ server.printUrls = () => {
1203
+ _printUrls();
1204
+ for (const localUrl of server.resolvedUrls?.local ?? []) {
1205
+ const appUrl = localUrl.endsWith("/") ? localUrl : `${localUrl}/`;
1206
+ const inspectorUrl = `${server.config.base && appUrl.endsWith(server.config.base) ? appUrl.slice(0, -server.config.base.length) : appUrl.slice(0, -1)}/${baseUrl}/`;
1207
+ console.log(` ${green("➜")} ${bold("UnoCSS Inspector")}: ${colorUrl(`${inspectorUrl}`)}`);
1208
+ }
1209
+ };
1210
+ }
1211
+ return {
1212
+ name: "unocss:inspector",
1213
+ apply: "serve",
1214
+ configureServer,
1215
+ devtools: { setup(ctx$1) {
1216
+ ctx$1.docks.register({
1217
+ id: "unocss",
1218
+ title: "UnoCSS",
1219
+ icon: "https://unocss.dev/logo.svg",
1220
+ type: "iframe",
1221
+ url: `/${baseUrl}`
1222
+ });
1223
+ } }
1224
+ };
931
1225
  }
932
1226
  function getCircularReplacer() {
933
- const ancestors = [];
934
- return function(key, value) {
935
- if (typeof value !== "object" || value === null)
936
- return value;
937
- while (ancestors.length > 0 && ancestors.at(-1) !== this)
938
- ancestors.pop();
939
- if (ancestors.includes(value))
940
- return "[Circular]";
941
- ancestors.push(value);
942
- return value;
943
- };
1227
+ const ancestors = [];
1228
+ return function(key, value) {
1229
+ if (typeof value !== "object" || value === null) return value;
1230
+ while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();
1231
+ if (ancestors.includes(value)) return "[Circular]";
1232
+ ancestors.push(value);
1233
+ return value;
1234
+ };
944
1235
  }
945
1236
 
946
- export { UnocssInspector as default };
1237
+ //#endregion
1238
+ export { UnocssInspector as default };