@weapp-tailwindcss/postcss 2.1.5-beta.0 → 2.1.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -69,26 +69,151 @@ function fingerprintOptions(value, state = { map: /* @__PURE__ */ new WeakMap(),
69
69
 
70
70
  // src/options-resolver.ts
71
71
  var BASE_CACHE_KEY = "base";
72
+ var SIMPLE_OVERRIDE_UNSET = "__unset__";
73
+ function getSimpleOverrideCacheKey(options) {
74
+ let isMainChunk = SIMPLE_OVERRIDE_UNSET;
75
+ let majorVersion = SIMPLE_OVERRIDE_UNSET;
76
+ let cssRemoveProperty = SIMPLE_OVERRIDE_UNSET;
77
+ let cssRemoveHoverPseudoClass = SIMPLE_OVERRIDE_UNSET;
78
+ let uniAppX = SIMPLE_OVERRIDE_UNSET;
79
+ let cssPreflightRange = SIMPLE_OVERRIDE_UNSET;
80
+ let injectAdditionalCssVarScope = SIMPLE_OVERRIDE_UNSET;
81
+ let rem2rpx = SIMPLE_OVERRIDE_UNSET;
82
+ let px2rpx = SIMPLE_OVERRIDE_UNSET;
83
+ let unitsToPx = SIMPLE_OVERRIDE_UNSET;
84
+ let cssCalc = SIMPLE_OVERRIDE_UNSET;
85
+ let cssChildCombinatorReplaceValue = SIMPLE_OVERRIDE_UNSET;
86
+ let cssPreflight = SIMPLE_OVERRIDE_UNSET;
87
+ for (const key of Object.keys(options)) {
88
+ const value = options[key];
89
+ switch (key) {
90
+ case "isMainChunk":
91
+ if (typeof value !== "boolean") {
92
+ return void 0;
93
+ }
94
+ isMainChunk = value ? "1" : "0";
95
+ break;
96
+ case "majorVersion":
97
+ if (typeof value !== "number") {
98
+ return void 0;
99
+ }
100
+ majorVersion = String(value);
101
+ break;
102
+ case "cssRemoveProperty":
103
+ if (typeof value !== "boolean") {
104
+ return void 0;
105
+ }
106
+ cssRemoveProperty = value ? "1" : "0";
107
+ break;
108
+ case "cssRemoveHoverPseudoClass":
109
+ if (typeof value !== "boolean") {
110
+ return void 0;
111
+ }
112
+ cssRemoveHoverPseudoClass = value ? "1" : "0";
113
+ break;
114
+ case "uniAppX":
115
+ if (typeof value !== "boolean") {
116
+ return void 0;
117
+ }
118
+ uniAppX = value ? "1" : "0";
119
+ break;
120
+ case "cssPreflightRange":
121
+ if (typeof value !== "string") {
122
+ return void 0;
123
+ }
124
+ cssPreflightRange = value;
125
+ break;
126
+ case "injectAdditionalCssVarScope":
127
+ if (typeof value !== "boolean") {
128
+ return void 0;
129
+ }
130
+ injectAdditionalCssVarScope = value ? "1" : "0";
131
+ break;
132
+ case "rem2rpx":
133
+ if (typeof value !== "boolean") {
134
+ return void 0;
135
+ }
136
+ rem2rpx = value ? "1" : "0";
137
+ break;
138
+ case "px2rpx":
139
+ if (typeof value !== "boolean") {
140
+ return void 0;
141
+ }
142
+ px2rpx = value ? "1" : "0";
143
+ break;
144
+ case "unitsToPx":
145
+ if (typeof value !== "boolean") {
146
+ return void 0;
147
+ }
148
+ unitsToPx = value ? "1" : "0";
149
+ break;
150
+ case "cssCalc":
151
+ if (typeof value !== "boolean") {
152
+ return void 0;
153
+ }
154
+ cssCalc = value ? "1" : "0";
155
+ break;
156
+ case "cssChildCombinatorReplaceValue":
157
+ if (typeof value !== "string") {
158
+ return void 0;
159
+ }
160
+ cssChildCombinatorReplaceValue = value;
161
+ break;
162
+ case "cssPreflight":
163
+ if (value !== false) {
164
+ return void 0;
165
+ }
166
+ cssPreflight = "0";
167
+ break;
168
+ default:
169
+ return void 0;
170
+ }
171
+ }
172
+ return [
173
+ "simple",
174
+ isMainChunk,
175
+ majorVersion,
176
+ cssRemoveProperty,
177
+ cssRemoveHoverPseudoClass,
178
+ uniAppX,
179
+ cssPreflightRange,
180
+ injectAdditionalCssVarScope,
181
+ rem2rpx,
182
+ px2rpx,
183
+ unitsToPx,
184
+ cssCalc,
185
+ cssChildCombinatorReplaceValue,
186
+ cssPreflight
187
+ ].join(":");
188
+ }
72
189
  function hasOverrides(options) {
73
190
  return Boolean(options && Object.keys(options).length > 0);
74
191
  }
75
192
  function createOptionsResolver(baseOptions) {
76
193
  const cacheByKey = /* @__PURE__ */ new Map();
77
194
  const cacheByRef = /* @__PURE__ */ new WeakMap();
78
- const fingerprintByRef = /* @__PURE__ */ new WeakMap();
195
+ const cacheKeyByRef = /* @__PURE__ */ new WeakMap();
196
+ const emptyOverrideRefs = /* @__PURE__ */ new WeakSet();
79
197
  cacheByKey.set(BASE_CACHE_KEY, baseOptions);
80
198
  const resolve = (overrides) => {
81
- if (!hasOverrides(overrides)) {
199
+ if (!overrides) {
82
200
  return baseOptions;
83
201
  }
84
202
  const refCached = cacheByRef.get(overrides);
85
203
  if (refCached) {
86
204
  return refCached;
87
205
  }
88
- let key = fingerprintByRef.get(overrides);
206
+ if (emptyOverrideRefs.has(overrides)) {
207
+ return baseOptions;
208
+ }
209
+ if (!hasOverrides(overrides)) {
210
+ emptyOverrideRefs.add(overrides);
211
+ return baseOptions;
212
+ }
213
+ let key = cacheKeyByRef.get(overrides);
89
214
  if (!key) {
90
- key = fingerprintOptions(overrides);
91
- fingerprintByRef.set(overrides, key);
215
+ key = getSimpleOverrideCacheKey(overrides) ?? fingerprintOptions(overrides);
216
+ cacheKeyByRef.set(overrides, key);
92
217
  }
93
218
  const cached = cacheByKey.get(key);
94
219
  if (cached) {
@@ -247,37 +372,38 @@ function createContext() {
247
372
  }
248
373
 
249
374
  // src/plugins/getCalcDuplicateCleaner.ts
375
+ var calcDuplicateCleanerPlugin = {
376
+ postcssPlugin: "postcss-calc-duplicate-cleaner",
377
+ Rule(rule) {
378
+ rule.walkDecls((decl) => {
379
+ const prev = decl.prev();
380
+ if (!prev || prev.type !== "decl") {
381
+ return;
382
+ }
383
+ if (prev.prop !== decl.prop) {
384
+ return;
385
+ }
386
+ if (prev.important !== decl.important) {
387
+ return;
388
+ }
389
+ if (prev.value !== decl.value) {
390
+ return;
391
+ }
392
+ decl.remove();
393
+ });
394
+ }
395
+ };
250
396
  function getCalcDuplicateCleaner(options) {
251
397
  if (!options.cssCalc) {
252
398
  return null;
253
399
  }
254
- return {
255
- postcssPlugin: "postcss-calc-duplicate-cleaner",
256
- Rule(rule) {
257
- rule.walkDecls((decl) => {
258
- const prev = decl.prev();
259
- if (!prev || prev.type !== "decl") {
260
- return;
261
- }
262
- if (prev.prop !== decl.prop) {
263
- return;
264
- }
265
- if (prev.important !== decl.important) {
266
- return;
267
- }
268
- if (prev.value !== decl.value) {
269
- return;
270
- }
271
- decl.remove();
272
- });
273
- }
274
- };
400
+ return calcDuplicateCleanerPlugin;
275
401
  }
276
402
 
277
403
  // src/plugins/getCalcPlugin.ts
278
404
  import postcssCalc from "@weapp-tailwindcss/postcss-calc";
279
405
 
280
- // ../../node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/omit.mjs
406
+ // ../../node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/omit.mjs
281
407
  function omit(obj, keys) {
282
408
  const result = { ...obj };
283
409
  for (let i = 0; i < keys.length; i++) {
@@ -288,12 +414,17 @@ function omit(obj, keys) {
288
414
  }
289
415
 
290
416
  // src/plugins/getCalcPlugin.ts
417
+ var EMPTY_CALC_OPTIONS = {};
291
418
  function getCalcPlugin(options) {
292
419
  if (!options.cssCalc) {
293
420
  return null;
294
421
  }
295
- const calcOptions = Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {};
296
- return postcssCalc(calcOptions);
422
+ if (options.cssCalc === true || Array.isArray(options.cssCalc)) {
423
+ return postcssCalc(EMPTY_CALC_OPTIONS);
424
+ }
425
+ return postcssCalc(
426
+ omit(options.cssCalc, ["includeCustomProperties"])
427
+ );
297
428
  }
298
429
 
299
430
  // src/plugins/getCustomPropertyCleaner.ts
@@ -305,6 +436,7 @@ function getCustomPropertyCleaner(options) {
305
436
  if (!shouldMatchCustomProperties) {
306
437
  return null;
307
438
  }
439
+ const shouldInspectValue = (value) => value.includes("var(") && value.includes("--");
308
440
  return {
309
441
  postcssPlugin: "postcss-remove-include-custom-properties",
310
442
  OnceExit(root) {
@@ -317,7 +449,7 @@ function getCustomPropertyCleaner(options) {
317
449
  decl.remove();
318
450
  return;
319
451
  }
320
- if (!shouldMatchCustomProperties || !/--/.test(decl.value)) {
452
+ if (!shouldInspectValue(decl.value)) {
321
453
  return;
322
454
  }
323
455
  const parsed = valueParser2(decl.value);
@@ -365,10 +497,12 @@ function getPxTransformPlugin(options) {
365
497
  if (!options.px2rpx) {
366
498
  return null;
367
499
  }
368
- const userOptions = typeof options.px2rpx === "object" ? options.px2rpx : {};
500
+ if (options.px2rpx === true) {
501
+ return postcssPxtrans(defaultPxTransformOptions);
502
+ }
369
503
  return postcssPxtrans(
370
504
  defuOverrideArray2(
371
- userOptions,
505
+ options.px2rpx,
372
506
  defaultPxTransformOptions
373
507
  )
374
508
  );
@@ -385,13 +519,19 @@ var defaultRemOptions = {
385
519
  var defaultStage = {
386
520
  processorStage: "OnceExit"
387
521
  };
522
+ var defaultRemTransformOptions = {
523
+ ...defaultRemOptions,
524
+ ...defaultStage
525
+ };
388
526
  function getRemTransformPlugin(options) {
389
527
  if (!options.rem2rpx) {
390
528
  return null;
391
529
  }
392
- const userOptions = typeof options.rem2rpx === "object" ? options.rem2rpx : defaultRemOptions;
530
+ if (options.rem2rpx === true) {
531
+ return postcssRem2rpx(defaultRemTransformOptions);
532
+ }
393
533
  const merged = defuOverrideArray3(
394
- userOptions,
534
+ options.rem2rpx,
395
535
  defaultStage
396
536
  );
397
537
  return postcssRem2rpx(merged);
@@ -593,6 +733,12 @@ var OKLAB_SUFFIX = "in oklab";
593
733
  var INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
594
734
  var RADIUS_THRESHOLD = 1e5;
595
735
  var CLAMP_PX = 9999;
736
+ var MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
737
+ var MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
738
+ var MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
739
+ var MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
740
+ var RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
741
+ var SCIENTIFIC_NOTATION_RE = /e/i;
596
742
  function isTailwindcssV4(options) {
597
743
  return options?.majorVersion === 4;
598
744
  }
@@ -602,10 +748,10 @@ function testIfRootHostForV4(node) {
602
748
  var cssVarsV4Nodes = createCssVarNodes(cssVarsV4_default);
603
749
  function isTailwindcssV4ModernCheck(atRule) {
604
750
  return atRule.name === "supports" && [
605
- /-webkit-hyphens\s*:\s*none/,
606
- /margin-trim\s*:\s*inline/,
607
- /-moz-orient\s*:\s*inline/,
608
- /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/
751
+ MODERN_CHECK_WEBKIT_HYPHENS_RE,
752
+ MODERN_CHECK_MARGIN_TRIM_RE,
753
+ MODERN_CHECK_MOZ_ORIENT_RE,
754
+ MODERN_CHECK_COLOR_RGB_RE
609
755
  ].every((regex) => regex.test(atRule.params));
610
756
  }
611
757
  function normalizeTailwindcssV4Declaration(decl) {
@@ -618,14 +764,15 @@ function normalizeTailwindcssV4Declaration(decl) {
618
764
  return true;
619
765
  }
620
766
  if (decl.prop.includes("radius")) {
767
+ RADIUS_VALUE_RE.lastIndex = 0;
621
768
  const next = decl.value.replace(
622
- /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi,
769
+ RADIUS_VALUE_RE,
623
770
  (m, num) => {
624
771
  const n = Number(num);
625
772
  if (!Number.isFinite(n)) {
626
773
  return `${CLAMP_PX}px`;
627
774
  }
628
- if (/e/i.test(String(num)) || n > RADIUS_THRESHOLD) {
775
+ if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) {
629
776
  return `${CLAMP_PX}px`;
630
777
  }
631
778
  return m;
@@ -669,6 +816,8 @@ var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
669
816
  // src/selectorParser/before-after.ts
670
817
  import psp from "postcss-selector-parser";
671
818
  var beforeAfterStateRef = null;
819
+ var BEFORE_PSEUDO_RE = /^:?:before$/;
820
+ var AFTER_PSEUDO_RE = /^:?:after$/;
672
821
  var beforeAfterParser = psp((selectors) => {
673
822
  const state = beforeAfterStateRef;
674
823
  if (!state) {
@@ -676,10 +825,10 @@ var beforeAfterParser = psp((selectors) => {
676
825
  }
677
826
  selectors.walkPseudos((s) => {
678
827
  if (s.parent?.length === 1) {
679
- if (/^:?:before$/.test(s.value)) {
828
+ if (BEFORE_PSEUDO_RE.test(s.value)) {
680
829
  state.before = true;
681
830
  }
682
- if (/^:?:after$/.test(s.value)) {
831
+ if (AFTER_PSEUDO_RE.test(s.value)) {
683
832
  state.after = true;
684
833
  }
685
834
  }
@@ -701,6 +850,7 @@ import psp3 from "postcss-selector-parser";
701
850
 
702
851
  // src/selectorParser/utils.ts
703
852
  import psp2 from "postcss-selector-parser";
853
+ var combinatorSelectorAstCache = /* @__PURE__ */ new WeakMap();
704
854
  function normalizeTransformOptions(options) {
705
855
  return {
706
856
  lossless: false,
@@ -738,12 +888,16 @@ function composeIsPseudoAst(strs) {
738
888
  }));
739
889
  }
740
890
  function getCombinatorSelectorAst(options) {
741
- let childCombinatorReplaceValue = mklist(psp2.tag({ value: "view" }));
742
- const { cssChildCombinatorReplaceValue } = options;
743
- if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
744
- childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
891
+ let template = combinatorSelectorAstCache.get(options);
892
+ if (!template) {
893
+ template = mklist(psp2.tag({ value: "view" }));
894
+ const { cssChildCombinatorReplaceValue } = options;
895
+ if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
896
+ template = composeIsPseudoAst(cssChildCombinatorReplaceValue);
897
+ }
898
+ combinatorSelectorAstCache.set(options, template);
745
899
  }
746
- return childCombinatorReplaceValue;
900
+ return template.map((node) => node.clone());
747
901
  }
748
902
 
749
903
  // src/selectorParser/fallback.ts
@@ -754,8 +908,17 @@ function getFallbackRemove(_rule, options) {
754
908
  const cacheKey = options ?? fallbackDefaultKey;
755
909
  let entry = fallbackRemoveCache.get(cacheKey);
756
910
  if (!entry) {
911
+ let writeSelectorCache2 = function(selector, result) {
912
+ if (selectorCache.size >= selectorCacheLimit) {
913
+ selectorCache.clear();
914
+ }
915
+ selectorCache.set(selector, result);
916
+ };
917
+ var writeSelectorCache = writeSelectorCache2;
757
918
  const uniAppX = isUniAppXEnabled(options);
758
919
  let currentRule;
920
+ const selectorCache = /* @__PURE__ */ new Map();
921
+ const selectorCacheLimit = 5e4;
759
922
  const parser = psp3((selectors) => {
760
923
  const activeRule = currentRule;
761
924
  let maybeImportantId = false;
@@ -812,12 +975,33 @@ function getFallbackRemove(_rule, options) {
812
975
  });
813
976
  const rawTransformSync = parser.transformSync.bind(parser);
814
977
  const transform = (targetRule) => {
978
+ const sourceSelector = targetRule.selector;
979
+ if (!sourceSelector) {
980
+ return;
981
+ }
982
+ const cached = selectorCache.get(sourceSelector);
983
+ if (cached) {
984
+ if (cached.action === "remove") {
985
+ targetRule.remove();
986
+ } else if (cached.action === "update" && cached.selector && cached.selector !== sourceSelector) {
987
+ targetRule.selector = cached.selector;
988
+ }
989
+ return;
990
+ }
815
991
  currentRule = targetRule;
816
992
  try {
817
993
  rawTransformSync(targetRule, FALLBACK_TRANSFORM_OPTIONS);
818
994
  } finally {
819
995
  currentRule = void 0;
820
996
  }
997
+ const wasRemoved = targetRule.parent == null;
998
+ if (wasRemoved) {
999
+ writeSelectorCache2(sourceSelector, { action: "remove" });
1000
+ } else if (targetRule.selector === sourceSelector) {
1001
+ writeSelectorCache2(sourceSelector, { action: "keep" });
1002
+ } else {
1003
+ writeSelectorCache2(sourceSelector, { action: "update", selector: targetRule.selector });
1004
+ }
821
1005
  };
822
1006
  parser.transformSync = ((input, opts) => {
823
1007
  const transformOptions = opts ? normalizeTransformOptions(opts) : FALLBACK_TRANSFORM_OPTIONS;
@@ -848,15 +1032,21 @@ import psp4 from "postcss-selector-parser";
848
1032
 
849
1033
  // src/shared.ts
850
1034
  import { escape, MappingChars2String } from "@weapp-core/escape";
851
- function internalCssSelectorReplacer(selectors, options = {
852
- escapeMap: MappingChars2String
853
- }) {
854
- const { escapeMap } = options;
855
- const escapeOptions = {};
856
- if (escapeMap !== void 0) {
857
- escapeOptions["map"] = escapeMap;
1035
+ var escapeOptionsCache = /* @__PURE__ */ new WeakMap();
1036
+ function getEscapeOptions(escapeMap) {
1037
+ let cached = escapeOptionsCache.get(escapeMap);
1038
+ if (!cached) {
1039
+ cached = { map: escapeMap };
1040
+ escapeOptionsCache.set(escapeMap, cached);
858
1041
  }
859
- return escape(selectors, escapeOptions);
1042
+ return cached;
1043
+ }
1044
+ function internalCssSelectorReplacer(selectors, options) {
1045
+ const escapeMap = options?.escapeMap;
1046
+ if (escapeMap === void 0 || escapeMap === MappingChars2String) {
1047
+ return escape(selectors);
1048
+ }
1049
+ return escape(selectors, getEscapeOptions(escapeMap));
860
1050
  }
861
1051
  function composeIsPseudo(strs) {
862
1052
  if (typeof strs === "string") {
@@ -896,7 +1086,7 @@ function reorderLiteralFirst(rule, declarations, isVariable) {
896
1086
  if (alreadyOrdered) {
897
1087
  return;
898
1088
  }
899
- const anchor = declarations[declarations.length - 1]?.next() ?? void 0;
1089
+ const anchor = declarations.at(-1)?.next() ?? void 0;
900
1090
  for (const decl of declarations) {
901
1091
  decl.remove();
902
1092
  }
@@ -935,49 +1125,32 @@ var LEGACY_WEBKIT_SPACING_PROPS = /* @__PURE__ */ new Set([
935
1125
  "-webkit-margin-after"
936
1126
  ]);
937
1127
  var VAR_REFERENCE_PATTERN = /var\(/i;
938
- function dedupeSpacingProps(rule) {
939
- const grouped = /* @__PURE__ */ new Map();
940
- for (const node of rule.nodes) {
941
- if (node.type !== "decl") {
942
- continue;
943
- }
944
- if (!SPACING_PROP_SET.has(node.prop)) {
945
- continue;
946
- }
947
- const list = grouped.get(node.prop);
948
- if (list) {
949
- list.push(node);
950
- } else {
951
- grouped.set(node.prop, [node]);
952
- }
1128
+ function dedupeSpacingGroup(rule, declarations) {
1129
+ if (declarations.length <= 1) {
1130
+ return;
953
1131
  }
954
- for (const [, declarations] of grouped) {
955
- if (declarations.length <= 1) {
1132
+ const unique = [];
1133
+ const seenValues = /* @__PURE__ */ new Set();
1134
+ for (const decl of declarations) {
1135
+ if (decl.parent !== rule) {
956
1136
  continue;
957
1137
  }
958
- const unique = [];
959
- const seenValues = /* @__PURE__ */ new Set();
960
- for (const decl of declarations) {
961
- if (decl.parent !== rule) {
962
- continue;
963
- }
964
- const key = `${decl.important ? "!important@@" : ""}${decl.value}`;
965
- if (seenValues.has(key)) {
966
- decl.remove();
967
- continue;
968
- }
969
- seenValues.add(key);
970
- unique.push(decl);
971
- }
972
- if (unique.length <= 1) {
1138
+ const key = `${decl.important ? "!important@@" : ""}${decl.value}`;
1139
+ if (seenValues.has(key)) {
1140
+ decl.remove();
973
1141
  continue;
974
1142
  }
975
- reorderLiteralFirst(
976
- rule,
977
- unique,
978
- (decl) => VAR_REFERENCE_PATTERN.test(decl.value)
979
- );
1143
+ seenValues.add(key);
1144
+ unique.push(decl);
980
1145
  }
1146
+ if (unique.length <= 1) {
1147
+ return;
1148
+ }
1149
+ reorderLiteralFirst(
1150
+ rule,
1151
+ unique,
1152
+ (decl) => VAR_REFERENCE_PATTERN.test(decl.value)
1153
+ );
981
1154
  }
982
1155
  function isNotLastChildPseudo(node) {
983
1156
  if (!node || node.type !== "pseudo" || node.value !== ":not") {
@@ -1018,6 +1191,7 @@ function transformSpacingSelector(nodes2, options) {
1018
1191
  return false;
1019
1192
  }
1020
1193
  function normalizeSpacingDeclarations(rule) {
1194
+ const grouped = /* @__PURE__ */ new Map();
1021
1195
  for (const node of [...rule.nodes]) {
1022
1196
  if (node.type !== "decl") {
1023
1197
  continue;
@@ -1030,8 +1204,19 @@ function normalizeSpacingDeclarations(rule) {
1030
1204
  if (mirror) {
1031
1205
  node.prop = mirror;
1032
1206
  }
1207
+ if (!SPACING_PROP_SET.has(node.prop)) {
1208
+ continue;
1209
+ }
1210
+ const declarations = grouped.get(node.prop);
1211
+ if (declarations) {
1212
+ declarations.push(node);
1213
+ } else {
1214
+ grouped.set(node.prop, [node]);
1215
+ }
1216
+ }
1217
+ for (const declarations of grouped.values()) {
1218
+ dedupeSpacingGroup(rule, declarations);
1033
1219
  }
1034
- dedupeSpacingProps(rule);
1035
1220
  }
1036
1221
 
1037
1222
  // src/selectorParser/rule-transformer.ts
@@ -1105,16 +1290,14 @@ function handleClassNode(node, context) {
1105
1290
  if (node.type !== "class") {
1106
1291
  return;
1107
1292
  }
1108
- const { escapeMap } = context.options;
1109
- node.value = escapeMap === void 0 ? internalCssSelectorReplacer(node.value, {}) : internalCssSelectorReplacer(node.value, { escapeMap });
1293
+ node.value = context.selectorReplacerOptions === void 0 ? internalCssSelectorReplacer(node.value) : internalCssSelectorReplacer(node.value, context.selectorReplacerOptions);
1110
1294
  }
1111
1295
  function handleUniversalNode(node, context) {
1112
1296
  if (node.type !== "universal") {
1113
1297
  return;
1114
1298
  }
1115
- const replacement = context.options.cssSelectorReplacement?.universal;
1116
- if (replacement) {
1117
- node.value = composeIsPseudo(replacement);
1299
+ if (context.universalReplacement) {
1300
+ node.value = context.universalReplacement;
1118
1301
  }
1119
1302
  }
1120
1303
  function shouldRemoveHoverSelector(selector, options) {
@@ -1174,8 +1357,8 @@ function handlePseudoNode(node, index, context, parent) {
1174
1357
  stripUnsupportedRtlLanguagePseudo(node);
1175
1358
  return;
1176
1359
  }
1177
- if (node.value === ":root" && context.options.cssSelectorReplacement?.root) {
1178
- node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
1360
+ if (node.value === ":root" && context.rootReplacement) {
1361
+ node.value = context.rootReplacement;
1179
1362
  return;
1180
1363
  }
1181
1364
  if (node.value === ":where") {
@@ -1254,6 +1437,9 @@ function createRuleTransformer(options) {
1254
1437
  let context;
1255
1438
  const selectorResultCache = /* @__PURE__ */ new Map();
1256
1439
  const selectorResultCacheLimit = 5e4;
1440
+ const rootReplacement = options.cssSelectorReplacement?.root ? composeIsPseudo(options.cssSelectorReplacement.root) : void 0;
1441
+ const universalReplacement = options.cssSelectorReplacement?.universal ? composeIsPseudo(options.cssSelectorReplacement.universal) : void 0;
1442
+ const selectorReplacerOptions = options.escapeMap ? { escapeMap: options.escapeMap } : void 0;
1257
1443
  function writeSelectorResultCache(selector, result) {
1258
1444
  if (selectorResultCache.size >= selectorResultCacheLimit) {
1259
1445
  selectorResultCache.clear();
@@ -1288,7 +1474,10 @@ function createRuleTransformer(options) {
1288
1474
  context = {
1289
1475
  options,
1290
1476
  requiresSpacingNormalization: false,
1291
- rule
1477
+ rule,
1478
+ rootReplacement,
1479
+ universalReplacement,
1480
+ selectorReplacerOptions
1292
1481
  };
1293
1482
  let wasRemoved = false;
1294
1483
  let requiresSpacingNormalization = false;
@@ -1360,6 +1549,8 @@ var variablePriorityProps = /* @__PURE__ */ new Set([
1360
1549
  function getCanonicalProp(prop) {
1361
1550
  return logicalPropMap.get(prop) ?? prop;
1362
1551
  }
1552
+ var NESTED_CALC_RE = /calc\(\s*calc\(/gi;
1553
+ var CALC_WRAP_RE = /calc\(\s*(1\s*-\s*var\([^()]+\))\s*\)/gi;
1363
1554
  function normalizeCalcValue(value) {
1364
1555
  if (!value.includes("calc")) {
1365
1556
  return value;
@@ -1368,9 +1559,11 @@ function normalizeCalcValue(value) {
1368
1559
  let prev;
1369
1560
  do {
1370
1561
  prev = next;
1371
- next = prev.replace(/calc\(\s*calc\(/gi, "calc((");
1562
+ NESTED_CALC_RE.lastIndex = 0;
1563
+ next = prev.replace(NESTED_CALC_RE, "calc((");
1372
1564
  } while (next !== prev);
1373
- return next.replace(/calc\(\s*(1\s*-\s*var\([^()]+\))\s*\)/gi, "($1)");
1565
+ CALC_WRAP_RE.lastIndex = 0;
1566
+ return next.replace(CALC_WRAP_RE, "($1)");
1374
1567
  }
1375
1568
  function hasVariableReference(value) {
1376
1569
  return value.includes("var(");
@@ -1515,16 +1708,19 @@ function normalizeRootSelectors(value) {
1515
1708
  }
1516
1709
  return Array.isArray(value) ? value.filter(Boolean) : [value];
1517
1710
  }
1518
- function shouldAppendHostSelector(rule, options) {
1519
- const selectors = rule.selectors ?? [];
1520
- if (selectors.includes(":host")) {
1521
- return false;
1522
- }
1711
+ function createHostSelectorAppender(options) {
1523
1712
  const rootSelectors = normalizeRootSelectors(options.cssSelectorReplacement?.root);
1524
- if (rootSelectors.length !== DEFAULT_ROOT_SELECTORS.length || !rootSelectors.every((selector, index) => selector === DEFAULT_ROOT_SELECTORS[index])) {
1525
- return false;
1713
+ const shouldAppendHostSelector = rootSelectors.length === DEFAULT_ROOT_SELECTORS.length && rootSelectors.every((selector, index) => selector === DEFAULT_ROOT_SELECTORS[index]);
1714
+ if (!shouldAppendHostSelector) {
1715
+ return void 0;
1526
1716
  }
1527
- return DEFAULT_ROOT_SELECTORS.every((selector) => selectors.includes(selector));
1717
+ return (rule) => {
1718
+ const selectors = rule.selectors ?? [];
1719
+ if (selectors.includes(":host")) {
1720
+ return false;
1721
+ }
1722
+ return DEFAULT_ROOT_SELECTORS.every((selector) => selectors.includes(selector));
1723
+ };
1528
1724
  }
1529
1725
  var postcssWeappTailwindcssPostPlugin = (options) => {
1530
1726
  const opts = defu(options, {
@@ -1534,6 +1730,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1534
1730
  postcssPlugin
1535
1731
  };
1536
1732
  const cleanRootSpecificity = createRootSpecificityCleaner(opts);
1733
+ const shouldAppendHostSelector = createHostSelectorAppender(opts);
1537
1734
  const enableMainChunkTransforms = opts.isMainChunk !== false;
1538
1735
  if (enableMainChunkTransforms || cleanRootSpecificity) {
1539
1736
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
@@ -1543,7 +1740,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1543
1740
  }
1544
1741
  cleanRootSpecificity?.(rule);
1545
1742
  if (enableMainChunkTransforms) {
1546
- if (shouldAppendHostSelector(rule, opts)) {
1743
+ if (shouldAppendHostSelector?.(rule)) {
1547
1744
  rule.selectors = [...rule.selectors, ":host"];
1548
1745
  }
1549
1746
  dedupeDeclarations(rule);
@@ -1884,8 +2081,11 @@ function commonChunkPreflight(node, options) {
1884
2081
  }
1885
2082
 
1886
2083
  // src/plugins/pre.ts
2084
+ var MEDIA_HOVER_NAME_RE = /media\(\s*hover\s*:\s*hover\s*\)/;
2085
+ var MEDIA_HOVER_PARAMS_RE = /\(\s*hover\s*:\s*hover\s*\)/;
2086
+ var COLOR_MIX_RE = /color-mix/;
1887
2087
  function isAtMediaHover(atRule) {
1888
- return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
2088
+ return MEDIA_HOVER_NAME_RE.test(atRule.name) || atRule.name === "media" && MEDIA_HOVER_PARAMS_RE.test(atRule.params);
1889
2089
  }
1890
2090
  var postcssWeappTailwindcssPrePlugin = (options) => {
1891
2091
  const opts = defu2(options, { isMainChunk: true });
@@ -1902,7 +2102,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1902
2102
  atRule.remove();
1903
2103
  }
1904
2104
  } else if (atRule.name === "supports") {
1905
- if (/color-mix/.test(atRule.params)) {
2105
+ if (COLOR_MIX_RE.test(atRule.params)) {
1906
2106
  atRule.remove();
1907
2107
  }
1908
2108
  } else if (atRule.name === "layer") {
@@ -1947,7 +2147,6 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1947
2147
  postcssWeappTailwindcssPrePlugin.postcss = true;
1948
2148
 
1949
2149
  // src/pipeline.ts
1950
- var STAGE_ORDER = ["pre", "normal", "post"];
1951
2150
  function normalizeUserPlugins(plugins) {
1952
2151
  if (!plugins) {
1953
2152
  return [];
@@ -1960,140 +2159,52 @@ function normalizeUserPlugins(plugins) {
1960
2159
  }
1961
2160
  return [];
1962
2161
  }
1963
- function createStaticDefinition(id, stage, plugin) {
2162
+ function createPreparedNode(id, stage, createPlugin) {
1964
2163
  return {
1965
2164
  id,
1966
2165
  stage,
1967
- prepare: () => ({
1968
- id,
1969
- stage,
1970
- createPlugin: () => plugin
1971
- })
2166
+ createPlugin
1972
2167
  };
1973
2168
  }
1974
- function createPipelineDefinitions(options) {
1975
- const stages = {
1976
- pre: [],
1977
- normal: [],
1978
- post: []
1979
- };
2169
+ function createPreparedNodes(options) {
2170
+ const preparedNodes = [];
1980
2171
  const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
1981
2172
  userPlugins.forEach((plugin, index) => {
1982
- stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
1983
- });
1984
- stages.pre.push({
1985
- id: "pre:core",
1986
- stage: "pre",
1987
- prepare: () => ({
1988
- id: "pre:core",
1989
- stage: "pre",
1990
- createPlugin: () => postcssWeappTailwindcssPrePlugin(options)
1991
- })
1992
- });
1993
- stages.normal.push({
1994
- id: "normal:preset-env",
1995
- stage: "normal",
1996
- prepare: () => ({
1997
- id: "normal:preset-env",
1998
- stage: "normal",
1999
- createPlugin: () => postcssPresetEnv(options.cssPresetEnv)
2000
- })
2001
- });
2002
- stages.normal.push({
2003
- id: "normal:color-functional-fallback",
2004
- stage: "normal",
2005
- prepare: () => ({
2006
- id: "normal:color-functional-fallback",
2007
- stage: "normal",
2008
- createPlugin: () => createColorFunctionalFallback()
2009
- })
2010
- });
2011
- stages.normal.push({
2012
- id: "normal:units-to-px",
2013
- stage: "normal",
2014
- prepare: () => {
2015
- const plugin = getUnitsToPxPlugin(options);
2016
- return plugin ? {
2017
- id: "normal:units-to-px",
2018
- stage: "normal",
2019
- createPlugin: () => plugin
2020
- } : void 0;
2021
- }
2173
+ preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2022
2174
  });
2023
- stages.normal.push({
2024
- id: "normal:px-transform",
2025
- stage: "normal",
2026
- prepare: () => {
2027
- const plugin = getPxTransformPlugin(options);
2028
- return plugin ? {
2029
- id: "normal:px-transform",
2030
- stage: "normal",
2031
- createPlugin: () => plugin
2032
- } : void 0;
2033
- }
2034
- });
2035
- stages.normal.push({
2036
- id: "normal:rem-transform",
2037
- stage: "normal",
2038
- prepare: () => {
2039
- const plugin = getRemTransformPlugin(options);
2040
- return plugin ? {
2041
- id: "normal:rem-transform",
2042
- stage: "normal",
2043
- createPlugin: () => plugin
2044
- } : void 0;
2045
- }
2046
- });
2047
- stages.normal.push({
2048
- id: "normal:calc",
2049
- stage: "normal",
2050
- prepare: () => {
2051
- const plugin = getCalcPlugin(options);
2052
- return plugin ? {
2053
- id: "normal:calc",
2054
- stage: "normal",
2055
- createPlugin: () => plugin
2056
- } : void 0;
2057
- }
2058
- });
2059
- stages.normal.push({
2060
- id: "normal:calc-duplicate-cleaner",
2061
- stage: "normal",
2062
- prepare: () => {
2063
- const plugin = getCalcDuplicateCleaner(options);
2064
- return plugin ? {
2065
- id: "normal:calc-duplicate-cleaner",
2066
- stage: "normal",
2067
- createPlugin: () => plugin
2068
- } : void 0;
2069
- }
2070
- });
2071
- stages.normal.push({
2072
- id: "normal:custom-property-cleaner",
2073
- stage: "normal",
2074
- prepare: () => {
2075
- const plugin = getCustomPropertyCleaner(options);
2076
- return plugin ? {
2077
- id: "normal:custom-property-cleaner",
2078
- stage: "normal",
2079
- createPlugin: () => plugin
2080
- } : void 0;
2081
- }
2082
- });
2083
- stages.post.push({
2084
- id: "post:core",
2085
- stage: "post",
2086
- prepare: () => ({
2087
- id: "post:core",
2088
- stage: "post",
2089
- createPlugin: () => postcssWeappTailwindcssPostPlugin(options)
2090
- })
2091
- });
2092
- return STAGE_ORDER.flatMap((stage) => stages[stage]);
2175
+ preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
2176
+ preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(options.cssPresetEnv)));
2177
+ preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
2178
+ const unitsToPxPlugin = getUnitsToPxPlugin(options);
2179
+ if (unitsToPxPlugin) {
2180
+ preparedNodes.push(createPreparedNode("normal:units-to-px", "normal", () => unitsToPxPlugin));
2181
+ }
2182
+ const pxTransformPlugin = getPxTransformPlugin(options);
2183
+ if (pxTransformPlugin) {
2184
+ preparedNodes.push(createPreparedNode("normal:px-transform", "normal", () => pxTransformPlugin));
2185
+ }
2186
+ const remTransformPlugin = getRemTransformPlugin(options);
2187
+ if (remTransformPlugin) {
2188
+ preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
2189
+ }
2190
+ const calcPlugin = getCalcPlugin(options);
2191
+ if (calcPlugin) {
2192
+ preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
2193
+ }
2194
+ const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
2195
+ if (calcDuplicateCleaner) {
2196
+ preparedNodes.push(createPreparedNode("normal:calc-duplicate-cleaner", "normal", () => calcDuplicateCleaner));
2197
+ }
2198
+ const customPropertyCleaner = getCustomPropertyCleaner(options);
2199
+ if (customPropertyCleaner) {
2200
+ preparedNodes.push(createPreparedNode("normal:custom-property-cleaner", "normal", () => customPropertyCleaner));
2201
+ }
2202
+ preparedNodes.push(createPreparedNode("post:core", "post", () => postcssWeappTailwindcssPostPlugin(options)));
2203
+ return preparedNodes;
2093
2204
  }
2094
2205
  function createStylePipeline(options) {
2095
2206
  options.ctx = createContext();
2096
- const preparedNodes = createPipelineDefinitions(options).map((definition) => definition.prepare(options)).filter(Boolean);
2207
+ const preparedNodes = createPreparedNodes(options);
2097
2208
  if (preparedNodes.length === 0) {
2098
2209
  return {
2099
2210
  nodes: [],
@@ -2155,6 +2266,35 @@ function createProcessOptions(options) {
2155
2266
  ...options.postcssOptions?.options ?? {}
2156
2267
  };
2157
2268
  }
2269
+ function getSimpleProcessOptionsCacheKey(options) {
2270
+ const parts = ["simple"];
2271
+ for (const key of Object.keys(options).sort()) {
2272
+ const value = options[key];
2273
+ switch (typeof value) {
2274
+ case "string":
2275
+ parts.push(`${key}:str:${value}`);
2276
+ break;
2277
+ case "number":
2278
+ parts.push(`${key}:num:${value}`);
2279
+ break;
2280
+ case "boolean":
2281
+ parts.push(`${key}:bool:${value ? "1" : "0"}`);
2282
+ break;
2283
+ case "undefined":
2284
+ parts.push(`${key}:undefined`);
2285
+ break;
2286
+ case "object":
2287
+ if (value === null) {
2288
+ parts.push(`${key}:null`);
2289
+ break;
2290
+ }
2291
+ return void 0;
2292
+ default:
2293
+ return void 0;
2294
+ }
2295
+ }
2296
+ return parts.join("|");
2297
+ }
2158
2298
  var StyleProcessorCache = class {
2159
2299
  pipelineCache = /* @__PURE__ */ new WeakMap();
2160
2300
  processOptionsCache = /* @__PURE__ */ new WeakMap();
@@ -2187,11 +2327,11 @@ var StyleProcessorCache = class {
2187
2327
  }
2188
2328
  getProcessOptions(options) {
2189
2329
  const source = options.postcssOptions?.options;
2190
- const fingerprint = source ? fingerprintOptions(source) : void 0;
2330
+ const cacheKey = source ? getSimpleProcessOptionsCacheKey(source) ?? fingerprintOptions(source) : void 0;
2191
2331
  const cached = this.processOptionsCache.get(options);
2192
- if (!cached || cached.fingerprint !== fingerprint) {
2332
+ if (!cached || cached.cacheKey !== cacheKey) {
2193
2333
  const created = createProcessOptions(options);
2194
- this.processOptionsCache.set(options, { value: created, fingerprint });
2334
+ this.processOptionsCache.set(options, { value: created, cacheKey });
2195
2335
  return { ...created };
2196
2336
  }
2197
2337
  return { ...cached.value };