@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.mjs CHANGED
@@ -6941,20 +6941,309 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
6941
6941
  if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
6942
6942
  }
6943
6943
  //#endregion
6944
- //#region src/compat/mini-program-css/color-gamut.ts
6944
+ //#region src/cssVarsV4.ts
6945
+ function property(ident, initialValue, _syntax) {
6946
+ return {
6947
+ prop: ident,
6948
+ value: initialValue || ""
6949
+ };
6950
+ }
6951
+ const nullShadow = "0 0 #0000";
6952
+ const nodes = [
6953
+ property("--tw-border-spacing-x", "0", "<length>"),
6954
+ property("--tw-border-spacing-y", "0", "<length>"),
6955
+ property("--tw-translate-x", "0"),
6956
+ property("--tw-translate-y", "0"),
6957
+ property("--tw-translate-z", "0"),
6958
+ property("--tw-scale-x", "1"),
6959
+ property("--tw-scale-y", "1"),
6960
+ property("--tw-scale-z", "1"),
6961
+ property("--tw-rotate-x"),
6962
+ property("--tw-rotate-y"),
6963
+ property("--tw-rotate-z"),
6964
+ property("--tw-skew-x"),
6965
+ property("--tw-skew-y"),
6966
+ property("--tw-pan-x"),
6967
+ property("--tw-pan-y"),
6968
+ property("--tw-pinch-zoom"),
6969
+ property("--tw-scroll-snap-strictness", "proximity", "*"),
6970
+ property("--tw-space-x-reverse", "0"),
6971
+ property("--tw-space-y-reverse", "0"),
6972
+ property("--tw-scrollbar-thumb", "#0000", "<color>"),
6973
+ property("--tw-scrollbar-track", "#0000", "<color>"),
6974
+ property("--tw-border-style", "solid"),
6975
+ property("--tw-divide-x-reverse", "0"),
6976
+ property("--tw-divide-y-reverse", "0"),
6977
+ property("--tw-gradient-position", "initial"),
6978
+ property("--tw-gradient-from", "#0000", "<color>"),
6979
+ property("--tw-gradient-via", "#0000", "<color>"),
6980
+ property("--tw-gradient-to", "#0000", "<color>"),
6981
+ property("--tw-gradient-stops", "initial"),
6982
+ property("--tw-gradient-via-stops", "initial"),
6983
+ property("--tw-gradient-from-position", "0%", "<length-percentage>"),
6984
+ property("--tw-gradient-via-position", "50%", "<length-percentage>"),
6985
+ property("--tw-gradient-to-position", "100%", "<length-percentage>"),
6986
+ property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
6987
+ property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
6988
+ property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
6989
+ property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
6990
+ property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
6991
+ property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
6992
+ property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
6993
+ property("--tw-mask-linear-position", "0deg"),
6994
+ property("--tw-mask-linear-from-position", "0%"),
6995
+ property("--tw-mask-linear-to-position", "100%"),
6996
+ property("--tw-mask-linear-from-color", "black"),
6997
+ property("--tw-mask-linear-to-color", "transparent"),
6998
+ property("--tw-mask-radial-from-position", "0%"),
6999
+ property("--tw-mask-radial-to-position", "100%"),
7000
+ property("--tw-mask-radial-from-color", "black"),
7001
+ property("--tw-mask-radial-to-color", "transparent"),
7002
+ property("--tw-mask-radial-shape", "ellipse"),
7003
+ property("--tw-mask-radial-size", "farthest-corner"),
7004
+ property("--tw-mask-radial-position", "center"),
7005
+ property("--tw-mask-conic-position", "0deg"),
7006
+ property("--tw-mask-conic-from-position", "0%"),
7007
+ property("--tw-mask-conic-to-position", "100%"),
7008
+ property("--tw-mask-conic-from-color", "black"),
7009
+ property("--tw-mask-conic-to-color", "transparent"),
7010
+ property("--tw-font-weight"),
7011
+ property("--tw-blur"),
7012
+ property("--tw-brightness"),
7013
+ property("--tw-contrast"),
7014
+ property("--tw-grayscale"),
7015
+ property("--tw-hue-rotate"),
7016
+ property("--tw-invert"),
7017
+ property("--tw-opacity"),
7018
+ property("--tw-saturate"),
7019
+ property("--tw-sepia"),
7020
+ property("--tw-drop-shadow"),
7021
+ property("--tw-drop-shadow-color"),
7022
+ property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
7023
+ property("--tw-drop-shadow-size"),
7024
+ property("--tw-backdrop-blur"),
7025
+ property("--tw-backdrop-brightness"),
7026
+ property("--tw-backdrop-contrast"),
7027
+ property("--tw-backdrop-grayscale"),
7028
+ property("--tw-backdrop-hue-rotate"),
7029
+ property("--tw-backdrop-invert"),
7030
+ property("--tw-backdrop-opacity"),
7031
+ property("--tw-backdrop-saturate"),
7032
+ property("--tw-backdrop-sepia"),
7033
+ property("--tw-duration", "initial"),
7034
+ property("--tw-ease", "initial"),
7035
+ property("--tw-content", "\"\""),
7036
+ property("--tw-contain-size"),
7037
+ property("--tw-contain-layout"),
7038
+ property("--tw-contain-paint"),
7039
+ property("--tw-contain-style"),
7040
+ property("--tw-leading"),
7041
+ property("--tw-tracking"),
7042
+ property("--tw-ordinal"),
7043
+ property("--tw-slashed-zero"),
7044
+ property("--tw-numeric-figure"),
7045
+ property("--tw-numeric-spacing"),
7046
+ property("--tw-numeric-fraction"),
7047
+ property("--tw-outline-style", "solid"),
7048
+ property("--tw-text-shadow-color", "initial"),
7049
+ property("--tw-text-shadow-alpha", "100%", "<percentage>"),
7050
+ property("--tw-shadow", nullShadow),
7051
+ property("--tw-shadow-color", "initial"),
7052
+ property("--tw-shadow-alpha", "100%", "<percentage>"),
7053
+ property("--tw-inset-shadow", nullShadow),
7054
+ property("--tw-inset-shadow-color", "initial"),
7055
+ property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
7056
+ property("--tw-ring-color"),
7057
+ property("--tw-ring-shadow", nullShadow),
7058
+ property("--tw-inset-ring-color"),
7059
+ property("--tw-inset-ring-shadow", nullShadow),
7060
+ property("--tw-ring-inset"),
7061
+ property("--tw-ring-offset-width", "0px", "<length>"),
7062
+ property("--tw-ring-offset-color", "#fff"),
7063
+ property("--tw-ring-offset-shadow", nullShadow)
7064
+ ];
7065
+ for (const edge of [
7066
+ "top",
7067
+ "right",
7068
+ "bottom",
7069
+ "left"
7070
+ ]) 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"));
7071
+ //#endregion
7072
+ //#region src/utils/css-vars.ts
7073
+ /**
7074
+ * 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
7075
+ */
7076
+ function createCssVarNodes(definitions) {
7077
+ return definitions.map((def) => new Declaration({
7078
+ prop: def.prop,
7079
+ value: def.value
7080
+ }));
7081
+ }
7082
+ //#endregion
7083
+ //#region src/compat/tailwindcss-v4.ts
7084
+ const OKLAB_SUFFIX = "in oklab";
7085
+ const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
7086
+ const RADIUS_THRESHOLD = 1e5;
7087
+ const CLAMP_PX = 9999;
7088
+ const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
7089
+ const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
7090
+ const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
7091
+ const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
7092
+ const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
7093
+ const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
6945
7094
  const DISPLAY_P3_VALUE_RE$1 = /color\(\s*display-p3\b/i;
6946
7095
  const COLOR_GAMUT_P3_RE$1 = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
6947
- function isDisplayP3MediaRule(atRule) {
7096
+ const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
7097
+ const SCIENTIFIC_NOTATION_RE = /e/i;
7098
+ const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
7099
+ const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
7100
+ const DEFAULT_VARIABLE_SCOPE_SELECTORS = new Set([
7101
+ "*",
7102
+ ":root",
7103
+ ":host",
7104
+ "page",
7105
+ ".tw-root",
7106
+ "wx-root-portal-content",
7107
+ "view",
7108
+ "text",
7109
+ ":before",
7110
+ ":after",
7111
+ "::before",
7112
+ "::after",
7113
+ "::backdrop"
7114
+ ]);
7115
+ function isTailwindcssV4(options) {
7116
+ return options?.majorVersion === 4;
7117
+ }
7118
+ function testIfRootHostForV4(node) {
7119
+ return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
7120
+ }
7121
+ createCssVarNodes(nodes);
7122
+ function collectUsedTailwindcssV4Variables(root) {
7123
+ const props = /* @__PURE__ */ new Set();
7124
+ root.walkDecls((decl) => {
7125
+ if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
7126
+ TW_VAR_FUNCTION_RE.lastIndex = 0;
7127
+ let match = TW_VAR_FUNCTION_RE.exec(decl.value);
7128
+ while (match !== null) {
7129
+ const prop = match[1];
7130
+ if (prop) props.add(prop);
7131
+ match = TW_VAR_FUNCTION_RE.exec(decl.value);
7132
+ }
7133
+ });
7134
+ root.walkAtRules("property", (atRule) => {
7135
+ const prop = atRule.params.trim();
7136
+ if (prop.startsWith("--tw-")) props.add(prop);
7137
+ });
7138
+ return props;
7139
+ }
7140
+ function usesTailwindcssV4ContentVariable(root) {
7141
+ let used = false;
7142
+ root.walkDecls((decl) => {
7143
+ if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
7144
+ });
7145
+ return used;
7146
+ }
7147
+ function createUsedCssVarsV4Nodes(usedProps) {
7148
+ return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new Declaration({
7149
+ prop: def.prop,
7150
+ value: def.value
7151
+ }));
7152
+ }
7153
+ function isInsideAtRule(decl, name) {
7154
+ let parent = decl.parent;
7155
+ while (parent) {
7156
+ if (parent.type === "atrule" && parent.name === name) return true;
7157
+ parent = parent.parent;
7158
+ }
7159
+ return false;
7160
+ }
7161
+ function isDefaultVariableScopeRule(rule) {
7162
+ if (!rule.selectors.every((selector) => DEFAULT_VARIABLE_SCOPE_SELECTORS.has(selector.trim()))) return false;
7163
+ let hasDeclaration = false;
7164
+ let onlyCustomProperties = true;
7165
+ rule.each((node) => {
7166
+ if (node.type !== "decl") return;
7167
+ hasDeclaration = true;
7168
+ if (!node.prop.startsWith("--")) onlyCustomProperties = false;
7169
+ });
7170
+ return hasDeclaration && onlyCustomProperties;
7171
+ }
7172
+ function collectScopedTailwindcssV4DefaultVariables(root) {
7173
+ const props = /* @__PURE__ */ new Set();
7174
+ root.walkDecls((decl) => {
7175
+ if (!decl.prop.startsWith("--tw-")) return;
7176
+ if (isInsideAtRule(decl, "supports")) return;
7177
+ if (decl.parent?.type === "rule" && isDefaultVariableScopeRule(decl.parent)) props.add(decl.prop);
7178
+ });
7179
+ return props;
7180
+ }
7181
+ function createMissingCssVarsV4Nodes(root, usedProps) {
7182
+ const scopedProps = collectScopedTailwindcssV4DefaultVariables(root);
7183
+ return nodes.filter((def) => usedProps.has(def.prop) && !scopedProps.has(def.prop)).map((def) => new Declaration({
7184
+ prop: def.prop,
7185
+ value: def.value
7186
+ }));
7187
+ }
7188
+ function isTailwindcssV4ModernCheck(atRule) {
7189
+ return atRule.name === "supports" && [
7190
+ MODERN_CHECK_WEBKIT_HYPHENS_RE,
7191
+ MODERN_CHECK_MARGIN_TRIM_RE,
7192
+ MODERN_CHECK_MOZ_ORIENT_RE,
7193
+ MODERN_CHECK_COLOR_RGB_RE
7194
+ ].every((regex) => regex.test(atRule.params));
7195
+ }
7196
+ function isTailwindcssV4LinearGradientSupports(atRule) {
7197
+ return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
7198
+ }
7199
+ function isTailwindcssV4DisplayP3Supports(atRule) {
7200
+ return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
7201
+ }
7202
+ function isTailwindcssV4DisplayP3Media(atRule) {
6948
7203
  return atRule.name === "media" && COLOR_GAMUT_P3_RE$1.test(atRule.params);
6949
7204
  }
6950
- function isDisplayP3Declaration(decl) {
7205
+ function isTailwindcssV4DisplayP3Declaration(decl) {
6951
7206
  return DISPLAY_P3_VALUE_RE$1.test(decl.value);
6952
7207
  }
7208
+ function normalizeTailwindcssV4Declaration(decl) {
7209
+ if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
7210
+ decl.value = decl.value.slice(0, decl.value.length - 8);
7211
+ return true;
7212
+ }
7213
+ if (INFINITY_CALC_REGEXP.test(decl.value)) {
7214
+ decl.value = `${CLAMP_PX}px`;
7215
+ return true;
7216
+ }
7217
+ if (decl.prop.includes("radius")) {
7218
+ RADIUS_VALUE_RE.lastIndex = 0;
7219
+ const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
7220
+ const n = Number(num);
7221
+ if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
7222
+ if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
7223
+ return m;
7224
+ });
7225
+ if (next !== decl.value) {
7226
+ decl.value = next;
7227
+ return true;
7228
+ }
7229
+ }
7230
+ return false;
7231
+ }
7232
+ //#endregion
7233
+ //#region src/compat/mini-program-css/color-gamut.ts
7234
+ const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
7235
+ const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
7236
+ function isDisplayP3MediaRule(atRule) {
7237
+ return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
7238
+ }
7239
+ function isDisplayP3Declaration(decl) {
7240
+ return DISPLAY_P3_VALUE_RE.test(decl.value);
7241
+ }
6953
7242
  //#endregion
6954
7243
  //#region src/compat/mini-program-css/selectors.ts
6955
7244
  const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
6956
- const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
6957
- "*",
7245
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,:after,:before";
7246
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = new Set([
6958
7247
  "view",
6959
7248
  "text",
6960
7249
  ":before",
@@ -6962,6 +7251,7 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
6962
7251
  "::before",
6963
7252
  "::after"
6964
7253
  ]);
7254
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
6965
7255
  const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
6966
7256
  ":host",
6967
7257
  ":root",
@@ -7043,6 +7333,9 @@ function normalizeSelector$1(selector) {
7043
7333
  function getRuleSelectors(rule) {
7044
7334
  return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
7045
7335
  }
7336
+ function getSortedRuleSelectorKey(rule) {
7337
+ return getRuleSelectors(rule).sort().join(",");
7338
+ }
7046
7339
  function isUnsupportedBrowserSelector(selector) {
7047
7340
  const normalized = normalizeSelector$1(selector);
7048
7341
  return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
@@ -7065,7 +7358,7 @@ const PREFLIGHT_RESET_PROPS = new Set([
7065
7358
  "padding"
7066
7359
  ]);
7067
7360
  const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
7068
- const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
7361
+ const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
7069
7362
  function hasTailwindPreflightDeclaration(rule) {
7070
7363
  let hasTailwindVar = false;
7071
7364
  let hasResetProp = false;
@@ -7111,7 +7404,7 @@ function isPseudoContentInitRule(rule) {
7111
7404
  function usesTwContentVariable(root) {
7112
7405
  let used = false;
7113
7406
  root.walkDecls((decl) => {
7114
- if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
7407
+ if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
7115
7408
  });
7116
7409
  return used;
7117
7410
  }
@@ -7194,6 +7487,7 @@ function removeUnsupportedModernColorDeclarations(root) {
7194
7487
  //#endregion
7195
7488
  //#region src/compat/mini-program-css/finalize.ts
7196
7489
  const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
7490
+ const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
7197
7491
  function createPseudoContentInitRule() {
7198
7492
  const rule = postcss.rule({ selector: "::before,\n::after" });
7199
7493
  rule.append({
@@ -7219,7 +7513,7 @@ function collectPreflightRules(root, options = {}) {
7219
7513
  }
7220
7514
  function createPreflightResetRule(cssPreflight) {
7221
7515
  if (!cssPreflight || typeof cssPreflight !== "object") return;
7222
- const rule = postcss.rule({ selector: "view,text,:after,:before" });
7516
+ const rule = postcss.rule({ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR });
7223
7517
  for (const [prop, value] of Object.entries(cssPreflight)) {
7224
7518
  if (value === false) continue;
7225
7519
  rule.append({
@@ -7248,6 +7542,18 @@ function collectThemeVariableRule(root, options = {}) {
7248
7542
  for (const decl of declarations.values()) rule.append(decl);
7249
7543
  return rule;
7250
7544
  }
7545
+ function hasTailwindcssV4Signal(css) {
7546
+ if (TAILWIND_V4_BANNER_RE.test(css)) return true;
7547
+ const root = postcss.parse(css);
7548
+ let hasProperty = false;
7549
+ root.walkAtRules("property", (atRule) => {
7550
+ if (atRule.params.trim().startsWith("--tw-")) {
7551
+ hasProperty = true;
7552
+ return false;
7553
+ }
7554
+ });
7555
+ return hasProperty;
7556
+ }
7251
7557
  function getTopDirectiveTail(root) {
7252
7558
  let tail;
7253
7559
  for (const node of root.nodes ?? []) {
@@ -7285,12 +7591,28 @@ function insertHoistedRules(root, rules, anchor) {
7285
7591
  if (topDirectiveTail) topDirectiveTail.after(rules);
7286
7592
  else root.prepend(rules);
7287
7593
  }
7594
+ function mergeEquivalentHoistedRules(rules) {
7595
+ const mergedRules = [];
7596
+ const ruleBySelector = /* @__PURE__ */ new Map();
7597
+ for (const rule of rules) {
7598
+ const key = getSortedRuleSelectorKey(rule);
7599
+ const existingRule = ruleBySelector.get(key);
7600
+ if (existingRule) {
7601
+ existingRule.append(...(rule.nodes ?? []).map((node) => node.clone()));
7602
+ continue;
7603
+ }
7604
+ ruleBySelector.set(key, rule);
7605
+ mergedRules.push(rule);
7606
+ }
7607
+ return mergedRules;
7608
+ }
7288
7609
  function unwrapTailwindSourceMedia(root) {
7289
7610
  root.walkAtRules("media", (atRule) => {
7290
7611
  if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
7291
7612
  });
7292
7613
  }
7293
7614
  function finalizeMiniProgramCssRoot(root, options = {}) {
7615
+ const tailwindcssV4DefaultNodes = options.isTailwindcssV4 === true ? createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root)) : [];
7294
7616
  removeUnsupportedCascadeLayers(root);
7295
7617
  unwrapTailwindSourceMedia(root);
7296
7618
  root.walkAtRules("property", (atRule) => {
@@ -7312,8 +7634,12 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
7312
7634
  const resetRule = createPreflightResetRule(options.cssPreflight);
7313
7635
  if (resetRule) preflightRules.push(resetRule);
7314
7636
  }
7637
+ if (tailwindcssV4DefaultNodes.length > 0) preflightRules.push(postcss.rule({
7638
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7639
+ nodes: tailwindcssV4DefaultNodes
7640
+ }));
7315
7641
  const themeRule = collectThemeVariableRule(root, options);
7316
- insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
7642
+ insertHoistedRules(root, mergeEquivalentHoistedRules(themeRule ? [...preflightRules, themeRule] : preflightRules), hoistAnchor);
7317
7643
  }
7318
7644
  function hoistTailwindPreflightBase(css) {
7319
7645
  try {
@@ -7325,10 +7651,19 @@ function hoistTailwindPreflightBase(css) {
7325
7651
  }
7326
7652
  }
7327
7653
  function finalizeMiniProgramCss(css, options = {}) {
7654
+ let isTailwindcssV4 = options.isTailwindcssV4;
7655
+ if (isTailwindcssV4 === void 0) try {
7656
+ isTailwindcssV4 = hasTailwindcssV4Signal(css);
7657
+ } catch {
7658
+ isTailwindcssV4 = TAILWIND_V4_BANNER_RE.test(css);
7659
+ }
7328
7660
  const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
7329
7661
  try {
7330
7662
  const root = postcss.parse(cleanedCss);
7331
- finalizeMiniProgramCssRoot(root, options);
7663
+ finalizeMiniProgramCssRoot(root, {
7664
+ ...options,
7665
+ isTailwindcssV4
7666
+ });
7332
7667
  return root.toString();
7333
7668
  } catch {
7334
7669
  return cleanedCss;
@@ -7337,16 +7672,7 @@ function finalizeMiniProgramCss(css, options = {}) {
7337
7672
  //#endregion
7338
7673
  //#region src/compat/mini-program-css/prune-generated.ts
7339
7674
  const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
7340
- const DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE = "view,text,:before,:after";
7341
7675
  const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
7342
- const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
7343
- "view",
7344
- "text",
7345
- ":before",
7346
- ":after",
7347
- "::before",
7348
- "::after"
7349
- ]);
7350
7676
  function isConditionalCompilationComment(text) {
7351
7677
  return /#(?:ifn?def|endif)\b/.test(text);
7352
7678
  }
@@ -7360,7 +7686,7 @@ function removeEmptyContentInitDeclarations(rule) {
7360
7686
  }
7361
7687
  function isMiniProgramElementVariableScopeRule(rule) {
7362
7688
  const selectors = getRuleSelectors(rule);
7363
- return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS.has(selector));
7689
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS.has(selector));
7364
7690
  }
7365
7691
  function isTailwindV4GradientRuntimeDeclaration(decl) {
7366
7692
  return decl.prop.startsWith("--tw-gradient-");
@@ -7374,7 +7700,7 @@ function moveTailwindV4GradientRuntimeDeclarations(rule) {
7374
7700
  }
7375
7701
  });
7376
7702
  if (gradientDeclarations.length > 0) rule.before(new postcss.Rule({
7377
- selector: DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE,
7703
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
7378
7704
  nodes: gradientDeclarations
7379
7705
  }));
7380
7706
  if (rule.nodes.length === 0) rule.remove();
@@ -7411,7 +7737,7 @@ function pruneMiniProgramGeneratedCss(css, options = {}) {
7411
7737
  root.walkRules((rule) => {
7412
7738
  if (isKeyframesRule(rule)) return;
7413
7739
  if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
7414
- rule.selector = DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE;
7740
+ rule.selector = MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR;
7415
7741
  return;
7416
7742
  }
7417
7743
  if (isMiniProgramThemeVariableRule(rule)) {
@@ -52477,245 +52803,6 @@ function normalizeTailwindcssRpxDeclaration(decl, options) {
52477
52803
  return false;
52478
52804
  }
52479
52805
  //#endregion
52480
- //#region src/cssVarsV4.ts
52481
- function property(ident, initialValue, _syntax) {
52482
- return {
52483
- prop: ident,
52484
- value: initialValue || ""
52485
- };
52486
- }
52487
- const nullShadow = "0 0 #0000";
52488
- const nodes = [
52489
- property("--tw-border-spacing-x", "0", "<length>"),
52490
- property("--tw-border-spacing-y", "0", "<length>"),
52491
- property("--tw-translate-x", "0"),
52492
- property("--tw-translate-y", "0"),
52493
- property("--tw-translate-z", "0"),
52494
- property("--tw-scale-x", "1"),
52495
- property("--tw-scale-y", "1"),
52496
- property("--tw-scale-z", "1"),
52497
- property("--tw-rotate-x"),
52498
- property("--tw-rotate-y"),
52499
- property("--tw-rotate-z"),
52500
- property("--tw-skew-x"),
52501
- property("--tw-skew-y"),
52502
- property("--tw-pan-x"),
52503
- property("--tw-pan-y"),
52504
- property("--tw-pinch-zoom"),
52505
- property("--tw-scroll-snap-strictness", "proximity", "*"),
52506
- property("--tw-space-x-reverse", "0"),
52507
- property("--tw-space-y-reverse", "0"),
52508
- property("--tw-scrollbar-thumb", "#0000", "<color>"),
52509
- property("--tw-scrollbar-track", "#0000", "<color>"),
52510
- property("--tw-border-style", "solid"),
52511
- property("--tw-divide-x-reverse", "0"),
52512
- property("--tw-divide-y-reverse", "0"),
52513
- property("--tw-gradient-position", "initial"),
52514
- property("--tw-gradient-from", "#0000", "<color>"),
52515
- property("--tw-gradient-via", "#0000", "<color>"),
52516
- property("--tw-gradient-to", "#0000", "<color>"),
52517
- property("--tw-gradient-stops", "initial"),
52518
- property("--tw-gradient-via-stops", "initial"),
52519
- property("--tw-gradient-from-position", "0%", "<length-percentage>"),
52520
- property("--tw-gradient-via-position", "50%", "<length-percentage>"),
52521
- property("--tw-gradient-to-position", "100%", "<length-percentage>"),
52522
- property("--tw-mask-linear", "linear-gradient(#fff, #fff)"),
52523
- property("--tw-mask-radial", "linear-gradient(#fff, #fff)"),
52524
- property("--tw-mask-conic", "linear-gradient(#fff, #fff)"),
52525
- property("--tw-mask-left", "linear-gradient(#fff, #fff)"),
52526
- property("--tw-mask-right", "linear-gradient(#fff, #fff)"),
52527
- property("--tw-mask-bottom", "linear-gradient(#fff, #fff)"),
52528
- property("--tw-mask-top", "linear-gradient(#fff, #fff)"),
52529
- property("--tw-mask-linear-position", "0deg"),
52530
- property("--tw-mask-linear-from-position", "0%"),
52531
- property("--tw-mask-linear-to-position", "100%"),
52532
- property("--tw-mask-linear-from-color", "black"),
52533
- property("--tw-mask-linear-to-color", "transparent"),
52534
- property("--tw-mask-radial-from-position", "0%"),
52535
- property("--tw-mask-radial-to-position", "100%"),
52536
- property("--tw-mask-radial-from-color", "black"),
52537
- property("--tw-mask-radial-to-color", "transparent"),
52538
- property("--tw-mask-radial-shape", "ellipse"),
52539
- property("--tw-mask-radial-size", "farthest-corner"),
52540
- property("--tw-mask-radial-position", "center"),
52541
- property("--tw-mask-conic-position", "0deg"),
52542
- property("--tw-mask-conic-from-position", "0%"),
52543
- property("--tw-mask-conic-to-position", "100%"),
52544
- property("--tw-mask-conic-from-color", "black"),
52545
- property("--tw-mask-conic-to-color", "transparent"),
52546
- property("--tw-font-weight"),
52547
- property("--tw-blur"),
52548
- property("--tw-brightness"),
52549
- property("--tw-contrast"),
52550
- property("--tw-grayscale"),
52551
- property("--tw-hue-rotate"),
52552
- property("--tw-invert"),
52553
- property("--tw-opacity"),
52554
- property("--tw-saturate"),
52555
- property("--tw-sepia"),
52556
- property("--tw-drop-shadow"),
52557
- property("--tw-drop-shadow-color"),
52558
- property("--tw-drop-shadow-alpha", "100%", "<percentage>"),
52559
- property("--tw-drop-shadow-size"),
52560
- property("--tw-backdrop-blur"),
52561
- property("--tw-backdrop-brightness"),
52562
- property("--tw-backdrop-contrast"),
52563
- property("--tw-backdrop-grayscale"),
52564
- property("--tw-backdrop-hue-rotate"),
52565
- property("--tw-backdrop-invert"),
52566
- property("--tw-backdrop-opacity"),
52567
- property("--tw-backdrop-saturate"),
52568
- property("--tw-backdrop-sepia"),
52569
- property("--tw-duration", "initial"),
52570
- property("--tw-ease", "initial"),
52571
- property("--tw-content", "\"\""),
52572
- property("--tw-contain-size"),
52573
- property("--tw-contain-layout"),
52574
- property("--tw-contain-paint"),
52575
- property("--tw-contain-style"),
52576
- property("--tw-leading"),
52577
- property("--tw-tracking"),
52578
- property("--tw-ordinal"),
52579
- property("--tw-slashed-zero"),
52580
- property("--tw-numeric-figure"),
52581
- property("--tw-numeric-spacing"),
52582
- property("--tw-numeric-fraction"),
52583
- property("--tw-outline-style", "solid"),
52584
- property("--tw-text-shadow-color", "initial"),
52585
- property("--tw-text-shadow-alpha", "100%", "<percentage>"),
52586
- property("--tw-shadow", nullShadow),
52587
- property("--tw-shadow-color", "initial"),
52588
- property("--tw-shadow-alpha", "100%", "<percentage>"),
52589
- property("--tw-inset-shadow", nullShadow),
52590
- property("--tw-inset-shadow-color", "initial"),
52591
- property("--tw-inset-shadow-alpha", "100%", "<percentage>"),
52592
- property("--tw-ring-color"),
52593
- property("--tw-ring-shadow", nullShadow),
52594
- property("--tw-inset-ring-color"),
52595
- property("--tw-inset-ring-shadow", nullShadow),
52596
- property("--tw-ring-inset"),
52597
- property("--tw-ring-offset-width", "0px", "<length>"),
52598
- property("--tw-ring-offset-color", "#fff"),
52599
- property("--tw-ring-offset-shadow", nullShadow)
52600
- ];
52601
- for (const edge of [
52602
- "top",
52603
- "right",
52604
- "bottom",
52605
- "left"
52606
- ]) 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"));
52607
- //#endregion
52608
- //#region src/utils/css-vars.ts
52609
- /**
52610
- * 将 CSS 变量定义转换为可直接插入的 Declaration 节点列表。
52611
- */
52612
- function createCssVarNodes(definitions) {
52613
- return definitions.map((def) => new Declaration({
52614
- prop: def.prop,
52615
- value: def.value
52616
- }));
52617
- }
52618
- //#endregion
52619
- //#region src/compat/tailwindcss-v4.ts
52620
- const OKLAB_SUFFIX = "in oklab";
52621
- const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
52622
- const RADIUS_THRESHOLD = 1e5;
52623
- const CLAMP_PX = 9999;
52624
- const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
52625
- const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
52626
- const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
52627
- const MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)/;
52628
- const LINEAR_GRADIENT_LAB_RE = /background-image\s*:\s*linear-gradient\(\s*in\s+lab\s*,\s*red\s*,\s*red\s*\)/;
52629
- const DISPLAY_P3_COLOR_RE = /color\s*:\s*color\(\s*display-p3\s+0\s+0\s+0%\s*\)/;
52630
- const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
52631
- const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
52632
- const RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
52633
- const SCIENTIFIC_NOTATION_RE = /e/i;
52634
- const TW_VAR_FUNCTION_RE = /var\(\s*(--tw-[\w-]+)\b/g;
52635
- const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
52636
- function isTailwindcssV4(options) {
52637
- return options?.majorVersion === 4;
52638
- }
52639
- function testIfRootHostForV4(node) {
52640
- return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
52641
- }
52642
- createCssVarNodes(nodes);
52643
- function collectUsedTailwindcssV4Variables(root) {
52644
- const props = /* @__PURE__ */ new Set();
52645
- root.walkDecls((decl) => {
52646
- if (decl.prop.startsWith("--tw-")) props.add(decl.prop);
52647
- TW_VAR_FUNCTION_RE.lastIndex = 0;
52648
- let match = TW_VAR_FUNCTION_RE.exec(decl.value);
52649
- while (match !== null) {
52650
- const prop = match[1];
52651
- if (prop) props.add(prop);
52652
- match = TW_VAR_FUNCTION_RE.exec(decl.value);
52653
- }
52654
- });
52655
- root.walkAtRules("property", (atRule) => {
52656
- const prop = atRule.params.trim();
52657
- if (prop.startsWith("--tw-")) props.add(prop);
52658
- });
52659
- return props;
52660
- }
52661
- function usesTailwindcssV4ContentVariable(root) {
52662
- let used = false;
52663
- root.walkDecls((decl) => {
52664
- if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
52665
- });
52666
- return used;
52667
- }
52668
- function createUsedCssVarsV4Nodes(usedProps) {
52669
- return nodes.filter((def) => usedProps.has(def.prop)).map((def) => new Declaration({
52670
- prop: def.prop,
52671
- value: def.value
52672
- }));
52673
- }
52674
- function isTailwindcssV4ModernCheck(atRule) {
52675
- return atRule.name === "supports" && [
52676
- MODERN_CHECK_WEBKIT_HYPHENS_RE,
52677
- MODERN_CHECK_MARGIN_TRIM_RE,
52678
- MODERN_CHECK_MOZ_ORIENT_RE,
52679
- MODERN_CHECK_COLOR_RGB_RE
52680
- ].every((regex) => regex.test(atRule.params));
52681
- }
52682
- function isTailwindcssV4LinearGradientSupports(atRule) {
52683
- return atRule.name === "supports" && LINEAR_GRADIENT_LAB_RE.test(atRule.params);
52684
- }
52685
- function isTailwindcssV4DisplayP3Supports(atRule) {
52686
- return atRule.name === "supports" && DISPLAY_P3_COLOR_RE.test(atRule.params);
52687
- }
52688
- function isTailwindcssV4DisplayP3Media(atRule) {
52689
- return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
52690
- }
52691
- function isTailwindcssV4DisplayP3Declaration(decl) {
52692
- return DISPLAY_P3_VALUE_RE.test(decl.value);
52693
- }
52694
- function normalizeTailwindcssV4Declaration(decl) {
52695
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
52696
- decl.value = decl.value.slice(0, decl.value.length - 8);
52697
- return true;
52698
- }
52699
- if (INFINITY_CALC_REGEXP.test(decl.value)) {
52700
- decl.value = `${CLAMP_PX}px`;
52701
- return true;
52702
- }
52703
- if (decl.prop.includes("radius")) {
52704
- RADIUS_VALUE_RE.lastIndex = 0;
52705
- const next = decl.value.replace(RADIUS_VALUE_RE, (m, num) => {
52706
- const n = Number(num);
52707
- if (!Number.isFinite(n)) return `${CLAMP_PX}px`;
52708
- if (SCIENTIFIC_NOTATION_RE.test(String(num)) || n > RADIUS_THRESHOLD) return `${CLAMP_PX}px`;
52709
- return m;
52710
- });
52711
- if (next !== decl.value) {
52712
- decl.value = next;
52713
- return true;
52714
- }
52715
- }
52716
- return false;
52717
- }
52718
- //#endregion
52719
52806
  //#region src/constants.ts
52720
52807
  const postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
52721
52808
  //#endregion
@@ -53599,12 +53686,21 @@ function removeLegacyFlexboxPrefix(decl) {
53599
53686
  }
53600
53687
  if (LEGACY_FLEXBOX_DECLARATION_PROPS.has(decl.prop)) decl.remove();
53601
53688
  }
53689
+ function injectMissingTailwindcssV4Defaults(root) {
53690
+ const nodes = createMissingCssVarsV4Nodes(root, collectUsedTailwindcssV4Variables(root));
53691
+ if (nodes.length === 0) return;
53692
+ root.append({
53693
+ selector: MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR,
53694
+ nodes
53695
+ });
53696
+ }
53602
53697
  const postcssWeappTailwindcssPostPlugin = (options) => {
53603
53698
  const opts = defu(options, { isMainChunk: true });
53604
53699
  const p = { postcssPlugin };
53605
53700
  const cleanRootSpecificity = createRootSpecificityCleaner(opts);
53606
53701
  const cleanFallbackPlaceholder = createFallbackPlaceholderCleaner();
53607
53702
  const shouldAppendHostSelector = createHostSelectorAppender(opts);
53703
+ let shouldInjectTailwindcssV4Defaults = false;
53608
53704
  const enableMainChunkTransforms = opts.isMainChunk !== false;
53609
53705
  if (enableMainChunkTransforms || cleanRootSpecificity) {
53610
53706
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
@@ -53641,13 +53737,17 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
53641
53737
  root.walkAtRules((atRule) => {
53642
53738
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53643
53739
  });
53740
+ if (shouldInjectTailwindcssV4Defaults) injectMissingTailwindcssV4Defaults(root);
53644
53741
  };
53645
53742
  p.AtRuleExit = (atRule) => {
53646
53743
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
53647
53744
  /**
53648
53745
  * @description 移除 property
53649
53746
  */
53650
- if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
53747
+ if (opts.cssRemoveProperty && atRule.name === "property") {
53748
+ if (opts.majorVersion === 4 && atRule.params.trim().startsWith("--tw-")) shouldInjectTailwindcssV4Defaults = true;
53749
+ atRule.remove();
53750
+ }
53651
53751
  /**
53652
53752
  * 清除空节点
53653
53753
  */