@unocss/core 0.24.4 → 0.26.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 +44 -34
- package/dist/index.d.ts +119 -64
- package/dist/index.mjs +44 -34
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -366,7 +366,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
366
366
|
};
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
const version = "0.
|
|
369
|
+
const version = "0.26.1";
|
|
370
370
|
|
|
371
371
|
class UnoGenerator {
|
|
372
372
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -403,48 +403,55 @@ class UnoGenerator {
|
|
|
403
403
|
}
|
|
404
404
|
return set;
|
|
405
405
|
}
|
|
406
|
-
|
|
406
|
+
makeContext(raw, applied) {
|
|
407
|
+
const context = {
|
|
408
|
+
rawSelector: raw,
|
|
409
|
+
currentSelector: applied[1],
|
|
410
|
+
theme: this.config.theme,
|
|
411
|
+
generator: this,
|
|
412
|
+
variantHandlers: applied[2],
|
|
413
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
414
|
+
variantMatch: applied
|
|
415
|
+
};
|
|
416
|
+
return context;
|
|
417
|
+
}
|
|
418
|
+
async parseToken(raw, alias) {
|
|
407
419
|
if (this.blocked.has(raw))
|
|
408
420
|
return;
|
|
409
|
-
|
|
410
|
-
|
|
421
|
+
const cacheKey = `${raw}${alias ? ` ${alias}` : ""}`;
|
|
422
|
+
const cached = this._cache.get(cacheKey);
|
|
423
|
+
if (cached)
|
|
424
|
+
return cached;
|
|
411
425
|
let current = raw;
|
|
412
426
|
for (const p of this.config.preprocess)
|
|
413
427
|
current = p(raw);
|
|
414
428
|
if (this.isBlocked(current)) {
|
|
415
429
|
this.blocked.add(raw);
|
|
416
|
-
this._cache.set(
|
|
430
|
+
this._cache.set(cacheKey, null);
|
|
417
431
|
return;
|
|
418
432
|
}
|
|
419
433
|
const applied = this.matchVariants(raw, current);
|
|
420
434
|
if (!applied || this.isBlocked(applied[1])) {
|
|
421
435
|
this.blocked.add(raw);
|
|
422
|
-
this._cache.set(
|
|
436
|
+
this._cache.set(cacheKey, null);
|
|
423
437
|
return;
|
|
424
438
|
}
|
|
425
|
-
const context =
|
|
426
|
-
|
|
427
|
-
currentSelector: applied[1],
|
|
428
|
-
theme: this.config.theme,
|
|
429
|
-
generator: this,
|
|
430
|
-
variantHandlers: applied[2],
|
|
431
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
432
|
-
};
|
|
433
|
-
const expanded = this.expandShortcut(applied[1], context);
|
|
439
|
+
const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2]]);
|
|
440
|
+
const expanded = this.expandShortcut(context.currentSelector, context);
|
|
434
441
|
if (expanded) {
|
|
435
|
-
const utils = await this.stringifyShortcuts(
|
|
442
|
+
const utils = await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]);
|
|
436
443
|
if (utils?.length) {
|
|
437
|
-
this._cache.set(
|
|
444
|
+
this._cache.set(cacheKey, utils);
|
|
438
445
|
return utils;
|
|
439
446
|
}
|
|
440
447
|
} else {
|
|
441
|
-
const utils = (await this.parseUtil(
|
|
448
|
+
const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
442
449
|
if (utils?.length) {
|
|
443
|
-
this._cache.set(
|
|
450
|
+
this._cache.set(cacheKey, utils);
|
|
444
451
|
return utils;
|
|
445
452
|
}
|
|
446
453
|
}
|
|
447
|
-
this._cache.set(
|
|
454
|
+
this._cache.set(cacheKey, null);
|
|
448
455
|
}
|
|
449
456
|
async generate(input, {
|
|
450
457
|
id,
|
|
@@ -680,26 +687,29 @@ class UnoGenerator {
|
|
|
680
687
|
for (const item of parsed) {
|
|
681
688
|
if (isRawUtil(item))
|
|
682
689
|
continue;
|
|
683
|
-
const { selector, entries, parent: parent2 } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
690
|
+
const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
684
691
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
685
|
-
mapItem[0].push([entries, !!item[3]?.noMerge]);
|
|
692
|
+
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
686
693
|
}
|
|
687
694
|
return selectorMap.map(([e2, index], selector, mediaQuery) => {
|
|
688
|
-
const stringify = (noMerge
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
695
|
+
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
696
|
+
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
697
|
+
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
698
|
+
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
699
|
+
const body = entriesToCss(entries);
|
|
700
|
+
if (body)
|
|
701
|
+
return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }];
|
|
702
|
+
return void 0;
|
|
703
|
+
});
|
|
693
704
|
};
|
|
694
705
|
const merges = [
|
|
695
|
-
[e2.filter(([, noMerge]) => noMerge).map(([entries]) => entries), true],
|
|
696
|
-
[e2.filter(([, noMerge]) => !noMerge).map(([entries]) => entries), false]
|
|
706
|
+
[e2.filter(([, noMerge]) => noMerge).map(([entries, , sort]) => [entries, sort]), true],
|
|
707
|
+
[e2.filter(([, noMerge]) => !noMerge).map(([entries, , sort]) => [entries, sort]), false]
|
|
697
708
|
];
|
|
698
|
-
return merges.map(([e3, noMerge]) =>
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
});
|
|
709
|
+
return merges.map(([e3, noMerge]) => [
|
|
710
|
+
...stringify(false, noMerge, e3.filter(([entries]) => entries.some((entry) => entry[0] === CONTROL_SHORTCUT_NO_MERGE))),
|
|
711
|
+
...stringify(true, noMerge, e3.filter(([entries]) => entries.every((entry) => entry[0] !== CONTROL_SHORTCUT_NO_MERGE)))
|
|
712
|
+
]);
|
|
703
713
|
}).flat(2).filter(Boolean);
|
|
704
714
|
}
|
|
705
715
|
isBlocked(raw) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LoadConfigResult } from 'unconfig';
|
|
2
|
+
|
|
1
3
|
declare class UnoGenerator {
|
|
2
4
|
userConfig: UserConfig;
|
|
3
5
|
defaults: UserConfigDefaults;
|
|
@@ -9,7 +11,8 @@ declare class UnoGenerator {
|
|
|
9
11
|
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults);
|
|
10
12
|
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void;
|
|
11
13
|
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>;
|
|
12
|
-
|
|
14
|
+
makeContext(raw: string, applied: VariantMatchedResult): RuleContext<{}>;
|
|
15
|
+
parseToken(raw: string, alias?: string): Promise<StringifiedUtil[] | undefined>;
|
|
13
16
|
generate(input: string | Set<string>, { id, scope, preflights, safelist, minify, }?: GenerateOptions): Promise<GenerateResult>;
|
|
14
17
|
matchVariants(raw: string, current?: string): VariantMatchedResult;
|
|
15
18
|
applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): UtilObject;
|
|
@@ -23,6 +26,68 @@ declare class UnoGenerator {
|
|
|
23
26
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
24
27
|
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
|
|
25
28
|
|
|
29
|
+
declare function escapeRegExp(string: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* CSS Selector Escape
|
|
32
|
+
*/
|
|
33
|
+
declare function escapeSelector(str: string): string;
|
|
34
|
+
declare const e: typeof escapeSelector;
|
|
35
|
+
|
|
36
|
+
declare function normalizeCSSEntries(obj: CSSEntries | CSSObject): CSSEntries;
|
|
37
|
+
declare function normalizeCSSValues(obj: CSSValues): CSSEntries[];
|
|
38
|
+
declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
|
|
39
|
+
declare function entriesToCss(arr?: CSSEntries): string;
|
|
40
|
+
declare function isObject(item: any): item is Record<string, any>;
|
|
41
|
+
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
42
|
+
declare function clone<T>(val: T): T;
|
|
43
|
+
declare function isStaticRule(rule: Rule): rule is StaticRule;
|
|
44
|
+
declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
45
|
+
|
|
46
|
+
declare function toArray<T>(value?: T | T[]): T[];
|
|
47
|
+
declare function uniq<T>(value: T[]): T[];
|
|
48
|
+
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
49
|
+
|
|
50
|
+
declare const attributifyRE: RegExp;
|
|
51
|
+
declare const validateFilterRE: RegExp;
|
|
52
|
+
declare const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
53
|
+
declare function isAttributifySelector(selector: string): RegExpMatchArray | null;
|
|
54
|
+
declare function isValidSelector(selector?: string): selector is string;
|
|
55
|
+
declare function normalizeVariant(variant: Variant): VariantObject;
|
|
56
|
+
declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil;
|
|
57
|
+
declare function notNull<T>(value: T | null | undefined): value is T;
|
|
58
|
+
|
|
59
|
+
declare class TwoKeyMap<K1, K2, V> {
|
|
60
|
+
_map: Map<K1, Map<K2, V>>;
|
|
61
|
+
get(key1: K1, key2: K2): V | undefined;
|
|
62
|
+
getFallback(key1: K1, key2: K2, fallback: V): V;
|
|
63
|
+
set(key1: K1, key2: K2, value: V): this;
|
|
64
|
+
has(key1: K1, key2: K2): boolean | undefined;
|
|
65
|
+
delete(key1: K1, key2: K2): boolean;
|
|
66
|
+
deleteTop(key1: K1): boolean;
|
|
67
|
+
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
68
|
+
}
|
|
69
|
+
declare class BetterMap<K, V> extends Map<K, V> {
|
|
70
|
+
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
74
|
+
|
|
75
|
+
declare const regexClassGroup: RegExp;
|
|
76
|
+
declare function expandVariantGroup(str: string): string;
|
|
77
|
+
|
|
78
|
+
declare function warnOnce(msg: string): void;
|
|
79
|
+
|
|
80
|
+
declare type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
81
|
+
declare type ValueHandler<K extends string> = {
|
|
82
|
+
[S in K]: ValueHandler<K>;
|
|
83
|
+
} & {
|
|
84
|
+
(str: string): string | undefined;
|
|
85
|
+
__options: {
|
|
86
|
+
sequence: K[];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
|
|
90
|
+
|
|
26
91
|
declare type Awaitable<T> = T | Promise<T>;
|
|
27
92
|
declare type Arrayable<T> = T | T[];
|
|
28
93
|
declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
@@ -93,6 +158,10 @@ interface RuleContext<Theme extends {} = {}> {
|
|
|
93
158
|
* Matched variants handlers for this rule.
|
|
94
159
|
*/
|
|
95
160
|
variantHandlers: VariantHandler[];
|
|
161
|
+
/**
|
|
162
|
+
* The result of variant matching.
|
|
163
|
+
*/
|
|
164
|
+
variantMatch: VariantMatchedResult;
|
|
96
165
|
/**
|
|
97
166
|
* Constrcut a custom CSS rule.
|
|
98
167
|
* Variants and selector escaping will be handled automatically.
|
|
@@ -310,6 +379,48 @@ interface UserOnlyOptions<Theme extends {} = {}> {
|
|
|
310
379
|
*/
|
|
311
380
|
envMode?: 'dev' | 'build';
|
|
312
381
|
}
|
|
382
|
+
interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
|
|
383
|
+
ready: Promise<LoadConfigResult<Config>>;
|
|
384
|
+
uno: UnoGenerator;
|
|
385
|
+
tokens: Set<string>;
|
|
386
|
+
modules: BetterMap<string, string>;
|
|
387
|
+
filter: (code: string, id: string) => boolean;
|
|
388
|
+
extract: (code: string, id?: string) => Promise<void>;
|
|
389
|
+
reloadConfig: () => Promise<LoadConfigResult<Config>>;
|
|
390
|
+
getConfig: () => Promise<Config>;
|
|
391
|
+
invalidate: () => void;
|
|
392
|
+
onInvalidate: (fn: () => void) => void;
|
|
393
|
+
}
|
|
394
|
+
interface SourceMap {
|
|
395
|
+
file?: string;
|
|
396
|
+
mappings?: string;
|
|
397
|
+
names?: string[];
|
|
398
|
+
sources?: string[];
|
|
399
|
+
sourcesContent?: string[];
|
|
400
|
+
version?: number;
|
|
401
|
+
}
|
|
402
|
+
interface TransformResult {
|
|
403
|
+
code: string;
|
|
404
|
+
map?: SourceMap | null;
|
|
405
|
+
etag?: string;
|
|
406
|
+
deps?: string[];
|
|
407
|
+
dynamicDeps?: string[];
|
|
408
|
+
}
|
|
409
|
+
interface SourceCodeTransformer {
|
|
410
|
+
name: string;
|
|
411
|
+
/**
|
|
412
|
+
* The order of transformer
|
|
413
|
+
*/
|
|
414
|
+
enforce?: 'pre' | 'post';
|
|
415
|
+
/**
|
|
416
|
+
* Custom id filter, if not provided, the extraction filter will be applied
|
|
417
|
+
*/
|
|
418
|
+
idFilter?: (id: string) => boolean;
|
|
419
|
+
/**
|
|
420
|
+
* The transform function
|
|
421
|
+
*/
|
|
422
|
+
transform: (code: string, id: string, ctx: UnocssPluginContext) => Awaitable<string | TransformResult | null | undefined>;
|
|
423
|
+
}
|
|
313
424
|
/**
|
|
314
425
|
* For other modules to aggregate the options
|
|
315
426
|
*/
|
|
@@ -332,6 +443,12 @@ interface PluginOptions {
|
|
|
332
443
|
* Patterns that filter the files NOT being extracted.
|
|
333
444
|
*/
|
|
334
445
|
exclude?: FilterPattern;
|
|
446
|
+
/**
|
|
447
|
+
* Custom transformers to the source code
|
|
448
|
+
*
|
|
449
|
+
* Currently only supported in Vite
|
|
450
|
+
*/
|
|
451
|
+
transformers?: SourceCodeTransformer[];
|
|
335
452
|
}
|
|
336
453
|
interface UserConfig<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions {
|
|
337
454
|
}
|
|
@@ -410,70 +527,8 @@ interface GenerateOptions {
|
|
|
410
527
|
scope?: string;
|
|
411
528
|
}
|
|
412
529
|
|
|
413
|
-
declare function escapeRegExp(string: string): string;
|
|
414
|
-
/**
|
|
415
|
-
* CSS Selector Escape
|
|
416
|
-
*/
|
|
417
|
-
declare function escapeSelector(str: string): string;
|
|
418
|
-
declare const e: typeof escapeSelector;
|
|
419
|
-
|
|
420
|
-
declare function normalizeCSSEntries(obj: CSSEntries | CSSObject): CSSEntries;
|
|
421
|
-
declare function normalizeCSSValues(obj: CSSValues): CSSEntries[];
|
|
422
|
-
declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
|
|
423
|
-
declare function entriesToCss(arr?: CSSEntries): string;
|
|
424
|
-
declare function isObject(item: any): item is Record<string, any>;
|
|
425
|
-
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
426
|
-
declare function clone<T>(val: T): T;
|
|
427
|
-
declare function isStaticRule(rule: Rule): rule is StaticRule;
|
|
428
|
-
declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
429
|
-
|
|
430
|
-
declare function toArray<T>(value?: T | T[]): T[];
|
|
431
|
-
declare function uniq<T>(value: T[]): T[];
|
|
432
|
-
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
433
|
-
|
|
434
|
-
declare const attributifyRE: RegExp;
|
|
435
|
-
declare const validateFilterRE: RegExp;
|
|
436
|
-
declare const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
437
|
-
declare function isAttributifySelector(selector: string): RegExpMatchArray | null;
|
|
438
|
-
declare function isValidSelector(selector?: string): selector is string;
|
|
439
|
-
declare function normalizeVariant(variant: Variant): VariantObject;
|
|
440
|
-
declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil;
|
|
441
|
-
declare function notNull<T>(value: T | null | undefined): value is T;
|
|
442
|
-
|
|
443
|
-
declare class TwoKeyMap<K1, K2, V> {
|
|
444
|
-
_map: Map<K1, Map<K2, V>>;
|
|
445
|
-
get(key1: K1, key2: K2): V | undefined;
|
|
446
|
-
getFallback(key1: K1, key2: K2, fallback: V): V;
|
|
447
|
-
set(key1: K1, key2: K2, value: V): this;
|
|
448
|
-
has(key1: K1, key2: K2): boolean | undefined;
|
|
449
|
-
delete(key1: K1, key2: K2): boolean;
|
|
450
|
-
deleteTop(key1: K1): boolean;
|
|
451
|
-
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
452
|
-
}
|
|
453
|
-
declare class BetterMap<K, V> extends Map<K, V> {
|
|
454
|
-
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
458
|
-
|
|
459
|
-
declare const regexClassGroup: RegExp;
|
|
460
|
-
declare function expandVariantGroup(str: string): string;
|
|
461
|
-
|
|
462
|
-
declare function warnOnce(msg: string): void;
|
|
463
|
-
|
|
464
|
-
declare type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
465
|
-
declare type ValueHandler<K extends string> = {
|
|
466
|
-
[S in K]: ValueHandler<K>;
|
|
467
|
-
} & {
|
|
468
|
-
(str: string): string | undefined;
|
|
469
|
-
__options: {
|
|
470
|
-
sequence: K[];
|
|
471
|
-
};
|
|
472
|
-
};
|
|
473
|
-
declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
|
|
474
|
-
|
|
475
530
|
declare const extractorSplit: Extractor;
|
|
476
531
|
|
|
477
532
|
declare const extractorSvelte: Extractor;
|
|
478
533
|
|
|
479
|
-
export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, ThemeExtender, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
|
534
|
+
export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|
package/dist/index.mjs
CHANGED
|
@@ -362,7 +362,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
362
362
|
};
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
const version = "0.
|
|
365
|
+
const version = "0.26.1";
|
|
366
366
|
|
|
367
367
|
class UnoGenerator {
|
|
368
368
|
constructor(userConfig = {}, defaults = {}) {
|
|
@@ -399,48 +399,55 @@ class UnoGenerator {
|
|
|
399
399
|
}
|
|
400
400
|
return set;
|
|
401
401
|
}
|
|
402
|
-
|
|
402
|
+
makeContext(raw, applied) {
|
|
403
|
+
const context = {
|
|
404
|
+
rawSelector: raw,
|
|
405
|
+
currentSelector: applied[1],
|
|
406
|
+
theme: this.config.theme,
|
|
407
|
+
generator: this,
|
|
408
|
+
variantHandlers: applied[2],
|
|
409
|
+
constructCSS: (...args) => this.constructCustomCSS(context, ...args),
|
|
410
|
+
variantMatch: applied
|
|
411
|
+
};
|
|
412
|
+
return context;
|
|
413
|
+
}
|
|
414
|
+
async parseToken(raw, alias) {
|
|
403
415
|
if (this.blocked.has(raw))
|
|
404
416
|
return;
|
|
405
|
-
|
|
406
|
-
|
|
417
|
+
const cacheKey = `${raw}${alias ? ` ${alias}` : ""}`;
|
|
418
|
+
const cached = this._cache.get(cacheKey);
|
|
419
|
+
if (cached)
|
|
420
|
+
return cached;
|
|
407
421
|
let current = raw;
|
|
408
422
|
for (const p of this.config.preprocess)
|
|
409
423
|
current = p(raw);
|
|
410
424
|
if (this.isBlocked(current)) {
|
|
411
425
|
this.blocked.add(raw);
|
|
412
|
-
this._cache.set(
|
|
426
|
+
this._cache.set(cacheKey, null);
|
|
413
427
|
return;
|
|
414
428
|
}
|
|
415
429
|
const applied = this.matchVariants(raw, current);
|
|
416
430
|
if (!applied || this.isBlocked(applied[1])) {
|
|
417
431
|
this.blocked.add(raw);
|
|
418
|
-
this._cache.set(
|
|
432
|
+
this._cache.set(cacheKey, null);
|
|
419
433
|
return;
|
|
420
434
|
}
|
|
421
|
-
const context =
|
|
422
|
-
|
|
423
|
-
currentSelector: applied[1],
|
|
424
|
-
theme: this.config.theme,
|
|
425
|
-
generator: this,
|
|
426
|
-
variantHandlers: applied[2],
|
|
427
|
-
constructCSS: (...args) => this.constructCustomCSS(context, ...args)
|
|
428
|
-
};
|
|
429
|
-
const expanded = this.expandShortcut(applied[1], context);
|
|
435
|
+
const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2]]);
|
|
436
|
+
const expanded = this.expandShortcut(context.currentSelector, context);
|
|
430
437
|
if (expanded) {
|
|
431
|
-
const utils = await this.stringifyShortcuts(
|
|
438
|
+
const utils = await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]);
|
|
432
439
|
if (utils?.length) {
|
|
433
|
-
this._cache.set(
|
|
440
|
+
this._cache.set(cacheKey, utils);
|
|
434
441
|
return utils;
|
|
435
442
|
}
|
|
436
443
|
} else {
|
|
437
|
-
const utils = (await this.parseUtil(
|
|
444
|
+
const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
|
|
438
445
|
if (utils?.length) {
|
|
439
|
-
this._cache.set(
|
|
446
|
+
this._cache.set(cacheKey, utils);
|
|
440
447
|
return utils;
|
|
441
448
|
}
|
|
442
449
|
}
|
|
443
|
-
this._cache.set(
|
|
450
|
+
this._cache.set(cacheKey, null);
|
|
444
451
|
}
|
|
445
452
|
async generate(input, {
|
|
446
453
|
id,
|
|
@@ -676,26 +683,29 @@ class UnoGenerator {
|
|
|
676
683
|
for (const item of parsed) {
|
|
677
684
|
if (isRawUtil(item))
|
|
678
685
|
continue;
|
|
679
|
-
const { selector, entries, parent: parent2 } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
686
|
+
const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
|
|
680
687
|
const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
|
|
681
|
-
mapItem[0].push([entries, !!item[3]?.noMerge]);
|
|
688
|
+
mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
|
|
682
689
|
}
|
|
683
690
|
return selectorMap.map(([e2, index], selector, mediaQuery) => {
|
|
684
|
-
const stringify = (noMerge
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
691
|
+
const stringify = (flatten, noMerge, entrySortPair) => {
|
|
692
|
+
const maxSort = Math.max(...entrySortPair.map((e3) => e3[1]));
|
|
693
|
+
const entriesList = entrySortPair.map((e3) => e3[0]);
|
|
694
|
+
return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
|
|
695
|
+
const body = entriesToCss(entries);
|
|
696
|
+
if (body)
|
|
697
|
+
return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }];
|
|
698
|
+
return void 0;
|
|
699
|
+
});
|
|
689
700
|
};
|
|
690
701
|
const merges = [
|
|
691
|
-
[e2.filter(([, noMerge]) => noMerge).map(([entries]) => entries), true],
|
|
692
|
-
[e2.filter(([, noMerge]) => !noMerge).map(([entries]) => entries), false]
|
|
702
|
+
[e2.filter(([, noMerge]) => noMerge).map(([entries, , sort]) => [entries, sort]), true],
|
|
703
|
+
[e2.filter(([, noMerge]) => !noMerge).map(([entries, , sort]) => [entries, sort]), false]
|
|
693
704
|
];
|
|
694
|
-
return merges.map(([e3, noMerge]) =>
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
});
|
|
705
|
+
return merges.map(([e3, noMerge]) => [
|
|
706
|
+
...stringify(false, noMerge, e3.filter(([entries]) => entries.some((entry) => entry[0] === CONTROL_SHORTCUT_NO_MERGE))),
|
|
707
|
+
...stringify(true, noMerge, e3.filter(([entries]) => entries.every((entry) => entry[0] !== CONTROL_SHORTCUT_NO_MERGE)))
|
|
708
|
+
]);
|
|
699
709
|
}).flat(2).filter(Boolean);
|
|
700
710
|
}
|
|
701
711
|
isBlocked(raw) {
|