@weapp-tailwindcss/postcss 3.0.0-next.9 → 3.0.1

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.js CHANGED
@@ -6929,20 +6929,309 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
6929
6929
  if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
6930
6930
  }
6931
6931
  //#endregion
6932
- //#region src/compat/mini-program-css/color-gamut.ts
6932
+ //#region src/cssVarsV4.ts
6933
+ function property(ident, initialValue, _syntax) {
6934
+ return {
6935
+ prop: ident,
6936
+ value: initialValue || ""
6937
+ };
6938
+ }
6939
+ const nullShadow = "0 0 #0000";
6940
+ const nodes = [
6941
+ property("--tw-border-spacing-x", "0", "<length>"),
6942
+ property("--tw-border-spacing-y", "0", "<length>"),
6943
+ property("--tw-translate-x", "0"),
6944
+ property("--tw-translate-y", "0"),
6945
+ property("--tw-translate-z", "0"),
6946
+ property("--tw-scale-x", "1"),
6947
+ property("--tw-scale-y", "1"),
6948
+ property("--tw-scale-z", "1"),
6949
+ property("--tw-rotate-x"),
6950
+ property("--tw-rotate-y"),
6951
+ property("--tw-rotate-z"),
6952
+ property("--tw-skew-x"),
6953
+ property("--tw-skew-y"),
6954
+ property("--tw-pan-x"),
6955
+ property("--tw-pan-y"),
6956
+ property("--tw-pinch-zoom"),
6957
+ property("--tw-scroll-snap-strictness", "proximity", "*"),
6958
+ property("--tw-space-x-reverse", "0"),
6959
+ property("--tw-space-y-reverse", "0"),
6960
+ property("--tw-scrollbar-thumb", "#0000", "<color>"),
6961
+ property("--tw-scrollbar-track", "#0000", "<color>"),
6962
+ property("--tw-border-style", "solid"),
6963
+ property("--tw-divide-x-reverse", "0"),
6964
+ property("--tw-divide-y-reverse", "0"),
6965
+ property("--tw-gradient-position", "initial"),
6966
+ property("--tw-gradient-from", "#0000", "<color>"),
6967
+ property("--tw-gradient-via", "#0000", "<color>"),
6968
+ property("--tw-gradient-to", "#0000", "<color>"),
6969
+ property("--tw-gradient-stops", "initial"),
6970
+ property("--tw-gradient-via-stops", "initial"),
6971
+ property("--tw-gradient-from-position", "0%", "<length-percentage>"),
6972
+ property("--tw-gradient-via-position", "50%", "<length-percentage>"),
6973
+ property("--tw-gradient-to-position", "100%", "<length-percentage>"),
6974
+ property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
6975
+ property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
6976
+ property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
6977
+ property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
6978
+ property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
6979
+ property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
6980
+ property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
6981
+ property("--tw-mask-linear-position", "0deg"),
6982
+ property("--tw-mask-linear-from-position", "0%"),
6983
+ property("--tw-mask-linear-to-position", "100%"),
6984
+ property("--tw-mask-linear-from-color", "black"),
6985
+ property("--tw-mask-linear-to-color", "transparent"),
6986
+ property("--tw-mask-radial-from-position", "0%"),
6987
+ property("--tw-mask-radial-to-position", "100%"),
6988
+ property("--tw-mask-radial-from-color", "black"),
6989
+ property("--tw-mask-radial-to-color", "transparent"),
6990
+ property("--tw-mask-radial-shape", "ellipse"),
6991
+ property("--tw-mask-radial-size", "farthest-corner"),
6992
+ property("--tw-mask-radial-position", "center"),
6993
+ property("--tw-mask-conic-position", "0deg"),
6994
+ property("--tw-mask-conic-from-position", "0%"),
6995
+ property("--tw-mask-conic-to-position", "100%"),
6996
+ property("--tw-mask-conic-from-color", "black"),
6997
+ property("--tw-mask-conic-to-color", "transparent"),
6998
+ property("--tw-font-weight"),
6999
+ property("--tw-blur"),
7000
+ property("--tw-brightness"),
7001
+ property("--tw-contrast"),
7002
+ property("--tw-grayscale"),
7003
+ property("--tw-hue-rotate"),
7004
+ property("--tw-invert"),
7005
+ property("--tw-opacity"),
7006
+ property("--tw-saturate"),
7007
+ property("--tw-sepia"),
7008
+ property("--tw-drop-shadow"),
7009
+ property("--tw-drop-shadow-color"),
7010
+ property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
7011
+ property("--tw-drop-shadow-size"),
7012
+ property("--tw-backdrop-blur"),
7013
+ property("--tw-backdrop-brightness"),
7014
+ property("--tw-backdrop-contrast"),
7015
+ property("--tw-backdrop-grayscale"),
7016
+ property("--tw-backdrop-hue-rotate"),
7017
+ property("--tw-backdrop-invert"),
7018
+ property("--tw-backdrop-opacity"),
7019
+ property("--tw-backdrop-saturate"),
7020
+ property("--tw-backdrop-sepia"),
7021
+ property("--tw-duration", "initial"),
7022
+ property("--tw-ease", "initial"),
7023
+ property("--tw-content", "\"\""),
7024
+ property("--tw-contain-size"),
7025
+ property("--tw-contain-layout"),
7026
+ property("--tw-contain-paint"),
7027
+ property("--tw-contain-style"),
7028
+ property("--tw-leading"),
7029
+ property("--tw-tracking"),
7030
+ property("--tw-ordinal"),
7031
+ property("--tw-slashed-zero"),
7032
+ property("--tw-numeric-figure"),
7033
+ property("--tw-numeric-spacing"),
7034
+ property("--tw-numeric-fraction"),
7035
+ property("--tw-outline-style", "solid"),
7036
+ property("--tw-text-shadow-color", "initial"),
7037
+ property("--tw-text-shadow-alpha", "100%", "<percentage>"),
7038
+ property("--tw-shadow", nullShadow),
7039
+ property("--tw-shadow-color", "initial"),
7040
+ property("--tw-shadow-alpha", "100%", "<percentage>"),
7041
+ property("--tw-inset-shadow", nullShadow),
7042
+ property("--tw-inset-shadow-color", "initial"),
7043
+ property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
7044
+ property("--tw-ring-color"),
7045
+ property("--tw-ring-shadow", nullShadow),
7046
+ property("--tw-inset-ring-color"),
7047
+ property("--tw-inset-ring-shadow", nullShadow),
7048
+ property("--tw-ring-inset"),
7049
+ property("--tw-ring-offset-width", "0px", "<length>"),
7050
+ property("--tw-ring-offset-color", "#fff"),
7051
+ property("--tw-ring-offset-shadow", nullShadow)
7052
+ ];
7053
+ for (const edge of [
7054
+ "top",
7055
+ "right",
7056
+ "bottom",
7057
+ "left"
7058
+ ]) nodes.push(property(`--tw-mask-${edge}-from-position`, "0%"), property(`--tw-mask-${edge}-to-position`, "100%"), property(`--tw-mask-${edge}-from-color`, "black"), property(`--tw-mask-${edge}-to-color`, "transparent"));
7059
+ //#endregion
7060
+ //#region src/utils/css-vars.ts
7061
+ /**
7062
+ * 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
7063
+ */
7064
+ function createCssVarNodes(definitions) {
7065
+ return definitions.map((def) => new postcss.Declaration({
7066
+ prop: def.prop,
7067
+ value: def.value
7068
+ }));
7069
+ }
7070
+ //#endregion
7071
+ //#region src/compat/tailwindcss-v4.ts
7072
+ const OKLAB_SUFFIX = "in oklab";
7073
+ const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
7074
+ const RADIUS_THRESHOLD = 1e5;
7075
+ const CLAMP_PX = 9999;
7076
+ const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
7077
+ const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
7078
+ const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
7079
+ const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
7080
+ const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
7081
+ const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
6933
7082
  const DISPLAY_P3_VALUE_RE$1 = /color\(\s*display-p3\b/i;
6934
7083
  const COLOR_GAMUT_P3_RE$1 = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
6935
- function isDisplayP3MediaRule(atRule) {
7084
+ const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
7085
+ const SCIENTIFIC_NOTATION_RE = /e/i;
7086
+ const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
7087
+ const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
7088
+ const DEFAULT_VARIABLE_SCOPE_SELECTORS = new Set([
7089
+ "*",
7090
+ ":root",
7091
+ ":host",
7092
+ "page",
7093
+ ".tw-root",
7094
+ "wx-root-portal-content",
7095
+ "view",
7096
+ "text",
7097
+ ":before",
7098
+ ":after",
7099
+ "::before",
7100
+ "::after",
7101
+ "::backdrop"
7102
+ ]);
7103
+ function isTailwindcssV4(options) {
7104
+ return options?.majorVersion === 4;
7105
+ }
7106
+ function testIfRootHostForV4(node) {
7107
+ return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
7108
+ }
7109
+ createCssVarNodes(nodes);
7110
+ function collectUsedTailwindcssV4Variables(root) {
7111
+ const props = /* @__PURE__ */ new Set();
7112
+ root.walkDecls((decl) => {
7113
+ if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
7114
+ TW_VAR_FUNCTION_RE.lastIndex = 0;
7115
+ let match = TW_VAR_FUNCTION_RE.exec(decl.value);
7116
+ while (match !== null) {
7117
+ const prop = match[1];
7118
+ if (prop) props.add(prop);
7119
+ match = TW_VAR_FUNCTION_RE.exec(decl.value);
7120
+ }
7121
+ });
7122
+ root.walkAtRules("property", (atRule) => {
7123
+ const prop = atRule.params.trim();
7124
+ if (prop.startsWith("--tw-")) props.add(prop);
7125
+ });
7126
+ return props;
7127
+ }
7128
+ function usesTailwindcssV4ContentVariable(root) {
7129
+ let used = false;
7130
+ root.walkDecls((decl) => {
7131
+ if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
7132
+ });
7133
+ return used;
7134
+ }
7135
+ function createUsedCssVarsV4Nodes(usedProps) {
7136
+ return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new postcss.Declaration({
7137
+ prop: def.prop,
7138
+ value: def.value
7139
+ }));
7140
+ }
7141
+ function isInsideAtRule(decl, name) {
7142
+ let parent = decl.parent;
7143
+ while (parent) {
7144
+ if (parent.type === "atrule" && parent.name === name) return true;
7145
+ parent = parent.parent;
7146
+ }
7147
+ return false;
7148
+ }
7149
+ function isDefaultVariableScopeRule(rule) {
7150
+ if (!rule.selectors.every((selector) => DEFAULT_VARIABLE_SCOPE_SELECTORS.has(selector.trim()))) return false;
7151
+ let hasDeclaration = false;
7152
+ let onlyCustomProperties = true;
7153
+ rule.each((node) => {
7154
+ if (node.type !== "decl") return;
7155
+ hasDeclaration = true;
7156
+ if (!node.prop.startsWith("--")) onlyCustomProperties = false;
7157
+ });
7158
+ return hasDeclaration && onlyCustomProperties;
7159
+ }
7160
+ function collectScopedTailwindcssV4DefaultVariables(root) {
7161
+ const props = /* @__PURE__ */ new Set();
7162
+ root.walkDecls((decl) => {
7163
+ if (!decl.prop.startsWith("--tw-")) return;
7164
+ if (isInsideAtRule(decl, "supports")) return;
7165
+ if (decl.parent?.type === "rule" && isDefaultVariableScopeRule(decl.parent)) props.add(decl.prop);
7166
+ });
7167
+ return props;
7168
+ }
7169
+ function createMissingCssVarsV4Nodes(root, usedProps) {
7170
+ const scopedProps = collectScopedTailwindcssV4DefaultVariables(root);
7171
+ return nodes.filter((def) => usedProps.has(def.prop) && !scopedProps.has(def.prop)).map((def) => new postcss.Declaration({
7172
+ prop: def.prop,
7173
+ value: def.value
7174
+ }));
7175
+ }
7176
+ function isTailwindcssV4ModernCheck(atRule) {
7177
+ return atRule.name === "supports" && [
7178
+ MODERN_CHECK_WEBKIT_HYPHENS_RE,
7179
+ MODERN_CHECK_MARGIN_TRIM_RE,
7180
+ MODERN_CHECK_MOZ_ORIENT_RE,
7181
+ MODERN_CHECK_COLOR_RGB_RE
7182
+ ].every((regex) => regex.test(atRule.params));
7183
+ }
7184
+ function isTailwindcssV4LinearGradientSupports(atRule) {
7185
+ return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
7186
+ }
7187
+ function isTailwindcssV4DisplayP3Supports(atRule) {
7188
+ return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
7189
+ }
7190
+ function isTailwindcssV4DisplayP3Media(atRule) {
6936
7191
  return atRule.name === "media" && COLOR_GAMUT_P3_RE$1.test(atRule.params);
6937
7192
  }
6938
- function isDisplayP3Declaration(decl) {
7193
+ function isTailwindcssV4DisplayP3Declaration(decl) {
6939
7194
  return DISPLAY_P3_VALUE_RE$1.test(decl.value);
6940
7195
  }
7196
+ function normalizeTailwindcssV4Declaration(decl) {
7197
+ if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
7198
+ decl.value = decl.value.slice(0, decl.value.length - 8);
7199
+ return true;
7200
+ }
7201
+ if (INFINITY_CALC_REGEXP.test(decl.value)) {
7202
+ decl.value = `${CLAMP_PX}px`;
7203
+ return true;
7204
+ }
7205
+ if (decl.prop.includes("radius")) {
7206
+ RADIUS_VALUE_RE.lastIndex = 0;
7207
+ const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
7208
+ const n = Number(num);
7209
+ if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
7210
+ if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
7211
+ return m;
7212
+ });
7213
+ if (next !== decl.value) {
7214
+ decl.value = next;
7215
+ return true;
7216
+ }
7217
+ }
7218
+ return false;
7219
+ }
7220
+ //#endregion
7221
+ //#region src/compat/mini-program-css/color-gamut.ts
7222
+ const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
7223
+ const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
7224
+ function isDisplayP3MediaRule(atRule) {
7225
+ return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
7226
+ }
7227
+ function isDisplayP3Declaration(decl) {
7228
+ return DISPLAY_P3_VALUE_RE.test(decl.value);
7229
+ }
6941
7230
  //#endregion
6942
7231
  //#region src/compat/mini-program-css/selectors.ts
6943
7232
  const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
6944
- const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
6945
- "*",
7233
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
7234
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = new Set([
6946
7235
  "view",
6947
7236
  "text",
6948
7237
  ":before",
@@ -6950,6 +7239,7 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
6950
7239
  "::before",
6951
7240
  "::after"
6952
7241
  ]);
7242
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
6953
7243
  const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
6954
7244
  ":host",
6955
7245
  ":root",
@@ -7028,8 +7318,14 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
7028
7318
  function normalizeSelector$1(selector) {
7029
7319
  return selector.trim().replace(/\s+/g, "");
7030
7320
  }
7321
+ function normalizePseudoElementSelector(selector) {
7322
+ return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
7323
+ }
7031
7324
  function getRuleSelectors(rule) {
7032
- return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
7325
+ return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
7326
+ }
7327
+ function getSortedRuleSelectorKey(rule) {
7328
+ return getRuleSelectors(rule).sort().join(",");
7033
7329
  }
7034
7330
  function isUnsupportedBrowserSelector(selector) {
7035
7331
  const normalized = normalizeSelector$1(selector);
@@ -7053,7 +7349,7 @@ const PREFLIGHT_RESET_PROPS = new Set([
7053
7349
  "padding"
7054
7350
  ]);
7055
7351
  const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
7056
- const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
7352
+ const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
7057
7353
  function hasTailwindPreflightDeclaration(rule) {
7058
7354
  let hasTailwindVar = false;
7059
7355
  let hasResetProp = false;
@@ -7063,13 +7359,6 @@ function hasTailwindPreflightDeclaration(rule) {
7063
7359
  });
7064
7360
  return hasTailwindVar || hasResetProp;
7065
7361
  }
7066
- function hasTwContentDeclaration(rule) {
7067
- let hasContentInit = false;
7068
- rule.walkDecls("--tw-content", () => {
7069
- hasContentInit = true;
7070
- });
7071
- return hasContentInit;
7072
- }
7073
7362
  function isCustomPropertyRule(rule) {
7074
7363
  let hasDeclaration = false;
7075
7364
  let allCustomProperties = true;
@@ -7099,7 +7388,7 @@ function isPseudoContentInitRule(rule) {
7099
7388
  function usesTwContentVariable(root) {
7100
7389
  let used = false;
7101
7390
  root.walkDecls((decl) => {
7102
- if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
7391
+ if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
7103
7392
  });
7104
7393
  return used;
7105
7394
  }
@@ -7182,8 +7471,11 @@ function removeUnsupportedModernColorDeclarations(root) {
7182
7471
  //#endregion
7183
7472
  //#region src/compat/mini-program-css/finalize.ts
7184
7473
  const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
7474
+ const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
7475
+ const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
7476
+ const MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS = new Set(["::before", "::after"]);
7185
7477
  function createPseudoContentInitRule() {
7186
- const rule = postcss.default.rule({ selector: "::before,\n::after" });
7478
+ const rule = postcss.default.rule({ selector: MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR });
7187
7479
  rule.append({
7188
7480
  prop: "--tw-content",
7189
7481
  value: "''"
@@ -7192,22 +7484,29 @@ function createPseudoContentInitRule() {
7192
7484
  }
7193
7485
  function collectPreflightRules(root, options = {}) {
7194
7486
  const preflightNodes = [];
7195
- let hasContentInit = false;
7196
- for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
7197
- preflightNodes.push(node);
7198
- if (hasTwContentDeclaration(node)) hasContentInit = true;
7199
- }
7487
+ for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) preflightNodes.push(node);
7200
7488
  if (preflightNodes.length === 0) return [];
7201
- const clonedPreflightRules = preflightNodes.map((node) => node.clone());
7202
- const contentInitRules = options.preservePseudoContentInit ? clonedPreflightRules.filter((rule) => hasTwContentDeclaration(rule)) : [];
7203
- const otherPreflightRules = clonedPreflightRules.filter((rule) => !hasTwContentDeclaration(rule));
7204
- const preflightRules = hasContentInit ? [...contentInitRules, ...otherPreflightRules] : [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...otherPreflightRules];
7489
+ const clonedPreflightRules = preflightNodes.map((node) => {
7490
+ const rule = node.clone();
7491
+ rule.walkDecls("--tw-content", (decl) => {
7492
+ if (isEmptyTwContentDeclaration(decl)) decl.remove();
7493
+ });
7494
+ return rule;
7495
+ });
7496
+ for (const rule of clonedPreflightRules) {
7497
+ const selectors = getRuleSelectors(rule);
7498
+ const hasElementSelector = selectors.some((selector) => selector === "view" || selector === "text");
7499
+ if (selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PSEUDO_CONTENT_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR;
7500
+ else if (hasElementSelector && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector))) rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
7501
+ }
7502
+ const nonEmptyPreflightRules = clonedPreflightRules.filter((rule) => (rule.nodes?.length ?? 0) > 0);
7503
+ const preflightRules = [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...nonEmptyPreflightRules];
7205
7504
  for (const node of preflightNodes) node.remove();
7206
7505
  return preflightRules;
7207
7506
  }
7208
7507
  function createPreflightResetRule(cssPreflight) {
7209
7508
  if (!cssPreflight || typeof cssPreflight !== "object") return;
7210
- const rule = postcss.default.rule({ selector: "view,text,:after,:before" });
7509
+ const rule = postcss.default.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
7211
7510
  for (const [prop, value] of Object.entries(cssPreflight)) {
7212
7511
  if (value === false) continue;
7213
7512
  rule.append({
@@ -7236,6 +7535,18 @@ function collectThemeVariableRule(root, options = {}) {
7236
7535
  for (const decl of declarations.values()) rule.append(decl);
7237
7536
  return rule;
7238
7537
  }
7538
+ function hasTailwindcssV4Signal(css) {
7539
+ if (TAILWIND_V4_BANNER_RE.test(css)) return true;
7540
+ const root = postcss.default.parse(css);
7541
+ let hasProperty = false;
7542
+ root.walkAtRules("property", (atRule) => {
7543
+ if (atRule.params.trim().startsWith("--tw-")) {
7544
+ hasProperty = true;
7545
+ return false;
7546
+ }
7547
+ });
7548
+ return hasProperty;
7549
+ }
7239
7550
  function getTopDirectiveTail(root) {
7240
7551
  let tail;
7241
7552
  for (const node of root.nodes ?? []) {
@@ -7273,12 +7584,28 @@ function insertHoistedRules(root, rules, anchor) {
7273
7584
  if (topDirectiveTail) topDirectiveTail.after(rules);
7274
7585
  else root.prepend(rules);
7275
7586
  }
7587
+ function mergeEquivalentHoistedRules(rules) {
7588
+ const mergedRules = [];
7589
+ const ruleBySelector = /* @__PURE__ */ new Map();
7590
+ for (const rule of rules) {
7591
+ const key = getSortedRuleSelectorKey(rule);
7592
+ const existingRule = ruleBySelector.get(key);
7593
+ if (existingRule) {
7594
+ existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
7595
+ continue;
7596
+ }
7597
+ ruleBySelector.set(key, rule);
7598
+ mergedRules.push(rule);
7599
+ }
7600
+ return mergedRules;
7601
+ }
7276
7602
  function unwrapTailwindSourceMedia(root) {
7277
7603
  root.walkAtRules("media", (atRule) => {
7278
7604
  if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
7279
7605
  });
7280
7606
  }
7281
7607
  function finalizeMiniProgramCssRoot(root, options = {}) {
7608
+ const tailwindcssV4DefaultNodes = options.isTailwindcssV4 === true ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
7282
7609
  removeUnsupportedCascadeLayers(root);
7283
7610
  unwrapTailwindSourceMedia(root);
7284
7611
  root.walkAtRules("property", (atRule) => {
@@ -7300,8 +7627,12 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
7300
7627
  const resetRule = createPreflightResetRule(options.cssPreflight);
7301
7628
  if (resetRule) preflightRules.push(resetRule);
7302
7629
  }
7630
+ if (tailwindcssV4DefaultNodes.length > 0) preflightRules.push(postcss.default.rule({
7631
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7632
+ nodes: tailwindcssV4DefaultNodes
7633
+ }));
7303
7634
  const themeRule = collectThemeVariableRule(root, options);
7304
- insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
7635
+ insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
7305
7636
  }
7306
7637
  function hoistTailwindPreflightBase(css) {
7307
7638
  try {
@@ -7313,10 +7644,19 @@ function hoistTailwindPreflightBase(css) {
7313
7644
  }
7314
7645
  }
7315
7646
  function finalizeMiniProgramCss(css, options = {}) {
7647
+ let isTailwindcssV4 = options.isTailwindcssV4;
7648
+ if (isTailwindcssV4 === void 0) try {
7649
+ isTailwindcssV4 = hasTailwindcssV4Signal(css);
7650
+ } catch {
7651
+ isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(css);
7652
+ }
7316
7653
  const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
7317
7654
  try {
7318
7655
  const root = postcss.default.parse(cleanedCss);
7319
- finalizeMiniProgramCssRoot(root, options);
7656
+ finalizeMiniProgramCssRoot(root, {
7657
+ ...options,
7658
+ isTailwindcssV4
7659
+ });
7320
7660
  return root.toString();
7321
7661
  } catch {
7322
7662
  return cleanedCss;
@@ -7325,16 +7665,7 @@ function finalizeMiniProgramCss(css, options = {}) {
7325
7665
  //#endregion
7326
7666
  //#region src/compat/mini-program-css/prune-generated.ts
7327
7667
  const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
7328
- const DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE = "view,text,:before,:after";
7329
7668
  const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
7330
- const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
7331
- "view",
7332
- "text",
7333
- ":before",
7334
- ":after",
7335
- "::before",
7336
- "::after"
7337
- ]);
7338
7669
  function isConditionalCompilationComment(text) {
7339
7670
  return /#(?:ifn?def|endif)\b/.test(text);
7340
7671
  }
@@ -7348,7 +7679,7 @@ function removeEmptyContentInitDeclarations(rule) {
7348
7679
  }
7349
7680
  function isMiniProgramElementVariableScopeRule(rule) {
7350
7681
  const selectors = getRuleSelectors(rule);
7351
- return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS.has(selector));
7682
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
7352
7683
  }
7353
7684
  function isTailwindV4GradientRuntimeDeclaration(decl) {
7354
7685
  return decl.prop.startsWith("--tw-gradient-");
@@ -7362,7 +7693,7 @@ function moveTailwindV4GradientRuntimeDeclarations(rule) {
7362
7693
  }
7363
7694
  });
7364
7695
  if (gradientDeclarations.length > 0) rule.before(new postcss.default.Rule({
7365
- selector: DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE,
7696
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7366
7697
  nodes: gradientDeclarations
7367
7698
  }));
7368
7699
  if (rule.nodes.length === 0) rule.remove();
@@ -7399,7 +7730,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
7399
7730
  root.walkRules((rule) => {
7400
7731
  if (isKeyframesRule(rule)) return;
7401
7732
  if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
7402
- rule.selector = DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE;
7733
+ rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
7403
7734
  return;
7404
7735
  }
7405
7736
  if (isMiniProgramThemeVariableRule(rule)) {
@@ -52483,245 +52814,6 @@ function normalizeTailwindcssRpxDeclaration(decl, options) {
52483
52814
  return false;
52484
52815
  }
52485
52816
  //#endregion
52486
- //#region src/cssVarsV4.ts
52487
- function property(ident, initialValue, _syntax) {
52488
- return {
52489
- prop: ident,
52490
- value: initialValue || ""
52491
- };
52492
- }
52493
- const nullShadow = "0 0 #0000";
52494
- const nodes = [
52495
- property("--tw-border-spacing-x", "0", "<length>"),
52496
- property("--tw-border-spacing-y", "0", "<length>"),
52497
- property("--tw-translate-x", "0"),
52498
- property("--tw-translate-y", "0"),
52499
- property("--tw-translate-z", "0"),
52500
- property("--tw-scale-x", "1"),
52501
- property("--tw-scale-y", "1"),
52502
- property("--tw-scale-z", "1"),
52503
- property("--tw-rotate-x"),
52504
- property("--tw-rotate-y"),
52505
- property("--tw-rotate-z"),
52506
- property("--tw-skew-x"),
52507
- property("--tw-skew-y"),
52508
- property("--tw-pan-x"),
52509
- property("--tw-pan-y"),
52510
- property("--tw-pinch-zoom"),
52511
- property("--tw-scroll-snap-strictness", "proximity", "*"),
52512
- property("--tw-space-x-reverse", "0"),
52513
- property("--tw-space-y-reverse", "0"),
52514
- property("--tw-scrollbar-thumb", "#0000", "<color>"),
52515
- property("--tw-scrollbar-track", "#0000", "<color>"),
52516
- property("--tw-border-style", "solid"),
52517
- property("--tw-divide-x-reverse", "0"),
52518
- property("--tw-divide-y-reverse", "0"),
52519
- property("--tw-gradient-position", "initial"),
52520
- property("--tw-gradient-from", "#0000", "<color>"),
52521
- property("--tw-gradient-via", "#0000", "<color>"),
52522
- property("--tw-gradient-to", "#0000", "<color>"),
52523
- property("--tw-gradient-stops", "initial"),
52524
- property("--tw-gradient-via-stops", "initial"),
52525
- property("--tw-gradient-from-position", "0%", "<length-percentage>"),
52526
- property("--tw-gradient-via-position", "50%", "<length-percentage>"),
52527
- property("--tw-gradient-to-position", "100%", "<length-percentage>"),
52528
- property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
52529
- property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
52530
- property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
52531
- property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
52532
- property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
52533
- property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
52534
- property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
52535
- property("--tw-mask-linear-position", "0deg"),
52536
- property("--tw-mask-linear-from-position", "0%"),
52537
- property("--tw-mask-linear-to-position", "100%"),
52538
- property("--tw-mask-linear-from-color", "black"),
52539
- property("--tw-mask-linear-to-color", "transparent"),
52540
- property("--tw-mask-radial-from-position", "0%"),
52541
- property("--tw-mask-radial-to-position", "100%"),
52542
- property("--tw-mask-radial-from-color", "black"),
52543
- property("--tw-mask-radial-to-color", "transparent"),
52544
- property("--tw-mask-radial-shape", "ellipse"),
52545
- property("--tw-mask-radial-size", "farthest-corner"),
52546
- property("--tw-mask-radial-position", "center"),
52547
- property("--tw-mask-conic-position", "0deg"),
52548
- property("--tw-mask-conic-from-position", "0%"),
52549
- property("--tw-mask-conic-to-position", "100%"),
52550
- property("--tw-mask-conic-from-color", "black"),
52551
- property("--tw-mask-conic-to-color", "transparent"),
52552
- property("--tw-font-weight"),
52553
- property("--tw-blur"),
52554
- property("--tw-brightness"),
52555
- property("--tw-contrast"),
52556
- property("--tw-grayscale"),
52557
- property("--tw-hue-rotate"),
52558
- property("--tw-invert"),
52559
- property("--tw-opacity"),
52560
- property("--tw-saturate"),
52561
- property("--tw-sepia"),
52562
- property("--tw-drop-shadow"),
52563
- property("--tw-drop-shadow-color"),
52564
- property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
52565
- property("--tw-drop-shadow-size"),
52566
- property("--tw-backdrop-blur"),
52567
- property("--tw-backdrop-brightness"),
52568
- property("--tw-backdrop-contrast"),
52569
- property("--tw-backdrop-grayscale"),
52570
- property("--tw-backdrop-hue-rotate"),
52571
- property("--tw-backdrop-invert"),
52572
- property("--tw-backdrop-opacity"),
52573
- property("--tw-backdrop-saturate"),
52574
- property("--tw-backdrop-sepia"),
52575
- property("--tw-duration", "initial"),
52576
- property("--tw-ease", "initial"),
52577
- property("--tw-content", "\"\""),
52578
- property("--tw-contain-size"),
52579
- property("--tw-contain-layout"),
52580
- property("--tw-contain-paint"),
52581
- property("--tw-contain-style"),
52582
- property("--tw-leading"),
52583
- property("--tw-tracking"),
52584
- property("--tw-ordinal"),
52585
- property("--tw-slashed-zero"),
52586
- property("--tw-numeric-figure"),
52587
- property("--tw-numeric-spacing"),
52588
- property("--tw-numeric-fraction"),
52589
- property("--tw-outline-style", "solid"),
52590
- property("--tw-text-shadow-color", "initial"),
52591
- property("--tw-text-shadow-alpha", "100%", "<percentage>"),
52592
- property("--tw-shadow", nullShadow),
52593
- property("--tw-shadow-color", "initial"),
52594
- property("--tw-shadow-alpha", "100%", "<percentage>"),
52595
- property("--tw-inset-shadow", nullShadow),
52596
- property("--tw-inset-shadow-color", "initial"),
52597
- property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
52598
- property("--tw-ring-color"),
52599
- property("--tw-ring-shadow", nullShadow),
52600
- property("--tw-inset-ring-color"),
52601
- property("--tw-inset-ring-shadow", nullShadow),
52602
- property("--tw-ring-inset"),
52603
- property("--tw-ring-offset-width", "0px", "<length>"),
52604
- property("--tw-ring-offset-color", "#fff"),
52605
- property("--tw-ring-offset-shadow", nullShadow)
52606
- ];
52607
- for (const edge of [
52608
- "top",
52609
- "right",
52610
- "bottom",
52611
- "left"
52612
- ]) nodes.push(property(`--tw-mask-${edge}-from-position`, "0%"), property(`--tw-mask-${edge}-to-position`, "100%"), property(`--tw-mask-${edge}-from-color`, "black"), property(`--tw-mask-${edge}-to-color`, "transparent"));
52613
- //#endregion
52614
- //#region src/utils/css-vars.ts
52615
- /**
52616
- * 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
52617
- */
52618
- function createCssVarNodes(definitions) {
52619
- return definitions.map((def) => new postcss.Declaration({
52620
- prop: def.prop,
52621
- value: def.value
52622
- }));
52623
- }
52624
- //#endregion
52625
- //#region src/compat/tailwindcss-v4.ts
52626
- const OKLAB_SUFFIX = "in oklab";
52627
- const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
52628
- const RADIUS_THRESHOLD = 1e5;
52629
- const CLAMP_PX = 9999;
52630
- const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
52631
- const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
52632
- const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
52633
- const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
52634
- const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
52635
- const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
52636
- const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
52637
- const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
52638
- const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
52639
- const SCIENTIFIC_NOTATION_RE = /e/i;
52640
- const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
52641
- const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
52642
- function isTailwindcssV4(options) {
52643
- return options?.majorVersion === 4;
52644
- }
52645
- function testIfRootHostForV4(node) {
52646
- return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
52647
- }
52648
- createCssVarNodes(nodes);
52649
- function collectUsedTailwindcssV4Variables(root) {
52650
- const props = /* @__PURE__ */ new Set();
52651
- root.walkDecls((decl) => {
52652
- if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
52653
- TW_VAR_FUNCTION_RE.lastIndex = 0;
52654
- let match = TW_VAR_FUNCTION_RE.exec(decl.value);
52655
- while (match !== null) {
52656
- const prop = match[1];
52657
- if (prop) props.add(prop);
52658
- match = TW_VAR_FUNCTION_RE.exec(decl.value);
52659
- }
52660
- });
52661
- root.walkAtRules("property", (atRule) => {
52662
- const prop = atRule.params.trim();
52663
- if (prop.startsWith("--tw-")) props.add(prop);
52664
- });
52665
- return props;
52666
- }
52667
- function usesTailwindcssV4ContentVariable(root) {
52668
- let used = false;
52669
- root.walkDecls((decl) => {
52670
- if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
52671
- });
52672
- return used;
52673
- }
52674
- function createUsedCssVarsV4Nodes(usedProps) {
52675
- return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new postcss.Declaration({
52676
- prop: def.prop,
52677
- value: def.value
52678
- }));
52679
- }
52680
- function isTailwindcssV4ModernCheck(atRule) {
52681
- return atRule.name === "supports" && [
52682
- MODERN_CHECK_WEBKIT_HYPHENS_RE,
52683
- MODERN_CHECK_MARGIN_TRIM_RE,
52684
- MODERN_CHECK_MOZ_ORIENT_RE,
52685
- MODERN_CHECK_COLOR_RGB_RE
52686
- ].every((regex) => regex.test(atRule.params));
52687
- }
52688
- function isTailwindcssV4LinearGradientSupports(atRule) {
52689
- return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
52690
- }
52691
- function isTailwindcssV4DisplayP3Supports(atRule) {
52692
- return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
52693
- }
52694
- function isTailwindcssV4DisplayP3Media(atRule) {
52695
- return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
52696
- }
52697
- function isTailwindcssV4DisplayP3Declaration(decl) {
52698
- return DISPLAY_P3_VALUE_RE.test(decl.value);
52699
- }
52700
- function normalizeTailwindcssV4Declaration(decl) {
52701
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
52702
- decl.value = decl.value.slice(0, decl.value.length - 8);
52703
- return true;
52704
- }
52705
- if (INFINITY_CALC_REGEXP.test(decl.value)) {
52706
- decl.value = `${CLAMP_PX}px`;
52707
- return true;
52708
- }
52709
- if (decl.prop.includes("radius")) {
52710
- RADIUS_VALUE_RE.lastIndex = 0;
52711
- const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
52712
- const n = Number(num);
52713
- if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
52714
- if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
52715
- return m;
52716
- });
52717
- if (next !== decl.value) {
52718
- decl.value = next;
52719
- return true;
52720
- }
52721
- }
52722
- return false;
52723
- }
52724
- //#endregion
52725
52817
  //#region src/constants.ts
52726
52818
  const postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
52727
52819
  //#endregion
@@ -53111,6 +53203,7 @@ const MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET = new Set([
53111
53203
  "::-webkit-backdrop",
53112
53204
  "::file-selector-button"
53113
53205
  ]);
53206
+ const NORMALIZED_PSEUDO_ELEMENT_SELECTOR = new Map([[":before", "::before"], [":after", "::after"]]);
53114
53207
  function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
53115
53208
  if (!isUniAppXEnabled(options)) return selector.nodes.some((node) => node.type === "pseudo" && MINI_PROGRAM_UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
53116
53209
  return selector.nodes.some((node) => node.type === "pseudo" && UNSUPPORTED_PSEUDO_ELEMENT_SELECTOR_SET.has(node.value));
@@ -53147,6 +53240,11 @@ function handlePseudoNode(node, index, context, parent) {
53147
53240
  node.value = context.rootReplacement;
53148
53241
  return;
53149
53242
  }
53243
+ const normalizedPseudoElement = NORMALIZED_PSEUDO_ELEMENT_SELECTOR.get(node.value);
53244
+ if (normalizedPseudoElement) {
53245
+ node.value = normalizedPseudoElement;
53246
+ return;
53247
+ }
53150
53248
  if (node.value === ":where") flattenWherePseudo(node, context, index, parent);
53151
53249
  }
53152
53250
  function handleTagOrAttribute(node, context) {
@@ -53605,12 +53703,21 @@ function removeLegacyFlexboxPrefix(decl) {
53605
53703
  }
53606
53704
  if (LEGACY_FLEXBOX_DECLARATION_PROPS.has(decl.prop)) decl.remove();
53607
53705
  }
53706
+ function injectMissingTailwindcssV4Defaults(root) {
53707
+ const nodes = createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root));
53708
+ if (nodes.length === 0) return;
53709
+ root.append({
53710
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
53711
+ nodes
53712
+ });
53713
+ }
53608
53714
  const postcssWeappTailwindcssPostPlugin = (options) => {
53609
53715
  const opts = (0, _weapp_tailwindcss_shared.defu)(options, { isMainChunk: true });
53610
53716
  const p = { postcssPlugin };
53611
53717
  const cleanRootSpecificity = createRootSpecificityCleaner(opts);
53612
53718
  const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
53613
53719
  const shouldAppendHostSelector = createHostSelectorAppender(opts);
53720
+ let shouldInjectTailwindcssV4Defaults = false;
53614
53721
  const enableMainChunkTransforms = opts.isMainChunk !== false;
53615
53722
  if (enableMainChunkTransforms || cleanRootSpecificity) {
53616
53723
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
@@ -53647,13 +53754,17 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
53647
53754
  root.walkAtRules((atRule) => {
53648
53755
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53649
53756
  });
53757
+ if (shouldInjectTailwindcssV4Defaults) injectMissingTailwindcssV4Defaults(root);
53650
53758
  };
53651
53759
  p.AtRuleExit = (atRule) => {
53652
53760
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53653
53761
  /**
53654
53762
  * @description 移除 property
53655
53763
  */
53656
- if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
53764
+ if (opts.cssRemoveProperty && atRule.name === "property") {
53765
+ if (opts.majorVersion === 4 && atRule.params.trim().startsWith("--tw-")) shouldInjectTailwindcssV4Defaults = true;
53766
+ atRule.remove();
53767
+ }
53657
53768
  /**
53658
53769
  * 清除空节点
53659
53770
  */