@unocss/core 0.55.6 → 0.56.0

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 CHANGED
@@ -55,6 +55,14 @@ function toArray(value = []) {
55
55
  function uniq(value) {
56
56
  return Array.from(new Set(value));
57
57
  }
58
+ function uniqueBy(array, equalFn) {
59
+ return array.reduce((acc, cur) => {
60
+ const index = acc.findIndex((item) => equalFn(cur, item));
61
+ if (index === -1)
62
+ acc.push(cur);
63
+ return acc;
64
+ }, []);
65
+ }
58
66
  function isString(s) {
59
67
  return typeof s === "string";
60
68
  }
@@ -392,36 +400,6 @@ function warnOnce(msg) {
392
400
  warned.add(msg);
393
401
  }
394
402
 
395
- function createValueHandler(handlers) {
396
- const handler = function(str) {
397
- const s = this.__options?.sequence || [];
398
- this.__options.sequence = [];
399
- for (const n of s) {
400
- const res = handlers[n](str);
401
- if (res != null)
402
- return res;
403
- }
404
- };
405
- function addProcessor(that, name) {
406
- if (!that.__options) {
407
- that.__options = {
408
- sequence: []
409
- };
410
- }
411
- that.__options.sequence.push(name);
412
- return that;
413
- }
414
- for (const name of Object.keys(handlers)) {
415
- Object.defineProperty(handler, name, {
416
- enumerable: true,
417
- get() {
418
- return addProcessor(this, name);
419
- }
420
- });
421
- }
422
- return handler;
423
- }
424
-
425
403
  const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
426
404
  const splitWithVariantGroupRE = /([\\:]?[\s"'`;<>]|:\(|\)"|\)\s)/g;
427
405
  function splitCode(code) {
@@ -467,7 +445,8 @@ function resolveShortcuts(shortcuts) {
467
445
  });
468
446
  }
469
447
  const __RESOLVED = "_uno_resolved";
470
- function resolvePreset(preset) {
448
+ function resolvePreset(presetInput) {
449
+ let preset = typeof presetInput === "function" ? presetInput() : presetInput;
471
450
  if (__RESOLVED in preset)
472
451
  return preset;
473
452
  preset = { ...preset };
@@ -501,7 +480,7 @@ function resolvePresets(preset) {
501
480
  }
502
481
  function resolveConfig(userConfig = {}, defaults = {}) {
503
482
  const config = Object.assign({}, defaults, userConfig);
504
- const rawPresets = uniq((config.presets || []).flatMap(toArray).flatMap(resolvePresets));
483
+ const rawPresets = uniqueBy((config.presets || []).flatMap(toArray).flatMap(resolvePresets), (a, b) => a.name === b.name);
505
484
  const sortedPresets = [
506
485
  ...rawPresets.filter((p) => p.enforce === "pre"),
507
486
  ...rawPresets.filter((p) => !p.enforce),
@@ -612,8 +591,11 @@ function mergeAutocompleteShorthands(shorthands) {
612
591
  {}
613
592
  );
614
593
  }
594
+ function definePreset(preset) {
595
+ return preset;
596
+ }
615
597
 
616
- const version = "0.55.6";
598
+ const version = "0.56.0";
617
599
 
618
600
  var __defProp = Object.defineProperty;
619
601
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -1103,7 +1085,7 @@ class UnoGenerator {
1103
1085
  }).flat(2).filter(Boolean));
1104
1086
  }
1105
1087
  isBlocked(raw) {
1106
- return !raw || this.config.blocklist.some((e2) => isString(e2) ? e2 === raw : e2.test(raw));
1088
+ return !raw || this.config.blocklist.some((e2) => typeof e2 === "function" ? e2(raw) : isString(e2) ? e2 === raw : e2.test(raw));
1107
1089
  }
1108
1090
  }
1109
1091
  function createGenerator(config, defaults) {
@@ -1139,9 +1121,9 @@ exports.clearIdenticalEntries = clearIdenticalEntries;
1139
1121
  exports.clone = clone;
1140
1122
  exports.collapseVariantGroup = collapseVariantGroup;
1141
1123
  exports.createGenerator = createGenerator;
1142
- exports.createValueHandler = createValueHandler;
1143
1124
  exports.cssIdRE = cssIdRE;
1144
1125
  exports.defaultSplitRE = defaultSplitRE;
1126
+ exports.definePreset = definePreset;
1145
1127
  exports.e = e;
1146
1128
  exports.entriesToCss = entriesToCss;
1147
1129
  exports.escapeRegExp = escapeRegExp;
@@ -1176,6 +1158,7 @@ exports.splitWithVariantGroupRE = splitWithVariantGroupRE;
1176
1158
  exports.toArray = toArray;
1177
1159
  exports.toEscapedSelector = toEscapedSelector;
1178
1160
  exports.uniq = uniq;
1161
+ exports.uniqueBy = uniqueBy;
1179
1162
  exports.validateFilterRE = validateFilterRE;
1180
1163
  exports.warnOnce = warnOnce;
1181
1164
  exports.withLayer = withLayer;
package/dist/index.d.cts CHANGED
@@ -73,6 +73,7 @@ declare function isStaticShortcut(sc: Shortcut<any>): sc is StaticShortcut;
73
73
 
74
74
  declare function toArray<T>(value?: T | T[]): T[];
75
75
  declare function uniq<T>(value: T[]): T[];
76
+ declare function uniqueBy<T>(array: readonly T[], equalFn: (a: T, b: T) => boolean): T[];
76
77
  declare function isString(s: any): s is string;
77
78
 
78
79
  declare const attributifyRE: RegExp;
@@ -130,17 +131,6 @@ declare function expandVariantGroup(str: MagicString, separators?: string[], dep
130
131
 
131
132
  declare function warnOnce(msg: string): void;
132
133
 
133
- type ValueHandlerCallback = (str: string) => string | number | undefined;
134
- type ValueHandler<K extends string> = {
135
- [S in K]: ValueHandler<K>;
136
- } & {
137
- (str: string): string | undefined;
138
- __options: {
139
- sequence: K[];
140
- };
141
- };
142
- declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
143
-
144
134
  declare class UnoGenerator<Theme extends object = object> {
145
135
  userConfig: UserConfig<Theme>;
146
136
  defaults: UserConfigDefaults<Theme>;
@@ -362,7 +352,7 @@ interface Preflight<Theme extends object = object> {
362
352
  getCSS: (context: PreflightContext<Theme>) => Promise<string | undefined> | string | undefined;
363
353
  layer?: string;
364
354
  }
365
- type BlocklistRule = string | RegExp;
355
+ type BlocklistRule = string | RegExp | ((selector: string) => boolean | null | undefined);
366
356
  interface VariantHandlerContext {
367
357
  /**
368
358
  * Rewrite the output selector. Often be used to append parents.
@@ -551,7 +541,7 @@ interface ConfigBase<Theme extends object = object> {
551
541
  /**
552
542
  * Presets
553
543
  */
554
- presets?: (Preset<Theme> | Preset<Theme>[])[];
544
+ presets?: (PresetOrFactory<Theme> | PresetOrFactory<Theme>[])[];
555
545
  /**
556
546
  * Additional options for auto complete
557
547
  */
@@ -656,6 +646,8 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
656
646
  */
657
647
  layer?: string;
658
648
  }
649
+ type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
650
+ type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
659
651
  interface GeneratorOptions {
660
652
  /**
661
653
  * Merge utilities with the exact same body to save the file size
@@ -838,7 +830,7 @@ interface PluginOptions {
838
830
  * The usage extracted from each source will be **merged** together.
839
831
  */
840
832
  content?: ContentOptions;
841
- /** ========== DEPRECATED OPTIONS ========== **/
833
+ /** ========== DEPRECATED OPTIONS ========== */
842
834
  /**
843
835
  * @deprecated Renamed to `content`
844
836
  */
@@ -849,9 +841,9 @@ interface PluginOptions {
849
841
  */
850
842
  include?: FilterPattern;
851
843
  /**
852
- * Patterns that filter the files NOT being extracted.
853
- * @deprecated moved to `content.pipeline.exclude`
854
- */
844
+ * Patterns that filter the files NOT being extracted.
845
+ * @deprecated moved to `content.pipeline.exclude`
846
+ */
855
847
  exclude?: FilterPattern;
856
848
  }
857
849
  interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions, CliOptions {
@@ -976,15 +968,17 @@ declare function resolveShortcuts<Theme extends object = object>(shortcuts: User
976
968
  /**
977
969
  * Resolve a single preset, nested presets are ignored
978
970
  */
979
- declare function resolvePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
971
+ declare function resolvePreset<Theme extends object = object>(presetInput: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>;
980
972
  /**
981
973
  * Resolve presets with nested presets
982
974
  */
983
- declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>[];
975
+ declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>[];
984
976
  declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): ResolvedConfig<Theme>;
985
977
  /**
986
978
  * Merge multiple configs into one, later ones have higher priority
987
979
  */
988
980
  declare function mergeConfigs<Theme extends object = object>(configs: UserConfig<Theme>[]): UserConfig<Theme>;
981
+ declare function definePreset<Options extends object | undefined = undefined, Theme extends object = object>(preset: PresetFactory<Theme, Options>): PresetFactory<Theme, Options>;
982
+ declare function definePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
989
983
 
990
- export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetOptions, type RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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 ValueHandler, type ValueHandlerCallback, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isCountableSet, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
984
+ export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, 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 RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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, toArray, toEscapedSelector, uniq, uniqueBy, validateFilterRE, warnOnce, withLayer };
package/dist/index.d.mts CHANGED
@@ -73,6 +73,7 @@ declare function isStaticShortcut(sc: Shortcut<any>): sc is StaticShortcut;
73
73
 
74
74
  declare function toArray<T>(value?: T | T[]): T[];
75
75
  declare function uniq<T>(value: T[]): T[];
76
+ declare function uniqueBy<T>(array: readonly T[], equalFn: (a: T, b: T) => boolean): T[];
76
77
  declare function isString(s: any): s is string;
77
78
 
78
79
  declare const attributifyRE: RegExp;
@@ -130,17 +131,6 @@ declare function expandVariantGroup(str: MagicString, separators?: string[], dep
130
131
 
131
132
  declare function warnOnce(msg: string): void;
132
133
 
133
- type ValueHandlerCallback = (str: string) => string | number | undefined;
134
- type ValueHandler<K extends string> = {
135
- [S in K]: ValueHandler<K>;
136
- } & {
137
- (str: string): string | undefined;
138
- __options: {
139
- sequence: K[];
140
- };
141
- };
142
- declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
143
-
144
134
  declare class UnoGenerator<Theme extends object = object> {
145
135
  userConfig: UserConfig<Theme>;
146
136
  defaults: UserConfigDefaults<Theme>;
@@ -362,7 +352,7 @@ interface Preflight<Theme extends object = object> {
362
352
  getCSS: (context: PreflightContext<Theme>) => Promise<string | undefined> | string | undefined;
363
353
  layer?: string;
364
354
  }
365
- type BlocklistRule = string | RegExp;
355
+ type BlocklistRule = string | RegExp | ((selector: string) => boolean | null | undefined);
366
356
  interface VariantHandlerContext {
367
357
  /**
368
358
  * Rewrite the output selector. Often be used to append parents.
@@ -551,7 +541,7 @@ interface ConfigBase<Theme extends object = object> {
551
541
  /**
552
542
  * Presets
553
543
  */
554
- presets?: (Preset<Theme> | Preset<Theme>[])[];
544
+ presets?: (PresetOrFactory<Theme> | PresetOrFactory<Theme>[])[];
555
545
  /**
556
546
  * Additional options for auto complete
557
547
  */
@@ -656,6 +646,8 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
656
646
  */
657
647
  layer?: string;
658
648
  }
649
+ type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
650
+ type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
659
651
  interface GeneratorOptions {
660
652
  /**
661
653
  * Merge utilities with the exact same body to save the file size
@@ -838,7 +830,7 @@ interface PluginOptions {
838
830
  * The usage extracted from each source will be **merged** together.
839
831
  */
840
832
  content?: ContentOptions;
841
- /** ========== DEPRECATED OPTIONS ========== **/
833
+ /** ========== DEPRECATED OPTIONS ========== */
842
834
  /**
843
835
  * @deprecated Renamed to `content`
844
836
  */
@@ -849,9 +841,9 @@ interface PluginOptions {
849
841
  */
850
842
  include?: FilterPattern;
851
843
  /**
852
- * Patterns that filter the files NOT being extracted.
853
- * @deprecated moved to `content.pipeline.exclude`
854
- */
844
+ * Patterns that filter the files NOT being extracted.
845
+ * @deprecated moved to `content.pipeline.exclude`
846
+ */
855
847
  exclude?: FilterPattern;
856
848
  }
857
849
  interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions, CliOptions {
@@ -976,15 +968,17 @@ declare function resolveShortcuts<Theme extends object = object>(shortcuts: User
976
968
  /**
977
969
  * Resolve a single preset, nested presets are ignored
978
970
  */
979
- declare function resolvePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
971
+ declare function resolvePreset<Theme extends object = object>(presetInput: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>;
980
972
  /**
981
973
  * Resolve presets with nested presets
982
974
  */
983
- declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>[];
975
+ declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>[];
984
976
  declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): ResolvedConfig<Theme>;
985
977
  /**
986
978
  * Merge multiple configs into one, later ones have higher priority
987
979
  */
988
980
  declare function mergeConfigs<Theme extends object = object>(configs: UserConfig<Theme>[]): UserConfig<Theme>;
981
+ declare function definePreset<Options extends object | undefined = undefined, Theme extends object = object>(preset: PresetFactory<Theme, Options>): PresetFactory<Theme, Options>;
982
+ declare function definePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
989
983
 
990
- export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetOptions, type RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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 ValueHandler, type ValueHandlerCallback, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isCountableSet, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
984
+ export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, 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 RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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, toArray, toEscapedSelector, uniq, uniqueBy, validateFilterRE, warnOnce, withLayer };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare function isStaticShortcut(sc: Shortcut<any>): sc is StaticShortcut;
73
73
 
74
74
  declare function toArray<T>(value?: T | T[]): T[];
75
75
  declare function uniq<T>(value: T[]): T[];
76
+ declare function uniqueBy<T>(array: readonly T[], equalFn: (a: T, b: T) => boolean): T[];
76
77
  declare function isString(s: any): s is string;
77
78
 
78
79
  declare const attributifyRE: RegExp;
@@ -130,17 +131,6 @@ declare function expandVariantGroup(str: MagicString, separators?: string[], dep
130
131
 
131
132
  declare function warnOnce(msg: string): void;
132
133
 
133
- type ValueHandlerCallback = (str: string) => string | number | undefined;
134
- type ValueHandler<K extends string> = {
135
- [S in K]: ValueHandler<K>;
136
- } & {
137
- (str: string): string | undefined;
138
- __options: {
139
- sequence: K[];
140
- };
141
- };
142
- declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
143
-
144
134
  declare class UnoGenerator<Theme extends object = object> {
145
135
  userConfig: UserConfig<Theme>;
146
136
  defaults: UserConfigDefaults<Theme>;
@@ -362,7 +352,7 @@ interface Preflight<Theme extends object = object> {
362
352
  getCSS: (context: PreflightContext<Theme>) => Promise<string | undefined> | string | undefined;
363
353
  layer?: string;
364
354
  }
365
- type BlocklistRule = string | RegExp;
355
+ type BlocklistRule = string | RegExp | ((selector: string) => boolean | null | undefined);
366
356
  interface VariantHandlerContext {
367
357
  /**
368
358
  * Rewrite the output selector. Often be used to append parents.
@@ -551,7 +541,7 @@ interface ConfigBase<Theme extends object = object> {
551
541
  /**
552
542
  * Presets
553
543
  */
554
- presets?: (Preset<Theme> | Preset<Theme>[])[];
544
+ presets?: (PresetOrFactory<Theme> | PresetOrFactory<Theme>[])[];
555
545
  /**
556
546
  * Additional options for auto complete
557
547
  */
@@ -656,6 +646,8 @@ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
656
646
  */
657
647
  layer?: string;
658
648
  }
649
+ type PresetFactory<Theme extends object = object, PresetOptions extends object | undefined = undefined> = (options?: PresetOptions) => Preset<Theme>;
650
+ type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
659
651
  interface GeneratorOptions {
660
652
  /**
661
653
  * Merge utilities with the exact same body to save the file size
@@ -838,7 +830,7 @@ interface PluginOptions {
838
830
  * The usage extracted from each source will be **merged** together.
839
831
  */
840
832
  content?: ContentOptions;
841
- /** ========== DEPRECATED OPTIONS ========== **/
833
+ /** ========== DEPRECATED OPTIONS ========== */
842
834
  /**
843
835
  * @deprecated Renamed to `content`
844
836
  */
@@ -849,9 +841,9 @@ interface PluginOptions {
849
841
  */
850
842
  include?: FilterPattern;
851
843
  /**
852
- * Patterns that filter the files NOT being extracted.
853
- * @deprecated moved to `content.pipeline.exclude`
854
- */
844
+ * Patterns that filter the files NOT being extracted.
845
+ * @deprecated moved to `content.pipeline.exclude`
846
+ */
855
847
  exclude?: FilterPattern;
856
848
  }
857
849
  interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions, CliOptions {
@@ -976,15 +968,17 @@ declare function resolveShortcuts<Theme extends object = object>(shortcuts: User
976
968
  /**
977
969
  * Resolve a single preset, nested presets are ignored
978
970
  */
979
- declare function resolvePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
971
+ declare function resolvePreset<Theme extends object = object>(presetInput: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>;
980
972
  /**
981
973
  * Resolve presets with nested presets
982
974
  */
983
- declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>[];
975
+ declare function resolvePresets<Theme extends object = object>(preset: Preset<Theme> | PresetFactory<Theme, any>): Preset<Theme>[];
984
976
  declare function resolveConfig<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): ResolvedConfig<Theme>;
985
977
  /**
986
978
  * Merge multiple configs into one, later ones have higher priority
987
979
  */
988
980
  declare function mergeConfigs<Theme extends object = object>(configs: UserConfig<Theme>[]): UserConfig<Theme>;
981
+ declare function definePreset<Options extends object | undefined = undefined, Theme extends object = object>(preset: PresetFactory<Theme, Options>): PresetFactory<Theme, Options>;
982
+ declare function definePreset<Theme extends object = object>(preset: Preset<Theme>): Preset<Theme>;
989
983
 
990
- export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, type ParsedUtil, type PartialByKeys, type PluginOptions, type Postprocessor, type Preflight, type PreflightContext, type PreparedRule, type Preprocessor, type Preset, type PresetOptions, type RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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 ValueHandler, type ValueHandlerCallback, type Variant, type VariantContext, type VariantFunction, type VariantHandler, type VariantHandlerContext, type VariantMatchedResult, type VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isCountableSet, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
984
+ export { type ArgumentType, type Arrayable, type AutoCompleteExtractor, type AutoCompleteExtractorContext, type AutoCompleteExtractorResult, type AutoCompleteFunction, type AutoCompleteTemplate, type Awaitable, BetterMap, type BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, type CSSColorValue, type CSSEntries, type CSSObject, type CSSValue, type CSSValues, type CliEntryItem, type CliOptions, type ConfigBase, type ContentOptions, 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 ParsedColorValue, 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 RGBAColorValue, type RawUtil, type Replacement, type RequiredByKey, type ResolvedConfig, type RestArgs, type Rule, type RuleContext, type RuleMeta, 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, toArray, toEscapedSelector, uniq, uniqueBy, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -53,6 +53,14 @@ function toArray(value = []) {
53
53
  function uniq(value) {
54
54
  return Array.from(new Set(value));
55
55
  }
56
+ function uniqueBy(array, equalFn) {
57
+ return array.reduce((acc, cur) => {
58
+ const index = acc.findIndex((item) => equalFn(cur, item));
59
+ if (index === -1)
60
+ acc.push(cur);
61
+ return acc;
62
+ }, []);
63
+ }
56
64
  function isString(s) {
57
65
  return typeof s === "string";
58
66
  }
@@ -390,36 +398,6 @@ function warnOnce(msg) {
390
398
  warned.add(msg);
391
399
  }
392
400
 
393
- function createValueHandler(handlers) {
394
- const handler = function(str) {
395
- const s = this.__options?.sequence || [];
396
- this.__options.sequence = [];
397
- for (const n of s) {
398
- const res = handlers[n](str);
399
- if (res != null)
400
- return res;
401
- }
402
- };
403
- function addProcessor(that, name) {
404
- if (!that.__options) {
405
- that.__options = {
406
- sequence: []
407
- };
408
- }
409
- that.__options.sequence.push(name);
410
- return that;
411
- }
412
- for (const name of Object.keys(handlers)) {
413
- Object.defineProperty(handler, name, {
414
- enumerable: true,
415
- get() {
416
- return addProcessor(this, name);
417
- }
418
- });
419
- }
420
- return handler;
421
- }
422
-
423
401
  const defaultSplitRE = /[\\:]?[\s'"`;{}]+/g;
424
402
  const splitWithVariantGroupRE = /([\\:]?[\s"'`;<>]|:\(|\)"|\)\s)/g;
425
403
  function splitCode(code) {
@@ -465,7 +443,8 @@ function resolveShortcuts(shortcuts) {
465
443
  });
466
444
  }
467
445
  const __RESOLVED = "_uno_resolved";
468
- function resolvePreset(preset) {
446
+ function resolvePreset(presetInput) {
447
+ let preset = typeof presetInput === "function" ? presetInput() : presetInput;
469
448
  if (__RESOLVED in preset)
470
449
  return preset;
471
450
  preset = { ...preset };
@@ -499,7 +478,7 @@ function resolvePresets(preset) {
499
478
  }
500
479
  function resolveConfig(userConfig = {}, defaults = {}) {
501
480
  const config = Object.assign({}, defaults, userConfig);
502
- const rawPresets = uniq((config.presets || []).flatMap(toArray).flatMap(resolvePresets));
481
+ const rawPresets = uniqueBy((config.presets || []).flatMap(toArray).flatMap(resolvePresets), (a, b) => a.name === b.name);
503
482
  const sortedPresets = [
504
483
  ...rawPresets.filter((p) => p.enforce === "pre"),
505
484
  ...rawPresets.filter((p) => !p.enforce),
@@ -610,8 +589,11 @@ function mergeAutocompleteShorthands(shorthands) {
610
589
  {}
611
590
  );
612
591
  }
592
+ function definePreset(preset) {
593
+ return preset;
594
+ }
613
595
 
614
- const version = "0.55.6";
596
+ const version = "0.56.0";
615
597
 
616
598
  var __defProp = Object.defineProperty;
617
599
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -1101,7 +1083,7 @@ class UnoGenerator {
1101
1083
  }).flat(2).filter(Boolean));
1102
1084
  }
1103
1085
  isBlocked(raw) {
1104
- return !raw || this.config.blocklist.some((e2) => isString(e2) ? e2 === raw : e2.test(raw));
1086
+ return !raw || this.config.blocklist.some((e2) => typeof e2 === "function" ? e2(raw) : isString(e2) ? e2 === raw : e2.test(raw));
1105
1087
  }
1106
1088
  }
1107
1089
  function createGenerator(config, defaults) {
@@ -1127,4 +1109,4 @@ function defaultVariantHandler(input, next) {
1127
1109
  return next(input);
1128
1110
  }
1129
1111
 
1130
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, CountableSet, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isCountableSet, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
1112
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, CountableSet, TwoKeyMap, UnoGenerator, 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, toArray, toEscapedSelector, uniq, uniqueBy, validateFilterRE, warnOnce, withLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.55.6",
3
+ "version": "0.56.0",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",