@unocss/core 0.53.6 → 0.54.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.cjs CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ const MagicString = require('magic-string');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
8
+
9
+ const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
10
+
5
11
  function escapeRegExp(string) {
6
12
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7
13
  }
@@ -233,27 +239,54 @@ function makeRegexClassGroup(separators = ["-", ":"]) {
233
239
  }
234
240
  function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
235
241
  const regexClassGroup = makeRegexClassGroup(separators);
236
- let hasChanged = false;
242
+ let hasChanged;
237
243
  let content = str.toString();
238
244
  const prefixes = /* @__PURE__ */ new Set();
245
+ const groupsByOffset = /* @__PURE__ */ new Map();
239
246
  do {
240
- const before = content;
247
+ hasChanged = false;
241
248
  content = content.replace(
242
249
  regexClassGroup,
243
- (from, pre, sep, body) => {
250
+ (from, pre, sep, body, groupOffset) => {
244
251
  if (!separators.includes(sep))
245
252
  return from;
253
+ hasChanged = true;
246
254
  prefixes.add(pre + sep);
247
- return body.split(/\s/g).filter(Boolean).map((i) => i === "~" ? pre : i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
255
+ const bodyOffset = groupOffset + pre.length + sep.length + 1;
256
+ const group = { length: from.length, items: [] };
257
+ groupsByOffset.set(groupOffset, group);
258
+ for (const itemMatch of [...body.matchAll(/\S+/g)]) {
259
+ const itemOffset = bodyOffset + itemMatch.index;
260
+ let innerItems = groupsByOffset.get(itemOffset)?.items;
261
+ if (innerItems) {
262
+ groupsByOffset.delete(itemOffset);
263
+ } else {
264
+ innerItems = [{
265
+ offset: itemOffset,
266
+ length: itemMatch[0].length,
267
+ className: itemMatch[0]
268
+ }];
269
+ }
270
+ for (const item of innerItems) {
271
+ item.className = item.className === "~" ? pre : item.className.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`);
272
+ group.items.push(item);
273
+ }
274
+ }
275
+ return "$".repeat(from.length);
248
276
  }
249
277
  );
250
- hasChanged = content !== before;
251
278
  depth -= 1;
252
279
  } while (hasChanged && depth);
280
+ const expanded = typeof str === "string" ? new MagicString__default(str) : str;
281
+ for (const [offset, group] of groupsByOffset)
282
+ expanded.overwrite(offset, offset + group.length, group.items.map((item) => item.className).join(" "));
253
283
  return {
254
284
  prefixes: Array.from(prefixes),
255
- expanded: content,
256
- hasChanged
285
+ hasChanged,
286
+ groupsByOffset,
287
+ get expanded() {
288
+ return expanded.toString();
289
+ }
257
290
  };
258
291
  }
259
292
  function collapseVariantGroup(str, prefixes) {
@@ -282,14 +315,8 @@ function collapseVariantGroup(str, prefixes) {
282
315
  }).join(" ");
283
316
  }
284
317
  function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
285
- const {
286
- expanded
287
- } = parseVariantGroup(str.toString(), separators, depth);
288
- if (typeof str === "string") {
289
- return expanded;
290
- } else {
291
- return str.length() ? str.overwrite(0, str.original.length, expanded) : str;
292
- }
318
+ const res = parseVariantGroup(str, separators, depth);
319
+ return typeof str === "string" ? res.expanded : str;
293
320
  }
294
321
 
295
322
  const warned = /* @__PURE__ */ new Set();
@@ -507,7 +534,7 @@ function mergeThemes(themes) {
507
534
  return themes.map((theme) => theme ? clone(theme) : {}).reduce((a, b) => mergeDeep(a, b), {});
508
535
  }
509
536
 
510
- const version = "0.53.6";
537
+ const version = "0.54.0";
511
538
 
512
539
  class UnoGenerator {
513
540
  constructor(userConfig = {}, defaults = {}) {
@@ -729,8 +756,11 @@ class UnoGenerator {
729
756
  let handler = await v.match(processed, context);
730
757
  if (!handler)
731
758
  continue;
732
- if (isString(handler))
759
+ if (isString(handler)) {
760
+ if (handler === processed)
761
+ continue;
733
762
  handler = { matcher: handler };
763
+ }
734
764
  processed = handler.matcher;
735
765
  handlers.unshift(handler);
736
766
  variants.add(v);
package/dist/index.d.ts CHANGED
@@ -134,10 +134,15 @@ declare class BetterMap<K, V> extends Map<K, V> {
134
134
  declare function withLayer<T extends object>(layer: string, rules: Rule<T>[]): Rule<T>[];
135
135
 
136
136
  declare function makeRegexClassGroup(separators?: string[]): RegExp;
137
- declare function parseVariantGroup(str: string, separators?: string[], depth?: number): {
137
+ interface VariantGroup {
138
+ length: number;
139
+ items: HighlightAnnotation[];
140
+ }
141
+ declare function parseVariantGroup(str: string | MagicString, separators?: string[], depth?: number): {
138
142
  prefixes: string[];
139
- expanded: string;
140
143
  hasChanged: boolean;
144
+ groupsByOffset: Map<number, VariantGroup>;
145
+ readonly expanded: string;
141
146
  };
142
147
  declare function collapseVariantGroup(str: string, prefixes: string[]): string;
143
148
  declare function expandVariantGroup(str: string, separators?: string[], depth?: number): string;
@@ -706,12 +711,10 @@ interface SourceMap {
706
711
  sourcesContent?: string[];
707
712
  version?: number;
708
713
  }
709
- interface TransformResult {
710
- code: string;
711
- map?: SourceMap | null;
712
- etag?: string;
713
- deps?: string[];
714
- dynamicDeps?: string[];
714
+ interface HighlightAnnotation {
715
+ offset: number;
716
+ length: number;
717
+ className: string;
715
718
  }
716
719
  type SourceCodeTransformerEnforce = 'pre' | 'post' | 'default';
717
720
  interface SourceCodeTransformer {
@@ -727,7 +730,9 @@ interface SourceCodeTransformer {
727
730
  /**
728
731
  * The transform function
729
732
  */
730
- transform: (code: MagicString, id: string, ctx: UnocssPluginContext) => Awaitable<void>;
733
+ transform: (code: MagicString, id: string, ctx: UnocssPluginContext) => Awaitable<{
734
+ highlightAnnotations?: HighlightAnnotation[];
735
+ } | void>;
731
736
  }
732
737
  interface ContentOptions {
733
738
  /**
@@ -945,4 +950,4 @@ declare function resolveConfig<Theme extends object = object>(userConfig?: UserC
945
950
  */
946
951
  declare function mergeConfigs<Theme extends object = object>(configs: UserConfig<Theme>[]): UserConfig<Theme>;
947
952
 
948
- export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, 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, ToArray, TransformResult, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
953
+ export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValue, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, HighlightAnnotation, 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, ToArray, TwoKeyMap, UnoGenerator, UnocssPluginContext, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, clone, collapseVariantGroup, createGenerator, createValueHandler, cssIdRE, defaultSplitRE, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit as extractorDefault, extractorSplit, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isString, isValidSelector, makeRegexClassGroup, mergeConfigs, mergeDeep, noop, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, parseVariantGroup, regexScopePlaceholder, resolveConfig, resolvePreset, resolvePresets, resolveShortcuts, splitWithVariantGroupRE, toArray, toEscapedSelector, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import MagicString from 'magic-string';
2
+
1
3
  function escapeRegExp(string) {
2
4
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
5
  }
@@ -229,27 +231,54 @@ function makeRegexClassGroup(separators = ["-", ":"]) {
229
231
  }
230
232
  function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
231
233
  const regexClassGroup = makeRegexClassGroup(separators);
232
- let hasChanged = false;
234
+ let hasChanged;
233
235
  let content = str.toString();
234
236
  const prefixes = /* @__PURE__ */ new Set();
237
+ const groupsByOffset = /* @__PURE__ */ new Map();
235
238
  do {
236
- const before = content;
239
+ hasChanged = false;
237
240
  content = content.replace(
238
241
  regexClassGroup,
239
- (from, pre, sep, body) => {
242
+ (from, pre, sep, body, groupOffset) => {
240
243
  if (!separators.includes(sep))
241
244
  return from;
245
+ hasChanged = true;
242
246
  prefixes.add(pre + sep);
243
- return body.split(/\s/g).filter(Boolean).map((i) => i === "~" ? pre : i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
247
+ const bodyOffset = groupOffset + pre.length + sep.length + 1;
248
+ const group = { length: from.length, items: [] };
249
+ groupsByOffset.set(groupOffset, group);
250
+ for (const itemMatch of [...body.matchAll(/\S+/g)]) {
251
+ const itemOffset = bodyOffset + itemMatch.index;
252
+ let innerItems = groupsByOffset.get(itemOffset)?.items;
253
+ if (innerItems) {
254
+ groupsByOffset.delete(itemOffset);
255
+ } else {
256
+ innerItems = [{
257
+ offset: itemOffset,
258
+ length: itemMatch[0].length,
259
+ className: itemMatch[0]
260
+ }];
261
+ }
262
+ for (const item of innerItems) {
263
+ item.className = item.className === "~" ? pre : item.className.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`);
264
+ group.items.push(item);
265
+ }
266
+ }
267
+ return "$".repeat(from.length);
244
268
  }
245
269
  );
246
- hasChanged = content !== before;
247
270
  depth -= 1;
248
271
  } while (hasChanged && depth);
272
+ const expanded = typeof str === "string" ? new MagicString(str) : str;
273
+ for (const [offset, group] of groupsByOffset)
274
+ expanded.overwrite(offset, offset + group.length, group.items.map((item) => item.className).join(" "));
249
275
  return {
250
276
  prefixes: Array.from(prefixes),
251
- expanded: content,
252
- hasChanged
277
+ hasChanged,
278
+ groupsByOffset,
279
+ get expanded() {
280
+ return expanded.toString();
281
+ }
253
282
  };
254
283
  }
255
284
  function collapseVariantGroup(str, prefixes) {
@@ -278,14 +307,8 @@ function collapseVariantGroup(str, prefixes) {
278
307
  }).join(" ");
279
308
  }
280
309
  function expandVariantGroup(str, separators = ["-", ":"], depth = 5) {
281
- const {
282
- expanded
283
- } = parseVariantGroup(str.toString(), separators, depth);
284
- if (typeof str === "string") {
285
- return expanded;
286
- } else {
287
- return str.length() ? str.overwrite(0, str.original.length, expanded) : str;
288
- }
310
+ const res = parseVariantGroup(str, separators, depth);
311
+ return typeof str === "string" ? res.expanded : str;
289
312
  }
290
313
 
291
314
  const warned = /* @__PURE__ */ new Set();
@@ -503,7 +526,7 @@ function mergeThemes(themes) {
503
526
  return themes.map((theme) => theme ? clone(theme) : {}).reduce((a, b) => mergeDeep(a, b), {});
504
527
  }
505
528
 
506
- const version = "0.53.6";
529
+ const version = "0.54.0";
507
530
 
508
531
  class UnoGenerator {
509
532
  constructor(userConfig = {}, defaults = {}) {
@@ -725,8 +748,11 @@ class UnoGenerator {
725
748
  let handler = await v.match(processed, context);
726
749
  if (!handler)
727
750
  continue;
728
- if (isString(handler))
751
+ if (isString(handler)) {
752
+ if (handler === processed)
753
+ continue;
729
754
  handler = { matcher: handler };
755
+ }
730
756
  processed = handler.matcher;
731
757
  handlers.unshift(handler);
732
758
  variants.add(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.53.6",
3
+ "version": "0.54.0",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",