@unocss/core 0.45.13 → 0.45.18

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
@@ -45,10 +45,6 @@ function toArray(value = []) {
45
45
  function uniq(value) {
46
46
  return Array.from(new Set(value));
47
47
  }
48
- function mergeSet(target, append) {
49
- append.forEach((i) => target.add(i));
50
- return target;
51
- }
52
48
  function isString(s) {
53
49
  return typeof s === "string";
54
50
  }
@@ -138,7 +134,7 @@ function isStaticShortcut(sc) {
138
134
 
139
135
  const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
140
136
  const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
141
- const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
137
+ const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
142
138
  const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
143
139
  function isAttributifySelector(selector) {
144
140
  return selector.match(attributifyRE);
@@ -286,12 +282,12 @@ function createValueHandler(handlers) {
286
282
  return handler;
287
283
  }
288
284
 
289
- const splitCode = (code) => code.split(/\\?[\s'"`;={}]+/g).filter(isValidSelector);
285
+ const splitCode = (code) => [...new Set(code.split(/\\?[\s'"`;={}]+/g))].filter(isValidSelector);
290
286
  const extractorSplit = {
291
287
  name: "split",
292
288
  order: 0,
293
289
  extract({ code }) {
294
- return new Set(splitCode(code));
290
+ return splitCode(code);
295
291
  }
296
292
  };
297
293
 
@@ -325,7 +321,7 @@ function createNanoEvents() {
325
321
  const LAYER_DEFAULT = "default";
326
322
  const LAYER_PREFLIGHTS = "preflights";
327
323
  const LAYER_SHORTCUTS = "shortcuts";
328
- const DEAFULT_LAYERS = {
324
+ const DEFAULT_LAYERS = {
329
325
  [LAYER_PREFLIGHTS]: -100,
330
326
  [LAYER_SHORTCUTS]: -10,
331
327
  [LAYER_DEFAULT]: 0
@@ -364,7 +360,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
364
360
  ...rawPresets.filter((p) => !p.enforce),
365
361
  ...rawPresets.filter((p) => p.enforce === "post")
366
362
  ];
367
- const layers = Object.assign(DEAFULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
363
+ const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
368
364
  function mergePresets(key) {
369
365
  return uniq([
370
366
  ...sortedPresets.flatMap((p) => toArray(p[key] || [])),
@@ -378,13 +374,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
378
374
  const rules = mergePresets("rules");
379
375
  const rulesStaticMap = {};
380
376
  const rulesSize = rules.length;
381
- rules.forEach((rule, i) => {
377
+ const rulesDynamic = rules.map((rule, i) => {
382
378
  if (isStaticRule(rule)) {
383
379
  const prefix = rule[2]?.prefix || "";
384
380
  rulesStaticMap[prefix + rule[0]] = [i, rule[1], rule[2], rule];
385
- delete rules[i];
381
+ return void 0;
386
382
  }
387
- });
383
+ return [i, ...rule];
384
+ }).filter(Boolean).reverse();
388
385
  const theme = clone([
389
386
  ...sortedPresets.map((p) => p.theme || {}),
390
387
  config.theme || {}
@@ -406,7 +403,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
406
403
  layers,
407
404
  theme,
408
405
  rulesSize,
409
- rulesDynamic: rules,
406
+ rulesDynamic,
410
407
  rulesStaticMap,
411
408
  preprocess: mergePresets("preprocess"),
412
409
  postprocess: mergePresets("postprocess"),
@@ -419,7 +416,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
419
416
  };
420
417
  }
421
418
 
422
- const version = "0.45.13";
419
+ const version = "0.45.18";
423
420
 
424
421
  class UnoGenerator {
425
422
  constructor(userConfig = {}, defaults = {}) {
@@ -455,7 +452,10 @@ class UnoGenerator {
455
452
  };
456
453
  for (const extractor of this.config.extractors) {
457
454
  const result = await extractor.extract(context);
458
- result?.forEach((t) => set.add(t));
455
+ if (result) {
456
+ for (const token of result)
457
+ set.add(token);
458
+ }
459
459
  }
460
460
  return set;
461
461
  }
@@ -583,12 +583,12 @@ class UnoGenerator {
583
583
  return layerCache[layer];
584
584
  let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
585
585
  const size = items.length;
586
- const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta]) => {
586
+ const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta, , variantNoMerge]) => {
587
587
  const scopedSelector = selector ? applyScope(selector, scope) : selector;
588
588
  return [
589
589
  [[scopedSelector ?? "", meta?.sort ?? 0]],
590
590
  body,
591
- !!meta?.noMerge
591
+ !!(variantNoMerge ?? meta?.noMerge)
592
592
  ];
593
593
  });
594
594
  if (!sorted.length)
@@ -701,7 +701,8 @@ class UnoGenerator {
701
701
  entries: variantContextResult.entries,
702
702
  parent,
703
703
  layer: variantContextResult.layer,
704
- sort: variantContextResult.sort
704
+ sort: variantContextResult.sort,
705
+ noMerge: variantContextResult.noMerge
705
706
  };
706
707
  for (const p of this.config.postprocess)
707
708
  p(obj);
@@ -719,14 +720,13 @@ class UnoGenerator {
719
720
  }
720
721
  async parseUtil(input, context, internal = false) {
721
722
  const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
722
- const recordRule = this.config.details ? (r) => {
723
+ if (this.config.details)
723
724
  context.rules = context.rules ?? [];
724
- context.rules.push(r);
725
- } : noop;
726
725
  const staticMatch = this.config.rulesStaticMap[processed];
727
726
  if (staticMatch) {
728
727
  if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
729
- recordRule(staticMatch[3]);
728
+ if (this.config.details)
729
+ context.rules.push(staticMatch[3]);
730
730
  const index = staticMatch[0];
731
731
  const entry = normalizeCSSEntries(staticMatch[1]);
732
732
  const meta = staticMatch[2];
@@ -737,24 +737,24 @@ class UnoGenerator {
737
737
  }
738
738
  }
739
739
  context.variantHandlers = variantHandlers;
740
- const { rulesDynamic, rulesSize } = this.config;
741
- for (let i = rulesSize - 1; i >= 0; i--) {
742
- const rule = rulesDynamic[i];
743
- if (!rule)
740
+ const { rulesDynamic } = this.config;
741
+ for (const [i, matcher, handler, meta] of rulesDynamic) {
742
+ if (meta?.internal && !internal)
744
743
  continue;
745
- if (rule[2]?.internal && !internal)
746
- continue;
747
- const [matcher, handler, meta] = rule;
748
- if (meta?.prefix && !processed.startsWith(meta.prefix))
749
- continue;
750
- const unprefixed = meta?.prefix ? processed.slice(meta.prefix.length) : processed;
744
+ let unprefixed = processed;
745
+ if (meta?.prefix) {
746
+ if (!processed.startsWith(meta.prefix))
747
+ continue;
748
+ unprefixed = processed.slice(meta.prefix.length);
749
+ }
751
750
  const match = unprefixed.match(matcher);
752
751
  if (!match)
753
752
  continue;
754
753
  const result = await handler(match, context);
755
754
  if (!result)
756
755
  continue;
757
- recordRule(rule);
756
+ if (this.config.details)
757
+ context.rules.push([matcher, handler, meta]);
758
758
  const entries = normalizeCSSValues(result).filter((i2) => i2.length);
759
759
  if (entries.length) {
760
760
  return entries.map((e2) => {
@@ -770,8 +770,8 @@ class UnoGenerator {
770
770
  if (!parsed)
771
771
  return;
772
772
  if (isRawUtil(parsed))
773
- return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
774
- const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
773
+ return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0, void 0];
774
+ const { selector, entries, parent, layer: variantLayer, sort: variantSort, noMerge } = this.applyVariants(parsed);
775
775
  const body = entriesToCss(entries);
776
776
  if (!body)
777
777
  return;
@@ -781,7 +781,7 @@ class UnoGenerator {
781
781
  layer: variantLayer ?? metaLayer,
782
782
  sort: variantSort ?? metaSort
783
783
  };
784
- return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
784
+ return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
785
785
  }
786
786
  expandShortcut(input, context, depth = 5) {
787
787
  if (depth === 0)
@@ -841,12 +841,12 @@ class UnoGenerator {
841
841
  const rawStringfieldUtil = [];
842
842
  for (const item of parsed) {
843
843
  if (isRawUtil(item)) {
844
- rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
844
+ rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context, void 0]);
845
845
  continue;
846
846
  }
847
- const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
847
+ const { selector, entries, parent: parent2, sort, noMerge } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
848
848
  const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
849
- mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
849
+ mapItem[0].push([entries, !!(noMerge ?? item[3]?.noMerge), sort ?? 0]);
850
850
  }
851
851
  return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
852
852
  const stringify = (flatten, noMerge, entrySortPair) => {
@@ -855,7 +855,7 @@ class UnoGenerator {
855
855
  return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
856
856
  const body = entriesToCss(entries);
857
857
  if (body)
858
- return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
858
+ return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context, void 0];
859
859
  return void 0;
860
860
  });
861
861
  };
@@ -887,7 +887,8 @@ function applyScope(css, scope) {
887
887
  function movePseudoElementsEnd(selector) {
888
888
  const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
889
889
  if (pseudoElements) {
890
- pseudoElements.forEach((e2) => selector = selector.replace(e2, ""));
890
+ for (const e2 of pseudoElements)
891
+ selector = selector.replace(e2, "");
891
892
  selector += pseudoElements.join("");
892
893
  }
893
894
  return selector;
@@ -928,7 +929,6 @@ exports.isStaticShortcut = isStaticShortcut;
928
929
  exports.isString = isString;
929
930
  exports.isValidSelector = isValidSelector;
930
931
  exports.mergeDeep = mergeDeep;
931
- exports.mergeSet = mergeSet;
932
932
  exports.movePseudoElementsEnd = movePseudoElementsEnd;
933
933
  exports.noop = noop;
934
934
  exports.normalizeCSSEntries = normalizeCSSEntries;
package/dist/index.d.ts CHANGED
@@ -102,7 +102,6 @@ declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
102
102
 
103
103
  declare function toArray<T>(value?: T | T[]): T[];
104
104
  declare function uniq<T>(value: T[]): T[];
105
- declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
106
105
  declare function isString(s: any): s is string;
107
106
 
108
107
  declare const attributifyRE: RegExp;
@@ -130,7 +129,7 @@ declare class BetterMap<K, V> extends Map<K, V> {
130
129
  map<R>(mapFn: (value: V, key: K) => R): R[];
131
130
  }
132
131
 
133
- declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
132
+ declare function withLayer<T extends {}>(layer: string, rules: Rule<T>[]): Rule<T>[];
134
133
 
135
134
  declare const regexClassGroup: RegExp;
136
135
  declare function expandVariantGroup(str: string, seperators?: string[], depth?: number): string;
@@ -272,7 +271,7 @@ interface PreflightContext<Theme extends {} = {}> {
272
271
  }
273
272
  interface Extractor {
274
273
  name: string;
275
- extract(ctx: ExtractorContext): Awaitable<Set<string> | undefined>;
274
+ extract(ctx: ExtractorContext): Awaitable<Set<string> | string[] | undefined>;
276
275
  order?: number;
277
276
  }
278
277
  interface RuleMeta {
@@ -356,6 +355,11 @@ interface VariantHandlerContext {
356
355
  * Order in which the variant is sorted within single rule.
357
356
  */
358
357
  sort?: number;
358
+ /**
359
+ * Option to not merge the resulting entries even if the body are the same.
360
+ * @default false
361
+ */
362
+ noMerge?: boolean;
359
363
  }
360
364
  interface VariantHandler {
361
365
  /**
@@ -617,6 +621,7 @@ interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
617
621
  onInvalidate: (fn: () => void) => void;
618
622
  root: string;
619
623
  updateRoot: (root: string) => Promise<LoadConfigResult<Config>>;
624
+ getConfigFileList: () => string[];
620
625
  }
621
626
  interface SourceMap {
622
627
  file?: string;
@@ -687,7 +692,7 @@ interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors'
687
692
  preprocess: Preprocessor[];
688
693
  postprocess: Postprocessor[];
689
694
  rulesSize: number;
690
- rulesDynamic: (DynamicRule | undefined)[];
695
+ rulesDynamic: [number, ...DynamicRule][];
691
696
  rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined, Rule] | undefined>;
692
697
  autocomplete: {
693
698
  templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
@@ -725,7 +730,8 @@ declare type StringifiedUtil = readonly [
725
730
  body: string,
726
731
  parent: string | undefined,
727
732
  meta: RuleMeta | undefined,
728
- context: RuleContext | undefined
733
+ context: RuleContext | undefined,
734
+ noMerge: boolean | undefined
729
735
  ];
730
736
  declare type PreparedRule = readonly [
731
737
  selector: [string, number][],
@@ -738,6 +744,7 @@ interface UtilObject {
738
744
  parent: string | undefined;
739
745
  layer: string | undefined;
740
746
  sort: number | undefined;
747
+ noMerge: boolean | undefined;
741
748
  }
742
749
  interface GenerateOptions {
743
750
  /**
@@ -769,4 +776,4 @@ declare const extractorSplit: Extractor;
769
776
 
770
777
  declare const extractorSvelte: Extractor;
771
778
 
772
- export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, 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, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
779
+ export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, 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, 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 };
package/dist/index.mjs CHANGED
@@ -41,10 +41,6 @@ function toArray(value = []) {
41
41
  function uniq(value) {
42
42
  return Array.from(new Set(value));
43
43
  }
44
- function mergeSet(target, append) {
45
- append.forEach((i) => target.add(i));
46
- return target;
47
- }
48
44
  function isString(s) {
49
45
  return typeof s === "string";
50
46
  }
@@ -134,7 +130,7 @@ function isStaticShortcut(sc) {
134
130
 
135
131
  const attributifyRE = /^\[(.+?)~?="(.*)"\]$/;
136
132
  const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
137
- const validateFilterRE = /(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/;
133
+ const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
138
134
  const CONTROL_SHORTCUT_NO_MERGE = "$$shortcut-no-merge";
139
135
  function isAttributifySelector(selector) {
140
136
  return selector.match(attributifyRE);
@@ -282,12 +278,12 @@ function createValueHandler(handlers) {
282
278
  return handler;
283
279
  }
284
280
 
285
- const splitCode = (code) => code.split(/\\?[\s'"`;={}]+/g).filter(isValidSelector);
281
+ const splitCode = (code) => [...new Set(code.split(/\\?[\s'"`;={}]+/g))].filter(isValidSelector);
286
282
  const extractorSplit = {
287
283
  name: "split",
288
284
  order: 0,
289
285
  extract({ code }) {
290
- return new Set(splitCode(code));
286
+ return splitCode(code);
291
287
  }
292
288
  };
293
289
 
@@ -321,7 +317,7 @@ function createNanoEvents() {
321
317
  const LAYER_DEFAULT = "default";
322
318
  const LAYER_PREFLIGHTS = "preflights";
323
319
  const LAYER_SHORTCUTS = "shortcuts";
324
- const DEAFULT_LAYERS = {
320
+ const DEFAULT_LAYERS = {
325
321
  [LAYER_PREFLIGHTS]: -100,
326
322
  [LAYER_SHORTCUTS]: -10,
327
323
  [LAYER_DEFAULT]: 0
@@ -360,7 +356,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
360
356
  ...rawPresets.filter((p) => !p.enforce),
361
357
  ...rawPresets.filter((p) => p.enforce === "post")
362
358
  ];
363
- const layers = Object.assign(DEAFULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
359
+ const layers = Object.assign(DEFAULT_LAYERS, ...rawPresets.map((i) => i.layers), userConfig.layers);
364
360
  function mergePresets(key) {
365
361
  return uniq([
366
362
  ...sortedPresets.flatMap((p) => toArray(p[key] || [])),
@@ -374,13 +370,14 @@ function resolveConfig(userConfig = {}, defaults = {}) {
374
370
  const rules = mergePresets("rules");
375
371
  const rulesStaticMap = {};
376
372
  const rulesSize = rules.length;
377
- rules.forEach((rule, i) => {
373
+ const rulesDynamic = rules.map((rule, i) => {
378
374
  if (isStaticRule(rule)) {
379
375
  const prefix = rule[2]?.prefix || "";
380
376
  rulesStaticMap[prefix + rule[0]] = [i, rule[1], rule[2], rule];
381
- delete rules[i];
377
+ return void 0;
382
378
  }
383
- });
379
+ return [i, ...rule];
380
+ }).filter(Boolean).reverse();
384
381
  const theme = clone([
385
382
  ...sortedPresets.map((p) => p.theme || {}),
386
383
  config.theme || {}
@@ -402,7 +399,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
402
399
  layers,
403
400
  theme,
404
401
  rulesSize,
405
- rulesDynamic: rules,
402
+ rulesDynamic,
406
403
  rulesStaticMap,
407
404
  preprocess: mergePresets("preprocess"),
408
405
  postprocess: mergePresets("postprocess"),
@@ -415,7 +412,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
415
412
  };
416
413
  }
417
414
 
418
- const version = "0.45.13";
415
+ const version = "0.45.18";
419
416
 
420
417
  class UnoGenerator {
421
418
  constructor(userConfig = {}, defaults = {}) {
@@ -451,7 +448,10 @@ class UnoGenerator {
451
448
  };
452
449
  for (const extractor of this.config.extractors) {
453
450
  const result = await extractor.extract(context);
454
- result?.forEach((t) => set.add(t));
451
+ if (result) {
452
+ for (const token of result)
453
+ set.add(token);
454
+ }
455
455
  }
456
456
  return set;
457
457
  }
@@ -579,12 +579,12 @@ class UnoGenerator {
579
579
  return layerCache[layer];
580
580
  let css = Array.from(sheet).sort((a, b) => (this.parentOrders.get(a[0]) ?? 0) - (this.parentOrders.get(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
581
581
  const size = items.length;
582
- const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta]) => {
582
+ const sorted = items.filter((i) => (i[4]?.layer || LAYER_DEFAULT) === layer).sort((a, b) => a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0).map(([, selector, body, , meta, , variantNoMerge]) => {
583
583
  const scopedSelector = selector ? applyScope(selector, scope) : selector;
584
584
  return [
585
585
  [[scopedSelector ?? "", meta?.sort ?? 0]],
586
586
  body,
587
- !!meta?.noMerge
587
+ !!(variantNoMerge ?? meta?.noMerge)
588
588
  ];
589
589
  });
590
590
  if (!sorted.length)
@@ -697,7 +697,8 @@ class UnoGenerator {
697
697
  entries: variantContextResult.entries,
698
698
  parent,
699
699
  layer: variantContextResult.layer,
700
- sort: variantContextResult.sort
700
+ sort: variantContextResult.sort,
701
+ noMerge: variantContextResult.noMerge
701
702
  };
702
703
  for (const p of this.config.postprocess)
703
704
  p(obj);
@@ -715,14 +716,13 @@ class UnoGenerator {
715
716
  }
716
717
  async parseUtil(input, context, internal = false) {
717
718
  const [raw, processed, variantHandlers] = isString(input) ? this.matchVariants(input) : input;
718
- const recordRule = this.config.details ? (r) => {
719
+ if (this.config.details)
719
720
  context.rules = context.rules ?? [];
720
- context.rules.push(r);
721
- } : noop;
722
721
  const staticMatch = this.config.rulesStaticMap[processed];
723
722
  if (staticMatch) {
724
723
  if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
725
- recordRule(staticMatch[3]);
724
+ if (this.config.details)
725
+ context.rules.push(staticMatch[3]);
726
726
  const index = staticMatch[0];
727
727
  const entry = normalizeCSSEntries(staticMatch[1]);
728
728
  const meta = staticMatch[2];
@@ -733,24 +733,24 @@ class UnoGenerator {
733
733
  }
734
734
  }
735
735
  context.variantHandlers = variantHandlers;
736
- const { rulesDynamic, rulesSize } = this.config;
737
- for (let i = rulesSize - 1; i >= 0; i--) {
738
- const rule = rulesDynamic[i];
739
- if (!rule)
736
+ const { rulesDynamic } = this.config;
737
+ for (const [i, matcher, handler, meta] of rulesDynamic) {
738
+ if (meta?.internal && !internal)
740
739
  continue;
741
- if (rule[2]?.internal && !internal)
742
- continue;
743
- const [matcher, handler, meta] = rule;
744
- if (meta?.prefix && !processed.startsWith(meta.prefix))
745
- continue;
746
- const unprefixed = meta?.prefix ? processed.slice(meta.prefix.length) : processed;
740
+ let unprefixed = processed;
741
+ if (meta?.prefix) {
742
+ if (!processed.startsWith(meta.prefix))
743
+ continue;
744
+ unprefixed = processed.slice(meta.prefix.length);
745
+ }
747
746
  const match = unprefixed.match(matcher);
748
747
  if (!match)
749
748
  continue;
750
749
  const result = await handler(match, context);
751
750
  if (!result)
752
751
  continue;
753
- recordRule(rule);
752
+ if (this.config.details)
753
+ context.rules.push([matcher, handler, meta]);
754
754
  const entries = normalizeCSSValues(result).filter((i2) => i2.length);
755
755
  if (entries.length) {
756
756
  return entries.map((e2) => {
@@ -766,8 +766,8 @@ class UnoGenerator {
766
766
  if (!parsed)
767
767
  return;
768
768
  if (isRawUtil(parsed))
769
- return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
770
- const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
769
+ return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0, void 0];
770
+ const { selector, entries, parent, layer: variantLayer, sort: variantSort, noMerge } = this.applyVariants(parsed);
771
771
  const body = entriesToCss(entries);
772
772
  if (!body)
773
773
  return;
@@ -777,7 +777,7 @@ class UnoGenerator {
777
777
  layer: variantLayer ?? metaLayer,
778
778
  sort: variantSort ?? metaSort
779
779
  };
780
- return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
780
+ return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0, noMerge];
781
781
  }
782
782
  expandShortcut(input, context, depth = 5) {
783
783
  if (depth === 0)
@@ -837,12 +837,12 @@ class UnoGenerator {
837
837
  const rawStringfieldUtil = [];
838
838
  for (const item of parsed) {
839
839
  if (isRawUtil(item)) {
840
- rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
840
+ rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context, void 0]);
841
841
  continue;
842
842
  }
843
- const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
843
+ const { selector, entries, parent: parent2, sort, noMerge } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
844
844
  const mapItem = selectorMap.getFallback(selector, parent2, [[], item[0]]);
845
- mapItem[0].push([entries, !!item[3]?.noMerge, sort ?? 0]);
845
+ mapItem[0].push([entries, !!(noMerge ?? item[3]?.noMerge), sort ?? 0]);
846
846
  }
847
847
  return rawStringfieldUtil.concat(selectorMap.map(([e2, index], selector, joinedParents) => {
848
848
  const stringify = (flatten, noMerge, entrySortPair) => {
@@ -851,7 +851,7 @@ class UnoGenerator {
851
851
  return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
852
852
  const body = entriesToCss(entries);
853
853
  if (body)
854
- return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context];
854
+ return [index, selector, body, joinedParents, { ...meta, noMerge, sort: maxSort }, context, void 0];
855
855
  return void 0;
856
856
  });
857
857
  };
@@ -883,7 +883,8 @@ function applyScope(css, scope) {
883
883
  function movePseudoElementsEnd(selector) {
884
884
  const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g);
885
885
  if (pseudoElements) {
886
- pseudoElements.forEach((e2) => selector = selector.replace(e2, ""));
886
+ for (const e2 of pseudoElements)
887
+ selector = selector.replace(e2, "");
887
888
  selector += pseudoElements.join("");
888
889
  }
889
890
  return selector;
@@ -898,4 +899,4 @@ function defaultVariantHandler(input, next) {
898
899
  return next(input);
899
900
  }
900
901
 
901
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
902
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.45.13",
3
+ "version": "0.45.18",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "devDependencies": {
40
40
  "magic-string": "^0.26.2",
41
- "unconfig": "^0.3.5"
41
+ "unconfig": "^0.3.6"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",