@unocss/core 0.64.0 → 0.65.0-beta.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.d.mts +22 -13
- package/dist/index.d.ts +22 -13
- package/dist/index.mjs +192 -138
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -133,7 +133,7 @@ declare function expandVariantGroup(str: MagicString, separators?: string[], dep
|
|
|
133
133
|
declare function warnOnce(msg: string): void;
|
|
134
134
|
|
|
135
135
|
declare const symbols: ControlSymbols;
|
|
136
|
-
declare class
|
|
136
|
+
declare class UnoGeneratorInternal<Theme extends object = object> {
|
|
137
137
|
userConfig: UserConfig<Theme>;
|
|
138
138
|
defaults: UserConfigDefaults<Theme>;
|
|
139
139
|
version: string;
|
|
@@ -144,15 +144,16 @@ declare class UnoGenerator<Theme extends object = object> {
|
|
|
144
144
|
events: Emitter<{
|
|
145
145
|
config: (config: ResolvedConfig<Theme>) => void;
|
|
146
146
|
}>;
|
|
147
|
-
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
148
|
-
|
|
147
|
+
protected constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
148
|
+
static create<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<UnoGeneratorInternal<Theme>>;
|
|
149
|
+
setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<void>;
|
|
149
150
|
applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
|
|
150
151
|
applyExtractors(code: string, id?: string, extracted?: CountableSet<string>): Promise<CountableSet<string>>;
|
|
151
152
|
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
152
153
|
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
|
|
153
154
|
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<false>): Promise<GenerateResult<Set<string>>>;
|
|
154
155
|
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<true>): Promise<GenerateResult<Map<string, ExtendedTokenInfo<Theme>>>>;
|
|
155
|
-
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme
|
|
156
|
+
matchVariants(raw: string, current?: string): Promise<readonly VariantMatchedResult<Theme>[]>;
|
|
156
157
|
private applyVariants;
|
|
157
158
|
constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
158
159
|
parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
@@ -162,7 +163,13 @@ declare class UnoGenerator<Theme extends object = object> {
|
|
|
162
163
|
isBlocked(raw: string): boolean;
|
|
163
164
|
getBlocked(raw: string): [BlocklistValue, BlocklistMeta | undefined] | undefined;
|
|
164
165
|
}
|
|
165
|
-
declare
|
|
166
|
+
declare class UnoGenerator<Theme extends object = object> extends UnoGeneratorInternal<Theme> {
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
|
|
169
|
+
*/
|
|
170
|
+
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
171
|
+
}
|
|
172
|
+
declare function createGenerator<Theme extends object = object>(config?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<UnoGenerator<Theme>>;
|
|
166
173
|
declare const regexScopePlaceholder: RegExp;
|
|
167
174
|
declare function hasScopePlaceholder(css: string): boolean;
|
|
168
175
|
declare function toEscapedSelector(raw: string): string;
|
|
@@ -452,7 +459,7 @@ interface VariantHandler {
|
|
|
452
459
|
*/
|
|
453
460
|
layer?: string | undefined;
|
|
454
461
|
}
|
|
455
|
-
type VariantFunction<Theme extends object = object> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | undefined>;
|
|
462
|
+
type VariantFunction<Theme extends object = object> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | VariantHandler[] | undefined>;
|
|
456
463
|
interface VariantObject<Theme extends object = object> {
|
|
457
464
|
/**
|
|
458
465
|
* The name of the variant.
|
|
@@ -571,7 +578,7 @@ interface ConfigBase<Theme extends object = object> {
|
|
|
571
578
|
/**
|
|
572
579
|
* Presets
|
|
573
580
|
*/
|
|
574
|
-
presets?: (
|
|
581
|
+
presets?: (PresetOrFactoryAwaitable<Theme> | PresetOrFactoryAwaitable<Theme>[])[];
|
|
575
582
|
/**
|
|
576
583
|
* Additional options for auto complete
|
|
577
584
|
*/
|
|
@@ -698,7 +705,9 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
|
|
|
698
705
|
api?: any;
|
|
699
706
|
}
|
|
700
707
|
type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
|
|
708
|
+
type PresetFactoryAwaitable<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Awaitable<Preset<Theme>>;
|
|
701
709
|
type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
|
|
710
|
+
type PresetOrFactoryAwaitable<Theme extends object = object> = PresetOrFactory<Theme> | Promise<Preset<Theme>> | PresetFactoryAwaitable<Theme>;
|
|
702
711
|
interface GeneratorOptions {
|
|
703
712
|
/**
|
|
704
713
|
* Merge utilities with the exact same body to save the file size
|
|
@@ -907,7 +916,7 @@ interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, U
|
|
|
907
916
|
}
|
|
908
917
|
interface UserConfigDefaults<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme> {
|
|
909
918
|
}
|
|
910
|
-
interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByKey<UserConfig<Theme>, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete'> {
|
|
919
|
+
interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByKey<UserConfig<Theme>, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete' | 'presets'> {
|
|
911
920
|
presets: Preset<Theme>[];
|
|
912
921
|
shortcuts: Shortcut<Theme>[];
|
|
913
922
|
variants: VariantObject<Theme>[];
|
|
@@ -931,7 +940,7 @@ interface GenerateResult<T = Set<string>> {
|
|
|
931
940
|
setLayer: (layer: string, callback: (content: string) => Promise<string>) => Promise<string>;
|
|
932
941
|
matched: T;
|
|
933
942
|
}
|
|
934
|
-
type VariantMatchedResult<Theme extends object = object> =
|
|
943
|
+
type VariantMatchedResult<Theme extends object = object> = [
|
|
935
944
|
raw: string,
|
|
936
945
|
current: string,
|
|
937
946
|
variantHandlers: VariantHandler[],
|
|
@@ -1022,12 +1031,12 @@ declare function resolveShortcuts<Theme extends object = object>(shortcuts: User
|
|
|
1022
1031
|
/**
|
|
1023
1032
|
* Resolve a single preset, nested presets are ignored
|
|
1024
1033
|
*/
|
|
1025
|
-
declare function resolvePreset<Theme extends object = object>(presetInput:
|
|
1034
|
+
declare function resolvePreset<Theme extends object = object>(presetInput: PresetOrFactoryAwaitable<Theme>): Promise<Preset<Theme>>;
|
|
1026
1035
|
/**
|
|
1027
1036
|
* Resolve presets with nested presets
|
|
1028
1037
|
*/
|
|
1029
|
-
declare function resolvePresets<Theme extends object = object>(preset:
|
|
1030
|
-
declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): ResolvedConfig<Theme
|
|
1038
|
+
declare function resolvePresets<Theme extends object = object>(preset: PresetOrFactoryAwaitable<Theme>): Promise<Preset<Theme>[]>;
|
|
1039
|
+
declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<ResolvedConfig<Theme>>;
|
|
1031
1040
|
/**
|
|
1032
1041
|
* Merge multiple configs into one, later ones have higher priority
|
|
1033
1042
|
*/
|
|
@@ -1039,4 +1048,4 @@ declare const defaultSplitRE: RegExp;
|
|
|
1039
1048
|
declare const splitWithVariantGroupRE: RegExp;
|
|
1040
1049
|
declare const extractorSplit: Extractor;
|
|
1041
1050
|
|
|
1042
|
-
export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistMeta, type BlocklistRule, type BlocklistValue, type CSSEntries, type CSSEntriesInput, type CSSEntry, type CSSObject, type CSSObjectInput, type CSSValue, type CSSValueInput, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, type ControlSymbols, type ControlSymbolsEntry, type ControlSymbolsValue, CountableSet, type DeepPartial, type DynamicMatcher, type DynamicRule, type DynamicShortcut, type DynamicShortcutMatcher, type ExtendedTokenInfo, type Extractor, type ExtractorContext, type FilterPattern, type FlatObjectTuple, type GenerateOptions, type GenerateResult, type GeneratorOptions, type HighlightAnnotation, type ObjectToEntry, type OutputCssLayersOptions, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetFactory, type PresetOptions, type PresetOrFactory, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, type SafeListContext, type Shift, type Shortcut, type ShortcutValue, type SourceCodeTransformer, type SourceCodeTransformerEnforce, type SourceMap, type StaticRule, type StaticShortcut, type StaticShortcutMap, type StringifiedUtil, type SuggestResult, type ThemeExtender, type ToArray, TwoKeyMap, UnoGenerator, type UnocssPluginContext, type UserConfig, type UserConfigDefaults, type UserOnlyOptions, type UserShortcuts, type UtilObject, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, 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 };
|
|
1051
|
+
export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistMeta, type BlocklistRule, type BlocklistValue, type CSSEntries, type CSSEntriesInput, type CSSEntry, type CSSObject, type CSSObjectInput, type CSSValue, type CSSValueInput, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, type ControlSymbols, type ControlSymbolsEntry, type ControlSymbolsValue, CountableSet, type DeepPartial, type DynamicMatcher, type DynamicRule, type DynamicShortcut, type DynamicShortcutMatcher, type ExtendedTokenInfo, type Extractor, type ExtractorContext, type FilterPattern, type FlatObjectTuple, type GenerateOptions, type GenerateResult, type GeneratorOptions, type HighlightAnnotation, type ObjectToEntry, type OutputCssLayersOptions, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetFactory, type PresetFactoryAwaitable, type PresetOptions, type PresetOrFactory, type PresetOrFactoryAwaitable, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, type SafeListContext, type Shift, type Shortcut, type ShortcutValue, type SourceCodeTransformer, type SourceCodeTransformerEnforce, type SourceMap, type StaticRule, type StaticShortcut, type StaticShortcutMap, type StringifiedUtil, type SuggestResult, type ThemeExtender, type ToArray, TwoKeyMap, UnoGenerator, type UnocssPluginContext, type UserConfig, type UserConfigDefaults, type UserOnlyOptions, type UserShortcuts, type UtilObject, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ declare function expandVariantGroup(str: MagicString, separators?: string[], dep
|
|
|
133
133
|
declare function warnOnce(msg: string): void;
|
|
134
134
|
|
|
135
135
|
declare const symbols: ControlSymbols;
|
|
136
|
-
declare class
|
|
136
|
+
declare class UnoGeneratorInternal<Theme extends object = object> {
|
|
137
137
|
userConfig: UserConfig<Theme>;
|
|
138
138
|
defaults: UserConfigDefaults<Theme>;
|
|
139
139
|
version: string;
|
|
@@ -144,15 +144,16 @@ declare class UnoGenerator<Theme extends object = object> {
|
|
|
144
144
|
events: Emitter<{
|
|
145
145
|
config: (config: ResolvedConfig<Theme>) => void;
|
|
146
146
|
}>;
|
|
147
|
-
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
148
|
-
|
|
147
|
+
protected constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
148
|
+
static create<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<UnoGeneratorInternal<Theme>>;
|
|
149
|
+
setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<void>;
|
|
149
150
|
applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
|
|
150
151
|
applyExtractors(code: string, id?: string, extracted?: CountableSet<string>): Promise<CountableSet<string>>;
|
|
151
152
|
makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
|
|
152
153
|
parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
|
|
153
154
|
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<false>): Promise<GenerateResult<Set<string>>>;
|
|
154
155
|
generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<true>): Promise<GenerateResult<Map<string, ExtendedTokenInfo<Theme>>>>;
|
|
155
|
-
matchVariants(raw: string, current?: string): Promise<VariantMatchedResult<Theme
|
|
156
|
+
matchVariants(raw: string, current?: string): Promise<readonly VariantMatchedResult<Theme>[]>;
|
|
156
157
|
private applyVariants;
|
|
157
158
|
constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
|
|
158
159
|
parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
|
|
@@ -162,7 +163,13 @@ declare class UnoGenerator<Theme extends object = object> {
|
|
|
162
163
|
isBlocked(raw: string): boolean;
|
|
163
164
|
getBlocked(raw: string): [BlocklistValue, BlocklistMeta | undefined] | undefined;
|
|
164
165
|
}
|
|
165
|
-
declare
|
|
166
|
+
declare class UnoGenerator<Theme extends object = object> extends UnoGeneratorInternal<Theme> {
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
|
|
169
|
+
*/
|
|
170
|
+
constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
|
|
171
|
+
}
|
|
172
|
+
declare function createGenerator<Theme extends object = object>(config?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<UnoGenerator<Theme>>;
|
|
166
173
|
declare const regexScopePlaceholder: RegExp;
|
|
167
174
|
declare function hasScopePlaceholder(css: string): boolean;
|
|
168
175
|
declare function toEscapedSelector(raw: string): string;
|
|
@@ -452,7 +459,7 @@ interface VariantHandler {
|
|
|
452
459
|
*/
|
|
453
460
|
layer?: string | undefined;
|
|
454
461
|
}
|
|
455
|
-
type VariantFunction<Theme extends object = object> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | undefined>;
|
|
462
|
+
type VariantFunction<Theme extends object = object> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | VariantHandler[] | undefined>;
|
|
456
463
|
interface VariantObject<Theme extends object = object> {
|
|
457
464
|
/**
|
|
458
465
|
* The name of the variant.
|
|
@@ -571,7 +578,7 @@ interface ConfigBase<Theme extends object = object> {
|
|
|
571
578
|
/**
|
|
572
579
|
* Presets
|
|
573
580
|
*/
|
|
574
|
-
presets?: (
|
|
581
|
+
presets?: (PresetOrFactoryAwaitable<Theme> | PresetOrFactoryAwaitable<Theme>[])[];
|
|
575
582
|
/**
|
|
576
583
|
* Additional options for auto complete
|
|
577
584
|
*/
|
|
@@ -698,7 +705,9 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
|
|
|
698
705
|
api?: any;
|
|
699
706
|
}
|
|
700
707
|
type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
|
|
708
|
+
type PresetFactoryAwaitable<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Awaitable<Preset<Theme>>;
|
|
701
709
|
type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
|
|
710
|
+
type PresetOrFactoryAwaitable<Theme extends object = object> = PresetOrFactory<Theme> | Promise<Preset<Theme>> | PresetFactoryAwaitable<Theme>;
|
|
702
711
|
interface GeneratorOptions {
|
|
703
712
|
/**
|
|
704
713
|
* Merge utilities with the exact same body to save the file size
|
|
@@ -907,7 +916,7 @@ interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, U
|
|
|
907
916
|
}
|
|
908
917
|
interface UserConfigDefaults<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme> {
|
|
909
918
|
}
|
|
910
|
-
interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByKey<UserConfig<Theme>, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete'> {
|
|
919
|
+
interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByKey<UserConfig<Theme>, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete' | 'presets'> {
|
|
911
920
|
presets: Preset<Theme>[];
|
|
912
921
|
shortcuts: Shortcut<Theme>[];
|
|
913
922
|
variants: VariantObject<Theme>[];
|
|
@@ -931,7 +940,7 @@ interface GenerateResult<T = Set<string>> {
|
|
|
931
940
|
setLayer: (layer: string, callback: (content: string) => Promise<string>) => Promise<string>;
|
|
932
941
|
matched: T;
|
|
933
942
|
}
|
|
934
|
-
type VariantMatchedResult<Theme extends object = object> =
|
|
943
|
+
type VariantMatchedResult<Theme extends object = object> = [
|
|
935
944
|
raw: string,
|
|
936
945
|
current: string,
|
|
937
946
|
variantHandlers: VariantHandler[],
|
|
@@ -1022,12 +1031,12 @@ declare function resolveShortcuts<Theme extends object = object>(shortcuts: User
|
|
|
1022
1031
|
/**
|
|
1023
1032
|
* Resolve a single preset, nested presets are ignored
|
|
1024
1033
|
*/
|
|
1025
|
-
declare function resolvePreset<Theme extends object = object>(presetInput:
|
|
1034
|
+
declare function resolvePreset<Theme extends object = object>(presetInput: PresetOrFactoryAwaitable<Theme>): Promise<Preset<Theme>>;
|
|
1026
1035
|
/**
|
|
1027
1036
|
* Resolve presets with nested presets
|
|
1028
1037
|
*/
|
|
1029
|
-
declare function resolvePresets<Theme extends object = object>(preset:
|
|
1030
|
-
declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): ResolvedConfig<Theme
|
|
1038
|
+
declare function resolvePresets<Theme extends object = object>(preset: PresetOrFactoryAwaitable<Theme>): Promise<Preset<Theme>[]>;
|
|
1039
|
+
declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<ResolvedConfig<Theme>>;
|
|
1031
1040
|
/**
|
|
1032
1041
|
* Merge multiple configs into one, later ones have higher priority
|
|
1033
1042
|
*/
|
|
@@ -1039,4 +1048,4 @@ declare const defaultSplitRE: RegExp;
|
|
|
1039
1048
|
declare const splitWithVariantGroupRE: RegExp;
|
|
1040
1049
|
declare const extractorSplit: Extractor;
|
|
1041
1050
|
|
|
1042
|
-
export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistMeta, type BlocklistRule, type BlocklistValue, type CSSEntries, type CSSEntriesInput, type CSSEntry, type CSSObject, type CSSObjectInput, type CSSValue, type CSSValueInput, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, type ControlSymbols, type ControlSymbolsEntry, type ControlSymbolsValue, CountableSet, type DeepPartial, type DynamicMatcher, type DynamicRule, type DynamicShortcut, type DynamicShortcutMatcher, type ExtendedTokenInfo, type Extractor, type ExtractorContext, type FilterPattern, type FlatObjectTuple, type GenerateOptions, type GenerateResult, type GeneratorOptions, type HighlightAnnotation, type ObjectToEntry, type OutputCssLayersOptions, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetFactory, type PresetOptions, type PresetOrFactory, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, type SafeListContext, type Shift, type Shortcut, type ShortcutValue, type SourceCodeTransformer, type SourceCodeTransformerEnforce, type SourceMap, type StaticRule, type StaticShortcut, type StaticShortcutMap, type StringifiedUtil, type SuggestResult, type ThemeExtender, type ToArray, TwoKeyMap, UnoGenerator, type UnocssPluginContext, type UserConfig, type UserConfigDefaults, type UserOnlyOptions, type UserShortcuts, type UtilObject, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, 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 };
|
|
1051
|
+
export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistMeta, type BlocklistRule, type BlocklistValue, type CSSEntries, type CSSEntriesInput, type CSSEntry, type CSSObject, type CSSObjectInput, type CSSValue, type CSSValueInput, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, type ControlSymbols, type ControlSymbolsEntry, type ControlSymbolsValue, CountableSet, type DeepPartial, type DynamicMatcher, type DynamicRule, type DynamicShortcut, type DynamicShortcutMatcher, type ExtendedTokenInfo, type Extractor, type ExtractorContext, type FilterPattern, type FlatObjectTuple, type GenerateOptions, type GenerateResult, type GeneratorOptions, type HighlightAnnotation, type ObjectToEntry, type OutputCssLayersOptions, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetFactory, type PresetFactoryAwaitable, type PresetOptions, type PresetOrFactory, type PresetOrFactoryAwaitable, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, type SafeListContext, type Shift, type Shortcut, type ShortcutValue, type SourceCodeTransformer, type SourceCodeTransformerEnforce, type SourceMap, type StaticRule, type StaticShortcut, type StaticShortcutMap, type StringifiedUtil, type SuggestResult, type ThemeExtender, type ToArray, TwoKeyMap, UnoGenerator, type UnocssPluginContext, type UserConfig, type UserConfigDefaults, type UserOnlyOptions, type UserShortcuts, type UtilObject, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -442,8 +442,8 @@ function resolveShortcuts(shortcuts) {
|
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
const __RESOLVED = "_uno_resolved";
|
|
445
|
-
function resolvePreset(presetInput) {
|
|
446
|
-
let preset = typeof presetInput === "function" ? presetInput() : presetInput;
|
|
445
|
+
async function resolvePreset(presetInput) {
|
|
446
|
+
let preset = typeof presetInput === "function" ? await presetInput() : await presetInput;
|
|
447
447
|
if (__RESOLVED in preset)
|
|
448
448
|
return preset;
|
|
449
449
|
preset = { ...preset };
|
|
@@ -468,11 +468,11 @@ function resolvePreset(presetInput) {
|
|
|
468
468
|
}
|
|
469
469
|
return preset;
|
|
470
470
|
}
|
|
471
|
-
function resolvePresets(preset) {
|
|
472
|
-
const root = resolvePreset(preset);
|
|
471
|
+
async function resolvePresets(preset) {
|
|
472
|
+
const root = await resolvePreset(preset);
|
|
473
473
|
if (!root.presets)
|
|
474
474
|
return [root];
|
|
475
|
-
const nested = (root.presets || []).flatMap(toArray).flatMap(resolvePresets);
|
|
475
|
+
const nested = (await Promise.all((root.presets || []).flatMap(toArray).flatMap(resolvePresets))).flat();
|
|
476
476
|
return [root, ...nested];
|
|
477
477
|
}
|
|
478
478
|
function mergeContentOptions(optionsArray) {
|
|
@@ -524,9 +524,12 @@ function mergeContentOptions(optionsArray) {
|
|
|
524
524
|
}
|
|
525
525
|
return mergedContent;
|
|
526
526
|
}
|
|
527
|
-
function resolveConfig(userConfig = {}, defaults = {}) {
|
|
527
|
+
async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
528
528
|
const config = Object.assign({}, defaults, userConfig);
|
|
529
|
-
const rawPresets = uniqueBy(
|
|
529
|
+
const rawPresets = uniqueBy(
|
|
530
|
+
(await Promise.all((config.presets || []).flatMap(toArray).flatMap(resolvePresets))).flat(),
|
|
531
|
+
(a, b) => a.name === b.name
|
|
532
|
+
);
|
|
530
533
|
const sortedPresets = [
|
|
531
534
|
...rawPresets.filter((p) => p.enforce === "pre"),
|
|
532
535
|
...rawPresets.filter((p) => !p.enforce),
|
|
@@ -650,7 +653,7 @@ function definePreset(preset) {
|
|
|
650
653
|
return preset;
|
|
651
654
|
}
|
|
652
655
|
|
|
653
|
-
const version = "0.
|
|
656
|
+
const version = "0.65.0-beta.1";
|
|
654
657
|
|
|
655
658
|
function createNanoEvents() {
|
|
656
659
|
return {
|
|
@@ -678,7 +681,7 @@ const symbols = {
|
|
|
678
681
|
selector: "$$symbol-selector",
|
|
679
682
|
layer: "$$symbol-layer"
|
|
680
683
|
};
|
|
681
|
-
class
|
|
684
|
+
class UnoGeneratorInternal {
|
|
682
685
|
constructor(userConfig = {}, defaults = {}) {
|
|
683
686
|
this.userConfig = userConfig;
|
|
684
687
|
this.defaults = defaults;
|
|
@@ -688,10 +691,14 @@ class UnoGenerator {
|
|
|
688
691
|
__publicField(this, "blocked", /* @__PURE__ */ new Set());
|
|
689
692
|
__publicField(this, "parentOrders", /* @__PURE__ */ new Map());
|
|
690
693
|
__publicField(this, "events", createNanoEvents());
|
|
691
|
-
this.config = resolveConfig(userConfig, defaults);
|
|
692
|
-
this.events.emit("config", this.config);
|
|
693
694
|
}
|
|
694
|
-
|
|
695
|
+
static async create(userConfig = {}, defaults = {}) {
|
|
696
|
+
const uno = new UnoGeneratorInternal(userConfig, defaults);
|
|
697
|
+
uno.config = await resolveConfig(uno.userConfig, uno.defaults);
|
|
698
|
+
uno.events.emit("config", uno.config);
|
|
699
|
+
return uno;
|
|
700
|
+
}
|
|
701
|
+
async setConfig(userConfig, defaults) {
|
|
695
702
|
if (!userConfig)
|
|
696
703
|
return;
|
|
697
704
|
if (defaults)
|
|
@@ -700,7 +707,7 @@ class UnoGenerator {
|
|
|
700
707
|
this.blocked.clear();
|
|
701
708
|
this.parentOrders.clear();
|
|
702
709
|
this._cache.clear();
|
|
703
|
-
this.config = resolveConfig(userConfig, this.defaults);
|
|
710
|
+
this.config = await resolveConfig(userConfig, this.defaults);
|
|
704
711
|
this.events.emit("config", this.config);
|
|
705
712
|
}
|
|
706
713
|
async applyExtractors(code, id, extracted = /* @__PURE__ */ new Set()) {
|
|
@@ -752,20 +759,24 @@ class UnoGenerator {
|
|
|
752
759
|
this._cache.set(cacheKey, null);
|
|
753
760
|
return;
|
|
754
761
|
}
|
|
755
|
-
const
|
|
756
|
-
if (!
|
|
762
|
+
const variantResults = await this.matchVariants(raw, current);
|
|
763
|
+
if (variantResults.every((i) => !i || this.isBlocked(i[1]))) {
|
|
757
764
|
this.blocked.add(raw);
|
|
758
765
|
this._cache.set(cacheKey, null);
|
|
759
766
|
return;
|
|
760
767
|
}
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
this._cache.set(cacheKey, utils);
|
|
768
|
+
const handleVariantResult = async (matched) => {
|
|
769
|
+
const context = this.makeContext(raw, [alias || matched[0], matched[1], matched[2], matched[3]]);
|
|
770
|
+
if (this.config.details)
|
|
771
|
+
context.variants = [...matched[3]];
|
|
772
|
+
const expanded = await this.expandShortcut(context.currentSelector, context);
|
|
773
|
+
const utils = expanded ? await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]) : (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i, context)).filter(notNull);
|
|
768
774
|
return utils;
|
|
775
|
+
};
|
|
776
|
+
const result = (await Promise.all(variantResults.map((i) => handleVariantResult(i)))).flat().filter((x) => !!x);
|
|
777
|
+
if (result?.length) {
|
|
778
|
+
this._cache.set(cacheKey, result);
|
|
779
|
+
return result;
|
|
769
780
|
}
|
|
770
781
|
this._cache.set(cacheKey, null);
|
|
771
782
|
}
|
|
@@ -920,40 +931,65 @@ class UnoGenerator {
|
|
|
920
931
|
};
|
|
921
932
|
}
|
|
922
933
|
async matchVariants(raw, current) {
|
|
923
|
-
const variants = /* @__PURE__ */ new Set();
|
|
924
|
-
const handlers = [];
|
|
925
|
-
let processed = current || raw;
|
|
926
|
-
let applied = true;
|
|
927
934
|
const context = {
|
|
928
935
|
rawSelector: raw,
|
|
929
936
|
theme: this.config.theme,
|
|
930
937
|
generator: this
|
|
931
938
|
};
|
|
932
|
-
|
|
933
|
-
applied =
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
if (isString(handler)) {
|
|
941
|
-
if (handler === processed)
|
|
939
|
+
const match = async (result) => {
|
|
940
|
+
let applied = true;
|
|
941
|
+
const [, , handlers, variants] = result;
|
|
942
|
+
while (applied) {
|
|
943
|
+
applied = false;
|
|
944
|
+
const processed = result[1];
|
|
945
|
+
for (const v of this.config.variants) {
|
|
946
|
+
if (!v.multiPass && variants.has(v))
|
|
942
947
|
continue;
|
|
943
|
-
handler =
|
|
948
|
+
let handler = await v.match(processed, context);
|
|
949
|
+
if (!handler)
|
|
950
|
+
continue;
|
|
951
|
+
if (isString(handler)) {
|
|
952
|
+
if (handler === processed)
|
|
953
|
+
continue;
|
|
954
|
+
handler = { matcher: handler };
|
|
955
|
+
}
|
|
956
|
+
if (Array.isArray(handler)) {
|
|
957
|
+
if (!handler.length)
|
|
958
|
+
continue;
|
|
959
|
+
if (handler.length === 1) {
|
|
960
|
+
handler = handler[0];
|
|
961
|
+
} else {
|
|
962
|
+
if (v.multiPass)
|
|
963
|
+
throw new Error("multiPass can not be used together with array return variants");
|
|
964
|
+
const clones = handler.map((h) => {
|
|
965
|
+
const _processed = h.matcher ?? processed;
|
|
966
|
+
const _handlers = [h, ...handlers];
|
|
967
|
+
const _variants = new Set(variants);
|
|
968
|
+
_variants.add(v);
|
|
969
|
+
return [result[0], _processed, _handlers, _variants];
|
|
970
|
+
});
|
|
971
|
+
return (await Promise.all(clones.map((c) => match(c)))).flat();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
result[1] = handler.matcher ?? processed;
|
|
975
|
+
handlers.unshift(handler);
|
|
976
|
+
variants.add(v);
|
|
977
|
+
applied = true;
|
|
978
|
+
break;
|
|
944
979
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
break;
|
|
980
|
+
if (!applied)
|
|
981
|
+
break;
|
|
982
|
+
if (handlers.length > 500)
|
|
983
|
+
throw new Error(`Too many variants applied to "${raw}"`);
|
|
950
984
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
985
|
+
return [result];
|
|
986
|
+
};
|
|
987
|
+
return await match([
|
|
988
|
+
raw,
|
|
989
|
+
current || raw,
|
|
990
|
+
[],
|
|
991
|
+
/* @__PURE__ */ new Set()
|
|
992
|
+
]);
|
|
957
993
|
}
|
|
958
994
|
applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
|
|
959
995
|
const handler = variantHandlers.slice().sort((a, b) => (a.order || 0) - (b.order || 0)).reduceRight(
|
|
@@ -1008,95 +1044,101 @@ class UnoGenerator {
|
|
|
1008
1044
|
return cssBody;
|
|
1009
1045
|
}
|
|
1010
1046
|
async parseUtil(input, context, internal = false, shortcutPrefix) {
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (staticMatch
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
context.variantHandlers = variantHandlers;
|
|
1029
|
-
const { rulesDynamic } = this.config;
|
|
1030
|
-
for (const [i, matcher, handler, meta] of rulesDynamic) {
|
|
1031
|
-
if (meta?.internal && !internal)
|
|
1032
|
-
continue;
|
|
1033
|
-
let unprefixed = processed;
|
|
1034
|
-
if (meta?.prefix) {
|
|
1035
|
-
const prefixes = toArray(meta.prefix);
|
|
1036
|
-
if (shortcutPrefix) {
|
|
1037
|
-
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1038
|
-
if (!prefixes.some((i2) => shortcutPrefixes.includes(i2)))
|
|
1039
|
-
continue;
|
|
1040
|
-
} else {
|
|
1041
|
-
const prefix = prefixes.find((i2) => processed.startsWith(i2));
|
|
1042
|
-
if (prefix == null)
|
|
1043
|
-
continue;
|
|
1044
|
-
unprefixed = processed.slice(prefix.length);
|
|
1047
|
+
const variantResults = isString(input) ? await this.matchVariants(input) : [input];
|
|
1048
|
+
const parse = async ([raw, processed, variantHandlers]) => {
|
|
1049
|
+
if (this.config.details)
|
|
1050
|
+
context.rules = context.rules ?? [];
|
|
1051
|
+
const staticMatch = this.config.rulesStaticMap[processed];
|
|
1052
|
+
if (staticMatch) {
|
|
1053
|
+
if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
|
|
1054
|
+
if (this.config.details)
|
|
1055
|
+
context.rules.push(staticMatch[3]);
|
|
1056
|
+
const index = staticMatch[0];
|
|
1057
|
+
const entry = normalizeCSSEntries(staticMatch[1]);
|
|
1058
|
+
const meta = staticMatch[2];
|
|
1059
|
+
if (isString(entry))
|
|
1060
|
+
return [[index, entry, meta]];
|
|
1061
|
+
else
|
|
1062
|
+
return [[index, raw, entry, meta, variantHandlers]];
|
|
1045
1063
|
}
|
|
1046
1064
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1065
|
+
context.variantHandlers = variantHandlers;
|
|
1066
|
+
const { rulesDynamic } = this.config;
|
|
1067
|
+
for (const [i, matcher, handler, meta] of rulesDynamic) {
|
|
1068
|
+
if (meta?.internal && !internal)
|
|
1069
|
+
continue;
|
|
1070
|
+
let unprefixed = processed;
|
|
1071
|
+
if (meta?.prefix) {
|
|
1072
|
+
const prefixes = toArray(meta.prefix);
|
|
1073
|
+
if (shortcutPrefix) {
|
|
1074
|
+
const shortcutPrefixes = toArray(shortcutPrefix);
|
|
1075
|
+
if (!prefixes.some((i2) => shortcutPrefixes.includes(i2)))
|
|
1076
|
+
continue;
|
|
1077
|
+
} else {
|
|
1078
|
+
const prefix = prefixes.find((i2) => processed.startsWith(i2));
|
|
1079
|
+
if (prefix == null)
|
|
1080
|
+
continue;
|
|
1081
|
+
unprefixed = processed.slice(prefix.length);
|
|
1061
1082
|
}
|
|
1062
|
-
result = entries2;
|
|
1063
|
-
} else if (Symbol.iterator in result && !Array.isArray(result)) {
|
|
1064
|
-
result = Array.from(result).filter(notNull);
|
|
1065
1083
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
variants = [
|
|
1081
|
-
{ parent: entry[1] },
|
|
1082
|
-
...variants
|
|
1083
|
-
];
|
|
1084
|
-
} else if (entry[0] === symbols.selector) {
|
|
1085
|
-
variants = [
|
|
1086
|
-
{ selector: entry[1] },
|
|
1087
|
-
...variants
|
|
1088
|
-
];
|
|
1089
|
-
} else if (entry[0] === symbols.layer) {
|
|
1090
|
-
variants = [
|
|
1091
|
-
{ layer: entry[1] },
|
|
1092
|
-
...variants
|
|
1093
|
-
];
|
|
1084
|
+
const match = unprefixed.match(matcher);
|
|
1085
|
+
if (!match)
|
|
1086
|
+
continue;
|
|
1087
|
+
let result = await handler(match, context);
|
|
1088
|
+
if (!result)
|
|
1089
|
+
continue;
|
|
1090
|
+
if (this.config.details)
|
|
1091
|
+
context.rules.push([matcher, handler, meta]);
|
|
1092
|
+
if (typeof result !== "string") {
|
|
1093
|
+
if (Symbol.asyncIterator in result) {
|
|
1094
|
+
const entries2 = [];
|
|
1095
|
+
for await (const r of result) {
|
|
1096
|
+
if (r)
|
|
1097
|
+
entries2.push(r);
|
|
1094
1098
|
}
|
|
1099
|
+
result = entries2;
|
|
1100
|
+
} else if (Symbol.iterator in result && !Array.isArray(result)) {
|
|
1101
|
+
result = Array.from(result).filter(notNull);
|
|
1095
1102
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1103
|
+
}
|
|
1104
|
+
const entries = normalizeCSSValues(result).filter((i2) => i2.length);
|
|
1105
|
+
if (entries.length) {
|
|
1106
|
+
return entries.map((css) => {
|
|
1107
|
+
if (isString(css))
|
|
1108
|
+
return [i, css, meta];
|
|
1109
|
+
let variants = variantHandlers;
|
|
1110
|
+
for (const entry of css) {
|
|
1111
|
+
if (entry[0] === symbols.variants) {
|
|
1112
|
+
variants = [
|
|
1113
|
+
...toArray(entry[1]),
|
|
1114
|
+
...variants
|
|
1115
|
+
];
|
|
1116
|
+
} else if (entry[0] === symbols.parent) {
|
|
1117
|
+
variants = [
|
|
1118
|
+
{ parent: entry[1] },
|
|
1119
|
+
...variants
|
|
1120
|
+
];
|
|
1121
|
+
} else if (entry[0] === symbols.selector) {
|
|
1122
|
+
variants = [
|
|
1123
|
+
{ selector: entry[1] },
|
|
1124
|
+
...variants
|
|
1125
|
+
];
|
|
1126
|
+
} else if (entry[0] === symbols.layer) {
|
|
1127
|
+
variants = [
|
|
1128
|
+
{ layer: entry[1] },
|
|
1129
|
+
...variants
|
|
1130
|
+
];
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return [i, raw, css, meta, variants];
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1098
1136
|
}
|
|
1099
|
-
}
|
|
1137
|
+
};
|
|
1138
|
+
const parsed = (await Promise.all(variantResults.map((i) => parse(i)))).flat().filter((x) => !!x);
|
|
1139
|
+
if (!parsed.length)
|
|
1140
|
+
return void 0;
|
|
1141
|
+
return parsed;
|
|
1100
1142
|
}
|
|
1101
1143
|
stringifyUtil(parsed, context) {
|
|
1102
1144
|
if (!parsed)
|
|
@@ -1166,17 +1208,20 @@ class UnoGenerator {
|
|
|
1166
1208
|
}).flat();
|
|
1167
1209
|
}
|
|
1168
1210
|
if (!result) {
|
|
1169
|
-
const
|
|
1170
|
-
|
|
1171
|
-
const
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1211
|
+
const matched = isString(input) ? await this.matchVariants(input) : [input];
|
|
1212
|
+
for (const match of matched) {
|
|
1213
|
+
const [raw, inputWithoutVariant] = match;
|
|
1214
|
+
if (raw !== inputWithoutVariant) {
|
|
1215
|
+
const expanded = await this.expandShortcut(inputWithoutVariant, context, depth - 1);
|
|
1216
|
+
if (expanded)
|
|
1217
|
+
result = expanded[0].map((item) => isString(item) ? raw.replace(inputWithoutVariant, item) : item);
|
|
1218
|
+
}
|
|
1174
1219
|
}
|
|
1175
1220
|
}
|
|
1176
1221
|
if (!result)
|
|
1177
1222
|
return;
|
|
1178
1223
|
return [
|
|
1179
|
-
(await Promise.all(result.map(async (r) => (isString(r) ? (await this.expandShortcut(r, context, depth - 1))?.[0] : void 0) || [r]))).flat(1).filter(
|
|
1224
|
+
(await Promise.all(result.map(async (r) => (isString(r) ? (await this.expandShortcut(r, context, depth - 1))?.[0] : void 0) || [r]))).flat(1).filter((x) => !!x),
|
|
1180
1225
|
meta
|
|
1181
1226
|
];
|
|
1182
1227
|
}
|
|
@@ -1234,8 +1279,17 @@ class UnoGenerator {
|
|
|
1234
1279
|
return rule ? Array.isArray(rule) ? rule : [rule, void 0] : void 0;
|
|
1235
1280
|
}
|
|
1236
1281
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1282
|
+
class UnoGenerator extends UnoGeneratorInternal {
|
|
1283
|
+
/**
|
|
1284
|
+
* @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
|
|
1285
|
+
*/
|
|
1286
|
+
constructor(userConfig = {}, defaults = {}) {
|
|
1287
|
+
super(userConfig, defaults);
|
|
1288
|
+
console.warn("`new UnoGenerator()` is deprecated, please use `createGenerator()` instead");
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
async function createGenerator(config, defaults) {
|
|
1292
|
+
return await UnoGeneratorInternal.create(config, defaults);
|
|
1239
1293
|
}
|
|
1240
1294
|
const regexScopePlaceholder = /\s\$\$\s+/g;
|
|
1241
1295
|
function hasScopePlaceholder(css) {
|