@unocss/core 0.54.3 → 0.55.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +64 -10
- package/dist/index.d.ts +68 -37
- package/dist/index.mjs +63 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -213,6 +213,36 @@ class BetterMap extends Map {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
class CountableSet extends Set {
|
|
217
|
+
constructor(values) {
|
|
218
|
+
super(values);
|
|
219
|
+
this._map ?? (this._map = /* @__PURE__ */ new Map());
|
|
220
|
+
}
|
|
221
|
+
add(key) {
|
|
222
|
+
this._map ?? (this._map = /* @__PURE__ */ new Map());
|
|
223
|
+
this._map.set(key, (this._map.get(key) ?? 0) + 1);
|
|
224
|
+
return super.add(key);
|
|
225
|
+
}
|
|
226
|
+
delete(key) {
|
|
227
|
+
this._map.delete(key);
|
|
228
|
+
return super.delete(key);
|
|
229
|
+
}
|
|
230
|
+
clear() {
|
|
231
|
+
this._map.clear();
|
|
232
|
+
super.clear();
|
|
233
|
+
}
|
|
234
|
+
getCount(key) {
|
|
235
|
+
return this._map.get(key) ?? 0;
|
|
236
|
+
}
|
|
237
|
+
setCount(key, count) {
|
|
238
|
+
this._map.set(key, count);
|
|
239
|
+
return super.add(key);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function isCountableSet(value) {
|
|
243
|
+
return value instanceof CountableSet;
|
|
244
|
+
}
|
|
245
|
+
|
|
216
246
|
function withLayer(layer, rules) {
|
|
217
247
|
rules.forEach((r) => {
|
|
218
248
|
if (!r[2])
|
|
@@ -371,7 +401,7 @@ function createValueHandler(handlers) {
|
|
|
371
401
|
const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
|
|
372
402
|
const splitWithVariantGroupRE = /([\\:]?[\s"'`;<>]|:\(|\)"|\)\s)/g;
|
|
373
403
|
function splitCode(code) {
|
|
374
|
-
return
|
|
404
|
+
return code.split(defaultSplitRE);
|
|
375
405
|
}
|
|
376
406
|
const extractorSplit = {
|
|
377
407
|
name: "@unocss/core/extractor-split",
|
|
@@ -567,7 +597,7 @@ function mergeAutocompleteShorthands(shorthands) {
|
|
|
567
597
|
);
|
|
568
598
|
}
|
|
569
599
|
|
|
570
|
-
const version = "0.
|
|
600
|
+
const version = "0.55.1";
|
|
571
601
|
|
|
572
602
|
class UnoGenerator {
|
|
573
603
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -598,11 +628,17 @@ class UnoGenerator {
|
|
|
598
628
|
original: code,
|
|
599
629
|
code,
|
|
600
630
|
id,
|
|
601
|
-
extracted
|
|
631
|
+
extracted,
|
|
632
|
+
envMode: this.config.envMode
|
|
602
633
|
};
|
|
603
634
|
for (const extractor of this.config.extractors) {
|
|
604
635
|
const result = await extractor.extract?.(context);
|
|
605
|
-
if (result)
|
|
636
|
+
if (!result)
|
|
637
|
+
continue;
|
|
638
|
+
if (isCountableSet(result) && isCountableSet(extracted)) {
|
|
639
|
+
for (const token of result)
|
|
640
|
+
extracted.setCount(token, extracted.getCount(token) + result.getCount(token));
|
|
641
|
+
} else {
|
|
606
642
|
for (const token of result)
|
|
607
643
|
extracted.add(token);
|
|
608
644
|
}
|
|
@@ -658,14 +694,23 @@ class UnoGenerator {
|
|
|
658
694
|
scope,
|
|
659
695
|
preflights = true,
|
|
660
696
|
safelist = true,
|
|
661
|
-
minify = false
|
|
697
|
+
minify = false,
|
|
698
|
+
extendedInfo = false
|
|
662
699
|
} = options;
|
|
663
|
-
const tokens = isString(input) ? await this.applyExtractors(
|
|
664
|
-
|
|
665
|
-
|
|
700
|
+
const tokens = isString(input) ? await this.applyExtractors(
|
|
701
|
+
input,
|
|
702
|
+
id,
|
|
703
|
+
extendedInfo ? new CountableSet() : /* @__PURE__ */ new Set()
|
|
704
|
+
) : Array.isArray(input) ? new Set(input) : input;
|
|
705
|
+
if (safelist) {
|
|
706
|
+
this.config.safelist.forEach((s) => {
|
|
707
|
+
if (!tokens.has(s))
|
|
708
|
+
tokens.add(s);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
666
711
|
const nl = minify ? "" : "\n";
|
|
667
712
|
const layerSet = /* @__PURE__ */ new Set([LAYER_DEFAULT]);
|
|
668
|
-
const matched = /* @__PURE__ */ new Set();
|
|
713
|
+
const matched = extendedInfo ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
669
714
|
const sheet = /* @__PURE__ */ new Map();
|
|
670
715
|
let preflightsMap = {};
|
|
671
716
|
const tokenPromises = Array.from(tokens).map(async (raw) => {
|
|
@@ -674,7 +719,14 @@ class UnoGenerator {
|
|
|
674
719
|
const payload = await this.parseToken(raw);
|
|
675
720
|
if (payload == null)
|
|
676
721
|
return;
|
|
677
|
-
matched
|
|
722
|
+
if (matched instanceof Map) {
|
|
723
|
+
matched.set(raw, {
|
|
724
|
+
data: payload,
|
|
725
|
+
count: isCountableSet(tokens) ? tokens.getCount(raw) : -1
|
|
726
|
+
});
|
|
727
|
+
} else {
|
|
728
|
+
matched.add(raw);
|
|
729
|
+
}
|
|
678
730
|
for (const item of payload) {
|
|
679
731
|
const parent = item[3] || "";
|
|
680
732
|
const layer = item[4]?.layer;
|
|
@@ -1056,6 +1108,7 @@ function defaultVariantHandler(input, next) {
|
|
|
1056
1108
|
|
|
1057
1109
|
exports.BetterMap = BetterMap;
|
|
1058
1110
|
exports.CONTROL_SHORTCUT_NO_MERGE = CONTROL_SHORTCUT_NO_MERGE;
|
|
1111
|
+
exports.CountableSet = CountableSet;
|
|
1059
1112
|
exports.TwoKeyMap = TwoKeyMap;
|
|
1060
1113
|
exports.UnoGenerator = UnoGenerator;
|
|
1061
1114
|
exports.attributifyRE = attributifyRE;
|
|
@@ -1075,6 +1128,7 @@ exports.extractorDefault = extractorSplit;
|
|
|
1075
1128
|
exports.extractorSplit = extractorSplit;
|
|
1076
1129
|
exports.hasScopePlaceholder = hasScopePlaceholder;
|
|
1077
1130
|
exports.isAttributifySelector = isAttributifySelector;
|
|
1131
|
+
exports.isCountableSet = isCountableSet;
|
|
1078
1132
|
exports.isObject = isObject;
|
|
1079
1133
|
exports.isRawUtil = isRawUtil;
|
|
1080
1134
|
exports.isStaticRule = isStaticRule;
|
package/dist/index.d.ts
CHANGED
|
@@ -51,37 +51,6 @@ declare class Emitter<Events extends EventsMap = DefaultEvents> {
|
|
|
51
51
|
emit<K extends keyof Events>(this: this, event: K, ...args: Parameters<Events[K]>): void;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
declare class UnoGenerator<Theme extends object = object> {
|
|
55
|
-
userConfig: UserConfig<Theme>;
|
|
56
|
-
defaults: UserConfigDefaults<Theme>;
|
|
57
|
-
version: string;
|
|
58
|
-
private _cache;
|
|
59
|
-
config: ResolvedConfig<Theme>;
|
|
60
|
-
blocked: Set<string>;
|
|
61
|
-
parentOrders: Map<string, number>;
|
|
62
|
-
events: Emitter<{
|
|
63
|
-
config: (config: ResolvedConfig<Theme>) => void;
|
|
64
|
-
}>;
|
|
65
|
-
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
66
|
-
setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): void;
|
|
67
|
-
applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
|
|
68
|
-
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
69
|
-
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
|
|
70
|
-
generate(input: string | Set<string> | string[], options?: GenerateOptions): Promise<GenerateResult>;
|
|
71
|
-
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme>>;
|
|
72
|
-
private applyVariants;
|
|
73
|
-
constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
74
|
-
parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
75
|
-
stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme> | undefined;
|
|
76
|
-
expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[ShortcutValue[], RuleMeta | undefined] | undefined>;
|
|
77
|
-
stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: ShortcutValue[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
|
|
78
|
-
isBlocked(raw: string): boolean;
|
|
79
|
-
}
|
|
80
|
-
declare function createGenerator<Theme extends object = object>(config?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): UnoGenerator<Theme>;
|
|
81
|
-
declare const regexScopePlaceholder: RegExp;
|
|
82
|
-
declare function hasScopePlaceholder(css: string): RegExpMatchArray | null;
|
|
83
|
-
declare function toEscapedSelector(raw: string): string;
|
|
84
|
-
|
|
85
54
|
declare function escapeRegExp(string: string): string;
|
|
86
55
|
/**
|
|
87
56
|
* CSS Selector Escape
|
|
@@ -131,6 +100,17 @@ declare class BetterMap<K, V> extends Map<K, V> {
|
|
|
131
100
|
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
132
101
|
}
|
|
133
102
|
|
|
103
|
+
declare class CountableSet<K> extends Set<K> {
|
|
104
|
+
_map: Map<K, number>;
|
|
105
|
+
constructor(values?: Iterable<K>);
|
|
106
|
+
add(key: K): this;
|
|
107
|
+
delete(key: K): boolean;
|
|
108
|
+
clear(): void;
|
|
109
|
+
getCount(key: K): number;
|
|
110
|
+
setCount(key: K, count: number): this;
|
|
111
|
+
}
|
|
112
|
+
declare function isCountableSet<T = string>(value: any): value is CountableSet<T>;
|
|
113
|
+
|
|
134
114
|
declare function withLayer<T extends object>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
135
115
|
|
|
136
116
|
declare function makeRegexClassGroup(separators?: string[]): RegExp;
|
|
@@ -161,6 +141,39 @@ type ValueHandler<K extends string> = {
|
|
|
161
141
|
};
|
|
162
142
|
declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
|
|
163
143
|
|
|
144
|
+
declare class UnoGenerator<Theme extends object = object> {
|
|
145
|
+
userConfig: UserConfig<Theme>;
|
|
146
|
+
defaults: UserConfigDefaults<Theme>;
|
|
147
|
+
version: string;
|
|
148
|
+
private _cache;
|
|
149
|
+
config: ResolvedConfig<Theme>;
|
|
150
|
+
blocked: Set<string>;
|
|
151
|
+
parentOrders: Map<string, number>;
|
|
152
|
+
events: Emitter<{
|
|
153
|
+
config: (config: ResolvedConfig<Theme>) => void;
|
|
154
|
+
}>;
|
|
155
|
+
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
156
|
+
setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): void;
|
|
157
|
+
applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
|
|
158
|
+
applyExtractors(code: string, id?: string, extracted?: CountableSet<string>): Promise<CountableSet<string>>;
|
|
159
|
+
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
160
|
+
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
|
|
161
|
+
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<false>): Promise<GenerateResult<Set<string>>>;
|
|
162
|
+
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<true>): Promise<GenerateResult<Map<string, ExtendedTokenInfo<Theme>>>>;
|
|
163
|
+
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme>>;
|
|
164
|
+
private applyVariants;
|
|
165
|
+
constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
166
|
+
parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
167
|
+
stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme> | undefined;
|
|
168
|
+
expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[ShortcutValue[], RuleMeta | undefined] | undefined>;
|
|
169
|
+
stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: ShortcutValue[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
|
|
170
|
+
isBlocked(raw: string): boolean;
|
|
171
|
+
}
|
|
172
|
+
declare function createGenerator<Theme extends object = object>(config?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): UnoGenerator<Theme>;
|
|
173
|
+
declare const regexScopePlaceholder: RegExp;
|
|
174
|
+
declare function hasScopePlaceholder(css: string): RegExpMatchArray | null;
|
|
175
|
+
declare function toEscapedSelector(raw: string): string;
|
|
176
|
+
|
|
164
177
|
type Awaitable<T> = T | Promise<T>;
|
|
165
178
|
type Arrayable<T> = T | T[];
|
|
166
179
|
type ToArray<T> = T extends (infer U)[] ? U[] : T[];
|
|
@@ -272,7 +285,8 @@ interface ExtractorContext {
|
|
|
272
285
|
readonly original: string;
|
|
273
286
|
code: string;
|
|
274
287
|
id?: string;
|
|
275
|
-
extracted: Set<string>;
|
|
288
|
+
extracted: Set<string> | CountableSet<string>;
|
|
289
|
+
envMode?: 'dev' | 'build';
|
|
276
290
|
}
|
|
277
291
|
interface PreflightContext<Theme extends object = object> {
|
|
278
292
|
/**
|
|
@@ -292,7 +306,7 @@ interface Extractor {
|
|
|
292
306
|
*
|
|
293
307
|
* Return `undefined` to skip this extractor.
|
|
294
308
|
*/
|
|
295
|
-
extract?(ctx: ExtractorContext): Awaitable<Set<string> | string[] | undefined | void>;
|
|
309
|
+
extract?(ctx: ExtractorContext): Awaitable<Set<string> | CountableSet<string> | string[] | undefined | void>;
|
|
296
310
|
}
|
|
297
311
|
interface RuleMeta {
|
|
298
312
|
/**
|
|
@@ -860,12 +874,12 @@ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByK
|
|
|
860
874
|
};
|
|
861
875
|
separators: string[];
|
|
862
876
|
}
|
|
863
|
-
interface GenerateResult {
|
|
877
|
+
interface GenerateResult<T = Set<string>> {
|
|
864
878
|
css: string;
|
|
865
879
|
layers: string[];
|
|
866
880
|
getLayer(name?: string): string | undefined;
|
|
867
881
|
getLayers(includes?: string[], excludes?: string[]): string;
|
|
868
|
-
matched:
|
|
882
|
+
matched: T;
|
|
869
883
|
}
|
|
870
884
|
type VariantMatchedResult<Theme extends object = object> = readonly [
|
|
871
885
|
raw: string,
|
|
@@ -911,7 +925,20 @@ interface UtilObject {
|
|
|
911
925
|
sort: number | undefined;
|
|
912
926
|
noMerge: boolean | undefined;
|
|
913
927
|
}
|
|
914
|
-
|
|
928
|
+
/**
|
|
929
|
+
* Returned from `uno.generate()` when `extendedInfo` option is enabled.
|
|
930
|
+
*/
|
|
931
|
+
interface ExtendedTokenInfo<Theme extends object = object> {
|
|
932
|
+
/**
|
|
933
|
+
* Stringified util data
|
|
934
|
+
*/
|
|
935
|
+
data: StringifiedUtil<Theme>[];
|
|
936
|
+
/**
|
|
937
|
+
* Return -1 if the data structure is not countable
|
|
938
|
+
*/
|
|
939
|
+
count: number;
|
|
940
|
+
}
|
|
941
|
+
interface GenerateOptions<T extends boolean> {
|
|
915
942
|
/**
|
|
916
943
|
* Filepath of the file being processed.
|
|
917
944
|
*/
|
|
@@ -935,6 +962,10 @@ interface GenerateOptions {
|
|
|
935
962
|
* @experimental
|
|
936
963
|
*/
|
|
937
964
|
scope?: string;
|
|
965
|
+
/**
|
|
966
|
+
* If return extended "matched" with payload and count
|
|
967
|
+
*/
|
|
968
|
+
extendedInfo?: T;
|
|
938
969
|
}
|
|
939
970
|
|
|
940
971
|
declare const defaultSplitRE: RegExp;
|
|
@@ -956,4 +987,4 @@ declare function resolveConfig<Theme extends object = object>(userConfig?: UserC
|
|
|
956
987
|
*/
|
|
957
988
|
declare function mergeConfigs<Theme extends object = object>(configs: UserConfig<Theme>[]): UserConfig<Theme>;
|
|
958
989
|
|
|
959
|
-
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, HighlightAnnotation, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, ToArray, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
|
990
|
+
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, CountableSet, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtendedTokenInfo, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, HighlightAnnotation, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, ToArray, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, 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, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -209,6 +209,36 @@ class BetterMap extends Map {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
class CountableSet extends Set {
|
|
213
|
+
constructor(values) {
|
|
214
|
+
super(values);
|
|
215
|
+
this._map ?? (this._map = /* @__PURE__ */ new Map());
|
|
216
|
+
}
|
|
217
|
+
add(key) {
|
|
218
|
+
this._map ?? (this._map = /* @__PURE__ */ new Map());
|
|
219
|
+
this._map.set(key, (this._map.get(key) ?? 0) + 1);
|
|
220
|
+
return super.add(key);
|
|
221
|
+
}
|
|
222
|
+
delete(key) {
|
|
223
|
+
this._map.delete(key);
|
|
224
|
+
return super.delete(key);
|
|
225
|
+
}
|
|
226
|
+
clear() {
|
|
227
|
+
this._map.clear();
|
|
228
|
+
super.clear();
|
|
229
|
+
}
|
|
230
|
+
getCount(key) {
|
|
231
|
+
return this._map.get(key) ?? 0;
|
|
232
|
+
}
|
|
233
|
+
setCount(key, count) {
|
|
234
|
+
this._map.set(key, count);
|
|
235
|
+
return super.add(key);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function isCountableSet(value) {
|
|
239
|
+
return value instanceof CountableSet;
|
|
240
|
+
}
|
|
241
|
+
|
|
212
242
|
function withLayer(layer, rules) {
|
|
213
243
|
rules.forEach((r) => {
|
|
214
244
|
if (!r[2])
|
|
@@ -367,7 +397,7 @@ function createValueHandler(handlers) {
|
|
|
367
397
|
const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
|
|
368
398
|
const splitWithVariantGroupRE = /([\\:]?[\s"'`;<>]|:\(|\)"|\)\s)/g;
|
|
369
399
|
function splitCode(code) {
|
|
370
|
-
return
|
|
400
|
+
return code.split(defaultSplitRE);
|
|
371
401
|
}
|
|
372
402
|
const extractorSplit = {
|
|
373
403
|
name: "@unocss/core/extractor-split",
|
|
@@ -563,7 +593,7 @@ function mergeAutocompleteShorthands(shorthands) {
|
|
|
563
593
|
);
|
|
564
594
|
}
|
|
565
595
|
|
|
566
|
-
const version = "0.
|
|
596
|
+
const version = "0.55.1";
|
|
567
597
|
|
|
568
598
|
class UnoGenerator {
|
|
569
599
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -594,11 +624,17 @@ class UnoGenerator {
|
|
|
594
624
|
original: code,
|
|
595
625
|
code,
|
|
596
626
|
id,
|
|
597
|
-
extracted
|
|
627
|
+
extracted,
|
|
628
|
+
envMode: this.config.envMode
|
|
598
629
|
};
|
|
599
630
|
for (const extractor of this.config.extractors) {
|
|
600
631
|
const result = await extractor.extract?.(context);
|
|
601
|
-
if (result)
|
|
632
|
+
if (!result)
|
|
633
|
+
continue;
|
|
634
|
+
if (isCountableSet(result) && isCountableSet(extracted)) {
|
|
635
|
+
for (const token of result)
|
|
636
|
+
extracted.setCount(token, extracted.getCount(token) + result.getCount(token));
|
|
637
|
+
} else {
|
|
602
638
|
for (const token of result)
|
|
603
639
|
extracted.add(token);
|
|
604
640
|
}
|
|
@@ -654,14 +690,23 @@ class UnoGenerator {
|
|
|
654
690
|
scope,
|
|
655
691
|
preflights = true,
|
|
656
692
|
safelist = true,
|
|
657
|
-
minify = false
|
|
693
|
+
minify = false,
|
|
694
|
+
extendedInfo = false
|
|
658
695
|
} = options;
|
|
659
|
-
const tokens = isString(input) ? await this.applyExtractors(
|
|
660
|
-
|
|
661
|
-
|
|
696
|
+
const tokens = isString(input) ? await this.applyExtractors(
|
|
697
|
+
input,
|
|
698
|
+
id,
|
|
699
|
+
extendedInfo ? new CountableSet() : /* @__PURE__ */ new Set()
|
|
700
|
+
) : Array.isArray(input) ? new Set(input) : input;
|
|
701
|
+
if (safelist) {
|
|
702
|
+
this.config.safelist.forEach((s) => {
|
|
703
|
+
if (!tokens.has(s))
|
|
704
|
+
tokens.add(s);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
662
707
|
const nl = minify ? "" : "\n";
|
|
663
708
|
const layerSet = /* @__PURE__ */ new Set([LAYER_DEFAULT]);
|
|
664
|
-
const matched = /* @__PURE__ */ new Set();
|
|
709
|
+
const matched = extendedInfo ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Set();
|
|
665
710
|
const sheet = /* @__PURE__ */ new Map();
|
|
666
711
|
let preflightsMap = {};
|
|
667
712
|
const tokenPromises = Array.from(tokens).map(async (raw) => {
|
|
@@ -670,7 +715,14 @@ class UnoGenerator {
|
|
|
670
715
|
const payload = await this.parseToken(raw);
|
|
671
716
|
if (payload == null)
|
|
672
717
|
return;
|
|
673
|
-
matched
|
|
718
|
+
if (matched instanceof Map) {
|
|
719
|
+
matched.set(raw, {
|
|
720
|
+
data: payload,
|
|
721
|
+
count: isCountableSet(tokens) ? tokens.getCount(raw) : -1
|
|
722
|
+
});
|
|
723
|
+
} else {
|
|
724
|
+
matched.add(raw);
|
|
725
|
+
}
|
|
674
726
|
for (const item of payload) {
|
|
675
727
|
const parent = item[3] || "";
|
|
676
728
|
const layer = item[4]?.layer;
|
|
@@ -1050,4 +1102,4 @@ function defaultVariantHandler(input, next) {
|
|
|
1050
1102
|
return next(input);
|
|
1051
1103
|
}
|
|
1052
1104
|
|
|
1053
|
-
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|
|
1105
|
+
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, CountableSet, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, 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, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
|