@unocss/core 0.49.2 → 0.49.4

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
@@ -227,10 +227,11 @@ function makeRegexClassGroup(separators = ["-", ":"]) {
227
227
  regexCache[key].lastIndex = 0;
228
228
  return regexCache[key];
229
229
  }
230
- function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
230
+ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
231
231
  const regexClassGroup = makeRegexClassGroup(separators);
232
232
  let hasChanged = false;
233
233
  let content = str.toString();
234
+ const prefixes = /* @__PURE__ */ new Set();
234
235
  do {
235
236
  const before = content;
236
237
  content = content.replace(
@@ -238,16 +239,52 @@ function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
238
239
  (from, pre, sep, body) => {
239
240
  if (!separators.includes(sep))
240
241
  return from;
242
+ prefixes.add(pre + sep);
241
243
  return body.split(/\s/g).filter(Boolean).map((i) => i === "~" ? pre : i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
242
244
  }
243
245
  );
244
246
  hasChanged = content !== before;
245
247
  depth -= 1;
246
248
  } while (hasChanged && depth);
249
+ return {
250
+ prefixes: Array.from(prefixes),
251
+ expanded: content,
252
+ hasChanged
253
+ };
254
+ }
255
+ function collapseVariantGroup(str, prefixes) {
256
+ const collection = /* @__PURE__ */ new Map();
257
+ const sortedPrefix = prefixes.sort((a, b) => b.length - a.length);
258
+ return str.split(/\s+/g).map((part) => {
259
+ const prefix = sortedPrefix.find((prefix2) => part.startsWith(prefix2));
260
+ if (!prefix)
261
+ return part;
262
+ const body = part.slice(prefix.length);
263
+ if (collection.has(prefix)) {
264
+ collection.get(prefix).push(body);
265
+ return null;
266
+ } else {
267
+ const items = [body];
268
+ collection.set(prefix, items);
269
+ return {
270
+ prefix,
271
+ items
272
+ };
273
+ }
274
+ }).filter(notNull).map((i) => {
275
+ if (typeof i === "string")
276
+ return i;
277
+ return `${i.prefix}(${i.items.join(" ")})`;
278
+ }).join(" ");
279
+ }
280
+ function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
281
+ const {
282
+ expanded
283
+ } = parseVariantGroup(str.toString(), separators, depth);
247
284
  if (typeof str === "string") {
248
- return content;
285
+ return expanded;
249
286
  } else {
250
- return str.length() ? str.overwrite(0, str.length(), content) : str;
287
+ return str.length() ? str.overwrite(0, str.length(), expanded) : str;
251
288
  }
252
289
  }
253
290
 
@@ -444,7 +481,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
444
481
  };
445
482
  }
446
483
 
447
- const version = "0.49.2";
484
+ const version = "0.49.4";
448
485
 
449
486
  class UnoGenerator {
450
487
  constructor(userConfig = {}, defaults = {}) {
@@ -940,6 +977,7 @@ exports.arbitraryPropertyRE = arbitraryPropertyRE;
940
977
  exports.attributifyRE = attributifyRE;
941
978
  exports.clearIdenticalEntries = clearIdenticalEntries;
942
979
  exports.clone = clone;
980
+ exports.collapseVariantGroup = collapseVariantGroup;
943
981
  exports.createGenerator = createGenerator;
944
982
  exports.createValueHandler = createValueHandler;
945
983
  exports.cssIdRE = cssIdRE;
@@ -966,6 +1004,7 @@ exports.normalizeCSSEntries = normalizeCSSEntries;
966
1004
  exports.normalizeCSSValues = normalizeCSSValues;
967
1005
  exports.normalizeVariant = normalizeVariant;
968
1006
  exports.notNull = notNull;
1007
+ exports.parseVariantGroup = parseVariantGroup;
969
1008
  exports.regexScopePlaceholder = regexScopePlaceholder;
970
1009
  exports.toArray = toArray;
971
1010
  exports.toEscapedSelector = toEscapedSelector;
package/dist/index.d.ts CHANGED
@@ -132,6 +132,12 @@ declare class BetterMap<K, V> extends Map<K, V> {
132
132
  declare function withLayer<T extends {}>(layer: string, rules: Rule<T>[]): Rule<T>[];
133
133
 
134
134
  declare function makeRegexClassGroup(separators?: string[]): RegExp;
135
+ declare function parseVariantGroup(str: string, separators?: string[], depth?: number): {
136
+ prefixes: string[];
137
+ expanded: string;
138
+ hasChanged: boolean;
139
+ };
140
+ declare function collapseVariantGroup(str: string, prefixes: string[]): string;
135
141
  declare function expandVariantGroup(str: string, separators?: string[], depth?: number): string;
136
142
  declare function expandVariantGroup(str: MagicString, separators?: string[], depth?: number): MagicString;
137
143
 
@@ -821,4 +827,4 @@ declare const extractorSplit: Extractor;
821
827
 
822
828
  declare const extractorSvelte: Extractor;
823
829
 
824
- export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, 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, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
830
+ export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExtraContentOptions, 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, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -223,10 +223,11 @@ function makeRegexClassGroup(separators = ["-", ":"]) {
223
223
  regexCache[key].lastIndex = 0;
224
224
  return regexCache[key];
225
225
  }
226
- function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
226
+ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
227
227
  const regexClassGroup = makeRegexClassGroup(separators);
228
228
  let hasChanged = false;
229
229
  let content = str.toString();
230
+ const prefixes = /* @__PURE__ */ new Set();
230
231
  do {
231
232
  const before = content;
232
233
  content = content.replace(
@@ -234,16 +235,52 @@ function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
234
235
  (from, pre, sep, body) => {
235
236
  if (!separators.includes(sep))
236
237
  return from;
238
+ prefixes.add(pre + sep);
237
239
  return body.split(/\s/g).filter(Boolean).map((i) => i === "~" ? pre : i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
238
240
  }
239
241
  );
240
242
  hasChanged = content !== before;
241
243
  depth -= 1;
242
244
  } while (hasChanged && depth);
245
+ return {
246
+ prefixes: Array.from(prefixes),
247
+ expanded: content,
248
+ hasChanged
249
+ };
250
+ }
251
+ function collapseVariantGroup(str, prefixes) {
252
+ const collection = /* @__PURE__ */ new Map();
253
+ const sortedPrefix = prefixes.sort((a, b) => b.length - a.length);
254
+ return str.split(/\s+/g).map((part) => {
255
+ const prefix = sortedPrefix.find((prefix2) => part.startsWith(prefix2));
256
+ if (!prefix)
257
+ return part;
258
+ const body = part.slice(prefix.length);
259
+ if (collection.has(prefix)) {
260
+ collection.get(prefix).push(body);
261
+ return null;
262
+ } else {
263
+ const items = [body];
264
+ collection.set(prefix, items);
265
+ return {
266
+ prefix,
267
+ items
268
+ };
269
+ }
270
+ }).filter(notNull).map((i) => {
271
+ if (typeof i === "string")
272
+ return i;
273
+ return `${i.prefix}(${i.items.join(" ")})`;
274
+ }).join(" ");
275
+ }
276
+ function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
277
+ const {
278
+ expanded
279
+ } = parseVariantGroup(str.toString(), separators, depth);
243
280
  if (typeof str === "string") {
244
- return content;
281
+ return expanded;
245
282
  } else {
246
- return str.length() ? str.overwrite(0, str.length(), content) : str;
283
+ return str.length() ? str.overwrite(0, str.length(), expanded) : str;
247
284
  }
248
285
  }
249
286
 
@@ -440,7 +477,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
440
477
  };
441
478
  }
442
479
 
443
- const version = "0.49.2";
480
+ const version = "0.49.4";
444
481
 
445
482
  class UnoGenerator {
446
483
  constructor(userConfig = {}, defaults = {}) {
@@ -928,4 +965,4 @@ function defaultVariantHandler(input, next) {
928
965
  return next(input);
929
966
  }
930
967
 
931
- export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexScopePlaceholder, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
968
+ export { BetterMap, CONTROL_SHORTCUT_NO_MERGE, TwoKeyMap, UnoGenerator, arbitraryPropertyRE, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeDeep, movePseudoElementsEnd, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, 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.49.2",
3
+ "version": "0.49.4",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",