@weapp-tailwindcss/postcss 1.3.1 → 1.3.2
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 +338 -226
- package/dist/index.mjs +330 -218
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,25 +34,8 @@ function getDefaultOptions(options) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// src/plugins/index.ts
|
|
38
|
-
var _postcsscalc = require('@weapp-tailwindcss/postcss-calc'); var _postcsscalc2 = _interopRequireDefault(_postcsscalc);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// ../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/omit.mjs
|
|
42
|
-
function omit(obj, keys) {
|
|
43
|
-
const result = { ...obj };
|
|
44
|
-
for (let i = 0; i < keys.length; i++) {
|
|
45
|
-
const key = keys[i];
|
|
46
|
-
delete result[key];
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
37
|
// src/plugins/index.ts
|
|
52
38
|
var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
|
|
53
|
-
var _postcsspxtransform = require('postcss-pxtransform'); var _postcsspxtransform2 = _interopRequireDefault(_postcsspxtransform);
|
|
54
|
-
var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
|
|
55
|
-
var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
|
|
56
39
|
|
|
57
40
|
// src/plugins/ctx.ts
|
|
58
41
|
function createContext() {
|
|
@@ -70,40 +53,167 @@ function createContext() {
|
|
|
70
53
|
};
|
|
71
54
|
}
|
|
72
55
|
|
|
73
|
-
// src/plugins/
|
|
56
|
+
// src/plugins/getCalcPlugin.ts
|
|
57
|
+
var _postcsscalc = require('@weapp-tailwindcss/postcss-calc'); var _postcsscalc2 = _interopRequireDefault(_postcsscalc);
|
|
74
58
|
|
|
59
|
+
// ../../node_modules/.pnpm/es-toolkit@1.40.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
60
|
+
function omit(obj, keys) {
|
|
61
|
+
const result = { ...obj };
|
|
62
|
+
for (let i = 0; i < keys.length; i++) {
|
|
63
|
+
const key = keys[i];
|
|
64
|
+
delete result[key];
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
75
68
|
|
|
76
|
-
// src/
|
|
77
|
-
|
|
69
|
+
// src/plugins/getCalcPlugin.ts
|
|
70
|
+
function getCalcPlugin(options) {
|
|
71
|
+
if (!options.cssCalc) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const calcOptions = Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {};
|
|
75
|
+
return _postcsscalc2.default.call(void 0, calcOptions);
|
|
76
|
+
}
|
|
78
77
|
|
|
79
|
-
// src/
|
|
78
|
+
// src/plugins/getCustomPropertyCleaner.ts
|
|
80
79
|
|
|
81
|
-
var
|
|
80
|
+
var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
|
|
81
|
+
function getCustomPropertyCleaner(options) {
|
|
82
|
+
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
83
|
+
if (!includeCustomProperties || includeCustomProperties.length === 0) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
88
|
+
OnceExit(root) {
|
|
89
|
+
root.walkDecls((decl, idx) => {
|
|
90
|
+
if (idx === 0 || !/--/.test(decl.value)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const prevNode = _optionalChain([decl, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes, 'access', _7 => _7[idx - 1]]);
|
|
94
|
+
if (!prevNode || prevNode.prop !== decl.prop) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
|
|
98
|
+
parsed.walk((node) => {
|
|
99
|
+
if (node.type !== "function" || node.value !== "var") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const match = node.nodes.find((x) => {
|
|
103
|
+
return x.type === "word" && _shared.regExpTest.call(void 0, includeCustomProperties, x.value);
|
|
104
|
+
});
|
|
105
|
+
if (match) {
|
|
106
|
+
decl.remove();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
82
113
|
|
|
83
|
-
// src/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
// src/plugins/getPxTransformPlugin.ts
|
|
115
|
+
|
|
116
|
+
var _postcsspxtransform = require('postcss-pxtransform'); var _postcsspxtransform2 = _interopRequireDefault(_postcsspxtransform);
|
|
117
|
+
var defaultPxTransformOptions = {
|
|
118
|
+
platform: "weapp",
|
|
119
|
+
unitPrecision: 5,
|
|
120
|
+
propList: ["*"],
|
|
121
|
+
selectorBlackList: [],
|
|
122
|
+
replace: true,
|
|
123
|
+
mediaQuery: false,
|
|
124
|
+
minPixelValue: 0,
|
|
125
|
+
designWidth: 750,
|
|
126
|
+
deviceRatio: {
|
|
127
|
+
375: 2,
|
|
128
|
+
640: 2.34 / 2,
|
|
129
|
+
750: 1,
|
|
130
|
+
828: 1.81 / 2
|
|
91
131
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
};
|
|
133
|
+
function getPxTransformPlugin(options) {
|
|
134
|
+
if (!options.px2rpx) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const userOptions = typeof options.px2rpx === "object" ? options.px2rpx : {};
|
|
138
|
+
return _postcsspxtransform2.default.call(void 0,
|
|
139
|
+
_shared.defuOverrideArray.call(void 0,
|
|
140
|
+
userOptions,
|
|
141
|
+
defaultPxTransformOptions
|
|
142
|
+
)
|
|
143
|
+
);
|
|
95
144
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
145
|
+
|
|
146
|
+
// src/plugins/getRemTransformPlugin.ts
|
|
147
|
+
|
|
148
|
+
var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
|
|
149
|
+
var defaultRemOptions = {
|
|
150
|
+
rootValue: 32,
|
|
151
|
+
propList: ["*"],
|
|
152
|
+
transformUnit: "rpx"
|
|
153
|
+
};
|
|
154
|
+
var defaultStage = {
|
|
155
|
+
processorStage: "OnceExit"
|
|
156
|
+
};
|
|
157
|
+
function getRemTransformPlugin(options) {
|
|
158
|
+
if (!options.rem2rpx) {
|
|
159
|
+
return null;
|
|
99
160
|
}
|
|
100
|
-
|
|
101
|
-
|
|
161
|
+
const userOptions = typeof options.rem2rpx === "object" ? options.rem2rpx : defaultRemOptions;
|
|
162
|
+
const merged = _shared.defuOverrideArray.call(void 0,
|
|
163
|
+
userOptions,
|
|
164
|
+
defaultStage
|
|
165
|
+
);
|
|
166
|
+
return _postcssremtoresponsivepixel2.default.call(void 0, merged);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/plugins/post.ts
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
// src/constants.ts
|
|
173
|
+
var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
174
|
+
|
|
175
|
+
// src/selectorParser/before-after.ts
|
|
176
|
+
var _postcssselectorparser = require('postcss-selector-parser'); var _postcssselectorparser2 = _interopRequireDefault(_postcssselectorparser);
|
|
177
|
+
var beforeAfterStateRef = null;
|
|
178
|
+
var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
179
|
+
const state = beforeAfterStateRef;
|
|
180
|
+
if (!state) {
|
|
181
|
+
return;
|
|
102
182
|
}
|
|
103
|
-
|
|
183
|
+
selectors.walkPseudos((s) => {
|
|
184
|
+
if (_optionalChain([s, 'access', _8 => _8.parent, 'optionalAccess', _9 => _9.length]) === 1) {
|
|
185
|
+
if (/^:?:before$/.test(s.value)) {
|
|
186
|
+
state.before = true;
|
|
187
|
+
}
|
|
188
|
+
if (/^:?:after$/.test(s.value)) {
|
|
189
|
+
state.after = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
195
|
+
const state = {
|
|
196
|
+
before: false,
|
|
197
|
+
after: false
|
|
198
|
+
};
|
|
199
|
+
beforeAfterStateRef = state;
|
|
200
|
+
beforeAfterParser.astSync(node);
|
|
201
|
+
beforeAfterStateRef = null;
|
|
202
|
+
return state.before && state.after;
|
|
104
203
|
}
|
|
105
204
|
|
|
106
|
-
// src/selectorParser.ts
|
|
205
|
+
// src/selectorParser/fallback.ts
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
// src/selectorParser/utils.ts
|
|
209
|
+
|
|
210
|
+
function normalizeTransformOptions(options) {
|
|
211
|
+
return {
|
|
212
|
+
lossless: false,
|
|
213
|
+
updateSelector: true,
|
|
214
|
+
...options
|
|
215
|
+
};
|
|
216
|
+
}
|
|
107
217
|
function mklist(node) {
|
|
108
218
|
return [
|
|
109
219
|
node,
|
|
@@ -141,9 +251,140 @@ function getCombinatorSelectorAst(options) {
|
|
|
141
251
|
}
|
|
142
252
|
return childCombinatorReplaceValue;
|
|
143
253
|
}
|
|
144
|
-
|
|
254
|
+
|
|
255
|
+
// src/selectorParser/fallback.ts
|
|
256
|
+
var fallbackRemoveCache = /* @__PURE__ */ new WeakMap();
|
|
257
|
+
var fallbackDefaultKey = {};
|
|
258
|
+
function getFallbackRemove(_rule, options) {
|
|
259
|
+
const cacheKey = _nullishCoalesce(options, () => ( fallbackDefaultKey));
|
|
260
|
+
let entry = fallbackRemoveCache.get(cacheKey);
|
|
261
|
+
if (!entry) {
|
|
262
|
+
const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _10 => _10.uniAppX]));
|
|
263
|
+
let currentRule;
|
|
264
|
+
const parser = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
265
|
+
const activeRule = currentRule;
|
|
266
|
+
let maybeImportantId = false;
|
|
267
|
+
selectors.walk((selector, idx) => {
|
|
268
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
269
|
+
maybeImportantId = true;
|
|
270
|
+
}
|
|
271
|
+
if (selector.type === "universal") {
|
|
272
|
+
_optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
|
|
273
|
+
} else if (selector.type === "pseudo") {
|
|
274
|
+
if (selector.value === ":is") {
|
|
275
|
+
if (maybeImportantId && _optionalChain([selector, 'access', _14 => _14.nodes, 'access', _15 => _15[0], 'optionalAccess', _16 => _16.type]) === "selector") {
|
|
276
|
+
selector.replaceWith(selector.nodes[0]);
|
|
277
|
+
} else {
|
|
278
|
+
_optionalChain([selector, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.remove, 'call', _19 => _19()]);
|
|
279
|
+
}
|
|
280
|
+
} else if (selector.value === ":not") {
|
|
281
|
+
for (const x of selector.nodes) {
|
|
282
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
283
|
+
x.nodes = [
|
|
284
|
+
_postcssselectorparser2.default.tag({
|
|
285
|
+
value: "#n"
|
|
286
|
+
})
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else if (selector.value === ":where") {
|
|
291
|
+
for (const n of selector.nodes) {
|
|
292
|
+
for (const node of n.nodes) {
|
|
293
|
+
if (node.type === "attribute") {
|
|
294
|
+
node.remove();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} else if (selector.type === "attribute") {
|
|
300
|
+
if (selector.attribute === "hidden") {
|
|
301
|
+
_optionalChain([activeRule, 'optionalAccess', _20 => _20.remove, 'call', _21 => _21()]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
selectors.walk((selector) => {
|
|
306
|
+
if (selector.type === "pseudo") {
|
|
307
|
+
if (selector.value === ":where") {
|
|
308
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
309
|
+
if (res) {
|
|
310
|
+
selector.remove();
|
|
311
|
+
}
|
|
312
|
+
} else if (selector.type === "pseudo") {
|
|
313
|
+
if (uniAppX) {
|
|
314
|
+
selector.remove();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
const rawTransformSync = parser.transformSync.bind(parser);
|
|
321
|
+
const transform = (targetRule) => {
|
|
322
|
+
currentRule = targetRule;
|
|
323
|
+
try {
|
|
324
|
+
rawTransformSync(targetRule, normalizeTransformOptions());
|
|
325
|
+
} finally {
|
|
326
|
+
currentRule = void 0;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
parser.transformSync = ((input, opts) => {
|
|
330
|
+
if (input && typeof input === "object" && "type" in input) {
|
|
331
|
+
const maybeRule = input;
|
|
332
|
+
if (maybeRule.type === "rule") {
|
|
333
|
+
currentRule = input;
|
|
334
|
+
try {
|
|
335
|
+
return rawTransformSync(input, normalizeTransformOptions(opts));
|
|
336
|
+
} finally {
|
|
337
|
+
currentRule = void 0;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return rawTransformSync(input, opts);
|
|
342
|
+
});
|
|
343
|
+
entry = {
|
|
344
|
+
parser,
|
|
345
|
+
transform
|
|
346
|
+
};
|
|
347
|
+
fallbackRemoveCache.set(cacheKey, entry);
|
|
348
|
+
}
|
|
349
|
+
return entry.parser;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/selectorParser/rule-transformer.ts
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
// src/shared.ts
|
|
356
|
+
var _escape = require('@weapp-core/escape');
|
|
357
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
358
|
+
escapeMap: _escape.MappingChars2String
|
|
359
|
+
}) {
|
|
360
|
+
const { mangleContext, escapeMap } = options;
|
|
361
|
+
if (mangleContext) {
|
|
362
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
363
|
+
}
|
|
364
|
+
return _escape.escape.call(void 0, selectors, {
|
|
365
|
+
map: escapeMap
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function composeIsPseudo(strs) {
|
|
369
|
+
if (typeof strs === "string") {
|
|
370
|
+
return strs;
|
|
371
|
+
}
|
|
372
|
+
if (strs.length > 1) {
|
|
373
|
+
return `:is(${strs.join(",")})`;
|
|
374
|
+
}
|
|
375
|
+
return strs.join("");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/selectorParser/rule-transformer.ts
|
|
379
|
+
var ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
380
|
+
function createRuleTransformer(options) {
|
|
381
|
+
let currentRule;
|
|
145
382
|
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
|
|
146
383
|
const transform = (selectors) => {
|
|
384
|
+
const rule = currentRule;
|
|
385
|
+
if (!rule) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
147
388
|
selectors.walk((selector, index) => {
|
|
148
389
|
if (selector.type === "class") {
|
|
149
390
|
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
@@ -151,7 +392,7 @@ function createRuleTransform(rule, options) {
|
|
|
151
392
|
mangleContext
|
|
152
393
|
});
|
|
153
394
|
} else if (selector.type === "universal") {
|
|
154
|
-
if (_optionalChain([cssSelectorReplacement, 'optionalAccess',
|
|
395
|
+
if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _22 => _22.universal])) {
|
|
155
396
|
selector.value = composeIsPseudo(cssSelectorReplacement.universal);
|
|
156
397
|
}
|
|
157
398
|
} else if (selector.type === "selector") {
|
|
@@ -162,7 +403,7 @@ function createRuleTransform(rule, options) {
|
|
|
162
403
|
}
|
|
163
404
|
}
|
|
164
405
|
} else if (selector.type === "pseudo") {
|
|
165
|
-
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess',
|
|
406
|
+
if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _23 => _23.root])) {
|
|
166
407
|
selector.value = composeIsPseudo(cssSelectorReplacement.root);
|
|
167
408
|
} else if (selector.value === ":where") {
|
|
168
409
|
if (uniAppX) {
|
|
@@ -171,7 +412,7 @@ function createRuleTransform(rule, options) {
|
|
|
171
412
|
if (index === 0 && selector.length === 1) {
|
|
172
413
|
selector.walk((node, idx) => {
|
|
173
414
|
if (idx === 0 && node.type === "class") {
|
|
174
|
-
const nodes2 = _optionalChain([node, 'access',
|
|
415
|
+
const nodes2 = _optionalChain([node, 'access', _24 => _24.parent, 'optionalAccess', _25 => _25.nodes]);
|
|
175
416
|
if (nodes2) {
|
|
176
417
|
const first = nodes2[idx + 1];
|
|
177
418
|
if (first && first.type === "combinator" && first.value === ">") {
|
|
@@ -214,7 +455,7 @@ function createRuleTransform(rule, options) {
|
|
|
214
455
|
}
|
|
215
456
|
} else if (selector.type === "combinator") {
|
|
216
457
|
if (selector.value === ">") {
|
|
217
|
-
const nodes2 = _optionalChain([selector, 'access',
|
|
458
|
+
const nodes2 = _optionalChain([selector, 'access', _26 => _26.parent, 'optionalAccess', _27 => _27.nodes]);
|
|
218
459
|
if (nodes2) {
|
|
219
460
|
const first = nodes2[index + 1];
|
|
220
461
|
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")) {
|
|
@@ -223,7 +464,7 @@ function createRuleTransform(rule, options) {
|
|
|
223
464
|
const third = nodes2[index + 3];
|
|
224
465
|
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")) {
|
|
225
466
|
const ast = getCombinatorSelectorAst(options);
|
|
226
|
-
_optionalChain([selector, 'access',
|
|
467
|
+
_optionalChain([selector, 'access', _28 => _28.parent, 'optionalAccess', _29 => _29.nodes, 'access', _30 => _30.splice, 'call', _31 => _31(
|
|
227
468
|
index + 1,
|
|
228
469
|
3,
|
|
229
470
|
...ast
|
|
@@ -252,90 +493,23 @@ function createRuleTransform(rule, options) {
|
|
|
252
493
|
rule.remove();
|
|
253
494
|
}
|
|
254
495
|
};
|
|
255
|
-
|
|
496
|
+
const parser = _postcssselectorparser2.default.call(void 0, transform);
|
|
497
|
+
return (rule) => {
|
|
498
|
+
currentRule = rule;
|
|
499
|
+
try {
|
|
500
|
+
parser.transformSync(rule, normalizeTransformOptions());
|
|
501
|
+
} finally {
|
|
502
|
+
currentRule = void 0;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
256
505
|
}
|
|
257
506
|
function ruleTransformSync(rule, options) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
265
|
-
let b = false;
|
|
266
|
-
let a = false;
|
|
267
|
-
_postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
268
|
-
selectors.walkPseudos((s) => {
|
|
269
|
-
if (_optionalChain([s, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.length]) === 1) {
|
|
270
|
-
if (/^:?:before$/.test(s.value)) {
|
|
271
|
-
b = true;
|
|
272
|
-
}
|
|
273
|
-
if (/^:?:after$/.test(s.value)) {
|
|
274
|
-
a = true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}).astSync(node);
|
|
279
|
-
return b && a;
|
|
280
|
-
}
|
|
281
|
-
function getFallbackRemove(rule, options) {
|
|
282
|
-
const { uniAppX } = _shared.defuOverrideArray.call(void 0, options, {});
|
|
283
|
-
const fallbackRemove = _postcssselectorparser2.default.call(void 0, (selectors) => {
|
|
284
|
-
let maybeImportantId = false;
|
|
285
|
-
selectors.walk((selector, idx) => {
|
|
286
|
-
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
287
|
-
maybeImportantId = true;
|
|
288
|
-
}
|
|
289
|
-
if (selector.type === "universal") {
|
|
290
|
-
_optionalChain([selector, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.remove, 'call', _19 => _19()]);
|
|
291
|
-
} else if (selector.type === "pseudo") {
|
|
292
|
-
if (selector.value === ":is") {
|
|
293
|
-
if (maybeImportantId && _optionalChain([selector, 'access', _20 => _20.nodes, 'access', _21 => _21[0], 'optionalAccess', _22 => _22.type]) === "selector") {
|
|
294
|
-
selector.replaceWith(selector.nodes[0]);
|
|
295
|
-
} else {
|
|
296
|
-
_optionalChain([selector, 'access', _23 => _23.parent, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
|
|
297
|
-
}
|
|
298
|
-
} else if (selector.value === ":not") {
|
|
299
|
-
for (const x of selector.nodes) {
|
|
300
|
-
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
301
|
-
x.nodes = [
|
|
302
|
-
_postcssselectorparser2.default.tag({
|
|
303
|
-
value: "#n"
|
|
304
|
-
})
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} else if (selector.value === ":where") {
|
|
309
|
-
for (const n of selector.nodes) {
|
|
310
|
-
for (const node of n.nodes) {
|
|
311
|
-
if (node.type === "attribute") {
|
|
312
|
-
node.remove();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
} else if (selector.type === "attribute") {
|
|
318
|
-
if (selector.attribute === "hidden") {
|
|
319
|
-
_optionalChain([rule, 'optionalAccess', _26 => _26.remove, 'call', _27 => _27()]);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
selectors.walk((selector) => {
|
|
324
|
-
if (selector.type === "pseudo") {
|
|
325
|
-
if (selector.value === ":where") {
|
|
326
|
-
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
327
|
-
if (res) {
|
|
328
|
-
selector.remove();
|
|
329
|
-
}
|
|
330
|
-
} else if (selector.type === "pseudo") {
|
|
331
|
-
if (uniAppX) {
|
|
332
|
-
selector.remove();
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
return fallbackRemove;
|
|
507
|
+
let transformer = ruleTransformCache.get(options);
|
|
508
|
+
if (!transformer) {
|
|
509
|
+
transformer = createRuleTransformer(options);
|
|
510
|
+
ruleTransformCache.set(options, transformer);
|
|
511
|
+
}
|
|
512
|
+
transformer(rule);
|
|
339
513
|
}
|
|
340
514
|
|
|
341
515
|
// src/plugins/post.ts
|
|
@@ -348,11 +522,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
348
522
|
postcssPlugin
|
|
349
523
|
};
|
|
350
524
|
if (opts.isMainChunk) {
|
|
525
|
+
const fallbackRemove = getFallbackRemove(void 0, opts);
|
|
351
526
|
p.RuleExit = (rule) => {
|
|
352
|
-
|
|
353
|
-
updateSelector: true,
|
|
354
|
-
lossless: false
|
|
355
|
-
});
|
|
527
|
+
fallbackRemove.transformSync(rule);
|
|
356
528
|
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
357
529
|
rule.remove();
|
|
358
530
|
}
|
|
@@ -373,12 +545,12 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
373
545
|
if (opts.cssRemoveProperty && atRule.name === "property") {
|
|
374
546
|
atRule.remove();
|
|
375
547
|
}
|
|
376
|
-
_optionalChain([atRule, 'access',
|
|
548
|
+
_optionalChain([atRule, 'access', _32 => _32.nodes, 'optionalAccess', _33 => _33.length]) === 0 && atRule.remove();
|
|
377
549
|
};
|
|
378
550
|
}
|
|
379
551
|
if (typeof opts.customRuleCallback === "function") {
|
|
380
552
|
p.Rule = (rule) => {
|
|
381
|
-
_optionalChain([opts, 'access',
|
|
553
|
+
_optionalChain([opts, 'access', _34 => _34.customRuleCallback, 'optionalCall', _35 => _35(rule, opts)]);
|
|
382
554
|
};
|
|
383
555
|
}
|
|
384
556
|
return p;
|
|
@@ -819,7 +991,7 @@ function remakeCssVarSelector(selectors, options) {
|
|
|
819
991
|
function commonChunkPreflight(node, options) {
|
|
820
992
|
const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
821
993
|
if (testIfVariablesScope(node)) {
|
|
822
|
-
_optionalChain([ctx, 'optionalAccess',
|
|
994
|
+
_optionalChain([ctx, 'optionalAccess', _36 => _36.markVariablesScope, 'call', _37 => _37(node)]);
|
|
823
995
|
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
824
996
|
node.before(makePseudoVarRule());
|
|
825
997
|
if (typeof cssInjectPreflight === "function") {
|
|
@@ -884,9 +1056,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
884
1056
|
root.walkAtRules((atRule) => {
|
|
885
1057
|
if (atRule.name === "layer") {
|
|
886
1058
|
if (atRule.params === "properties") {
|
|
887
|
-
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access',
|
|
1059
|
+
if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _38 => _38.nodes, 'optionalAccess', _39 => _39.length]) === 0) {
|
|
888
1060
|
layerProperties = atRule;
|
|
889
|
-
} else if (_optionalChain([atRule, 'access',
|
|
1061
|
+
} else if (_optionalChain([atRule, 'access', _40 => _40.first, 'optionalAccess', _41 => _41.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
|
|
890
1062
|
if (layerProperties) {
|
|
891
1063
|
layerProperties.replaceWith(atRule.first.nodes);
|
|
892
1064
|
atRule.remove();
|
|
@@ -898,7 +1070,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
898
1070
|
atRule.replaceWith(atRule.nodes);
|
|
899
1071
|
}
|
|
900
1072
|
} else if (isTailwindcssV4ModernCheck(atRule)) {
|
|
901
|
-
if (_optionalChain([atRule, 'access',
|
|
1073
|
+
if (_optionalChain([atRule, 'access', _42 => _42.first, 'optionalAccess', _43 => _43.type]) === "atrule" && atRule.first.name === "layer") {
|
|
902
1074
|
atRule.replaceWith(atRule.first.nodes);
|
|
903
1075
|
}
|
|
904
1076
|
}
|
|
@@ -914,98 +1086,38 @@ postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
|
914
1086
|
|
|
915
1087
|
// src/plugins/index.ts
|
|
916
1088
|
|
|
917
|
-
function
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
postcssWeappTailwindcssPrePlugin(options)
|
|
923
|
-
].filter((x) => Boolean(x));
|
|
924
|
-
plugins.push(
|
|
925
|
-
// https://preset-env.cssdb.org/
|
|
926
|
-
// https://github.com/csstools/postcss-plugins/tree/main/plugin-packs/postcss-preset-env#readme
|
|
927
|
-
_postcsspresetenv2.default.call(void 0,
|
|
928
|
-
options.cssPresetEnv
|
|
929
|
-
)
|
|
930
|
-
);
|
|
931
|
-
if (options.px2rpx) {
|
|
932
|
-
plugins.push(
|
|
933
|
-
_postcsspxtransform2.default.call(void 0,
|
|
934
|
-
_shared.defuOverrideArray.call(void 0,
|
|
935
|
-
typeof options.px2rpx === "object" ? options.px2rpx : {},
|
|
936
|
-
{
|
|
937
|
-
platform: "weapp",
|
|
938
|
-
unitPrecision: 5,
|
|
939
|
-
propList: ["*"],
|
|
940
|
-
selectorBlackList: [],
|
|
941
|
-
replace: true,
|
|
942
|
-
mediaQuery: false,
|
|
943
|
-
minPixelValue: 0,
|
|
944
|
-
designWidth: 750,
|
|
945
|
-
deviceRatio: {
|
|
946
|
-
375: 2,
|
|
947
|
-
640: 2.34 / 2,
|
|
948
|
-
750: 1,
|
|
949
|
-
828: 1.81 / 2
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
)
|
|
953
|
-
)
|
|
954
|
-
);
|
|
1089
|
+
function normalizePlugins(options) {
|
|
1090
|
+
const plugins = [];
|
|
1091
|
+
const pxPlugin = getPxTransformPlugin(options);
|
|
1092
|
+
if (pxPlugin) {
|
|
1093
|
+
plugins.push(pxPlugin);
|
|
955
1094
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
_shared.defuOverrideArray.call(void 0,
|
|
960
|
-
typeof options.rem2rpx === "object" ? options.rem2rpx : {
|
|
961
|
-
rootValue: 32,
|
|
962
|
-
propList: ["*"],
|
|
963
|
-
transformUnit: "rpx"
|
|
964
|
-
},
|
|
965
|
-
{
|
|
966
|
-
processorStage: "OnceExit"
|
|
967
|
-
}
|
|
968
|
-
)
|
|
969
|
-
)
|
|
970
|
-
);
|
|
1095
|
+
const remPlugin = getRemTransformPlugin(options);
|
|
1096
|
+
if (remPlugin) {
|
|
1097
|
+
plugins.push(remPlugin);
|
|
971
1098
|
}
|
|
972
|
-
const
|
|
973
|
-
if (
|
|
974
|
-
plugins.push(
|
|
975
|
-
// 核心在 OnceExit 的时候去执行的
|
|
976
|
-
_postcsscalc2.default.call(void 0,
|
|
977
|
-
Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {}
|
|
978
|
-
)
|
|
979
|
-
);
|
|
1099
|
+
const calcPlugin = getCalcPlugin(options);
|
|
1100
|
+
if (calcPlugin) {
|
|
1101
|
+
plugins.push(calcPlugin);
|
|
980
1102
|
}
|
|
981
|
-
|
|
982
|
-
if (
|
|
983
|
-
plugins.push(
|
|
984
|
-
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
985
|
-
OnceExit(root) {
|
|
986
|
-
root.walkDecls((decl, idx) => {
|
|
987
|
-
if (idx > 0 && /--/.test(decl.value)) {
|
|
988
|
-
const prevNode = _optionalChain([decl, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.nodes, 'access', _44 => _44[idx - 1]]);
|
|
989
|
-
if (prevNode && prevNode.prop === decl.prop) {
|
|
990
|
-
const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
|
|
991
|
-
parsed.walk((node) => {
|
|
992
|
-
if (node.type === "function" && node.value === "var") {
|
|
993
|
-
const item = node.nodes.find((x) => {
|
|
994
|
-
return x.type === "word" && _shared.regExpTest.call(void 0, includeCustomProperties, x.value);
|
|
995
|
-
});
|
|
996
|
-
if (item) {
|
|
997
|
-
decl.remove();
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1103
|
+
const customPropertyCleaner = getCustomPropertyCleaner(options);
|
|
1104
|
+
if (customPropertyCleaner) {
|
|
1105
|
+
plugins.push(customPropertyCleaner);
|
|
1006
1106
|
}
|
|
1007
1107
|
return plugins;
|
|
1008
1108
|
}
|
|
1109
|
+
function getPlugins(options) {
|
|
1110
|
+
const ctx = createContext();
|
|
1111
|
+
options.ctx = ctx;
|
|
1112
|
+
const plugins = [
|
|
1113
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _44 => _44.postcssOptions, 'optionalAccess', _45 => _45.plugins]), () => ( [])),
|
|
1114
|
+
postcssWeappTailwindcssPrePlugin(options),
|
|
1115
|
+
_postcsspresetenv2.default.call(void 0, options.cssPresetEnv),
|
|
1116
|
+
...normalizePlugins(options),
|
|
1117
|
+
postcssWeappTailwindcssPostPlugin(options)
|
|
1118
|
+
].filter(Boolean);
|
|
1119
|
+
return plugins;
|
|
1120
|
+
}
|
|
1009
1121
|
|
|
1010
1122
|
// src/preflight.ts
|
|
1011
1123
|
function createInjectPreflight(options) {
|
|
@@ -1030,7 +1142,7 @@ function createInjectPreflight(options) {
|
|
|
1030
1142
|
function createProcessOptions(options) {
|
|
1031
1143
|
return {
|
|
1032
1144
|
from: void 0,
|
|
1033
|
-
..._nullishCoalesce(_optionalChain([options, 'access',
|
|
1145
|
+
..._nullishCoalesce(_optionalChain([options, 'access', _46 => _46.postcssOptions, 'optionalAccess', _47 => _47.options]), () => ( {}))
|
|
1034
1146
|
};
|
|
1035
1147
|
}
|
|
1036
1148
|
var pluginCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1045,7 +1157,7 @@ function getCachedPlugins(options) {
|
|
|
1045
1157
|
return plugins;
|
|
1046
1158
|
}
|
|
1047
1159
|
function getCachedProcessOptions(options) {
|
|
1048
|
-
const source = _optionalChain([options, 'access',
|
|
1160
|
+
const source = _optionalChain([options, 'access', _48 => _48.postcssOptions, 'optionalAccess', _49 => _49.options]);
|
|
1049
1161
|
let cached = processOptionsCache.get(options);
|
|
1050
1162
|
const cachedSource = processOptionsSourceCache.get(options);
|
|
1051
1163
|
if (!cached || cachedSource !== source) {
|
package/dist/index.mjs
CHANGED
|
@@ -34,25 +34,8 @@ function getDefaultOptions(options) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// src/plugins/index.ts
|
|
38
|
-
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
39
|
-
import { defuOverrideArray as defuOverrideArray2, regExpTest } from "@weapp-tailwindcss/shared";
|
|
40
|
-
|
|
41
|
-
// ../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/omit.mjs
|
|
42
|
-
function omit(obj, keys) {
|
|
43
|
-
const result = { ...obj };
|
|
44
|
-
for (let i = 0; i < keys.length; i++) {
|
|
45
|
-
const key = keys[i];
|
|
46
|
-
delete result[key];
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
37
|
// src/plugins/index.ts
|
|
52
38
|
import postcssPresetEnv from "postcss-preset-env";
|
|
53
|
-
import postcssPxtransform from "postcss-pxtransform";
|
|
54
|
-
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
55
|
-
import valueParser from "postcss-value-parser";
|
|
56
39
|
|
|
57
40
|
// src/plugins/ctx.ts
|
|
58
41
|
function createContext() {
|
|
@@ -70,44 +53,171 @@ function createContext() {
|
|
|
70
53
|
};
|
|
71
54
|
}
|
|
72
55
|
|
|
56
|
+
// src/plugins/getCalcPlugin.ts
|
|
57
|
+
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
58
|
+
|
|
59
|
+
// ../../node_modules/.pnpm/es-toolkit@1.40.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
60
|
+
function omit(obj, keys) {
|
|
61
|
+
const result = { ...obj };
|
|
62
|
+
for (let i = 0; i < keys.length; i++) {
|
|
63
|
+
const key = keys[i];
|
|
64
|
+
delete result[key];
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/plugins/getCalcPlugin.ts
|
|
70
|
+
function getCalcPlugin(options) {
|
|
71
|
+
if (!options.cssCalc) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const calcOptions = Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {};
|
|
75
|
+
return postcssCalc(calcOptions);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/plugins/getCustomPropertyCleaner.ts
|
|
79
|
+
import { regExpTest } from "@weapp-tailwindcss/shared";
|
|
80
|
+
import valueParser from "postcss-value-parser";
|
|
81
|
+
function getCustomPropertyCleaner(options) {
|
|
82
|
+
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
83
|
+
if (!includeCustomProperties || includeCustomProperties.length === 0) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
88
|
+
OnceExit(root) {
|
|
89
|
+
root.walkDecls((decl, idx) => {
|
|
90
|
+
if (idx === 0 || !/--/.test(decl.value)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const prevNode = decl.parent?.nodes[idx - 1];
|
|
94
|
+
if (!prevNode || prevNode.prop !== decl.prop) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const parsed = valueParser(decl.value);
|
|
98
|
+
parsed.walk((node) => {
|
|
99
|
+
if (node.type !== "function" || node.value !== "var") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const match = node.nodes.find((x) => {
|
|
103
|
+
return x.type === "word" && regExpTest(includeCustomProperties, x.value);
|
|
104
|
+
});
|
|
105
|
+
if (match) {
|
|
106
|
+
decl.remove();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/plugins/getPxTransformPlugin.ts
|
|
115
|
+
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
116
|
+
import postcssPxtransform from "postcss-pxtransform";
|
|
117
|
+
var defaultPxTransformOptions = {
|
|
118
|
+
platform: "weapp",
|
|
119
|
+
unitPrecision: 5,
|
|
120
|
+
propList: ["*"],
|
|
121
|
+
selectorBlackList: [],
|
|
122
|
+
replace: true,
|
|
123
|
+
mediaQuery: false,
|
|
124
|
+
minPixelValue: 0,
|
|
125
|
+
designWidth: 750,
|
|
126
|
+
deviceRatio: {
|
|
127
|
+
375: 2,
|
|
128
|
+
640: 2.34 / 2,
|
|
129
|
+
750: 1,
|
|
130
|
+
828: 1.81 / 2
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
function getPxTransformPlugin(options) {
|
|
134
|
+
if (!options.px2rpx) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const userOptions = typeof options.px2rpx === "object" ? options.px2rpx : {};
|
|
138
|
+
return postcssPxtransform(
|
|
139
|
+
defuOverrideArray(
|
|
140
|
+
userOptions,
|
|
141
|
+
defaultPxTransformOptions
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/plugins/getRemTransformPlugin.ts
|
|
147
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
148
|
+
import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
|
|
149
|
+
var defaultRemOptions = {
|
|
150
|
+
rootValue: 32,
|
|
151
|
+
propList: ["*"],
|
|
152
|
+
transformUnit: "rpx"
|
|
153
|
+
};
|
|
154
|
+
var defaultStage = {
|
|
155
|
+
processorStage: "OnceExit"
|
|
156
|
+
};
|
|
157
|
+
function getRemTransformPlugin(options) {
|
|
158
|
+
if (!options.rem2rpx) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const userOptions = typeof options.rem2rpx === "object" ? options.rem2rpx : defaultRemOptions;
|
|
162
|
+
const merged = defuOverrideArray2(
|
|
163
|
+
userOptions,
|
|
164
|
+
defaultStage
|
|
165
|
+
);
|
|
166
|
+
return postcssRem2rpx(merged);
|
|
167
|
+
}
|
|
168
|
+
|
|
73
169
|
// src/plugins/post.ts
|
|
74
170
|
import { defu } from "@weapp-tailwindcss/shared";
|
|
75
171
|
|
|
76
172
|
// src/constants.ts
|
|
77
173
|
var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
|
|
78
174
|
|
|
79
|
-
// src/selectorParser.ts
|
|
80
|
-
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
175
|
+
// src/selectorParser/before-after.ts
|
|
81
176
|
import psp from "postcss-selector-parser";
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}) {
|
|
88
|
-
const { mangleContext, escapeMap } = options;
|
|
89
|
-
if (mangleContext) {
|
|
90
|
-
selectors = mangleContext.cssHandler(selectors);
|
|
177
|
+
var beforeAfterStateRef = null;
|
|
178
|
+
var beforeAfterParser = psp((selectors) => {
|
|
179
|
+
const state = beforeAfterStateRef;
|
|
180
|
+
if (!state) {
|
|
181
|
+
return;
|
|
91
182
|
}
|
|
92
|
-
|
|
93
|
-
|
|
183
|
+
selectors.walkPseudos((s) => {
|
|
184
|
+
if (s.parent?.length === 1) {
|
|
185
|
+
if (/^:?:before$/.test(s.value)) {
|
|
186
|
+
state.before = true;
|
|
187
|
+
}
|
|
188
|
+
if (/^:?:after$/.test(s.value)) {
|
|
189
|
+
state.after = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
94
192
|
});
|
|
193
|
+
});
|
|
194
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
195
|
+
const state = {
|
|
196
|
+
before: false,
|
|
197
|
+
after: false
|
|
198
|
+
};
|
|
199
|
+
beforeAfterStateRef = state;
|
|
200
|
+
beforeAfterParser.astSync(node);
|
|
201
|
+
beforeAfterStateRef = null;
|
|
202
|
+
return state.before && state.after;
|
|
95
203
|
}
|
|
96
|
-
function composeIsPseudo(strs) {
|
|
97
|
-
if (typeof strs === "string") {
|
|
98
|
-
return strs;
|
|
99
|
-
}
|
|
100
|
-
if (strs.length > 1) {
|
|
101
|
-
return `:is(${strs.join(",")})`;
|
|
102
|
-
}
|
|
103
|
-
return strs.join("");
|
|
104
|
-
}
|
|
105
204
|
|
|
106
|
-
// src/selectorParser.ts
|
|
205
|
+
// src/selectorParser/fallback.ts
|
|
206
|
+
import psp3 from "postcss-selector-parser";
|
|
207
|
+
|
|
208
|
+
// src/selectorParser/utils.ts
|
|
209
|
+
import psp2 from "postcss-selector-parser";
|
|
210
|
+
function normalizeTransformOptions(options) {
|
|
211
|
+
return {
|
|
212
|
+
lossless: false,
|
|
213
|
+
updateSelector: true,
|
|
214
|
+
...options
|
|
215
|
+
};
|
|
216
|
+
}
|
|
107
217
|
function mklist(node) {
|
|
108
218
|
return [
|
|
109
219
|
node,
|
|
110
|
-
|
|
220
|
+
psp2.combinator({
|
|
111
221
|
value: "+"
|
|
112
222
|
}),
|
|
113
223
|
node.clone()
|
|
@@ -115,35 +225,166 @@ function mklist(node) {
|
|
|
115
225
|
}
|
|
116
226
|
function composeIsPseudoAst(strs) {
|
|
117
227
|
if (typeof strs === "string") {
|
|
118
|
-
return mklist(
|
|
228
|
+
return mklist(psp2.tag({
|
|
119
229
|
value: strs
|
|
120
230
|
}));
|
|
121
231
|
}
|
|
122
232
|
if (strs.length > 1) {
|
|
123
|
-
return mklist(
|
|
233
|
+
return mklist(psp2.pseudo({
|
|
124
234
|
value: ":is",
|
|
125
235
|
nodes: strs.map(
|
|
126
|
-
(str) =>
|
|
236
|
+
(str) => psp2.tag({
|
|
127
237
|
value: str
|
|
128
238
|
})
|
|
129
239
|
)
|
|
130
240
|
}));
|
|
131
241
|
}
|
|
132
|
-
return mklist(
|
|
242
|
+
return mklist(psp2.tag({
|
|
133
243
|
value: strs[0]
|
|
134
244
|
}));
|
|
135
245
|
}
|
|
136
246
|
function getCombinatorSelectorAst(options) {
|
|
137
|
-
let childCombinatorReplaceValue = mklist(
|
|
247
|
+
let childCombinatorReplaceValue = mklist(psp2.tag({ value: "view" }));
|
|
138
248
|
const { cssChildCombinatorReplaceValue } = options;
|
|
139
249
|
if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
140
250
|
childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
|
|
141
251
|
}
|
|
142
252
|
return childCombinatorReplaceValue;
|
|
143
253
|
}
|
|
144
|
-
|
|
254
|
+
|
|
255
|
+
// src/selectorParser/fallback.ts
|
|
256
|
+
var fallbackRemoveCache = /* @__PURE__ */ new WeakMap();
|
|
257
|
+
var fallbackDefaultKey = {};
|
|
258
|
+
function getFallbackRemove(_rule, options) {
|
|
259
|
+
const cacheKey = options ?? fallbackDefaultKey;
|
|
260
|
+
let entry = fallbackRemoveCache.get(cacheKey);
|
|
261
|
+
if (!entry) {
|
|
262
|
+
const uniAppX = Boolean(options?.uniAppX);
|
|
263
|
+
let currentRule;
|
|
264
|
+
const parser = psp3((selectors) => {
|
|
265
|
+
const activeRule = currentRule;
|
|
266
|
+
let maybeImportantId = false;
|
|
267
|
+
selectors.walk((selector, idx) => {
|
|
268
|
+
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
269
|
+
maybeImportantId = true;
|
|
270
|
+
}
|
|
271
|
+
if (selector.type === "universal") {
|
|
272
|
+
selector.parent?.remove();
|
|
273
|
+
} else if (selector.type === "pseudo") {
|
|
274
|
+
if (selector.value === ":is") {
|
|
275
|
+
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
276
|
+
selector.replaceWith(selector.nodes[0]);
|
|
277
|
+
} else {
|
|
278
|
+
selector.parent?.remove();
|
|
279
|
+
}
|
|
280
|
+
} else if (selector.value === ":not") {
|
|
281
|
+
for (const x of selector.nodes) {
|
|
282
|
+
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
283
|
+
x.nodes = [
|
|
284
|
+
psp3.tag({
|
|
285
|
+
value: "#n"
|
|
286
|
+
})
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else if (selector.value === ":where") {
|
|
291
|
+
for (const n of selector.nodes) {
|
|
292
|
+
for (const node of n.nodes) {
|
|
293
|
+
if (node.type === "attribute") {
|
|
294
|
+
node.remove();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} else if (selector.type === "attribute") {
|
|
300
|
+
if (selector.attribute === "hidden") {
|
|
301
|
+
activeRule?.remove();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
selectors.walk((selector) => {
|
|
306
|
+
if (selector.type === "pseudo") {
|
|
307
|
+
if (selector.value === ":where") {
|
|
308
|
+
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
309
|
+
if (res) {
|
|
310
|
+
selector.remove();
|
|
311
|
+
}
|
|
312
|
+
} else if (selector.type === "pseudo") {
|
|
313
|
+
if (uniAppX) {
|
|
314
|
+
selector.remove();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
const rawTransformSync = parser.transformSync.bind(parser);
|
|
321
|
+
const transform = (targetRule) => {
|
|
322
|
+
currentRule = targetRule;
|
|
323
|
+
try {
|
|
324
|
+
rawTransformSync(targetRule, normalizeTransformOptions());
|
|
325
|
+
} finally {
|
|
326
|
+
currentRule = void 0;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
parser.transformSync = ((input, opts) => {
|
|
330
|
+
if (input && typeof input === "object" && "type" in input) {
|
|
331
|
+
const maybeRule = input;
|
|
332
|
+
if (maybeRule.type === "rule") {
|
|
333
|
+
currentRule = input;
|
|
334
|
+
try {
|
|
335
|
+
return rawTransformSync(input, normalizeTransformOptions(opts));
|
|
336
|
+
} finally {
|
|
337
|
+
currentRule = void 0;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return rawTransformSync(input, opts);
|
|
342
|
+
});
|
|
343
|
+
entry = {
|
|
344
|
+
parser,
|
|
345
|
+
transform
|
|
346
|
+
};
|
|
347
|
+
fallbackRemoveCache.set(cacheKey, entry);
|
|
348
|
+
}
|
|
349
|
+
return entry.parser;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/selectorParser/rule-transformer.ts
|
|
353
|
+
import psp4 from "postcss-selector-parser";
|
|
354
|
+
|
|
355
|
+
// src/shared.ts
|
|
356
|
+
import { escape, MappingChars2String } from "@weapp-core/escape";
|
|
357
|
+
function internalCssSelectorReplacer(selectors, options = {
|
|
358
|
+
escapeMap: MappingChars2String
|
|
359
|
+
}) {
|
|
360
|
+
const { mangleContext, escapeMap } = options;
|
|
361
|
+
if (mangleContext) {
|
|
362
|
+
selectors = mangleContext.cssHandler(selectors);
|
|
363
|
+
}
|
|
364
|
+
return escape(selectors, {
|
|
365
|
+
map: escapeMap
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function composeIsPseudo(strs) {
|
|
369
|
+
if (typeof strs === "string") {
|
|
370
|
+
return strs;
|
|
371
|
+
}
|
|
372
|
+
if (strs.length > 1) {
|
|
373
|
+
return `:is(${strs.join(",")})`;
|
|
374
|
+
}
|
|
375
|
+
return strs.join("");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/selectorParser/rule-transformer.ts
|
|
379
|
+
var ruleTransformCache = /* @__PURE__ */ new WeakMap();
|
|
380
|
+
function createRuleTransformer(options) {
|
|
381
|
+
let currentRule;
|
|
145
382
|
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
|
|
146
383
|
const transform = (selectors) => {
|
|
384
|
+
const rule = currentRule;
|
|
385
|
+
if (!rule) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
147
388
|
selectors.walk((selector, index) => {
|
|
148
389
|
if (selector.type === "class") {
|
|
149
390
|
selector.value = internalCssSelectorReplacer(selector.value, {
|
|
@@ -252,90 +493,23 @@ function createRuleTransform(rule, options) {
|
|
|
252
493
|
rule.remove();
|
|
253
494
|
}
|
|
254
495
|
};
|
|
255
|
-
|
|
496
|
+
const parser = psp4(transform);
|
|
497
|
+
return (rule) => {
|
|
498
|
+
currentRule = rule;
|
|
499
|
+
try {
|
|
500
|
+
parser.transformSync(rule, normalizeTransformOptions());
|
|
501
|
+
} finally {
|
|
502
|
+
currentRule = void 0;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
256
505
|
}
|
|
257
506
|
function ruleTransformSync(rule, options) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
265
|
-
let b = false;
|
|
266
|
-
let a = false;
|
|
267
|
-
psp((selectors) => {
|
|
268
|
-
selectors.walkPseudos((s) => {
|
|
269
|
-
if (s.parent?.length === 1) {
|
|
270
|
-
if (/^:?:before$/.test(s.value)) {
|
|
271
|
-
b = true;
|
|
272
|
-
}
|
|
273
|
-
if (/^:?:after$/.test(s.value)) {
|
|
274
|
-
a = true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}).astSync(node);
|
|
279
|
-
return b && a;
|
|
280
|
-
}
|
|
281
|
-
function getFallbackRemove(rule, options) {
|
|
282
|
-
const { uniAppX } = defuOverrideArray(options, {});
|
|
283
|
-
const fallbackRemove = psp((selectors) => {
|
|
284
|
-
let maybeImportantId = false;
|
|
285
|
-
selectors.walk((selector, idx) => {
|
|
286
|
-
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
|
|
287
|
-
maybeImportantId = true;
|
|
288
|
-
}
|
|
289
|
-
if (selector.type === "universal") {
|
|
290
|
-
selector.parent?.remove();
|
|
291
|
-
} else if (selector.type === "pseudo") {
|
|
292
|
-
if (selector.value === ":is") {
|
|
293
|
-
if (maybeImportantId && selector.nodes[0]?.type === "selector") {
|
|
294
|
-
selector.replaceWith(selector.nodes[0]);
|
|
295
|
-
} else {
|
|
296
|
-
selector.parent?.remove();
|
|
297
|
-
}
|
|
298
|
-
} else if (selector.value === ":not") {
|
|
299
|
-
for (const x of selector.nodes) {
|
|
300
|
-
if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
|
|
301
|
-
x.nodes = [
|
|
302
|
-
psp.tag({
|
|
303
|
-
value: "#n"
|
|
304
|
-
})
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} else if (selector.value === ":where") {
|
|
309
|
-
for (const n of selector.nodes) {
|
|
310
|
-
for (const node of n.nodes) {
|
|
311
|
-
if (node.type === "attribute") {
|
|
312
|
-
node.remove();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
} else if (selector.type === "attribute") {
|
|
318
|
-
if (selector.attribute === "hidden") {
|
|
319
|
-
rule?.remove();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
selectors.walk((selector) => {
|
|
324
|
-
if (selector.type === "pseudo") {
|
|
325
|
-
if (selector.value === ":where") {
|
|
326
|
-
const res = selector.nodes.every((x) => x.nodes.length === 0);
|
|
327
|
-
if (res) {
|
|
328
|
-
selector.remove();
|
|
329
|
-
}
|
|
330
|
-
} else if (selector.type === "pseudo") {
|
|
331
|
-
if (uniAppX) {
|
|
332
|
-
selector.remove();
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
return fallbackRemove;
|
|
507
|
+
let transformer = ruleTransformCache.get(options);
|
|
508
|
+
if (!transformer) {
|
|
509
|
+
transformer = createRuleTransformer(options);
|
|
510
|
+
ruleTransformCache.set(options, transformer);
|
|
511
|
+
}
|
|
512
|
+
transformer(rule);
|
|
339
513
|
}
|
|
340
514
|
|
|
341
515
|
// src/plugins/post.ts
|
|
@@ -348,11 +522,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
348
522
|
postcssPlugin
|
|
349
523
|
};
|
|
350
524
|
if (opts.isMainChunk) {
|
|
525
|
+
const fallbackRemove = getFallbackRemove(void 0, opts);
|
|
351
526
|
p.RuleExit = (rule) => {
|
|
352
|
-
|
|
353
|
-
updateSelector: true,
|
|
354
|
-
lossless: false
|
|
355
|
-
});
|
|
527
|
+
fallbackRemove.transformSync(rule);
|
|
356
528
|
if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
|
|
357
529
|
rule.remove();
|
|
358
530
|
}
|
|
@@ -914,96 +1086,36 @@ postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
|
914
1086
|
|
|
915
1087
|
// src/plugins/index.ts
|
|
916
1088
|
import { default as default2 } from "postcss-rem-to-responsive-pixel";
|
|
1089
|
+
function normalizePlugins(options) {
|
|
1090
|
+
const plugins = [];
|
|
1091
|
+
const pxPlugin = getPxTransformPlugin(options);
|
|
1092
|
+
if (pxPlugin) {
|
|
1093
|
+
plugins.push(pxPlugin);
|
|
1094
|
+
}
|
|
1095
|
+
const remPlugin = getRemTransformPlugin(options);
|
|
1096
|
+
if (remPlugin) {
|
|
1097
|
+
plugins.push(remPlugin);
|
|
1098
|
+
}
|
|
1099
|
+
const calcPlugin = getCalcPlugin(options);
|
|
1100
|
+
if (calcPlugin) {
|
|
1101
|
+
plugins.push(calcPlugin);
|
|
1102
|
+
}
|
|
1103
|
+
const customPropertyCleaner = getCustomPropertyCleaner(options);
|
|
1104
|
+
if (customPropertyCleaner) {
|
|
1105
|
+
plugins.push(customPropertyCleaner);
|
|
1106
|
+
}
|
|
1107
|
+
return plugins;
|
|
1108
|
+
}
|
|
917
1109
|
function getPlugins(options) {
|
|
918
1110
|
const ctx = createContext();
|
|
919
1111
|
options.ctx = ctx;
|
|
920
1112
|
const plugins = [
|
|
921
1113
|
...options.postcssOptions?.plugins ?? [],
|
|
922
|
-
postcssWeappTailwindcssPrePlugin(options)
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
postcssPresetEnv(
|
|
928
|
-
options.cssPresetEnv
|
|
929
|
-
)
|
|
930
|
-
);
|
|
931
|
-
if (options.px2rpx) {
|
|
932
|
-
plugins.push(
|
|
933
|
-
postcssPxtransform(
|
|
934
|
-
defuOverrideArray2(
|
|
935
|
-
typeof options.px2rpx === "object" ? options.px2rpx : {},
|
|
936
|
-
{
|
|
937
|
-
platform: "weapp",
|
|
938
|
-
unitPrecision: 5,
|
|
939
|
-
propList: ["*"],
|
|
940
|
-
selectorBlackList: [],
|
|
941
|
-
replace: true,
|
|
942
|
-
mediaQuery: false,
|
|
943
|
-
minPixelValue: 0,
|
|
944
|
-
designWidth: 750,
|
|
945
|
-
deviceRatio: {
|
|
946
|
-
375: 2,
|
|
947
|
-
640: 2.34 / 2,
|
|
948
|
-
750: 1,
|
|
949
|
-
828: 1.81 / 2
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
)
|
|
953
|
-
)
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
if (options.rem2rpx) {
|
|
957
|
-
plugins.push(
|
|
958
|
-
postcssRem2rpx(
|
|
959
|
-
defuOverrideArray2(
|
|
960
|
-
typeof options.rem2rpx === "object" ? options.rem2rpx : {
|
|
961
|
-
rootValue: 32,
|
|
962
|
-
propList: ["*"],
|
|
963
|
-
transformUnit: "rpx"
|
|
964
|
-
},
|
|
965
|
-
{
|
|
966
|
-
processorStage: "OnceExit"
|
|
967
|
-
}
|
|
968
|
-
)
|
|
969
|
-
)
|
|
970
|
-
);
|
|
971
|
-
}
|
|
972
|
-
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
973
|
-
if (options.cssCalc) {
|
|
974
|
-
plugins.push(
|
|
975
|
-
// 核心在 OnceExit 的时候去执行的
|
|
976
|
-
postcssCalc(
|
|
977
|
-
Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {}
|
|
978
|
-
)
|
|
979
|
-
);
|
|
980
|
-
}
|
|
981
|
-
plugins.push(postcssWeappTailwindcssPostPlugin(options));
|
|
982
|
-
if (includeCustomProperties) {
|
|
983
|
-
plugins.push({
|
|
984
|
-
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
985
|
-
OnceExit(root) {
|
|
986
|
-
root.walkDecls((decl, idx) => {
|
|
987
|
-
if (idx > 0 && /--/.test(decl.value)) {
|
|
988
|
-
const prevNode = decl.parent?.nodes[idx - 1];
|
|
989
|
-
if (prevNode && prevNode.prop === decl.prop) {
|
|
990
|
-
const parsed = valueParser(decl.value);
|
|
991
|
-
parsed.walk((node) => {
|
|
992
|
-
if (node.type === "function" && node.value === "var") {
|
|
993
|
-
const item = node.nodes.find((x) => {
|
|
994
|
-
return x.type === "word" && regExpTest(includeCustomProperties, x.value);
|
|
995
|
-
});
|
|
996
|
-
if (item) {
|
|
997
|
-
decl.remove();
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1114
|
+
postcssWeappTailwindcssPrePlugin(options),
|
|
1115
|
+
postcssPresetEnv(options.cssPresetEnv),
|
|
1116
|
+
...normalizePlugins(options),
|
|
1117
|
+
postcssWeappTailwindcssPostPlugin(options)
|
|
1118
|
+
].filter(Boolean);
|
|
1007
1119
|
return plugins;
|
|
1008
1120
|
}
|
|
1009
1121
|
|