@unocss/core 0.31.14 → 0.31.17

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
@@ -155,6 +155,8 @@ function isRawUtil(util) {
155
155
  function notNull(value) {
156
156
  return value != null;
157
157
  }
158
+ function noop() {
159
+ }
158
160
 
159
161
  class TwoKeyMap {
160
162
  constructor() {
@@ -407,7 +409,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
407
409
  const rulesSize = rules.length;
408
410
  rules.forEach((rule, i) => {
409
411
  if (isStaticRule(rule)) {
410
- rulesStaticMap[rule[0]] = [i, rule[1], rule[2]];
412
+ rulesStaticMap[rule[0]] = [i, rule[1], rule[2], rule];
411
413
  delete rules[i];
412
414
  }
413
415
  });
@@ -445,7 +447,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
445
447
  };
446
448
  }
447
449
 
448
- const version = "0.31.14";
450
+ const version = "0.31.17";
449
451
 
450
452
  class UnoGenerator {
451
453
  constructor(userConfig = {}, defaults = {}) {
@@ -515,6 +517,8 @@ class UnoGenerator {
515
517
  return;
516
518
  }
517
519
  const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2], applied[3]]);
520
+ if (this.config.details)
521
+ context.variants = [...applied[3]];
518
522
  const expanded = this.expandShortcut(context.currentSelector, context);
519
523
  if (expanded) {
520
524
  const utils = await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]);
@@ -523,7 +527,7 @@ class UnoGenerator {
523
527
  return utils;
524
528
  }
525
529
  } else {
526
- const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
530
+ const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i, context)).filter(notNull);
527
531
  if (utils?.length) {
528
532
  this._cache.set(cacheKey, utils);
529
533
  return utils;
@@ -680,10 +684,16 @@ class UnoGenerator {
680
684
  }
681
685
  async parseUtil(input, context, internal = false) {
682
686
  const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
687
+ const recordRule = this.config.details ? (r) => {
688
+ context.rules = context.rules ?? [];
689
+ context.rules.push(r);
690
+ } : noop;
683
691
  const staticMatch = this.config.rulesStaticMap[processed];
684
692
  if (staticMatch) {
685
- if (staticMatch[1] && (internal || !staticMatch[2]?.internal))
693
+ if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
694
+ recordRule(staticMatch[3]);
686
695
  return [[staticMatch[0], raw, normalizeCSSEntries(staticMatch[1]), staticMatch[2], variantHandlers]];
696
+ }
687
697
  }
688
698
  context.variantHandlers = variantHandlers;
689
699
  const { rulesDynamic, rulesSize } = this.config;
@@ -700,6 +710,7 @@ class UnoGenerator {
700
710
  const result = await handler(match, context);
701
711
  if (!result)
702
712
  continue;
713
+ recordRule(rule);
703
714
  if (typeof result === "string")
704
715
  return [[i, result, meta]];
705
716
  const entries = normalizeCSSValues(result).filter((i2) => i2.length);
@@ -707,11 +718,11 @@ class UnoGenerator {
707
718
  return entries.map((e2) => [i, raw, e2, meta, variantHandlers]);
708
719
  }
709
720
  }
710
- stringifyUtil(parsed) {
721
+ stringifyUtil(parsed, context) {
711
722
  if (!parsed)
712
723
  return;
713
724
  if (isRawUtil(parsed))
714
- return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
725
+ return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
715
726
  const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
716
727
  const body = entriesToCss(entries);
717
728
  if (!body)
@@ -722,11 +733,15 @@ class UnoGenerator {
722
733
  layer: variantLayer ?? metaLayer,
723
734
  sort: variantSort ?? metaSort
724
735
  };
725
- return [parsed[0], selector, body, parent, ruleMeta];
736
+ return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
726
737
  }
727
738
  expandShortcut(processed, context, depth = 3) {
728
739
  if (depth === 0)
729
740
  return;
741
+ const recordShortcut = this.config.details ? (s) => {
742
+ context.shortcuts = context.shortcuts ?? [];
743
+ context.shortcuts.push(s);
744
+ } : noop;
730
745
  let meta;
731
746
  let result;
732
747
  for (const s of this.config.shortcuts) {
@@ -734,6 +749,7 @@ class UnoGenerator {
734
749
  if (s[0] === processed) {
735
750
  meta = meta || s[2];
736
751
  result = s[1];
752
+ recordShortcut(s);
737
753
  break;
738
754
  }
739
755
  } else {
@@ -742,6 +758,7 @@ class UnoGenerator {
742
758
  result = s[1](match, context);
743
759
  if (result) {
744
760
  meta = meta || s[2];
761
+ recordShortcut(s);
745
762
  break;
746
763
  }
747
764
  }
@@ -767,7 +784,7 @@ class UnoGenerator {
767
784
  const rawStringfieldUtil = [];
768
785
  for (const item of parsed) {
769
786
  if (isRawUtil(item)) {
770
- rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2]]);
787
+ rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
771
788
  continue;
772
789
  }
773
790
  const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
@@ -781,7 +798,7 @@ class UnoGenerator {
781
798
  return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
782
799
  const body = entriesToCss(entries);
783
800
  if (body)
784
- return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }];
801
+ return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }, context];
785
802
  return void 0;
786
803
  });
787
804
  };
@@ -844,6 +861,7 @@ exports.isValidSelector = isValidSelector;
844
861
  exports.matchingPair = matchingPair;
845
862
  exports.mergeDeep = mergeDeep;
846
863
  exports.mergeSet = mergeSet;
864
+ exports.noop = noop;
847
865
  exports.normalizeCSSEntries = normalizeCSSEntries;
848
866
  exports.normalizeCSSValues = normalizeCSSValues;
849
867
  exports.normalizeVariant = normalizeVariant;
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ declare class UnoGenerator {
19
19
  applyVariants(parsed: ParsedUtil, variantHandlers?: VariantHandler[], raw?: string): UtilObject;
20
20
  constructCustomCSS(context: Readonly<RuleContext>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
21
21
  parseUtil(input: string | VariantMatchedResult, context: RuleContext, internal?: boolean): Promise<ParsedUtil[] | RawUtil[] | undefined>;
22
- stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined;
22
+ stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext): StringifiedUtil | undefined;
23
23
  expandShortcut(processed: string, context: RuleContext, depth?: number): [string[], RuleMeta | undefined] | undefined;
24
24
  stringifyShortcuts(parent: VariantMatchedResult, context: RuleContext, expanded: string[], meta?: RuleMeta): Promise<StringifiedUtil[] | undefined>;
25
25
  isBlocked(raw: string): boolean;
@@ -58,6 +58,7 @@ declare function isValidSelector(selector?: string): selector is string;
58
58
  declare function normalizeVariant(variant: Variant): VariantObject;
59
59
  declare function isRawUtil(util: ParsedUtil | RawUtil | StringifiedUtil): util is RawUtil;
60
60
  declare function notNull<T>(value: T | null | undefined): value is T;
61
+ declare function noop(): void;
61
62
 
62
63
  declare class TwoKeyMap<K1, K2, V> {
63
64
  _map: Map<K1, Map<K2, V>>;
@@ -187,6 +188,18 @@ interface RuleContext<Theme extends {} = {}> {
187
188
  * Variants and selector escaping will be handled automatically.
188
189
  */
189
190
  constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
191
+ /**
192
+ * Available only when `details` option is enabled.
193
+ */
194
+ rules?: Rule[];
195
+ /**
196
+ * Available only when `details` option is enabled.
197
+ */
198
+ shortcuts?: Shortcut[];
199
+ /**
200
+ * Available only when `details` option is enabled.
201
+ */
202
+ variants?: Variant[];
190
203
  }
191
204
  interface VariantContext<Theme extends {} = {}> {
192
205
  /**
@@ -386,6 +399,16 @@ interface ConfigBase<Theme extends {} = {}> {
386
399
  */
387
400
  extractors?: Arrayable<AutoCompleteExtractor>;
388
401
  };
402
+ /**
403
+ * Expose internal details for debugging / inspecting
404
+ *
405
+ * Added `rules`, `shortcuts`, `variants` to the context and expose the context object in `StringifiedUtil`
406
+ *
407
+ * You don't usually need to set this.
408
+ *
409
+ * @default false
410
+ */
411
+ details?: boolean;
389
412
  }
390
413
  declare type AutoCompleteTemplate = string;
391
414
  declare type AutoCompleteFunction = (input: string) => Awaitable<string[]>;
@@ -564,7 +587,7 @@ interface ResolvedConfig extends Omit<RequiredByKey<UserConfig, 'mergeSelectors'
564
587
  postprocess: Postprocessor[];
565
588
  rulesSize: number;
566
589
  rulesDynamic: (DynamicRule | undefined)[];
567
- rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined] | undefined>;
590
+ rulesStaticMap: Record<string, [number, CSSObject | CSSEntries, RuleMeta | undefined, Rule] | undefined>;
568
591
  autocomplete: {
569
592
  templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
570
593
  extractors: AutoCompleteExtractor[];
@@ -600,7 +623,8 @@ declare type StringifiedUtil = readonly [
600
623
  selector: string | undefined,
601
624
  body: string,
602
625
  parent: string | undefined,
603
- meta: RuleMeta | undefined
626
+ meta: RuleMeta | undefined,
627
+ context: RuleContext | undefined
604
628
  ];
605
629
  interface UtilObject {
606
630
  selector: string;
@@ -639,4 +663,4 @@ declare const extractorSplit: Extractor;
639
663
 
640
664
  declare const extractorSvelte: Extractor;
641
665
 
642
- 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, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
666
+ 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, 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 };
package/dist/index.mjs CHANGED
@@ -151,6 +151,8 @@ function isRawUtil(util) {
151
151
  function notNull(value) {
152
152
  return value != null;
153
153
  }
154
+ function noop() {
155
+ }
154
156
 
155
157
  class TwoKeyMap {
156
158
  constructor() {
@@ -403,7 +405,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
403
405
  const rulesSize = rules.length;
404
406
  rules.forEach((rule, i) => {
405
407
  if (isStaticRule(rule)) {
406
- rulesStaticMap[rule[0]] = [i, rule[1], rule[2]];
408
+ rulesStaticMap[rule[0]] = [i, rule[1], rule[2], rule];
407
409
  delete rules[i];
408
410
  }
409
411
  });
@@ -441,7 +443,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
441
443
  };
442
444
  }
443
445
 
444
- const version = "0.31.14";
446
+ const version = "0.31.17";
445
447
 
446
448
  class UnoGenerator {
447
449
  constructor(userConfig = {}, defaults = {}) {
@@ -511,6 +513,8 @@ class UnoGenerator {
511
513
  return;
512
514
  }
513
515
  const context = this.makeContext(raw, [alias || applied[0], applied[1], applied[2], applied[3]]);
516
+ if (this.config.details)
517
+ context.variants = [...applied[3]];
514
518
  const expanded = this.expandShortcut(context.currentSelector, context);
515
519
  if (expanded) {
516
520
  const utils = await this.stringifyShortcuts(context.variantMatch, context, expanded[0], expanded[1]);
@@ -519,7 +523,7 @@ class UnoGenerator {
519
523
  return utils;
520
524
  }
521
525
  } else {
522
- const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i)).filter(notNull);
526
+ const utils = (await this.parseUtil(context.variantMatch, context))?.map((i) => this.stringifyUtil(i, context)).filter(notNull);
523
527
  if (utils?.length) {
524
528
  this._cache.set(cacheKey, utils);
525
529
  return utils;
@@ -676,10 +680,16 @@ class UnoGenerator {
676
680
  }
677
681
  async parseUtil(input, context, internal = false) {
678
682
  const [raw, processed, variantHandlers] = typeof input === "string" ? this.matchVariants(input) : input;
683
+ const recordRule = this.config.details ? (r) => {
684
+ context.rules = context.rules ?? [];
685
+ context.rules.push(r);
686
+ } : noop;
679
687
  const staticMatch = this.config.rulesStaticMap[processed];
680
688
  if (staticMatch) {
681
- if (staticMatch[1] && (internal || !staticMatch[2]?.internal))
689
+ if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
690
+ recordRule(staticMatch[3]);
682
691
  return [[staticMatch[0], raw, normalizeCSSEntries(staticMatch[1]), staticMatch[2], variantHandlers]];
692
+ }
683
693
  }
684
694
  context.variantHandlers = variantHandlers;
685
695
  const { rulesDynamic, rulesSize } = this.config;
@@ -696,6 +706,7 @@ class UnoGenerator {
696
706
  const result = await handler(match, context);
697
707
  if (!result)
698
708
  continue;
709
+ recordRule(rule);
699
710
  if (typeof result === "string")
700
711
  return [[i, result, meta]];
701
712
  const entries = normalizeCSSValues(result).filter((i2) => i2.length);
@@ -703,11 +714,11 @@ class UnoGenerator {
703
714
  return entries.map((e2) => [i, raw, e2, meta, variantHandlers]);
704
715
  }
705
716
  }
706
- stringifyUtil(parsed) {
717
+ stringifyUtil(parsed, context) {
707
718
  if (!parsed)
708
719
  return;
709
720
  if (isRawUtil(parsed))
710
- return [parsed[0], void 0, parsed[1], void 0, parsed[2]];
721
+ return [parsed[0], void 0, parsed[1], void 0, parsed[2], this.config.details ? context : void 0];
711
722
  const { selector, entries, parent, layer: variantLayer, sort: variantSort } = this.applyVariants(parsed);
712
723
  const body = entriesToCss(entries);
713
724
  if (!body)
@@ -718,11 +729,15 @@ class UnoGenerator {
718
729
  layer: variantLayer ?? metaLayer,
719
730
  sort: variantSort ?? metaSort
720
731
  };
721
- return [parsed[0], selector, body, parent, ruleMeta];
732
+ return [parsed[0], selector, body, parent, ruleMeta, this.config.details ? context : void 0];
722
733
  }
723
734
  expandShortcut(processed, context, depth = 3) {
724
735
  if (depth === 0)
725
736
  return;
737
+ const recordShortcut = this.config.details ? (s) => {
738
+ context.shortcuts = context.shortcuts ?? [];
739
+ context.shortcuts.push(s);
740
+ } : noop;
726
741
  let meta;
727
742
  let result;
728
743
  for (const s of this.config.shortcuts) {
@@ -730,6 +745,7 @@ class UnoGenerator {
730
745
  if (s[0] === processed) {
731
746
  meta = meta || s[2];
732
747
  result = s[1];
748
+ recordShortcut(s);
733
749
  break;
734
750
  }
735
751
  } else {
@@ -738,6 +754,7 @@ class UnoGenerator {
738
754
  result = s[1](match, context);
739
755
  if (result) {
740
756
  meta = meta || s[2];
757
+ recordShortcut(s);
741
758
  break;
742
759
  }
743
760
  }
@@ -763,7 +780,7 @@ class UnoGenerator {
763
780
  const rawStringfieldUtil = [];
764
781
  for (const item of parsed) {
765
782
  if (isRawUtil(item)) {
766
- rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2]]);
783
+ rawStringfieldUtil.push([item[0], void 0, item[1], void 0, item[2], context]);
767
784
  continue;
768
785
  }
769
786
  const { selector, entries, parent: parent2, sort } = this.applyVariants(item, [...item[4], ...parentVariants], raw);
@@ -777,7 +794,7 @@ class UnoGenerator {
777
794
  return (flatten ? [entriesList.flat(1)] : entriesList).map((entries) => {
778
795
  const body = entriesToCss(entries);
779
796
  if (body)
780
- return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }];
797
+ return [index, selector, body, mediaQuery, { ...meta, noMerge, sort: maxSort }, context];
781
798
  return void 0;
782
799
  });
783
800
  };
@@ -813,4 +830,4 @@ function toEscapedSelector(raw) {
813
830
  return `.${e(raw)}`;
814
831
  }
815
832
 
816
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractQuoted, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, matchingPair, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
833
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.31.14",
3
+ "version": "0.31.17",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "keywords": [
6
6
  "unocss",