@weapp-tailwindcss/postcss 2.1.6 → 2.2.0-alpha.1
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/chunk-2DNJBRQ3.mjs +64 -0
- package/dist/chunk-2Y3ULRB3.js +64 -0
- package/dist/html-transform.js +4 -61
- package/dist/html-transform.mjs +3 -60
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +426 -84
- package/dist/index.mjs +382 -40
- package/dist/{types-CsRGpZ_r.d.mts → types-DiOShlJF.d.mts} +39 -4
- package/dist/{types-CsRGpZ_r.d.ts → types-DiOShlJF.d.ts} +39 -4
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +8 -5
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
html_transform_default
|
|
3
|
+
} from "./chunk-2DNJBRQ3.mjs";
|
|
1
4
|
import "./chunk-WAXGOBY2.mjs";
|
|
2
5
|
|
|
3
6
|
// src/handler.ts
|
|
4
7
|
import { defuOverrideArray as defuOverrideArray4 } from "@weapp-tailwindcss/shared";
|
|
8
|
+
import { LRUCache } from "lru-cache";
|
|
5
9
|
|
|
6
10
|
// src/compat/uni-app-x.ts
|
|
7
11
|
import postcss from "postcss";
|
|
@@ -132,6 +136,145 @@ function shouldRemoveEmptyRuleForUniAppX(rule, options) {
|
|
|
132
136
|
return isUniAppXEnabled(options) && rule.nodes.length === 0;
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
// src/compat/uni-app-x-uvue.ts
|
|
140
|
+
import selectorParser from "postcss-selector-parser";
|
|
141
|
+
var ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
|
|
142
|
+
var FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
|
|
143
|
+
var IMPORTANT_SUFFIX_RE = /\s*!important$/i;
|
|
144
|
+
function isUniAppXUvueTarget(options) {
|
|
145
|
+
return Boolean(options?.uniAppX) && options?.uniAppXCssTarget === "uvue";
|
|
146
|
+
}
|
|
147
|
+
function normalizeUnsupportedMode(mode) {
|
|
148
|
+
return mode ?? "warn";
|
|
149
|
+
}
|
|
150
|
+
function normalizeValue(value) {
|
|
151
|
+
return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
|
|
152
|
+
}
|
|
153
|
+
function getSourceFile(rule, result) {
|
|
154
|
+
return rule.source?.input.from ?? result.opts.from ?? "unknown source";
|
|
155
|
+
}
|
|
156
|
+
function collectUtilityClassNames(rule) {
|
|
157
|
+
const classNames = /* @__PURE__ */ new Set();
|
|
158
|
+
for (const selector of rule.selectors ?? []) {
|
|
159
|
+
try {
|
|
160
|
+
const ast = selectorParser().astSync(selector);
|
|
161
|
+
ast.walkClasses((node) => {
|
|
162
|
+
if (node.value) {
|
|
163
|
+
classNames.add(node.value);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
} catch {
|
|
167
|
+
for (const match of selector.matchAll(FALLBACK_CLASS_RE)) {
|
|
168
|
+
if (match[1]) {
|
|
169
|
+
classNames.add(match[1].replaceAll("\\", ""));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return [...classNames];
|
|
175
|
+
}
|
|
176
|
+
function hasOnlyClassSelectors(rule) {
|
|
177
|
+
const selectors = rule.selectors ?? [];
|
|
178
|
+
if (selectors.length === 0) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
return selectors.every((selector) => {
|
|
182
|
+
try {
|
|
183
|
+
const ast = selectorParser().astSync(selector);
|
|
184
|
+
return ast.nodes.every((node) => node.nodes.length > 0 && node.nodes.every((child) => child.type === "class"));
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function getUnsupportedDeclarationReason(prop, value) {
|
|
191
|
+
const normalizedProp = prop.trim().toLowerCase();
|
|
192
|
+
const normalizedValue = normalizeValue(value);
|
|
193
|
+
if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) {
|
|
194
|
+
return `${normalizedProp}: ${value}`;
|
|
195
|
+
}
|
|
196
|
+
if (normalizedProp === "min-height" && normalizedValue === "100vh") {
|
|
197
|
+
return `${normalizedProp}: ${value}`;
|
|
198
|
+
}
|
|
199
|
+
if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") {
|
|
200
|
+
return `${normalizedProp}: ${value}`;
|
|
201
|
+
}
|
|
202
|
+
if (normalizedProp === "gap" || normalizedProp === "row-gap" || normalizedProp === "column-gap") {
|
|
203
|
+
return `${normalizedProp}: ${value}`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function reportUnsupportedRule(rule, result, mode, warningCache, reason) {
|
|
207
|
+
if (mode === "silent") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const classNames = collectUtilityClassNames(rule);
|
|
211
|
+
const classLabel = classNames.length > 0 ? classNames.join(", ") : rule.selector;
|
|
212
|
+
const source = getSourceFile(rule, result);
|
|
213
|
+
const message = `uni-app x uvue unsupported utility: ${classLabel} (${reason}) in ${source}`;
|
|
214
|
+
if (mode === "error") {
|
|
215
|
+
throw rule.error(message);
|
|
216
|
+
}
|
|
217
|
+
if (warningCache.has(message)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
warningCache.add(message);
|
|
221
|
+
rule.warn(result, message);
|
|
222
|
+
}
|
|
223
|
+
function applyUniAppXUvueCompatibility(result, options) {
|
|
224
|
+
if (!isUniAppXUvueTarget(options)) {
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
|
|
228
|
+
const warningCache = /* @__PURE__ */ new Set();
|
|
229
|
+
result.root.walkRules((rule) => {
|
|
230
|
+
if (!hasOnlyClassSelectors(rule)) {
|
|
231
|
+
reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
|
|
232
|
+
rule.remove();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
rule.walkDecls((decl) => {
|
|
236
|
+
const reason = getUnsupportedDeclarationReason(decl.prop, decl.value);
|
|
237
|
+
if (!reason) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
reportUnsupportedRule(rule, result, mode, warningCache, reason);
|
|
241
|
+
decl.remove();
|
|
242
|
+
});
|
|
243
|
+
if ((rule.nodes?.length ?? 0) === 0) {
|
|
244
|
+
rule.remove();
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
result.root.walkAtRules((atRule) => {
|
|
248
|
+
if ((atRule.nodes?.length ?? 0) === 0) {
|
|
249
|
+
atRule.remove();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const nextResult = result.root.toResult(result.opts);
|
|
253
|
+
nextResult.messages.push(...result.messages);
|
|
254
|
+
return nextResult;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/content-probe.ts
|
|
258
|
+
var EMPTY_SIGNAL = {
|
|
259
|
+
hasModernColorFunction: false,
|
|
260
|
+
hasPresetEnvFeatures: false
|
|
261
|
+
};
|
|
262
|
+
var MODERN_COLOR_RE = /rgb\w*\s*\([^),][^\s),]*\s[^),][^\s),]*\s[^),][^),/]*\/[^)]+\)/i;
|
|
263
|
+
function probeFeatures(css) {
|
|
264
|
+
if (!css) {
|
|
265
|
+
return { ...EMPTY_SIGNAL };
|
|
266
|
+
}
|
|
267
|
+
const hasModernColorFunction = MODERN_COLOR_RE.test(css);
|
|
268
|
+
const hasPresetEnvFeatures = true;
|
|
269
|
+
return {
|
|
270
|
+
hasModernColorFunction,
|
|
271
|
+
hasPresetEnvFeatures
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function signalToCacheKey(signal) {
|
|
275
|
+
return `signal:${signal.hasPresetEnvFeatures ? 1 : 0},${signal.hasModernColorFunction ? 1 : 0}`;
|
|
276
|
+
}
|
|
277
|
+
|
|
135
278
|
// src/defaults.ts
|
|
136
279
|
function getDefaultOptions(options) {
|
|
137
280
|
return {
|
|
@@ -154,6 +297,7 @@ function getDefaultOptions(options) {
|
|
|
154
297
|
},
|
|
155
298
|
// 支付宝小程序不支持,所以默认关闭
|
|
156
299
|
cssRemoveProperty: true,
|
|
300
|
+
uniAppXUnsupported: "warn",
|
|
157
301
|
// cssRemoveAtSupports: true,
|
|
158
302
|
// cssRemoveAtMedia: true,
|
|
159
303
|
cssSelectorReplacement: {
|
|
@@ -163,9 +307,6 @@ function getDefaultOptions(options) {
|
|
|
163
307
|
};
|
|
164
308
|
}
|
|
165
309
|
|
|
166
|
-
// src/options-resolver.ts
|
|
167
|
-
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
168
|
-
|
|
169
310
|
// src/fingerprint.ts
|
|
170
311
|
function fingerprintOptions(value, state = { map: /* @__PURE__ */ new WeakMap(), counter: 0 }) {
|
|
171
312
|
if (value === null || value === void 0) {
|
|
@@ -197,6 +338,7 @@ function fingerprintOptions(value, state = { map: /* @__PURE__ */ new WeakMap(),
|
|
|
197
338
|
}
|
|
198
339
|
|
|
199
340
|
// src/options-resolver.ts
|
|
341
|
+
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
200
342
|
var BASE_CACHE_KEY = "base";
|
|
201
343
|
var SIMPLE_OVERRIDE_UNSET = "__unset__";
|
|
202
344
|
function getSimpleOverrideCacheKey(options) {
|
|
@@ -213,6 +355,7 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
213
355
|
let cssCalc = SIMPLE_OVERRIDE_UNSET;
|
|
214
356
|
let cssChildCombinatorReplaceValue = SIMPLE_OVERRIDE_UNSET;
|
|
215
357
|
let cssPreflight = SIMPLE_OVERRIDE_UNSET;
|
|
358
|
+
let autoprefixer = SIMPLE_OVERRIDE_UNSET;
|
|
216
359
|
for (const key of Object.keys(options)) {
|
|
217
360
|
const value = options[key];
|
|
218
361
|
switch (key) {
|
|
@@ -294,6 +437,12 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
294
437
|
}
|
|
295
438
|
cssPreflight = "0";
|
|
296
439
|
break;
|
|
440
|
+
case "autoprefixer":
|
|
441
|
+
if (typeof value !== "boolean") {
|
|
442
|
+
return void 0;
|
|
443
|
+
}
|
|
444
|
+
autoprefixer = value ? "1" : "0";
|
|
445
|
+
break;
|
|
297
446
|
default:
|
|
298
447
|
return void 0;
|
|
299
448
|
}
|
|
@@ -312,7 +461,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
312
461
|
unitsToPx,
|
|
313
462
|
cssCalc,
|
|
314
463
|
cssChildCombinatorReplaceValue,
|
|
315
|
-
cssPreflight
|
|
464
|
+
cssPreflight,
|
|
465
|
+
autoprefixer
|
|
316
466
|
].join(":");
|
|
317
467
|
}
|
|
318
468
|
function hasOverrides(options) {
|
|
@@ -387,6 +537,28 @@ import postcss2 from "postcss";
|
|
|
387
537
|
// src/pipeline.ts
|
|
388
538
|
import postcssPresetEnv from "postcss-preset-env";
|
|
389
539
|
|
|
540
|
+
// src/autoprefixer.ts
|
|
541
|
+
import autoprefixerPlugin from "autoprefixer";
|
|
542
|
+
var WEAPP_AUTOPREFIXER_BROWSERS = [
|
|
543
|
+
"iOS >= 8",
|
|
544
|
+
"Android >= 4.4",
|
|
545
|
+
"ChromeAndroid >= 37"
|
|
546
|
+
];
|
|
547
|
+
var AUTOPREFIXER_PLUGIN_NAME = "autoprefixer";
|
|
548
|
+
function isAutoprefixerPlugin(plugin) {
|
|
549
|
+
return plugin?.postcssPlugin === AUTOPREFIXER_PLUGIN_NAME;
|
|
550
|
+
}
|
|
551
|
+
function resolveAutoprefixerPlugin(option) {
|
|
552
|
+
if (option === false) {
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
const userOptions = option === true || option === void 0 ? {} : option;
|
|
556
|
+
return autoprefixerPlugin({
|
|
557
|
+
...userOptions,
|
|
558
|
+
overrideBrowserslist: userOptions.overrideBrowserslist ?? WEAPP_AUTOPREFIXER_BROWSERS
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
390
562
|
// src/plugins/colorFunctionalFallback.ts
|
|
391
563
|
import valueParser from "postcss-value-parser";
|
|
392
564
|
var RGB_FUNCTION_NAME = "rgb";
|
|
@@ -532,7 +704,7 @@ function getCalcDuplicateCleaner(options) {
|
|
|
532
704
|
// src/plugins/getCalcPlugin.ts
|
|
533
705
|
import postcssCalc from "@weapp-tailwindcss/postcss-calc";
|
|
534
706
|
|
|
535
|
-
// ../../node_modules/.pnpm/es-toolkit@1.
|
|
707
|
+
// ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/object/omit.mjs
|
|
536
708
|
function omit(obj, keys) {
|
|
537
709
|
const result = { ...obj };
|
|
538
710
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -667,13 +839,52 @@ function getRemTransformPlugin(options) {
|
|
|
667
839
|
}
|
|
668
840
|
|
|
669
841
|
// src/plugins/getUnitsToPxPlugin.ts
|
|
670
|
-
import
|
|
842
|
+
import postcssUnitConverter, { presets } from "postcss-rule-unit-converter";
|
|
671
843
|
function getUnitsToPxPlugin(options) {
|
|
672
844
|
if (!options.unitsToPx) {
|
|
673
845
|
return null;
|
|
674
846
|
}
|
|
675
847
|
const userOptions = typeof options.unitsToPx === "object" ? options.unitsToPx : void 0;
|
|
676
|
-
|
|
848
|
+
if (userOptions?.disabled || userOptions?.transform === false) {
|
|
849
|
+
return postcssUnitConverter({ disabled: true });
|
|
850
|
+
}
|
|
851
|
+
const presetOptions = {};
|
|
852
|
+
const converterOptions = {
|
|
853
|
+
rules: []
|
|
854
|
+
};
|
|
855
|
+
if (userOptions?.minValue !== void 0) {
|
|
856
|
+
presetOptions.minValue = userOptions.minValue;
|
|
857
|
+
converterOptions.minValue = userOptions.minValue;
|
|
858
|
+
}
|
|
859
|
+
if (userOptions?.to !== void 0) {
|
|
860
|
+
presetOptions.to = userOptions.to;
|
|
861
|
+
}
|
|
862
|
+
if (userOptions?.transform !== void 0) {
|
|
863
|
+
presetOptions.transform = userOptions.transform;
|
|
864
|
+
}
|
|
865
|
+
if (userOptions?.unitMap !== void 0) {
|
|
866
|
+
presetOptions.unitMap = userOptions.unitMap;
|
|
867
|
+
}
|
|
868
|
+
if (userOptions?.exclude !== void 0) {
|
|
869
|
+
converterOptions.exclude = userOptions.exclude;
|
|
870
|
+
}
|
|
871
|
+
if (userOptions?.mediaQuery !== void 0) {
|
|
872
|
+
converterOptions.mediaQuery = userOptions.mediaQuery;
|
|
873
|
+
}
|
|
874
|
+
if (userOptions?.propList !== void 0) {
|
|
875
|
+
converterOptions.propList = userOptions.propList;
|
|
876
|
+
}
|
|
877
|
+
if (userOptions?.replace !== void 0) {
|
|
878
|
+
converterOptions.replace = userOptions.replace;
|
|
879
|
+
}
|
|
880
|
+
if (userOptions?.selectorBlackList !== void 0) {
|
|
881
|
+
converterOptions.selectorBlackList = userOptions.selectorBlackList;
|
|
882
|
+
}
|
|
883
|
+
if (userOptions?.unitPrecision !== void 0) {
|
|
884
|
+
converterOptions.unitPrecision = userOptions.unitPrecision;
|
|
885
|
+
}
|
|
886
|
+
converterOptions.rules = presets.unitsToPx(presetOptions);
|
|
887
|
+
return postcssUnitConverter(converterOptions);
|
|
677
888
|
}
|
|
678
889
|
|
|
679
890
|
// src/plugins/post.ts
|
|
@@ -1822,6 +2033,7 @@ function dedupeDeclarations(rule) {
|
|
|
1822
2033
|
}
|
|
1823
2034
|
|
|
1824
2035
|
// src/plugins/post/specificity-cleaner.ts
|
|
2036
|
+
var FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
1825
2037
|
function normalizeSelectorList(value) {
|
|
1826
2038
|
if (value === void 0 || value === false) {
|
|
1827
2039
|
return [];
|
|
@@ -1836,6 +2048,45 @@ function getSpecificityMatchingName(options) {
|
|
|
1836
2048
|
}
|
|
1837
2049
|
return void 0;
|
|
1838
2050
|
}
|
|
2051
|
+
function replaceFallbackPlaceholder(selector) {
|
|
2052
|
+
let output = selector;
|
|
2053
|
+
for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) {
|
|
2054
|
+
if (output.includes(suffix)) {
|
|
2055
|
+
output = output.split(suffix).join("");
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return output;
|
|
2059
|
+
}
|
|
2060
|
+
function createFallbackPlaceholderReplacer() {
|
|
2061
|
+
return (code) => {
|
|
2062
|
+
let output = code;
|
|
2063
|
+
for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) {
|
|
2064
|
+
if (output.includes(suffix)) {
|
|
2065
|
+
output = output.split(suffix).join("");
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
return output;
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
function createFallbackPlaceholderCleaner() {
|
|
2072
|
+
return (rule) => {
|
|
2073
|
+
if (!rule.selectors || rule.selectors.length === 0) {
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
let changed = false;
|
|
2077
|
+
const next = rule.selectors.map((selector) => {
|
|
2078
|
+
const updated = replaceFallbackPlaceholder(selector);
|
|
2079
|
+
if (updated !== selector) {
|
|
2080
|
+
changed = true;
|
|
2081
|
+
}
|
|
2082
|
+
return updated;
|
|
2083
|
+
});
|
|
2084
|
+
changed && assignRuleSelectors(rule, next, {
|
|
2085
|
+
phase: "post",
|
|
2086
|
+
reason: "clean-fallback-placeholder"
|
|
2087
|
+
});
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
1839
2090
|
function createRootSpecificityCleaner(options) {
|
|
1840
2091
|
const specificityMatchingName = getSpecificityMatchingName(options);
|
|
1841
2092
|
const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
|
|
@@ -1908,6 +2159,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
1908
2159
|
postcssPlugin
|
|
1909
2160
|
};
|
|
1910
2161
|
const cleanRootSpecificity = createRootSpecificityCleaner(opts);
|
|
2162
|
+
const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
|
|
1911
2163
|
const shouldAppendHostSelector = createHostSelectorAppender(opts);
|
|
1912
2164
|
const enableMainChunkTransforms = opts.isMainChunk !== false;
|
|
1913
2165
|
if (enableMainChunkTransforms || cleanRootSpecificity) {
|
|
@@ -1916,6 +2168,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
1916
2168
|
if (enableMainChunkTransforms) {
|
|
1917
2169
|
fallbackRemove?.transformSync(rule);
|
|
1918
2170
|
}
|
|
2171
|
+
cleanFallbackPlaceholder(rule);
|
|
1919
2172
|
cleanRootSpecificity?.(rule);
|
|
1920
2173
|
if (enableMainChunkTransforms) {
|
|
1921
2174
|
if (shouldAppendHostSelector?.(rule)) {
|
|
@@ -2373,7 +2626,29 @@ function createPreparedNode(id, stage, createPlugin) {
|
|
|
2373
2626
|
createPlugin
|
|
2374
2627
|
};
|
|
2375
2628
|
}
|
|
2376
|
-
function
|
|
2629
|
+
function hasUserAutoprefixerPlugin(rawPlugins, plugins) {
|
|
2630
|
+
if (plugins.some((plugin) => isAutoprefixerPlugin(plugin))) {
|
|
2631
|
+
return true;
|
|
2632
|
+
}
|
|
2633
|
+
if (rawPlugins && !Array.isArray(rawPlugins) && typeof rawPlugins === "object") {
|
|
2634
|
+
const autoprefixerEntry = rawPlugins["autoprefixer"];
|
|
2635
|
+
return Boolean(autoprefixerEntry);
|
|
2636
|
+
}
|
|
2637
|
+
return false;
|
|
2638
|
+
}
|
|
2639
|
+
function shouldUseDefaultAutoprefixer(options, userPlugins) {
|
|
2640
|
+
if (options.autoprefixer === false) {
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
if (hasUserAutoprefixerPlugin(options.postcssOptions?.plugins, userPlugins)) {
|
|
2644
|
+
return false;
|
|
2645
|
+
}
|
|
2646
|
+
if (options.autoprefixer === true || typeof options.autoprefixer === "object") {
|
|
2647
|
+
return true;
|
|
2648
|
+
}
|
|
2649
|
+
return options.majorVersion === 4;
|
|
2650
|
+
}
|
|
2651
|
+
function createPreparedNodes(options, signal) {
|
|
2377
2652
|
const preparedNodes = [];
|
|
2378
2653
|
const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
|
|
2379
2654
|
const presetEnvOptions = options.cssPresetEnv;
|
|
@@ -2381,8 +2656,12 @@ function createPreparedNodes(options) {
|
|
|
2381
2656
|
preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
|
|
2382
2657
|
});
|
|
2383
2658
|
preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
|
|
2384
|
-
|
|
2385
|
-
|
|
2659
|
+
if (!signal || signal.hasPresetEnvFeatures) {
|
|
2660
|
+
preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(presetEnvOptions)));
|
|
2661
|
+
}
|
|
2662
|
+
if (!signal || signal.hasModernColorFunction) {
|
|
2663
|
+
preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
|
|
2664
|
+
}
|
|
2386
2665
|
const unitsToPxPlugin = getUnitsToPxPlugin(options);
|
|
2387
2666
|
if (unitsToPxPlugin) {
|
|
2388
2667
|
preparedNodes.push(createPreparedNode("normal:units-to-px", "normal", () => unitsToPxPlugin));
|
|
@@ -2407,12 +2686,18 @@ function createPreparedNodes(options) {
|
|
|
2407
2686
|
if (customPropertyCleaner) {
|
|
2408
2687
|
preparedNodes.push(createPreparedNode("normal:custom-property-cleaner", "normal", () => customPropertyCleaner));
|
|
2409
2688
|
}
|
|
2689
|
+
if (shouldUseDefaultAutoprefixer(options, userPlugins)) {
|
|
2690
|
+
const plugin = resolveAutoprefixerPlugin(options.autoprefixer);
|
|
2691
|
+
if (plugin) {
|
|
2692
|
+
preparedNodes.push(createPreparedNode("normal:autoprefixer", "normal", () => plugin));
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2410
2695
|
preparedNodes.push(createPreparedNode("post:core", "post", () => postcssWeappTailwindcssPostPlugin(options)));
|
|
2411
2696
|
return preparedNodes;
|
|
2412
2697
|
}
|
|
2413
|
-
function createStylePipeline(options) {
|
|
2698
|
+
function createStylePipeline(options, signal) {
|
|
2414
2699
|
options.ctx = createContext();
|
|
2415
|
-
const preparedNodes = createPreparedNodes(options);
|
|
2700
|
+
const preparedNodes = createPreparedNodes(options, signal);
|
|
2416
2701
|
if (preparedNodes.length === 0) {
|
|
2417
2702
|
return {
|
|
2418
2703
|
nodes: [],
|
|
@@ -2504,9 +2789,8 @@ function getSimpleProcessOptionsCacheKey(options) {
|
|
|
2504
2789
|
return parts.join("|");
|
|
2505
2790
|
}
|
|
2506
2791
|
var StyleProcessorCache = class {
|
|
2507
|
-
|
|
2792
|
+
pipelineCacheByKey = /* @__PURE__ */ new Map();
|
|
2508
2793
|
processOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
2509
|
-
processorCache = /* @__PURE__ */ new WeakMap();
|
|
2510
2794
|
processorCacheByKey = /* @__PURE__ */ new Map();
|
|
2511
2795
|
processorKeyCache = /* @__PURE__ */ new WeakMap();
|
|
2512
2796
|
createProcessorCacheKey(options) {
|
|
@@ -2525,11 +2809,26 @@ var StyleProcessorCache = class {
|
|
|
2525
2809
|
}
|
|
2526
2810
|
});
|
|
2527
2811
|
}
|
|
2528
|
-
|
|
2529
|
-
|
|
2812
|
+
/**
|
|
2813
|
+
* 构建包含信号的复合缓存键
|
|
2814
|
+
*/
|
|
2815
|
+
createCompositeCacheKey(optionsFingerprint, signal) {
|
|
2816
|
+
if (!signal) {
|
|
2817
|
+
return optionsFingerprint;
|
|
2818
|
+
}
|
|
2819
|
+
return `${optionsFingerprint}|${signalToCacheKey(signal)}`;
|
|
2820
|
+
}
|
|
2821
|
+
getPipeline(options, signal) {
|
|
2822
|
+
let optionsKey = this.processorKeyCache.get(options);
|
|
2823
|
+
if (!optionsKey) {
|
|
2824
|
+
optionsKey = this.createProcessorCacheKey(options);
|
|
2825
|
+
this.processorKeyCache.set(options, optionsKey);
|
|
2826
|
+
}
|
|
2827
|
+
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
2828
|
+
let pipeline = this.pipelineCacheByKey.get(compositeKey);
|
|
2530
2829
|
if (!pipeline) {
|
|
2531
|
-
pipeline = createStylePipeline(options);
|
|
2532
|
-
this.
|
|
2830
|
+
pipeline = createStylePipeline(options, signal);
|
|
2831
|
+
this.pipelineCacheByKey.set(compositeKey, pipeline);
|
|
2533
2832
|
}
|
|
2534
2833
|
return pipeline;
|
|
2535
2834
|
}
|
|
@@ -2544,27 +2843,33 @@ var StyleProcessorCache = class {
|
|
|
2544
2843
|
}
|
|
2545
2844
|
return { ...cached.value };
|
|
2546
2845
|
}
|
|
2547
|
-
getProcessor(options) {
|
|
2548
|
-
let
|
|
2846
|
+
getProcessor(options, signal) {
|
|
2847
|
+
let optionsKey = this.processorKeyCache.get(options);
|
|
2848
|
+
if (!optionsKey) {
|
|
2849
|
+
optionsKey = this.createProcessorCacheKey(options);
|
|
2850
|
+
this.processorKeyCache.set(options, optionsKey);
|
|
2851
|
+
}
|
|
2852
|
+
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
2853
|
+
let processor = this.processorCacheByKey.get(compositeKey);
|
|
2549
2854
|
if (!processor) {
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
this.processorKeyCache.set(options, cacheKey);
|
|
2554
|
-
}
|
|
2555
|
-
processor = this.processorCacheByKey.get(cacheKey);
|
|
2556
|
-
if (!processor) {
|
|
2557
|
-
const pipeline = this.getPipeline(options);
|
|
2558
|
-
processor = postcss2(pipeline.plugins);
|
|
2559
|
-
this.processorCacheByKey.set(cacheKey, processor);
|
|
2560
|
-
}
|
|
2561
|
-
this.processorCache.set(options, processor);
|
|
2855
|
+
const pipeline = this.getPipeline(options, signal);
|
|
2856
|
+
processor = postcss2(pipeline.plugins);
|
|
2857
|
+
this.processorCacheByKey.set(compositeKey, processor);
|
|
2562
2858
|
}
|
|
2563
2859
|
return processor;
|
|
2564
2860
|
}
|
|
2565
2861
|
};
|
|
2566
2862
|
|
|
2567
2863
|
// src/handler.ts
|
|
2864
|
+
var CSS_RESULT_CACHE_MAX = 256;
|
|
2865
|
+
function simpleHash(str) {
|
|
2866
|
+
let hash = 2166136261 | 0;
|
|
2867
|
+
for (let i = 0; i < str.length; i++) {
|
|
2868
|
+
hash ^= str.charCodeAt(i);
|
|
2869
|
+
hash = hash * 16777619 | 0;
|
|
2870
|
+
}
|
|
2871
|
+
return (hash >>> 0).toString(36);
|
|
2872
|
+
}
|
|
2568
2873
|
function createStyleHandler(options) {
|
|
2569
2874
|
const cachedOptions = defuOverrideArray4(
|
|
2570
2875
|
options,
|
|
@@ -2572,28 +2877,65 @@ function createStyleHandler(options) {
|
|
|
2572
2877
|
);
|
|
2573
2878
|
cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
|
|
2574
2879
|
const resolver = createOptionsResolver(cachedOptions);
|
|
2575
|
-
const
|
|
2880
|
+
const processorCache = new StyleProcessorCache();
|
|
2576
2881
|
const base = resolver.resolve();
|
|
2577
|
-
|
|
2578
|
-
|
|
2882
|
+
processorCache.getProcessor(base);
|
|
2883
|
+
processorCache.getProcessOptions(base);
|
|
2884
|
+
const optionsFingerprintCache = /* @__PURE__ */ new WeakMap();
|
|
2885
|
+
function getOptionsFingerprint(opts) {
|
|
2886
|
+
const cached = optionsFingerprintCache.get(opts);
|
|
2887
|
+
if (cached) {
|
|
2888
|
+
return cached;
|
|
2889
|
+
}
|
|
2890
|
+
const fp = fingerprintOptions(opts);
|
|
2891
|
+
optionsFingerprintCache.set(opts, fp);
|
|
2892
|
+
return fp;
|
|
2893
|
+
}
|
|
2894
|
+
const resultCache = new LRUCache({ max: CSS_RESULT_CACHE_MAX });
|
|
2895
|
+
const hasUserPlugins = Boolean(
|
|
2896
|
+
cachedOptions.postcssOptions?.plugins && (Array.isArray(cachedOptions.postcssOptions.plugins) ? cachedOptions.postcssOptions.plugins.length > 0 : typeof cachedOptions.postcssOptions.plugins === "object" && Object.keys(cachedOptions.postcssOptions.plugins).length > 0)
|
|
2897
|
+
);
|
|
2579
2898
|
const handler = ((rawSource, opt) => {
|
|
2580
2899
|
const resolvedOptions = resolver.resolve(opt);
|
|
2581
|
-
|
|
2582
|
-
|
|
2900
|
+
let signal;
|
|
2901
|
+
if (!hasUserPlugins) {
|
|
2902
|
+
try {
|
|
2903
|
+
signal = probeFeatures(rawSource);
|
|
2904
|
+
} catch {
|
|
2905
|
+
signal = void 0;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
const optsFp = getOptionsFingerprint(resolvedOptions);
|
|
2909
|
+
const signalKey = signal ? signalToCacheKey(signal) : "";
|
|
2910
|
+
const contentHash = simpleHash(rawSource);
|
|
2911
|
+
const cacheKey = `${optsFp}|${signalKey}|${contentHash}`;
|
|
2912
|
+
const cachedResult = resultCache.get(cacheKey);
|
|
2913
|
+
if (cachedResult) {
|
|
2914
|
+
return Promise.resolve(cachedResult);
|
|
2915
|
+
}
|
|
2916
|
+
const processor = processorCache.getProcessor(resolvedOptions, signal);
|
|
2917
|
+
const processOptions = processorCache.getProcessOptions(resolvedOptions);
|
|
2583
2918
|
return processor.process(
|
|
2584
2919
|
rawSource,
|
|
2585
2920
|
processOptions
|
|
2586
|
-
).async().then((result) =>
|
|
2921
|
+
).async().then((result) => {
|
|
2922
|
+
const baseCompatible = applyUniAppXBaseCompatibility(result, resolvedOptions);
|
|
2923
|
+
const finalResult = applyUniAppXUvueCompatibility(baseCompatible, resolvedOptions);
|
|
2924
|
+
resultCache.set(cacheKey, finalResult);
|
|
2925
|
+
return finalResult;
|
|
2926
|
+
});
|
|
2587
2927
|
});
|
|
2588
2928
|
handler.getPipeline = (opt) => {
|
|
2589
2929
|
const resolvedOptions = resolver.resolve(opt);
|
|
2590
|
-
return
|
|
2930
|
+
return processorCache.getPipeline(resolvedOptions);
|
|
2591
2931
|
};
|
|
2592
2932
|
return handler;
|
|
2593
2933
|
}
|
|
2594
2934
|
export {
|
|
2935
|
+
createFallbackPlaceholderReplacer,
|
|
2595
2936
|
createInjectPreflight,
|
|
2596
2937
|
createStyleHandler,
|
|
2597
2938
|
createStylePipeline,
|
|
2598
|
-
internalCssSelectorReplacer
|
|
2939
|
+
internalCssSelectorReplacer,
|
|
2940
|
+
html_transform_default as postcssHtmlTransform
|
|
2599
2941
|
};
|