@weapp-tailwindcss/postcss 2.1.6 → 2.2.0-next.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.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.45.1/node_modules/es-toolkit/dist/object/omit.mjs
707
+ // ../../node_modules/.pnpm/es-toolkit@1.46.0/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++) {
@@ -1822,6 +1994,7 @@ function dedupeDeclarations(rule) {
1822
1994
  }
1823
1995
 
1824
1996
  // src/plugins/post/specificity-cleaner.ts
1997
+ var FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
1825
1998
  function normalizeSelectorList(value) {
1826
1999
  if (value === void 0 || value === false) {
1827
2000
  return [];
@@ -1836,6 +2009,45 @@ function getSpecificityMatchingName(options) {
1836
2009
  }
1837
2010
  return void 0;
1838
2011
  }
2012
+ function replaceFallbackPlaceholder(selector) {
2013
+ let output = selector;
2014
+ for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) {
2015
+ if (output.includes(suffix)) {
2016
+ output = output.split(suffix).join("");
2017
+ }
2018
+ }
2019
+ return output;
2020
+ }
2021
+ function createFallbackPlaceholderReplacer() {
2022
+ return (code) => {
2023
+ let output = code;
2024
+ for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) {
2025
+ if (output.includes(suffix)) {
2026
+ output = output.split(suffix).join("");
2027
+ }
2028
+ }
2029
+ return output;
2030
+ };
2031
+ }
2032
+ function createFallbackPlaceholderCleaner() {
2033
+ return (rule) => {
2034
+ if (!rule.selectors || rule.selectors.length === 0) {
2035
+ return;
2036
+ }
2037
+ let changed = false;
2038
+ const next = rule.selectors.map((selector) => {
2039
+ const updated = replaceFallbackPlaceholder(selector);
2040
+ if (updated !== selector) {
2041
+ changed = true;
2042
+ }
2043
+ return updated;
2044
+ });
2045
+ changed && assignRuleSelectors(rule, next, {
2046
+ phase: "post",
2047
+ reason: "clean-fallback-placeholder"
2048
+ });
2049
+ };
2050
+ }
1839
2051
  function createRootSpecificityCleaner(options) {
1840
2052
  const specificityMatchingName = getSpecificityMatchingName(options);
1841
2053
  const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
@@ -1908,6 +2120,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1908
2120
  postcssPlugin
1909
2121
  };
1910
2122
  const cleanRootSpecificity = createRootSpecificityCleaner(opts);
2123
+ const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
1911
2124
  const shouldAppendHostSelector = createHostSelectorAppender(opts);
1912
2125
  const enableMainChunkTransforms = opts.isMainChunk !== false;
1913
2126
  if (enableMainChunkTransforms || cleanRootSpecificity) {
@@ -1916,6 +2129,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1916
2129
  if (enableMainChunkTransforms) {
1917
2130
  fallbackRemove?.transformSync(rule);
1918
2131
  }
2132
+ cleanFallbackPlaceholder(rule);
1919
2133
  cleanRootSpecificity?.(rule);
1920
2134
  if (enableMainChunkTransforms) {
1921
2135
  if (shouldAppendHostSelector?.(rule)) {
@@ -2373,7 +2587,29 @@ function createPreparedNode(id, stage, createPlugin) {
2373
2587
  createPlugin
2374
2588
  };
2375
2589
  }
2376
- function createPreparedNodes(options) {
2590
+ function hasUserAutoprefixerPlugin(rawPlugins, plugins) {
2591
+ if (plugins.some((plugin) => isAutoprefixerPlugin(plugin))) {
2592
+ return true;
2593
+ }
2594
+ if (rawPlugins && !Array.isArray(rawPlugins) && typeof rawPlugins === "object") {
2595
+ const autoprefixerEntry = rawPlugins["autoprefixer"];
2596
+ return Boolean(autoprefixerEntry);
2597
+ }
2598
+ return false;
2599
+ }
2600
+ function shouldUseDefaultAutoprefixer(options, userPlugins) {
2601
+ if (options.autoprefixer === false) {
2602
+ return false;
2603
+ }
2604
+ if (hasUserAutoprefixerPlugin(options.postcssOptions?.plugins, userPlugins)) {
2605
+ return false;
2606
+ }
2607
+ if (options.autoprefixer === true || typeof options.autoprefixer === "object") {
2608
+ return true;
2609
+ }
2610
+ return options.majorVersion === 4;
2611
+ }
2612
+ function createPreparedNodes(options, signal) {
2377
2613
  const preparedNodes = [];
2378
2614
  const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
2379
2615
  const presetEnvOptions = options.cssPresetEnv;
@@ -2381,8 +2617,12 @@ function createPreparedNodes(options) {
2381
2617
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2382
2618
  });
2383
2619
  preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
2384
- preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(presetEnvOptions)));
2385
- preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
2620
+ if (!signal || signal.hasPresetEnvFeatures) {
2621
+ preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(presetEnvOptions)));
2622
+ }
2623
+ if (!signal || signal.hasModernColorFunction) {
2624
+ preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
2625
+ }
2386
2626
  const unitsToPxPlugin = getUnitsToPxPlugin(options);
2387
2627
  if (unitsToPxPlugin) {
2388
2628
  preparedNodes.push(createPreparedNode("normal:units-to-px", "normal", () => unitsToPxPlugin));
@@ -2407,12 +2647,18 @@ function createPreparedNodes(options) {
2407
2647
  if (customPropertyCleaner) {
2408
2648
  preparedNodes.push(createPreparedNode("normal:custom-property-cleaner", "normal", () => customPropertyCleaner));
2409
2649
  }
2650
+ if (shouldUseDefaultAutoprefixer(options, userPlugins)) {
2651
+ const plugin = resolveAutoprefixerPlugin(options.autoprefixer);
2652
+ if (plugin) {
2653
+ preparedNodes.push(createPreparedNode("normal:autoprefixer", "normal", () => plugin));
2654
+ }
2655
+ }
2410
2656
  preparedNodes.push(createPreparedNode("post:core", "post", () => postcssWeappTailwindcssPostPlugin(options)));
2411
2657
  return preparedNodes;
2412
2658
  }
2413
- function createStylePipeline(options) {
2659
+ function createStylePipeline(options, signal) {
2414
2660
  options.ctx = createContext();
2415
- const preparedNodes = createPreparedNodes(options);
2661
+ const preparedNodes = createPreparedNodes(options, signal);
2416
2662
  if (preparedNodes.length === 0) {
2417
2663
  return {
2418
2664
  nodes: [],
@@ -2504,9 +2750,8 @@ function getSimpleProcessOptionsCacheKey(options) {
2504
2750
  return parts.join("|");
2505
2751
  }
2506
2752
  var StyleProcessorCache = class {
2507
- pipelineCache = /* @__PURE__ */ new WeakMap();
2753
+ pipelineCacheByKey = /* @__PURE__ */ new Map();
2508
2754
  processOptionsCache = /* @__PURE__ */ new WeakMap();
2509
- processorCache = /* @__PURE__ */ new WeakMap();
2510
2755
  processorCacheByKey = /* @__PURE__ */ new Map();
2511
2756
  processorKeyCache = /* @__PURE__ */ new WeakMap();
2512
2757
  createProcessorCacheKey(options) {
@@ -2525,11 +2770,26 @@ var StyleProcessorCache = class {
2525
2770
  }
2526
2771
  });
2527
2772
  }
2528
- getPipeline(options) {
2529
- let pipeline = this.pipelineCache.get(options);
2773
+ /**
2774
+ * 构建包含信号的复合缓存键
2775
+ */
2776
+ createCompositeCacheKey(optionsFingerprint, signal) {
2777
+ if (!signal) {
2778
+ return optionsFingerprint;
2779
+ }
2780
+ return `${optionsFingerprint}|${signalToCacheKey(signal)}`;
2781
+ }
2782
+ getPipeline(options, signal) {
2783
+ let optionsKey = this.processorKeyCache.get(options);
2784
+ if (!optionsKey) {
2785
+ optionsKey = this.createProcessorCacheKey(options);
2786
+ this.processorKeyCache.set(options, optionsKey);
2787
+ }
2788
+ const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
2789
+ let pipeline = this.pipelineCacheByKey.get(compositeKey);
2530
2790
  if (!pipeline) {
2531
- pipeline = createStylePipeline(options);
2532
- this.pipelineCache.set(options, pipeline);
2791
+ pipeline = createStylePipeline(options, signal);
2792
+ this.pipelineCacheByKey.set(compositeKey, pipeline);
2533
2793
  }
2534
2794
  return pipeline;
2535
2795
  }
@@ -2544,27 +2804,33 @@ var StyleProcessorCache = class {
2544
2804
  }
2545
2805
  return { ...cached.value };
2546
2806
  }
2547
- getProcessor(options) {
2548
- let processor = this.processorCache.get(options);
2807
+ getProcessor(options, signal) {
2808
+ let optionsKey = this.processorKeyCache.get(options);
2809
+ if (!optionsKey) {
2810
+ optionsKey = this.createProcessorCacheKey(options);
2811
+ this.processorKeyCache.set(options, optionsKey);
2812
+ }
2813
+ const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
2814
+ let processor = this.processorCacheByKey.get(compositeKey);
2549
2815
  if (!processor) {
2550
- let cacheKey = this.processorKeyCache.get(options);
2551
- if (!cacheKey) {
2552
- cacheKey = this.createProcessorCacheKey(options);
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);
2816
+ const pipeline = this.getPipeline(options, signal);
2817
+ processor = postcss2(pipeline.plugins);
2818
+ this.processorCacheByKey.set(compositeKey, processor);
2562
2819
  }
2563
2820
  return processor;
2564
2821
  }
2565
2822
  };
2566
2823
 
2567
2824
  // src/handler.ts
2825
+ var CSS_RESULT_CACHE_MAX = 256;
2826
+ function simpleHash(str) {
2827
+ let hash = 2166136261 | 0;
2828
+ for (let i = 0; i < str.length; i++) {
2829
+ hash ^= str.charCodeAt(i);
2830
+ hash = hash * 16777619 | 0;
2831
+ }
2832
+ return (hash >>> 0).toString(36);
2833
+ }
2568
2834
  function createStyleHandler(options) {
2569
2835
  const cachedOptions = defuOverrideArray4(
2570
2836
  options,
@@ -2572,28 +2838,65 @@ function createStyleHandler(options) {
2572
2838
  );
2573
2839
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
2574
2840
  const resolver = createOptionsResolver(cachedOptions);
2575
- const cache = new StyleProcessorCache();
2841
+ const processorCache = new StyleProcessorCache();
2576
2842
  const base = resolver.resolve();
2577
- cache.getProcessor(base);
2578
- cache.getProcessOptions(base);
2843
+ processorCache.getProcessor(base);
2844
+ processorCache.getProcessOptions(base);
2845
+ const optionsFingerprintCache = /* @__PURE__ */ new WeakMap();
2846
+ function getOptionsFingerprint(opts) {
2847
+ const cached = optionsFingerprintCache.get(opts);
2848
+ if (cached) {
2849
+ return cached;
2850
+ }
2851
+ const fp = fingerprintOptions(opts);
2852
+ optionsFingerprintCache.set(opts, fp);
2853
+ return fp;
2854
+ }
2855
+ const resultCache = new LRUCache({ max: CSS_RESULT_CACHE_MAX });
2856
+ const hasUserPlugins = Boolean(
2857
+ 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)
2858
+ );
2579
2859
  const handler = ((rawSource, opt) => {
2580
2860
  const resolvedOptions = resolver.resolve(opt);
2581
- const processor = cache.getProcessor(resolvedOptions);
2582
- const processOptions = cache.getProcessOptions(resolvedOptions);
2861
+ let signal;
2862
+ if (!hasUserPlugins) {
2863
+ try {
2864
+ signal = probeFeatures(rawSource);
2865
+ } catch {
2866
+ signal = void 0;
2867
+ }
2868
+ }
2869
+ const optsFp = getOptionsFingerprint(resolvedOptions);
2870
+ const signalKey = signal ? signalToCacheKey(signal) : "";
2871
+ const contentHash = simpleHash(rawSource);
2872
+ const cacheKey = `${optsFp}|${signalKey}|${contentHash}`;
2873
+ const cachedResult = resultCache.get(cacheKey);
2874
+ if (cachedResult) {
2875
+ return Promise.resolve(cachedResult);
2876
+ }
2877
+ const processor = processorCache.getProcessor(resolvedOptions, signal);
2878
+ const processOptions = processorCache.getProcessOptions(resolvedOptions);
2583
2879
  return processor.process(
2584
2880
  rawSource,
2585
2881
  processOptions
2586
- ).async().then((result) => applyUniAppXBaseCompatibility(result, resolvedOptions));
2882
+ ).async().then((result) => {
2883
+ const baseCompatible = applyUniAppXBaseCompatibility(result, resolvedOptions);
2884
+ const finalResult = applyUniAppXUvueCompatibility(baseCompatible, resolvedOptions);
2885
+ resultCache.set(cacheKey, finalResult);
2886
+ return finalResult;
2887
+ });
2587
2888
  });
2588
2889
  handler.getPipeline = (opt) => {
2589
2890
  const resolvedOptions = resolver.resolve(opt);
2590
- return cache.getPipeline(resolvedOptions);
2891
+ return processorCache.getPipeline(resolvedOptions);
2591
2892
  };
2592
2893
  return handler;
2593
2894
  }
2594
2895
  export {
2896
+ createFallbackPlaceholderReplacer,
2595
2897
  createInjectPreflight,
2596
2898
  createStyleHandler,
2597
2899
  createStylePipeline,
2598
- internalCssSelectorReplacer
2900
+ internalCssSelectorReplacer,
2901
+ html_transform_default as postcssHtmlTransform
2599
2902
  };
@@ -4,6 +4,27 @@ import { Result } from 'postcss-load-config';
4
4
  import { PxTransformOptions } from 'postcss-pxtrans';
5
5
  import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
6
  import { UserDefinedOptions as UserDefinedOptions$1 } from 'postcss-units-to-px';
7
+ import autoprefixer from 'autoprefixer';
8
+
9
+ type AutoprefixerOptions = autoprefixer.Options;
10
+ type WeappAutoprefixerOptions = boolean | AutoprefixerOptions;
11
+
12
+ /**
13
+ * CSS 内容特征探测模块
14
+ *
15
+ * 通过正则和字符串匹配快速判断 CSS 是否包含特定特征,
16
+ * 用于在构建流水线前决定哪些插件可以跳过。
17
+ * 仅使用字符串方法和正则表达式,不引入 AST 解析开销。
18
+ */
19
+ /**
20
+ * CSS 内容特征信号,表示哪些特征存在于当前 CSS 中
21
+ */
22
+ interface FeatureSignal {
23
+ /** CSS 中是否包含现代颜色函数语法(如 rgb(r g b / a) 空格分隔写法) */
24
+ hasModernColorFunction: boolean;
25
+ /** CSS 中是否包含需要 postcss-preset-env 处理的特征 */
26
+ hasPresetEnvFeatures: boolean;
27
+ }
7
28
 
8
29
  type PipelineStage = 'pre' | 'normal' | 'post';
9
30
  interface PipelineNodeCursor {
@@ -45,7 +66,7 @@ interface StyleProcessingPipeline {
45
66
  nodes: ResolvedPipelineNode[];
46
67
  plugins: AcceptedPlugin[];
47
68
  }
48
- declare function createStylePipeline(options: IStyleHandlerOptions): StyleProcessingPipeline;
69
+ declare function createStylePipeline(options: IStyleHandlerOptions, signal?: FeatureSignal): StyleProcessingPipeline;
49
70
 
50
71
  declare function createContext(): {
51
72
  variablesScopeWeakMap: WeakMap<WeakKey, any>;
@@ -77,6 +98,8 @@ interface IPropValue {
77
98
  prop: string;
78
99
  value: string;
79
100
  }
101
+ type UniAppXCssTarget = 'uvue';
102
+ type UniAppXUnsupportedMode = 'error' | 'warn' | 'silent';
80
103
  type CssPreflightOptions = {
81
104
  [key: string]: string | number | boolean;
82
105
  } | false;
@@ -101,6 +124,7 @@ type IStyleHandlerOptions = {
101
124
  cssRemoveProperty?: boolean;
102
125
  cssRemoveHoverPseudoClass?: boolean;
103
126
  cssPresetEnv?: PresetEnvOptions;
127
+ autoprefixer?: WeappAutoprefixerOptions;
104
128
  cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
105
129
  atRules?: {
106
130
  property?: boolean;
@@ -108,6 +132,8 @@ type IStyleHandlerOptions = {
108
132
  media?: boolean;
109
133
  };
110
134
  uniAppX?: boolean;
135
+ uniAppXCssTarget?: UniAppXCssTarget;
136
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
111
137
  majorVersion?: number;
112
138
  } & RequiredStyleHandlerOptions;
113
139
  interface UserDefinedPostcssOptions {
@@ -115,6 +141,7 @@ interface UserDefinedPostcssOptions {
115
141
  cssPreflightRange?: 'all';
116
142
  cssChildCombinatorReplaceValue?: string | string[];
117
143
  cssPresetEnv?: PresetEnvOptions;
144
+ autoprefixer?: WeappAutoprefixerOptions;
118
145
  injectAdditionalCssVarScope?: boolean;
119
146
  cssSelectorReplacement?: {
120
147
  root?: string | string[] | false;
@@ -127,6 +154,8 @@ interface UserDefinedPostcssOptions {
127
154
  cssRemoveHoverPseudoClass?: boolean;
128
155
  cssRemoveProperty?: boolean;
129
156
  uniAppX?: boolean;
157
+ uniAppXCssTarget?: UniAppXCssTarget;
158
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
130
159
  }
131
160
 
132
161
  interface StyleHandler {
@@ -134,4 +163,4 @@ interface StyleHandler {
134
163
  getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
135
164
  }
136
165
 
137
- export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type PresetEnvOptions as f, type ResolvedPipelineNode as g, type StyleProcessingPipeline as h, createInjectPreflight as i, createStylePipeline as j };
166
+ export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UniAppXCssTarget as U, type WeappAutoprefixerOptions as W, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type PresetEnvOptions as f, type ResolvedPipelineNode as g, type StyleProcessingPipeline as h, type UniAppXUnsupportedMode as i, type UserDefinedPostcssOptions as j, createInjectPreflight as k, createStylePipeline as l };