@unocss/core 66.5.10 → 66.5.12
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.d.mts +859 -884
- package/dist/index.mjs +1117 -1233
- package/package.json +5 -6
- package/dist/index.d.ts +0 -1137
package/dist/index.mjs
CHANGED
|
@@ -1,1360 +1,1244 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
1
2
|
const LAYER_DEFAULT = "default";
|
|
2
3
|
const LAYER_PREFLIGHTS = "preflights";
|
|
3
4
|
const LAYER_SHORTCUTS = "shortcuts";
|
|
4
5
|
const LAYER_IMPORTS = "imports";
|
|
5
6
|
const DEFAULT_LAYERS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
[LAYER_IMPORTS]: -200,
|
|
8
|
+
[LAYER_PREFLIGHTS]: -100,
|
|
9
|
+
[LAYER_SHORTCUTS]: -10,
|
|
10
|
+
[LAYER_DEFAULT]: 0
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/extractors/split.ts
|
|
12
15
|
const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
|
|
13
16
|
const splitWithVariantGroupRE = /([\\:]?[\s"'`;<>]|:\(|\)"|\)\s)/g;
|
|
14
17
|
function splitCode(code) {
|
|
15
|
-
|
|
18
|
+
return code.split(defaultSplitRE);
|
|
16
19
|
}
|
|
17
20
|
const extractorSplit = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
name: "@unocss/core/extractor-split",
|
|
22
|
+
order: 0,
|
|
23
|
+
extract({ code }) {
|
|
24
|
+
return splitCode(code);
|
|
25
|
+
}
|
|
23
26
|
};
|
|
24
27
|
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/utils/basic.ts
|
|
25
30
|
function toArray(value = []) {
|
|
26
|
-
|
|
31
|
+
return Array.isArray(value) ? value : [value];
|
|
27
32
|
}
|
|
28
33
|
function uniq(value) {
|
|
29
|
-
|
|
34
|
+
return Array.from(new Set(value));
|
|
30
35
|
}
|
|
31
36
|
function uniqueBy(array, equalFn) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return acc;
|
|
37
|
-
}, []);
|
|
37
|
+
return array.reduce((acc, cur) => {
|
|
38
|
+
if (acc.findIndex((item) => equalFn(cur, item)) === -1) acc.push(cur);
|
|
39
|
+
return acc;
|
|
40
|
+
}, []);
|
|
38
41
|
}
|
|
39
42
|
function isString(s) {
|
|
40
|
-
|
|
43
|
+
return typeof s === "string";
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this._map.set(key, count);
|
|
73
|
-
return super.add(key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/utils/countable-set.ts
|
|
48
|
+
var CountableSet = class extends Set {
|
|
49
|
+
constructor(values) {
|
|
50
|
+
super();
|
|
51
|
+
this._map = /* @__PURE__ */ new Map();
|
|
52
|
+
if (values) for (const key of values) this.add(key);
|
|
53
|
+
}
|
|
54
|
+
add(key) {
|
|
55
|
+
this._map.set(key, (this._map.get(key) ?? 0) + 1);
|
|
56
|
+
return super.add(key);
|
|
57
|
+
}
|
|
58
|
+
delete(key) {
|
|
59
|
+
if (!this._map.has(key)) return false;
|
|
60
|
+
this._map.delete(key);
|
|
61
|
+
return super.delete(key);
|
|
62
|
+
}
|
|
63
|
+
clear() {
|
|
64
|
+
this._map.clear();
|
|
65
|
+
super.clear();
|
|
66
|
+
}
|
|
67
|
+
getCount(key) {
|
|
68
|
+
return this._map.get(key) ?? 0;
|
|
69
|
+
}
|
|
70
|
+
setCount(key, count) {
|
|
71
|
+
this._map.set(key, count);
|
|
72
|
+
return super.add(key);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
76
75
|
function isCountableSet(value) {
|
|
77
|
-
|
|
76
|
+
return value instanceof CountableSet;
|
|
78
77
|
}
|
|
79
78
|
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/utils/escape.ts
|
|
80
81
|
function escapeRegExp(string) {
|
|
81
|
-
|
|
82
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
82
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* CSS Selector Escape
|
|
86
|
+
*/
|
|
83
87
|
function escapeSelector(str) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (codeUnit >= 128 || codeUnit === 45 || codeUnit === 95 || codeUnit >= 48 && codeUnit <= 57 || codeUnit >= 65 && codeUnit <= 90 || codeUnit >= 97 && codeUnit <= 122) {
|
|
120
|
-
result += str.charAt(index);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
result += `\\${str.charAt(index)}`;
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
88
|
+
const length = str.length;
|
|
89
|
+
let index = -1;
|
|
90
|
+
let codeUnit;
|
|
91
|
+
let result = "";
|
|
92
|
+
const firstCodeUnit = str.charCodeAt(0);
|
|
93
|
+
while (++index < length) {
|
|
94
|
+
codeUnit = str.charCodeAt(index);
|
|
95
|
+
if (codeUnit === 0) {
|
|
96
|
+
result += "�";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (codeUnit === 37) {
|
|
100
|
+
result += "\\%";
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (codeUnit === 44) {
|
|
104
|
+
result += "\\,";
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (codeUnit >= 1 && codeUnit <= 31 || codeUnit === 127 || index === 0 && codeUnit >= 48 && codeUnit <= 57 || index === 1 && codeUnit >= 48 && codeUnit <= 57 && firstCodeUnit === 45) {
|
|
108
|
+
result += `\\${codeUnit.toString(16)} `;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (index === 0 && length === 1 && codeUnit === 45) {
|
|
112
|
+
result += `\\${str.charAt(index)}`;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (codeUnit >= 128 || codeUnit === 45 || codeUnit === 95 || codeUnit >= 48 && codeUnit <= 57 || codeUnit >= 65 && codeUnit <= 90 || codeUnit >= 97 && codeUnit <= 122) {
|
|
116
|
+
result += str.charAt(index);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
result += `\\${str.charAt(index)}`;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
126
122
|
}
|
|
127
123
|
const e = escapeSelector;
|
|
128
124
|
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/utils/events.ts
|
|
127
|
+
/**
|
|
128
|
+
* Create event emitter.
|
|
129
|
+
*
|
|
130
|
+
* ```js
|
|
131
|
+
* import { createNanoEvents } from 'nanoevents'
|
|
132
|
+
*
|
|
133
|
+
* class Ticker {
|
|
134
|
+
* constructor() {
|
|
135
|
+
* this.emitter = createNanoEvents()
|
|
136
|
+
* }
|
|
137
|
+
* on(...args) {
|
|
138
|
+
* return this.emitter.on(...args)
|
|
139
|
+
* }
|
|
140
|
+
* tick() {
|
|
141
|
+
* this.emitter.emit('tick')
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
129
146
|
function createNanoEvents() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
return {
|
|
148
|
+
events: {},
|
|
149
|
+
emit(event, ...args) {
|
|
150
|
+
(this.events[event] || []).forEach((i) => i(...args));
|
|
151
|
+
},
|
|
152
|
+
on(event, cb) {
|
|
153
|
+
(this.events[event] = this.events[event] || []).push(cb);
|
|
154
|
+
return () => this.events[event] = (this.events[event] || []).filter((i) => i !== cb);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
140
157
|
}
|
|
141
158
|
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/utils/helpers.ts
|
|
142
161
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
143
162
|
const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)($|\?)/;
|
|
144
163
|
const validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
|
|
145
164
|
function isAttributifySelector(selector) {
|
|
146
|
-
|
|
165
|
+
return selector.match(attributifyRE);
|
|
147
166
|
}
|
|
148
167
|
function isValidSelector(selector = "") {
|
|
149
|
-
|
|
168
|
+
return validateFilterRE.test(selector);
|
|
150
169
|
}
|
|
151
170
|
function normalizeVariant(variant) {
|
|
152
|
-
|
|
171
|
+
return typeof variant === "function" ? { match: variant } : variant;
|
|
153
172
|
}
|
|
154
173
|
function isRawUtil(util) {
|
|
155
|
-
|
|
174
|
+
return util.length === 3;
|
|
156
175
|
}
|
|
157
176
|
function notNull(value) {
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
function noop() {
|
|
177
|
+
return value != null;
|
|
161
178
|
}
|
|
179
|
+
function noop() {}
|
|
162
180
|
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/utils/layer.ts
|
|
163
183
|
function withLayer(layer, rules) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
return rules;
|
|
184
|
+
rules.forEach((r) => {
|
|
185
|
+
if (!r[2]) r[2] = { layer };
|
|
186
|
+
else r[2].layer = layer;
|
|
187
|
+
});
|
|
188
|
+
return rules;
|
|
171
189
|
}
|
|
172
190
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/utils/map.ts
|
|
193
|
+
var TwoKeyMap = class {
|
|
194
|
+
constructor() {
|
|
195
|
+
this._map = /* @__PURE__ */ new Map();
|
|
196
|
+
}
|
|
197
|
+
get(key1, key2) {
|
|
198
|
+
const m2 = this._map.get(key1);
|
|
199
|
+
if (m2) return m2.get(key2);
|
|
200
|
+
}
|
|
201
|
+
getFallback(key1, key2, fallback) {
|
|
202
|
+
let m2 = this._map.get(key1);
|
|
203
|
+
if (!m2) {
|
|
204
|
+
m2 = /* @__PURE__ */ new Map();
|
|
205
|
+
this._map.set(key1, m2);
|
|
206
|
+
}
|
|
207
|
+
if (!m2.has(key2)) m2.set(key2, fallback);
|
|
208
|
+
return m2.get(key2);
|
|
209
|
+
}
|
|
210
|
+
set(key1, key2, value) {
|
|
211
|
+
let m2 = this._map.get(key1);
|
|
212
|
+
if (!m2) {
|
|
213
|
+
m2 = /* @__PURE__ */ new Map();
|
|
214
|
+
this._map.set(key1, m2);
|
|
215
|
+
}
|
|
216
|
+
m2.set(key2, value);
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
has(key1, key2) {
|
|
220
|
+
return this._map.get(key1)?.has(key2);
|
|
221
|
+
}
|
|
222
|
+
delete(key1, key2) {
|
|
223
|
+
return this._map.get(key1)?.delete(key2) || false;
|
|
224
|
+
}
|
|
225
|
+
deleteTop(key1) {
|
|
226
|
+
return this._map.delete(key1);
|
|
227
|
+
}
|
|
228
|
+
map(fn) {
|
|
229
|
+
return Array.from(this._map.entries()).flatMap(([k1, m2]) => Array.from(m2.entries()).map(([k2, v]) => {
|
|
230
|
+
return fn(v, k1, k2);
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var BetterMap = class extends Map {
|
|
235
|
+
getFallback(key, fallback) {
|
|
236
|
+
const v = this.get(key);
|
|
237
|
+
if (v === void 0) {
|
|
238
|
+
this.set(key, fallback);
|
|
239
|
+
return fallback;
|
|
240
|
+
}
|
|
241
|
+
return v;
|
|
242
|
+
}
|
|
243
|
+
map(mapFn) {
|
|
244
|
+
const result = [];
|
|
245
|
+
this.forEach((v, k) => {
|
|
246
|
+
result.push(mapFn(v, k));
|
|
247
|
+
});
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
flatMap(mapFn) {
|
|
251
|
+
const result = [];
|
|
252
|
+
this.forEach((v, k) => {
|
|
253
|
+
result.push(...mapFn(v, k));
|
|
254
|
+
});
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
238
258
|
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/utils/object.ts
|
|
239
261
|
function normalizeCSSEntries(obj) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return (!Array.isArray(obj) ? Object.entries(obj) : obj).filter((i) => i[1] != null);
|
|
262
|
+
if (isString(obj)) return obj;
|
|
263
|
+
return (!Array.isArray(obj) ? Object.entries(obj) : obj).filter((i) => i[1] != null);
|
|
243
264
|
}
|
|
244
265
|
function normalizeCSSValues(obj) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
else
|
|
249
|
-
return [obj];
|
|
250
|
-
} else {
|
|
251
|
-
return [normalizeCSSEntries(obj)];
|
|
252
|
-
}
|
|
266
|
+
if (Array.isArray(obj)) if (obj.find((i) => !Array.isArray(i) || Array.isArray(i[0]))) return obj.map((i) => normalizeCSSEntries(i));
|
|
267
|
+
else return [obj];
|
|
268
|
+
else return [normalizeCSSEntries(obj)];
|
|
253
269
|
}
|
|
254
270
|
function clearIdenticalEntries(entry) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
return true;
|
|
263
|
-
});
|
|
271
|
+
return entry.filter(([k, v], idx) => {
|
|
272
|
+
if (k.startsWith("$$")) return false;
|
|
273
|
+
for (let i = idx - 1; i >= 0; i--) if (entry[i][0] === k && entry[i][1] === v) return false;
|
|
274
|
+
return true;
|
|
275
|
+
});
|
|
264
276
|
}
|
|
265
277
|
const VirtualKey = "__virtual_key__";
|
|
266
278
|
function entriesToCss(arr) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return clearIdenticalEntries(arr).map(([key, value]) => value != null && typeof value !== "function" ? key !== VirtualKey ? `${key}:${value};` : value : void 0).filter(Boolean).join("");
|
|
279
|
+
if (arr == null) return "";
|
|
280
|
+
return clearIdenticalEntries(arr).map(([key, value]) => value != null && typeof value !== "function" ? key !== VirtualKey ? `${key}:${value};` : value : void 0).filter(Boolean).join("");
|
|
270
281
|
}
|
|
271
282
|
function isObject(item) {
|
|
272
|
-
|
|
283
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
273
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Deep merge two objects
|
|
287
|
+
*/
|
|
274
288
|
function mergeDeep(original, patch, mergeArray = false) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Object.keys(p).forEach((key) => {
|
|
286
|
-
if (isObject(o[key]) && isObject(p[key]) || Array.isArray(o[key]) && Array.isArray(p[key]))
|
|
287
|
-
output[key] = mergeDeep(o[key], p[key], mergeArray);
|
|
288
|
-
else
|
|
289
|
-
Object.assign(output, { [key]: p[key] });
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return output;
|
|
289
|
+
const o = original;
|
|
290
|
+
const p = patch;
|
|
291
|
+
if (Array.isArray(p)) if (mergeArray && Array.isArray(p)) return [...o, ...p];
|
|
292
|
+
else return [...p];
|
|
293
|
+
const output = { ...o };
|
|
294
|
+
if (isObject(o) && isObject(p)) Object.keys(p).forEach((key) => {
|
|
295
|
+
if (isObject(o[key]) && isObject(p[key]) || Array.isArray(o[key]) && Array.isArray(p[key])) output[key] = mergeDeep(o[key], p[key], mergeArray);
|
|
296
|
+
else Object.assign(output, { [key]: p[key] });
|
|
297
|
+
});
|
|
298
|
+
return output;
|
|
293
299
|
}
|
|
294
300
|
function clone(val) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return out;
|
|
316
|
-
}
|
|
317
|
-
return val;
|
|
301
|
+
let k, out, tmp;
|
|
302
|
+
if (Array.isArray(val)) {
|
|
303
|
+
out = Array.from({ length: k = val.length });
|
|
304
|
+
while (k--) out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
308
|
+
out = {};
|
|
309
|
+
for (k in val) if (k === "__proto__") Object.defineProperty(out, k, {
|
|
310
|
+
value: clone(val[k]),
|
|
311
|
+
configurable: true,
|
|
312
|
+
enumerable: true,
|
|
313
|
+
writable: true
|
|
314
|
+
});
|
|
315
|
+
else out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
318
|
+
return val;
|
|
318
319
|
}
|
|
319
320
|
function isStaticRule(rule) {
|
|
320
|
-
|
|
321
|
+
return isString(rule[0]);
|
|
321
322
|
}
|
|
322
323
|
function isStaticShortcut(sc) {
|
|
323
|
-
|
|
324
|
+
return isString(sc[0]);
|
|
324
325
|
}
|
|
325
326
|
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/utils/variant-group.ts
|
|
326
329
|
const regexCache = {};
|
|
327
330
|
function makeRegexClassGroup(separators = ["-", ":"]) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return regexCache[key];
|
|
331
|
+
const key = separators.join("|");
|
|
332
|
+
if (!regexCache[key]) regexCache[key] = new RegExp(`((?:[!@<~\\w+:_-]|\\[&?>?:?\\S*\\])+?)(${key})\\(((?:[~!<>\\w\\s:/\\\\,%#.$?-]|\\[[^\\]]*?\\])+?)\\)(?!\\s*?=>)`, "gm");
|
|
333
|
+
regexCache[key].lastIndex = 0;
|
|
334
|
+
return regexCache[key];
|
|
333
335
|
}
|
|
334
336
|
function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
prefixes: Array.from(prefixes),
|
|
396
|
-
hasChanged,
|
|
397
|
-
groupsByOffset,
|
|
398
|
-
// Computed lazily because MagicString's toString does a lot of work
|
|
399
|
-
get expanded() {
|
|
400
|
-
return expanded.toString();
|
|
401
|
-
}
|
|
402
|
-
};
|
|
337
|
+
const regexClassGroup = makeRegexClassGroup(separators);
|
|
338
|
+
let hasChanged;
|
|
339
|
+
let content = str.toString();
|
|
340
|
+
const prefixes = /* @__PURE__ */ new Set();
|
|
341
|
+
const groupsByOffset = /* @__PURE__ */ new Map();
|
|
342
|
+
do {
|
|
343
|
+
hasChanged = false;
|
|
344
|
+
content = content.replace(regexClassGroup, (from, pre, sep, body, groupOffset) => {
|
|
345
|
+
if (!separators.includes(sep)) return from;
|
|
346
|
+
hasChanged = true;
|
|
347
|
+
prefixes.add(pre + sep);
|
|
348
|
+
const bodyOffset = groupOffset + pre.length + sep.length + 1;
|
|
349
|
+
const group = {
|
|
350
|
+
length: from.length,
|
|
351
|
+
items: []
|
|
352
|
+
};
|
|
353
|
+
groupsByOffset.set(groupOffset, group);
|
|
354
|
+
for (const itemMatch of [...body.matchAll(/\S+/g)]) {
|
|
355
|
+
const itemOffset = bodyOffset + itemMatch.index;
|
|
356
|
+
let innerItems = groupsByOffset.get(itemOffset)?.items;
|
|
357
|
+
if (innerItems) groupsByOffset.delete(itemOffset);
|
|
358
|
+
else innerItems = [{
|
|
359
|
+
offset: itemOffset,
|
|
360
|
+
length: itemMatch[0].length,
|
|
361
|
+
className: itemMatch[0]
|
|
362
|
+
}];
|
|
363
|
+
for (const item of innerItems) {
|
|
364
|
+
item.className = item.className === "~" ? pre : item.className.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`);
|
|
365
|
+
group.items.push(item);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return "$".repeat(from.length);
|
|
369
|
+
});
|
|
370
|
+
depth -= 1;
|
|
371
|
+
} while (hasChanged && depth);
|
|
372
|
+
let expanded;
|
|
373
|
+
if (typeof str === "string") {
|
|
374
|
+
expanded = "";
|
|
375
|
+
let prevOffset = 0;
|
|
376
|
+
for (const [offset, group] of groupsByOffset) {
|
|
377
|
+
expanded += str.slice(prevOffset, offset);
|
|
378
|
+
expanded += group.items.map((item) => item.className).join(" ");
|
|
379
|
+
prevOffset = offset + group.length;
|
|
380
|
+
}
|
|
381
|
+
expanded += str.slice(prevOffset);
|
|
382
|
+
} else {
|
|
383
|
+
expanded = str;
|
|
384
|
+
for (const [offset, group] of groupsByOffset) expanded.overwrite(offset, offset + group.length, group.items.map((item) => item.className).join(" "));
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
prefixes: Array.from(prefixes),
|
|
388
|
+
hasChanged,
|
|
389
|
+
groupsByOffset,
|
|
390
|
+
get expanded() {
|
|
391
|
+
return expanded.toString();
|
|
392
|
+
}
|
|
393
|
+
};
|
|
403
394
|
}
|
|
404
395
|
function collapseVariantGroup(str, prefixes) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return `${i.prefix}(${i.items.join(" ")})`;
|
|
427
|
-
}).join(" ");
|
|
396
|
+
const collection = /* @__PURE__ */ new Map();
|
|
397
|
+
const sortedPrefix = prefixes.sort((a, b) => b.length - a.length);
|
|
398
|
+
return str.split(/\s+/g).map((part) => {
|
|
399
|
+
const prefix = sortedPrefix.find((prefix$1) => part.startsWith(prefix$1));
|
|
400
|
+
if (!prefix) return part;
|
|
401
|
+
const body = part.slice(prefix.length);
|
|
402
|
+
if (collection.has(prefix)) {
|
|
403
|
+
collection.get(prefix).push(body);
|
|
404
|
+
return null;
|
|
405
|
+
} else {
|
|
406
|
+
const items = [body];
|
|
407
|
+
collection.set(prefix, items);
|
|
408
|
+
return {
|
|
409
|
+
prefix,
|
|
410
|
+
items
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}).filter(notNull).map((i) => {
|
|
414
|
+
if (typeof i === "string") return i;
|
|
415
|
+
return `${i.prefix}(${i.items.join(" ")})`;
|
|
416
|
+
}).join(" ");
|
|
428
417
|
}
|
|
429
418
|
function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
430
|
-
|
|
431
|
-
|
|
419
|
+
const res = parseVariantGroup(str, separators, depth);
|
|
420
|
+
return typeof str === "string" ? res.expanded : str;
|
|
432
421
|
}
|
|
433
422
|
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/utils/warn.ts
|
|
434
425
|
const warned = /* @__PURE__ */ new Set();
|
|
435
426
|
function warnOnce(msg) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
warned.add(msg);
|
|
427
|
+
if (warned.has(msg)) return;
|
|
428
|
+
console.warn("[unocss]", msg);
|
|
429
|
+
warned.add(msg);
|
|
440
430
|
}
|
|
441
431
|
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/config.ts
|
|
442
434
|
function resolveShortcuts(shortcuts) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
});
|
|
435
|
+
return toArray(shortcuts).flatMap((s) => {
|
|
436
|
+
if (Array.isArray(s)) return [s];
|
|
437
|
+
return Object.entries(s);
|
|
438
|
+
});
|
|
448
439
|
}
|
|
449
440
|
const __RESOLVED = "_uno_resolved";
|
|
441
|
+
/**
|
|
442
|
+
* Resolve a single preset, nested presets are ignored
|
|
443
|
+
*/
|
|
450
444
|
async function resolvePreset(presetInput) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
shortcuts?.forEach(apply);
|
|
472
|
-
preset.rules?.forEach(apply);
|
|
473
|
-
}
|
|
474
|
-
return preset;
|
|
445
|
+
let preset = typeof presetInput === "function" ? await presetInput() : await presetInput;
|
|
446
|
+
if (__RESOLVED in preset) return preset;
|
|
447
|
+
preset = { ...preset };
|
|
448
|
+
Object.defineProperty(preset, __RESOLVED, {
|
|
449
|
+
value: true,
|
|
450
|
+
enumerable: false
|
|
451
|
+
});
|
|
452
|
+
const shortcuts = preset.shortcuts ? resolveShortcuts(preset.shortcuts) : void 0;
|
|
453
|
+
preset.shortcuts = shortcuts;
|
|
454
|
+
if (preset.prefix || preset.layer) {
|
|
455
|
+
const apply = (i) => {
|
|
456
|
+
if (!i[2]) i[2] = {};
|
|
457
|
+
const meta = i[2];
|
|
458
|
+
if (meta.prefix == null && preset.prefix) meta.prefix = toArray(preset.prefix);
|
|
459
|
+
if (meta.layer == null && preset.layer) meta.layer = preset.layer;
|
|
460
|
+
};
|
|
461
|
+
shortcuts?.forEach(apply);
|
|
462
|
+
preset.rules?.forEach(apply);
|
|
463
|
+
}
|
|
464
|
+
return preset;
|
|
475
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Resolve presets with nested presets
|
|
468
|
+
*/
|
|
476
469
|
async function resolvePresets(preset) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const nested = (await Promise.all((root.presets || []).flatMap(toArray).flatMap(resolvePresets))).flat();
|
|
481
|
-
return [root, ...nested];
|
|
470
|
+
const root = await resolvePreset(preset);
|
|
471
|
+
if (!root.presets) return [root];
|
|
472
|
+
return [root, ...(await Promise.all((root.presets || []).flatMap(toArray).flatMap(resolvePresets))).flat()];
|
|
482
473
|
}
|
|
483
474
|
function mergeContentOptions(optionsArray) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
inline.push(options.inline);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const mergedContent = {
|
|
512
|
-
pipeline: pipelineDisabled ? false : {
|
|
513
|
-
include: uniq(mergeFilterPatterns(...pipelineIncludes)),
|
|
514
|
-
exclude: uniq(mergeFilterPatterns(...pipelineExcludes))
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
if (filesystem.length) {
|
|
518
|
-
mergedContent.filesystem = uniq(filesystem.flat());
|
|
519
|
-
}
|
|
520
|
-
if (inline.length) {
|
|
521
|
-
mergedContent.inline = uniq(inline.flat());
|
|
522
|
-
}
|
|
523
|
-
return mergedContent;
|
|
475
|
+
if (optionsArray.length === 0) return {};
|
|
476
|
+
const pipelineIncludes = [];
|
|
477
|
+
const pipelineExcludes = [];
|
|
478
|
+
let pipelineDisabled = false;
|
|
479
|
+
const filesystem = [];
|
|
480
|
+
const inline = [];
|
|
481
|
+
for (const options of optionsArray) {
|
|
482
|
+
if (options.pipeline === false) {
|
|
483
|
+
pipelineDisabled = true;
|
|
484
|
+
break;
|
|
485
|
+
} else {
|
|
486
|
+
if (options.pipeline?.include) pipelineIncludes.push(options.pipeline.include);
|
|
487
|
+
if (options.pipeline?.exclude) pipelineExcludes.push(options.pipeline.exclude);
|
|
488
|
+
}
|
|
489
|
+
if (options.filesystem) filesystem.push(options.filesystem);
|
|
490
|
+
if (options.inline) inline.push(options.inline);
|
|
491
|
+
}
|
|
492
|
+
const mergedContent = { pipeline: pipelineDisabled ? false : {
|
|
493
|
+
include: uniq(mergeFilterPatterns(...pipelineIncludes)),
|
|
494
|
+
exclude: uniq(mergeFilterPatterns(...pipelineExcludes))
|
|
495
|
+
} };
|
|
496
|
+
if (filesystem.length) mergedContent.filesystem = uniq(filesystem.flat());
|
|
497
|
+
if (inline.length) mergedContent.inline = uniq(inline.flat());
|
|
498
|
+
return mergedContent;
|
|
524
499
|
}
|
|
525
500
|
async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
autocomplete,
|
|
597
|
-
variants: getMerged("variants").map(normalizeVariant).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
598
|
-
shortcuts: resolveShortcuts(getMerged("shortcuts")).reverse(),
|
|
599
|
-
extractors,
|
|
600
|
-
safelist: getMerged("safelist"),
|
|
601
|
-
separators,
|
|
602
|
-
details: config.details ?? config.envMode === "dev",
|
|
603
|
-
content,
|
|
604
|
-
transformers: uniqueBy(getMerged("transformers"), (a, b) => a.name === b.name)
|
|
605
|
-
};
|
|
606
|
-
const extendThemes = getMerged("extendTheme");
|
|
607
|
-
for (const extendTheme of extendThemes)
|
|
608
|
-
resolved.theme = extendTheme(resolved.theme, resolved) || resolved.theme;
|
|
609
|
-
for (const p of sources)
|
|
610
|
-
p?.configResolved?.(resolved);
|
|
611
|
-
return resolved;
|
|
501
|
+
const config = Object.assign({}, defaults, userConfig);
|
|
502
|
+
const rawPresets = uniqueBy((await Promise.all((config.presets || []).flatMap(toArray).flatMap(resolvePresets))).flat(), (a, b) => a.name === b.name);
|
|
503
|
+
const sortedPresets = [
|
|
504
|
+
...rawPresets.filter((p) => p.enforce === "pre"),
|
|
505
|
+
...rawPresets.filter((p) => !p.enforce),
|
|
506
|
+
...rawPresets.filter((p) => p.enforce === "post")
|
|
507
|
+
];
|
|
508
|
+
const sources = [...sortedPresets, config];
|
|
509
|
+
const sourcesReversed = [...sources].reverse();
|
|
510
|
+
const layers = Object.assign({}, DEFAULT_LAYERS, ...sources.map((i) => i.layers));
|
|
511
|
+
function getMerged(key) {
|
|
512
|
+
return uniq(sources.flatMap((p) => toArray(p[key] || [])));
|
|
513
|
+
}
|
|
514
|
+
const extractors = getMerged("extractors");
|
|
515
|
+
let extractorDefault = sourcesReversed.find((i) => i.extractorDefault !== void 0)?.extractorDefault;
|
|
516
|
+
if (extractorDefault === void 0) extractorDefault = extractorSplit;
|
|
517
|
+
if (extractorDefault && !extractors.includes(extractorDefault)) extractors.unshift(extractorDefault);
|
|
518
|
+
extractors.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
519
|
+
const rules = getMerged("rules");
|
|
520
|
+
const rulesSize = rules.length;
|
|
521
|
+
const rulesStaticMap = {};
|
|
522
|
+
const rulesDynamic = [];
|
|
523
|
+
for (const [index, rule] of rules.entries()) {
|
|
524
|
+
const meta = rule[2] ?? (rule[2] = {});
|
|
525
|
+
meta.__index = index;
|
|
526
|
+
if (isStaticRule(rule)) toArray(meta.prefix ?? "").forEach((prefix) => {
|
|
527
|
+
rulesStaticMap[prefix + rule[0]] = rule;
|
|
528
|
+
});
|
|
529
|
+
else rulesDynamic.unshift(rule);
|
|
530
|
+
}
|
|
531
|
+
const autocomplete = {
|
|
532
|
+
templates: uniq(sources.flatMap((p) => toArray(p.autocomplete?.templates))),
|
|
533
|
+
extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
534
|
+
shorthands: mergeAutocompleteShorthands(sources.map((p) => p.autocomplete?.shorthands || {}))
|
|
535
|
+
};
|
|
536
|
+
let separators = getMerged("separators");
|
|
537
|
+
if (!separators.length) separators = [":", "-"];
|
|
538
|
+
const content = mergeContentOptions(getMerged("content"));
|
|
539
|
+
const resolved = {
|
|
540
|
+
mergeSelectors: true,
|
|
541
|
+
warn: true,
|
|
542
|
+
sortLayers: (layers$1) => layers$1,
|
|
543
|
+
...config,
|
|
544
|
+
blocklist: getMerged("blocklist"),
|
|
545
|
+
presets: sortedPresets,
|
|
546
|
+
envMode: config.envMode || "build",
|
|
547
|
+
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
548
|
+
layers,
|
|
549
|
+
theme: mergeThemes(sources.map((p) => p.theme)),
|
|
550
|
+
rules,
|
|
551
|
+
rulesSize,
|
|
552
|
+
rulesDynamic,
|
|
553
|
+
rulesStaticMap,
|
|
554
|
+
preprocess: getMerged("preprocess"),
|
|
555
|
+
postprocess: getMerged("postprocess"),
|
|
556
|
+
preflights: getMerged("preflights"),
|
|
557
|
+
autocomplete,
|
|
558
|
+
variants: getMerged("variants").map(normalizeVariant).sort((a, b) => (a.order || 0) - (b.order || 0)),
|
|
559
|
+
shortcuts: resolveShortcuts(getMerged("shortcuts")).reverse(),
|
|
560
|
+
extractors,
|
|
561
|
+
safelist: getMerged("safelist"),
|
|
562
|
+
separators,
|
|
563
|
+
details: config.details ?? config.envMode === "dev",
|
|
564
|
+
content,
|
|
565
|
+
transformers: uniqueBy(getMerged("transformers"), (a, b) => a.name === b.name)
|
|
566
|
+
};
|
|
567
|
+
const extendThemes = getMerged("extendTheme");
|
|
568
|
+
for (const extendTheme of extendThemes) resolved.theme = extendTheme(resolved.theme, resolved) || resolved.theme;
|
|
569
|
+
for (const p of sources) p?.configResolved?.(resolved);
|
|
570
|
+
return resolved;
|
|
612
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* Merge multiple configs into one, later ones have higher priority
|
|
574
|
+
*/
|
|
613
575
|
function mergeConfigs(configs) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
576
|
+
const maybeArrays = [
|
|
577
|
+
"shortcuts",
|
|
578
|
+
"preprocess",
|
|
579
|
+
"postprocess"
|
|
580
|
+
];
|
|
581
|
+
return configs.map((config) => Object.entries(config).reduce((acc, [key, value]) => ({
|
|
582
|
+
...acc,
|
|
583
|
+
[key]: maybeArrays.includes(key) ? toArray(value) : value
|
|
584
|
+
}), {})).reduce(({ theme: themeA, content: contentA, ...a }, { theme: themeB, content: contentB, ...b }) => {
|
|
585
|
+
const c = mergeDeep(a, b, true);
|
|
586
|
+
if (themeA || themeB) c.theme = mergeThemes([themeA, themeB]);
|
|
587
|
+
if (contentA || contentB) c.content = mergeContentOptions([contentA || {}, contentB || {}]);
|
|
588
|
+
return c;
|
|
589
|
+
}, {});
|
|
627
590
|
}
|
|
628
591
|
function mergeThemes(themes) {
|
|
629
|
-
|
|
592
|
+
return themes.map((theme) => theme ? clone(theme) : {}).reduce((a, b) => mergeDeep(a, b), {});
|
|
630
593
|
}
|
|
631
594
|
function mergeAutocompleteShorthands(shorthands) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
};
|
|
645
|
-
}, {});
|
|
595
|
+
return shorthands.reduce((a, b) => {
|
|
596
|
+
const rs = {};
|
|
597
|
+
for (const key in b) {
|
|
598
|
+
const value = b[key];
|
|
599
|
+
if (Array.isArray(value)) rs[key] = `(${value.join("|")})`;
|
|
600
|
+
else rs[key] = value;
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
...a,
|
|
604
|
+
...rs
|
|
605
|
+
};
|
|
606
|
+
}, {});
|
|
646
607
|
}
|
|
647
608
|
function mergeFilterPatterns(...filterPatterns) {
|
|
648
|
-
|
|
609
|
+
return filterPatterns.flatMap(flatternFilterPattern);
|
|
649
610
|
}
|
|
650
611
|
function flatternFilterPattern(pattern) {
|
|
651
|
-
|
|
612
|
+
return Array.isArray(pattern) ? pattern : pattern ? [pattern] : [];
|
|
652
613
|
}
|
|
653
614
|
function definePreset(preset) {
|
|
654
|
-
|
|
615
|
+
return preset;
|
|
655
616
|
}
|
|
656
617
|
|
|
657
|
-
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region package.json
|
|
620
|
+
var version = "66.5.12";
|
|
658
621
|
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/generator.ts
|
|
659
624
|
const symbols = {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
625
|
+
shortcutsNoMerge: "$$symbol-shortcut-no-merge",
|
|
626
|
+
noMerge: "$$symbol-no-merge",
|
|
627
|
+
variants: "$$symbol-variants",
|
|
628
|
+
parent: "$$symbol-parent",
|
|
629
|
+
selector: "$$symbol-selector",
|
|
630
|
+
layer: "$$symbol-layer",
|
|
631
|
+
sort: "$$symbol-sort",
|
|
632
|
+
body: "$$symbol-body"
|
|
633
|
+
};
|
|
634
|
+
var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
635
|
+
constructor(userConfig = {}, defaults = {}) {
|
|
636
|
+
this.userConfig = userConfig;
|
|
637
|
+
this.defaults = defaults;
|
|
638
|
+
this.version = version;
|
|
639
|
+
this.events = createNanoEvents();
|
|
640
|
+
this.config = void 0;
|
|
641
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
642
|
+
this.blocked = /* @__PURE__ */ new Set();
|
|
643
|
+
this.parentOrders = /* @__PURE__ */ new Map();
|
|
644
|
+
this.activatedRules = /* @__PURE__ */ new Set();
|
|
645
|
+
this.resolveCSSResult = (raw, result, rule, context) => {
|
|
646
|
+
const entries = normalizeCSSValues(result).filter((i) => i.length);
|
|
647
|
+
if (entries.length) {
|
|
648
|
+
if (this.config.details) context.rules.push(rule);
|
|
649
|
+
context.generator.activatedRules.add(rule);
|
|
650
|
+
const meta = rule[2];
|
|
651
|
+
return entries.map((css) => {
|
|
652
|
+
if (isString(css)) return [
|
|
653
|
+
meta.__index,
|
|
654
|
+
css,
|
|
655
|
+
meta
|
|
656
|
+
];
|
|
657
|
+
let variants = context.variantHandlers;
|
|
658
|
+
let entryMeta = meta;
|
|
659
|
+
for (const entry of css) if (entry[0] === symbols.variants) if (typeof entry[1] === "function") variants = entry[1](variants) || variants;
|
|
660
|
+
else variants = [...toArray(entry[1]), ...variants];
|
|
661
|
+
else if (entry[0] === symbols.parent) variants = [{ parent: entry[1] }, ...variants];
|
|
662
|
+
else if (entry[0] === symbols.selector) variants = [{ selector: entry[1] }, ...variants];
|
|
663
|
+
else if (entry[0] === symbols.layer) variants = [{ layer: entry[1] }, ...variants];
|
|
664
|
+
else if (entry[0] === symbols.sort) entryMeta = {
|
|
665
|
+
...entryMeta,
|
|
666
|
+
sort: entry[1]
|
|
667
|
+
};
|
|
668
|
+
else if (entry[0] === symbols.noMerge) entryMeta = {
|
|
669
|
+
...entryMeta,
|
|
670
|
+
noMerge: entry[1]
|
|
671
|
+
};
|
|
672
|
+
else if (entry[0] === symbols.body) entry[0] = VirtualKey;
|
|
673
|
+
return [
|
|
674
|
+
meta.__index,
|
|
675
|
+
raw,
|
|
676
|
+
css,
|
|
677
|
+
entryMeta,
|
|
678
|
+
variants
|
|
679
|
+
];
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
static async create(userConfig = {}, defaults = {}) {
|
|
685
|
+
const uno = new UnoGeneratorInternal(userConfig, defaults);
|
|
686
|
+
uno.config = await resolveConfig(uno.userConfig, uno.defaults);
|
|
687
|
+
uno.events.emit("config", uno.config);
|
|
688
|
+
return uno;
|
|
689
|
+
}
|
|
690
|
+
async setConfig(userConfig, defaults) {
|
|
691
|
+
if (!userConfig) return;
|
|
692
|
+
if (defaults) this.defaults = defaults;
|
|
693
|
+
this.userConfig = userConfig;
|
|
694
|
+
this.blocked.clear();
|
|
695
|
+
this.parentOrders.clear();
|
|
696
|
+
this.activatedRules.clear();
|
|
697
|
+
this.cache.clear();
|
|
698
|
+
this.config = await resolveConfig(userConfig, this.defaults);
|
|
699
|
+
this.events.emit("config", this.config);
|
|
700
|
+
}
|
|
701
|
+
async applyExtractors(code, id, extracted = /* @__PURE__ */ new Set()) {
|
|
702
|
+
const context = {
|
|
703
|
+
original: code,
|
|
704
|
+
code,
|
|
705
|
+
id,
|
|
706
|
+
extracted,
|
|
707
|
+
envMode: this.config.envMode
|
|
708
|
+
};
|
|
709
|
+
for (const extractor of this.config.extractors) {
|
|
710
|
+
const result = await extractor.extract?.(context);
|
|
711
|
+
if (!result) continue;
|
|
712
|
+
if (isCountableSet(result) && isCountableSet(extracted)) for (const token of result) extracted.setCount(token, extracted.getCount(token) + result.getCount(token));
|
|
713
|
+
else for (const token of result) extracted.add(token);
|
|
714
|
+
}
|
|
715
|
+
return extracted;
|
|
716
|
+
}
|
|
717
|
+
makeContext(raw, applied) {
|
|
718
|
+
const context = {
|
|
719
|
+
rawSelector: raw,
|
|
720
|
+
currentSelector: applied[1],
|
|
721
|
+
theme: this.config.theme,
|
|
722
|
+
generator: this,
|
|
723
|
+
symbols,
|
|
724
|
+
variantHandlers: applied[2],
|
|
725
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
726
|
+
variantMatch: applied
|
|
727
|
+
};
|
|
728
|
+
return context;
|
|
729
|
+
}
|
|
730
|
+
async parseToken(raw, alias) {
|
|
731
|
+
if (this.blocked.has(raw)) return;
|
|
732
|
+
const cacheKey = `${raw}${alias ? ` ${alias}` : ""}`;
|
|
733
|
+
if (this.cache.has(cacheKey)) return this.cache.get(cacheKey);
|
|
734
|
+
const current = this.config.preprocess.reduce((acc, p) => p(acc) ?? acc, raw);
|
|
735
|
+
if (this.isBlocked(current)) {
|
|
736
|
+
this.blocked.add(raw);
|
|
737
|
+
this.cache.set(cacheKey, null);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
const variantResults = await this.matchVariants(raw, current);
|
|
741
|
+
if (variantResults.every((i) => !i || this.isBlocked(i[1]))) {
|
|
742
|
+
this.blocked.add(raw);
|
|
743
|
+
this.cache.set(cacheKey, null);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
const handleVariantResult = async (matched) => {
|
|
747
|
+
const context = this.makeContext(raw, [
|
|
748
|
+
alias || matched[0],
|
|
749
|
+
matched[1],
|
|
750
|
+
matched[2],
|
|
751
|
+
matched[3]
|
|
752
|
+
]);
|
|
753
|
+
if (this.config.details) context.variants = [...matched[3]];
|
|
754
|
+
const expanded = await this.expandShortcut(context.currentSelector, context);
|
|
755
|
+
return expanded ? await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]) : (await this.parseUtil(context.variantMatch, context))?.flatMap((i) => this.stringifyUtil(i, context)).filter(notNull);
|
|
756
|
+
};
|
|
757
|
+
const result = (await Promise.all(variantResults.map((i) => handleVariantResult(i)))).flat().filter((x) => !!x);
|
|
758
|
+
if (result?.length) {
|
|
759
|
+
this.cache.set(cacheKey, result);
|
|
760
|
+
return result;
|
|
761
|
+
}
|
|
762
|
+
this.cache.set(cacheKey, null);
|
|
763
|
+
}
|
|
764
|
+
async generate(input, options = {}) {
|
|
765
|
+
const { id, scope, preflights = true, safelist = true, minify = false, extendedInfo = false } = options;
|
|
766
|
+
const tokens = isString(input) ? await this.applyExtractors(input, id, extendedInfo ? new CountableSet() : /* @__PURE__ */ new Set()) : Array.isArray(input) ? new Set(input) : input;
|
|
767
|
+
if (safelist) {
|
|
768
|
+
const safelistContext = {
|
|
769
|
+
generator: this,
|
|
770
|
+
theme: this.config.theme
|
|
771
|
+
};
|
|
772
|
+
this.config.safelist.flatMap((s) => typeof s === "function" ? s(safelistContext) : s).forEach((s) => {
|
|
773
|
+
const trimedS = s.trim();
|
|
774
|
+
if (trimedS && !tokens.has(trimedS)) tokens.add(trimedS);
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
const nl = minify ? "" : "\n";
|
|
778
|
+
const layerSet = new Set([LAYER_DEFAULT]);
|
|
779
|
+
const matched = extendedInfo ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
780
|
+
const sheet = /* @__PURE__ */ new Map();
|
|
781
|
+
let preflightsMap = {};
|
|
782
|
+
const tokenPromises = Array.from(tokens).map(async (raw) => {
|
|
783
|
+
if (matched.has(raw)) return;
|
|
784
|
+
const payload = await this.parseToken(raw);
|
|
785
|
+
if (payload == null) return;
|
|
786
|
+
if (matched instanceof Map) matched.set(raw, {
|
|
787
|
+
data: payload,
|
|
788
|
+
count: isCountableSet(tokens) ? tokens.getCount(raw) : -1
|
|
789
|
+
});
|
|
790
|
+
else matched.add(raw);
|
|
791
|
+
for (const item of payload) {
|
|
792
|
+
const parent = item[3] || "";
|
|
793
|
+
const layer = item[4]?.layer;
|
|
794
|
+
if (!sheet.has(parent)) sheet.set(parent, []);
|
|
795
|
+
sheet.get(parent).push(item);
|
|
796
|
+
if (layer) layerSet.add(layer);
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
await Promise.all(tokenPromises);
|
|
800
|
+
await (async () => {
|
|
801
|
+
if (!preflights) return;
|
|
802
|
+
const preflightContext = {
|
|
803
|
+
generator: this,
|
|
804
|
+
theme: this.config.theme
|
|
805
|
+
};
|
|
806
|
+
const preflightLayerSet = /* @__PURE__ */ new Set([]);
|
|
807
|
+
this.config.preflights.forEach(({ layer = LAYER_PREFLIGHTS }) => {
|
|
808
|
+
layerSet.add(layer);
|
|
809
|
+
preflightLayerSet.add(layer);
|
|
810
|
+
});
|
|
811
|
+
preflightsMap = Object.fromEntries(await Promise.all(Array.from(preflightLayerSet).map(async (layer) => {
|
|
812
|
+
return [layer, (await Promise.all(this.config.preflights.filter((i) => (i.layer || LAYER_PREFLIGHTS) === layer).map(async (i) => await i.getCSS(preflightContext)))).filter(Boolean).join(nl)];
|
|
813
|
+
})));
|
|
814
|
+
})();
|
|
815
|
+
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
816
|
+
const layerCache = {};
|
|
817
|
+
const outputCssLayers = this.config.outputToCssLayers;
|
|
818
|
+
const getLayerAlias = (layer) => {
|
|
819
|
+
let alias = layer;
|
|
820
|
+
if (typeof outputCssLayers === "object") alias = outputCssLayers.cssLayerName?.(layer);
|
|
821
|
+
return alias === null ? null : alias ?? layer;
|
|
822
|
+
};
|
|
823
|
+
const getLayer = (layer = LAYER_DEFAULT) => {
|
|
824
|
+
if (layerCache[layer]) return layerCache[layer];
|
|
825
|
+
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
|
|
826
|
+
const size = items.length;
|
|
827
|
+
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => {
|
|
828
|
+
return a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[5]?.currentSelector?.localeCompare(b[5]?.currentSelector ?? "") || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0;
|
|
829
|
+
}).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
830
|
+
return [
|
|
831
|
+
[[(selector ? applyScope(selector, scope) : selector) ?? "", meta?.sort ?? 0]],
|
|
832
|
+
body,
|
|
833
|
+
!!(variantNoMerge ?? meta?.noMerge)
|
|
834
|
+
];
|
|
835
|
+
});
|
|
836
|
+
if (!sorted.length) return void 0;
|
|
837
|
+
const ruleLines = sorted.reverse().map(([selectorSortPair, body, noMerge], idx) => {
|
|
838
|
+
if (!noMerge && this.config.mergeSelectors) for (let i = idx + 1; i < size; i++) {
|
|
839
|
+
const current = sorted[i];
|
|
840
|
+
if (current && !current[2] && (selectorSortPair && current[0] || selectorSortPair == null && current[0] == null) && current[1] === body) {
|
|
841
|
+
if (selectorSortPair && current[0]) current[0].push(...selectorSortPair);
|
|
842
|
+
return null;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const selectors = selectorSortPair ? uniq(selectorSortPair.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || "") || 0).map((pair) => pair[0]).filter(Boolean)) : [];
|
|
846
|
+
return selectors.length ? `${selectors.join(`,${nl}`)}{${body}}` : body;
|
|
847
|
+
}).filter(Boolean);
|
|
848
|
+
const rules = Array.from(new Set(ruleLines)).reverse().join(nl);
|
|
849
|
+
if (!parent) return rules;
|
|
850
|
+
const parents = parent.split(" $$ ");
|
|
851
|
+
return `${parents.join("{")}{${nl}${rules}${nl}${"}".repeat(parents.length)}`;
|
|
852
|
+
}).filter(Boolean).join(nl);
|
|
853
|
+
if (preflights) css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
854
|
+
let alias;
|
|
855
|
+
if (outputCssLayers && css) {
|
|
856
|
+
alias = getLayerAlias(layer);
|
|
857
|
+
if (alias !== null) css = `@layer ${alias}{${nl}${css}${nl}}`;
|
|
858
|
+
}
|
|
859
|
+
const layerMark = minify ? "" : `/* layer: ${layer}${alias && alias !== layer ? `, alias: ${alias}` : ""} */${nl}`;
|
|
860
|
+
return layerCache[layer] = css ? layerMark + css : "";
|
|
861
|
+
};
|
|
862
|
+
const getLayers = (includes = layers, excludes) => {
|
|
863
|
+
const layers$1 = includes.filter((i) => !excludes?.includes(i));
|
|
864
|
+
return [outputCssLayers && layers$1.length > 0 ? `@layer ${layers$1.map(getLayerAlias).filter(notNull).join(", ")};` : void 0, ...layers$1.map((i) => getLayer(i) || "")].filter(Boolean).join(nl);
|
|
865
|
+
};
|
|
866
|
+
const setLayer = async (layer, callback) => {
|
|
867
|
+
const content = await callback(getLayer(layer));
|
|
868
|
+
layerCache[layer] = content;
|
|
869
|
+
return content;
|
|
870
|
+
};
|
|
871
|
+
return {
|
|
872
|
+
get css() {
|
|
873
|
+
return getLayers();
|
|
874
|
+
},
|
|
875
|
+
layers,
|
|
876
|
+
matched,
|
|
877
|
+
getLayers,
|
|
878
|
+
getLayer,
|
|
879
|
+
setLayer
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
async matchVariants(raw, current) {
|
|
883
|
+
const context = {
|
|
884
|
+
rawSelector: raw,
|
|
885
|
+
theme: this.config.theme,
|
|
886
|
+
generator: this
|
|
887
|
+
};
|
|
888
|
+
const match = async (result) => {
|
|
889
|
+
let applied = true;
|
|
890
|
+
const [, , handlers, variants] = result;
|
|
891
|
+
while (applied) {
|
|
892
|
+
applied = false;
|
|
893
|
+
const processed = result[1];
|
|
894
|
+
for (const v of this.config.variants) {
|
|
895
|
+
if (!v.multiPass && variants.has(v)) continue;
|
|
896
|
+
let handler = await v.match(processed, context);
|
|
897
|
+
if (!handler) continue;
|
|
898
|
+
if (isString(handler)) {
|
|
899
|
+
if (handler === processed) continue;
|
|
900
|
+
handler = { matcher: handler };
|
|
901
|
+
}
|
|
902
|
+
if (Array.isArray(handler)) {
|
|
903
|
+
if (!handler.length) continue;
|
|
904
|
+
if (handler.length === 1) handler = handler[0];
|
|
905
|
+
else {
|
|
906
|
+
if (v.multiPass) throw new Error("multiPass can not be used together with array return variants");
|
|
907
|
+
const clones = handler.map((h) => {
|
|
908
|
+
const _processed = h.matcher ?? processed;
|
|
909
|
+
const _handlers = [h, ...handlers];
|
|
910
|
+
const _variants = new Set(variants);
|
|
911
|
+
_variants.add(v);
|
|
912
|
+
return [
|
|
913
|
+
result[0],
|
|
914
|
+
_processed,
|
|
915
|
+
_handlers,
|
|
916
|
+
_variants
|
|
917
|
+
];
|
|
918
|
+
});
|
|
919
|
+
return (await Promise.all(clones.map((c) => match(c)))).flat();
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
result[1] = handler.matcher ?? processed;
|
|
923
|
+
handlers.unshift(handler);
|
|
924
|
+
variants.add(v);
|
|
925
|
+
applied = true;
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
if (!applied) break;
|
|
929
|
+
if (handlers.length > 500) throw new Error(`Too many variants applied to "${raw}"`);
|
|
930
|
+
}
|
|
931
|
+
return [result];
|
|
932
|
+
};
|
|
933
|
+
return await match([
|
|
934
|
+
raw,
|
|
935
|
+
current || raw,
|
|
936
|
+
[],
|
|
937
|
+
/* @__PURE__ */ new Set()
|
|
938
|
+
]);
|
|
939
|
+
}
|
|
940
|
+
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
941
|
+
const variantContextResult = variantHandlers.slice().sort((a, b) => (a.order || 0) - (b.order || 0)).reduceRight((previous, v) => (input) => {
|
|
942
|
+
const entries = v.body?.(input.entries) || input.entries;
|
|
943
|
+
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
944
|
+
const selector = v.selector?.(input.selector, entries);
|
|
945
|
+
return (v.handle ?? defaultVariantHandler)({
|
|
946
|
+
...input,
|
|
947
|
+
entries,
|
|
948
|
+
selector: selector || input.selector,
|
|
949
|
+
parent: parents[0] || input.parent,
|
|
950
|
+
parentOrder: parents[1] || input.parentOrder,
|
|
951
|
+
layer: v.layer || input.layer,
|
|
952
|
+
sort: v.sort || input.sort
|
|
953
|
+
}, previous);
|
|
954
|
+
}, (input) => input)({
|
|
955
|
+
prefix: "",
|
|
956
|
+
selector: toEscapedSelector(raw),
|
|
957
|
+
pseudo: "",
|
|
958
|
+
entries: parsed[2]
|
|
959
|
+
});
|
|
960
|
+
const { parent, parentOrder } = variantContextResult;
|
|
961
|
+
if (parent != null && parentOrder != null) this.parentOrders.set(parent, parentOrder);
|
|
962
|
+
const obj = {
|
|
963
|
+
selector: [
|
|
964
|
+
variantContextResult.prefix,
|
|
965
|
+
variantContextResult.selector,
|
|
966
|
+
variantContextResult.pseudo
|
|
967
|
+
].join(""),
|
|
968
|
+
entries: variantContextResult.entries,
|
|
969
|
+
parent,
|
|
970
|
+
layer: variantContextResult.layer,
|
|
971
|
+
sort: variantContextResult.sort,
|
|
972
|
+
noMerge: variantContextResult.noMerge
|
|
973
|
+
};
|
|
974
|
+
return this.config.postprocess.reduce((utilities, p) => {
|
|
975
|
+
const result = [];
|
|
976
|
+
for (const util of utilities) {
|
|
977
|
+
const processed = p(util);
|
|
978
|
+
if (Array.isArray(processed)) result.push(...processed.filter(notNull));
|
|
979
|
+
else result.push(processed || util);
|
|
980
|
+
}
|
|
981
|
+
return result;
|
|
982
|
+
}, [obj]);
|
|
983
|
+
}
|
|
984
|
+
constructCustomCSS(context, body, overrideSelector) {
|
|
985
|
+
const normalizedBody = normalizeCSSEntries(body);
|
|
986
|
+
if (isString(normalizedBody)) return normalizedBody;
|
|
987
|
+
return this.applyVariants([
|
|
988
|
+
0,
|
|
989
|
+
overrideSelector || context.rawSelector,
|
|
990
|
+
normalizedBody,
|
|
991
|
+
void 0,
|
|
992
|
+
context.variantHandlers
|
|
993
|
+
]).map(({ selector, entries, parent }) => {
|
|
994
|
+
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
995
|
+
if (parent) return `${parent}{${cssBody}}`;
|
|
996
|
+
return cssBody;
|
|
997
|
+
}).join("");
|
|
998
|
+
}
|
|
999
|
+
async parseUtil(input, context, internal = false, shortcutPrefix) {
|
|
1000
|
+
const variantResults = isString(input) ? await this.matchVariants(input) : [input];
|
|
1001
|
+
const parse = async ([raw, processed, variantHandlers]) => {
|
|
1002
|
+
if (this.config.details) context.rules = context.rules ?? [];
|
|
1003
|
+
const scopeContext = {
|
|
1004
|
+
...context,
|
|
1005
|
+
variantHandlers
|
|
1006
|
+
};
|
|
1007
|
+
const staticMatch = this.config.rulesStaticMap[processed];
|
|
1008
|
+
if (staticMatch) {
|
|
1009
|
+
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) return this.resolveCSSResult(raw, staticMatch[1], staticMatch, scopeContext);
|
|
1010
|
+
}
|
|
1011
|
+
for (const rule of this.config.rulesDynamic) {
|
|
1012
|
+
const [matcher, handler, meta] = rule;
|
|
1013
|
+
if (meta?.internal && !internal) continue;
|
|
1014
|
+
let unprefixed = processed;
|
|
1015
|
+
if (meta?.prefix) {
|
|
1016
|
+
const prefixes = toArray(meta.prefix);
|
|
1017
|
+
if (shortcutPrefix) {
|
|
1018
|
+
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1019
|
+
if (!prefixes.some((i) => shortcutPrefixes.includes(i))) continue;
|
|
1020
|
+
} else {
|
|
1021
|
+
const prefix = prefixes.find((i) => processed.startsWith(i));
|
|
1022
|
+
if (prefix == null) continue;
|
|
1023
|
+
unprefixed = processed.slice(prefix.length);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
const match = unprefixed.match(matcher);
|
|
1027
|
+
if (!match) continue;
|
|
1028
|
+
let result = await handler(match, scopeContext);
|
|
1029
|
+
if (!result) continue;
|
|
1030
|
+
if (typeof result !== "string") {
|
|
1031
|
+
if (Symbol.asyncIterator in result) {
|
|
1032
|
+
const entries = [];
|
|
1033
|
+
for await (const r of result) if (r) entries.push(r);
|
|
1034
|
+
result = entries;
|
|
1035
|
+
} else if (Symbol.iterator in result && !Array.isArray(result)) result = Array.from(result).filter(notNull);
|
|
1036
|
+
}
|
|
1037
|
+
const resolvedResult = this.resolveCSSResult(raw, result, rule, scopeContext);
|
|
1038
|
+
if (resolvedResult) return resolvedResult;
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
const parsed = (await Promise.all(variantResults.map((i) => parse(i)))).flat().filter((x) => !!x);
|
|
1042
|
+
if (!parsed.length) return void 0;
|
|
1043
|
+
return parsed;
|
|
1044
|
+
}
|
|
1045
|
+
stringifyUtil(parsed, context) {
|
|
1046
|
+
if (!parsed) return;
|
|
1047
|
+
if (isRawUtil(parsed)) return [[
|
|
1048
|
+
parsed[0],
|
|
1049
|
+
void 0,
|
|
1050
|
+
parsed[1],
|
|
1051
|
+
void 0,
|
|
1052
|
+
parsed[2],
|
|
1053
|
+
this.config.details ? context : void 0,
|
|
1054
|
+
void 0
|
|
1055
|
+
]];
|
|
1056
|
+
const utilities = this.applyVariants(parsed);
|
|
1057
|
+
const result = [];
|
|
1058
|
+
for (const util of utilities) {
|
|
1059
|
+
const { selector, entries, parent, layer: variantLayer, sort: variantSort, noMerge } = util;
|
|
1060
|
+
const body = entriesToCss(entries);
|
|
1061
|
+
if (!body) continue;
|
|
1062
|
+
const { layer: metaLayer, sort: metaSort, ...meta } = parsed[3] ?? {};
|
|
1063
|
+
const ruleMeta = {
|
|
1064
|
+
...meta,
|
|
1065
|
+
layer: variantLayer ?? metaLayer,
|
|
1066
|
+
sort: variantSort ?? metaSort
|
|
1067
|
+
};
|
|
1068
|
+
result.push([
|
|
1069
|
+
parsed[0],
|
|
1070
|
+
selector,
|
|
1071
|
+
body,
|
|
1072
|
+
parent,
|
|
1073
|
+
ruleMeta,
|
|
1074
|
+
this.config.details ? context : void 0,
|
|
1075
|
+
noMerge
|
|
1076
|
+
]);
|
|
1077
|
+
}
|
|
1078
|
+
return result;
|
|
1079
|
+
}
|
|
1080
|
+
async expandShortcut(input, context, depth = 5) {
|
|
1081
|
+
if (depth === 0) return;
|
|
1082
|
+
const recordShortcut = this.config.details ? (s) => {
|
|
1083
|
+
context.shortcuts = context.shortcuts ?? [];
|
|
1084
|
+
context.shortcuts.push(s);
|
|
1085
|
+
} : noop;
|
|
1086
|
+
let meta;
|
|
1087
|
+
let result;
|
|
1088
|
+
let stringResult;
|
|
1089
|
+
let inlineResult;
|
|
1090
|
+
for (const s of this.config.shortcuts) {
|
|
1091
|
+
let unprefixed = input;
|
|
1092
|
+
if (s[2]?.prefix) {
|
|
1093
|
+
const prefix = toArray(s[2].prefix).find((i) => input.startsWith(i));
|
|
1094
|
+
if (prefix == null) continue;
|
|
1095
|
+
unprefixed = input.slice(prefix.length);
|
|
1096
|
+
}
|
|
1097
|
+
if (isStaticShortcut(s)) {
|
|
1098
|
+
if (s[0] === unprefixed) {
|
|
1099
|
+
meta = meta || s[2];
|
|
1100
|
+
result = s[1];
|
|
1101
|
+
recordShortcut(s);
|
|
1102
|
+
break;
|
|
1103
|
+
}
|
|
1104
|
+
} else {
|
|
1105
|
+
const match = unprefixed.match(s[0]);
|
|
1106
|
+
if (match) result = s[1](match, context);
|
|
1107
|
+
if (result) {
|
|
1108
|
+
meta = meta || s[2];
|
|
1109
|
+
recordShortcut(s);
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
if (result) {
|
|
1115
|
+
stringResult = uniq(toArray(result).filter(isString).map((s) => expandVariantGroup(s.trim()).split(/\s+/g)).flat());
|
|
1116
|
+
inlineResult = toArray(result).filter((i) => !isString(i)).map((i) => ({
|
|
1117
|
+
handles: [],
|
|
1118
|
+
value: i
|
|
1119
|
+
}));
|
|
1120
|
+
}
|
|
1121
|
+
if (!result) {
|
|
1122
|
+
const matched = isString(input) ? await this.matchVariants(input) : [input];
|
|
1123
|
+
for (const match of matched) {
|
|
1124
|
+
const [raw, inputWithoutVariant, handles] = match;
|
|
1125
|
+
if (raw !== inputWithoutVariant) {
|
|
1126
|
+
const expanded = await this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
1127
|
+
if (expanded) {
|
|
1128
|
+
stringResult = expanded[0].filter(isString).map((item) => raw.replace(inputWithoutVariant, item));
|
|
1129
|
+
inlineResult = expanded[0].filter((i) => !isString(i)).map((item) => {
|
|
1130
|
+
return {
|
|
1131
|
+
handles: [...item.handles, ...handles],
|
|
1132
|
+
value: item.value
|
|
1133
|
+
};
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
if (!stringResult?.length && !inlineResult?.length) return;
|
|
1140
|
+
return [[await Promise.all(toArray(stringResult).map(async (s) => (await this.expandShortcut(s, context, depth - 1))?.[0] || [s])), inlineResult].flat(2).filter((x) => !!x), meta];
|
|
1141
|
+
}
|
|
1142
|
+
async stringifyShortcuts(parent, context, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
1143
|
+
const layerMap = new BetterMap();
|
|
1144
|
+
const parsed = (await Promise.all(uniq(expanded).map(async (i) => {
|
|
1145
|
+
const result = isString(i) ? await this.parseUtil(i, context, true, meta.prefix) : [[
|
|
1146
|
+
Number.POSITIVE_INFINITY,
|
|
1147
|
+
"{inline}",
|
|
1148
|
+
normalizeCSSEntries(i.value),
|
|
1149
|
+
void 0,
|
|
1150
|
+
i.handles
|
|
1151
|
+
]];
|
|
1152
|
+
if (!result && this.config.warn) warnOnce(`unmatched utility "${i}" in shortcut "${parent[1]}"`);
|
|
1153
|
+
return result || [];
|
|
1154
|
+
}))).flat(1).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
1155
|
+
const [raw, , parentVariants] = parent;
|
|
1156
|
+
const rawStringifiedUtil = [];
|
|
1157
|
+
for (const item of parsed) {
|
|
1158
|
+
if (isRawUtil(item)) {
|
|
1159
|
+
rawStringifiedUtil.push([
|
|
1160
|
+
item[0],
|
|
1161
|
+
void 0,
|
|
1162
|
+
item[1],
|
|
1163
|
+
void 0,
|
|
1164
|
+
item[2],
|
|
1165
|
+
context,
|
|
1166
|
+
void 0
|
|
1167
|
+
]);
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
const isNoMerge = Object.fromEntries(item[2])[symbols.shortcutsNoMerge];
|
|
1171
|
+
const variants = [...item[4], ...!isNoMerge ? parentVariants : []];
|
|
1172
|
+
for (const { selector, entries, parent: parent$1, sort, noMerge, layer } of this.applyVariants(item, variants, raw)) layerMap.getFallback(layer ?? meta.layer, new TwoKeyMap()).getFallback(selector, parent$1, [[], item[0]])[0].push([
|
|
1173
|
+
entries,
|
|
1174
|
+
!!(noMerge ?? item[3]?.noMerge),
|
|
1175
|
+
sort ?? 0
|
|
1176
|
+
]);
|
|
1177
|
+
}
|
|
1178
|
+
return rawStringifiedUtil.concat(layerMap.flatMap((selectorMap, layer) => selectorMap.map(([e$1, index], selector, joinedParents) => {
|
|
1179
|
+
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
1180
|
+
const maxSort = Math.max(...entrySortPair.map((e$2) => e$2[1]));
|
|
1181
|
+
const entriesList = entrySortPair.map((e$2) => e$2[0]);
|
|
1182
|
+
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
1183
|
+
const body = entriesToCss(entries);
|
|
1184
|
+
if (body) return [
|
|
1185
|
+
index,
|
|
1186
|
+
selector,
|
|
1187
|
+
body,
|
|
1188
|
+
joinedParents,
|
|
1189
|
+
{
|
|
1190
|
+
...meta,
|
|
1191
|
+
noMerge,
|
|
1192
|
+
sort: maxSort,
|
|
1193
|
+
layer
|
|
1194
|
+
},
|
|
1195
|
+
context,
|
|
1196
|
+
void 0
|
|
1197
|
+
];
|
|
1198
|
+
});
|
|
1199
|
+
};
|
|
1200
|
+
return [[e$1.filter(([, noMerge]) => noMerge).map(([entries, , sort]) => [entries, sort]), true], [e$1.filter(([, noMerge]) => !noMerge).map(([entries, , sort]) => [entries, sort]), false]].map(([e$2, noMerge]) => [...stringify(false, noMerge, e$2.filter(([entries]) => entries.some((entry) => entry[0] === symbols.shortcutsNoMerge))), ...stringify(true, noMerge, e$2.filter(([entries]) => entries.every((entry) => entry[0] !== symbols.shortcutsNoMerge)))]);
|
|
1201
|
+
}).flat(2).filter(Boolean)));
|
|
1202
|
+
}
|
|
1203
|
+
isBlocked(raw) {
|
|
1204
|
+
return !raw || this.config.blocklist.map((e$1) => Array.isArray(e$1) ? e$1[0] : e$1).some((e$1) => typeof e$1 === "function" ? e$1(raw) : isString(e$1) ? e$1 === raw : e$1.test(raw));
|
|
1205
|
+
}
|
|
1206
|
+
getBlocked(raw) {
|
|
1207
|
+
const rule = this.config.blocklist.find((e$1) => {
|
|
1208
|
+
const v = Array.isArray(e$1) ? e$1[0] : e$1;
|
|
1209
|
+
return typeof v === "function" ? v(raw) : isString(v) ? v === raw : v.test(raw);
|
|
1210
|
+
});
|
|
1211
|
+
return rule ? Array.isArray(rule) ? rule : [rule, void 0] : void 0;
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
var UnoGenerator = class extends UnoGeneratorInternal {
|
|
1215
|
+
/**
|
|
1216
|
+
* @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
|
|
1217
|
+
*/
|
|
1218
|
+
constructor(userConfig = {}, defaults = {}) {
|
|
1219
|
+
super(userConfig, defaults);
|
|
1220
|
+
console.warn("`new UnoGenerator()` is deprecated, please use `createGenerator()` instead");
|
|
1221
|
+
}
|
|
668
1222
|
};
|
|
669
|
-
class UnoGeneratorInternal {
|
|
670
|
-
constructor(userConfig = {}, defaults = {}) {
|
|
671
|
-
this.userConfig = userConfig;
|
|
672
|
-
this.defaults = defaults;
|
|
673
|
-
}
|
|
674
|
-
version = version;
|
|
675
|
-
events = createNanoEvents();
|
|
676
|
-
config = void 0;
|
|
677
|
-
cache = /* @__PURE__ */ new Map();
|
|
678
|
-
blocked = /* @__PURE__ */ new Set();
|
|
679
|
-
parentOrders = /* @__PURE__ */ new Map();
|
|
680
|
-
activatedRules = /* @__PURE__ */ new Set();
|
|
681
|
-
static async create(userConfig = {}, defaults = {}) {
|
|
682
|
-
const uno = new UnoGeneratorInternal(userConfig, defaults);
|
|
683
|
-
uno.config = await resolveConfig(uno.userConfig, uno.defaults);
|
|
684
|
-
uno.events.emit("config", uno.config);
|
|
685
|
-
return uno;
|
|
686
|
-
}
|
|
687
|
-
async setConfig(userConfig, defaults) {
|
|
688
|
-
if (!userConfig)
|
|
689
|
-
return;
|
|
690
|
-
if (defaults)
|
|
691
|
-
this.defaults = defaults;
|
|
692
|
-
this.userConfig = userConfig;
|
|
693
|
-
this.blocked.clear();
|
|
694
|
-
this.parentOrders.clear();
|
|
695
|
-
this.activatedRules.clear();
|
|
696
|
-
this.cache.clear();
|
|
697
|
-
this.config = await resolveConfig(userConfig, this.defaults);
|
|
698
|
-
this.events.emit("config", this.config);
|
|
699
|
-
}
|
|
700
|
-
async applyExtractors(code, id, extracted = /* @__PURE__ */ new Set()) {
|
|
701
|
-
const context = {
|
|
702
|
-
original: code,
|
|
703
|
-
code,
|
|
704
|
-
id,
|
|
705
|
-
extracted,
|
|
706
|
-
envMode: this.config.envMode
|
|
707
|
-
};
|
|
708
|
-
for (const extractor of this.config.extractors) {
|
|
709
|
-
const result = await extractor.extract?.(context);
|
|
710
|
-
if (!result)
|
|
711
|
-
continue;
|
|
712
|
-
if (isCountableSet(result) && isCountableSet(extracted)) {
|
|
713
|
-
for (const token of result)
|
|
714
|
-
extracted.setCount(token, extracted.getCount(token) + result.getCount(token));
|
|
715
|
-
} else {
|
|
716
|
-
for (const token of result)
|
|
717
|
-
extracted.add(token);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
return extracted;
|
|
721
|
-
}
|
|
722
|
-
makeContext(raw, applied) {
|
|
723
|
-
const context = {
|
|
724
|
-
rawSelector: raw,
|
|
725
|
-
currentSelector: applied[1],
|
|
726
|
-
theme: this.config.theme,
|
|
727
|
-
generator: this,
|
|
728
|
-
symbols,
|
|
729
|
-
variantHandlers: applied[2],
|
|
730
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
731
|
-
variantMatch: applied
|
|
732
|
-
};
|
|
733
|
-
return context;
|
|
734
|
-
}
|
|
735
|
-
async parseToken(raw, alias) {
|
|
736
|
-
if (this.blocked.has(raw))
|
|
737
|
-
return;
|
|
738
|
-
const cacheKey = `${raw}${alias ? ` ${alias}` : ""}`;
|
|
739
|
-
if (this.cache.has(cacheKey))
|
|
740
|
-
return this.cache.get(cacheKey);
|
|
741
|
-
const current = this.config.preprocess.reduce((acc, p) => p(acc) ?? acc, raw);
|
|
742
|
-
if (this.isBlocked(current)) {
|
|
743
|
-
this.blocked.add(raw);
|
|
744
|
-
this.cache.set(cacheKey, null);
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
const variantResults = await this.matchVariants(raw, current);
|
|
748
|
-
if (variantResults.every((i) => !i || this.isBlocked(i[1]))) {
|
|
749
|
-
this.blocked.add(raw);
|
|
750
|
-
this.cache.set(cacheKey, null);
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
const handleVariantResult = async (matched) => {
|
|
754
|
-
const context = this.makeContext(raw, [alias || matched[0], matched[1], matched[2], matched[3]]);
|
|
755
|
-
if (this.config.details)
|
|
756
|
-
context.variants = [...matched[3]];
|
|
757
|
-
const expanded = await this.expandShortcut(context.currentSelector, context);
|
|
758
|
-
const utils = expanded ? await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]) : (await this.parseUtil(context.variantMatch, context))?.flatMap((i) => this.stringifyUtil(i, context)).filter(notNull);
|
|
759
|
-
return utils;
|
|
760
|
-
};
|
|
761
|
-
const result = (await Promise.all(variantResults.map((i) => handleVariantResult(i)))).flat().filter((x) => !!x);
|
|
762
|
-
if (result?.length) {
|
|
763
|
-
this.cache.set(cacheKey, result);
|
|
764
|
-
return result;
|
|
765
|
-
}
|
|
766
|
-
this.cache.set(cacheKey, null);
|
|
767
|
-
}
|
|
768
|
-
async generate(input, options = {}) {
|
|
769
|
-
const {
|
|
770
|
-
id,
|
|
771
|
-
scope,
|
|
772
|
-
preflights = true,
|
|
773
|
-
safelist = true,
|
|
774
|
-
minify = false,
|
|
775
|
-
extendedInfo = false
|
|
776
|
-
} = options;
|
|
777
|
-
const tokens = isString(input) ? await this.applyExtractors(
|
|
778
|
-
input,
|
|
779
|
-
id,
|
|
780
|
-
extendedInfo ? new CountableSet() : /* @__PURE__ */ new Set()
|
|
781
|
-
) : Array.isArray(input) ? new Set(input) : input;
|
|
782
|
-
if (safelist) {
|
|
783
|
-
const safelistContext = {
|
|
784
|
-
generator: this,
|
|
785
|
-
theme: this.config.theme
|
|
786
|
-
};
|
|
787
|
-
this.config.safelist.flatMap((s) => typeof s === "function" ? s(safelistContext) : s).forEach((s) => {
|
|
788
|
-
const trimedS = s.trim();
|
|
789
|
-
if (trimedS && !tokens.has(trimedS))
|
|
790
|
-
tokens.add(trimedS);
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
const nl = minify ? "" : "\n";
|
|
794
|
-
const layerSet = /* @__PURE__ */ new Set([LAYER_DEFAULT]);
|
|
795
|
-
const matched = extendedInfo ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
796
|
-
const sheet = /* @__PURE__ */ new Map();
|
|
797
|
-
let preflightsMap = {};
|
|
798
|
-
const tokenPromises = Array.from(tokens).map(async (raw) => {
|
|
799
|
-
if (matched.has(raw))
|
|
800
|
-
return;
|
|
801
|
-
const payload = await this.parseToken(raw);
|
|
802
|
-
if (payload == null)
|
|
803
|
-
return;
|
|
804
|
-
if (matched instanceof Map) {
|
|
805
|
-
matched.set(raw, {
|
|
806
|
-
data: payload,
|
|
807
|
-
count: isCountableSet(tokens) ? tokens.getCount(raw) : -1
|
|
808
|
-
});
|
|
809
|
-
} else {
|
|
810
|
-
matched.add(raw);
|
|
811
|
-
}
|
|
812
|
-
for (const item of payload) {
|
|
813
|
-
const parent = item[3] || "";
|
|
814
|
-
const layer = item[4]?.layer;
|
|
815
|
-
if (!sheet.has(parent))
|
|
816
|
-
sheet.set(parent, []);
|
|
817
|
-
sheet.get(parent).push(item);
|
|
818
|
-
if (layer)
|
|
819
|
-
layerSet.add(layer);
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
await Promise.all(tokenPromises);
|
|
823
|
-
await (async () => {
|
|
824
|
-
if (!preflights)
|
|
825
|
-
return;
|
|
826
|
-
const preflightContext = {
|
|
827
|
-
generator: this,
|
|
828
|
-
theme: this.config.theme
|
|
829
|
-
};
|
|
830
|
-
const preflightLayerSet = /* @__PURE__ */ new Set([]);
|
|
831
|
-
this.config.preflights.forEach(({ layer = LAYER_PREFLIGHTS }) => {
|
|
832
|
-
layerSet.add(layer);
|
|
833
|
-
preflightLayerSet.add(layer);
|
|
834
|
-
});
|
|
835
|
-
preflightsMap = Object.fromEntries(
|
|
836
|
-
await Promise.all(Array.from(preflightLayerSet).map(
|
|
837
|
-
async (layer) => {
|
|
838
|
-
const preflights2 = await Promise.all(
|
|
839
|
-
this.config.preflights.filter((i) => (i.layer || LAYER_PREFLIGHTS) === layer).map(async (i) => await i.getCSS(preflightContext))
|
|
840
|
-
);
|
|
841
|
-
const css = preflights2.filter(Boolean).join(nl);
|
|
842
|
-
return [layer, css];
|
|
843
|
-
}
|
|
844
|
-
))
|
|
845
|
-
);
|
|
846
|
-
})();
|
|
847
|
-
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
848
|
-
const layerCache = {};
|
|
849
|
-
const outputCssLayers = this.config.outputToCssLayers;
|
|
850
|
-
const getLayerAlias = (layer) => {
|
|
851
|
-
let alias = layer;
|
|
852
|
-
if (typeof outputCssLayers === "object") {
|
|
853
|
-
alias = outputCssLayers.cssLayerName?.(layer);
|
|
854
|
-
}
|
|
855
|
-
return alias === null ? null : alias ?? layer;
|
|
856
|
-
};
|
|
857
|
-
const getLayer = (layer = LAYER_DEFAULT) => {
|
|
858
|
-
if (layerCache[layer])
|
|
859
|
-
return layerCache[layer];
|
|
860
|
-
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
|
|
861
|
-
const size = items.length;
|
|
862
|
-
const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => {
|
|
863
|
-
return a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[5]?.currentSelector?.localeCompare(b[5]?.currentSelector ?? "") || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0;
|
|
864
|
-
}).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
865
|
-
const scopedSelector = selector ? applyScope(selector, scope) : selector;
|
|
866
|
-
return [
|
|
867
|
-
[[scopedSelector ?? "", meta?.sort ?? 0]],
|
|
868
|
-
body,
|
|
869
|
-
!!(variantNoMerge ?? meta?.noMerge)
|
|
870
|
-
];
|
|
871
|
-
});
|
|
872
|
-
if (!sorted.length)
|
|
873
|
-
return void 0;
|
|
874
|
-
const ruleLines = sorted.reverse().map(([selectorSortPair, body, noMerge], idx) => {
|
|
875
|
-
if (!noMerge && this.config.mergeSelectors) {
|
|
876
|
-
for (let i = idx + 1; i < size; i++) {
|
|
877
|
-
const current = sorted[i];
|
|
878
|
-
if (current && !current[2] && (selectorSortPair && current[0] || selectorSortPair == null && current[0] == null) && current[1] === body) {
|
|
879
|
-
if (selectorSortPair && current[0])
|
|
880
|
-
current[0].push(...selectorSortPair);
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
const selectors = selectorSortPair ? uniq(selectorSortPair.sort((a, b) => a[1] - b[1] || a[0]?.localeCompare(b[0] || "") || 0).map((pair) => pair[0]).filter(Boolean)) : [];
|
|
886
|
-
return selectors.length ? `${selectors.join(`,${nl}`)}{${body}}` : body;
|
|
887
|
-
}).filter(Boolean);
|
|
888
|
-
const rules = Array.from(new Set(ruleLines)).reverse().join(nl);
|
|
889
|
-
if (!parent)
|
|
890
|
-
return rules;
|
|
891
|
-
const parents = parent.split(" $$ ");
|
|
892
|
-
return `${parents.join("{")}{${nl}${rules}${nl}${"}".repeat(parents.length)}`;
|
|
893
|
-
}).filter(Boolean).join(nl);
|
|
894
|
-
if (preflights) {
|
|
895
|
-
css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
896
|
-
}
|
|
897
|
-
let alias;
|
|
898
|
-
if (outputCssLayers && css) {
|
|
899
|
-
alias = getLayerAlias(layer);
|
|
900
|
-
if (alias !== null) {
|
|
901
|
-
css = `@layer ${alias}{${nl}${css}${nl}}`;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
const layerMark = minify ? "" : `/* layer: ${layer}${alias && alias !== layer ? `, alias: ${alias}` : ""} */${nl}`;
|
|
905
|
-
return layerCache[layer] = css ? layerMark + css : "";
|
|
906
|
-
};
|
|
907
|
-
const getLayers = (includes = layers, excludes) => {
|
|
908
|
-
const layers2 = includes.filter((i) => !excludes?.includes(i));
|
|
909
|
-
return [
|
|
910
|
-
outputCssLayers && layers2.length > 0 ? `@layer ${layers2.map(getLayerAlias).filter(notNull).join(", ")};` : void 0,
|
|
911
|
-
...layers2.map((i) => getLayer(i) || "")
|
|
912
|
-
].filter(Boolean).join(nl);
|
|
913
|
-
};
|
|
914
|
-
const setLayer = async (layer, callback) => {
|
|
915
|
-
const content = await callback(getLayer(layer));
|
|
916
|
-
layerCache[layer] = content;
|
|
917
|
-
return content;
|
|
918
|
-
};
|
|
919
|
-
return {
|
|
920
|
-
get css() {
|
|
921
|
-
return getLayers();
|
|
922
|
-
},
|
|
923
|
-
layers,
|
|
924
|
-
matched,
|
|
925
|
-
getLayers,
|
|
926
|
-
getLayer,
|
|
927
|
-
setLayer
|
|
928
|
-
};
|
|
929
|
-
}
|
|
930
|
-
async matchVariants(raw, current) {
|
|
931
|
-
const context = {
|
|
932
|
-
rawSelector: raw,
|
|
933
|
-
theme: this.config.theme,
|
|
934
|
-
generator: this
|
|
935
|
-
};
|
|
936
|
-
const match = async (result) => {
|
|
937
|
-
let applied = true;
|
|
938
|
-
const [, , handlers, variants] = result;
|
|
939
|
-
while (applied) {
|
|
940
|
-
applied = false;
|
|
941
|
-
const processed = result[1];
|
|
942
|
-
for (const v of this.config.variants) {
|
|
943
|
-
if (!v.multiPass && variants.has(v))
|
|
944
|
-
continue;
|
|
945
|
-
let handler = await v.match(processed, context);
|
|
946
|
-
if (!handler)
|
|
947
|
-
continue;
|
|
948
|
-
if (isString(handler)) {
|
|
949
|
-
if (handler === processed)
|
|
950
|
-
continue;
|
|
951
|
-
handler = { matcher: handler };
|
|
952
|
-
}
|
|
953
|
-
if (Array.isArray(handler)) {
|
|
954
|
-
if (!handler.length)
|
|
955
|
-
continue;
|
|
956
|
-
if (handler.length === 1) {
|
|
957
|
-
handler = handler[0];
|
|
958
|
-
} else {
|
|
959
|
-
if (v.multiPass)
|
|
960
|
-
throw new Error("multiPass can not be used together with array return variants");
|
|
961
|
-
const clones = handler.map((h) => {
|
|
962
|
-
const _processed = h.matcher ?? processed;
|
|
963
|
-
const _handlers = [h, ...handlers];
|
|
964
|
-
const _variants = new Set(variants);
|
|
965
|
-
_variants.add(v);
|
|
966
|
-
return [result[0], _processed, _handlers, _variants];
|
|
967
|
-
});
|
|
968
|
-
return (await Promise.all(clones.map((c) => match(c)))).flat();
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
result[1] = handler.matcher ?? processed;
|
|
972
|
-
handlers.unshift(handler);
|
|
973
|
-
variants.add(v);
|
|
974
|
-
applied = true;
|
|
975
|
-
break;
|
|
976
|
-
}
|
|
977
|
-
if (!applied)
|
|
978
|
-
break;
|
|
979
|
-
if (handlers.length > 500)
|
|
980
|
-
throw new Error(`Too many variants applied to "${raw}"`);
|
|
981
|
-
}
|
|
982
|
-
return [result];
|
|
983
|
-
};
|
|
984
|
-
return await match([
|
|
985
|
-
raw,
|
|
986
|
-
current || raw,
|
|
987
|
-
[],
|
|
988
|
-
/* @__PURE__ */ new Set()
|
|
989
|
-
]);
|
|
990
|
-
}
|
|
991
|
-
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
992
|
-
const handler = variantHandlers.slice().sort((a, b) => (a.order || 0) - (b.order || 0)).reduceRight(
|
|
993
|
-
(previous, v) => (input) => {
|
|
994
|
-
const entries = v.body?.(input.entries) || input.entries;
|
|
995
|
-
const parents = Array.isArray(v.parent) ? v.parent : [v.parent, void 0];
|
|
996
|
-
const selector = v.selector?.(input.selector, entries);
|
|
997
|
-
return (v.handle ?? defaultVariantHandler)({
|
|
998
|
-
...input,
|
|
999
|
-
entries,
|
|
1000
|
-
selector: selector || input.selector,
|
|
1001
|
-
parent: parents[0] || input.parent,
|
|
1002
|
-
parentOrder: parents[1] || input.parentOrder,
|
|
1003
|
-
layer: v.layer || input.layer,
|
|
1004
|
-
sort: v.sort || input.sort
|
|
1005
|
-
}, previous);
|
|
1006
|
-
},
|
|
1007
|
-
(input) => input
|
|
1008
|
-
);
|
|
1009
|
-
const variantContextResult = handler({
|
|
1010
|
-
prefix: "",
|
|
1011
|
-
selector: toEscapedSelector(raw),
|
|
1012
|
-
pseudo: "",
|
|
1013
|
-
entries: parsed[2]
|
|
1014
|
-
});
|
|
1015
|
-
const { parent, parentOrder } = variantContextResult;
|
|
1016
|
-
if (parent != null && parentOrder != null)
|
|
1017
|
-
this.parentOrders.set(parent, parentOrder);
|
|
1018
|
-
const obj = {
|
|
1019
|
-
selector: [
|
|
1020
|
-
variantContextResult.prefix,
|
|
1021
|
-
variantContextResult.selector,
|
|
1022
|
-
variantContextResult.pseudo
|
|
1023
|
-
].join(""),
|
|
1024
|
-
entries: variantContextResult.entries,
|
|
1025
|
-
parent,
|
|
1026
|
-
layer: variantContextResult.layer,
|
|
1027
|
-
sort: variantContextResult.sort,
|
|
1028
|
-
noMerge: variantContextResult.noMerge
|
|
1029
|
-
};
|
|
1030
|
-
return this.config.postprocess.reduce(
|
|
1031
|
-
(utilities, p) => {
|
|
1032
|
-
const result = [];
|
|
1033
|
-
for (const util of utilities) {
|
|
1034
|
-
const processed = p(util);
|
|
1035
|
-
if (Array.isArray(processed)) {
|
|
1036
|
-
result.push(...processed.filter(notNull));
|
|
1037
|
-
} else {
|
|
1038
|
-
result.push(processed || util);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
return result;
|
|
1042
|
-
},
|
|
1043
|
-
[obj]
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
constructCustomCSS(context, body, overrideSelector) {
|
|
1047
|
-
const normalizedBody = normalizeCSSEntries(body);
|
|
1048
|
-
if (isString(normalizedBody))
|
|
1049
|
-
return normalizedBody;
|
|
1050
|
-
return this.applyVariants([0, overrideSelector || context.rawSelector, normalizedBody, void 0, context.variantHandlers]).map(({ selector, entries, parent }) => {
|
|
1051
|
-
const cssBody = `${selector}{${entriesToCss(entries)}}`;
|
|
1052
|
-
if (parent)
|
|
1053
|
-
return `${parent}{${cssBody}}`;
|
|
1054
|
-
return cssBody;
|
|
1055
|
-
}).join("");
|
|
1056
|
-
}
|
|
1057
|
-
async parseUtil(input, context, internal = false, shortcutPrefix) {
|
|
1058
|
-
const variantResults = isString(input) ? await this.matchVariants(input) : [input];
|
|
1059
|
-
const parse = async ([raw, processed, variantHandlers]) => {
|
|
1060
|
-
if (this.config.details)
|
|
1061
|
-
context.rules = context.rules ?? [];
|
|
1062
|
-
const scopeContext = {
|
|
1063
|
-
...context,
|
|
1064
|
-
variantHandlers
|
|
1065
|
-
};
|
|
1066
|
-
const staticMatch = this.config.rulesStaticMap[processed];
|
|
1067
|
-
if (staticMatch) {
|
|
1068
|
-
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
1069
|
-
return this.resolveCSSResult(raw, staticMatch[1], staticMatch, scopeContext);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
for (const rule of this.config.rulesDynamic) {
|
|
1073
|
-
const [matcher, handler, meta] = rule;
|
|
1074
|
-
if (meta?.internal && !internal)
|
|
1075
|
-
continue;
|
|
1076
|
-
let unprefixed = processed;
|
|
1077
|
-
if (meta?.prefix) {
|
|
1078
|
-
const prefixes = toArray(meta.prefix);
|
|
1079
|
-
if (shortcutPrefix) {
|
|
1080
|
-
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1081
|
-
if (!prefixes.some((i) => shortcutPrefixes.includes(i)))
|
|
1082
|
-
continue;
|
|
1083
|
-
} else {
|
|
1084
|
-
const prefix = prefixes.find((i) => processed.startsWith(i));
|
|
1085
|
-
if (prefix == null)
|
|
1086
|
-
continue;
|
|
1087
|
-
unprefixed = processed.slice(prefix.length);
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
const match = unprefixed.match(matcher);
|
|
1091
|
-
if (!match)
|
|
1092
|
-
continue;
|
|
1093
|
-
let result = await handler(match, scopeContext);
|
|
1094
|
-
if (!result)
|
|
1095
|
-
continue;
|
|
1096
|
-
if (typeof result !== "string") {
|
|
1097
|
-
if (Symbol.asyncIterator in result) {
|
|
1098
|
-
const entries = [];
|
|
1099
|
-
for await (const r of result) {
|
|
1100
|
-
if (r)
|
|
1101
|
-
entries.push(r);
|
|
1102
|
-
}
|
|
1103
|
-
result = entries;
|
|
1104
|
-
} else if (Symbol.iterator in result && !Array.isArray(result)) {
|
|
1105
|
-
result = Array.from(result).filter(notNull);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
const resolvedResult = this.resolveCSSResult(raw, result, rule, scopeContext);
|
|
1109
|
-
if (resolvedResult) {
|
|
1110
|
-
return resolvedResult;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
};
|
|
1114
|
-
const parsed = (await Promise.all(variantResults.map((i) => parse(i)))).flat().filter((x) => !!x);
|
|
1115
|
-
if (!parsed.length)
|
|
1116
|
-
return void 0;
|
|
1117
|
-
return parsed;
|
|
1118
|
-
}
|
|
1119
|
-
resolveCSSResult = (raw, result, rule, context) => {
|
|
1120
|
-
const entries = normalizeCSSValues(result).filter((i) => i.length);
|
|
1121
|
-
if (entries.length) {
|
|
1122
|
-
if (this.config.details) {
|
|
1123
|
-
context.rules.push(rule);
|
|
1124
|
-
}
|
|
1125
|
-
context.generator.activatedRules.add(rule);
|
|
1126
|
-
const meta = rule[2];
|
|
1127
|
-
return entries.map((css) => {
|
|
1128
|
-
if (isString(css))
|
|
1129
|
-
return [meta.__index, css, meta];
|
|
1130
|
-
let variants = context.variantHandlers;
|
|
1131
|
-
let entryMeta = meta;
|
|
1132
|
-
for (const entry of css) {
|
|
1133
|
-
if (entry[0] === symbols.variants) {
|
|
1134
|
-
if (typeof entry[1] === "function") {
|
|
1135
|
-
variants = entry[1](variants) || variants;
|
|
1136
|
-
} else {
|
|
1137
|
-
variants = [
|
|
1138
|
-
...toArray(entry[1]),
|
|
1139
|
-
...variants
|
|
1140
|
-
];
|
|
1141
|
-
}
|
|
1142
|
-
} else if (entry[0] === symbols.parent) {
|
|
1143
|
-
variants = [
|
|
1144
|
-
{ parent: entry[1] },
|
|
1145
|
-
...variants
|
|
1146
|
-
];
|
|
1147
|
-
} else if (entry[0] === symbols.selector) {
|
|
1148
|
-
variants = [
|
|
1149
|
-
{ selector: entry[1] },
|
|
1150
|
-
...variants
|
|
1151
|
-
];
|
|
1152
|
-
} else if (entry[0] === symbols.layer) {
|
|
1153
|
-
variants = [
|
|
1154
|
-
{ layer: entry[1] },
|
|
1155
|
-
...variants
|
|
1156
|
-
];
|
|
1157
|
-
} else if (entry[0] === symbols.sort) {
|
|
1158
|
-
entryMeta = {
|
|
1159
|
-
...entryMeta,
|
|
1160
|
-
sort: entry[1]
|
|
1161
|
-
};
|
|
1162
|
-
} else if (entry[0] === symbols.noMerge) {
|
|
1163
|
-
entryMeta = {
|
|
1164
|
-
...entryMeta,
|
|
1165
|
-
noMerge: entry[1]
|
|
1166
|
-
};
|
|
1167
|
-
} else if (entry[0] === symbols.body) {
|
|
1168
|
-
entry[0] = VirtualKey;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
return [meta.__index, raw, css, entryMeta, variants];
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
};
|
|
1175
|
-
stringifyUtil(parsed, context) {
|
|
1176
|
-
if (!parsed)
|
|
1177
|
-
return;
|
|
1178
|
-
if (isRawUtil(parsed))
|
|
1179
|
-
return [[parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0, void 0]];
|
|
1180
|
-
const utilities = this.applyVariants(parsed);
|
|
1181
|
-
const result = [];
|
|
1182
|
-
for (const util of utilities) {
|
|
1183
|
-
const {
|
|
1184
|
-
selector,
|
|
1185
|
-
entries,
|
|
1186
|
-
parent,
|
|
1187
|
-
layer: variantLayer,
|
|
1188
|
-
sort: variantSort,
|
|
1189
|
-
noMerge
|
|
1190
|
-
} = util;
|
|
1191
|
-
const body = entriesToCss(entries);
|
|
1192
|
-
if (!body)
|
|
1193
|
-
continue;
|
|
1194
|
-
const { layer: metaLayer, sort: metaSort, ...meta } = parsed[3] ?? {};
|
|
1195
|
-
const ruleMeta = {
|
|
1196
|
-
...meta,
|
|
1197
|
-
layer: variantLayer ?? metaLayer,
|
|
1198
|
-
sort: variantSort ?? metaSort
|
|
1199
|
-
};
|
|
1200
|
-
result.push([parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge]);
|
|
1201
|
-
}
|
|
1202
|
-
return result;
|
|
1203
|
-
}
|
|
1204
|
-
async expandShortcut(input, context, depth = 5) {
|
|
1205
|
-
if (depth === 0)
|
|
1206
|
-
return;
|
|
1207
|
-
const recordShortcut = this.config.details ? (s) => {
|
|
1208
|
-
context.shortcuts = context.shortcuts ?? [];
|
|
1209
|
-
context.shortcuts.push(s);
|
|
1210
|
-
} : noop;
|
|
1211
|
-
let meta;
|
|
1212
|
-
let result;
|
|
1213
|
-
let stringResult;
|
|
1214
|
-
let inlineResult;
|
|
1215
|
-
for (const s of this.config.shortcuts) {
|
|
1216
|
-
let unprefixed = input;
|
|
1217
|
-
if (s[2]?.prefix) {
|
|
1218
|
-
const prefixes = toArray(s[2].prefix);
|
|
1219
|
-
const prefix = prefixes.find((i) => input.startsWith(i));
|
|
1220
|
-
if (prefix == null)
|
|
1221
|
-
continue;
|
|
1222
|
-
unprefixed = input.slice(prefix.length);
|
|
1223
|
-
}
|
|
1224
|
-
if (isStaticShortcut(s)) {
|
|
1225
|
-
if (s[0] === unprefixed) {
|
|
1226
|
-
meta = meta || s[2];
|
|
1227
|
-
result = s[1];
|
|
1228
|
-
recordShortcut(s);
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
} else {
|
|
1232
|
-
const match = unprefixed.match(s[0]);
|
|
1233
|
-
if (match)
|
|
1234
|
-
result = s[1](match, context);
|
|
1235
|
-
if (result) {
|
|
1236
|
-
meta = meta || s[2];
|
|
1237
|
-
recordShortcut(s);
|
|
1238
|
-
break;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
if (result) {
|
|
1243
|
-
stringResult = uniq(toArray(result).filter(isString).map((s) => expandVariantGroup(s.trim()).split(/\s+/g)).flat());
|
|
1244
|
-
inlineResult = toArray(result).filter((i) => !isString(i)).map((i) => ({ handles: [], value: i }));
|
|
1245
|
-
}
|
|
1246
|
-
if (!result) {
|
|
1247
|
-
const matched = isString(input) ? await this.matchVariants(input) : [input];
|
|
1248
|
-
for (const match of matched) {
|
|
1249
|
-
const [raw, inputWithoutVariant, handles] = match;
|
|
1250
|
-
if (raw !== inputWithoutVariant) {
|
|
1251
|
-
const expanded = await this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
1252
|
-
if (expanded) {
|
|
1253
|
-
stringResult = expanded[0].filter(isString).map((item) => raw.replace(inputWithoutVariant, item));
|
|
1254
|
-
inlineResult = expanded[0].filter((i) => !isString(i)).map((item) => {
|
|
1255
|
-
return { handles: [...item.handles, ...handles], value: item.value };
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
if (!stringResult?.length && !inlineResult?.length)
|
|
1262
|
-
return;
|
|
1263
|
-
return [
|
|
1264
|
-
[
|
|
1265
|
-
await Promise.all(toArray(stringResult).map(async (s) => (await this.expandShortcut(s, context, depth - 1))?.[0] || [s])),
|
|
1266
|
-
inlineResult
|
|
1267
|
-
].flat(2).filter((x) => !!x),
|
|
1268
|
-
meta
|
|
1269
|
-
];
|
|
1270
|
-
}
|
|
1271
|
-
async stringifyShortcuts(parent, context, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
1272
|
-
const layerMap = new BetterMap();
|
|
1273
|
-
const parsed = (await Promise.all(uniq(expanded).map(async (i) => {
|
|
1274
|
-
const result = isString(i) ? await this.parseUtil(i, context, true, meta.prefix) : [[Number.POSITIVE_INFINITY, "{inline}", normalizeCSSEntries(i.value), void 0, i.handles]];
|
|
1275
|
-
if (!result && this.config.warn)
|
|
1276
|
-
warnOnce(`unmatched utility "${i}" in shortcut "${parent[1]}"`);
|
|
1277
|
-
return result || [];
|
|
1278
|
-
}))).flat(1).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
1279
|
-
const [raw, , parentVariants] = parent;
|
|
1280
|
-
const rawStringifiedUtil = [];
|
|
1281
|
-
for (const item of parsed) {
|
|
1282
|
-
if (isRawUtil(item)) {
|
|
1283
|
-
rawStringifiedUtil.push([item[0], void 0, item[1], void 0, item[2], context, void 0]);
|
|
1284
|
-
continue;
|
|
1285
|
-
}
|
|
1286
|
-
const isNoMerge = Object.fromEntries(item[2])[symbols.shortcutsNoMerge];
|
|
1287
|
-
const variants = [...item[4], ...!isNoMerge ? parentVariants : []];
|
|
1288
|
-
for (const { selector, entries, parent: parent2, sort, noMerge, layer } of this.applyVariants(item, variants, raw)) {
|
|
1289
|
-
const selectorMap = layerMap.getFallback(layer ?? meta.layer, new TwoKeyMap());
|
|
1290
|
-
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
1291
|
-
mapItem[0].push([entries, !!(noMerge ?? item[3]?.noMerge), sort ?? 0]);
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
return rawStringifiedUtil.concat(layerMap.flatMap(
|
|
1295
|
-
(selectorMap, layer) => selectorMap.map(([e2, index], selector, joinedParents) => {
|
|
1296
|
-
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
1297
|
-
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
1298
|
-
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
1299
|
-
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
1300
|
-
const body = entriesToCss(entries);
|
|
1301
|
-
if (body)
|
|
1302
|
-
return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort, layer }, context, void 0];
|
|
1303
|
-
return void 0;
|
|
1304
|
-
});
|
|
1305
|
-
};
|
|
1306
|
-
const merges = [
|
|
1307
|
-
[e2.filter(([, noMerge]) => noMerge).map(([entries, , sort]) => [entries, sort]), true],
|
|
1308
|
-
[e2.filter(([, noMerge]) => !noMerge).map(([entries, , sort]) => [entries, sort]), false]
|
|
1309
|
-
];
|
|
1310
|
-
return merges.map(([e3, noMerge]) => [
|
|
1311
|
-
...stringify(false, noMerge, e3.filter(([entries]) => entries.some((entry) => entry[0] === symbols.shortcutsNoMerge))),
|
|
1312
|
-
...stringify(true, noMerge, e3.filter(([entries]) => entries.every((entry) => entry[0] !== symbols.shortcutsNoMerge)))
|
|
1313
|
-
]);
|
|
1314
|
-
}).flat(2).filter(Boolean)
|
|
1315
|
-
));
|
|
1316
|
-
}
|
|
1317
|
-
isBlocked(raw) {
|
|
1318
|
-
return !raw || this.config.blocklist.map((e2) => Array.isArray(e2) ? e2[0] : e2).some((e2) => typeof e2 === "function" ? e2(raw) : isString(e2) ? e2 === raw : e2.test(raw));
|
|
1319
|
-
}
|
|
1320
|
-
getBlocked(raw) {
|
|
1321
|
-
const rule = this.config.blocklist.find((e2) => {
|
|
1322
|
-
const v = Array.isArray(e2) ? e2[0] : e2;
|
|
1323
|
-
return typeof v === "function" ? v(raw) : isString(v) ? v === raw : v.test(raw);
|
|
1324
|
-
});
|
|
1325
|
-
return rule ? Array.isArray(rule) ? rule : [rule, void 0] : void 0;
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
class UnoGenerator extends UnoGeneratorInternal {
|
|
1329
|
-
/**
|
|
1330
|
-
* @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
|
|
1331
|
-
*/
|
|
1332
|
-
constructor(userConfig = {}, defaults = {}) {
|
|
1333
|
-
super(userConfig, defaults);
|
|
1334
|
-
console.warn("`new UnoGenerator()` is deprecated, please use `createGenerator()` instead");
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
1223
|
async function createGenerator(config, defaults) {
|
|
1338
|
-
|
|
1224
|
+
return await UnoGeneratorInternal.create(config, defaults);
|
|
1339
1225
|
}
|
|
1340
1226
|
const regexScopePlaceholder = /\s\$\$\s+/g;
|
|
1341
1227
|
function hasScopePlaceholder(css) {
|
|
1342
|
-
|
|
1228
|
+
return regexScopePlaceholder.test(css);
|
|
1343
1229
|
}
|
|
1344
1230
|
function applyScope(css, scope) {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
else
|
|
1348
|
-
return scope ? `${scope} ${css}` : css;
|
|
1231
|
+
if (hasScopePlaceholder(css)) return css.replace(regexScopePlaceholder, scope ? ` ${scope} ` : " ");
|
|
1232
|
+
else return scope ? `${scope} ${css}` : css;
|
|
1349
1233
|
}
|
|
1350
1234
|
const attributifyRe = /^\[(.+?)(~?=)"(.*)"\]$/;
|
|
1351
1235
|
function toEscapedSelector(raw) {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
return `.${e(raw)}`;
|
|
1236
|
+
if (attributifyRe.test(raw)) return raw.replace(attributifyRe, (_, n, s, i) => `[${e(n)}${s}"${e(i)}"]`);
|
|
1237
|
+
return `.${e(raw)}`;
|
|
1355
1238
|
}
|
|
1356
1239
|
function defaultVariantHandler(input, next) {
|
|
1357
|
-
|
|
1240
|
+
return next(input);
|
|
1358
1241
|
}
|
|
1359
1242
|
|
|
1360
|
-
|
|
1243
|
+
//#endregion
|
|
1244
|
+
export { BetterMap, CountableSet, DEFAULT_LAYERS, LAYER_DEFAULT, LAYER_IMPORTS, LAYER_PREFLIGHTS, LAYER_SHORTCUTS, TwoKeyMap, UnoGenerator, VirtualKey, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createNanoEvents, cssIdRE, defaultSplitRE, definePreset, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isCountableSet, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, symbols, toArray, toEscapedSelector, uniq, uniqueBy, validateFilterRE, warnOnce, withLayer };
|