@unocss/core 66.6.6 → 66.6.7
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 +17 -17
- package/dist/index.mjs +19 -34
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -8,14 +8,14 @@ declare function uniqueBy<T>(array: readonly T[], equalFn: (a: T, b: T) => boole
|
|
|
8
8
|
declare function isString(s: any): s is string;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/utils/countable-set.d.ts
|
|
11
|
-
declare class CountableSet<K
|
|
12
|
-
_map: Map<K
|
|
13
|
-
constructor(values?: Iterable<K
|
|
14
|
-
add(key: K
|
|
15
|
-
delete(key: K
|
|
11
|
+
declare class CountableSet<K> extends Set<K> {
|
|
12
|
+
_map: Map<K, number>;
|
|
13
|
+
constructor(values?: Iterable<K>);
|
|
14
|
+
add(key: K): this;
|
|
15
|
+
delete(key: K): boolean;
|
|
16
16
|
clear(): void;
|
|
17
|
-
getCount(key: K
|
|
18
|
-
setCount(key: K
|
|
17
|
+
getCount(key: K): number;
|
|
18
|
+
setCount(key: K, count: number): this;
|
|
19
19
|
}
|
|
20
20
|
declare function isCountableSet<T = string>(value: any): value is CountableSet<T>;
|
|
21
21
|
//#endregion
|
|
@@ -62,7 +62,7 @@ declare class Emitter<Events extends EventsMap = DefaultEvents> {
|
|
|
62
62
|
* @param cb The listener function.
|
|
63
63
|
* @returns Unbind listener from event.
|
|
64
64
|
*/
|
|
65
|
-
on<K
|
|
65
|
+
on<K extends keyof Events>(this: this, event: K, cb: Events[K]): Unsubscribe;
|
|
66
66
|
/**
|
|
67
67
|
* Calls each of the listeners registered for a given event.
|
|
68
68
|
*
|
|
@@ -73,7 +73,7 @@ declare class Emitter<Events extends EventsMap = DefaultEvents> {
|
|
|
73
73
|
* @param event The event name.
|
|
74
74
|
* @param args The arguments for listeners.
|
|
75
75
|
*/
|
|
76
|
-
emit<K
|
|
76
|
+
emit<K extends keyof Events>(this: this, event: K, ...args: Parameters<Events[K]>): void;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Create event emitter.
|
|
@@ -121,10 +121,10 @@ declare class TwoKeyMap<K1, K2, V> {
|
|
|
121
121
|
deleteTop(key1: K1): boolean;
|
|
122
122
|
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
123
123
|
}
|
|
124
|
-
declare class BetterMap<K
|
|
125
|
-
getFallback(key: K
|
|
126
|
-
map<R>(mapFn: (value: V, key: K
|
|
127
|
-
flatMap<R extends readonly unknown[]>(mapFn: (value: V, key: K
|
|
124
|
+
declare class BetterMap<K, V> extends Map<K, V> {
|
|
125
|
+
getFallback(key: K, fallback: V): V;
|
|
126
|
+
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
127
|
+
flatMap<R extends readonly unknown[]>(mapFn: (value: V, key: K) => R): R[number][];
|
|
128
128
|
}
|
|
129
129
|
//#endregion
|
|
130
130
|
//#region src/utils/object.d.ts
|
|
@@ -215,8 +215,8 @@ type Shift<T> = T extends [_: any, ...args: infer A] ? A : never;
|
|
|
215
215
|
type RestArgs<T> = Shift<ArgumentType<T>>;
|
|
216
216
|
type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };
|
|
217
217
|
type FlatObjectTuple<T> = { [K in keyof T]: T[K] };
|
|
218
|
-
type PartialByKeys<T, K
|
|
219
|
-
type RequiredByKey<T, K
|
|
218
|
+
type PartialByKeys<T, K extends keyof T = keyof T> = FlatObjectTuple<Partial<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>;
|
|
219
|
+
type RequiredByKey<T, K extends keyof T = keyof T> = FlatObjectTuple<Required<Pick<T, Extract<keyof T, K>>> & Omit<T, K>>;
|
|
220
220
|
type CSSObject = Record<string, string | number | undefined>;
|
|
221
221
|
/**
|
|
222
222
|
* [property, value, operators?]
|
|
@@ -789,8 +789,8 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
|
|
|
789
789
|
*/
|
|
790
790
|
meta?: Record<string, any>;
|
|
791
791
|
}
|
|
792
|
-
type PresetFactory<Theme extends object = object, PresetOptions
|
|
793
|
-
type PresetFactoryAwaitable<Theme extends object = object, PresetOptions
|
|
792
|
+
type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
|
|
793
|
+
type PresetFactoryAwaitable<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Awaitable<Preset<Theme>>;
|
|
794
794
|
type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
|
|
795
795
|
type PresetOrFactoryAwaitable<Theme extends object = object> = PresetOrFactory<Theme> | Promise<Preset<Theme>> | PresetFactoryAwaitable<Theme>;
|
|
796
796
|
interface GeneratorOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,6 @@ const DEFAULT_LAYERS = {
|
|
|
9
9
|
[LAYER_SHORTCUTS]: -10,
|
|
10
10
|
[LAYER_DEFAULT]: 0
|
|
11
11
|
};
|
|
12
|
-
|
|
13
12
|
//#endregion
|
|
14
13
|
//#region src/extractors/split.ts
|
|
15
14
|
const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
|
|
@@ -24,7 +23,6 @@ const extractorSplit = {
|
|
|
24
23
|
return splitCode(code);
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
|
-
|
|
28
26
|
//#endregion
|
|
29
27
|
//#region src/utils/basic.ts
|
|
30
28
|
function toArray(value = []) {
|
|
@@ -42,7 +40,6 @@ function uniqueBy(array, equalFn) {
|
|
|
42
40
|
function isString(s) {
|
|
43
41
|
return typeof s === "string";
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
//#endregion
|
|
47
44
|
//#region src/utils/countable-set.ts
|
|
48
45
|
var CountableSet = class extends Set {
|
|
@@ -75,7 +72,6 @@ var CountableSet = class extends Set {
|
|
|
75
72
|
function isCountableSet(value) {
|
|
76
73
|
return value instanceof CountableSet;
|
|
77
74
|
}
|
|
78
|
-
|
|
79
75
|
//#endregion
|
|
80
76
|
//#region src/utils/escape.ts
|
|
81
77
|
function escapeRegExp(string) {
|
|
@@ -121,7 +117,6 @@ function escapeSelector(str) {
|
|
|
121
117
|
return result;
|
|
122
118
|
}
|
|
123
119
|
const e = escapeSelector;
|
|
124
|
-
|
|
125
120
|
//#endregion
|
|
126
121
|
//#region src/utils/events.ts
|
|
127
122
|
/**
|
|
@@ -155,7 +150,6 @@ function createNanoEvents() {
|
|
|
155
150
|
}
|
|
156
151
|
};
|
|
157
152
|
}
|
|
158
|
-
|
|
159
153
|
//#endregion
|
|
160
154
|
//#region src/utils/helpers.ts
|
|
161
155
|
const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
|
|
@@ -177,7 +171,6 @@ function notNull(value) {
|
|
|
177
171
|
return value != null;
|
|
178
172
|
}
|
|
179
173
|
function noop() {}
|
|
180
|
-
|
|
181
174
|
//#endregion
|
|
182
175
|
//#region src/utils/layer.ts
|
|
183
176
|
function withLayer(layer, rules) {
|
|
@@ -187,7 +180,6 @@ function withLayer(layer, rules) {
|
|
|
187
180
|
});
|
|
188
181
|
return rules;
|
|
189
182
|
}
|
|
190
|
-
|
|
191
183
|
//#endregion
|
|
192
184
|
//#region src/utils/map.ts
|
|
193
185
|
var TwoKeyMap = class {
|
|
@@ -255,7 +247,6 @@ var BetterMap = class extends Map {
|
|
|
255
247
|
return result;
|
|
256
248
|
}
|
|
257
249
|
};
|
|
258
|
-
|
|
259
250
|
//#endregion
|
|
260
251
|
//#region src/utils/object.ts
|
|
261
252
|
function normalizeCSSEntries(obj) {
|
|
@@ -277,7 +268,7 @@ function clearIdenticalEntries(entry) {
|
|
|
277
268
|
const VirtualKey = "__virtual_key__";
|
|
278
269
|
function entriesToCss(arr) {
|
|
279
270
|
if (arr == null) return "";
|
|
280
|
-
return clearIdenticalEntries(arr).map(([key, value]) => value != null && typeof value !== "function" ? key !==
|
|
271
|
+
return clearIdenticalEntries(arr).map(([key, value]) => value != null && typeof value !== "function" ? key !== "__virtual_key__" ? `${key}:${value};` : value : void 0).filter(Boolean).join("");
|
|
281
272
|
}
|
|
282
273
|
function isObject(item) {
|
|
283
274
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
@@ -323,7 +314,6 @@ function isStaticRule(rule) {
|
|
|
323
314
|
function isStaticShortcut(sc) {
|
|
324
315
|
return isString(sc[0]);
|
|
325
316
|
}
|
|
326
|
-
|
|
327
317
|
//#endregion
|
|
328
318
|
//#region src/utils/variant-group.ts
|
|
329
319
|
const regexCache = {};
|
|
@@ -396,7 +386,7 @@ function collapseVariantGroup(str, prefixes) {
|
|
|
396
386
|
const collection = /* @__PURE__ */ new Map();
|
|
397
387
|
const sortedPrefix = prefixes.sort((a, b) => b.length - a.length);
|
|
398
388
|
return str.split(/\s+/g).map((part) => {
|
|
399
|
-
const prefix = sortedPrefix.find((prefix
|
|
389
|
+
const prefix = sortedPrefix.find((prefix) => part.startsWith(prefix));
|
|
400
390
|
if (!prefix) return part;
|
|
401
391
|
const body = part.slice(prefix.length);
|
|
402
392
|
if (collection.has(prefix)) {
|
|
@@ -419,7 +409,6 @@ function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
|
419
409
|
const res = parseVariantGroup(str, separators, depth);
|
|
420
410
|
return typeof str === "string" ? res.expanded : str;
|
|
421
411
|
}
|
|
422
|
-
|
|
423
412
|
//#endregion
|
|
424
413
|
//#region src/utils/warn.ts
|
|
425
414
|
const warned = /* @__PURE__ */ new Set();
|
|
@@ -428,7 +417,6 @@ function warnOnce(msg) {
|
|
|
428
417
|
console.warn("[unocss]", msg);
|
|
429
418
|
warned.add(msg);
|
|
430
419
|
}
|
|
431
|
-
|
|
432
420
|
//#endregion
|
|
433
421
|
//#region src/config.ts
|
|
434
422
|
function resolveShortcuts(shortcuts) {
|
|
@@ -539,7 +527,7 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
539
527
|
const resolved = {
|
|
540
528
|
mergeSelectors: true,
|
|
541
529
|
warn: true,
|
|
542
|
-
sortLayers: (layers
|
|
530
|
+
sortLayers: (layers) => layers,
|
|
543
531
|
...config,
|
|
544
532
|
blocklist: getMerged("blocklist"),
|
|
545
533
|
presets: sortedPresets,
|
|
@@ -614,11 +602,9 @@ function flatternFilterPattern(pattern) {
|
|
|
614
602
|
function definePreset(preset) {
|
|
615
603
|
return preset;
|
|
616
604
|
}
|
|
617
|
-
|
|
618
605
|
//#endregion
|
|
619
606
|
//#region package.json
|
|
620
|
-
var version = "66.6.
|
|
621
|
-
|
|
607
|
+
var version = "66.6.7";
|
|
622
608
|
//#endregion
|
|
623
609
|
//#region src/generator.ts
|
|
624
610
|
const symbols = {
|
|
@@ -832,10 +818,10 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
832
818
|
preflightLayerSet.add(layer);
|
|
833
819
|
});
|
|
834
820
|
preflightsMap = Object.fromEntries(await Promise.all(Array.from(preflightLayerSet).map(async (layer) => {
|
|
835
|
-
return [layer, (await Promise.all(this.config.preflights.filter((i) => (i.layer ||
|
|
821
|
+
return [layer, (await Promise.all(this.config.preflights.filter((i) => (i.layer || "preflights") === layer).map(async (i) => await i.getCSS(preflightContext)))).filter(Boolean).join(nl)];
|
|
836
822
|
})));
|
|
837
823
|
})();
|
|
838
|
-
const sortLayers = (layers
|
|
824
|
+
const sortLayers = (layers) => this.config.sortLayers(layers.sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
839
825
|
const layers = sortLayers(Array.from(layerSet));
|
|
840
826
|
const layerCache = {};
|
|
841
827
|
const outputCssLayers = this.config.outputToCssLayers;
|
|
@@ -848,7 +834,7 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
848
834
|
if (layerCache[layer]) return layerCache[layer];
|
|
849
835
|
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]) => {
|
|
850
836
|
const size = items.length;
|
|
851
|
-
const sorted = items.filter((i) => (i[4]?.layer ||
|
|
837
|
+
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => {
|
|
852
838
|
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;
|
|
853
839
|
}).map(([, selector, body, , meta, , variantNoMerge]) => {
|
|
854
840
|
return [
|
|
@@ -884,10 +870,10 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
884
870
|
return layerCache[layer] = css ? layerMark + css : "";
|
|
885
871
|
};
|
|
886
872
|
const getLayers = (includes = layers, excludes) => {
|
|
887
|
-
const layers
|
|
888
|
-
const css = layers
|
|
873
|
+
const layers = includes.filter((i) => !excludes?.includes(i));
|
|
874
|
+
const css = layers.map(getLayer).filter(Boolean);
|
|
889
875
|
if (outputCssLayers) {
|
|
890
|
-
let layerNames = layers
|
|
876
|
+
let layerNames = layers;
|
|
891
877
|
if (typeof outputCssLayers === "object" && outputCssLayers.allLayers) layerNames = sortLayers(Object.keys(this.config.layers));
|
|
892
878
|
if (layerNames.length > 0) css.unshift(`@layer ${layerNames.map(getLayerAlias).filter(notNull).join(", ")};`);
|
|
893
879
|
}
|
|
@@ -1199,16 +1185,16 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
1199
1185
|
}
|
|
1200
1186
|
const isNoMerge = Object.fromEntries(item[2])[symbols.shortcutsNoMerge];
|
|
1201
1187
|
const variants = [...item[4], ...!isNoMerge ? parentVariants : []];
|
|
1202
|
-
for (const { selector, entries, parent
|
|
1188
|
+
for (const { selector, entries, parent, sort, noMerge, layer } of this.applyVariants(item, variants, raw)) layerMap.getFallback(layer ?? meta.layer, new TwoKeyMap()).getFallback(selector, parent, [[], item[0]])[0].push([
|
|
1203
1189
|
entries,
|
|
1204
1190
|
!!(noMerge ?? item[3]?.noMerge),
|
|
1205
1191
|
sort ?? 0
|
|
1206
1192
|
]);
|
|
1207
1193
|
}
|
|
1208
|
-
return rawStringifiedUtil.concat(layerMap.flatMap((selectorMap, layer) => selectorMap.map(([e
|
|
1194
|
+
return rawStringifiedUtil.concat(layerMap.flatMap((selectorMap, layer) => selectorMap.map(([e, index], selector, joinedParents) => {
|
|
1209
1195
|
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
1210
|
-
const maxSort = Math.max(...entrySortPair.map((e
|
|
1211
|
-
const entriesList = entrySortPair.map((e
|
|
1196
|
+
const maxSort = Math.max(...entrySortPair.map((e) => e[1]));
|
|
1197
|
+
const entriesList = entrySortPair.map((e) => e[0]);
|
|
1212
1198
|
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
1213
1199
|
const body = entriesToCss(entries);
|
|
1214
1200
|
if (body) return [
|
|
@@ -1227,15 +1213,15 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
1227
1213
|
];
|
|
1228
1214
|
});
|
|
1229
1215
|
};
|
|
1230
|
-
return [[e
|
|
1216
|
+
return [[e.filter(([, noMerge]) => noMerge).map(([entries, , sort]) => [entries, sort]), true], [e.filter(([, noMerge]) => !noMerge).map(([entries, , sort]) => [entries, sort]), false]].map(([e, noMerge]) => [...stringify(false, noMerge, e.filter(([entries]) => entries.some((entry) => entry[0] === symbols.shortcutsNoMerge))), ...stringify(true, noMerge, e.filter(([entries]) => entries.every((entry) => entry[0] !== symbols.shortcutsNoMerge)))]);
|
|
1231
1217
|
}).flat(2).filter(Boolean)));
|
|
1232
1218
|
}
|
|
1233
1219
|
isBlocked(raw) {
|
|
1234
|
-
return !raw || this.config.blocklist.map((e
|
|
1220
|
+
return !raw || this.config.blocklist.map((e) => Array.isArray(e) ? e[0] : e).some((e) => typeof e === "function" ? e(raw) : isString(e) ? e === raw : e.test(raw));
|
|
1235
1221
|
}
|
|
1236
1222
|
getBlocked(raw) {
|
|
1237
|
-
const rule = this.config.blocklist.find((e
|
|
1238
|
-
const v = Array.isArray(e
|
|
1223
|
+
const rule = this.config.blocklist.find((e) => {
|
|
1224
|
+
const v = Array.isArray(e) ? e[0] : e;
|
|
1239
1225
|
return typeof v === "function" ? v(raw) : isString(v) ? v === raw : v.test(raw);
|
|
1240
1226
|
});
|
|
1241
1227
|
return rule ? Array.isArray(rule) ? rule : [rule, void 0] : void 0;
|
|
@@ -1269,6 +1255,5 @@ function toEscapedSelector(raw) {
|
|
|
1269
1255
|
function defaultVariantHandler(input, next) {
|
|
1270
1256
|
return next(input);
|
|
1271
1257
|
}
|
|
1272
|
-
|
|
1273
1258
|
//#endregion
|
|
1274
|
-
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 };
|
|
1259
|
+
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 };
|