@weapp-tailwindcss/postcss 1.0.11 → 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-Ca68m5Pt.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-Ca68m5Pt.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-Ca68m5Pt.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-Ca68m5Pt.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,
@@ -122,92 +123,103 @@ function getCombinatorSelectorAst(options) {
122
123
  return childCombinatorReplaceValue;
123
124
  }
124
125
  function createRuleTransform(rule, options) {
125
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
126
+ const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
126
127
  const transform = (selectors) => {
127
128
  selectors.walk((selector, index) => {
128
- if (selector.type === "universal") {
129
- if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _ => _.universal])) {
130
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
131
- }
132
- } else if (selector.type === "selector") {
133
- if (cssRemoveHoverPseudoClass) {
134
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
135
- if (node) {
136
- 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);
137
138
  }
138
- }
139
- } else if (selector.type === "pseudo") {
140
- if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _2 => _2.root])) {
141
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
142
- } else if (selector.value === ":where") {
143
- if (index === 0 && selector.length === 1) {
144
- selector.walk((node, idx) => {
145
- if (idx === 0 && node.type === "class") {
146
- const nodes = _optionalChain([node, 'access', _3 => _3.parent, 'optionalAccess', _4 => _4.nodes]);
147
- if (nodes) {
148
- const first = nodes[idx + 1];
149
- if (first && first.type === "combinator" && first.value === ">") {
150
- const second = nodes[idx + 2];
151
- if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
152
- const ast = getCombinatorSelectorAst(options);
153
- second.replaceWith(
154
- ...ast
155
- );
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
+ }
156
164
  }
157
165
  }
158
166
  }
159
- }
160
- });
161
- selector.replaceWith(...selector.nodes);
162
- for (const node of rule.nodes) {
163
- if (node.type === "decl") {
164
- if (node.prop === "margin-block-start") {
165
- node.prop = "margin-block-end";
166
- } else if (node.prop === "margin-block-end") {
167
- node.prop = "margin-block-start";
168
- } else if (node.prop === "margin-inline-start") {
169
- node.prop = "margin-inline-end";
170
- } else if (node.prop === "margin-inline-end") {
171
- node.prop = "margin-inline-start";
172
- } else if (node.prop === "margin-top") {
173
- node.prop = "margin-bottom";
174
- } else if (node.prop === "margin-bottom") {
175
- node.prop = "margin-top";
176
- } else if (node.prop === "margin-left") {
177
- node.prop = "margin-right";
178
- } else if (node.prop === "margin-right") {
179
- 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
+ }
180
188
  }
181
189
  }
182
190
  }
183
191
  }
184
- }
185
- } else if (selector.type === "class") {
186
- selector.value = internalCssSelectorReplacer(selector.value, {
187
- escapeMap,
188
- mangleContext
189
- });
190
- } else if (selector.type === "combinator") {
191
- if (selector.value === ">") {
192
- const nodes = _optionalChain([selector, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes]);
193
- if (nodes) {
194
- const first = nodes[index + 1];
195
- 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")) {
196
- const second = nodes[index + 2];
197
- if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
198
- const third = nodes[index + 3];
199
- 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")) {
200
- const ast = getCombinatorSelectorAst(options);
201
- _optionalChain([selector, 'access', _7 => _7.parent, 'optionalAccess', _8 => _8.nodes, 'access', _9 => _9.splice, 'call', _10 => _10(
202
- index + 1,
203
- 3,
204
- ...ast
205
- )]);
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
+ }
206
209
  }
207
210
  }
208
211
  }
209
212
  }
210
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
+ }
211
223
  }
212
224
  });
213
225
  if (selectors.length === 0) {
@@ -317,19 +329,31 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
317
329
  rule.remove();
318
330
  }
319
331
  rule.walkDecls((decl) => {
320
- 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)) {
321
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";
322
338
  }
323
339
  });
340
+ if (opts.uniAppX) {
341
+ if (rule.nodes.length === 0) {
342
+ rule.remove();
343
+ }
344
+ }
324
345
  });
325
- opts.cssRemoveProperty && root.walkAtRules("property", (rule) => {
326
- 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();
327
351
  });
328
352
  };
329
353
  }
330
354
  if (typeof opts.customRuleCallback === "function") {
331
355
  p.Rule = (rule) => {
332
- _optionalChain([opts, 'access', _24 => _24.customRuleCallback, 'optionalCall', _25 => _25(rule, opts)]);
356
+ _optionalChain([opts, 'access', _26 => _26.customRuleCallback, 'optionalCall', _27 => _27(rule, opts)]);
333
357
  };
334
358
  }
335
359
  return p;
@@ -623,7 +647,7 @@ function remakeCssVarSelector(selectors, options) {
623
647
  function commonChunkPreflight(node, options) {
624
648
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
625
649
  if (testIfVariablesScope(node)) {
626
- _optionalChain([ctx, 'optionalAccess', _26 => _26.markVariablesScope, 'call', _27 => _27(node)]);
650
+ _optionalChain([ctx, 'optionalAccess', _28 => _28.markVariablesScope, 'call', _29 => _29(node)]);
627
651
  node.selectors = remakeCssVarSelector(node.selectors, options);
628
652
  node.before(makePseudoVarRule());
629
653
  if (typeof cssInjectPreflight === "function") {
@@ -682,9 +706,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
682
706
  p.Once = (root) => {
683
707
  root.walkAtRules((atRule) => {
684
708
  if (atRule.name === "layer" && atRule.params === "properties") {
685
- 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) {
686
710
  layerProperties = atRule;
687
- } 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)) {
688
712
  if (layerProperties) {
689
713
  layerProperties.replaceWith(atRule.first.nodes);
690
714
  atRule.remove();
@@ -693,7 +717,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
693
717
  }
694
718
  }
695
719
  } else if (isTailwindcssV4ModernCheck(atRule)) {
696
- 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") {
697
721
  atRule.replaceWith(atRule.first.nodes);
698
722
  }
699
723
  }
@@ -716,7 +740,7 @@ function compare(e3, t2) {
716
740
  return e3.a === t2.a ? e3.b === t2.b ? e3.c - t2.c : e3.b - t2.b : e3.a - t2.a;
717
741
  }
718
742
  function selectorSpecificity(t2, s) {
719
- 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)]);
720
744
  if (i) return i;
721
745
  if (!t2) return { a: 0, b: 0, c: 0 };
722
746
  let c = 0, n = 0, o2 = 0;
@@ -792,7 +816,7 @@ function selectorSpecificity(t2, s) {
792
816
  case ":active-view-transition-type":
793
817
  return { a: 0, b: 1, c: 0 };
794
818
  }
795
- 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) => {
796
820
  const t3 = selectorSpecificity(e3, s);
797
821
  c += t3.a, n += t3.b, o2 += t3.c;
798
822
  });
@@ -820,8 +844,8 @@ function alwaysValidSelector(s) {
820
844
  const o2 = _postcssselectorparser2.default.call(void 0, ).astSync(s);
821
845
  let t2 = true;
822
846
  return o2.walk((e3) => {
823
- 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())) {
824
- 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()) {
825
849
  let s2 = true;
826
850
  if (e3.nodes[0].walkCombinators(() => {
827
851
  s2 = false;
@@ -933,8 +957,8 @@ function splitSelectors(o2, t2, n = 0) {
933
957
  if (_postcssselectorparser2.default.call(void 0, ).astSync(o3).walkPseudos((e3) => {
934
958
  if (":is" !== e3.value.toLowerCase() || !e3.nodes || !e3.nodes.length) return;
935
959
  if ("selector" === e3.nodes[0].type && 0 === e3.nodes[0].nodes.length) return;
936
- 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()})` }]);
937
- 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");
938
962
  let o4 = e3.parent;
939
963
  for (; o4; ) {
940
964
  if (o4.value && ":is" === o4.value.toLowerCase() && "pseudo" === o4.type) return void (a = true);
@@ -956,7 +980,7 @@ function splitSelectors(o2, t2, n = 0) {
956
980
  let s = "";
957
981
  for (let t3 = 0; t3 < e3.length; t3++) {
958
982
  const n2 = e3[t3];
959
- 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));
960
984
  }
961
985
  c.push(s);
962
986
  }), a && n < 10 && (c = splitSelectors(c, t2, n + 1)), c;
@@ -1017,7 +1041,7 @@ function getPlugins(options) {
1017
1041
  const ctx = createContext();
1018
1042
  options.ctx = ctx;
1019
1043
  const plugins = [
1020
- ..._nullishCoalesce(_optionalChain([options, 'access', _60 => _60.postcssOptions, 'optionalAccess', _61 => _61.plugins]), () => ( [])),
1044
+ ..._nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.plugins]), () => ( [])),
1021
1045
  postcssWeappTailwindcssPrePlugin(options),
1022
1046
  _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
1023
1047
  ];
@@ -1061,7 +1085,7 @@ function styleHandler(rawSource, options) {
1061
1085
  getPlugins(options)
1062
1086
  ).process(
1063
1087
  rawSource,
1064
- _nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.options]), () => ( {
1088
+ _nullishCoalesce(_optionalChain([options, 'access', _64 => _64.postcssOptions, 'optionalAccess', _65 => _65.options]), () => ( {
1065
1089
  from: void 0
1066
1090
  }))
1067
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,
@@ -122,92 +123,103 @@ function getCombinatorSelectorAst(options) {
122
123
  return childCombinatorReplaceValue;
123
124
  }
124
125
  function createRuleTransform(rule, options) {
125
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
126
+ const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
126
127
  const transform = (selectors) => {
127
128
  selectors.walk((selector, index) => {
128
- if (selector.type === "universal") {
129
- if (cssSelectorReplacement?.universal) {
130
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
131
- }
132
- } else if (selector.type === "selector") {
133
- if (cssRemoveHoverPseudoClass) {
134
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
135
- if (node) {
136
- 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);
137
138
  }
138
- }
139
- } else if (selector.type === "pseudo") {
140
- if (selector.value === ":root" && cssSelectorReplacement?.root) {
141
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
142
- } else if (selector.value === ":where") {
143
- if (index === 0 && selector.length === 1) {
144
- selector.walk((node, idx) => {
145
- if (idx === 0 && node.type === "class") {
146
- const nodes = node.parent?.nodes;
147
- if (nodes) {
148
- const first = nodes[idx + 1];
149
- if (first && first.type === "combinator" && first.value === ">") {
150
- const second = nodes[idx + 2];
151
- if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
152
- const ast = getCombinatorSelectorAst(options);
153
- second.replaceWith(
154
- ...ast
155
- );
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
+ }
156
164
  }
157
165
  }
158
166
  }
159
- }
160
- });
161
- selector.replaceWith(...selector.nodes);
162
- for (const node of rule.nodes) {
163
- if (node.type === "decl") {
164
- if (node.prop === "margin-block-start") {
165
- node.prop = "margin-block-end";
166
- } else if (node.prop === "margin-block-end") {
167
- node.prop = "margin-block-start";
168
- } else if (node.prop === "margin-inline-start") {
169
- node.prop = "margin-inline-end";
170
- } else if (node.prop === "margin-inline-end") {
171
- node.prop = "margin-inline-start";
172
- } else if (node.prop === "margin-top") {
173
- node.prop = "margin-bottom";
174
- } else if (node.prop === "margin-bottom") {
175
- node.prop = "margin-top";
176
- } else if (node.prop === "margin-left") {
177
- node.prop = "margin-right";
178
- } else if (node.prop === "margin-right") {
179
- 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
+ }
180
188
  }
181
189
  }
182
190
  }
183
191
  }
184
- }
185
- } else if (selector.type === "class") {
186
- selector.value = internalCssSelectorReplacer(selector.value, {
187
- escapeMap,
188
- mangleContext
189
- });
190
- } else if (selector.type === "combinator") {
191
- if (selector.value === ">") {
192
- const nodes = selector.parent?.nodes;
193
- if (nodes) {
194
- const first = nodes[index + 1];
195
- 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")) {
196
- const second = nodes[index + 2];
197
- if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
198
- const third = nodes[index + 3];
199
- 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")) {
200
- const ast = getCombinatorSelectorAst(options);
201
- selector.parent?.nodes.splice(
202
- index + 1,
203
- 3,
204
- ...ast
205
- );
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
+ }
206
209
  }
207
210
  }
208
211
  }
209
212
  }
210
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
+ }
211
223
  }
212
224
  });
213
225
  if (selectors.length === 0) {
@@ -317,13 +329,25 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
317
329
  rule.remove();
318
330
  }
319
331
  rule.walkDecls((decl) => {
320
- 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)) {
321
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";
322
338
  }
323
339
  });
340
+ if (opts.uniAppX) {
341
+ if (rule.nodes.length === 0) {
342
+ rule.remove();
343
+ }
344
+ }
324
345
  });
325
- opts.cssRemoveProperty && root.walkAtRules("property", (rule) => {
326
- rule.remove();
346
+ root.walkAtRules((atRule) => {
347
+ if (opts.cssRemoveProperty && atRule.name === "property") {
348
+ atRule.remove();
349
+ }
350
+ atRule.nodes?.length === 0 && atRule.remove();
327
351
  });
328
352
  };
329
353
  }
@@ -49,6 +49,7 @@ type IStyleHandlerOptions = {
49
49
  supports?: boolean;
50
50
  media?: boolean;
51
51
  };
52
+ uniAppX?: boolean;
52
53
  } & RequiredStyleHandlerOptions;
53
54
  interface UserDefinedPostcssOptions {
54
55
  cssPreflight?: CssPreflightOptions;
@@ -65,6 +66,7 @@ interface UserDefinedPostcssOptions {
65
66
  cssRemoveHoverPseudoClass?: boolean;
66
67
  cssRemoveProperty?: boolean;
67
68
  customRuleCallback?: CustomRuleCallback;
69
+ uniAppX?: boolean;
68
70
  }
69
71
 
70
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 };
@@ -49,6 +49,7 @@ type IStyleHandlerOptions = {
49
49
  supports?: boolean;
50
50
  media?: boolean;
51
51
  };
52
+ uniAppX?: boolean;
52
53
  } & RequiredStyleHandlerOptions;
53
54
  interface UserDefinedPostcssOptions {
54
55
  cssPreflight?: CssPreflightOptions;
@@ -65,6 +66,7 @@ interface UserDefinedPostcssOptions {
65
66
  cssRemoveHoverPseudoClass?: boolean;
66
67
  cssRemoveProperty?: boolean;
67
68
  customRuleCallback?: CustomRuleCallback;
69
+ uniAppX?: boolean;
68
70
  }
69
71
 
70
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-Ca68m5Pt.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-Ca68m5Pt.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.11",
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": {