@unocss/core 0.21.0 → 0.21.1

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
@@ -93,6 +93,32 @@ function mergeDeep(original, patch) {
93
93
  }
94
94
  return output;
95
95
  }
96
+ function clone(val) {
97
+ let k, out, tmp;
98
+ if (Array.isArray(val)) {
99
+ out = Array(k = val.length);
100
+ while (k--)
101
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
102
+ return out;
103
+ }
104
+ if (Object.prototype.toString.call(val) === "[object Object]") {
105
+ out = {};
106
+ for (k in val) {
107
+ if (k === "__proto__") {
108
+ Object.defineProperty(out, k, {
109
+ value: clone(val[k]),
110
+ configurable: true,
111
+ enumerable: true,
112
+ writable: true
113
+ });
114
+ } else {
115
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+ return val;
121
+ }
96
122
  function isStaticRule(rule) {
97
123
  return typeof rule[0] === "string";
98
124
  }
@@ -332,10 +358,11 @@ function resolveConfig(userConfig = {}, defaults = {}) {
332
358
  delete rules[i];
333
359
  }
334
360
  });
335
- const theme = [
361
+ const theme = clone([
336
362
  ...sortedPresets.map((p) => p.theme || {}),
337
363
  config.theme || {}
338
- ].reduce((a, p) => mergeDeep(a, p), {});
364
+ ].reduce((a, p) => mergeDeep(a, p), {}));
365
+ mergePresets("extendTheme").forEach((extendTheme) => extendTheme(theme));
339
366
  return {
340
367
  mergeSelectors: true,
341
368
  warn: true,
@@ -360,7 +387,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
360
387
  };
361
388
  }
362
389
 
363
- const version = "0.21.0";
390
+ const version = "0.21.1";
364
391
 
365
392
  class UnoGenerator {
366
393
  constructor(userConfig = {}, defaults = {}) {
@@ -695,6 +722,7 @@ exports.TwoKeyMap = TwoKeyMap;
695
722
  exports.UnoGenerator = UnoGenerator;
696
723
  exports.attributifyRE = attributifyRE;
697
724
  exports.clearIdenticalEntries = clearIdenticalEntries;
725
+ exports.clone = clone;
698
726
  exports.createGenerator = createGenerator;
699
727
  exports.createValueHandler = createValueHandler;
700
728
  exports.e = e;
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefau
23
23
  declare const hasScopePlaceholder: (css: string) => RegExpMatchArray | null;
24
24
 
25
25
  declare type Awaitable<T> = T | Promise<T>;
26
+ declare type Arrayable<T> = T | T[];
26
27
  declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
27
28
  declare type Shift<T> = T extends [_: any, ...args: infer A] ? A : never;
28
29
  declare type RestArgs<T> = Shift<ArgumentType<T>>;
@@ -183,6 +184,7 @@ declare type VariantObject<Theme extends {} = {}> = {
183
184
  declare type Variant<Theme extends {} = {}> = VariantFunction<Theme> | VariantObject<Theme>;
184
185
  declare type Preprocessor = (matcher: string) => string | undefined;
185
186
  declare type Postprocessor = (util: UtilObject) => void;
187
+ declare type ThemeExtender<T> = (theme: T) => void;
186
188
  interface ConfigBase<Theme extends {} = {}> {
187
189
  /**
188
190
  * Rules to generate CSS utilities
@@ -231,11 +233,15 @@ interface ConfigBase<Theme extends {} = {}> {
231
233
  /**
232
234
  * Preprocess the incoming utilities, return falsy value to exclude
233
235
  */
234
- preprocess?: Preprocessor | Preprocessor[];
236
+ preprocess?: Arrayable<Preprocessor>;
235
237
  /**
236
238
  * Process the generate utils object
237
239
  */
238
- postprocess?: Postprocessor | Postprocessor[];
240
+ postprocess?: Arrayable<Postprocessor>;
241
+ /**
242
+ * Custom functions to extend the theme object
243
+ */
244
+ extendTheme?: Arrayable<ThemeExtender<Theme>>;
239
245
  }
240
246
  interface Preset<Theme extends {} = {}> extends ConfigBase<Theme> {
241
247
  name: string;
@@ -392,6 +398,7 @@ declare function clearIdenticalEntries(entry: CSSEntries): CSSEntries;
392
398
  declare function entriesToCss(arr?: CSSEntries): string;
393
399
  declare function isObject(item: any): item is Record<string, any>;
394
400
  declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
401
+ declare function clone<T>(val: T): T;
395
402
  declare function isStaticRule(rule: Rule): rule is StaticRule;
396
403
  declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
397
404
 
@@ -445,4 +452,4 @@ declare const extractorSplit: Extractor;
445
452
 
446
453
  declare const extractorSvelte: Extractor;
447
454
 
448
- export { ArgumentType, Awaitable, BetterMap, BlocklistRule, 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, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, ValueHandler, ValueHandlerCallback, Variant, VariantContext, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, clearIdenticalEntries, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
455
+ export { ArgumentType, Arrayable, Awaitable, BetterMap, BlocklistRule, 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, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, ThemeExtender, TwoKeyMap, UnoGenerator, 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, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
package/dist/index.mjs CHANGED
@@ -89,6 +89,32 @@ function mergeDeep(original, patch) {
89
89
  }
90
90
  return output;
91
91
  }
92
+ function clone(val) {
93
+ let k, out, tmp;
94
+ if (Array.isArray(val)) {
95
+ out = Array(k = val.length);
96
+ while (k--)
97
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
98
+ return out;
99
+ }
100
+ if (Object.prototype.toString.call(val) === "[object Object]") {
101
+ out = {};
102
+ for (k in val) {
103
+ if (k === "__proto__") {
104
+ Object.defineProperty(out, k, {
105
+ value: clone(val[k]),
106
+ configurable: true,
107
+ enumerable: true,
108
+ writable: true
109
+ });
110
+ } else {
111
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
112
+ }
113
+ }
114
+ return out;
115
+ }
116
+ return val;
117
+ }
92
118
  function isStaticRule(rule) {
93
119
  return typeof rule[0] === "string";
94
120
  }
@@ -328,10 +354,11 @@ function resolveConfig(userConfig = {}, defaults = {}) {
328
354
  delete rules[i];
329
355
  }
330
356
  });
331
- const theme = [
357
+ const theme = clone([
332
358
  ...sortedPresets.map((p) => p.theme || {}),
333
359
  config.theme || {}
334
- ].reduce((a, p) => mergeDeep(a, p), {});
360
+ ].reduce((a, p) => mergeDeep(a, p), {}));
361
+ mergePresets("extendTheme").forEach((extendTheme) => extendTheme(theme));
335
362
  return {
336
363
  mergeSelectors: true,
337
364
  warn: true,
@@ -356,7 +383,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
356
383
  };
357
384
  }
358
385
 
359
- const version = "0.21.0";
386
+ const version = "0.21.1";
360
387
 
361
388
  class UnoGenerator {
362
389
  constructor(userConfig = {}, defaults = {}) {
@@ -686,4 +713,4 @@ function toEscapedSelector(raw) {
686
713
  return `.${e(raw)}`;
687
714
  }
688
715
 
689
- export { BetterMap, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
716
+ export { BetterMap, TwoKeyMap, UnoGenerator, attributifyRE, clearIdenticalEntries, clone, createGenerator, createValueHandler, e, entriesToCss, escapeRegExp, escapeSelector, expandVariantGroup, extractorSplit, extractorSvelte, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeCSSEntries, normalizeCSSValues, normalizeVariant, notNull, regexClassGroup, toArray, uniq, validateFilterRE, warnOnce, withLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/core",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "The instant on-demand Atomic CSS engine.",
5
5
  "keywords": [
6
6
  "unocss",