@unocss/core 0.27.1 → 0.27.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
@@ -221,20 +221,10 @@ function withLayer(layer, rules) {
221
221
 
222
222
  const regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
223
223
  function expandVariantGroup(str) {
224
- const replaces = [];
225
- let match;
226
- while (match = regexClassGroup.exec(str)) {
227
- const start = match.index;
228
- const end = start + match[0].length;
229
- const [, pre, sep, body] = match;
230
- const replacement = body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
231
- replaces.unshift([start, end, replacement]);
232
- }
233
- let result = str;
234
- replaces.forEach(([start, end, replacement]) => {
235
- result = result.slice(0, start) + replacement + result.slice(end);
224
+ regexClassGroup.lastIndex = 0;
225
+ return str.replace(regexClassGroup, (_, pre, sep, body) => {
226
+ return body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
236
227
  });
237
- return result;
238
228
  }
239
229
 
240
230
  const warned = /* @__PURE__ */ new Set();
@@ -366,7 +356,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
366
356
  };
367
357
  }
368
358
 
369
- const version = "0.27.1";
359
+ const version = "0.27.4";
370
360
 
371
361
  class UnoGenerator {
372
362
  constructor(userConfig = {}, defaults = {}) {
@@ -493,8 +483,12 @@ class UnoGenerator {
493
483
  const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
494
484
  let preflightsMap = {};
495
485
  if (preflights) {
486
+ const preflightContext = {
487
+ generator: this,
488
+ theme: this.config.theme
489
+ };
496
490
  preflightsMap = Object.fromEntries(await Promise.all(layers.map(async (layer) => {
497
- const preflights2 = await Promise.all(this.config.preflights.filter((i) => (i.layer || "default") === layer).map(async (i) => await i.getCSS()));
491
+ const preflights2 = await Promise.all(this.config.preflights.filter((i) => (i.layer || "default") === layer).map(async (i) => await i.getCSS(preflightContext)));
498
492
  const css = preflights2.filter(Boolean).join(nl);
499
493
  return [layer, css];
500
494
  })));
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LoadConfigResult } from 'unconfig';
2
- import MagicString from 'magic-string-extra';
2
+ import MagicString from 'magic-string';
3
3
 
4
4
  declare class UnoGenerator {
5
5
  userConfig: UserConfig;
@@ -76,6 +76,7 @@ declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
76
76
 
77
77
  declare const regexClassGroup: RegExp;
78
78
  declare function expandVariantGroup(str: string): string;
79
+ declare function expandVariantGroup(str: MagicString): MagicString;
79
80
 
80
81
  declare function warnOnce(msg: string): void;
81
82
 
@@ -189,6 +190,16 @@ interface ExtractorContext {
189
190
  code: string;
190
191
  id?: string;
191
192
  }
193
+ interface PreflightContext<Theme extends {} = {}> {
194
+ /**
195
+ * UnoCSS generator instance
196
+ */
197
+ generator: UnoGenerator;
198
+ /**
199
+ * The theme object
200
+ */
201
+ theme: Theme;
202
+ }
192
203
  interface Extractor {
193
204
  name: string;
194
205
  extract(ctx: ExtractorContext): Awaitable<Set<string> | undefined>;
@@ -228,7 +239,7 @@ declare type UserShortcuts<Theme extends {} = {}> = StaticShortcutMap | (StaticS
228
239
  declare type Shortcut<Theme extends {} = {}> = StaticShortcut | DynamicShortcut<Theme>;
229
240
  declare type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
230
241
  interface Preflight {
231
- getCSS: () => Promise<string | undefined> | string | undefined;
242
+ getCSS: (context: PreflightContext) => Promise<string | undefined> | string | undefined;
232
243
  layer?: string;
233
244
  }
234
245
  declare type BlocklistRule = string | RegExp;
@@ -533,4 +544,4 @@ declare const extractorSplit: Extractor;
533
544
 
534
545
  declare const extractorSvelte: Extractor;
535
546
 
536
- export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, 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, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, uniq, validateFilterRE, warnOnce, withLayer };
547
+ export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, CONTROL_SHORTCUT_NO_MERGE, CSSColorValue, CSSEntries, CSSObject, CSSValues, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, ParsedColorValue, ParsedUtil, PartialByKeys, PluginOptions, Postprocessor, Preflight, PreflightContext, Preprocessor, Preset, PresetOptions, RGBAColorValue, RawUtil, RequiredByKey, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, SourceCodeTransformer, SourceMap, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, 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, extractorSplit, extractorSvelte, hasScopePlaceholder, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, regexScopePlaceholder, toArray, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -217,20 +217,10 @@ function withLayer(layer, rules) {
217
217
 
218
218
  const regexClassGroup = /([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;
219
219
  function expandVariantGroup(str) {
220
- const replaces = [];
221
- let match;
222
- while (match = regexClassGroup.exec(str)) {
223
- const start = match.index;
224
- const end = start + match[0].length;
225
- const [, pre, sep, body] = match;
226
- const replacement = body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
227
- replaces.unshift([start, end, replacement]);
228
- }
229
- let result = str;
230
- replaces.forEach(([start, end, replacement]) => {
231
- result = result.slice(0, start) + replacement + result.slice(end);
220
+ regexClassGroup.lastIndex = 0;
221
+ return str.replace(regexClassGroup, (_, pre, sep, body) => {
222
+ return body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
232
223
  });
233
- return result;
234
224
  }
235
225
 
236
226
  const warned = /* @__PURE__ */ new Set();
@@ -362,7 +352,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
362
352
  };
363
353
  }
364
354
 
365
- const version = "0.27.1";
355
+ const version = "0.27.4";
366
356
 
367
357
  class UnoGenerator {
368
358
  constructor(userConfig = {}, defaults = {}) {
@@ -489,8 +479,12 @@ class UnoGenerator {
489
479
  const layers = this.config.sortLayers(Array.from(layerSet).sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
490
480
  let preflightsMap = {};
491
481
  if (preflights) {
482
+ const preflightContext = {
483
+ generator: this,
484
+ theme: this.config.theme
485
+ };
492
486
  preflightsMap = Object.fromEntries(await Promise.all(layers.map(async (layer) => {
493
- const preflights2 = await Promise.all(this.config.preflights.filter((i) => (i.layer || "default") === layer).map(async (i) => await i.getCSS()));
487
+ const preflights2 = await Promise.all(this.config.preflights.filter((i) => (i.layer || "default") === layer).map(async (i) => await i.getCSS(preflightContext)));
494
488
  const css = preflights2.filter(Boolean).join(nl);
495
489
  return [layer, css];
496
490
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.27.1",
3
+ "version": "0.27.4",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "keywords": [
6
6
  "unocss",
@@ -37,7 +37,7 @@
37
37
  "module": "dist/index.mjs",
38
38
  "types": "dist/index.d.ts",
39
39
  "devDependencies": {
40
- "magic-string-extra": "^0.1.2",
40
+ "magic-string": "^0.26.1",
41
41
  "unconfig": "^0.3.1"
42
42
  },
43
43
  "scripts": {