@weapp-tailwindcss/postcss 1.3.0 → 1.3.2-alpha.0
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 +372 -231
- package/dist/index.mjs +367 -226
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./chunk-WAXGOBY2.mjs";
|
|
2
2
|
|
|
3
3
|
// src/handler.ts
|
|
4
|
-
import {
|
|
4
|
+
import { defuOverrideArray as defuOverrideArray3 } from "@weapp-tailwindcss/shared";
|
|
5
5
|
import postcss from "postcss";
|
|
6
6
|
|
|
7
7
|
// src/defaults.ts
|
|
@@ -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
|
});
|
|
95
|
-
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
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 && regExpTest(includeCustomProperties, 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
|
|
|
@@ -1027,14 +1139,40 @@ function createInjectPreflight(options) {
|
|
|
1027
1139
|
}
|
|
1028
1140
|
|
|
1029
1141
|
// src/handler.ts
|
|
1142
|
+
function createProcessOptions(options) {
|
|
1143
|
+
return {
|
|
1144
|
+
from: void 0,
|
|
1145
|
+
...options.postcssOptions?.options ?? {}
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
var pluginCache = /* @__PURE__ */ new WeakMap();
|
|
1149
|
+
var processOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
1150
|
+
var processOptionsSourceCache = /* @__PURE__ */ new WeakMap();
|
|
1151
|
+
function getCachedPlugins(options) {
|
|
1152
|
+
let plugins = pluginCache.get(options);
|
|
1153
|
+
if (!plugins) {
|
|
1154
|
+
plugins = getPlugins(options);
|
|
1155
|
+
pluginCache.set(options, plugins);
|
|
1156
|
+
}
|
|
1157
|
+
return plugins;
|
|
1158
|
+
}
|
|
1159
|
+
function getCachedProcessOptions(options) {
|
|
1160
|
+
const source = options.postcssOptions?.options;
|
|
1161
|
+
let cached = processOptionsCache.get(options);
|
|
1162
|
+
const cachedSource = processOptionsSourceCache.get(options);
|
|
1163
|
+
if (!cached || cachedSource !== source) {
|
|
1164
|
+
cached = createProcessOptions(options);
|
|
1165
|
+
processOptionsCache.set(options, cached);
|
|
1166
|
+
processOptionsSourceCache.set(options, source);
|
|
1167
|
+
}
|
|
1168
|
+
return { ...cached };
|
|
1169
|
+
}
|
|
1030
1170
|
function styleHandler(rawSource, options) {
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
).process(
|
|
1171
|
+
const plugins = getCachedPlugins(options);
|
|
1172
|
+
const processOptions = getCachedProcessOptions(options);
|
|
1173
|
+
return postcss(plugins).process(
|
|
1034
1174
|
rawSource,
|
|
1035
|
-
|
|
1036
|
-
from: void 0
|
|
1037
|
-
})
|
|
1175
|
+
processOptions
|
|
1038
1176
|
).async();
|
|
1039
1177
|
}
|
|
1040
1178
|
function createStyleHandler(options) {
|
|
@@ -1043,10 +1181,13 @@ function createStyleHandler(options) {
|
|
|
1043
1181
|
getDefaultOptions(options)
|
|
1044
1182
|
);
|
|
1045
1183
|
cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
|
|
1184
|
+
getCachedPlugins(cachedOptions);
|
|
1185
|
+
getCachedProcessOptions(cachedOptions);
|
|
1046
1186
|
return (rawSource, opt) => {
|
|
1187
|
+
const resolvedOptions = defuOverrideArray3(opt, cachedOptions);
|
|
1047
1188
|
return styleHandler(
|
|
1048
1189
|
rawSource,
|
|
1049
|
-
|
|
1190
|
+
resolvedOptions
|
|
1050
1191
|
);
|
|
1051
1192
|
};
|
|
1052
1193
|
}
|