@unocss/rule-utils 66.1.2 → 66.1.3
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 +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.mjs +46 -37
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,12 @@ declare function parseCssColor(str?: string): CSSColorValue | undefined;
|
|
|
40
40
|
declare function colorOpacityToString(color: CSSColorValue): string | number;
|
|
41
41
|
declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
|
|
42
42
|
|
|
43
|
+
declare const themeFnRE: RegExp;
|
|
44
|
+
declare function hasThemeFn(str: string): boolean;
|
|
45
|
+
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
46
|
+
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
47
|
+
declare function calcMaxWidthBySize(size: string): string;
|
|
48
|
+
|
|
43
49
|
type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
44
50
|
type ValueHandler<K extends string> = {
|
|
45
51
|
[S in K]: ValueHandler<K>;
|
|
@@ -54,11 +60,6 @@ declare function createValueHandler<K extends string>(handlers: Record<K, ValueH
|
|
|
54
60
|
declare const iconFnRE: RegExp;
|
|
55
61
|
declare function hasIconFn(str: string): boolean;
|
|
56
62
|
|
|
57
|
-
declare const themeFnRE: RegExp;
|
|
58
|
-
declare function hasThemeFn(str: string): boolean;
|
|
59
|
-
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
60
|
-
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
61
|
-
|
|
62
63
|
declare function getBracket(str: string, open: string, close: string): string[] | undefined;
|
|
63
64
|
declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
|
|
64
65
|
declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
|
|
@@ -68,4 +69,4 @@ declare function variantParentMatcher<T extends object = object>(name: string, p
|
|
|
68
69
|
declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
69
70
|
declare function variantGetParameter(prefix: Arrayable<string>, matcher: string, separators: string[]): string[] | undefined;
|
|
70
71
|
|
|
71
|
-
export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
|
72
|
+
export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ declare function parseCssColor(str?: string): CSSColorValue | undefined;
|
|
|
40
40
|
declare function colorOpacityToString(color: CSSColorValue): string | number;
|
|
41
41
|
declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
|
|
42
42
|
|
|
43
|
+
declare const themeFnRE: RegExp;
|
|
44
|
+
declare function hasThemeFn(str: string): boolean;
|
|
45
|
+
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
46
|
+
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
47
|
+
declare function calcMaxWidthBySize(size: string): string;
|
|
48
|
+
|
|
43
49
|
type ValueHandlerCallback = (str: string) => string | number | undefined;
|
|
44
50
|
type ValueHandler<K extends string> = {
|
|
45
51
|
[S in K]: ValueHandler<K>;
|
|
@@ -54,11 +60,6 @@ declare function createValueHandler<K extends string>(handlers: Record<K, ValueH
|
|
|
54
60
|
declare const iconFnRE: RegExp;
|
|
55
61
|
declare function hasIconFn(str: string): boolean;
|
|
56
62
|
|
|
57
|
-
declare const themeFnRE: RegExp;
|
|
58
|
-
declare function hasThemeFn(str: string): boolean;
|
|
59
|
-
declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
|
|
60
|
-
declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
|
|
61
|
-
|
|
62
63
|
declare function getBracket(str: string, open: string, close: string): string[] | undefined;
|
|
63
64
|
declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
|
|
64
65
|
declare function getStringComponents(str: string, separators: string | string[], limit?: number): string[] | undefined;
|
|
@@ -68,4 +69,4 @@ declare function variantParentMatcher<T extends object = object>(name: string, p
|
|
|
68
69
|
declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
|
|
69
70
|
declare function variantGetParameter(prefix: Arrayable<string>, matcher: string, separators: string[]): string[] | undefined;
|
|
70
71
|
|
|
71
|
-
export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
|
72
|
+
export { type CSSColorValue, type ParsedColorValue, type RGBAColorValue, type ValueHandler, type ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
package/dist/index.mjs
CHANGED
|
@@ -264,42 +264,6 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
function createValueHandler(handlers) {
|
|
268
|
-
const handler = function(str) {
|
|
269
|
-
const s = this.__options?.sequence || [];
|
|
270
|
-
this.__options.sequence = [];
|
|
271
|
-
for (const n of s) {
|
|
272
|
-
const res = handlers[n](str);
|
|
273
|
-
if (res != null)
|
|
274
|
-
return res;
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
function addProcessor(that, name) {
|
|
278
|
-
if (!that.__options) {
|
|
279
|
-
that.__options = {
|
|
280
|
-
sequence: []
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
that.__options.sequence.push(name);
|
|
284
|
-
return that;
|
|
285
|
-
}
|
|
286
|
-
for (const name of Object.keys(handlers)) {
|
|
287
|
-
Object.defineProperty(handler, name, {
|
|
288
|
-
enumerable: true,
|
|
289
|
-
configurable: true,
|
|
290
|
-
get() {
|
|
291
|
-
return addProcessor(this, name);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
return handler;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const iconFnRE = /icon\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
299
|
-
function hasIconFn(str) {
|
|
300
|
-
return str.includes("icon(") && str.includes(")");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
267
|
const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
304
268
|
function hasThemeFn(str) {
|
|
305
269
|
return str.includes("theme(") && str.includes(")");
|
|
@@ -342,6 +306,51 @@ function transformThemeString(code, theme, throwOnMissing = true) {
|
|
|
342
306
|
throw new Error(`theme of "${code}" did not found`);
|
|
343
307
|
}
|
|
344
308
|
}
|
|
309
|
+
function calcMaxWidthBySize(size) {
|
|
310
|
+
const value = size.match(/^-?\d+\.?\d*/)?.[0] || "";
|
|
311
|
+
const unit = size.slice(value.length);
|
|
312
|
+
if (unit === "px") {
|
|
313
|
+
const maxWidth = Number.parseFloat(value) - 0.1;
|
|
314
|
+
return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
|
|
315
|
+
}
|
|
316
|
+
return `calc(${size} - 0.1px)`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function createValueHandler(handlers) {
|
|
320
|
+
const handler = function(str) {
|
|
321
|
+
const s = this.__options?.sequence || [];
|
|
322
|
+
this.__options.sequence = [];
|
|
323
|
+
for (const n of s) {
|
|
324
|
+
const res = handlers[n](str);
|
|
325
|
+
if (res != null)
|
|
326
|
+
return res;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
function addProcessor(that, name) {
|
|
330
|
+
if (!that.__options) {
|
|
331
|
+
that.__options = {
|
|
332
|
+
sequence: []
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
that.__options.sequence.push(name);
|
|
336
|
+
return that;
|
|
337
|
+
}
|
|
338
|
+
for (const name of Object.keys(handlers)) {
|
|
339
|
+
Object.defineProperty(handler, name, {
|
|
340
|
+
enumerable: true,
|
|
341
|
+
configurable: true,
|
|
342
|
+
get() {
|
|
343
|
+
return addProcessor(this, name);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return handler;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const iconFnRE = /icon\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
351
|
+
function hasIconFn(str) {
|
|
352
|
+
return str.includes("icon(") && str.includes(")");
|
|
353
|
+
}
|
|
345
354
|
|
|
346
355
|
function variantMatcher(name, handler) {
|
|
347
356
|
let re;
|
|
@@ -423,4 +432,4 @@ function variantGetParameter(prefix, matcher, separators) {
|
|
|
423
432
|
}
|
|
424
433
|
}
|
|
425
434
|
|
|
426
|
-
export { alphaPlaceholders, alphaPlaceholdersRE, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, iconFnRE, parseCssColor, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
|
435
|
+
export { alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createValueHandler, cssColorFunctions, 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": "66.1.
|
|
4
|
+
"version": "66.1.3",
|
|
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.17",
|
|
37
|
-
"@unocss/core": "^66.1.
|
|
37
|
+
"@unocss/core": "^66.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "unbuild",
|