@unocss/core 0.51.0 → 0.51.2

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
@@ -83,16 +83,20 @@ function entriesToCss(arr) {
83
83
  function isObject(item) {
84
84
  return item && typeof item === "object" && !Array.isArray(item);
85
85
  }
86
- function mergeDeep(original, patch) {
86
+ function mergeDeep(original, patch, mergeArray = false) {
87
87
  const o = original;
88
88
  const p = patch;
89
- if (Array.isArray(o))
90
- return [...p];
89
+ if (Array.isArray(p)) {
90
+ if (mergeArray && Array.isArray(p))
91
+ return [...o, ...p];
92
+ else
93
+ return [...p];
94
+ }
91
95
  const output = { ...o };
92
96
  if (isObject(o) && isObject(p)) {
93
97
  Object.keys(p).forEach((key) => {
94
98
  if (isObject(o[key]) && isObject(p[key]) || Array.isArray(o[key]) && Array.isArray(p[key]))
95
- output[key] = mergeDeep(o[key], p[key]);
99
+ output[key] = mergeDeep(o[key], p[key], mergeArray);
96
100
  else
97
101
  Object.assign(output, { [key]: p[key] });
98
102
  });
@@ -368,7 +372,15 @@ function resolveShortcuts(shortcuts) {
368
372
  return Object.entries(s);
369
373
  });
370
374
  }
375
+ const __RESOLVED = "_uno_resolved";
371
376
  function resolvePreset(preset) {
377
+ if (__RESOLVED in preset)
378
+ return preset;
379
+ preset = { ...preset };
380
+ Object.defineProperty(preset, __RESOLVED, {
381
+ value: true,
382
+ enumerable: false
383
+ });
372
384
  const shortcuts = preset.shortcuts ? resolveShortcuts(preset.shortcuts) : void 0;
373
385
  preset.shortcuts = shortcuts;
374
386
  if (preset.prefix || preset.layer) {
@@ -386,9 +398,16 @@ function resolvePreset(preset) {
386
398
  }
387
399
  return preset;
388
400
  }
401
+ function resolvePresets(preset) {
402
+ const root = resolvePreset(preset);
403
+ if (!root.presets)
404
+ return [root];
405
+ const nested = (root.presets || []).flatMap(toArray).flatMap(resolvePresets);
406
+ return [root, ...nested];
407
+ }
389
408
  function resolveConfig(userConfig = {}, defaults = {}) {
390
409
  const config = Object.assign({}, defaults, userConfig);
391
- const rawPresets = (config.presets || []).flatMap(toArray).map(resolvePreset);
410
+ const rawPresets = uniq((config.presets || []).flatMap(toArray).flatMap(resolvePresets));
392
411
  const sortedPresets = [
393
412
  ...rawPresets.filter((p) => p.enforce === "pre"),
394
413
  ...rawPresets.filter((p) => !p.enforce),
@@ -465,7 +484,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
465
484
  return resolved;
466
485
  }
467
486
 
468
- const version = "0.51.0";
487
+ const version = "0.51.2";
469
488
 
470
489
  class UnoGenerator {
471
490
  constructor(userConfig = {}, defaults = {}) {
package/dist/index.d.ts CHANGED
@@ -94,7 +94,10 @@ declare function normalizeCSSValues(obj: CSSValue | string | (CSSValue | string)
94
94
  declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
95
95
  declare function entriesToCss(arr?: CSSEntries): string;
96
96
  declare function isObject(item: any): item is Record<string, any>;
97
- declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
97
+ /**
98
+ * Deep merge two objects
99
+ */
100
+ declare function mergeDeep<T>(original: T, patch: DeepPartial<T>, mergeArray?: boolean): T;
98
101
  declare function clone<T>(val: T): T;
99
102
  declare function isStaticRule(rule: Rule<any>): rule is StaticRule;
100
103
  declare function isStaticShortcut(sc: Shortcut<any>): sc is StaticShortcut;
@@ -518,6 +521,10 @@ interface ConfigBase<Theme extends {} = {}> {
518
521
  * It's also possible to return a new theme object to completely replace the original one.
519
522
  */
520
523
  extendTheme?: Arrayable<ThemeExtender<Theme>>;
524
+ /**
525
+ * Presets
526
+ */
527
+ presets?: (Preset<Theme> | Preset<Theme>[])[];
521
528
  /**
522
529
  * Additional options for auto complete
523
530
  */
@@ -642,10 +649,6 @@ interface UserOnlyOptions<Theme extends {} = {}> {
642
649
  * @default 'shortcuts'
643
650
  */
644
651
  shortcutsLayer?: string;
645
- /**
646
- * Presets
647
- */
648
- presets?: (Preset<Theme> | Preset<Theme>[])[];
649
652
  /**
650
653
  * Environment mode
651
654
  *
package/dist/index.mjs CHANGED
@@ -79,16 +79,20 @@ function entriesToCss(arr) {
79
79
  function isObject(item) {
80
80
  return item && typeof item === "object" && !Array.isArray(item);
81
81
  }
82
- function mergeDeep(original, patch) {
82
+ function mergeDeep(original, patch, mergeArray = false) {
83
83
  const o = original;
84
84
  const p = patch;
85
- if (Array.isArray(o))
86
- return [...p];
85
+ if (Array.isArray(p)) {
86
+ if (mergeArray && Array.isArray(p))
87
+ return [...o, ...p];
88
+ else
89
+ return [...p];
90
+ }
87
91
  const output = { ...o };
88
92
  if (isObject(o) && isObject(p)) {
89
93
  Object.keys(p).forEach((key) => {
90
94
  if (isObject(o[key]) && isObject(p[key]) || Array.isArray(o[key]) && Array.isArray(p[key]))
91
- output[key] = mergeDeep(o[key], p[key]);
95
+ output[key] = mergeDeep(o[key], p[key], mergeArray);
92
96
  else
93
97
  Object.assign(output, { [key]: p[key] });
94
98
  });
@@ -364,7 +368,15 @@ function resolveShortcuts(shortcuts) {
364
368
  return Object.entries(s);
365
369
  });
366
370
  }
371
+ const __RESOLVED = "_uno_resolved";
367
372
  function resolvePreset(preset) {
373
+ if (__RESOLVED in preset)
374
+ return preset;
375
+ preset = { ...preset };
376
+ Object.defineProperty(preset, __RESOLVED, {
377
+ value: true,
378
+ enumerable: false
379
+ });
368
380
  const shortcuts = preset.shortcuts ? resolveShortcuts(preset.shortcuts) : void 0;
369
381
  preset.shortcuts = shortcuts;
370
382
  if (preset.prefix || preset.layer) {
@@ -382,9 +394,16 @@ function resolvePreset(preset) {
382
394
  }
383
395
  return preset;
384
396
  }
397
+ function resolvePresets(preset) {
398
+ const root = resolvePreset(preset);
399
+ if (!root.presets)
400
+ return [root];
401
+ const nested = (root.presets || []).flatMap(toArray).flatMap(resolvePresets);
402
+ return [root, ...nested];
403
+ }
385
404
  function resolveConfig(userConfig = {}, defaults = {}) {
386
405
  const config = Object.assign({}, defaults, userConfig);
387
- const rawPresets = (config.presets || []).flatMap(toArray).map(resolvePreset);
406
+ const rawPresets = uniq((config.presets || []).flatMap(toArray).flatMap(resolvePresets));
388
407
  const sortedPresets = [
389
408
  ...rawPresets.filter((p) => p.enforce === "pre"),
390
409
  ...rawPresets.filter((p) => !p.enforce),
@@ -461,7 +480,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
461
480
  return resolved;
462
481
  }
463
482
 
464
- const version = "0.51.0";
483
+ const version = "0.51.2";
465
484
 
466
485
  class UnoGenerator {
467
486
  constructor(userConfig = {}, defaults = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.51.0",
3
+ "version": "0.51.2",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",