@weapp-tailwindcss/postcss 3.0.0-next.8 → 3.0.0

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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_html_transform = require("./html-transform-k7Y1Iv27.js");
2
+ const require_html_transform = require("./html-transform-Dgak7hXa.js");
3
3
  require("./types.js");
4
4
  let postcss = require("postcss");
5
5
  postcss = require_html_transform.__toESM(postcss);
@@ -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",
@@ -7031,6 +7321,9 @@ function normalizeSelector$1(selector) {
7031
7321
  function getRuleSelectors(rule) {
7032
7322
  return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
7033
7323
  }
7324
+ function getSortedRuleSelectorKey(rule) {
7325
+ return getRuleSelectors(rule).sort().join(",");
7326
+ }
7034
7327
  function isUnsupportedBrowserSelector(selector) {
7035
7328
  const normalized = normalizeSelector$1(selector);
7036
7329
  return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
@@ -7053,7 +7346,7 @@ const PREFLIGHT_RESET_PROPS = new Set([
7053
7346
  "padding"
7054
7347
  ]);
7055
7348
  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/;
7349
+ const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
7057
7350
  function hasTailwindPreflightDeclaration(rule) {
7058
7351
  let hasTailwindVar = false;
7059
7352
  let hasResetProp = false;
@@ -7099,7 +7392,7 @@ function isPseudoContentInitRule(rule) {
7099
7392
  function usesTwContentVariable(root) {
7100
7393
  let used = false;
7101
7394
  root.walkDecls((decl) => {
7102
- if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
7395
+ if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
7103
7396
  });
7104
7397
  return used;
7105
7398
  }
@@ -7182,6 +7475,7 @@ function removeUnsupportedModernColorDeclarations(root) {
7182
7475
  //#endregion
7183
7476
  //#region src/compat/mini-program-css/finalize.ts
7184
7477
  const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
7478
+ const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
7185
7479
  function createPseudoContentInitRule() {
7186
7480
  const rule = postcss.default.rule({ selector: "::before,\n::after" });
7187
7481
  rule.append({
@@ -7207,7 +7501,7 @@ function collectPreflightRules(root, options = {}) {
7207
7501
  }
7208
7502
  function createPreflightResetRule(cssPreflight) {
7209
7503
  if (!cssPreflight || typeof cssPreflight !== "object") return;
7210
- const rule = postcss.default.rule({ selector: "view,text,:after,:before" });
7504
+ const rule = postcss.default.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
7211
7505
  for (const [prop, value] of Object.entries(cssPreflight)) {
7212
7506
  if (value === false) continue;
7213
7507
  rule.append({
@@ -7236,6 +7530,18 @@ function collectThemeVariableRule(root, options = {}) {
7236
7530
  for (const decl of declarations.values()) rule.append(decl);
7237
7531
  return rule;
7238
7532
  }
7533
+ function hasTailwindcssV4Signal(css) {
7534
+ if (TAILWIND_V4_BANNER_RE.test(css)) return true;
7535
+ const root = postcss.default.parse(css);
7536
+ let hasProperty = false;
7537
+ root.walkAtRules("property", (atRule) => {
7538
+ if (atRule.params.trim().startsWith("--tw-")) {
7539
+ hasProperty = true;
7540
+ return false;
7541
+ }
7542
+ });
7543
+ return hasProperty;
7544
+ }
7239
7545
  function getTopDirectiveTail(root) {
7240
7546
  let tail;
7241
7547
  for (const node of root.nodes ?? []) {
@@ -7273,12 +7579,28 @@ function insertHoistedRules(root, rules, anchor) {
7273
7579
  if (topDirectiveTail) topDirectiveTail.after(rules);
7274
7580
  else root.prepend(rules);
7275
7581
  }
7582
+ function mergeEquivalentHoistedRules(rules) {
7583
+ const mergedRules = [];
7584
+ const ruleBySelector = /* @__PURE__ */ new Map();
7585
+ for (const rule of rules) {
7586
+ const key = getSortedRuleSelectorKey(rule);
7587
+ const existingRule = ruleBySelector.get(key);
7588
+ if (existingRule) {
7589
+ existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
7590
+ continue;
7591
+ }
7592
+ ruleBySelector.set(key, rule);
7593
+ mergedRules.push(rule);
7594
+ }
7595
+ return mergedRules;
7596
+ }
7276
7597
  function unwrapTailwindSourceMedia(root) {
7277
7598
  root.walkAtRules("media", (atRule) => {
7278
7599
  if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
7279
7600
  });
7280
7601
  }
7281
7602
  function finalizeMiniProgramCssRoot(root, options = {}) {
7603
+ const tailwindcssV4DefaultNodes = options.isTailwindcssV4 === true ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
7282
7604
  removeUnsupportedCascadeLayers(root);
7283
7605
  unwrapTailwindSourceMedia(root);
7284
7606
  root.walkAtRules("property", (atRule) => {
@@ -7300,8 +7622,12 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
7300
7622
  const resetRule = createPreflightResetRule(options.cssPreflight);
7301
7623
  if (resetRule) preflightRules.push(resetRule);
7302
7624
  }
7625
+ if (tailwindcssV4DefaultNodes.length > 0) preflightRules.push(postcss.default.rule({
7626
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7627
+ nodes: tailwindcssV4DefaultNodes
7628
+ }));
7303
7629
  const themeRule = collectThemeVariableRule(root, options);
7304
- insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
7630
+ insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
7305
7631
  }
7306
7632
  function hoistTailwindPreflightBase(css) {
7307
7633
  try {
@@ -7313,10 +7639,19 @@ function hoistTailwindPreflightBase(css) {
7313
7639
  }
7314
7640
  }
7315
7641
  function finalizeMiniProgramCss(css, options = {}) {
7642
+ let isTailwindcssV4 = options.isTailwindcssV4;
7643
+ if (isTailwindcssV4 === void 0) try {
7644
+ isTailwindcssV4 = hasTailwindcssV4Signal(css);
7645
+ } catch {
7646
+ isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(css);
7647
+ }
7316
7648
  const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
7317
7649
  try {
7318
7650
  const root = postcss.default.parse(cleanedCss);
7319
- finalizeMiniProgramCssRoot(root, options);
7651
+ finalizeMiniProgramCssRoot(root, {
7652
+ ...options,
7653
+ isTailwindcssV4
7654
+ });
7320
7655
  return root.toString();
7321
7656
  } catch {
7322
7657
  return cleanedCss;
@@ -7325,16 +7660,7 @@ function finalizeMiniProgramCss(css, options = {}) {
7325
7660
  //#endregion
7326
7661
  //#region src/compat/mini-program-css/prune-generated.ts
7327
7662
  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
7663
  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
7664
  function isConditionalCompilationComment(text) {
7339
7665
  return /#(?:ifn?def|endif)\b/.test(text);
7340
7666
  }
@@ -7348,7 +7674,7 @@ function removeEmptyContentInitDeclarations(rule) {
7348
7674
  }
7349
7675
  function isMiniProgramElementVariableScopeRule(rule) {
7350
7676
  const selectors = getRuleSelectors(rule);
7351
- return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS.has(selector));
7677
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
7352
7678
  }
7353
7679
  function isTailwindV4GradientRuntimeDeclaration(decl) {
7354
7680
  return decl.prop.startsWith("--tw-gradient-");
@@ -7362,7 +7688,7 @@ function moveTailwindV4GradientRuntimeDeclarations(rule) {
7362
7688
  }
7363
7689
  });
7364
7690
  if (gradientDeclarations.length > 0) rule.before(new postcss.default.Rule({
7365
- selector: DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE,
7691
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7366
7692
  nodes: gradientDeclarations
7367
7693
  }));
7368
7694
  if (rule.nodes.length === 0) rule.remove();
@@ -7399,7 +7725,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
7399
7725
  root.walkRules((rule) => {
7400
7726
  if (isKeyframesRule(rule)) return;
7401
7727
  if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
7402
- rule.selector = DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE;
7728
+ rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
7403
7729
  return;
7404
7730
  }
7405
7731
  if (isMiniProgramThemeVariableRule(rule)) {
@@ -52483,245 +52809,6 @@ function normalizeTailwindcssRpxDeclaration(decl, options) {
52483
52809
  return false;
52484
52810
  }
52485
52811
  //#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
52812
  //#region src/constants.ts
52726
52813
  const postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
52727
52814
  //#endregion
@@ -53605,12 +53692,21 @@ function removeLegacyFlexboxPrefix(decl) {
53605
53692
  }
53606
53693
  if (LEGACY_FLEXBOX_DECLARATION_PROPS.has(decl.prop)) decl.remove();
53607
53694
  }
53695
+ function injectMissingTailwindcssV4Defaults(root) {
53696
+ const nodes = createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root));
53697
+ if (nodes.length === 0) return;
53698
+ root.append({
53699
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
53700
+ nodes
53701
+ });
53702
+ }
53608
53703
  const postcssWeappTailwindcssPostPlugin = (options) => {
53609
53704
  const opts = (0, _weapp_tailwindcss_shared.defu)(options, { isMainChunk: true });
53610
53705
  const p = { postcssPlugin };
53611
53706
  const cleanRootSpecificity = createRootSpecificityCleaner(opts);
53612
53707
  const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
53613
53708
  const shouldAppendHostSelector = createHostSelectorAppender(opts);
53709
+ let shouldInjectTailwindcssV4Defaults = false;
53614
53710
  const enableMainChunkTransforms = opts.isMainChunk !== false;
53615
53711
  if (enableMainChunkTransforms || cleanRootSpecificity) {
53616
53712
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
@@ -53647,13 +53743,17 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
53647
53743
  root.walkAtRules((atRule) => {
53648
53744
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53649
53745
  });
53746
+ if (shouldInjectTailwindcssV4Defaults) injectMissingTailwindcssV4Defaults(root);
53650
53747
  };
53651
53748
  p.AtRuleExit = (atRule) => {
53652
53749
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53653
53750
  /**
53654
53751
  * @description 移除 property
53655
53752
  */
53656
- if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
53753
+ if (opts.cssRemoveProperty && atRule.name === "property") {
53754
+ if (opts.majorVersion === 4 && atRule.params.trim().startsWith("--tw-")) shouldInjectTailwindcssV4Defaults = true;
53755
+ atRule.remove();
53756
+ }
53657
53757
  /**
53658
53758
  * 清除空节点
53659
53759
  */