@weapp-tailwindcss/postcss 2.1.7 → 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++) {
@@ -2415,7 +2587,29 @@ function createPreparedNode(id, stage, createPlugin) {
2415
2587
  createPlugin
2416
2588
  };
2417
2589
  }
2418
- 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) {
2419
2613
  const preparedNodes = [];
2420
2614
  const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
2421
2615
  const presetEnvOptions = options.cssPresetEnv;
@@ -2423,8 +2617,12 @@ function createPreparedNodes(options) {
2423
2617
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2424
2618
  });
2425
2619
  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()));
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
+ }
2428
2626
  const unitsToPxPlugin = getUnitsToPxPlugin(options);
2429
2627
  if (unitsToPxPlugin) {
2430
2628
  preparedNodes.push(createPreparedNode("normal:units-to-px", "normal", () => unitsToPxPlugin));
@@ -2449,12 +2647,18 @@ function createPreparedNodes(options) {
2449
2647
  if (customPropertyCleaner) {
2450
2648
  preparedNodes.push(createPreparedNode("normal:custom-property-cleaner", "normal", () => customPropertyCleaner));
2451
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
+ }
2452
2656
  preparedNodes.push(createPreparedNode("post:core", "post", () => postcssWeappTailwindcssPostPlugin(options)));
2453
2657
  return preparedNodes;
2454
2658
  }
2455
- function createStylePipeline(options) {
2659
+ function createStylePipeline(options, signal) {
2456
2660
  options.ctx = createContext();
2457
- const preparedNodes = createPreparedNodes(options);
2661
+ const preparedNodes = createPreparedNodes(options, signal);
2458
2662
  if (preparedNodes.length === 0) {
2459
2663
  return {
2460
2664
  nodes: [],
@@ -2546,9 +2750,8 @@ function getSimpleProcessOptionsCacheKey(options) {
2546
2750
  return parts.join("|");
2547
2751
  }
2548
2752
  var StyleProcessorCache = class {
2549
- pipelineCache = /* @__PURE__ */ new WeakMap();
2753
+ pipelineCacheByKey = /* @__PURE__ */ new Map();
2550
2754
  processOptionsCache = /* @__PURE__ */ new WeakMap();
2551
- processorCache = /* @__PURE__ */ new WeakMap();
2552
2755
  processorCacheByKey = /* @__PURE__ */ new Map();
2553
2756
  processorKeyCache = /* @__PURE__ */ new WeakMap();
2554
2757
  createProcessorCacheKey(options) {
@@ -2567,11 +2770,26 @@ var StyleProcessorCache = class {
2567
2770
  }
2568
2771
  });
2569
2772
  }
2570
- getPipeline(options) {
2571
- 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);
2572
2790
  if (!pipeline) {
2573
- pipeline = createStylePipeline(options);
2574
- this.pipelineCache.set(options, pipeline);
2791
+ pipeline = createStylePipeline(options, signal);
2792
+ this.pipelineCacheByKey.set(compositeKey, pipeline);
2575
2793
  }
2576
2794
  return pipeline;
2577
2795
  }
@@ -2586,27 +2804,33 @@ var StyleProcessorCache = class {
2586
2804
  }
2587
2805
  return { ...cached.value };
2588
2806
  }
2589
- getProcessor(options) {
2590
- 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);
2591
2815
  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);
2816
+ const pipeline = this.getPipeline(options, signal);
2817
+ processor = postcss2(pipeline.plugins);
2818
+ this.processorCacheByKey.set(compositeKey, processor);
2604
2819
  }
2605
2820
  return processor;
2606
2821
  }
2607
2822
  };
2608
2823
 
2609
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
+ }
2610
2834
  function createStyleHandler(options) {
2611
2835
  const cachedOptions = defuOverrideArray4(
2612
2836
  options,
@@ -2614,22 +2838,57 @@ function createStyleHandler(options) {
2614
2838
  );
2615
2839
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
2616
2840
  const resolver = createOptionsResolver(cachedOptions);
2617
- const cache = new StyleProcessorCache();
2841
+ const processorCache = new StyleProcessorCache();
2618
2842
  const base = resolver.resolve();
2619
- cache.getProcessor(base);
2620
- 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
+ );
2621
2859
  const handler = ((rawSource, opt) => {
2622
2860
  const resolvedOptions = resolver.resolve(opt);
2623
- const processor = cache.getProcessor(resolvedOptions);
2624
- 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);
2625
2879
  return processor.process(
2626
2880
  rawSource,
2627
2881
  processOptions
2628
- ).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
+ });
2629
2888
  });
2630
2889
  handler.getPipeline = (opt) => {
2631
2890
  const resolvedOptions = resolver.resolve(opt);
2632
- return cache.getPipeline(resolvedOptions);
2891
+ return processorCache.getPipeline(resolvedOptions);
2633
2892
  };
2634
2893
  return handler;
2635
2894
  }
@@ -2638,5 +2897,6 @@ export {
2638
2897
  createInjectPreflight,
2639
2898
  createStyleHandler,
2640
2899
  createStylePipeline,
2641
- internalCssSelectorReplacer
2900
+ internalCssSelectorReplacer,
2901
+ html_transform_default as postcssHtmlTransform
2642
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 };
@@ -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 };
package/dist/types.d.mts CHANGED
@@ -4,4 +4,5 @@ import 'postcss-load-config';
4
4
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
5
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
6
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
7
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-CsRGpZ_r.mjs';
7
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UniAppXCssTarget, i as UniAppXUnsupportedMode, j as UserDefinedPostcssOptions, W as WeappAutoprefixerOptions } from './types-DJDvtI8K.mjs';
8
+ import 'autoprefixer';
package/dist/types.d.ts CHANGED
@@ -4,4 +4,5 @@ import 'postcss-load-config';
4
4
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
5
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
6
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
7
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-CsRGpZ_r.js';
7
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UniAppXCssTarget, i as UniAppXUnsupportedMode, j as UserDefinedPostcssOptions, W as WeappAutoprefixerOptions } from './types-DJDvtI8K.js';
8
+ import 'autoprefixer';