@unocss/core 0.33.4 → 0.34.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.cjs CHANGED
@@ -371,17 +371,18 @@ const extractorSvelte = {
371
371
  }
372
372
  };
373
373
 
374
- let createNanoEvents = () => ({
375
- events: {},
376
- emit(event, ...args) {
377
- (this.events[event] || []).forEach(i => i(...args));
378
- },
379
- on(event, cb) {
380
- (this.events[event] = this.events[event] || []).push(cb);
381
- return () =>
382
- (this.events[event] = (this.events[event] || []).filter(i => i !== cb))
383
- }
384
- });
374
+ function createNanoEvents() {
375
+ return {
376
+ events: {},
377
+ emit(event, ...args) {
378
+ (this.events[event] || []).forEach((i) => i(...args));
379
+ },
380
+ on(event, cb) {
381
+ (this.events[event] = this.events[event] || []).push(cb);
382
+ return () => this.events[event] = (this.events[event] || []).filter((i) => i !== cb);
383
+ }
384
+ };
385
+ }
385
386
 
386
387
  function resolveShortcuts(shortcuts) {
387
388
  return toArray(shortcuts).flatMap((s) => {
@@ -435,7 +436,6 @@ function resolveConfig(userConfig = {}, defaults = {}) {
435
436
  mergeSelectors: true,
436
437
  warn: true,
437
438
  blocklist: [],
438
- safelist: [],
439
439
  sortLayers: (layers2) => layers2,
440
440
  ...config,
441
441
  presets: sortedPresets,
@@ -452,11 +452,12 @@ function resolveConfig(userConfig = {}, defaults = {}) {
452
452
  autocomplete,
453
453
  variants: mergePresets("variants").map(normalizeVariant),
454
454
  shortcuts: resolveShortcuts(mergePresets("shortcuts")),
455
- extractors
455
+ extractors,
456
+ safelist: mergePresets("safelist")
456
457
  };
457
458
  }
458
459
 
459
- const version = "0.33.4";
460
+ const version = "0.34.1";
460
461
 
461
462
  class UnoGenerator {
462
463
  constructor(userConfig = {}, defaults = {}) {
@@ -660,7 +661,7 @@ class UnoGenerator {
660
661
  processed = handler.matcher;
661
662
  if (Array.isArray(handler.parent))
662
663
  this.parentOrders.set(handler.parent[0], handler.parent[1]);
663
- handlers.push(handler);
664
+ handlers.unshift(handler);
664
665
  variants.add(v);
665
666
  applied = true;
666
667
  break;
@@ -675,8 +676,9 @@ class UnoGenerator {
675
676
  applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
676
677
  const handlers = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0));
677
678
  const entries = handlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
679
+ const selector = handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw));
678
680
  const obj = {
679
- selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
681
+ selector: movePseudoElementsEnd(selector),
680
682
  entries,
681
683
  parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0),
682
684
  layer: handlers.reduce((p, v) => v.layer || p, void 0),
@@ -839,6 +841,14 @@ function applyScope(css, scope) {
839
841
  else
840
842
  return scope ? `${scope} ${css}` : css;
841
843
  }
844
+ function movePseudoElementsEnd(selector) {
845
+ const pseudoElements = selector.match(/::[\w-]+/g);
846
+ if (pseudoElements) {
847
+ pseudoElements.forEach((e2) => selector = selector.replace(e2, ""));
848
+ selector += pseudoElements.join("");
849
+ }
850
+ return selector;
851
+ }
842
852
  const attributifyRe = /^\[(.+?)(~?=)"(.*)"\]$/;
843
853
  function toEscapedSelector(raw) {
844
854
  if (attributifyRe.test(raw))
@@ -874,6 +884,7 @@ exports.isValidSelector = isValidSelector;
874
884
  exports.matchingPair = matchingPair;
875
885
  exports.mergeDeep = mergeDeep;
876
886
  exports.mergeSet = mergeSet;
887
+ exports.movePseudoElementsEnd = movePseudoElementsEnd;
877
888
  exports.noop = noop;
878
889
  exports.normalizeCSSEntries = normalizeCSSEntries;
879
890
  exports.normalizeCSSValues = normalizeCSSValues;
package/dist/index.d.ts CHANGED
@@ -1,63 +1,54 @@
1
1
  import { LoadConfigResult } from 'unconfig';
2
2
  import MagicString from 'magic-string';
3
3
 
4
- interface EventsMap {
5
- [event: string]: any
6
- }
7
-
4
+ declare type EventsMap = Record<string, any>;
8
5
  interface DefaultEvents extends EventsMap {
9
- [event: string]: (...args: any) => void
6
+ [event: string]: (...args: any) => void;
10
7
  }
11
-
12
8
  interface Unsubscribe {
13
- (): void
9
+ (): void;
14
10
  }
15
-
16
11
  declare class Emitter<Events extends EventsMap = DefaultEvents> {
17
- /**
18
- * Event names in keys and arrays with listeners in values.
19
- *
20
- * ```js
21
- * emitter1.events = emitter2.events
22
- * emitter2.events = { }
23
- * ```
24
- */
25
- events: Partial<{ [E in keyof Events]: Events[E][] }>
26
-
27
- /**
28
- * Add a listener for a given event.
29
- *
30
- * ```js
31
- * const unbind = ee.on('tick', (tickType, tickDuration) => {
32
- * count += 1
33
- * })
34
- *
35
- * disable () {
36
- * unbind()
37
- * }
38
- * ```
39
- *
40
- * @param event The event name.
41
- * @param cb The listener function.
42
- * @returns Unbind listener from event.
43
- */
44
- on<K extends keyof Events>(this: this, event: K, cb: Events[K]): Unsubscribe
45
-
46
- /**
47
- * Calls each of the listeners registered for a given event.
48
- *
49
- * ```js
50
- * ee.emit('tick', tickType, tickDuration)
51
- * ```
52
- *
53
- * @param event The event name.
54
- * @param args The arguments for listeners.
55
- */
56
- emit<K extends keyof Events>(
57
- this: this,
58
- event: K,
59
- ...args: Parameters<Events[K]>
60
- ): void
12
+ /**
13
+ * Event names in keys and arrays with listeners in values.
14
+ *
15
+ * ```js
16
+ * emitter1.events = emitter2.events
17
+ * emitter2.events = { }
18
+ * ```
19
+ */
20
+ events: Partial<{
21
+ [E in keyof Events]: Events[E][];
22
+ }>;
23
+ /**
24
+ * Add a listener for a given event.
25
+ *
26
+ * ```js
27
+ * const unbind = ee.on('tick', (tickType, tickDuration) => {
28
+ * count += 1
29
+ * })
30
+ *
31
+ * disable () {
32
+ * unbind()
33
+ * }
34
+ * ```
35
+ *
36
+ * @param event The event name.
37
+ * @param cb The listener function.
38
+ * @returns Unbind listener from event.
39
+ */
40
+ on<K extends keyof Events>(this: this, event: K, cb: Events[K]): Unsubscribe;
41
+ /**
42
+ * Calls each of the listeners registered for a given event.
43
+ *
44
+ * ```js
45
+ * ee.emit('tick', tickType, tickDuration)
46
+ * ```
47
+ *
48
+ * @param event The event name.
49
+ * @param args The arguments for listeners.
50
+ */
51
+ emit<K extends keyof Events>(this: this, event: K, ...args: Parameters<Events[K]>): void;
61
52
  }
62
53
 
63
54
  declare class UnoGenerator {
@@ -89,6 +80,7 @@ declare class UnoGenerator {
89
80
  declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
90
81
  declare const regexScopePlaceholder: RegExp;
91
82
  declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
83
+ declare function movePseudoElementsEnd(selector: string): string;
92
84
  declare function toEscapedSelector(raw: string): string;
93
85
 
94
86
  declare function escapeRegExp(string: string): string;
@@ -730,4 +722,4 @@ declare const extractorSplit: Extractor;
730
722
 
731
723
  declare const extractorSvelte: Extractor;
732
724
 
733
- export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DetailString, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtractStringOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, Preprocessor, Preset, PresetOptions, RGBAColorValue, Range, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
725
+ export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DetailString, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtractStringOptions, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, Preprocessor, Preset, PresetOptions, RGBAColorValue, Range, RawUtil, Replacement, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, SuggestResult, ThemeExtender, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -367,17 +367,18 @@ const extractorSvelte = {
367
367
  }
368
368
  };
369
369
 
370
- let createNanoEvents = () => ({
371
- events: {},
372
- emit(event, ...args) {
373
- (this.events[event] || []).forEach(i => i(...args));
374
- },
375
- on(event, cb) {
376
- (this.events[event] = this.events[event] || []).push(cb);
377
- return () =>
378
- (this.events[event] = (this.events[event] || []).filter(i => i !== cb))
379
- }
380
- });
370
+ function createNanoEvents() {
371
+ return {
372
+ events: {},
373
+ emit(event, ...args) {
374
+ (this.events[event] || []).forEach((i) => i(...args));
375
+ },
376
+ on(event, cb) {
377
+ (this.events[event] = this.events[event] || []).push(cb);
378
+ return () => this.events[event] = (this.events[event] || []).filter((i) => i !== cb);
379
+ }
380
+ };
381
+ }
381
382
 
382
383
  function resolveShortcuts(shortcuts) {
383
384
  return toArray(shortcuts).flatMap((s) => {
@@ -431,7 +432,6 @@ function resolveConfig(userConfig = {}, defaults = {}) {
431
432
  mergeSelectors: true,
432
433
  warn: true,
433
434
  blocklist: [],
434
- safelist: [],
435
435
  sortLayers: (layers2) => layers2,
436
436
  ...config,
437
437
  presets: sortedPresets,
@@ -448,11 +448,12 @@ function resolveConfig(userConfig = {}, defaults = {}) {
448
448
  autocomplete,
449
449
  variants: mergePresets("variants").map(normalizeVariant),
450
450
  shortcuts: resolveShortcuts(mergePresets("shortcuts")),
451
- extractors
451
+ extractors,
452
+ safelist: mergePresets("safelist")
452
453
  };
453
454
  }
454
455
 
455
- const version = "0.33.4";
456
+ const version = "0.34.1";
456
457
 
457
458
  class UnoGenerator {
458
459
  constructor(userConfig = {}, defaults = {}) {
@@ -656,7 +657,7 @@ class UnoGenerator {
656
657
  processed = handler.matcher;
657
658
  if (Array.isArray(handler.parent))
658
659
  this.parentOrders.set(handler.parent[0], handler.parent[1]);
659
- handlers.push(handler);
660
+ handlers.unshift(handler);
660
661
  variants.add(v);
661
662
  applied = true;
662
663
  break;
@@ -671,8 +672,9 @@ class UnoGenerator {
671
672
  applyVariants(parsed, variantHandlers = parsed[4], raw = parsed[1]) {
672
673
  const handlers = [...variantHandlers].sort((a, b) => (a.order || 0) - (b.order || 0));
673
674
  const entries = handlers.reduce((p, v) => v.body?.(p) || p, parsed[2]);
675
+ const selector = handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw));
674
676
  const obj = {
675
- selector: handlers.reduce((p, v) => v.selector?.(p, entries) || p, toEscapedSelector(raw)),
677
+ selector: movePseudoElementsEnd(selector),
676
678
  entries,
677
679
  parent: handlers.reduce((p, v) => Array.isArray(v.parent) ? v.parent[0] : v.parent || p, void 0),
678
680
  layer: handlers.reduce((p, v) => v.layer || p, void 0),
@@ -835,6 +837,14 @@ function applyScope(css, scope) {
835
837
  else
836
838
  return scope ? `${scope} ${css}` : css;
837
839
  }
840
+ function movePseudoElementsEnd(selector) {
841
+ const pseudoElements = selector.match(/::[\w-]+/g);
842
+ if (pseudoElements) {
843
+ pseudoElements.forEach((e2) => selector = selector.replace(e2, ""));
844
+ selector += pseudoElements.join("");
845
+ }
846
+ return selector;
847
+ }
838
848
  const attributifyRe = /^\[(.+?)(~?=)"(.*)"\]$/;
839
849
  function toEscapedSelector(raw) {
840
850
  if (attributifyRe.test(raw))
@@ -842,4 +852,4 @@ function toEscapedSelector(raw) {
842
852
  return `.${e(raw)}`;
843
853
  }
844
854
 
845
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
855
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, 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.33.4",
3
+ "version": "0.34.1",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "keywords": [
6
6
  "unocss",
@@ -38,7 +38,6 @@
38
38
  "sideEffects": false,
39
39
  "devDependencies": {
40
40
  "magic-string": "^0.26.2",
41
- "nanoevents": "^6.0.2",
42
41
  "unconfig": "^0.3.4"
43
42
  },
44
43
  "scripts": {