@weapp-tailwindcss/postcss 1.0.5 → 1.0.6
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 +276 -291
- package/dist/index.mjs +276 -291
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,17 +28,14 @@ function getDefaultOptions() {
|
|
|
28
28
|
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
29
29
|
var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
|
|
30
30
|
|
|
31
|
-
// src/symbols.ts
|
|
32
|
-
var VariablesScopeSymbol = Symbol("VariablesScope");
|
|
33
|
-
|
|
34
31
|
// src/plugins/ctx.ts
|
|
35
32
|
function createContext() {
|
|
36
33
|
const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
|
|
37
34
|
function isVariablesScope(rule) {
|
|
38
|
-
return variablesScopeWeakMap.get(rule) ===
|
|
35
|
+
return variablesScopeWeakMap.get(rule) === true;
|
|
39
36
|
}
|
|
40
37
|
function markVariablesScope(rule) {
|
|
41
|
-
variablesScopeWeakMap.set(rule,
|
|
38
|
+
variablesScopeWeakMap.set(rule, true);
|
|
42
39
|
}
|
|
43
40
|
return {
|
|
44
41
|
variablesScopeWeakMap,
|
|
@@ -53,8 +50,280 @@ var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
|
53
50
|
// src/selectorParser.ts
|
|
54
51
|
var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
|
|
55
52
|
|
|
56
|
-
// src/
|
|
53
|
+
// src/shared.ts
|
|
54
|
+
var _escape = require('@weapp-core/escape');
|
|
55
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
56
|
+
escapeMap: _escape.MappingChars2String
|
|
57
|
+
}) {
|
|
58
|
+
const { mangleContext, escapeMap } = options;
|
|
59
|
+
if (mangleContext) {
|
|
60
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
61
|
+
}
|
|
62
|
+
return _escape.escape.call(void 0, selectors, {
|
|
63
|
+
map: escapeMap
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function composeIsPseudo(strs) {
|
|
67
|
+
if (typeof strs === "string") {
|
|
68
|
+
return strs;
|
|
69
|
+
}
|
|
70
|
+
if (strs.length > 1) {
|
|
71
|
+
return `:is(${strs.join(",")})`;
|
|
72
|
+
}
|
|
73
|
+
return strs.join("");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/selectorParser.ts
|
|
77
|
+
function mklist(node) {
|
|
78
|
+
return [
|
|
79
|
+
node,
|
|
80
|
+
_postcssselectorparser2.default.combinator({
|
|
81
|
+
value: "+"
|
|
82
|
+
}),
|
|
83
|
+
node.clone()
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
function composeIsPseudoAst(strs) {
|
|
87
|
+
if (typeof strs === "string") {
|
|
88
|
+
return mklist(_postcssselectorparser2.default.tag({
|
|
89
|
+
value: strs
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
if (strs.length > 1) {
|
|
93
|
+
return mklist(_postcssselectorparser2.default.pseudo({
|
|
94
|
+
value: ":is",
|
|
95
|
+
nodes: strs.map(
|
|
96
|
+
(str) => _postcssselectorparser2.default.tag({
|
|
97
|
+
value: str
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
return mklist(_postcssselectorparser2.default.tag({
|
|
103
|
+
value: strs[0]
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
function getCombinatorSelectorAst(options) {
|
|
107
|
+
let childCombinatorReplaceValue = mklist(_postcssselectorparser2.default.tag({ value: "view" }));
|
|
108
|
+
const { cssChildCombinatorReplaceValue } = options;
|
|
109
|
+
if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
110
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
111
|
+
}
|
|
112
|
+
return childCombinatorReplaceValue;
|
|
113
|
+
}
|
|
114
|
+
function createRuleTransform(rule, options) {
|
|
115
|
+
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
116
|
+
const transform = (selectors) => {
|
|
117
|
+
selectors.walk((selector, index) => {
|
|
118
|
+
if (selector.type === "universal") {
|
|
119
|
+
if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
|
|
120
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
121
|
+
}
|
|
122
|
+
} else if (selector.type === "selector") {
|
|
123
|
+
if (cssRemoveHoverPseudoClass) {
|
|
124
|
+
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
125
|
+
if (node) {
|
|
126
|
+
selector.remove();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else if (selector.type === "pseudo") {
|
|
130
|
+
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
|
|
131
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
132
|
+
} else if (selector.value === ":where") {
|
|
133
|
+
if (index === 0 && selector.length === 1) {
|
|
134
|
+
selector.walk((node, idx) => {
|
|
135
|
+
if (idx === 0 && node.type === "class") {
|
|
136
|
+
const nodes = _optionalChain([node, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.nodes]);
|
|
137
|
+
if (nodes) {
|
|
138
|
+
const first = nodes[idx + 1];
|
|
139
|
+
if (first && first.type === "combinator" && first.value === ">") {
|
|
140
|
+
const second = nodes[idx + 2];
|
|
141
|
+
if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
|
|
142
|
+
const ast = getCombinatorSelectorAst(options);
|
|
143
|
+
second.replaceWith(
|
|
144
|
+
...ast
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
selector.replaceWith(...selector.nodes);
|
|
152
|
+
for (const node of rule.nodes) {
|
|
153
|
+
if (node.type === "decl") {
|
|
154
|
+
if (node.prop === "margin-block-start") {
|
|
155
|
+
node.prop = "margin-block-end";
|
|
156
|
+
} else if (node.prop === "margin-block-end") {
|
|
157
|
+
node.prop = "margin-block-start";
|
|
158
|
+
} else if (node.prop === "margin-inline-start") {
|
|
159
|
+
node.prop = "margin-inline-end";
|
|
160
|
+
} else if (node.prop === "margin-inline-end") {
|
|
161
|
+
node.prop = "margin-inline-start";
|
|
162
|
+
} else if (node.prop === "margin-top") {
|
|
163
|
+
node.prop = "margin-bottom";
|
|
164
|
+
} else if (node.prop === "margin-bottom") {
|
|
165
|
+
node.prop = "margin-top";
|
|
166
|
+
} else if (node.prop === "margin-left") {
|
|
167
|
+
node.prop = "margin-right";
|
|
168
|
+
} else if (node.prop === "margin-right") {
|
|
169
|
+
node.prop = "margin-left";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else if (selector.type === "class") {
|
|
176
|
+
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
177
|
+
escapeMap,
|
|
178
|
+
mangleContext
|
|
179
|
+
});
|
|
180
|
+
} else if (selector.type === "combinator") {
|
|
181
|
+
if (selector.value === ">") {
|
|
182
|
+
const nodes = _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
|
|
183
|
+
if (nodes) {
|
|
184
|
+
const first = nodes[index + 1];
|
|
185
|
+
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")) {
|
|
186
|
+
const second = nodes[index + 2];
|
|
187
|
+
if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
|
|
188
|
+
const third = nodes[index + 3];
|
|
189
|
+
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")) {
|
|
190
|
+
const ast = getCombinatorSelectorAst(options);
|
|
191
|
+
_optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes, 'access', _9 => _9.splice, 'call', _10 => _10(
|
|
192
|
+
index + 1,
|
|
193
|
+
3,
|
|
194
|
+
...ast
|
|
195
|
+
)]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (selectors.length === 0) {
|
|
204
|
+
rule.remove();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
return transform;
|
|
208
|
+
}
|
|
209
|
+
function ruleTransformSync(rule, options) {
|
|
210
|
+
const transformer = _postcssselectorparser2.default.call(void 0, createRuleTransform(rule, options));
|
|
211
|
+
return transformer.transformSync(rule, {
|
|
212
|
+
lossless: false,
|
|
213
|
+
updateSelector: true
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
217
|
+
let b = false;
|
|
218
|
+
let a = false;
|
|
219
|
+
_postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
220
|
+
selectors.walkPseudos((s) => {
|
|
221
|
+
if (_optionalChain([s, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.length]) === 1) {
|
|
222
|
+
if (/^:?:before$/.test(s.value)) {
|
|
223
|
+
b = true;
|
|
224
|
+
}
|
|
225
|
+
if (/^:?:after$/.test(s.value)) {
|
|
226
|
+
a = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}).astSync(node);
|
|
231
|
+
return b && a;
|
|
232
|
+
}
|
|
233
|
+
function getFallbackRemove(rule) {
|
|
234
|
+
const fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
235
|
+
let maybeImportantId = false;
|
|
236
|
+
selectors.walk((selector, idx) => {
|
|
237
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
238
|
+
maybeImportantId = true;
|
|
239
|
+
}
|
|
240
|
+
if (selector.type === "universal") {
|
|
241
|
+
_optionalChain([selector, 'access', _13 => _13.parent, 'optionalAccess', _14 => _14.remove, 'call', _15 => _15()]);
|
|
242
|
+
}
|
|
243
|
+
if (selector.type === "pseudo") {
|
|
244
|
+
if (selector.value === ":is") {
|
|
245
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _16 => _16.nodes, 'access', _17 => _17[0], 'optionalAccess', _18 => _18.type]) === "selector") {
|
|
246
|
+
selector.replaceWith(selector.nodes[0]);
|
|
247
|
+
} else {
|
|
248
|
+
_optionalChain([selector, 'access', _19 => _19.parent, 'optionalAccess', _20 => _20.remove, 'call', _21 => _21()]);
|
|
249
|
+
}
|
|
250
|
+
} else if (selector.value === ":not") {
|
|
251
|
+
for (const x of selector.nodes) {
|
|
252
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
253
|
+
x.nodes = [
|
|
254
|
+
_postcssselectorparser2.default.tag({
|
|
255
|
+
value: "#n"
|
|
256
|
+
})
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else if (selector.value === ":where") {
|
|
261
|
+
for (const n of selector.nodes) {
|
|
262
|
+
for (const node of n.nodes) {
|
|
263
|
+
if (node.type === "attribute") {
|
|
264
|
+
node.remove();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (selector.type === "attribute") {
|
|
271
|
+
if (selector.attribute === "hidden") {
|
|
272
|
+
_optionalChain([rule, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
selectors.walk((selector) => {
|
|
277
|
+
if (selector.type === "pseudo") {
|
|
278
|
+
if (selector.value === ":where") {
|
|
279
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
280
|
+
if (res) {
|
|
281
|
+
selector.remove();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
return fallbackRemove;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/plugins/post.ts
|
|
291
|
+
var OklabSuffix = "in oklab";
|
|
292
|
+
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
293
|
+
isMainChunk: true
|
|
294
|
+
}) => {
|
|
295
|
+
const { customRuleCallback, isMainChunk } = options;
|
|
296
|
+
const p = {
|
|
297
|
+
postcssPlugin
|
|
298
|
+
};
|
|
299
|
+
if (isMainChunk) {
|
|
300
|
+
p.OnceExit = (root) => {
|
|
301
|
+
root.walkRules((rule) => {
|
|
302
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
303
|
+
updateSelector: true,
|
|
304
|
+
lossless: false
|
|
305
|
+
});
|
|
306
|
+
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
307
|
+
rule.remove();
|
|
308
|
+
}
|
|
309
|
+
rule.walkDecls((decl) => {
|
|
310
|
+
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
311
|
+
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (typeof customRuleCallback === "function") {
|
|
318
|
+
p.Rule = (rule) => {
|
|
319
|
+
customRuleCallback(rule, options);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return p;
|
|
323
|
+
};
|
|
324
|
+
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
57
325
|
|
|
326
|
+
// src/mp.ts
|
|
58
327
|
|
|
59
328
|
|
|
60
329
|
// src/cssVars.ts
|
|
@@ -265,79 +534,6 @@ var cssVars_default = [
|
|
|
265
534
|
}
|
|
266
535
|
];
|
|
267
536
|
|
|
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
|
-
|
|
341
537
|
// src/mp.ts
|
|
342
538
|
var initialNodes = cssVars_default.map((x) => {
|
|
343
539
|
return new (0, _postcss.Declaration)({
|
|
@@ -345,11 +541,6 @@ var initialNodes = cssVars_default.map((x) => {
|
|
|
345
541
|
value: x.value
|
|
346
542
|
});
|
|
347
543
|
});
|
|
348
|
-
var PATTERNS = [
|
|
349
|
-
/:not\(template\)\s*[~+]\s*:not\(template\)/.source,
|
|
350
|
-
/:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
|
|
351
|
-
].join("|");
|
|
352
|
-
var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
|
|
353
544
|
function testIfVariablesScope(node, count = 2) {
|
|
354
545
|
if (isOnlyBeforeAndAfterPseudoElement(node)) {
|
|
355
546
|
const nodes = node.nodes;
|
|
@@ -413,24 +604,10 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
413
604
|
}
|
|
414
605
|
return selectors;
|
|
415
606
|
}
|
|
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;
|
|
423
|
-
if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
424
|
-
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
425
|
-
} else if (typeof cssChildCombinatorReplaceValue === "string") {
|
|
426
|
-
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
427
|
-
}
|
|
428
|
-
return childCombinatorReplaceValue;
|
|
429
|
-
}
|
|
430
607
|
function commonChunkPreflight(node, options) {
|
|
431
608
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
432
609
|
if (testIfVariablesScope(node)) {
|
|
433
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
610
|
+
_optionalChain([ctx, 'optionalAccess', _24 => _24.markVariablesScope, 'call', _25 => _25(node)]);
|
|
434
611
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
435
612
|
node.before(makePseudoVarRule());
|
|
436
613
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -451,198 +628,6 @@ function commonChunkPreflight(node, options) {
|
|
|
451
628
|
}
|
|
452
629
|
}
|
|
453
630
|
|
|
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
|
-
|
|
646
631
|
// src/plugins/pre.ts
|
|
647
632
|
function isAtMediaHover(atRule) {
|
|
648
633
|
return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
|
package/dist/index.mjs
CHANGED
|
@@ -28,17 +28,14 @@ function getDefaultOptions() {
|
|
|
28
28
|
import postcssPresetEnv from "postcss-preset-env";
|
|
29
29
|
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
30
30
|
|
|
31
|
-
// src/symbols.ts
|
|
32
|
-
var VariablesScopeSymbol = Symbol("VariablesScope");
|
|
33
|
-
|
|
34
31
|
// src/plugins/ctx.ts
|
|
35
32
|
function createContext() {
|
|
36
33
|
const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
|
|
37
34
|
function isVariablesScope(rule) {
|
|
38
|
-
return variablesScopeWeakMap.get(rule) ===
|
|
35
|
+
return variablesScopeWeakMap.get(rule) === true;
|
|
39
36
|
}
|
|
40
37
|
function markVariablesScope(rule) {
|
|
41
|
-
variablesScopeWeakMap.set(rule,
|
|
38
|
+
variablesScopeWeakMap.set(rule, true);
|
|
42
39
|
}
|
|
43
40
|
return {
|
|
44
41
|
variablesScopeWeakMap,
|
|
@@ -51,11 +48,283 @@ function createContext() {
|
|
|
51
48
|
var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
52
49
|
|
|
53
50
|
// src/selectorParser.ts
|
|
54
|
-
import
|
|
51
|
+
import psp from "postcss-selector-parser";
|
|
52
|
+
|
|
53
|
+
// src/shared.ts
|
|
54
|
+
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
55
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
56
|
+
escapeMap: MappingChars2String
|
|
57
|
+
}) {
|
|
58
|
+
const { mangleContext, escapeMap } = options;
|
|
59
|
+
if (mangleContext) {
|
|
60
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
61
|
+
}
|
|
62
|
+
return escape(selectors, {
|
|
63
|
+
map: escapeMap
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function composeIsPseudo(strs) {
|
|
67
|
+
if (typeof strs === "string") {
|
|
68
|
+
return strs;
|
|
69
|
+
}
|
|
70
|
+
if (strs.length > 1) {
|
|
71
|
+
return `:is(${strs.join(",")})`;
|
|
72
|
+
}
|
|
73
|
+
return strs.join("");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/selectorParser.ts
|
|
77
|
+
function mklist(node) {
|
|
78
|
+
return [
|
|
79
|
+
node,
|
|
80
|
+
psp.combinator({
|
|
81
|
+
value: "+"
|
|
82
|
+
}),
|
|
83
|
+
node.clone()
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
function composeIsPseudoAst(strs) {
|
|
87
|
+
if (typeof strs === "string") {
|
|
88
|
+
return mklist(psp.tag({
|
|
89
|
+
value: strs
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
if (strs.length > 1) {
|
|
93
|
+
return mklist(psp.pseudo({
|
|
94
|
+
value: ":is",
|
|
95
|
+
nodes: strs.map(
|
|
96
|
+
(str) => psp.tag({
|
|
97
|
+
value: str
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
return mklist(psp.tag({
|
|
103
|
+
value: strs[0]
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
function getCombinatorSelectorAst(options) {
|
|
107
|
+
let childCombinatorReplaceValue = mklist(psp.tag({ value: "view" }));
|
|
108
|
+
const { cssChildCombinatorReplaceValue } = options;
|
|
109
|
+
if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
110
|
+
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
111
|
+
}
|
|
112
|
+
return childCombinatorReplaceValue;
|
|
113
|
+
}
|
|
114
|
+
function createRuleTransform(rule, options) {
|
|
115
|
+
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
116
|
+
const transform = (selectors) => {
|
|
117
|
+
selectors.walk((selector, index) => {
|
|
118
|
+
if (selector.type === "universal") {
|
|
119
|
+
if (cssSelectorReplacement?.universal) {
|
|
120
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
121
|
+
}
|
|
122
|
+
} else if (selector.type === "selector") {
|
|
123
|
+
if (cssRemoveHoverPseudoClass) {
|
|
124
|
+
const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
|
|
125
|
+
if (node) {
|
|
126
|
+
selector.remove();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else if (selector.type === "pseudo") {
|
|
130
|
+
if (selector.value === ":root" && cssSelectorReplacement?.root) {
|
|
131
|
+
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
132
|
+
} else if (selector.value === ":where") {
|
|
133
|
+
if (index === 0 && selector.length === 1) {
|
|
134
|
+
selector.walk((node, idx) => {
|
|
135
|
+
if (idx === 0 && node.type === "class") {
|
|
136
|
+
const nodes = node.parent?.nodes;
|
|
137
|
+
if (nodes) {
|
|
138
|
+
const first = nodes[idx + 1];
|
|
139
|
+
if (first && first.type === "combinator" && first.value === ">") {
|
|
140
|
+
const second = nodes[idx + 2];
|
|
141
|
+
if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
|
|
142
|
+
const ast = getCombinatorSelectorAst(options);
|
|
143
|
+
second.replaceWith(
|
|
144
|
+
...ast
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
selector.replaceWith(...selector.nodes);
|
|
152
|
+
for (const node of rule.nodes) {
|
|
153
|
+
if (node.type === "decl") {
|
|
154
|
+
if (node.prop === "margin-block-start") {
|
|
155
|
+
node.prop = "margin-block-end";
|
|
156
|
+
} else if (node.prop === "margin-block-end") {
|
|
157
|
+
node.prop = "margin-block-start";
|
|
158
|
+
} else if (node.prop === "margin-inline-start") {
|
|
159
|
+
node.prop = "margin-inline-end";
|
|
160
|
+
} else if (node.prop === "margin-inline-end") {
|
|
161
|
+
node.prop = "margin-inline-start";
|
|
162
|
+
} else if (node.prop === "margin-top") {
|
|
163
|
+
node.prop = "margin-bottom";
|
|
164
|
+
} else if (node.prop === "margin-bottom") {
|
|
165
|
+
node.prop = "margin-top";
|
|
166
|
+
} else if (node.prop === "margin-left") {
|
|
167
|
+
node.prop = "margin-right";
|
|
168
|
+
} else if (node.prop === "margin-right") {
|
|
169
|
+
node.prop = "margin-left";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else if (selector.type === "class") {
|
|
176
|
+
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
177
|
+
escapeMap,
|
|
178
|
+
mangleContext
|
|
179
|
+
});
|
|
180
|
+
} else if (selector.type === "combinator") {
|
|
181
|
+
if (selector.value === ">") {
|
|
182
|
+
const nodes = selector.parent?.nodes;
|
|
183
|
+
if (nodes) {
|
|
184
|
+
const first = nodes[index + 1];
|
|
185
|
+
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")) {
|
|
186
|
+
const second = nodes[index + 2];
|
|
187
|
+
if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
|
|
188
|
+
const third = nodes[index + 3];
|
|
189
|
+
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")) {
|
|
190
|
+
const ast = getCombinatorSelectorAst(options);
|
|
191
|
+
selector.parent?.nodes.splice(
|
|
192
|
+
index + 1,
|
|
193
|
+
3,
|
|
194
|
+
...ast
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (selectors.length === 0) {
|
|
204
|
+
rule.remove();
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
return transform;
|
|
208
|
+
}
|
|
209
|
+
function ruleTransformSync(rule, options) {
|
|
210
|
+
const transformer = psp(createRuleTransform(rule, options));
|
|
211
|
+
return transformer.transformSync(rule, {
|
|
212
|
+
lossless: false,
|
|
213
|
+
updateSelector: true
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
217
|
+
let b = false;
|
|
218
|
+
let a = false;
|
|
219
|
+
psp((selectors) => {
|
|
220
|
+
selectors.walkPseudos((s) => {
|
|
221
|
+
if (s.parent?.length === 1) {
|
|
222
|
+
if (/^:?:before$/.test(s.value)) {
|
|
223
|
+
b = true;
|
|
224
|
+
}
|
|
225
|
+
if (/^:?:after$/.test(s.value)) {
|
|
226
|
+
a = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}).astSync(node);
|
|
231
|
+
return b && a;
|
|
232
|
+
}
|
|
233
|
+
function getFallbackRemove(rule) {
|
|
234
|
+
const fallbackRemove = psp((selectors) => {
|
|
235
|
+
let maybeImportantId = false;
|
|
236
|
+
selectors.walk((selector, idx) => {
|
|
237
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
238
|
+
maybeImportantId = true;
|
|
239
|
+
}
|
|
240
|
+
if (selector.type === "universal") {
|
|
241
|
+
selector.parent?.remove();
|
|
242
|
+
}
|
|
243
|
+
if (selector.type === "pseudo") {
|
|
244
|
+
if (selector.value === ":is") {
|
|
245
|
+
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
246
|
+
selector.replaceWith(selector.nodes[0]);
|
|
247
|
+
} else {
|
|
248
|
+
selector.parent?.remove();
|
|
249
|
+
}
|
|
250
|
+
} else if (selector.value === ":not") {
|
|
251
|
+
for (const x of selector.nodes) {
|
|
252
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
253
|
+
x.nodes = [
|
|
254
|
+
psp.tag({
|
|
255
|
+
value: "#n"
|
|
256
|
+
})
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else if (selector.value === ":where") {
|
|
261
|
+
for (const n of selector.nodes) {
|
|
262
|
+
for (const node of n.nodes) {
|
|
263
|
+
if (node.type === "attribute") {
|
|
264
|
+
node.remove();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (selector.type === "attribute") {
|
|
271
|
+
if (selector.attribute === "hidden") {
|
|
272
|
+
rule?.remove();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
selectors.walk((selector) => {
|
|
277
|
+
if (selector.type === "pseudo") {
|
|
278
|
+
if (selector.value === ":where") {
|
|
279
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
280
|
+
if (res) {
|
|
281
|
+
selector.remove();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
return fallbackRemove;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/plugins/post.ts
|
|
291
|
+
var OklabSuffix = "in oklab";
|
|
292
|
+
var postcssWeappTailwindcssPostPlugin = (options = {
|
|
293
|
+
isMainChunk: true
|
|
294
|
+
}) => {
|
|
295
|
+
const { customRuleCallback, isMainChunk } = options;
|
|
296
|
+
const p = {
|
|
297
|
+
postcssPlugin
|
|
298
|
+
};
|
|
299
|
+
if (isMainChunk) {
|
|
300
|
+
p.OnceExit = (root) => {
|
|
301
|
+
root.walkRules((rule) => {
|
|
302
|
+
getFallbackRemove(rule).transformSync(rule, {
|
|
303
|
+
updateSelector: true,
|
|
304
|
+
lossless: false
|
|
305
|
+
});
|
|
306
|
+
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
307
|
+
rule.remove();
|
|
308
|
+
}
|
|
309
|
+
rule.walkDecls((decl) => {
|
|
310
|
+
if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
|
|
311
|
+
decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (typeof customRuleCallback === "function") {
|
|
318
|
+
p.Rule = (rule) => {
|
|
319
|
+
customRuleCallback(rule, options);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return p;
|
|
323
|
+
};
|
|
324
|
+
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
55
325
|
|
|
56
326
|
// src/mp.ts
|
|
57
327
|
import { Declaration, Rule } from "postcss";
|
|
58
|
-
import psp2 from "postcss-selector-parser";
|
|
59
328
|
|
|
60
329
|
// src/cssVars.ts
|
|
61
330
|
var cssVars_default = [
|
|
@@ -265,79 +534,6 @@ var cssVars_default = [
|
|
|
265
534
|
}
|
|
266
535
|
];
|
|
267
536
|
|
|
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
|
-
|
|
341
537
|
// src/mp.ts
|
|
342
538
|
var initialNodes = cssVars_default.map((x) => {
|
|
343
539
|
return new Declaration({
|
|
@@ -345,11 +541,6 @@ var initialNodes = cssVars_default.map((x) => {
|
|
|
345
541
|
value: x.value
|
|
346
542
|
});
|
|
347
543
|
});
|
|
348
|
-
var PATTERNS = [
|
|
349
|
-
/:not\(template\)\s*[~+]\s*:not\(template\)/.source,
|
|
350
|
-
/:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
|
|
351
|
-
].join("|");
|
|
352
|
-
var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
|
|
353
544
|
function testIfVariablesScope(node, count = 2) {
|
|
354
545
|
if (isOnlyBeforeAndAfterPseudoElement(node)) {
|
|
355
546
|
const nodes = node.nodes;
|
|
@@ -413,20 +604,6 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
413
604
|
}
|
|
414
605
|
return selectors;
|
|
415
606
|
}
|
|
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;
|
|
423
|
-
if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
424
|
-
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
425
|
-
} else if (typeof cssChildCombinatorReplaceValue === "string") {
|
|
426
|
-
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
427
|
-
}
|
|
428
|
-
return childCombinatorReplaceValue;
|
|
429
|
-
}
|
|
430
607
|
function commonChunkPreflight(node, options) {
|
|
431
608
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
432
609
|
if (testIfVariablesScope(node)) {
|
|
@@ -451,198 +628,6 @@ function commonChunkPreflight(node, options) {
|
|
|
451
628
|
}
|
|
452
629
|
}
|
|
453
630
|
|
|
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
|
-
|
|
646
631
|
// src/plugins/pre.ts
|
|
647
632
|
function isAtMediaHover(atRule) {
|
|
648
633
|
return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
|