@unocss/rule-utils 0.62.3 → 0.63.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.d.mts CHANGED
@@ -37,10 +37,6 @@ declare function parseCssColor(str?: string): CSSColorValue | undefined;
37
37
  declare function colorOpacityToString(color: CSSColorValue): string | number;
38
38
  declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
39
39
 
40
- declare function getBracket(str: string, open: string, close: string): string[] | undefined;
41
- declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
42
- declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
43
-
44
40
  type ValueHandlerCallback = (str: string) => string | number | undefined;
45
41
  type ValueHandler<K extends string> = {
46
42
  [S in K]: ValueHandler<K>;
@@ -52,14 +48,21 @@ type ValueHandler<K extends string> = {
52
48
  };
53
49
  declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
54
50
 
55
- declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
56
- declare function variantParentMatcher(name: string, parent: string): VariantObject;
57
- declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
58
- declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
51
+ declare const iconFnRE: RegExp;
52
+ declare function hasIconFn(str: string): boolean;
59
53
 
60
54
  declare const themeFnRE: RegExp;
61
55
  declare function hasThemeFn(str: string): boolean;
62
56
  declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
63
57
  declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
64
58
 
65
- export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasThemeFn, hex2rgba, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
59
+ declare function getBracket(str: string, open: string, close: string): string[] | undefined;
60
+ declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
61
+ declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
62
+
63
+ declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
64
+ declare function variantParentMatcher(name: string, parent: string): VariantObject;
65
+ declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
66
+ declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
67
+
68
+ export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/dist/index.d.ts CHANGED
@@ -37,10 +37,6 @@ declare function parseCssColor(str?: string): CSSColorValue | undefined;
37
37
  declare function colorOpacityToString(color: CSSColorValue): string | number;
38
38
  declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
39
39
 
40
- declare function getBracket(str: string, open: string, close: string): string[] | undefined;
41
- declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
42
- declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
43
-
44
40
  type ValueHandlerCallback = (str: string) => string | number | undefined;
45
41
  type ValueHandler<K extends string> = {
46
42
  [S in K]: ValueHandler<K>;
@@ -52,14 +48,21 @@ type ValueHandler<K extends string> = {
52
48
  };
53
49
  declare function createValueHandler<K extends string>(handlers: Record<K, ValueHandlerCallback>): ValueHandler<K>;
54
50
 
55
- declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
56
- declare function variantParentMatcher(name: string, parent: string): VariantObject;
57
- declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
58
- declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
51
+ declare const iconFnRE: RegExp;
52
+ declare function hasIconFn(str: string): boolean;
59
53
 
60
54
  declare const themeFnRE: RegExp;
61
55
  declare function hasThemeFn(str: string): boolean;
62
56
  declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
63
57
  declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
64
58
 
65
- export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasThemeFn, hex2rgba, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
59
+ declare function getBracket(str: string, open: string, close: string): string[] | undefined;
60
+ declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
61
+ declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
62
+
63
+ declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
64
+ declare function variantParentMatcher(name: string, parent: string): VariantObject;
65
+ declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
66
+ declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
67
+
68
+ export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/dist/index.mjs CHANGED
@@ -295,6 +295,54 @@ function createValueHandler(handlers) {
295
295
  return handler;
296
296
  }
297
297
 
298
+ const iconFnRE = /icon\(\s*(['"])?(.*?)\1?\s*\)/g;
299
+ function hasIconFn(str) {
300
+ return str.includes("icon(") && str.includes(")");
301
+ }
302
+
303
+ const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
304
+ function hasThemeFn(str) {
305
+ return str.includes("theme(") && str.includes(")");
306
+ }
307
+ function transformThemeFn(code, theme, throwOnMissing = true) {
308
+ const matches = Array.from(code.toString().matchAll(themeFnRE));
309
+ if (!matches.length)
310
+ return code;
311
+ const s = new MagicString(code);
312
+ for (const match of matches) {
313
+ const rawArg = match[2];
314
+ if (!rawArg)
315
+ throw new Error("theme() expect exact one argument, but got 0");
316
+ const value = transformThemeString(rawArg, theme, throwOnMissing);
317
+ if (value) {
318
+ s.overwrite(
319
+ match.index,
320
+ match.index + match[0].length,
321
+ value
322
+ );
323
+ }
324
+ }
325
+ return s.toString();
326
+ }
327
+ function transformThemeString(code, theme, throwOnMissing = true) {
328
+ const [rawKey, alpha] = code.split("/");
329
+ const keys = rawKey.trim().split(".");
330
+ let value = keys.reduce((t, k) => t?.[k], theme);
331
+ if (typeof value === "object") {
332
+ value = value.DEFAULT;
333
+ }
334
+ if (typeof value === "string") {
335
+ if (alpha) {
336
+ const color = parseCssColor(value);
337
+ if (color)
338
+ value = colorToString(color, alpha);
339
+ }
340
+ return value;
341
+ } else if (throwOnMissing) {
342
+ throw new Error(`theme of "${code}" did not found`);
343
+ }
344
+ }
345
+
298
346
  function variantMatcher(name, handler) {
299
347
  let re;
300
348
  return {
@@ -371,47 +419,4 @@ function variantGetParameter(prefix, matcher, separators) {
371
419
  }
372
420
  }
373
421
 
374
- const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
375
- function hasThemeFn(str) {
376
- return str.includes("theme(") && str.includes(")");
377
- }
378
- function transformThemeFn(code, theme, throwOnMissing = true) {
379
- const matches = Array.from(code.toString().matchAll(themeFnRE));
380
- if (!matches.length)
381
- return code;
382
- const s = new MagicString(code);
383
- for (const match of matches) {
384
- const rawArg = match[2];
385
- if (!rawArg)
386
- throw new Error("theme() expect exact one argument, but got 0");
387
- const value = transformThemeString(rawArg, theme, throwOnMissing);
388
- if (value) {
389
- s.overwrite(
390
- match.index,
391
- match.index + match[0].length,
392
- value
393
- );
394
- }
395
- }
396
- return s.toString();
397
- }
398
- function transformThemeString(code, theme, throwOnMissing = true) {
399
- const [rawKey, alpha] = code.split("/");
400
- const keys = rawKey.trim().split(".");
401
- let value = keys.reduce((t, k) => t?.[k], theme);
402
- if (typeof value === "object") {
403
- value = value.DEFAULT;
404
- }
405
- if (typeof value === "string") {
406
- if (alpha) {
407
- const color = parseCssColor(value);
408
- if (color)
409
- value = colorToString(color, alpha);
410
- }
411
- return value;
412
- } else if (throwOnMissing) {
413
- throw new Error(`theme of "${code}" did not found`);
414
- }
415
- }
416
-
417
- export { colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasThemeFn, hex2rgba, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
422
+ export { colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/rule-utils",
3
3
  "type": "module",
4
- "version": "0.62.3",
4
+ "version": "0.63.0",
5
5
  "description": "Utilities for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "magic-string": "^0.30.11",
37
- "@unocss/core": "^0.62.3"
37
+ "@unocss/core": "^0.63.0"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "unbuild",