weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.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.
Files changed (171) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  4. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  5. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  6. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  7. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  8. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  9. package/dist/bundlers/shared/generator-css/directives.d.ts +11 -0
  10. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  11. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  12. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  13. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  14. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  15. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +12 -22
  17. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  18. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  19. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  20. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  21. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  22. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  23. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  24. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  25. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  26. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  27. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  28. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  29. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  30. package/dist/bundlers/vite/index.d.ts +1 -1
  31. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  32. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  33. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  34. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  35. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  38. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
  40. package/dist/cache-DPN5yKSX.js +497 -0
  41. package/dist/cache-nq0_XJoS.mjs +429 -0
  42. package/dist/cli/context.d.ts +0 -3
  43. package/dist/cli/helpers.d.ts +1 -2
  44. package/dist/cli/mount-options.d.ts +2 -0
  45. package/dist/cli/types.d.ts +0 -2
  46. package/dist/cli.js +108 -598
  47. package/dist/cli.mjs +119 -608
  48. package/dist/constants.d.ts +1 -2
  49. package/dist/context/tailwindcss.d.ts +1 -1
  50. package/dist/core.js +13 -20
  51. package/dist/core.mjs +8 -14
  52. package/dist/css-macro/postcss.js +1 -1
  53. package/dist/css-macro/postcss.mjs +1 -1
  54. package/dist/css-macro.d.ts +1 -0
  55. package/dist/css-macro.js +2 -2
  56. package/dist/css-macro.mjs +2 -2
  57. package/dist/defaults.d.ts +15 -1
  58. package/dist/defaults.js +33 -14
  59. package/dist/defaults.mjs +30 -15
  60. package/dist/generator/index.d.ts +1 -1
  61. package/dist/generator/options.d.ts +3 -4
  62. package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
  63. package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
  64. package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
  65. package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
  66. package/dist/generator.js +1 -1
  67. package/dist/generator.mjs +1 -1
  68. package/dist/gulp.js +29 -28
  69. package/dist/gulp.mjs +25 -24
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.js +6 -6
  72. package/dist/index.mjs +5 -5
  73. package/dist/js/index.d.ts +1 -0
  74. package/dist/js/literal-transform.d.ts +2 -0
  75. package/dist/logger-BRy6XPQ2.js +1 -0
  76. package/dist/logger-Bub1jggA.mjs +2 -0
  77. package/dist/postcss/config-directive.d.ts +1 -0
  78. package/dist/postcss/context.d.ts +9 -0
  79. package/dist/postcss/source-files.d.ts +8 -0
  80. package/dist/postcss/tailwind-version.d.ts +3 -0
  81. package/dist/postcss-BtAP6sQO.mjs +288 -0
  82. package/dist/postcss-WsXlC7A-.js +298 -0
  83. package/dist/postcss.d.ts +2 -2
  84. package/dist/postcss.js +3 -276
  85. package/dist/postcss.mjs +1 -269
  86. package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
  87. package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
  88. package/dist/presets.js +6 -4
  89. package/dist/presets.mjs +4 -2
  90. package/dist/reset.d.ts +1 -0
  91. package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
  92. package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
  93. package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
  94. package/dist/runtime-patch-qwuisukL.js +85 -0
  95. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  96. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  97. package/dist/tailwindcss/patcher.d.ts +1 -2
  98. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  99. package/dist/tailwindcss/runtime.d.ts +2 -3
  100. package/dist/tailwindcss/targets.d.ts +1 -5
  101. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  102. package/dist/tailwindcss/v4/patcher.d.ts +2 -1
  103. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  104. package/dist/tailwindcss/version.d.ts +4 -0
  105. package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
  106. package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
  107. package/dist/typedoc.export.d.ts +0 -2
  108. package/dist/types/index.d.ts +2 -9
  109. package/dist/types/shared.d.ts +3 -0
  110. package/dist/types/user-defined-options/general.d.ts +0 -2
  111. package/dist/types/user-defined-options/important.d.ts +3 -3
  112. package/dist/uni-app-x/vite.d.ts +1 -1
  113. package/dist/utils/disabled.d.ts +2 -3
  114. package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
  115. package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
  116. package/dist/vite.d.ts +1 -2
  117. package/dist/vite.js +3 -4
  118. package/dist/vite.mjs +2 -2
  119. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  120. package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
  121. package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
  122. package/dist/webpack.js +1 -1
  123. package/dist/webpack.mjs +1 -1
  124. package/package.json +23 -35
  125. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  126. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  127. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  128. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  129. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  130. package/dist/cli/config.d.ts +0 -5
  131. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  132. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  133. package/dist/cli/patch-options.d.ts +0 -6
  134. package/dist/cli/tokens.d.ts +0 -4
  135. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  136. package/dist/cli/workspace/patch-package.d.ts +0 -3
  137. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  138. package/dist/cli/workspace/types.d.ts +0 -11
  139. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  140. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  141. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  142. package/dist/cli/workspace.d.ts +0 -2
  143. package/dist/experimental/index.d.ts +0 -2
  144. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  145. package/dist/experimental/oxc/index.d.ts +0 -2
  146. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  147. package/dist/experimental/shared/cache.d.ts +0 -3
  148. package/dist/experimental/shared/transform.d.ts +0 -3
  149. package/dist/experimental/shared.d.ts +0 -8
  150. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  151. package/dist/experimental/swc/index.d.ts +0 -2
  152. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  153. package/dist/js/syntax.d.ts +0 -10
  154. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  155. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  156. package/dist/patcher-options-6gJN2EXy.js +0 -115
  157. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  158. package/dist/tailwindcss/recorder.d.ts +0 -13
  159. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  160. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  161. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  162. package/dist/tailwindcss/targets/types.d.ts +0 -35
  163. package/dist/types/disabled-options.d.ts +0 -4
  164. package/dist/webpack4.d.ts +0 -4
  165. package/dist/webpack4.js +0 -387
  166. package/dist/webpack4.mjs +0 -379
  167. package/scripts/postinstall.mjs +0 -59
  168. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  169. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  170. /package/dist/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
  171. /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +0 -0
@@ -1,5 +1,5 @@
1
- import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-Y-Ikv4Fu.mjs";
2
- import { l as replaceWxml } from "./recorder-XdFvVASS.mjs";
1
+ import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-CzfdCZyd.mjs";
2
+ import { l as replaceWxml } from "./precheck-DlrmwCc-.mjs";
3
3
  import postcss from "postcss";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
@@ -23,7 +23,69 @@ async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSourc
23
23
  if (!cacheHit) await applyResult(result);
24
24
  }
25
25
  //#endregion
26
- //#region src/bundlers/shared/css-cleanup.ts
26
+ //#region src/bundlers/shared/css-cleanup/at-rules.ts
27
+ const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
28
+ function removeAtRulesByScan(css, names) {
29
+ let index = 0;
30
+ let result = "";
31
+ const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
32
+ while (index < css.length) {
33
+ const match = atRulePattern.exec(css.slice(index));
34
+ if (!match || match.index === void 0) {
35
+ result += css.slice(index);
36
+ break;
37
+ }
38
+ const start = index + match.index;
39
+ result += css.slice(index, start);
40
+ const blockStart = css.indexOf("{", start);
41
+ if (blockStart === -1) {
42
+ result += css.slice(start);
43
+ break;
44
+ }
45
+ let depth = 0;
46
+ let cursor = blockStart;
47
+ for (; cursor < css.length; cursor++) {
48
+ const char = css[cursor];
49
+ if (char === "{") depth++;
50
+ else if (char === "}") {
51
+ depth--;
52
+ if (depth === 0) {
53
+ cursor++;
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ index = cursor;
59
+ }
60
+ return result;
61
+ }
62
+ function removeUnsupportedMiniProgramAtRules(css) {
63
+ try {
64
+ const root = postcss.parse(css);
65
+ root.walkAtRules((atRule) => {
66
+ if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
67
+ });
68
+ root.walkAtRules((atRule) => {
69
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
70
+ });
71
+ return root.toString();
72
+ } catch {
73
+ return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
74
+ }
75
+ }
76
+ //#endregion
77
+ //#region src/bundlers/shared/css-cleanup/color-gamut.ts
78
+ const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
79
+ const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
80
+ function isDisplayP3MediaRule(atRule) {
81
+ return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
82
+ }
83
+ function isDisplayP3Declaration(decl) {
84
+ return DISPLAY_P3_VALUE_RE.test(decl.value);
85
+ }
86
+ //#endregion
87
+ //#region src/bundlers/shared/css-cleanup/selectors.ts
88
+ const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
27
89
  const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
28
90
  "*",
29
91
  "view",
@@ -33,7 +95,6 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
33
95
  "::before",
34
96
  "::after"
35
97
  ]);
36
- const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
37
98
  const MINI_PROGRAM_THEME_SCOPE_SELECTORS$1 = new Set([
38
99
  ":host",
39
100
  ":root",
@@ -109,6 +170,75 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
109
170
  "ul",
110
171
  "video"
111
172
  ]);
173
+ function normalizeSelector(selector) {
174
+ return selector.trim().replace(/\s+/g, "");
175
+ }
176
+ function getRuleSelectors(rule) {
177
+ return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
178
+ }
179
+ function isUnsupportedBrowserSelector(selector) {
180
+ const normalized = normalizeSelector(selector);
181
+ return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
182
+ }
183
+ //#endregion
184
+ //#region src/bundlers/shared/css-cleanup/root-cleanups.ts
185
+ function removeSpecificityPlaceholders(root) {
186
+ root.walkRules((rule) => {
187
+ if (!rule.selectors || rule.selectors.length === 0) return;
188
+ let changed = false;
189
+ const selectors = rule.selectors.map((selector) => {
190
+ let next = selector;
191
+ for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
192
+ if (next !== selector) changed = true;
193
+ return next;
194
+ });
195
+ if (changed) rule.selectors = selectors;
196
+ });
197
+ }
198
+ function removeEmptyAtRuleAncestors(parent) {
199
+ while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
200
+ const nextParent = parent.parent;
201
+ parent.remove();
202
+ parent = nextParent;
203
+ }
204
+ }
205
+ function removeUnsupportedBrowserSelectors(root) {
206
+ root.walkRules((rule) => {
207
+ if (!rule.selectors || rule.selectors.length === 0) return;
208
+ const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
209
+ if (selectors.length === rule.selectors.length) return;
210
+ if (selectors.length === 0) {
211
+ const parent = rule.parent;
212
+ rule.remove();
213
+ removeEmptyAtRuleAncestors(parent);
214
+ return;
215
+ }
216
+ rule.selectors = selectors;
217
+ });
218
+ }
219
+ function removeDeclarationAndEmptyRule(decl) {
220
+ const parent = decl.parent;
221
+ decl.remove();
222
+ if (parent?.type === "rule" && parent.nodes.length === 0) {
223
+ const ruleParent = parent.parent;
224
+ parent.remove();
225
+ removeEmptyAtRuleAncestors(ruleParent);
226
+ }
227
+ }
228
+ function removeDisplayP3Declarations(root) {
229
+ root.walkAtRules((atRule) => {
230
+ if (isDisplayP3MediaRule(atRule)) {
231
+ const parent = atRule.parent;
232
+ atRule.remove();
233
+ removeEmptyAtRuleAncestors(parent);
234
+ }
235
+ });
236
+ root.walkDecls((decl) => {
237
+ if (isDisplayP3Declaration(decl)) removeDeclarationAndEmptyRule(decl);
238
+ });
239
+ }
240
+ //#endregion
241
+ //#region src/bundlers/shared/css-cleanup.ts
112
242
  const PREFLIGHT_RESET_PROPS = new Set([
113
243
  "box-sizing",
114
244
  "border",
@@ -118,63 +248,6 @@ const PREFLIGHT_RESET_PROPS = new Set([
118
248
  "margin",
119
249
  "padding"
120
250
  ]);
121
- const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
122
- const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
123
- function removeAtRulesByScan(css, names) {
124
- let index = 0;
125
- let result = "";
126
- const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
127
- while (index < css.length) {
128
- const match = atRulePattern.exec(css.slice(index));
129
- if (!match || match.index === void 0) {
130
- result += css.slice(index);
131
- break;
132
- }
133
- const start = index + match.index;
134
- result += css.slice(index, start);
135
- const blockStart = css.indexOf("{", start);
136
- if (blockStart === -1) {
137
- result += css.slice(start);
138
- break;
139
- }
140
- let depth = 0;
141
- let cursor = blockStart;
142
- for (; cursor < css.length; cursor++) {
143
- const char = css[cursor];
144
- if (char === "{") depth++;
145
- else if (char === "}") {
146
- depth--;
147
- if (depth === 0) {
148
- cursor++;
149
- break;
150
- }
151
- }
152
- }
153
- index = cursor;
154
- }
155
- return result;
156
- }
157
- const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
158
- function removeUnsupportedMiniProgramAtRules(css) {
159
- try {
160
- const root = postcss.parse(css);
161
- root.walkAtRules((atRule) => {
162
- if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
163
- });
164
- root.walkAtRules((atRule) => {
165
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
166
- });
167
- return root.toString();
168
- } catch {
169
- return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
170
- }
171
- }
172
- function normalizeSelector(selector) {
173
- return selector.trim().replace(/\s+/g, "");
174
- }
175
- function getRuleSelectors(rule) {
176
- return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
177
- }
178
251
  function isMiniProgramThemeScopeSelector$1(selectors) {
179
252
  return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS$1.has(selector));
180
253
  }
@@ -223,71 +296,6 @@ function createPseudoContentInitRule() {
223
296
  });
224
297
  return rule;
225
298
  }
226
- function isDisplayP3MediaRule(atRule) {
227
- return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
228
- }
229
- function isDisplayP3Declaration(decl) {
230
- return DISPLAY_P3_VALUE_RE.test(decl.value);
231
- }
232
- function removeSpecificityPlaceholders(root) {
233
- root.walkRules((rule) => {
234
- if (!rule.selectors || rule.selectors.length === 0) return;
235
- let changed = false;
236
- const selectors = rule.selectors.map((selector) => {
237
- let next = selector;
238
- for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
239
- if (next !== selector) changed = true;
240
- return next;
241
- });
242
- if (changed) rule.selectors = selectors;
243
- });
244
- }
245
- function isUnsupportedBrowserSelector(selector) {
246
- const normalized = normalizeSelector(selector);
247
- return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
248
- }
249
- function removeUnsupportedBrowserSelectors(root) {
250
- root.walkRules((rule) => {
251
- if (!rule.selectors || rule.selectors.length === 0) return;
252
- const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
253
- if (selectors.length === rule.selectors.length) return;
254
- if (selectors.length === 0) {
255
- const parent = rule.parent;
256
- rule.remove();
257
- removeEmptyAtRuleAncestors(parent);
258
- return;
259
- }
260
- rule.selectors = selectors;
261
- });
262
- }
263
- function removeEmptyAtRuleAncestors(parent) {
264
- while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
265
- const nextParent = parent.parent;
266
- parent.remove();
267
- parent = nextParent;
268
- }
269
- }
270
- function removeDeclarationAndEmptyRule(decl) {
271
- const parent = decl.parent;
272
- decl.remove();
273
- if (parent?.type === "rule" && parent.nodes.length === 0) {
274
- const ruleParent = parent.parent;
275
- parent.remove();
276
- removeEmptyAtRuleAncestors(ruleParent);
277
- }
278
- }
279
- function removeDisplayP3Declarations(root) {
280
- root.walkAtRules((atRule) => {
281
- if (isDisplayP3MediaRule(atRule)) {
282
- const parent = atRule.parent;
283
- atRule.remove();
284
- removeEmptyAtRuleAncestors(parent);
285
- }
286
- });
287
- root.walkDecls((decl) => {
288
- if (isDisplayP3Declaration(decl)) removeDeclarationAndEmptyRule(decl);
289
- });
290
- }
291
299
  function collectPreflightRules(root) {
292
300
  const preflightNodes = [];
293
301
  let hasContentInit = false;
@@ -361,7 +369,7 @@ function finalizeMiniProgramCss(css) {
361
369
  }
362
370
  }
363
371
  //#endregion
364
- //#region src/bundlers/shared/generator-css.ts
372
+ //#region src/bundlers/shared/generator-css/markers.ts
365
373
  const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
366
374
  const TAILWIND_GENERATED_CSS_MARKER_RE = /\/\*!\s*tailwindcss v|@property\s+--tw-|--tw-|:not\(#\\#\)|\.[^,{]*(?:\\:|\\\[|\\#)|(?::host|page|\.tw-root|wx-root-portal-content)[^{]*\{[^}]*--(?:color|spacing|text|font-weight|radius)-/;
367
375
  const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
@@ -369,77 +377,6 @@ const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss genera
369
377
  const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
370
378
  const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
371
379
  const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
372
- const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
373
- const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
374
- ":host",
375
- "page",
376
- ".tw-root",
377
- "wx-root-portal-content"
378
- ]);
379
- const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
380
- const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
381
- const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
382
- const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
383
- const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
384
- const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
385
- "config",
386
- "custom-variant",
387
- "layer",
388
- "plugin",
389
- "reference",
390
- "source",
391
- "tailwind",
392
- "theme",
393
- "utility",
394
- "variant"
395
- ]);
396
- const LEGACY_CONTAINER_COMPAT_CSS = [
397
- ".container {",
398
- " width: 100%;",
399
- "}",
400
- "@media (min-width: 40rem) {",
401
- " .container {",
402
- " max-width: 40rem;",
403
- " }",
404
- "}",
405
- "@media (min-width: 48rem) {",
406
- " .container {",
407
- " max-width: 48rem;",
408
- " }",
409
- "}",
410
- "@media (min-width: 64rem) {",
411
- " .container {",
412
- " max-width: 64rem;",
413
- " }",
414
- "}",
415
- "@media (min-width: 80rem) {",
416
- " .container {",
417
- " max-width: 80rem;",
418
- " }",
419
- "}",
420
- "@media (min-width: 96rem) {",
421
- " .container {",
422
- " max-width: 96rem;",
423
- " }",
424
- "}"
425
- ].join("\n");
426
- const SOURCE_STYLE_EXTENSIONS = [
427
- ".vue",
428
- ".uvue",
429
- ".nvue",
430
- ".css",
431
- ".scss",
432
- ".sass",
433
- ".less",
434
- ".styl",
435
- ".stylus",
436
- ".wxss",
437
- ".acss",
438
- ".jxss",
439
- ".ttss",
440
- ".qss"
441
- ];
442
- const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
443
380
  function createCssAppend(base, extra) {
444
381
  if (!base) return extra;
445
382
  if (!extra) return base;
@@ -469,132 +406,28 @@ function hasTailwindGeneratedCss(rawSource) {
469
406
  function hasTailwindGeneratedCssMarkers(rawSource) {
470
407
  return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
471
408
  }
472
- function finalizeMiniProgramGeneratorCss(css, target) {
473
- if (target !== "weapp") return css;
474
- return finalizeMiniProgramCss(css);
475
- }
476
- function normalizeCompatSelector(selector) {
477
- return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
478
- }
479
- function isClassSelectorTerminator(char) {
480
- return /[\s>+~#,.:()[\]]/.test(char);
481
- }
482
- function unescapeSimpleCssIdent(value) {
483
- return value.replaceAll(/\\(.)/g, "$1");
484
- }
485
- function escapeCompatSelectorClasses(selector) {
486
- let result = "";
487
- let index = 0;
488
- let changed = false;
489
- while (index < selector.length) {
490
- const char = selector[index];
491
- if (char !== ".") {
492
- result += char;
493
- index += 1;
494
- continue;
495
- }
496
- let end = index + 1;
497
- let className = "";
498
- while (end < selector.length) {
499
- const current = selector[end];
500
- if (current === "\\" && end + 1 < selector.length) {
501
- className += current + selector[end + 1];
502
- end += 2;
503
- continue;
504
- }
505
- if (isClassSelectorTerminator(current)) break;
506
- className += current;
507
- end += 1;
508
- }
509
- if (className.includes("\\")) {
510
- result += `.${replaceWxml(unescapeSimpleCssIdent(className))}`;
511
- changed = true;
512
- } else result += `.${className}`;
513
- index = end;
514
- }
515
- return changed ? result : selector;
516
- }
517
- function normalizeCompatSelectors(selector) {
518
- const normalized = normalizeCompatSelector(selector);
519
- if (!normalized) return [];
520
- const selectors = new Set([normalized]);
521
- const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
522
- if (escaped) selectors.add(escaped);
523
- return [...selectors];
524
- }
525
- function createLegacyDeclarationValueMap(css) {
526
- const values = /* @__PURE__ */ new Map();
527
- postcss.parse(css).walkRules((rule) => {
528
- if (!rule.selectors || rule.selectors.length === 0) return;
529
- for (const selector of rule.selectors) {
530
- const normalizedSelectors = normalizeCompatSelectors(selector);
531
- rule.walkDecls((decl) => {
532
- if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
533
- });
534
- }
535
- });
536
- return values;
537
- }
538
- function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
539
- try {
540
- const legacyValues = createLegacyDeclarationValueMap(legacyCss);
541
- if (legacyValues.size === 0) return css;
542
- const root = postcss.parse(css);
543
- let changed = false;
544
- root.walkRules((rule) => {
545
- if (!rule.selectors || rule.selectors.length === 0) return;
546
- const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
547
- if (selectors.length === 0) return;
548
- rule.walkDecls((decl) => {
549
- if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
550
- for (const selector of selectors) {
551
- const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
552
- if (legacyValue && legacyValue !== decl.value) {
553
- decl.value = legacyValue;
554
- changed = true;
555
- return;
556
- }
557
- }
558
- });
559
- });
560
- return changed ? root.toString() : css;
561
- } catch {
562
- return css;
563
- }
564
- }
565
- function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
566
- return {
567
- cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
568
- cssSelectorReplacement: opts.cssSelectorReplacement,
569
- rem2rpx: opts.rem2rpx,
570
- px2rpx: opts.px2rpx,
571
- unitsToPx: opts.unitsToPx,
572
- cssRemoveProperty: opts.cssRemoveProperty,
573
- cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
574
- cssPresetEnv: opts.cssPresetEnv,
575
- autoprefixer: opts.autoprefixer,
576
- cssCalc: opts.cssCalc,
577
- atRules: opts.atRules,
578
- uniAppX: opts.uniAppX,
579
- uniAppXCssTarget: opts.uniAppXCssTarget,
580
- uniAppXUnsupported: opts.uniAppXUnsupported,
581
- ...cssHandlerOptions,
582
- ...generatorStyleOptions
583
- };
584
- }
409
+ //#endregion
410
+ //#region src/bundlers/shared/generator-css/directives.ts
411
+ const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
412
+ "config",
413
+ "custom-variant",
414
+ "layer",
415
+ "plugin",
416
+ "reference",
417
+ "source",
418
+ "tailwind",
419
+ "theme",
420
+ "utility",
421
+ "variant"
422
+ ]);
585
423
  function parseImportRequest(params) {
586
424
  return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
587
425
  }
588
426
  function parseConfigRequest(params) {
589
427
  return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
590
428
  }
591
- function resolvePostcssFromOption(cssHandlerOptions) {
592
- const from = cssHandlerOptions.postcssOptions?.options?.from;
593
- return typeof from === "string" && from.length > 0 ? from : void 0;
594
- }
595
- function resolveCssSourceBase(file, cssHandlerOptions) {
596
- const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
597
- return path.dirname(path.resolve(normalized));
429
+ function isPackageJsonImportRequest(request) {
430
+ return typeof request === "string" && request.startsWith("#");
598
431
  }
599
432
  function isTailwindImportAtRule(node) {
600
433
  if (node.name === "tailwind") return true;
@@ -605,11 +438,13 @@ function isTailwindImportAtRule(node) {
605
438
  function isTailwindSourceDirective(node) {
606
439
  if (node.type !== "atrule") return false;
607
440
  if (isTailwindImportAtRule(node)) return true;
441
+ if (node.name === "import" && isPackageJsonImportRequest(parseImportRequest(node.params))) return true;
608
442
  return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(node.name);
609
443
  }
610
444
  function isTailwindGenerationDirective(node) {
611
445
  if (node.type !== "atrule") return false;
612
- return isTailwindImportAtRule(node) || node.name === "layer" || node.name === "config";
446
+ const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" || node.name === "reference" ? parseConfigRequest(node.params) : void 0;
447
+ return isTailwindImportAtRule(node) || isPackageJsonImportRequest(request) || node.name === "apply" || node.name === "layer" || node.name === "config" || node.name === "source";
613
448
  }
614
449
  function removeTailwindSourceDirectives(rawSource) {
615
450
  try {
@@ -657,7 +492,7 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
657
492
  const configPath = parseConfigRequest(node.params);
658
493
  if (configPath && !config) {
659
494
  configRequest = configPath;
660
- config = path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
495
+ config = isPackageJsonImportRequest(configPath) ? void 0 : path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
661
496
  }
662
497
  if (removeConfig) {
663
498
  node.remove();
@@ -676,26 +511,223 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
676
511
  return;
677
512
  }
678
513
  }
679
- function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
680
- if (config && existsSync(config)) return config;
681
- if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
682
- const outputDir = path.dirname(file.replace(/[?#].*$/, ""));
683
- const baseCandidates = [
684
- sourceOptions.projectRoot,
685
- sourceOptions.cwd,
686
- process.cwd()
687
- ].filter((item) => typeof item === "string" && item.length > 0);
688
- for (const base of baseCandidates) {
689
- const candidates = [
690
- path.resolve(base, configRequest),
691
- path.resolve(base, "src", configRequest),
692
- path.resolve(base, outputDir, configRequest),
693
- path.resolve(base, "src", outputDir, configRequest)
694
- ];
695
- for (const candidate of candidates) if (existsSync(candidate)) return candidate;
514
+ //#endregion
515
+ //#region src/bundlers/shared/generator-css/legacy-selectors.ts
516
+ const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
517
+ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
518
+ ":host",
519
+ "page",
520
+ ".tw-root",
521
+ "wx-root-portal-content"
522
+ ]);
523
+ const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
524
+ function normalizeCompatSelector(selector) {
525
+ return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
526
+ }
527
+ function isClassSelectorTerminator(char) {
528
+ return /[\s>+~#,.:()[\]]/.test(char);
529
+ }
530
+ function unescapeSimpleCssIdent(value) {
531
+ return value.replaceAll(/\\(.)/g, "$1");
532
+ }
533
+ function escapeCompatSelectorClasses(selector) {
534
+ let result = "";
535
+ let index = 0;
536
+ let changed = false;
537
+ while (index < selector.length) {
538
+ const char = selector[index];
539
+ if (char !== ".") {
540
+ result += char;
541
+ index += 1;
542
+ continue;
543
+ }
544
+ let end = index + 1;
545
+ let className = "";
546
+ while (end < selector.length) {
547
+ const current = selector[end];
548
+ if (current === "\\" && end + 1 < selector.length) {
549
+ className += current + selector[end + 1];
550
+ end += 2;
551
+ continue;
552
+ }
553
+ if (isClassSelectorTerminator(current)) break;
554
+ className += current;
555
+ end += 1;
556
+ }
557
+ if (className.includes("\\")) {
558
+ result += `.${replaceWxml(unescapeSimpleCssIdent(className))}`;
559
+ changed = true;
560
+ } else result += `.${className}`;
561
+ index = end;
696
562
  }
697
- return sourceOptions.config;
563
+ return changed ? result : selector;
564
+ }
565
+ function normalizeCompatSelectors(selector) {
566
+ const normalized = normalizeCompatSelector(selector);
567
+ if (!normalized) return [];
568
+ const selectors = new Set([normalized]);
569
+ const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
570
+ if (escaped) selectors.add(escaped);
571
+ return [...selectors];
572
+ }
573
+ function normalizeCssSelector(selector) {
574
+ return selector.trim().replace(/\s+/g, "");
575
+ }
576
+ function getCompatSelectorKeys(selector) {
577
+ return normalizeCompatSelectors(selector).map(normalizeCssSelector);
578
+ }
579
+ function getRuleCompatSelectorKeys(rule) {
580
+ return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
581
+ }
582
+ function hasClassSelector(selector) {
583
+ return CLASS_SELECTOR_RE.test(selector);
584
+ }
585
+ function getNormalizedSelectorList(selector) {
586
+ return selector.split(",").map(normalizeCssSelector).filter(Boolean);
587
+ }
588
+ function isMiniProgramThemeScopeSelector(selector) {
589
+ const selectors = getNormalizedSelectorList(selector);
590
+ return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
591
+ }
592
+ function hasUtilityClassSelector(selector) {
593
+ return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
594
+ }
595
+ function isCustomPropertyOnlyRule(rule) {
596
+ let hasDeclaration = false;
597
+ let allCustomProperties = true;
598
+ rule.each((node) => {
599
+ if (node.type !== "decl") return;
600
+ hasDeclaration = true;
601
+ if (!node.prop.startsWith("--")) allCustomProperties = false;
602
+ });
603
+ return hasDeclaration && allCustomProperties;
604
+ }
605
+ function isPseudoContentInitRule(rule) {
606
+ let hasDeclaration = false;
607
+ let onlyContentVariable = true;
608
+ rule.each((node) => {
609
+ if (node.type !== "decl") return;
610
+ hasDeclaration = true;
611
+ if (node.prop !== "--tw-content") onlyContentVariable = false;
612
+ });
613
+ return hasDeclaration && onlyContentVariable;
614
+ }
615
+ function collectGeneratedSelectors(css) {
616
+ const selectors = /* @__PURE__ */ new Set();
617
+ try {
618
+ postcss.parse(css).walkRules((rule) => {
619
+ if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
620
+ for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
621
+ });
622
+ } catch {
623
+ return selectors;
624
+ }
625
+ return selectors;
626
+ }
627
+ function removeGeneratedSelectorCompatCss(css, generatedCss) {
628
+ const generatedSelectors = collectGeneratedSelectors(generatedCss);
629
+ if (generatedSelectors.size === 0) return css;
630
+ try {
631
+ const root = postcss.parse(css);
632
+ let removed = false;
633
+ root.walkRules((rule) => {
634
+ if (isPseudoContentInitRule(rule)) {
635
+ rule.remove();
636
+ removed = true;
637
+ return;
638
+ }
639
+ if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
640
+ if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
641
+ rule.remove();
642
+ removed = true;
643
+ }
644
+ });
645
+ root.walkAtRules((atRule) => {
646
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
647
+ });
648
+ return removed ? root.toString() : css;
649
+ } catch {
650
+ return css;
651
+ }
652
+ }
653
+ function collectDedupedPostTransformCompatCss(css, generatedCss) {
654
+ const generatedSelectors = collectGeneratedSelectors(generatedCss);
655
+ if (generatedSelectors.size === 0) return css;
656
+ const preservedNodes = [];
657
+ try {
658
+ const root = postcss.parse(css);
659
+ root.each((node) => {
660
+ if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
661
+ if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
662
+ const declarationProps = /* @__PURE__ */ new Set();
663
+ node.walkDecls((decl) => {
664
+ declarationProps.add(decl.prop);
665
+ });
666
+ postcss.parse(generatedCss).walkRules((rule) => {
667
+ const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
668
+ if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
669
+ rule.walkDecls((decl) => {
670
+ declarationProps.delete(decl.prop);
671
+ });
672
+ });
673
+ const nextRule = node.clone();
674
+ nextRule.walkDecls((decl) => {
675
+ if (!declarationProps.has(decl.prop)) decl.remove();
676
+ });
677
+ if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
678
+ }
679
+ return;
680
+ }
681
+ preservedNodes.push(node.clone());
682
+ });
683
+ if (preservedNodes.length === root.nodes.length) return css;
684
+ const nextRoot = postcss.root();
685
+ nextRoot.append(preservedNodes);
686
+ return nextRoot.toString();
687
+ } catch {
688
+ return css;
689
+ }
690
+ }
691
+ function removeDuplicatedViteMarkers(css, baseCss) {
692
+ if (!VITE_MARKER_RE.test(baseCss)) return css;
693
+ VITE_MARKER_RE.lastIndex = 0;
694
+ return css.replace(VITE_MARKER_RE, "");
695
+ }
696
+ //#endregion
697
+ //#region src/bundlers/shared/generator-css/config-directive.ts
698
+ function quoteCssString(value) {
699
+ return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
700
+ }
701
+ function toCssPath(value) {
702
+ return value.replaceAll("\\", "/");
703
+ }
704
+ function prependConfigDirective(css, config) {
705
+ if (!config || /@config\s+/.test(css)) return css;
706
+ return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
707
+ }
708
+ function normalizeConfigDirective(css, config) {
709
+ if (!config || !/@config\s+/.test(css)) return css;
710
+ return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
698
711
  }
712
+ //#endregion
713
+ //#region src/bundlers/shared/generator-css/source-files.ts
714
+ const SOURCE_STYLE_EXTENSIONS = [
715
+ ".vue",
716
+ ".uvue",
717
+ ".nvue",
718
+ ".css",
719
+ ".scss",
720
+ ".sass",
721
+ ".less",
722
+ ".styl",
723
+ ".stylus",
724
+ ".wxss",
725
+ ".acss",
726
+ ".jxss",
727
+ ".ttss",
728
+ ".qss"
729
+ ];
730
+ const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
699
731
  function stripStyleExtension(file) {
700
732
  return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
701
733
  }
@@ -749,9 +781,6 @@ function extractStyleDirectiveSources(source) {
749
781
  if (styleSources.length > 0) return styleSources;
750
782
  return hasTailwindSourceDirectives(source) ? [source] : [];
751
783
  }
752
- function shouldResolveSourceSideCssEntry(rawSource) {
753
- return rawSource.includes("@apply");
754
- }
755
784
  function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
756
785
  for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
757
786
  if (!existsSync(sourceFile)) continue;
@@ -766,6 +795,72 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
766
795
  }
767
796
  }
768
797
  }
798
+ //#endregion
799
+ //#region src/bundlers/shared/generator-css/source-resolver.ts
800
+ function resolvePostcssFromOption(cssHandlerOptions) {
801
+ const from = cssHandlerOptions.postcssOptions?.options?.from;
802
+ return typeof from === "string" && from.length > 0 ? from : void 0;
803
+ }
804
+ function resolveCssSourceBase(file, cssHandlerOptions) {
805
+ const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
806
+ return path.dirname(path.resolve(normalized));
807
+ }
808
+ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
809
+ if (config && existsSync(config)) return config;
810
+ if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
811
+ const outputDir = path.dirname(file.replace(/[?#].*$/, ""));
812
+ const baseCandidates = [
813
+ sourceOptions.projectRoot,
814
+ sourceOptions.cwd,
815
+ process.cwd()
816
+ ].filter((item) => typeof item === "string" && item.length > 0);
817
+ for (const base of baseCandidates) {
818
+ const candidates = [
819
+ path.resolve(base, configRequest),
820
+ path.resolve(base, "src", configRequest),
821
+ path.resolve(base, outputDir, configRequest),
822
+ path.resolve(base, "src", outputDir, configRequest)
823
+ ];
824
+ for (const candidate of candidates) if (existsSync(candidate)) return candidate;
825
+ }
826
+ return sourceOptions.config;
827
+ }
828
+ function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
829
+ const from = resolvePostcssFromOption(cssHandlerOptions);
830
+ if (!from || !path.isAbsolute(from)) return path.isAbsolute(file);
831
+ return true;
832
+ }
833
+ function shouldResolveSourceSideCssEntry(rawSource) {
834
+ return rawSource.includes("@apply");
835
+ }
836
+ function normalizeCssSourceForCompare(css) {
837
+ return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
838
+ }
839
+ function getOutputFileStem(file) {
840
+ const normalized = file.replace(/[?#].*$/, "");
841
+ return path.basename(normalized, path.extname(normalized));
842
+ }
843
+ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
844
+ const cssEntries = sourceOptions.cssEntries;
845
+ if (!cssEntries?.length) return;
846
+ const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
847
+ const outputStem = getOutputFileStem(file);
848
+ const matchingEntry = cssEntries.find((cssEntry) => {
849
+ if (!existsSync(cssEntry)) return false;
850
+ try {
851
+ if (normalizeCssSourceForCompare(readFileSync(cssEntry, "utf8")) === normalizedRawSource) return true;
852
+ return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
853
+ } catch {
854
+ return false;
855
+ }
856
+ });
857
+ if (!matchingEntry) return;
858
+ return resolveTailwindV4Source({
859
+ ...sourceOptions,
860
+ css: void 0,
861
+ cssEntries: [matchingEntry]
862
+ });
863
+ }
769
864
  function tryResolveTailwindV4SourceOptions(runtimeState) {
770
865
  try {
771
866
  return resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
@@ -773,16 +868,20 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
773
868
  return;
774
869
  }
775
870
  }
776
- async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
871
+ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
777
872
  const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
778
873
  if (majorVersion === 3) {
779
874
  const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
780
- const sourceSideEntrySource = resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: true });
875
+ const mergedSourceOptions = {
876
+ ...sourceOptions,
877
+ config: generatorOptions?.config ?? sourceOptions.config
878
+ };
879
+ const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
781
880
  const resolvedEntrySource = cssEntrySource ?? sourceSideEntrySource;
782
- if (!resolvedEntrySource) return resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
783
- const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, sourceOptions);
881
+ if (!resolvedEntrySource) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
882
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, mergedSourceOptions);
784
883
  return resolveTailwindV3Source({
785
- ...sourceOptions,
884
+ ...mergedSourceOptions,
786
885
  base: resolvedEntrySource.base,
787
886
  css: resolvedEntrySource.css,
788
887
  ...config ? { config } : {}
@@ -790,51 +889,105 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
790
889
  }
791
890
  const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
792
891
  const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
793
- const resolvedEntrySource = (sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0) ?? cssEntrySource;
794
- if (!resolvedEntrySource) return resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
892
+ const sourceSideEntrySource = sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0;
893
+ const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
894
+ const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4Source({
895
+ ...sourceOptions,
896
+ css: void 0,
897
+ cssEntries: [sourceOptions.cssEntries[0]]
898
+ }) : void 0;
899
+ const preferredCssEntrySource = matchedCssEntrySource ?? mainCssEntrySource;
900
+ if (preferredCssEntrySource) return generatorOptions?.config ? {
901
+ ...preferredCssEntrySource,
902
+ css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
903
+ } : preferredCssEntrySource;
904
+ const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
905
+ if (!resolvedEntrySource) {
906
+ const source = await resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
907
+ return generatorOptions?.config ? {
908
+ ...source,
909
+ css: prependConfigDirective(source.css, generatorOptions.config)
910
+ } : source;
911
+ }
912
+ const resolvedSourceOptions = sourceOptions ?? {};
913
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
795
914
  return resolveTailwindV4Source({
796
- ...sourceOptions ?? {},
915
+ ...resolvedSourceOptions,
797
916
  base: resolvedEntrySource.base,
798
- css: resolvedEntrySource.css
917
+ css: normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config)
799
918
  });
800
919
  }
801
- async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
920
+ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
802
921
  const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
803
- if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
922
+ if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
804
923
  let sourceOptions;
805
924
  try {
806
925
  sourceOptions = resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
807
926
  } catch {
808
- return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
927
+ return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
809
928
  }
810
- if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
929
+ if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
811
930
  return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4Source({
812
931
  ...sourceOptions,
813
932
  css: void 0,
814
933
  cssEntries: [cssEntry]
815
- })));
816
- }
817
- function isLocalImportRequest(request) {
818
- return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
934
+ }).then((source) => generatorOptions?.config ? {
935
+ ...source,
936
+ css: prependConfigDirective(source.css, generatorOptions.config)
937
+ } : source)));
819
938
  }
820
- function isPureLocalCssImportWrapper(css) {
821
- let hasImport = false;
939
+ //#endregion
940
+ //#region src/bundlers/shared/generator-css/legacy-compat.ts
941
+ const LEGACY_CONTAINER_COMPAT_CSS = [
942
+ ".container {",
943
+ " width: 100%;",
944
+ "}",
945
+ "@media (min-width: 40rem) {",
946
+ " .container {",
947
+ " max-width: 40rem;",
948
+ " }",
949
+ "}",
950
+ "@media (min-width: 48rem) {",
951
+ " .container {",
952
+ " max-width: 48rem;",
953
+ " }",
954
+ "}",
955
+ "@media (min-width: 64rem) {",
956
+ " .container {",
957
+ " max-width: 64rem;",
958
+ " }",
959
+ "}",
960
+ "@media (min-width: 80rem) {",
961
+ " .container {",
962
+ " max-width: 80rem;",
963
+ " }",
964
+ "}",
965
+ "@media (min-width: 96rem) {",
966
+ " .container {",
967
+ " max-width: 96rem;",
968
+ " }",
969
+ "}"
970
+ ].join("\n");
971
+ function removeTailwindApplyRules(rawSource) {
822
972
  try {
823
- const root = postcss.parse(css);
824
- for (const node of root.nodes) {
825
- if (node.type === "comment") continue;
826
- if (node.type !== "atrule" || node.name !== "import") return false;
827
- const request = parseImportRequest(node.params);
828
- if (!request || !isLocalImportRequest(request)) return false;
829
- hasImport = true;
830
- }
973
+ const root = postcss.parse(rawSource);
974
+ let removed = false;
975
+ root.walkAtRules("apply", (rule) => {
976
+ const parent = rule.parent;
977
+ if (parent?.type === "rule") parent.remove();
978
+ else rule.remove();
979
+ removed = true;
980
+ });
981
+ root.walkAtRules((rule) => {
982
+ if (rule.nodes && rule.nodes.length === 0) rule.remove();
983
+ });
984
+ return removed ? root.toString() : rawSource;
831
985
  } catch {
832
- return false;
986
+ return rawSource;
833
987
  }
834
- return hasImport;
835
988
  }
836
989
  function resolveLegacyCompatCssSource(rawSource) {
837
- return removeUnsupportedMiniProgramAtRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource)));
990
+ return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
838
991
  }
839
992
  function hasContainerConfigToken(rawSource) {
840
993
  return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
@@ -863,173 +1016,188 @@ function hasConfiguredContainerCompatSource(source) {
863
1016
  function hasConfiguredContainerCompatSources(sources) {
864
1017
  return sources.some((source) => hasConfiguredContainerCompatSource(source));
865
1018
  }
866
- function removeDuplicatedViteMarkers(css, baseCss) {
867
- if (!VITE_MARKER_RE.test(baseCss)) return css;
868
- VITE_MARKER_RE.lastIndex = 0;
869
- return css.replace(VITE_MARKER_RE, "");
870
- }
871
- function normalizeCssSelector(selector) {
872
- return selector.trim().replace(/\s+/g, "");
873
- }
874
- function getCompatSelectorKeys(selector) {
875
- return normalizeCompatSelectors(selector).map(normalizeCssSelector);
876
- }
877
- function getRuleCompatSelectorKeys(rule) {
878
- return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
1019
+ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1020
+ const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
1021
+ if (compatSource.trim().length === 0) return css;
1022
+ if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
1023
+ const { css: compatCss } = await styleHandler(compatSource, {
1024
+ ...cssHandlerOptions,
1025
+ ...generatorStyleOptions
1026
+ });
1027
+ const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
1028
+ if (cleanedCompatCss.trim().length === 0) return css;
1029
+ return createCssAppend(css, cleanedCompatCss);
879
1030
  }
880
- function hasClassSelector(selector) {
881
- return CLASS_SELECTOR_RE.test(selector);
1031
+ async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1032
+ const compatSource = resolveLegacyCompatCssSource(rawSource);
1033
+ const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
1034
+ if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
1035
+ const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
1036
+ ...cssHandlerOptions,
1037
+ ...generatorStyleOptions
1038
+ });
1039
+ const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
1040
+ if (cleanedCompatCss.trim().length === 0) return css;
1041
+ return createCssAppend(css, cleanedCompatCss);
882
1042
  }
883
- function getNormalizedSelectorList(selector) {
884
- return selector.split(",").map(normalizeCssSelector).filter(Boolean);
1043
+ //#endregion
1044
+ //#region src/bundlers/shared/generator-css/legacy-units.ts
1045
+ const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
1046
+ const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
1047
+ function createLegacyDeclarationValueMap(css) {
1048
+ const values = /* @__PURE__ */ new Map();
1049
+ postcss.parse(css).walkRules((rule) => {
1050
+ if (!rule.selectors || rule.selectors.length === 0) return;
1051
+ for (const selector of rule.selectors) {
1052
+ const normalizedSelectors = normalizeCompatSelectors(selector);
1053
+ rule.walkDecls((decl) => {
1054
+ if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
1055
+ });
1056
+ }
1057
+ });
1058
+ return values;
885
1059
  }
886
- function isMiniProgramThemeScopeSelector(selector) {
887
- const selectors = getNormalizedSelectorList(selector);
888
- return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
1060
+ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
1061
+ try {
1062
+ const legacyValues = createLegacyDeclarationValueMap(legacyCss);
1063
+ if (legacyValues.size === 0) return css;
1064
+ const root = postcss.parse(css);
1065
+ let changed = false;
1066
+ root.walkRules((rule) => {
1067
+ if (!rule.selectors || rule.selectors.length === 0) return;
1068
+ const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
1069
+ if (selectors.length === 0) return;
1070
+ rule.walkDecls((decl) => {
1071
+ if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
1072
+ for (const selector of selectors) {
1073
+ const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
1074
+ if (legacyValue && legacyValue !== decl.value) {
1075
+ decl.value = legacyValue;
1076
+ changed = true;
1077
+ return;
1078
+ }
1079
+ }
1080
+ });
1081
+ });
1082
+ return changed ? root.toString() : css;
1083
+ } catch {
1084
+ return css;
1085
+ }
889
1086
  }
890
- function hasUtilityClassSelector(selector) {
891
- return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
1087
+ //#endregion
1088
+ //#region src/bundlers/shared/generator-css.ts
1089
+ const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
1090
+ const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
1091
+ function finalizeMiniProgramGeneratorCss(css, target) {
1092
+ if (target !== "weapp") return css;
1093
+ return finalizeMiniProgramCss(css);
892
1094
  }
893
- function isCustomPropertyOnlyRule(rule) {
894
- let hasDeclaration = false;
895
- let allCustomProperties = true;
896
- rule.each((node) => {
897
- if (node.type !== "decl") return;
898
- hasDeclaration = true;
899
- if (!node.prop.startsWith("--")) allCustomProperties = false;
900
- });
901
- return hasDeclaration && allCustomProperties;
1095
+ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
1096
+ const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
1097
+ cssPreflight: opts.cssPreflight,
1098
+ cssPreflightRange: opts.cssPreflightRange
1099
+ } : {};
1100
+ return {
1101
+ cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
1102
+ cssSelectorReplacement: opts.cssSelectorReplacement,
1103
+ rem2rpx: opts.rem2rpx,
1104
+ px2rpx: opts.px2rpx,
1105
+ unitsToPx: opts.unitsToPx,
1106
+ cssRemoveProperty: opts.cssRemoveProperty,
1107
+ cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
1108
+ cssPresetEnv: opts.cssPresetEnv,
1109
+ autoprefixer: opts.autoprefixer,
1110
+ cssCalc: opts.cssCalc,
1111
+ atRules: opts.atRules,
1112
+ uniAppX: opts.uniAppX,
1113
+ uniAppXCssTarget: opts.uniAppXCssTarget,
1114
+ uniAppXUnsupported: opts.uniAppXUnsupported,
1115
+ ...cssHandlerOptions,
1116
+ ...tailwindV3StyleOptions,
1117
+ ...generatorStyleOptions
1118
+ };
902
1119
  }
903
- function isPseudoContentInitRule(rule) {
904
- let hasDeclaration = false;
905
- let onlyContentVariable = true;
906
- rule.each((node) => {
907
- if (node.type !== "decl") return;
908
- hasDeclaration = true;
909
- if (node.prop !== "--tw-content") onlyContentVariable = false;
910
- });
911
- return hasDeclaration && onlyContentVariable;
1120
+ function isLocalImportRequest(request) {
1121
+ return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
912
1122
  }
913
- function collectGeneratedSelectors(css) {
914
- const selectors = /* @__PURE__ */ new Set();
1123
+ function isPureLocalCssImportWrapper(css) {
1124
+ let hasImport = false;
915
1125
  try {
916
- postcss.parse(css).walkRules((rule) => {
917
- if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
918
- for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
919
- });
1126
+ const root = postcss.parse(css);
1127
+ for (const node of root.nodes) {
1128
+ if (node.type === "comment") continue;
1129
+ if (node.type !== "atrule" || node.name !== "import") return false;
1130
+ const request = parseImportRequest(node.params);
1131
+ if (!request || !isLocalImportRequest(request)) return false;
1132
+ hasImport = true;
1133
+ }
920
1134
  } catch {
921
- return selectors;
1135
+ return false;
922
1136
  }
923
- return selectors;
1137
+ return hasImport;
924
1138
  }
925
- function removeGeneratedSelectorCompatCss(css, generatedCss) {
926
- const generatedSelectors = collectGeneratedSelectors(generatedCss);
927
- if (generatedSelectors.size === 0) return css;
1139
+ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1140
+ let hasLocalImport = false;
1141
+ let hasTailwindDirective = false;
928
1142
  try {
929
1143
  const root = postcss.parse(css);
930
- let removed = false;
931
- root.walkRules((rule) => {
932
- if (isPseudoContentInitRule(rule)) {
933
- rule.remove();
934
- removed = true;
935
- return;
1144
+ for (const node of root.nodes) {
1145
+ if (node.type === "comment") continue;
1146
+ if (node.type === "atrule" && node.name === "import") {
1147
+ const request = parseImportRequest(node.params);
1148
+ if (!request || !isLocalImportRequest(request)) return;
1149
+ hasLocalImport = true;
1150
+ continue;
936
1151
  }
937
- if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
938
- if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
939
- rule.remove();
940
- removed = true;
1152
+ if (node.type === "atrule" && node.name === "source") {
1153
+ hasTailwindDirective = true;
1154
+ continue;
941
1155
  }
942
- });
943
- root.walkAtRules((atRule) => {
944
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
945
- });
946
- return removed ? root.toString() : css;
1156
+ return;
1157
+ }
947
1158
  } catch {
948
- return css;
1159
+ return;
949
1160
  }
1161
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
950
1162
  }
951
- function collectDedupedPostTransformCompatCss(css, generatedCss) {
952
- const generatedSelectors = collectGeneratedSelectors(generatedCss);
953
- if (generatedSelectors.size === 0) return css;
954
- const preservedNodes = [];
1163
+ function prefixLocalCssImportsWithWebpackIgnore(css) {
955
1164
  try {
956
1165
  const root = postcss.parse(css);
957
- root.each((node) => {
958
- if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
959
- if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
960
- const declarationProps = /* @__PURE__ */ new Set();
961
- node.walkDecls((decl) => {
962
- declarationProps.add(decl.prop);
963
- });
964
- postcss.parse(generatedCss).walkRules((rule) => {
965
- const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
966
- if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
967
- rule.walkDecls((decl) => {
968
- declarationProps.delete(decl.prop);
969
- });
970
- });
971
- const nextRule = node.clone();
972
- nextRule.walkDecls((decl) => {
973
- if (!declarationProps.has(decl.prop)) decl.remove();
974
- });
975
- if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
976
- }
977
- return;
978
- }
979
- preservedNodes.push(node.clone());
1166
+ root.walkAtRules("import", (atRule) => {
1167
+ const request = parseImportRequest(atRule.params);
1168
+ if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
980
1169
  });
981
- if (preservedNodes.length === root.nodes.length) return css;
982
- const nextRoot = postcss.root();
983
- nextRoot.append(preservedNodes);
984
- return nextRoot.toString();
1170
+ return root.toString();
985
1171
  } catch {
986
1172
  return css;
987
1173
  }
988
1174
  }
989
- async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
990
- const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
991
- if (compatSource.trim().length === 0) return css;
992
- if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
993
- const { css: compatCss } = await styleHandler(compatSource, {
994
- ...cssHandlerOptions,
995
- ...generatorStyleOptions
996
- });
997
- const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
998
- if (cleanedCompatCss.trim().length === 0) return css;
999
- return createCssAppend(css, cleanedCompatCss);
1000
- }
1001
- async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1002
- const compatSource = resolveLegacyCompatCssSource(rawSource);
1003
- const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
1004
- if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
1005
- const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
1006
- ...cssHandlerOptions,
1007
- ...generatorStyleOptions
1008
- });
1009
- const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
1010
- if (cleanedCompatCss.trim().length === 0) return css;
1011
- return createCssAppend(css, cleanedCompatCss);
1012
- }
1013
1175
  async function generateCssByGenerator(options) {
1014
1176
  const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
1015
1177
  const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
1016
1178
  const majorVersion = runtimeState.twPatcher.majorVersion;
1179
+ const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(rawSource);
1180
+ if (cleanedLocalImportWrapper !== void 0) return {
1181
+ css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
1182
+ target: generatorOptions.target,
1183
+ source: "generator",
1184
+ dependencies: []
1185
+ };
1017
1186
  if (isPureLocalCssImportWrapper(rawSource)) return;
1018
1187
  const hasGeneratedCss = hasTailwindGeneratedCss(rawSource);
1019
1188
  const hasSourceDirectives = hasTailwindSourceDirectives(rawSource);
1020
1189
  const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(rawSource);
1021
- const shouldForceGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1022
- const shouldAutoGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives;
1023
- if (generatorOptions.mode === "off" || !SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || (generatorOptions.mode === "force" ? !shouldForceGenerateCurrentCss : !shouldAutoGenerateCurrentCss) || generatorOptions.mode === "force" && majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers || generatorOptions.mode !== "force" && majorVersion === 3) return;
1190
+ const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1191
+ if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1024
1192
  try {
1025
- await runtimeState.patchPromise;
1026
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions);
1193
+ await runtimeState.readyPromise;
1194
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions);
1027
1195
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1028
1196
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1029
1197
  const generatedResults = await Promise.all(sources.map(async (source) => {
1030
1198
  return createWeappTailwindcssGenerator(source).generate({
1031
1199
  candidates: runtime,
1032
- scanSources: false,
1200
+ scanSources: majorVersion === 4,
1033
1201
  styleOptions: generatorStyleOptions,
1034
1202
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1035
1203
  target: generatorOptions.target
@@ -1057,7 +1225,8 @@ async function generateCssByGenerator(options) {
1057
1225
  if (extraSource.trim().length === 0) return {
1058
1226
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1059
1227
  target: generated.target,
1060
- source: "generator"
1228
+ source: "generator",
1229
+ dependencies: generated.dependencies
1061
1230
  };
1062
1231
  if (generated.target === "weapp") {
1063
1232
  const { css: userCss } = await styleHandler(extraSource, {
@@ -1068,14 +1237,15 @@ async function generateCssByGenerator(options) {
1068
1237
  } else css = createCssAppend(css, extraSource);
1069
1238
  }
1070
1239
  }
1071
- if (generated.target === "weapp" && generatorOptions.mode === "force") {
1240
+ if (generated.target === "weapp") {
1072
1241
  css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1073
1242
  css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1074
1243
  }
1075
1244
  return {
1076
1245
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1077
1246
  target: generated.target,
1078
- source: "generator"
1247
+ source: "generator",
1248
+ dependencies: generated.dependencies
1079
1249
  };
1080
1250
  }
1081
1251
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
@@ -1086,12 +1256,30 @@ async function generateCssByGenerator(options) {
1086
1256
  return {
1087
1257
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1088
1258
  target: generated.target,
1089
- source: generatorOptions.mode === "force" ? "generator-forced" : "generator"
1259
+ source: "generator",
1260
+ dependencies: generated.dependencies
1090
1261
  };
1091
1262
  } catch (error) {
1092
- if (generatorOptions.mode === "force") throw error;
1093
- debug("tailwind direct css generation failed, fallback to styleHandler: %s %O", file, error);
1263
+ debug("tailwind direct css generation failed: %s %O", file, error);
1264
+ throw error;
1094
1265
  }
1095
1266
  }
1267
+ async function validateCandidatesByGenerator(options) {
1268
+ const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
1269
+ const majorVersion = runtimeState.twPatcher.majorVersion;
1270
+ if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
1271
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, normalizeWeappTailwindcssGeneratorOptions(opts.generator));
1272
+ const classSets = await Promise.all(sources.map(async (source) => {
1273
+ const generator = createWeappTailwindcssGenerator(source);
1274
+ if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
1275
+ return (await generator.generate({
1276
+ candidates,
1277
+ target: "tailwind"
1278
+ })).classSet;
1279
+ }));
1280
+ const classSet = new Set(classSets.flatMap((item) => [...item]));
1281
+ debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
1282
+ return classSet;
1283
+ }
1096
1284
  //#endregion
1097
- export { processCachedTask as i, hasTailwindGeneratedCssMarkers as n, hasTailwindSourceDirectives as r, generateCssByGenerator as t };
1285
+ export { processCachedTask as a, hasTailwindGeneratedCssMarkers as i, validateCandidatesByGenerator as n, hasTailwindSourceDirectives as r, generateCssByGenerator as t };