@weapp-tailwindcss/postcss 2.2.1-next.4 → 2.2.1-next.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.
@@ -0,0 +1,6 @@
1
+ import type { AtRule, Declaration } from 'postcss';
2
+ /**
3
+ * 收敛小程序 CSS 中的 WebKit 前缀,只保留 WXSS 里有实际价值的兼容写法。
4
+ */
5
+ export declare function normalizeMiniProgramPrefixedDeclaration(decl: Declaration): void;
6
+ export declare function removeUnsupportedMiniProgramPrefixedAtRule(atRule: AtRule): void;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { type DynamicColorMixAlphaProtection, type DynamicColorMixAlphaProtectionOptions, type ModernColorValueNormalization, normalizeModernColorValue, protectDynamicColorMixAlpha, } from './compat/color-mix';
2
+ export { normalizeMiniProgramPrefixedDeclaration, removeUnsupportedMiniProgramPrefixedAtRule, } from './compat/mini-program-prefixes';
2
3
  export * from './handler';
3
4
  export { default as postcssHtmlTransform, type IOptions as PostcssHtmlTransformOptions } from './html-transform';
4
5
  export { createStylePipeline, type PipelineNodeContext, type PipelineNodeCursor, type PipelineStage, type ResolvedPipelineNode, type StyleProcessingPipeline, } from './pipeline';
package/dist/index.js CHANGED
@@ -274,6 +274,96 @@ function protectDynamicColorMixAlpha(css, options = {}) {
274
274
  };
275
275
  }
276
276
  //#endregion
277
+ //#region src/compat/mini-program-prefixes.ts
278
+ const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
279
+ "-webkit-box-orient",
280
+ "-webkit-line-clamp",
281
+ "-webkit-overflow-scrolling",
282
+ "-webkit-text-fill-color",
283
+ "-webkit-text-stroke",
284
+ "-webkit-text-stroke-color",
285
+ "-webkit-text-stroke-width"
286
+ ]);
287
+ const PRESERVED_WEBKIT_VALUE_DECLARATIONS = new Map([["display", new Set(["-webkit-box"])], ["-webkit-background-clip", new Set(["text"])]]);
288
+ const TRANSITION_PROPS = new Set(["transition", "transition-property"]);
289
+ function splitTopLevelCommaList(value) {
290
+ const parts = [];
291
+ let start = 0;
292
+ let depth = 0;
293
+ let quote;
294
+ let escaped = false;
295
+ for (let i = 0; i < value.length; i++) {
296
+ const char = value[i];
297
+ if (escaped) {
298
+ escaped = false;
299
+ continue;
300
+ }
301
+ if (char === "\\") {
302
+ escaped = true;
303
+ continue;
304
+ }
305
+ if (quote) {
306
+ if (char === quote) quote = void 0;
307
+ continue;
308
+ }
309
+ if (char === "\"" || char === "'") {
310
+ quote = char;
311
+ continue;
312
+ }
313
+ if (char === "(") {
314
+ depth++;
315
+ continue;
316
+ }
317
+ if (char === ")") {
318
+ depth = Math.max(0, depth - 1);
319
+ continue;
320
+ }
321
+ if (char === "," && depth === 0) {
322
+ parts.push(value.slice(start, i));
323
+ start = i + 1;
324
+ }
325
+ }
326
+ parts.push(value.slice(start));
327
+ return parts;
328
+ }
329
+ function isPreservedWebkitDeclaration(decl) {
330
+ const prop = decl.prop.toLowerCase();
331
+ if (prop.startsWith("-webkit-mask")) return true;
332
+ if (PRESERVED_WEBKIT_DECLARATION_PROPS.has(prop)) return true;
333
+ return PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(prop)?.has(decl.value.trim().toLowerCase()) ?? false;
334
+ }
335
+ function normalizeTransitionValue(value) {
336
+ return splitTopLevelCommaList(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
337
+ }
338
+ function hasUnsupportedWebkitKeywordValue(decl) {
339
+ const value = decl.value.trim().toLowerCase();
340
+ if (!value.startsWith("-webkit-")) return false;
341
+ if (PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(decl.prop.toLowerCase())?.has(value)) return false;
342
+ return /^-webkit-[\w-]+$/.test(value);
343
+ }
344
+ /**
345
+ * 收敛小程序 CSS 中的 WebKit 前缀,只保留 WXSS 里有实际价值的兼容写法。
346
+ */
347
+ function normalizeMiniProgramPrefixedDeclaration(decl) {
348
+ const prop = decl.prop.toLowerCase();
349
+ if (TRANSITION_PROPS.has(prop) && decl.value.toLowerCase().includes("-webkit-")) {
350
+ const value = normalizeTransitionValue(decl.value);
351
+ if (value.length === 0) {
352
+ decl.remove();
353
+ return;
354
+ }
355
+ decl.value = value;
356
+ }
357
+ if (prop.startsWith("-webkit-") && !isPreservedWebkitDeclaration(decl)) {
358
+ decl.remove();
359
+ return;
360
+ }
361
+ if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
362
+ }
363
+ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
364
+ if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
365
+ }
366
+ //#endregion
277
367
  //#region src/compat/uni-app-x.ts
278
368
  const UNI_APP_X_BASE_CARRIER_SELECTORS = new Set([
279
369
  "*",
@@ -691,7 +781,13 @@ const WEAPP_AUTOPREFIXER_BROWSERS = [
691
781
  "Android >= 4.4",
692
782
  "ChromeAndroid >= 37"
693
783
  ];
694
- const WEAPP_AUTOPREFIXER_DEFAULT_OPTIONS = { flexbox: false };
784
+ const WEAPP_AUTOPREFIXER_DEFAULT_OPTIONS = {
785
+ add: true,
786
+ flexbox: false,
787
+ grid: false,
788
+ remove: true,
789
+ supports: false
790
+ };
695
791
  const AUTOPREFIXER_PLUGIN_NAME = "autoprefixer";
696
792
  function isAutoprefixerPlugin(plugin) {
697
793
  return plugin?.postcssPlugin === AUTOPREFIXER_PLUGIN_NAME;
@@ -2032,17 +2128,29 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
2032
2128
  else normalizeTailwindcssRpxDeclaration(decl, { majorVersion: opts.majorVersion });
2033
2129
  if (enableMainChunkTransforms) normalizeTailwindcssV4Declaration(decl);
2034
2130
  removeLegacyFlexboxPrefix(decl);
2131
+ if (enableMainChunkTransforms) normalizeMiniProgramPrefixedDeclaration(decl);
2035
2132
  };
2036
- if (enableMainChunkTransforms) p.AtRuleExit = (atRule) => {
2037
- /**
2038
- * @description 移除 property
2039
- */
2040
- if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
2041
- /**
2042
- * 清除空节点
2043
- */
2044
- atRule.nodes?.length === 0 && atRule.remove();
2045
- };
2133
+ if (enableMainChunkTransforms) {
2134
+ p.OnceExit = (root) => {
2135
+ root.walkDecls((decl) => {
2136
+ normalizeMiniProgramPrefixedDeclaration(decl);
2137
+ });
2138
+ root.walkAtRules((atRule) => {
2139
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
2140
+ });
2141
+ };
2142
+ p.AtRuleExit = (atRule) => {
2143
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
2144
+ /**
2145
+ * @description 移除 property
2146
+ */
2147
+ if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
2148
+ /**
2149
+ * 清除空节点
2150
+ */
2151
+ atRule.nodes?.length === 0 && atRule.remove();
2152
+ };
2153
+ }
2046
2154
  return p;
2047
2155
  };
2048
2156
  postcssWeappTailwindcssPostPlugin.postcss = true;
@@ -2757,6 +2865,8 @@ exports.createInjectPreflight = createInjectPreflight;
2757
2865
  exports.createStyleHandler = createStyleHandler;
2758
2866
  exports.createStylePipeline = createStylePipeline;
2759
2867
  exports.internalCssSelectorReplacer = internalCssSelectorReplacer;
2868
+ exports.normalizeMiniProgramPrefixedDeclaration = normalizeMiniProgramPrefixedDeclaration;
2760
2869
  exports.normalizeModernColorValue = normalizeModernColorValue;
2761
2870
  exports.postcssHtmlTransform = require_html_transform.postcssHtmlTransform;
2762
2871
  exports.protectDynamicColorMixAlpha = protectDynamicColorMixAlpha;
2872
+ exports.removeUnsupportedMiniProgramPrefixedAtRule = removeUnsupportedMiniProgramPrefixedAtRule;
package/dist/index.mjs CHANGED
@@ -264,6 +264,96 @@ function protectDynamicColorMixAlpha(css, options = {}) {
264
264
  };
265
265
  }
266
266
  //#endregion
267
+ //#region src/compat/mini-program-prefixes.ts
268
+ const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
269
+ "-webkit-box-orient",
270
+ "-webkit-line-clamp",
271
+ "-webkit-overflow-scrolling",
272
+ "-webkit-text-fill-color",
273
+ "-webkit-text-stroke",
274
+ "-webkit-text-stroke-color",
275
+ "-webkit-text-stroke-width"
276
+ ]);
277
+ const PRESERVED_WEBKIT_VALUE_DECLARATIONS = new Map([["display", new Set(["-webkit-box"])], ["-webkit-background-clip", new Set(["text"])]]);
278
+ const TRANSITION_PROPS = new Set(["transition", "transition-property"]);
279
+ function splitTopLevelCommaList(value) {
280
+ const parts = [];
281
+ let start = 0;
282
+ let depth = 0;
283
+ let quote;
284
+ let escaped = false;
285
+ for (let i = 0; i < value.length; i++) {
286
+ const char = value[i];
287
+ if (escaped) {
288
+ escaped = false;
289
+ continue;
290
+ }
291
+ if (char === "\\") {
292
+ escaped = true;
293
+ continue;
294
+ }
295
+ if (quote) {
296
+ if (char === quote) quote = void 0;
297
+ continue;
298
+ }
299
+ if (char === "\"" || char === "'") {
300
+ quote = char;
301
+ continue;
302
+ }
303
+ if (char === "(") {
304
+ depth++;
305
+ continue;
306
+ }
307
+ if (char === ")") {
308
+ depth = Math.max(0, depth - 1);
309
+ continue;
310
+ }
311
+ if (char === "," && depth === 0) {
312
+ parts.push(value.slice(start, i));
313
+ start = i + 1;
314
+ }
315
+ }
316
+ parts.push(value.slice(start));
317
+ return parts;
318
+ }
319
+ function isPreservedWebkitDeclaration(decl) {
320
+ const prop = decl.prop.toLowerCase();
321
+ if (prop.startsWith("-webkit-mask")) return true;
322
+ if (PRESERVED_WEBKIT_DECLARATION_PROPS.has(prop)) return true;
323
+ return PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(prop)?.has(decl.value.trim().toLowerCase()) ?? false;
324
+ }
325
+ function normalizeTransitionValue(value) {
326
+ return splitTopLevelCommaList(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
327
+ }
328
+ function hasUnsupportedWebkitKeywordValue(decl) {
329
+ const value = decl.value.trim().toLowerCase();
330
+ if (!value.startsWith("-webkit-")) return false;
331
+ if (PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(decl.prop.toLowerCase())?.has(value)) return false;
332
+ return /^-webkit-[\w-]+$/.test(value);
333
+ }
334
+ /**
335
+ * 收敛小程序 CSS 中的 WebKit 前缀,只保留 WXSS 里有实际价值的兼容写法。
336
+ */
337
+ function normalizeMiniProgramPrefixedDeclaration(decl) {
338
+ const prop = decl.prop.toLowerCase();
339
+ if (TRANSITION_PROPS.has(prop) && decl.value.toLowerCase().includes("-webkit-")) {
340
+ const value = normalizeTransitionValue(decl.value);
341
+ if (value.length === 0) {
342
+ decl.remove();
343
+ return;
344
+ }
345
+ decl.value = value;
346
+ }
347
+ if (prop.startsWith("-webkit-") && !isPreservedWebkitDeclaration(decl)) {
348
+ decl.remove();
349
+ return;
350
+ }
351
+ if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
352
+ }
353
+ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
354
+ if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
355
+ }
356
+ //#endregion
267
357
  //#region src/compat/uni-app-x.ts
268
358
  const UNI_APP_X_BASE_CARRIER_SELECTORS = new Set([
269
359
  "*",
@@ -681,7 +771,13 @@ const WEAPP_AUTOPREFIXER_BROWSERS = [
681
771
  "Android >= 4.4",
682
772
  "ChromeAndroid >= 37"
683
773
  ];
684
- const WEAPP_AUTOPREFIXER_DEFAULT_OPTIONS = { flexbox: false };
774
+ const WEAPP_AUTOPREFIXER_DEFAULT_OPTIONS = {
775
+ add: true,
776
+ flexbox: false,
777
+ grid: false,
778
+ remove: true,
779
+ supports: false
780
+ };
685
781
  const AUTOPREFIXER_PLUGIN_NAME = "autoprefixer";
686
782
  function isAutoprefixerPlugin(plugin) {
687
783
  return plugin?.postcssPlugin === AUTOPREFIXER_PLUGIN_NAME;
@@ -2022,17 +2118,29 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
2022
2118
  else normalizeTailwindcssRpxDeclaration(decl, { majorVersion: opts.majorVersion });
2023
2119
  if (enableMainChunkTransforms) normalizeTailwindcssV4Declaration(decl);
2024
2120
  removeLegacyFlexboxPrefix(decl);
2121
+ if (enableMainChunkTransforms) normalizeMiniProgramPrefixedDeclaration(decl);
2025
2122
  };
2026
- if (enableMainChunkTransforms) p.AtRuleExit = (atRule) => {
2027
- /**
2028
- * @description 移除 property
2029
- */
2030
- if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
2031
- /**
2032
- * 清除空节点
2033
- */
2034
- atRule.nodes?.length === 0 && atRule.remove();
2035
- };
2123
+ if (enableMainChunkTransforms) {
2124
+ p.OnceExit = (root) => {
2125
+ root.walkDecls((decl) => {
2126
+ normalizeMiniProgramPrefixedDeclaration(decl);
2127
+ });
2128
+ root.walkAtRules((atRule) => {
2129
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
2130
+ });
2131
+ };
2132
+ p.AtRuleExit = (atRule) => {
2133
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
2134
+ /**
2135
+ * @description 移除 property
2136
+ */
2137
+ if (opts.cssRemoveProperty && atRule.name === "property") atRule.remove();
2138
+ /**
2139
+ * 清除空节点
2140
+ */
2141
+ atRule.nodes?.length === 0 && atRule.remove();
2142
+ };
2143
+ }
2036
2144
  return p;
2037
2145
  };
2038
2146
  postcssWeappTailwindcssPostPlugin.postcss = true;
@@ -2742,4 +2850,4 @@ function createStyleHandler(options) {
2742
2850
  return handler;
2743
2851
  }
2744
2852
  //#endregion
2745
- export { createFallbackPlaceholderReplacer, createInjectPreflight, createStyleHandler, createStylePipeline, internalCssSelectorReplacer, normalizeModernColorValue, postcssHtmlTransform, protectDynamicColorMixAlpha };
2853
+ export { createFallbackPlaceholderReplacer, createInjectPreflight, createStyleHandler, createStylePipeline, internalCssSelectorReplacer, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, postcssHtmlTransform, protectDynamicColorMixAlpha, removeUnsupportedMiniProgramPrefixedAtRule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.2.1-next.4",
3
+ "version": "2.2.1-next.5",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",