@weapp-tailwindcss/postcss 1.0.0-alpha.4 → 1.0.0-alpha.5
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.js +368 -29
- package/dist/index.mjs +366 -27
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var _shared = require('@weapp-tailwindcss/shared');
|
|
|
5
5
|
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
6
6
|
|
|
7
7
|
// src/plugins/index.ts
|
|
8
|
-
var
|
|
8
|
+
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
9
9
|
var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
|
|
10
10
|
|
|
11
11
|
// src/symbols.ts
|
|
@@ -36,7 +36,7 @@ var _postcssselectorparser = require('postcss-selector-parser'); var _postcsssel
|
|
|
36
36
|
// src/shared.ts
|
|
37
37
|
var _escape = require('@weapp-core/escape');
|
|
38
38
|
function internalCssSelectorReplacer(selectors, options = {
|
|
39
|
-
escapeMap: _escape.
|
|
39
|
+
escapeMap: _escape.MappingChars2String
|
|
40
40
|
}) {
|
|
41
41
|
const { mangleContext, escapeMap } = options;
|
|
42
42
|
if (mangleContext) {
|
|
@@ -86,11 +86,8 @@ function createRuleTransform(rule, options) {
|
|
|
86
86
|
};
|
|
87
87
|
return transform;
|
|
88
88
|
}
|
|
89
|
-
function getRuleTransformer(rule, options) {
|
|
90
|
-
return _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
|
|
91
|
-
}
|
|
92
89
|
function ruleTransformSync(rule, options) {
|
|
93
|
-
const transformer =
|
|
90
|
+
const transformer = _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
|
|
94
91
|
return transformer.transformSync(rule, {
|
|
95
92
|
lossless: false,
|
|
96
93
|
updateSelector: true
|
|
@@ -113,24 +110,56 @@ function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
|
113
110
|
}).astSync(node);
|
|
114
111
|
return b && a;
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (selector.type === "universal") {
|
|
123
|
-
_optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.remove, 'call', _7 => _7()]);
|
|
124
|
-
}
|
|
125
|
-
if (selector.type === "pseudo" && selector.value === ":is") {
|
|
126
|
-
if (maybeImportantId && _optionalChain([selector, 'access', _8 => _8.nodes, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) === "selector") {
|
|
127
|
-
selector.replaceWith(selector.nodes[0]);
|
|
128
|
-
} else {
|
|
129
|
-
_optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
|
|
113
|
+
function getFallbackRemove(rule) {
|
|
114
|
+
const fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
115
|
+
let maybeImportantId = false;
|
|
116
|
+
selectors.walk((selector, idx) => {
|
|
117
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
118
|
+
maybeImportantId = true;
|
|
130
119
|
}
|
|
131
|
-
|
|
120
|
+
if (selector.type === "universal") {
|
|
121
|
+
_optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.remove, 'call', _7 => _7()]);
|
|
122
|
+
}
|
|
123
|
+
if (selector.type === "pseudo") {
|
|
124
|
+
if (selector.value === ":is") {
|
|
125
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _8 => _8.nodes, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) === "selector") {
|
|
126
|
+
selector.replaceWith(selector.nodes[0]);
|
|
127
|
+
} else {
|
|
128
|
+
_optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
|
|
129
|
+
}
|
|
130
|
+
} else if (selector.value === ":not") {
|
|
131
|
+
for (const x of selector.nodes) {
|
|
132
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
133
|
+
x.nodes = [
|
|
134
|
+
_postcssselectorparser2.default.tag({
|
|
135
|
+
value: "n"
|
|
136
|
+
})
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (selector.type === "attribute") {
|
|
143
|
+
if (selector.attribute === "hidden") {
|
|
144
|
+
_optionalChain([rule, 'optionalAccess', _14 => _14.remove, 'call', _15 => _15()]);
|
|
145
|
+
} else {
|
|
146
|
+
selector.remove();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
selectors.walk((selector) => {
|
|
151
|
+
if (selector.type === "pseudo") {
|
|
152
|
+
if (selector.value === ":where") {
|
|
153
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
154
|
+
if (res) {
|
|
155
|
+
selector.remove();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
132
160
|
});
|
|
133
|
-
|
|
161
|
+
return fallbackRemove;
|
|
162
|
+
}
|
|
134
163
|
|
|
135
164
|
// src/plugins/post.ts
|
|
136
165
|
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
@@ -143,7 +172,7 @@ var postcssWeappTailwindcssPostPlugin = (options = {
|
|
|
143
172
|
if (isMainChunk) {
|
|
144
173
|
p.OnceExit = (root) => {
|
|
145
174
|
root.walkRules((rule) => {
|
|
146
|
-
|
|
175
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
147
176
|
updateSelector: true,
|
|
148
177
|
lossless: false
|
|
149
178
|
});
|
|
@@ -462,7 +491,7 @@ function commonChunkPreflight(node, options) {
|
|
|
462
491
|
const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
463
492
|
node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
|
|
464
493
|
if (testIfVariablesScope(node)) {
|
|
465
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
494
|
+
_optionalChain([ctx, 'optionalAccess', _16 => _16.markVariablesScope, 'call', _17 => _17(node)]);
|
|
466
495
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
467
496
|
node.before(makePseudoVarRule());
|
|
468
497
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -517,17 +546,327 @@ var postcssWeappTailwindcssPrePlugin = (options = {
|
|
|
517
546
|
};
|
|
518
547
|
postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
519
548
|
|
|
520
|
-
//
|
|
549
|
+
// ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.5.1/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
|
|
550
|
+
|
|
521
551
|
|
|
552
|
+
// ../../node_modules/.pnpm/@csstools+selector-specificity@5.0.0_postcss-selector-parser@7.0.0/node_modules/@csstools/selector-specificity/dist/index.mjs
|
|
553
|
+
|
|
554
|
+
function compare(e3, t2) {
|
|
555
|
+
return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
|
|
556
|
+
}
|
|
557
|
+
function selectorSpecificity(t2, s) {
|
|
558
|
+
const i = _optionalChain([s, 'optionalAccess', _18 => _18.customSpecificity, 'optionalCall', _19 => _19(t2)]);
|
|
559
|
+
if (i) return i;
|
|
560
|
+
if (!t2) return { a: 0, b: 0, c: 0 };
|
|
561
|
+
let c = 0, n = 0, o2 = 0;
|
|
562
|
+
if ("universal" == t2.type) return { a: 0, b: 0, c: 0 };
|
|
563
|
+
if ("id" === t2.type) c += 1;
|
|
564
|
+
else if ("tag" === t2.type) o2 += 1;
|
|
565
|
+
else if ("class" === t2.type) n += 1;
|
|
566
|
+
else if ("attribute" === t2.type) n += 1;
|
|
567
|
+
else if (isPseudoElement(t2)) switch (t2.value.toLowerCase()) {
|
|
568
|
+
case "::slotted":
|
|
569
|
+
if (o2 += 1, t2.nodes && t2.nodes.length > 0) {
|
|
570
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
571
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
572
|
+
}
|
|
573
|
+
break;
|
|
574
|
+
case "::view-transition-group":
|
|
575
|
+
case "::view-transition-image-pair":
|
|
576
|
+
case "::view-transition-old":
|
|
577
|
+
case "::view-transition-new":
|
|
578
|
+
return t2.nodes && 1 === t2.nodes.length && "selector" === t2.nodes[0].type && selectorNodeContainsNothingOrOnlyUniversal(t2.nodes[0]) ? { a: 0, b: 0, c: 0 } : { a: 0, b: 0, c: 1 };
|
|
579
|
+
default:
|
|
580
|
+
o2 += 1;
|
|
581
|
+
}
|
|
582
|
+
else if (_postcssselectorparser2.default.isPseudoClass(t2)) switch (t2.value.toLowerCase()) {
|
|
583
|
+
case ":-webkit-any":
|
|
584
|
+
case ":any":
|
|
585
|
+
default:
|
|
586
|
+
n += 1;
|
|
587
|
+
break;
|
|
588
|
+
case ":-moz-any":
|
|
589
|
+
case ":has":
|
|
590
|
+
case ":is":
|
|
591
|
+
case ":matches":
|
|
592
|
+
case ":not":
|
|
593
|
+
if (t2.nodes && t2.nodes.length > 0) {
|
|
594
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
595
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
case ":where":
|
|
599
|
+
break;
|
|
600
|
+
case ":nth-child":
|
|
601
|
+
case ":nth-last-child":
|
|
602
|
+
if (n += 1, t2.nodes && t2.nodes.length > 0) {
|
|
603
|
+
const i2 = t2.nodes[0].nodes.findIndex((e3) => "tag" === e3.type && "of" === e3.value.toLowerCase());
|
|
604
|
+
if (i2 > -1) {
|
|
605
|
+
const a = _postcssselectorparser2.default.selector({ nodes: [], value: "" });
|
|
606
|
+
t2.nodes[0].nodes.slice(i2 + 1).forEach((e3) => {
|
|
607
|
+
a.append(e3.clone());
|
|
608
|
+
});
|
|
609
|
+
const r = [a];
|
|
610
|
+
t2.nodes.length > 1 && r.push(...t2.nodes.slice(1));
|
|
611
|
+
const l = specificityOfMostSpecificListItem(r, s);
|
|
612
|
+
c += l.a, n += l.b, o2 += l.c;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
case ":local":
|
|
617
|
+
case ":global":
|
|
618
|
+
t2.nodes && t2.nodes.length > 0 && t2.nodes.forEach((e3) => {
|
|
619
|
+
const t3 = selectorSpecificity(e3, s);
|
|
620
|
+
c += t3.a, n += t3.b, o2 += t3.c;
|
|
621
|
+
});
|
|
622
|
+
break;
|
|
623
|
+
case ":host":
|
|
624
|
+
case ":host-context":
|
|
625
|
+
if (n += 1, t2.nodes && t2.nodes.length > 0) {
|
|
626
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
627
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
628
|
+
}
|
|
629
|
+
break;
|
|
630
|
+
case ":active-view-transition":
|
|
631
|
+
case ":active-view-transition-type":
|
|
632
|
+
return { a: 0, b: 1, c: 0 };
|
|
633
|
+
}
|
|
634
|
+
else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _20 => _20.nodes, 'optionalAccess', _21 => _21.length]) > 0 && t2.nodes.forEach((e3) => {
|
|
635
|
+
const t3 = selectorSpecificity(e3, s);
|
|
636
|
+
c += t3.a, n += t3.b, o2 += t3.c;
|
|
637
|
+
});
|
|
638
|
+
return { a: c, b: n, c: o2 };
|
|
639
|
+
}
|
|
640
|
+
function specificityOfMostSpecificListItem(e3, t2) {
|
|
641
|
+
let s = { a: 0, b: 0, c: 0 };
|
|
642
|
+
return e3.forEach((e4) => {
|
|
643
|
+
const i = selectorSpecificity(e4, t2);
|
|
644
|
+
compare(i, s) < 0 || (s = i);
|
|
645
|
+
}), s;
|
|
646
|
+
}
|
|
647
|
+
function isPseudoElement(t2) {
|
|
648
|
+
return _postcssselectorparser2.default.isPseudoElement(t2);
|
|
649
|
+
}
|
|
650
|
+
function selectorNodeContainsNothingOrOnlyUniversal(e3) {
|
|
651
|
+
if (!e3) return false;
|
|
652
|
+
if (!e3.nodes) return false;
|
|
653
|
+
const t2 = e3.nodes.filter((e4) => "comment" !== e4.type);
|
|
654
|
+
return 0 === t2.length || 1 === t2.length && "universal" === t2[0].type;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.5.1/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
|
|
658
|
+
function alwaysValidSelector(s) {
|
|
659
|
+
const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
|
|
660
|
+
let t2 = true;
|
|
661
|
+
return o2.walk((e3) => {
|
|
662
|
+
if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || _optionalChain([e3, 'access', _22 => _22.nodes, 'optionalAccess', _23 => _23.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
|
|
663
|
+
if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _24 => _24.nodes, 'optionalAccess', _25 => _25.length]) && ":not" === e3.value.toLowerCase()) {
|
|
664
|
+
let s2 = true;
|
|
665
|
+
if (e3.nodes[0].walkCombinators(() => {
|
|
666
|
+
s2 = false;
|
|
667
|
+
}), s2) return;
|
|
668
|
+
}
|
|
669
|
+
return t2 = false, false;
|
|
670
|
+
}
|
|
671
|
+
}), t2;
|
|
672
|
+
}
|
|
673
|
+
function sortCompoundSelectorsInsideComplexSelector(s) {
|
|
674
|
+
if (!s || !s.nodes || 1 === s.nodes.length) return;
|
|
675
|
+
const o2 = [];
|
|
676
|
+
let t2 = [];
|
|
677
|
+
for (let n2 = 0; n2 < s.nodes.length; n2++) "combinator" !== s.nodes[n2].type ? _postcssselectorparser2.default.isPseudoElement(s.nodes[n2]) ? (o2.push(t2), t2 = [s.nodes[n2]]) : t2.push(s.nodes[n2]) : (o2.push(t2), o2.push([s.nodes[n2]]), t2 = []);
|
|
678
|
+
o2.push(t2);
|
|
679
|
+
const n = [];
|
|
680
|
+
for (let e3 = 0; e3 < o2.length; e3++) {
|
|
681
|
+
const s2 = o2[e3];
|
|
682
|
+
s2.sort((e4, s3) => "selector" === e4.type && "selector" === s3.type && e4.nodes.length && s3.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : "selector" === e4.type && e4.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3, s3.type) : "selector" === s3.type && s3.nodes.length ? selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3, s3.type));
|
|
683
|
+
const t3 = new Set(s2.map((e4) => e4.type)), r = t3.has("universal") && (t3.has("tag") || t3.has("attribute") || t3.has("class") || t3.has("id") || t3.has("pseudo"));
|
|
684
|
+
for (let e4 = 0; e4 < s2.length; e4++) "universal" === s2[e4].type && r ? s2[e4].remove() : n.push(s2[e4]);
|
|
685
|
+
}
|
|
686
|
+
s.removeAll();
|
|
687
|
+
for (let o3 = n.length - 1; o3 >= 0; o3--) {
|
|
688
|
+
const t3 = n[o3 - 1];
|
|
689
|
+
if (n[o3].remove(), t3 && "tag" === t3.type && "tag" === n[o3].type) {
|
|
690
|
+
const t4 = _postcssselectorparser2.default.pseudo({ value: ":is", nodes: [_postcssselectorparser2.default.selector({ value: "", nodes: [n[o3]] })] });
|
|
691
|
+
t4.parent = s, s.nodes.unshift(t4);
|
|
692
|
+
} else n[o3].parent = s, s.nodes.unshift(n[o3]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function selectorTypeOrder(s, t2) {
|
|
696
|
+
return _postcssselectorparser2.default.isPseudoElement(s) ? o.pseudoElement : o[t2];
|
|
697
|
+
}
|
|
698
|
+
var o = { universal: 0, tag: 1, pseudoElement: 2, id: 3, class: 4, attribute: 5, pseudo: 6, selector: 7, string: 8, root: 9, comment: 10 };
|
|
699
|
+
function childAdjacentChild(e3) {
|
|
700
|
+
return !(!e3 || !e3.nodes) && ("selector" === e3.type && (3 === e3.nodes.length && (!(!e3.nodes[0] || "pseudo" !== e3.nodes[0].type || ":-csstools-matches" !== e3.nodes[0].value) && (!(!e3.nodes[1] || "combinator" !== e3.nodes[1].type || "+" !== e3.nodes[1].value && "~" !== e3.nodes[1].value) && (!(!e3.nodes[2] || "pseudo" !== e3.nodes[2].type || ":-csstools-matches" !== e3.nodes[2].value) && (!(!e3.nodes[0].nodes || 1 !== e3.nodes[0].nodes.length) && ("selector" === e3.nodes[0].nodes[0].type && (!(!e3.nodes[0].nodes[0].nodes || 3 !== e3.nodes[0].nodes[0].nodes.length) && (!(!e3.nodes[0].nodes[0].nodes || "combinator" !== e3.nodes[0].nodes[0].nodes[1].type || ">" !== e3.nodes[0].nodes[0].nodes[1].value) && (!(!e3.nodes[2].nodes || 1 !== e3.nodes[2].nodes.length) && ("selector" === e3.nodes[2].nodes[0].type && (!(!e3.nodes[2].nodes[0].nodes || 3 !== e3.nodes[2].nodes[0].nodes.length) && (!(!e3.nodes[2].nodes[0].nodes || "combinator" !== e3.nodes[2].nodes[0].nodes[1].type || ">" !== e3.nodes[2].nodes[0].nodes[1].value) && (e3.nodes[0].nodes[0].insertAfter(e3.nodes[0].nodes[0].nodes[0], e3.nodes[2].nodes[0].nodes[0].clone()), e3.nodes[2].nodes[0].nodes[1].remove(), e3.nodes[2].nodes[0].nodes[0].remove(), e3.nodes[0].replaceWith(e3.nodes[0].nodes[0]), e3.nodes[2].replaceWith(e3.nodes[2].nodes[0]), true))))))))))))));
|
|
701
|
+
}
|
|
702
|
+
function isInCompoundWithOneOtherElement(s) {
|
|
703
|
+
if (!s || !s.nodes) return false;
|
|
704
|
+
if (!_postcssselectorparser2.default.isSelector(s)) return false;
|
|
705
|
+
if (2 !== s.nodes.length) return false;
|
|
706
|
+
let o2 = -1, t2 = -1;
|
|
707
|
+
s.nodes[0] && _postcssselectorparser2.default.isPseudoClass(s.nodes[0]) && ":-csstools-matches" === s.nodes[0].value ? (o2 = 0, t2 = 1) : s.nodes[1] && _postcssselectorparser2.default.isPseudoClass(s.nodes[1]) && ":-csstools-matches" === s.nodes[1].value && (o2 = 1, t2 = 0);
|
|
708
|
+
const n = s.nodes[o2];
|
|
709
|
+
if (!n || !_postcssselectorparser2.default.isPseudoClass(n) || 1 !== n.nodes.length) return false;
|
|
710
|
+
const r = s.nodes[t2];
|
|
711
|
+
return !!r && (!_postcssselectorparser2.default.isCombinator(r) && (n.nodes[0].append(r.clone()), n.replaceWith(...n.nodes[0].nodes), r.remove(), true));
|
|
712
|
+
}
|
|
713
|
+
function isPseudoInFirstCompound(s) {
|
|
714
|
+
if (!s || !s.nodes) return false;
|
|
715
|
+
if (!_postcssselectorparser2.default.isSelector(s)) return false;
|
|
716
|
+
let o2 = -1;
|
|
717
|
+
for (let t3 = 0; t3 < s.nodes.length; t3++) {
|
|
718
|
+
const n2 = s.nodes[t3];
|
|
719
|
+
if (_postcssselectorparser2.default.isCombinator(n2)) return false;
|
|
720
|
+
if (_postcssselectorparser2.default.isPseudoClass(n2) && ":-csstools-matches" === n2.value) {
|
|
721
|
+
if (!n2.nodes || 1 !== n2.nodes.length) return false;
|
|
722
|
+
o2 = t3;
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const t2 = s.nodes[o2];
|
|
727
|
+
if (!t2 || !_postcssselectorparser2.default.isPseudoClass(t2)) return false;
|
|
728
|
+
const n = s.nodes.slice(0, o2), r = s.nodes.slice(o2 + 1);
|
|
729
|
+
return n.forEach((e3) => {
|
|
730
|
+
t2.nodes[0].append(e3.clone());
|
|
731
|
+
}), r.forEach((e3) => {
|
|
732
|
+
t2.nodes[0].append(e3.clone());
|
|
733
|
+
}), t2.replaceWith(...t2.nodes), n.forEach((e3) => {
|
|
734
|
+
e3.remove();
|
|
735
|
+
}), r.forEach((e3) => {
|
|
736
|
+
e3.remove();
|
|
737
|
+
}), true;
|
|
738
|
+
}
|
|
739
|
+
function complexSelectors(s, o2, t2, n) {
|
|
740
|
+
return s.flatMap((s2) => {
|
|
741
|
+
if (-1 === s2.indexOf(":-csstools-matches") && -1 === s2.toLowerCase().indexOf(":is")) return s2;
|
|
742
|
+
const r = _postcssselectorparser2.default.call(void 0, ).astSync(s2);
|
|
743
|
+
return r.walkPseudos((s3) => {
|
|
744
|
+
if (":is" === s3.value.toLowerCase() && s3.nodes && s3.nodes.length && "selector" === s3.nodes[0].type && 0 === s3.nodes[0].nodes.length) return s3.value = ":not", void s3.nodes[0].append(_postcssselectorparser2.default.universal());
|
|
745
|
+
if (":-csstools-matches" === s3.value) if (!s3.nodes || s3.nodes.length) {
|
|
746
|
+
if (s3.walkPseudos((s4) => {
|
|
747
|
+
if (_postcssselectorparser2.default.isPseudoElement(s4)) {
|
|
748
|
+
let e3 = s4.value;
|
|
749
|
+
if (e3.startsWith("::-csstools-invalid-")) return;
|
|
750
|
+
for (; e3.startsWith(":"); ) e3 = e3.slice(1);
|
|
751
|
+
s4.value = `::-csstools-invalid-${e3}`, n();
|
|
752
|
+
}
|
|
753
|
+
}), 1 === s3.nodes.length && "selector" === s3.nodes[0].type) {
|
|
754
|
+
if (1 === s3.nodes[0].nodes.length) return void s3.replaceWith(s3.nodes[0].nodes[0]);
|
|
755
|
+
if (!s3.nodes[0].some((e3) => "combinator" === e3.type)) return void s3.replaceWith(...s3.nodes[0].nodes);
|
|
756
|
+
}
|
|
757
|
+
1 !== r.nodes.length || "selector" !== r.nodes[0].type || 1 !== r.nodes[0].nodes.length || r.nodes[0].nodes[0] !== s3 ? childAdjacentChild(s3.parent) || isInCompoundWithOneOtherElement(s3.parent) || isPseudoInFirstCompound(s3.parent) || ("warning" === o2.onComplexSelector && t2(), s3.value = ":is") : s3.replaceWith(...s3.nodes[0].nodes);
|
|
758
|
+
} else s3.remove();
|
|
759
|
+
}), r.walk((e3) => {
|
|
760
|
+
"selector" === e3.type && "nodes" in e3 && 1 === e3.nodes.length && "selector" === e3.nodes[0].type && e3.replaceWith(e3.nodes[0]);
|
|
761
|
+
}), r.walk((e3) => {
|
|
762
|
+
"nodes" in e3 && sortCompoundSelectorsInsideComplexSelector(e3);
|
|
763
|
+
}), r.toString();
|
|
764
|
+
}).filter((e3) => !!e3);
|
|
765
|
+
}
|
|
766
|
+
function splitSelectors(o2, t2, n = 0) {
|
|
767
|
+
const r = ":not(#" + t2.specificityMatchingName + ")", d = ":not(." + t2.specificityMatchingName + ")", l = ":not(" + t2.specificityMatchingName + ")";
|
|
768
|
+
return o2.flatMap((o3) => {
|
|
769
|
+
if (-1 === o3.toLowerCase().indexOf(":is")) return o3;
|
|
770
|
+
let a = false;
|
|
771
|
+
const i = [];
|
|
772
|
+
if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
|
|
773
|
+
if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
|
|
774
|
+
if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
|
|
775
|
+
if ("pseudo" === _optionalChain([e3, 'access', _26 => _26.parent, 'optionalAccess', _27 => _27.parent, 'optionalAccess', _28 => _28.type]) && ":not" === _optionalChain([e3, 'access', _29 => _29.parent, 'optionalAccess', _30 => _30.parent, 'optionalAccess', _31 => _31.value, 'optionalAccess', _32 => _32.toLowerCase, 'call', _33 => _33()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
|
|
776
|
+
if ("pseudo" === _optionalChain([e3, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.parent, 'optionalAccess', _36 => _36.type]) && ":has" === _optionalChain([e3, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.parent, 'optionalAccess', _39 => _39.value, 'optionalAccess', _40 => _40.toLowerCase, 'call', _41 => _41()])) return void (e3.value = ":-csstools-matches");
|
|
777
|
+
let o4 = e3.parent;
|
|
778
|
+
for (; o4; ) {
|
|
779
|
+
if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
|
|
780
|
+
o4 = o4.parent;
|
|
781
|
+
}
|
|
782
|
+
const t3 = selectorSpecificity(e3), n2 = e3.sourceIndex, c2 = n2 + e3.toString().length, p = [];
|
|
783
|
+
e3.nodes.forEach((e4) => {
|
|
784
|
+
const o5 = { start: n2, end: c2, option: "" }, a2 = selectorSpecificity(e4);
|
|
785
|
+
let i2 = e4.toString().trim();
|
|
786
|
+
const u = Math.max(0, t3.a - a2.a), h = Math.max(0, t3.b - a2.b), f = Math.max(0, t3.c - a2.c);
|
|
787
|
+
for (let e5 = 0; e5 < u; e5++) i2 += r;
|
|
788
|
+
for (let e5 = 0; e5 < h; e5++) i2 += d;
|
|
789
|
+
for (let e5 = 0; e5 < f; e5++) i2 += l;
|
|
790
|
+
o5.option = i2, p.push(o5);
|
|
791
|
+
}), i.push(p);
|
|
792
|
+
}), !i.length) return [o3];
|
|
793
|
+
let c = [];
|
|
794
|
+
return cartesianProduct(...i).forEach((e3) => {
|
|
795
|
+
let s = "";
|
|
796
|
+
for (let t3 = 0; t3 < e3.length; t3++) {
|
|
797
|
+
const n2 = e3[t3];
|
|
798
|
+
s += o3.substring(_optionalChain([e3, 'access', _42 => _42[t3 - 1], 'optionalAccess', _43 => _43.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
|
|
799
|
+
}
|
|
800
|
+
c.push(s);
|
|
801
|
+
}), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
|
|
802
|
+
}).filter((e3) => !!e3);
|
|
803
|
+
}
|
|
804
|
+
function cartesianProduct(...e3) {
|
|
805
|
+
const s = [], o2 = e3.length - 1;
|
|
806
|
+
return function helper(t2, n) {
|
|
807
|
+
for (let r = 0, d = e3[n].length; r < d; r++) {
|
|
808
|
+
const d2 = t2.slice(0);
|
|
809
|
+
d2.push(e3[n][r]), n === o2 ? s.push(d2) : helper(d2, n + 1);
|
|
810
|
+
}
|
|
811
|
+
}([], 0), s;
|
|
812
|
+
}
|
|
813
|
+
var t = /:is\(/i;
|
|
814
|
+
var creator = (e3) => {
|
|
815
|
+
const s = { specificityMatchingName: "does-not-exist", ...e3 || {} };
|
|
816
|
+
return { postcssPlugin: "postcss-is-pseudo-class", prepare() {
|
|
817
|
+
const e4 = /* @__PURE__ */ new WeakSet();
|
|
818
|
+
return { postcssPlugin: "postcss-is-pseudo-class", Rule(o2, { result: n }) {
|
|
819
|
+
if (!o2.selector) return;
|
|
820
|
+
if (!t.test(o2.selector)) return;
|
|
821
|
+
if (e4.has(o2)) return;
|
|
822
|
+
let r = false;
|
|
823
|
+
const warnOnComplexSelector = () => {
|
|
824
|
+
"warning" === s.onComplexSelector && (r || (r = true, o2.warn(n, `Complex selectors in '${o2.selector}' can not be transformed to an equivalent selector without ':is()'.`)));
|
|
825
|
+
};
|
|
826
|
+
let d = false;
|
|
827
|
+
const warnOnPseudoElements = () => {
|
|
828
|
+
"warning" === s.onPseudoElement && (d || (d = true, o2.warn(n, `Pseudo elements are not allowed in ':is()', unable to transform '${o2.selector}'`)));
|
|
829
|
+
};
|
|
830
|
+
try {
|
|
831
|
+
let t2 = false;
|
|
832
|
+
const n2 = [], r2 = complexSelectors(splitSelectors(o2.selectors, { specificityMatchingName: s.specificityMatchingName }), { onComplexSelector: s.onComplexSelector }, warnOnComplexSelector, warnOnPseudoElements);
|
|
833
|
+
if (Array.from(new Set(r2)).forEach((s2) => {
|
|
834
|
+
if (o2.selectors.indexOf(s2) > -1) n2.push(s2);
|
|
835
|
+
else {
|
|
836
|
+
if (alwaysValidSelector(s2)) return n2.push(s2), void (t2 = true);
|
|
837
|
+
e4.add(o2), o2.cloneBefore({ selector: s2 }), t2 = true;
|
|
838
|
+
}
|
|
839
|
+
}), n2.length && t2 && (e4.add(o2), o2.cloneBefore({ selectors: n2 })), !s.preserve) {
|
|
840
|
+
if (!t2) return;
|
|
841
|
+
o2.remove();
|
|
842
|
+
}
|
|
843
|
+
} catch (e5) {
|
|
844
|
+
if (!(e5 instanceof Error)) throw e5;
|
|
845
|
+
if (e5.message.indexOf("call stack size exceeded") > -1) throw e5;
|
|
846
|
+
o2.warn(n, `Failed to parse selector "${o2.selector}" with error: ${e5.message}`);
|
|
847
|
+
}
|
|
848
|
+
} };
|
|
849
|
+
} };
|
|
850
|
+
};
|
|
851
|
+
creator.postcss = true;
|
|
852
|
+
|
|
853
|
+
// src/plugins/index.ts
|
|
522
854
|
|
|
523
855
|
function getPlugins(options) {
|
|
524
856
|
const ctx = createContext();
|
|
525
857
|
options.ctx = ctx;
|
|
526
858
|
const plugins = [
|
|
527
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
859
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _44 => _44.postcssOptions, 'optionalAccess', _45 => _45.plugins]), () => ( [])),
|
|
528
860
|
postcssWeappTailwindcssPrePlugin(options),
|
|
529
|
-
|
|
530
|
-
|
|
861
|
+
_postcsspresetenv2.default.call(void 0, {
|
|
862
|
+
features: {
|
|
863
|
+
"cascade-layers": true,
|
|
864
|
+
"is-pseudo-class": {
|
|
865
|
+
specificityMatchingName: "weapp-tw-ig"
|
|
866
|
+
},
|
|
867
|
+
"oklab-function": true,
|
|
868
|
+
"color-mix": true
|
|
869
|
+
}
|
|
531
870
|
})
|
|
532
871
|
];
|
|
533
872
|
if (options.rem2rpx) {
|
|
@@ -549,7 +888,7 @@ function getPlugins(options) {
|
|
|
549
888
|
function styleHandler(rawSource, options) {
|
|
550
889
|
return _postcss2.default.call(void 0, getPlugins(options)).process(
|
|
551
890
|
rawSource,
|
|
552
|
-
_nullishCoalesce(_optionalChain([options, 'access',
|
|
891
|
+
_nullishCoalesce(_optionalChain([options, 'access', _46 => _46.postcssOptions, 'optionalAccess', _47 => _47.options]), () => ( {
|
|
553
892
|
from: void 0
|
|
554
893
|
}))
|
|
555
894
|
).async();
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
|
5
5
|
import postcss from "postcss";
|
|
6
6
|
|
|
7
7
|
// src/plugins/index.ts
|
|
8
|
-
import
|
|
8
|
+
import postcssPresetEnv from "postcss-preset-env";
|
|
9
9
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
10
10
|
|
|
11
11
|
// src/symbols.ts
|
|
@@ -34,9 +34,9 @@ var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
|
34
34
|
import selectorParser from "postcss-selector-parser";
|
|
35
35
|
|
|
36
36
|
// src/shared.ts
|
|
37
|
-
import { escape,
|
|
37
|
+
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
38
38
|
function internalCssSelectorReplacer(selectors, options = {
|
|
39
|
-
escapeMap:
|
|
39
|
+
escapeMap: MappingChars2String
|
|
40
40
|
}) {
|
|
41
41
|
const { mangleContext, escapeMap } = options;
|
|
42
42
|
if (mangleContext) {
|
|
@@ -86,11 +86,8 @@ function createRuleTransform(rule, options) {
|
|
|
86
86
|
};
|
|
87
87
|
return transform;
|
|
88
88
|
}
|
|
89
|
-
function getRuleTransformer(rule, options) {
|
|
90
|
-
return selectorParser(createRuleTransform(rule, options));
|
|
91
|
-
}
|
|
92
89
|
function ruleTransformSync(rule, options) {
|
|
93
|
-
const transformer =
|
|
90
|
+
const transformer = selectorParser(createRuleTransform(rule, options));
|
|
94
91
|
return transformer.transformSync(rule, {
|
|
95
92
|
lossless: false,
|
|
96
93
|
updateSelector: true
|
|
@@ -113,24 +110,56 @@ function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
|
113
110
|
}).astSync(node);
|
|
114
111
|
return b && a;
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
selector.
|
|
124
|
-
}
|
|
125
|
-
if (selector.type === "pseudo" && selector.value === ":is") {
|
|
126
|
-
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
127
|
-
selector.replaceWith(selector.nodes[0]);
|
|
128
|
-
} else {
|
|
113
|
+
function getFallbackRemove(rule) {
|
|
114
|
+
const fallbackRemove = selectorParser((selectors) => {
|
|
115
|
+
let maybeImportantId = false;
|
|
116
|
+
selectors.walk((selector, idx) => {
|
|
117
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
118
|
+
maybeImportantId = true;
|
|
119
|
+
}
|
|
120
|
+
if (selector.type === "universal") {
|
|
129
121
|
selector.parent?.remove();
|
|
130
122
|
}
|
|
131
|
-
|
|
123
|
+
if (selector.type === "pseudo") {
|
|
124
|
+
if (selector.value === ":is") {
|
|
125
|
+
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
126
|
+
selector.replaceWith(selector.nodes[0]);
|
|
127
|
+
} else {
|
|
128
|
+
selector.parent?.remove();
|
|
129
|
+
}
|
|
130
|
+
} else if (selector.value === ":not") {
|
|
131
|
+
for (const x of selector.nodes) {
|
|
132
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
133
|
+
x.nodes = [
|
|
134
|
+
selectorParser.tag({
|
|
135
|
+
value: "n"
|
|
136
|
+
})
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (selector.type === "attribute") {
|
|
143
|
+
if (selector.attribute === "hidden") {
|
|
144
|
+
rule?.remove();
|
|
145
|
+
} else {
|
|
146
|
+
selector.remove();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
selectors.walk((selector) => {
|
|
151
|
+
if (selector.type === "pseudo") {
|
|
152
|
+
if (selector.value === ":where") {
|
|
153
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
154
|
+
if (res) {
|
|
155
|
+
selector.remove();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
132
160
|
});
|
|
133
|
-
|
|
161
|
+
return fallbackRemove;
|
|
162
|
+
}
|
|
134
163
|
|
|
135
164
|
// src/plugins/post.ts
|
|
136
165
|
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
@@ -143,7 +172,7 @@ var postcssWeappTailwindcssPostPlugin = (options = {
|
|
|
143
172
|
if (isMainChunk) {
|
|
144
173
|
p.OnceExit = (root) => {
|
|
145
174
|
root.walkRules((rule) => {
|
|
146
|
-
|
|
175
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
147
176
|
updateSelector: true,
|
|
148
177
|
lossless: false
|
|
149
178
|
});
|
|
@@ -517,17 +546,327 @@ var postcssWeappTailwindcssPrePlugin = (options = {
|
|
|
517
546
|
};
|
|
518
547
|
postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
519
548
|
|
|
549
|
+
// ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.5.1/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
|
|
550
|
+
import e2 from "postcss-selector-parser";
|
|
551
|
+
|
|
552
|
+
// ../../node_modules/.pnpm/@csstools+selector-specificity@5.0.0_postcss-selector-parser@7.0.0/node_modules/@csstools/selector-specificity/dist/index.mjs
|
|
553
|
+
import e from "postcss-selector-parser";
|
|
554
|
+
function compare(e3, t2) {
|
|
555
|
+
return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
|
|
556
|
+
}
|
|
557
|
+
function selectorSpecificity(t2, s) {
|
|
558
|
+
const i = s?.customSpecificity?.(t2);
|
|
559
|
+
if (i) return i;
|
|
560
|
+
if (!t2) return { a: 0, b: 0, c: 0 };
|
|
561
|
+
let c = 0, n = 0, o2 = 0;
|
|
562
|
+
if ("universal" == t2.type) return { a: 0, b: 0, c: 0 };
|
|
563
|
+
if ("id" === t2.type) c += 1;
|
|
564
|
+
else if ("tag" === t2.type) o2 += 1;
|
|
565
|
+
else if ("class" === t2.type) n += 1;
|
|
566
|
+
else if ("attribute" === t2.type) n += 1;
|
|
567
|
+
else if (isPseudoElement(t2)) switch (t2.value.toLowerCase()) {
|
|
568
|
+
case "::slotted":
|
|
569
|
+
if (o2 += 1, t2.nodes && t2.nodes.length > 0) {
|
|
570
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
571
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
572
|
+
}
|
|
573
|
+
break;
|
|
574
|
+
case "::view-transition-group":
|
|
575
|
+
case "::view-transition-image-pair":
|
|
576
|
+
case "::view-transition-old":
|
|
577
|
+
case "::view-transition-new":
|
|
578
|
+
return t2.nodes && 1 === t2.nodes.length && "selector" === t2.nodes[0].type && selectorNodeContainsNothingOrOnlyUniversal(t2.nodes[0]) ? { a: 0, b: 0, c: 0 } : { a: 0, b: 0, c: 1 };
|
|
579
|
+
default:
|
|
580
|
+
o2 += 1;
|
|
581
|
+
}
|
|
582
|
+
else if (e.isPseudoClass(t2)) switch (t2.value.toLowerCase()) {
|
|
583
|
+
case ":-webkit-any":
|
|
584
|
+
case ":any":
|
|
585
|
+
default:
|
|
586
|
+
n += 1;
|
|
587
|
+
break;
|
|
588
|
+
case ":-moz-any":
|
|
589
|
+
case ":has":
|
|
590
|
+
case ":is":
|
|
591
|
+
case ":matches":
|
|
592
|
+
case ":not":
|
|
593
|
+
if (t2.nodes && t2.nodes.length > 0) {
|
|
594
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
595
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
case ":where":
|
|
599
|
+
break;
|
|
600
|
+
case ":nth-child":
|
|
601
|
+
case ":nth-last-child":
|
|
602
|
+
if (n += 1, t2.nodes && t2.nodes.length > 0) {
|
|
603
|
+
const i2 = t2.nodes[0].nodes.findIndex((e3) => "tag" === e3.type && "of" === e3.value.toLowerCase());
|
|
604
|
+
if (i2 > -1) {
|
|
605
|
+
const a = e.selector({ nodes: [], value: "" });
|
|
606
|
+
t2.nodes[0].nodes.slice(i2 + 1).forEach((e3) => {
|
|
607
|
+
a.append(e3.clone());
|
|
608
|
+
});
|
|
609
|
+
const r = [a];
|
|
610
|
+
t2.nodes.length > 1 && r.push(...t2.nodes.slice(1));
|
|
611
|
+
const l = specificityOfMostSpecificListItem(r, s);
|
|
612
|
+
c += l.a, n += l.b, o2 += l.c;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
case ":local":
|
|
617
|
+
case ":global":
|
|
618
|
+
t2.nodes && t2.nodes.length > 0 && t2.nodes.forEach((e3) => {
|
|
619
|
+
const t3 = selectorSpecificity(e3, s);
|
|
620
|
+
c += t3.a, n += t3.b, o2 += t3.c;
|
|
621
|
+
});
|
|
622
|
+
break;
|
|
623
|
+
case ":host":
|
|
624
|
+
case ":host-context":
|
|
625
|
+
if (n += 1, t2.nodes && t2.nodes.length > 0) {
|
|
626
|
+
const e3 = specificityOfMostSpecificListItem(t2.nodes, s);
|
|
627
|
+
c += e3.a, n += e3.b, o2 += e3.c;
|
|
628
|
+
}
|
|
629
|
+
break;
|
|
630
|
+
case ":active-view-transition":
|
|
631
|
+
case ":active-view-transition-type":
|
|
632
|
+
return { a: 0, b: 1, c: 0 };
|
|
633
|
+
}
|
|
634
|
+
else e.isContainer(t2) && t2.nodes?.length > 0 && t2.nodes.forEach((e3) => {
|
|
635
|
+
const t3 = selectorSpecificity(e3, s);
|
|
636
|
+
c += t3.a, n += t3.b, o2 += t3.c;
|
|
637
|
+
});
|
|
638
|
+
return { a: c, b: n, c: o2 };
|
|
639
|
+
}
|
|
640
|
+
function specificityOfMostSpecificListItem(e3, t2) {
|
|
641
|
+
let s = { a: 0, b: 0, c: 0 };
|
|
642
|
+
return e3.forEach((e4) => {
|
|
643
|
+
const i = selectorSpecificity(e4, t2);
|
|
644
|
+
compare(i, s) < 0 || (s = i);
|
|
645
|
+
}), s;
|
|
646
|
+
}
|
|
647
|
+
function isPseudoElement(t2) {
|
|
648
|
+
return e.isPseudoElement(t2);
|
|
649
|
+
}
|
|
650
|
+
function selectorNodeContainsNothingOrOnlyUniversal(e3) {
|
|
651
|
+
if (!e3) return false;
|
|
652
|
+
if (!e3.nodes) return false;
|
|
653
|
+
const t2 = e3.nodes.filter((e4) => "comment" !== e4.type);
|
|
654
|
+
return 0 === t2.length || 1 === t2.length && "universal" === t2[0].type;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// ../../node_modules/.pnpm/@csstools+postcss-is-pseudo-class@5.0.1_postcss@8.5.1/node_modules/@csstools/postcss-is-pseudo-class/dist/index.mjs
|
|
658
|
+
function alwaysValidSelector(s) {
|
|
659
|
+
const o2 = e2().astSync(s);
|
|
660
|
+
let t2 = true;
|
|
661
|
+
return o2.walk((e3) => {
|
|
662
|
+
if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || e3.nodes?.length || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
|
|
663
|
+
if ("pseudo" === e3.type && 1 === e3.nodes?.length && ":not" === e3.value.toLowerCase()) {
|
|
664
|
+
let s2 = true;
|
|
665
|
+
if (e3.nodes[0].walkCombinators(() => {
|
|
666
|
+
s2 = false;
|
|
667
|
+
}), s2) return;
|
|
668
|
+
}
|
|
669
|
+
return t2 = false, false;
|
|
670
|
+
}
|
|
671
|
+
}), t2;
|
|
672
|
+
}
|
|
673
|
+
function sortCompoundSelectorsInsideComplexSelector(s) {
|
|
674
|
+
if (!s || !s.nodes || 1 === s.nodes.length) return;
|
|
675
|
+
const o2 = [];
|
|
676
|
+
let t2 = [];
|
|
677
|
+
for (let n2 = 0; n2 < s.nodes.length; n2++) "combinator" !== s.nodes[n2].type ? e2.isPseudoElement(s.nodes[n2]) ? (o2.push(t2), t2 = [s.nodes[n2]]) : t2.push(s.nodes[n2]) : (o2.push(t2), o2.push([s.nodes[n2]]), t2 = []);
|
|
678
|
+
o2.push(t2);
|
|
679
|
+
const n = [];
|
|
680
|
+
for (let e3 = 0; e3 < o2.length; e3++) {
|
|
681
|
+
const s2 = o2[e3];
|
|
682
|
+
s2.sort((e4, s3) => "selector" === e4.type && "selector" === s3.type && e4.nodes.length && s3.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : "selector" === e4.type && e4.nodes.length ? selectorTypeOrder(e4.nodes[0], e4.nodes[0].type) - selectorTypeOrder(s3, s3.type) : "selector" === s3.type && s3.nodes.length ? selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3.nodes[0], s3.nodes[0].type) : selectorTypeOrder(e4, e4.type) - selectorTypeOrder(s3, s3.type));
|
|
683
|
+
const t3 = new Set(s2.map((e4) => e4.type)), r = t3.has("universal") && (t3.has("tag") || t3.has("attribute") || t3.has("class") || t3.has("id") || t3.has("pseudo"));
|
|
684
|
+
for (let e4 = 0; e4 < s2.length; e4++) "universal" === s2[e4].type && r ? s2[e4].remove() : n.push(s2[e4]);
|
|
685
|
+
}
|
|
686
|
+
s.removeAll();
|
|
687
|
+
for (let o3 = n.length - 1; o3 >= 0; o3--) {
|
|
688
|
+
const t3 = n[o3 - 1];
|
|
689
|
+
if (n[o3].remove(), t3 && "tag" === t3.type && "tag" === n[o3].type) {
|
|
690
|
+
const t4 = e2.pseudo({ value: ":is", nodes: [e2.selector({ value: "", nodes: [n[o3]] })] });
|
|
691
|
+
t4.parent = s, s.nodes.unshift(t4);
|
|
692
|
+
} else n[o3].parent = s, s.nodes.unshift(n[o3]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function selectorTypeOrder(s, t2) {
|
|
696
|
+
return e2.isPseudoElement(s) ? o.pseudoElement : o[t2];
|
|
697
|
+
}
|
|
698
|
+
var o = { universal: 0, tag: 1, pseudoElement: 2, id: 3, class: 4, attribute: 5, pseudo: 6, selector: 7, string: 8, root: 9, comment: 10 };
|
|
699
|
+
function childAdjacentChild(e3) {
|
|
700
|
+
return !(!e3 || !e3.nodes) && ("selector" === e3.type && (3 === e3.nodes.length && (!(!e3.nodes[0] || "pseudo" !== e3.nodes[0].type || ":-csstools-matches" !== e3.nodes[0].value) && (!(!e3.nodes[1] || "combinator" !== e3.nodes[1].type || "+" !== e3.nodes[1].value && "~" !== e3.nodes[1].value) && (!(!e3.nodes[2] || "pseudo" !== e3.nodes[2].type || ":-csstools-matches" !== e3.nodes[2].value) && (!(!e3.nodes[0].nodes || 1 !== e3.nodes[0].nodes.length) && ("selector" === e3.nodes[0].nodes[0].type && (!(!e3.nodes[0].nodes[0].nodes || 3 !== e3.nodes[0].nodes[0].nodes.length) && (!(!e3.nodes[0].nodes[0].nodes || "combinator" !== e3.nodes[0].nodes[0].nodes[1].type || ">" !== e3.nodes[0].nodes[0].nodes[1].value) && (!(!e3.nodes[2].nodes || 1 !== e3.nodes[2].nodes.length) && ("selector" === e3.nodes[2].nodes[0].type && (!(!e3.nodes[2].nodes[0].nodes || 3 !== e3.nodes[2].nodes[0].nodes.length) && (!(!e3.nodes[2].nodes[0].nodes || "combinator" !== e3.nodes[2].nodes[0].nodes[1].type || ">" !== e3.nodes[2].nodes[0].nodes[1].value) && (e3.nodes[0].nodes[0].insertAfter(e3.nodes[0].nodes[0].nodes[0], e3.nodes[2].nodes[0].nodes[0].clone()), e3.nodes[2].nodes[0].nodes[1].remove(), e3.nodes[2].nodes[0].nodes[0].remove(), e3.nodes[0].replaceWith(e3.nodes[0].nodes[0]), e3.nodes[2].replaceWith(e3.nodes[2].nodes[0]), true))))))))))))));
|
|
701
|
+
}
|
|
702
|
+
function isInCompoundWithOneOtherElement(s) {
|
|
703
|
+
if (!s || !s.nodes) return false;
|
|
704
|
+
if (!e2.isSelector(s)) return false;
|
|
705
|
+
if (2 !== s.nodes.length) return false;
|
|
706
|
+
let o2 = -1, t2 = -1;
|
|
707
|
+
s.nodes[0] && e2.isPseudoClass(s.nodes[0]) && ":-csstools-matches" === s.nodes[0].value ? (o2 = 0, t2 = 1) : s.nodes[1] && e2.isPseudoClass(s.nodes[1]) && ":-csstools-matches" === s.nodes[1].value && (o2 = 1, t2 = 0);
|
|
708
|
+
const n = s.nodes[o2];
|
|
709
|
+
if (!n || !e2.isPseudoClass(n) || 1 !== n.nodes.length) return false;
|
|
710
|
+
const r = s.nodes[t2];
|
|
711
|
+
return !!r && (!e2.isCombinator(r) && (n.nodes[0].append(r.clone()), n.replaceWith(...n.nodes[0].nodes), r.remove(), true));
|
|
712
|
+
}
|
|
713
|
+
function isPseudoInFirstCompound(s) {
|
|
714
|
+
if (!s || !s.nodes) return false;
|
|
715
|
+
if (!e2.isSelector(s)) return false;
|
|
716
|
+
let o2 = -1;
|
|
717
|
+
for (let t3 = 0; t3 < s.nodes.length; t3++) {
|
|
718
|
+
const n2 = s.nodes[t3];
|
|
719
|
+
if (e2.isCombinator(n2)) return false;
|
|
720
|
+
if (e2.isPseudoClass(n2) && ":-csstools-matches" === n2.value) {
|
|
721
|
+
if (!n2.nodes || 1 !== n2.nodes.length) return false;
|
|
722
|
+
o2 = t3;
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const t2 = s.nodes[o2];
|
|
727
|
+
if (!t2 || !e2.isPseudoClass(t2)) return false;
|
|
728
|
+
const n = s.nodes.slice(0, o2), r = s.nodes.slice(o2 + 1);
|
|
729
|
+
return n.forEach((e3) => {
|
|
730
|
+
t2.nodes[0].append(e3.clone());
|
|
731
|
+
}), r.forEach((e3) => {
|
|
732
|
+
t2.nodes[0].append(e3.clone());
|
|
733
|
+
}), t2.replaceWith(...t2.nodes), n.forEach((e3) => {
|
|
734
|
+
e3.remove();
|
|
735
|
+
}), r.forEach((e3) => {
|
|
736
|
+
e3.remove();
|
|
737
|
+
}), true;
|
|
738
|
+
}
|
|
739
|
+
function complexSelectors(s, o2, t2, n) {
|
|
740
|
+
return s.flatMap((s2) => {
|
|
741
|
+
if (-1 === s2.indexOf(":-csstools-matches") && -1 === s2.toLowerCase().indexOf(":is")) return s2;
|
|
742
|
+
const r = e2().astSync(s2);
|
|
743
|
+
return r.walkPseudos((s3) => {
|
|
744
|
+
if (":is" === s3.value.toLowerCase() && s3.nodes && s3.nodes.length && "selector" === s3.nodes[0].type && 0 === s3.nodes[0].nodes.length) return s3.value = ":not", void s3.nodes[0].append(e2.universal());
|
|
745
|
+
if (":-csstools-matches" === s3.value) if (!s3.nodes || s3.nodes.length) {
|
|
746
|
+
if (s3.walkPseudos((s4) => {
|
|
747
|
+
if (e2.isPseudoElement(s4)) {
|
|
748
|
+
let e3 = s4.value;
|
|
749
|
+
if (e3.startsWith("::-csstools-invalid-")) return;
|
|
750
|
+
for (; e3.startsWith(":"); ) e3 = e3.slice(1);
|
|
751
|
+
s4.value = `::-csstools-invalid-${e3}`, n();
|
|
752
|
+
}
|
|
753
|
+
}), 1 === s3.nodes.length && "selector" === s3.nodes[0].type) {
|
|
754
|
+
if (1 === s3.nodes[0].nodes.length) return void s3.replaceWith(s3.nodes[0].nodes[0]);
|
|
755
|
+
if (!s3.nodes[0].some((e3) => "combinator" === e3.type)) return void s3.replaceWith(...s3.nodes[0].nodes);
|
|
756
|
+
}
|
|
757
|
+
1 !== r.nodes.length || "selector" !== r.nodes[0].type || 1 !== r.nodes[0].nodes.length || r.nodes[0].nodes[0] !== s3 ? childAdjacentChild(s3.parent) || isInCompoundWithOneOtherElement(s3.parent) || isPseudoInFirstCompound(s3.parent) || ("warning" === o2.onComplexSelector && t2(), s3.value = ":is") : s3.replaceWith(...s3.nodes[0].nodes);
|
|
758
|
+
} else s3.remove();
|
|
759
|
+
}), r.walk((e3) => {
|
|
760
|
+
"selector" === e3.type && "nodes" in e3 && 1 === e3.nodes.length && "selector" === e3.nodes[0].type && e3.replaceWith(e3.nodes[0]);
|
|
761
|
+
}), r.walk((e3) => {
|
|
762
|
+
"nodes" in e3 && sortCompoundSelectorsInsideComplexSelector(e3);
|
|
763
|
+
}), r.toString();
|
|
764
|
+
}).filter((e3) => !!e3);
|
|
765
|
+
}
|
|
766
|
+
function splitSelectors(o2, t2, n = 0) {
|
|
767
|
+
const r = ":not(#" + t2.specificityMatchingName + ")", d = ":not(." + t2.specificityMatchingName + ")", l = ":not(" + t2.specificityMatchingName + ")";
|
|
768
|
+
return o2.flatMap((o3) => {
|
|
769
|
+
if (-1 === o3.toLowerCase().indexOf(":is")) return o3;
|
|
770
|
+
let a = false;
|
|
771
|
+
const i = [];
|
|
772
|
+
if (e2().astSync(o3).walkPseudos((e3) => {
|
|
773
|
+
if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
|
|
774
|
+
if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
|
|
775
|
+
if ("pseudo" === e3.parent?.parent?.type && ":not" === e3.parent?.parent?.value?.toLowerCase()) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
|
|
776
|
+
if ("pseudo" === e3.parent?.parent?.type && ":has" === e3.parent?.parent?.value?.toLowerCase()) return void (e3.value = ":-csstools-matches");
|
|
777
|
+
let o4 = e3.parent;
|
|
778
|
+
for (; o4; ) {
|
|
779
|
+
if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
|
|
780
|
+
o4 = o4.parent;
|
|
781
|
+
}
|
|
782
|
+
const t3 = selectorSpecificity(e3), n2 = e3.sourceIndex, c2 = n2 + e3.toString().length, p = [];
|
|
783
|
+
e3.nodes.forEach((e4) => {
|
|
784
|
+
const o5 = { start: n2, end: c2, option: "" }, a2 = selectorSpecificity(e4);
|
|
785
|
+
let i2 = e4.toString().trim();
|
|
786
|
+
const u = Math.max(0, t3.a - a2.a), h = Math.max(0, t3.b - a2.b), f = Math.max(0, t3.c - a2.c);
|
|
787
|
+
for (let e5 = 0; e5 < u; e5++) i2 += r;
|
|
788
|
+
for (let e5 = 0; e5 < h; e5++) i2 += d;
|
|
789
|
+
for (let e5 = 0; e5 < f; e5++) i2 += l;
|
|
790
|
+
o5.option = i2, p.push(o5);
|
|
791
|
+
}), i.push(p);
|
|
792
|
+
}), !i.length) return [o3];
|
|
793
|
+
let c = [];
|
|
794
|
+
return cartesianProduct(...i).forEach((e3) => {
|
|
795
|
+
let s = "";
|
|
796
|
+
for (let t3 = 0; t3 < e3.length; t3++) {
|
|
797
|
+
const n2 = e3[t3];
|
|
798
|
+
s += o3.substring(e3[t3 - 1]?.end || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
|
|
799
|
+
}
|
|
800
|
+
c.push(s);
|
|
801
|
+
}), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
|
|
802
|
+
}).filter((e3) => !!e3);
|
|
803
|
+
}
|
|
804
|
+
function cartesianProduct(...e3) {
|
|
805
|
+
const s = [], o2 = e3.length - 1;
|
|
806
|
+
return function helper(t2, n) {
|
|
807
|
+
for (let r = 0, d = e3[n].length; r < d; r++) {
|
|
808
|
+
const d2 = t2.slice(0);
|
|
809
|
+
d2.push(e3[n][r]), n === o2 ? s.push(d2) : helper(d2, n + 1);
|
|
810
|
+
}
|
|
811
|
+
}([], 0), s;
|
|
812
|
+
}
|
|
813
|
+
var t = /:is\(/i;
|
|
814
|
+
var creator = (e3) => {
|
|
815
|
+
const s = { specificityMatchingName: "does-not-exist", ...e3 || {} };
|
|
816
|
+
return { postcssPlugin: "postcss-is-pseudo-class", prepare() {
|
|
817
|
+
const e4 = /* @__PURE__ */ new WeakSet();
|
|
818
|
+
return { postcssPlugin: "postcss-is-pseudo-class", Rule(o2, { result: n }) {
|
|
819
|
+
if (!o2.selector) return;
|
|
820
|
+
if (!t.test(o2.selector)) return;
|
|
821
|
+
if (e4.has(o2)) return;
|
|
822
|
+
let r = false;
|
|
823
|
+
const warnOnComplexSelector = () => {
|
|
824
|
+
"warning" === s.onComplexSelector && (r || (r = true, o2.warn(n, `Complex selectors in '${o2.selector}' can not be transformed to an equivalent selector without ':is()'.`)));
|
|
825
|
+
};
|
|
826
|
+
let d = false;
|
|
827
|
+
const warnOnPseudoElements = () => {
|
|
828
|
+
"warning" === s.onPseudoElement && (d || (d = true, o2.warn(n, `Pseudo elements are not allowed in ':is()', unable to transform '${o2.selector}'`)));
|
|
829
|
+
};
|
|
830
|
+
try {
|
|
831
|
+
let t2 = false;
|
|
832
|
+
const n2 = [], r2 = complexSelectors(splitSelectors(o2.selectors, { specificityMatchingName: s.specificityMatchingName }), { onComplexSelector: s.onComplexSelector }, warnOnComplexSelector, warnOnPseudoElements);
|
|
833
|
+
if (Array.from(new Set(r2)).forEach((s2) => {
|
|
834
|
+
if (o2.selectors.indexOf(s2) > -1) n2.push(s2);
|
|
835
|
+
else {
|
|
836
|
+
if (alwaysValidSelector(s2)) return n2.push(s2), void (t2 = true);
|
|
837
|
+
e4.add(o2), o2.cloneBefore({ selector: s2 }), t2 = true;
|
|
838
|
+
}
|
|
839
|
+
}), n2.length && t2 && (e4.add(o2), o2.cloneBefore({ selectors: n2 })), !s.preserve) {
|
|
840
|
+
if (!t2) return;
|
|
841
|
+
o2.remove();
|
|
842
|
+
}
|
|
843
|
+
} catch (e5) {
|
|
844
|
+
if (!(e5 instanceof Error)) throw e5;
|
|
845
|
+
if (e5.message.indexOf("call stack size exceeded") > -1) throw e5;
|
|
846
|
+
o2.warn(n, `Failed to parse selector "${o2.selector}" with error: ${e5.message}`);
|
|
847
|
+
}
|
|
848
|
+
} };
|
|
849
|
+
} };
|
|
850
|
+
};
|
|
851
|
+
creator.postcss = true;
|
|
852
|
+
|
|
520
853
|
// src/plugins/index.ts
|
|
521
|
-
import { default as default2 } from "
|
|
522
|
-
import { default as default3 } from "postcss-rem-to-responsive-pixel";
|
|
854
|
+
import { default as default2 } from "postcss-rem-to-responsive-pixel";
|
|
523
855
|
function getPlugins(options) {
|
|
524
856
|
const ctx = createContext();
|
|
525
857
|
options.ctx = ctx;
|
|
526
858
|
const plugins = [
|
|
527
859
|
...options.postcssOptions?.plugins ?? [],
|
|
528
860
|
postcssWeappTailwindcssPrePlugin(options),
|
|
529
|
-
|
|
530
|
-
|
|
861
|
+
postcssPresetEnv({
|
|
862
|
+
features: {
|
|
863
|
+
"cascade-layers": true,
|
|
864
|
+
"is-pseudo-class": {
|
|
865
|
+
specificityMatchingName: "weapp-tw-ig"
|
|
866
|
+
},
|
|
867
|
+
"oklab-function": true,
|
|
868
|
+
"color-mix": true
|
|
869
|
+
}
|
|
531
870
|
})
|
|
532
871
|
];
|
|
533
872
|
if (options.rem2rpx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/postcss",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "@weapp-tailwindcss/postcss",
|
|
5
5
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@weapp-core/escape": "~3.0.2",
|
|
36
|
+
"@weapp-core/escape": "~4.0.0",
|
|
38
37
|
"postcss": "~8.5.1",
|
|
38
|
+
"postcss-preset-env": "^10.1.3",
|
|
39
39
|
"postcss-rem-to-responsive-pixel": "~6.0.2",
|
|
40
40
|
"postcss-selector-parser": "~7.0.0",
|
|
41
41
|
"@weapp-tailwindcss/shared": "1.0.0-alpha.3"
|