@unocss/core 66.2.1 → 66.2.3

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.d.mts CHANGED
@@ -178,6 +178,7 @@ declare class UnoGeneratorInternal<Theme extends object = object> {
178
178
  private applyVariants;
179
179
  constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
180
180
  parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
181
+ private resolveCSSResult;
181
182
  stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme> | undefined;
182
183
  expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[(string | ShortcutInlineValue)[], RuleMeta | undefined] | undefined>;
183
184
  stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: (string | ShortcutInlineValue)[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
@@ -535,7 +536,7 @@ interface VariantObject<Theme extends object = object> {
535
536
  type Variant<Theme extends object = object> = VariantFunction<Theme> | VariantObject<Theme>;
536
537
  type Preprocessor = (matcher: string) => string | undefined;
537
538
  type Postprocessor = (util: UtilObject) => void;
538
- type ThemeExtender<T> = (theme: T) => T | void;
539
+ type ThemeExtender<Theme extends object = object> = (theme: Theme, config: Readonly<ResolvedConfig<Theme>>) => Theme | void;
539
540
  interface ConfigBase<Theme extends object = object> {
540
541
  /**
541
542
  * Rules to generate CSS utilities.
@@ -651,7 +652,7 @@ interface ConfigBase<Theme extends object = object> {
651
652
  *
652
653
  * First presets runs first and the user config
653
654
  */
654
- configResolved?: (config: ResolvedConfig) => void;
655
+ configResolved?: (config: ResolvedConfig<Theme>) => void;
655
656
  /**
656
657
  * Expose internal details for debugging / inspecting
657
658
  *
package/dist/index.d.ts CHANGED
@@ -178,6 +178,7 @@ declare class UnoGeneratorInternal<Theme extends object = object> {
178
178
  private applyVariants;
179
179
  constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
180
180
  parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
181
+ private resolveCSSResult;
181
182
  stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme> | undefined;
182
183
  expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[(string | ShortcutInlineValue)[], RuleMeta | undefined] | undefined>;
183
184
  stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: (string | ShortcutInlineValue)[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
@@ -535,7 +536,7 @@ interface VariantObject<Theme extends object = object> {
535
536
  type Variant<Theme extends object = object> = VariantFunction<Theme> | VariantObject<Theme>;
536
537
  type Preprocessor = (matcher: string) => string | undefined;
537
538
  type Postprocessor = (util: UtilObject) => void;
538
- type ThemeExtender<T> = (theme: T) => T | void;
539
+ type ThemeExtender<Theme extends object = object> = (theme: Theme, config: Readonly<ResolvedConfig<Theme>>) => Theme | void;
539
540
  interface ConfigBase<Theme extends object = object> {
540
541
  /**
541
542
  * Rules to generate CSS utilities.
@@ -651,7 +652,7 @@ interface ConfigBase<Theme extends object = object> {
651
652
  *
652
653
  * First presets runs first and the user config
653
654
  */
654
- configResolved?: (config: ResolvedConfig) => void;
655
+ configResolved?: (config: ResolvedConfig<Theme>) => void;
655
656
  /**
656
657
  * Expose internal details for debugging / inspecting
657
658
  *
package/dist/index.mjs CHANGED
@@ -567,10 +567,6 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
567
567
  });
568
568
  return false;
569
569
  }).reverse();
570
- let theme = mergeThemes(sources.map((p) => p.theme));
571
- const extendThemes = getMerged("extendTheme");
572
- for (const extendTheme of extendThemes)
573
- theme = extendTheme(theme) || theme;
574
570
  const autocomplete = {
575
571
  templates: uniq(sources.flatMap((p) => toArray(p.autocomplete?.templates))),
576
572
  extractors: sources.flatMap((p) => toArray(p.autocomplete?.extractors)).sort((a, b) => (a.order || 0) - (b.order || 0)),
@@ -591,7 +587,7 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
591
587
  envMode: config.envMode || "build",
592
588
  shortcutsLayer: config.shortcutsLayer || "shortcuts",
593
589
  layers,
594
- theme,
590
+ theme: mergeThemes(sources.map((p) => p.theme)),
595
591
  rules,
596
592
  rulesSize,
597
593
  rulesDynamic,
@@ -609,6 +605,9 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
609
605
  content,
610
606
  transformers: uniqueBy(getMerged("transformers"), (a, b) => a.name === b.name)
611
607
  };
608
+ const extendThemes = getMerged("extendTheme");
609
+ for (const extendTheme of extendThemes)
610
+ resolved.theme = extendTheme(resolved.theme, resolved) || resolved.theme;
612
611
  for (const p of sources)
613
612
  p?.configResolved?.(resolved);
614
613
  return resolved;
@@ -657,7 +656,7 @@ function definePreset(preset) {
657
656
  return preset;
658
657
  }
659
658
 
660
- const version = "66.2.1";
659
+ const version = "66.2.3";
661
660
 
662
661
  const symbols = {
663
662
  shortcutsNoMerge: "$$symbol-shortcut-no-merge",
@@ -1050,27 +1049,17 @@ class UnoGeneratorInternal {
1050
1049
  const parse = async ([raw, processed, variantHandlers]) => {
1051
1050
  if (this.config.details)
1052
1051
  context.rules = context.rules ?? [];
1052
+ const scopeContext = {
1053
+ ...context,
1054
+ variantHandlers
1055
+ };
1053
1056
  const staticMatch = this.config.rulesStaticMap[processed];
1054
1057
  if (staticMatch) {
1055
1058
  if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
1056
- if (this.config.details)
1057
- context.rules.push(staticMatch);
1058
- const index = this.config.rules.indexOf(staticMatch);
1059
- const entries = normalizeCSSValues(staticMatch[1]).filter((i) => i.length);
1060
- const meta = staticMatch[2];
1061
- if (entries.length) {
1062
- context.generator.activatedRules.add(staticMatch);
1063
- return entries.map((css) => {
1064
- if (isString(css))
1065
- return [index, css, meta];
1066
- return [index, raw, css, meta, variantHandlers];
1067
- });
1068
- }
1059
+ return this.resolveCSSResult(raw, staticMatch[1], staticMatch, scopeContext);
1069
1060
  }
1070
1061
  }
1071
- context.variantHandlers = variantHandlers;
1072
- const { rulesDynamic } = this.config;
1073
- for (const rule of rulesDynamic) {
1062
+ for (const rule of this.config.rulesDynamic) {
1074
1063
  const [matcher, handler, meta] = rule;
1075
1064
  if (meta?.internal && !internal)
1076
1065
  continue;
@@ -1091,71 +1080,24 @@ class UnoGeneratorInternal {
1091
1080
  const match = unprefixed.match(matcher);
1092
1081
  if (!match)
1093
1082
  continue;
1094
- let result = await handler(match, context);
1083
+ let result = await handler(match, scopeContext);
1095
1084
  if (!result)
1096
1085
  continue;
1097
- if (this.config.details)
1098
- context.rules.push(rule);
1099
1086
  if (typeof result !== "string") {
1100
1087
  if (Symbol.asyncIterator in result) {
1101
- const entries2 = [];
1088
+ const entries = [];
1102
1089
  for await (const r of result) {
1103
1090
  if (r)
1104
- entries2.push(r);
1091
+ entries.push(r);
1105
1092
  }
1106
- result = entries2;
1093
+ result = entries;
1107
1094
  } else if (Symbol.iterator in result && !Array.isArray(result)) {
1108
1095
  result = Array.from(result).filter(notNull);
1109
1096
  }
1110
1097
  }
1111
- const entries = normalizeCSSValues(result).filter((i) => i.length);
1112
- if (entries.length) {
1113
- context.generator.activatedRules.add(rule);
1114
- const index = this.config.rules.indexOf(rule);
1115
- return entries.map((css) => {
1116
- if (isString(css))
1117
- return [index, css, meta];
1118
- let variants = variantHandlers;
1119
- let entryMeta = meta;
1120
- for (const entry of css) {
1121
- if (entry[0] === symbols.variants) {
1122
- if (typeof entry[1] === "function") {
1123
- variants = entry[1](variants) || variants;
1124
- } else {
1125
- variants = [
1126
- ...toArray(entry[1]),
1127
- ...variants
1128
- ];
1129
- }
1130
- } else if (entry[0] === symbols.parent) {
1131
- variants = [
1132
- { parent: entry[1] },
1133
- ...variants
1134
- ];
1135
- } else if (entry[0] === symbols.selector) {
1136
- variants = [
1137
- { selector: entry[1] },
1138
- ...variants
1139
- ];
1140
- } else if (entry[0] === symbols.layer) {
1141
- variants = [
1142
- { layer: entry[1] },
1143
- ...variants
1144
- ];
1145
- } else if (entry[0] === symbols.sort) {
1146
- entryMeta = {
1147
- ...entryMeta,
1148
- sort: entry[1]
1149
- };
1150
- } else if (entry[0] === symbols.noMerge) {
1151
- entryMeta = {
1152
- ...entryMeta,
1153
- noMerge: entry[1]
1154
- };
1155
- }
1156
- }
1157
- return [index, raw, css, entryMeta, variants];
1158
- });
1098
+ const resolvedResult = this.resolveCSSResult(raw, result, rule, scopeContext);
1099
+ if (resolvedResult) {
1100
+ return resolvedResult;
1159
1101
  }
1160
1102
  }
1161
1103
  };
@@ -1164,6 +1106,61 @@ class UnoGeneratorInternal {
1164
1106
  return void 0;
1165
1107
  return parsed;
1166
1108
  }
1109
+ resolveCSSResult = (raw, result, rule, context) => {
1110
+ const entries = normalizeCSSValues(result).filter((i) => i.length);
1111
+ if (entries.length) {
1112
+ if (this.config.details) {
1113
+ context.rules.push(rule);
1114
+ }
1115
+ context.generator.activatedRules.add(rule);
1116
+ const index = context.generator.config.rules.indexOf(rule);
1117
+ const meta = rule[2];
1118
+ return entries.map((css) => {
1119
+ if (isString(css))
1120
+ return [index, css, meta];
1121
+ let variants = context.variantHandlers;
1122
+ let entryMeta = meta;
1123
+ for (const entry of css) {
1124
+ if (entry[0] === symbols.variants) {
1125
+ if (typeof entry[1] === "function") {
1126
+ variants = entry[1](variants) || variants;
1127
+ } else {
1128
+ variants = [
1129
+ ...toArray(entry[1]),
1130
+ ...variants
1131
+ ];
1132
+ }
1133
+ } else if (entry[0] === symbols.parent) {
1134
+ variants = [
1135
+ { parent: entry[1] },
1136
+ ...variants
1137
+ ];
1138
+ } else if (entry[0] === symbols.selector) {
1139
+ variants = [
1140
+ { selector: entry[1] },
1141
+ ...variants
1142
+ ];
1143
+ } else if (entry[0] === symbols.layer) {
1144
+ variants = [
1145
+ { layer: entry[1] },
1146
+ ...variants
1147
+ ];
1148
+ } else if (entry[0] === symbols.sort) {
1149
+ entryMeta = {
1150
+ ...entryMeta,
1151
+ sort: entry[1]
1152
+ };
1153
+ } else if (entry[0] === symbols.noMerge) {
1154
+ entryMeta = {
1155
+ ...entryMeta,
1156
+ noMerge: entry[1]
1157
+ };
1158
+ }
1159
+ }
1160
+ return [index, raw, css, entryMeta, variants];
1161
+ });
1162
+ }
1163
+ };
1167
1164
  stringifyUtil(parsed, context) {
1168
1165
  if (!parsed)
1169
1166
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
3
  "type": "module",
4
- "version": "66.2.1",
4
+ "version": "66.2.3",
5
5
  "description": "The instant on-demand Atomic CSS engine.",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",