@weapp-tailwindcss/postcss 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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
@@ -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() === "") {
@@ -934,7 +1032,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
934
1032
  if (opts.cssRemoveProperty && atRule.name === "property") {
935
1033
  atRule.remove();
936
1034
  }
937
- _optionalChain([atRule, 'access', _50 => _50.nodes, 'optionalAccess', _51 => _51.length]) === 0 && atRule.remove();
1035
+ _optionalChain([atRule, 'access', _57 => _57.nodes, 'optionalAccess', _58 => _58.length]) === 0 && atRule.remove();
938
1036
  };
939
1037
  }
940
1038
  return p;
@@ -1375,7 +1473,7 @@ function remakeCssVarSelector(selectors, options) {
1375
1473
  function commonChunkPreflight(node, options) {
1376
1474
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1377
1475
  if (testIfVariablesScope(node)) {
1378
- _optionalChain([ctx, 'optionalAccess', _52 => _52.markVariablesScope, 'call', _53 => _53(node)]);
1476
+ _optionalChain([ctx, 'optionalAccess', _59 => _59.markVariablesScope, 'call', _60 => _60(node)]);
1379
1477
  node.selectors = remakeCssVarSelector(node.selectors, options);
1380
1478
  node.before(makePseudoVarRule());
1381
1479
  if (typeof cssInjectPreflight === "function") {
@@ -1440,9 +1538,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1440
1538
  root.walkAtRules((atRule) => {
1441
1539
  if (atRule.name === "layer") {
1442
1540
  if (atRule.params === "properties") {
1443
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _54 => _54.nodes, 'optionalAccess', _55 => _55.length]) === 0) {
1541
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _61 => _61.nodes, 'optionalAccess', _62 => _62.length]) === 0) {
1444
1542
  layerProperties = atRule;
1445
- } else if (_optionalChain([atRule, 'access', _56 => _56.first, 'optionalAccess', _57 => _57.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1543
+ } else if (_optionalChain([atRule, 'access', _63 => _63.first, 'optionalAccess', _64 => _64.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1446
1544
  if (layerProperties) {
1447
1545
  layerProperties.replaceWith(atRule.first.nodes);
1448
1546
  atRule.remove();
@@ -1454,7 +1552,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1454
1552
  atRule.replaceWith(atRule.nodes);
1455
1553
  }
1456
1554
  } else if (isTailwindcssV4ModernCheck(atRule)) {
1457
- if (_optionalChain([atRule, 'access', _58 => _58.first, 'optionalAccess', _59 => _59.type]) === "atrule" && atRule.first.name === "layer") {
1555
+ if (_optionalChain([atRule, 'access', _65 => _65.first, 'optionalAccess', _66 => _66.type]) === "atrule" && atRule.first.name === "layer") {
1458
1556
  atRule.replaceWith(atRule.first.nodes);
1459
1557
  }
1460
1558
  }
@@ -1499,7 +1597,7 @@ function createPipelineDefinitions(options) {
1499
1597
  normal: [],
1500
1598
  post: []
1501
1599
  };
1502
- const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _60 => _60.postcssOptions, 'optionalAccess', _61 => _61.plugins]));
1600
+ const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _67 => _67.postcssOptions, 'optionalAccess', _68 => _68.plugins]));
1503
1601
  userPlugins.forEach((plugin, index) => {
1504
1602
  stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
1505
1603
  });
@@ -1521,6 +1619,15 @@ function createPipelineDefinitions(options) {
1521
1619
  createPlugin: () => _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
1522
1620
  })
1523
1621
  });
1622
+ stages.normal.push({
1623
+ id: "normal:color-functional-fallback",
1624
+ stage: "normal",
1625
+ prepare: () => ({
1626
+ id: "normal:color-functional-fallback",
1627
+ stage: "normal",
1628
+ createPlugin: () => createColorFunctionalFallback()
1629
+ })
1630
+ });
1524
1631
  stages.normal.push({
1525
1632
  id: "normal:px-transform",
1526
1633
  stage: "normal",
@@ -1650,7 +1757,7 @@ function createInjectPreflight(options) {
1650
1757
  function createProcessOptions(options) {
1651
1758
  return {
1652
1759
  from: void 0,
1653
- ..._nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.options]), () => ( {}))
1760
+ ..._nullishCoalesce(_optionalChain([options, 'access', _69 => _69.postcssOptions, 'optionalAccess', _70 => _70.options]), () => ( {}))
1654
1761
  };
1655
1762
  }
1656
1763
  var pipelineCache = /* @__PURE__ */ new WeakMap();
@@ -1665,7 +1772,7 @@ function getCachedPipeline(options) {
1665
1772
  return pipeline;
1666
1773
  }
1667
1774
  function getCachedProcessOptions(options) {
1668
- const source = _optionalChain([options, 'access', _64 => _64.postcssOptions, 'optionalAccess', _65 => _65.options]);
1775
+ const source = _optionalChain([options, 'access', _71 => _71.postcssOptions, 'optionalAccess', _72 => _72.options]);
1669
1776
  let cached = processOptionsCache.get(options);
1670
1777
  const cachedSource = processOptionsSourceCache.get(options);
1671
1778
  if (!cached || cachedSource !== source) {
package/dist/index.mjs CHANGED
@@ -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) {
@@ -1521,6 +1619,15 @@ function createPipelineDefinitions(options) {
1521
1619
  createPlugin: () => postcssPresetEnv(options.cssPresetEnv)
1522
1620
  })
1523
1621
  });
1622
+ stages.normal.push({
1623
+ id: "normal:color-functional-fallback",
1624
+ stage: "normal",
1625
+ prepare: () => ({
1626
+ id: "normal:color-functional-fallback",
1627
+ stage: "normal",
1628
+ createPlugin: () => createColorFunctionalFallback()
1629
+ })
1630
+ });
1524
1631
  stages.normal.push({
1525
1632
  id: "normal:px-transform",
1526
1633
  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.2",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",