@unocss/core 0.48.4 → 0.49.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
@@ -219,9 +219,16 @@ function withLayer(layer, rules) {
219
219
  return rules;
220
220
  }
221
221
 
222
- const regexClassGroup = /((?:[!@\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$?-]|\[.*?\])+?)\)(?!\s*?=>)/gm;
222
+ const regexCache = {};
223
+ function makeRegexClassGroup(separators = ["-", ":"]) {
224
+ const key = separators.join("|");
225
+ if (!regexCache[key])
226
+ regexCache[key] = new RegExp(`((?:[!@\\w+:_/-]|\\[&?>?:?.*\\])+?)(${key})\\(((?:[~!\\w\\s:/\\\\,%#.$?-]|\\[.*?\\])+?)\\)(?!\\s*?=>)`, "gm");
227
+ regexCache[key].lastIndex = 0;
228
+ return regexCache[key];
229
+ }
223
230
  function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
224
- regexClassGroup.lastIndex = 0;
231
+ const regexClassGroup = makeRegexClassGroup(separators);
225
232
  let hasChanged = false;
226
233
  let content = str.toString();
227
234
  do {
@@ -408,6 +415,9 @@ function resolveConfig(userConfig = {}, defaults = {}) {
408
415
  templates: uniq(sortedPresets.map((p) => toArray(p.autocomplete?.templates)).flat()),
409
416
  extractors: sortedPresets.map((p) => toArray(p.autocomplete?.extractors)).flat().sort((a, b) => (a.order || 0) - (b.order || 0))
410
417
  };
418
+ let separators = toArray(mergePresets("separators"));
419
+ if (!separators.length)
420
+ separators = [":", "-"];
411
421
  return {
412
422
  mergeSelectors: true,
413
423
  warn: true,
@@ -427,13 +437,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
427
437
  preflights: mergePresets("preflights"),
428
438
  autocomplete,
429
439
  variants: mergePresets("variants").map(normalizeVariant),
430
- shortcuts: resolveShortcuts(mergePresets("shortcuts")),
440
+ shortcuts: resolveShortcuts(mergePresets("shortcuts")).reverse(),
431
441
  extractors,
432
- safelist: mergePresets("safelist")
442
+ safelist: mergePresets("safelist"),
443
+ separators
433
444
  };
434
445
  }
435
446
 
436
- const version = "0.48.4";
447
+ const version = "0.49.0";
437
448
 
438
449
  class UnoGenerator {
439
450
  constructor(userConfig = {}, defaults = {}) {
@@ -894,8 +905,8 @@ class UnoGenerator {
894
905
  function createGenerator(config, defaults) {
895
906
  return new UnoGenerator(config, defaults);
896
907
  }
897
- const regexScopePlaceholder = / \$\$ /;
898
- const hasScopePlaceholder = (css) => css.match(regexScopePlaceholder);
908
+ const regexScopePlaceholder = /\s\$\$\s+/g;
909
+ const hasScopePlaceholder = (css) => css.match(/\s\$\$\s/);
899
910
  function applyScope(css, scope) {
900
911
  if (hasScopePlaceholder(css))
901
912
  return css.replace(regexScopePlaceholder, scope ? ` ${scope} ` : " ");
@@ -947,6 +958,7 @@ exports.isStaticRule = isStaticRule;
947
958
  exports.isStaticShortcut = isStaticShortcut;
948
959
  exports.isString = isString;
949
960
  exports.isValidSelector = isValidSelector;
961
+ exports.makeRegexClassGroup = makeRegexClassGroup;
950
962
  exports.mergeDeep = mergeDeep;
951
963
  exports.movePseudoElementsEnd = movePseudoElementsEnd;
952
964
  exports.noop = noop;
@@ -954,7 +966,6 @@ exports.normalizeCSSEntries = normalizeCSSEntries;
954
966
  exports.normalizeCSSValues = normalizeCSSValues;
955
967
  exports.normalizeVariant = normalizeVariant;
956
968
  exports.notNull = notNull;
957
- exports.regexClassGroup = regexClassGroup;
958
969
  exports.regexScopePlaceholder = regexScopePlaceholder;
959
970
  exports.toArray = toArray;
960
971
  exports.toEscapedSelector = toEscapedSelector;
package/dist/index.d.ts CHANGED
@@ -131,7 +131,7 @@ declare class BetterMap<K, V> extends Map<K, V> {
131
131
 
132
132
  declare function withLayer<T extends {}>(layer: string, rules: Rule<T>[]): Rule<T>[];
133
133
 
134
- declare const regexClassGroup: RegExp;
134
+ declare function makeRegexClassGroup(separators?: string[]): RegExp;
135
135
  declare function expandVariantGroup(str: string, separators?: string[], depth?: number): string;
136
136
  declare function expandVariantGroup(str: MagicString, separators?: string[], depth?: number): MagicString;
137
137
 
@@ -422,9 +422,17 @@ type Postprocessor = (util: UtilObject) => void;
422
422
  type ThemeExtender<T> = (theme: T) => void;
423
423
  interface ConfigBase<Theme extends {} = {}> {
424
424
  /**
425
- * Rules to generate CSS utilities
425
+ * Rules to generate CSS utilities.
426
+ *
427
+ * Later entries have higher priority.
426
428
  */
427
429
  rules?: Rule<Theme>[];
430
+ /**
431
+ * Variant separator
432
+ *
433
+ * @default [':', '-']
434
+ */
435
+ separators?: Arrayable<string>;
428
436
  /**
429
437
  * Variants that preprocess the selectors,
430
438
  * having the ability to rewrite the CSS object.
@@ -433,6 +441,8 @@ interface ConfigBase<Theme extends {} = {}> {
433
441
  /**
434
442
  * Similar to Windi CSS's shortcuts,
435
443
  * allows you have create new utilities by combining existing ones.
444
+ *
445
+ * Later entries have higher priority.
436
446
  */
437
447
  shortcuts?: UserShortcuts<Theme>;
438
448
  /**
@@ -727,6 +737,7 @@ interface ResolvedConfig<Theme extends {} = {}> extends Omit<RequiredByKey<UserC
727
737
  templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
728
738
  extractors: AutoCompleteExtractor[];
729
739
  };
740
+ separators: string[];
730
741
  }
731
742
  interface GenerateResult {
732
743
  css: string;
@@ -810,4 +821,4 @@ declare const extractorSplit: Extractor;
810
821
 
811
822
  declare const extractorSvelte: Extractor;
812
823
 
813
- export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
824
+ export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, PreparedRule, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, ShortcutValue, SourceCodeTransformer, SourceCodeTransformerEnforce, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -215,9 +215,16 @@ function withLayer(layer, rules) {
215
215
  return rules;
216
216
  }
217
217
 
218
- const regexClassGroup = /((?:[!@\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$?-]|\[.*?\])+?)\)(?!\s*?=>)/gm;
218
+ const regexCache = {};
219
+ function makeRegexClassGroup(separators = ["-", ":"]) {
220
+ const key = separators.join("|");
221
+ if (!regexCache[key])
222
+ regexCache[key] = new RegExp(`((?:[!@\\w+:_/-]|\\[&?>?:?.*\\])+?)(${key})\\(((?:[~!\\w\\s:/\\\\,%#.$?-]|\\[.*?\\])+?)\\)(?!\\s*?=>)`, "gm");
223
+ regexCache[key].lastIndex = 0;
224
+ return regexCache[key];
225
+ }
219
226
  function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
220
- regexClassGroup.lastIndex = 0;
227
+ const regexClassGroup = makeRegexClassGroup(separators);
221
228
  let hasChanged = false;
222
229
  let content = str.toString();
223
230
  do {
@@ -404,6 +411,9 @@ function resolveConfig(userConfig = {}, defaults = {}) {
404
411
  templates: uniq(sortedPresets.map((p) => toArray(p.autocomplete?.templates)).flat()),
405
412
  extractors: sortedPresets.map((p) => toArray(p.autocomplete?.extractors)).flat().sort((a, b) => (a.order || 0) - (b.order || 0))
406
413
  };
414
+ let separators = toArray(mergePresets("separators"));
415
+ if (!separators.length)
416
+ separators = [":", "-"];
407
417
  return {
408
418
  mergeSelectors: true,
409
419
  warn: true,
@@ -423,13 +433,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
423
433
  preflights: mergePresets("preflights"),
424
434
  autocomplete,
425
435
  variants: mergePresets("variants").map(normalizeVariant),
426
- shortcuts: resolveShortcuts(mergePresets("shortcuts")),
436
+ shortcuts: resolveShortcuts(mergePresets("shortcuts")).reverse(),
427
437
  extractors,
428
- safelist: mergePresets("safelist")
438
+ safelist: mergePresets("safelist"),
439
+ separators
429
440
  };
430
441
  }
431
442
 
432
- const version = "0.48.4";
443
+ const version = "0.49.0";
433
444
 
434
445
  class UnoGenerator {
435
446
  constructor(userConfig = {}, defaults = {}) {
@@ -890,8 +901,8 @@ class UnoGenerator {
890
901
  function createGenerator(config, defaults) {
891
902
  return new UnoGenerator(config, defaults);
892
903
  }
893
- const regexScopePlaceholder = / \$\$ /;
894
- const hasScopePlaceholder = (css) => css.match(regexScopePlaceholder);
904
+ const regexScopePlaceholder = /\s\$\$\s+/g;
905
+ const hasScopePlaceholder = (css) => css.match(/\s\$\$\s/);
895
906
  function applyScope(css, scope) {
896
907
  if (hasScopePlaceholder(css))
897
908
  return css.replace(regexScopePlaceholder, scope ? ` ${scope} ` : " ");
@@ -917,4 +928,4 @@ function defaultVariantHandler(input, next) {
917
928
  return next(input);
918
929
  }
919
930
 
920
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
931
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.48.4",
3
+ "version": "0.49.0",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",