@weapp-tailwindcss/postcss 2.1.7 → 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/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.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 postcssUnitsToPx from "postcss-units-to-px";
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
- return postcssUnitsToPx(userOptions);
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
@@ -2415,7 +2626,29 @@ function createPreparedNode(id, stage, createPlugin) {
2415
2626
  createPlugin
2416
2627
  };
2417
2628
  }
2418
- function createPreparedNodes(options) {
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) {
2419
2652
  const preparedNodes = [];
2420
2653
  const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
2421
2654
  const presetEnvOptions = options.cssPresetEnv;
@@ -2423,8 +2656,12 @@ function createPreparedNodes(options) {
2423
2656
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2424
2657
  });
2425
2658
  preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
2426
- preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(presetEnvOptions)));
2427
- preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
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
+ }
2428
2665
  const unitsToPxPlugin = getUnitsToPxPlugin(options);
2429
2666
  if (unitsToPxPlugin) {
2430
2667
  preparedNodes.push(createPreparedNode("normal:units-to-px", "normal", () => unitsToPxPlugin));
@@ -2449,12 +2686,18 @@ function createPreparedNodes(options) {
2449
2686
  if (customPropertyCleaner) {
2450
2687
  preparedNodes.push(createPreparedNode("normal:custom-property-cleaner", "normal", () => customPropertyCleaner));
2451
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
+ }
2452
2695
  preparedNodes.push(createPreparedNode("post:core", "post", () => postcssWeappTailwindcssPostPlugin(options)));
2453
2696
  return preparedNodes;
2454
2697
  }
2455
- function createStylePipeline(options) {
2698
+ function createStylePipeline(options, signal) {
2456
2699
  options.ctx = createContext();
2457
- const preparedNodes = createPreparedNodes(options);
2700
+ const preparedNodes = createPreparedNodes(options, signal);
2458
2701
  if (preparedNodes.length === 0) {
2459
2702
  return {
2460
2703
  nodes: [],
@@ -2546,9 +2789,8 @@ function getSimpleProcessOptionsCacheKey(options) {
2546
2789
  return parts.join("|");
2547
2790
  }
2548
2791
  var StyleProcessorCache = class {
2549
- pipelineCache = /* @__PURE__ */ new WeakMap();
2792
+ pipelineCacheByKey = /* @__PURE__ */ new Map();
2550
2793
  processOptionsCache = /* @__PURE__ */ new WeakMap();
2551
- processorCache = /* @__PURE__ */ new WeakMap();
2552
2794
  processorCacheByKey = /* @__PURE__ */ new Map();
2553
2795
  processorKeyCache = /* @__PURE__ */ new WeakMap();
2554
2796
  createProcessorCacheKey(options) {
@@ -2567,11 +2809,26 @@ var StyleProcessorCache = class {
2567
2809
  }
2568
2810
  });
2569
2811
  }
2570
- getPipeline(options) {
2571
- let pipeline = this.pipelineCache.get(options);
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);
2572
2829
  if (!pipeline) {
2573
- pipeline = createStylePipeline(options);
2574
- this.pipelineCache.set(options, pipeline);
2830
+ pipeline = createStylePipeline(options, signal);
2831
+ this.pipelineCacheByKey.set(compositeKey, pipeline);
2575
2832
  }
2576
2833
  return pipeline;
2577
2834
  }
@@ -2586,27 +2843,33 @@ var StyleProcessorCache = class {
2586
2843
  }
2587
2844
  return { ...cached.value };
2588
2845
  }
2589
- getProcessor(options) {
2590
- let processor = this.processorCache.get(options);
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);
2591
2854
  if (!processor) {
2592
- let cacheKey = this.processorKeyCache.get(options);
2593
- if (!cacheKey) {
2594
- cacheKey = this.createProcessorCacheKey(options);
2595
- this.processorKeyCache.set(options, cacheKey);
2596
- }
2597
- processor = this.processorCacheByKey.get(cacheKey);
2598
- if (!processor) {
2599
- const pipeline = this.getPipeline(options);
2600
- processor = postcss2(pipeline.plugins);
2601
- this.processorCacheByKey.set(cacheKey, processor);
2602
- }
2603
- this.processorCache.set(options, processor);
2855
+ const pipeline = this.getPipeline(options, signal);
2856
+ processor = postcss2(pipeline.plugins);
2857
+ this.processorCacheByKey.set(compositeKey, processor);
2604
2858
  }
2605
2859
  return processor;
2606
2860
  }
2607
2861
  };
2608
2862
 
2609
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
+ }
2610
2873
  function createStyleHandler(options) {
2611
2874
  const cachedOptions = defuOverrideArray4(
2612
2875
  options,
@@ -2614,22 +2877,57 @@ function createStyleHandler(options) {
2614
2877
  );
2615
2878
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
2616
2879
  const resolver = createOptionsResolver(cachedOptions);
2617
- const cache = new StyleProcessorCache();
2880
+ const processorCache = new StyleProcessorCache();
2618
2881
  const base = resolver.resolve();
2619
- cache.getProcessor(base);
2620
- cache.getProcessOptions(base);
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
+ );
2621
2898
  const handler = ((rawSource, opt) => {
2622
2899
  const resolvedOptions = resolver.resolve(opt);
2623
- const processor = cache.getProcessor(resolvedOptions);
2624
- const processOptions = cache.getProcessOptions(resolvedOptions);
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);
2625
2918
  return processor.process(
2626
2919
  rawSource,
2627
2920
  processOptions
2628
- ).async().then((result) => applyUniAppXBaseCompatibility(result, resolvedOptions));
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
+ });
2629
2927
  });
2630
2928
  handler.getPipeline = (opt) => {
2631
2929
  const resolvedOptions = resolver.resolve(opt);
2632
- return cache.getPipeline(resolvedOptions);
2930
+ return processorCache.getPipeline(resolvedOptions);
2633
2931
  };
2634
2932
  return handler;
2635
2933
  }
@@ -2638,5 +2936,6 @@ export {
2638
2936
  createInjectPreflight,
2639
2937
  createStyleHandler,
2640
2938
  createStylePipeline,
2641
- internalCssSelectorReplacer
2939
+ internalCssSelectorReplacer,
2940
+ html_transform_default as postcssHtmlTransform
2642
2941
  };
@@ -3,7 +3,28 @@ import { AcceptedPlugin, Result as Result$1 } from 'postcss';
3
3
  import { Result } from 'postcss-load-config';
4
4
  import { PxTransformOptions } from 'postcss-pxtrans';
5
5
  import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
- import { UserDefinedOptions as UserDefinedOptions$1 } from 'postcss-units-to-px';
6
+ import { UserDefinedOptions as UserDefinedOptions$1, UnitMap, GlobalUnitTransform } from 'postcss-rule-unit-converter';
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;
@@ -95,12 +118,19 @@ interface InternalCssSelectorReplacerOptions {
95
118
  interface CssCalcOptions extends PostCssCalcOptions {
96
119
  includeCustomProperties?: (string | RegExp)[];
97
120
  }
121
+ interface UnitsToPxOptions extends Pick<UserDefinedOptions$1, 'disabled' | 'exclude' | 'mediaQuery' | 'propList' | 'replace' | 'selectorBlackList' | 'unitPrecision'> {
122
+ minValue?: number;
123
+ to?: string;
124
+ unitMap?: UnitMap;
125
+ transform?: GlobalUnitTransform | false;
126
+ }
98
127
  type IStyleHandlerOptions = {
99
128
  ctx?: IContext;
100
129
  postcssOptions?: LoadedPostcssOptions;
101
130
  cssRemoveProperty?: boolean;
102
131
  cssRemoveHoverPseudoClass?: boolean;
103
132
  cssPresetEnv?: PresetEnvOptions;
133
+ autoprefixer?: WeappAutoprefixerOptions;
104
134
  cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
105
135
  atRules?: {
106
136
  property?: boolean;
@@ -108,6 +138,8 @@ type IStyleHandlerOptions = {
108
138
  media?: boolean;
109
139
  };
110
140
  uniAppX?: boolean;
141
+ uniAppXCssTarget?: UniAppXCssTarget;
142
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
111
143
  majorVersion?: number;
112
144
  } & RequiredStyleHandlerOptions;
113
145
  interface UserDefinedPostcssOptions {
@@ -115,6 +147,7 @@ interface UserDefinedPostcssOptions {
115
147
  cssPreflightRange?: 'all';
116
148
  cssChildCombinatorReplaceValue?: string | string[];
117
149
  cssPresetEnv?: PresetEnvOptions;
150
+ autoprefixer?: WeappAutoprefixerOptions;
118
151
  injectAdditionalCssVarScope?: boolean;
119
152
  cssSelectorReplacement?: {
120
153
  root?: string | string[] | false;
@@ -122,11 +155,13 @@ interface UserDefinedPostcssOptions {
122
155
  };
123
156
  rem2rpx?: boolean | UserDefinedOptions;
124
157
  px2rpx?: boolean | PxTransformOptions;
125
- unitsToPx?: boolean | UserDefinedOptions$1;
158
+ unitsToPx?: boolean | UnitsToPxOptions;
126
159
  postcssOptions?: LoadedPostcssOptions;
127
160
  cssRemoveHoverPseudoClass?: boolean;
128
161
  cssRemoveProperty?: boolean;
129
162
  uniAppX?: boolean;
163
+ uniAppXCssTarget?: UniAppXCssTarget;
164
+ uniAppXUnsupported?: UniAppXUnsupportedMode;
130
165
  }
131
166
 
132
167
  interface StyleHandler {
@@ -134,4 +169,4 @@ interface StyleHandler {
134
169
  getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
135
170
  }
136
171
 
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 };
172
+ 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 UnitsToPxOptions as j, type UserDefinedPostcssOptions as k, createInjectPreflight as l, createStylePipeline as m };