@unocss/core 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.js → index.cjs} +106 -170
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +73 -128
- package/package.json +5 -5
|
@@ -1,47 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
3
|
-
var __export = (target, all) => {
|
|
4
|
-
__markAsModule(target);
|
|
5
|
-
for (var name in all)
|
|
6
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
-
};
|
|
1
|
+
'use strict';
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
__export(exports, {
|
|
11
|
-
BetterMap: () => BetterMap,
|
|
12
|
-
TwoKeyMap: () => TwoKeyMap,
|
|
13
|
-
UnoGenerator: () => UnoGenerator,
|
|
14
|
-
attributifyRE: () => attributifyRE,
|
|
15
|
-
createGenerator: () => createGenerator,
|
|
16
|
-
e: () => e,
|
|
17
|
-
entriesToCss: () => entriesToCss,
|
|
18
|
-
escapeRegExp: () => escapeRegExp,
|
|
19
|
-
escapeSelector: () => escapeSelector,
|
|
20
|
-
expandVariantGroup: () => expandVariantGroup,
|
|
21
|
-
extractorSplit: () => extractorSplit,
|
|
22
|
-
hasScopePlaceholder: () => hasScopePlaceholder,
|
|
23
|
-
hex2rgba: () => hex2rgba,
|
|
24
|
-
isAttributifySelector: () => isAttributifySelector,
|
|
25
|
-
isObject: () => isObject,
|
|
26
|
-
isRawUtil: () => isRawUtil,
|
|
27
|
-
isStaticRule: () => isStaticRule,
|
|
28
|
-
isStaticShortcut: () => isStaticShortcut,
|
|
29
|
-
isValidSelector: () => isValidSelector,
|
|
30
|
-
mergeDeep: () => mergeDeep,
|
|
31
|
-
mergeSet: () => mergeSet,
|
|
32
|
-
normalizeCSSEntries: () => normalizeCSSEntries,
|
|
33
|
-
normalizeCSSValues: () => normalizeCSSValues,
|
|
34
|
-
normalizeVariant: () => normalizeVariant,
|
|
35
|
-
notNull: () => notNull,
|
|
36
|
-
regexClassGroup: () => regexClassGroup,
|
|
37
|
-
toArray: () => toArray,
|
|
38
|
-
uniq: () => uniq,
|
|
39
|
-
validateFilterRE: () => validateFilterRE,
|
|
40
|
-
warnOnce: () => warnOnce,
|
|
41
|
-
withLayer: () => withLayer
|
|
42
|
-
});
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
43
4
|
|
|
44
|
-
// src/utils/escape.ts
|
|
45
5
|
function escapeRegExp(string) {
|
|
46
6
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
47
7
|
}
|
|
@@ -77,13 +37,36 @@ function escapeSelector(str) {
|
|
|
77
37
|
}
|
|
78
38
|
return result;
|
|
79
39
|
}
|
|
80
|
-
|
|
40
|
+
const e = escapeSelector;
|
|
81
41
|
|
|
82
|
-
|
|
42
|
+
function normalizeCSSEntries(obj) {
|
|
43
|
+
return (!Array.isArray(obj) ? Object.entries(obj) : obj).filter((i) => i[1] != null);
|
|
44
|
+
}
|
|
45
|
+
function normalizeCSSValues(obj) {
|
|
46
|
+
if (Array.isArray(obj)) {
|
|
47
|
+
if (obj.find((i) => !Array.isArray(i) || Array.isArray(i[0])))
|
|
48
|
+
return obj.map((i) => normalizeCSSEntries(i));
|
|
49
|
+
else
|
|
50
|
+
return [obj];
|
|
51
|
+
} else {
|
|
52
|
+
return [normalizeCSSEntries(obj)];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function clearIdenticalEntries(entry) {
|
|
56
|
+
return entry.filter(([k, v], idx) => {
|
|
57
|
+
if (k.startsWith("$$"))
|
|
58
|
+
return false;
|
|
59
|
+
for (let i = idx - 1; i >= 0; i--) {
|
|
60
|
+
if (entry[i][0] === k && entry[i][1] === v)
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
83
66
|
function entriesToCss(arr) {
|
|
84
67
|
if (arr == null)
|
|
85
68
|
return "";
|
|
86
|
-
return arr.map(([key, value]) => value != null ? `${key}:${value};` : void 0).filter(Boolean).join("");
|
|
69
|
+
return clearIdenticalEntries(arr).map(([key, value]) => value != null ? `${key}:${value};` : void 0).filter(Boolean).join("");
|
|
87
70
|
}
|
|
88
71
|
function isObject(item) {
|
|
89
72
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
@@ -117,7 +100,6 @@ function isStaticShortcut(sc) {
|
|
|
117
100
|
return typeof sc[0] === "string";
|
|
118
101
|
}
|
|
119
102
|
|
|
120
|
-
// src/utils/basic.ts
|
|
121
103
|
function toArray(value = []) {
|
|
122
104
|
return Array.isArray(value) ? value : [value];
|
|
123
105
|
}
|
|
@@ -129,8 +111,7 @@ function mergeSet(target, append) {
|
|
|
129
111
|
return target;
|
|
130
112
|
}
|
|
131
113
|
|
|
132
|
-
|
|
133
|
-
var hexRE = /^#?([\da-f]+)$/i;
|
|
114
|
+
const hexRE = /^#?([\da-f]+)$/i;
|
|
134
115
|
function hex2rgba(hex = "") {
|
|
135
116
|
const [, body] = hex.match(hexRE) || [];
|
|
136
117
|
if (!body)
|
|
@@ -152,9 +133,8 @@ function hex2rgba(hex = "") {
|
|
|
152
133
|
}
|
|
153
134
|
}
|
|
154
135
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var validateFilterRE = /[a-z?]/;
|
|
136
|
+
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
137
|
+
const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
|
|
158
138
|
function isAttributifySelector(selector) {
|
|
159
139
|
return selector.match(attributifyRE);
|
|
160
140
|
}
|
|
@@ -171,10 +151,9 @@ function notNull(value) {
|
|
|
171
151
|
return value != null;
|
|
172
152
|
}
|
|
173
153
|
|
|
174
|
-
|
|
175
|
-
var TwoKeyMap = class {
|
|
154
|
+
class TwoKeyMap {
|
|
176
155
|
constructor() {
|
|
177
|
-
this._map = new Map();
|
|
156
|
+
this._map = /* @__PURE__ */ new Map();
|
|
178
157
|
}
|
|
179
158
|
get(key1, key2) {
|
|
180
159
|
const m2 = this._map.get(key1);
|
|
@@ -184,7 +163,7 @@ var TwoKeyMap = class {
|
|
|
184
163
|
getFallback(key1, key2, fallback) {
|
|
185
164
|
let m2 = this._map.get(key1);
|
|
186
165
|
if (!m2) {
|
|
187
|
-
m2 = new Map();
|
|
166
|
+
m2 = /* @__PURE__ */ new Map();
|
|
188
167
|
this._map.set(key1, m2);
|
|
189
168
|
}
|
|
190
169
|
if (!m2.has(key2))
|
|
@@ -194,19 +173,17 @@ var TwoKeyMap = class {
|
|
|
194
173
|
set(key1, key2, value) {
|
|
195
174
|
let m2 = this._map.get(key1);
|
|
196
175
|
if (!m2) {
|
|
197
|
-
m2 = new Map();
|
|
176
|
+
m2 = /* @__PURE__ */ new Map();
|
|
198
177
|
this._map.set(key1, m2);
|
|
199
178
|
}
|
|
200
179
|
m2.set(key2, value);
|
|
201
180
|
return this;
|
|
202
181
|
}
|
|
203
182
|
has(key1, key2) {
|
|
204
|
-
|
|
205
|
-
return (_a = this._map.get(key1)) == null ? void 0 : _a.has(key2);
|
|
183
|
+
return this._map.get(key1)?.has(key2);
|
|
206
184
|
}
|
|
207
185
|
delete(key1, key2) {
|
|
208
|
-
|
|
209
|
-
return ((_a = this._map.get(key1)) == null ? void 0 : _a.delete(key2)) || false;
|
|
186
|
+
return this._map.get(key1)?.delete(key2) || false;
|
|
210
187
|
}
|
|
211
188
|
deleteTop(key1) {
|
|
212
189
|
return this._map.delete(key1);
|
|
@@ -216,8 +193,8 @@ var TwoKeyMap = class {
|
|
|
216
193
|
return fn(v, k1, k2);
|
|
217
194
|
}));
|
|
218
195
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
196
|
+
}
|
|
197
|
+
class BetterMap extends Map {
|
|
221
198
|
map(mapFn) {
|
|
222
199
|
const result = [];
|
|
223
200
|
this.forEach((v, k) => {
|
|
@@ -225,9 +202,8 @@ var BetterMap = class extends Map {
|
|
|
225
202
|
});
|
|
226
203
|
return result;
|
|
227
204
|
}
|
|
228
|
-
}
|
|
205
|
+
}
|
|
229
206
|
|
|
230
|
-
// src/utils/layer.ts
|
|
231
207
|
function withLayer(layer, rules) {
|
|
232
208
|
rules.forEach((r) => {
|
|
233
209
|
if (!r[2])
|
|
@@ -238,8 +214,7 @@ function withLayer(layer, rules) {
|
|
|
238
214
|
return rules;
|
|
239
215
|
}
|
|
240
216
|
|
|
241
|
-
|
|
242
|
-
var regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
217
|
+
const regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
243
218
|
function expandVariantGroup(str) {
|
|
244
219
|
const replaces = [];
|
|
245
220
|
let match;
|
|
@@ -257,8 +232,7 @@ function expandVariantGroup(str) {
|
|
|
257
232
|
return result;
|
|
258
233
|
}
|
|
259
234
|
|
|
260
|
-
|
|
261
|
-
var warned = new Set();
|
|
235
|
+
const warned = /* @__PURE__ */ new Set();
|
|
262
236
|
function warnOnce(msg) {
|
|
263
237
|
if (warned.has(msg))
|
|
264
238
|
return;
|
|
@@ -266,8 +240,7 @@ function warnOnce(msg) {
|
|
|
266
240
|
warned.add(msg);
|
|
267
241
|
}
|
|
268
242
|
|
|
269
|
-
|
|
270
|
-
var extractorSplit = {
|
|
243
|
+
const extractorSplit = {
|
|
271
244
|
name: "split",
|
|
272
245
|
order: 0,
|
|
273
246
|
extract({ code }) {
|
|
@@ -275,7 +248,6 @@ var extractorSplit = {
|
|
|
275
248
|
}
|
|
276
249
|
};
|
|
277
250
|
|
|
278
|
-
// src/config.ts
|
|
279
251
|
function resolveShortcuts(shortcuts) {
|
|
280
252
|
return toArray(shortcuts).flatMap((s) => {
|
|
281
253
|
if (Array.isArray(s))
|
|
@@ -283,13 +255,13 @@ function resolveShortcuts(shortcuts) {
|
|
|
283
255
|
return Object.entries(s);
|
|
284
256
|
});
|
|
285
257
|
}
|
|
286
|
-
|
|
258
|
+
const defaultLayers = {
|
|
287
259
|
shortcuts: -1,
|
|
288
260
|
default: 0
|
|
289
261
|
};
|
|
290
262
|
function resolveConfig(userConfig = {}, defaults = {}) {
|
|
291
263
|
const config = Object.assign({}, defaults, userConfig);
|
|
292
|
-
const rawPresets = config.presets || [];
|
|
264
|
+
const rawPresets = (config.presets || []).flatMap(toArray);
|
|
293
265
|
const sortedPresets = [
|
|
294
266
|
...rawPresets.filter((p) => p.enforce === "pre"),
|
|
295
267
|
...rawPresets.filter((p) => !p.enforce),
|
|
@@ -324,9 +296,9 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
324
296
|
warn: true,
|
|
325
297
|
blocklist: [],
|
|
326
298
|
safelist: [],
|
|
327
|
-
presets: [],
|
|
328
299
|
sortLayers: (layers2) => layers2,
|
|
329
300
|
...config,
|
|
301
|
+
presets: sortedPresets,
|
|
330
302
|
envMode: config.envMode || "build",
|
|
331
303
|
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
332
304
|
layers,
|
|
@@ -341,18 +313,16 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
341
313
|
};
|
|
342
314
|
}
|
|
343
315
|
|
|
344
|
-
|
|
345
|
-
var version = "0.14.0";
|
|
316
|
+
const version = "0.15.0";
|
|
346
317
|
|
|
347
|
-
|
|
348
|
-
var UnoGenerator = class {
|
|
318
|
+
class UnoGenerator {
|
|
349
319
|
constructor(userConfig = {}, defaults = {}) {
|
|
350
320
|
this.userConfig = userConfig;
|
|
351
321
|
this.defaults = defaults;
|
|
352
322
|
this.version = version;
|
|
353
|
-
this._cache = new Map();
|
|
354
|
-
this.blocked = new Set();
|
|
355
|
-
this.parentOrders = new Map();
|
|
323
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
324
|
+
this.blocked = /* @__PURE__ */ new Set();
|
|
325
|
+
this.parentOrders = /* @__PURE__ */ new Map();
|
|
356
326
|
this.config = resolveConfig(userConfig, defaults);
|
|
357
327
|
}
|
|
358
328
|
setConfig(userConfig, defaults) {
|
|
@@ -366,7 +336,7 @@ var UnoGenerator = class {
|
|
|
366
336
|
this.parentOrders.clear();
|
|
367
337
|
this._cache.clear();
|
|
368
338
|
}
|
|
369
|
-
async applyExtractors(code, id, set = new Set()) {
|
|
339
|
+
async applyExtractors(code, id, set = /* @__PURE__ */ new Set()) {
|
|
370
340
|
const context = {
|
|
371
341
|
get original() {
|
|
372
342
|
return code;
|
|
@@ -376,7 +346,7 @@ var UnoGenerator = class {
|
|
|
376
346
|
};
|
|
377
347
|
for (const extractor of this.config.extractors) {
|
|
378
348
|
const result = await extractor.extract(context);
|
|
379
|
-
result
|
|
349
|
+
result?.forEach((t) => set.add(t));
|
|
380
350
|
}
|
|
381
351
|
return set;
|
|
382
352
|
}
|
|
@@ -391,11 +361,10 @@ var UnoGenerator = class {
|
|
|
391
361
|
if (safelist)
|
|
392
362
|
this.config.safelist.forEach((s) => tokens.add(s));
|
|
393
363
|
const nl = minify ? "" : "\n";
|
|
394
|
-
const layerSet = new Set(["default"]);
|
|
395
|
-
const matched = new Set();
|
|
396
|
-
const sheet = new Map();
|
|
364
|
+
const layerSet = /* @__PURE__ */ new Set(["default"]);
|
|
365
|
+
const matched = /* @__PURE__ */ new Set();
|
|
366
|
+
const sheet = /* @__PURE__ */ new Map();
|
|
397
367
|
const hit = (raw, payload) => {
|
|
398
|
-
var _a;
|
|
399
368
|
this._cache.set(raw, payload);
|
|
400
369
|
matched.add(raw);
|
|
401
370
|
for (const item of payload) {
|
|
@@ -403,7 +372,7 @@ var UnoGenerator = class {
|
|
|
403
372
|
if (!sheet.has(parent))
|
|
404
373
|
sheet.set(parent, []);
|
|
405
374
|
sheet.get(parent).push(item);
|
|
406
|
-
if (
|
|
375
|
+
if (item[4]?.layer)
|
|
407
376
|
layerSet.add(item[4].layer);
|
|
408
377
|
}
|
|
409
378
|
};
|
|
@@ -412,7 +381,6 @@ var UnoGenerator = class {
|
|
|
412
381
|
this._cache.set(raw, null);
|
|
413
382
|
};
|
|
414
383
|
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
415
|
-
var _a;
|
|
416
384
|
if (matched.has(raw) || this.blocked.has(raw))
|
|
417
385
|
return;
|
|
418
386
|
if (this._cache.has(raw)) {
|
|
@@ -440,11 +408,11 @@ var UnoGenerator = class {
|
|
|
440
408
|
const expanded = this.expandShortcut(applied[1], context);
|
|
441
409
|
if (expanded) {
|
|
442
410
|
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
443
|
-
if (utils
|
|
411
|
+
if (utils?.length)
|
|
444
412
|
return hit(raw, utils);
|
|
445
413
|
} else {
|
|
446
|
-
const utils = (
|
|
447
|
-
if (utils
|
|
414
|
+
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
415
|
+
if (utils?.length)
|
|
448
416
|
return hit(raw, utils);
|
|
449
417
|
}
|
|
450
418
|
this._cache.set(raw, null);
|
|
@@ -456,22 +424,13 @@ var UnoGenerator = class {
|
|
|
456
424
|
});
|
|
457
425
|
}
|
|
458
426
|
const layerCache = {};
|
|
459
|
-
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) =>
|
|
460
|
-
var _a, _b;
|
|
461
|
-
return ((_a = this.config.layers[a]) != null ? _a : 0) - ((_b = this.config.layers[b]) != null ? _b : 0) || a.localeCompare(b);
|
|
462
|
-
}));
|
|
427
|
+
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
463
428
|
const getLayer = (layer) => {
|
|
464
429
|
if (layerCache[layer])
|
|
465
430
|
return layerCache[layer];
|
|
466
431
|
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) || 0) - (this.parentOrders.get(b[0]) || 0)).map(([parent, items]) => {
|
|
467
432
|
const size = items.length;
|
|
468
|
-
const sorted = items.filter((i) =>
|
|
469
|
-
var _a;
|
|
470
|
-
return (((_a = i[4]) == null ? void 0 : _a.layer) || "default") === layer;
|
|
471
|
-
}).sort((a, b) => {
|
|
472
|
-
var _a;
|
|
473
|
-
return a[0] - b[0] || ((_a = a[1]) == null ? void 0 : _a.localeCompare(b[1] || "")) || 0;
|
|
474
|
-
}).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
433
|
+
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
475
434
|
if (!sorted.length)
|
|
476
435
|
return void 0;
|
|
477
436
|
const rules = sorted.reverse().map(([selector, body], idx) => {
|
|
@@ -497,7 +456,7 @@ var UnoGenerator = class {
|
|
|
497
456
|
return layerCache[layer] = !minify && css ? `/* layer: ${layer} */${nl}${css}` : css;
|
|
498
457
|
};
|
|
499
458
|
const getLayers = (includes = layers, excludes) => {
|
|
500
|
-
return includes.filter((i) => !
|
|
459
|
+
return includes.filter((i) => !excludes?.includes(i)).map((i) => getLayer(i) || "").filter(Boolean).join(nl);
|
|
501
460
|
};
|
|
502
461
|
return {
|
|
503
462
|
get css() {
|
|
@@ -510,7 +469,7 @@ var UnoGenerator = class {
|
|
|
510
469
|
};
|
|
511
470
|
}
|
|
512
471
|
matchVariants(raw, current) {
|
|
513
|
-
const usedVariants = new Set();
|
|
472
|
+
const usedVariants = /* @__PURE__ */ new Set();
|
|
514
473
|
const handlers = [];
|
|
515
474
|
let processed = current || raw;
|
|
516
475
|
let applied = false;
|
|
@@ -542,15 +501,10 @@ var UnoGenerator = class {
|
|
|
542
501
|
return [raw, processed, handlers];
|
|
543
502
|
}
|
|
544
503
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
504
|
+
const entries = variantHandlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
545
505
|
return [
|
|
546
|
-
variantHandlers.reduce((p, v) =>
|
|
547
|
-
|
|
548
|
-
return ((_a = v.selector) == null ? void 0 : _a.call(v, p)) || p;
|
|
549
|
-
}, toEscapedSelector(raw)),
|
|
550
|
-
variantHandlers.reduce((p, v) => {
|
|
551
|
-
var _a;
|
|
552
|
-
return ((_a = v.body) == null ? void 0 : _a.call(v, p)) || p;
|
|
553
|
-
}, parsed[2]),
|
|
506
|
+
variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
507
|
+
entries,
|
|
554
508
|
variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
555
509
|
];
|
|
556
510
|
}
|
|
@@ -563,11 +517,10 @@ var UnoGenerator = class {
|
|
|
563
517
|
return cssBody;
|
|
564
518
|
}
|
|
565
519
|
async parseUtil(input, context, internal = false) {
|
|
566
|
-
var _a, _b;
|
|
567
520
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
568
521
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
569
522
|
if (staticMatch) {
|
|
570
|
-
if (staticMatch[1] && (internal || !
|
|
523
|
+
if (staticMatch[1] && (internal || !staticMatch[2]?.internal))
|
|
571
524
|
return [[staticMatch[0], raw, normalizeCSSEntries(staticMatch[1]), staticMatch[2], variantHandlers]];
|
|
572
525
|
}
|
|
573
526
|
context.variantHandlers = variantHandlers;
|
|
@@ -576,7 +529,7 @@ var UnoGenerator = class {
|
|
|
576
529
|
const rule = rulesDynamic[i];
|
|
577
530
|
if (!rule)
|
|
578
531
|
continue;
|
|
579
|
-
if (
|
|
532
|
+
if (rule[2]?.internal && !internal)
|
|
580
533
|
continue;
|
|
581
534
|
const [matcher, handler, meta] = rule;
|
|
582
535
|
const match = processed.match(matcher);
|
|
@@ -630,10 +583,7 @@ var UnoGenerator = class {
|
|
|
630
583
|
if (!result)
|
|
631
584
|
return;
|
|
632
585
|
return [
|
|
633
|
-
result.flatMap((r) =>
|
|
634
|
-
var _a;
|
|
635
|
-
return ((_a = this.expandShortcut(r, context, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
636
|
-
}),
|
|
586
|
+
result.flatMap((r) => this.expandShortcut(r, context, depth - 1)?.[0] || [r]),
|
|
637
587
|
meta
|
|
638
588
|
];
|
|
639
589
|
}
|
|
@@ -665,12 +615,12 @@ var UnoGenerator = class {
|
|
|
665
615
|
isBlocked(raw) {
|
|
666
616
|
return !raw || this.config.blocklist.some((e2) => typeof e2 === "string" ? e2 === raw : e2.test(raw));
|
|
667
617
|
}
|
|
668
|
-
}
|
|
618
|
+
}
|
|
669
619
|
function createGenerator(config, defaults) {
|
|
670
620
|
return new UnoGenerator(config, defaults);
|
|
671
621
|
}
|
|
672
|
-
|
|
673
|
-
|
|
622
|
+
const reScopePlaceholder = / \$\$ /;
|
|
623
|
+
const hasScopePlaceholder = (css) => css.match(reScopePlaceholder);
|
|
674
624
|
function applyScope(css, scope) {
|
|
675
625
|
if (hasScopePlaceholder(css))
|
|
676
626
|
return css.replace(reScopePlaceholder, scope ? ` ${scope} ` : " ");
|
|
@@ -683,50 +633,36 @@ function toEscapedSelector(raw) {
|
|
|
683
633
|
else
|
|
684
634
|
return `.${e(raw)}`;
|
|
685
635
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
isValidSelector,
|
|
720
|
-
mergeDeep,
|
|
721
|
-
mergeSet,
|
|
722
|
-
normalizeCSSEntries,
|
|
723
|
-
normalizeCSSValues,
|
|
724
|
-
normalizeVariant,
|
|
725
|
-
notNull,
|
|
726
|
-
regexClassGroup,
|
|
727
|
-
toArray,
|
|
728
|
-
uniq,
|
|
729
|
-
validateFilterRE,
|
|
730
|
-
warnOnce,
|
|
731
|
-
withLayer
|
|
732
|
-
});
|
|
636
|
+
|
|
637
|
+
exports.BetterMap = BetterMap;
|
|
638
|
+
exports.TwoKeyMap = TwoKeyMap;
|
|
639
|
+
exports.UnoGenerator = UnoGenerator;
|
|
640
|
+
exports.attributifyRE = attributifyRE;
|
|
641
|
+
exports.clearIdenticalEntries = clearIdenticalEntries;
|
|
642
|
+
exports.createGenerator = createGenerator;
|
|
643
|
+
exports.e = e;
|
|
644
|
+
exports.entriesToCss = entriesToCss;
|
|
645
|
+
exports.escapeRegExp = escapeRegExp;
|
|
646
|
+
exports.escapeSelector = escapeSelector;
|
|
647
|
+
exports.expandVariantGroup = expandVariantGroup;
|
|
648
|
+
exports.extractorSplit = extractorSplit;
|
|
649
|
+
exports.hasScopePlaceholder = hasScopePlaceholder;
|
|
650
|
+
exports.hex2rgba = hex2rgba;
|
|
651
|
+
exports.isAttributifySelector = isAttributifySelector;
|
|
652
|
+
exports.isObject = isObject;
|
|
653
|
+
exports.isRawUtil = isRawUtil;
|
|
654
|
+
exports.isStaticRule = isStaticRule;
|
|
655
|
+
exports.isStaticShortcut = isStaticShortcut;
|
|
656
|
+
exports.isValidSelector = isValidSelector;
|
|
657
|
+
exports.mergeDeep = mergeDeep;
|
|
658
|
+
exports.mergeSet = mergeSet;
|
|
659
|
+
exports.normalizeCSSEntries = normalizeCSSEntries;
|
|
660
|
+
exports.normalizeCSSValues = normalizeCSSValues;
|
|
661
|
+
exports.normalizeVariant = normalizeVariant;
|
|
662
|
+
exports.notNull = notNull;
|
|
663
|
+
exports.regexClassGroup = regexClassGroup;
|
|
664
|
+
exports.toArray = toArray;
|
|
665
|
+
exports.uniq = uniq;
|
|
666
|
+
exports.validateFilterRE = validateFilterRE;
|
|
667
|
+
exports.warnOnce = warnOnce;
|
|
668
|
+
exports.withLayer = withLayer;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,8 +21,6 @@ declare class UnoGenerator {
|
|
|
21
21
|
}
|
|
22
22
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
23
23
|
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
|
|
24
|
-
declare function normalizeCSSEntries(obj: CSSEntries | CSSObject): CSSEntries;
|
|
25
|
-
declare function normalizeCSSValues(obj: CSSValues): CSSEntries[];
|
|
26
24
|
|
|
27
25
|
declare type Awaitable<T> = T | Promise<T>;
|
|
28
26
|
declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
@@ -113,7 +111,7 @@ interface VariantHandler {
|
|
|
113
111
|
/**
|
|
114
112
|
* Rewrite the output selector. Often be used to append pesudo classes or parents.
|
|
115
113
|
*/
|
|
116
|
-
selector?: (input: string) => string | undefined;
|
|
114
|
+
selector?: (input: string, body: CSSEntries) => string | undefined;
|
|
117
115
|
/**
|
|
118
116
|
* Rewrite the output css body. The input come in [key,value][] pairs.
|
|
119
117
|
*/
|
|
@@ -223,7 +221,7 @@ interface UserOnlyOptions<Theme extends {} = {}> {
|
|
|
223
221
|
/**
|
|
224
222
|
* Presets
|
|
225
223
|
*/
|
|
226
|
-
presets?: Preset[];
|
|
224
|
+
presets?: (Preset | Preset[])[];
|
|
227
225
|
/**
|
|
228
226
|
* Environment mode
|
|
229
227
|
*
|
|
@@ -329,6 +327,9 @@ declare function escapeRegExp(string: string): string;
|
|
|
329
327
|
declare function escapeSelector(str: string): string;
|
|
330
328
|
declare const e: typeof escapeSelector;
|
|
331
329
|
|
|
330
|
+
declare function normalizeCSSEntries(obj: CSSEntries | CSSObject): CSSEntries;
|
|
331
|
+
declare function normalizeCSSValues(obj: CSSValues): CSSEntries[];
|
|
332
|
+
declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
|
|
332
333
|
declare function entriesToCss(arr?: CSSEntries): string;
|
|
333
334
|
declare function isObject(item: any): item is Record<string, any>;
|
|
334
335
|
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
@@ -372,4 +373,4 @@ declare function warnOnce(msg: string): void;
|
|
|
372
373
|
|
|
373
374
|
declare const extractorSplit: Extractor;
|
|
374
375
|
|
|
375
|
-
export { ArgumentType, Awaitable, BetterMap, BlocklistRule, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedUtil, PartialByKeys, PluginOptions, Preflight, Preset, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, createGenerator, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
|
376
|
+
export { ArgumentType, Awaitable, BetterMap, BlocklistRule, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedUtil, PartialByKeys, PluginOptions, Preflight, Preset, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, createGenerator, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/utils/escape.ts
|
|
2
1
|
function escapeRegExp(string) {
|
|
3
2
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
3
|
}
|
|
@@ -34,13 +33,36 @@ function escapeSelector(str) {
|
|
|
34
33
|
}
|
|
35
34
|
return result;
|
|
36
35
|
}
|
|
37
|
-
|
|
36
|
+
const e = escapeSelector;
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
function normalizeCSSEntries(obj) {
|
|
39
|
+
return (!Array.isArray(obj) ? Object.entries(obj) : obj).filter((i) => i[1] != null);
|
|
40
|
+
}
|
|
41
|
+
function normalizeCSSValues(obj) {
|
|
42
|
+
if (Array.isArray(obj)) {
|
|
43
|
+
if (obj.find((i) => !Array.isArray(i) || Array.isArray(i[0])))
|
|
44
|
+
return obj.map((i) => normalizeCSSEntries(i));
|
|
45
|
+
else
|
|
46
|
+
return [obj];
|
|
47
|
+
} else {
|
|
48
|
+
return [normalizeCSSEntries(obj)];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function clearIdenticalEntries(entry) {
|
|
52
|
+
return entry.filter(([k, v], idx) => {
|
|
53
|
+
if (k.startsWith("$$"))
|
|
54
|
+
return false;
|
|
55
|
+
for (let i = idx - 1; i >= 0; i--) {
|
|
56
|
+
if (entry[i][0] === k && entry[i][1] === v)
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
40
62
|
function entriesToCss(arr) {
|
|
41
63
|
if (arr == null)
|
|
42
64
|
return "";
|
|
43
|
-
return arr.map(([key, value]) => value != null ? `${key}:${value};` : void 0).filter(Boolean).join("");
|
|
65
|
+
return clearIdenticalEntries(arr).map(([key, value]) => value != null ? `${key}:${value};` : void 0).filter(Boolean).join("");
|
|
44
66
|
}
|
|
45
67
|
function isObject(item) {
|
|
46
68
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
@@ -74,7 +96,6 @@ function isStaticShortcut(sc) {
|
|
|
74
96
|
return typeof sc[0] === "string";
|
|
75
97
|
}
|
|
76
98
|
|
|
77
|
-
// src/utils/basic.ts
|
|
78
99
|
function toArray(value = []) {
|
|
79
100
|
return Array.isArray(value) ? value : [value];
|
|
80
101
|
}
|
|
@@ -86,8 +107,7 @@ function mergeSet(target, append) {
|
|
|
86
107
|
return target;
|
|
87
108
|
}
|
|
88
109
|
|
|
89
|
-
|
|
90
|
-
var hexRE = /^#?([\da-f]+)$/i;
|
|
110
|
+
const hexRE = /^#?([\da-f]+)$/i;
|
|
91
111
|
function hex2rgba(hex = "") {
|
|
92
112
|
const [, body] = hex.match(hexRE) || [];
|
|
93
113
|
if (!body)
|
|
@@ -109,9 +129,8 @@ function hex2rgba(hex = "") {
|
|
|
109
129
|
}
|
|
110
130
|
}
|
|
111
131
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var validateFilterRE = /[a-z?]/;
|
|
132
|
+
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
133
|
+
const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
|
|
115
134
|
function isAttributifySelector(selector) {
|
|
116
135
|
return selector.match(attributifyRE);
|
|
117
136
|
}
|
|
@@ -128,10 +147,9 @@ function notNull(value) {
|
|
|
128
147
|
return value != null;
|
|
129
148
|
}
|
|
130
149
|
|
|
131
|
-
|
|
132
|
-
var TwoKeyMap = class {
|
|
150
|
+
class TwoKeyMap {
|
|
133
151
|
constructor() {
|
|
134
|
-
this._map = new Map();
|
|
152
|
+
this._map = /* @__PURE__ */ new Map();
|
|
135
153
|
}
|
|
136
154
|
get(key1, key2) {
|
|
137
155
|
const m2 = this._map.get(key1);
|
|
@@ -141,7 +159,7 @@ var TwoKeyMap = class {
|
|
|
141
159
|
getFallback(key1, key2, fallback) {
|
|
142
160
|
let m2 = this._map.get(key1);
|
|
143
161
|
if (!m2) {
|
|
144
|
-
m2 = new Map();
|
|
162
|
+
m2 = /* @__PURE__ */ new Map();
|
|
145
163
|
this._map.set(key1, m2);
|
|
146
164
|
}
|
|
147
165
|
if (!m2.has(key2))
|
|
@@ -151,19 +169,17 @@ var TwoKeyMap = class {
|
|
|
151
169
|
set(key1, key2, value) {
|
|
152
170
|
let m2 = this._map.get(key1);
|
|
153
171
|
if (!m2) {
|
|
154
|
-
m2 = new Map();
|
|
172
|
+
m2 = /* @__PURE__ */ new Map();
|
|
155
173
|
this._map.set(key1, m2);
|
|
156
174
|
}
|
|
157
175
|
m2.set(key2, value);
|
|
158
176
|
return this;
|
|
159
177
|
}
|
|
160
178
|
has(key1, key2) {
|
|
161
|
-
|
|
162
|
-
return (_a = this._map.get(key1)) == null ? void 0 : _a.has(key2);
|
|
179
|
+
return this._map.get(key1)?.has(key2);
|
|
163
180
|
}
|
|
164
181
|
delete(key1, key2) {
|
|
165
|
-
|
|
166
|
-
return ((_a = this._map.get(key1)) == null ? void 0 : _a.delete(key2)) || false;
|
|
182
|
+
return this._map.get(key1)?.delete(key2) || false;
|
|
167
183
|
}
|
|
168
184
|
deleteTop(key1) {
|
|
169
185
|
return this._map.delete(key1);
|
|
@@ -173,8 +189,8 @@ var TwoKeyMap = class {
|
|
|
173
189
|
return fn(v, k1, k2);
|
|
174
190
|
}));
|
|
175
191
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
192
|
+
}
|
|
193
|
+
class BetterMap extends Map {
|
|
178
194
|
map(mapFn) {
|
|
179
195
|
const result = [];
|
|
180
196
|
this.forEach((v, k) => {
|
|
@@ -182,9 +198,8 @@ var BetterMap = class extends Map {
|
|
|
182
198
|
});
|
|
183
199
|
return result;
|
|
184
200
|
}
|
|
185
|
-
}
|
|
201
|
+
}
|
|
186
202
|
|
|
187
|
-
// src/utils/layer.ts
|
|
188
203
|
function withLayer(layer, rules) {
|
|
189
204
|
rules.forEach((r) => {
|
|
190
205
|
if (!r[2])
|
|
@@ -195,8 +210,7 @@ function withLayer(layer, rules) {
|
|
|
195
210
|
return rules;
|
|
196
211
|
}
|
|
197
212
|
|
|
198
|
-
|
|
199
|
-
var regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
213
|
+
const regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
|
|
200
214
|
function expandVariantGroup(str) {
|
|
201
215
|
const replaces = [];
|
|
202
216
|
let match;
|
|
@@ -214,8 +228,7 @@ function expandVariantGroup(str) {
|
|
|
214
228
|
return result;
|
|
215
229
|
}
|
|
216
230
|
|
|
217
|
-
|
|
218
|
-
var warned = new Set();
|
|
231
|
+
const warned = /* @__PURE__ */ new Set();
|
|
219
232
|
function warnOnce(msg) {
|
|
220
233
|
if (warned.has(msg))
|
|
221
234
|
return;
|
|
@@ -223,8 +236,7 @@ function warnOnce(msg) {
|
|
|
223
236
|
warned.add(msg);
|
|
224
237
|
}
|
|
225
238
|
|
|
226
|
-
|
|
227
|
-
var extractorSplit = {
|
|
239
|
+
const extractorSplit = {
|
|
228
240
|
name: "split",
|
|
229
241
|
order: 0,
|
|
230
242
|
extract({ code }) {
|
|
@@ -232,7 +244,6 @@ var extractorSplit = {
|
|
|
232
244
|
}
|
|
233
245
|
};
|
|
234
246
|
|
|
235
|
-
// src/config.ts
|
|
236
247
|
function resolveShortcuts(shortcuts) {
|
|
237
248
|
return toArray(shortcuts).flatMap((s) => {
|
|
238
249
|
if (Array.isArray(s))
|
|
@@ -240,13 +251,13 @@ function resolveShortcuts(shortcuts) {
|
|
|
240
251
|
return Object.entries(s);
|
|
241
252
|
});
|
|
242
253
|
}
|
|
243
|
-
|
|
254
|
+
const defaultLayers = {
|
|
244
255
|
shortcuts: -1,
|
|
245
256
|
default: 0
|
|
246
257
|
};
|
|
247
258
|
function resolveConfig(userConfig = {}, defaults = {}) {
|
|
248
259
|
const config = Object.assign({}, defaults, userConfig);
|
|
249
|
-
const rawPresets = config.presets || [];
|
|
260
|
+
const rawPresets = (config.presets || []).flatMap(toArray);
|
|
250
261
|
const sortedPresets = [
|
|
251
262
|
...rawPresets.filter((p) => p.enforce === "pre"),
|
|
252
263
|
...rawPresets.filter((p) => !p.enforce),
|
|
@@ -281,9 +292,9 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
281
292
|
warn: true,
|
|
282
293
|
blocklist: [],
|
|
283
294
|
safelist: [],
|
|
284
|
-
presets: [],
|
|
285
295
|
sortLayers: (layers2) => layers2,
|
|
286
296
|
...config,
|
|
297
|
+
presets: sortedPresets,
|
|
287
298
|
envMode: config.envMode || "build",
|
|
288
299
|
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
289
300
|
layers,
|
|
@@ -298,18 +309,16 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
298
309
|
};
|
|
299
310
|
}
|
|
300
311
|
|
|
301
|
-
|
|
302
|
-
var version = "0.14.0";
|
|
312
|
+
const version = "0.15.0";
|
|
303
313
|
|
|
304
|
-
|
|
305
|
-
var UnoGenerator = class {
|
|
314
|
+
class UnoGenerator {
|
|
306
315
|
constructor(userConfig = {}, defaults = {}) {
|
|
307
316
|
this.userConfig = userConfig;
|
|
308
317
|
this.defaults = defaults;
|
|
309
318
|
this.version = version;
|
|
310
|
-
this._cache = new Map();
|
|
311
|
-
this.blocked = new Set();
|
|
312
|
-
this.parentOrders = new Map();
|
|
319
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
320
|
+
this.blocked = /* @__PURE__ */ new Set();
|
|
321
|
+
this.parentOrders = /* @__PURE__ */ new Map();
|
|
313
322
|
this.config = resolveConfig(userConfig, defaults);
|
|
314
323
|
}
|
|
315
324
|
setConfig(userConfig, defaults) {
|
|
@@ -323,7 +332,7 @@ var UnoGenerator = class {
|
|
|
323
332
|
this.parentOrders.clear();
|
|
324
333
|
this._cache.clear();
|
|
325
334
|
}
|
|
326
|
-
async applyExtractors(code, id, set = new Set()) {
|
|
335
|
+
async applyExtractors(code, id, set = /* @__PURE__ */ new Set()) {
|
|
327
336
|
const context = {
|
|
328
337
|
get original() {
|
|
329
338
|
return code;
|
|
@@ -333,7 +342,7 @@ var UnoGenerator = class {
|
|
|
333
342
|
};
|
|
334
343
|
for (const extractor of this.config.extractors) {
|
|
335
344
|
const result = await extractor.extract(context);
|
|
336
|
-
result
|
|
345
|
+
result?.forEach((t) => set.add(t));
|
|
337
346
|
}
|
|
338
347
|
return set;
|
|
339
348
|
}
|
|
@@ -348,11 +357,10 @@ var UnoGenerator = class {
|
|
|
348
357
|
if (safelist)
|
|
349
358
|
this.config.safelist.forEach((s) => tokens.add(s));
|
|
350
359
|
const nl = minify ? "" : "\n";
|
|
351
|
-
const layerSet = new Set(["default"]);
|
|
352
|
-
const matched = new Set();
|
|
353
|
-
const sheet = new Map();
|
|
360
|
+
const layerSet = /* @__PURE__ */ new Set(["default"]);
|
|
361
|
+
const matched = /* @__PURE__ */ new Set();
|
|
362
|
+
const sheet = /* @__PURE__ */ new Map();
|
|
354
363
|
const hit = (raw, payload) => {
|
|
355
|
-
var _a;
|
|
356
364
|
this._cache.set(raw, payload);
|
|
357
365
|
matched.add(raw);
|
|
358
366
|
for (const item of payload) {
|
|
@@ -360,7 +368,7 @@ var UnoGenerator = class {
|
|
|
360
368
|
if (!sheet.has(parent))
|
|
361
369
|
sheet.set(parent, []);
|
|
362
370
|
sheet.get(parent).push(item);
|
|
363
|
-
if (
|
|
371
|
+
if (item[4]?.layer)
|
|
364
372
|
layerSet.add(item[4].layer);
|
|
365
373
|
}
|
|
366
374
|
};
|
|
@@ -369,7 +377,6 @@ var UnoGenerator = class {
|
|
|
369
377
|
this._cache.set(raw, null);
|
|
370
378
|
};
|
|
371
379
|
await Promise.all(Array.from(tokens).map(async (raw) => {
|
|
372
|
-
var _a;
|
|
373
380
|
if (matched.has(raw) || this.blocked.has(raw))
|
|
374
381
|
return;
|
|
375
382
|
if (this._cache.has(raw)) {
|
|
@@ -397,11 +404,11 @@ var UnoGenerator = class {
|
|
|
397
404
|
const expanded = this.expandShortcut(applied[1], context);
|
|
398
405
|
if (expanded) {
|
|
399
406
|
const utils = await this.stringifyShortcuts(applied, context, expanded[0], expanded[1]);
|
|
400
|
-
if (utils
|
|
407
|
+
if (utils?.length)
|
|
401
408
|
return hit(raw, utils);
|
|
402
409
|
} else {
|
|
403
|
-
const utils = (
|
|
404
|
-
if (utils
|
|
410
|
+
const utils = (await this.parseUtil(applied, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
411
|
+
if (utils?.length)
|
|
405
412
|
return hit(raw, utils);
|
|
406
413
|
}
|
|
407
414
|
this._cache.set(raw, null);
|
|
@@ -413,22 +420,13 @@ var UnoGenerator = class {
|
|
|
413
420
|
});
|
|
414
421
|
}
|
|
415
422
|
const layerCache = {};
|
|
416
|
-
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) =>
|
|
417
|
-
var _a, _b;
|
|
418
|
-
return ((_a = this.config.layers[a]) != null ? _a : 0) - ((_b = this.config.layers[b]) != null ? _b : 0) || a.localeCompare(b);
|
|
419
|
-
}));
|
|
423
|
+
const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
420
424
|
const getLayer = (layer) => {
|
|
421
425
|
if (layerCache[layer])
|
|
422
426
|
return layerCache[layer];
|
|
423
427
|
let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) || 0) - (this.parentOrders.get(b[0]) || 0)).map(([parent, items]) => {
|
|
424
428
|
const size = items.length;
|
|
425
|
-
const sorted = items.filter((i) =>
|
|
426
|
-
var _a;
|
|
427
|
-
return (((_a = i[4]) == null ? void 0 : _a.layer) || "default") === layer;
|
|
428
|
-
}).sort((a, b) => {
|
|
429
|
-
var _a;
|
|
430
|
-
return a[0] - b[0] || ((_a = a[1]) == null ? void 0 : _a.localeCompare(b[1] || "")) || 0;
|
|
431
|
-
}).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
429
|
+
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => a[0] - b[0] || a[1]?.localeCompare(b[1] || "") || 0).map((a) => [a[1] ? applyScope(a[1], scope) : a[1], a[2]]);
|
|
432
430
|
if (!sorted.length)
|
|
433
431
|
return void 0;
|
|
434
432
|
const rules = sorted.reverse().map(([selector, body], idx) => {
|
|
@@ -454,7 +452,7 @@ var UnoGenerator = class {
|
|
|
454
452
|
return layerCache[layer] = !minify && css ? `/* layer: ${layer} */${nl}${css}` : css;
|
|
455
453
|
};
|
|
456
454
|
const getLayers = (includes = layers, excludes) => {
|
|
457
|
-
return includes.filter((i) => !
|
|
455
|
+
return includes.filter((i) => !excludes?.includes(i)).map((i) => getLayer(i) || "").filter(Boolean).join(nl);
|
|
458
456
|
};
|
|
459
457
|
return {
|
|
460
458
|
get css() {
|
|
@@ -467,7 +465,7 @@ var UnoGenerator = class {
|
|
|
467
465
|
};
|
|
468
466
|
}
|
|
469
467
|
matchVariants(raw, current) {
|
|
470
|
-
const usedVariants = new Set();
|
|
468
|
+
const usedVariants = /* @__PURE__ */ new Set();
|
|
471
469
|
const handlers = [];
|
|
472
470
|
let processed = current || raw;
|
|
473
471
|
let applied = false;
|
|
@@ -499,15 +497,10 @@ var UnoGenerator = class {
|
|
|
499
497
|
return [raw, processed, handlers];
|
|
500
498
|
}
|
|
501
499
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
500
|
+
const entries = variantHandlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
|
|
502
501
|
return [
|
|
503
|
-
variantHandlers.reduce((p, v) =>
|
|
504
|
-
|
|
505
|
-
return ((_a = v.selector) == null ? void 0 : _a.call(v, p)) || p;
|
|
506
|
-
}, toEscapedSelector(raw)),
|
|
507
|
-
variantHandlers.reduce((p, v) => {
|
|
508
|
-
var _a;
|
|
509
|
-
return ((_a = v.body) == null ? void 0 : _a.call(v, p)) || p;
|
|
510
|
-
}, parsed[2]),
|
|
502
|
+
variantHandlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
|
|
503
|
+
entries,
|
|
511
504
|
variantHandlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0)
|
|
512
505
|
];
|
|
513
506
|
}
|
|
@@ -520,11 +513,10 @@ var UnoGenerator = class {
|
|
|
520
513
|
return cssBody;
|
|
521
514
|
}
|
|
522
515
|
async parseUtil(input, context, internal = false) {
|
|
523
|
-
var _a, _b;
|
|
524
516
|
const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
|
|
525
517
|
const staticMatch = this.config.rulesStaticMap[processed];
|
|
526
518
|
if (staticMatch) {
|
|
527
|
-
if (staticMatch[1] && (internal || !
|
|
519
|
+
if (staticMatch[1] && (internal || !staticMatch[2]?.internal))
|
|
528
520
|
return [[staticMatch[0], raw, normalizeCSSEntries(staticMatch[1]), staticMatch[2], variantHandlers]];
|
|
529
521
|
}
|
|
530
522
|
context.variantHandlers = variantHandlers;
|
|
@@ -533,7 +525,7 @@ var UnoGenerator = class {
|
|
|
533
525
|
const rule = rulesDynamic[i];
|
|
534
526
|
if (!rule)
|
|
535
527
|
continue;
|
|
536
|
-
if (
|
|
528
|
+
if (rule[2]?.internal && !internal)
|
|
537
529
|
continue;
|
|
538
530
|
const [matcher, handler, meta] = rule;
|
|
539
531
|
const match = processed.match(matcher);
|
|
@@ -587,10 +579,7 @@ var UnoGenerator = class {
|
|
|
587
579
|
if (!result)
|
|
588
580
|
return;
|
|
589
581
|
return [
|
|
590
|
-
result.flatMap((r) =>
|
|
591
|
-
var _a;
|
|
592
|
-
return ((_a = this.expandShortcut(r, context, depth - 1)) == null ? void 0 : _a[0]) || [r];
|
|
593
|
-
}),
|
|
582
|
+
result.flatMap((r) => this.expandShortcut(r, context, depth - 1)?.[0] || [r]),
|
|
594
583
|
meta
|
|
595
584
|
];
|
|
596
585
|
}
|
|
@@ -622,12 +611,12 @@ var UnoGenerator = class {
|
|
|
622
611
|
isBlocked(raw) {
|
|
623
612
|
return !raw || this.config.blocklist.some((e2) => typeof e2 === "string" ? e2 === raw : e2.test(raw));
|
|
624
613
|
}
|
|
625
|
-
}
|
|
614
|
+
}
|
|
626
615
|
function createGenerator(config, defaults) {
|
|
627
616
|
return new UnoGenerator(config, defaults);
|
|
628
617
|
}
|
|
629
|
-
|
|
630
|
-
|
|
618
|
+
const reScopePlaceholder = / \$\$ /;
|
|
619
|
+
const hasScopePlaceholder = (css) => css.match(reScopePlaceholder);
|
|
631
620
|
function applyScope(css, scope) {
|
|
632
621
|
if (hasScopePlaceholder(css))
|
|
633
622
|
return css.replace(reScopePlaceholder, scope ? ` ${scope} ` : " ");
|
|
@@ -640,49 +629,5 @@ function toEscapedSelector(raw) {
|
|
|
640
629
|
else
|
|
641
630
|
return `.${e(raw)}`;
|
|
642
631
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
function normalizeCSSValues(obj) {
|
|
647
|
-
if (Array.isArray(obj)) {
|
|
648
|
-
if (obj.find((i) => !Array.isArray(i) || Array.isArray(i[0])))
|
|
649
|
-
return obj.map((i) => normalizeCSSEntries(i));
|
|
650
|
-
else
|
|
651
|
-
return [obj];
|
|
652
|
-
} else {
|
|
653
|
-
return [normalizeCSSEntries(obj)];
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
export {
|
|
657
|
-
BetterMap,
|
|
658
|
-
TwoKeyMap,
|
|
659
|
-
UnoGenerator,
|
|
660
|
-
attributifyRE,
|
|
661
|
-
createGenerator,
|
|
662
|
-
e,
|
|
663
|
-
entriesToCss,
|
|
664
|
-
escapeRegExp,
|
|
665
|
-
escapeSelector,
|
|
666
|
-
expandVariantGroup,
|
|
667
|
-
extractorSplit,
|
|
668
|
-
hasScopePlaceholder,
|
|
669
|
-
hex2rgba,
|
|
670
|
-
isAttributifySelector,
|
|
671
|
-
isObject,
|
|
672
|
-
isRawUtil,
|
|
673
|
-
isStaticRule,
|
|
674
|
-
isStaticShortcut,
|
|
675
|
-
isValidSelector,
|
|
676
|
-
mergeDeep,
|
|
677
|
-
mergeSet,
|
|
678
|
-
normalizeCSSEntries,
|
|
679
|
-
normalizeCSSValues,
|
|
680
|
-
normalizeVariant,
|
|
681
|
-
notNull,
|
|
682
|
-
regexClassGroup,
|
|
683
|
-
toArray,
|
|
684
|
-
uniq,
|
|
685
|
-
validateFilterRE,
|
|
686
|
-
warnOnce,
|
|
687
|
-
withLayer
|
|
688
|
-
};
|
|
632
|
+
|
|
633
|
+
export { BetterMap, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, createGenerator, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "The instant on-demand Atomic CSS engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"require": "./dist/index.
|
|
28
|
+
"require": "./dist/index.cjs",
|
|
29
29
|
"import": "./dist/index.mjs",
|
|
30
30
|
"types": "./dist/index.d.ts"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"main": "dist/index.
|
|
33
|
+
"main": "dist/index.cjs",
|
|
34
34
|
"module": "dist/index.mjs",
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
36
|
"files": [
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
40
|
+
"build": "unbuild",
|
|
41
|
+
"stub": "unbuild --stub"
|
|
42
42
|
}
|
|
43
43
|
}
|