@unocss/core 0.25.0 → 0.26.2
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 +31 -23
- package/dist/index.d.ts +120 -64
- package/dist/index.mjs +31 -24
- 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.2";
|
|
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,
|
|
@@ -712,11 +719,11 @@ class UnoGenerator {
|
|
|
712
719
|
function createGenerator(config, defaults) {
|
|
713
720
|
return new UnoGenerator(config, defaults);
|
|
714
721
|
}
|
|
715
|
-
const
|
|
716
|
-
const hasScopePlaceholder = (css) => css.match(
|
|
722
|
+
const regexScopePlaceholder = / \$\$ /;
|
|
723
|
+
const hasScopePlaceholder = (css) => css.match(regexScopePlaceholder);
|
|
717
724
|
function applyScope(css, scope) {
|
|
718
725
|
if (hasScopePlaceholder(css))
|
|
719
|
-
return css.replace(
|
|
726
|
+
return css.replace(regexScopePlaceholder, scope ? ` ${scope} ` : " ");
|
|
720
727
|
else
|
|
721
728
|
return scope ? `${scope} ${css}` : css;
|
|
722
729
|
}
|
|
@@ -757,6 +764,7 @@ exports.normalizeCSSValues = normalizeCSSValues;
|
|
|
757
764
|
exports.normalizeVariant = normalizeVariant;
|
|
758
765
|
exports.notNull = notNull;
|
|
759
766
|
exports.regexClassGroup = regexClassGroup;
|
|
767
|
+
exports.regexScopePlaceholder = regexScopePlaceholder;
|
|
760
768
|
exports.toArray = toArray;
|
|
761
769
|
exports.uniq = uniq;
|
|
762
770
|
exports.validateFilterRE = validateFilterRE;
|
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;
|
|
@@ -21,8 +24,71 @@ declare class UnoGenerator {
|
|
|
21
24
|
isBlocked(raw: string): boolean;
|
|
22
25
|
}
|
|
23
26
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
27
|
+
declare const regexScopePlaceholder: RegExp;
|
|
24
28
|
declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
|
|
25
29
|
|
|
30
|
+
declare function escapeRegExp(string: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* CSS Selector Escape
|
|
33
|
+
*/
|
|
34
|
+
declare function escapeSelector(str: string): string;
|
|
35
|
+
declare const e: typeof escapeSelector;
|
|
36
|
+
|
|
37
|
+
declare function normalizeCSSEntries(obj: CSSEntries | CSSObject): CSSEntries;
|
|
38
|
+
declare function normalizeCSSValues(obj: CSSValues): CSSEntries[];
|
|
39
|
+
declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
|
|
40
|
+
declare function entriesToCss(arr?: CSSEntries): string;
|
|
41
|
+
declare function isObject(item: any): item is Record<string, any>;
|
|
42
|
+
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
43
|
+
declare function clone<T>(val: T): T;
|
|
44
|
+
declare function isStaticRule(rule: Rule): rule is StaticRule;
|
|
45
|
+
declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
46
|
+
|
|
47
|
+
declare function toArray<T>(value?: T | T[]): T[];
|
|
48
|
+
declare function uniq<T>(value: T[]): T[];
|
|
49
|
+
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
50
|
+
|
|
51
|
+
declare const attributifyRE: RegExp;
|
|
52
|
+
declare const validateFilterRE: RegExp;
|
|
53
|
+
declare const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
|
|
54
|
+
declare function isAttributifySelector(selector: string): RegExpMatchArray | null;
|
|
55
|
+
declare function isValidSelector(selector?: string): selector is string;
|
|
56
|
+
declare function normalizeVariant(variant: Variant): VariantObject;
|
|
57
|
+
declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil;
|
|
58
|
+
declare function notNull<T>(value: T | null | undefined): value is T;
|
|
59
|
+
|
|
60
|
+
declare class TwoKeyMap<K1, K2, V> {
|
|
61
|
+
_map: Map<K1, Map<K2, V>>;
|
|
62
|
+
get(key1: K1, key2: K2): V | undefined;
|
|
63
|
+
getFallback(key1: K1, key2: K2, fallback: V): V;
|
|
64
|
+
set(key1: K1, key2: K2, value: V): this;
|
|
65
|
+
has(key1: K1, key2: K2): boolean | undefined;
|
|
66
|
+
delete(key1: K1, key2: K2): boolean;
|
|
67
|
+
deleteTop(key1: K1): boolean;
|
|
68
|
+
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
69
|
+
}
|
|
70
|
+
declare class BetterMap<K, V> extends Map<K, V> {
|
|
71
|
+
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
75
|
+
|
|
76
|
+
declare const regexClassGroup: RegExp;
|
|
77
|
+
declare function expandVariantGroup(str: string): string;
|
|
78
|
+
|
|
79
|
+
declare function warnOnce(msg: string): void;
|
|
80
|
+
|
|
81
|
+
declare type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
82
|
+
declare type ValueHandler<K extends string> = {
|
|
83
|
+
[S in K]: ValueHandler<K>;
|
|
84
|
+
} & {
|
|
85
|
+
(str: string): string | undefined;
|
|
86
|
+
__options: {
|
|
87
|
+
sequence: K[];
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
|
|
91
|
+
|
|
26
92
|
declare type Awaitable<T> = T | Promise<T>;
|
|
27
93
|
declare type Arrayable<T> = T | T[];
|
|
28
94
|
declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
@@ -93,6 +159,10 @@ interface RuleContext<Theme extends {} = {}> {
|
|
|
93
159
|
* Matched variants handlers for this rule.
|
|
94
160
|
*/
|
|
95
161
|
variantHandlers: VariantHandler[];
|
|
162
|
+
/**
|
|
163
|
+
* The result of variant matching.
|
|
164
|
+
*/
|
|
165
|
+
variantMatch: VariantMatchedResult;
|
|
96
166
|
/**
|
|
97
167
|
* Constrcut a custom CSS rule.
|
|
98
168
|
* Variants and selector escaping will be handled automatically.
|
|
@@ -310,6 +380,48 @@ interface UserOnlyOptions<Theme extends {} = {}> {
|
|
|
310
380
|
*/
|
|
311
381
|
envMode?: 'dev' | 'build';
|
|
312
382
|
}
|
|
383
|
+
interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
|
|
384
|
+
ready: Promise<LoadConfigResult<Config>>;
|
|
385
|
+
uno: UnoGenerator;
|
|
386
|
+
tokens: Set<string>;
|
|
387
|
+
modules: BetterMap<string, string>;
|
|
388
|
+
filter: (code: string, id: string) => boolean;
|
|
389
|
+
extract: (code: string, id?: string) => Promise<void>;
|
|
390
|
+
reloadConfig: () => Promise<LoadConfigResult<Config>>;
|
|
391
|
+
getConfig: () => Promise<Config>;
|
|
392
|
+
invalidate: () => void;
|
|
393
|
+
onInvalidate: (fn: () => void) => void;
|
|
394
|
+
}
|
|
395
|
+
interface SourceMap {
|
|
396
|
+
file?: string;
|
|
397
|
+
mappings?: string;
|
|
398
|
+
names?: string[];
|
|
399
|
+
sources?: string[];
|
|
400
|
+
sourcesContent?: string[];
|
|
401
|
+
version?: number;
|
|
402
|
+
}
|
|
403
|
+
interface TransformResult {
|
|
404
|
+
code: string;
|
|
405
|
+
map?: SourceMap | null;
|
|
406
|
+
etag?: string;
|
|
407
|
+
deps?: string[];
|
|
408
|
+
dynamicDeps?: string[];
|
|
409
|
+
}
|
|
410
|
+
interface SourceCodeTransformer {
|
|
411
|
+
name: string;
|
|
412
|
+
/**
|
|
413
|
+
* The order of transformer
|
|
414
|
+
*/
|
|
415
|
+
enforce?: 'pre' | 'post';
|
|
416
|
+
/**
|
|
417
|
+
* Custom id filter, if not provided, the extraction filter will be applied
|
|
418
|
+
*/
|
|
419
|
+
idFilter?: (id: string) => boolean;
|
|
420
|
+
/**
|
|
421
|
+
* The transform function
|
|
422
|
+
*/
|
|
423
|
+
transform: (code: string, id: string, ctx: UnocssPluginContext) => Awaitable<string | TransformResult | null | undefined>;
|
|
424
|
+
}
|
|
313
425
|
/**
|
|
314
426
|
* For other modules to aggregate the options
|
|
315
427
|
*/
|
|
@@ -332,6 +444,12 @@ interface PluginOptions {
|
|
|
332
444
|
* Patterns that filter the files NOT being extracted.
|
|
333
445
|
*/
|
|
334
446
|
exclude?: FilterPattern;
|
|
447
|
+
/**
|
|
448
|
+
* Custom transformers to the source code
|
|
449
|
+
*
|
|
450
|
+
* Currently only supported in Vite
|
|
451
|
+
*/
|
|
452
|
+
transformers?: SourceCodeTransformer[];
|
|
335
453
|
}
|
|
336
454
|
interface UserConfig<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions {
|
|
337
455
|
}
|
|
@@ -410,70 +528,8 @@ interface GenerateOptions {
|
|
|
410
528
|
scope?: string;
|
|
411
529
|
}
|
|
412
530
|
|
|
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
531
|
declare const extractorSplit: Extractor;
|
|
476
532
|
|
|
477
533
|
declare const extractorSvelte: Extractor;
|
|
478
534
|
|
|
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 };
|
|
535
|
+
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, regexScopePlaceholder, 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.2";
|
|
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,
|
|
@@ -708,11 +715,11 @@ class UnoGenerator {
|
|
|
708
715
|
function createGenerator(config, defaults) {
|
|
709
716
|
return new UnoGenerator(config, defaults);
|
|
710
717
|
}
|
|
711
|
-
const
|
|
712
|
-
const hasScopePlaceholder = (css) => css.match(
|
|
718
|
+
const regexScopePlaceholder = / \$\$ /;
|
|
719
|
+
const hasScopePlaceholder = (css) => css.match(regexScopePlaceholder);
|
|
713
720
|
function applyScope(css, scope) {
|
|
714
721
|
if (hasScopePlaceholder(css))
|
|
715
|
-
return css.replace(
|
|
722
|
+
return css.replace(regexScopePlaceholder, scope ? ` ${scope} ` : " ");
|
|
716
723
|
else
|
|
717
724
|
return scope ? `${scope} ${css}` : css;
|
|
718
725
|
}
|
|
@@ -723,4 +730,4 @@ function toEscapedSelector(raw) {
|
|
|
723
730
|
return `.${e(raw)}`;
|
|
724
731
|
}
|
|
725
732
|
|
|
726
|
-
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, 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 };
|
|
733
|
+
export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, 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, regexScopePlaceholder, toArray, uniq, validateFilterRE, warnOnce, withLayer };
|