@weapp-tailwindcss/postcss 1.0.4 → 1.0.6

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 +134 -50
  2. package/dist/index.mjs +124 -40
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28,17 +28,14 @@ function getDefaultOptions() {
28
28
  var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
29
29
  var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
30
30
 
31
- // src/symbols.ts
32
- var VariablesScopeSymbol = Symbol("VariablesScope");
33
-
34
31
  // src/plugins/ctx.ts
35
32
  function createContext() {
36
33
  const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
37
34
  function isVariablesScope(rule) {
38
- return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
35
+ return variablesScopeWeakMap.get(rule) === true;
39
36
  }
40
37
  function markVariablesScope(rule) {
41
- variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
38
+ variablesScopeWeakMap.set(rule, true);
42
39
  }
43
40
  return {
44
41
  variablesScopeWeakMap,
@@ -77,27 +74,130 @@ function composeIsPseudo(strs) {
77
74
  }
78
75
 
79
76
  // src/selectorParser.ts
77
+ function mklist(node) {
78
+ return [
79
+ node,
80
+ _postcssselectorparser2.default.combinator({
81
+ value: "+"
82
+ }),
83
+ node.clone()
84
+ ];
85
+ }
86
+ function composeIsPseudoAst(strs) {
87
+ if (typeof strs === "string") {
88
+ return mklist(_postcssselectorparser2.default.tag({
89
+ value: strs
90
+ }));
91
+ }
92
+ if (strs.length > 1) {
93
+ return mklist(_postcssselectorparser2.default.pseudo({
94
+ value: ":is",
95
+ nodes: strs.map(
96
+ (str) => _postcssselectorparser2.default.tag({
97
+ value: str
98
+ })
99
+ )
100
+ }));
101
+ }
102
+ return mklist(_postcssselectorparser2.default.tag({
103
+ value: strs[0]
104
+ }));
105
+ }
106
+ function getCombinatorSelectorAst(options) {
107
+ let childCombinatorReplaceValue = mklist(_postcssselectorparser2.default.tag({ value: "view" }));
108
+ const { cssChildCombinatorReplaceValue } = options;
109
+ if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
110
+ childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
111
+ }
112
+ return childCombinatorReplaceValue;
113
+ }
80
114
  function createRuleTransform(rule, options) {
81
115
  const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
82
116
  const transform = (selectors) => {
83
- selectors.walk((selector) => {
84
- if (selector.type === "universal" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
85
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
86
- }
87
- if (cssRemoveHoverPseudoClass && selector.type === "selector") {
88
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
89
- if (node) {
90
- selector.remove();
117
+ selectors.walk((selector, index) => {
118
+ if (selector.type === "universal") {
119
+ if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
120
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
91
121
  }
92
- }
93
- if (selector.type === "pseudo" && selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
94
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
95
- }
96
- if (selector.type === "class") {
122
+ } else if (selector.type === "selector") {
123
+ if (cssRemoveHoverPseudoClass) {
124
+ const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
125
+ if (node) {
126
+ selector.remove();
127
+ }
128
+ }
129
+ } else if (selector.type === "pseudo") {
130
+ if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
131
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
132
+ } else if (selector.value === ":where") {
133
+ if (index === 0 && selector.length === 1) {
134
+ selector.walk((node, idx) => {
135
+ if (idx === 0 && node.type === "class") {
136
+ const nodes = _optionalChain([node, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.nodes]);
137
+ if (nodes) {
138
+ const first = nodes[idx + 1];
139
+ if (first && first.type === "combinator" && first.value === ">") {
140
+ const second = nodes[idx + 2];
141
+ if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
142
+ const ast = getCombinatorSelectorAst(options);
143
+ second.replaceWith(
144
+ ...ast
145
+ );
146
+ }
147
+ }
148
+ }
149
+ }
150
+ });
151
+ selector.replaceWith(...selector.nodes);
152
+ for (const node of rule.nodes) {
153
+ if (node.type === "decl") {
154
+ if (node.prop === "margin-block-start") {
155
+ node.prop = "margin-block-end";
156
+ } else if (node.prop === "margin-block-end") {
157
+ node.prop = "margin-block-start";
158
+ } else if (node.prop === "margin-inline-start") {
159
+ node.prop = "margin-inline-end";
160
+ } else if (node.prop === "margin-inline-end") {
161
+ node.prop = "margin-inline-start";
162
+ } else if (node.prop === "margin-top") {
163
+ node.prop = "margin-bottom";
164
+ } else if (node.prop === "margin-bottom") {
165
+ node.prop = "margin-top";
166
+ } else if (node.prop === "margin-left") {
167
+ node.prop = "margin-right";
168
+ } else if (node.prop === "margin-right") {
169
+ node.prop = "margin-left";
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ } else if (selector.type === "class") {
97
176
  selector.value = internalCssSelectorReplacer(selector.value, {
98
177
  escapeMap,
99
178
  mangleContext
100
179
  });
180
+ } else if (selector.type === "combinator") {
181
+ if (selector.value === ">") {
182
+ const nodes = _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
183
+ if (nodes) {
184
+ const first = nodes[index + 1];
185
+ if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
186
+ const second = nodes[index + 2];
187
+ if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
188
+ const third = nodes[index + 3];
189
+ if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
190
+ const ast = getCombinatorSelectorAst(options);
191
+ _optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes, 'access', _9 => _9.splice, 'call', _10 => _10(
192
+ index + 1,
193
+ 3,
194
+ ...ast
195
+ )]);
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
101
201
  }
102
202
  });
103
203
  if (selectors.length === 0) {
@@ -118,7 +218,7 @@ function isOnlyBeforeAndAfterPseudoElement(node) {
118
218
  let a = false;
119
219
  _postcssselectorparser2.default.call(void 0, (selectors) => {
120
220
  selectors.walkPseudos((s) => {
121
- if (_optionalChain([s, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.length]) === 1) {
221
+ if (_optionalChain([s, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.length]) === 1) {
122
222
  if (/^:?:before$/.test(s.value)) {
123
223
  b = true;
124
224
  }
@@ -138,14 +238,14 @@ function getFallbackRemove(rule) {
138
238
  maybeImportantId = true;
139
239
  }
140
240
  if (selector.type === "universal") {
141
- _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.remove, 'call', _7 => _7()]);
241
+ _optionalChain([selector, 'access', _13 => _13.parent, 'optionalAccess', _14 => _14.remove, 'call', _15 => _15()]);
142
242
  }
143
243
  if (selector.type === "pseudo") {
144
244
  if (selector.value === ":is") {
145
- if (maybeImportantId && _optionalChain([selector, 'access', _8 => _8.nodes, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.type]) === "selector") {
245
+ if (maybeImportantId && _optionalChain([selector, 'access', _16 => _16.nodes, 'access', _17 => _17[0], 'optionalAccess', _18 => _18.type]) === "selector") {
146
246
  selector.replaceWith(selector.nodes[0]);
147
247
  } else {
148
- _optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
248
+ _optionalChain([selector, 'access', _19 => _19.parent, 'optionalAccess', _20 => _20.remove, 'call', _21 => _21()]);
149
249
  }
150
250
  } else if (selector.value === ":not") {
151
251
  for (const x of selector.nodes) {
@@ -169,7 +269,7 @@ function getFallbackRemove(rule) {
169
269
  }
170
270
  if (selector.type === "attribute") {
171
271
  if (selector.attribute === "hidden") {
172
- _optionalChain([rule, 'optionalAccess', _14 => _14.remove, 'call', _15 => _15()]);
272
+ _optionalChain([rule, 'optionalAccess', _22 => _22.remove, 'call', _23 => _23()]);
173
273
  }
174
274
  }
175
275
  });
@@ -441,11 +541,6 @@ var initialNodes = cssVars_default.map((x) => {
441
541
  value: x.value
442
542
  });
443
543
  });
444
- var PATTERNS = [
445
- /:not\(template\)\s*[~+]\s*:not\(template\)/.source,
446
- /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
447
- ].join("|");
448
- var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
449
544
  function testIfVariablesScope(node, count = 2) {
450
545
  if (isOnlyBeforeAndAfterPseudoElement(node)) {
451
546
  const nodes = node.nodes;
@@ -509,21 +604,10 @@ function remakeCssVarSelector(selectors, options) {
509
604
  }
510
605
  return selectors;
511
606
  }
512
- function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
513
- let childCombinatorReplaceValue = "view + view";
514
- if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
515
- const x = composeIsPseudo(cssChildCombinatorReplaceValue);
516
- childCombinatorReplaceValue = `${x} + ${x}`;
517
- } else if (typeof cssChildCombinatorReplaceValue === "string") {
518
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
519
- }
520
- return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
521
- }
522
607
  function commonChunkPreflight(node, options) {
523
- const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
524
- node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
608
+ const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
525
609
  if (testIfVariablesScope(node)) {
526
- _optionalChain([ctx, 'optionalAccess', _16 => _16.markVariablesScope, 'call', _17 => _17(node)]);
610
+ _optionalChain([ctx, 'optionalAccess', _24 => _24.markVariablesScope, 'call', _25 => _25(node)]);
527
611
  node.selectors = remakeCssVarSelector(node.selectors, options);
528
612
  node.before(makePseudoVarRule());
529
613
  if (typeof cssInjectPreflight === "function") {
@@ -587,7 +671,7 @@ function compare(e3, t2) {
587
671
  return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
588
672
  }
589
673
  function selectorSpecificity(t2, s) {
590
- const i = _optionalChain([s, 'optionalAccess', _18 => _18.customSpecificity, 'optionalCall', _19 => _19(t2)]);
674
+ const i = _optionalChain([s, 'optionalAccess', _26 => _26.customSpecificity, 'optionalCall', _27 => _27(t2)]);
591
675
  if (i) return i;
592
676
  if (!t2) return { a: 0, b: 0, c: 0 };
593
677
  let c = 0, n = 0, o2 = 0;
@@ -663,7 +747,7 @@ function selectorSpecificity(t2, s) {
663
747
  case ":active-view-transition-type":
664
748
  return { a: 0, b: 1, c: 0 };
665
749
  }
666
- else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _20 => _20.nodes, 'optionalAccess', _21 => _21.length]) > 0 && t2.nodes.forEach((e3) => {
750
+ else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _28 => _28.nodes, 'optionalAccess', _29 => _29.length]) > 0 && t2.nodes.forEach((e3) => {
667
751
  const t3 = selectorSpecificity(e3, s);
668
752
  c += t3.a, n += t3.b, o2 += t3.c;
669
753
  });
@@ -691,8 +775,8 @@ function alwaysValidSelector(s) {
691
775
  const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
692
776
  let t2 = true;
693
777
  return o2.walk((e3) => {
694
- if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || _optionalChain([e3, 'access', _22 => _22.nodes, 'optionalAccess', _23 => _23.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
695
- if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _24 => _24.nodes, 'optionalAccess', _25 => _25.length]) && ":not" === e3.value.toLowerCase()) {
778
+ if ("class" !== e3.type && "comment" !== e3.type && "id" !== e3.type && "root" !== e3.type && "selector" !== e3.type && "string" !== e3.type && "tag" !== e3.type && "universal" !== e3.type && ("attribute" !== e3.type || e3.insensitive) && ("combinator" !== e3.type || "+" !== e3.value && ">" !== e3.value && "~" !== e3.value && " " !== e3.value) && ("pseudo" !== e3.type || _optionalChain([e3, 'access', _30 => _30.nodes, 'optionalAccess', _31 => _31.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
779
+ if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _32 => _32.nodes, 'optionalAccess', _33 => _33.length]) && ":not" === e3.value.toLowerCase()) {
696
780
  let s2 = true;
697
781
  if (e3.nodes[0].walkCombinators(() => {
698
782
  s2 = false;
@@ -804,8 +888,8 @@ function splitSelectors(o2, t2, n = 0) {
804
888
  if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
805
889
  if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
806
890
  if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
807
- if ("pseudo" === _optionalChain([e3, 'access', _26 => _26.parent, 'optionalAccess', _27 => _27.parent, 'optionalAccess', _28 => _28.type]) && ":not" === _optionalChain([e3, 'access', _29 => _29.parent, 'optionalAccess', _30 => _30.parent, 'optionalAccess', _31 => _31.value, 'optionalAccess', _32 => _32.toLowerCase, 'call', _33 => _33()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
808
- if ("pseudo" === _optionalChain([e3, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.parent, 'optionalAccess', _36 => _36.type]) && ":has" === _optionalChain([e3, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.parent, 'optionalAccess', _39 => _39.value, 'optionalAccess', _40 => _40.toLowerCase, 'call', _41 => _41()])) return void (e3.value = ":-csstools-matches");
891
+ if ("pseudo" === _optionalChain([e3, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.parent, 'optionalAccess', _36 => _36.type]) && ":not" === _optionalChain([e3, 'access', _37 => _37.parent, 'optionalAccess', _38 => _38.parent, 'optionalAccess', _39 => _39.value, 'optionalAccess', _40 => _40.toLowerCase, 'call', _41 => _41()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
892
+ if ("pseudo" === _optionalChain([e3, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.parent, 'optionalAccess', _44 => _44.type]) && ":has" === _optionalChain([e3, 'access', _45 => _45.parent, 'optionalAccess', _46 => _46.parent, 'optionalAccess', _47 => _47.value, 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()])) return void (e3.value = ":-csstools-matches");
809
893
  let o4 = e3.parent;
810
894
  for (; o4; ) {
811
895
  if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
@@ -827,7 +911,7 @@ function splitSelectors(o2, t2, n = 0) {
827
911
  let s = "";
828
912
  for (let t3 = 0; t3 < e3.length; t3++) {
829
913
  const n2 = e3[t3];
830
- s += o3.substring(_optionalChain([e3, 'access', _42 => _42[t3 - 1], 'optionalAccess', _43 => _43.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
914
+ s += o3.substring(_optionalChain([e3, 'access', _50 => _50[t3 - 1], 'optionalAccess', _51 => _51.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
831
915
  }
832
916
  c.push(s);
833
917
  }), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
@@ -888,7 +972,7 @@ function getPlugins(options) {
888
972
  const ctx = createContext();
889
973
  options.ctx = ctx;
890
974
  const plugins = [
891
- ..._nullishCoalesce(_optionalChain([options, 'access', _44 => _44.postcssOptions, 'optionalAccess', _45 => _45.plugins]), () => ( [])),
975
+ ..._nullishCoalesce(_optionalChain([options, 'access', _52 => _52.postcssOptions, 'optionalAccess', _53 => _53.plugins]), () => ( [])),
892
976
  postcssWeappTailwindcssPrePlugin(options),
893
977
  _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
894
978
  ];
@@ -932,7 +1016,7 @@ function styleHandler(rawSource, options) {
932
1016
  getPlugins(options)
933
1017
  ).process(
934
1018
  rawSource,
935
- _nullishCoalesce(_optionalChain([options, 'access', _46 => _46.postcssOptions, 'optionalAccess', _47 => _47.options]), () => ( {
1019
+ _nullishCoalesce(_optionalChain([options, 'access', _54 => _54.postcssOptions, 'optionalAccess', _55 => _55.options]), () => ( {
936
1020
  from: void 0
937
1021
  }))
938
1022
  ).async();
package/dist/index.mjs CHANGED
@@ -28,17 +28,14 @@ function getDefaultOptions() {
28
28
  import postcssPresetEnv from "postcss-preset-env";
29
29
  import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
30
30
 
31
- // src/symbols.ts
32
- var VariablesScopeSymbol = Symbol("VariablesScope");
33
-
34
31
  // src/plugins/ctx.ts
35
32
  function createContext() {
36
33
  const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
37
34
  function isVariablesScope(rule) {
38
- return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
35
+ return variablesScopeWeakMap.get(rule) === true;
39
36
  }
40
37
  function markVariablesScope(rule) {
41
- variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
38
+ variablesScopeWeakMap.set(rule, true);
42
39
  }
43
40
  return {
44
41
  variablesScopeWeakMap,
@@ -51,7 +48,7 @@ function createContext() {
51
48
  var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
52
49
 
53
50
  // src/selectorParser.ts
54
- import selectorParser from "postcss-selector-parser";
51
+ import psp from "postcss-selector-parser";
55
52
 
56
53
  // src/shared.ts
57
54
  import { escape, MappingChars2String } from "@weapp-core/escape";
@@ -77,27 +74,130 @@ function composeIsPseudo(strs) {
77
74
  }
78
75
 
79
76
  // src/selectorParser.ts
77
+ function mklist(node) {
78
+ return [
79
+ node,
80
+ psp.combinator({
81
+ value: "+"
82
+ }),
83
+ node.clone()
84
+ ];
85
+ }
86
+ function composeIsPseudoAst(strs) {
87
+ if (typeof strs === "string") {
88
+ return mklist(psp.tag({
89
+ value: strs
90
+ }));
91
+ }
92
+ if (strs.length > 1) {
93
+ return mklist(psp.pseudo({
94
+ value: ":is",
95
+ nodes: strs.map(
96
+ (str) => psp.tag({
97
+ value: str
98
+ })
99
+ )
100
+ }));
101
+ }
102
+ return mklist(psp.tag({
103
+ value: strs[0]
104
+ }));
105
+ }
106
+ function getCombinatorSelectorAst(options) {
107
+ let childCombinatorReplaceValue = mklist(psp.tag({ value: "view" }));
108
+ const { cssChildCombinatorReplaceValue } = options;
109
+ if (typeof cssChildCombinatorReplaceValue === "string" || Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
110
+ childCombinatorReplaceValue = composeIsPseudoAst(cssChildCombinatorReplaceValue);
111
+ }
112
+ return childCombinatorReplaceValue;
113
+ }
80
114
  function createRuleTransform(rule, options) {
81
115
  const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
82
116
  const transform = (selectors) => {
83
- selectors.walk((selector) => {
84
- if (selector.type === "universal" && cssSelectorReplacement?.universal) {
85
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
86
- }
87
- if (cssRemoveHoverPseudoClass && selector.type === "selector") {
88
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
89
- if (node) {
90
- selector.remove();
117
+ selectors.walk((selector, index) => {
118
+ if (selector.type === "universal") {
119
+ if (cssSelectorReplacement?.universal) {
120
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
91
121
  }
92
- }
93
- if (selector.type === "pseudo" && selector.value === ":root" && cssSelectorReplacement?.root) {
94
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
95
- }
96
- if (selector.type === "class") {
122
+ } else if (selector.type === "selector") {
123
+ if (cssRemoveHoverPseudoClass) {
124
+ const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
125
+ if (node) {
126
+ selector.remove();
127
+ }
128
+ }
129
+ } else if (selector.type === "pseudo") {
130
+ if (selector.value === ":root" && cssSelectorReplacement?.root) {
131
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
132
+ } else if (selector.value === ":where") {
133
+ if (index === 0 && selector.length === 1) {
134
+ selector.walk((node, idx) => {
135
+ if (idx === 0 && node.type === "class") {
136
+ const nodes = node.parent?.nodes;
137
+ if (nodes) {
138
+ const first = nodes[idx + 1];
139
+ if (first && first.type === "combinator" && first.value === ">") {
140
+ const second = nodes[idx + 2];
141
+ if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
142
+ const ast = getCombinatorSelectorAst(options);
143
+ second.replaceWith(
144
+ ...ast
145
+ );
146
+ }
147
+ }
148
+ }
149
+ }
150
+ });
151
+ selector.replaceWith(...selector.nodes);
152
+ for (const node of rule.nodes) {
153
+ if (node.type === "decl") {
154
+ if (node.prop === "margin-block-start") {
155
+ node.prop = "margin-block-end";
156
+ } else if (node.prop === "margin-block-end") {
157
+ node.prop = "margin-block-start";
158
+ } else if (node.prop === "margin-inline-start") {
159
+ node.prop = "margin-inline-end";
160
+ } else if (node.prop === "margin-inline-end") {
161
+ node.prop = "margin-inline-start";
162
+ } else if (node.prop === "margin-top") {
163
+ node.prop = "margin-bottom";
164
+ } else if (node.prop === "margin-bottom") {
165
+ node.prop = "margin-top";
166
+ } else if (node.prop === "margin-left") {
167
+ node.prop = "margin-right";
168
+ } else if (node.prop === "margin-right") {
169
+ node.prop = "margin-left";
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ } else if (selector.type === "class") {
97
176
  selector.value = internalCssSelectorReplacer(selector.value, {
98
177
  escapeMap,
99
178
  mangleContext
100
179
  });
180
+ } else if (selector.type === "combinator") {
181
+ if (selector.value === ">") {
182
+ const nodes = selector.parent?.nodes;
183
+ if (nodes) {
184
+ const first = nodes[index + 1];
185
+ if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
186
+ const second = nodes[index + 2];
187
+ if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
188
+ const third = nodes[index + 3];
189
+ if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
190
+ const ast = getCombinatorSelectorAst(options);
191
+ selector.parent?.nodes.splice(
192
+ index + 1,
193
+ 3,
194
+ ...ast
195
+ );
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
101
201
  }
102
202
  });
103
203
  if (selectors.length === 0) {
@@ -107,7 +207,7 @@ function createRuleTransform(rule, options) {
107
207
  return transform;
108
208
  }
109
209
  function ruleTransformSync(rule, options) {
110
- const transformer = selectorParser(createRuleTransform(rule, options));
210
+ const transformer = psp(createRuleTransform(rule, options));
111
211
  return transformer.transformSync(rule, {
112
212
  lossless: false,
113
213
  updateSelector: true
@@ -116,7 +216,7 @@ function ruleTransformSync(rule, options) {
116
216
  function isOnlyBeforeAndAfterPseudoElement(node) {
117
217
  let b = false;
118
218
  let a = false;
119
- selectorParser((selectors) => {
219
+ psp((selectors) => {
120
220
  selectors.walkPseudos((s) => {
121
221
  if (s.parent?.length === 1) {
122
222
  if (/^:?:before$/.test(s.value)) {
@@ -131,7 +231,7 @@ function isOnlyBeforeAndAfterPseudoElement(node) {
131
231
  return b && a;
132
232
  }
133
233
  function getFallbackRemove(rule) {
134
- const fallbackRemove = selectorParser((selectors) => {
234
+ const fallbackRemove = psp((selectors) => {
135
235
  let maybeImportantId = false;
136
236
  selectors.walk((selector, idx) => {
137
237
  if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) {
@@ -151,7 +251,7 @@ function getFallbackRemove(rule) {
151
251
  for (const x of selector.nodes) {
152
252
  if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") {
153
253
  x.nodes = [
154
- selectorParser.tag({
254
+ psp.tag({
155
255
  value: "#n"
156
256
  })
157
257
  ];
@@ -441,11 +541,6 @@ var initialNodes = cssVars_default.map((x) => {
441
541
  value: x.value
442
542
  });
443
543
  });
444
- var PATTERNS = [
445
- /:not\(template\)\s*[~+]\s*:not\(template\)/.source,
446
- /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
447
- ].join("|");
448
- var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
449
544
  function testIfVariablesScope(node, count = 2) {
450
545
  if (isOnlyBeforeAndAfterPseudoElement(node)) {
451
546
  const nodes = node.nodes;
@@ -509,19 +604,8 @@ function remakeCssVarSelector(selectors, options) {
509
604
  }
510
605
  return selectors;
511
606
  }
512
- function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
513
- let childCombinatorReplaceValue = "view + view";
514
- if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
515
- const x = composeIsPseudo(cssChildCombinatorReplaceValue);
516
- childCombinatorReplaceValue = `${x} + ${x}`;
517
- } else if (typeof cssChildCombinatorReplaceValue === "string") {
518
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
519
- }
520
- return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
521
- }
522
607
  function commonChunkPreflight(node, options) {
523
- const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
524
- node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
608
+ const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
525
609
  if (testIfVariablesScope(node)) {
526
610
  ctx?.markVariablesScope(node);
527
611
  node.selectors = remakeCssVarSelector(node.selectors, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",