@unocss/rule-utils 66.6.6-beta.1 → 66.6.7
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.mjs +36 -43
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { escapeRegExp, escapeSelector, isString, toArray } from "@unocss/core";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
|
-
|
|
4
3
|
//#region src/utilities.ts
|
|
5
4
|
function getBracket(str, open, close) {
|
|
6
5
|
if (str === "") return;
|
|
@@ -64,7 +63,6 @@ function getStringComponents(str, separators, limit, open = "(", close = ")") {
|
|
|
64
63
|
}
|
|
65
64
|
if (components.length > 0) return components;
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
//#endregion
|
|
69
67
|
//#region src/colors.ts
|
|
70
68
|
const cssColorFunctions = [
|
|
@@ -268,7 +266,6 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
268
266
|
alpha
|
|
269
267
|
};
|
|
270
268
|
}
|
|
271
|
-
|
|
272
269
|
//#endregion
|
|
273
270
|
//#region src/directive.ts
|
|
274
271
|
const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
@@ -309,7 +306,6 @@ function calcMaxWidthBySize(size) {
|
|
|
309
306
|
}
|
|
310
307
|
return `calc(${size} - 0.1px)`;
|
|
311
308
|
}
|
|
312
|
-
|
|
313
309
|
//#endregion
|
|
314
310
|
//#region src/handlers.ts
|
|
315
311
|
function createValueHandler(handlers) {
|
|
@@ -336,14 +332,12 @@ function createValueHandler(handlers) {
|
|
|
336
332
|
});
|
|
337
333
|
return handler;
|
|
338
334
|
}
|
|
339
|
-
|
|
340
335
|
//#endregion
|
|
341
336
|
//#region src/icon.ts
|
|
342
337
|
const iconFnRE = /icon\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
343
338
|
function hasIconFn(str) {
|
|
344
339
|
return str.includes("icon(") && str.includes(")");
|
|
345
340
|
}
|
|
346
|
-
|
|
347
341
|
//#endregion
|
|
348
342
|
//#region src/pseudo.ts
|
|
349
343
|
const PseudoPlaceholder = "__pseudo_placeholder__";
|
|
@@ -404,7 +398,8 @@ const PseudoClasses = Object.fromEntries([
|
|
|
404
398
|
["placeholder", "::placeholder"],
|
|
405
399
|
["before", "::before"],
|
|
406
400
|
["after", "::after"],
|
|
407
|
-
["file", "::file-selector-button"]
|
|
401
|
+
["file", "::file-selector-button"],
|
|
402
|
+
["details-content", "::details-content"]
|
|
408
403
|
].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
409
404
|
const PseudoClassesKeys = Object.keys(PseudoClasses);
|
|
410
405
|
const PseudoClassesColon = Object.fromEntries([["backdrop", "::backdrop"]].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
@@ -433,15 +428,15 @@ const excludedPseudo = [
|
|
|
433
428
|
const PseudoClassesAndElementsStr = Object.entries(PseudoClasses).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
434
429
|
const PseudoClassesAndElementsColonStr = Object.entries(PseudoClassesColon).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
435
430
|
function createTaggedPseudoClassMatcher(tag, parent, combinator, utils) {
|
|
436
|
-
const { h, variantGetBracket
|
|
437
|
-
const rawRE =
|
|
431
|
+
const { h, variantGetBracket } = utils;
|
|
432
|
+
const rawRE = new RegExp(`^(${escapeRegExp(parent)}:)(\\S+)${escapeRegExp(combinator)}\\1`);
|
|
438
433
|
let splitRE;
|
|
439
434
|
let pseudoRE;
|
|
440
435
|
let pseudoColonRE;
|
|
441
436
|
let pseudoVarRE;
|
|
442
437
|
const matchBracket = (input) => {
|
|
443
438
|
var _rest$split;
|
|
444
|
-
const body = variantGetBracket
|
|
439
|
+
const body = variantGetBracket(`${tag}-`, input, []);
|
|
445
440
|
if (!body) return;
|
|
446
441
|
const [match, rest] = body;
|
|
447
442
|
const bracketValue = h.bracket(match);
|
|
@@ -484,10 +479,10 @@ function createTaggedPseudoClassMatcher(tag, parent, combinator, utils) {
|
|
|
484
479
|
name: `pseudo:${tag}`,
|
|
485
480
|
match(input, ctx) {
|
|
486
481
|
if (!(splitRE && pseudoRE && pseudoColonRE)) {
|
|
487
|
-
splitRE =
|
|
488
|
-
pseudoRE =
|
|
489
|
-
pseudoColonRE =
|
|
490
|
-
pseudoVarRE =
|
|
482
|
+
splitRE = new RegExp(`(?:${ctx.generator.config.separators.join("|")})`);
|
|
483
|
+
pseudoRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.join("|")})`);
|
|
484
|
+
pseudoColonRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
485
|
+
pseudoVarRE = new RegExp(`^${tag}-(?:(${PseudoClassFunctionsStr})-)?\\[(.+)\\](?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
491
486
|
}
|
|
492
487
|
if (!input.startsWith(tag)) return;
|
|
493
488
|
const result = matchBracket(input) || matchPseudo(input) || matchPseudoVar(input);
|
|
@@ -495,9 +490,9 @@ function createTaggedPseudoClassMatcher(tag, parent, combinator, utils) {
|
|
|
495
490
|
const [_label, matcher, prefix, pseudoName = ""] = result;
|
|
496
491
|
return {
|
|
497
492
|
matcher,
|
|
498
|
-
handle: (input
|
|
499
|
-
...input
|
|
500
|
-
prefix: `${prefix}${combinator}${input
|
|
493
|
+
handle: (input, next) => next({
|
|
494
|
+
...input,
|
|
495
|
+
prefix: `${prefix}${combinator}${input.prefix}`.replace(rawRE, "$1$2:"),
|
|
501
496
|
sort: PseudoClassesKeys.indexOf(pseudoName) ?? PseudoClassesColonKeys.indexOf(pseudoName)
|
|
502
497
|
})
|
|
503
498
|
};
|
|
@@ -514,8 +509,8 @@ function createPseudoClassesAndElements(utils) {
|
|
|
514
509
|
name: "pseudo",
|
|
515
510
|
match(input, ctx) {
|
|
516
511
|
if (!(PseudoClassesAndElementsRE && PseudoClassesAndElementsColonRE)) {
|
|
517
|
-
PseudoClassesAndElementsRE =
|
|
518
|
-
PseudoClassesAndElementsColonRE =
|
|
512
|
+
PseudoClassesAndElementsRE = new RegExp(`^(${PseudoClassesAndElementsStr})(?:-(\\d+|\\[(\\w|[+-.])+\\]))?(?:${ctx.generator.config.separators.join("|")})`);
|
|
513
|
+
PseudoClassesAndElementsColonRE = new RegExp(`^(${PseudoClassesAndElementsColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
519
514
|
}
|
|
520
515
|
const match = input.match(PseudoClassesAndElementsRE) || input.match(PseudoClassesAndElementsColonRE);
|
|
521
516
|
if (match) {
|
|
@@ -531,10 +526,10 @@ function createPseudoClassesAndElements(utils) {
|
|
|
531
526
|
if (index === -1) index = void 0;
|
|
532
527
|
return {
|
|
533
528
|
matcher: input.slice(match[0].length),
|
|
534
|
-
handle: (input
|
|
535
|
-
const selectors = pseudo.includes("::") && !excludedPseudo.includes(pseudo) ? { pseudo: `${input
|
|
529
|
+
handle: (input, next) => {
|
|
530
|
+
const selectors = pseudo.includes("::") && !excludedPseudo.includes(pseudo) ? { pseudo: `${input.pseudo}${pseudo}` } : { selector: `${input.selector}${pseudo}` };
|
|
536
531
|
return next({
|
|
537
|
-
...input
|
|
532
|
+
...input,
|
|
538
533
|
...selectors,
|
|
539
534
|
sort: index,
|
|
540
535
|
noMerge: true
|
|
@@ -548,14 +543,14 @@ function createPseudoClassesAndElements(utils) {
|
|
|
548
543
|
}, {
|
|
549
544
|
name: "pseudo:multi",
|
|
550
545
|
match(input, ctx) {
|
|
551
|
-
if (!PseudoClassesMultiRE) PseudoClassesMultiRE =
|
|
546
|
+
if (!PseudoClassesMultiRE) PseudoClassesMultiRE = new RegExp(`^(${PseudoClassesMultiStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
552
547
|
const match = input.match(PseudoClassesMultiRE);
|
|
553
548
|
if (match) return PseudoClassesMulti[match[1]].map((pseudo) => {
|
|
554
549
|
return {
|
|
555
550
|
matcher: input.slice(match[0].length),
|
|
556
|
-
handle: (input
|
|
557
|
-
...input
|
|
558
|
-
pseudo: `${input
|
|
551
|
+
handle: (input, next) => next({
|
|
552
|
+
...input,
|
|
553
|
+
pseudo: `${input.pseudo}${pseudo}`
|
|
559
554
|
})
|
|
560
555
|
};
|
|
561
556
|
});
|
|
@@ -565,21 +560,21 @@ function createPseudoClassesAndElements(utils) {
|
|
|
565
560
|
}];
|
|
566
561
|
}
|
|
567
562
|
function createPseudoClassFunctions(utils) {
|
|
568
|
-
const { getBracket
|
|
563
|
+
const { getBracket, h } = utils;
|
|
569
564
|
let PseudoClassFunctionsRE;
|
|
570
565
|
let PseudoClassColonFunctionsRE;
|
|
571
566
|
let PseudoClassVarFunctionRE;
|
|
572
567
|
return {
|
|
573
568
|
match(input, ctx) {
|
|
574
569
|
if (!(PseudoClassFunctionsRE && PseudoClassColonFunctionsRE)) {
|
|
575
|
-
PseudoClassFunctionsRE =
|
|
576
|
-
PseudoClassColonFunctionsRE =
|
|
577
|
-
PseudoClassVarFunctionRE =
|
|
570
|
+
PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
571
|
+
PseudoClassColonFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
572
|
+
PseudoClassVarFunctionRE = new RegExp(`^(${PseudoClassFunctionsStr})-(\\[.+\\])(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
578
573
|
}
|
|
579
574
|
const match = input.match(PseudoClassFunctionsRE) || input.match(PseudoClassColonFunctionsRE) || input.match(PseudoClassVarFunctionRE);
|
|
580
575
|
if (match) {
|
|
581
576
|
const fn = match[1];
|
|
582
|
-
const pseudo = getBracket
|
|
577
|
+
const pseudo = getBracket(match[2], "[", "]") ? h.bracket(match[2]) : PseudoClasses[match[2]] || PseudoClassesColon[match[2]] || `:${match[2]}`;
|
|
583
578
|
return {
|
|
584
579
|
matcher: input.slice(match[0].length),
|
|
585
580
|
selector: (s) => `${s}:${fn}(${pseudo})`
|
|
@@ -618,7 +613,6 @@ function createPartClasses() {
|
|
|
618
613
|
multiPass: true
|
|
619
614
|
};
|
|
620
615
|
}
|
|
621
|
-
|
|
622
616
|
//#endregion
|
|
623
617
|
//#region src/variants.ts
|
|
624
618
|
function variantMatcher(name, handler, options = {}) {
|
|
@@ -626,15 +620,15 @@ function variantMatcher(name, handler, options = {}) {
|
|
|
626
620
|
return {
|
|
627
621
|
name,
|
|
628
622
|
match(input, ctx) {
|
|
629
|
-
if (!re) re =
|
|
623
|
+
if (!re) re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
|
|
630
624
|
const match = input.match(re);
|
|
631
625
|
if (match) {
|
|
632
626
|
const matcher = input.slice(match[0].length);
|
|
633
|
-
const handlers = toArray(handler).map((handler
|
|
627
|
+
const handlers = toArray(handler).map((handler) => ({
|
|
634
628
|
matcher,
|
|
635
|
-
handle: (input
|
|
636
|
-
...input
|
|
637
|
-
...handler
|
|
629
|
+
handle: (input, next) => next({
|
|
630
|
+
...input,
|
|
631
|
+
...handler(input)
|
|
638
632
|
}),
|
|
639
633
|
...options
|
|
640
634
|
}));
|
|
@@ -649,13 +643,13 @@ function variantParentMatcher(name, parent) {
|
|
|
649
643
|
return {
|
|
650
644
|
name,
|
|
651
645
|
match(input, ctx) {
|
|
652
|
-
if (!re) re =
|
|
646
|
+
if (!re) re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
|
|
653
647
|
const match = input.match(re);
|
|
654
648
|
if (match) return {
|
|
655
649
|
matcher: input.slice(match[0].length),
|
|
656
|
-
handle: (input
|
|
657
|
-
...input
|
|
658
|
-
parent: `${input
|
|
650
|
+
handle: (input, next) => next({
|
|
651
|
+
...input,
|
|
652
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}${parent}`
|
|
659
653
|
})
|
|
660
654
|
};
|
|
661
655
|
},
|
|
@@ -704,6 +698,5 @@ function variantGetParameter(prefix, matcher, separators) {
|
|
|
704
698
|
}
|
|
705
699
|
}
|
|
706
700
|
}
|
|
707
|
-
|
|
708
701
|
//#endregion
|
|
709
|
-
export { PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|
|
702
|
+
export { PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, 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.6.
|
|
4
|
+
"version": "66.6.7",
|
|
5
5
|
"description": "Utilities for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"magic-string": "^0.30.21",
|
|
33
|
-
"@unocss/core": "^66.6.
|
|
33
|
+
"@unocss/core": "^66.6.7"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsdown",
|