@weapp-tailwindcss/postcss 2.1.6-alpha.1 → 2.1.6-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +127 -22
  2. package/dist/index.mjs +117 -12
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -794,13 +794,16 @@ function stripUnsupportedPseudoForUniAppX(node, enabled) {
794
794
  if (!enabled) {
795
795
  return;
796
796
  }
797
+ if (node.value === ":host") {
798
+ return;
799
+ }
797
800
  node.remove();
798
801
  }
799
802
  function stripUnsupportedNodeForUniAppX(node, options) {
800
803
  if (!isUniAppXEnabled(options)) {
801
804
  return false;
802
805
  }
803
- if (node.type === "tag" || node.type === "attribute" || node.type === "pseudo") {
806
+ if (node.type === "attribute" || node.type === "pseudo") {
804
807
  node.remove();
805
808
  return true;
806
809
  }
@@ -1307,10 +1310,17 @@ function shouldRemoveHoverSelector(selector, options) {
1307
1310
  return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
1308
1311
  }
1309
1312
  var UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = /* @__PURE__ */ new Set([
1313
+ ":after",
1314
+ ":before",
1315
+ "::after",
1316
+ "::before",
1310
1317
  "::backdrop",
1311
1318
  "::file-selector-button"
1312
1319
  ]);
1313
- function shouldRemoveUnsupportedPseudoElementSelector(selector) {
1320
+ function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
1321
+ if (!isUniAppXEnabled(options)) {
1322
+ return selector.nodes.some((node) => node.type === "pseudo" && (node.value === "::backdrop" || node.value === "::file-selector-button"));
1323
+ }
1314
1324
  return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
1315
1325
  }
1316
1326
  function isHiddenOrTemplateNotPseudo(node) {
@@ -1369,7 +1379,7 @@ function handleTagOrAttribute(node, context) {
1369
1379
  stripUnsupportedNodeForUniAppX(node, context.options);
1370
1380
  }
1371
1381
  function handleSelectorNode(selector, context) {
1372
- if (shouldRemoveUnsupportedPseudoElementSelector(selector)) {
1382
+ if (shouldRemoveUnsupportedPseudoElementSelector(selector, context.options)) {
1373
1383
  selector.remove();
1374
1384
  return;
1375
1385
  }
@@ -1516,6 +1526,65 @@ function ruleTransformSync(rule, options) {
1516
1526
  transformer(rule);
1517
1527
  }
1518
1528
 
1529
+ // src/utils/selector-guard.ts
1530
+ var ruleSelectorMutationStateMap = /* @__PURE__ */ new WeakMap();
1531
+ var DEFAULT_SELECTOR_MUTATION_LIMIT = 24;
1532
+ function toSelectorSignature(selectors) {
1533
+ return selectors.join(",");
1534
+ }
1535
+ function getRuleSelectorMutationState(rule) {
1536
+ let state = ruleSelectorMutationStateMap.get(rule);
1537
+ if (!state) {
1538
+ state = {
1539
+ count: 0,
1540
+ seen: /* @__PURE__ */ new Set(),
1541
+ trace: []
1542
+ };
1543
+ const current = _nullishCoalesce(rule.selectors, () => ( []));
1544
+ state.seen.add(toSelectorSignature(current));
1545
+ ruleSelectorMutationStateMap.set(rule, state);
1546
+ }
1547
+ return state;
1548
+ }
1549
+ function pushTrace(state, meta, selectors) {
1550
+ state.trace.push(`${meta.phase}:${meta.reason}:${toSelectorSignature(selectors)}`);
1551
+ if (state.trace.length > DEFAULT_SELECTOR_MUTATION_LIMIT) {
1552
+ state.trace.shift();
1553
+ }
1554
+ }
1555
+ function createSelectorCycleError(meta, state, selectors) {
1556
+ const next = toSelectorSignature(selectors);
1557
+ const trace = [...state.trace, `${meta.phase}:${meta.reason}:${next}`].join(" -> ");
1558
+ return new Error(`[postcss-selector-guard] \u68C0\u6D4B\u5230\u53EF\u80FD\u7684\u9009\u62E9\u5668\u6B7B\u5FAA\u73AF: ${trace}`);
1559
+ }
1560
+ function assignRuleSelectors(rule, selectors, meta) {
1561
+ const current = _nullishCoalesce(rule.selectors, () => ( []));
1562
+ const currentSignature = toSelectorSignature(current);
1563
+ const nextSignature = toSelectorSignature(selectors);
1564
+ if (currentSignature === nextSignature) {
1565
+ return false;
1566
+ }
1567
+ const state = getRuleSelectorMutationState(rule);
1568
+ if (state.seen.has(nextSignature)) {
1569
+ throw createSelectorCycleError(meta, state, selectors);
1570
+ }
1571
+ state.count += 1;
1572
+ if (state.count > DEFAULT_SELECTOR_MUTATION_LIMIT) {
1573
+ throw createSelectorCycleError(meta, state, selectors);
1574
+ }
1575
+ pushTrace(state, meta, selectors);
1576
+ state.seen.add(nextSignature);
1577
+ rule.selectors = selectors;
1578
+ return true;
1579
+ }
1580
+ function appendRuleSelector(rule, selector, meta) {
1581
+ const current = _nullishCoalesce(rule.selectors, () => ( []));
1582
+ if (current.includes(selector)) {
1583
+ return false;
1584
+ }
1585
+ return assignRuleSelectors(rule, [...current, selector], meta);
1586
+ }
1587
+
1519
1588
  // src/plugins/post/decl-dedupe.ts
1520
1589
  var logicalPropMap = /* @__PURE__ */ new Map([
1521
1590
  // margin 方向映射
@@ -1684,6 +1753,7 @@ function createRootSpecificityCleaner(options) {
1684
1753
  if (!rule.selectors || rule.selectors.length === 0) {
1685
1754
  return;
1686
1755
  }
1756
+ let changed = false;
1687
1757
  const next = rule.selectors.map((selector) => {
1688
1758
  let updated = selector;
1689
1759
  for (const target of targets) {
@@ -1694,9 +1764,15 @@ function createRootSpecificityCleaner(options) {
1694
1764
  updated = updated.split(target.spacedMatch).join(target.replacement);
1695
1765
  }
1696
1766
  }
1767
+ if (updated !== selector) {
1768
+ changed = true;
1769
+ }
1697
1770
  return updated;
1698
1771
  });
1699
- rule.selectors = next;
1772
+ changed && assignRuleSelectors(rule, next, {
1773
+ phase: "post",
1774
+ reason: "clean-root-specificity"
1775
+ });
1700
1776
  };
1701
1777
  }
1702
1778
 
@@ -1741,7 +1817,10 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1741
1817
  _optionalChain([cleanRootSpecificity, 'optionalCall', _58 => _58(rule)]);
1742
1818
  if (enableMainChunkTransforms) {
1743
1819
  if (_optionalChain([shouldAppendHostSelector, 'optionalCall', _59 => _59(rule)])) {
1744
- rule.selectors = [...rule.selectors, ":host"];
1820
+ appendRuleSelector(rule, ":host", {
1821
+ phase: "post",
1822
+ reason: "append-host-selector"
1823
+ });
1745
1824
  }
1746
1825
  dedupeDeclarations(rule);
1747
1826
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
@@ -2047,20 +2126,39 @@ function remakeCssVarSelector(selectors, options) {
2047
2126
  }
2048
2127
  return selectors;
2049
2128
  }
2129
+ function resolveUniAppXVariableScopeSelectors(options) {
2130
+ const universal = _optionalChain([options, 'access', _62 => _62.cssSelectorReplacement, 'optionalAccess', _63 => _63.universal]);
2131
+ if (Array.isArray(universal) && universal.length > 0) {
2132
+ return [...universal];
2133
+ }
2134
+ if (typeof universal === "string" && universal.length > 0) {
2135
+ return [universal];
2136
+ }
2137
+ return ["view", "text"];
2138
+ }
2050
2139
  function commonChunkPreflight(node, options) {
2051
2140
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
2052
- const rootOption = _optionalChain([options, 'access', _62 => _62.cssSelectorReplacement, 'optionalAccess', _63 => _63.root]);
2141
+ const uniAppXEnabled = isUniAppXEnabled(options);
2142
+ const rootOption = _optionalChain([options, 'access', _64 => _64.cssSelectorReplacement, 'optionalAccess', _65 => _65.root]);
2053
2143
  const rootSelectors = rootOption === false || rootOption === void 0 ? [] : Array.isArray(rootOption) ? rootOption.filter(Boolean) : [rootOption];
2054
2144
  const hasHostSelector = node.selectors.some((selector) => selector.includes(":host"));
2055
2145
  const hasRootPseudoSelector = node.selectors.some((selector) => selector.includes(":root"));
2056
2146
  const hasAllDefaultRootSelectors = DEFAULT_ROOT_SELECTORS2.every((selector) => node.selectors.includes(selector));
2057
2147
  if (!hasHostSelector && !rootSelectors.includes(":host") && (hasRootPseudoSelector || rootSelectors.length === DEFAULT_ROOT_SELECTORS2.length && rootSelectors.every((selector, index) => selector === DEFAULT_ROOT_SELECTORS2[index]) && hasAllDefaultRootSelectors)) {
2058
- node.selectors = [...node.selectors, ":host"];
2148
+ appendRuleSelector(node, ":host", {
2149
+ phase: "pre",
2150
+ reason: "append-host-selector"
2151
+ });
2059
2152
  }
2060
- if (testIfVariablesScope(node)) {
2061
- _optionalChain([ctx, 'optionalAccess', _64 => _64.markVariablesScope, 'call', _65 => _65(node)]);
2062
- node.selectors = remakeCssVarSelector(node.selectors, options);
2063
- node.before(makePseudoVarRule());
2153
+ if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
2154
+ _optionalChain([ctx, 'optionalAccess', _66 => _66.markVariablesScope, 'call', _67 => _67(node)]);
2155
+ assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
2156
+ phase: "pre",
2157
+ reason: "rewrite-variable-scope"
2158
+ });
2159
+ if (!uniAppXEnabled) {
2160
+ node.before(makePseudoVarRule());
2161
+ }
2064
2162
  if (typeof cssInjectPreflight === "function") {
2065
2163
  node.append(...cssInjectPreflight());
2066
2164
  }
@@ -2068,12 +2166,19 @@ function commonChunkPreflight(node, options) {
2068
2166
  const isTailwindcss4 = isTailwindcssV4(options);
2069
2167
  if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
2070
2168
  const syntheticRule = new (0, _postcss.Rule)({
2071
- selectors: ["*", "::after", "::before"],
2169
+ selectors: uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : ["*", "::after", "::before"],
2072
2170
  nodes: isTailwindcss4 ? cssVarsV4Nodes : cssVarsV3Nodes
2073
2171
  });
2074
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
2172
+ if (!uniAppXEnabled) {
2173
+ assignRuleSelectors(syntheticRule, remakeCssVarSelector(syntheticRule.selectors, options), {
2174
+ phase: "pre",
2175
+ reason: "rewrite-synthetic-variable-scope"
2176
+ });
2177
+ }
2075
2178
  node.before(syntheticRule);
2076
- node.before(makePseudoVarRule());
2179
+ if (!uniAppXEnabled) {
2180
+ node.before(makePseudoVarRule());
2181
+ }
2077
2182
  if (typeof cssInjectPreflight === "function") {
2078
2183
  syntheticRule.append(...cssInjectPreflight());
2079
2184
  }
@@ -2118,9 +2223,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
2118
2223
  root.walkAtRules((atRule) => {
2119
2224
  if (atRule.name === "layer") {
2120
2225
  if (atRule.params === "properties") {
2121
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _66 => _66.nodes, 'optionalAccess', _67 => _67.length]) === 0) {
2226
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _68 => _68.nodes, 'optionalAccess', _69 => _69.length]) === 0) {
2122
2227
  layerProperties = atRule;
2123
- } else if (_optionalChain([atRule, 'access', _68 => _68.first, 'optionalAccess', _69 => _69.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
2228
+ } else if (_optionalChain([atRule, 'access', _70 => _70.first, 'optionalAccess', _71 => _71.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
2124
2229
  if (layerProperties) {
2125
2230
  layerProperties.replaceWith(atRule.first.nodes);
2126
2231
  atRule.remove();
@@ -2132,7 +2237,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
2132
2237
  atRule.replaceWith(atRule.nodes);
2133
2238
  }
2134
2239
  } else if (isTailwindcssV4ModernCheck(atRule)) {
2135
- if (_optionalChain([atRule, 'access', _70 => _70.first, 'optionalAccess', _71 => _71.type]) === "atrule" && atRule.first.name === "layer") {
2240
+ if (_optionalChain([atRule, 'access', _72 => _72.first, 'optionalAccess', _73 => _73.type]) === "atrule" && atRule.first.name === "layer") {
2136
2241
  atRule.replaceWith(atRule.first.nodes);
2137
2242
  }
2138
2243
  }
@@ -2168,7 +2273,7 @@ function createPreparedNode(id, stage, createPlugin) {
2168
2273
  }
2169
2274
  function createPreparedNodes(options) {
2170
2275
  const preparedNodes = [];
2171
- const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _72 => _72.postcssOptions, 'optionalAccess', _73 => _73.plugins]));
2276
+ const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _74 => _74.postcssOptions, 'optionalAccess', _75 => _75.plugins]));
2172
2277
  const presetEnvOptions = options.cssPresetEnv;
2173
2278
  userPlugins.forEach((plugin, index) => {
2174
2279
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
@@ -2264,7 +2369,7 @@ function createStylePipeline(options) {
2264
2369
  function createProcessOptions(options) {
2265
2370
  return {
2266
2371
  from: void 0,
2267
- ..._nullishCoalesce(_optionalChain([options, 'access', _74 => _74.postcssOptions, 'optionalAccess', _75 => _75.options]), () => ( {}))
2372
+ ..._nullishCoalesce(_optionalChain([options, 'access', _76 => _76.postcssOptions, 'optionalAccess', _77 => _77.options]), () => ( {}))
2268
2373
  };
2269
2374
  }
2270
2375
  function getSimpleProcessOptionsCacheKey(options) {
@@ -2303,7 +2408,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2303
2408
  __init4() {this.processorCacheByKey = /* @__PURE__ */ new Map()}
2304
2409
  __init5() {this.processorKeyCache = /* @__PURE__ */ new WeakMap()}
2305
2410
  createProcessorCacheKey(options) {
2306
- const from = _optionalChain([options, 'access', _76 => _76.postcssOptions, 'optionalAccess', _77 => _77.options, 'optionalAccess', _78 => _78.from]);
2411
+ const from = _optionalChain([options, 'access', _78 => _78.postcssOptions, 'optionalAccess', _79 => _79.options, 'optionalAccess', _80 => _80.from]);
2307
2412
  if (from == null) {
2308
2413
  return fingerprintOptions(options);
2309
2414
  }
@@ -2312,7 +2417,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2312
2417
  postcssOptions: {
2313
2418
  ..._nullishCoalesce(options.postcssOptions, () => ( {})),
2314
2419
  options: {
2315
- ..._nullishCoalesce(_optionalChain([options, 'access', _79 => _79.postcssOptions, 'optionalAccess', _80 => _80.options]), () => ( {})),
2420
+ ..._nullishCoalesce(_optionalChain([options, 'access', _81 => _81.postcssOptions, 'optionalAccess', _82 => _82.options]), () => ( {})),
2316
2421
  from: void 0
2317
2422
  }
2318
2423
  }
@@ -2327,7 +2432,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2327
2432
  return pipeline;
2328
2433
  }
2329
2434
  getProcessOptions(options) {
2330
- const source = _optionalChain([options, 'access', _81 => _81.postcssOptions, 'optionalAccess', _82 => _82.options]);
2435
+ const source = _optionalChain([options, 'access', _83 => _83.postcssOptions, 'optionalAccess', _84 => _84.options]);
2331
2436
  const cacheKey = source ? _nullishCoalesce(getSimpleProcessOptionsCacheKey(source), () => ( fingerprintOptions(source))) : void 0;
2332
2437
  const cached = this.processOptionsCache.get(options);
2333
2438
  if (!cached || cached.cacheKey !== cacheKey) {
package/dist/index.mjs CHANGED
@@ -794,13 +794,16 @@ function stripUnsupportedPseudoForUniAppX(node, enabled) {
794
794
  if (!enabled) {
795
795
  return;
796
796
  }
797
+ if (node.value === ":host") {
798
+ return;
799
+ }
797
800
  node.remove();
798
801
  }
799
802
  function stripUnsupportedNodeForUniAppX(node, options) {
800
803
  if (!isUniAppXEnabled(options)) {
801
804
  return false;
802
805
  }
803
- if (node.type === "tag" || node.type === "attribute" || node.type === "pseudo") {
806
+ if (node.type === "attribute" || node.type === "pseudo") {
804
807
  node.remove();
805
808
  return true;
806
809
  }
@@ -1307,10 +1310,17 @@ function shouldRemoveHoverSelector(selector, options) {
1307
1310
  return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
1308
1311
  }
1309
1312
  var UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = /* @__PURE__ */ new Set([
1313
+ ":after",
1314
+ ":before",
1315
+ "::after",
1316
+ "::before",
1310
1317
  "::backdrop",
1311
1318
  "::file-selector-button"
1312
1319
  ]);
1313
- function shouldRemoveUnsupportedPseudoElementSelector(selector) {
1320
+ function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
1321
+ if (!isUniAppXEnabled(options)) {
1322
+ return selector.nodes.some((node) => node.type === "pseudo" && (node.value === "::backdrop" || node.value === "::file-selector-button"));
1323
+ }
1314
1324
  return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
1315
1325
  }
1316
1326
  function isHiddenOrTemplateNotPseudo(node) {
@@ -1369,7 +1379,7 @@ function handleTagOrAttribute(node, context) {
1369
1379
  stripUnsupportedNodeForUniAppX(node, context.options);
1370
1380
  }
1371
1381
  function handleSelectorNode(selector, context) {
1372
- if (shouldRemoveUnsupportedPseudoElementSelector(selector)) {
1382
+ if (shouldRemoveUnsupportedPseudoElementSelector(selector, context.options)) {
1373
1383
  selector.remove();
1374
1384
  return;
1375
1385
  }
@@ -1516,6 +1526,65 @@ function ruleTransformSync(rule, options) {
1516
1526
  transformer(rule);
1517
1527
  }
1518
1528
 
1529
+ // src/utils/selector-guard.ts
1530
+ var ruleSelectorMutationStateMap = /* @__PURE__ */ new WeakMap();
1531
+ var DEFAULT_SELECTOR_MUTATION_LIMIT = 24;
1532
+ function toSelectorSignature(selectors) {
1533
+ return selectors.join(",");
1534
+ }
1535
+ function getRuleSelectorMutationState(rule) {
1536
+ let state = ruleSelectorMutationStateMap.get(rule);
1537
+ if (!state) {
1538
+ state = {
1539
+ count: 0,
1540
+ seen: /* @__PURE__ */ new Set(),
1541
+ trace: []
1542
+ };
1543
+ const current = rule.selectors ?? [];
1544
+ state.seen.add(toSelectorSignature(current));
1545
+ ruleSelectorMutationStateMap.set(rule, state);
1546
+ }
1547
+ return state;
1548
+ }
1549
+ function pushTrace(state, meta, selectors) {
1550
+ state.trace.push(`${meta.phase}:${meta.reason}:${toSelectorSignature(selectors)}`);
1551
+ if (state.trace.length > DEFAULT_SELECTOR_MUTATION_LIMIT) {
1552
+ state.trace.shift();
1553
+ }
1554
+ }
1555
+ function createSelectorCycleError(meta, state, selectors) {
1556
+ const next = toSelectorSignature(selectors);
1557
+ const trace = [...state.trace, `${meta.phase}:${meta.reason}:${next}`].join(" -> ");
1558
+ return new Error(`[postcss-selector-guard] \u68C0\u6D4B\u5230\u53EF\u80FD\u7684\u9009\u62E9\u5668\u6B7B\u5FAA\u73AF: ${trace}`);
1559
+ }
1560
+ function assignRuleSelectors(rule, selectors, meta) {
1561
+ const current = rule.selectors ?? [];
1562
+ const currentSignature = toSelectorSignature(current);
1563
+ const nextSignature = toSelectorSignature(selectors);
1564
+ if (currentSignature === nextSignature) {
1565
+ return false;
1566
+ }
1567
+ const state = getRuleSelectorMutationState(rule);
1568
+ if (state.seen.has(nextSignature)) {
1569
+ throw createSelectorCycleError(meta, state, selectors);
1570
+ }
1571
+ state.count += 1;
1572
+ if (state.count > DEFAULT_SELECTOR_MUTATION_LIMIT) {
1573
+ throw createSelectorCycleError(meta, state, selectors);
1574
+ }
1575
+ pushTrace(state, meta, selectors);
1576
+ state.seen.add(nextSignature);
1577
+ rule.selectors = selectors;
1578
+ return true;
1579
+ }
1580
+ function appendRuleSelector(rule, selector, meta) {
1581
+ const current = rule.selectors ?? [];
1582
+ if (current.includes(selector)) {
1583
+ return false;
1584
+ }
1585
+ return assignRuleSelectors(rule, [...current, selector], meta);
1586
+ }
1587
+
1519
1588
  // src/plugins/post/decl-dedupe.ts
1520
1589
  var logicalPropMap = /* @__PURE__ */ new Map([
1521
1590
  // margin 方向映射
@@ -1684,6 +1753,7 @@ function createRootSpecificityCleaner(options) {
1684
1753
  if (!rule.selectors || rule.selectors.length === 0) {
1685
1754
  return;
1686
1755
  }
1756
+ let changed = false;
1687
1757
  const next = rule.selectors.map((selector) => {
1688
1758
  let updated = selector;
1689
1759
  for (const target of targets) {
@@ -1694,9 +1764,15 @@ function createRootSpecificityCleaner(options) {
1694
1764
  updated = updated.split(target.spacedMatch).join(target.replacement);
1695
1765
  }
1696
1766
  }
1767
+ if (updated !== selector) {
1768
+ changed = true;
1769
+ }
1697
1770
  return updated;
1698
1771
  });
1699
- rule.selectors = next;
1772
+ changed && assignRuleSelectors(rule, next, {
1773
+ phase: "post",
1774
+ reason: "clean-root-specificity"
1775
+ });
1700
1776
  };
1701
1777
  }
1702
1778
 
@@ -1741,7 +1817,10 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
1741
1817
  cleanRootSpecificity?.(rule);
1742
1818
  if (enableMainChunkTransforms) {
1743
1819
  if (shouldAppendHostSelector?.(rule)) {
1744
- rule.selectors = [...rule.selectors, ":host"];
1820
+ appendRuleSelector(rule, ":host", {
1821
+ phase: "post",
1822
+ reason: "append-host-selector"
1823
+ });
1745
1824
  }
1746
1825
  dedupeDeclarations(rule);
1747
1826
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
@@ -2047,20 +2126,39 @@ function remakeCssVarSelector(selectors, options) {
2047
2126
  }
2048
2127
  return selectors;
2049
2128
  }
2129
+ function resolveUniAppXVariableScopeSelectors(options) {
2130
+ const universal = options.cssSelectorReplacement?.universal;
2131
+ if (Array.isArray(universal) && universal.length > 0) {
2132
+ return [...universal];
2133
+ }
2134
+ if (typeof universal === "string" && universal.length > 0) {
2135
+ return [universal];
2136
+ }
2137
+ return ["view", "text"];
2138
+ }
2050
2139
  function commonChunkPreflight(node, options) {
2051
2140
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
2141
+ const uniAppXEnabled = isUniAppXEnabled(options);
2052
2142
  const rootOption = options.cssSelectorReplacement?.root;
2053
2143
  const rootSelectors = rootOption === false || rootOption === void 0 ? [] : Array.isArray(rootOption) ? rootOption.filter(Boolean) : [rootOption];
2054
2144
  const hasHostSelector = node.selectors.some((selector) => selector.includes(":host"));
2055
2145
  const hasRootPseudoSelector = node.selectors.some((selector) => selector.includes(":root"));
2056
2146
  const hasAllDefaultRootSelectors = DEFAULT_ROOT_SELECTORS2.every((selector) => node.selectors.includes(selector));
2057
2147
  if (!hasHostSelector && !rootSelectors.includes(":host") && (hasRootPseudoSelector || rootSelectors.length === DEFAULT_ROOT_SELECTORS2.length && rootSelectors.every((selector, index) => selector === DEFAULT_ROOT_SELECTORS2[index]) && hasAllDefaultRootSelectors)) {
2058
- node.selectors = [...node.selectors, ":host"];
2148
+ appendRuleSelector(node, ":host", {
2149
+ phase: "pre",
2150
+ reason: "append-host-selector"
2151
+ });
2059
2152
  }
2060
- if (testIfVariablesScope(node)) {
2153
+ if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
2061
2154
  ctx?.markVariablesScope(node);
2062
- node.selectors = remakeCssVarSelector(node.selectors, options);
2063
- node.before(makePseudoVarRule());
2155
+ assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
2156
+ phase: "pre",
2157
+ reason: "rewrite-variable-scope"
2158
+ });
2159
+ if (!uniAppXEnabled) {
2160
+ node.before(makePseudoVarRule());
2161
+ }
2064
2162
  if (typeof cssInjectPreflight === "function") {
2065
2163
  node.append(...cssInjectPreflight());
2066
2164
  }
@@ -2068,12 +2166,19 @@ function commonChunkPreflight(node, options) {
2068
2166
  const isTailwindcss4 = isTailwindcssV4(options);
2069
2167
  if (injectAdditionalCssVarScope && (isTailwindcss4 ? testIfRootHostForV4(node) : testIfTwBackdrop(node))) {
2070
2168
  const syntheticRule = new Rule({
2071
- selectors: ["*", "::after", "::before"],
2169
+ selectors: uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : ["*", "::after", "::before"],
2072
2170
  nodes: isTailwindcss4 ? cssVarsV4Nodes : cssVarsV3Nodes
2073
2171
  });
2074
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
2172
+ if (!uniAppXEnabled) {
2173
+ assignRuleSelectors(syntheticRule, remakeCssVarSelector(syntheticRule.selectors, options), {
2174
+ phase: "pre",
2175
+ reason: "rewrite-synthetic-variable-scope"
2176
+ });
2177
+ }
2075
2178
  node.before(syntheticRule);
2076
- node.before(makePseudoVarRule());
2179
+ if (!uniAppXEnabled) {
2180
+ node.before(makePseudoVarRule());
2181
+ }
2077
2182
  if (typeof cssInjectPreflight === "function") {
2078
2183
  syntheticRule.append(...cssInjectPreflight());
2079
2184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.1.6-alpha.1",
3
+ "version": "2.1.6-alpha.2",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",