@unocss/rule-utils 0.62.3 → 0.62.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.d.mts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +43 -43
- package/package.json +2 -2
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,18 @@ 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;
|
|
59
|
-
|
|
60
51
|
declare const themeFnRE: RegExp;
|
|
61
52
|
declare function hasThemeFn(str: string): boolean;
|
|
62
53
|
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
63
54
|
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
64
55
|
|
|
56
|
+
declare function getBracket(str: string, open: string, close: string): string[] | undefined;
|
|
57
|
+
declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
|
|
58
|
+
declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
|
|
59
|
+
|
|
60
|
+
declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
|
|
61
|
+
declare function variantParentMatcher(name: string, parent: string): VariantObject;
|
|
62
|
+
declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
63
|
+
declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
64
|
+
|
|
65
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 };
|
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,18 @@ 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;
|
|
59
|
-
|
|
60
51
|
declare const themeFnRE: RegExp;
|
|
61
52
|
declare function hasThemeFn(str: string): boolean;
|
|
62
53
|
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
63
54
|
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
64
55
|
|
|
56
|
+
declare function getBracket(str: string, open: string, close: string): string[] | undefined;
|
|
57
|
+
declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
|
|
58
|
+
declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
|
|
59
|
+
|
|
60
|
+
declare function variantMatcher(name: string, handler: (input: VariantHandlerContext) => Record<string, any>): VariantObject;
|
|
61
|
+
declare function variantParentMatcher(name: string, parent: string): VariantObject;
|
|
62
|
+
declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
63
|
+
declare function variantGetParameter(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
64
|
+
|
|
65
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -295,6 +295,49 @@ function createValueHandler(handlers) {
|
|
|
295
295
|
return handler;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
299
|
+
function hasThemeFn(str) {
|
|
300
|
+
return str.includes("theme(") && str.includes(")");
|
|
301
|
+
}
|
|
302
|
+
function transformThemeFn(code, theme, throwOnMissing = true) {
|
|
303
|
+
const matches = Array.from(code.toString().matchAll(themeFnRE));
|
|
304
|
+
if (!matches.length)
|
|
305
|
+
return code;
|
|
306
|
+
const s = new MagicString(code);
|
|
307
|
+
for (const match of matches) {
|
|
308
|
+
const rawArg = match[2];
|
|
309
|
+
if (!rawArg)
|
|
310
|
+
throw new Error("theme() expect exact one argument, but got 0");
|
|
311
|
+
const value = transformThemeString(rawArg, theme, throwOnMissing);
|
|
312
|
+
if (value) {
|
|
313
|
+
s.overwrite(
|
|
314
|
+
match.index,
|
|
315
|
+
match.index + match[0].length,
|
|
316
|
+
value
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return s.toString();
|
|
321
|
+
}
|
|
322
|
+
function transformThemeString(code, theme, throwOnMissing = true) {
|
|
323
|
+
const [rawKey, alpha] = code.split("/");
|
|
324
|
+
const keys = rawKey.trim().split(".");
|
|
325
|
+
let value = keys.reduce((t, k) => t?.[k], theme);
|
|
326
|
+
if (typeof value === "object") {
|
|
327
|
+
value = value.DEFAULT;
|
|
328
|
+
}
|
|
329
|
+
if (typeof value === "string") {
|
|
330
|
+
if (alpha) {
|
|
331
|
+
const color = parseCssColor(value);
|
|
332
|
+
if (color)
|
|
333
|
+
value = colorToString(color, alpha);
|
|
334
|
+
}
|
|
335
|
+
return value;
|
|
336
|
+
} else if (throwOnMissing) {
|
|
337
|
+
throw new Error(`theme of "${code}" did not found`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
298
341
|
function variantMatcher(name, handler) {
|
|
299
342
|
let re;
|
|
300
343
|
return {
|
|
@@ -371,47 +414,4 @@ function variantGetParameter(prefix, matcher, separators) {
|
|
|
371
414
|
}
|
|
372
415
|
}
|
|
373
416
|
|
|
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
417
|
export { colorOpacityToString, colorToString, createValueHandler, getBracket, getStringComponent, getStringComponents, hasThemeFn, hex2rgba, 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.
|
|
4
|
+
"version": "0.62.4",
|
|
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.
|
|
37
|
+
"@unocss/core": "^0.62.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "unbuild",
|