@weapp-tailwindcss/postcss 2.0.4 → 2.0.5

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.
Files changed (3) hide show
  1. package/dist/index.js +254 -221
  2. package/dist/index.mjs +231 -198
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -276,6 +276,227 @@ function getRemTransformPlugin(options) {
276
276
  // src/plugins/post.ts
277
277
 
278
278
 
279
+ // src/compat/tailwindcss-v4.ts
280
+
281
+
282
+ // src/cssVarsV4.ts
283
+ function property(ident, initialValue, _syntax) {
284
+ return {
285
+ prop: ident,
286
+ value: initialValue || ""
287
+ };
288
+ }
289
+ var nullShadow = "0 0 #0000";
290
+ var nodes = [
291
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
292
+ property("--tw-border-spacing-x", "0", "<length>"),
293
+ property("--tw-border-spacing-y", "0", "<length>"),
294
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
295
+ property("--tw-translate-x", "0"),
296
+ property("--tw-translate-y", "0"),
297
+ property("--tw-translate-z", "0"),
298
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
299
+ property("--tw-scale-x", "1"),
300
+ property("--tw-scale-y", "1"),
301
+ property("--tw-scale-z", "1"),
302
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
303
+ property("--tw-rotate-x"),
304
+ property("--tw-rotate-y"),
305
+ property("--tw-rotate-z"),
306
+ property("--tw-skew-x"),
307
+ property("--tw-skew-y"),
308
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
309
+ property("--tw-pan-x"),
310
+ property("--tw-pan-y"),
311
+ property("--tw-pinch-zoom"),
312
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
313
+ property("--tw-scroll-snap-strictness", "proximity", "*"),
314
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
315
+ property("--tw-space-x-reverse", "0"),
316
+ property("--tw-space-y-reverse", "0"),
317
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
318
+ property("--tw-border-style", "solid"),
319
+ property("--tw-divide-x-reverse", "0"),
320
+ property("--tw-divide-y-reverse", "0"),
321
+ property("--tw-gradient-position", "initial"),
322
+ property("--tw-gradient-from", "#0000", "<color>"),
323
+ property("--tw-gradient-via", "#0000", "<color>"),
324
+ property("--tw-gradient-to", "#0000", "<color>"),
325
+ property("--tw-gradient-stops", "initial"),
326
+ property("--tw-gradient-via-stops", "initial"),
327
+ property("--tw-gradient-from-position", "0%", "<length-percentage>"),
328
+ property("--tw-gradient-via-position", "50%", "<length-percentage>"),
329
+ property("--tw-gradient-to-position", "100%", "<length-percentage>"),
330
+ property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
331
+ property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
332
+ property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
333
+ property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
334
+ property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
335
+ property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
336
+ property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
337
+ property("--tw-mask-linear-position", "0deg"),
338
+ property("--tw-mask-linear-from-position", "0%"),
339
+ property("--tw-mask-linear-to-position", "100%"),
340
+ property("--tw-mask-linear-from-color", "black"),
341
+ property("--tw-mask-linear-to-color", "transparent"),
342
+ property("--tw-mask-radial-from-position", "0%"),
343
+ property("--tw-mask-radial-to-position", "100%"),
344
+ property("--tw-mask-radial-from-color", "black"),
345
+ property("--tw-mask-radial-to-color", "transparent"),
346
+ property("--tw-mask-radial-shape", "ellipse"),
347
+ property("--tw-mask-radial-size", "farthest-corner"),
348
+ property("--tw-mask-radial-position", "center"),
349
+ property("--tw-mask-conic-position", "0deg"),
350
+ property("--tw-mask-conic-from-position", "0%"),
351
+ property("--tw-mask-conic-to-position", "100%"),
352
+ property("--tw-mask-conic-from-color", "black"),
353
+ property("--tw-mask-conic-to-color", "transparent"),
354
+ property("--tw-font-weight"),
355
+ property("--tw-blur"),
356
+ property("--tw-brightness"),
357
+ property("--tw-contrast"),
358
+ property("--tw-grayscale"),
359
+ property("--tw-hue-rotate"),
360
+ property("--tw-invert"),
361
+ property("--tw-opacity"),
362
+ property("--tw-saturate"),
363
+ property("--tw-sepia"),
364
+ property("--tw-drop-shadow"),
365
+ property("--tw-drop-shadow-color"),
366
+ property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
367
+ property("--tw-drop-shadow-size"),
368
+ property("--tw-backdrop-blur"),
369
+ property("--tw-backdrop-brightness"),
370
+ property("--tw-backdrop-contrast"),
371
+ property("--tw-backdrop-grayscale"),
372
+ property("--tw-backdrop-hue-rotate"),
373
+ property("--tw-backdrop-invert"),
374
+ property("--tw-backdrop-opacity"),
375
+ property("--tw-backdrop-saturate"),
376
+ property("--tw-backdrop-sepia"),
377
+ property("--tw-duration", "initial"),
378
+ property("--tw-ease", "initial"),
379
+ property("--tw-content", '""'),
380
+ property("--tw-contain-size"),
381
+ property("--tw-contain-layout"),
382
+ property("--tw-contain-paint"),
383
+ property("--tw-contain-style"),
384
+ property("--tw-leading"),
385
+ property("--tw-tracking"),
386
+ property("--tw-ordinal"),
387
+ property("--tw-slashed-zero"),
388
+ property("--tw-numeric-figure"),
389
+ property("--tw-numeric-spacing"),
390
+ property("--tw-numeric-fraction"),
391
+ property("--tw-outline-style", "solid"),
392
+ property("--tw-text-shadow-color", "initial"),
393
+ property("--tw-text-shadow-alpha", "100%", "<percentage>"),
394
+ property("--tw-shadow", nullShadow),
395
+ property("--tw-shadow-color", "initial"),
396
+ property("--tw-shadow-alpha", "100%", "<percentage>"),
397
+ property("--tw-inset-shadow", nullShadow),
398
+ property("--tw-inset-shadow-color", "initial"),
399
+ property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
400
+ property("--tw-ring-color"),
401
+ property("--tw-ring-shadow", nullShadow),
402
+ property("--tw-inset-ring-color"),
403
+ property("--tw-inset-ring-shadow", nullShadow),
404
+ // Legacy 旧版变量兼容
405
+ property("--tw-ring-inset"),
406
+ property("--tw-ring-offset-width", "0px", "<length>"),
407
+ property("--tw-ring-offset-color", "#fff"),
408
+ property("--tw-ring-offset-shadow", nullShadow)
409
+ ];
410
+ for (const edge of ["top", "right", "bottom", "left"]) {
411
+ nodes.push(
412
+ property(`--tw-mask-${edge}-from-position`, "0%"),
413
+ property(`--tw-mask-${edge}-to-position`, "100%"),
414
+ property(`--tw-mask-${edge}-from-color`, "black"),
415
+ property(`--tw-mask-${edge}-to-color`, "transparent")
416
+ );
417
+ }
418
+ var cssVarsV4_default = nodes;
419
+
420
+ // src/compat/tailwindcss-v4.ts
421
+ var OKLAB_SUFFIX = "in oklab";
422
+ var INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
423
+ var RADIUS_THRESHOLD = 1e5;
424
+ var CLAMP_PX = 9999;
425
+ function isTailwindcssV4(options) {
426
+ return _optionalChain([options, 'optionalAccess', _12 => _12.majorVersion]) === 4;
427
+ }
428
+ function testIfRootHostForV4(node) {
429
+ return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
430
+ }
431
+ var cssVarsV4Nodes = cssVarsV4_default.map((x) => {
432
+ return new (0, _postcss.Declaration)({
433
+ prop: x.prop,
434
+ value: x.value
435
+ });
436
+ });
437
+ function isTailwindcssV4ModernCheck(atRule) {
438
+ return atRule.name === "supports" && [
439
+ /-webkit-hyphens\s*:\s*none/,
440
+ /margin-trim\s*:\s*inline/,
441
+ /-moz-orient\s*:\s*inline/,
442
+ /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/
443
+ ].every((regex) => regex.test(atRule.params));
444
+ }
445
+ function normalizeTailwindcssV4Declaration(decl) {
446
+ if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
447
+ decl.value = decl.value.slice(0, decl.value.length - OKLAB_SUFFIX.length);
448
+ return true;
449
+ }
450
+ if (INFINITY_CALC_REGEXP.test(decl.value)) {
451
+ decl.value = `${CLAMP_PX}px`;
452
+ return true;
453
+ }
454
+ if (decl.prop.includes("radius")) {
455
+ const next = decl.value.replace(
456
+ /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi,
457
+ (m, num) => {
458
+ const n = Number(num);
459
+ if (!Number.isFinite(n)) {
460
+ return `${CLAMP_PX}px`;
461
+ }
462
+ if (/e/i.test(String(num)) || n > RADIUS_THRESHOLD) {
463
+ return `${CLAMP_PX}px`;
464
+ }
465
+ return m;
466
+ }
467
+ );
468
+ if (next !== decl.value) {
469
+ decl.value = next;
470
+ return true;
471
+ }
472
+ }
473
+ return false;
474
+ }
475
+
476
+ // src/compat/uni-app-x.ts
477
+ function isUniAppXEnabled(options) {
478
+ return Boolean(_optionalChain([options, 'optionalAccess', _13 => _13.uniAppX]));
479
+ }
480
+ function stripUnsupportedPseudoForUniAppX(node, enabled) {
481
+ if (!enabled) {
482
+ return;
483
+ }
484
+ node.remove();
485
+ }
486
+ function stripUnsupportedNodeForUniAppX(node, options) {
487
+ if (!isUniAppXEnabled(options)) {
488
+ return false;
489
+ }
490
+ if (node.type === "tag" || node.type === "attribute" || node.type === "pseudo") {
491
+ node.remove();
492
+ return true;
493
+ }
494
+ return false;
495
+ }
496
+ function shouldRemoveEmptyRuleForUniAppX(rule, options) {
497
+ return isUniAppXEnabled(options) && rule.nodes.length === 0;
498
+ }
499
+
279
500
  // src/constants.ts
280
501
  var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
281
502
 
@@ -288,7 +509,7 @@ var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors)
288
509
  return;
289
510
  }
290
511
  selectors.walkPseudos((s) => {
291
- if (_optionalChain([s, 'access', _12 => _12.parent, 'optionalAccess', _13 => _13.length]) === 1) {
512
+ if (_optionalChain([s, 'access', _14 => _14.parent, 'optionalAccess', _15 => _15.length]) === 1) {
292
513
  if (/^:?:before$/.test(s.value)) {
293
514
  state.before = true;
294
515
  }
@@ -366,7 +587,7 @@ function getFallbackRemove(_rule, options) {
366
587
  const cacheKey = _nullishCoalesce(options, () => ( fallbackDefaultKey));
367
588
  let entry = fallbackRemoveCache.get(cacheKey);
368
589
  if (!entry) {
369
- const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _14 => _14.uniAppX]));
590
+ const uniAppX = isUniAppXEnabled(options);
370
591
  let currentRule;
371
592
  const parser = _postcssselectorparser2.default.call(void 0, (selectors) => {
372
593
  const activeRule = currentRule;
@@ -376,13 +597,13 @@ function getFallbackRemove(_rule, options) {
376
597
  maybeImportantId = true;
377
598
  }
378
599
  if (selector.type === "universal") {
379
- _optionalChain([selector, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.remove, 'call', _17 => _17()]);
600
+ _optionalChain([selector, 'access', _16 => _16.parent, 'optionalAccess', _17 => _17.remove, 'call', _18 => _18()]);
380
601
  } else if (selector.type === "pseudo") {
381
602
  if (selector.value === ":is") {
382
- if (maybeImportantId && _optionalChain([selector, 'access', _18 => _18.nodes, 'access', _19 => _19[0], 'optionalAccess', _20 => _20.type]) === "selector") {
603
+ if (maybeImportantId && _optionalChain([selector, 'access', _19 => _19.nodes, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.type]) === "selector") {
383
604
  selector.replaceWith(selector.nodes[0]);
384
605
  } else {
385
- _optionalChain([selector, 'access', _21 => _21.parent, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
606
+ _optionalChain([selector, 'access', _22 => _22.parent, 'optionalAccess', _23 => _23.remove, 'call', _24 => _24()]);
386
607
  }
387
608
  } else if (selector.value === ":not") {
388
609
  for (const x of selector.nodes) {
@@ -405,7 +626,7 @@ function getFallbackRemove(_rule, options) {
405
626
  }
406
627
  } else if (selector.type === "attribute") {
407
628
  if (selector.attribute === "hidden") {
408
- _optionalChain([activeRule, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
629
+ _optionalChain([activeRule, 'optionalAccess', _25 => _25.remove, 'call', _26 => _26()]);
409
630
  }
410
631
  }
411
632
  });
@@ -417,9 +638,7 @@ function getFallbackRemove(_rule, options) {
417
638
  selector.remove();
418
639
  }
419
640
  } else if (selector.type === "pseudo") {
420
- if (uniAppX) {
421
- selector.remove();
422
- }
641
+ stripUnsupportedPseudoForUniAppX(selector, uniAppX);
423
642
  }
424
643
  }
425
644
  });
@@ -553,7 +772,7 @@ function dedupeSpacingProps(rule) {
553
772
  if (alreadyOrdered) {
554
773
  continue;
555
774
  }
556
- const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _26 => _26[unique.length - 1], 'optionalAccess', _27 => _27.next, 'call', _28 => _28()]), () => ( void 0));
775
+ const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _27 => _27[unique.length - 1], 'optionalAccess', _28 => _28.next, 'call', _29 => _29()]), () => ( void 0));
557
776
  for (const decl of unique) {
558
777
  decl.remove();
559
778
  }
@@ -578,7 +797,7 @@ function isNotLastChildPseudo(node) {
578
797
  if (firstSelector.type !== "selector") {
579
798
  return false;
580
799
  }
581
- const target = _optionalChain([firstSelector, 'access', _29 => _29.nodes, 'optionalAccess', _30 => _30[0]]);
800
+ const target = _optionalChain([firstSelector, 'access', _30 => _30.nodes, 'optionalAccess', _31 => _31[0]]);
582
801
  return Boolean(target && target.type === "pseudo" && target.value === ":last-child");
583
802
  }
584
803
  function transformSpacingSelector(nodes2, options) {
@@ -621,11 +840,11 @@ function normalizeSpacingDeclarations(rule) {
621
840
  dedupeSpacingProps(rule);
622
841
  }
623
842
  function flattenWherePseudo(node, context, index, parent) {
624
- if (context.options.uniAppX) {
843
+ if (isUniAppXEnabled(context.options)) {
625
844
  node.value = ":is";
626
845
  }
627
846
  if (index === 0 && node.length === 1) {
628
- const targetSelector = _optionalChain([node, 'access', _31 => _31.nodes, 'optionalAccess', _32 => _32[0]]);
847
+ const targetSelector = _optionalChain([node, 'access', _32 => _32.nodes, 'optionalAccess', _33 => _33[0]]);
629
848
  if (targetSelector && targetSelector.type === "selector" && transformSpacingSelector(targetSelector.nodes, context.options)) {
630
849
  context.requiresSpacingNormalization = true;
631
850
  }
@@ -645,7 +864,7 @@ function handleUniversalNode(node, context) {
645
864
  if (node.type !== "universal") {
646
865
  return;
647
866
  }
648
- const replacement = _optionalChain([context, 'access', _33 => _33.options, 'access', _34 => _34.cssSelectorReplacement, 'optionalAccess', _35 => _35.universal]);
867
+ const replacement = _optionalChain([context, 'access', _34 => _34.options, 'access', _35 => _35.cssSelectorReplacement, 'optionalAccess', _36 => _36.universal]);
649
868
  if (replacement) {
650
869
  node.value = composeIsPseudo(replacement);
651
870
  }
@@ -680,7 +899,7 @@ function handleCombinatorNode(node, index, context) {
680
899
  if (node.type !== "combinator" || node.value !== ">") {
681
900
  return;
682
901
  }
683
- const nodes2 = _optionalChain([node, 'access', _36 => _36.parent, 'optionalAccess', _37 => _37.nodes]);
902
+ const nodes2 = _optionalChain([node, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.nodes]);
684
903
  if (!nodes2) {
685
904
  return;
686
905
  }
@@ -696,7 +915,7 @@ function handlePseudoNode(node, index, context, parent) {
696
915
  if (node.type !== "pseudo") {
697
916
  return;
698
917
  }
699
- if (node.value === ":root" && _optionalChain([context, 'access', _38 => _38.options, 'access', _39 => _39.cssSelectorReplacement, 'optionalAccess', _40 => _40.root])) {
918
+ if (node.value === ":root" && _optionalChain([context, 'access', _39 => _39.options, 'access', _40 => _40.cssSelectorReplacement, 'optionalAccess', _41 => _41.root])) {
700
919
  node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
701
920
  return;
702
921
  }
@@ -705,12 +924,7 @@ function handlePseudoNode(node, index, context, parent) {
705
924
  }
706
925
  }
707
926
  function handleTagOrAttribute(node, context) {
708
- if (!context.options.uniAppX) {
709
- return;
710
- }
711
- if (node.type === "tag" || node.type === "attribute") {
712
- node.remove();
713
- }
927
+ stripUnsupportedNodeForUniAppX(node, context.options);
714
928
  }
715
929
  function handleSelectorNode(selector, context) {
716
930
  if (shouldRemoveHoverSelector(selector, context.options)) {
@@ -723,7 +937,7 @@ function handleSelectorNode(selector, context) {
723
937
  }
724
938
  function transformSelectors(selectors, context) {
725
939
  selectors.walk((node, index) => {
726
- const parent = _optionalChain([node, 'access', _41 => _41.parent, 'optionalAccess', _42 => _42.type]) === "selector" ? node.parent : void 0;
940
+ const parent = _optionalChain([node, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.type]) === "selector" ? node.parent : void 0;
727
941
  switch (node.type) {
728
942
  case "class":
729
943
  handleClassNode(node, context);
@@ -801,7 +1015,7 @@ function normalizeSelectorList(value) {
801
1015
  return Array.isArray(value) ? value.filter(Boolean) : [value];
802
1016
  }
803
1017
  function getSpecificityMatchingName(options) {
804
- const feature = _optionalChain([options, 'access', _43 => _43.cssPresetEnv, 'optionalAccess', _44 => _44.features, 'optionalAccess', _45 => _45["is-pseudo-class"]]);
1018
+ const feature = _optionalChain([options, 'access', _44 => _44.cssPresetEnv, 'optionalAccess', _45 => _45.features, 'optionalAccess', _46 => _46["is-pseudo-class"]]);
805
1019
  if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
806
1020
  const specificityName = feature.specificityMatchingName;
807
1021
  return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
@@ -810,12 +1024,12 @@ function getSpecificityMatchingName(options) {
810
1024
  }
811
1025
  function createRootSpecificityCleaner(options) {
812
1026
  const specificityMatchingName = getSpecificityMatchingName(options);
813
- const selectors = normalizeSelectorList(_optionalChain([options, 'access', _46 => _46.cssSelectorReplacement, 'optionalAccess', _47 => _47.root]));
1027
+ const selectors = normalizeSelectorList(_optionalChain([options, 'access', _47 => _47.cssSelectorReplacement, 'optionalAccess', _48 => _48.root]));
814
1028
  if (!specificityMatchingName || selectors.length === 0) {
815
1029
  return void 0;
816
1030
  }
817
1031
  const suffix = `:not(.${specificityMatchingName})`;
818
- const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _48 => _48.trim, 'call', _49 => _49()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _50 => _50.length]))).map((selector) => ({
1032
+ const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _49 => _49.trim, 'call', _50 => _50()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _51 => _51.length]))).map((selector) => ({
819
1033
  match: `${selector}${suffix}`,
820
1034
  spacedMatch: `${selector} ${suffix}`,
821
1035
  replacement: selector
@@ -842,7 +1056,6 @@ function createRootSpecificityCleaner(options) {
842
1056
  rule.selectors = next;
843
1057
  };
844
1058
  }
845
- var OklabSuffix = "in oklab";
846
1059
  var logicalPropMap = /* @__PURE__ */ new Map([
847
1060
  // margin 方向映射
848
1061
  ["margin-inline-start", "margin-left"],
@@ -961,7 +1174,7 @@ function dedupeDeclarations(rule) {
961
1174
  if (!needReorder) {
962
1175
  continue;
963
1176
  }
964
- const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _51 => _51[declarations.length - 1], 'optionalAccess', _52 => _52.next, 'call', _53 => _53()]), () => ( void 0));
1177
+ const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _52 => _52[declarations.length - 1], 'optionalAccess', _53 => _53.next, 'call', _54 => _54()]), () => ( void 0));
965
1178
  for (const decl of declarations) {
966
1179
  decl.remove();
967
1180
  }
@@ -1006,52 +1219,27 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1006
1219
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
1007
1220
  p.RuleExit = (rule) => {
1008
1221
  if (enableMainChunkTransforms) {
1009
- _optionalChain([fallbackRemove, 'optionalAccess', _54 => _54.transformSync, 'call', _55 => _55(rule)]);
1222
+ _optionalChain([fallbackRemove, 'optionalAccess', _55 => _55.transformSync, 'call', _56 => _56(rule)]);
1010
1223
  }
1011
- _optionalChain([cleanRootSpecificity, 'optionalCall', _56 => _56(rule)]);
1224
+ _optionalChain([cleanRootSpecificity, 'optionalCall', _57 => _57(rule)]);
1012
1225
  if (enableMainChunkTransforms) {
1013
1226
  dedupeDeclarations(rule);
1014
1227
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
1015
1228
  rule.remove();
1016
1229
  }
1017
- if (opts.uniAppX && rule.nodes.length === 0) {
1230
+ if (shouldRemoveEmptyRuleForUniAppX(rule, opts)) {
1018
1231
  rule.remove();
1019
1232
  }
1020
1233
  }
1021
1234
  };
1022
1235
  }
1023
1236
  if (enableMainChunkTransforms) {
1024
- p.DeclarationExit = (decl) => {
1025
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
1026
- decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
1027
- } else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
1028
- decl.value = "9999px";
1029
- } else if (decl.prop.includes("radius")) {
1030
- const CLAMP_PX = 9999;
1031
- const THRESHOLD = 1e5;
1032
- const next = decl.value.replace(
1033
- /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi,
1034
- (m, num) => {
1035
- const n = Number(num);
1036
- if (!Number.isFinite(n)) {
1037
- return `${CLAMP_PX}px`;
1038
- }
1039
- if (/e/i.test(String(num)) || n > THRESHOLD) {
1040
- return `${CLAMP_PX}px`;
1041
- }
1042
- return m;
1043
- }
1044
- );
1045
- if (next !== decl.value) {
1046
- decl.value = next;
1047
- }
1048
- }
1049
- };
1237
+ p.DeclarationExit = (decl) => normalizeTailwindcssV4Declaration(decl);
1050
1238
  p.AtRuleExit = (atRule) => {
1051
1239
  if (opts.cssRemoveProperty && atRule.name === "property") {
1052
1240
  atRule.remove();
1053
1241
  }
1054
- _optionalChain([atRule, 'access', _57 => _57.nodes, 'optionalAccess', _58 => _58.length]) === 0 && atRule.remove();
1242
+ _optionalChain([atRule, 'access', _58 => _58.nodes, 'optionalAccess', _59 => _59.length]) === 0 && atRule.remove();
1055
1243
  };
1056
1244
  }
1057
1245
  return p;
@@ -1272,144 +1460,6 @@ var cssVarsV3_default = [
1272
1460
  }
1273
1461
  ];
1274
1462
 
1275
- // src/cssVarsV4.ts
1276
- function property(ident, initialValue, _syntax) {
1277
- return {
1278
- prop: ident,
1279
- value: initialValue || ""
1280
- };
1281
- }
1282
- var nullShadow = "0 0 #0000";
1283
- var nodes = [
1284
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1285
- property("--tw-border-spacing-x", "0", "<length>"),
1286
- property("--tw-border-spacing-y", "0", "<length>"),
1287
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1288
- property("--tw-translate-x", "0"),
1289
- property("--tw-translate-y", "0"),
1290
- property("--tw-translate-z", "0"),
1291
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1292
- property("--tw-scale-x", "1"),
1293
- property("--tw-scale-y", "1"),
1294
- property("--tw-scale-z", "1"),
1295
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1296
- property("--tw-rotate-x"),
1297
- property("--tw-rotate-y"),
1298
- property("--tw-rotate-z"),
1299
- property("--tw-skew-x"),
1300
- property("--tw-skew-y"),
1301
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1302
- property("--tw-pan-x"),
1303
- property("--tw-pan-y"),
1304
- property("--tw-pinch-zoom"),
1305
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1306
- property("--tw-scroll-snap-strictness", "proximity", "*"),
1307
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1308
- property("--tw-space-x-reverse", "0"),
1309
- property("--tw-space-y-reverse", "0"),
1310
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1311
- property("--tw-border-style", "solid"),
1312
- property("--tw-divide-x-reverse", "0"),
1313
- property("--tw-divide-y-reverse", "0"),
1314
- property("--tw-gradient-position", "initial"),
1315
- property("--tw-gradient-from", "#0000", "<color>"),
1316
- property("--tw-gradient-via", "#0000", "<color>"),
1317
- property("--tw-gradient-to", "#0000", "<color>"),
1318
- property("--tw-gradient-stops", "initial"),
1319
- property("--tw-gradient-via-stops", "initial"),
1320
- property("--tw-gradient-from-position", "0%", "<length-percentage>"),
1321
- property("--tw-gradient-via-position", "50%", "<length-percentage>"),
1322
- property("--tw-gradient-to-position", "100%", "<length-percentage>"),
1323
- property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
1324
- property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
1325
- property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
1326
- property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
1327
- property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
1328
- property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
1329
- property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
1330
- property("--tw-mask-linear-position", "0deg"),
1331
- property("--tw-mask-linear-from-position", "0%"),
1332
- property("--tw-mask-linear-to-position", "100%"),
1333
- property("--tw-mask-linear-from-color", "black"),
1334
- property("--tw-mask-linear-to-color", "transparent"),
1335
- property("--tw-mask-radial-from-position", "0%"),
1336
- property("--tw-mask-radial-to-position", "100%"),
1337
- property("--tw-mask-radial-from-color", "black"),
1338
- property("--tw-mask-radial-to-color", "transparent"),
1339
- property("--tw-mask-radial-shape", "ellipse"),
1340
- property("--tw-mask-radial-size", "farthest-corner"),
1341
- property("--tw-mask-radial-position", "center"),
1342
- property("--tw-mask-conic-position", "0deg"),
1343
- property("--tw-mask-conic-from-position", "0%"),
1344
- property("--tw-mask-conic-to-position", "100%"),
1345
- property("--tw-mask-conic-from-color", "black"),
1346
- property("--tw-mask-conic-to-color", "transparent"),
1347
- property("--tw-font-weight"),
1348
- property("--tw-blur"),
1349
- property("--tw-brightness"),
1350
- property("--tw-contrast"),
1351
- property("--tw-grayscale"),
1352
- property("--tw-hue-rotate"),
1353
- property("--tw-invert"),
1354
- property("--tw-opacity"),
1355
- property("--tw-saturate"),
1356
- property("--tw-sepia"),
1357
- property("--tw-drop-shadow"),
1358
- property("--tw-drop-shadow-color"),
1359
- property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
1360
- property("--tw-drop-shadow-size"),
1361
- property("--tw-backdrop-blur"),
1362
- property("--tw-backdrop-brightness"),
1363
- property("--tw-backdrop-contrast"),
1364
- property("--tw-backdrop-grayscale"),
1365
- property("--tw-backdrop-hue-rotate"),
1366
- property("--tw-backdrop-invert"),
1367
- property("--tw-backdrop-opacity"),
1368
- property("--tw-backdrop-saturate"),
1369
- property("--tw-backdrop-sepia"),
1370
- property("--tw-duration", "initial"),
1371
- property("--tw-ease", "initial"),
1372
- property("--tw-content", '""'),
1373
- property("--tw-contain-size"),
1374
- property("--tw-contain-layout"),
1375
- property("--tw-contain-paint"),
1376
- property("--tw-contain-style"),
1377
- property("--tw-leading"),
1378
- property("--tw-tracking"),
1379
- property("--tw-ordinal"),
1380
- property("--tw-slashed-zero"),
1381
- property("--tw-numeric-figure"),
1382
- property("--tw-numeric-spacing"),
1383
- property("--tw-numeric-fraction"),
1384
- property("--tw-outline-style", "solid"),
1385
- property("--tw-text-shadow-color", "initial"),
1386
- property("--tw-text-shadow-alpha", "100%", "<percentage>"),
1387
- property("--tw-shadow", nullShadow),
1388
- property("--tw-shadow-color", "initial"),
1389
- property("--tw-shadow-alpha", "100%", "<percentage>"),
1390
- property("--tw-inset-shadow", nullShadow),
1391
- property("--tw-inset-shadow-color", "initial"),
1392
- property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
1393
- property("--tw-ring-color"),
1394
- property("--tw-ring-shadow", nullShadow),
1395
- property("--tw-inset-ring-color"),
1396
- property("--tw-inset-ring-shadow", nullShadow),
1397
- // Legacy 旧版变量兼容
1398
- property("--tw-ring-inset"),
1399
- property("--tw-ring-offset-width", "0px", "<length>"),
1400
- property("--tw-ring-offset-color", "#fff"),
1401
- property("--tw-ring-offset-shadow", nullShadow)
1402
- ];
1403
- for (const edge of ["top", "right", "bottom", "left"]) {
1404
- nodes.push(
1405
- property(`--tw-mask-${edge}-from-position`, "0%"),
1406
- property(`--tw-mask-${edge}-to-position`, "100%"),
1407
- property(`--tw-mask-${edge}-from-color`, "black"),
1408
- property(`--tw-mask-${edge}-to-color`, "transparent")
1409
- );
1410
- }
1411
- var cssVarsV4_default = nodes;
1412
-
1413
1463
  // src/mp.ts
1414
1464
  var cssVarsV3Nodes = cssVarsV3_default.map((x) => {
1415
1465
  return new (0, _postcss.Declaration)({
@@ -1417,12 +1467,6 @@ var cssVarsV3Nodes = cssVarsV3_default.map((x) => {
1417
1467
  value: x.value
1418
1468
  });
1419
1469
  });
1420
- var cssVarsV4Nodes = cssVarsV4_default.map((x) => {
1421
- return new (0, _postcss.Declaration)({
1422
- prop: x.prop,
1423
- value: x.value
1424
- });
1425
- });
1426
1470
  function testIfVariablesScope(node, count = 2) {
1427
1471
  if (isOnlyBeforeAndAfterPseudoElement(node)) {
1428
1472
  const nodes2 = node.nodes;
@@ -1455,9 +1499,6 @@ function testIfTwBackdrop(node, count = 2) {
1455
1499
  }
1456
1500
  return false;
1457
1501
  }
1458
- function testIfRootHostForV4(node) {
1459
- return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
1460
- }
1461
1502
  function makePseudoVarRule() {
1462
1503
  const pseudoVarRule = new (0, _postcss.Rule)({
1463
1504
  // selectors: ['::before', '::after'],
@@ -1492,14 +1533,14 @@ function remakeCssVarSelector(selectors, options) {
1492
1533
  function commonChunkPreflight(node, options) {
1493
1534
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1494
1535
  if (testIfVariablesScope(node)) {
1495
- _optionalChain([ctx, 'optionalAccess', _59 => _59.markVariablesScope, 'call', _60 => _60(node)]);
1536
+ _optionalChain([ctx, 'optionalAccess', _60 => _60.markVariablesScope, 'call', _61 => _61(node)]);
1496
1537
  node.selectors = remakeCssVarSelector(node.selectors, options);
1497
1538
  node.before(makePseudoVarRule());
1498
1539
  if (typeof cssInjectPreflight === "function") {
1499
1540
  node.append(...cssInjectPreflight());
1500
1541
  }
1501
1542
  }
1502
- const isTailwindcss4 = options.majorVersion === 4;
1543
+ const isTailwindcss4 = isTailwindcssV4(options);
1503
1544
  if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
1504
1545
  const syntheticRule = new (0, _postcss.Rule)({
1505
1546
  selectors: ["*", "::after", "::before"],
@@ -1518,14 +1559,6 @@ function commonChunkPreflight(node, options) {
1518
1559
  function isAtMediaHover(atRule) {
1519
1560
  return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
1520
1561
  }
1521
- function isTailwindcssV4ModernCheck(atRule) {
1522
- return atRule.name === "supports" && [
1523
- /-webkit-hyphens\s*:\s*none/,
1524
- /margin-trim\s*:\s*inline/,
1525
- /-moz-orient\s*:\s*inline/,
1526
- /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/
1527
- ].every((regex) => regex.test(atRule.params));
1528
- }
1529
1562
  var postcssWeappTailwindcssPrePlugin = (options) => {
1530
1563
  const opts = _shared.defu.call(void 0, options, { isMainChunk: true });
1531
1564
  const p = {
@@ -1557,9 +1590,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1557
1590
  root.walkAtRules((atRule) => {
1558
1591
  if (atRule.name === "layer") {
1559
1592
  if (atRule.params === "properties") {
1560
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _61 => _61.nodes, 'optionalAccess', _62 => _62.length]) === 0) {
1593
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _62 => _62.nodes, 'optionalAccess', _63 => _63.length]) === 0) {
1561
1594
  layerProperties = atRule;
1562
- } else if (_optionalChain([atRule, 'access', _63 => _63.first, 'optionalAccess', _64 => _64.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1595
+ } else if (_optionalChain([atRule, 'access', _64 => _64.first, 'optionalAccess', _65 => _65.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1563
1596
  if (layerProperties) {
1564
1597
  layerProperties.replaceWith(atRule.first.nodes);
1565
1598
  atRule.remove();
@@ -1571,7 +1604,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1571
1604
  atRule.replaceWith(atRule.nodes);
1572
1605
  }
1573
1606
  } else if (isTailwindcssV4ModernCheck(atRule)) {
1574
- if (_optionalChain([atRule, 'access', _65 => _65.first, 'optionalAccess', _66 => _66.type]) === "atrule" && atRule.first.name === "layer") {
1607
+ if (_optionalChain([atRule, 'access', _66 => _66.first, 'optionalAccess', _67 => _67.type]) === "atrule" && atRule.first.name === "layer") {
1575
1608
  atRule.replaceWith(atRule.first.nodes);
1576
1609
  }
1577
1610
  }
@@ -1616,7 +1649,7 @@ function createPipelineDefinitions(options) {
1616
1649
  normal: [],
1617
1650
  post: []
1618
1651
  };
1619
- const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _67 => _67.postcssOptions, 'optionalAccess', _68 => _68.plugins]));
1652
+ const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _68 => _68.postcssOptions, 'optionalAccess', _69 => _69.plugins]));
1620
1653
  userPlugins.forEach((plugin, index) => {
1621
1654
  stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
1622
1655
  });
@@ -1776,7 +1809,7 @@ function createInjectPreflight(options) {
1776
1809
  function createProcessOptions(options) {
1777
1810
  return {
1778
1811
  from: void 0,
1779
- ..._nullishCoalesce(_optionalChain([options, 'access', _69 => _69.postcssOptions, 'optionalAccess', _70 => _70.options]), () => ( {}))
1812
+ ..._nullishCoalesce(_optionalChain([options, 'access', _70 => _70.postcssOptions, 'optionalAccess', _71 => _71.options]), () => ( {}))
1780
1813
  };
1781
1814
  }
1782
1815
  var pipelineCache = /* @__PURE__ */ new WeakMap();
@@ -1791,7 +1824,7 @@ function getCachedPipeline(options) {
1791
1824
  return pipeline;
1792
1825
  }
1793
1826
  function getCachedProcessOptions(options) {
1794
- const source = _optionalChain([options, 'access', _71 => _71.postcssOptions, 'optionalAccess', _72 => _72.options]);
1827
+ const source = _optionalChain([options, 'access', _72 => _72.postcssOptions, 'optionalAccess', _73 => _73.options]);
1795
1828
  let cached = processOptionsCache.get(options);
1796
1829
  const cachedSource = processOptionsSourceCache.get(options);
1797
1830
  if (!cached || cachedSource !== source) {
package/dist/index.mjs CHANGED
@@ -276,6 +276,227 @@ function getRemTransformPlugin(options) {
276
276
  // src/plugins/post.ts
277
277
  import { defu } from "@weapp-tailwindcss/shared";
278
278
 
279
+ // src/compat/tailwindcss-v4.ts
280
+ import { Declaration } from "postcss";
281
+
282
+ // src/cssVarsV4.ts
283
+ function property(ident, initialValue, _syntax) {
284
+ return {
285
+ prop: ident,
286
+ value: initialValue || ""
287
+ };
288
+ }
289
+ var nullShadow = "0 0 #0000";
290
+ var nodes = [
291
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
292
+ property("--tw-border-spacing-x", "0", "<length>"),
293
+ property("--tw-border-spacing-y", "0", "<length>"),
294
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
295
+ property("--tw-translate-x", "0"),
296
+ property("--tw-translate-y", "0"),
297
+ property("--tw-translate-z", "0"),
298
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
299
+ property("--tw-scale-x", "1"),
300
+ property("--tw-scale-y", "1"),
301
+ property("--tw-scale-z", "1"),
302
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
303
+ property("--tw-rotate-x"),
304
+ property("--tw-rotate-y"),
305
+ property("--tw-rotate-z"),
306
+ property("--tw-skew-x"),
307
+ property("--tw-skew-y"),
308
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
309
+ property("--tw-pan-x"),
310
+ property("--tw-pan-y"),
311
+ property("--tw-pinch-zoom"),
312
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
313
+ property("--tw-scroll-snap-strictness", "proximity", "*"),
314
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
315
+ property("--tw-space-x-reverse", "0"),
316
+ property("--tw-space-y-reverse", "0"),
317
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
318
+ property("--tw-border-style", "solid"),
319
+ property("--tw-divide-x-reverse", "0"),
320
+ property("--tw-divide-y-reverse", "0"),
321
+ property("--tw-gradient-position", "initial"),
322
+ property("--tw-gradient-from", "#0000", "<color>"),
323
+ property("--tw-gradient-via", "#0000", "<color>"),
324
+ property("--tw-gradient-to", "#0000", "<color>"),
325
+ property("--tw-gradient-stops", "initial"),
326
+ property("--tw-gradient-via-stops", "initial"),
327
+ property("--tw-gradient-from-position", "0%", "<length-percentage>"),
328
+ property("--tw-gradient-via-position", "50%", "<length-percentage>"),
329
+ property("--tw-gradient-to-position", "100%", "<length-percentage>"),
330
+ property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
331
+ property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
332
+ property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
333
+ property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
334
+ property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
335
+ property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
336
+ property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
337
+ property("--tw-mask-linear-position", "0deg"),
338
+ property("--tw-mask-linear-from-position", "0%"),
339
+ property("--tw-mask-linear-to-position", "100%"),
340
+ property("--tw-mask-linear-from-color", "black"),
341
+ property("--tw-mask-linear-to-color", "transparent"),
342
+ property("--tw-mask-radial-from-position", "0%"),
343
+ property("--tw-mask-radial-to-position", "100%"),
344
+ property("--tw-mask-radial-from-color", "black"),
345
+ property("--tw-mask-radial-to-color", "transparent"),
346
+ property("--tw-mask-radial-shape", "ellipse"),
347
+ property("--tw-mask-radial-size", "farthest-corner"),
348
+ property("--tw-mask-radial-position", "center"),
349
+ property("--tw-mask-conic-position", "0deg"),
350
+ property("--tw-mask-conic-from-position", "0%"),
351
+ property("--tw-mask-conic-to-position", "100%"),
352
+ property("--tw-mask-conic-from-color", "black"),
353
+ property("--tw-mask-conic-to-color", "transparent"),
354
+ property("--tw-font-weight"),
355
+ property("--tw-blur"),
356
+ property("--tw-brightness"),
357
+ property("--tw-contrast"),
358
+ property("--tw-grayscale"),
359
+ property("--tw-hue-rotate"),
360
+ property("--tw-invert"),
361
+ property("--tw-opacity"),
362
+ property("--tw-saturate"),
363
+ property("--tw-sepia"),
364
+ property("--tw-drop-shadow"),
365
+ property("--tw-drop-shadow-color"),
366
+ property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
367
+ property("--tw-drop-shadow-size"),
368
+ property("--tw-backdrop-blur"),
369
+ property("--tw-backdrop-brightness"),
370
+ property("--tw-backdrop-contrast"),
371
+ property("--tw-backdrop-grayscale"),
372
+ property("--tw-backdrop-hue-rotate"),
373
+ property("--tw-backdrop-invert"),
374
+ property("--tw-backdrop-opacity"),
375
+ property("--tw-backdrop-saturate"),
376
+ property("--tw-backdrop-sepia"),
377
+ property("--tw-duration", "initial"),
378
+ property("--tw-ease", "initial"),
379
+ property("--tw-content", '""'),
380
+ property("--tw-contain-size"),
381
+ property("--tw-contain-layout"),
382
+ property("--tw-contain-paint"),
383
+ property("--tw-contain-style"),
384
+ property("--tw-leading"),
385
+ property("--tw-tracking"),
386
+ property("--tw-ordinal"),
387
+ property("--tw-slashed-zero"),
388
+ property("--tw-numeric-figure"),
389
+ property("--tw-numeric-spacing"),
390
+ property("--tw-numeric-fraction"),
391
+ property("--tw-outline-style", "solid"),
392
+ property("--tw-text-shadow-color", "initial"),
393
+ property("--tw-text-shadow-alpha", "100%", "<percentage>"),
394
+ property("--tw-shadow", nullShadow),
395
+ property("--tw-shadow-color", "initial"),
396
+ property("--tw-shadow-alpha", "100%", "<percentage>"),
397
+ property("--tw-inset-shadow", nullShadow),
398
+ property("--tw-inset-shadow-color", "initial"),
399
+ property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
400
+ property("--tw-ring-color"),
401
+ property("--tw-ring-shadow", nullShadow),
402
+ property("--tw-inset-ring-color"),
403
+ property("--tw-inset-ring-shadow", nullShadow),
404
+ // Legacy 旧版变量兼容
405
+ property("--tw-ring-inset"),
406
+ property("--tw-ring-offset-width", "0px", "<length>"),
407
+ property("--tw-ring-offset-color", "#fff"),
408
+ property("--tw-ring-offset-shadow", nullShadow)
409
+ ];
410
+ for (const edge of ["top", "right", "bottom", "left"]) {
411
+ nodes.push(
412
+ property(`--tw-mask-${edge}-from-position`, "0%"),
413
+ property(`--tw-mask-${edge}-to-position`, "100%"),
414
+ property(`--tw-mask-${edge}-from-color`, "black"),
415
+ property(`--tw-mask-${edge}-to-color`, "transparent")
416
+ );
417
+ }
418
+ var cssVarsV4_default = nodes;
419
+
420
+ // src/compat/tailwindcss-v4.ts
421
+ var OKLAB_SUFFIX = "in oklab";
422
+ var INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
423
+ var RADIUS_THRESHOLD = 1e5;
424
+ var CLAMP_PX = 9999;
425
+ function isTailwindcssV4(options) {
426
+ return options?.majorVersion === 4;
427
+ }
428
+ function testIfRootHostForV4(node) {
429
+ return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
430
+ }
431
+ var cssVarsV4Nodes = cssVarsV4_default.map((x) => {
432
+ return new Declaration({
433
+ prop: x.prop,
434
+ value: x.value
435
+ });
436
+ });
437
+ function isTailwindcssV4ModernCheck(atRule) {
438
+ return atRule.name === "supports" && [
439
+ /-webkit-hyphens\s*:\s*none/,
440
+ /margin-trim\s*:\s*inline/,
441
+ /-moz-orient\s*:\s*inline/,
442
+ /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/
443
+ ].every((regex) => regex.test(atRule.params));
444
+ }
445
+ function normalizeTailwindcssV4Declaration(decl) {
446
+ if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
447
+ decl.value = decl.value.slice(0, decl.value.length - OKLAB_SUFFIX.length);
448
+ return true;
449
+ }
450
+ if (INFINITY_CALC_REGEXP.test(decl.value)) {
451
+ decl.value = `${CLAMP_PX}px`;
452
+ return true;
453
+ }
454
+ if (decl.prop.includes("radius")) {
455
+ const next = decl.value.replace(
456
+ /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi,
457
+ (m, num) => {
458
+ const n = Number(num);
459
+ if (!Number.isFinite(n)) {
460
+ return `${CLAMP_PX}px`;
461
+ }
462
+ if (/e/i.test(String(num)) || n > RADIUS_THRESHOLD) {
463
+ return `${CLAMP_PX}px`;
464
+ }
465
+ return m;
466
+ }
467
+ );
468
+ if (next !== decl.value) {
469
+ decl.value = next;
470
+ return true;
471
+ }
472
+ }
473
+ return false;
474
+ }
475
+
476
+ // src/compat/uni-app-x.ts
477
+ function isUniAppXEnabled(options) {
478
+ return Boolean(options?.uniAppX);
479
+ }
480
+ function stripUnsupportedPseudoForUniAppX(node, enabled) {
481
+ if (!enabled) {
482
+ return;
483
+ }
484
+ node.remove();
485
+ }
486
+ function stripUnsupportedNodeForUniAppX(node, options) {
487
+ if (!isUniAppXEnabled(options)) {
488
+ return false;
489
+ }
490
+ if (node.type === "tag" || node.type === "attribute" || node.type === "pseudo") {
491
+ node.remove();
492
+ return true;
493
+ }
494
+ return false;
495
+ }
496
+ function shouldRemoveEmptyRuleForUniAppX(rule, options) {
497
+ return isUniAppXEnabled(options) && rule.nodes.length === 0;
498
+ }
499
+
279
500
  // src/constants.ts
280
501
  var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
281
502
 
@@ -366,7 +587,7 @@ function getFallbackRemove(_rule, options) {
366
587
  const cacheKey = options ?? fallbackDefaultKey;
367
588
  let entry = fallbackRemoveCache.get(cacheKey);
368
589
  if (!entry) {
369
- const uniAppX = Boolean(options?.uniAppX);
590
+ const uniAppX = isUniAppXEnabled(options);
370
591
  let currentRule;
371
592
  const parser = psp3((selectors) => {
372
593
  const activeRule = currentRule;
@@ -417,9 +638,7 @@ function getFallbackRemove(_rule, options) {
417
638
  selector.remove();
418
639
  }
419
640
  } else if (selector.type === "pseudo") {
420
- if (uniAppX) {
421
- selector.remove();
422
- }
641
+ stripUnsupportedPseudoForUniAppX(selector, uniAppX);
423
642
  }
424
643
  }
425
644
  });
@@ -621,7 +840,7 @@ function normalizeSpacingDeclarations(rule) {
621
840
  dedupeSpacingProps(rule);
622
841
  }
623
842
  function flattenWherePseudo(node, context, index, parent) {
624
- if (context.options.uniAppX) {
843
+ if (isUniAppXEnabled(context.options)) {
625
844
  node.value = ":is";
626
845
  }
627
846
  if (index === 0 && node.length === 1) {
@@ -705,12 +924,7 @@ function handlePseudoNode(node, index, context, parent) {
705
924
  }
706
925
  }
707
926
  function handleTagOrAttribute(node, context) {
708
- if (!context.options.uniAppX) {
709
- return;
710
- }
711
- if (node.type === "tag" || node.type === "attribute") {
712
- node.remove();
713
- }
927
+ stripUnsupportedNodeForUniAppX(node, context.options);
714
928
  }
715
929
  function handleSelectorNode(selector, context) {
716
930
  if (shouldRemoveHoverSelector(selector, context.options)) {
@@ -842,7 +1056,6 @@ function createRootSpecificityCleaner(options) {
842
1056
  rule.selectors = next;
843
1057
  };
844
1058
  }
845
- var OklabSuffix = "in oklab";
846
1059
  var logicalPropMap = /* @__PURE__ */ new Map([
847
1060
  // margin 方向映射
848
1061
  ["margin-inline-start", "margin-left"],
@@ -1014,39 +1227,14 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1014
1227
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
1015
1228
  rule.remove();
1016
1229
  }
1017
- if (opts.uniAppX && rule.nodes.length === 0) {
1230
+ if (shouldRemoveEmptyRuleForUniAppX(rule, opts)) {
1018
1231
  rule.remove();
1019
1232
  }
1020
1233
  }
1021
1234
  };
1022
1235
  }
1023
1236
  if (enableMainChunkTransforms) {
1024
- p.DeclarationExit = (decl) => {
1025
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
1026
- decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
1027
- } else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
1028
- decl.value = "9999px";
1029
- } else if (decl.prop.includes("radius")) {
1030
- const CLAMP_PX = 9999;
1031
- const THRESHOLD = 1e5;
1032
- const next = decl.value.replace(
1033
- /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi,
1034
- (m, num) => {
1035
- const n = Number(num);
1036
- if (!Number.isFinite(n)) {
1037
- return `${CLAMP_PX}px`;
1038
- }
1039
- if (/e/i.test(String(num)) || n > THRESHOLD) {
1040
- return `${CLAMP_PX}px`;
1041
- }
1042
- return m;
1043
- }
1044
- );
1045
- if (next !== decl.value) {
1046
- decl.value = next;
1047
- }
1048
- }
1049
- };
1237
+ p.DeclarationExit = (decl) => normalizeTailwindcssV4Declaration(decl);
1050
1238
  p.AtRuleExit = (atRule) => {
1051
1239
  if (opts.cssRemoveProperty && atRule.name === "property") {
1052
1240
  atRule.remove();
@@ -1062,7 +1250,7 @@ postcssWeappTailwindcssPostPlugin.postcss = true;
1062
1250
  import { defu as defu2 } from "@weapp-tailwindcss/shared";
1063
1251
 
1064
1252
  // src/mp.ts
1065
- import { Declaration, Rule } from "postcss";
1253
+ import { Declaration as Declaration2, Rule } from "postcss";
1066
1254
 
1067
1255
  // src/cssVarsV3.ts
1068
1256
  var cssVarsV3_default = [
@@ -1272,153 +1460,9 @@ var cssVarsV3_default = [
1272
1460
  }
1273
1461
  ];
1274
1462
 
1275
- // src/cssVarsV4.ts
1276
- function property(ident, initialValue, _syntax) {
1277
- return {
1278
- prop: ident,
1279
- value: initialValue || ""
1280
- };
1281
- }
1282
- var nullShadow = "0 0 #0000";
1283
- var nodes = [
1284
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1285
- property("--tw-border-spacing-x", "0", "<length>"),
1286
- property("--tw-border-spacing-y", "0", "<length>"),
1287
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1288
- property("--tw-translate-x", "0"),
1289
- property("--tw-translate-y", "0"),
1290
- property("--tw-translate-z", "0"),
1291
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1292
- property("--tw-scale-x", "1"),
1293
- property("--tw-scale-y", "1"),
1294
- property("--tw-scale-z", "1"),
1295
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1296
- property("--tw-rotate-x"),
1297
- property("--tw-rotate-y"),
1298
- property("--tw-rotate-z"),
1299
- property("--tw-skew-x"),
1300
- property("--tw-skew-y"),
1301
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1302
- property("--tw-pan-x"),
1303
- property("--tw-pan-y"),
1304
- property("--tw-pinch-zoom"),
1305
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1306
- property("--tw-scroll-snap-strictness", "proximity", "*"),
1307
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1308
- property("--tw-space-x-reverse", "0"),
1309
- property("--tw-space-y-reverse", "0"),
1310
- // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1311
- property("--tw-border-style", "solid"),
1312
- property("--tw-divide-x-reverse", "0"),
1313
- property("--tw-divide-y-reverse", "0"),
1314
- property("--tw-gradient-position", "initial"),
1315
- property("--tw-gradient-from", "#0000", "<color>"),
1316
- property("--tw-gradient-via", "#0000", "<color>"),
1317
- property("--tw-gradient-to", "#0000", "<color>"),
1318
- property("--tw-gradient-stops", "initial"),
1319
- property("--tw-gradient-via-stops", "initial"),
1320
- property("--tw-gradient-from-position", "0%", "<length-percentage>"),
1321
- property("--tw-gradient-via-position", "50%", "<length-percentage>"),
1322
- property("--tw-gradient-to-position", "100%", "<length-percentage>"),
1323
- property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
1324
- property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
1325
- property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
1326
- property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
1327
- property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
1328
- property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
1329
- property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
1330
- property("--tw-mask-linear-position", "0deg"),
1331
- property("--tw-mask-linear-from-position", "0%"),
1332
- property("--tw-mask-linear-to-position", "100%"),
1333
- property("--tw-mask-linear-from-color", "black"),
1334
- property("--tw-mask-linear-to-color", "transparent"),
1335
- property("--tw-mask-radial-from-position", "0%"),
1336
- property("--tw-mask-radial-to-position", "100%"),
1337
- property("--tw-mask-radial-from-color", "black"),
1338
- property("--tw-mask-radial-to-color", "transparent"),
1339
- property("--tw-mask-radial-shape", "ellipse"),
1340
- property("--tw-mask-radial-size", "farthest-corner"),
1341
- property("--tw-mask-radial-position", "center"),
1342
- property("--tw-mask-conic-position", "0deg"),
1343
- property("--tw-mask-conic-from-position", "0%"),
1344
- property("--tw-mask-conic-to-position", "100%"),
1345
- property("--tw-mask-conic-from-color", "black"),
1346
- property("--tw-mask-conic-to-color", "transparent"),
1347
- property("--tw-font-weight"),
1348
- property("--tw-blur"),
1349
- property("--tw-brightness"),
1350
- property("--tw-contrast"),
1351
- property("--tw-grayscale"),
1352
- property("--tw-hue-rotate"),
1353
- property("--tw-invert"),
1354
- property("--tw-opacity"),
1355
- property("--tw-saturate"),
1356
- property("--tw-sepia"),
1357
- property("--tw-drop-shadow"),
1358
- property("--tw-drop-shadow-color"),
1359
- property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
1360
- property("--tw-drop-shadow-size"),
1361
- property("--tw-backdrop-blur"),
1362
- property("--tw-backdrop-brightness"),
1363
- property("--tw-backdrop-contrast"),
1364
- property("--tw-backdrop-grayscale"),
1365
- property("--tw-backdrop-hue-rotate"),
1366
- property("--tw-backdrop-invert"),
1367
- property("--tw-backdrop-opacity"),
1368
- property("--tw-backdrop-saturate"),
1369
- property("--tw-backdrop-sepia"),
1370
- property("--tw-duration", "initial"),
1371
- property("--tw-ease", "initial"),
1372
- property("--tw-content", '""'),
1373
- property("--tw-contain-size"),
1374
- property("--tw-contain-layout"),
1375
- property("--tw-contain-paint"),
1376
- property("--tw-contain-style"),
1377
- property("--tw-leading"),
1378
- property("--tw-tracking"),
1379
- property("--tw-ordinal"),
1380
- property("--tw-slashed-zero"),
1381
- property("--tw-numeric-figure"),
1382
- property("--tw-numeric-spacing"),
1383
- property("--tw-numeric-fraction"),
1384
- property("--tw-outline-style", "solid"),
1385
- property("--tw-text-shadow-color", "initial"),
1386
- property("--tw-text-shadow-alpha", "100%", "<percentage>"),
1387
- property("--tw-shadow", nullShadow),
1388
- property("--tw-shadow-color", "initial"),
1389
- property("--tw-shadow-alpha", "100%", "<percentage>"),
1390
- property("--tw-inset-shadow", nullShadow),
1391
- property("--tw-inset-shadow-color", "initial"),
1392
- property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
1393
- property("--tw-ring-color"),
1394
- property("--tw-ring-shadow", nullShadow),
1395
- property("--tw-inset-ring-color"),
1396
- property("--tw-inset-ring-shadow", nullShadow),
1397
- // Legacy 旧版变量兼容
1398
- property("--tw-ring-inset"),
1399
- property("--tw-ring-offset-width", "0px", "<length>"),
1400
- property("--tw-ring-offset-color", "#fff"),
1401
- property("--tw-ring-offset-shadow", nullShadow)
1402
- ];
1403
- for (const edge of ["top", "right", "bottom", "left"]) {
1404
- nodes.push(
1405
- property(`--tw-mask-${edge}-from-position`, "0%"),
1406
- property(`--tw-mask-${edge}-to-position`, "100%"),
1407
- property(`--tw-mask-${edge}-from-color`, "black"),
1408
- property(`--tw-mask-${edge}-to-color`, "transparent")
1409
- );
1410
- }
1411
- var cssVarsV4_default = nodes;
1412
-
1413
1463
  // src/mp.ts
1414
1464
  var cssVarsV3Nodes = cssVarsV3_default.map((x) => {
1415
- return new Declaration({
1416
- prop: x.prop,
1417
- value: x.value
1418
- });
1419
- });
1420
- var cssVarsV4Nodes = cssVarsV4_default.map((x) => {
1421
- return new Declaration({
1465
+ return new Declaration2({
1422
1466
  prop: x.prop,
1423
1467
  value: x.value
1424
1468
  });
@@ -1455,16 +1499,13 @@ function testIfTwBackdrop(node, count = 2) {
1455
1499
  }
1456
1500
  return false;
1457
1501
  }
1458
- function testIfRootHostForV4(node) {
1459
- return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
1460
- }
1461
1502
  function makePseudoVarRule() {
1462
1503
  const pseudoVarRule = new Rule({
1463
1504
  // selectors: ['::before', '::after'],
1464
1505
  selector: "::before,::after"
1465
1506
  });
1466
1507
  pseudoVarRule.append(
1467
- new Declaration({
1508
+ new Declaration2({
1468
1509
  prop: "--tw-content",
1469
1510
  value: '""'
1470
1511
  })
@@ -1499,7 +1540,7 @@ function commonChunkPreflight(node, options) {
1499
1540
  node.append(...cssInjectPreflight());
1500
1541
  }
1501
1542
  }
1502
- const isTailwindcss4 = options.majorVersion === 4;
1543
+ const isTailwindcss4 = isTailwindcssV4(options);
1503
1544
  if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
1504
1545
  const syntheticRule = new Rule({
1505
1546
  selectors: ["*", "::after", "::before"],
@@ -1518,14 +1559,6 @@ function commonChunkPreflight(node, options) {
1518
1559
  function isAtMediaHover(atRule) {
1519
1560
  return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
1520
1561
  }
1521
- function isTailwindcssV4ModernCheck(atRule) {
1522
- return atRule.name === "supports" && [
1523
- /-webkit-hyphens\s*:\s*none/,
1524
- /margin-trim\s*:\s*inline/,
1525
- /-moz-orient\s*:\s*inline/,
1526
- /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/
1527
- ].every((regex) => regex.test(atRule.params));
1528
- }
1529
1562
  var postcssWeappTailwindcssPrePlugin = (options) => {
1530
1563
  const opts = defu2(options, { isMainChunk: true });
1531
1564
  const p = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -43,9 +43,9 @@
43
43
  "@weapp-tailwindcss/postcss-calc": "^1.0.0",
44
44
  "postcss": "~8.5.6",
45
45
  "postcss-preset-env": "^10.4.0",
46
- "postcss-pxtransform": "^4.1.8",
46
+ "postcss-pxtransform": "^4.1.9",
47
47
  "postcss-rem-to-responsive-pixel": "^6.1.0",
48
- "postcss-selector-parser": "~7.1.0",
48
+ "postcss-selector-parser": "~7.1.1",
49
49
  "postcss-value-parser": "^4.2.0",
50
50
  "@weapp-tailwindcss/shared": "1.1.1"
51
51
  },