@weapp-tailwindcss/postcss 2.2.1-next.5 → 3.0.0-next.6

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
@@ -274,6 +274,72 @@ function protectDynamicColorMixAlpha(css, options = {}) {
274
274
  };
275
275
  }
276
276
  //#endregion
277
+ //#region src/compat/mini-program-css/at-rules.ts
278
+ const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
279
+ function removeAtRulesByScan(css, names) {
280
+ let index = 0;
281
+ let result = "";
282
+ const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
283
+ while (index < css.length) {
284
+ const match = atRulePattern.exec(css.slice(index));
285
+ if (!match || match.index === void 0) {
286
+ result += css.slice(index);
287
+ break;
288
+ }
289
+ const start = index + match.index;
290
+ result += css.slice(index, start);
291
+ const blockStart = css.indexOf("{", start);
292
+ if (blockStart === -1) {
293
+ result += css.slice(start);
294
+ break;
295
+ }
296
+ let depth = 0;
297
+ let cursor = blockStart;
298
+ for (; cursor < css.length; cursor++) {
299
+ const char = css[cursor];
300
+ if (char === "{") depth++;
301
+ else if (char === "}") {
302
+ depth--;
303
+ if (depth === 0) {
304
+ cursor++;
305
+ break;
306
+ }
307
+ }
308
+ }
309
+ index = cursor;
310
+ }
311
+ return result;
312
+ }
313
+ function removeUnsupportedMiniProgramAtRules(css) {
314
+ try {
315
+ const root = postcss.default.parse(css);
316
+ root.walkAtRules((atRule) => {
317
+ if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
318
+ });
319
+ root.walkAtRules((atRule) => {
320
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
321
+ });
322
+ return root.toString();
323
+ } catch {
324
+ return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
325
+ }
326
+ }
327
+ function removeUnsupportedAtSupports(css) {
328
+ return removeUnsupportedMiniProgramAtRules(css);
329
+ }
330
+ /**
331
+ * 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
332
+ */
333
+ function removeUnsupportedCascadeLayers(root) {
334
+ root.walkAtRules("layer", (atRule) => {
335
+ if (!atRule.nodes || atRule.nodes.length === 0) {
336
+ atRule.remove();
337
+ return;
338
+ }
339
+ atRule.replaceWith(...atRule.nodes);
340
+ });
341
+ }
342
+ //#endregion
277
343
  //#region src/compat/mini-program-prefixes.ts
278
344
  const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
279
345
  "-webkit-box-orient",
@@ -286,7 +352,7 @@ const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
286
352
  ]);
287
353
  const PRESERVED_WEBKIT_VALUE_DECLARATIONS = new Map([["display", new Set(["-webkit-box"])], ["-webkit-background-clip", new Set(["text"])]]);
288
354
  const TRANSITION_PROPS = new Set(["transition", "transition-property"]);
289
- function splitTopLevelCommaList(value) {
355
+ function splitTopLevelCommaList$1(value) {
290
356
  const parts = [];
291
357
  let start = 0;
292
358
  let depth = 0;
@@ -333,7 +399,7 @@ function isPreservedWebkitDeclaration(decl) {
333
399
  return PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(prop)?.has(decl.value.trim().toLowerCase()) ?? false;
334
400
  }
335
401
  function normalizeTransitionValue(value) {
336
- return splitTopLevelCommaList(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
402
+ return splitTopLevelCommaList$1(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
337
403
  }
338
404
  function hasUnsupportedWebkitKeywordValue(decl) {
339
405
  const value = decl.value.trim().toLowerCase();
@@ -364,6 +430,502 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
364
430
  if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
365
431
  }
366
432
  //#endregion
433
+ //#region src/compat/mini-program-css/color-gamut.ts
434
+ const DISPLAY_P3_VALUE_RE$1 = /color\(\s*display-p3\b/i;
435
+ const COLOR_GAMUT_P3_RE$1 = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
436
+ function isDisplayP3MediaRule(atRule) {
437
+ return atRule.name === "media" && COLOR_GAMUT_P3_RE$1.test(atRule.params);
438
+ }
439
+ function isDisplayP3Declaration(decl) {
440
+ return DISPLAY_P3_VALUE_RE$1.test(decl.value);
441
+ }
442
+ //#endregion
443
+ //#region src/compat/mini-program-css/selectors.ts
444
+ const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
445
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
446
+ "*",
447
+ "view",
448
+ "text",
449
+ ":before",
450
+ ":after",
451
+ "::before",
452
+ "::after"
453
+ ]);
454
+ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
455
+ ":host",
456
+ ":root",
457
+ "page",
458
+ ".tw-root",
459
+ "wx-root-portal-content"
460
+ ]);
461
+ const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
462
+ const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = new Set([
463
+ ":-moz-focusring",
464
+ ":-moz-ui-invalid",
465
+ "::-webkit-calendar-picker-indicator",
466
+ "::-webkit-date-and-time-value",
467
+ "::-webkit-datetime-edit",
468
+ "::-webkit-datetime-edit-day-field",
469
+ "::-webkit-datetime-edit-fields-wrapper",
470
+ "::-webkit-datetime-edit-hour-field",
471
+ "::-webkit-datetime-edit-meridiem-field",
472
+ "::-webkit-datetime-edit-millisecond-field",
473
+ "::-webkit-datetime-edit-minute-field",
474
+ "::-webkit-datetime-edit-month-field",
475
+ "::-webkit-datetime-edit-second-field",
476
+ "::-webkit-datetime-edit-year-field",
477
+ "::-webkit-inner-spin-button",
478
+ "::-webkit-input-placeholder",
479
+ "::-webkit-outer-spin-button",
480
+ "::-webkit-search-decoration",
481
+ "::placeholder",
482
+ "[hidden]:where(:not([hidden='until-found']))"
483
+ ]);
484
+ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
485
+ "a",
486
+ "abbr:where([title])",
487
+ "audio",
488
+ "b",
489
+ "button",
490
+ "canvas",
491
+ "code",
492
+ "embed",
493
+ "h1",
494
+ "h2",
495
+ "h3",
496
+ "h4",
497
+ "h5",
498
+ "h6",
499
+ "hr",
500
+ "html",
501
+ "iframe",
502
+ "img",
503
+ "input",
504
+ "input:where([type='button'],[type='reset'],[type='submit'])",
505
+ "kbd",
506
+ "menu",
507
+ "object",
508
+ "ol",
509
+ "optgroup",
510
+ "pre",
511
+ "progress",
512
+ "samp",
513
+ "select",
514
+ "select[multiple]optgroup",
515
+ "select[multiple]optgroupoption",
516
+ "select[size]optgroup",
517
+ "select[size]optgroupoption",
518
+ "small",
519
+ "strong",
520
+ "sub",
521
+ "summary",
522
+ "sup",
523
+ "svg",
524
+ "table",
525
+ "textarea",
526
+ "ul",
527
+ "video"
528
+ ]);
529
+ function normalizeSelector$1(selector) {
530
+ return selector.trim().replace(/\s+/g, "");
531
+ }
532
+ function getRuleSelectors(rule) {
533
+ return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
534
+ }
535
+ function isUnsupportedBrowserSelector(selector) {
536
+ const normalized = normalizeSelector$1(selector);
537
+ return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
538
+ }
539
+ function isMiniProgramPreflightSelector(selectors) {
540
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
541
+ }
542
+ function isMiniProgramThemeScopeSelector(selectors) {
543
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
544
+ }
545
+ //#endregion
546
+ //#region src/compat/mini-program-css/predicates.ts
547
+ const PREFLIGHT_RESET_PROPS = new Set([
548
+ "box-sizing",
549
+ "border",
550
+ "border-width",
551
+ "border-style",
552
+ "border-color",
553
+ "margin",
554
+ "padding"
555
+ ]);
556
+ const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
557
+ const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
558
+ function hasTailwindPreflightDeclaration(rule) {
559
+ let hasTailwindVar = false;
560
+ let hasResetProp = false;
561
+ rule.walkDecls((decl) => {
562
+ if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
563
+ if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
564
+ });
565
+ return hasTailwindVar || hasResetProp;
566
+ }
567
+ function hasTwContentDeclaration(rule) {
568
+ let hasContentInit = false;
569
+ rule.walkDecls("--tw-content", () => {
570
+ hasContentInit = true;
571
+ });
572
+ return hasContentInit;
573
+ }
574
+ function isCustomPropertyRule(rule) {
575
+ let hasDeclaration = false;
576
+ let allCustomProperties = true;
577
+ rule.each((node) => {
578
+ if (node.type !== "decl") return;
579
+ hasDeclaration = true;
580
+ if (!node.prop.startsWith("--")) allCustomProperties = false;
581
+ });
582
+ return hasDeclaration && allCustomProperties;
583
+ }
584
+ function isEmptyTwContentDeclaration(decl) {
585
+ return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
586
+ }
587
+ function isOnlyTwContentDeclarations(rule) {
588
+ let hasDeclaration = false;
589
+ let onlyContentVariable = true;
590
+ rule.walkDecls((decl) => {
591
+ hasDeclaration = true;
592
+ if (decl.prop !== "--tw-content") onlyContentVariable = false;
593
+ });
594
+ return hasDeclaration && onlyContentVariable;
595
+ }
596
+ function isPseudoContentInitRule(rule) {
597
+ const selector = rule.selector.replace(/\s+/g, "");
598
+ return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations(rule);
599
+ }
600
+ function usesTwContentVariable(root) {
601
+ let used = false;
602
+ root.walkDecls((decl) => {
603
+ if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
604
+ });
605
+ return used;
606
+ }
607
+ function isMiniProgramPreflightRule(node) {
608
+ if (node.type !== "rule") return false;
609
+ return isMiniProgramPreflightSelector(getRuleSelectors(node)) && hasTailwindPreflightDeclaration(node);
610
+ }
611
+ function isMiniProgramThemeVariableRule(node) {
612
+ if (node.type !== "rule") return false;
613
+ return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
614
+ }
615
+ //#endregion
616
+ //#region src/compat/mini-program-css/root-cleanups.ts
617
+ function removeSpecificityPlaceholders(root) {
618
+ root.walkRules((rule) => {
619
+ if (!rule.selectors || rule.selectors.length === 0) return;
620
+ let changed = false;
621
+ const selectors = rule.selectors.map((selector) => {
622
+ let next = selector;
623
+ for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
624
+ if (next !== selector) changed = true;
625
+ return next;
626
+ });
627
+ if (changed) rule.selectors = selectors;
628
+ });
629
+ }
630
+ function removeEmptyAtRuleAncestors(parent) {
631
+ while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
632
+ const nextParent = parent.parent;
633
+ parent.remove();
634
+ parent = nextParent?.type === "atrule" ? nextParent : void 0;
635
+ }
636
+ }
637
+ function removeUnsupportedBrowserSelectors(root) {
638
+ root.walkRules((rule) => {
639
+ if (!rule.selectors || rule.selectors.length === 0) return;
640
+ const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
641
+ if (selectors.length === rule.selectors.length) return;
642
+ if (selectors.length === 0) {
643
+ const parent = rule.parent;
644
+ rule.remove();
645
+ removeEmptyAtRuleAncestors(parent);
646
+ return;
647
+ }
648
+ rule.selectors = selectors;
649
+ });
650
+ }
651
+ function removeDeclarationAndEmptyRule$1(decl) {
652
+ const parent = decl.parent;
653
+ decl.remove();
654
+ if (parent?.type === "rule" && parent.nodes.length === 0) {
655
+ const ruleParent = parent.parent;
656
+ parent.remove();
657
+ removeEmptyAtRuleAncestors(ruleParent);
658
+ }
659
+ }
660
+ function removeDisplayP3Declarations(root) {
661
+ root.walkAtRules((atRule) => {
662
+ if (isDisplayP3MediaRule(atRule)) {
663
+ const parent = atRule.parent;
664
+ atRule.remove();
665
+ removeEmptyAtRuleAncestors(parent);
666
+ }
667
+ });
668
+ }
669
+ function removeUnsupportedModernColorDeclarations(root) {
670
+ const customPropertyValues = /* @__PURE__ */ new Map();
671
+ root.walkDecls((decl) => {
672
+ if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
673
+ });
674
+ root.walkDecls((decl) => {
675
+ const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
676
+ if (normalized.changed) {
677
+ decl.value = normalized.value;
678
+ if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
679
+ }
680
+ if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
681
+ });
682
+ }
683
+ //#endregion
684
+ //#region src/compat/mini-program-css/finalize.ts
685
+ const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
686
+ function createPseudoContentInitRule() {
687
+ const rule = postcss.default.rule({ selector: "::before,\n::after" });
688
+ rule.append({
689
+ prop: "--tw-content",
690
+ value: "''"
691
+ });
692
+ return rule;
693
+ }
694
+ function collectPreflightRules(root, options = {}) {
695
+ const preflightNodes = [];
696
+ let hasContentInit = false;
697
+ for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
698
+ preflightNodes.push(node);
699
+ if (hasTwContentDeclaration(node)) hasContentInit = true;
700
+ }
701
+ if (preflightNodes.length === 0) return [];
702
+ const clonedPreflightRules = preflightNodes.map((node) => node.clone());
703
+ const contentInitRules = options.preservePseudoContentInit ? clonedPreflightRules.filter((rule) => hasTwContentDeclaration(rule)) : [];
704
+ const otherPreflightRules = clonedPreflightRules.filter((rule) => !hasTwContentDeclaration(rule));
705
+ const preflightRules = hasContentInit ? [...contentInitRules, ...otherPreflightRules] : [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...otherPreflightRules];
706
+ for (const node of preflightNodes) node.remove();
707
+ return preflightRules;
708
+ }
709
+ function createPreflightResetRule(cssPreflight) {
710
+ if (!cssPreflight || typeof cssPreflight !== "object") return;
711
+ const rule = postcss.default.rule({ selector: "view,text,:after,:before" });
712
+ for (const [prop, value] of Object.entries(cssPreflight)) {
713
+ if (value === false) continue;
714
+ rule.append({
715
+ prop,
716
+ value: value.toString()
717
+ });
718
+ }
719
+ return rule.nodes?.length ? rule : void 0;
720
+ }
721
+ function collectThemeVariableRule(root, options = {}) {
722
+ const themeRules = [];
723
+ const declarations = /* @__PURE__ */ new Map();
724
+ const shouldPreserveContentInit = options.preservePseudoContentInit || usesTwContentVariable(root);
725
+ for (const node of root.nodes ?? []) {
726
+ if (!isMiniProgramThemeVariableRule(node)) continue;
727
+ themeRules.push(node);
728
+ node.walkDecls((decl) => {
729
+ if (isDisplayP3Declaration(decl)) return;
730
+ if (!shouldPreserveContentInit && isEmptyTwContentDeclaration(decl)) return;
731
+ declarations.set(decl.prop, decl.clone());
732
+ });
733
+ }
734
+ for (const rule of themeRules) rule.remove();
735
+ if (declarations.size === 0) return;
736
+ const rule = postcss.default.rule({ selector: MINI_PROGRAM_THEME_SCOPE_SELECTOR });
737
+ for (const decl of declarations.values()) rule.append(decl);
738
+ return rule;
739
+ }
740
+ function getTopDirectiveTail(root) {
741
+ let tail;
742
+ for (const node of root.nodes ?? []) {
743
+ if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
744
+ tail = node;
745
+ continue;
746
+ }
747
+ break;
748
+ }
749
+ return tail;
750
+ }
751
+ function createHoistInsertionAnchor(root) {
752
+ for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
753
+ const anchor = postcss.default.comment({ text: HOIST_ANCHOR_COMMENT });
754
+ node.before(anchor);
755
+ return anchor;
756
+ }
757
+ }
758
+ function insertHoistedRules(root, rules, anchor) {
759
+ if (anchor && !anchor.parent) anchor = void 0;
760
+ if (rules.length === 0) {
761
+ anchor?.remove();
762
+ return;
763
+ }
764
+ const topDirectiveTail = getTopDirectiveTail(root);
765
+ const firstRule = rules[0];
766
+ if (!firstRule) return;
767
+ if (anchor) {
768
+ if (anchor.raws.before === void 0) delete firstRule.raws.before;
769
+ else firstRule.raws.before = anchor.raws.before;
770
+ anchor.replaceWith(rules);
771
+ return;
772
+ }
773
+ firstRule.raws.before = topDirectiveTail ? "\n" : "";
774
+ if (topDirectiveTail) topDirectiveTail.after(rules);
775
+ else root.prepend(rules);
776
+ }
777
+ function unwrapTailwindSourceMedia(root) {
778
+ root.walkAtRules("media", (atRule) => {
779
+ if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
780
+ });
781
+ }
782
+ function finalizeMiniProgramCssRoot(root, options = {}) {
783
+ removeUnsupportedCascadeLayers(root);
784
+ unwrapTailwindSourceMedia(root);
785
+ root.walkAtRules("property", (atRule) => {
786
+ atRule.remove();
787
+ });
788
+ removeSpecificityPlaceholders(root);
789
+ removeUnsupportedBrowserSelectors(root);
790
+ removeDisplayP3Declarations(root);
791
+ removeUnsupportedModernColorDeclarations(root);
792
+ root.walkDecls((decl) => {
793
+ normalizeMiniProgramPrefixedDeclaration(decl);
794
+ });
795
+ root.walkAtRules((atRule) => {
796
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
797
+ });
798
+ const hoistAnchor = createHoistInsertionAnchor(root);
799
+ const preflightRules = collectPreflightRules(root, options);
800
+ if (preflightRules.length === 0) {
801
+ const resetRule = createPreflightResetRule(options.cssPreflight);
802
+ if (resetRule) preflightRules.push(resetRule);
803
+ }
804
+ const themeRule = collectThemeVariableRule(root, options);
805
+ insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
806
+ }
807
+ function hoistTailwindPreflightBase(css) {
808
+ try {
809
+ const root = postcss.default.parse(css);
810
+ insertHoistedRules(root, collectPreflightRules(root, { preservePseudoContentInit: true }));
811
+ return root.toString();
812
+ } catch {
813
+ return css;
814
+ }
815
+ }
816
+ function finalizeMiniProgramCss(css, options = {}) {
817
+ const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
818
+ try {
819
+ const root = postcss.default.parse(cleanedCss);
820
+ finalizeMiniProgramCssRoot(root, options);
821
+ return root.toString();
822
+ } catch {
823
+ return cleanedCss;
824
+ }
825
+ }
826
+ //#endregion
827
+ //#region src/compat/mini-program-css/prune-generated.ts
828
+ const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
829
+ const DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE = "view,text,:before,:after";
830
+ const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
831
+ const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
832
+ "view",
833
+ "text",
834
+ ":before",
835
+ ":after",
836
+ "::before",
837
+ "::after"
838
+ ]);
839
+ function hasClassSelector$2(selector) {
840
+ return CLASS_SELECTOR_RE$1.test(selector);
841
+ }
842
+ function removeEmptyContentInitDeclarations(rule) {
843
+ rule.walkDecls((decl) => {
844
+ if (isEmptyTwContentDeclaration(decl)) decl.remove();
845
+ });
846
+ }
847
+ function isMiniProgramElementVariableScopeRule(rule) {
848
+ const selectors = getRuleSelectors(rule);
849
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS.has(selector));
850
+ }
851
+ function isTailwindV4GradientRuntimeDeclaration(decl) {
852
+ return decl.prop.startsWith("--tw-gradient-");
853
+ }
854
+ function moveTailwindV4GradientRuntimeDeclarations(rule) {
855
+ const gradientDeclarations = [];
856
+ rule.walkDecls((decl) => {
857
+ if (isTailwindV4GradientRuntimeDeclaration(decl)) {
858
+ gradientDeclarations.push(decl.clone());
859
+ decl.remove();
860
+ }
861
+ });
862
+ if (gradientDeclarations.length > 0) rule.before(new postcss.default.Rule({
863
+ selector: DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE,
864
+ nodes: gradientDeclarations
865
+ }));
866
+ if (rule.nodes.length === 0) rule.remove();
867
+ }
868
+ function isKeyframesRule(rule) {
869
+ let parent = rule.parent;
870
+ while (parent) {
871
+ if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
872
+ parent = parent.parent;
873
+ }
874
+ return false;
875
+ }
876
+ /**
877
+ * 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
878
+ */
879
+ function pruneMiniProgramGeneratedCss(css, options = {}) {
880
+ const root = postcss.default.parse(css);
881
+ const shouldPreserveContentInit = options.preservePreflight || usesTwContentVariable(root);
882
+ root.walkComments((comment) => {
883
+ comment.remove();
884
+ });
885
+ removeUnsupportedCascadeLayers(root);
886
+ removeUnsupportedModernColorDeclarations(root);
887
+ root.walkAtRules("supports", (atRule) => {
888
+ atRule.remove();
889
+ });
890
+ root.walkAtRules((atRule) => {
891
+ removeUnsupportedMiniProgramPrefixedAtRule(atRule);
892
+ });
893
+ root.walkDecls((decl) => {
894
+ normalizeMiniProgramPrefixedDeclaration(decl);
895
+ });
896
+ root.walkRules((rule) => {
897
+ if (isKeyframesRule(rule)) return;
898
+ if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
899
+ rule.selector = DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE;
900
+ return;
901
+ }
902
+ if (isMiniProgramThemeVariableRule(rule)) {
903
+ moveTailwindV4GradientRuntimeDeclarations(rule);
904
+ if (!rule.parent) return;
905
+ rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
906
+ return;
907
+ }
908
+ if (hasClassSelector$2(rule.selector)) return;
909
+ if (!shouldPreserveContentInit) removeEmptyContentInitDeclarations(rule);
910
+ if (isPseudoContentInitRule(rule)) {
911
+ if (!shouldPreserveContentInit) rule.remove();
912
+ return;
913
+ }
914
+ if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
915
+ if (isCustomPropertyRule(rule)) {
916
+ moveTailwindV4GradientRuntimeDeclarations(rule);
917
+ if (!rule.parent) return;
918
+ rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
919
+ return;
920
+ }
921
+ rule.remove();
922
+ });
923
+ root.walkAtRules((atRule) => {
924
+ if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
925
+ });
926
+ return root.toString();
927
+ }
928
+ //#endregion
367
929
  //#region src/compat/uni-app-x.ts
368
930
  const UNI_APP_X_BASE_CARRIER_SELECTORS = new Set([
369
931
  "*",
@@ -1935,6 +2497,78 @@ function normalizeCalcValue(value) {
1935
2497
  function hasVariableReference(value) {
1936
2498
  return value.includes("var(");
1937
2499
  }
2500
+ function splitTopLevelCommaList(value) {
2501
+ const parts = [];
2502
+ let start = 0;
2503
+ let depth = 0;
2504
+ let quote;
2505
+ let escaped = false;
2506
+ for (let i = 0; i < value.length; i++) {
2507
+ const char = value[i];
2508
+ if (escaped) {
2509
+ escaped = false;
2510
+ continue;
2511
+ }
2512
+ if (char === "\\") {
2513
+ escaped = true;
2514
+ continue;
2515
+ }
2516
+ if (quote) {
2517
+ if (char === quote) quote = void 0;
2518
+ continue;
2519
+ }
2520
+ if (char === "\"" || char === "'") {
2521
+ quote = char;
2522
+ continue;
2523
+ }
2524
+ if (char === "(") {
2525
+ depth++;
2526
+ continue;
2527
+ }
2528
+ if (char === ")") {
2529
+ depth = Math.max(0, depth - 1);
2530
+ continue;
2531
+ }
2532
+ if (char === "," && depth === 0) {
2533
+ parts.push(value.slice(start, i));
2534
+ start = i + 1;
2535
+ }
2536
+ }
2537
+ parts.push(value.slice(start));
2538
+ return parts;
2539
+ }
2540
+ function getTransitionPropertySet(value) {
2541
+ const items = splitTopLevelCommaList(value).map((item) => item.trim().toLowerCase()).filter(Boolean);
2542
+ return items.length > 0 ? new Set(items) : void 0;
2543
+ }
2544
+ function isSubsetOfSet(subset, superset) {
2545
+ for (const item of subset) if (!superset.has(item)) return false;
2546
+ return true;
2547
+ }
2548
+ function removeRedundantTransitionPropertyFallbacks(rule) {
2549
+ const entries = rule.nodes.filter((node) => node.type === "decl" && node.prop.toLowerCase() === "transition-property").map((decl) => ({
2550
+ decl,
2551
+ items: getTransitionPropertySet(decl.value)
2552
+ }));
2553
+ for (let i = 0; i < entries.length; i++) {
2554
+ const entry = entries[i];
2555
+ if (!entry?.items) continue;
2556
+ for (let j = i + 1; j < entries.length; j++) {
2557
+ const next = entries[j];
2558
+ if (!next?.items) continue;
2559
+ if (next.items.size === entry.items.size && isSubsetOfSet(entry.items, next.items)) {
2560
+ next.decl.remove();
2561
+ entries.splice(j, 1);
2562
+ j--;
2563
+ continue;
2564
+ }
2565
+ if (next.items.size > entry.items.size && isSubsetOfSet(entry.items, next.items)) {
2566
+ entry.decl.remove();
2567
+ break;
2568
+ }
2569
+ }
2570
+ }
2571
+ }
1938
2572
  function dedupeDeclarations(rule) {
1939
2573
  const entries = [];
1940
2574
  for (const node of [...rule.nodes]) {
@@ -1986,6 +2620,7 @@ function dedupeDeclarations(rule) {
1986
2620
  if (literalSeen.get(canonical)) node.remove();
1987
2621
  else literalSeen.set(canonical, node);
1988
2622
  }
2623
+ removeRedundantTransitionPropertyFallbacks(rule);
1989
2624
  }
1990
2625
  //#endregion
1991
2626
  //#region src/plugins/post/specificity-cleaner.ts
@@ -2135,6 +2770,9 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
2135
2770
  root.walkDecls((decl) => {
2136
2771
  normalizeMiniProgramPrefixedDeclaration(decl);
2137
2772
  });
2773
+ root.walkRules((rule) => {
2774
+ removeRedundantTransitionPropertyFallbacks(rule);
2775
+ });
2138
2776
  root.walkAtRules((atRule) => {
2139
2777
  removeUnsupportedMiniProgramPrefixedAtRule(atRule);
2140
2778
  });
@@ -2864,9 +3502,15 @@ exports.createFallbackPlaceholderReplacer = createFallbackPlaceholderReplacer;
2864
3502
  exports.createInjectPreflight = createInjectPreflight;
2865
3503
  exports.createStyleHandler = createStyleHandler;
2866
3504
  exports.createStylePipeline = createStylePipeline;
3505
+ exports.finalizeMiniProgramCss = finalizeMiniProgramCss;
3506
+ exports.hoistTailwindPreflightBase = hoistTailwindPreflightBase;
2867
3507
  exports.internalCssSelectorReplacer = internalCssSelectorReplacer;
2868
3508
  exports.normalizeMiniProgramPrefixedDeclaration = normalizeMiniProgramPrefixedDeclaration;
2869
3509
  exports.normalizeModernColorValue = normalizeModernColorValue;
2870
3510
  exports.postcssHtmlTransform = require_html_transform.postcssHtmlTransform;
2871
3511
  exports.protectDynamicColorMixAlpha = protectDynamicColorMixAlpha;
3512
+ exports.pruneMiniProgramGeneratedCss = pruneMiniProgramGeneratedCss;
3513
+ exports.removeUnsupportedAtSupports = removeUnsupportedAtSupports;
3514
+ exports.removeUnsupportedCascadeLayers = removeUnsupportedCascadeLayers;
3515
+ exports.removeUnsupportedMiniProgramAtRules = removeUnsupportedMiniProgramAtRules;
2872
3516
  exports.removeUnsupportedMiniProgramPrefixedAtRule = removeUnsupportedMiniProgramPrefixedAtRule;