@weapp-tailwindcss/postcss 2.1.6-alpha.0 → 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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-BUB5jCYX.mjs';
2
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, d as PipelineNodeCursor, e as PipelineStage, R as RequiredStyleHandlerOptions, f as ResolvedPipelineNode, g as StyleProcessingPipeline, U as UserDefinedPostcssOptions, h as createInjectPreflight, i as createStylePipeline } from './types-BUB5jCYX.mjs';
3
- export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
1
+ import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-CsRGpZ_r.mjs';
2
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, d as PipelineNodeCursor, e as PipelineStage, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, g as ResolvedPipelineNode, h as StyleProcessingPipeline, U as UserDefinedPostcssOptions, i as createInjectPreflight, j as createStylePipeline } from './types-CsRGpZ_r.mjs';
4
3
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
4
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
5
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-BUB5jCYX.js';
2
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, d as PipelineNodeCursor, e as PipelineStage, R as RequiredStyleHandlerOptions, f as ResolvedPipelineNode, g as StyleProcessingPipeline, U as UserDefinedPostcssOptions, h as createInjectPreflight, i as createStylePipeline } from './types-BUB5jCYX.js';
3
- export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
1
+ import { I as IStyleHandlerOptions, S as StyleHandler, a as InternalCssSelectorReplacerOptions } from './types-CsRGpZ_r.js';
2
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, L as LoadedPostcssOptions, P as PipelineNodeContext, d as PipelineNodeCursor, e as PipelineStage, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, g as ResolvedPipelineNode, h as StyleProcessingPipeline, U as UserDefinedPostcssOptions, i as createInjectPreflight, j as createStylePipeline } from './types-CsRGpZ_r.js';
4
3
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
5
4
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
5
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
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,12 +2273,13 @@ 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]));
2277
+ const presetEnvOptions = options.cssPresetEnv;
2172
2278
  userPlugins.forEach((plugin, index) => {
2173
2279
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2174
2280
  });
2175
2281
  preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
2176
- preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)));
2282
+ preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => _postcsspresetenv2.default.call(void 0, presetEnvOptions)));
2177
2283
  preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
2178
2284
  const unitsToPxPlugin = getUnitsToPxPlugin(options);
2179
2285
  if (unitsToPxPlugin) {
@@ -2263,7 +2369,7 @@ function createStylePipeline(options) {
2263
2369
  function createProcessOptions(options) {
2264
2370
  return {
2265
2371
  from: void 0,
2266
- ..._nullishCoalesce(_optionalChain([options, 'access', _74 => _74.postcssOptions, 'optionalAccess', _75 => _75.options]), () => ( {}))
2372
+ ..._nullishCoalesce(_optionalChain([options, 'access', _76 => _76.postcssOptions, 'optionalAccess', _77 => _77.options]), () => ( {}))
2267
2373
  };
2268
2374
  }
2269
2375
  function getSimpleProcessOptionsCacheKey(options) {
@@ -2302,7 +2408,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2302
2408
  __init4() {this.processorCacheByKey = /* @__PURE__ */ new Map()}
2303
2409
  __init5() {this.processorKeyCache = /* @__PURE__ */ new WeakMap()}
2304
2410
  createProcessorCacheKey(options) {
2305
- 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]);
2306
2412
  if (from == null) {
2307
2413
  return fingerprintOptions(options);
2308
2414
  }
@@ -2311,7 +2417,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2311
2417
  postcssOptions: {
2312
2418
  ..._nullishCoalesce(options.postcssOptions, () => ( {})),
2313
2419
  options: {
2314
- ..._nullishCoalesce(_optionalChain([options, 'access', _79 => _79.postcssOptions, 'optionalAccess', _80 => _80.options]), () => ( {})),
2420
+ ..._nullishCoalesce(_optionalChain([options, 'access', _81 => _81.postcssOptions, 'optionalAccess', _82 => _82.options]), () => ( {})),
2315
2421
  from: void 0
2316
2422
  }
2317
2423
  }
@@ -2326,7 +2432,7 @@ var StyleProcessorCache = (_class = class {constructor() { _class.prototype.__in
2326
2432
  return pipeline;
2327
2433
  }
2328
2434
  getProcessOptions(options) {
2329
- 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]);
2330
2436
  const cacheKey = source ? _nullishCoalesce(getSimpleProcessOptionsCacheKey(source), () => ( fingerprintOptions(source))) : void 0;
2331
2437
  const cached = this.processOptionsCache.get(options);
2332
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
  }
@@ -2169,11 +2274,12 @@ function createPreparedNode(id, stage, createPlugin) {
2169
2274
  function createPreparedNodes(options) {
2170
2275
  const preparedNodes = [];
2171
2276
  const userPlugins = normalizeUserPlugins(options.postcssOptions?.plugins);
2277
+ const presetEnvOptions = options.cssPresetEnv;
2172
2278
  userPlugins.forEach((plugin, index) => {
2173
2279
  preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
2174
2280
  });
2175
2281
  preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
2176
- preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(options.cssPresetEnv)));
2282
+ preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => postcssPresetEnv(presetEnvOptions)));
2177
2283
  preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
2178
2284
  const unitsToPxPlugin = getUnitsToPxPlugin(options);
2179
2285
  if (unitsToPxPlugin) {
@@ -1,7 +1,6 @@
1
1
  import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
2
2
  import { AcceptedPlugin, Result as Result$1 } from 'postcss';
3
3
  import { Result } from 'postcss-load-config';
4
- import { pluginOptions } from 'postcss-preset-env';
5
4
  import { PxTransformOptions } from 'postcss-pxtrans';
6
5
  import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
7
6
  import { UserDefinedOptions as UserDefinedOptions$1 } from 'postcss-units-to-px';
@@ -58,6 +57,21 @@ type IContext = ReturnType<typeof createContext>;
58
57
  type InjectPreflight = () => IPropValue[];
59
58
  declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
60
59
 
60
+ interface PresetEnvOptions {
61
+ stage?: false | 0 | 1 | 2 | 3 | 4;
62
+ minimumVendorImplementations?: number;
63
+ browsers?: string | string[];
64
+ features?: Record<string, boolean | Record<string, unknown>>;
65
+ insertBefore?: Record<string, unknown>;
66
+ insertAfter?: Record<string, unknown>;
67
+ debug?: boolean;
68
+ logical?: {
69
+ inlineDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
70
+ blockDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
71
+ };
72
+ [key: string]: unknown;
73
+ }
74
+
61
75
  type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
62
76
  interface IPropValue {
63
77
  prop: string;
@@ -86,7 +100,7 @@ type IStyleHandlerOptions = {
86
100
  postcssOptions?: LoadedPostcssOptions;
87
101
  cssRemoveProperty?: boolean;
88
102
  cssRemoveHoverPseudoClass?: boolean;
89
- cssPresetEnv?: pluginOptions;
103
+ cssPresetEnv?: PresetEnvOptions;
90
104
  cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
91
105
  atRules?: {
92
106
  property?: boolean;
@@ -100,7 +114,7 @@ interface UserDefinedPostcssOptions {
100
114
  cssPreflight?: CssPreflightOptions;
101
115
  cssPreflightRange?: 'all';
102
116
  cssChildCombinatorReplaceValue?: string | string[];
103
- cssPresetEnv?: pluginOptions;
117
+ cssPresetEnv?: PresetEnvOptions;
104
118
  injectAdditionalCssVarScope?: boolean;
105
119
  cssSelectorReplacement?: {
106
120
  root?: string | string[] | false;
@@ -120,4 +134,4 @@ interface StyleHandler {
120
134
  getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
121
135
  }
122
136
 
123
- export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type ResolvedPipelineNode as f, type StyleProcessingPipeline as g, createInjectPreflight as h, createStylePipeline as i };
137
+ export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type PresetEnvOptions as f, type ResolvedPipelineNode as g, type StyleProcessingPipeline as h, createInjectPreflight as i, createStylePipeline as j };
@@ -1,7 +1,6 @@
1
1
  import { PostCssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
2
2
  import { AcceptedPlugin, Result as Result$1 } from 'postcss';
3
3
  import { Result } from 'postcss-load-config';
4
- import { pluginOptions } from 'postcss-preset-env';
5
4
  import { PxTransformOptions } from 'postcss-pxtrans';
6
5
  import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
7
6
  import { UserDefinedOptions as UserDefinedOptions$1 } from 'postcss-units-to-px';
@@ -58,6 +57,21 @@ type IContext = ReturnType<typeof createContext>;
58
57
  type InjectPreflight = () => IPropValue[];
59
58
  declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
60
59
 
60
+ interface PresetEnvOptions {
61
+ stage?: false | 0 | 1 | 2 | 3 | 4;
62
+ minimumVendorImplementations?: number;
63
+ browsers?: string | string[];
64
+ features?: Record<string, boolean | Record<string, unknown>>;
65
+ insertBefore?: Record<string, unknown>;
66
+ insertAfter?: Record<string, unknown>;
67
+ debug?: boolean;
68
+ logical?: {
69
+ inlineDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
70
+ blockDirection?: 'top-to-bottom' | 'bottom-to-top' | 'right-to-left' | 'left-to-right';
71
+ };
72
+ [key: string]: unknown;
73
+ }
74
+
61
75
  type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
62
76
  interface IPropValue {
63
77
  prop: string;
@@ -86,7 +100,7 @@ type IStyleHandlerOptions = {
86
100
  postcssOptions?: LoadedPostcssOptions;
87
101
  cssRemoveProperty?: boolean;
88
102
  cssRemoveHoverPseudoClass?: boolean;
89
- cssPresetEnv?: pluginOptions;
103
+ cssPresetEnv?: PresetEnvOptions;
90
104
  cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
91
105
  atRules?: {
92
106
  property?: boolean;
@@ -100,7 +114,7 @@ interface UserDefinedPostcssOptions {
100
114
  cssPreflight?: CssPreflightOptions;
101
115
  cssPreflightRange?: 'all';
102
116
  cssChildCombinatorReplaceValue?: string | string[];
103
- cssPresetEnv?: pluginOptions;
117
+ cssPresetEnv?: PresetEnvOptions;
104
118
  injectAdditionalCssVarScope?: boolean;
105
119
  cssSelectorReplacement?: {
106
120
  root?: string | string[] | false;
@@ -120,4 +134,4 @@ interface StyleHandler {
120
134
  getPipeline: (opt?: Partial<IStyleHandlerOptions>) => StyleProcessingPipeline;
121
135
  }
122
136
 
123
- export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type ResolvedPipelineNode as f, type StyleProcessingPipeline as g, createInjectPreflight as h, createStylePipeline as i };
137
+ export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type PipelineNodeContext as P, type RequiredStyleHandlerOptions as R, type StyleHandler as S, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CssPreflightOptions as b, type IPropValue as c, type PipelineNodeCursor as d, type PipelineStage as e, type PresetEnvOptions as f, type ResolvedPipelineNode as g, type StyleProcessingPipeline as h, createInjectPreflight as i, createStylePipeline as j };
package/dist/types.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import '@weapp-tailwindcss/postcss-calc';
2
2
  import 'postcss';
3
3
  import 'postcss-load-config';
4
- export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
5
4
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
6
5
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
7
6
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
8
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-BUB5jCYX.mjs';
7
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-CsRGpZ_r.mjs';
package/dist/types.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import '@weapp-tailwindcss/postcss-calc';
2
2
  import 'postcss';
3
3
  import 'postcss-load-config';
4
- export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
5
4
  export { PxTransformOptions as Px2rpxOptions } from 'postcss-pxtrans';
6
5
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
7
6
  export { UserDefinedOptions as UnitsToPxOptions } from 'postcss-units-to-px';
8
- export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-BUB5jCYX.js';
7
+ export { C as CssCalcOptions, b as CssPreflightOptions, c as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, f as PresetEnvOptions, R as RequiredStyleHandlerOptions, S as StyleHandler, U as UserDefinedPostcssOptions } from './types-CsRGpZ_r.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.1.6-alpha.0",
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",
@@ -35,6 +35,20 @@
35
35
  "main": "./dist/index.js",
36
36
  "module": "./dist/index.mjs",
37
37
  "types": "./dist/index.d.ts",
38
+ "typesVersions": {
39
+ "*": {
40
+ "html-transform": [
41
+ "./dist/html-transform.d.ts"
42
+ ],
43
+ "types": [
44
+ "./dist/types.d.ts"
45
+ ],
46
+ "*": [
47
+ "./dist/*",
48
+ "./dist/index.d.ts"
49
+ ]
50
+ }
51
+ },
38
52
  "files": [
39
53
  "dist"
40
54
  ],
@@ -51,7 +65,7 @@
51
65
  "postcss-selector-parser": "~7.1.1",
52
66
  "postcss-units-to-px": "^0.2.0",
53
67
  "postcss-value-parser": "^4.2.0",
54
- "@weapp-tailwindcss/shared": "1.1.3-alpha.0"
68
+ "@weapp-tailwindcss/shared": "1.1.3-alpha.1"
55
69
  },
56
70
  "devDependencies": {
57
71
  "@csstools/postcss-is-pseudo-class": "^6.0.0",