@weapp-tailwindcss/postcss 1.0.4 → 1.0.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 +287 -188
- package/dist/index.mjs +278 -179
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,179 +53,10 @@ var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
|
53
53
|
// src/selectorParser.ts
|
|
54
54
|
var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
|
|
55
55
|
|
|
56
|
-
// src/shared.ts
|
|
57
|
-
var _escape = require('@weapp-core/escape');
|
|
58
|
-
function internalCssSelectorReplacer(selectors, options = {
|
|
59
|
-
escapeMap: _escape.MappingChars2String
|
|
60
|
-
}) {
|
|
61
|
-
const { mangleContext, escapeMap } = options;
|
|
62
|
-
if (mangleContext) {
|
|
63
|
-
selectors = mangleContext.cssHandler(selectors);
|
|
64
|
-
}
|
|
65
|
-
return _escape.escape.call(void 0, selectors, {
|
|
66
|
-
map: escapeMap
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function composeIsPseudo(strs) {
|
|
70
|
-
if (typeof strs === "string") {
|
|
71
|
-
return strs;
|
|
72
|
-
}
|
|
73
|
-
if (strs.length > 1) {
|
|
74
|
-
return `:is(${strs.join(",")})`;
|
|
75
|
-
}
|
|
76
|
-
return strs.join("");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/selectorParser.ts
|
|
80
|
-
function createRuleTransform(rule, options) {
|
|
81
|
-
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
82
|
-
const transform = (selectors) => {
|
|
83
|
-
selectors.walk((selector) => {
|
|
84
|
-
if (selector.type === "universal" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
|
|
85
|
-
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
86
|
-
}
|
|
87
|
-
if (cssRemoveHoverPseudoClass && selector.type === "selector") {
|
|
88
|
-
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
89
|
-
if (node) {
|
|
90
|
-
selector.remove();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (selector.type === "pseudo" && selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
|
|
94
|
-
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
95
|
-
}
|
|
96
|
-
if (selector.type === "class") {
|
|
97
|
-
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
98
|
-
escapeMap,
|
|
99
|
-
mangleContext
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if (selectors.length === 0) {
|
|
104
|
-
rule.remove();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return transform;
|
|
108
|
-
}
|
|
109
|
-
function ruleTransformSync(rule, options) {
|
|
110
|
-
const transformer = _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
|
|
111
|
-
return transformer.transformSync(rule, {
|
|
112
|
-
lossless: false,
|
|
113
|
-
updateSelector: true
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
117
|
-
let b = false;
|
|
118
|
-
let a = false;
|
|
119
|
-
_postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
120
|
-
selectors.walkPseudos((s) => {
|
|
121
|
-
if (_optionalChain([s, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.length]) === 1) {
|
|
122
|
-
if (/^:?:before$/.test(s.value)) {
|
|
123
|
-
b = true;
|
|
124
|
-
}
|
|
125
|
-
if (/^:?:after$/.test(s.value)) {
|
|
126
|
-
a = true;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}).astSync(node);
|
|
131
|
-
return b && a;
|
|
132
|
-
}
|
|
133
|
-
function getFallbackRemove(rule) {
|
|
134
|
-
const fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
135
|
-
let maybeImportantId = false;
|
|
136
|
-
selectors.walk((selector, idx) => {
|
|
137
|
-
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
138
|
-
maybeImportantId = true;
|
|
139
|
-
}
|
|
140
|
-
if (selector.type === "universal") {
|
|
141
|
-
_optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.remove, 'call', _7 => _7()]);
|
|
142
|
-
}
|
|
143
|
-
if (selector.type === "pseudo") {
|
|
144
|
-
if (selector.value === ":is") {
|
|
145
|
-
if (maybeImportantId && _optionalChain([selector, 'access', _8 => _8.nodes, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) === "selector") {
|
|
146
|
-
selector.replaceWith(selector.nodes[0]);
|
|
147
|
-
} else {
|
|
148
|
-
_optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
|
|
149
|
-
}
|
|
150
|
-
} else if (selector.value === ":not") {
|
|
151
|
-
for (const x of selector.nodes) {
|
|
152
|
-
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
153
|
-
x.nodes = [
|
|
154
|
-
_postcssselectorparser2.default.tag({
|
|
155
|
-
value: "#n"
|
|
156
|
-
})
|
|
157
|
-
];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} else if (selector.value === ":where") {
|
|
161
|
-
for (const n of selector.nodes) {
|
|
162
|
-
for (const node of n.nodes) {
|
|
163
|
-
if (node.type === "attribute") {
|
|
164
|
-
node.remove();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (selector.type === "attribute") {
|
|
171
|
-
if (selector.attribute === "hidden") {
|
|
172
|
-
_optionalChain([rule, 'optionalAccess', _14 => _14.remove, 'call', _15 => _15()]);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
selectors.walk((selector) => {
|
|
177
|
-
if (selector.type === "pseudo") {
|
|
178
|
-
if (selector.value === ":where") {
|
|
179
|
-
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
180
|
-
if (res) {
|
|
181
|
-
selector.remove();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return fallbackRemove;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// src/plugins/post.ts
|
|
191
|
-
var OklabSuffix = "in oklab";
|
|
192
|
-
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
193
|
-
isMainChunk: true
|
|
194
|
-
}) => {
|
|
195
|
-
const { customRuleCallback, isMainChunk } = options;
|
|
196
|
-
const p = {
|
|
197
|
-
postcssPlugin
|
|
198
|
-
};
|
|
199
|
-
if (isMainChunk) {
|
|
200
|
-
p.OnceExit = (root) => {
|
|
201
|
-
root.walkRules((rule) => {
|
|
202
|
-
getFallbackRemove(rule).transformSync(rule, {
|
|
203
|
-
updateSelector: true,
|
|
204
|
-
lossless: false
|
|
205
|
-
});
|
|
206
|
-
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
207
|
-
rule.remove();
|
|
208
|
-
}
|
|
209
|
-
rule.walkDecls((decl) => {
|
|
210
|
-
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
211
|
-
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
if (typeof customRuleCallback === "function") {
|
|
218
|
-
p.Rule = (rule) => {
|
|
219
|
-
customRuleCallback(rule, options);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return p;
|
|
223
|
-
};
|
|
224
|
-
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
225
|
-
|
|
226
56
|
// src/mp.ts
|
|
227
57
|
|
|
228
58
|
|
|
59
|
+
|
|
229
60
|
// src/cssVars.ts
|
|
230
61
|
var cssVars_default = [
|
|
231
62
|
{
|
|
@@ -434,6 +265,79 @@ var cssVars_default = [
|
|
|
434
265
|
}
|
|
435
266
|
];
|
|
436
267
|
|
|
268
|
+
// src/shared.ts
|
|
269
|
+
var _escape = require('@weapp-core/escape');
|
|
270
|
+
|
|
271
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
272
|
+
escapeMap: _escape.MappingChars2String
|
|
273
|
+
}) {
|
|
274
|
+
const { mangleContext, escapeMap } = options;
|
|
275
|
+
if (mangleContext) {
|
|
276
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
277
|
+
}
|
|
278
|
+
return _escape.escape.call(void 0, selectors, {
|
|
279
|
+
map: escapeMap
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function composeIsPseudoAst(strs) {
|
|
283
|
+
if (typeof strs === "string") {
|
|
284
|
+
return [
|
|
285
|
+
_postcssselectorparser2.default.tag({
|
|
286
|
+
value: strs
|
|
287
|
+
}),
|
|
288
|
+
_postcssselectorparser2.default.combinator({
|
|
289
|
+
value: "+"
|
|
290
|
+
}),
|
|
291
|
+
_postcssselectorparser2.default.tag({
|
|
292
|
+
value: strs
|
|
293
|
+
})
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
if (strs.length > 1) {
|
|
297
|
+
return [
|
|
298
|
+
_postcssselectorparser2.default.pseudo({
|
|
299
|
+
value: ":is",
|
|
300
|
+
nodes: strs.map(
|
|
301
|
+
(str) => _postcssselectorparser2.default.tag({
|
|
302
|
+
value: str
|
|
303
|
+
})
|
|
304
|
+
)
|
|
305
|
+
}),
|
|
306
|
+
_postcssselectorparser2.default.combinator({
|
|
307
|
+
value: "+"
|
|
308
|
+
}),
|
|
309
|
+
_postcssselectorparser2.default.pseudo({
|
|
310
|
+
value: ":is",
|
|
311
|
+
nodes: strs.map(
|
|
312
|
+
(str) => _postcssselectorparser2.default.tag({
|
|
313
|
+
value: str
|
|
314
|
+
})
|
|
315
|
+
)
|
|
316
|
+
})
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
return [
|
|
320
|
+
_postcssselectorparser2.default.tag({
|
|
321
|
+
value: strs[0]
|
|
322
|
+
}),
|
|
323
|
+
_postcssselectorparser2.default.combinator({
|
|
324
|
+
value: "+"
|
|
325
|
+
}),
|
|
326
|
+
_postcssselectorparser2.default.tag({
|
|
327
|
+
value: strs[0]
|
|
328
|
+
})
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
function composeIsPseudo(strs) {
|
|
332
|
+
if (typeof strs === "string") {
|
|
333
|
+
return strs;
|
|
334
|
+
}
|
|
335
|
+
if (strs.length > 1) {
|
|
336
|
+
return `:is(${strs.join(",")})`;
|
|
337
|
+
}
|
|
338
|
+
return strs.join("");
|
|
339
|
+
}
|
|
340
|
+
|
|
437
341
|
// src/mp.ts
|
|
438
342
|
var initialNodes = cssVars_default.map((x) => {
|
|
439
343
|
return new (0, _postcss.Declaration)({
|
|
@@ -509,21 +413,24 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
509
413
|
}
|
|
510
414
|
return selectors;
|
|
511
415
|
}
|
|
512
|
-
function
|
|
513
|
-
let childCombinatorReplaceValue =
|
|
416
|
+
function getCombinatorSelectorAst(options) {
|
|
417
|
+
let childCombinatorReplaceValue = [
|
|
418
|
+
_postcssselectorparser2.default.tag({ value: "view" }),
|
|
419
|
+
_postcssselectorparser2.default.combinator({ value: "+" }),
|
|
420
|
+
_postcssselectorparser2.default.tag({ value: "view" })
|
|
421
|
+
];
|
|
422
|
+
const { cssChildCombinatorReplaceValue } = options;
|
|
514
423
|
if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
515
|
-
|
|
516
|
-
childCombinatorReplaceValue = `${x} + ${x}`;
|
|
424
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
517
425
|
} else if (typeof cssChildCombinatorReplaceValue === "string") {
|
|
518
|
-
childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
|
|
426
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
519
427
|
}
|
|
520
|
-
return
|
|
428
|
+
return childCombinatorReplaceValue;
|
|
521
429
|
}
|
|
522
430
|
function commonChunkPreflight(node, options) {
|
|
523
|
-
const { ctx,
|
|
524
|
-
node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
|
|
431
|
+
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
525
432
|
if (testIfVariablesScope(node)) {
|
|
526
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
433
|
+
_optionalChain([ctx, 'optionalAccess', _ => _.markVariablesScope, 'call', _2 => _2(node)]);
|
|
527
434
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
528
435
|
node.before(makePseudoVarRule());
|
|
529
436
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -544,6 +451,198 @@ function commonChunkPreflight(node, options) {
|
|
|
544
451
|
}
|
|
545
452
|
}
|
|
546
453
|
|
|
454
|
+
// src/selectorParser.ts
|
|
455
|
+
function createRuleTransform(rule, options) {
|
|
456
|
+
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
457
|
+
const transform = (selectors) => {
|
|
458
|
+
selectors.walk((selector, index) => {
|
|
459
|
+
if (selector.type === "universal") {
|
|
460
|
+
if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _3 => _3.universal])) {
|
|
461
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
462
|
+
}
|
|
463
|
+
} else if (selector.type === "selector") {
|
|
464
|
+
if (cssRemoveHoverPseudoClass) {
|
|
465
|
+
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
466
|
+
if (node) {
|
|
467
|
+
selector.remove();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else if (selector.type === "pseudo") {
|
|
471
|
+
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _4 => _4.root])) {
|
|
472
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
473
|
+
} else if (selector.value === ":where") {
|
|
474
|
+
if (index === 0 && selector.length === 1) {
|
|
475
|
+
selector.walk((node, idx) => {
|
|
476
|
+
if (idx === 0 && node.type === "class") {
|
|
477
|
+
const nodes = _optionalChain([node, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
|
|
478
|
+
if (nodes) {
|
|
479
|
+
const first = nodes[idx + 1];
|
|
480
|
+
if (first && first.type === "combinator" && first.value === ">") {
|
|
481
|
+
const second = nodes[idx + 2];
|
|
482
|
+
if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
|
|
483
|
+
const ast = getCombinatorSelectorAst(options);
|
|
484
|
+
second.replaceWith(
|
|
485
|
+
...ast
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
selector.replaceWith(...selector.nodes);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} else if (selector.type === "class") {
|
|
496
|
+
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
497
|
+
escapeMap,
|
|
498
|
+
mangleContext
|
|
499
|
+
});
|
|
500
|
+
} else if (selector.type === "combinator") {
|
|
501
|
+
if (selector.value === ">") {
|
|
502
|
+
const nodes = _optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes]);
|
|
503
|
+
if (nodes) {
|
|
504
|
+
const first = nodes[index + 1];
|
|
505
|
+
if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
|
|
506
|
+
const second = nodes[index + 2];
|
|
507
|
+
if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
|
|
508
|
+
const third = nodes[index + 3];
|
|
509
|
+
if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
|
|
510
|
+
const ast = getCombinatorSelectorAst(options);
|
|
511
|
+
_optionalChain([selector, 'access', _9 => _9.parent, 'optionalAccess', _10 => _10.nodes, 'access', _11 => _11.splice, 'call', _12 => _12(
|
|
512
|
+
index + 1,
|
|
513
|
+
3,
|
|
514
|
+
...ast
|
|
515
|
+
)]);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
if (selectors.length === 0) {
|
|
524
|
+
rule.remove();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
return transform;
|
|
528
|
+
}
|
|
529
|
+
function ruleTransformSync(rule, options) {
|
|
530
|
+
const transformer = _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
|
|
531
|
+
return transformer.transformSync(rule, {
|
|
532
|
+
lossless: false,
|
|
533
|
+
updateSelector: true
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
537
|
+
let b = false;
|
|
538
|
+
let a = false;
|
|
539
|
+
_postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
540
|
+
selectors.walkPseudos((s) => {
|
|
541
|
+
if (_optionalChain([s, 'access', _13 => _13.parent, 'optionalAccess', _14 => _14.length]) === 1) {
|
|
542
|
+
if (/^:?:before$/.test(s.value)) {
|
|
543
|
+
b = true;
|
|
544
|
+
}
|
|
545
|
+
if (/^:?:after$/.test(s.value)) {
|
|
546
|
+
a = true;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}).astSync(node);
|
|
551
|
+
return b && a;
|
|
552
|
+
}
|
|
553
|
+
function getFallbackRemove(rule) {
|
|
554
|
+
const fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
555
|
+
let maybeImportantId = false;
|
|
556
|
+
selectors.walk((selector, idx) => {
|
|
557
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
558
|
+
maybeImportantId = true;
|
|
559
|
+
}
|
|
560
|
+
if (selector.type === "universal") {
|
|
561
|
+
_optionalChain([selector, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.remove, 'call', _17 => _17()]);
|
|
562
|
+
}
|
|
563
|
+
if (selector.type === "pseudo") {
|
|
564
|
+
if (selector.value === ":is") {
|
|
565
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _18 => _18.nodes, 'access', _19 => _19[0], 'optionalAccess', _20 => _20.type]) === "selector") {
|
|
566
|
+
selector.replaceWith(selector.nodes[0]);
|
|
567
|
+
} else {
|
|
568
|
+
_optionalChain([selector, 'access', _21 => _21.parent, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
|
|
569
|
+
}
|
|
570
|
+
} else if (selector.value === ":not") {
|
|
571
|
+
for (const x of selector.nodes) {
|
|
572
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
573
|
+
x.nodes = [
|
|
574
|
+
_postcssselectorparser2.default.tag({
|
|
575
|
+
value: "#n"
|
|
576
|
+
})
|
|
577
|
+
];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
} else if (selector.value === ":where") {
|
|
581
|
+
for (const n of selector.nodes) {
|
|
582
|
+
for (const node of n.nodes) {
|
|
583
|
+
if (node.type === "attribute") {
|
|
584
|
+
node.remove();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (selector.type === "attribute") {
|
|
591
|
+
if (selector.attribute === "hidden") {
|
|
592
|
+
_optionalChain([rule, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
selectors.walk((selector) => {
|
|
597
|
+
if (selector.type === "pseudo") {
|
|
598
|
+
if (selector.value === ":where") {
|
|
599
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
600
|
+
if (res) {
|
|
601
|
+
selector.remove();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
return fallbackRemove;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/plugins/post.ts
|
|
611
|
+
var OklabSuffix = "in oklab";
|
|
612
|
+
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
613
|
+
isMainChunk: true
|
|
614
|
+
}) => {
|
|
615
|
+
const { customRuleCallback, isMainChunk } = options;
|
|
616
|
+
const p = {
|
|
617
|
+
postcssPlugin
|
|
618
|
+
};
|
|
619
|
+
if (isMainChunk) {
|
|
620
|
+
p.OnceExit = (root) => {
|
|
621
|
+
root.walkRules((rule) => {
|
|
622
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
623
|
+
updateSelector: true,
|
|
624
|
+
lossless: false
|
|
625
|
+
});
|
|
626
|
+
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
627
|
+
rule.remove();
|
|
628
|
+
}
|
|
629
|
+
rule.walkDecls((decl) => {
|
|
630
|
+
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
631
|
+
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
if (typeof customRuleCallback === "function") {
|
|
638
|
+
p.Rule = (rule) => {
|
|
639
|
+
customRuleCallback(rule, options);
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
return p;
|
|
643
|
+
};
|
|
644
|
+
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
645
|
+
|
|
547
646
|
// src/plugins/pre.ts
|
|
548
647
|
function isAtMediaHover(atRule) {
|
|
549
648
|
return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
|
|
@@ -587,7 +686,7 @@ function compare(e3, t2) {
|
|
|
587
686
|
return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
|
|
588
687
|
}
|
|
589
688
|
function selectorSpecificity(t2, s) {
|
|
590
|
-
const i = _optionalChain([s, 'optionalAccess',
|
|
689
|
+
const i = _optionalChain([s, 'optionalAccess', _26 => _26.customSpecificity, 'optionalCall', _27 => _27(t2)]);
|
|
591
690
|
if (i) return i;
|
|
592
691
|
if (!t2) return { a: 0, b: 0, c: 0 };
|
|
593
692
|
let c = 0, n = 0, o2 = 0;
|
|
@@ -663,7 +762,7 @@ function selectorSpecificity(t2, s) {
|
|
|
663
762
|
case ":active-view-transition-type":
|
|
664
763
|
return { a: 0, b: 1, c: 0 };
|
|
665
764
|
}
|
|
666
|
-
else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access',
|
|
765
|
+
else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _28 => _28.nodes, 'optionalAccess', _29 => _29.length]) > 0 && t2.nodes.forEach((e3) => {
|
|
667
766
|
const t3 = selectorSpecificity(e3, s);
|
|
668
767
|
c += t3.a, n += t3.b, o2 += t3.c;
|
|
669
768
|
});
|
|
@@ -691,8 +790,8 @@ function alwaysValidSelector(s) {
|
|
|
691
790
|
const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
|
|
692
791
|
let t2 = true;
|
|
693
792
|
return o2.walk((e3) => {
|
|
694
|
-
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',
|
|
695
|
-
if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access',
|
|
793
|
+
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', _30 => _30.nodes, 'optionalAccess', _31 => _31.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
|
|
794
|
+
if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _32 => _32.nodes, 'optionalAccess', _33 => _33.length]) && ":not" === e3.value.toLowerCase()) {
|
|
696
795
|
let s2 = true;
|
|
697
796
|
if (e3.nodes[0].walkCombinators(() => {
|
|
698
797
|
s2 = false;
|
|
@@ -804,8 +903,8 @@ function splitSelectors(o2, t2, n = 0) {
|
|
|
804
903
|
if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
|
|
805
904
|
if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
|
|
806
905
|
if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
|
|
807
|
-
if ("pseudo" === _optionalChain([e3, 'access',
|
|
808
|
-
if ("pseudo" === _optionalChain([e3, 'access',
|
|
906
|
+
if ("pseudo" === _optionalChain([e3, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.parent, 'optionalAccess', _36 => _36.type]) && ":not" === _optionalChain([e3, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.parent, 'optionalAccess', _39 => _39.value, 'optionalAccess', _40 => _40.toLowerCase, 'call', _41 => _41()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
|
|
907
|
+
if ("pseudo" === _optionalChain([e3, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.parent, 'optionalAccess', _44 => _44.type]) && ":has" === _optionalChain([e3, 'access', _45 => _45.parent, 'optionalAccess', _46 => _46.parent, 'optionalAccess', _47 => _47.value, 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()])) return void (e3.value = ":-csstools-matches");
|
|
809
908
|
let o4 = e3.parent;
|
|
810
909
|
for (; o4; ) {
|
|
811
910
|
if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
|
|
@@ -827,7 +926,7 @@ function splitSelectors(o2, t2, n = 0) {
|
|
|
827
926
|
let s = "";
|
|
828
927
|
for (let t3 = 0; t3 < e3.length; t3++) {
|
|
829
928
|
const n2 = e3[t3];
|
|
830
|
-
s += o3.substring(_optionalChain([e3, 'access',
|
|
929
|
+
s += o3.substring(_optionalChain([e3, 'access', _50 => _50[t3 - 1], 'optionalAccess', _51 => _51.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
|
|
831
930
|
}
|
|
832
931
|
c.push(s);
|
|
833
932
|
}), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
|
|
@@ -888,7 +987,7 @@ function getPlugins(options) {
|
|
|
888
987
|
const ctx = createContext();
|
|
889
988
|
options.ctx = ctx;
|
|
890
989
|
const plugins = [
|
|
891
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
990
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _52 => _52.postcssOptions, 'optionalAccess', _53 => _53.plugins]), () => ( [])),
|
|
892
991
|
postcssWeappTailwindcssPrePlugin(options),
|
|
893
992
|
_postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
|
|
894
993
|
];
|
|
@@ -932,7 +1031,7 @@ function styleHandler(rawSource, options) {
|
|
|
932
1031
|
getPlugins(options)
|
|
933
1032
|
).process(
|
|
934
1033
|
rawSource,
|
|
935
|
-
_nullishCoalesce(_optionalChain([options, 'access',
|
|
1034
|
+
_nullishCoalesce(_optionalChain([options, 'access', _54 => _54.postcssOptions, 'optionalAccess', _55 => _55.options]), () => ( {
|
|
936
1035
|
from: void 0
|
|
937
1036
|
}))
|
|
938
1037
|
).async();
|
package/dist/index.mjs
CHANGED
|
@@ -51,180 +51,11 @@ function createContext() {
|
|
|
51
51
|
var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
52
52
|
|
|
53
53
|
// src/selectorParser.ts
|
|
54
|
-
import
|
|
55
|
-
|
|
56
|
-
// src/shared.ts
|
|
57
|
-
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
58
|
-
function internalCssSelectorReplacer(selectors, options = {
|
|
59
|
-
escapeMap: MappingChars2String
|
|
60
|
-
}) {
|
|
61
|
-
const { mangleContext, escapeMap } = options;
|
|
62
|
-
if (mangleContext) {
|
|
63
|
-
selectors = mangleContext.cssHandler(selectors);
|
|
64
|
-
}
|
|
65
|
-
return escape(selectors, {
|
|
66
|
-
map: escapeMap
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function composeIsPseudo(strs) {
|
|
70
|
-
if (typeof strs === "string") {
|
|
71
|
-
return strs;
|
|
72
|
-
}
|
|
73
|
-
if (strs.length > 1) {
|
|
74
|
-
return `:is(${strs.join(",")})`;
|
|
75
|
-
}
|
|
76
|
-
return strs.join("");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/selectorParser.ts
|
|
80
|
-
function createRuleTransform(rule, options) {
|
|
81
|
-
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
82
|
-
const transform = (selectors) => {
|
|
83
|
-
selectors.walk((selector) => {
|
|
84
|
-
if (selector.type === "universal" && cssSelectorReplacement?.universal) {
|
|
85
|
-
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
86
|
-
}
|
|
87
|
-
if (cssRemoveHoverPseudoClass && selector.type === "selector") {
|
|
88
|
-
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
89
|
-
if (node) {
|
|
90
|
-
selector.remove();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (selector.type === "pseudo" && selector.value === ":root" && cssSelectorReplacement?.root) {
|
|
94
|
-
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
95
|
-
}
|
|
96
|
-
if (selector.type === "class") {
|
|
97
|
-
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
98
|
-
escapeMap,
|
|
99
|
-
mangleContext
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if (selectors.length === 0) {
|
|
104
|
-
rule.remove();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return transform;
|
|
108
|
-
}
|
|
109
|
-
function ruleTransformSync(rule, options) {
|
|
110
|
-
const transformer = selectorParser(createRuleTransform(rule, options));
|
|
111
|
-
return transformer.transformSync(rule, {
|
|
112
|
-
lossless: false,
|
|
113
|
-
updateSelector: true
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
117
|
-
let b = false;
|
|
118
|
-
let a = false;
|
|
119
|
-
selectorParser((selectors) => {
|
|
120
|
-
selectors.walkPseudos((s) => {
|
|
121
|
-
if (s.parent?.length === 1) {
|
|
122
|
-
if (/^:?:before$/.test(s.value)) {
|
|
123
|
-
b = true;
|
|
124
|
-
}
|
|
125
|
-
if (/^:?:after$/.test(s.value)) {
|
|
126
|
-
a = true;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}).astSync(node);
|
|
131
|
-
return b && a;
|
|
132
|
-
}
|
|
133
|
-
function getFallbackRemove(rule) {
|
|
134
|
-
const fallbackRemove = selectorParser((selectors) => {
|
|
135
|
-
let maybeImportantId = false;
|
|
136
|
-
selectors.walk((selector, idx) => {
|
|
137
|
-
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
138
|
-
maybeImportantId = true;
|
|
139
|
-
}
|
|
140
|
-
if (selector.type === "universal") {
|
|
141
|
-
selector.parent?.remove();
|
|
142
|
-
}
|
|
143
|
-
if (selector.type === "pseudo") {
|
|
144
|
-
if (selector.value === ":is") {
|
|
145
|
-
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
146
|
-
selector.replaceWith(selector.nodes[0]);
|
|
147
|
-
} else {
|
|
148
|
-
selector.parent?.remove();
|
|
149
|
-
}
|
|
150
|
-
} else if (selector.value === ":not") {
|
|
151
|
-
for (const x of selector.nodes) {
|
|
152
|
-
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
153
|
-
x.nodes = [
|
|
154
|
-
selectorParser.tag({
|
|
155
|
-
value: "#n"
|
|
156
|
-
})
|
|
157
|
-
];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} else if (selector.value === ":where") {
|
|
161
|
-
for (const n of selector.nodes) {
|
|
162
|
-
for (const node of n.nodes) {
|
|
163
|
-
if (node.type === "attribute") {
|
|
164
|
-
node.remove();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (selector.type === "attribute") {
|
|
171
|
-
if (selector.attribute === "hidden") {
|
|
172
|
-
rule?.remove();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
selectors.walk((selector) => {
|
|
177
|
-
if (selector.type === "pseudo") {
|
|
178
|
-
if (selector.value === ":where") {
|
|
179
|
-
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
180
|
-
if (res) {
|
|
181
|
-
selector.remove();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return fallbackRemove;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// src/plugins/post.ts
|
|
191
|
-
var OklabSuffix = "in oklab";
|
|
192
|
-
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
193
|
-
isMainChunk: true
|
|
194
|
-
}) => {
|
|
195
|
-
const { customRuleCallback, isMainChunk } = options;
|
|
196
|
-
const p = {
|
|
197
|
-
postcssPlugin
|
|
198
|
-
};
|
|
199
|
-
if (isMainChunk) {
|
|
200
|
-
p.OnceExit = (root) => {
|
|
201
|
-
root.walkRules((rule) => {
|
|
202
|
-
getFallbackRemove(rule).transformSync(rule, {
|
|
203
|
-
updateSelector: true,
|
|
204
|
-
lossless: false
|
|
205
|
-
});
|
|
206
|
-
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
207
|
-
rule.remove();
|
|
208
|
-
}
|
|
209
|
-
rule.walkDecls((decl) => {
|
|
210
|
-
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
211
|
-
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
if (typeof customRuleCallback === "function") {
|
|
218
|
-
p.Rule = (rule) => {
|
|
219
|
-
customRuleCallback(rule, options);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return p;
|
|
223
|
-
};
|
|
224
|
-
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
54
|
+
import psp3 from "postcss-selector-parser";
|
|
225
55
|
|
|
226
56
|
// src/mp.ts
|
|
227
57
|
import { Declaration, Rule } from "postcss";
|
|
58
|
+
import psp2 from "postcss-selector-parser";
|
|
228
59
|
|
|
229
60
|
// src/cssVars.ts
|
|
230
61
|
var cssVars_default = [
|
|
@@ -434,6 +265,79 @@ var cssVars_default = [
|
|
|
434
265
|
}
|
|
435
266
|
];
|
|
436
267
|
|
|
268
|
+
// src/shared.ts
|
|
269
|
+
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
270
|
+
import psp from "postcss-selector-parser";
|
|
271
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
272
|
+
escapeMap: MappingChars2String
|
|
273
|
+
}) {
|
|
274
|
+
const { mangleContext, escapeMap } = options;
|
|
275
|
+
if (mangleContext) {
|
|
276
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
277
|
+
}
|
|
278
|
+
return escape(selectors, {
|
|
279
|
+
map: escapeMap
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function composeIsPseudoAst(strs) {
|
|
283
|
+
if (typeof strs === "string") {
|
|
284
|
+
return [
|
|
285
|
+
psp.tag({
|
|
286
|
+
value: strs
|
|
287
|
+
}),
|
|
288
|
+
psp.combinator({
|
|
289
|
+
value: "+"
|
|
290
|
+
}),
|
|
291
|
+
psp.tag({
|
|
292
|
+
value: strs
|
|
293
|
+
})
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
if (strs.length > 1) {
|
|
297
|
+
return [
|
|
298
|
+
psp.pseudo({
|
|
299
|
+
value: ":is",
|
|
300
|
+
nodes: strs.map(
|
|
301
|
+
(str) => psp.tag({
|
|
302
|
+
value: str
|
|
303
|
+
})
|
|
304
|
+
)
|
|
305
|
+
}),
|
|
306
|
+
psp.combinator({
|
|
307
|
+
value: "+"
|
|
308
|
+
}),
|
|
309
|
+
psp.pseudo({
|
|
310
|
+
value: ":is",
|
|
311
|
+
nodes: strs.map(
|
|
312
|
+
(str) => psp.tag({
|
|
313
|
+
value: str
|
|
314
|
+
})
|
|
315
|
+
)
|
|
316
|
+
})
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
return [
|
|
320
|
+
psp.tag({
|
|
321
|
+
value: strs[0]
|
|
322
|
+
}),
|
|
323
|
+
psp.combinator({
|
|
324
|
+
value: "+"
|
|
325
|
+
}),
|
|
326
|
+
psp.tag({
|
|
327
|
+
value: strs[0]
|
|
328
|
+
})
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
function composeIsPseudo(strs) {
|
|
332
|
+
if (typeof strs === "string") {
|
|
333
|
+
return strs;
|
|
334
|
+
}
|
|
335
|
+
if (strs.length > 1) {
|
|
336
|
+
return `:is(${strs.join(",")})`;
|
|
337
|
+
}
|
|
338
|
+
return strs.join("");
|
|
339
|
+
}
|
|
340
|
+
|
|
437
341
|
// src/mp.ts
|
|
438
342
|
var initialNodes = cssVars_default.map((x) => {
|
|
439
343
|
return new Declaration({
|
|
@@ -509,19 +413,22 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
509
413
|
}
|
|
510
414
|
return selectors;
|
|
511
415
|
}
|
|
512
|
-
function
|
|
513
|
-
let childCombinatorReplaceValue =
|
|
416
|
+
function getCombinatorSelectorAst(options) {
|
|
417
|
+
let childCombinatorReplaceValue = [
|
|
418
|
+
psp2.tag({ value: "view" }),
|
|
419
|
+
psp2.combinator({ value: "+" }),
|
|
420
|
+
psp2.tag({ value: "view" })
|
|
421
|
+
];
|
|
422
|
+
const { cssChildCombinatorReplaceValue } = options;
|
|
514
423
|
if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
515
|
-
|
|
516
|
-
childCombinatorReplaceValue = `${x} + ${x}`;
|
|
424
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
517
425
|
} else if (typeof cssChildCombinatorReplaceValue === "string") {
|
|
518
|
-
childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
|
|
426
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
519
427
|
}
|
|
520
|
-
return
|
|
428
|
+
return childCombinatorReplaceValue;
|
|
521
429
|
}
|
|
522
430
|
function commonChunkPreflight(node, options) {
|
|
523
|
-
const { ctx,
|
|
524
|
-
node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
|
|
431
|
+
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
525
432
|
if (testIfVariablesScope(node)) {
|
|
526
433
|
ctx?.markVariablesScope(node);
|
|
527
434
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
@@ -544,6 +451,198 @@ function commonChunkPreflight(node, options) {
|
|
|
544
451
|
}
|
|
545
452
|
}
|
|
546
453
|
|
|
454
|
+
// src/selectorParser.ts
|
|
455
|
+
function createRuleTransform(rule, options) {
|
|
456
|
+
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
457
|
+
const transform = (selectors) => {
|
|
458
|
+
selectors.walk((selector, index) => {
|
|
459
|
+
if (selector.type === "universal") {
|
|
460
|
+
if (cssSelectorReplacement?.universal) {
|
|
461
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
462
|
+
}
|
|
463
|
+
} else if (selector.type === "selector") {
|
|
464
|
+
if (cssRemoveHoverPseudoClass) {
|
|
465
|
+
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
466
|
+
if (node) {
|
|
467
|
+
selector.remove();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else if (selector.type === "pseudo") {
|
|
471
|
+
if (selector.value === ":root" && cssSelectorReplacement?.root) {
|
|
472
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
473
|
+
} else if (selector.value === ":where") {
|
|
474
|
+
if (index === 0 && selector.length === 1) {
|
|
475
|
+
selector.walk((node, idx) => {
|
|
476
|
+
if (idx === 0 && node.type === "class") {
|
|
477
|
+
const nodes = node.parent?.nodes;
|
|
478
|
+
if (nodes) {
|
|
479
|
+
const first = nodes[idx + 1];
|
|
480
|
+
if (first && first.type === "combinator" && first.value === ">") {
|
|
481
|
+
const second = nodes[idx + 2];
|
|
482
|
+
if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
|
|
483
|
+
const ast = getCombinatorSelectorAst(options);
|
|
484
|
+
second.replaceWith(
|
|
485
|
+
...ast
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
selector.replaceWith(...selector.nodes);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} else if (selector.type === "class") {
|
|
496
|
+
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
497
|
+
escapeMap,
|
|
498
|
+
mangleContext
|
|
499
|
+
});
|
|
500
|
+
} else if (selector.type === "combinator") {
|
|
501
|
+
if (selector.value === ">") {
|
|
502
|
+
const nodes = selector.parent?.nodes;
|
|
503
|
+
if (nodes) {
|
|
504
|
+
const first = nodes[index + 1];
|
|
505
|
+
if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
|
|
506
|
+
const second = nodes[index + 2];
|
|
507
|
+
if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
|
|
508
|
+
const third = nodes[index + 3];
|
|
509
|
+
if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
|
|
510
|
+
const ast = getCombinatorSelectorAst(options);
|
|
511
|
+
selector.parent?.nodes.splice(
|
|
512
|
+
index + 1,
|
|
513
|
+
3,
|
|
514
|
+
...ast
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
if (selectors.length === 0) {
|
|
524
|
+
rule.remove();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
return transform;
|
|
528
|
+
}
|
|
529
|
+
function ruleTransformSync(rule, options) {
|
|
530
|
+
const transformer = psp3(createRuleTransform(rule, options));
|
|
531
|
+
return transformer.transformSync(rule, {
|
|
532
|
+
lossless: false,
|
|
533
|
+
updateSelector: true
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
537
|
+
let b = false;
|
|
538
|
+
let a = false;
|
|
539
|
+
psp3((selectors) => {
|
|
540
|
+
selectors.walkPseudos((s) => {
|
|
541
|
+
if (s.parent?.length === 1) {
|
|
542
|
+
if (/^:?:before$/.test(s.value)) {
|
|
543
|
+
b = true;
|
|
544
|
+
}
|
|
545
|
+
if (/^:?:after$/.test(s.value)) {
|
|
546
|
+
a = true;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}).astSync(node);
|
|
551
|
+
return b && a;
|
|
552
|
+
}
|
|
553
|
+
function getFallbackRemove(rule) {
|
|
554
|
+
const fallbackRemove = psp3((selectors) => {
|
|
555
|
+
let maybeImportantId = false;
|
|
556
|
+
selectors.walk((selector, idx) => {
|
|
557
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
558
|
+
maybeImportantId = true;
|
|
559
|
+
}
|
|
560
|
+
if (selector.type === "universal") {
|
|
561
|
+
selector.parent?.remove();
|
|
562
|
+
}
|
|
563
|
+
if (selector.type === "pseudo") {
|
|
564
|
+
if (selector.value === ":is") {
|
|
565
|
+
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
566
|
+
selector.replaceWith(selector.nodes[0]);
|
|
567
|
+
} else {
|
|
568
|
+
selector.parent?.remove();
|
|
569
|
+
}
|
|
570
|
+
} else if (selector.value === ":not") {
|
|
571
|
+
for (const x of selector.nodes) {
|
|
572
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
573
|
+
x.nodes = [
|
|
574
|
+
psp3.tag({
|
|
575
|
+
value: "#n"
|
|
576
|
+
})
|
|
577
|
+
];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
} else if (selector.value === ":where") {
|
|
581
|
+
for (const n of selector.nodes) {
|
|
582
|
+
for (const node of n.nodes) {
|
|
583
|
+
if (node.type === "attribute") {
|
|
584
|
+
node.remove();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (selector.type === "attribute") {
|
|
591
|
+
if (selector.attribute === "hidden") {
|
|
592
|
+
rule?.remove();
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
selectors.walk((selector) => {
|
|
597
|
+
if (selector.type === "pseudo") {
|
|
598
|
+
if (selector.value === ":where") {
|
|
599
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
600
|
+
if (res) {
|
|
601
|
+
selector.remove();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
return fallbackRemove;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/plugins/post.ts
|
|
611
|
+
var OklabSuffix = "in oklab";
|
|
612
|
+
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
613
|
+
isMainChunk: true
|
|
614
|
+
}) => {
|
|
615
|
+
const { customRuleCallback, isMainChunk } = options;
|
|
616
|
+
const p = {
|
|
617
|
+
postcssPlugin
|
|
618
|
+
};
|
|
619
|
+
if (isMainChunk) {
|
|
620
|
+
p.OnceExit = (root) => {
|
|
621
|
+
root.walkRules((rule) => {
|
|
622
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
623
|
+
updateSelector: true,
|
|
624
|
+
lossless: false
|
|
625
|
+
});
|
|
626
|
+
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
627
|
+
rule.remove();
|
|
628
|
+
}
|
|
629
|
+
rule.walkDecls((decl) => {
|
|
630
|
+
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
631
|
+
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
if (typeof customRuleCallback === "function") {
|
|
638
|
+
p.Rule = (rule) => {
|
|
639
|
+
customRuleCallback(rule, options);
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
return p;
|
|
643
|
+
};
|
|
644
|
+
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
645
|
+
|
|
547
646
|
// src/plugins/pre.ts
|
|
548
647
|
function isAtMediaHover(atRule) {
|
|
549
648
|
return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
|