@unocss/core 66.2.2 → 66.3.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.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>;
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>;
package/dist/index.mjs CHANGED
@@ -656,7 +656,7 @@ function definePreset(preset) {
656
656
  return preset;
657
657
  }
658
658
 
659
- const version = "66.2.2";
659
+ const version = "66.3.0";
660
660
 
661
661
  const symbols = {
662
662
  shortcutsNoMerge: "$$symbol-shortcut-no-merge",
@@ -739,9 +739,7 @@ class UnoGeneratorInternal {
739
739
  const cacheKey = `${raw}${alias ? ` ${alias}` : ""}`;
740
740
  if (this.cache.has(cacheKey))
741
741
  return this.cache.get(cacheKey);
742
- let current = raw;
743
- for (const p of this.config.preprocess)
744
- current = p(raw);
742
+ const current = this.config.preprocess.reduce((acc, p) => p(acc) ?? acc, raw);
745
743
  if (this.isBlocked(current)) {
746
744
  this.blocked.add(raw);
747
745
  this.cache.set(cacheKey, null);
@@ -1049,27 +1047,17 @@ class UnoGeneratorInternal {
1049
1047
  const parse = async ([raw, processed, variantHandlers]) => {
1050
1048
  if (this.config.details)
1051
1049
  context.rules = context.rules ?? [];
1050
+ const scopeContext = {
1051
+ ...context,
1052
+ variantHandlers
1053
+ };
1052
1054
  const staticMatch = this.config.rulesStaticMap[processed];
1053
1055
  if (staticMatch) {
1054
1056
  if (staticMatch[1] && (internal || !staticMatch[2]?.internal)) {
1055
- if (this.config.details)
1056
- context.rules.push(staticMatch);
1057
- const index = this.config.rules.indexOf(staticMatch);
1058
- const entries = normalizeCSSValues(staticMatch[1]).filter((i) => i.length);
1059
- const meta = staticMatch[2];
1060
- if (entries.length) {
1061
- context.generator.activatedRules.add(staticMatch);
1062
- return entries.map((css) => {
1063
- if (isString(css))
1064
- return [index, css, meta];
1065
- return [index, raw, css, meta, variantHandlers];
1066
- });
1067
- }
1057
+ return this.resolveCSSResult(raw, staticMatch[1], staticMatch, scopeContext);
1068
1058
  }
1069
1059
  }
1070
- context.variantHandlers = variantHandlers;
1071
- const { rulesDynamic } = this.config;
1072
- for (const rule of rulesDynamic) {
1060
+ for (const rule of this.config.rulesDynamic) {
1073
1061
  const [matcher, handler, meta] = rule;
1074
1062
  if (meta?.internal && !internal)
1075
1063
  continue;
@@ -1090,71 +1078,24 @@ class UnoGeneratorInternal {
1090
1078
  const match = unprefixed.match(matcher);
1091
1079
  if (!match)
1092
1080
  continue;
1093
- let result = await handler(match, context);
1081
+ let result = await handler(match, scopeContext);
1094
1082
  if (!result)
1095
1083
  continue;
1096
- if (this.config.details)
1097
- context.rules.push(rule);
1098
1084
  if (typeof result !== "string") {
1099
1085
  if (Symbol.asyncIterator in result) {
1100
- const entries2 = [];
1086
+ const entries = [];
1101
1087
  for await (const r of result) {
1102
1088
  if (r)
1103
- entries2.push(r);
1089
+ entries.push(r);
1104
1090
  }
1105
- result = entries2;
1091
+ result = entries;
1106
1092
  } else if (Symbol.iterator in result && !Array.isArray(result)) {
1107
1093
  result = Array.from(result).filter(notNull);
1108
1094
  }
1109
1095
  }
1110
- const entries = normalizeCSSValues(result).filter((i) => i.length);
1111
- if (entries.length) {
1112
- context.generator.activatedRules.add(rule);
1113
- const index = this.config.rules.indexOf(rule);
1114
- return entries.map((css) => {
1115
- if (isString(css))
1116
- return [index, css, meta];
1117
- let variants = variantHandlers;
1118
- let entryMeta = meta;
1119
- for (const entry of css) {
1120
- if (entry[0] === symbols.variants) {
1121
- if (typeof entry[1] === "function") {
1122
- variants = entry[1](variants) || variants;
1123
- } else {
1124
- variants = [
1125
- ...toArray(entry[1]),
1126
- ...variants
1127
- ];
1128
- }
1129
- } else if (entry[0] === symbols.parent) {
1130
- variants = [
1131
- { parent: entry[1] },
1132
- ...variants
1133
- ];
1134
- } else if (entry[0] === symbols.selector) {
1135
- variants = [
1136
- { selector: entry[1] },
1137
- ...variants
1138
- ];
1139
- } else if (entry[0] === symbols.layer) {
1140
- variants = [
1141
- { layer: entry[1] },
1142
- ...variants
1143
- ];
1144
- } else if (entry[0] === symbols.sort) {
1145
- entryMeta = {
1146
- ...entryMeta,
1147
- sort: entry[1]
1148
- };
1149
- } else if (entry[0] === symbols.noMerge) {
1150
- entryMeta = {
1151
- ...entryMeta,
1152
- noMerge: entry[1]
1153
- };
1154
- }
1155
- }
1156
- return [index, raw, css, entryMeta, variants];
1157
- });
1096
+ const resolvedResult = this.resolveCSSResult(raw, result, rule, scopeContext);
1097
+ if (resolvedResult) {
1098
+ return resolvedResult;
1158
1099
  }
1159
1100
  }
1160
1101
  };
@@ -1163,6 +1104,61 @@ class UnoGeneratorInternal {
1163
1104
  return void 0;
1164
1105
  return parsed;
1165
1106
  }
1107
+ resolveCSSResult = (raw, result, rule, context) => {
1108
+ const entries = normalizeCSSValues(result).filter((i) => i.length);
1109
+ if (entries.length) {
1110
+ if (this.config.details) {
1111
+ context.rules.push(rule);
1112
+ }
1113
+ context.generator.activatedRules.add(rule);
1114
+ const index = context.generator.config.rules.indexOf(rule);
1115
+ const meta = rule[2];
1116
+ return entries.map((css) => {
1117
+ if (isString(css))
1118
+ return [index, css, meta];
1119
+ let variants = context.variantHandlers;
1120
+ let entryMeta = meta;
1121
+ for (const entry of css) {
1122
+ if (entry[0] === symbols.variants) {
1123
+ if (typeof entry[1] === "function") {
1124
+ variants = entry[1](variants) || variants;
1125
+ } else {
1126
+ variants = [
1127
+ ...toArray(entry[1]),
1128
+ ...variants
1129
+ ];
1130
+ }
1131
+ } else if (entry[0] === symbols.parent) {
1132
+ variants = [
1133
+ { parent: entry[1] },
1134
+ ...variants
1135
+ ];
1136
+ } else if (entry[0] === symbols.selector) {
1137
+ variants = [
1138
+ { selector: entry[1] },
1139
+ ...variants
1140
+ ];
1141
+ } else if (entry[0] === symbols.layer) {
1142
+ variants = [
1143
+ { layer: entry[1] },
1144
+ ...variants
1145
+ ];
1146
+ } else if (entry[0] === symbols.sort) {
1147
+ entryMeta = {
1148
+ ...entryMeta,
1149
+ sort: entry[1]
1150
+ };
1151
+ } else if (entry[0] === symbols.noMerge) {
1152
+ entryMeta = {
1153
+ ...entryMeta,
1154
+ noMerge: entry[1]
1155
+ };
1156
+ }
1157
+ }
1158
+ return [index, raw, css, entryMeta, variants];
1159
+ });
1160
+ }
1161
+ };
1166
1162
  stringifyUtil(parsed, context) {
1167
1163
  if (!parsed)
1168
1164
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
3
  "type": "module",
4
- "version": "66.2.2",
4
+ "version": "66.3.0",
5
5
  "description": "The instant on-demand Atomic CSS engine.",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",