@weapp-tailwindcss/postcss 3.2.4 → 3.2.5

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.
@@ -7,6 +7,7 @@ export declare function removeRootSpecificityPlaceholders(root: postcss.Root): v
7
7
  export declare function removeEmptyAtRules(root: postcss.Root): number;
8
8
  export declare function removeEmptyBlockAtRules(root: postcss.Root): number;
9
9
  export declare function removeUnsupportedBrowserSelectors(root: postcss.Root): void;
10
+ export declare function removeEmptyStandardPropertyFallbacks(root: postcss.Root): void;
10
11
  export declare function removeDisplayP3Declarations(root: postcss.Root): void;
11
12
  interface RemoveTailwindContainerRulesOptions {
12
13
  generatedOnly?: boolean;
package/dist/index.cjs CHANGED
@@ -937,15 +937,18 @@ function isTailwindPreflightDeclaration(decl) {
937
937
  if (prop === "font-family" && value.startsWith("var(--default-font-family") || prop === "font-feature-settings" && value.startsWith("var(--default-font-feature-settings") || prop === "font-variation-settings" && value.startsWith("var(--default-font-variation-settings")) return true;
938
938
  return TAILWIND_PREFLIGHT_DECLARATIONS.has(`${prop}:${value}`);
939
939
  }
940
- function isScopedTailwindThemeCarrierRule(rule) {
940
+ function hasTailwindSourceEvidence(declarations, hasTailwindBanner) {
941
+ return hasTailwindBanner || declarations.some((decl) => decl.prop.startsWith("--tw-"));
942
+ }
943
+ function isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) {
941
944
  const selectors = rule.selectors ?? [rule.selector];
942
945
  const declarations = getDeclarations(rule);
943
946
  return selectors.length > 0 && selectors.every((selector) => {
944
947
  const normalized = normalizeCssSignatureValue(selector);
945
948
  return hasVueScopedAttr(selector) && (normalized.startsWith(":root") || normalized.startsWith(":host"));
946
- }) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--"));
949
+ }) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--")) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
947
950
  }
948
- function isScopedUniversalTailwindPreflightRule(rule) {
951
+ function isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) {
949
952
  const selectors = rule.selectors ?? [rule.selector];
950
953
  const declarations = getDeclarations(rule);
951
954
  return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
@@ -953,7 +956,7 @@ function isScopedUniversalTailwindPreflightRule(rule) {
953
956
  "margin",
954
957
  "padding",
955
958
  "border"
956
- ].includes(decl.prop));
959
+ ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
957
960
  }
958
961
  function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
959
962
  if (!hasTailwindBanner) return false;
@@ -961,7 +964,7 @@ function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
961
964
  const declarations = getDeclarations(rule);
962
965
  return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
963
966
  }
964
- function isUnscopedMiniProgramTailwindPreflightRule(rule) {
967
+ function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
965
968
  const selectors = rule.selectors ?? [rule.selector];
966
969
  if (selectors.length === 0 || !selectors.every((selector) => {
967
970
  const normalized = normalizeCssSignatureValue(selector);
@@ -973,7 +976,7 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule) {
973
976
  "margin",
974
977
  "padding",
975
978
  "border"
976
- ].includes(decl.prop));
979
+ ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
977
980
  }
978
981
  function isScopedMiniProgramTailwindContentInitRule(rule) {
979
982
  const selectors = rule.selectors ?? [rule.selector];
@@ -996,7 +999,7 @@ function stripScopedTailwindNoise(root) {
996
999
  if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
997
1000
  });
998
1001
  root.walkRules((rule) => {
999
- if (isScopedTailwindThemeCarrierRule(rule) || isScopedUniversalTailwindPreflightRule(rule) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
1002
+ if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
1000
1003
  });
1001
1004
  root.walkAtRules((atRule) => {
1002
1005
  if (isLikelyTailwindPropertyAtRule(atRule)) {
@@ -1217,9 +1220,15 @@ function applyUniAppXUvueCompatibility(result, options) {
1217
1220
  root = calcResult.root;
1218
1221
  calcMessages = calcResult.messages;
1219
1222
  }
1220
- if (sfcStyleRequest) stripScopedTailwindNoise(root);
1223
+ if (sfcStyleRequest) {
1224
+ stripScopedTailwindNoise(root);
1225
+ const nextResult = root.toResult(result.opts);
1226
+ nextResult.messages.push(...result.messages);
1227
+ nextResult.messages.push(...calcMessages);
1228
+ return nextResult;
1229
+ }
1221
1230
  root.walkRules((rule) => {
1222
- if (!sfcStyleRequest && !hasOnlyClassSelectors(rule)) {
1231
+ if (!hasOnlyClassSelectors(rule)) {
1223
1232
  reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
1224
1233
  rule.remove();
1225
1234
  return;
@@ -2539,6 +2548,11 @@ function removeDeclarationAndEmptyRule$1(decl) {
2539
2548
  removeEmptyAtRuleAncestors(ruleParent);
2540
2549
  }
2541
2550
  }
2551
+ function removeEmptyStandardPropertyFallbacks(root) {
2552
+ root.walkDecls((decl) => {
2553
+ if (!decl.prop.startsWith("--") && decl.value.trim().length === 0 && decl.parent?.nodes.some((node) => node !== decl && node.type === "decl" && node.prop === decl.prop && node.value.trim().length > 0)) removeDeclarationAndEmptyRule$1(decl);
2554
+ });
2555
+ }
2542
2556
  function removeDisplayP3Declarations(root) {
2543
2557
  root.walkAtRules((atRule) => {
2544
2558
  if (isDisplayP3MediaRule(atRule)) {
@@ -2636,6 +2650,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
2636
2650
  removeRootSpecificityPlaceholders(root);
2637
2651
  removeUnsupportedBrowserSelectors(root);
2638
2652
  removeDisplayP3Declarations(root);
2653
+ removeEmptyStandardPropertyFallbacks(root);
2639
2654
  removeTailwindContainerMaxWidthMediaRules(root);
2640
2655
  removeTailwindContainerWidthRules(root, { generatedOnly: true });
2641
2656
  removeUnsupportedModernColorDeclarations(root);
@@ -3183,6 +3198,16 @@ function removeEmptyAtRules$2(root) {
3183
3198
  if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
3184
3199
  });
3185
3200
  }
3201
+ function insertWebkitBackgroundClipText(root) {
3202
+ root.walkDecls("background-clip", (decl) => {
3203
+ if (decl.value.trim().toLowerCase() !== "text") return;
3204
+ const parent = decl.parent;
3205
+ if (!parent || !("nodes" in parent)) return;
3206
+ if (!parent.nodes.some((node) => {
3207
+ return node.type === "decl" && node.prop.toLowerCase() === "-webkit-background-clip" && node.value.trim().toLowerCase() === "text";
3208
+ })) decl.cloneBefore({ prop: "-webkit-background-clip" });
3209
+ });
3210
+ }
3186
3211
  function transformCssNesting(root) {
3187
3212
  (0, postcss.default)([(0, postcss_preset_env.default)({
3188
3213
  stage: false,
@@ -3192,7 +3217,7 @@ function transformCssNesting(root) {
3192
3217
  }
3193
3218
  function transformWebCssCompat(css, options) {
3194
3219
  const normalized = normalizeWebCssCompatOptions(options);
3195
- if (!isWebCssCompatEnabled(normalized)) return css;
3220
+ if (!isWebCssCompatEnabled(normalized) && normalized.preset !== "legacy-web") return css;
3196
3221
  try {
3197
3222
  const root = postcss.default.parse(css);
3198
3223
  if (normalized.features.theme) unwrapThemeAtRules(root);
@@ -3206,6 +3231,7 @@ function transformWebCssCompat(css, options) {
3206
3231
  normalizeTailwindcssV4GradientPositionDeclarations(root);
3207
3232
  normalizeTailwindcssV4InfinityCalcDeclarations(root);
3208
3233
  normalizeModernColorDeclarations(root, normalized.features);
3234
+ if (normalized.preset === "legacy-web") insertWebkitBackgroundClipText(root);
3209
3235
  if (normalized.features.layer) removeUnsupportedCascadeLayers(root);
3210
3236
  removeEmptyAtRules$2(root);
3211
3237
  return root.toString();
package/dist/index.js CHANGED
@@ -922,15 +922,18 @@ function isTailwindPreflightDeclaration(decl) {
922
922
  if (prop === "font-family" && value.startsWith("var(--default-font-family") || prop === "font-feature-settings" && value.startsWith("var(--default-font-feature-settings") || prop === "font-variation-settings" && value.startsWith("var(--default-font-variation-settings")) return true;
923
923
  return TAILWIND_PREFLIGHT_DECLARATIONS.has(`${prop}:${value}`);
924
924
  }
925
- function isScopedTailwindThemeCarrierRule(rule) {
925
+ function hasTailwindSourceEvidence(declarations, hasTailwindBanner) {
926
+ return hasTailwindBanner || declarations.some((decl) => decl.prop.startsWith("--tw-"));
927
+ }
928
+ function isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) {
926
929
  const selectors = rule.selectors ?? [rule.selector];
927
930
  const declarations = getDeclarations(rule);
928
931
  return selectors.length > 0 && selectors.every((selector) => {
929
932
  const normalized = normalizeCssSignatureValue(selector);
930
933
  return hasVueScopedAttr(selector) && (normalized.startsWith(":root") || normalized.startsWith(":host"));
931
- }) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--"));
934
+ }) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--")) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
932
935
  }
933
- function isScopedUniversalTailwindPreflightRule(rule) {
936
+ function isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) {
934
937
  const selectors = rule.selectors ?? [rule.selector];
935
938
  const declarations = getDeclarations(rule);
936
939
  return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
@@ -938,7 +941,7 @@ function isScopedUniversalTailwindPreflightRule(rule) {
938
941
  "margin",
939
942
  "padding",
940
943
  "border"
941
- ].includes(decl.prop));
944
+ ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
942
945
  }
943
946
  function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
944
947
  if (!hasTailwindBanner) return false;
@@ -946,7 +949,7 @@ function isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) {
946
949
  const declarations = getDeclarations(rule);
947
950
  return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
948
951
  }
949
- function isUnscopedMiniProgramTailwindPreflightRule(rule) {
952
+ function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
950
953
  const selectors = rule.selectors ?? [rule.selector];
951
954
  if (selectors.length === 0 || !selectors.every((selector) => {
952
955
  const normalized = normalizeCssSignatureValue(selector);
@@ -958,7 +961,7 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule) {
958
961
  "margin",
959
962
  "padding",
960
963
  "border"
961
- ].includes(decl.prop));
964
+ ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
962
965
  }
963
966
  function isScopedMiniProgramTailwindContentInitRule(rule) {
964
967
  const selectors = rule.selectors ?? [rule.selector];
@@ -981,7 +984,7 @@ function stripScopedTailwindNoise(root) {
981
984
  if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
982
985
  });
983
986
  root.walkRules((rule) => {
984
- if (isScopedTailwindThemeCarrierRule(rule) || isScopedUniversalTailwindPreflightRule(rule) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
987
+ if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
985
988
  });
986
989
  root.walkAtRules((atRule) => {
987
990
  if (isLikelyTailwindPropertyAtRule(atRule)) {
@@ -1202,9 +1205,15 @@ function applyUniAppXUvueCompatibility(result, options) {
1202
1205
  root = calcResult.root;
1203
1206
  calcMessages = calcResult.messages;
1204
1207
  }
1205
- if (sfcStyleRequest) stripScopedTailwindNoise(root);
1208
+ if (sfcStyleRequest) {
1209
+ stripScopedTailwindNoise(root);
1210
+ const nextResult = root.toResult(result.opts);
1211
+ nextResult.messages.push(...result.messages);
1212
+ nextResult.messages.push(...calcMessages);
1213
+ return nextResult;
1214
+ }
1206
1215
  root.walkRules((rule) => {
1207
- if (!sfcStyleRequest && !hasOnlyClassSelectors(rule)) {
1216
+ if (!hasOnlyClassSelectors(rule)) {
1208
1217
  reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
1209
1218
  rule.remove();
1210
1219
  return;
@@ -2524,6 +2533,11 @@ function removeDeclarationAndEmptyRule$1(decl) {
2524
2533
  removeEmptyAtRuleAncestors(ruleParent);
2525
2534
  }
2526
2535
  }
2536
+ function removeEmptyStandardPropertyFallbacks(root) {
2537
+ root.walkDecls((decl) => {
2538
+ if (!decl.prop.startsWith("--") && decl.value.trim().length === 0 && decl.parent?.nodes.some((node) => node !== decl && node.type === "decl" && node.prop === decl.prop && node.value.trim().length > 0)) removeDeclarationAndEmptyRule$1(decl);
2539
+ });
2540
+ }
2527
2541
  function removeDisplayP3Declarations(root) {
2528
2542
  root.walkAtRules((atRule) => {
2529
2543
  if (isDisplayP3MediaRule(atRule)) {
@@ -2621,6 +2635,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
2621
2635
  removeRootSpecificityPlaceholders(root);
2622
2636
  removeUnsupportedBrowserSelectors(root);
2623
2637
  removeDisplayP3Declarations(root);
2638
+ removeEmptyStandardPropertyFallbacks(root);
2624
2639
  removeTailwindContainerMaxWidthMediaRules(root);
2625
2640
  removeTailwindContainerWidthRules(root, { generatedOnly: true });
2626
2641
  removeUnsupportedModernColorDeclarations(root);
@@ -3168,6 +3183,16 @@ function removeEmptyAtRules$2(root) {
3168
3183
  if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
3169
3184
  });
3170
3185
  }
3186
+ function insertWebkitBackgroundClipText(root) {
3187
+ root.walkDecls("background-clip", (decl) => {
3188
+ if (decl.value.trim().toLowerCase() !== "text") return;
3189
+ const parent = decl.parent;
3190
+ if (!parent || !("nodes" in parent)) return;
3191
+ if (!parent.nodes.some((node) => {
3192
+ return node.type === "decl" && node.prop.toLowerCase() === "-webkit-background-clip" && node.value.trim().toLowerCase() === "text";
3193
+ })) decl.cloneBefore({ prop: "-webkit-background-clip" });
3194
+ });
3195
+ }
3171
3196
  function transformCssNesting(root) {
3172
3197
  postcss$1([postcssPresetEnv({
3173
3198
  stage: false,
@@ -3177,7 +3202,7 @@ function transformCssNesting(root) {
3177
3202
  }
3178
3203
  function transformWebCssCompat(css, options) {
3179
3204
  const normalized = normalizeWebCssCompatOptions(options);
3180
- if (!isWebCssCompatEnabled(normalized)) return css;
3205
+ if (!isWebCssCompatEnabled(normalized) && normalized.preset !== "legacy-web") return css;
3181
3206
  try {
3182
3207
  const root = postcss$1.parse(css);
3183
3208
  if (normalized.features.theme) unwrapThemeAtRules(root);
@@ -3191,6 +3216,7 @@ function transformWebCssCompat(css, options) {
3191
3216
  normalizeTailwindcssV4GradientPositionDeclarations(root);
3192
3217
  normalizeTailwindcssV4InfinityCalcDeclarations(root);
3193
3218
  normalizeModernColorDeclarations(root, normalized.features);
3219
+ if (normalized.preset === "legacy-web") insertWebkitBackgroundClipText(root);
3194
3220
  if (normalized.features.layer) removeUnsupportedCascadeLayers(root);
3195
3221
  removeEmptyAtRules$2(root);
3196
3222
  return root.toString();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
3
  "type": "module",
4
- "version": "3.2.4",
4
+ "version": "3.2.5",
5
5
  "description": "@weapp-tailwindcss/postcss",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -71,10 +71,10 @@
71
71
  "@tailwindcss-mangle/engine": "0.2.0",
72
72
  "@weapp-core/escape": "~8.0.0",
73
73
  "autoprefixer": "^10.5.4",
74
- "es-toolkit": "^1.49.0",
74
+ "es-toolkit": "^1.50.0",
75
75
  "lru-cache": "11.5.2",
76
76
  "micromatch": "^4.0.8",
77
- "postcss": "^8.5.22",
77
+ "postcss": "^8.5.24",
78
78
  "postcss-load-config": "^6.0.1",
79
79
  "postcss-preset-env": "^11.3.2",
80
80
  "postcss-pxtrans": "^1.0.4",
@@ -83,8 +83,8 @@
83
83
  "postcss-selector-parser": "~7.1.4",
84
84
  "postcss-value-parser": "^4.2.0",
85
85
  "@weapp-tailwindcss/postcss-calc": "^1.0.3",
86
- "tailwindcss-config": "2.0.2",
87
- "@weapp-tailwindcss/shared": "2.0.1"
86
+ "@weapp-tailwindcss/shared": "2.0.1",
87
+ "tailwindcss-config": "2.0.2"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@csstools/postcss-is-pseudo-class": "^6.0.0",