@weapp-tailwindcss/postcss 1.0.10 → 1.0.12

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-PPOinWpH.mjs';
2
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-PPOinWpH.mjs';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-BuzFFGLX.mjs';
2
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-BuzFFGLX.mjs';
3
3
  import postcss from 'postcss';
4
4
  import '@weapp-tailwindcss/mangle';
5
5
  import 'postcss-load-config';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-PPOinWpH.js';
2
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-PPOinWpH.js';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-BuzFFGLX.js';
2
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-BuzFFGLX.js';
3
3
  import postcss from 'postcss';
4
4
  import '@weapp-tailwindcss/mangle';
5
5
  import 'postcss-load-config';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postc
7
7
  // src/defaults.ts
8
8
  function getDefaultOptions() {
9
9
  return {
10
+ // https://github.com/postcss/postcss-calc
10
11
  cssPresetEnv: {
11
12
  features: {
12
13
  "cascade-layers": true,
@@ -22,6 +23,8 @@ function getDefaultOptions() {
22
23
  }
23
24
  },
24
25
  cssRemoveProperty: true,
26
+ // cssRemoveAtSupports: true,
27
+ // cssRemoveAtMedia: true,
25
28
  cssSelectorReplacement: {
26
29
  root: "page",
27
30
  universal: ["view", "text"]
@@ -120,92 +123,103 @@ function getCombinatorSelectorAst(options) {
120
123
  return childCombinatorReplaceValue;
121
124
  }
122
125
  function createRuleTransform(rule, options) {
123
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
126
+ const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
124
127
  const transform = (selectors) => {
125
128
  selectors.walk((selector, index) => {
126
- if (selector.type === "universal") {
127
- if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
128
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
129
- }
130
- } else if (selector.type === "selector") {
131
- if (cssRemoveHoverPseudoClass) {
132
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
133
- if (node) {
134
- selector.remove();
129
+ if (!uniAppX) {
130
+ if (selector.type === "class") {
131
+ selector.value = internalCssSelectorReplacer(selector.value, {
132
+ escapeMap,
133
+ mangleContext
134
+ });
135
+ } else if (selector.type === "universal") {
136
+ if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
137
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
135
138
  }
136
- }
137
- } else if (selector.type === "pseudo") {
138
- if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
139
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
140
- } else if (selector.value === ":where") {
141
- if (index === 0 && selector.length === 1) {
142
- selector.walk((node, idx) => {
143
- if (idx === 0 && node.type === "class") {
144
- const nodes = _optionalChain([node, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.nodes]);
145
- if (nodes) {
146
- const first = nodes[idx + 1];
147
- if (first && first.type === "combinator" && first.value === ">") {
148
- const second = nodes[idx + 2];
149
- if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
150
- const ast = getCombinatorSelectorAst(options);
151
- second.replaceWith(
152
- ...ast
153
- );
139
+ } else if (selector.type === "selector") {
140
+ if (cssRemoveHoverPseudoClass) {
141
+ const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
142
+ if (node) {
143
+ selector.remove();
144
+ }
145
+ }
146
+ } else if (selector.type === "pseudo") {
147
+ if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
148
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
149
+ } else if (selector.value === ":where") {
150
+ if (index === 0 && selector.length === 1) {
151
+ selector.walk((node, idx) => {
152
+ if (idx === 0 && node.type === "class") {
153
+ const nodes = _optionalChain([node, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.nodes]);
154
+ if (nodes) {
155
+ const first = nodes[idx + 1];
156
+ if (first && first.type === "combinator" && first.value === ">") {
157
+ const second = nodes[idx + 2];
158
+ if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
159
+ const ast = getCombinatorSelectorAst(options);
160
+ second.replaceWith(
161
+ ...ast
162
+ );
163
+ }
154
164
  }
155
165
  }
156
166
  }
157
- }
158
- });
159
- selector.replaceWith(...selector.nodes);
160
- for (const node of rule.nodes) {
161
- if (node.type === "decl") {
162
- if (node.prop === "margin-block-start") {
163
- node.prop = "margin-block-end";
164
- } else if (node.prop === "margin-block-end") {
165
- node.prop = "margin-block-start";
166
- } else if (node.prop === "margin-inline-start") {
167
- node.prop = "margin-inline-end";
168
- } else if (node.prop === "margin-inline-end") {
169
- node.prop = "margin-inline-start";
170
- } else if (node.prop === "margin-top") {
171
- node.prop = "margin-bottom";
172
- } else if (node.prop === "margin-bottom") {
173
- node.prop = "margin-top";
174
- } else if (node.prop === "margin-left") {
175
- node.prop = "margin-right";
176
- } else if (node.prop === "margin-right") {
177
- node.prop = "margin-left";
167
+ });
168
+ selector.replaceWith(...selector.nodes);
169
+ for (const node of rule.nodes) {
170
+ if (node.type === "decl") {
171
+ if (node.prop === "margin-block-start") {
172
+ node.prop = "margin-block-end";
173
+ } else if (node.prop === "margin-block-end") {
174
+ node.prop = "margin-block-start";
175
+ } else if (node.prop === "margin-inline-start") {
176
+ node.prop = "margin-inline-end";
177
+ } else if (node.prop === "margin-inline-end") {
178
+ node.prop = "margin-inline-start";
179
+ } else if (node.prop === "margin-top") {
180
+ node.prop = "margin-bottom";
181
+ } else if (node.prop === "margin-bottom") {
182
+ node.prop = "margin-top";
183
+ } else if (node.prop === "margin-left") {
184
+ node.prop = "margin-right";
185
+ } else if (node.prop === "margin-right") {
186
+ node.prop = "margin-left";
187
+ }
178
188
  }
179
189
  }
180
190
  }
181
191
  }
182
- }
183
- } else if (selector.type === "class") {
184
- selector.value = internalCssSelectorReplacer(selector.value, {
185
- escapeMap,
186
- mangleContext
187
- });
188
- } else if (selector.type === "combinator") {
189
- if (selector.value === ">") {
190
- const nodes = _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
191
- if (nodes) {
192
- const first = nodes[index + 1];
193
- 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")) {
194
- const second = nodes[index + 2];
195
- if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
196
- const third = nodes[index + 3];
197
- 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")) {
198
- const ast = getCombinatorSelectorAst(options);
199
- _optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes, 'access', _9 => _9.splice, 'call', _10 => _10(
200
- index + 1,
201
- 3,
202
- ...ast
203
- )]);
192
+ } else if (selector.type === "combinator") {
193
+ if (selector.value === ">") {
194
+ const nodes = _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
195
+ if (nodes) {
196
+ const first = nodes[index + 1];
197
+ 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")) {
198
+ const second = nodes[index + 2];
199
+ if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
200
+ const third = nodes[index + 3];
201
+ 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")) {
202
+ const ast = getCombinatorSelectorAst(options);
203
+ _optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes, 'access', _9 => _9.splice, 'call', _10 => _10(
204
+ index + 1,
205
+ 3,
206
+ ...ast
207
+ )]);
208
+ }
204
209
  }
205
210
  }
206
211
  }
207
212
  }
208
213
  }
214
+ } else {
215
+ if (selector.type === "class") {
216
+ selector.value = internalCssSelectorReplacer(selector.value, {
217
+ escapeMap,
218
+ mangleContext
219
+ });
220
+ } else {
221
+ selector.remove();
222
+ }
209
223
  }
210
224
  });
211
225
  if (selectors.length === 0) {
@@ -315,19 +329,31 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
315
329
  rule.remove();
316
330
  }
317
331
  rule.walkDecls((decl) => {
318
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
332
+ if (opts.uniAppX && decl.prop.startsWith("--")) {
333
+ decl.remove();
334
+ } else if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
319
335
  decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
336
+ } else if (/calc\(\s*infinity\s*\*\s*1px/.test(decl.value)) {
337
+ decl.value = "9999px";
320
338
  }
321
339
  });
340
+ if (opts.uniAppX) {
341
+ if (rule.nodes.length === 0) {
342
+ rule.remove();
343
+ }
344
+ }
322
345
  });
323
- opts.cssRemoveProperty && root.walkAtRules("property", (rule) => {
324
- rule.remove();
346
+ root.walkAtRules((atRule) => {
347
+ if (opts.cssRemoveProperty && atRule.name === "property") {
348
+ atRule.remove();
349
+ }
350
+ _optionalChain([atRule, 'access', _24 => _24.nodes, 'optionalAccess', _25 => _25.length]) === 0 && atRule.remove();
325
351
  });
326
352
  };
327
353
  }
328
354
  if (typeof opts.customRuleCallback === "function") {
329
355
  p.Rule = (rule) => {
330
- _optionalChain([opts, 'access', _24 => _24.customRuleCallback, 'optionalCall', _25 => _25(rule, opts)]);
356
+ _optionalChain([opts, 'access', _26 => _26.customRuleCallback, 'optionalCall', _27 => _27(rule, opts)]);
331
357
  };
332
358
  }
333
359
  return p;
@@ -621,7 +647,7 @@ function remakeCssVarSelector(selectors, options) {
621
647
  function commonChunkPreflight(node, options) {
622
648
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
623
649
  if (testIfVariablesScope(node)) {
624
- _optionalChain([ctx, 'optionalAccess', _26 => _26.markVariablesScope, 'call', _27 => _27(node)]);
650
+ _optionalChain([ctx, 'optionalAccess', _28 => _28.markVariablesScope, 'call', _29 => _29(node)]);
625
651
  node.selectors = remakeCssVarSelector(node.selectors, options);
626
652
  node.before(makePseudoVarRule());
627
653
  if (typeof cssInjectPreflight === "function") {
@@ -668,6 +694,10 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
668
694
  } else {
669
695
  atRule.remove();
670
696
  }
697
+ } else if (atRule.name === "supports") {
698
+ if (/color-mix/.test(atRule.params)) {
699
+ atRule.remove();
700
+ }
671
701
  }
672
702
  }
673
703
  };
@@ -676,9 +706,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
676
706
  p.Once = (root) => {
677
707
  root.walkAtRules((atRule) => {
678
708
  if (atRule.name === "layer" && atRule.params === "properties") {
679
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _28 => _28.nodes, 'optionalAccess', _29 => _29.length]) === 0) {
709
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _30 => _30.nodes, 'optionalAccess', _31 => _31.length]) === 0) {
680
710
  layerProperties = atRule;
681
- } else if (_optionalChain([atRule, 'access', _30 => _30.first, 'optionalAccess', _31 => _31.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
711
+ } else if (_optionalChain([atRule, 'access', _32 => _32.first, 'optionalAccess', _33 => _33.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
682
712
  if (layerProperties) {
683
713
  layerProperties.replaceWith(atRule.first.nodes);
684
714
  atRule.remove();
@@ -687,7 +717,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
687
717
  }
688
718
  }
689
719
  } else if (isTailwindcssV4ModernCheck(atRule)) {
690
- if (_optionalChain([atRule, 'access', _32 => _32.first, 'optionalAccess', _33 => _33.type]) === "atrule" && atRule.first.name === "layer") {
720
+ if (_optionalChain([atRule, 'access', _34 => _34.first, 'optionalAccess', _35 => _35.type]) === "atrule" && atRule.first.name === "layer") {
691
721
  atRule.replaceWith(atRule.first.nodes);
692
722
  }
693
723
  }
@@ -710,7 +740,7 @@ function compare(e3, t2) {
710
740
  return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
711
741
  }
712
742
  function selectorSpecificity(t2, s) {
713
- const i = _optionalChain([s, 'optionalAccess', _34 => _34.customSpecificity, 'optionalCall', _35 => _35(t2)]);
743
+ const i = _optionalChain([s, 'optionalAccess', _36 => _36.customSpecificity, 'optionalCall', _37 => _37(t2)]);
714
744
  if (i) return i;
715
745
  if (!t2) return { a: 0, b: 0, c: 0 };
716
746
  let c = 0, n = 0, o2 = 0;
@@ -786,7 +816,7 @@ function selectorSpecificity(t2, s) {
786
816
  case ":active-view-transition-type":
787
817
  return { a: 0, b: 1, c: 0 };
788
818
  }
789
- else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _36 => _36.nodes, 'optionalAccess', _37 => _37.length]) > 0 && t2.nodes.forEach((e3) => {
819
+ else _postcssselectorparser2.default.isContainer(t2) && _optionalChain([t2, 'access', _38 => _38.nodes, 'optionalAccess', _39 => _39.length]) > 0 && t2.nodes.forEach((e3) => {
790
820
  const t3 = selectorSpecificity(e3, s);
791
821
  c += t3.a, n += t3.b, o2 += t3.c;
792
822
  });
@@ -814,8 +844,8 @@ function alwaysValidSelector(s) {
814
844
  const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
815
845
  let t2 = true;
816
846
  return o2.walk((e3) => {
817
- 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', _38 => _38.nodes, 'optionalAccess', _39 => _39.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
818
- if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _40 => _40.nodes, 'optionalAccess', _41 => _41.length]) && ":not" === e3.value.toLowerCase()) {
847
+ 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', _40 => _40.nodes, 'optionalAccess', _41 => _41.length]) || ":hover" !== e3.value.toLowerCase() && ":focus" !== e3.value.toLowerCase())) {
848
+ if ("pseudo" === e3.type && 1 === _optionalChain([e3, 'access', _42 => _42.nodes, 'optionalAccess', _43 => _43.length]) && ":not" === e3.value.toLowerCase()) {
819
849
  let s2 = true;
820
850
  if (e3.nodes[0].walkCombinators(() => {
821
851
  s2 = false;
@@ -927,8 +957,8 @@ function splitSelectors(o2, t2, n = 0) {
927
957
  if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
928
958
  if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
929
959
  if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
930
- if ("pseudo" === _optionalChain([e3, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.parent, 'optionalAccess', _44 => _44.type]) && ":not" === _optionalChain([e3, 'access', _45 => _45.parent, 'optionalAccess', _46 => _46.parent, 'optionalAccess', _47 => _47.value, 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
931
- if ("pseudo" === _optionalChain([e3, 'access', _50 => _50.parent, 'optionalAccess', _51 => _51.parent, 'optionalAccess', _52 => _52.type]) && ":has" === _optionalChain([e3, 'access', _53 => _53.parent, 'optionalAccess', _54 => _54.parent, 'optionalAccess', _55 => _55.value, 'optionalAccess', _56 => _56.toLowerCase, 'call', _57 => _57()])) return void (e3.value = ":-csstools-matches");
960
+ if ("pseudo" === _optionalChain([e3, 'access', _44 => _44.parent, 'optionalAccess', _45 => _45.parent, 'optionalAccess', _46 => _46.type]) && ":not" === _optionalChain([e3, 'access', _47 => _47.parent, 'optionalAccess', _48 => _48.parent, 'optionalAccess', _49 => _49.value, 'optionalAccess', _50 => _50.toLowerCase, 'call', _51 => _51()])) return void i.push([{ start: e3.parent.parent.sourceIndex, end: e3.parent.parent.sourceIndex + e3.parent.parent.toString().length, option: `:not(${e3.nodes.toString()})` }]);
961
+ if ("pseudo" === _optionalChain([e3, 'access', _52 => _52.parent, 'optionalAccess', _53 => _53.parent, 'optionalAccess', _54 => _54.type]) && ":has" === _optionalChain([e3, 'access', _55 => _55.parent, 'optionalAccess', _56 => _56.parent, 'optionalAccess', _57 => _57.value, 'optionalAccess', _58 => _58.toLowerCase, 'call', _59 => _59()])) return void (e3.value = ":-csstools-matches");
932
962
  let o4 = e3.parent;
933
963
  for (; o4; ) {
934
964
  if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
@@ -950,7 +980,7 @@ function splitSelectors(o2, t2, n = 0) {
950
980
  let s = "";
951
981
  for (let t3 = 0; t3 < e3.length; t3++) {
952
982
  const n2 = e3[t3];
953
- s += o3.substring(_optionalChain([e3, 'access', _58 => _58[t3 - 1], 'optionalAccess', _59 => _59.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
983
+ s += o3.substring(_optionalChain([e3, 'access', _60 => _60[t3 - 1], 'optionalAccess', _61 => _61.end]) || 0, e3[t3].start), s += ":-csstools-matches(" + n2.option + ")", t3 === e3.length - 1 && (s += o3.substring(e3[t3].end));
954
984
  }
955
985
  c.push(s);
956
986
  }), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
@@ -1011,7 +1041,7 @@ function getPlugins(options) {
1011
1041
  const ctx = createContext();
1012
1042
  options.ctx = ctx;
1013
1043
  const plugins = [
1014
- ..._nullishCoalesce(_optionalChain([options, 'access', _60 => _60.postcssOptions, 'optionalAccess', _61 => _61.plugins]), () => ( [])),
1044
+ ..._nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.plugins]), () => ( [])),
1015
1045
  postcssWeappTailwindcssPrePlugin(options),
1016
1046
  _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
1017
1047
  ];
@@ -1055,7 +1085,7 @@ function styleHandler(rawSource, options) {
1055
1085
  getPlugins(options)
1056
1086
  ).process(
1057
1087
  rawSource,
1058
- _nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.options]), () => ( {
1088
+ _nullishCoalesce(_optionalChain([options, 'access', _64 => _64.postcssOptions, 'optionalAccess', _65 => _65.options]), () => ( {
1059
1089
  from: void 0
1060
1090
  }))
1061
1091
  ).async();
package/dist/index.mjs CHANGED
@@ -7,6 +7,7 @@ import postcss from "postcss";
7
7
  // src/defaults.ts
8
8
  function getDefaultOptions() {
9
9
  return {
10
+ // https://github.com/postcss/postcss-calc
10
11
  cssPresetEnv: {
11
12
  features: {
12
13
  "cascade-layers": true,
@@ -22,6 +23,8 @@ function getDefaultOptions() {
22
23
  }
23
24
  },
24
25
  cssRemoveProperty: true,
26
+ // cssRemoveAtSupports: true,
27
+ // cssRemoveAtMedia: true,
25
28
  cssSelectorReplacement: {
26
29
  root: "page",
27
30
  universal: ["view", "text"]
@@ -120,92 +123,103 @@ function getCombinatorSelectorAst(options) {
120
123
  return childCombinatorReplaceValue;
121
124
  }
122
125
  function createRuleTransform(rule, options) {
123
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
126
+ const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
124
127
  const transform = (selectors) => {
125
128
  selectors.walk((selector, index) => {
126
- if (selector.type === "universal") {
127
- if (cssSelectorReplacement?.universal) {
128
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
129
- }
130
- } else if (selector.type === "selector") {
131
- if (cssRemoveHoverPseudoClass) {
132
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
133
- if (node) {
134
- selector.remove();
129
+ if (!uniAppX) {
130
+ if (selector.type === "class") {
131
+ selector.value = internalCssSelectorReplacer(selector.value, {
132
+ escapeMap,
133
+ mangleContext
134
+ });
135
+ } else if (selector.type === "universal") {
136
+ if (cssSelectorReplacement?.universal) {
137
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
135
138
  }
136
- }
137
- } else if (selector.type === "pseudo") {
138
- if (selector.value === ":root" && cssSelectorReplacement?.root) {
139
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
140
- } else if (selector.value === ":where") {
141
- if (index === 0 && selector.length === 1) {
142
- selector.walk((node, idx) => {
143
- if (idx === 0 && node.type === "class") {
144
- const nodes = node.parent?.nodes;
145
- if (nodes) {
146
- const first = nodes[idx + 1];
147
- if (first && first.type === "combinator" && first.value === ">") {
148
- const second = nodes[idx + 2];
149
- if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
150
- const ast = getCombinatorSelectorAst(options);
151
- second.replaceWith(
152
- ...ast
153
- );
139
+ } else if (selector.type === "selector") {
140
+ if (cssRemoveHoverPseudoClass) {
141
+ const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
142
+ if (node) {
143
+ selector.remove();
144
+ }
145
+ }
146
+ } else if (selector.type === "pseudo") {
147
+ if (selector.value === ":root" && cssSelectorReplacement?.root) {
148
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
149
+ } else if (selector.value === ":where") {
150
+ if (index === 0 && selector.length === 1) {
151
+ selector.walk((node, idx) => {
152
+ if (idx === 0 && node.type === "class") {
153
+ const nodes = node.parent?.nodes;
154
+ if (nodes) {
155
+ const first = nodes[idx + 1];
156
+ if (first && first.type === "combinator" && first.value === ">") {
157
+ const second = nodes[idx + 2];
158
+ if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
159
+ const ast = getCombinatorSelectorAst(options);
160
+ second.replaceWith(
161
+ ...ast
162
+ );
163
+ }
154
164
  }
155
165
  }
156
166
  }
157
- }
158
- });
159
- selector.replaceWith(...selector.nodes);
160
- for (const node of rule.nodes) {
161
- if (node.type === "decl") {
162
- if (node.prop === "margin-block-start") {
163
- node.prop = "margin-block-end";
164
- } else if (node.prop === "margin-block-end") {
165
- node.prop = "margin-block-start";
166
- } else if (node.prop === "margin-inline-start") {
167
- node.prop = "margin-inline-end";
168
- } else if (node.prop === "margin-inline-end") {
169
- node.prop = "margin-inline-start";
170
- } else if (node.prop === "margin-top") {
171
- node.prop = "margin-bottom";
172
- } else if (node.prop === "margin-bottom") {
173
- node.prop = "margin-top";
174
- } else if (node.prop === "margin-left") {
175
- node.prop = "margin-right";
176
- } else if (node.prop === "margin-right") {
177
- node.prop = "margin-left";
167
+ });
168
+ selector.replaceWith(...selector.nodes);
169
+ for (const node of rule.nodes) {
170
+ if (node.type === "decl") {
171
+ if (node.prop === "margin-block-start") {
172
+ node.prop = "margin-block-end";
173
+ } else if (node.prop === "margin-block-end") {
174
+ node.prop = "margin-block-start";
175
+ } else if (node.prop === "margin-inline-start") {
176
+ node.prop = "margin-inline-end";
177
+ } else if (node.prop === "margin-inline-end") {
178
+ node.prop = "margin-inline-start";
179
+ } else if (node.prop === "margin-top") {
180
+ node.prop = "margin-bottom";
181
+ } else if (node.prop === "margin-bottom") {
182
+ node.prop = "margin-top";
183
+ } else if (node.prop === "margin-left") {
184
+ node.prop = "margin-right";
185
+ } else if (node.prop === "margin-right") {
186
+ node.prop = "margin-left";
187
+ }
178
188
  }
179
189
  }
180
190
  }
181
191
  }
182
- }
183
- } else if (selector.type === "class") {
184
- selector.value = internalCssSelectorReplacer(selector.value, {
185
- escapeMap,
186
- mangleContext
187
- });
188
- } else if (selector.type === "combinator") {
189
- if (selector.value === ">") {
190
- const nodes = selector.parent?.nodes;
191
- if (nodes) {
192
- const first = nodes[index + 1];
193
- 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")) {
194
- const second = nodes[index + 2];
195
- if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
196
- const third = nodes[index + 3];
197
- 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")) {
198
- const ast = getCombinatorSelectorAst(options);
199
- selector.parent?.nodes.splice(
200
- index + 1,
201
- 3,
202
- ...ast
203
- );
192
+ } else if (selector.type === "combinator") {
193
+ if (selector.value === ">") {
194
+ const nodes = selector.parent?.nodes;
195
+ if (nodes) {
196
+ const first = nodes[index + 1];
197
+ 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")) {
198
+ const second = nodes[index + 2];
199
+ if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
200
+ const third = nodes[index + 3];
201
+ 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")) {
202
+ const ast = getCombinatorSelectorAst(options);
203
+ selector.parent?.nodes.splice(
204
+ index + 1,
205
+ 3,
206
+ ...ast
207
+ );
208
+ }
204
209
  }
205
210
  }
206
211
  }
207
212
  }
208
213
  }
214
+ } else {
215
+ if (selector.type === "class") {
216
+ selector.value = internalCssSelectorReplacer(selector.value, {
217
+ escapeMap,
218
+ mangleContext
219
+ });
220
+ } else {
221
+ selector.remove();
222
+ }
209
223
  }
210
224
  });
211
225
  if (selectors.length === 0) {
@@ -315,13 +329,25 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
315
329
  rule.remove();
316
330
  }
317
331
  rule.walkDecls((decl) => {
318
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
332
+ if (opts.uniAppX && decl.prop.startsWith("--")) {
333
+ decl.remove();
334
+ } else if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OklabSuffix)) {
319
335
  decl.value = decl.value.slice(0, decl.value.length - OklabSuffix.length);
336
+ } else if (/calc\(\s*infinity\s*\*\s*1px/.test(decl.value)) {
337
+ decl.value = "9999px";
320
338
  }
321
339
  });
340
+ if (opts.uniAppX) {
341
+ if (rule.nodes.length === 0) {
342
+ rule.remove();
343
+ }
344
+ }
322
345
  });
323
- opts.cssRemoveProperty && root.walkAtRules("property", (rule) => {
324
- rule.remove();
346
+ root.walkAtRules((atRule) => {
347
+ if (opts.cssRemoveProperty && atRule.name === "property") {
348
+ atRule.remove();
349
+ }
350
+ atRule.nodes?.length === 0 && atRule.remove();
325
351
  });
326
352
  };
327
353
  }
@@ -668,6 +694,10 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
668
694
  } else {
669
695
  atRule.remove();
670
696
  }
697
+ } else if (atRule.name === "supports") {
698
+ if (/color-mix/.test(atRule.params)) {
699
+ atRule.remove();
700
+ }
671
701
  }
672
702
  }
673
703
  };
@@ -44,6 +44,12 @@ type IStyleHandlerOptions = {
44
44
  cssRemoveProperty?: boolean;
45
45
  cssRemoveHoverPseudoClass?: boolean;
46
46
  cssPresetEnv?: pluginOptions;
47
+ atRules?: {
48
+ property?: boolean;
49
+ supports?: boolean;
50
+ media?: boolean;
51
+ };
52
+ uniAppX?: boolean;
47
53
  } & RequiredStyleHandlerOptions;
48
54
  interface UserDefinedPostcssOptions {
49
55
  cssPreflight?: CssPreflightOptions;
@@ -60,6 +66,7 @@ interface UserDefinedPostcssOptions {
60
66
  cssRemoveHoverPseudoClass?: boolean;
61
67
  cssRemoveProperty?: boolean;
62
68
  customRuleCallback?: CustomRuleCallback;
69
+ uniAppX?: boolean;
63
70
  }
64
71
 
65
72
  export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };
@@ -44,6 +44,12 @@ type IStyleHandlerOptions = {
44
44
  cssRemoveProperty?: boolean;
45
45
  cssRemoveHoverPseudoClass?: boolean;
46
46
  cssPresetEnv?: pluginOptions;
47
+ atRules?: {
48
+ property?: boolean;
49
+ supports?: boolean;
50
+ media?: boolean;
51
+ };
52
+ uniAppX?: boolean;
47
53
  } & RequiredStyleHandlerOptions;
48
54
  interface UserDefinedPostcssOptions {
49
55
  cssPreflight?: CssPreflightOptions;
@@ -60,6 +66,7 @@ interface UserDefinedPostcssOptions {
60
66
  cssRemoveHoverPseudoClass?: boolean;
61
67
  cssRemoveProperty?: boolean;
62
68
  customRuleCallback?: CustomRuleCallback;
69
+ uniAppX?: boolean;
63
70
  }
64
71
 
65
72
  export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };
package/dist/types.d.mts CHANGED
@@ -3,4 +3,4 @@ import 'postcss';
3
3
  import 'postcss-load-config';
4
4
  import 'postcss-preset-env';
5
5
  import 'postcss-rem-to-responsive-pixel';
6
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-PPOinWpH.mjs';
6
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-BuzFFGLX.mjs';
package/dist/types.d.ts CHANGED
@@ -3,4 +3,4 @@ import 'postcss';
3
3
  import 'postcss-load-config';
4
4
  import 'postcss-preset-env';
5
5
  import 'postcss-rem-to-responsive-pixel';
6
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-PPOinWpH.js';
6
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-BuzFFGLX.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -35,12 +35,13 @@
35
35
  "dependencies": {
36
36
  "@weapp-core/escape": "~4.0.1",
37
37
  "postcss": "~8.5.3",
38
- "postcss-preset-env": "^10.1.5",
38
+ "postcss-preset-env": "^10.1.6",
39
39
  "postcss-rem-to-responsive-pixel": "~6.0.2",
40
40
  "postcss-selector-parser": "~7.1.0",
41
41
  "@weapp-tailwindcss/shared": "1.0.2"
42
42
  },
43
43
  "devDependencies": {
44
+ "postcss-value-parser": "^4.2.0",
44
45
  "@weapp-tailwindcss/mangle": "1.0.4"
45
46
  },
46
47
  "scripts": {