@weapp-tailwindcss/postcss 3.2.6 → 3.2.7

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
@@ -129,6 +129,187 @@ function stripUnsupportedNodeForUniAppX(node, options) {
129
129
  function shouldRemoveEmptyRuleForUniAppX(rule, options) {
130
130
  return isUniAppXEnabled(options) && rule.nodes.length === 0;
131
131
  }
132
+ const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
133
+ "oklch",
134
+ "oklab",
135
+ "lch",
136
+ "lab"
137
+ ]);
138
+ const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
139
+ "rgb",
140
+ "rgba",
141
+ "hsl",
142
+ "hsla",
143
+ "hwb"
144
+ ]);
145
+ const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
146
+ const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
147
+ const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
148
+ const TRANSPARENT_COLOR_RE = /^transparent$/i;
149
+ const CURRENT_COLOR_RE = /^currentcolor$/i;
150
+ const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
151
+ const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
152
+ //#endregion
153
+ //#region src/compat/color-mix/modern.ts
154
+ function isDisplayP3ColorFunction(colorSource) {
155
+ return /^color\(\s*display-p3\b/i.test(colorSource.trim());
156
+ }
157
+ function isModernColorSyntaxFunction(colorSource) {
158
+ const parsed = valueParser(colorSource.trim());
159
+ const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
160
+ if (node?.type !== "function") return false;
161
+ const name = node.value.toLowerCase();
162
+ if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
163
+ return !node.nodes.some((child) => child.type === "div" && child.value === ",");
164
+ }
165
+ function hasUnsupportedModernColorFunction(value) {
166
+ const parsed = valueParser(value);
167
+ let hasUnsupported = false;
168
+ parsed.walk((node) => {
169
+ if (node.type !== "function") return;
170
+ const name = node.value.toLowerCase();
171
+ if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node)) || isModernColorSyntaxFunction(valueParser.stringify(node))) {
172
+ hasUnsupported = true;
173
+ return false;
174
+ }
175
+ });
176
+ return hasUnsupported;
177
+ }
178
+ //#endregion
179
+ //#region src/compat/color-mix/parse.ts
180
+ function splitArguments(nodes) {
181
+ const args = [];
182
+ let current = [];
183
+ for (const node of nodes) {
184
+ if (node.type === "div" && node.value === ",") {
185
+ args.push(current);
186
+ current = [];
187
+ continue;
188
+ }
189
+ current.push(node);
190
+ }
191
+ args.push(current);
192
+ return args;
193
+ }
194
+ function splitStopSegments(nodes) {
195
+ const segments = [];
196
+ let current = [];
197
+ for (const node of nodes) {
198
+ if (node.type === "space") {
199
+ if (current.length > 0) {
200
+ segments.push(current);
201
+ current = [];
202
+ }
203
+ continue;
204
+ }
205
+ current.push(node);
206
+ }
207
+ if (current.length > 0) segments.push(current);
208
+ return segments;
209
+ }
210
+ function trimNodes$1(nodes) {
211
+ let start = 0;
212
+ let end = nodes.length;
213
+ while (start < end && nodes[start]?.type === "space") start += 1;
214
+ while (end > start && nodes[end - 1]?.type === "space") end -= 1;
215
+ return nodes.slice(start, end);
216
+ }
217
+ function getParsedColorData(colorSource) {
218
+ try {
219
+ return color(parseComponentValue(tokenize({ css: colorSource })));
220
+ } catch {
221
+ return false;
222
+ }
223
+ }
224
+ function parseAlphaValue(alphaSource) {
225
+ const parsed = Number.parseFloat(alphaSource);
226
+ if (Number.isFinite(parsed)) return alphaSource.trim().endsWith("%") ? parsed / 100 : parsed;
227
+ }
228
+ function resolveVarColor(colorSource, customPropertyValues, depth = 0) {
229
+ if (depth > 5) return;
230
+ const parsed = valueParser(colorSource.trim());
231
+ const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
232
+ if (node?.type !== "function" || node.value.toLowerCase() !== "var") return;
233
+ const args = splitArguments(node.nodes);
234
+ const propertyName = valueParser.stringify(trimNodes$1(args[0] ?? [])).trim();
235
+ if (!CUSTOM_PROPERTY_RE.test(propertyName)) return;
236
+ const resolved = customPropertyValues.get(propertyName);
237
+ if (!resolved) {
238
+ const fallback = args[1] ? valueParser.stringify(trimNodes$1(args[1])).trim() : void 0;
239
+ return fallback ? resolveColorData(fallback, customPropertyValues, depth + 1) : void 0;
240
+ }
241
+ return resolveColorData(resolved, customPropertyValues, depth + 1);
242
+ }
243
+ function resolveColorData(colorSource, customPropertyValues, depth = 0) {
244
+ if (typeof colorSource !== "string") return;
245
+ const trimmed = colorSource.trim();
246
+ if (TRANSPARENT_COLOR_RE.test(trimmed)) return getParsedColorData(trimmed) || void 0;
247
+ if (CURRENT_COLOR_RE.test(trimmed) || CSS_WIDE_KEYWORD_RE.test(trimmed)) return;
248
+ const resolvedVar = resolveVarColor(trimmed, customPropertyValues, depth);
249
+ if (resolvedVar) return resolvedVar;
250
+ return getParsedColorData(trimmed) || void 0;
251
+ }
252
+ function normalizeColorFunctionName(colorSource, alpha, customPropertyValues) {
253
+ const resolvedColor = resolveColorData(colorSource, customPropertyValues);
254
+ if (!resolvedColor) return;
255
+ resolvedColor.alpha = alpha;
256
+ return serializeRGB(resolvedColor).toString();
257
+ }
258
+ function normalizeColorFunctionWithDynamicAlpha(colorSource, alphaSource, customPropertyValues) {
259
+ const resolvedColor = resolveColorData(colorSource, customPropertyValues);
260
+ const alphaColor = getParsedColorData(`rgb(0 0 0 / ${alphaSource})`);
261
+ if (!resolvedColor || !alphaColor || typeof alphaColor.alpha === "number") return;
262
+ resolvedColor.alpha = alphaColor.alpha;
263
+ return serializeRGB(resolvedColor).toString();
264
+ }
265
+ function normalizeStandaloneColorFunction(colorSource) {
266
+ const resolvedColor = getParsedColorData(colorSource);
267
+ return resolvedColor ? serializeRGB(resolvedColor).toString() : void 0;
268
+ }
269
+ //#endregion
270
+ //#region src/compat/color-mix/resolve.ts
271
+ function createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues) {
272
+ const alpha = alphaSource.trim();
273
+ return normalizeColorFunctionWithDynamicAlpha(colorSource, CUSTOM_PROPERTY_RE.test(alpha) ? `var(${alpha})` : alpha, customPropertyValues);
274
+ }
275
+ function tryResolveColorMix(node, customPropertyValues) {
276
+ const args = splitArguments(node.nodes);
277
+ if (args.length < 3) return;
278
+ const colorStopNodes = splitStopSegments(args[1] ?? []);
279
+ if (colorStopNodes.length < 2) return;
280
+ const colorNodes = trimNodes$1(colorStopNodes[0] ?? []);
281
+ const alphaNodes = trimNodes$1(colorStopNodes[1] ?? []);
282
+ const trailingNodes = trimNodes$1(args[2] ?? []);
283
+ if (!colorNodes.length || !alphaNodes.length || valueParser.stringify(trailingNodes).trim().toLowerCase() !== "transparent") return;
284
+ const colorSource = valueParser.stringify(colorNodes).trim();
285
+ const alphaSource = valueParser.stringify(alphaNodes).trim();
286
+ if (!colorSource || !alphaSource || INTERNAL_TAILWIND_ALPHA_RE.test(alphaSource)) return;
287
+ if (CURRENT_COLOR_RE.test(colorSource)) return {
288
+ value: colorSource,
289
+ deferred: false
290
+ };
291
+ if (DYNAMIC_ALPHA_RE.test(alphaSource)) {
292
+ const normalized = createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues);
293
+ return normalized ? {
294
+ value: normalized,
295
+ deferred: true
296
+ } : {
297
+ value: colorSource,
298
+ deferred: true
299
+ };
300
+ }
301
+ const alpha = parseAlphaValue(alphaSource);
302
+ if (alpha === void 0) return;
303
+ const normalized = normalizeColorFunctionName(colorSource, alpha, customPropertyValues);
304
+ if (normalized) return {
305
+ value: normalized,
306
+ deferred: false
307
+ };
308
+ return {
309
+ value: colorSource,
310
+ deferred: false
311
+ };
312
+ }
132
313
  //#endregion
133
314
  //#region src/cssVarsV4.ts
134
315
  function property(ident, initialValue, _syntax) {
@@ -383,52 +564,599 @@ function createMissingCssVarsV4Nodes(root, usedProps) {
383
564
  }));
384
565
  }
385
566
  //#endregion
386
- //#region src/compat/tailwindcss-v4/gradients.ts
387
- function collectTailwindcssV4ThemeVariables(root) {
388
- const variables = /* @__PURE__ */ new Map();
389
- root.walkRules((rule) => {
390
- if (!testIfRootHostForV4(rule) && !rule.selector.includes("page") && !rule.selector.includes(".tw-root")) return;
391
- rule.walkDecls((decl) => {
392
- if (decl.prop.startsWith("--color-")) variables.set(decl.prop, decl.value);
393
- });
394
- });
395
- return variables;
396
- }
397
- function resolveTailwindcssV4GradientColor(value, themeVariables) {
398
- const trimmed = value.trim();
399
- const match = COLOR_VAR_RE.exec(trimmed);
400
- if (!match) return trimmed;
401
- return themeVariables.get(match[1]) ?? trimmed;
402
- }
403
- function getSingleClassSelector(selector) {
404
- const match = SIMPLE_CLASS_SELECTOR_RE.exec(selector.trim());
405
- return match ? match[1] : void 0;
406
- }
407
- function normalizeDeclarationValue(value) {
408
- return value.replace(/\s+/g, " ").trim();
409
- }
410
- function normalizeTailwindcssV4GradientPosition(value) {
411
- return value.replace(/calc\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn))\s*\*\s*-1\s*\)/gi, "-$1").replace(/^in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?$/i, "").replace(/\s+in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?\s*$/i, "").replace(/\s+(?:longer|shorter|increasing|decreasing)\s*$/i, "").trim();
412
- }
413
- function normalizeTailwindcssV4InfinityCalcValue(value) {
414
- return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
415
- }
416
- const INFINITY_CALC_CSS_RE = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)/gi;
417
- /** 在预处理器解析前收敛 Tailwind v4 生成的无限圆角,避免 Sass 将 infinity 当作非法表达式。 */
418
- function normalizeTailwindcssV4InfinityCalcCss(css) {
419
- return css.replace(INFINITY_CALC_CSS_RE, `${CLAMP_PX}px`);
567
+ //#region src/compat/color-mix.ts
568
+ const DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX = "__weapp_tw_var_fallback_";
569
+ function getStandaloneDynamicVarWithFallback(value) {
570
+ const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
571
+ const variable = nodes.length === 1 ? nodes[0] : void 0;
572
+ const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
573
+ if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
574
+ return variable;
420
575
  }
421
- function normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl) {
422
- const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
423
- if (normalized) return normalized;
424
- const backgroundImageDecl = rule.nodes.find((node) => {
425
- return node.type === "decl" && node.prop === "background-image";
576
+ /**
577
+ * 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
578
+ */
579
+ function protectDynamicVarFallbacks(css) {
580
+ if (!css.includes("var(") || !css.includes(",")) return {
581
+ css,
582
+ restore: (value) => value
583
+ };
584
+ const replacements = /* @__PURE__ */ new Map();
585
+ let root;
586
+ try {
587
+ root = postcss$1.parse(css);
588
+ } catch {
589
+ return {
590
+ css,
591
+ restore: (value) => value
592
+ };
593
+ }
594
+ root.walkDecls((decl) => {
595
+ if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
596
+ const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
597
+ replacements.set(placeholder, decl.value);
598
+ decl.value = placeholder;
426
599
  });
427
- if (!backgroundImageDecl) return normalized;
428
- if (/^radial-gradient\(/i.test(backgroundImageDecl.value)) return "at center";
429
- if (/^conic-gradient\(/i.test(backgroundImageDecl.value)) return "from 0deg";
430
- return normalized;
431
- }
600
+ if (replacements.size === 0) return {
601
+ css,
602
+ restore: (value) => value
603
+ };
604
+ return {
605
+ css: root.toString(),
606
+ restore(value) {
607
+ let restored = value;
608
+ for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
609
+ return restored;
610
+ }
611
+ };
612
+ }
613
+ function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
614
+ if (!hasUnsupportedModernColorFunction(value)) return {
615
+ value,
616
+ changed: false,
617
+ hasUnsupported: false
618
+ };
619
+ const parsed = valueParser(value);
620
+ let changed = false;
621
+ parsed.walk((node) => {
622
+ if (node.type !== "function") return;
623
+ const name = node.value.toLowerCase();
624
+ const source = valueParser.stringify(node);
625
+ let normalized;
626
+ if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
627
+ else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
628
+ if (!normalized) return;
629
+ const mutableNode = node;
630
+ mutableNode.type = "word";
631
+ mutableNode.value = normalized;
632
+ delete mutableNode.nodes;
633
+ changed = true;
634
+ });
635
+ const nextValue = changed ? parsed.toString() : value;
636
+ return {
637
+ value: nextValue,
638
+ changed,
639
+ hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
640
+ };
641
+ }
642
+ function createPlaceholder(index) {
643
+ return `${PLACEHOLDER_PREFIX}${index}__`;
644
+ }
645
+ function unwrapProtectedSupports(cssRoot) {
646
+ cssRoot.walkAtRules("supports", (atRule) => {
647
+ if (!atRule.nodes || !atRule.toString().includes("__weapp_tw_color_mix_")) return;
648
+ atRule.replaceWith(atRule.nodes);
649
+ });
650
+ }
651
+ function protectDynamicColorMixAlpha(css, options = {}) {
652
+ if (!css.includes("color-mix")) return {
653
+ css,
654
+ restore: (value) => value
655
+ };
656
+ const replacements = /* @__PURE__ */ new Map();
657
+ const root = postcss$1.parse(css);
658
+ const customPropertyValues = new Map(options.customPropertyValues);
659
+ let changed = false;
660
+ root.walkDecls((decl) => {
661
+ if (decl.prop.startsWith("--") && !decl.value.includes("color-mix")) customPropertyValues.set(decl.prop, decl.value.trim());
662
+ });
663
+ root.walkDecls((decl) => {
664
+ if (!decl.value.includes("color-mix")) return;
665
+ const parsed = valueParser(decl.value);
666
+ let mutated = false;
667
+ parsed.walk((node) => {
668
+ if (node.type !== "function" || node.value.toLowerCase() !== "color-mix") return;
669
+ const resolved = tryResolveColorMix(node, customPropertyValues);
670
+ if (resolved) {
671
+ if (resolved.deferred) {
672
+ const placeholder = createPlaceholder(replacements.size);
673
+ replacements.set(placeholder, resolved.value);
674
+ const mutableNode = node;
675
+ mutableNode.type = "word";
676
+ mutableNode.value = placeholder;
677
+ delete mutableNode.nodes;
678
+ mutated = true;
679
+ return;
680
+ }
681
+ const mutableNode = node;
682
+ mutableNode.type = "word";
683
+ mutableNode.value = resolved.value;
684
+ delete mutableNode.nodes;
685
+ mutated = true;
686
+ }
687
+ });
688
+ if (mutated) {
689
+ decl.value = parsed.toString();
690
+ changed = true;
691
+ }
692
+ });
693
+ if (replacements.size > 0) unwrapProtectedSupports(root);
694
+ return {
695
+ css: changed ? root.toString() : css,
696
+ restore(value) {
697
+ let restored = value;
698
+ for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
699
+ return restored;
700
+ }
701
+ };
702
+ }
703
+ //#endregion
704
+ //#region src/compat/mini-program-css/color-gamut.ts
705
+ const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
706
+ const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
707
+ function isDisplayP3MediaRule(atRule) {
708
+ return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
709
+ }
710
+ function isDisplayP3Declaration(decl) {
711
+ return DISPLAY_P3_VALUE_RE.test(decl.value);
712
+ }
713
+ //#endregion
714
+ //#region src/compat/mini-program-css/selectors.ts
715
+ const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
716
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
717
+ const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
718
+ "view",
719
+ "text",
720
+ ":before",
721
+ ":after",
722
+ "::before",
723
+ "::after"
724
+ ]);
725
+ const MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS = /* @__PURE__ */ new Set([
726
+ ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS,
727
+ "button",
728
+ "input",
729
+ "textarea",
730
+ "canvas",
731
+ "video",
732
+ "audio"
733
+ ]);
734
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS$1 = /* @__PURE__ */ new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
735
+ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
736
+ ":host",
737
+ ":root",
738
+ "page",
739
+ ".tw-root",
740
+ "wx-root-portal-content"
741
+ ]);
742
+ function normalizeMiniProgramThemeScopeSelector(root) {
743
+ if (root === false) return ":host";
744
+ if (root === void 0) return MINI_PROGRAM_THEME_SCOPE_SELECTOR;
745
+ const selectors = Array.isArray(root) ? root.filter(Boolean) : [root];
746
+ return [.../* @__PURE__ */ new Set([":host", ...selectors])].join(",");
747
+ }
748
+ const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
749
+ const ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(.does-not-exist)"];
750
+ const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = /* @__PURE__ */ new Set([
751
+ ":-moz-focusring",
752
+ ":-moz-ui-invalid",
753
+ "::-webkit-calendar-picker-indicator",
754
+ "::-webkit-date-and-time-value",
755
+ "::-webkit-datetime-edit",
756
+ "::-webkit-datetime-edit-day-field",
757
+ "::-webkit-datetime-edit-fields-wrapper",
758
+ "::-webkit-datetime-edit-hour-field",
759
+ "::-webkit-datetime-edit-meridiem-field",
760
+ "::-webkit-datetime-edit-millisecond-field",
761
+ "::-webkit-datetime-edit-minute-field",
762
+ "::-webkit-datetime-edit-month-field",
763
+ "::-webkit-datetime-edit-second-field",
764
+ "::-webkit-datetime-edit-year-field",
765
+ "::-webkit-inner-spin-button",
766
+ "::-webkit-input-placeholder",
767
+ "::-webkit-outer-spin-button",
768
+ "::-webkit-search-decoration",
769
+ "::placeholder",
770
+ "[hidden]:where(:not([hidden='until-found']))"
771
+ ]);
772
+ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = /* @__PURE__ */ new Set([
773
+ "a",
774
+ "abbr:where([title])",
775
+ "audio",
776
+ "b",
777
+ "button",
778
+ "canvas",
779
+ "code",
780
+ "embed",
781
+ "h1",
782
+ "h2",
783
+ "h3",
784
+ "h4",
785
+ "h5",
786
+ "h6",
787
+ "hr",
788
+ "html",
789
+ "iframe",
790
+ "img",
791
+ "input",
792
+ "input:where([type='button'],[type='reset'],[type='submit'])",
793
+ "kbd",
794
+ "menu",
795
+ "object",
796
+ "ol",
797
+ "optgroup",
798
+ "pre",
799
+ "progress",
800
+ "samp",
801
+ "select",
802
+ "select[multiple]optgroup",
803
+ "select[multiple]optgroupoption",
804
+ "select[size]optgroup",
805
+ "select[size]optgroupoption",
806
+ "small",
807
+ "strong",
808
+ "sub",
809
+ "summary",
810
+ "sup",
811
+ "svg",
812
+ "table",
813
+ "textarea",
814
+ "ul",
815
+ "video"
816
+ ]);
817
+ const MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS = /* @__PURE__ */ new Set([...MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS, "::file-selector-button"]);
818
+ function normalizeSelector$2(selector) {
819
+ return selector.trim().replace(/\s+/g, "");
820
+ }
821
+ function normalizePseudoElementSelector(selector) {
822
+ return normalizeSelector$2(selector).replace(/^:(before|after)$/, "::$1");
823
+ }
824
+ function getRuleSelectors(rule) {
825
+ return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
826
+ }
827
+ function getSortedRuleSelectorKey(rule) {
828
+ return getRuleSelectors(rule).sort().join(",");
829
+ }
830
+ function isUnsupportedBrowserSelector(selector) {
831
+ const normalized = normalizeSelector$2(selector);
832
+ return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized) && !MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalized);
833
+ }
834
+ function isUnsupportedBrowserPreflightSelector(selector) {
835
+ const normalizedParts = selector.split(",").map(normalizeSelector$2).filter(Boolean);
836
+ return normalizedParts.length > 1 && normalizedParts.every((part) => MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS.has(part));
837
+ }
838
+ function isMiniProgramNativeElementSelector(selector) {
839
+ return MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalizePseudoElementSelector(selector));
840
+ }
841
+ function isMiniProgramPreflightSelector(selectors) {
842
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
843
+ }
844
+ function isMiniProgramThemeScopeSelector(selectors) {
845
+ return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
846
+ }
847
+ //#endregion
848
+ //#region src/compat/mini-program-css/predicates.ts
849
+ const PREFLIGHT_RESET_PROPS = /* @__PURE__ */ new Set([
850
+ "box-sizing",
851
+ "border",
852
+ "border-width",
853
+ "border-style",
854
+ "border-color",
855
+ "margin",
856
+ "padding"
857
+ ]);
858
+ const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
859
+ const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
860
+ const BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS = /* @__PURE__ */ new Map([["button", /* @__PURE__ */ new Set(["appearance:button", "-moz-appearance:button"])], ["textarea", /* @__PURE__ */ new Set(["resize:vertical"])]]);
861
+ function hasTailwindPreflightDeclaration(rule) {
862
+ let hasTailwindVar = false;
863
+ let hasResetProp = false;
864
+ rule.walkDecls((decl) => {
865
+ if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
866
+ if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
867
+ });
868
+ return hasTailwindVar || hasResetProp;
869
+ }
870
+ function hasTailwindVariableDeclaration(rule) {
871
+ let hasTailwindVar = false;
872
+ rule.walkDecls((decl) => {
873
+ if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
874
+ });
875
+ return hasTailwindVar;
876
+ }
877
+ function isCustomPropertyRule(rule) {
878
+ let hasDeclaration = false;
879
+ let allCustomProperties = true;
880
+ rule.each((node) => {
881
+ if (node.type !== "decl") return;
882
+ hasDeclaration = true;
883
+ if (!node.prop.startsWith("--")) allCustomProperties = false;
884
+ });
885
+ return hasDeclaration && allCustomProperties;
886
+ }
887
+ function isEmptyTwContentDeclaration(decl) {
888
+ return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
889
+ }
890
+ function isOnlyTwContentDeclarations$1(rule) {
891
+ let hasDeclaration = false;
892
+ let onlyContentVariable = true;
893
+ rule.walkDecls((decl) => {
894
+ hasDeclaration = true;
895
+ if (decl.prop !== "--tw-content") onlyContentVariable = false;
896
+ });
897
+ return hasDeclaration && onlyContentVariable;
898
+ }
899
+ function isPseudoContentInitRule(rule) {
900
+ const selector = rule.selector.replace(/\s+/g, "");
901
+ return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
902
+ }
903
+ function usesTwContentVariable(root) {
904
+ let used = false;
905
+ root.walkDecls((decl) => {
906
+ if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
907
+ });
908
+ return used;
909
+ }
910
+ function isMiniProgramPreflightRule(node) {
911
+ if (node.type !== "rule") return false;
912
+ const selectors = getRuleSelectors(node);
913
+ if (!isMiniProgramPreflightSelector(selectors)) return false;
914
+ if (selectors.includes("*")) return hasTailwindPreflightDeclaration(node);
915
+ if (hasTailwindVariableDeclaration(node)) return true;
916
+ return selectors.some((selector) => selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after") && selectors.some((selector) => selector === "view" || selector === "text") && hasTailwindPreflightDeclaration(node);
917
+ }
918
+ function isBrowserElementPreflightRule(node) {
919
+ if (node.type !== "rule") return false;
920
+ const selectors = getRuleSelectors(node);
921
+ if (selectors.length !== 1) return false;
922
+ const declarations = BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS.get(selectors[0]);
923
+ if (!declarations) return false;
924
+ let hasDeclaration = false;
925
+ let allBrowserPreflightDeclarations = true;
926
+ node.each((child) => {
927
+ if (child.type !== "decl") return;
928
+ hasDeclaration = true;
929
+ const key = `${child.prop.toLowerCase()}:${child.value.trim().toLowerCase()}`;
930
+ if (!declarations.has(key)) allBrowserPreflightDeclarations = false;
931
+ });
932
+ return hasDeclaration && allBrowserPreflightDeclarations;
933
+ }
934
+ function isMiniProgramThemeVariableRule(node) {
935
+ if (node.type !== "rule") return false;
936
+ return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
937
+ }
938
+ //#endregion
939
+ //#region src/compat/mini-program-css/root-cleanups.ts
940
+ function removeSpecificityPlaceholders(root) {
941
+ root.walkRules((rule) => {
942
+ if (!rule.selectors || rule.selectors.length === 0) return;
943
+ let changed = false;
944
+ const selectors = rule.selectors.map((selector) => {
945
+ let next = selector;
946
+ for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
947
+ if (next !== selector) changed = true;
948
+ return next;
949
+ });
950
+ if (changed) rule.selectors = selectors;
951
+ });
952
+ }
953
+ function hasMiniProgramCssSpecificityPlaceholders(source) {
954
+ return SPECIFICITY_PLACEHOLDER_SUFFIXES.some((suffix) => source.includes(suffix));
955
+ }
956
+ function stripMiniProgramCssSpecificityPlaceholders(source) {
957
+ let output = source;
958
+ for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
959
+ return output;
960
+ }
961
+ const removeSpecificityPlaceholdersFromSource = stripMiniProgramCssSpecificityPlaceholders;
962
+ function removeRootSpecificityPlaceholders(root) {
963
+ root.walkRules((rule) => {
964
+ if (!rule.selectors || rule.selectors.length === 0) return;
965
+ let changed = false;
966
+ const selectors = rule.selectors.map((selector) => {
967
+ let next = selector;
968
+ for (const scopeSelector of MINI_PROGRAM_THEME_SCOPE_SELECTORS) for (const suffix of ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES) {
969
+ const target = `${scopeSelector}${suffix}`;
970
+ if (next.includes(target)) next = next.split(target).join(scopeSelector);
971
+ }
972
+ if (next !== selector) changed = true;
973
+ return next;
974
+ });
975
+ if (changed) rule.selectors = selectors;
976
+ });
977
+ }
978
+ function isEffectivelyEmptyContainer(container) {
979
+ return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
980
+ }
981
+ function removeEmptyAtRules(root) {
982
+ let removed = 0;
983
+ const visit = (container) => {
984
+ for (const node of [...container.nodes ?? []]) {
985
+ if (!("nodes" in node) || node.nodes === void 0) continue;
986
+ visit(node);
987
+ if (node.type === "atrule" && node.parent && isEffectivelyEmptyContainer(node)) {
988
+ node.remove();
989
+ removed++;
990
+ }
991
+ }
992
+ };
993
+ visit(root);
994
+ return removed;
995
+ }
996
+ function removeEmptyBlockAtRules(root) {
997
+ let removed = 0;
998
+ root.walkAtRules((atRule) => {
999
+ if (atRule.nodes?.length === 0) {
1000
+ atRule.remove();
1001
+ removed++;
1002
+ }
1003
+ });
1004
+ return removed;
1005
+ }
1006
+ function removeEmptyAtRuleAncestors(parent) {
1007
+ while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
1008
+ const nextParent = parent.parent;
1009
+ parent.remove();
1010
+ parent = nextParent?.type === "atrule" ? nextParent : void 0;
1011
+ }
1012
+ }
1013
+ function removeUnsupportedBrowserSelectors(root) {
1014
+ root.walkRules((rule) => {
1015
+ if (!rule.selectors || rule.selectors.length === 0) return;
1016
+ if (isUnsupportedBrowserPreflightSelector(rule.selector)) {
1017
+ const parent = rule.parent;
1018
+ rule.remove();
1019
+ removeEmptyAtRuleAncestors(parent);
1020
+ return;
1021
+ }
1022
+ if (isBrowserElementPreflightRule(rule)) {
1023
+ const parent = rule.parent;
1024
+ rule.remove();
1025
+ removeEmptyAtRuleAncestors(parent);
1026
+ return;
1027
+ }
1028
+ const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
1029
+ if (selectors.length === rule.selectors.length) return;
1030
+ if (selectors.length === 0) {
1031
+ const parent = rule.parent;
1032
+ rule.remove();
1033
+ removeEmptyAtRuleAncestors(parent);
1034
+ return;
1035
+ }
1036
+ rule.selectors = selectors;
1037
+ });
1038
+ }
1039
+ function removeDeclarationAndEmptyRule$1(decl) {
1040
+ const parent = decl.parent;
1041
+ decl.remove();
1042
+ if (parent?.type === "rule" && parent.nodes.length === 0) {
1043
+ const ruleParent = parent.parent;
1044
+ parent.remove();
1045
+ removeEmptyAtRuleAncestors(ruleParent);
1046
+ }
1047
+ }
1048
+ function removeEmptyStandardDeclarations(root) {
1049
+ root.walkDecls((decl) => {
1050
+ if (!decl.prop.startsWith("--") && decl.value.trim().length === 0 && decl.next()?.type !== "comment") removeDeclarationAndEmptyRule$1(decl);
1051
+ });
1052
+ }
1053
+ function removeDisplayP3Declarations(root) {
1054
+ root.walkAtRules((atRule) => {
1055
+ if (isDisplayP3MediaRule(atRule)) {
1056
+ const parent = atRule.parent;
1057
+ atRule.remove();
1058
+ removeEmptyAtRuleAncestors(parent);
1059
+ }
1060
+ });
1061
+ }
1062
+ const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
1063
+ const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
1064
+ function isContainerMaxWidthOnlyRule(rule) {
1065
+ if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
1066
+ const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
1067
+ return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
1068
+ }
1069
+ function removeTailwindContainerMaxWidthMediaRules(root) {
1070
+ root.walkAtRules("media", (atRule) => {
1071
+ if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
1072
+ atRule.walkRules((rule) => {
1073
+ if (!isContainerMaxWidthOnlyRule(rule)) return;
1074
+ const parent = rule.parent;
1075
+ rule.remove();
1076
+ removeEmptyAtRuleAncestors(parent);
1077
+ });
1078
+ });
1079
+ }
1080
+ function isContainerWidthOnlyRule(rule) {
1081
+ if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
1082
+ const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
1083
+ return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
1084
+ }
1085
+ function isTailwindGeneratedContainerRule(rule) {
1086
+ const previous = rule.prev();
1087
+ return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
1088
+ }
1089
+ function removeTailwindContainerWidthRules(root, options = {}) {
1090
+ root.walkRules((rule) => {
1091
+ if (!isContainerWidthOnlyRule(rule)) return;
1092
+ if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
1093
+ const parent = rule.parent;
1094
+ if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
1095
+ rule.remove();
1096
+ removeEmptyAtRuleAncestors(parent);
1097
+ });
1098
+ }
1099
+ function removeUnsupportedModernColorDeclarations(root) {
1100
+ const customPropertyValues = /* @__PURE__ */ new Map();
1101
+ root.walkDecls((decl) => {
1102
+ if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
1103
+ });
1104
+ root.walkDecls((decl) => {
1105
+ const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
1106
+ if (normalized.changed) {
1107
+ decl.value = normalized.value;
1108
+ if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
1109
+ }
1110
+ if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
1111
+ });
1112
+ }
1113
+ //#endregion
1114
+ //#region src/compat/tailwindcss-v4/gradients.ts
1115
+ function collectTailwindcssV4ThemeVariables(root) {
1116
+ const variables = /* @__PURE__ */ new Map();
1117
+ root.walkRules((rule) => {
1118
+ if (!testIfRootHostForV4(rule) && !rule.selector.includes("page") && !rule.selector.includes(".tw-root")) return;
1119
+ rule.walkDecls((decl) => {
1120
+ if (decl.prop.startsWith("--color-")) variables.set(decl.prop, decl.value);
1121
+ });
1122
+ });
1123
+ return variables;
1124
+ }
1125
+ function resolveTailwindcssV4GradientColor(value, themeVariables) {
1126
+ const trimmed = value.trim();
1127
+ const match = COLOR_VAR_RE.exec(trimmed);
1128
+ if (!match) return trimmed;
1129
+ return themeVariables.get(match[1]) ?? trimmed;
1130
+ }
1131
+ function getSingleClassSelector(selector) {
1132
+ const match = SIMPLE_CLASS_SELECTOR_RE.exec(selector.trim());
1133
+ return match ? match[1] : void 0;
1134
+ }
1135
+ function normalizeDeclarationValue(value) {
1136
+ return value.replace(/\s+/g, " ").trim();
1137
+ }
1138
+ function normalizeTailwindcssV4GradientPosition(value) {
1139
+ return value.replace(/calc\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|grad|rad|turn))\s*\*\s*-1\s*\)/gi, "-$1").replace(/^in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?$/i, "").replace(/\s+in\s+(?:oklab|oklch|hsl|srgb)(?:\s+(?:longer|shorter|increasing|decreasing)\s+hue)?\s*$/i, "").replace(/\s+(?:longer|shorter|increasing|decreasing)\s*$/i, "").trim();
1140
+ }
1141
+ function normalizeTailwindcssV4InfinityCalcValue(value) {
1142
+ return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
1143
+ }
1144
+ const INFINITY_CALC_CSS_RE = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)/gi;
1145
+ /** 在预处理器解析前收敛 Tailwind v4 生成的无限圆角,避免 Sass 将 infinity 当作非法表达式。 */
1146
+ function normalizeTailwindcssV4InfinityCalcCss(css) {
1147
+ return css.replace(INFINITY_CALC_CSS_RE, `${CLAMP_PX}px`);
1148
+ }
1149
+ function normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl) {
1150
+ const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
1151
+ if (normalized) return normalized;
1152
+ const backgroundImageDecl = rule.nodes.find((node) => {
1153
+ return node.type === "decl" && node.prop === "background-image";
1154
+ });
1155
+ if (!backgroundImageDecl) return normalized;
1156
+ if (/^radial-gradient\(/i.test(backgroundImageDecl.value)) return "at center";
1157
+ if (/^conic-gradient\(/i.test(backgroundImageDecl.value)) return "from 0deg";
1158
+ return normalized;
1159
+ }
432
1160
  function appendStopPosition(color, position) {
433
1161
  const normalizedPosition = position?.trim();
434
1162
  return normalizedPosition ? `${color} ${normalizedPosition}` : color;
@@ -802,7 +1530,7 @@ function isTailwindcssV4DisplayP3Declaration(decl) {
802
1530
  }
803
1531
  //#endregion
804
1532
  //#region src/compat/uni-app-x-uvue/scoped-style.ts
805
- const MINI_PROGRAM_PREFLIGHT_SELECTORS$1 = /* @__PURE__ */ new Set([
1533
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
806
1534
  "view",
807
1535
  "text",
808
1536
  "::after",
@@ -953,743 +1681,426 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) {
953
1681
  const selectors = rule.selectors ?? [rule.selector];
954
1682
  if (selectors.length === 0 || !selectors.every((selector) => {
955
1683
  const normalized = normalizeCssSignatureValue(selector);
956
- return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(normalized);
1684
+ return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
957
1685
  })) return false;
958
1686
  const declarations = getDeclarations(rule);
959
1687
  return declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || [
960
1688
  "box-sizing",
961
- "margin",
962
- "padding",
963
- "border"
964
- ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
965
- }
966
- function isScopedMiniProgramTailwindContentInitRule(rule) {
967
- const selectors = rule.selectors ?? [rule.selector];
968
- if (selectors.length === 0 || !selectors.every((selector) => {
969
- const normalized = normalizeCssSignatureValue(selector);
970
- return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS$1.has(normalized);
971
- })) return false;
972
- const declarations = getDeclarations(rule);
973
- return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
974
- }
975
- function isLikelyTailwindPropertyAtRule(atRule) {
976
- return typeof atRule.name === "string" && atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
977
- }
978
- function stripScopedTailwindNoise(root) {
979
- let hasTailwindBanner = false;
980
- root.walkComments((comment) => {
981
- if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) hasTailwindBanner = true;
982
- });
983
- root.walkComments((comment) => {
984
- if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
985
- });
986
- root.walkRules((rule) => {
987
- if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
988
- });
989
- root.walkAtRules((atRule) => {
990
- if (isLikelyTailwindPropertyAtRule(atRule)) {
991
- atRule.remove();
992
- return;
993
- }
994
- if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
995
- });
996
- }
997
- //#endregion
998
- //#region src/compat/uni-app-x-uvue/theme.ts
999
- const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
1000
- ":host",
1001
- ":root",
1002
- ".tw-root",
1003
- "page",
1004
- "uni-page-body",
1005
- "wx-root-portal-content"
1006
- ]);
1007
- function normalizeSelector$2(selector) {
1008
- return selector.replace(/\s+/g, "").toLowerCase();
1009
- }
1010
- function isUniAppXSystemRootCarrierRule(rule) {
1011
- const selectors = rule.selectors ?? [];
1012
- if (selectors.length === 0) return false;
1013
- let hasRootMarker = false;
1014
- for (const selector of selectors) {
1015
- const normalized = normalizeSelector$2(selector);
1016
- if (!SYSTEM_ROOT_SELECTORS.has(normalized)) return false;
1017
- if (normalized === ":host" || normalized === ":root" || normalized === ".tw-root") hasRootMarker = true;
1018
- }
1019
- return hasRootMarker;
1020
- }
1021
- function resolveNodes(nodes, variables, resolving) {
1022
- for (let index = 0; index < nodes.length; index++) {
1023
- const node = nodes[index];
1024
- if (node?.type !== "function") continue;
1025
- if (node.value.toLowerCase() !== "var") {
1026
- resolveNodes(node.nodes, variables, resolving);
1027
- continue;
1028
- }
1029
- const variable = node.nodes.find((child) => child.type === "word");
1030
- if (variable?.type !== "word" || !variable.value.startsWith("--")) {
1031
- resolveNodes(node.nodes, variables, resolving);
1032
- continue;
1033
- }
1034
- const commaIndex = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
1035
- const fallback = commaIndex >= 0 ? valueParser.stringify(node.nodes.slice(commaIndex + 1)).trim() : "";
1036
- const configured = variables.get(variable.value);
1037
- let replacement;
1038
- if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
1039
- else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
1040
- if (replacement === void 0) {
1041
- resolveNodes(node.nodes, variables, resolving);
1042
- continue;
1043
- }
1044
- const replacementNodes = valueParser(replacement).nodes;
1045
- nodes.splice(index, 1, ...replacementNodes);
1046
- index += replacementNodes.length - 1;
1047
- }
1048
- }
1049
- function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set()) {
1050
- if (!value.includes("var(")) return value;
1051
- const parsed = valueParser(value);
1052
- resolveNodes(parsed.nodes, variables, resolving);
1053
- return parsed.toString();
1054
- }
1055
- function getUnresolvedAuthorVariableFallback(value) {
1056
- const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
1057
- const variable = nodes.length === 1 ? nodes[0] : void 0;
1058
- if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
1059
- const variableNode = variable.nodes.find((node) => node.type === "word");
1060
- const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
1061
- if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
1062
- const fallback = valueParser.stringify(variable.nodes.slice(commaIndex + 1)).trim();
1063
- if (!fallback) return;
1064
- return {
1065
- name: variableNode.value,
1066
- fallback
1067
- };
1068
- }
1069
- /**
1070
- * HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
1071
- */
1072
- function splitUnresolvedAuthorVariableFallbacks(root, variables) {
1073
- if (typeof root.walkDecls !== "function") return false;
1074
- let changed = false;
1075
- root.walkDecls((decl) => {
1076
- if (decl.prop.startsWith("--")) return;
1077
- const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
1078
- if (!unresolved || variables.has(unresolved.name)) return;
1079
- decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
1080
- decl.value = `var(${unresolved.name})`;
1081
- changed = true;
1082
- });
1083
- return changed;
1084
- }
1085
- /**
1086
- * UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
1087
- * 内联到实际 utility,再移除仅用于变量承载的系统规则。
1088
- */
1089
- function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
1090
- const carrierRules = [];
1091
- const variables = new Map(customPropertyValues);
1092
- root.walkRules((rule) => {
1093
- if (!isUniAppXSystemRootCarrierRule(rule)) return;
1094
- carrierRules.push(rule);
1095
- rule.walkDecls((decl) => {
1096
- if (decl.prop.startsWith("--")) variables.set(decl.prop, decl.value);
1097
- });
1098
- });
1099
- if (variables.size > 0) {
1100
- const carriers = new Set(carrierRules);
1101
- root.walkDecls((decl) => {
1102
- if (decl.parent?.type === "rule" && carriers.has(decl.parent)) return;
1103
- decl.value = resolveThemeValue(decl.value, variables);
1104
- });
1105
- }
1106
- splitUnresolvedAuthorVariableFallbacks(root, variables);
1107
- for (const rule of carrierRules) rule.remove();
1108
- }
1109
- //#endregion
1110
- //#region src/compat/uni-app-x-uvue.ts
1111
- const ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
1112
- const FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
1113
- const IMPORTANT_SUFFIX_RE = /\s*!important$/i;
1114
- const TRANSFORM_PROPERTIES = /* @__PURE__ */ new Set(["transform", "-webkit-transform"]);
1115
- function isUniAppXUvueTarget(options) {
1116
- return Boolean(options?.uniAppX) && options?.uniAppXCssTarget === "uvue";
1117
- }
1118
- function normalizeUnsupportedMode(mode) {
1119
- return mode ?? "warn";
1120
- }
1121
- function normalizeValue(value) {
1122
- return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
1123
- }
1124
- function hasCalcFunction(value) {
1125
- const parsed = valueParser(value);
1126
- let found = false;
1127
- parsed.walk((node) => {
1128
- if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
1129
- });
1130
- return found;
1131
- }
1132
- function normalizeUniAppXTransformValue(value) {
1133
- if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
1134
- const parsed = valueParser(value);
1135
- let changed = false;
1136
- parsed.walk((node) => {
1137
- if (node.type !== "function" || node.value.toLowerCase() !== "translate") return;
1138
- for (const child of node.nodes) {
1139
- if (child.type !== "div" || child.value !== ",") continue;
1140
- child.value = " ";
1141
- child.before = "";
1142
- child.after = "";
1143
- changed = true;
1144
- }
1145
- });
1146
- return changed ? parsed.toString() : value;
1147
- }
1148
- function getSourceFile(rule, result) {
1149
- return rule.source?.input.from ?? result.opts.from ?? "unknown source";
1150
- }
1151
- function collectUtilityClassNames(rule) {
1152
- const classNames = /* @__PURE__ */ new Set();
1153
- for (const selector of rule.selectors ?? []) try {
1154
- selectorParser().astSync(selector).walkClasses((node) => {
1155
- if (node.value) classNames.add(node.value);
1156
- });
1157
- } catch {
1158
- for (const match of selector.matchAll(FALLBACK_CLASS_RE)) if (match[1]) classNames.add(match[1].replaceAll("\\", ""));
1159
- }
1160
- return [...classNames];
1161
- }
1162
- function hasOnlyClassSelectors(rule) {
1163
- const selectors = rule.selectors ?? [];
1164
- if (selectors.length === 0) return false;
1165
- return selectors.every((selector) => {
1166
- try {
1167
- return selectorParser().astSync(selector).nodes.every((node) => node.nodes.length > 0 && node.nodes.every((child) => child.type === "class"));
1168
- } catch {
1169
- return false;
1170
- }
1171
- });
1689
+ "margin",
1690
+ "padding",
1691
+ "border"
1692
+ ].includes(decl.prop)) && hasTailwindSourceEvidence(declarations, hasTailwindBanner);
1172
1693
  }
1173
- function getUnsupportedDeclarationReason(prop, value) {
1174
- const normalizedProp = prop.trim().toLowerCase();
1175
- const normalizedValue = normalizeValue(value);
1176
- if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
1177
- if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
1178
- if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
1179
- if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
1180
- if (normalizedProp === "gap" || normalizedProp === "row-gap" || normalizedProp === "column-gap") return `${normalizedProp}: ${value}`;
1694
+ function isScopedMiniProgramTailwindContentInitRule(rule) {
1695
+ const selectors = rule.selectors ?? [rule.selector];
1696
+ if (selectors.length === 0 || !selectors.every((selector) => {
1697
+ const normalized = normalizeCssSignatureValue(selector);
1698
+ return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
1699
+ })) return false;
1700
+ const declarations = getDeclarations(rule);
1701
+ return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
1181
1702
  }
1182
- function reportUnsupportedRule(rule, result, mode, warningCache, reason) {
1183
- if (mode === "silent") return;
1184
- const classNames = collectUtilityClassNames(rule);
1185
- const message = `uni-app x uvue unsupported utility: ${classNames.length > 0 ? classNames.join(", ") : rule.selector} (${reason}) in ${getSourceFile(rule, result)}`;
1186
- if (mode === "error") throw rule.error(message);
1187
- if (warningCache.has(message)) return;
1188
- warningCache.add(message);
1189
- rule.warn(result, message);
1703
+ function isLikelyTailwindPropertyAtRule(atRule) {
1704
+ return typeof atRule.name === "string" && atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
1190
1705
  }
1191
- function applyUniAppXUvueCompatibility(result, options) {
1192
- if (!isUniAppXUvueTarget(options)) return result;
1193
- const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
1194
- const warningCache = /* @__PURE__ */ new Set();
1195
- const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
1196
- let root = result.root;
1197
- let calcMessages = [];
1198
- consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
1199
- if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
1200
- root.walkDecls((decl) => {
1201
- normalizeTailwindcssV4Declaration(decl);
1202
- if (TRANSFORM_PROPERTIES.has(decl.prop.toLowerCase())) decl.value = normalizeUniAppXTransformValue(decl.value);
1203
- });
1204
- const calcResult = postcss$1([postcssCalc()]).process(root, result.opts).sync();
1205
- root = calcResult.root;
1206
- calcMessages = calcResult.messages;
1207
- }
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
- }
1706
+ function stripScopedTailwindNoise(root) {
1707
+ let hasTailwindBanner = false;
1708
+ root.walkComments((comment) => {
1709
+ if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) hasTailwindBanner = true;
1710
+ });
1711
+ root.walkComments((comment) => {
1712
+ if (TAILWIND_VERSION_COMMENT_RE.test(comment.text)) comment.remove();
1713
+ });
1215
1714
  root.walkRules((rule) => {
1216
- if (!hasOnlyClassSelectors(rule)) {
1217
- reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
1218
- rule.remove();
1219
- return;
1220
- }
1221
- rule.walkDecls((decl) => {
1222
- const reason = getUnsupportedDeclarationReason(decl.prop, decl.value);
1223
- if (!reason) return;
1224
- reportUnsupportedRule(rule, result, mode, warningCache, reason);
1225
- decl.remove();
1226
- });
1227
- if ((rule.nodes?.length ?? 0) === 0) rule.remove();
1715
+ if (isScopedTailwindThemeCarrierRule(rule, hasTailwindBanner) || isScopedUniversalTailwindPreflightRule(rule, hasTailwindBanner) || isScopedTailwindElementPreflightRule(rule, hasTailwindBanner) || isUnscopedMiniProgramTailwindPreflightRule(rule, hasTailwindBanner) || isScopedMiniProgramTailwindContentInitRule(rule)) rule.remove();
1228
1716
  });
1229
1717
  root.walkAtRules((atRule) => {
1230
- if (atRule.name?.toLowerCase() === "property") {
1718
+ if (isLikelyTailwindPropertyAtRule(atRule)) {
1231
1719
  atRule.remove();
1232
1720
  return;
1233
1721
  }
1234
1722
  if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
1235
1723
  });
1236
- const nextResult = root.toResult(result.opts);
1237
- nextResult.messages.push(...result.messages);
1238
- nextResult.messages.push(...calcMessages);
1239
- return nextResult;
1240
1724
  }
1241
1725
  //#endregion
1242
- //#region src/branches/uni-app-x-css-uvue/index.ts
1243
- function postprocessUniAppXUvueCss(result, options) {
1244
- return applyUniAppXUvueCompatibility(applyUniAppXBaseCompatibility(result, options), options);
1245
- }
1246
- //#endregion
1247
- //#region src/branches/uni-app-x-css-webview/index.ts
1248
- function postprocessUniAppXWebviewCss(result, options) {
1249
- return applyUniAppXBaseCompatibility(result, options);
1250
- }
1251
- //#endregion
1252
- //#region src/branches/web/index.ts
1253
- function postprocessWebCss(result, _options) {
1254
- return result;
1255
- }
1256
- //#endregion
1257
- //#region src/style-targets/style.ts
1258
- function postprocessGenericCss(result, _options) {
1259
- return result;
1726
+ //#region src/compat/uni-app-x-uvue/theme.ts
1727
+ const SYSTEM_ROOT_SELECTORS = /* @__PURE__ */ new Set([
1728
+ ":host",
1729
+ ":root",
1730
+ ".tw-root",
1731
+ "page",
1732
+ "uni-page-body",
1733
+ "wx-root-portal-content"
1734
+ ]);
1735
+ function normalizeSelector$1(selector) {
1736
+ return selector.replace(/\s+/g, "").toLowerCase();
1260
1737
  }
1261
- function createPostcssStyleTargetProfile(target) {
1262
- switch (target) {
1263
- case "mini-program": return {
1264
- target,
1265
- postprocess: postprocessMiniProgramCss
1266
- };
1267
- case "uni-app-x-css-uvue": return {
1268
- target,
1269
- postprocess: postprocessUniAppXUvueCss
1270
- };
1271
- case "uni-app-x-css-webview": return {
1272
- target,
1273
- postprocess: postprocessUniAppXWebviewCss
1274
- };
1275
- case "web": return {
1276
- target,
1277
- postprocess: postprocessWebCss
1278
- };
1279
- default: return {
1280
- target,
1281
- postprocess: postprocessGenericCss
1282
- };
1738
+ function isUniAppXSystemRootCarrierRule(rule) {
1739
+ const selectors = rule.selectors ?? [];
1740
+ if (selectors.length === 0) return false;
1741
+ let hasRootMarker = false;
1742
+ for (const selector of selectors) {
1743
+ const normalized = normalizeSelector$1(selector);
1744
+ if (!SYSTEM_ROOT_SELECTORS.has(normalized)) return false;
1745
+ if (normalized === ":host" || normalized === ":root" || normalized === ".tw-root") hasRootMarker = true;
1283
1746
  }
1747
+ return hasRootMarker;
1284
1748
  }
1285
- //#endregion
1286
- //#region src/frameworks/shared.ts
1287
- function isWebLikeStylePlatform(platform) {
1288
- const normalized = platform?.trim().toLowerCase();
1289
- return normalized === "h5" || normalized === "web" || normalized?.startsWith("web-") === true || normalized === "app" || normalized === "app-plus" || normalized?.startsWith("app-") === true;
1290
- }
1291
- function resolveWebPlatformOrTarget(options, fallbackTarget) {
1292
- return isWebLikeStylePlatform(options.platform) ? "web" : fallbackTarget;
1293
- }
1294
- function createStaticTargetFrameworkStrategy(framework, fallbackTarget) {
1295
- return {
1296
- framework,
1297
- resolveStyleTarget: (options) => resolveWebPlatformOrTarget(options, fallbackTarget)
1298
- };
1299
- }
1300
- //#endregion
1301
- //#region src/frameworks/generic/index.ts
1302
- const genericPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("generic", "generic");
1303
- //#endregion
1304
- //#region src/frameworks/kbone/index.ts
1305
- const kbonePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("kbone", "generic");
1306
- //#endregion
1307
- //#region src/frameworks/mpx/index.ts
1308
- const mpxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("mpx", "mini-program");
1309
- //#endregion
1310
- //#region src/frameworks/native/index.ts
1311
- const nativePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("native", "mini-program");
1312
- //#endregion
1313
- //#region src/frameworks/remax/index.ts
1314
- const remaxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("remax", "mini-program");
1315
- //#endregion
1316
- //#region src/frameworks/taro/index.ts
1317
- const taroPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("taro", "mini-program");
1318
- //#endregion
1319
- //#region src/frameworks/uni-app/index.ts
1320
- const uniAppPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app", "mini-program");
1321
- //#endregion
1322
- //#region src/frameworks/uni-app-vite/index.ts
1323
- const uniAppVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app-vite", "mini-program");
1324
- //#endregion
1325
- //#region src/frameworks/uni-app-x/index.ts
1326
- const uniAppXPostcssFrameworkStrategy = {
1327
- framework: "uni-app-x",
1328
- resolveStyleTarget: (options) => options.uniAppXCssTarget === "uvue" ? "uni-app-x-css-uvue" : "uni-app-x-css-webview"
1329
- };
1330
- //#endregion
1331
- //#region src/frameworks/weapp-vite/index.ts
1332
- const weappVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("weapp-vite", "mini-program");
1333
- //#endregion
1334
- //#region src/frameworks/index.ts
1335
- function isUniAppXFramework(options) {
1336
- if (options.uniAppX === false) return false;
1337
- return options.uniAppX === true || options.appType === "uni-app-x";
1338
- }
1339
- function resolvePostcssFrameworkStrategy(options) {
1340
- if (isUniAppXFramework(options)) return uniAppXPostcssFrameworkStrategy;
1341
- switch (options.appType) {
1342
- case "kbone": return kbonePostcssFrameworkStrategy;
1343
- case "mpx": return mpxPostcssFrameworkStrategy;
1344
- case "native": return nativePostcssFrameworkStrategy;
1345
- case "remax": return remaxPostcssFrameworkStrategy;
1346
- case "taro": return taroPostcssFrameworkStrategy;
1347
- case "uni-app": return uniAppPostcssFrameworkStrategy;
1348
- case "uni-app-vite": return uniAppVitePostcssFrameworkStrategy;
1349
- case "weapp-vite": return weappVitePostcssFrameworkStrategy;
1350
- default: return genericPostcssFrameworkStrategy;
1749
+ function resolveNodes(nodes, variables, resolving) {
1750
+ for (let index = 0; index < nodes.length; index++) {
1751
+ const node = nodes[index];
1752
+ if (node?.type !== "function") continue;
1753
+ if (node.value.toLowerCase() !== "var") {
1754
+ resolveNodes(node.nodes, variables, resolving);
1755
+ continue;
1756
+ }
1757
+ const variable = node.nodes.find((child) => child.type === "word");
1758
+ if (variable?.type !== "word" || !variable.value.startsWith("--")) {
1759
+ resolveNodes(node.nodes, variables, resolving);
1760
+ continue;
1761
+ }
1762
+ const commaIndex = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
1763
+ const fallback = commaIndex >= 0 ? valueParser.stringify(node.nodes.slice(commaIndex + 1)).trim() : "";
1764
+ const configured = variables.get(variable.value);
1765
+ let replacement;
1766
+ if (configured !== void 0 && !resolving.has(variable.value)) replacement = resolveThemeValue(configured, variables, /* @__PURE__ */ new Set([...resolving, variable.value]));
1767
+ else if (fallback && isTailwindcssV4ThemeVariable(variable.value)) replacement = resolveThemeValue(fallback, variables, resolving);
1768
+ if (replacement === void 0) {
1769
+ resolveNodes(node.nodes, variables, resolving);
1770
+ continue;
1771
+ }
1772
+ const replacementNodes = valueParser(replacement).nodes;
1773
+ nodes.splice(index, 1, ...replacementNodes);
1774
+ index += replacementNodes.length - 1;
1351
1775
  }
1352
1776
  }
1353
- function resolvePostcssFrameworkProfile(options) {
1354
- const strategy = resolvePostcssFrameworkStrategy(options);
1355
- const target = strategy.resolveStyleTarget(options);
1356
- const targetProfile = createPostcssStyleTargetProfile(target);
1777
+ function resolveThemeValue(value, variables, resolving = /* @__PURE__ */ new Set()) {
1778
+ if (!value.includes("var(")) return value;
1779
+ const parsed = valueParser(value);
1780
+ resolveNodes(parsed.nodes, variables, resolving);
1781
+ return parsed.toString();
1782
+ }
1783
+ function getUnresolvedAuthorVariableFallback(value) {
1784
+ const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
1785
+ const variable = nodes.length === 1 ? nodes[0] : void 0;
1786
+ if (variable?.type !== "function" || variable.value.toLowerCase() !== "var") return;
1787
+ const variableNode = variable.nodes.find((node) => node.type === "word");
1788
+ const commaIndex = variable.nodes.findIndex((node) => node.type === "div" && node.value === ",");
1789
+ if (variableNode?.type !== "word" || !variableNode.value.startsWith("--") || isTailwindcssV4ThemeVariable(variableNode.value) || variableNode.value.startsWith("--default-") || commaIndex < 0) return;
1790
+ const fallback = valueParser.stringify(variable.nodes.slice(commaIndex + 1)).trim();
1791
+ if (!fallback) return;
1357
1792
  return {
1358
- framework: strategy.framework,
1359
- target,
1360
- branch: target,
1361
- postprocess: targetProfile.postprocess
1793
+ name: variableNode.value,
1794
+ fallback
1362
1795
  };
1363
1796
  }
1364
- function resolvePostcssStyleTarget(options) {
1365
- return resolvePostcssFrameworkProfile(options).target;
1797
+ /**
1798
+ * HBuilderX 不接受带 fallback 的 var() 声明,拆成静态 fallback 与动态变量两条声明。
1799
+ */
1800
+ function splitUnresolvedAuthorVariableFallbacks(root, variables) {
1801
+ if (typeof root.walkDecls !== "function") return false;
1802
+ let changed = false;
1803
+ root.walkDecls((decl) => {
1804
+ if (decl.prop.startsWith("--")) return;
1805
+ const unresolved = getUnresolvedAuthorVariableFallback(decl.value);
1806
+ if (!unresolved || variables.has(unresolved.name)) return;
1807
+ decl.parent?.insertBefore(decl, decl.clone({ value: unresolved.fallback }));
1808
+ decl.value = `var(${unresolved.name})`;
1809
+ changed = true;
1810
+ });
1811
+ return changed;
1812
+ }
1813
+ /**
1814
+ * UVUE 不支持 Tailwind 的混合根选择器,因此先把根作用域中的静态主题 token
1815
+ * 内联到实际 utility,再移除仅用于变量承载的系统规则。
1816
+ */
1817
+ function consumeUniAppXSystemRootTheme(root, customPropertyValues) {
1818
+ const carrierRules = [];
1819
+ const variables = new Map(customPropertyValues);
1820
+ root.walkRules((rule) => {
1821
+ if (!isUniAppXSystemRootCarrierRule(rule)) return;
1822
+ carrierRules.push(rule);
1823
+ rule.walkDecls((decl) => {
1824
+ if (decl.prop.startsWith("--")) variables.set(decl.prop, decl.value);
1825
+ });
1826
+ });
1827
+ if (variables.size > 0) {
1828
+ const carriers = new Set(carrierRules);
1829
+ root.walkDecls((decl) => {
1830
+ if (decl.parent?.type === "rule" && carriers.has(decl.parent)) return;
1831
+ decl.value = resolveThemeValue(decl.value, variables);
1832
+ });
1833
+ }
1834
+ splitUnresolvedAuthorVariableFallbacks(root, variables);
1835
+ for (const rule of carrierRules) rule.remove();
1366
1836
  }
1367
1837
  //#endregion
1368
- //#region src/branches/style.ts
1369
- function resolvePostcssStyleBranch(options) {
1370
- return resolvePostcssStyleTarget(options);
1838
+ //#region src/compat/uni-app-x-uvue.ts
1839
+ const ALLOWED_DISPLAY_VALUES = /* @__PURE__ */ new Set(["flex", "none"]);
1840
+ const FALLBACK_CLASS_RE = /\.((?:\\.|[\w-])+)/g;
1841
+ const IMPORTANT_SUFFIX_RE = /\s*!important$/i;
1842
+ const TRANSFORM_PROPERTIES = /* @__PURE__ */ new Set(["transform", "-webkit-transform"]);
1843
+ function isUniAppXUvueTarget(options) {
1844
+ return Boolean(options?.uniAppX) && options?.uniAppXCssTarget === "uvue";
1371
1845
  }
1372
- function resolvePostcssStyleBranchProfile(options) {
1373
- return resolvePostcssFrameworkProfile(options);
1846
+ function normalizeUnsupportedMode(mode) {
1847
+ return mode ?? "warn";
1374
1848
  }
1375
- const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
1376
- "oklch",
1377
- "oklab",
1378
- "lch",
1379
- "lab"
1380
- ]);
1381
- const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
1382
- "rgb",
1383
- "rgba",
1384
- "hsl",
1385
- "hsla",
1386
- "hwb"
1387
- ]);
1388
- const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
1389
- const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
1390
- const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
1391
- const TRANSPARENT_COLOR_RE = /^transparent$/i;
1392
- const CURRENT_COLOR_RE = /^currentcolor$/i;
1393
- const CSS_WIDE_KEYWORD_RE = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
1394
- const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
1395
- //#endregion
1396
- //#region src/compat/color-mix/modern.ts
1397
- function isDisplayP3ColorFunction(colorSource) {
1398
- return /^color\(\s*display-p3\b/i.test(colorSource.trim());
1849
+ function normalizeValue(value) {
1850
+ return value.trim().toLowerCase().replace(IMPORTANT_SUFFIX_RE, "");
1399
1851
  }
1400
- function isModernColorSyntaxFunction(colorSource) {
1401
- const parsed = valueParser(colorSource.trim());
1402
- const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
1403
- if (node?.type !== "function") return false;
1404
- const name = node.value.toLowerCase();
1405
- if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
1406
- return !node.nodes.some((child) => child.type === "div" && child.value === ",");
1852
+ function hasCalcFunction(value) {
1853
+ const parsed = valueParser(value);
1854
+ let found = false;
1855
+ parsed.walk((node) => {
1856
+ if (node.type === "function" && node.value.toLowerCase() === "calc") found = true;
1857
+ });
1858
+ return found;
1407
1859
  }
1408
- function hasUnsupportedModernColorFunction(value) {
1860
+ function normalizeUniAppXTransformValue(value) {
1861
+ if (!value.toLowerCase().includes("translate(") || !value.includes(",")) return value;
1409
1862
  const parsed = valueParser(value);
1410
- let hasUnsupported = false;
1863
+ let changed = false;
1411
1864
  parsed.walk((node) => {
1412
- if (node.type !== "function") return;
1413
- const name = node.value.toLowerCase();
1414
- if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node)) || isModernColorSyntaxFunction(valueParser.stringify(node))) {
1415
- hasUnsupported = true;
1416
- return false;
1865
+ if (node.type !== "function" || node.value.toLowerCase() !== "translate") return;
1866
+ for (const child of node.nodes) {
1867
+ if (child.type !== "div" || child.value !== ",") continue;
1868
+ child.value = " ";
1869
+ child.before = "";
1870
+ child.after = "";
1871
+ changed = true;
1417
1872
  }
1418
1873
  });
1419
- return hasUnsupported;
1874
+ return changed ? parsed.toString() : value;
1420
1875
  }
1421
- //#endregion
1422
- //#region src/compat/color-mix/parse.ts
1423
- function splitArguments(nodes) {
1424
- const args = [];
1425
- let current = [];
1426
- for (const node of nodes) {
1427
- if (node.type === "div" && node.value === ",") {
1428
- args.push(current);
1429
- current = [];
1430
- continue;
1431
- }
1432
- current.push(node);
1433
- }
1434
- args.push(current);
1435
- return args;
1876
+ function getSourceFile(rule, result) {
1877
+ return rule.source?.input.from ?? result.opts.from ?? "unknown source";
1436
1878
  }
1437
- function splitStopSegments(nodes) {
1438
- const segments = [];
1439
- let current = [];
1440
- for (const node of nodes) {
1441
- if (node.type === "space") {
1442
- if (current.length > 0) {
1443
- segments.push(current);
1444
- current = [];
1445
- }
1446
- continue;
1447
- }
1448
- current.push(node);
1879
+ function collectUtilityClassNames(rule) {
1880
+ const classNames = /* @__PURE__ */ new Set();
1881
+ for (const selector of rule.selectors ?? []) try {
1882
+ selectorParser().astSync(selector).walkClasses((node) => {
1883
+ if (node.value) classNames.add(node.value);
1884
+ });
1885
+ } catch {
1886
+ for (const match of selector.matchAll(FALLBACK_CLASS_RE)) if (match[1]) classNames.add(match[1].replaceAll("\\", ""));
1449
1887
  }
1450
- if (current.length > 0) segments.push(current);
1451
- return segments;
1888
+ return [...classNames];
1452
1889
  }
1453
- function trimNodes$1(nodes) {
1454
- let start = 0;
1455
- let end = nodes.length;
1456
- while (start < end && nodes[start]?.type === "space") start += 1;
1457
- while (end > start && nodes[end - 1]?.type === "space") end -= 1;
1458
- return nodes.slice(start, end);
1890
+ function hasOnlyClassSelectors(rule) {
1891
+ const selectors = rule.selectors ?? [];
1892
+ if (selectors.length === 0) return false;
1893
+ return selectors.every((selector) => {
1894
+ try {
1895
+ return selectorParser().astSync(selector).nodes.every((node) => node.nodes.length > 0 && node.nodes.every((child) => child.type === "class"));
1896
+ } catch {
1897
+ return false;
1898
+ }
1899
+ });
1459
1900
  }
1460
- function getParsedColorData(colorSource) {
1461
- try {
1462
- return color(parseComponentValue(tokenize({ css: colorSource })));
1463
- } catch {
1464
- return false;
1465
- }
1901
+ function getUnsupportedDeclarationReason(prop, value) {
1902
+ const normalizedProp = prop.trim().toLowerCase();
1903
+ const normalizedValue = normalizeValue(value);
1904
+ if (hasCalcFunction(value)) return `${normalizedProp}: ${value}`;
1905
+ if (normalizedProp === "display" && !ALLOWED_DISPLAY_VALUES.has(normalizedValue)) return `${normalizedProp}: ${value}`;
1906
+ if (normalizedProp === "min-height" && normalizedValue === "100vh") return `${normalizedProp}: ${value}`;
1907
+ if (normalizedProp === "grid-template-columns" || normalizedProp === "grid-template-rows" || normalizedProp === "grid-auto-columns" || normalizedProp === "grid-auto-rows" || normalizedProp === "grid-auto-flow") return `${normalizedProp}: ${value}`;
1908
+ if (normalizedProp === "gap" || normalizedProp === "row-gap" || normalizedProp === "column-gap") return `${normalizedProp}: ${value}`;
1466
1909
  }
1467
- function parseAlphaValue(alphaSource) {
1468
- const parsed = Number.parseFloat(alphaSource);
1469
- if (Number.isFinite(parsed)) return alphaSource.trim().endsWith("%") ? parsed / 100 : parsed;
1910
+ function reportUnsupportedRule(rule, result, mode, warningCache, reason) {
1911
+ if (mode === "silent") return;
1912
+ const classNames = collectUtilityClassNames(rule);
1913
+ const message = `uni-app x uvue unsupported utility: ${classNames.length > 0 ? classNames.join(", ") : rule.selector} (${reason}) in ${getSourceFile(rule, result)}`;
1914
+ if (mode === "error") throw rule.error(message);
1915
+ if (warningCache.has(message)) return;
1916
+ warningCache.add(message);
1917
+ rule.warn(result, message);
1470
1918
  }
1471
- function resolveVarColor(colorSource, customPropertyValues, depth = 0) {
1472
- if (depth > 5) return;
1473
- const parsed = valueParser(colorSource.trim());
1474
- const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
1475
- if (node?.type !== "function" || node.value.toLowerCase() !== "var") return;
1476
- const args = splitArguments(node.nodes);
1477
- const propertyName = valueParser.stringify(trimNodes$1(args[0] ?? [])).trim();
1478
- if (!CUSTOM_PROPERTY_RE.test(propertyName)) return;
1479
- const resolved = customPropertyValues.get(propertyName);
1480
- if (!resolved) {
1481
- const fallback = args[1] ? valueParser.stringify(trimNodes$1(args[1])).trim() : void 0;
1482
- return fallback ? resolveColorData(fallback, customPropertyValues, depth + 1) : void 0;
1919
+ function applyUniAppXUvueCompatibility(result, options) {
1920
+ if (!isUniAppXUvueTarget(options)) return result;
1921
+ const mode = normalizeUnsupportedMode(options?.uniAppXUnsupported);
1922
+ const warningCache = /* @__PURE__ */ new Set();
1923
+ const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
1924
+ let root = result.root;
1925
+ let calcMessages = [];
1926
+ consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
1927
+ if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
1928
+ root.walkDecls((decl) => {
1929
+ normalizeTailwindcssV4Declaration(decl);
1930
+ if (TRANSFORM_PROPERTIES.has(decl.prop.toLowerCase())) decl.value = normalizeUniAppXTransformValue(decl.value);
1931
+ });
1932
+ const calcResult = postcss$1([postcssCalc()]).process(root, result.opts).sync();
1933
+ root = calcResult.root;
1934
+ calcMessages = calcResult.messages;
1935
+ removeEmptyStandardDeclarations(root);
1483
1936
  }
1484
- return resolveColorData(resolved, customPropertyValues, depth + 1);
1485
- }
1486
- function resolveColorData(colorSource, customPropertyValues, depth = 0) {
1487
- if (typeof colorSource !== "string") return;
1488
- const trimmed = colorSource.trim();
1489
- if (TRANSPARENT_COLOR_RE.test(trimmed)) return getParsedColorData(trimmed) || void 0;
1490
- if (CURRENT_COLOR_RE.test(trimmed) || CSS_WIDE_KEYWORD_RE.test(trimmed)) return;
1491
- const resolvedVar = resolveVarColor(trimmed, customPropertyValues, depth);
1492
- if (resolvedVar) return resolvedVar;
1493
- return getParsedColorData(trimmed) || void 0;
1937
+ if (sfcStyleRequest) {
1938
+ stripScopedTailwindNoise(root);
1939
+ const nextResult = root.toResult(result.opts);
1940
+ nextResult.messages.push(...result.messages);
1941
+ nextResult.messages.push(...calcMessages);
1942
+ return nextResult;
1943
+ }
1944
+ root.walkRules((rule) => {
1945
+ if (!hasOnlyClassSelectors(rule)) {
1946
+ reportUnsupportedRule(rule, result, mode, warningCache, "selector must be class-only");
1947
+ rule.remove();
1948
+ return;
1949
+ }
1950
+ rule.walkDecls((decl) => {
1951
+ const reason = getUnsupportedDeclarationReason(decl.prop, decl.value);
1952
+ if (!reason) return;
1953
+ reportUnsupportedRule(rule, result, mode, warningCache, reason);
1954
+ decl.remove();
1955
+ });
1956
+ if ((rule.nodes?.length ?? 0) === 0) rule.remove();
1957
+ });
1958
+ root.walkAtRules((atRule) => {
1959
+ if (atRule.name?.toLowerCase() === "property") {
1960
+ atRule.remove();
1961
+ return;
1962
+ }
1963
+ if ((atRule.nodes?.length ?? 0) === 0) atRule.remove();
1964
+ });
1965
+ const nextResult = root.toResult(result.opts);
1966
+ nextResult.messages.push(...result.messages);
1967
+ nextResult.messages.push(...calcMessages);
1968
+ return nextResult;
1494
1969
  }
1495
- function normalizeColorFunctionName(colorSource, alpha, customPropertyValues) {
1496
- const resolvedColor = resolveColorData(colorSource, customPropertyValues);
1497
- if (!resolvedColor) return;
1498
- resolvedColor.alpha = alpha;
1499
- return serializeRGB(resolvedColor).toString();
1970
+ //#endregion
1971
+ //#region src/branches/uni-app-x-css-uvue/index.ts
1972
+ function postprocessUniAppXUvueCss(result, options) {
1973
+ return applyUniAppXUvueCompatibility(applyUniAppXBaseCompatibility(result, options), options);
1500
1974
  }
1501
- function normalizeColorFunctionWithDynamicAlpha(colorSource, alphaSource, customPropertyValues) {
1502
- const resolvedColor = resolveColorData(colorSource, customPropertyValues);
1503
- const alphaColor = getParsedColorData(`rgb(0 0 0 / ${alphaSource})`);
1504
- if (!resolvedColor || !alphaColor || typeof alphaColor.alpha === "number") return;
1505
- resolvedColor.alpha = alphaColor.alpha;
1506
- return serializeRGB(resolvedColor).toString();
1975
+ //#endregion
1976
+ //#region src/branches/uni-app-x-css-webview/index.ts
1977
+ function postprocessUniAppXWebviewCss(result, options) {
1978
+ return applyUniAppXBaseCompatibility(result, options);
1507
1979
  }
1508
- function normalizeStandaloneColorFunction(colorSource) {
1509
- const resolvedColor = getParsedColorData(colorSource);
1510
- return resolvedColor ? serializeRGB(resolvedColor).toString() : void 0;
1980
+ //#endregion
1981
+ //#region src/branches/web/index.ts
1982
+ function postprocessWebCss(result, _options) {
1983
+ return result;
1511
1984
  }
1512
1985
  //#endregion
1513
- //#region src/compat/color-mix/resolve.ts
1514
- function createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues) {
1515
- const alpha = alphaSource.trim();
1516
- return normalizeColorFunctionWithDynamicAlpha(colorSource, CUSTOM_PROPERTY_RE.test(alpha) ? `var(${alpha})` : alpha, customPropertyValues);
1986
+ //#region src/style-targets/style.ts
1987
+ function postprocessGenericCss(result, _options) {
1988
+ return result;
1517
1989
  }
1518
- function tryResolveColorMix(node, customPropertyValues) {
1519
- const args = splitArguments(node.nodes);
1520
- if (args.length < 3) return;
1521
- const colorStopNodes = splitStopSegments(args[1] ?? []);
1522
- if (colorStopNodes.length < 2) return;
1523
- const colorNodes = trimNodes$1(colorStopNodes[0] ?? []);
1524
- const alphaNodes = trimNodes$1(colorStopNodes[1] ?? []);
1525
- const trailingNodes = trimNodes$1(args[2] ?? []);
1526
- if (!colorNodes.length || !alphaNodes.length || valueParser.stringify(trailingNodes).trim().toLowerCase() !== "transparent") return;
1527
- const colorSource = valueParser.stringify(colorNodes).trim();
1528
- const alphaSource = valueParser.stringify(alphaNodes).trim();
1529
- if (!colorSource || !alphaSource || INTERNAL_TAILWIND_ALPHA_RE.test(alphaSource)) return;
1530
- if (CURRENT_COLOR_RE.test(colorSource)) return {
1531
- value: colorSource,
1532
- deferred: false
1533
- };
1534
- if (DYNAMIC_ALPHA_RE.test(alphaSource)) {
1535
- const normalized = createRgbaWithAlpha(colorSource, alphaSource, customPropertyValues);
1536
- return normalized ? {
1537
- value: normalized,
1538
- deferred: true
1539
- } : {
1540
- value: colorSource,
1541
- deferred: true
1990
+ function createPostcssStyleTargetProfile(target) {
1991
+ switch (target) {
1992
+ case "mini-program": return {
1993
+ target,
1994
+ postprocess: postprocessMiniProgramCss
1995
+ };
1996
+ case "uni-app-x-css-uvue": return {
1997
+ target,
1998
+ postprocess: postprocessUniAppXUvueCss
1999
+ };
2000
+ case "uni-app-x-css-webview": return {
2001
+ target,
2002
+ postprocess: postprocessUniAppXWebviewCss
2003
+ };
2004
+ case "web": return {
2005
+ target,
2006
+ postprocess: postprocessWebCss
2007
+ };
2008
+ default: return {
2009
+ target,
2010
+ postprocess: postprocessGenericCss
1542
2011
  };
1543
2012
  }
1544
- const alpha = parseAlphaValue(alphaSource);
1545
- if (alpha === void 0) return;
1546
- const normalized = normalizeColorFunctionName(colorSource, alpha, customPropertyValues);
1547
- if (normalized) return {
1548
- value: normalized,
1549
- deferred: false
1550
- };
1551
- return {
1552
- value: colorSource,
1553
- deferred: false
1554
- };
1555
2013
  }
1556
2014
  //#endregion
1557
- //#region src/compat/color-mix.ts
1558
- const DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX = "__weapp_tw_var_fallback_";
1559
- function getStandaloneDynamicVarWithFallback(value) {
1560
- const nodes = valueParser(value).nodes.filter((node) => node.type !== "space" && node.type !== "comment");
1561
- const variable = nodes.length === 1 ? nodes[0] : void 0;
1562
- const property = variable?.type === "function" ? variable.nodes.find((node) => node.type === "word" && node.value.startsWith("--")) : void 0;
1563
- if (variable?.type !== "function" || variable.value.toLowerCase() !== "var" || property?.type !== "word" || isTailwindcssV4ThemeVariable(property.value) || !variable.nodes.some((node) => node.type === "div" && node.value === ",")) return;
1564
- return variable;
2015
+ //#region src/frameworks/shared.ts
2016
+ function isWebLikeStylePlatform(platform) {
2017
+ const normalized = platform?.trim().toLowerCase();
2018
+ return normalized === "h5" || normalized === "web" || normalized?.startsWith("web-") === true || normalized === "app" || normalized === "app-plus" || normalized?.startsWith("app-") === true;
1565
2019
  }
1566
- /**
1567
- * 保护带 fallback 的作者 CSS 变量,避免兼容插件把它错误静态化。
1568
- */
1569
- function protectDynamicVarFallbacks(css) {
1570
- if (!css.includes("var(") || !css.includes(",")) return {
1571
- css,
1572
- restore: (value) => value
1573
- };
1574
- const replacements = /* @__PURE__ */ new Map();
1575
- let root;
1576
- try {
1577
- root = postcss$1.parse(css);
1578
- } catch {
1579
- return {
1580
- css,
1581
- restore: (value) => value
1582
- };
1583
- }
1584
- root.walkDecls((decl) => {
1585
- if (!getStandaloneDynamicVarWithFallback(decl.value)) return;
1586
- const placeholder = `${DYNAMIC_VAR_FALLBACK_PLACEHOLDER_PREFIX}${replacements.size}__`;
1587
- replacements.set(placeholder, decl.value);
1588
- decl.value = placeholder;
1589
- });
1590
- if (replacements.size === 0) return {
1591
- css,
1592
- restore: (value) => value
1593
- };
1594
- return {
1595
- css: root.toString(),
1596
- restore(value) {
1597
- let restored = value;
1598
- for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
1599
- return restored;
1600
- }
1601
- };
2020
+ function resolveWebPlatformOrTarget(options, fallbackTarget) {
2021
+ return isWebLikeStylePlatform(options.platform) ? "web" : fallbackTarget;
1602
2022
  }
1603
- function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */ new Map()) {
1604
- if (!hasUnsupportedModernColorFunction(value)) return {
1605
- value,
1606
- changed: false,
1607
- hasUnsupported: false
1608
- };
1609
- const parsed = valueParser(value);
1610
- let changed = false;
1611
- parsed.walk((node) => {
1612
- if (node.type !== "function") return;
1613
- const name = node.value.toLowerCase();
1614
- const source = valueParser.stringify(node);
1615
- let normalized;
1616
- if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
1617
- else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
1618
- if (!normalized) return;
1619
- const mutableNode = node;
1620
- mutableNode.type = "word";
1621
- mutableNode.value = normalized;
1622
- delete mutableNode.nodes;
1623
- changed = true;
1624
- });
1625
- const nextValue = changed ? parsed.toString() : value;
2023
+ function createStaticTargetFrameworkStrategy(framework, fallbackTarget) {
1626
2024
  return {
1627
- value: nextValue,
1628
- changed,
1629
- hasUnsupported: hasUnsupportedModernColorFunction(nextValue)
2025
+ framework,
2026
+ resolveStyleTarget: (options) => resolveWebPlatformOrTarget(options, fallbackTarget)
1630
2027
  };
1631
2028
  }
1632
- function createPlaceholder(index) {
1633
- return `${PLACEHOLDER_PREFIX}${index}__`;
1634
- }
1635
- function unwrapProtectedSupports(cssRoot) {
1636
- cssRoot.walkAtRules("supports", (atRule) => {
1637
- if (!atRule.nodes || !atRule.toString().includes("__weapp_tw_color_mix_")) return;
1638
- atRule.replaceWith(atRule.nodes);
1639
- });
1640
- }
1641
- function protectDynamicColorMixAlpha(css, options = {}) {
1642
- if (!css.includes("color-mix")) return {
1643
- css,
1644
- restore: (value) => value
1645
- };
1646
- const replacements = /* @__PURE__ */ new Map();
1647
- const root = postcss$1.parse(css);
1648
- const customPropertyValues = new Map(options.customPropertyValues);
1649
- let changed = false;
1650
- root.walkDecls((decl) => {
1651
- if (decl.prop.startsWith("--") && !decl.value.includes("color-mix")) customPropertyValues.set(decl.prop, decl.value.trim());
1652
- });
1653
- root.walkDecls((decl) => {
1654
- if (!decl.value.includes("color-mix")) return;
1655
- const parsed = valueParser(decl.value);
1656
- let mutated = false;
1657
- parsed.walk((node) => {
1658
- if (node.type !== "function" || node.value.toLowerCase() !== "color-mix") return;
1659
- const resolved = tryResolveColorMix(node, customPropertyValues);
1660
- if (resolved) {
1661
- if (resolved.deferred) {
1662
- const placeholder = createPlaceholder(replacements.size);
1663
- replacements.set(placeholder, resolved.value);
1664
- const mutableNode = node;
1665
- mutableNode.type = "word";
1666
- mutableNode.value = placeholder;
1667
- delete mutableNode.nodes;
1668
- mutated = true;
1669
- return;
1670
- }
1671
- const mutableNode = node;
1672
- mutableNode.type = "word";
1673
- mutableNode.value = resolved.value;
1674
- delete mutableNode.nodes;
1675
- mutated = true;
1676
- }
1677
- });
1678
- if (mutated) {
1679
- decl.value = parsed.toString();
1680
- changed = true;
1681
- }
1682
- });
1683
- if (replacements.size > 0) unwrapProtectedSupports(root);
2029
+ //#endregion
2030
+ //#region src/frameworks/generic/index.ts
2031
+ const genericPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("generic", "generic");
2032
+ //#endregion
2033
+ //#region src/frameworks/kbone/index.ts
2034
+ const kbonePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("kbone", "generic");
2035
+ //#endregion
2036
+ //#region src/frameworks/mpx/index.ts
2037
+ const mpxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("mpx", "mini-program");
2038
+ //#endregion
2039
+ //#region src/frameworks/native/index.ts
2040
+ const nativePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("native", "mini-program");
2041
+ //#endregion
2042
+ //#region src/frameworks/remax/index.ts
2043
+ const remaxPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("remax", "mini-program");
2044
+ //#endregion
2045
+ //#region src/frameworks/taro/index.ts
2046
+ const taroPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("taro", "mini-program");
2047
+ //#endregion
2048
+ //#region src/frameworks/uni-app/index.ts
2049
+ const uniAppPostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app", "mini-program");
2050
+ //#endregion
2051
+ //#region src/frameworks/uni-app-vite/index.ts
2052
+ const uniAppVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("uni-app-vite", "mini-program");
2053
+ //#endregion
2054
+ //#region src/frameworks/uni-app-x/index.ts
2055
+ const uniAppXPostcssFrameworkStrategy = {
2056
+ framework: "uni-app-x",
2057
+ resolveStyleTarget: (options) => options.uniAppXCssTarget === "uvue" ? "uni-app-x-css-uvue" : "uni-app-x-css-webview"
2058
+ };
2059
+ //#endregion
2060
+ //#region src/frameworks/weapp-vite/index.ts
2061
+ const weappVitePostcssFrameworkStrategy = createStaticTargetFrameworkStrategy("weapp-vite", "mini-program");
2062
+ //#endregion
2063
+ //#region src/frameworks/index.ts
2064
+ function isUniAppXFramework(options) {
2065
+ if (options.uniAppX === false) return false;
2066
+ return options.uniAppX === true || options.appType === "uni-app-x";
2067
+ }
2068
+ function resolvePostcssFrameworkStrategy(options) {
2069
+ if (isUniAppXFramework(options)) return uniAppXPostcssFrameworkStrategy;
2070
+ switch (options.appType) {
2071
+ case "kbone": return kbonePostcssFrameworkStrategy;
2072
+ case "mpx": return mpxPostcssFrameworkStrategy;
2073
+ case "native": return nativePostcssFrameworkStrategy;
2074
+ case "remax": return remaxPostcssFrameworkStrategy;
2075
+ case "taro": return taroPostcssFrameworkStrategy;
2076
+ case "uni-app": return uniAppPostcssFrameworkStrategy;
2077
+ case "uni-app-vite": return uniAppVitePostcssFrameworkStrategy;
2078
+ case "weapp-vite": return weappVitePostcssFrameworkStrategy;
2079
+ default: return genericPostcssFrameworkStrategy;
2080
+ }
2081
+ }
2082
+ function resolvePostcssFrameworkProfile(options) {
2083
+ const strategy = resolvePostcssFrameworkStrategy(options);
2084
+ const target = strategy.resolveStyleTarget(options);
2085
+ const targetProfile = createPostcssStyleTargetProfile(target);
1684
2086
  return {
1685
- css: changed ? root.toString() : css,
1686
- restore(value) {
1687
- let restored = value;
1688
- for (const [placeholder, replacement] of replacements) restored = restored.split(placeholder).join(replacement);
1689
- return restored;
1690
- }
2087
+ framework: strategy.framework,
2088
+ target,
2089
+ branch: target,
2090
+ postprocess: targetProfile.postprocess
1691
2091
  };
1692
2092
  }
2093
+ function resolvePostcssStyleTarget(options) {
2094
+ return resolvePostcssFrameworkProfile(options).target;
2095
+ }
2096
+ //#endregion
2097
+ //#region src/branches/style.ts
2098
+ function resolvePostcssStyleBranch(options) {
2099
+ return resolvePostcssStyleTarget(options);
2100
+ }
2101
+ function resolvePostcssStyleBranchProfile(options) {
2102
+ return resolvePostcssFrameworkProfile(options);
2103
+ }
1693
2104
  //#endregion
1694
2105
  //#region src/compat/mini-program-css/cascade-layers.ts
1695
2106
  const LAYER_PATH_SEPARATOR = "";
@@ -1999,267 +2410,42 @@ function normalizeMiniProgramPrefixedDeclaration(decl) {
1999
2410
  if (prop.startsWith("-webkit-") && !isPreservedWebkitDeclaration(decl)) {
2000
2411
  decl.remove();
2001
2412
  return;
2002
- }
2003
- if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
2004
- }
2005
- function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
2006
- if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
2007
- }
2008
- //#endregion
2009
- //#region src/compat/mini-program-css/directives.ts
2010
- const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
2011
- const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
2012
- function hasTailwindcssV4Signal(css) {
2013
- if (TAILWIND_V4_BANNER_RE.test(css)) return true;
2014
- const root = postcss$1.parse(css);
2015
- let hasProperty = false;
2016
- root.walkAtRules("property", (atRule) => {
2017
- if (atRule.params.trim().startsWith("--tw-")) {
2018
- hasProperty = true;
2019
- return false;
2020
- }
2021
- });
2022
- return hasProperty;
2023
- }
2024
- function unwrapTailwindSourceMedia(root) {
2025
- root.walkAtRules("media", (atRule) => {
2026
- if (!atRule.params.startsWith("source(")) return;
2027
- if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
2028
- else atRule.remove();
2029
- });
2030
- }
2031
- function removeTailwindGenerationDirectives(root) {
2032
- root.walkComments((comment) => {
2033
- if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
2034
- });
2035
- root.walkAtRules((atRule) => {
2036
- if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
2037
- });
2038
- }
2039
- //#endregion
2040
- //#region src/compat/mini-program-css/selectors.ts
2041
- const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
2042
- const MINI_PROGRAM_ELEMENT_SCOPE_SELECTOR = "view,text,::after,::before";
2043
- const MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
2044
- "view",
2045
- "text",
2046
- ":before",
2047
- ":after",
2048
- "::before",
2049
- "::after"
2050
- ]);
2051
- const MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS = /* @__PURE__ */ new Set([
2052
- ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS,
2053
- "button",
2054
- "input",
2055
- "textarea",
2056
- "canvas",
2057
- "video",
2058
- "audio"
2059
- ]);
2060
- const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set(["*", ...MINI_PROGRAM_ELEMENT_SCOPE_SELECTORS]);
2061
- const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
2062
- ":host",
2063
- ":root",
2064
- "page",
2065
- ".tw-root",
2066
- "wx-root-portal-content"
2067
- ]);
2068
- function normalizeMiniProgramThemeScopeSelector(root) {
2069
- if (root === false) return ":host";
2070
- if (root === void 0) return MINI_PROGRAM_THEME_SCOPE_SELECTOR;
2071
- const selectors = Array.isArray(root) ? root.filter(Boolean) : [root];
2072
- return [.../* @__PURE__ */ new Set([":host", ...selectors])].join(",");
2073
- }
2074
- const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
2075
- const ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(.does-not-exist)"];
2076
- const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = /* @__PURE__ */ new Set([
2077
- ":-moz-focusring",
2078
- ":-moz-ui-invalid",
2079
- "::-webkit-calendar-picker-indicator",
2080
- "::-webkit-date-and-time-value",
2081
- "::-webkit-datetime-edit",
2082
- "::-webkit-datetime-edit-day-field",
2083
- "::-webkit-datetime-edit-fields-wrapper",
2084
- "::-webkit-datetime-edit-hour-field",
2085
- "::-webkit-datetime-edit-meridiem-field",
2086
- "::-webkit-datetime-edit-millisecond-field",
2087
- "::-webkit-datetime-edit-minute-field",
2088
- "::-webkit-datetime-edit-month-field",
2089
- "::-webkit-datetime-edit-second-field",
2090
- "::-webkit-datetime-edit-year-field",
2091
- "::-webkit-inner-spin-button",
2092
- "::-webkit-input-placeholder",
2093
- "::-webkit-outer-spin-button",
2094
- "::-webkit-search-decoration",
2095
- "::placeholder",
2096
- "[hidden]:where(:not([hidden='until-found']))"
2097
- ]);
2098
- const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = /* @__PURE__ */ new Set([
2099
- "a",
2100
- "abbr:where([title])",
2101
- "audio",
2102
- "b",
2103
- "button",
2104
- "canvas",
2105
- "code",
2106
- "embed",
2107
- "h1",
2108
- "h2",
2109
- "h3",
2110
- "h4",
2111
- "h5",
2112
- "h6",
2113
- "hr",
2114
- "html",
2115
- "iframe",
2116
- "img",
2117
- "input",
2118
- "input:where([type='button'],[type='reset'],[type='submit'])",
2119
- "kbd",
2120
- "menu",
2121
- "object",
2122
- "ol",
2123
- "optgroup",
2124
- "pre",
2125
- "progress",
2126
- "samp",
2127
- "select",
2128
- "select[multiple]optgroup",
2129
- "select[multiple]optgroupoption",
2130
- "select[size]optgroup",
2131
- "select[size]optgroupoption",
2132
- "small",
2133
- "strong",
2134
- "sub",
2135
- "summary",
2136
- "sup",
2137
- "svg",
2138
- "table",
2139
- "textarea",
2140
- "ul",
2141
- "video"
2142
- ]);
2143
- const MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS = /* @__PURE__ */ new Set([...MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS, "::file-selector-button"]);
2144
- function normalizeSelector$1(selector) {
2145
- return selector.trim().replace(/\s+/g, "");
2146
- }
2147
- function normalizePseudoElementSelector(selector) {
2148
- return normalizeSelector$1(selector).replace(/^:(before|after)$/, "::$1");
2149
- }
2150
- function getRuleSelectors(rule) {
2151
- return rule.selector.split(",").map(normalizePseudoElementSelector).filter(Boolean);
2152
- }
2153
- function getSortedRuleSelectorKey(rule) {
2154
- return getRuleSelectors(rule).sort().join(",");
2155
- }
2156
- function isUnsupportedBrowserSelector(selector) {
2157
- const normalized = normalizeSelector$1(selector);
2158
- return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized) && !MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalized);
2159
- }
2160
- function isUnsupportedBrowserPreflightSelector(selector) {
2161
- const normalizedParts = selector.split(",").map(normalizeSelector$1).filter(Boolean);
2162
- return normalizedParts.length > 1 && normalizedParts.every((part) => MINI_PROGRAM_UNSUPPORTED_BROWSER_PREFLIGHT_SELECTOR_PARTS.has(part));
2163
- }
2164
- function isMiniProgramNativeElementSelector(selector) {
2165
- return MINI_PROGRAM_NATIVE_ELEMENT_SELECTORS.has(normalizePseudoElementSelector(selector));
2166
- }
2167
- function isMiniProgramPreflightSelector(selectors) {
2168
- 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");
2169
- }
2170
- function isMiniProgramThemeScopeSelector(selectors) {
2171
- return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
2172
- }
2173
- //#endregion
2174
- //#region src/compat/mini-program-css/predicates.ts
2175
- const PREFLIGHT_RESET_PROPS = /* @__PURE__ */ new Set([
2176
- "box-sizing",
2177
- "border",
2178
- "border-width",
2179
- "border-style",
2180
- "border-color",
2181
- "margin",
2182
- "padding"
2183
- ]);
2184
- const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
2185
- const TW_CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
2186
- const BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS = /* @__PURE__ */ new Map([["button", /* @__PURE__ */ new Set(["appearance:button", "-moz-appearance:button"])], ["textarea", /* @__PURE__ */ new Set(["resize:vertical"])]]);
2187
- function hasTailwindPreflightDeclaration(rule) {
2188
- let hasTailwindVar = false;
2189
- let hasResetProp = false;
2190
- rule.walkDecls((decl) => {
2191
- if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
2192
- if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
2193
- });
2194
- return hasTailwindVar || hasResetProp;
2195
- }
2196
- function hasTailwindVariableDeclaration(rule) {
2197
- let hasTailwindVar = false;
2198
- rule.walkDecls((decl) => {
2199
- if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
2200
- });
2201
- return hasTailwindVar;
2202
- }
2203
- function isCustomPropertyRule(rule) {
2204
- let hasDeclaration = false;
2205
- let allCustomProperties = true;
2206
- rule.each((node) => {
2207
- if (node.type !== "decl") return;
2208
- hasDeclaration = true;
2209
- if (!node.prop.startsWith("--")) allCustomProperties = false;
2210
- });
2211
- return hasDeclaration && allCustomProperties;
2413
+ }
2414
+ if (hasUnsupportedWebkitKeywordValue(decl)) decl.remove();
2212
2415
  }
2213
- function isEmptyTwContentDeclaration(decl) {
2214
- return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
2416
+ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
2417
+ if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
2215
2418
  }
2216
- function isOnlyTwContentDeclarations$1(rule) {
2217
- let hasDeclaration = false;
2218
- let onlyContentVariable = true;
2219
- rule.walkDecls((decl) => {
2220
- hasDeclaration = true;
2221
- if (decl.prop !== "--tw-content") onlyContentVariable = false;
2419
+ //#endregion
2420
+ //#region src/compat/mini-program-css/directives.ts
2421
+ const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
2422
+ const GENERATOR_PLACEHOLDER_COMMENT_RE = /^\s*(?:!\s*)?weapp-tailwindcss generator-placeholder\s*$/i;
2423
+ function hasTailwindcssV4Signal(css) {
2424
+ if (TAILWIND_V4_BANNER_RE.test(css)) return true;
2425
+ const root = postcss$1.parse(css);
2426
+ let hasProperty = false;
2427
+ root.walkAtRules("property", (atRule) => {
2428
+ if (atRule.params.trim().startsWith("--tw-")) {
2429
+ hasProperty = true;
2430
+ return false;
2431
+ }
2222
2432
  });
2223
- return hasDeclaration && onlyContentVariable;
2224
- }
2225
- function isPseudoContentInitRule(rule) {
2226
- const selector = rule.selector.replace(/\s+/g, "");
2227
- return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations$1(rule);
2433
+ return hasProperty;
2228
2434
  }
2229
- function usesTwContentVariable(root) {
2230
- let used = false;
2231
- root.walkDecls((decl) => {
2232
- if (TW_CONTENT_VAR_RE.test(decl.value)) used = true;
2435
+ function unwrapTailwindSourceMedia(root) {
2436
+ root.walkAtRules("media", (atRule) => {
2437
+ if (!atRule.params.startsWith("source(")) return;
2438
+ if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
2439
+ else atRule.remove();
2233
2440
  });
2234
- return used;
2235
- }
2236
- function isMiniProgramPreflightRule(node) {
2237
- if (node.type !== "rule") return false;
2238
- const selectors = getRuleSelectors(node);
2239
- if (!isMiniProgramPreflightSelector(selectors)) return false;
2240
- if (selectors.includes("*")) return hasTailwindPreflightDeclaration(node);
2241
- if (hasTailwindVariableDeclaration(node)) return true;
2242
- return selectors.some((selector) => selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after") && selectors.some((selector) => selector === "view" || selector === "text") && hasTailwindPreflightDeclaration(node);
2243
2441
  }
2244
- function isBrowserElementPreflightRule(node) {
2245
- if (node.type !== "rule") return false;
2246
- const selectors = getRuleSelectors(node);
2247
- if (selectors.length !== 1) return false;
2248
- const declarations = BROWSER_PREFLIGHT_SINGLE_ELEMENT_DECLARATIONS.get(selectors[0]);
2249
- if (!declarations) return false;
2250
- let hasDeclaration = false;
2251
- let allBrowserPreflightDeclarations = true;
2252
- node.each((child) => {
2253
- if (child.type !== "decl") return;
2254
- hasDeclaration = true;
2255
- const key = `${child.prop.toLowerCase()}:${child.value.trim().toLowerCase()}`;
2256
- if (!declarations.has(key)) allBrowserPreflightDeclarations = false;
2442
+ function removeTailwindGenerationDirectives(root) {
2443
+ root.walkComments((comment) => {
2444
+ if (GENERATOR_PLACEHOLDER_COMMENT_RE.test(comment.text)) comment.remove();
2445
+ });
2446
+ root.walkAtRules((atRule) => {
2447
+ if (atRule.name === "config" || atRule.name === "source" || atRule.name === "tailwind" || atRule.name === "reference" || atRule.name === "plugin") atRule.remove();
2257
2448
  });
2258
- return hasDeclaration && allBrowserPreflightDeclarations;
2259
- }
2260
- function isMiniProgramThemeVariableRule(node) {
2261
- if (node.type !== "rule") return false;
2262
- return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
2263
2449
  }
2264
2450
  //#endregion
2265
2451
  //#region src/compat/mini-program-css/hoist.ts
@@ -2414,191 +2600,6 @@ function createPreflightResetRule(cssPreflight) {
2414
2600
  return rule.nodes?.length ? rule : void 0;
2415
2601
  }
2416
2602
  //#endregion
2417
- //#region src/compat/mini-program-css/color-gamut.ts
2418
- const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
2419
- const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
2420
- function isDisplayP3MediaRule(atRule) {
2421
- return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
2422
- }
2423
- function isDisplayP3Declaration(decl) {
2424
- return DISPLAY_P3_VALUE_RE.test(decl.value);
2425
- }
2426
- //#endregion
2427
- //#region src/compat/mini-program-css/root-cleanups.ts
2428
- function removeSpecificityPlaceholders(root) {
2429
- root.walkRules((rule) => {
2430
- if (!rule.selectors || rule.selectors.length === 0) return;
2431
- let changed = false;
2432
- const selectors = rule.selectors.map((selector) => {
2433
- let next = selector;
2434
- for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
2435
- if (next !== selector) changed = true;
2436
- return next;
2437
- });
2438
- if (changed) rule.selectors = selectors;
2439
- });
2440
- }
2441
- function hasMiniProgramCssSpecificityPlaceholders(source) {
2442
- return SPECIFICITY_PLACEHOLDER_SUFFIXES.some((suffix) => source.includes(suffix));
2443
- }
2444
- function stripMiniProgramCssSpecificityPlaceholders(source) {
2445
- let output = source;
2446
- for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
2447
- return output;
2448
- }
2449
- const removeSpecificityPlaceholdersFromSource = stripMiniProgramCssSpecificityPlaceholders;
2450
- function removeRootSpecificityPlaceholders(root) {
2451
- root.walkRules((rule) => {
2452
- if (!rule.selectors || rule.selectors.length === 0) return;
2453
- let changed = false;
2454
- const selectors = rule.selectors.map((selector) => {
2455
- let next = selector;
2456
- for (const scopeSelector of MINI_PROGRAM_THEME_SCOPE_SELECTORS) for (const suffix of ROOT_SPECIFICITY_PLACEHOLDER_SUFFIXES) {
2457
- const target = `${scopeSelector}${suffix}`;
2458
- if (next.includes(target)) next = next.split(target).join(scopeSelector);
2459
- }
2460
- if (next !== selector) changed = true;
2461
- return next;
2462
- });
2463
- if (changed) rule.selectors = selectors;
2464
- });
2465
- }
2466
- function isEffectivelyEmptyContainer(container) {
2467
- return container.nodes !== void 0 && container.nodes.every((node) => node.type === "comment");
2468
- }
2469
- function removeEmptyAtRules(root) {
2470
- let removed = 0;
2471
- const visit = (container) => {
2472
- for (const node of [...container.nodes ?? []]) {
2473
- if (!("nodes" in node) || node.nodes === void 0) continue;
2474
- visit(node);
2475
- if (node.type === "atrule" && node.parent && isEffectivelyEmptyContainer(node)) {
2476
- node.remove();
2477
- removed++;
2478
- }
2479
- }
2480
- };
2481
- visit(root);
2482
- return removed;
2483
- }
2484
- function removeEmptyBlockAtRules(root) {
2485
- let removed = 0;
2486
- root.walkAtRules((atRule) => {
2487
- if (atRule.nodes?.length === 0) {
2488
- atRule.remove();
2489
- removed++;
2490
- }
2491
- });
2492
- return removed;
2493
- }
2494
- function removeEmptyAtRuleAncestors(parent) {
2495
- while (parent?.type === "atrule" && isEffectivelyEmptyContainer(parent)) {
2496
- const nextParent = parent.parent;
2497
- parent.remove();
2498
- parent = nextParent?.type === "atrule" ? nextParent : void 0;
2499
- }
2500
- }
2501
- function removeUnsupportedBrowserSelectors(root) {
2502
- root.walkRules((rule) => {
2503
- if (!rule.selectors || rule.selectors.length === 0) return;
2504
- if (isUnsupportedBrowserPreflightSelector(rule.selector)) {
2505
- const parent = rule.parent;
2506
- rule.remove();
2507
- removeEmptyAtRuleAncestors(parent);
2508
- return;
2509
- }
2510
- if (isBrowserElementPreflightRule(rule)) {
2511
- const parent = rule.parent;
2512
- rule.remove();
2513
- removeEmptyAtRuleAncestors(parent);
2514
- return;
2515
- }
2516
- const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
2517
- if (selectors.length === rule.selectors.length) return;
2518
- if (selectors.length === 0) {
2519
- const parent = rule.parent;
2520
- rule.remove();
2521
- removeEmptyAtRuleAncestors(parent);
2522
- return;
2523
- }
2524
- rule.selectors = selectors;
2525
- });
2526
- }
2527
- function removeDeclarationAndEmptyRule$1(decl) {
2528
- const parent = decl.parent;
2529
- decl.remove();
2530
- if (parent?.type === "rule" && parent.nodes.length === 0) {
2531
- const ruleParent = parent.parent;
2532
- parent.remove();
2533
- removeEmptyAtRuleAncestors(ruleParent);
2534
- }
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
- }
2541
- function removeDisplayP3Declarations(root) {
2542
- root.walkAtRules((atRule) => {
2543
- if (isDisplayP3MediaRule(atRule)) {
2544
- const parent = atRule.parent;
2545
- atRule.remove();
2546
- removeEmptyAtRuleAncestors(parent);
2547
- }
2548
- });
2549
- }
2550
- const SIMPLE_MIN_WIDTH_MEDIA_RE = /^\(\s*min-width\s*:[^)]+\)$/i;
2551
- const TAILWIND_GENERATED_TOKEN_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
2552
- function isContainerMaxWidthOnlyRule(rule) {
2553
- if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
2554
- const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
2555
- return declarations.length === 1 && declarations[0]?.prop === "max-width" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
2556
- }
2557
- function removeTailwindContainerMaxWidthMediaRules(root) {
2558
- root.walkAtRules("media", (atRule) => {
2559
- if (!SIMPLE_MIN_WIDTH_MEDIA_RE.test(atRule.params.trim())) return;
2560
- atRule.walkRules((rule) => {
2561
- if (!isContainerMaxWidthOnlyRule(rule)) return;
2562
- const parent = rule.parent;
2563
- rule.remove();
2564
- removeEmptyAtRuleAncestors(parent);
2565
- });
2566
- });
2567
- }
2568
- function isContainerWidthOnlyRule(rule) {
2569
- if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return false;
2570
- const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
2571
- return declarations.length === 1 && declarations[0]?.prop === "width" && declarations[0].value.trim() === "100%" && (rule.nodes ?? []).every((node) => node.type === "decl" || node.type === "comment");
2572
- }
2573
- function isTailwindGeneratedContainerRule(rule) {
2574
- const previous = rule.prev();
2575
- return previous?.type === "comment" && TAILWIND_GENERATED_TOKEN_COMMENT_RE.test(previous.text);
2576
- }
2577
- function removeTailwindContainerWidthRules(root, options = {}) {
2578
- root.walkRules((rule) => {
2579
- if (!isContainerWidthOnlyRule(rule)) return;
2580
- if (options.generatedOnly && !isTailwindGeneratedContainerRule(rule)) return;
2581
- const parent = rule.parent;
2582
- if (isTailwindGeneratedContainerRule(rule)) rule.prev()?.remove();
2583
- rule.remove();
2584
- removeEmptyAtRuleAncestors(parent);
2585
- });
2586
- }
2587
- function removeUnsupportedModernColorDeclarations(root) {
2588
- const customPropertyValues = /* @__PURE__ */ new Map();
2589
- root.walkDecls((decl) => {
2590
- if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
2591
- });
2592
- root.walkDecls((decl) => {
2593
- const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
2594
- if (normalized.changed) {
2595
- decl.value = normalized.value;
2596
- if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
2597
- }
2598
- if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
2599
- });
2600
- }
2601
- //#endregion
2602
2603
  //#region src/compat/mini-program-css/theme.ts
2603
2604
  function collectThemeVariableRule(root, options = {}) {
2604
2605
  const themeRules = [];
@@ -2635,7 +2636,7 @@ function finalizeMiniProgramCssRoot(root, options = {}) {
2635
2636
  removeRootSpecificityPlaceholders(root);
2636
2637
  removeUnsupportedBrowserSelectors(root);
2637
2638
  removeDisplayP3Declarations(root);
2638
- removeEmptyStandardPropertyFallbacks(root);
2639
+ removeEmptyStandardDeclarations(root);
2639
2640
  removeTailwindContainerMaxWidthMediaRules(root);
2640
2641
  removeTailwindContainerWidthRules(root, { generatedOnly: true });
2641
2642
  removeUnsupportedModernColorDeclarations(root);