@weapp-tailwindcss/postcss 2.0.1 → 2.0.3

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 +168 -42
  2. package/dist/index.mjs +141 -15
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postc
7
7
  // src/defaults.ts
8
8
  function getDefaultOptions(options) {
9
9
  return {
10
- // https://github.com/postcss/postcss-calc
10
+ // 参考:https://github.com/postcss/postcss-calc
11
11
  cssPresetEnv: {
12
12
  features: {
13
13
  "cascade-layers": true,
@@ -16,8 +16,9 @@ function getDefaultOptions(options) {
16
16
  },
17
17
  "oklab-function": true,
18
18
  "color-mix": true,
19
+ "color-functional-notation": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.cssPresetEnv, 'optionalAccess', _2 => _2.features, 'optionalAccess', _3 => _3["color-functional-notation"]]), () => ( { preserve: false })),
19
20
  // 在 calc 下,这个需要开启
20
- "custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.cssPresetEnv, 'optionalAccess', _2 => _2.features, 'optionalAccess', _3 => _3["custom-properties"]]), () => ( _optionalChain([options, 'optionalAccess', _4 => _4.cssCalc]))) ? { preserve: true } : false
21
+ "custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.cssPresetEnv, 'optionalAccess', _5 => _5.features, 'optionalAccess', _6 => _6["custom-properties"]]), () => ( _optionalChain([options, 'optionalAccess', _7 => _7.cssCalc]))) ? { preserve: true } : false
21
22
  },
22
23
  autoprefixer: {
23
24
  add: false
@@ -37,6 +38,103 @@ function getDefaultOptions(options) {
37
38
  // src/pipeline.ts
38
39
  var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
39
40
 
41
+ // src/plugins/colorFunctionalFallback.ts
42
+ var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
43
+ var RGB_FUNCTION_NAME = "rgb";
44
+ var isSlashDiv = (node) => node.type === "div" && node.value === "/";
45
+ function trimNodes(nodes2) {
46
+ let start = 0;
47
+ let end = nodes2.length;
48
+ while (start < end && _optionalChain([nodes2, 'access', _8 => _8[start], 'optionalAccess', _9 => _9.type]) === "space") {
49
+ start += 1;
50
+ }
51
+ while (end > start && _optionalChain([nodes2, 'access', _10 => _10[end - 1], 'optionalAccess', _11 => _11.type]) === "space") {
52
+ end -= 1;
53
+ }
54
+ return nodes2.slice(start, end);
55
+ }
56
+ function splitColorComponents(nodes2) {
57
+ const parts = [];
58
+ let current = [];
59
+ nodes2.forEach((node) => {
60
+ if (node.type === "div" && node.value === ",") {
61
+ if (current.length) {
62
+ parts.push(current);
63
+ current = [];
64
+ }
65
+ return;
66
+ }
67
+ if (node.type === "space") {
68
+ if (current.length) {
69
+ parts.push(current);
70
+ current = [];
71
+ }
72
+ return;
73
+ }
74
+ current.push(node);
75
+ });
76
+ if (current.length) {
77
+ parts.push(current);
78
+ }
79
+ return parts;
80
+ }
81
+ var buildFunctionNodes = (content) => _postcssvalueparser2.default.call(void 0, content).nodes;
82
+ function convertRgbFunction(fnNode) {
83
+ const slashIndex = fnNode.nodes.findIndex(isSlashDiv);
84
+ if (slashIndex === -1) {
85
+ return false;
86
+ }
87
+ const colorNodes = trimNodes(fnNode.nodes.slice(0, slashIndex));
88
+ const alphaNodes = trimNodes(fnNode.nodes.slice(slashIndex + 1));
89
+ if (!colorNodes.length || !alphaNodes.length) {
90
+ return false;
91
+ }
92
+ const colorParts = splitColorComponents(colorNodes);
93
+ if (colorParts.length !== 3) {
94
+ return false;
95
+ }
96
+ const normalizedColors = colorParts.map((part) => _postcssvalueparser2.default.stringify(part).trim()).filter(Boolean);
97
+ if (normalizedColors.length !== 3) {
98
+ return false;
99
+ }
100
+ const alphaText = _postcssvalueparser2.default.stringify(alphaNodes).trim();
101
+ if (!alphaText) {
102
+ return false;
103
+ }
104
+ fnNode.value = "rgba";
105
+ const nextValue = `${normalizedColors.join(", ")}, ${alphaText}`;
106
+ fnNode.nodes = buildFunctionNodes(nextValue);
107
+ return true;
108
+ }
109
+ function transformDeclaration(decl) {
110
+ if (!decl.value || !decl.value.toLowerCase().includes(RGB_FUNCTION_NAME)) {
111
+ return;
112
+ }
113
+ const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
114
+ let mutated = false;
115
+ parsed.walk((node) => {
116
+ if (node.type !== "function") {
117
+ return;
118
+ }
119
+ if (node.value.toLowerCase() !== RGB_FUNCTION_NAME) {
120
+ return;
121
+ }
122
+ if (convertRgbFunction(node)) {
123
+ mutated = true;
124
+ }
125
+ });
126
+ if (mutated) {
127
+ decl.value = parsed.toString();
128
+ }
129
+ }
130
+ function createColorFunctionalFallback() {
131
+ return {
132
+ postcssPlugin: "weapp-tailwindcss-color-functional-fallback",
133
+ Declaration: transformDeclaration
134
+ };
135
+ }
136
+ createColorFunctionalFallback.postcss = true;
137
+
40
138
  // src/plugins/ctx.ts
41
139
  function createContext() {
42
140
  const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
@@ -77,7 +175,7 @@ function getCalcPlugin(options) {
77
175
 
78
176
  // src/plugins/getCustomPropertyCleaner.ts
79
177
 
80
- var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
178
+
81
179
  function getCustomPropertyCleaner(options) {
82
180
  const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
83
181
  const shouldMatchCustomProperties = Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0;
@@ -190,7 +288,7 @@ var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors)
190
288
  return;
191
289
  }
192
290
  selectors.walkPseudos((s) => {
193
- if (_optionalChain([s, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.length]) === 1) {
291
+ if (_optionalChain([s, 'access', _12 => _12.parent, 'optionalAccess', _13 => _13.length]) === 1) {
194
292
  if (/^:?:before$/.test(s.value)) {
195
293
  state.before = true;
196
294
  }
@@ -268,7 +366,7 @@ function getFallbackRemove(_rule, options) {
268
366
  const cacheKey = _nullishCoalesce(options, () => ( fallbackDefaultKey));
269
367
  let entry = fallbackRemoveCache.get(cacheKey);
270
368
  if (!entry) {
271
- const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _7 => _7.uniAppX]));
369
+ const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _14 => _14.uniAppX]));
272
370
  let currentRule;
273
371
  const parser = _postcssselectorparser2.default.call(void 0, (selectors) => {
274
372
  const activeRule = currentRule;
@@ -278,13 +376,13 @@ function getFallbackRemove(_rule, options) {
278
376
  maybeImportantId = true;
279
377
  }
280
378
  if (selector.type === "universal") {
281
- _optionalChain([selector, 'access', _8 => _8.parent, 'optionalAccess', _9 => _9.remove, 'call', _10 => _10()]);
379
+ _optionalChain([selector, 'access', _15 => _15.parent, 'optionalAccess', _16 => _16.remove, 'call', _17 => _17()]);
282
380
  } else if (selector.type === "pseudo") {
283
381
  if (selector.value === ":is") {
284
- if (maybeImportantId && _optionalChain([selector, 'access', _11 => _11.nodes, 'access', _12 => _12[0], 'optionalAccess', _13 => _13.type]) === "selector") {
382
+ if (maybeImportantId && _optionalChain([selector, 'access', _18 => _18.nodes, 'access', _19 => _19[0], 'optionalAccess', _20 => _20.type]) === "selector") {
285
383
  selector.replaceWith(selector.nodes[0]);
286
384
  } else {
287
- _optionalChain([selector, 'access', _14 => _14.parent, 'optionalAccess', _15 => _15.remove, 'call', _16 => _16()]);
385
+ _optionalChain([selector, 'access', _21 => _21.parent, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
288
386
  }
289
387
  } else if (selector.value === ":not") {
290
388
  for (const x of selector.nodes) {
@@ -307,7 +405,7 @@ function getFallbackRemove(_rule, options) {
307
405
  }
308
406
  } else if (selector.type === "attribute") {
309
407
  if (selector.attribute === "hidden") {
310
- _optionalChain([activeRule, 'optionalAccess', _17 => _17.remove, 'call', _18 => _18()]);
408
+ _optionalChain([activeRule, 'optionalAccess', _24 => _24.remove, 'call', _25 => _25()]);
311
409
  }
312
410
  }
313
411
  });
@@ -455,7 +553,7 @@ function dedupeSpacingProps(rule) {
455
553
  if (alreadyOrdered) {
456
554
  continue;
457
555
  }
458
- const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _19 => _19[unique.length - 1], 'optionalAccess', _20 => _20.next, 'call', _21 => _21()]), () => ( void 0));
556
+ const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _26 => _26[unique.length - 1], 'optionalAccess', _27 => _27.next, 'call', _28 => _28()]), () => ( void 0));
459
557
  for (const decl of unique) {
460
558
  decl.remove();
461
559
  }
@@ -480,7 +578,7 @@ function isNotLastChildPseudo(node) {
480
578
  if (firstSelector.type !== "selector") {
481
579
  return false;
482
580
  }
483
- const target = _optionalChain([firstSelector, 'access', _22 => _22.nodes, 'optionalAccess', _23 => _23[0]]);
581
+ const target = _optionalChain([firstSelector, 'access', _29 => _29.nodes, 'optionalAccess', _30 => _30[0]]);
484
582
  return Boolean(target && target.type === "pseudo" && target.value === ":last-child");
485
583
  }
486
584
  function transformSpacingSelector(nodes2, options) {
@@ -527,7 +625,7 @@ function flattenWherePseudo(node, context, index, parent) {
527
625
  node.value = ":is";
528
626
  }
529
627
  if (index === 0 && node.length === 1) {
530
- const targetSelector = _optionalChain([node, 'access', _24 => _24.nodes, 'optionalAccess', _25 => _25[0]]);
628
+ const targetSelector = _optionalChain([node, 'access', _31 => _31.nodes, 'optionalAccess', _32 => _32[0]]);
531
629
  if (targetSelector && targetSelector.type === "selector" && transformSpacingSelector(targetSelector.nodes, context.options)) {
532
630
  context.requiresSpacingNormalization = true;
533
631
  }
@@ -547,7 +645,7 @@ function handleUniversalNode(node, context) {
547
645
  if (node.type !== "universal") {
548
646
  return;
549
647
  }
550
- const replacement = _optionalChain([context, 'access', _26 => _26.options, 'access', _27 => _27.cssSelectorReplacement, 'optionalAccess', _28 => _28.universal]);
648
+ const replacement = _optionalChain([context, 'access', _33 => _33.options, 'access', _34 => _34.cssSelectorReplacement, 'optionalAccess', _35 => _35.universal]);
551
649
  if (replacement) {
552
650
  node.value = composeIsPseudo(replacement);
553
651
  }
@@ -582,7 +680,7 @@ function handleCombinatorNode(node, index, context) {
582
680
  if (node.type !== "combinator" || node.value !== ">") {
583
681
  return;
584
682
  }
585
- const nodes2 = _optionalChain([node, 'access', _29 => _29.parent, 'optionalAccess', _30 => _30.nodes]);
683
+ const nodes2 = _optionalChain([node, 'access', _36 => _36.parent, 'optionalAccess', _37 => _37.nodes]);
586
684
  if (!nodes2) {
587
685
  return;
588
686
  }
@@ -598,7 +696,7 @@ function handlePseudoNode(node, index, context, parent) {
598
696
  if (node.type !== "pseudo") {
599
697
  return;
600
698
  }
601
- if (node.value === ":root" && _optionalChain([context, 'access', _31 => _31.options, 'access', _32 => _32.cssSelectorReplacement, 'optionalAccess', _33 => _33.root])) {
699
+ if (node.value === ":root" && _optionalChain([context, 'access', _38 => _38.options, 'access', _39 => _39.cssSelectorReplacement, 'optionalAccess', _40 => _40.root])) {
602
700
  node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
603
701
  return;
604
702
  }
@@ -625,7 +723,7 @@ function handleSelectorNode(selector, context) {
625
723
  }
626
724
  function transformSelectors(selectors, context) {
627
725
  selectors.walk((node, index) => {
628
- const parent = _optionalChain([node, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.type]) === "selector" ? node.parent : void 0;
726
+ const parent = _optionalChain([node, 'access', _41 => _41.parent, 'optionalAccess', _42 => _42.type]) === "selector" ? node.parent : void 0;
629
727
  switch (node.type) {
630
728
  case "class":
631
729
  handleClassNode(node, context);
@@ -703,7 +801,7 @@ function normalizeSelectorList(value) {
703
801
  return Array.isArray(value) ? value.filter(Boolean) : [value];
704
802
  }
705
803
  function getSpecificityMatchingName(options) {
706
- const feature = _optionalChain([options, 'access', _36 => _36.cssPresetEnv, 'optionalAccess', _37 => _37.features, 'optionalAccess', _38 => _38["is-pseudo-class"]]);
804
+ const feature = _optionalChain([options, 'access', _43 => _43.cssPresetEnv, 'optionalAccess', _44 => _44.features, 'optionalAccess', _45 => _45["is-pseudo-class"]]);
707
805
  if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
708
806
  const specificityName = feature.specificityMatchingName;
709
807
  return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
@@ -712,12 +810,12 @@ function getSpecificityMatchingName(options) {
712
810
  }
713
811
  function createRootSpecificityCleaner(options) {
714
812
  const specificityMatchingName = getSpecificityMatchingName(options);
715
- const selectors = normalizeSelectorList(_optionalChain([options, 'access', _39 => _39.cssSelectorReplacement, 'optionalAccess', _40 => _40.root]));
813
+ const selectors = normalizeSelectorList(_optionalChain([options, 'access', _46 => _46.cssSelectorReplacement, 'optionalAccess', _47 => _47.root]));
716
814
  if (!specificityMatchingName || selectors.length === 0) {
717
815
  return void 0;
718
816
  }
719
817
  const suffix = `:not(.${specificityMatchingName})`;
720
- const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _41 => _41.trim, 'call', _42 => _42()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _43 => _43.length]))).map((selector) => ({
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) => ({
721
819
  match: `${selector}${suffix}`,
722
820
  spacedMatch: `${selector} ${suffix}`,
723
821
  replacement: selector
@@ -746,17 +844,17 @@ function createRootSpecificityCleaner(options) {
746
844
  }
747
845
  var OklabSuffix = "in oklab";
748
846
  var logicalPropMap = /* @__PURE__ */ new Map([
749
- // margin
847
+ // margin 方向映射
750
848
  ["margin-inline-start", "margin-left"],
751
849
  ["margin-inline-end", "margin-right"],
752
850
  ["margin-block-start", "margin-top"],
753
851
  ["margin-block-end", "margin-bottom"],
754
- // padding
852
+ // padding 方向映射
755
853
  ["padding-inline-start", "padding-left"],
756
854
  ["padding-inline-end", "padding-right"],
757
855
  ["padding-block-start", "padding-top"],
758
856
  ["padding-block-end", "padding-bottom"],
759
- // border
857
+ // border 方向映射
760
858
  ["border-inline-start", "border-left"],
761
859
  ["border-inline-end", "border-right"],
762
860
  ["border-block-start", "border-top"],
@@ -863,7 +961,7 @@ function dedupeDeclarations(rule) {
863
961
  if (!needReorder) {
864
962
  continue;
865
963
  }
866
- const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _44 => _44[declarations.length - 1], 'optionalAccess', _45 => _45.next, 'call', _46 => _46()]), () => ( void 0));
964
+ const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _51 => _51[declarations.length - 1], 'optionalAccess', _52 => _52.next, 'call', _53 => _53()]), () => ( void 0));
867
965
  for (const decl of declarations) {
868
966
  decl.remove();
869
967
  }
@@ -908,9 +1006,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
908
1006
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
909
1007
  p.RuleExit = (rule) => {
910
1008
  if (enableMainChunkTransforms) {
911
- _optionalChain([fallbackRemove, 'optionalAccess', _47 => _47.transformSync, 'call', _48 => _48(rule)]);
1009
+ _optionalChain([fallbackRemove, 'optionalAccess', _54 => _54.transformSync, 'call', _55 => _55(rule)]);
912
1010
  }
913
- _optionalChain([cleanRootSpecificity, 'optionalCall', _49 => _49(rule)]);
1011
+ _optionalChain([cleanRootSpecificity, 'optionalCall', _56 => _56(rule)]);
914
1012
  if (enableMainChunkTransforms) {
915
1013
  dedupeDeclarations(rule);
916
1014
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
@@ -928,13 +1026,32 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
928
1026
  decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
929
1027
  } else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
930
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
+ }
931
1048
  }
932
1049
  };
933
1050
  p.AtRuleExit = (atRule) => {
934
1051
  if (opts.cssRemoveProperty && atRule.name === "property") {
935
1052
  atRule.remove();
936
1053
  }
937
- _optionalChain([atRule, 'access', _50 => _50.nodes, 'optionalAccess', _51 => _51.length]) === 0 && atRule.remove();
1054
+ _optionalChain([atRule, 'access', _57 => _57.nodes, 'optionalAccess', _58 => _58.length]) === 0 && atRule.remove();
938
1055
  };
939
1056
  }
940
1057
  return p;
@@ -1164,33 +1281,33 @@ function property(ident, initialValue, _syntax) {
1164
1281
  }
1165
1282
  var nullShadow = "0 0 #0000";
1166
1283
  var nodes = [
1167
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1284
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1168
1285
  property("--tw-border-spacing-x", "0", "<length>"),
1169
1286
  property("--tw-border-spacing-y", "0", "<length>"),
1170
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1287
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1171
1288
  property("--tw-translate-x", "0"),
1172
1289
  property("--tw-translate-y", "0"),
1173
1290
  property("--tw-translate-z", "0"),
1174
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1291
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1175
1292
  property("--tw-scale-x", "1"),
1176
1293
  property("--tw-scale-y", "1"),
1177
1294
  property("--tw-scale-z", "1"),
1178
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1295
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1179
1296
  property("--tw-rotate-x"),
1180
1297
  property("--tw-rotate-y"),
1181
1298
  property("--tw-rotate-z"),
1182
1299
  property("--tw-skew-x"),
1183
1300
  property("--tw-skew-y"),
1184
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1301
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1185
1302
  property("--tw-pan-x"),
1186
1303
  property("--tw-pan-y"),
1187
1304
  property("--tw-pinch-zoom"),
1188
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1305
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1189
1306
  property("--tw-scroll-snap-strictness", "proximity", "*"),
1190
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1307
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1191
1308
  property("--tw-space-x-reverse", "0"),
1192
1309
  property("--tw-space-y-reverse", "0"),
1193
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1310
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1194
1311
  property("--tw-border-style", "solid"),
1195
1312
  property("--tw-divide-x-reverse", "0"),
1196
1313
  property("--tw-divide-y-reverse", "0"),
@@ -1277,7 +1394,7 @@ var nodes = [
1277
1394
  property("--tw-ring-shadow", nullShadow),
1278
1395
  property("--tw-inset-ring-color"),
1279
1396
  property("--tw-inset-ring-shadow", nullShadow),
1280
- // Legacy
1397
+ // Legacy 旧版变量兼容
1281
1398
  property("--tw-ring-inset"),
1282
1399
  property("--tw-ring-offset-width", "0px", "<length>"),
1283
1400
  property("--tw-ring-offset-color", "#fff"),
@@ -1375,7 +1492,7 @@ function remakeCssVarSelector(selectors, options) {
1375
1492
  function commonChunkPreflight(node, options) {
1376
1493
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1377
1494
  if (testIfVariablesScope(node)) {
1378
- _optionalChain([ctx, 'optionalAccess', _52 => _52.markVariablesScope, 'call', _53 => _53(node)]);
1495
+ _optionalChain([ctx, 'optionalAccess', _59 => _59.markVariablesScope, 'call', _60 => _60(node)]);
1379
1496
  node.selectors = remakeCssVarSelector(node.selectors, options);
1380
1497
  node.before(makePseudoVarRule());
1381
1498
  if (typeof cssInjectPreflight === "function") {
@@ -1440,9 +1557,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1440
1557
  root.walkAtRules((atRule) => {
1441
1558
  if (atRule.name === "layer") {
1442
1559
  if (atRule.params === "properties") {
1443
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _54 => _54.nodes, 'optionalAccess', _55 => _55.length]) === 0) {
1560
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _61 => _61.nodes, 'optionalAccess', _62 => _62.length]) === 0) {
1444
1561
  layerProperties = atRule;
1445
- } else if (_optionalChain([atRule, 'access', _56 => _56.first, 'optionalAccess', _57 => _57.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1562
+ } else if (_optionalChain([atRule, 'access', _63 => _63.first, 'optionalAccess', _64 => _64.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1446
1563
  if (layerProperties) {
1447
1564
  layerProperties.replaceWith(atRule.first.nodes);
1448
1565
  atRule.remove();
@@ -1454,7 +1571,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1454
1571
  atRule.replaceWith(atRule.nodes);
1455
1572
  }
1456
1573
  } else if (isTailwindcssV4ModernCheck(atRule)) {
1457
- if (_optionalChain([atRule, 'access', _58 => _58.first, 'optionalAccess', _59 => _59.type]) === "atrule" && atRule.first.name === "layer") {
1574
+ if (_optionalChain([atRule, 'access', _65 => _65.first, 'optionalAccess', _66 => _66.type]) === "atrule" && atRule.first.name === "layer") {
1458
1575
  atRule.replaceWith(atRule.first.nodes);
1459
1576
  }
1460
1577
  }
@@ -1499,7 +1616,7 @@ function createPipelineDefinitions(options) {
1499
1616
  normal: [],
1500
1617
  post: []
1501
1618
  };
1502
- const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _60 => _60.postcssOptions, 'optionalAccess', _61 => _61.plugins]));
1619
+ const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _67 => _67.postcssOptions, 'optionalAccess', _68 => _68.plugins]));
1503
1620
  userPlugins.forEach((plugin, index) => {
1504
1621
  stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
1505
1622
  });
@@ -1521,6 +1638,15 @@ function createPipelineDefinitions(options) {
1521
1638
  createPlugin: () => _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
1522
1639
  })
1523
1640
  });
1641
+ stages.normal.push({
1642
+ id: "normal:color-functional-fallback",
1643
+ stage: "normal",
1644
+ prepare: () => ({
1645
+ id: "normal:color-functional-fallback",
1646
+ stage: "normal",
1647
+ createPlugin: () => createColorFunctionalFallback()
1648
+ })
1649
+ });
1524
1650
  stages.normal.push({
1525
1651
  id: "normal:px-transform",
1526
1652
  stage: "normal",
@@ -1650,7 +1776,7 @@ function createInjectPreflight(options) {
1650
1776
  function createProcessOptions(options) {
1651
1777
  return {
1652
1778
  from: void 0,
1653
- ..._nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.options]), () => ( {}))
1779
+ ..._nullishCoalesce(_optionalChain([options, 'access', _69 => _69.postcssOptions, 'optionalAccess', _70 => _70.options]), () => ( {}))
1654
1780
  };
1655
1781
  }
1656
1782
  var pipelineCache = /* @__PURE__ */ new WeakMap();
@@ -1665,7 +1791,7 @@ function getCachedPipeline(options) {
1665
1791
  return pipeline;
1666
1792
  }
1667
1793
  function getCachedProcessOptions(options) {
1668
- const source = _optionalChain([options, 'access', _64 => _64.postcssOptions, 'optionalAccess', _65 => _65.options]);
1794
+ const source = _optionalChain([options, 'access', _71 => _71.postcssOptions, 'optionalAccess', _72 => _72.options]);
1669
1795
  let cached = processOptionsCache.get(options);
1670
1796
  const cachedSource = processOptionsSourceCache.get(options);
1671
1797
  if (!cached || cachedSource !== source) {
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import postcss from "postcss";
7
7
  // src/defaults.ts
8
8
  function getDefaultOptions(options) {
9
9
  return {
10
- // https://github.com/postcss/postcss-calc
10
+ // 参考:https://github.com/postcss/postcss-calc
11
11
  cssPresetEnv: {
12
12
  features: {
13
13
  "cascade-layers": true,
@@ -16,6 +16,7 @@ function getDefaultOptions(options) {
16
16
  },
17
17
  "oklab-function": true,
18
18
  "color-mix": true,
19
+ "color-functional-notation": options?.cssPresetEnv?.features?.["color-functional-notation"] ?? { preserve: false },
19
20
  // 在 calc 下,这个需要开启
20
21
  "custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ?? options?.cssCalc ? { preserve: true } : false
21
22
  },
@@ -37,6 +38,103 @@ function getDefaultOptions(options) {
37
38
  // src/pipeline.ts
38
39
  import postcssPresetEnv from "postcss-preset-env";
39
40
 
41
+ // src/plugins/colorFunctionalFallback.ts
42
+ import valueParser from "postcss-value-parser";
43
+ var RGB_FUNCTION_NAME = "rgb";
44
+ var isSlashDiv = (node) => node.type === "div" && node.value === "/";
45
+ function trimNodes(nodes2) {
46
+ let start = 0;
47
+ let end = nodes2.length;
48
+ while (start < end && nodes2[start]?.type === "space") {
49
+ start += 1;
50
+ }
51
+ while (end > start && nodes2[end - 1]?.type === "space") {
52
+ end -= 1;
53
+ }
54
+ return nodes2.slice(start, end);
55
+ }
56
+ function splitColorComponents(nodes2) {
57
+ const parts = [];
58
+ let current = [];
59
+ nodes2.forEach((node) => {
60
+ if (node.type === "div" && node.value === ",") {
61
+ if (current.length) {
62
+ parts.push(current);
63
+ current = [];
64
+ }
65
+ return;
66
+ }
67
+ if (node.type === "space") {
68
+ if (current.length) {
69
+ parts.push(current);
70
+ current = [];
71
+ }
72
+ return;
73
+ }
74
+ current.push(node);
75
+ });
76
+ if (current.length) {
77
+ parts.push(current);
78
+ }
79
+ return parts;
80
+ }
81
+ var buildFunctionNodes = (content) => valueParser(content).nodes;
82
+ function convertRgbFunction(fnNode) {
83
+ const slashIndex = fnNode.nodes.findIndex(isSlashDiv);
84
+ if (slashIndex === -1) {
85
+ return false;
86
+ }
87
+ const colorNodes = trimNodes(fnNode.nodes.slice(0, slashIndex));
88
+ const alphaNodes = trimNodes(fnNode.nodes.slice(slashIndex + 1));
89
+ if (!colorNodes.length || !alphaNodes.length) {
90
+ return false;
91
+ }
92
+ const colorParts = splitColorComponents(colorNodes);
93
+ if (colorParts.length !== 3) {
94
+ return false;
95
+ }
96
+ const normalizedColors = colorParts.map((part) => valueParser.stringify(part).trim()).filter(Boolean);
97
+ if (normalizedColors.length !== 3) {
98
+ return false;
99
+ }
100
+ const alphaText = valueParser.stringify(alphaNodes).trim();
101
+ if (!alphaText) {
102
+ return false;
103
+ }
104
+ fnNode.value = "rgba";
105
+ const nextValue = `${normalizedColors.join(", ")}, ${alphaText}`;
106
+ fnNode.nodes = buildFunctionNodes(nextValue);
107
+ return true;
108
+ }
109
+ function transformDeclaration(decl) {
110
+ if (!decl.value || !decl.value.toLowerCase().includes(RGB_FUNCTION_NAME)) {
111
+ return;
112
+ }
113
+ const parsed = valueParser(decl.value);
114
+ let mutated = false;
115
+ parsed.walk((node) => {
116
+ if (node.type !== "function") {
117
+ return;
118
+ }
119
+ if (node.value.toLowerCase() !== RGB_FUNCTION_NAME) {
120
+ return;
121
+ }
122
+ if (convertRgbFunction(node)) {
123
+ mutated = true;
124
+ }
125
+ });
126
+ if (mutated) {
127
+ decl.value = parsed.toString();
128
+ }
129
+ }
130
+ function createColorFunctionalFallback() {
131
+ return {
132
+ postcssPlugin: "weapp-tailwindcss-color-functional-fallback",
133
+ Declaration: transformDeclaration
134
+ };
135
+ }
136
+ createColorFunctionalFallback.postcss = true;
137
+
40
138
  // src/plugins/ctx.ts
41
139
  function createContext() {
42
140
  const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
@@ -77,7 +175,7 @@ function getCalcPlugin(options) {
77
175
 
78
176
  // src/plugins/getCustomPropertyCleaner.ts
79
177
  import { regExpTest } from "@weapp-tailwindcss/shared";
80
- import valueParser from "postcss-value-parser";
178
+ import valueParser2 from "postcss-value-parser";
81
179
  function getCustomPropertyCleaner(options) {
82
180
  const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
83
181
  const shouldMatchCustomProperties = Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0;
@@ -99,7 +197,7 @@ function getCustomPropertyCleaner(options) {
99
197
  if (!shouldMatchCustomProperties || !/--/.test(decl.value)) {
100
198
  return;
101
199
  }
102
- const parsed = valueParser(decl.value);
200
+ const parsed = valueParser2(decl.value);
103
201
  let containsIncludedCustomProperty = false;
104
202
  parsed.walk((node) => {
105
203
  if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) {
@@ -746,17 +844,17 @@ function createRootSpecificityCleaner(options) {
746
844
  }
747
845
  var OklabSuffix = "in oklab";
748
846
  var logicalPropMap = /* @__PURE__ */ new Map([
749
- // margin
847
+ // margin 方向映射
750
848
  ["margin-inline-start", "margin-left"],
751
849
  ["margin-inline-end", "margin-right"],
752
850
  ["margin-block-start", "margin-top"],
753
851
  ["margin-block-end", "margin-bottom"],
754
- // padding
852
+ // padding 方向映射
755
853
  ["padding-inline-start", "padding-left"],
756
854
  ["padding-inline-end", "padding-right"],
757
855
  ["padding-block-start", "padding-top"],
758
856
  ["padding-block-end", "padding-bottom"],
759
- // border
857
+ // border 方向映射
760
858
  ["border-inline-start", "border-left"],
761
859
  ["border-inline-end", "border-right"],
762
860
  ["border-block-start", "border-top"],
@@ -928,6 +1026,25 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
928
1026
  decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
929
1027
  } else if (/calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/.test(decl.value)) {
930
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
+ }
931
1048
  }
932
1049
  };
933
1050
  p.AtRuleExit = (atRule) => {
@@ -1164,33 +1281,33 @@ function property(ident, initialValue, _syntax) {
1164
1281
  }
1165
1282
  var nullShadow = "0 0 #0000";
1166
1283
  var nodes = [
1167
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1284
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1137
1168
1285
  property("--tw-border-spacing-x", "0", "<length>"),
1169
1286
  property("--tw-border-spacing-y", "0", "<length>"),
1170
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1287
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1205
1171
1288
  property("--tw-translate-x", "0"),
1172
1289
  property("--tw-translate-y", "0"),
1173
1290
  property("--tw-translate-z", "0"),
1174
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1291
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1285
1175
1292
  property("--tw-scale-x", "1"),
1176
1293
  property("--tw-scale-y", "1"),
1177
1294
  property("--tw-scale-z", "1"),
1178
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1295
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1424
1179
1296
  property("--tw-rotate-x"),
1180
1297
  property("--tw-rotate-y"),
1181
1298
  property("--tw-rotate-z"),
1182
1299
  property("--tw-skew-x"),
1183
1300
  property("--tw-skew-y"),
1184
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1301
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1641C13-L1641C88
1185
1302
  property("--tw-pan-x"),
1186
1303
  property("--tw-pan-y"),
1187
1304
  property("--tw-pinch-zoom"),
1188
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1305
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1189
1306
  property("--tw-scroll-snap-strictness", "proximity", "*"),
1190
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1307
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L1688C38-L1688C95
1191
1308
  property("--tw-space-x-reverse", "0"),
1192
1309
  property("--tw-space-y-reverse", "0"),
1193
- // https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1310
+ // 参考:https://github.com/tailwindlabs/tailwindcss/blob/main/packages/tailwindcss/src/utilities.ts#L2169C22-L2169C60
1194
1311
  property("--tw-border-style", "solid"),
1195
1312
  property("--tw-divide-x-reverse", "0"),
1196
1313
  property("--tw-divide-y-reverse", "0"),
@@ -1277,7 +1394,7 @@ var nodes = [
1277
1394
  property("--tw-ring-shadow", nullShadow),
1278
1395
  property("--tw-inset-ring-color"),
1279
1396
  property("--tw-inset-ring-shadow", nullShadow),
1280
- // Legacy
1397
+ // Legacy 旧版变量兼容
1281
1398
  property("--tw-ring-inset"),
1282
1399
  property("--tw-ring-offset-width", "0px", "<length>"),
1283
1400
  property("--tw-ring-offset-color", "#fff"),
@@ -1521,6 +1638,15 @@ function createPipelineDefinitions(options) {
1521
1638
  createPlugin: () => postcssPresetEnv(options.cssPresetEnv)
1522
1639
  })
1523
1640
  });
1641
+ stages.normal.push({
1642
+ id: "normal:color-functional-fallback",
1643
+ stage: "normal",
1644
+ prepare: () => ({
1645
+ id: "normal:color-functional-fallback",
1646
+ stage: "normal",
1647
+ createPlugin: () => createColorFunctionalFallback()
1648
+ })
1649
+ });
1524
1650
  stages.normal.push({
1525
1651
  id: "normal:px-transform",
1526
1652
  stage: "normal",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
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.7",
46
+ "postcss-pxtransform": "^4.1.8",
47
47
  "postcss-rem-to-responsive-pixel": "^6.1.0",
48
48
  "postcss-selector-parser": "~7.1.0",
49
49
  "postcss-value-parser": "^4.2.0",