@weapp-tailwindcss/postcss 3.2.7 → 3.2.9

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
@@ -216,7 +216,8 @@ function trimNodes$1(nodes) {
216
216
  }
217
217
  function getParsedColorData(colorSource) {
218
218
  try {
219
- return color(parseComponentValue(tokenize({ css: colorSource })));
219
+ const parsed = parseComponentValue(tokenize({ css: colorSource }));
220
+ return color(parsed);
220
221
  } catch {
221
222
  return false;
222
223
  }
@@ -3248,8 +3249,7 @@ function transformWebCssSafeSelectors(css, options) {
3248
3249
  }
3249
3250
  }
3250
3251
  //#endregion
3251
- //#region src/css-macro/auto.ts
3252
- const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
3252
+ //#region src/css-macro/conditions.ts
3253
3253
  const PLATFORM_ENV_KEYS$1 = [
3254
3254
  "WEAPP_TW_TARGET",
3255
3255
  "WEAPP_TAILWINDCSS_TARGET",
@@ -3261,9 +3261,6 @@ const PLATFORM_ENV_KEYS$1 = [
3261
3261
  ];
3262
3262
  const CONDITIONAL_END_RE = /^\s*#endif\s*$/;
3263
3263
  const CUSTOM_VARIANT_CONDITIONAL_FALLBACK_RE = /@custom-variant\b[\s\S]*?\/\*\s*#ifn?def\s[^*]*\*\/[\s\S]*?@slot\b[\s\S]*?\/\*\s*#endif\s*\*\//;
3264
- function readEnvValue$1(key) {
3265
- return typeof process === "undefined" ? void 0 : process.env[key];
3266
- }
3267
3264
  function normalizePlatformToken(value) {
3268
3265
  return value?.trim().replaceAll("_", "-").toUpperCase() || void 0;
3269
3266
  }
@@ -3271,7 +3268,7 @@ function resolveCssMacroPlatform(options) {
3271
3268
  const explicit = normalizePlatformToken(options?.platform);
3272
3269
  if (explicit) return explicit;
3273
3270
  for (const key of PLATFORM_ENV_KEYS$1) {
3274
- const value = normalizePlatformToken(readEnvValue$1(key));
3271
+ const value = normalizePlatformToken(process.env[key]);
3275
3272
  if (value) return value;
3276
3273
  }
3277
3274
  }
@@ -3341,45 +3338,84 @@ function quoteAtRuleParam(value) {
3341
3338
  function hasSlotNode(nodes) {
3342
3339
  return nodes.some((node) => node.type === "atrule" && node.name === "slot");
3343
3340
  }
3341
+ function createConditionalAtRule(start, nodes) {
3342
+ const rule = postcss$1.atRule({
3343
+ name: start.directive === "ifndef" ? ifndefAtRule : ifdefAtRule,
3344
+ params: quoteAtRuleParam(start.expression)
3345
+ });
3346
+ rule.append(...nodes.map((node) => node.clone()));
3347
+ return rule;
3348
+ }
3349
+ function findConditionalEnd(nodes, index) {
3350
+ let depth = 1;
3351
+ for (let searchIndex = index + 1; searchIndex < nodes.length; searchIndex += 1) {
3352
+ const current = nodes[searchIndex];
3353
+ if (current?.type !== "comment") continue;
3354
+ if (parseConditionalStart(current.text)) depth += 1;
3355
+ else if (CONDITIONAL_END_RE.test(current.text) && --depth === 0) return searchIndex;
3356
+ }
3357
+ return -1;
3358
+ }
3344
3359
  function rewriteCustomVariantConditionalComments(root) {
3345
3360
  let changed = false;
3346
- root.walkAtRules("custom-variant", (rule) => {
3347
- const nodes = [...rule.nodes ?? []];
3361
+ const transformContainer = (container, variant) => {
3362
+ const nodes = [...container.nodes ?? []];
3348
3363
  for (let index = 0; index < nodes.length; index += 1) {
3349
3364
  const node = nodes[index];
3350
- if (node?.type !== "comment") continue;
3351
- const start = parseConditionalStart(node.text);
3365
+ const start = node?.type === "comment" ? parseConditionalStart(node.text) : void 0;
3352
3366
  if (!start) continue;
3353
- let depth = 1;
3354
- let endIndex = -1;
3355
- for (let searchIndex = index + 1; searchIndex < nodes.length; searchIndex += 1) {
3356
- const current = nodes[searchIndex];
3357
- if (current?.type !== "comment") continue;
3358
- if (parseConditionalStart(current.text)) {
3359
- depth += 1;
3360
- continue;
3361
- }
3362
- if (CONDITIONAL_END_RE.test(current.text)) {
3363
- depth -= 1;
3364
- if (depth === 0) {
3365
- endIndex = searchIndex;
3366
- break;
3367
- }
3368
- }
3369
- }
3367
+ const endIndex = findConditionalEnd(nodes, index);
3370
3368
  if (endIndex < 0) continue;
3371
3369
  const conditionalNodes = nodes.slice(index + 1, endIndex);
3372
3370
  if (!hasSlotNode(conditionalNodes)) continue;
3373
- const conditionalAtRule = postcss$1.atRule({
3374
- name: start.directive === "ifndef" ? ifndefAtRule : ifdefAtRule,
3375
- params: quoteAtRuleParam(start.expression)
3376
- });
3377
- conditionalAtRule.append(...conditionalNodes.map((current) => current.clone()));
3378
- node.replaceWith(conditionalAtRule);
3371
+ if (container !== variant) {
3372
+ node.remove();
3373
+ nodes[endIndex]?.remove();
3374
+ const variantNodes = [...variant.nodes ?? []];
3375
+ variant.removeAll();
3376
+ variant.append(createConditionalAtRule(start, variantNodes));
3377
+ changed = true;
3378
+ return true;
3379
+ }
3380
+ node.replaceWith(createConditionalAtRule(start, conditionalNodes));
3379
3381
  for (const removedNode of nodes.slice(index + 1, endIndex + 1)) removedNode.remove();
3380
3382
  changed = true;
3381
3383
  }
3382
- });
3384
+ for (const node of [...container.nodes ?? []]) if ("nodes" in node && node.nodes && transformContainer(node, variant)) return true;
3385
+ return false;
3386
+ };
3387
+ const variants = [];
3388
+ root.walkAtRules("custom-variant", (rule) => variants.push(rule));
3389
+ for (const variant of variants) transformContainer(variant, variant);
3390
+ return changed;
3391
+ }
3392
+ function rewriteOuterCustomVariantConditionalComments(root) {
3393
+ let changed = false;
3394
+ const transformContainer = (container) => {
3395
+ const nodes = [...container.nodes ?? []];
3396
+ for (let index = 0; index < nodes.length; index += 1) {
3397
+ const node = nodes[index];
3398
+ const start = node?.type === "comment" ? parseConditionalStart(node.text) : void 0;
3399
+ if (!start) continue;
3400
+ const endIndex = findConditionalEnd(nodes, index);
3401
+ if (endIndex < 0) continue;
3402
+ const conditionalNodes = nodes.slice(index + 1, endIndex);
3403
+ const customVariants = conditionalNodes.filter((current) => current.type === "atrule" && current.name === "custom-variant");
3404
+ if (customVariants.length === 0 || customVariants.some((variant) => !variant.nodes?.length)) continue;
3405
+ for (const variant of customVariants) {
3406
+ const variantNodes = [...variant.nodes ?? []];
3407
+ variant.removeAll();
3408
+ variant.append(createConditionalAtRule(start, variantNodes));
3409
+ }
3410
+ if (conditionalNodes.every((current) => current.type === "comment" || current.type === "atrule" && current.name === "custom-variant")) {
3411
+ node.remove();
3412
+ for (const removedNode of nodes.slice(index + 1, endIndex + 1)) if (removedNode.type === "comment") removedNode.remove();
3413
+ }
3414
+ changed = true;
3415
+ }
3416
+ for (const node of [...container.nodes ?? []]) if ("nodes" in node && node.nodes) transformContainer(node);
3417
+ };
3418
+ transformContainer(root);
3383
3419
  return changed;
3384
3420
  }
3385
3421
  function compileCssMacroConditionalComments(css, options) {
@@ -3405,11 +3441,8 @@ function compileCssMacroConditionalComments(css, options) {
3405
3441
  continue;
3406
3442
  }
3407
3443
  }
3408
- if (getActiveConditionalValue(stack) === false) {
3409
- node.remove();
3410
- continue;
3411
- }
3412
- if ("nodes" in node && node.nodes) transformContainer(node);
3444
+ if (getActiveConditionalValue(stack) === false) node.remove();
3445
+ else if ("nodes" in node && node.nodes) transformContainer(node);
3413
3446
  }
3414
3447
  };
3415
3448
  transformContainer(root);
@@ -3418,28 +3451,15 @@ function compileCssMacroConditionalComments(css, options) {
3418
3451
  return css;
3419
3452
  }
3420
3453
  }
3421
- function parseCssPluginRequest(params) {
3422
- const value = params.trim();
3423
- const quoted = /^(['"])(.*?)\1/.exec(value);
3424
- if (quoted) return quoted[2];
3425
- const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
3426
- return url?.[2] ?? url?.[3];
3427
- }
3428
- function isCssMacroPluginRequest(request) {
3429
- if (request === "weapp-tailwindcss/css-macro") return true;
3430
- if (!request?.includes("css-macro")) return false;
3431
- return path.basename(request).startsWith("css-macro");
3432
- }
3433
- function hasCssMacroTailwindV4Directive(css) {
3434
- if (!css?.includes("css-macro")) return false;
3454
+ function transformCssMacroTailwindV4Source(css) {
3455
+ if (!hasCssMacroTailwindV4CustomVariantConditionalComments(css)) return css;
3435
3456
  try {
3436
- let found = false;
3437
- postcss$1.parse(css).walkAtRules("plugin", (rule) => {
3438
- if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
3439
- });
3440
- return found;
3457
+ const root = postcss$1.parse(css);
3458
+ const outerChanged = rewriteOuterCustomVariantConditionalComments(root);
3459
+ const innerChanged = rewriteCustomVariantConditionalComments(root);
3460
+ return outerChanged || innerChanged ? root.toString() : css;
3441
3461
  } catch {
3442
- return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
3462
+ return css;
3443
3463
  }
3444
3464
  }
3445
3465
  function hasCssMacroTailwindV4CustomVariantConditionalComments(css) {
@@ -3447,18 +3467,31 @@ function hasCssMacroTailwindV4CustomVariantConditionalComments(css) {
3447
3467
  try {
3448
3468
  const root = postcss$1.parse(css);
3449
3469
  let found = false;
3450
- root.walkAtRules("custom-variant", (rule) => {
3451
- const nodes = [...rule.nodes ?? []];
3470
+ const hasConditionalSlot = (container) => {
3471
+ const nodes = [...container.nodes ?? []];
3452
3472
  for (let index = 0; index < nodes.length; index += 1) {
3453
3473
  const node = nodes[index];
3454
3474
  if (node?.type !== "comment" || !parseConditionalStart(node.text)) continue;
3455
3475
  const tail = nodes.slice(index + 1);
3456
- if (tail.some((current) => current.type === "comment" && CONDITIONAL_END_RE.test(current.text)) && hasSlotNode(tail)) {
3457
- found = true;
3458
- return false;
3459
- }
3476
+ if (tail.some((current) => current.type === "comment" && CONDITIONAL_END_RE.test(current.text)) && hasSlotNode(tail)) return true;
3460
3477
  }
3478
+ return nodes.some((node) => "nodes" in node && node.nodes && hasConditionalSlot(node));
3479
+ };
3480
+ root.walkAtRules("custom-variant", (rule) => {
3481
+ if (hasConditionalSlot(rule)) found = true;
3461
3482
  });
3483
+ const scanOuterConditional = (container) => {
3484
+ const nodes = [...container.nodes ?? []];
3485
+ for (let index = 0; index < nodes.length; index += 1) {
3486
+ const node = nodes[index];
3487
+ if (node?.type !== "comment" || !parseConditionalStart(node.text)) continue;
3488
+ const endIndex = findConditionalEnd(nodes, index);
3489
+ if (endIndex < 0) continue;
3490
+ if (nodes.slice(index + 1, endIndex).some((current) => current.type === "atrule" && current.name === "custom-variant")) return true;
3491
+ }
3492
+ return nodes.some((node) => "nodes" in node && node.nodes && scanOuterConditional(node));
3493
+ };
3494
+ found ||= scanOuterConditional(root);
3462
3495
  return found;
3463
3496
  } catch {
3464
3497
  return CUSTOM_VARIANT_CONDITIONAL_FALLBACK_RE.test(css);
@@ -3469,28 +3502,42 @@ function hasCssMacroTailwindV4InternalAtRules(css) {
3469
3502
  try {
3470
3503
  let found = false;
3471
3504
  postcss$1.parse(css).walkAtRules((rule) => {
3472
- if (rule.name === "weapp-tw-ifdef" || rule.name === "weapp-tw-ifndef") {
3473
- found = true;
3474
- return false;
3475
- }
3505
+ if (rule.name === "weapp-tw-ifdef" || rule.name === "weapp-tw-ifndef") found = true;
3476
3506
  });
3477
3507
  return found;
3478
3508
  } catch {
3479
3509
  return /@weapp-tw-ifn?def\b/.test(css);
3480
3510
  }
3481
3511
  }
3482
- function hasCssMacroTailwindV4Source(css) {
3483
- return hasCssMacroTailwindV4Directive(css) || hasCssMacroTailwindV4CustomVariantConditionalComments(css) || hasCssMacroTailwindV4InternalAtRules(css);
3512
+ //#endregion
3513
+ //#region src/css-macro/auto.ts
3514
+ const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
3515
+ function parseCssPluginRequest(params) {
3516
+ const value = params.trim();
3517
+ const quoted = /^(['"])(.*?)\1/.exec(value);
3518
+ if (quoted) return quoted[2];
3519
+ const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
3520
+ return url?.[2] ?? url?.[3];
3484
3521
  }
3485
- function transformCssMacroTailwindV4Source(css) {
3486
- if (!hasCssMacroTailwindV4CustomVariantConditionalComments(css)) return css;
3522
+ function isCssMacroPluginRequest(request) {
3523
+ if (request === "weapp-tailwindcss/css-macro") return true;
3524
+ return Boolean(request?.includes("css-macro") && path.basename(request).startsWith("css-macro"));
3525
+ }
3526
+ function hasCssMacroTailwindV4Directive(css) {
3527
+ if (!css?.includes("css-macro")) return false;
3487
3528
  try {
3488
- const root = postcss$1.parse(css);
3489
- return rewriteCustomVariantConditionalComments(root) ? root.toString() : css;
3529
+ let found = false;
3530
+ postcss$1.parse(css).walkAtRules("plugin", (rule) => {
3531
+ if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
3532
+ });
3533
+ return found;
3490
3534
  } catch {
3491
- return css;
3535
+ return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
3492
3536
  }
3493
3537
  }
3538
+ function hasCssMacroTailwindV4Source(css) {
3539
+ return hasCssMacroTailwindV4Directive(css) || hasCssMacroTailwindV4CustomVariantConditionalComments(css) || hasCssMacroTailwindV4InternalAtRules(css);
3540
+ }
3494
3541
  function isCssMacroPostcssPlugin(plugin) {
3495
3542
  if (plugin === creator) return true;
3496
3543
  return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
@@ -3501,8 +3548,7 @@ function withCssMacroPostcssPlugins(plugins) {
3501
3548
  if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
3502
3549
  if (typeof plugins === "object") {
3503
3550
  const values = Object.values(plugins).filter(Boolean);
3504
- if (values.some(isCssMacroPostcssPlugin)) return values;
3505
- return [...values, macroPlugin];
3551
+ return values.some(isCssMacroPostcssPlugin) ? values : [...values, macroPlugin];
3506
3552
  }
3507
3553
  return [macroPlugin];
3508
3554
  }
@@ -4611,6 +4657,7 @@ function getDefaultOptions(options) {
4611
4657
  autoprefixer: { add: false }
4612
4658
  },
4613
4659
  cssRemoveProperty: true,
4660
+ cssRemoveFocusPseudoClass: true,
4614
4661
  uniAppXUnsupported: "warn",
4615
4662
  cssSelectorReplacement: {
4616
4663
  root: [
@@ -4658,7 +4705,9 @@ const CSS_OPTION_KEYS = [
4658
4705
  "unitsToPx",
4659
4706
  "unitConversion",
4660
4707
  "platform",
4708
+ "cssRemoveActivePseudoClass",
4661
4709
  "cssRemoveHoverPseudoClass",
4710
+ "cssRemoveFocusPseudoClass",
4662
4711
  "cssRemoveProperty",
4663
4712
  "cssCalc",
4664
4713
  "atRules",
@@ -4668,7 +4717,9 @@ function getSimpleOverrideCacheKey(options) {
4668
4717
  let isMainChunk = SIMPLE_OVERRIDE_UNSET;
4669
4718
  let majorVersion = SIMPLE_OVERRIDE_UNSET;
4670
4719
  let cssRemoveProperty = SIMPLE_OVERRIDE_UNSET;
4720
+ let cssRemoveActivePseudoClass = SIMPLE_OVERRIDE_UNSET;
4671
4721
  let cssRemoveHoverPseudoClass = SIMPLE_OVERRIDE_UNSET;
4722
+ let cssRemoveFocusPseudoClass = SIMPLE_OVERRIDE_UNSET;
4672
4723
  let uniAppX = SIMPLE_OVERRIDE_UNSET;
4673
4724
  let cssPreflightRange = SIMPLE_OVERRIDE_UNSET;
4674
4725
  let injectAdditionalCssVarScope = SIMPLE_OVERRIDE_UNSET;
@@ -4700,6 +4751,14 @@ function getSimpleOverrideCacheKey(options) {
4700
4751
  if (typeof value !== "boolean") return;
4701
4752
  cssRemoveHoverPseudoClass = value ? "1" : "0";
4702
4753
  break;
4754
+ case "cssRemoveActivePseudoClass":
4755
+ if (typeof value !== "boolean") return;
4756
+ cssRemoveActivePseudoClass = value ? "1" : "0";
4757
+ break;
4758
+ case "cssRemoveFocusPseudoClass":
4759
+ if (typeof value !== "boolean") return;
4760
+ cssRemoveFocusPseudoClass = value ? "1" : "0";
4761
+ break;
4703
4762
  case "uniAppX":
4704
4763
  if (typeof value !== "boolean") return;
4705
4764
  uniAppX = value ? "1" : "0";
@@ -4756,7 +4815,9 @@ function getSimpleOverrideCacheKey(options) {
4756
4815
  isMainChunk,
4757
4816
  majorVersion,
4758
4817
  cssRemoveProperty,
4818
+ cssRemoveActivePseudoClass,
4759
4819
  cssRemoveHoverPseudoClass,
4820
+ cssRemoveFocusPseudoClass,
4760
4821
  uniAppX,
4761
4822
  cssPreflightRange,
4762
4823
  injectAdditionalCssVarScope,
@@ -5008,26 +5069,45 @@ function getCustomPropertyCleaner(options) {
5008
5069
  const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
5009
5070
  if (!(Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0)) return null;
5010
5071
  const shouldInspectValue = (value) => value.includes("var(") && value.includes("--");
5072
+ const containsIncludedCustomProperty = (value) => {
5073
+ if (!shouldInspectValue(value)) return false;
5074
+ const parsed = valueParser(value);
5075
+ let containsIncludedCustomProperty = false;
5076
+ parsed.walk((node) => {
5077
+ if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) return;
5078
+ if (node.nodes.find((x) => {
5079
+ return x.type === "word" && regExpTest(includeCustomProperties, x.value);
5080
+ })) containsIncludedCustomProperty = true;
5081
+ });
5082
+ return containsIncludedCustomProperty;
5083
+ };
5084
+ const hasSameSourceRange = (left, right) => {
5085
+ const leftSource = left.source;
5086
+ const rightSource = right.source;
5087
+ if (!leftSource?.start || !leftSource.end || !rightSource?.start || !rightSource.end || leftSource.input !== rightSource.input) return false;
5088
+ return leftSource.start.line === rightSource.start.line && leftSource.start.column === rightSource.start.column && leftSource.end.line === rightSource.end.line && leftSource.end.column === rightSource.end.column;
5089
+ };
5011
5090
  return {
5012
5091
  postcssPlugin: "postcss-remove-include-custom-properties",
5013
5092
  OnceExit(root) {
5014
5093
  root.walkDecls((decl) => {
5015
5094
  const prevNode = decl.prev();
5016
- if (!prevNode || prevNode.type !== "decl" || prevNode.prop !== decl.prop) return;
5017
- if (prevNode.value === decl.value) {
5095
+ if (prevNode && prevNode.type === "decl" && prevNode.prop === decl.prop && prevNode.important === decl.important && prevNode.value === decl.value) {
5018
5096
  decl.remove();
5019
5097
  return;
5020
5098
  }
5021
- if (!shouldInspectValue(decl.value)) return;
5022
- const parsed = valueParser(decl.value);
5023
- let containsIncludedCustomProperty = false;
5024
- parsed.walk((node) => {
5025
- if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) return;
5026
- if (node.nodes.find((x) => {
5027
- return x.type === "word" && regExpTest(includeCustomProperties, x.value);
5028
- })) containsIncludedCustomProperty = true;
5029
- });
5030
- if (containsIncludedCustomProperty) decl.remove();
5099
+ if (!containsIncludedCustomProperty(decl.value)) return;
5100
+ let fallbackDecl;
5101
+ let node = prevNode;
5102
+ while (node) {
5103
+ if (node.type === "decl" && node.prop === decl.prop) {
5104
+ fallbackDecl = node;
5105
+ break;
5106
+ }
5107
+ node = node.prev();
5108
+ }
5109
+ if (!fallbackDecl || fallbackDecl.important !== decl.important || fallbackDecl !== prevNode && !hasSameSourceRange(fallbackDecl, decl) || containsIncludedCustomProperty(fallbackDecl.value)) return;
5110
+ decl.remove();
5031
5111
  });
5032
5112
  }
5033
5113
  };
@@ -5071,7 +5151,8 @@ const defaultRemTransformOptions = {
5071
5151
  function getRemTransformPlugin(options) {
5072
5152
  if (!options.rem2rpx) return null;
5073
5153
  if (options.rem2rpx === true) return postcssRem2rpx(defaultRemTransformOptions);
5074
- return postcssRem2rpx(defuOverrideArray(options.rem2rpx, defaultStage));
5154
+ const merged = defuOverrideArray(options.rem2rpx, defaultStage);
5155
+ return postcssRem2rpx(merged);
5075
5156
  }
5076
5157
  //#endregion
5077
5158
  //#region src/plugins/getUnitConversionPlugin.ts
@@ -5311,9 +5392,10 @@ function getFallbackRemove(_rule, options) {
5311
5392
  if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) maybeImportantId = true;
5312
5393
  if (selector.type === "universal") selector.parent?.remove();
5313
5394
  else if (selector.type === "pseudo") {
5314
- if (selector.value === ":is") if (maybeImportantId && selector.nodes[0]?.type === "selector") selector.replaceWith(selector.nodes[0]);
5315
- else selector.parent?.remove();
5316
- else if (selector.value === ":not") {
5395
+ if (selector.value === ":is") {
5396
+ if (maybeImportantId && selector.nodes[0]?.type === "selector") selector.replaceWith(selector.nodes[0]);
5397
+ else selector.parent?.remove();
5398
+ } else if (selector.value === ":not") {
5317
5399
  for (const x of selector.nodes) if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") x.nodes = [selectorParser.tag({ value: "#n" })];
5318
5400
  }
5319
5401
  } else if (selector.type === "attribute") {
@@ -5353,14 +5435,16 @@ function getFallbackRemove(_rule, options) {
5353
5435
  } finally {
5354
5436
  currentRule = void 0;
5355
5437
  }
5356
- if (transformOptions === FALLBACK_TRANSFORM_OPTIONS) if (targetRule.parent == null) {
5357
- targetRule.selector = "";
5358
- writeSelectorCache(sourceSelector, { action: "remove" });
5359
- } else if (targetRule.selector === sourceSelector) writeSelectorCache(sourceSelector, { action: "keep" });
5360
- else writeSelectorCache(sourceSelector, {
5361
- action: "update",
5362
- selector: targetRule.selector
5363
- });
5438
+ if (transformOptions === FALLBACK_TRANSFORM_OPTIONS) {
5439
+ if (targetRule.parent == null) {
5440
+ targetRule.selector = "";
5441
+ writeSelectorCache(sourceSelector, { action: "remove" });
5442
+ } else if (targetRule.selector === sourceSelector) writeSelectorCache(sourceSelector, { action: "keep" });
5443
+ else writeSelectorCache(sourceSelector, {
5444
+ action: "update",
5445
+ selector: targetRule.selector
5446
+ });
5447
+ }
5364
5448
  };
5365
5449
  parser.transformSync = ((input, opts) => {
5366
5450
  const transformOptions = opts ? normalizeTransformOptions(opts) : FALLBACK_TRANSFORM_OPTIONS;
@@ -5378,6 +5462,47 @@ function getFallbackRemove(_rule, options) {
5378
5462
  return entry.parser;
5379
5463
  }
5380
5464
  //#endregion
5465
+ //#region src/selectorParser/pseudo.ts
5466
+ function selectorContainsPseudoClass(selector, pseudoClasses) {
5467
+ if (pseudoClasses.length === 0) return false;
5468
+ let attributeDepth = 0;
5469
+ let quote;
5470
+ let escaped = false;
5471
+ for (let index = 0; index < selector.length; index += 1) {
5472
+ const character = selector[index];
5473
+ if (escaped) {
5474
+ escaped = false;
5475
+ continue;
5476
+ }
5477
+ if (character === "\\") {
5478
+ escaped = true;
5479
+ continue;
5480
+ }
5481
+ if (quote) {
5482
+ if (character === quote) quote = void 0;
5483
+ continue;
5484
+ }
5485
+ if (character === "\"" || character === "'") {
5486
+ quote = character;
5487
+ continue;
5488
+ }
5489
+ if (character === "[") {
5490
+ attributeDepth += 1;
5491
+ continue;
5492
+ }
5493
+ if (character === "]") {
5494
+ attributeDepth = Math.max(0, attributeDepth - 1);
5495
+ continue;
5496
+ }
5497
+ if (attributeDepth > 0 || character !== ":") continue;
5498
+ let end = index + 1;
5499
+ while (end < selector.length && /[\w-]/.test(selector[end] ?? "")) end += 1;
5500
+ if (pseudoClasses.includes(selector.slice(index, end))) return true;
5501
+ index = end - 1;
5502
+ }
5503
+ return false;
5504
+ }
5505
+ //#endregion
5381
5506
  //#region src/utils/decl-order.ts
5382
5507
  /**
5383
5508
  * 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
@@ -5487,6 +5612,53 @@ function normalizeSpacingDeclarations(rule) {
5487
5612
  for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
5488
5613
  }
5489
5614
  //#endregion
5615
+ //#region src/selectorParser/rule-transformer/unsupported-pseudos.ts
5616
+ const UNSUPPORTED_MINI_PROGRAM_PSEUDO_CLASS_SET = /* @__PURE__ */ new Set([
5617
+ ":autofill",
5618
+ ":checked",
5619
+ ":default",
5620
+ ":disabled",
5621
+ ":enabled",
5622
+ ":focus-visible",
5623
+ ":focus-within",
5624
+ ":fullscreen",
5625
+ ":indeterminate",
5626
+ ":in-range",
5627
+ ":invalid",
5628
+ ":modal",
5629
+ ":open",
5630
+ ":optional",
5631
+ ":out-of-range",
5632
+ ":placeholder-shown",
5633
+ ":read-only",
5634
+ ":read-write",
5635
+ ":required",
5636
+ ":target",
5637
+ ":valid",
5638
+ ":visited"
5639
+ ]);
5640
+ const unsupportedPseudoClassSetCache = /* @__PURE__ */ new WeakMap();
5641
+ function getUnsupportedPseudoClassSet(options) {
5642
+ const cached = unsupportedPseudoClassSetCache.get(options);
5643
+ if (cached) return cached;
5644
+ const pseudoClasses = new Set(UNSUPPORTED_MINI_PROGRAM_PSEUDO_CLASS_SET);
5645
+ if (options.cssRemoveHoverPseudoClass) pseudoClasses.add(":hover");
5646
+ if (options.cssRemoveActivePseudoClass) pseudoClasses.add(":active");
5647
+ if (options.cssRemoveFocusPseudoClass) pseudoClasses.add(":focus");
5648
+ unsupportedPseudoClassSetCache.set(options, pseudoClasses);
5649
+ return pseudoClasses;
5650
+ }
5651
+ function findRootSelector(node) {
5652
+ let current = node;
5653
+ while (current.parent && current.parent.type !== "root") current = current.parent;
5654
+ return current.type === "selector" ? current : void 0;
5655
+ }
5656
+ function removeUnsupportedPseudoSelector(node, options, unsupportedPseudoClasses = getUnsupportedPseudoClassSet(options)) {
5657
+ if (node.type !== "pseudo" || !unsupportedPseudoClasses.has(node.value)) return false;
5658
+ findRootSelector(node)?.remove();
5659
+ return true;
5660
+ }
5661
+ //#endregion
5490
5662
  //#region src/selectorParser/rule-transformer/pseudos.ts
5491
5663
  const RTL_LANGUAGE_ANY_PSEUDO_SET = /* @__PURE__ */ new Set([
5492
5664
  ":-moz-any",
@@ -5620,6 +5792,12 @@ function transformExpandedSelectorNodes(selector, context) {
5620
5792
  else if (node.type === "universal" && context.universalReplacement) node.value = context.universalReplacement;
5621
5793
  });
5622
5794
  }
5795
+ function transformExpandedUniversalNodes(selector, context) {
5796
+ if (!context.universalReplacement) return;
5797
+ selector.walk((node) => {
5798
+ if (node.type === "universal") node.value = context.universalReplacement;
5799
+ });
5800
+ }
5623
5801
  function appendExpandedWhereSelectors(parent, index, branches, context) {
5624
5802
  const root = parent.parent;
5625
5803
  if (!root) return false;
@@ -5640,7 +5818,10 @@ function flattenWherePseudo(node, context, index, parent) {
5640
5818
  for (const branch of branches) if (transformSpacingSelector(branch.nodes, context.options)) context.requiresSpacingNormalization = true;
5641
5819
  if (branches.length > 1 && appendExpandedWhereSelectors(parent, index, branches, context)) return;
5642
5820
  const targetSelector = branches[0];
5643
- if (targetSelector) node.replaceWith(...targetSelector.nodes.map((item) => item.clone()));
5821
+ if (targetSelector) {
5822
+ transformExpandedUniversalNodes(targetSelector, context);
5823
+ node.replaceWith(...targetSelector.nodes.map((item) => item.clone()));
5824
+ }
5644
5825
  if (parent.type === "selector" && parent.length === 0) parent.remove();
5645
5826
  }
5646
5827
  function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
@@ -5649,6 +5830,7 @@ function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
5649
5830
  }
5650
5831
  function handlePseudoNode(node, index, context, parent) {
5651
5832
  if (node.type !== "pseudo") return;
5833
+ if (removeUnsupportedPseudoSelector(node, context.options, context.unsupportedPseudoClasses ?? getUnsupportedPseudoClassSet(context.options))) return;
5652
5834
  if (isRtlLanguageAnyPseudo(node)) {
5653
5835
  stripUnsupportedRtlLanguagePseudo(node);
5654
5836
  return;
@@ -5674,10 +5856,6 @@ function handleUniversalNode(node, context) {
5674
5856
  if (node.type !== "universal") return;
5675
5857
  if (context.universalReplacement) node.value = context.universalReplacement;
5676
5858
  }
5677
- function shouldRemoveHoverSelector(selector, options) {
5678
- if (!options.cssRemoveHoverPseudoClass) return false;
5679
- return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
5680
- }
5681
5859
  function isHiddenOrTemplateNotPseudo(node) {
5682
5860
  if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
5683
5861
  const selector = node.first;
@@ -5708,8 +5886,10 @@ function handleSelectorNode(selector, context) {
5708
5886
  selector.remove();
5709
5887
  return;
5710
5888
  }
5711
- if (shouldRemoveHoverSelector(selector, context.options)) {
5712
- selector.remove();
5889
+ const unsupportedPseudoClasses = context.unsupportedPseudoClasses ?? getUnsupportedPseudoClassSet(context.options);
5890
+ const unsupportedPseudo = selector.nodes.find((node) => node.type === "pseudo" && unsupportedPseudoClasses.has(node.value));
5891
+ if (unsupportedPseudo) {
5892
+ removeUnsupportedPseudoSelector(unsupportedPseudo, context.options, unsupportedPseudoClasses);
5713
5893
  return;
5714
5894
  }
5715
5895
  if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
@@ -5744,10 +5924,7 @@ function transformSelectors(selectors, context) {
5744
5924
  handleCombinatorNode(node, index, context);
5745
5925
  break;
5746
5926
  case "tag":
5747
- case "attribute":
5748
- handleTagOrAttribute(node, context);
5749
- break;
5750
- default: break;
5927
+ case "attribute": handleTagOrAttribute(node, context);
5751
5928
  }
5752
5929
  });
5753
5930
  if (context.requiresSpacingNormalization) normalizeSpacingDeclarations(context.rule);
@@ -5767,6 +5944,7 @@ function createRuleTransformer(options) {
5767
5944
  const rootReplacement = options.cssSelectorReplacement?.root ? composeIsPseudo(options.cssSelectorReplacement.root) : void 0;
5768
5945
  const universalReplacement = options.cssSelectorReplacement?.universal ? composeIsPseudo(options.cssSelectorReplacement.universal) : void 0;
5769
5946
  const selectorReplacerOptions = options.escapeMap ? { escapeMap: options.escapeMap } : void 0;
5947
+ const unsupportedPseudoClasses = getUnsupportedPseudoClassSet(options);
5770
5948
  function writeSelectorResultCache(selector, result) {
5771
5949
  if (selectorResultCache.size >= selectorResultCacheLimit) selectorResultCache.clear();
5772
5950
  selectorResultCache.set(selector, result);
@@ -5795,7 +5973,8 @@ function createRuleTransformer(options) {
5795
5973
  rule,
5796
5974
  rootReplacement,
5797
5975
  universalReplacement,
5798
- selectorReplacerOptions
5976
+ selectorReplacerOptions,
5977
+ unsupportedPseudoClasses
5799
5978
  };
5800
5979
  let wasRemoved = false;
5801
5980
  let requiresSpacingNormalization = false;
@@ -6440,9 +6619,10 @@ const postcssWeappTailwindcssPrePlugin = (options) => {
6440
6619
  ruleTransformSync(rule, opts);
6441
6620
  },
6442
6621
  AtRule(atRule) {
6443
- if (isAtMediaHover(atRule)) if (atRule.nodes) atRule.replaceWith(atRule.nodes);
6444
- else atRule.remove();
6445
- else if (atRule.name === "supports") {
6622
+ if (isAtMediaHover(atRule)) {
6623
+ if (atRule.nodes) atRule.replaceWith(atRule.nodes);
6624
+ else atRule.remove();
6625
+ } else if (atRule.name === "supports") {
6446
6626
  if (COLOR_MIX_RE.test(atRule.params)) removeAtRuleAndEmptyAncestors(atRule);
6447
6627
  else if (isTailwindcssV4LinearGradientSupports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
6448
6628
  else if (isTailwindcssV4DisplayP3Supports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
@@ -6710,7 +6890,8 @@ var StyleProcessorCache = class {
6710
6890
  const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
6711
6891
  let processor = this.processorCacheByKey.get(compositeKey);
6712
6892
  if (!processor) {
6713
- processor = postcss$1(this.getPipeline(options, signal).plugins);
6893
+ const pipeline = this.getPipeline(options, signal);
6894
+ processor = postcss$1(pipeline.plugins);
6714
6895
  this.processorCacheByKey.set(compositeKey, processor);
6715
6896
  }
6716
6897
  return processor;
@@ -7324,4 +7505,4 @@ function mergeMiniProgramThemeScopeRuleDeclarations(baseCss, css) {
7324
7505
  }
7325
7506
  }
7326
7507
  //#endregion
7327
- export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
7508
+ export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssImportRequestsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, consumeCascadeLayers, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createPostcssStyleTargetProfile, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, dedupeCoveredCssRules, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isMiniProgramLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramGeneratedCssForPostcss, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, protectDynamicVarFallbacks, pruneMiniProgramGeneratedCss, removeEmptyAtRules, removeMatchingLocalCssImports, removeMatchingLocalCssImportsRoot, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramCssImportsRoot, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolvePostcssConfig, resolvePostcssFrameworkProfile, resolvePostcssFrameworkStrategy, resolvePostcssStyleBranch, resolvePostcssStyleBranchProfile, resolvePostcssStyleTarget, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, selectorContainsPseudoClass, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };