@weapp-tailwindcss/postcss 3.1.5 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  export declare const COLOR_MIX_NAME = "color-mix";
2
2
  export declare const MODERN_COLOR_FUNCTION_NAMES: Set<string>;
3
+ export declare const MODERN_COLOR_SYNTAX_FUNCTION_NAMES: Set<string>;
3
4
  export declare const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
4
5
  export declare const DYNAMIC_ALPHA_RE: RegExp;
5
6
  export declare const INTERNAL_TAILWIND_ALPHA_RE: RegExp;
@@ -1,2 +1,3 @@
1
1
  export declare function isDisplayP3ColorFunction(colorSource: string): boolean;
2
+ export declare function isModernColorSyntaxFunction(colorSource: string): boolean;
2
3
  export declare function hasUnsupportedModernColorFunction(value: string): boolean;
@@ -9,6 +9,8 @@ export declare function collectUsedTailwindcssV4Variables(root: Root): Set<strin
9
9
  export declare function usesTailwindcssV4ContentVariable(root: Root): boolean;
10
10
  export declare function createUsedCssVarsV4Nodes(usedProps: ReadonlySet<string>): PostcssDeclaration[];
11
11
  export declare function createMissingCssVarsV4Nodes(root: Root, usedProps: ReadonlySet<string>): PostcssDeclaration[];
12
+ export declare function normalizeTailwindcssV4GradientPosition(value: string): string;
13
+ export declare function normalizeTailwindcssV4InfinityCalcValue(value: string): string;
12
14
  export declare function mergeTailwindcssV4GradientDirectionRules(root: Root): void;
13
15
  export declare function appendTailwindcssV4MiniProgramGradientRules(root: Root): void;
14
16
  export declare function isTailwindcssV4ModernCheck(atRule: AtRule): boolean;
@@ -5,3 +5,6 @@ export interface NormalizedWebCssCompatOptions {
5
5
  }
6
6
  export declare function normalizeWebCssCompatOptions(options: WebCssCompatUserOptions | undefined): NormalizedWebCssCompatOptions;
7
7
  export declare function transformWebCssCompat(css: string, options: WebCssCompatUserOptions | undefined): string;
8
+ export declare function transformWebCssSafeSelectors(css: string, options?: {
9
+ escapeMap?: Record<string, string> | undefined;
10
+ } | undefined): string;
@@ -3,6 +3,9 @@ import type { TailwindCssDirectiveOptions } from './directives';
3
3
  export interface RewriteLocalCssImportRequestOptions {
4
4
  styleOutputExtension?: string | undefined;
5
5
  }
6
+ export interface RestoreLocalCssImportOptions {
7
+ outputFile?: string | undefined;
8
+ }
6
9
  export declare function createCssSourceOrderAppend(base: string, extra: string): string;
7
10
  export declare function isLocalCssImportRequest(request: string): boolean;
8
11
  export declare function removeTailwindSourceDirectivesRoot(root: Root, options?: TailwindCssDirectiveOptions): boolean;
@@ -19,7 +22,7 @@ export declare function splitLocalCssImports(source: string): {
19
22
  imports: string;
20
23
  source: string;
21
24
  } | undefined;
22
- export declare function restoreLocalCssImports(css: string, imports: string | undefined): string;
25
+ export declare function restoreLocalCssImports(css: string, imports: string | undefined, options?: RestoreLocalCssImportOptions): string;
23
26
  export declare function normalizeOutputImportRequest(request: string, styleOutputExtension: string | undefined): string;
24
27
  export declare function rewriteLocalCssImportRequestsForOutputRoot(root: Root, options?: RewriteLocalCssImportRequestOptions): boolean;
25
28
  export declare function rewriteLocalCssImportRequestsForOutput(css: string, options?: RewriteLocalCssImportRequestOptions): string;
@@ -1,5 +1,5 @@
1
1
  import type { IStyleHandlerOptions, WebCssCompatUserOptions } from '../types';
2
- export type WeappTailwindcssPostcssTarget = 'weapp' | 'web' | 'tailwind';
2
+ export type WeappTailwindcssPostcssTarget = 'weapp' | 'web';
3
3
  export interface TailwindCandidateSource {
4
4
  content: string;
5
5
  extension?: string | undefined;
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { type DynamicColorMixAlphaProtection, type DynamicColorMixAlphaProtectio
2
2
  export { finalizeMiniProgramCss, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, pruneMiniProgramGeneratedCss, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, stripMiniProgramCssSpecificityPlaceholders, unwrapUnsupportedCascadeLayers, } from './compat/mini-program-css';
3
3
  export { normalizeMiniProgramPrefixedDeclaration, removeUnsupportedMiniProgramPrefixedAtRule, } from './compat/mini-program-prefixes';
4
4
  export { convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxValueToRem, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssWebRpxDeclarations, type TailwindcssRpxToRemOptions, } from './compat/tailwindcss-rpx';
5
- export { type NormalizedWebCssCompatOptions, normalizeWebCssCompatOptions, transformWebCssCompat, } from './compat/web-css';
5
+ export { type NormalizedWebCssCompatOptions, normalizeWebCssCompatOptions, transformWebCssCompat, transformWebCssSafeSelectors, } from './compat/web-css';
6
6
  export { compileCssMacroConditionalComments, CSS_MACRO_STYLE_OPTIONS_MARKER, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, transformCssMacroCss, transformCssMacroTailwindV4Source, withCssMacroStyleOptions, } from './css-macro/auto';
7
7
  export { CSS_MACRO_POSTCSS_PLUGIN_NAME, default as cssMacroPostcssPlugin } from './css-macro/postcss';
8
8
  export { createWeappTailwindcssPostcssPlugin } from './generator-plugin';
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ postcss_value_parser = require_rolldown_runtime.__toESM(postcss_value_parser);
11
11
  let autoprefixer = require("autoprefixer");
12
12
  let autoprefixer$1 = require_rolldown_runtime.__toESM(autoprefixer, 1);
13
13
  autoprefixer = require_rolldown_runtime.__toESM(autoprefixer);
14
+ let _weapp_core_escape = require("@weapp-core/escape");
14
15
  let node_path = require("node:path");
15
16
  node_path = require_rolldown_runtime.__toESM(node_path);
16
17
  let node_process = require("node:process");
@@ -31,7 +32,6 @@ let postcss_rem_to_responsive_pixel = require("postcss-rem-to-responsive-pixel")
31
32
  postcss_rem_to_responsive_pixel = require_rolldown_runtime.__toESM(postcss_rem_to_responsive_pixel);
32
33
  let postcss_rule_unit_converter = require("postcss-rule-unit-converter");
33
34
  postcss_rule_unit_converter = require_rolldown_runtime.__toESM(postcss_rule_unit_converter);
34
- let _weapp_core_escape = require("@weapp-core/escape");
35
35
  let postcss_load_config = require("postcss-load-config");
36
36
  postcss_load_config = require_rolldown_runtime.__toESM(postcss_load_config);
37
37
  const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
@@ -40,6 +40,13 @@ const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
40
40
  "lch",
41
41
  "lab"
42
42
  ]);
43
+ const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
44
+ "rgb",
45
+ "rgba",
46
+ "hsl",
47
+ "hsla",
48
+ "hwb"
49
+ ]);
43
50
  const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
44
51
  const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
45
52
  const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
@@ -52,13 +59,21 @@ const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
52
59
  function isDisplayP3ColorFunction(colorSource) {
53
60
  return /^color\(\s*display-p3\b/i.test(colorSource.trim());
54
61
  }
62
+ function isModernColorSyntaxFunction(colorSource) {
63
+ const parsed = (0, postcss_value_parser.default)(colorSource.trim());
64
+ const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
65
+ if (node?.type !== "function") return false;
66
+ const name = node.value.toLowerCase();
67
+ if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
68
+ return !node.nodes.some((child) => child.type === "div" && child.value === ",");
69
+ }
55
70
  function hasUnsupportedModernColorFunction(value) {
56
71
  const parsed = (0, postcss_value_parser.default)(value);
57
72
  let hasUnsupported = false;
58
73
  parsed.walk((node) => {
59
74
  if (node.type !== "function") return;
60
75
  const name = node.value.toLowerCase();
61
- if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node))) {
76
+ if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(postcss_value_parser.default.stringify(node)) || isModernColorSyntaxFunction(postcss_value_parser.default.stringify(node))) {
62
77
  hasUnsupported = true;
63
78
  return false;
64
79
  }
@@ -6885,7 +6900,7 @@ function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */
6885
6900
  const name = node.value.toLowerCase();
6886
6901
  const source = postcss_value_parser.default.stringify(node);
6887
6902
  let normalized;
6888
- if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
6903
+ if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
6889
6904
  else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
6890
6905
  if (!normalized) return;
6891
6906
  const mutableNode = node;
@@ -7269,10 +7284,9 @@ function createCssVarNodes(definitions) {
7269
7284
  }
7270
7285
  //#endregion
7271
7286
  //#region src/compat/tailwindcss-v4.ts
7272
- const OKLAB_SUFFIX = "in oklab";
7273
- const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
7274
7287
  const RADIUS_THRESHOLD = 1e5;
7275
7288
  const CLAMP_PX = 9999;
7289
+ const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)$/i;
7276
7290
  const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
7277
7291
  const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
7278
7292
  const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
@@ -7410,6 +7424,9 @@ function normalizeDeclarationValue(value) {
7410
7424
  function normalizeTailwindcssV4GradientPosition(value) {
7411
7425
  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();
7412
7426
  }
7427
+ function normalizeTailwindcssV4InfinityCalcValue(value) {
7428
+ return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
7429
+ }
7413
7430
  function normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl) {
7414
7431
  const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
7415
7432
  if (normalized) return normalized;
@@ -7454,6 +7471,7 @@ function reorderTailwindcssV4GradientDirectionRule(rule) {
7454
7471
  else if (node.prop === "background-image" && node.value.includes("linear-gradient(")) gradientBackgroundDecls.push(node);
7455
7472
  }
7456
7473
  if (gradientPositionDecls.length === 0 || gradientBackgroundDecls.length === 0) return;
7474
+ for (const decl of gradientPositionDecls) decl.value = normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl);
7457
7475
  const anchor = rule.nodes.find((node) => {
7458
7476
  return node.type === "decl" && (node.prop === "--tw-gradient-position" || node.prop === "background-image" && node.value.includes("linear-gradient("));
7459
7477
  });
@@ -7467,6 +7485,9 @@ function mergeTailwindcssV4GradientDirectionRules(root) {
7467
7485
  const seen = /* @__PURE__ */ new Map();
7468
7486
  root.walkRules((rule) => {
7469
7487
  if (!isTailwindcssV4GradientDirectionRule(rule)) return;
7488
+ rule.walkDecls("--tw-gradient-position", (decl) => {
7489
+ decl.value = normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl);
7490
+ });
7470
7491
  const selector = rule.selector.trim();
7471
7492
  const previous = seen.get(selector);
7472
7493
  if (!previous || previous.parent !== rule.parent) {
@@ -7757,12 +7778,16 @@ function normalizeTailwindcssV4Declaration(decl) {
7757
7778
  decl.value = normalizedGradientPositionFallback;
7758
7779
  changed = true;
7759
7780
  }
7760
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
7761
- decl.value = decl.parent?.type === "rule" ? normalizeTailwindcssV4GradientDirectionDeclaration(decl.parent, decl) : normalizeTailwindcssV4GradientPosition(decl.value);
7762
- return true;
7781
+ if (decl.prop === "--tw-gradient-position") {
7782
+ const nextValue = decl.parent?.type === "rule" ? normalizeTailwindcssV4GradientDirectionDeclaration(decl.parent, decl) : normalizeTailwindcssV4GradientPosition(decl.value);
7783
+ if (nextValue !== decl.value) {
7784
+ decl.value = nextValue;
7785
+ return true;
7786
+ }
7763
7787
  }
7764
- if (INFINITY_CALC_REGEXP.test(decl.value)) {
7765
- decl.value = `${CLAMP_PX}px`;
7788
+ const normalizedInfinityCalcValue = normalizeTailwindcssV4InfinityCalcValue(decl.value);
7789
+ if (normalizedInfinityCalcValue !== decl.value) {
7790
+ decl.value = normalizedInfinityCalcValue;
7766
7791
  return true;
7767
7792
  }
7768
7793
  if (decl.prop.includes("radius")) {
@@ -60655,6 +60680,27 @@ const creator$1 = (e) => {
60655
60680
  };
60656
60681
  creator$1.postcss = !0;
60657
60682
  //#endregion
60683
+ //#region src/shared.ts
60684
+ const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
60685
+ function getEscapeOptions(escapeMap) {
60686
+ let cached = escapeOptionsCache.get(escapeMap);
60687
+ if (!cached) {
60688
+ cached = { map: escapeMap };
60689
+ escapeOptionsCache.set(escapeMap, cached);
60690
+ }
60691
+ return cached;
60692
+ }
60693
+ function internalCssSelectorReplacer(selectors, options) {
60694
+ const escapeMap = options?.escapeMap;
60695
+ if (escapeMap === void 0 || escapeMap === _weapp_core_escape.MappingChars2String) return (0, _weapp_core_escape.escape)(selectors);
60696
+ return (0, _weapp_core_escape.escape)(selectors, getEscapeOptions(escapeMap));
60697
+ }
60698
+ function composeIsPseudo(strs) {
60699
+ if (typeof strs === "string") return strs;
60700
+ if (strs.length > 1) return `:is(${strs.join(",")})`;
60701
+ return strs.join("");
60702
+ }
60703
+ //#endregion
60658
60704
  //#region src/compat/web-css.ts
60659
60705
  const disabledFeatures = {
60660
60706
  theme: false,
@@ -60778,18 +60824,29 @@ function resolveCustomPropertyVarValue(value, customPropertyValues) {
60778
60824
  });
60779
60825
  return changed ? parsed.toString() : value;
60780
60826
  }
60781
- function insertModernColorFallbackDeclaration(decl, fallbackValue) {
60782
- if (decl.prev()?.type === "decl" && decl.prev().prop === decl.prop && decl.prev().value === fallbackValue) return;
60783
- decl.cloneBefore({ value: fallbackValue });
60827
+ function usesResolvableTailwindColorVariable(value, customPropertyValues) {
60828
+ if (!value.includes("var(")) return false;
60829
+ const parsed = (0, postcss_value_parser.default)(value);
60830
+ let usesColorVariable = false;
60831
+ parsed.walk((node) => {
60832
+ if (node.type !== "function" || node.value.toLowerCase() !== "var") return;
60833
+ const propertyNode = node.nodes.find((child) => child.type === "word" && child.value.startsWith("--color-"));
60834
+ if (propertyNode && customPropertyValues.has(propertyNode.value)) usesColorVariable = true;
60835
+ });
60836
+ return usesColorVariable;
60784
60837
  }
60785
60838
  function normalizeModernColorDeclarations(root, features) {
60786
60839
  if (!features.oklch && !features.colorFunctions) return;
60787
60840
  const customPropertyValues = collectCustomPropertyValues(root);
60788
60841
  root.walkDecls((decl) => {
60789
- const normalized = normalizeModernColorValue(resolveCustomPropertyVarValue(decl.value, customPropertyValues), customPropertyValues);
60790
- if (!normalized.changed) return;
60791
- if (!features.colorFunctions && !/oklch|oklab/i.test(decl.value)) return;
60792
- insertModernColorFallbackDeclaration(decl, normalized.value);
60842
+ const value = resolveCustomPropertyVarValue(decl.value, customPropertyValues);
60843
+ const normalized = normalizeModernColorValue(value, customPropertyValues);
60844
+ if (!normalized.changed) {
60845
+ if (value !== decl.value && usesResolvableTailwindColorVariable(decl.value, customPropertyValues)) decl.value = value;
60846
+ return;
60847
+ }
60848
+ if (!features.colorFunctions && !/oklch|oklab/i.test(value)) return;
60849
+ decl.value = normalized.value;
60793
60850
  });
60794
60851
  }
60795
60852
  function removeModernColorSupports(root) {
@@ -60799,6 +60856,39 @@ function removeModernColorSupports(root) {
60799
60856
  else atRule.remove();
60800
60857
  });
60801
60858
  }
60859
+ function normalizeTailwindcssV4GradientPositionDeclarations(root) {
60860
+ root.walkDecls("--tw-gradient-position", (decl) => {
60861
+ const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
60862
+ if (normalized) {
60863
+ decl.value = normalized;
60864
+ return;
60865
+ }
60866
+ if (normalized === decl.value.trim()) return;
60867
+ const parent = decl.parent;
60868
+ if (parent?.type !== "rule") {
60869
+ decl.value = "to bottom";
60870
+ return;
60871
+ }
60872
+ const backgroundImageDecl = parent.nodes.find((node) => {
60873
+ return node.type === "decl" && node.prop === "background-image";
60874
+ });
60875
+ if (/^radial-gradient\(/i.test(backgroundImageDecl?.value ?? "")) {
60876
+ decl.value = "at center";
60877
+ return;
60878
+ }
60879
+ if (/^conic-gradient\(/i.test(backgroundImageDecl?.value ?? "")) {
60880
+ decl.value = "from 0deg";
60881
+ return;
60882
+ }
60883
+ decl.value = "to bottom";
60884
+ });
60885
+ }
60886
+ function normalizeTailwindcssV4InfinityCalcDeclarations(root) {
60887
+ root.walkDecls((decl) => {
60888
+ const normalized = normalizeTailwindcssV4InfinityCalcValue(decl.value);
60889
+ if (normalized !== decl.value) decl.value = normalized;
60890
+ });
60891
+ }
60802
60892
  function removeEmptyAtRules$1(root) {
60803
60893
  root.walkAtRules((atRule) => {
60804
60894
  if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
@@ -60825,6 +60915,8 @@ function transformWebCssCompat(css, options) {
60825
60915
  }
60826
60916
  if (normalized.features.supports) removeModernColorSupports(root);
60827
60917
  if (normalized.features.nesting) transformCssNesting(root);
60918
+ normalizeTailwindcssV4GradientPositionDeclarations(root);
60919
+ normalizeTailwindcssV4InfinityCalcDeclarations(root);
60828
60920
  normalizeModernColorDeclarations(root, normalized.features);
60829
60921
  removeEmptyAtRules$1(root);
60830
60922
  return root.toString();
@@ -60832,6 +60924,22 @@ function transformWebCssCompat(css, options) {
60832
60924
  return css;
60833
60925
  }
60834
60926
  }
60927
+ function transformWebCssSafeSelectors(css, options) {
60928
+ try {
60929
+ const root = postcss.default.parse(css);
60930
+ root.walkRules((rule) => {
60931
+ if (!rule.selector.includes(".")) return;
60932
+ rule.selector = (0, import_dist$1.default)((selectors) => {
60933
+ selectors.walkClasses((node) => {
60934
+ node.value = internalCssSelectorReplacer(node.value, options);
60935
+ });
60936
+ }).processSync(rule.selector);
60937
+ });
60938
+ return root.toString();
60939
+ } catch {
60940
+ return css;
60941
+ }
60942
+ }
60835
60943
  //#endregion
60836
60944
  //#region src/css-macro/auto.ts
60837
60945
  const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
@@ -61749,6 +61857,18 @@ function resolveTailwindV4PostcssSourceCss(css, sourceOptions, root) {
61749
61857
  const packageName = sourceOptions.packageName ?? "tailwindcss";
61750
61858
  return isTailwindV4ApplyOnlyCss(css, root) ? `@import "${packageName}" source(none);\n@reference "${packageName}";\n${css}` : css;
61751
61859
  }
61860
+ function isMiniProgramGeneratorTarget(target) {
61861
+ return target !== "web";
61862
+ }
61863
+ function finalizeGeneratedCss(css, target, styleOptions, webCompat) {
61864
+ if (target === "web") return transformWebCssCompat(css, webCompat);
61865
+ if (!isMiniProgramGeneratorTarget(target)) return css;
61866
+ return finalizeMiniProgramCss(css, {
61867
+ cssSelectorReplacement: styleOptions?.cssOptions?.cssSelectorReplacement ?? styleOptions?.cssSelectorReplacement,
61868
+ isTailwindcssV4: true,
61869
+ tailwindcssV4GradientFallback: styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? styleOptions?.tailwindcssV4GradientFallback
61870
+ });
61871
+ }
61752
61872
  function createWeappTailwindcssPostcssPlugin(adapters) {
61753
61873
  const plugin = (options = {}) => {
61754
61874
  return {
@@ -61773,18 +61893,19 @@ function createWeappTailwindcssPostcssPlugin(adapters) {
61773
61893
  base,
61774
61894
  projectRoot
61775
61895
  });
61776
- const generated = await adapters.createGenerator(source).generate({
61896
+ const generator = adapters.createGenerator(source);
61897
+ const generatorStyleOptions = {
61898
+ ...generatorOptions.styleOptions,
61899
+ ...styleOptions
61900
+ };
61901
+ const generated = await generator.generate({
61777
61902
  candidates: /* @__PURE__ */ new Set([...autoCandidates, ...candidates ?? []]),
61778
61903
  scanSources: scanSources ?? false,
61779
61904
  sources: [...collectedSources.sources, ...sources ?? []],
61780
- styleOptions: {
61781
- ...generatorOptions.styleOptions,
61782
- ...styleOptions
61783
- },
61905
+ styleOptions: generatorStyleOptions,
61784
61906
  target: generatorOptions.target
61785
61907
  });
61786
- const css = isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css;
61787
- replaceRootCss(root, generated.target === "web" ? transformWebCssCompat(css, generatorOptions.webCompat) : css, result);
61908
+ replaceRootCss(root, finalizeGeneratedCss(isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css, generated.target, generatorStyleOptions, generatorOptions.webCompat), result);
61788
61909
  addDependencyMessages(result, generated);
61789
61910
  addSourceDependencyMessages(result, collectedSources.files);
61790
61911
  result.messages.push({
@@ -61928,9 +62049,52 @@ function splitLocalCssImports(source) {
61928
62049
  return;
61929
62050
  }
61930
62051
  }
61931
- function restoreLocalCssImports(css, imports) {
62052
+ function normalizeOutputPath(file) {
62053
+ const segments = [];
62054
+ for (const segment of file.replace(/\\/g, "/").replace(/^\/+/, "").split("/")) {
62055
+ if (!segment || segment === ".") continue;
62056
+ if (segment === "..") {
62057
+ if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
62058
+ else segments.push(segment);
62059
+ continue;
62060
+ }
62061
+ segments.push(segment);
62062
+ }
62063
+ return segments.join("/");
62064
+ }
62065
+ function resolveOutputImportRequest(file, request) {
62066
+ const { clean } = splitRequestSuffix(request.replace(/\\/g, "/"));
62067
+ if (clean.startsWith("/")) return normalizeOutputPath(clean);
62068
+ const normalizedFile = normalizeOutputPath(file);
62069
+ const baseDir = normalizedFile.includes("/") ? normalizedFile.slice(0, normalizedFile.lastIndexOf("/")) : "";
62070
+ return normalizeOutputPath(baseDir ? `${baseDir}/${clean}` : clean);
62071
+ }
62072
+ function isSelfOutputImport(outputFile, node) {
62073
+ if (node.type !== "atrule" || node.name !== "import") return false;
62074
+ const request = parseImportRequest(node.params);
62075
+ return request !== void 0 && isLocalCssImportRequest(request) && resolveOutputImportRequest(outputFile, request) === normalizeOutputPath(outputFile);
62076
+ }
62077
+ function filterSelfOutputImports(imports, outputFile) {
62078
+ if (!outputFile) return imports;
62079
+ try {
62080
+ const root = postcss.default.parse(imports);
62081
+ let changed = false;
62082
+ root.walk((node) => {
62083
+ if (isSelfOutputImport(outputFile, node)) {
62084
+ node.remove();
62085
+ changed = true;
62086
+ }
62087
+ });
62088
+ return changed ? root.toString() : imports;
62089
+ } catch {
62090
+ return imports;
62091
+ }
62092
+ }
62093
+ function restoreLocalCssImports(css, imports, options = {}) {
61932
62094
  if (!imports?.trim()) return css;
61933
- return createCssSourceOrderAppend(imports, css);
62095
+ const filteredImports = filterSelfOutputImports(imports, options.outputFile);
62096
+ if (!filteredImports.trim()) return css;
62097
+ return createCssSourceOrderAppend(filteredImports, css);
61934
62098
  }
61935
62099
  function splitRequestSuffix(request) {
61936
62100
  const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
@@ -62982,27 +63146,6 @@ function getFallbackRemove(_rule, options) {
62982
63146
  return entry.parser;
62983
63147
  }
62984
63148
  //#endregion
62985
- //#region src/shared.ts
62986
- const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
62987
- function getEscapeOptions(escapeMap) {
62988
- let cached = escapeOptionsCache.get(escapeMap);
62989
- if (!cached) {
62990
- cached = { map: escapeMap };
62991
- escapeOptionsCache.set(escapeMap, cached);
62992
- }
62993
- return cached;
62994
- }
62995
- function internalCssSelectorReplacer(selectors, options) {
62996
- const escapeMap = options?.escapeMap;
62997
- if (escapeMap === void 0 || escapeMap === _weapp_core_escape.MappingChars2String) return (0, _weapp_core_escape.escape)(selectors);
62998
- return (0, _weapp_core_escape.escape)(selectors, getEscapeOptions(escapeMap));
62999
- }
63000
- function composeIsPseudo(strs) {
63001
- if (typeof strs === "string") return strs;
63002
- if (strs.length > 1) return `:is(${strs.join(",")})`;
63003
- return strs.join("");
63004
- }
63005
- //#endregion
63006
63149
  //#region src/utils/decl-order.ts
63007
63150
  /**
63008
63151
  * 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
@@ -64906,6 +65049,7 @@ exports.toPosixPath = toPosixPath;
64906
65049
  exports.transformCssMacroCss = transformCssMacroCss;
64907
65050
  exports.transformCssMacroTailwindV4Source = transformCssMacroTailwindV4Source;
64908
65051
  exports.transformWebCssCompat = transformWebCssCompat;
65052
+ exports.transformWebCssSafeSelectors = transformWebCssSafeSelectors;
64909
65053
  Object.defineProperty(exports, "unitConversionComposeRules", {
64910
65054
  enumerable: true,
64911
65055
  get: function() {
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import { createRequire } from "node:module";
5
5
  import postcss, { Declaration, Rule, rule, default as postcss$1 } from "postcss";
6
6
  import valueParser from "postcss-value-parser";
7
7
  import s from "autoprefixer";
8
+ import { MappingChars2String, escape } from "@weapp-core/escape";
8
9
  import path from "node:path";
9
10
  import process$1 from "node:process";
10
11
  import { realpathSync } from "node:fs";
@@ -18,7 +19,6 @@ import postcssCalc from "@weapp-tailwindcss/postcss-calc";
18
19
  import postcssPxtrans from "postcss-pxtrans";
19
20
  import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
20
21
  import postcssUnitConverter, { composeRules as unitConversionComposeRules, presets, presets as unitConversionPresets } from "postcss-rule-unit-converter";
21
- import { MappingChars2String, escape } from "@weapp-core/escape";
22
22
  import postcssrc from "postcss-load-config";
23
23
  //#region \0rolldown/runtime.js
24
24
  var __create = Object.create;
@@ -49,6 +49,13 @@ const MODERN_COLOR_FUNCTION_NAMES = /* @__PURE__ */ new Set([
49
49
  "lch",
50
50
  "lab"
51
51
  ]);
52
+ const MODERN_COLOR_SYNTAX_FUNCTION_NAMES = /* @__PURE__ */ new Set([
53
+ "rgb",
54
+ "rgba",
55
+ "hsl",
56
+ "hsla",
57
+ "hwb"
58
+ ]);
52
59
  const PLACEHOLDER_PREFIX = "__weapp_tw_color_mix_";
53
60
  const DYNAMIC_ALPHA_RE = /\b(?:var|env)\(|--[\w-]+\b/;
54
61
  const INTERNAL_TAILWIND_ALPHA_RE = /var\(\s*--tw-[^)]+-alpha\s*\)/;
@@ -61,13 +68,21 @@ const CUSTOM_PROPERTY_RE = /^--[\w-]+$/;
61
68
  function isDisplayP3ColorFunction(colorSource) {
62
69
  return /^color\(\s*display-p3\b/i.test(colorSource.trim());
63
70
  }
71
+ function isModernColorSyntaxFunction(colorSource) {
72
+ const parsed = valueParser(colorSource.trim());
73
+ const node = parsed.nodes.length === 1 ? parsed.nodes[0] : void 0;
74
+ if (node?.type !== "function") return false;
75
+ const name = node.value.toLowerCase();
76
+ if (!MODERN_COLOR_SYNTAX_FUNCTION_NAMES.has(name)) return false;
77
+ return !node.nodes.some((child) => child.type === "div" && child.value === ",");
78
+ }
64
79
  function hasUnsupportedModernColorFunction(value) {
65
80
  const parsed = valueParser(value);
66
81
  let hasUnsupported = false;
67
82
  parsed.walk((node) => {
68
83
  if (node.type !== "function") return;
69
84
  const name = node.value.toLowerCase();
70
- if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node))) {
85
+ if (name === "color-mix" || MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(valueParser.stringify(node)) || isModernColorSyntaxFunction(valueParser.stringify(node))) {
71
86
  hasUnsupported = true;
72
87
  return false;
73
88
  }
@@ -6894,7 +6909,7 @@ function normalizeModernColorValue(value, customPropertyValues = /* @__PURE__ */
6894
6909
  const name = node.value.toLowerCase();
6895
6910
  const source = valueParser.stringify(node);
6896
6911
  let normalized;
6897
- if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source)) normalized = normalizeStandaloneColorFunction(source);
6912
+ if (MODERN_COLOR_FUNCTION_NAMES.has(name) || name === "color" && isDisplayP3ColorFunction(source) || isModernColorSyntaxFunction(source)) normalized = normalizeStandaloneColorFunction(source);
6898
6913
  else if (name === "color-mix") normalized = tryResolveColorMix(node, customPropertyValues)?.value;
6899
6914
  if (!normalized) return;
6900
6915
  const mutableNode = node;
@@ -7278,10 +7293,9 @@ function createCssVarNodes(definitions) {
7278
7293
  }
7279
7294
  //#endregion
7280
7295
  //#region src/compat/tailwindcss-v4.ts
7281
- const OKLAB_SUFFIX = "in oklab";
7282
- const INFINITY_CALC_REGEXP = /calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px/;
7283
7296
  const RADIUS_THRESHOLD = 1e5;
7284
7297
  const CLAMP_PX = 9999;
7298
+ const INFINITY_CALC_VALUE_REGEXP = /^calc\(\s*infinity\s*\*\s*(?:\d+(?:\.\d*)?|\.\d+)r?px\s*\)$/i;
7285
7299
  const MODERN_CHECK_WEBKIT_HYPHENS_RE = /-webkit-hyphens\s*:\s*none/;
7286
7300
  const MODERN_CHECK_MARGIN_TRIM_RE = /margin-trim\s*:\s*inline/;
7287
7301
  const MODERN_CHECK_MOZ_ORIENT_RE = /-moz-orient\s*:\s*inline/;
@@ -7419,6 +7433,9 @@ function normalizeDeclarationValue(value) {
7419
7433
  function normalizeTailwindcssV4GradientPosition(value) {
7420
7434
  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();
7421
7435
  }
7436
+ function normalizeTailwindcssV4InfinityCalcValue(value) {
7437
+ return INFINITY_CALC_VALUE_REGEXP.test(value.trim()) ? `${CLAMP_PX}px` : value;
7438
+ }
7422
7439
  function normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl) {
7423
7440
  const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
7424
7441
  if (normalized) return normalized;
@@ -7463,6 +7480,7 @@ function reorderTailwindcssV4GradientDirectionRule(rule) {
7463
7480
  else if (node.prop === "background-image" && node.value.includes("linear-gradient(")) gradientBackgroundDecls.push(node);
7464
7481
  }
7465
7482
  if (gradientPositionDecls.length === 0 || gradientBackgroundDecls.length === 0) return;
7483
+ for (const decl of gradientPositionDecls) decl.value = normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl);
7466
7484
  const anchor = rule.nodes.find((node) => {
7467
7485
  return node.type === "decl" && (node.prop === "--tw-gradient-position" || node.prop === "background-image" && node.value.includes("linear-gradient("));
7468
7486
  });
@@ -7476,6 +7494,9 @@ function mergeTailwindcssV4GradientDirectionRules(root) {
7476
7494
  const seen = /* @__PURE__ */ new Map();
7477
7495
  root.walkRules((rule) => {
7478
7496
  if (!isTailwindcssV4GradientDirectionRule(rule)) return;
7497
+ rule.walkDecls("--tw-gradient-position", (decl) => {
7498
+ decl.value = normalizeTailwindcssV4GradientDirectionDeclaration(rule, decl);
7499
+ });
7479
7500
  const selector = rule.selector.trim();
7480
7501
  const previous = seen.get(selector);
7481
7502
  if (!previous || previous.parent !== rule.parent) {
@@ -7766,12 +7787,16 @@ function normalizeTailwindcssV4Declaration(decl) {
7766
7787
  decl.value = normalizedGradientPositionFallback;
7767
7788
  changed = true;
7768
7789
  }
7769
- if (decl.prop === "--tw-gradient-position" && decl.value.endsWith(OKLAB_SUFFIX)) {
7770
- decl.value = decl.parent?.type === "rule" ? normalizeTailwindcssV4GradientDirectionDeclaration(decl.parent, decl) : normalizeTailwindcssV4GradientPosition(decl.value);
7771
- return true;
7790
+ if (decl.prop === "--tw-gradient-position") {
7791
+ const nextValue = decl.parent?.type === "rule" ? normalizeTailwindcssV4GradientDirectionDeclaration(decl.parent, decl) : normalizeTailwindcssV4GradientPosition(decl.value);
7792
+ if (nextValue !== decl.value) {
7793
+ decl.value = nextValue;
7794
+ return true;
7795
+ }
7772
7796
  }
7773
- if (INFINITY_CALC_REGEXP.test(decl.value)) {
7774
- decl.value = `${CLAMP_PX}px`;
7797
+ const normalizedInfinityCalcValue = normalizeTailwindcssV4InfinityCalcValue(decl.value);
7798
+ if (normalizedInfinityCalcValue !== decl.value) {
7799
+ decl.value = normalizedInfinityCalcValue;
7775
7800
  return true;
7776
7801
  }
7777
7802
  if (decl.prop.includes("radius")) {
@@ -60640,6 +60665,27 @@ const creator$1 = (e) => {
60640
60665
  };
60641
60666
  creator$1.postcss = !0;
60642
60667
  //#endregion
60668
+ //#region src/shared.ts
60669
+ const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
60670
+ function getEscapeOptions(escapeMap) {
60671
+ let cached = escapeOptionsCache.get(escapeMap);
60672
+ if (!cached) {
60673
+ cached = { map: escapeMap };
60674
+ escapeOptionsCache.set(escapeMap, cached);
60675
+ }
60676
+ return cached;
60677
+ }
60678
+ function internalCssSelectorReplacer(selectors, options) {
60679
+ const escapeMap = options?.escapeMap;
60680
+ if (escapeMap === void 0 || escapeMap === MappingChars2String) return escape(selectors);
60681
+ return escape(selectors, getEscapeOptions(escapeMap));
60682
+ }
60683
+ function composeIsPseudo(strs) {
60684
+ if (typeof strs === "string") return strs;
60685
+ if (strs.length > 1) return `:is(${strs.join(",")})`;
60686
+ return strs.join("");
60687
+ }
60688
+ //#endregion
60643
60689
  //#region src/compat/web-css.ts
60644
60690
  const disabledFeatures = {
60645
60691
  theme: false,
@@ -60763,18 +60809,29 @@ function resolveCustomPropertyVarValue(value, customPropertyValues) {
60763
60809
  });
60764
60810
  return changed ? parsed.toString() : value;
60765
60811
  }
60766
- function insertModernColorFallbackDeclaration(decl, fallbackValue) {
60767
- if (decl.prev()?.type === "decl" && decl.prev().prop === decl.prop && decl.prev().value === fallbackValue) return;
60768
- decl.cloneBefore({ value: fallbackValue });
60812
+ function usesResolvableTailwindColorVariable(value, customPropertyValues) {
60813
+ if (!value.includes("var(")) return false;
60814
+ const parsed = valueParser(value);
60815
+ let usesColorVariable = false;
60816
+ parsed.walk((node) => {
60817
+ if (node.type !== "function" || node.value.toLowerCase() !== "var") return;
60818
+ const propertyNode = node.nodes.find((child) => child.type === "word" && child.value.startsWith("--color-"));
60819
+ if (propertyNode && customPropertyValues.has(propertyNode.value)) usesColorVariable = true;
60820
+ });
60821
+ return usesColorVariable;
60769
60822
  }
60770
60823
  function normalizeModernColorDeclarations(root, features) {
60771
60824
  if (!features.oklch && !features.colorFunctions) return;
60772
60825
  const customPropertyValues = collectCustomPropertyValues(root);
60773
60826
  root.walkDecls((decl) => {
60774
- const normalized = normalizeModernColorValue(resolveCustomPropertyVarValue(decl.value, customPropertyValues), customPropertyValues);
60775
- if (!normalized.changed) return;
60776
- if (!features.colorFunctions && !/oklch|oklab/i.test(decl.value)) return;
60777
- insertModernColorFallbackDeclaration(decl, normalized.value);
60827
+ const value = resolveCustomPropertyVarValue(decl.value, customPropertyValues);
60828
+ const normalized = normalizeModernColorValue(value, customPropertyValues);
60829
+ if (!normalized.changed) {
60830
+ if (value !== decl.value && usesResolvableTailwindColorVariable(decl.value, customPropertyValues)) decl.value = value;
60831
+ return;
60832
+ }
60833
+ if (!features.colorFunctions && !/oklch|oklab/i.test(value)) return;
60834
+ decl.value = normalized.value;
60778
60835
  });
60779
60836
  }
60780
60837
  function removeModernColorSupports(root) {
@@ -60784,6 +60841,39 @@ function removeModernColorSupports(root) {
60784
60841
  else atRule.remove();
60785
60842
  });
60786
60843
  }
60844
+ function normalizeTailwindcssV4GradientPositionDeclarations(root) {
60845
+ root.walkDecls("--tw-gradient-position", (decl) => {
60846
+ const normalized = normalizeTailwindcssV4GradientPosition(decl.value);
60847
+ if (normalized) {
60848
+ decl.value = normalized;
60849
+ return;
60850
+ }
60851
+ if (normalized === decl.value.trim()) return;
60852
+ const parent = decl.parent;
60853
+ if (parent?.type !== "rule") {
60854
+ decl.value = "to bottom";
60855
+ return;
60856
+ }
60857
+ const backgroundImageDecl = parent.nodes.find((node) => {
60858
+ return node.type === "decl" && node.prop === "background-image";
60859
+ });
60860
+ if (/^radial-gradient\(/i.test(backgroundImageDecl?.value ?? "")) {
60861
+ decl.value = "at center";
60862
+ return;
60863
+ }
60864
+ if (/^conic-gradient\(/i.test(backgroundImageDecl?.value ?? "")) {
60865
+ decl.value = "from 0deg";
60866
+ return;
60867
+ }
60868
+ decl.value = "to bottom";
60869
+ });
60870
+ }
60871
+ function normalizeTailwindcssV4InfinityCalcDeclarations(root) {
60872
+ root.walkDecls((decl) => {
60873
+ const normalized = normalizeTailwindcssV4InfinityCalcValue(decl.value);
60874
+ if (normalized !== decl.value) decl.value = normalized;
60875
+ });
60876
+ }
60787
60877
  function removeEmptyAtRules$1(root) {
60788
60878
  root.walkAtRules((atRule) => {
60789
60879
  if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
@@ -60810,6 +60900,8 @@ function transformWebCssCompat(css, options) {
60810
60900
  }
60811
60901
  if (normalized.features.supports) removeModernColorSupports(root);
60812
60902
  if (normalized.features.nesting) transformCssNesting(root);
60903
+ normalizeTailwindcssV4GradientPositionDeclarations(root);
60904
+ normalizeTailwindcssV4InfinityCalcDeclarations(root);
60813
60905
  normalizeModernColorDeclarations(root, normalized.features);
60814
60906
  removeEmptyAtRules$1(root);
60815
60907
  return root.toString();
@@ -60817,6 +60909,22 @@ function transformWebCssCompat(css, options) {
60817
60909
  return css;
60818
60910
  }
60819
60911
  }
60912
+ function transformWebCssSafeSelectors(css, options) {
60913
+ try {
60914
+ const root = postcss$1.parse(css);
60915
+ root.walkRules((rule) => {
60916
+ if (!rule.selector.includes(".")) return;
60917
+ rule.selector = (0, import_dist$1.default)((selectors) => {
60918
+ selectors.walkClasses((node) => {
60919
+ node.value = internalCssSelectorReplacer(node.value, options);
60920
+ });
60921
+ }).processSync(rule.selector);
60922
+ });
60923
+ return root.toString();
60924
+ } catch {
60925
+ return css;
60926
+ }
60927
+ }
60820
60928
  //#endregion
60821
60929
  //#region src/css-macro/auto.ts
60822
60930
  const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
@@ -61734,6 +61842,18 @@ function resolveTailwindV4PostcssSourceCss(css, sourceOptions, root) {
61734
61842
  const packageName = sourceOptions.packageName ?? "tailwindcss";
61735
61843
  return isTailwindV4ApplyOnlyCss(css, root) ? `@import "${packageName}" source(none);\n@reference "${packageName}";\n${css}` : css;
61736
61844
  }
61845
+ function isMiniProgramGeneratorTarget(target) {
61846
+ return target !== "web";
61847
+ }
61848
+ function finalizeGeneratedCss(css, target, styleOptions, webCompat) {
61849
+ if (target === "web") return transformWebCssCompat(css, webCompat);
61850
+ if (!isMiniProgramGeneratorTarget(target)) return css;
61851
+ return finalizeMiniProgramCss(css, {
61852
+ cssSelectorReplacement: styleOptions?.cssOptions?.cssSelectorReplacement ?? styleOptions?.cssSelectorReplacement,
61853
+ isTailwindcssV4: true,
61854
+ tailwindcssV4GradientFallback: styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? styleOptions?.tailwindcssV4GradientFallback
61855
+ });
61856
+ }
61737
61857
  function createWeappTailwindcssPostcssPlugin(adapters) {
61738
61858
  const plugin = (options = {}) => {
61739
61859
  return {
@@ -61758,18 +61878,19 @@ function createWeappTailwindcssPostcssPlugin(adapters) {
61758
61878
  base,
61759
61879
  projectRoot
61760
61880
  });
61761
- const generated = await adapters.createGenerator(source).generate({
61881
+ const generator = adapters.createGenerator(source);
61882
+ const generatorStyleOptions = {
61883
+ ...generatorOptions.styleOptions,
61884
+ ...styleOptions
61885
+ };
61886
+ const generated = await generator.generate({
61762
61887
  candidates: /* @__PURE__ */ new Set([...autoCandidates, ...candidates ?? []]),
61763
61888
  scanSources: scanSources ?? false,
61764
61889
  sources: [...collectedSources.sources, ...sources ?? []],
61765
- styleOptions: {
61766
- ...generatorOptions.styleOptions,
61767
- ...styleOptions
61768
- },
61890
+ styleOptions: generatorStyleOptions,
61769
61891
  target: generatorOptions.target
61770
61892
  });
61771
- const css = isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css;
61772
- replaceRootCss(root, generated.target === "web" ? transformWebCssCompat(css, generatorOptions.webCompat) : css, result);
61893
+ replaceRootCss(root, finalizeGeneratedCss(isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, applyOnlyCssSelectors ?? /* @__PURE__ */ new Set()) : generated.css, generated.target, generatorStyleOptions, generatorOptions.webCompat), result);
61773
61894
  addDependencyMessages(result, generated);
61774
61895
  addSourceDependencyMessages(result, collectedSources.files);
61775
61896
  result.messages.push({
@@ -61913,9 +62034,52 @@ function splitLocalCssImports(source) {
61913
62034
  return;
61914
62035
  }
61915
62036
  }
61916
- function restoreLocalCssImports(css, imports) {
62037
+ function normalizeOutputPath(file) {
62038
+ const segments = [];
62039
+ for (const segment of file.replace(/\\/g, "/").replace(/^\/+/, "").split("/")) {
62040
+ if (!segment || segment === ".") continue;
62041
+ if (segment === "..") {
62042
+ if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
62043
+ else segments.push(segment);
62044
+ continue;
62045
+ }
62046
+ segments.push(segment);
62047
+ }
62048
+ return segments.join("/");
62049
+ }
62050
+ function resolveOutputImportRequest(file, request) {
62051
+ const { clean } = splitRequestSuffix(request.replace(/\\/g, "/"));
62052
+ if (clean.startsWith("/")) return normalizeOutputPath(clean);
62053
+ const normalizedFile = normalizeOutputPath(file);
62054
+ const baseDir = normalizedFile.includes("/") ? normalizedFile.slice(0, normalizedFile.lastIndexOf("/")) : "";
62055
+ return normalizeOutputPath(baseDir ? `${baseDir}/${clean}` : clean);
62056
+ }
62057
+ function isSelfOutputImport(outputFile, node) {
62058
+ if (node.type !== "atrule" || node.name !== "import") return false;
62059
+ const request = parseImportRequest(node.params);
62060
+ return request !== void 0 && isLocalCssImportRequest(request) && resolveOutputImportRequest(outputFile, request) === normalizeOutputPath(outputFile);
62061
+ }
62062
+ function filterSelfOutputImports(imports, outputFile) {
62063
+ if (!outputFile) return imports;
62064
+ try {
62065
+ const root = postcss.parse(imports);
62066
+ let changed = false;
62067
+ root.walk((node) => {
62068
+ if (isSelfOutputImport(outputFile, node)) {
62069
+ node.remove();
62070
+ changed = true;
62071
+ }
62072
+ });
62073
+ return changed ? root.toString() : imports;
62074
+ } catch {
62075
+ return imports;
62076
+ }
62077
+ }
62078
+ function restoreLocalCssImports(css, imports, options = {}) {
61917
62079
  if (!imports?.trim()) return css;
61918
- return createCssSourceOrderAppend(imports, css);
62080
+ const filteredImports = filterSelfOutputImports(imports, options.outputFile);
62081
+ if (!filteredImports.trim()) return css;
62082
+ return createCssSourceOrderAppend(filteredImports, css);
61919
62083
  }
61920
62084
  function splitRequestSuffix(request) {
61921
62085
  const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
@@ -62967,27 +63131,6 @@ function getFallbackRemove(_rule, options) {
62967
63131
  return entry.parser;
62968
63132
  }
62969
63133
  //#endregion
62970
- //#region src/shared.ts
62971
- const escapeOptionsCache = /* @__PURE__ */ new WeakMap();
62972
- function getEscapeOptions(escapeMap) {
62973
- let cached = escapeOptionsCache.get(escapeMap);
62974
- if (!cached) {
62975
- cached = { map: escapeMap };
62976
- escapeOptionsCache.set(escapeMap, cached);
62977
- }
62978
- return cached;
62979
- }
62980
- function internalCssSelectorReplacer(selectors, options) {
62981
- const escapeMap = options?.escapeMap;
62982
- if (escapeMap === void 0 || escapeMap === MappingChars2String) return escape(selectors);
62983
- return escape(selectors, getEscapeOptions(escapeMap));
62984
- }
62985
- function composeIsPseudo(strs) {
62986
- if (typeof strs === "string") return strs;
62987
- if (strs.length > 1) return `:is(${strs.join(",")})`;
62988
- return strs.join("");
62989
- }
62990
- //#endregion
62991
63134
  //#region src/utils/decl-order.ts
62992
63135
  /**
62993
63136
  * 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
@@ -64795,4 +64938,4 @@ function containsCssAfterMinify(baseCss, css) {
64795
64938
  return ruleKeys.size > 0 && [...ruleKeys].every((key) => baseRuleKeys.has(key));
64796
64939
  }
64797
64940
  //#endregion
64798
- export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
64941
+ export { CSS_MACRO_POSTCSS_PLUGIN_NAME, CSS_MACRO_STYLE_OPTIONS_MARKER, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_PATTERN, analyzeTailwindCssDirectives, cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, collectApplyOnlyCssSelectors, collectApplyOnlyCssSelectorsRoot, collectCssInlineSourceCandidates, compileCssMacroConditionalComments, containsCssAfterMinify, convertTailwindcssRpxDeclarationToRem, convertTailwindcssRpxDeclarationsToRem, convertTailwindcssRpxValueToRem, createCssSourceOrderAppend, createFallbackPlaceholderReplacer, createInjectPreflight, createSourceScanPattern, createStyleHandler, createStylePipeline, createTailwindSourceEntryMatcher, createWeappTailwindcssPostcssPlugin, creator as cssMacroPostcssPlugin, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, filterApplyOnlyGeneratedCss, filterApplyOnlyGeneratedCssRoot, filterExistingCssRules, finalizeMiniProgramCss, getPostcssPluginName, hasCssMacroStyleOptions, hasCssMacroTailwindV4CustomVariantConditionalComments, hasCssMacroTailwindV4Directive, hasCssMacroTailwindV4InternalAtRules, hasCssMacroTailwindV4Source, hasMiniProgramCssSpecificityPlaceholders, hoistTailwindPreflightBase, internalCssSelectorReplacer, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, isLocalCssImportRequest, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, isTailwindCssGenerationDirective, isTailwindCssImportAtRule, isTailwindCssImportRequest, isTailwindCssPackageJsonImportRequest, isWeappTailwindcssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeLegacyContentEntries, normalizeMiniProgramPrefixedDeclaration, normalizeModernColorValue, normalizeOutputImportRequest, normalizeTailwindCssImportRequest, normalizeTailwindcssRpxDeclaration, normalizeTailwindcssRpxDeclarations, normalizeTailwindcssWebRpxDeclarations, normalizeWebCssCompatOptions, parseConfigParam, parseSourceFileParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, postcssHtmlTransform, prefixLocalCssImportsWithWebpackIgnoreRoot, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedAtSupports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedMiniProgramPrefixedAtRule, resolveCssSourceEntries, resolveFilteredPostcssConfig, resolveSourceScanPath, resolveTailwindSourceEntry, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, rewriteLocalCssImportRequestsForOutputRoot, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, toPosixPath, transformCssMacroCss, transformCssMacroTailwindV4Source, transformWebCssCompat, transformWebCssSafeSelectors, unitConversionComposeRules, unitConversionPresets, unwrapUnsupportedCascadeLayers, withCssMacroStyleOptions };
package/dist/types.d.ts CHANGED
@@ -63,6 +63,12 @@ export interface CssAtRules {
63
63
  supports?: boolean | undefined;
64
64
  media?: boolean | undefined;
65
65
  }
66
+ /**
67
+ * Web 兼容预设。
68
+ *
69
+ * `legacy-web` 面向 Web Compact 输出,兼容基线为 Chrome/91.0.4472.114 与
70
+ * AppleWebKit/537.36;`off` 表示关闭降级。
71
+ */
66
72
  export type WebCssCompatPreset = 'off' | 'legacy-web';
67
73
  /**
68
74
  * Web 兼容降级的功能开关。
@@ -99,7 +105,7 @@ export interface WebCssCompatFeatures {
99
105
  }
100
106
  export interface WebCssCompatOptions {
101
107
  /**
102
- * 兼容预设。`legacy-web` 面向旧 Android/iOS WebView,`off` 表示关闭降级。
108
+ * 兼容预设。`legacy-web` 面向 Chrome 91 / AppleWebKit 537.36 WebView 基线,`off` 表示关闭降级。
103
109
  */
104
110
  preset?: WebCssCompatPreset | undefined;
105
111
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -76,9 +76,9 @@
76
76
  "postcss-rule-unit-converter": "^0.2.2",
77
77
  "postcss-selector-parser": "~7.1.4",
78
78
  "postcss-value-parser": "^4.2.0",
79
+ "tailwindcss-config": "2.0.1",
79
80
  "@weapp-tailwindcss/postcss-calc": "^1.0.2",
80
- "@weapp-tailwindcss/shared": "2.0.0",
81
- "tailwindcss-config": "2.0.1"
81
+ "@weapp-tailwindcss/shared": "2.0.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@csstools/css-color-parser": "^4.1.9",