weapp-tailwindcss 5.0.0-next.2 → 5.0.0-next.21

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 (221) hide show
  1. package/README.md +6 -7
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundle-state-BnV8o2Yn.js +530 -0
  4. package/dist/bundle-state-CLnuf2CW.mjs +414 -0
  5. package/dist/bundlers/shared/cache.d.ts +6 -6
  6. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -0
  7. package/dist/bundlers/shared/css-cleanup.d.ts +1 -4
  8. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  9. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  10. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  11. package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
  12. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  13. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  14. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  15. package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
  16. package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
  17. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
  18. package/dist/bundlers/shared/generator-css.d.ts +16 -22
  19. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  20. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  21. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  22. package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
  23. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  24. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
  25. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
  26. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  27. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  28. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  29. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  30. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  31. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  32. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  33. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  34. package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
  35. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
  36. package/dist/bundlers/vite/index.d.ts +1 -1
  37. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  38. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  39. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  40. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
  41. package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
  42. package/dist/bundlers/vite/source-candidates.d.ts +16 -1
  43. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  44. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  45. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  46. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
  47. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
  48. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
  49. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  50. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  51. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
  52. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  53. package/dist/cache/index.d.ts +6 -6
  54. package/dist/cli/context.d.ts +1 -14
  55. package/dist/cli/doctor/types.d.ts +11 -11
  56. package/dist/cli/helpers.d.ts +1 -2
  57. package/dist/cli/mount-options.d.ts +2 -0
  58. package/dist/cli/types.d.ts +0 -2
  59. package/dist/cli/vscode-entry.d.ts +3 -3
  60. package/dist/cli.js +605 -611
  61. package/dist/cli.mjs +614 -620
  62. package/dist/constants.d.ts +1 -2
  63. package/dist/core.js +13 -20
  64. package/dist/core.mjs +8 -14
  65. package/dist/css-macro/postcss.js +3 -2
  66. package/dist/css-macro/postcss.mjs +3 -2
  67. package/dist/css-macro.d.ts +1 -0
  68. package/dist/css-macro.js +2 -2
  69. package/dist/css-macro.mjs +2 -2
  70. package/dist/defaults-B1igPF_e.mjs +150 -0
  71. package/dist/defaults-IHhYxNeU.js +193 -0
  72. package/dist/defaults.d.ts +15 -1
  73. package/dist/defaults.js +6 -131
  74. package/dist/defaults.mjs +2 -129
  75. package/dist/escape.js +10 -2
  76. package/dist/escape.mjs +10 -2
  77. package/dist/generator/index.d.ts +1 -1
  78. package/dist/generator/options.d.ts +9 -8
  79. package/dist/generator/types.d.ts +3 -3
  80. package/dist/generator-B4RNgMLx.js +55 -0
  81. package/dist/generator-DvyhmC76.mjs +32 -0
  82. package/dist/generator.js +12 -11
  83. package/dist/generator.mjs +2 -1
  84. package/dist/gulp.js +185 -47
  85. package/dist/gulp.mjs +179 -41
  86. package/dist/incremental-runtime-class-set-C7Q7fC5u.mjs +1863 -0
  87. package/dist/incremental-runtime-class-set-DZsbM0-a.js +1926 -0
  88. package/dist/index.d.ts +1 -1
  89. package/dist/index.js +6 -6
  90. package/dist/index.mjs +5 -5
  91. package/dist/js/babel/cache-options.d.ts +3 -0
  92. package/dist/js/babel/parse.d.ts +7 -4
  93. package/dist/js/index.d.ts +1 -0
  94. package/dist/js/literal-transform.d.ts +2 -0
  95. package/dist/js/precheck.d.ts +2 -2
  96. package/dist/logger-CZUxvJJD.mjs +2 -0
  97. package/dist/logger-EVNB9z7i.js +1 -0
  98. package/dist/postcss/config-directive.d.ts +1 -0
  99. package/dist/postcss/context.d.ts +9 -0
  100. package/dist/postcss/source-files.d.ts +8 -0
  101. package/dist/postcss/tailwind-version.d.ts +3 -0
  102. package/dist/postcss-CFa6-qO9.js +237 -0
  103. package/dist/postcss-Drpy7j-g.mjs +228 -0
  104. package/dist/postcss.d.ts +2 -2
  105. package/dist/postcss.js +3 -276
  106. package/dist/postcss.mjs +1 -269
  107. package/dist/{recorder-gYSNLfOP.js → precheck-8pQbjqpq.js} +218 -314
  108. package/dist/{recorder-zsgatmkB.mjs → precheck-D1O5AWzy.mjs} +186 -281
  109. package/dist/presets.js +13 -11
  110. package/dist/presets.mjs +11 -9
  111. package/dist/reset.d.ts +1 -0
  112. package/dist/runtime-registry-CdCV3Opt.js +5496 -0
  113. package/dist/shared/mpx.d.ts +1 -0
  114. package/dist/source-candidates-CUTNdsiz.js +222 -0
  115. package/dist/source-candidates-CnD4vyic.mjs +209 -0
  116. package/dist/tailwindcss/miniprogram.d.ts +1 -1
  117. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  118. package/dist/tailwindcss/patcher.d.ts +1 -2
  119. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  120. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  121. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  122. package/dist/tailwindcss/runtime.d.ts +11 -12
  123. package/dist/tailwindcss/source-scan.d.ts +35 -0
  124. package/dist/tailwindcss/targets.d.ts +1 -5
  125. package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
  126. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  127. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  128. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  129. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  130. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  131. package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
  132. package/dist/tailwindcss/version.d.ts +4 -0
  133. package/dist/tailwindcss-B_JAdOQf.mjs +600 -0
  134. package/dist/tailwindcss-whZE3HpL.js +651 -0
  135. package/dist/typedoc.export.d.ts +0 -2
  136. package/dist/types/index.d.ts +51 -48
  137. package/dist/types/shared.d.ts +3 -0
  138. package/dist/types/user-defined-options/general.d.ts +23 -23
  139. package/dist/types/user-defined-options/important.d.ts +31 -28
  140. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  141. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  142. package/dist/uni-app-x/vite.d.ts +1 -1
  143. package/dist/utils/disabled.d.ts +2 -3
  144. package/dist/utils/object.d.ts +9 -0
  145. package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
  146. package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
  147. package/dist/v3-engine-CCwvhRrQ.js +3473 -0
  148. package/dist/v3-engine-DyIcbpZm.mjs +3190 -0
  149. package/dist/{vite-CrlzCNqz.mjs → vite-B8IiXgVD.mjs} +1256 -1088
  150. package/dist/vite-BcnwgJMt.js +2368 -0
  151. package/dist/vite.d.ts +1 -2
  152. package/dist/vite.js +3 -4
  153. package/dist/vite.mjs +2 -2
  154. package/dist/weapp-tw-css-import-rewrite-loader.js +4533 -16
  155. package/dist/weapp-tw-runtime-classset-loader.js +33 -7
  156. package/dist/webpack-C4zI624R.js +846 -0
  157. package/dist/webpack-DTkshAtp.mjs +836 -0
  158. package/dist/webpack.js +1 -1
  159. package/dist/webpack.mjs +1 -1
  160. package/package.json +27 -37
  161. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  162. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  163. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  164. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  165. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  166. package/dist/cli/config.d.ts +0 -5
  167. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  168. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  169. package/dist/cli/patch-options.d.ts +0 -6
  170. package/dist/cli/tokens.d.ts +0 -4
  171. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  172. package/dist/cli/workspace/patch-package.d.ts +0 -3
  173. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  174. package/dist/cli/workspace/types.d.ts +0 -11
  175. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  176. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  177. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  178. package/dist/cli/workspace.d.ts +0 -2
  179. package/dist/css-imports-BbrbluP9.js +0 -177
  180. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  181. package/dist/experimental/index.d.ts +0 -2
  182. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  183. package/dist/experimental/oxc/index.d.ts +0 -2
  184. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  185. package/dist/experimental/shared/cache.d.ts +0 -3
  186. package/dist/experimental/shared/transform.d.ts +0 -3
  187. package/dist/experimental/shared.d.ts +0 -8
  188. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  189. package/dist/experimental/swc/index.d.ts +0 -2
  190. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  191. package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
  192. package/dist/generator-css-B5ejWUMv.mjs +0 -1098
  193. package/dist/generator-css-D3OdPRiS.js +0 -1125
  194. package/dist/generator-mmhXzZnv.js +0 -1276
  195. package/dist/js/syntax.d.ts +0 -10
  196. package/dist/lightningcss/index.d.ts +0 -8
  197. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  198. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  199. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  200. package/dist/lightningcss/style-handler.d.ts +0 -17
  201. package/dist/loader-anchors-CNkWT8hx.js +0 -273
  202. package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
  203. package/dist/logger-BZ45DZJT.js +0 -1003
  204. package/dist/logger-BoVx1Dbt.mjs +0 -935
  205. package/dist/patcher-options-6gJN2EXy.js +0 -115
  206. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  207. package/dist/tailwindcss/recorder.d.ts +0 -13
  208. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  209. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  210. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  211. package/dist/tailwindcss/targets/types.d.ts +0 -35
  212. package/dist/types/disabled-options.d.ts +0 -4
  213. package/dist/vite-BC9U7ahn.js +0 -2199
  214. package/dist/webpack-Bu6M-Hbw.mjs +0 -441
  215. package/dist/webpack-DD7A6V0u.js +0 -456
  216. package/dist/webpack4.d.ts +0 -4
  217. package/dist/webpack4.js +0 -387
  218. package/dist/webpack4.mjs +0 -379
  219. package/scripts/postinstall.mjs +0 -59
  220. /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
  221. /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
@@ -0,0 +1,1926 @@
1
+ const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_v3_engine = require("./v3-engine-CCwvhRrQ.js");
3
+ const require_generator = require("./generator-B4RNgMLx.js");
4
+ const require_precheck = require("./precheck-8pQbjqpq.js");
5
+ const require_tailwindcss = require("./tailwindcss-whZE3HpL.js");
6
+ let node_fs = require("node:fs");
7
+ let postcss = require("postcss");
8
+ postcss = require_chunk.__toESM(postcss);
9
+ let node_path = require("node:path");
10
+ node_path = require_chunk.__toESM(node_path);
11
+ let node_process = require("node:process");
12
+ node_process = require_chunk.__toESM(node_process);
13
+ let tailwindcss_patch = require("tailwindcss-patch");
14
+ let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
15
+ //#region src/bundlers/shared/generator-css/markers.ts
16
+ const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
17
+ 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)-/;
18
+ const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
19
+ const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
20
+ const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
21
+ const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
22
+ const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
23
+ const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
24
+ function createCssAppend(base, extra) {
25
+ if (!base) return extra;
26
+ if (!extra) return base;
27
+ return `${base}\n${extra}`;
28
+ }
29
+ function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
30
+ const trimmedRaw = rawSource.trim();
31
+ const trimmedTailwind = rawTailwindCss.trim();
32
+ if (trimmedRaw === trimmedTailwind) return {
33
+ before: "",
34
+ after: ""
35
+ };
36
+ if (trimmedTailwind.startsWith(trimmedRaw)) return {
37
+ before: "",
38
+ after: ""
39
+ };
40
+ const start = rawSource.indexOf(rawTailwindCss);
41
+ if (start === -1) return;
42
+ return {
43
+ before: rawSource.slice(0, start),
44
+ after: rawSource.slice(start + rawTailwindCss.length)
45
+ };
46
+ }
47
+ function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
48
+ const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
49
+ if (!match || match.index === void 0) return;
50
+ let afterStart = match.index + match[0].length;
51
+ while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
52
+ if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
53
+ afterStart += rawTailwindCss.length;
54
+ while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
55
+ }
56
+ return {
57
+ before: rawSource.slice(0, match.index),
58
+ after: rawSource.slice(afterStart)
59
+ };
60
+ }
61
+ function splitTailwindGeneratedCssByBanner(rawSource, start) {
62
+ const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
63
+ if (!match || match.index === void 0) return;
64
+ return {
65
+ before: rawSource.slice(0, match.index),
66
+ after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
67
+ };
68
+ }
69
+ function stripTailwindBanner(css) {
70
+ return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
71
+ }
72
+ function stripTailwindBanners(css) {
73
+ return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
74
+ }
75
+ function stripGeneratorPlaceholderMarkers(css) {
76
+ return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
77
+ }
78
+ function hasTailwindGeneratedCss(rawSource) {
79
+ return TAILWIND_V4_BANNER_RE.test(rawSource);
80
+ }
81
+ function hasTailwindGeneratedCssMarkers(rawSource) {
82
+ return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
83
+ }
84
+ //#endregion
85
+ //#region src/bundlers/shared/generator-css/directives.ts
86
+ const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
87
+ "config",
88
+ "custom-variant",
89
+ "layer",
90
+ "plugin",
91
+ "reference",
92
+ "source",
93
+ "tailwind",
94
+ "theme",
95
+ "utility",
96
+ "variant"
97
+ ]);
98
+ const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
99
+ "config",
100
+ "custom-variant",
101
+ "plugin",
102
+ "source",
103
+ "tailwind",
104
+ "theme",
105
+ "utility",
106
+ "variant"
107
+ ]);
108
+ const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
109
+ const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
110
+ const TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE = /^\s*@(?:theme|utility|variant|custom-variant)\b[\s\S]*$/;
111
+ const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
112
+ function parseImportRequest(params) {
113
+ return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
114
+ }
115
+ function parseConfigRequest(params) {
116
+ return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
117
+ }
118
+ function isPackageJsonImportRequest(request) {
119
+ return typeof request === "string" && request.startsWith("#");
120
+ }
121
+ function isWeappTailwindcssImportRequest(request) {
122
+ return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
123
+ }
124
+ function normalizeTailwindImportRequest(request, options = {}) {
125
+ if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
126
+ return request;
127
+ }
128
+ function replaceImportRequest(params, request, replacement) {
129
+ const index = params.indexOf(request);
130
+ if (index === -1) return params;
131
+ return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
132
+ }
133
+ function normalizeTailwindImportAtRules(root, options = {}) {
134
+ if (!options.importFallback) return false;
135
+ let changed = false;
136
+ const seenCanonicalImports = /* @__PURE__ */ new Set();
137
+ root.walkAtRules("import", (node) => {
138
+ const request = parseImportRequest(node.params);
139
+ const normalizedRequest = normalizeTailwindImportRequest(request, options);
140
+ if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
141
+ const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
142
+ const normalizedKey = normalizedParams.trim();
143
+ if (seenCanonicalImports.has(normalizedKey)) {
144
+ node.remove();
145
+ changed = true;
146
+ return;
147
+ }
148
+ seenCanonicalImports.add(normalizedKey);
149
+ if (normalizedParams !== node.params) {
150
+ node.params = normalizedParams;
151
+ changed = true;
152
+ }
153
+ });
154
+ return changed;
155
+ }
156
+ function normalizeTailwindDirectiveLine(line, options = {}) {
157
+ if (!options.importFallback || !line.trimStart().startsWith("@import")) return line;
158
+ const request = parseImportRequest(line.trimStart().replace(/^@import\b/, ""));
159
+ if (!request || !isWeappTailwindcssImportRequest(request)) return line;
160
+ return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
161
+ }
162
+ function extractTailwindDirectiveLines(rawSource, options = {}) {
163
+ const directives = [];
164
+ const seenImports = /* @__PURE__ */ new Set();
165
+ for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
166
+ const trimmed = line.trim();
167
+ if (!trimmed || trimmed.startsWith("//")) continue;
168
+ const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
169
+ if (!directive) continue;
170
+ const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
171
+ const normalizedTrimmed = normalized.trim();
172
+ if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
173
+ const request = /^@import\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@import\b/, "")) : void 0;
174
+ if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest(request)) continue;
175
+ if (/^@import\b/.test(normalizedTrimmed) && !request) continue;
176
+ if (request && isTailwindImportRequest(request)) {
177
+ const key = normalizedTrimmed;
178
+ if (seenImports.has(key)) continue;
179
+ seenImports.add(key);
180
+ }
181
+ directives.push(normalized);
182
+ }
183
+ return directives;
184
+ }
185
+ function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
186
+ const directives = extractTailwindDirectiveLines(rawSource, options);
187
+ return directives.length > 0 ? directives.join("\n") : void 0;
188
+ }
189
+ function extractConfigRequestFromSource(rawSource) {
190
+ for (const line of rawSource.split(/\r?\n/)) {
191
+ const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
192
+ const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
193
+ if (request) return request;
194
+ }
195
+ }
196
+ function hasPreprocessorOnlySyntax(rawSource) {
197
+ return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
198
+ }
199
+ function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
200
+ return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
201
+ }
202
+ function normalizeTailwindSourceDirectives(rawSource, options = {}) {
203
+ if (!options.importFallback) return rawSource;
204
+ try {
205
+ const root = postcss.default.parse(rawSource);
206
+ return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
207
+ } catch {
208
+ return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
209
+ }
210
+ }
211
+ function isTailwindImportRequest(request) {
212
+ return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
213
+ }
214
+ function isTailwindImportAtRule(node, options = {}) {
215
+ if (node.name === "tailwind") return true;
216
+ if (node.name !== "import") return false;
217
+ return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
218
+ }
219
+ function isTailwindSourceDirective(node, options = {}) {
220
+ if (node.type !== "atrule") return false;
221
+ const atRule = node;
222
+ if (isTailwindImportAtRule(atRule, options)) return true;
223
+ if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
224
+ return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
225
+ }
226
+ function hasGeneratedCssArtifacts(rawSource) {
227
+ return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
228
+ }
229
+ function isTailwindGenerationDirective(node, options = {}) {
230
+ if (node.type !== "atrule") return false;
231
+ const atRule = node;
232
+ const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
233
+ return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
234
+ }
235
+ function removeTailwindSourceDirectives(rawSource, options = {}) {
236
+ try {
237
+ if (hasPreprocessorOnlySyntax(rawSource)) return "";
238
+ const source = stripGeneratorPlaceholderMarkers(rawSource);
239
+ const root = postcss.default.parse(source);
240
+ let removed = false;
241
+ root.walk((node) => {
242
+ if (isTailwindSourceDirective(node, options)) {
243
+ node.remove();
244
+ removed = true;
245
+ }
246
+ });
247
+ return removed ? root.toString() : source;
248
+ } catch {
249
+ return stripGeneratorPlaceholderMarkers(rawSource);
250
+ }
251
+ }
252
+ function hasTailwindSourceDirectives(rawSource, options = {}) {
253
+ try {
254
+ if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
255
+ const root = postcss.default.parse(rawSource);
256
+ let found = false;
257
+ const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
258
+ root.walk((node) => {
259
+ if (isTailwindGenerationDirective(node, {
260
+ ...options,
261
+ ignoreLayer
262
+ })) {
263
+ found = true;
264
+ return false;
265
+ }
266
+ });
267
+ return found;
268
+ } catch {
269
+ return extractTailwindDirectiveLines(rawSource, options).length > 0;
270
+ }
271
+ }
272
+ function hasTailwindRootDirectives(rawSource, options = {}) {
273
+ if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
274
+ try {
275
+ const root = postcss.default.parse(rawSource);
276
+ let found = false;
277
+ root.walkAtRules((node) => {
278
+ const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
279
+ if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
280
+ found = true;
281
+ return false;
282
+ }
283
+ });
284
+ return found;
285
+ } catch {
286
+ return extractTailwindDirectiveLines(rawSource, options).length > 0;
287
+ }
288
+ }
289
+ function hasTailwindApplyDirective(rawSource) {
290
+ if (!rawSource.includes("@apply")) return false;
291
+ try {
292
+ const root = postcss.default.parse(rawSource);
293
+ let found = false;
294
+ root.walkAtRules("apply", () => {
295
+ found = true;
296
+ return false;
297
+ });
298
+ return found;
299
+ } catch {
300
+ return false;
301
+ }
302
+ }
303
+ function resolveCssEntrySource(rawSource, base, options = {}) {
304
+ try {
305
+ const root = postcss.default.parse(rawSource);
306
+ const normalizedImports = normalizeTailwindImportAtRules(root, options);
307
+ let found = false;
308
+ let config;
309
+ let configRequest;
310
+ let removedConfig = false;
311
+ const removeConfig = options.removeConfig ?? true;
312
+ const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
313
+ root.walk((node) => {
314
+ if (isTailwindGenerationDirective(node, {
315
+ ...options,
316
+ ignoreLayer
317
+ })) found = true;
318
+ if (node.type === "atrule" && node.name === "config") {
319
+ const configPath = parseConfigRequest(node.params);
320
+ if (configPath && !config) {
321
+ configRequest = configPath;
322
+ config = isPackageJsonImportRequest(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
323
+ }
324
+ if (removeConfig) {
325
+ node.remove();
326
+ removedConfig = true;
327
+ }
328
+ }
329
+ });
330
+ if (!found) return;
331
+ if (hasPreprocessorOnlySyntax(rawSource)) {
332
+ const css = extractTailwindSourceForPostcssFallback(rawSource, {
333
+ ...options,
334
+ removeConfig
335
+ });
336
+ if (css) return {
337
+ css,
338
+ config,
339
+ configRequest,
340
+ base
341
+ };
342
+ }
343
+ return {
344
+ css: removedConfig || normalizedImports ? root.toString() : rawSource,
345
+ config,
346
+ configRequest,
347
+ base
348
+ };
349
+ } catch {
350
+ const css = extractTailwindSourceForPostcssFallback(rawSource, options);
351
+ const configRequest = extractConfigRequestFromSource(rawSource);
352
+ const config = configRequest && !isPackageJsonImportRequest(configRequest) ? node_path.default.isAbsolute(configRequest) ? configRequest : node_path.default.resolve(base, configRequest) : void 0;
353
+ return css ? {
354
+ css,
355
+ config,
356
+ configRequest,
357
+ base
358
+ } : void 0;
359
+ }
360
+ }
361
+ //#endregion
362
+ //#region src/bundlers/shared/cache.ts
363
+ async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
364
+ let cacheHit = false;
365
+ const result = await cache.process({
366
+ key: cacheKey,
367
+ hashKey,
368
+ rawSource,
369
+ hash,
370
+ resolveCache: readCache,
371
+ async onCacheHit(value) {
372
+ cacheHit = true;
373
+ await applyResult(value);
374
+ onCacheHit?.();
375
+ },
376
+ transform
377
+ });
378
+ if (!cacheHit) await applyResult(result);
379
+ }
380
+ //#endregion
381
+ //#region src/bundlers/shared/generator-css/legacy-selectors.ts
382
+ const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
383
+ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
384
+ ":host",
385
+ "page",
386
+ ".tw-root",
387
+ "wx-root-portal-content"
388
+ ]);
389
+ const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
390
+ const SELECTOR_CACHE_LIMIT = 64;
391
+ const generatedSelectorCache = /* @__PURE__ */ new Map();
392
+ function setGeneratedSelectorCache(css, selectors) {
393
+ if (generatedSelectorCache.size >= SELECTOR_CACHE_LIMIT) {
394
+ const firstKey = generatedSelectorCache.keys().next().value;
395
+ if (firstKey !== void 0) generatedSelectorCache.delete(firstKey);
396
+ }
397
+ generatedSelectorCache.set(css, selectors);
398
+ }
399
+ function normalizeCompatSelector(selector) {
400
+ return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
401
+ }
402
+ function isClassSelectorTerminator(char) {
403
+ return /[\s>+~#,.:()[\]]/.test(char);
404
+ }
405
+ function unescapeSimpleCssIdent(value) {
406
+ return value.replaceAll(/\\(.)/g, "$1");
407
+ }
408
+ function escapeCompatSelectorClasses(selector) {
409
+ let result = "";
410
+ let index = 0;
411
+ let changed = false;
412
+ while (index < selector.length) {
413
+ const char = selector[index];
414
+ if (char !== ".") {
415
+ result += char;
416
+ index += 1;
417
+ continue;
418
+ }
419
+ let end = index + 1;
420
+ let className = "";
421
+ while (end < selector.length) {
422
+ const current = selector[end];
423
+ if (current === void 0) break;
424
+ if (current === "\\" && end + 1 < selector.length) {
425
+ const escaped = selector[end + 1];
426
+ if (escaped === void 0) break;
427
+ className += current + escaped;
428
+ end += 2;
429
+ continue;
430
+ }
431
+ if (isClassSelectorTerminator(current)) break;
432
+ className += current;
433
+ end += 1;
434
+ }
435
+ if (className.includes("\\")) {
436
+ result += `.${require_precheck.replaceWxml(unescapeSimpleCssIdent(className))}`;
437
+ changed = true;
438
+ } else result += `.${className}`;
439
+ index = end;
440
+ }
441
+ return changed ? result : selector;
442
+ }
443
+ function normalizeCompatSelectors(selector) {
444
+ const normalized = normalizeCompatSelector(selector);
445
+ if (!normalized) return [];
446
+ const selectors = new Set([normalized]);
447
+ const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
448
+ if (escaped) selectors.add(escaped);
449
+ return [...selectors];
450
+ }
451
+ function normalizeCssSelector(selector) {
452
+ return selector.trim().replace(/\s+/g, "");
453
+ }
454
+ function getCompatSelectorKeys(selector) {
455
+ return normalizeCompatSelectors(selector).map(normalizeCssSelector);
456
+ }
457
+ function getRuleCompatSelectorKeys(rule) {
458
+ return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
459
+ }
460
+ function hasClassSelector(selector) {
461
+ return CLASS_SELECTOR_RE.test(selector);
462
+ }
463
+ function getNormalizedSelectorList(selector) {
464
+ return selector.split(",").map(normalizeCssSelector).filter(Boolean);
465
+ }
466
+ function isMiniProgramThemeScopeSelector(selector) {
467
+ const selectors = getNormalizedSelectorList(selector);
468
+ return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
469
+ }
470
+ function hasUtilityClassSelector(selector) {
471
+ return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
472
+ }
473
+ function isCustomPropertyOnlyRule(rule) {
474
+ let hasDeclaration = false;
475
+ let allCustomProperties = true;
476
+ rule.each((node) => {
477
+ if (node.type !== "decl") return;
478
+ hasDeclaration = true;
479
+ if (!node.prop.startsWith("--")) allCustomProperties = false;
480
+ });
481
+ return hasDeclaration && allCustomProperties;
482
+ }
483
+ function isPseudoContentInitRule(rule) {
484
+ let hasDeclaration = false;
485
+ let onlyContentVariable = true;
486
+ rule.each((node) => {
487
+ if (node.type !== "decl") return;
488
+ hasDeclaration = true;
489
+ if (node.prop !== "--tw-content") onlyContentVariable = false;
490
+ });
491
+ return hasDeclaration && onlyContentVariable;
492
+ }
493
+ function collectGeneratedSelectors(css) {
494
+ const cached = generatedSelectorCache.get(css);
495
+ if (cached) return cached;
496
+ const selectors = /* @__PURE__ */ new Set();
497
+ try {
498
+ postcss.default.parse(css).walkRules((rule) => {
499
+ if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
500
+ for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
501
+ });
502
+ } catch {
503
+ return selectors;
504
+ }
505
+ setGeneratedSelectorCache(css, selectors);
506
+ return selectors;
507
+ }
508
+ function collectGeneratedDeclarationPropsBySelector(generatedCss, selectors) {
509
+ const propsBySelector = /* @__PURE__ */ new Map();
510
+ try {
511
+ postcss.default.parse(generatedCss).walkRules((rule) => {
512
+ const matchedSelectors = getRuleCompatSelectorKeys(rule).filter((selector) => selectors.has(selector));
513
+ if (matchedSelectors.length === 0) return;
514
+ const props = /* @__PURE__ */ new Set();
515
+ rule.walkDecls((decl) => {
516
+ props.add(decl.prop);
517
+ });
518
+ for (const selector of matchedSelectors) {
519
+ const existing = propsBySelector.get(selector);
520
+ if (existing) for (const prop of props) existing.add(prop);
521
+ else propsBySelector.set(selector, new Set(props));
522
+ }
523
+ });
524
+ } catch {
525
+ return propsBySelector;
526
+ }
527
+ return propsBySelector;
528
+ }
529
+ function removeGeneratedSelectorCompatCss(css, generatedCss) {
530
+ const generatedSelectors = collectGeneratedSelectors(generatedCss);
531
+ if (generatedSelectors.size === 0) return css;
532
+ try {
533
+ const root = postcss.default.parse(css);
534
+ let removed = false;
535
+ root.walkRules((rule) => {
536
+ if (isPseudoContentInitRule(rule)) {
537
+ rule.remove();
538
+ removed = true;
539
+ return;
540
+ }
541
+ if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
542
+ if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
543
+ rule.remove();
544
+ removed = true;
545
+ }
546
+ });
547
+ root.walkAtRules((atRule) => {
548
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
549
+ });
550
+ return removed ? root.toString() : css;
551
+ } catch {
552
+ return css;
553
+ }
554
+ }
555
+ function collectDedupedPostTransformCompatCss(css, generatedCss) {
556
+ const generatedSelectors = collectGeneratedSelectors(generatedCss);
557
+ if (generatedSelectors.size === 0) return css;
558
+ const generatedDeclarationPropsBySelector = collectGeneratedDeclarationPropsBySelector(generatedCss, generatedSelectors);
559
+ const preservedNodes = [];
560
+ try {
561
+ const root = postcss.default.parse(css);
562
+ root.each((node) => {
563
+ if (node.type === "rule") {
564
+ const nodeSelectors = getRuleCompatSelectorKeys(node);
565
+ if (!nodeSelectors.some((selector) => generatedSelectors.has(selector))) {
566
+ preservedNodes.push(node.clone());
567
+ return;
568
+ }
569
+ if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
570
+ const declarationProps = /* @__PURE__ */ new Set();
571
+ node.walkDecls((decl) => {
572
+ declarationProps.add(decl.prop);
573
+ });
574
+ for (const selector of nodeSelectors) {
575
+ const generatedProps = generatedDeclarationPropsBySelector.get(selector);
576
+ if (!generatedProps) continue;
577
+ for (const prop of generatedProps) declarationProps.delete(prop);
578
+ }
579
+ const nextRule = node.clone();
580
+ nextRule.walkDecls((decl) => {
581
+ if (!declarationProps.has(decl.prop)) decl.remove();
582
+ });
583
+ if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
584
+ }
585
+ return;
586
+ }
587
+ preservedNodes.push(node.clone());
588
+ });
589
+ if (preservedNodes.length === root.nodes.length) return css;
590
+ const nextRoot = postcss.default.root();
591
+ nextRoot.append(preservedNodes);
592
+ return nextRoot.toString();
593
+ } catch {
594
+ return css;
595
+ }
596
+ }
597
+ function removeDuplicatedViteMarkers(css, baseCss) {
598
+ if (!VITE_MARKER_RE.test(baseCss)) return css;
599
+ VITE_MARKER_RE.lastIndex = 0;
600
+ return css.replace(VITE_MARKER_RE, "");
601
+ }
602
+ //#endregion
603
+ //#region src/bundlers/shared/generator-css/config-directive.ts
604
+ function quoteCssString(value) {
605
+ return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
606
+ }
607
+ function toCssPath(value) {
608
+ return value.replaceAll("\\", "/");
609
+ }
610
+ function prependConfigDirective(css, config) {
611
+ if (!config || /@config\s+/.test(css)) return css;
612
+ return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
613
+ }
614
+ function normalizeConfigDirective(css, config) {
615
+ if (!config || !/@config\s+/.test(css)) return css;
616
+ return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
617
+ }
618
+ //#endregion
619
+ //#region src/bundlers/shared/generator-css/source-files.ts
620
+ const SOURCE_STYLE_EXTENSIONS = [
621
+ ".vue",
622
+ ".uvue",
623
+ ".nvue",
624
+ ".css",
625
+ ".scss",
626
+ ".sass",
627
+ ".less",
628
+ ".styl",
629
+ ".stylus",
630
+ ".wxss",
631
+ ".acss",
632
+ ".jxss",
633
+ ".ttss",
634
+ ".qss"
635
+ ];
636
+ const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
637
+ function stripStyleExtension(file) {
638
+ return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
639
+ }
640
+ function createSourceStylePathCandidates(file, sourceOptions) {
641
+ const bases = [
642
+ sourceOptions.projectRoot,
643
+ sourceOptions.cwd,
644
+ node_process.default.cwd()
645
+ ].filter((item) => typeof item === "string" && item.length > 0);
646
+ const outputRoots = [sourceOptions.outputRoot].filter((item) => typeof item === "string" && item.length > 0);
647
+ const strippedFile = stripStyleExtension(file);
648
+ const relativeFiles = /* @__PURE__ */ new Set();
649
+ const addOutputRelativePath = (absoluteFile) => {
650
+ for (const outputRoot of outputRoots) {
651
+ const relative = node_path.default.relative(outputRoot, absoluteFile);
652
+ if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
653
+ relativeFiles.add(relative);
654
+ }
655
+ };
656
+ if (node_path.default.isAbsolute(strippedFile)) {
657
+ addOutputRelativePath(strippedFile);
658
+ for (const base of bases) {
659
+ const relative = node_path.default.relative(base, strippedFile);
660
+ if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
661
+ relativeFiles.add(relative);
662
+ }
663
+ } else relativeFiles.add(strippedFile);
664
+ const candidates = /* @__PURE__ */ new Set();
665
+ for (const relativeFile of relativeFiles) {
666
+ if (!relativeFile || node_path.default.isAbsolute(relativeFile)) continue;
667
+ for (const base of bases) for (const sourceRoot of ["", "src"]) {
668
+ const prefix = sourceRoot ? node_path.default.resolve(base, sourceRoot, relativeFile) : node_path.default.resolve(base, relativeFile);
669
+ for (const extension of SOURCE_STYLE_EXTENSIONS) candidates.add(`${prefix}${extension}`);
670
+ }
671
+ }
672
+ return [...candidates];
673
+ }
674
+ function extractStyleDirectiveSources(source) {
675
+ const styleSources = [];
676
+ SFC_STYLE_BLOCK_RE.lastIndex = 0;
677
+ let match = SFC_STYLE_BLOCK_RE.exec(source);
678
+ while (match !== null) {
679
+ const styleSource = match[1] ?? "";
680
+ if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
681
+ match = SFC_STYLE_BLOCK_RE.exec(source);
682
+ }
683
+ if (styleSources.length > 0) return styleSources;
684
+ return hasTailwindSourceDirectives(source) ? [source] : [];
685
+ }
686
+ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
687
+ for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
688
+ if (!(0, node_fs.existsSync)(sourceFile)) continue;
689
+ try {
690
+ const source = (0, node_fs.readFileSync)(sourceFile, "utf8");
691
+ for (const styleSource of extractStyleDirectiveSources(source)) {
692
+ const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
693
+ if (cssEntrySource) return {
694
+ ...cssEntrySource,
695
+ file: sourceFile
696
+ };
697
+ }
698
+ } catch {
699
+ continue;
700
+ }
701
+ }
702
+ }
703
+ //#endregion
704
+ //#region src/bundlers/shared/generator-css/source-resolver.ts
705
+ function resolvePostcssFromOption(cssHandlerOptions) {
706
+ const from = cssHandlerOptions.postcssOptions?.options?.from;
707
+ return typeof from === "string" && from.length > 0 ? from : void 0;
708
+ }
709
+ function resolvePostcssSourceFile(cssHandlerOptions) {
710
+ const from = resolvePostcssFromOption(cssHandlerOptions);
711
+ if (!from || !node_path.default.isAbsolute(from)) return;
712
+ return from.replace(/[?#].*$/, "");
713
+ }
714
+ function resolveCssHandlerSourceOptions(cssHandlerOptions) {
715
+ return cssHandlerOptions.sourceOptions;
716
+ }
717
+ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
718
+ return require_v3_engine.omitUndefined({
719
+ projectRoot: sourceOptions.projectRoot,
720
+ baseFallbacks: sourceOptions.baseFallbacks,
721
+ packageName: sourceOptions.packageName,
722
+ base: options.base,
723
+ css: options.css
724
+ });
725
+ }
726
+ function resolveCssSourceBase(file, cssHandlerOptions) {
727
+ const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
728
+ return node_path.default.dirname(node_path.default.resolve(normalized));
729
+ }
730
+ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
731
+ if (config && (0, node_fs.existsSync)(config)) return config;
732
+ if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
733
+ const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
734
+ const baseCandidates = [
735
+ sourceOptions.projectRoot,
736
+ sourceOptions.cwd,
737
+ node_process.default.cwd()
738
+ ].filter((item) => typeof item === "string" && item.length > 0);
739
+ for (const base of baseCandidates) {
740
+ const candidates = [
741
+ node_path.default.resolve(base, configRequest),
742
+ node_path.default.resolve(base, "src", configRequest),
743
+ node_path.default.resolve(base, outputDir, configRequest),
744
+ node_path.default.resolve(base, "src", outputDir, configRequest)
745
+ ];
746
+ for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
747
+ }
748
+ return sourceOptions.config;
749
+ }
750
+ function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
751
+ const from = resolvePostcssFromOption(cssHandlerOptions);
752
+ if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
753
+ return true;
754
+ }
755
+ function shouldResolveSourceSideCssEntry(rawSource) {
756
+ return rawSource.includes("@apply") || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
757
+ }
758
+ function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
759
+ return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
760
+ }
761
+ function normalizeCssSourceForCompare(css) {
762
+ return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
763
+ }
764
+ function getOutputFileStem(file) {
765
+ const normalized = file.replace(/[?#].*$/, "");
766
+ return node_path.default.basename(normalized, node_path.default.extname(normalized));
767
+ }
768
+ function getOutputFileWithoutExtension(file) {
769
+ const normalized = file.replace(/[?#].*$/, "");
770
+ const ext = node_path.default.extname(normalized);
771
+ return ext ? normalized.slice(0, -ext.length) : normalized;
772
+ }
773
+ function normalizeMatchPath(file) {
774
+ return file.split(node_path.default.sep).join("/");
775
+ }
776
+ function stripKnownBuildRootPrefix(file) {
777
+ const segments = normalizeMatchPath(file).split("/");
778
+ const knownRoots = new Set(["dist", "src"]);
779
+ for (let index = segments.length - 1; index >= 0; index--) if (knownRoots.has(segments[index])) return segments.slice(index + 1).join("/");
780
+ return segments.join("/");
781
+ }
782
+ function isMatchingTailwindV4CssSourceFile(file, cssSourceFile) {
783
+ const outputBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(file)));
784
+ const sourceBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(cssSourceFile)));
785
+ const outputRelativeBase = stripKnownBuildRootPrefix(outputBase);
786
+ const sourceRelativeBase = stripKnownBuildRootPrefix(sourceBase);
787
+ return outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || outputRelativeBase.length > 0 && outputRelativeBase === sourceRelativeBase;
788
+ }
789
+ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
790
+ const cssEntries = sourceOptions.cssEntries;
791
+ if (!cssEntries?.length) return;
792
+ const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
793
+ const outputStem = getOutputFileStem(file);
794
+ const matchingEntry = cssEntries.find((cssEntry) => {
795
+ if (!(0, node_fs.existsSync)(cssEntry)) return false;
796
+ try {
797
+ if (normalizeCssSourceForCompare((0, node_fs.readFileSync)(cssEntry, "utf8")) === normalizedRawSource) return true;
798
+ return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
799
+ } catch {
800
+ return false;
801
+ }
802
+ });
803
+ if (!matchingEntry) return;
804
+ return require_v3_engine.resolveTailwindV4Source({
805
+ ...require_v3_engine.omitUndefined(sourceOptions),
806
+ cssEntries: [matchingEntry]
807
+ });
808
+ }
809
+ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
810
+ const cssSources = sourceOptions.cssSources;
811
+ if (!cssSources?.length) return;
812
+ const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
813
+ const sourceFile = resolvePostcssSourceFile(cssHandlerOptions);
814
+ const matchingSource = cssSources.find((cssSource) => {
815
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
816
+ if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return true;
817
+ if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file)) return true;
818
+ return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
819
+ });
820
+ if (!matchingSource) return;
821
+ return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions);
822
+ }
823
+ function tryResolveTailwindV4SourceOptions(runtimeState) {
824
+ try {
825
+ return require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
826
+ } catch {
827
+ return;
828
+ }
829
+ }
830
+ function hasConfiguredTailwindV4CssSource(sourceOptions) {
831
+ return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
832
+ }
833
+ async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions) {
834
+ const source = await require_v3_engine.resolveTailwindV4Source({
835
+ ...require_v3_engine.omitUndefined(sourceOptions),
836
+ cssSources: [cssSource]
837
+ });
838
+ const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd();
839
+ return withGeneratorSourceMetadata(source, {
840
+ matchedCssSourceFile: typeof cssSource.file === "string" ? cssSource.file : void 0,
841
+ sourceBase: require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback),
842
+ sourceCss: cssSource.css
843
+ });
844
+ }
845
+ async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
846
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
847
+ const sourceBase = require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
848
+ return require_v3_engine.resolveTailwindV4EntriesFromCss(cssSource.css, sourceBase);
849
+ }
850
+ function countRuntimeCandidateHits(candidates, runtime) {
851
+ if (!runtime?.size) return 0;
852
+ let hits = 0;
853
+ for (const candidate of candidates) if (runtime.has(candidate)) hits += 1;
854
+ return hits;
855
+ }
856
+ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandlerOptions, sourceOptions, selectionOptions) {
857
+ const cssSources = sourceOptions.cssSources;
858
+ const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
859
+ if (!cssHandlerOptions.isMainChunk || !cssSources?.length || !getSourceCandidatesForEntries) return;
860
+ const matches = [];
861
+ await Promise.all(cssSources.map(async (cssSource, index) => {
862
+ const resolved = await resolveTailwindV4CssSourceEntries(cssSource, sourceOptions);
863
+ if (resolved?.entries === void 0) return;
864
+ const scopedCandidates = getSourceCandidatesForEntries(resolved?.entries);
865
+ const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
866
+ if (runtimeHits === 0) return;
867
+ matches.push({
868
+ cssSource,
869
+ index,
870
+ runtimeHits,
871
+ totalCandidates: scopedCandidates.size
872
+ });
873
+ }));
874
+ if (matches.length === 0) return;
875
+ matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
876
+ const best = matches[0];
877
+ const second = matches[1];
878
+ if (!best) return;
879
+ if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
880
+ return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions);
881
+ }
882
+ function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
883
+ return (cssSource) => require_v3_engine.resolveTailwindV4Source({
884
+ ...require_v3_engine.omitUndefined(sourceOptions),
885
+ cssSources: [cssSource]
886
+ }).then((source) => generatorOptions?.config ? {
887
+ ...source,
888
+ css: prependConfigDirective(source.css, generatorOptions.config)
889
+ } : source);
890
+ }
891
+ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
892
+ if (!resolvedEntrySource) return;
893
+ const resolvedSourceOptions = require_v3_engine.omitUndefined(sourceOptions);
894
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
895
+ const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
896
+ return withMatchedSourceSideMetadata(await require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
897
+ base: resolvedEntrySource.base,
898
+ css
899
+ })), resolvedEntrySource);
900
+ }
901
+ function withGeneratorSourceMetadata(source, metadata) {
902
+ return {
903
+ ...source,
904
+ __weappTailwindcssMeta: metadata
905
+ };
906
+ }
907
+ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
908
+ return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
909
+ matchedCssSourceFile: resolvedEntrySource.file,
910
+ sourceBase: resolvedEntrySource.base,
911
+ sourceCss: resolvedEntrySource.css
912
+ }) : source;
913
+ }
914
+ function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
915
+ if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
916
+ return `@reference "${sourceOptions.packageName ?? "tailwindcss"}";\n${css}`;
917
+ }
918
+ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
919
+ const base = resolveCssSourceBase(file, cssHandlerOptions);
920
+ const cssEntrySource = resolveCssEntrySource(rawSource, base, {
921
+ importFallback: generatorOptions?.importFallback ?? false,
922
+ removeConfig: majorVersion === 3
923
+ });
924
+ if (majorVersion === 3) {
925
+ const sourceOptions = require_v3_engine.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
926
+ const mergedSourceOptions = require_v3_engine.omitUndefined({
927
+ ...sourceOptions,
928
+ config: generatorOptions?.config ?? sourceOptions.config,
929
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions)
930
+ });
931
+ const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
932
+ base,
933
+ css: rawSource
934
+ } : void 0;
935
+ const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
936
+ const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? applyEntrySource ?? cssEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
937
+ if (!resolvedEntrySource) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
938
+ if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
939
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v3_engine.omitUndefined(mergedSourceOptions));
940
+ return require_v3_engine.resolveTailwindV3Source({
941
+ ...mergedSourceOptions,
942
+ base: resolvedEntrySource.base,
943
+ css: resolvedEntrySource.css,
944
+ ...config ? { config } : {}
945
+ });
946
+ }
947
+ const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
948
+ const resolvedSourceOptions = sourceOptions ? require_v3_engine.omitUndefined({
949
+ ...sourceOptions,
950
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions)
951
+ }) : void 0;
952
+ const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
953
+ const sourceSideEntrySource = resolvedSourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, resolvedSourceOptions, { removeConfig: false }) : void 0;
954
+ const matchedCssSource = sourceOptions ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) : void 0;
955
+ const candidateMatchedCssSource = sourceOptions ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions) : void 0;
956
+ const configuredCssSource = sourceOptions && hasConfiguredTailwindV4CssSource(sourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await require_v3_engine.resolveTailwindV4Source(sourceOptions) : void 0;
957
+ if (configuredCssSource) return generatorOptions?.config ? {
958
+ ...configuredCssSource,
959
+ css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
960
+ } : configuredCssSource;
961
+ const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
962
+ const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await require_v3_engine.resolveTailwindV4Source({
963
+ ...require_v3_engine.omitUndefined(sourceOptions),
964
+ cssEntries: [sourceOptions.cssEntries[0]]
965
+ }) : void 0;
966
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
967
+ if (preferredCssEntrySource) return generatorOptions?.config ? {
968
+ ...preferredCssEntrySource,
969
+ css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
970
+ } : preferredCssEntrySource;
971
+ const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
972
+ if (!resolvedEntrySource) {
973
+ const source = await require_v3_engine.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
974
+ return generatorOptions?.config ? {
975
+ ...source,
976
+ css: prependConfigDirective(source.css, generatorOptions.config)
977
+ } : source;
978
+ }
979
+ if (sourceSideEntrySource && resolvedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, resolvedSourceOptions, generatorOptions, file);
980
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
981
+ const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions ?? {});
982
+ return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions ?? {}, {
983
+ base: resolvedEntrySource.base,
984
+ css
985
+ }));
986
+ }
987
+ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
988
+ const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
989
+ importFallback: generatorOptions?.importFallback ?? false,
990
+ removeConfig: majorVersion === 3
991
+ });
992
+ if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) {
993
+ const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
994
+ return resolved ? [resolved] : [];
995
+ }
996
+ let sourceOptions;
997
+ try {
998
+ sourceOptions = require_v3_engine.omitUndefined({
999
+ ...require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher),
1000
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions)
1001
+ });
1002
+ } catch {
1003
+ const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1004
+ return resolved ? [resolved] : [];
1005
+ }
1006
+ const matchedCssEntrySource = cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
1007
+ const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
1008
+ const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
1009
+ const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
1010
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
1011
+ if (sourceSideCssSource) return [sourceSideCssSource];
1012
+ if (preferredCssEntrySource) return [generatorOptions?.config ? {
1013
+ ...preferredCssEntrySource,
1014
+ css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1015
+ } : preferredCssEntrySource];
1016
+ if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
1017
+ if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
1018
+ const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1019
+ return resolved ? [resolved] : [];
1020
+ }
1021
+ const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_v3_engine.resolveTailwindV4Source({
1022
+ ...require_v3_engine.omitUndefined(sourceOptions),
1023
+ cssEntries: [cssEntry]
1024
+ }).then((source) => generatorOptions?.config ? {
1025
+ ...source,
1026
+ css: prependConfigDirective(source.css, generatorOptions.config)
1027
+ } : source)));
1028
+ const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
1029
+ return [...cssEntrySources, ...cssSources];
1030
+ }
1031
+ async function resolveGeneratorSourceEntries(source, runtimeState) {
1032
+ if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
1033
+ const sourceMetadata = source.__weappTailwindcssMeta;
1034
+ const resolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
1035
+ if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
1036
+ const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
1037
+ if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && node_path.default.resolve(cssSource.file) === node_path.default.resolve(sourceMetadata.matchedCssSourceFile)) return true;
1038
+ return cssSource.css === source.css;
1039
+ });
1040
+ if (!matchingCssSource) return resolved?.entries;
1041
+ const sourceResolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(matchingCssSource.css, typeof matchingCssSource.base === "string" && matchingCssSource.base.length > 0 ? matchingCssSource.base : typeof matchingCssSource.file === "string" && matchingCssSource.file.length > 0 ? node_path.default.dirname(matchingCssSource.file) : source.base);
1042
+ if (sourceResolved?.entries.length) return sourceResolved.entries;
1043
+ for (const dependency of matchingCssSource.dependencies ?? []) {
1044
+ if (!(0, node_fs.existsSync)(dependency)) continue;
1045
+ try {
1046
+ const dependencyResolved = await require_v3_engine.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(dependency, "utf8"), node_path.default.dirname(dependency));
1047
+ if (dependencyResolved?.entries.length) return dependencyResolved.entries;
1048
+ } catch {}
1049
+ }
1050
+ return resolved?.entries;
1051
+ }
1052
+ //#endregion
1053
+ //#region src/bundlers/shared/generator-css/legacy-compat.ts
1054
+ const LEGACY_CONTAINER_COMPAT_CSS = [
1055
+ ".container {",
1056
+ " width: 100%;",
1057
+ "}",
1058
+ "@media (min-width: 40rem) {",
1059
+ " .container {",
1060
+ " max-width: 40rem;",
1061
+ " }",
1062
+ "}",
1063
+ "@media (min-width: 48rem) {",
1064
+ " .container {",
1065
+ " max-width: 48rem;",
1066
+ " }",
1067
+ "}",
1068
+ "@media (min-width: 64rem) {",
1069
+ " .container {",
1070
+ " max-width: 64rem;",
1071
+ " }",
1072
+ "}",
1073
+ "@media (min-width: 80rem) {",
1074
+ " .container {",
1075
+ " max-width: 80rem;",
1076
+ " }",
1077
+ "}",
1078
+ "@media (min-width: 96rem) {",
1079
+ " .container {",
1080
+ " max-width: 96rem;",
1081
+ " }",
1082
+ "}"
1083
+ ].join("\n");
1084
+ const LEGACY_COMPAT_CACHE_LIMIT = 128;
1085
+ const legacyCompatSourceCache = /* @__PURE__ */ new Map();
1086
+ const legacyCompatTransformCache = /* @__PURE__ */ new Map();
1087
+ function setLimitedCacheValue(cache, key, value) {
1088
+ if (cache.size >= LEGACY_COMPAT_CACHE_LIMIT) {
1089
+ const firstKey = cache.keys().next().value;
1090
+ if (firstKey !== void 0) cache.delete(firstKey);
1091
+ }
1092
+ cache.set(key, value);
1093
+ }
1094
+ function createStableJson(value) {
1095
+ if (value === void 0) return "undefined";
1096
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
1097
+ if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
1098
+ return `{${Object.keys(value).sort().map((key) => {
1099
+ const record = value;
1100
+ return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
1101
+ }).join(",")}}`;
1102
+ }
1103
+ function createLegacyCompatTransformCacheKey(source, options) {
1104
+ return `${createStableJson(options)}\0${source}`;
1105
+ }
1106
+ function countUnclosedBlocks(source) {
1107
+ let depth = 0;
1108
+ let quote;
1109
+ let inComment = false;
1110
+ let escaped = false;
1111
+ for (let index = 0; index < source.length; index += 1) {
1112
+ const char = source[index];
1113
+ const next = source[index + 1];
1114
+ if (inComment) {
1115
+ if (char === "*" && next === "/") {
1116
+ inComment = false;
1117
+ index += 1;
1118
+ }
1119
+ continue;
1120
+ }
1121
+ if (quote) {
1122
+ if (escaped) {
1123
+ escaped = false;
1124
+ continue;
1125
+ }
1126
+ if (char === "\\") {
1127
+ escaped = true;
1128
+ continue;
1129
+ }
1130
+ if (char === quote) quote = void 0;
1131
+ continue;
1132
+ }
1133
+ if (char === "/" && next === "*") {
1134
+ inComment = true;
1135
+ index += 1;
1136
+ continue;
1137
+ }
1138
+ if (char === "\"" || char === "'") {
1139
+ quote = char;
1140
+ continue;
1141
+ }
1142
+ if (char === "{") depth += 1;
1143
+ else if (char === "}" && depth > 0) depth -= 1;
1144
+ }
1145
+ return depth;
1146
+ }
1147
+ function closeTrailingUnclosedBlocks(source) {
1148
+ try {
1149
+ postcss.default.parse(source);
1150
+ return source;
1151
+ } catch (error) {
1152
+ if (error.reason !== "Unclosed block") return source;
1153
+ const unclosedBlocks = countUnclosedBlocks(source);
1154
+ return unclosedBlocks > 0 ? `${source}${"}".repeat(unclosedBlocks)}` : source;
1155
+ }
1156
+ }
1157
+ function removeTailwindApplyRules(rawSource) {
1158
+ try {
1159
+ const root = postcss.default.parse(rawSource);
1160
+ let removed = false;
1161
+ root.walkAtRules("apply", (rule) => {
1162
+ const parent = rule.parent;
1163
+ if (parent?.type === "rule") parent.remove();
1164
+ else rule.remove();
1165
+ removed = true;
1166
+ });
1167
+ root.walkAtRules((rule) => {
1168
+ if (rule.nodes && rule.nodes.length === 0) rule.remove();
1169
+ });
1170
+ return removed ? root.toString() : rawSource;
1171
+ } catch {
1172
+ return rawSource;
1173
+ }
1174
+ }
1175
+ function resolveLegacyCompatCssSource(rawSource) {
1176
+ const cached = legacyCompatSourceCache.get(rawSource);
1177
+ if (cached !== void 0) return cached;
1178
+ const resolved = closeTrailingUnclosedBlocks((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(removeTailwindApplyRules(removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(stripTailwindBanners(rawSource))))));
1179
+ setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
1180
+ return resolved;
1181
+ }
1182
+ function hasContainerConfigToken(rawSource) {
1183
+ return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
1184
+ }
1185
+ function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
1186
+ if (hasContainerConfigToken(rawSource)) return true;
1187
+ const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
1188
+ if (!cssEntrySource?.config) return false;
1189
+ try {
1190
+ return /\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"));
1191
+ } catch {
1192
+ return false;
1193
+ }
1194
+ }
1195
+ function hasConfiguredContainerCompatSource(source) {
1196
+ if (hasContainerConfigToken(source.css)) return true;
1197
+ const cssEntrySource = resolveCssEntrySource(source.css, source.base);
1198
+ if (cssEntrySource?.config) try {
1199
+ if (/\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"))) return true;
1200
+ } catch {}
1201
+ if ("config" in source && source.config) try {
1202
+ if (/\bcontainer\b/.test((0, node_fs.readFileSync)(source.config, "utf8"))) return true;
1203
+ } catch {}
1204
+ return false;
1205
+ }
1206
+ function hasConfiguredContainerCompatSources(sources) {
1207
+ return sources.some((source) => hasConfiguredContainerCompatSource(source));
1208
+ }
1209
+ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1210
+ const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
1211
+ if (compatSource.trim().length === 0) return css;
1212
+ if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
1213
+ const styleOptions = {
1214
+ ...cssHandlerOptions,
1215
+ ...generatorStyleOptions
1216
+ };
1217
+ const compatCssCacheKey = createLegacyCompatTransformCacheKey(compatSource, styleOptions);
1218
+ let compatCss = legacyCompatTransformCache.get(compatCssCacheKey);
1219
+ if (compatCss === void 0) {
1220
+ compatCss = (await styleHandler(compatSource, styleOptions)).css;
1221
+ setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
1222
+ }
1223
+ const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css), css);
1224
+ if (cleanedCompatCss.trim().length === 0) return css;
1225
+ return createCssAppend(css, cleanedCompatCss);
1226
+ }
1227
+ async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1228
+ const compatSource = resolveLegacyCompatCssSource(rawSource);
1229
+ const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
1230
+ if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
1231
+ const styleOptions = {
1232
+ ...cssHandlerOptions,
1233
+ ...generatorStyleOptions
1234
+ };
1235
+ const compatCssCacheKey = createLegacyCompatTransformCacheKey(LEGACY_CONTAINER_COMPAT_CSS, styleOptions);
1236
+ let compatCss = legacyCompatTransformCache.get(compatCssCacheKey);
1237
+ if (compatCss === void 0) {
1238
+ compatCss = (await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, styleOptions)).css;
1239
+ setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
1240
+ }
1241
+ const cleanedCompatCss = collectDedupedPostTransformCompatCss((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css);
1242
+ if (cleanedCompatCss.trim().length === 0) return css;
1243
+ return createCssAppend(css, cleanedCompatCss);
1244
+ }
1245
+ //#endregion
1246
+ //#region src/bundlers/shared/generator-css/legacy-units.ts
1247
+ const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
1248
+ const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
1249
+ function createLegacyDeclarationValueMap(css) {
1250
+ const values = /* @__PURE__ */ new Map();
1251
+ postcss.default.parse(css).walkRules((rule) => {
1252
+ if (!rule.selectors || rule.selectors.length === 0) return;
1253
+ for (const selector of rule.selectors) {
1254
+ const normalizedSelectors = normalizeCompatSelectors(selector);
1255
+ rule.walkDecls((decl) => {
1256
+ if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
1257
+ });
1258
+ }
1259
+ });
1260
+ return values;
1261
+ }
1262
+ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
1263
+ try {
1264
+ const legacyValues = createLegacyDeclarationValueMap(legacyCss);
1265
+ if (legacyValues.size === 0) return css;
1266
+ const root = postcss.default.parse(css);
1267
+ let changed = false;
1268
+ root.walkRules((rule) => {
1269
+ if (!rule.selectors || rule.selectors.length === 0) return;
1270
+ const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
1271
+ if (selectors.length === 0) return;
1272
+ rule.walkDecls((decl) => {
1273
+ if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
1274
+ for (const selector of selectors) {
1275
+ const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
1276
+ if (legacyValue && legacyValue !== decl.value) {
1277
+ decl.value = legacyValue;
1278
+ changed = true;
1279
+ return;
1280
+ }
1281
+ }
1282
+ });
1283
+ });
1284
+ return changed ? root.toString() : css;
1285
+ } catch {
1286
+ return css;
1287
+ }
1288
+ }
1289
+ //#endregion
1290
+ //#region src/bundlers/shared/generator-css.ts
1291
+ const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
1292
+ const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
1293
+ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
1294
+ if (target !== "weapp") return css;
1295
+ return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
1296
+ cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
1297
+ preservePseudoContentInit: majorVersion === 3
1298
+ });
1299
+ }
1300
+ function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
1301
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.isolateCssSource) return scopedRuntime;
1302
+ return new Set([...scopedRuntime, ...runtime]);
1303
+ }
1304
+ function shouldIsolateMatchedCssSource(source, sourceEntries) {
1305
+ return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile && sourceEntries !== void 0);
1306
+ }
1307
+ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
1308
+ const preflightStyleOptions = {
1309
+ cssPreflight: opts.cssPreflight,
1310
+ cssPreflightRange: opts.cssPreflightRange
1311
+ };
1312
+ const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(opts.uniAppX);
1313
+ return {
1314
+ cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
1315
+ cssSelectorReplacement: opts.cssSelectorReplacement,
1316
+ rem2rpx: opts.rem2rpx,
1317
+ px2rpx: opts.px2rpx,
1318
+ unitsToPx: opts.unitsToPx,
1319
+ cssRemoveProperty: opts.cssRemoveProperty,
1320
+ cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
1321
+ cssPresetEnv: opts.cssPresetEnv,
1322
+ autoprefixer: opts.autoprefixer,
1323
+ cssCalc: opts.cssCalc,
1324
+ atRules: opts.atRules,
1325
+ uniAppX: resolvedUniAppXOptions.enabled,
1326
+ uniAppXCssTarget: opts.uniAppXCssTarget,
1327
+ uniAppXUnsupported: opts.uniAppXUnsupported,
1328
+ ...cssHandlerOptions,
1329
+ ...preflightStyleOptions,
1330
+ ...generatorStyleOptions
1331
+ };
1332
+ }
1333
+ function isLocalImportRequest(request) {
1334
+ return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
1335
+ }
1336
+ function isCommentOnlyCss(source) {
1337
+ try {
1338
+ const root = postcss.default.parse(source);
1339
+ return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
1340
+ } catch {
1341
+ return false;
1342
+ }
1343
+ }
1344
+ function stripTailwindSourceMediaFragments(source) {
1345
+ return source.replace(/^\s*@media\s+source\([^)]*\)\s*\{\s*$/gm, "").replace(/^\s*\}\s*(?=@(?:source|theme|config|plugin|utility|variant|custom-variant)\b)/gm, "").replace(/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/gm, "");
1346
+ }
1347
+ function stripLeadingTailwindSourceMediaCloseFragment(source) {
1348
+ return source.replace(/^\s*\}\s*(?:\n|$)/, "");
1349
+ }
1350
+ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
1351
+ try {
1352
+ postcss.default.parse(source);
1353
+ return source;
1354
+ } catch {
1355
+ return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
1356
+ }
1357
+ }
1358
+ function createCssSourceOrderAppend(base, extra) {
1359
+ if (!base) return extra;
1360
+ if (!extra) return base;
1361
+ if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
1362
+ return `${base}\n${extra}`;
1363
+ }
1364
+ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
1365
+ const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
1366
+ if (placeholderParts) return placeholderParts;
1367
+ const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
1368
+ if (exactParts) return exactParts;
1369
+ return splitTailwindGeneratedCssByBanner(rawSource);
1370
+ }
1371
+ async function transformGeneratorUserCss(source, options) {
1372
+ if (source.trim().length === 0) return "";
1373
+ const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1374
+ if (cleanedSource.trim().length === 0) return "";
1375
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
1376
+ if (userSource.trim().length === 0) return "";
1377
+ if (isCommentOnlyCss(userSource)) return userSource;
1378
+ if (options.generatorTarget !== "weapp") return userSource;
1379
+ const { css } = await options.styleHandler(userSource, {
1380
+ ...options.generatorStyleOptions,
1381
+ ...options.cssUserHandlerOptions
1382
+ });
1383
+ return (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css);
1384
+ }
1385
+ function isPureLocalCssImportWrapper(css) {
1386
+ let hasImport = false;
1387
+ try {
1388
+ const root = postcss.default.parse(css);
1389
+ for (const node of root.nodes) {
1390
+ if (node.type === "comment") continue;
1391
+ if (node.type !== "atrule" || node.name !== "import") return false;
1392
+ const request = parseImportRequest(node.params);
1393
+ if (!request || !isLocalImportRequest(request)) return false;
1394
+ hasImport = true;
1395
+ }
1396
+ } catch {
1397
+ return false;
1398
+ }
1399
+ return hasImport;
1400
+ }
1401
+ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1402
+ let hasLocalImport = false;
1403
+ let hasTailwindDirective = false;
1404
+ try {
1405
+ const root = postcss.default.parse(css);
1406
+ for (const node of root.nodes) {
1407
+ if (node.type === "comment") continue;
1408
+ if (node.type === "atrule" && node.name === "import") {
1409
+ const request = parseImportRequest(node.params);
1410
+ if (!request || !isLocalImportRequest(request)) return;
1411
+ hasLocalImport = true;
1412
+ continue;
1413
+ }
1414
+ if (node.type === "atrule" && node.name === "source") {
1415
+ hasTailwindDirective = true;
1416
+ continue;
1417
+ }
1418
+ return;
1419
+ }
1420
+ } catch {
1421
+ return;
1422
+ }
1423
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
1424
+ }
1425
+ function prefixLocalCssImportsWithWebpackIgnore(css) {
1426
+ try {
1427
+ const root = postcss.default.parse(css);
1428
+ root.walkAtRules("import", (atRule) => {
1429
+ const request = parseImportRequest(atRule.params);
1430
+ if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
1431
+ });
1432
+ return root.toString();
1433
+ } catch {
1434
+ return css;
1435
+ }
1436
+ }
1437
+ async function generateCssByGenerator(options) {
1438
+ const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
1439
+ const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
1440
+ const majorVersion = runtimeState.twPatcher.majorVersion;
1441
+ const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1442
+ const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
1443
+ if (cleanedLocalImportWrapper !== void 0) return {
1444
+ css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
1445
+ target: generatorOptions.target,
1446
+ source: "generator",
1447
+ dependencies: []
1448
+ };
1449
+ if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
1450
+ const hasGeneratedCss = hasTailwindGeneratedCss(effectiveRawSource);
1451
+ const hasSourceDirectives = hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1452
+ const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(effectiveRawSource);
1453
+ const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1454
+ if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1455
+ try {
1456
+ await runtimeState.readyPromise;
1457
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
1458
+ getSourceCandidatesForEntries,
1459
+ runtime
1460
+ });
1461
+ const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1462
+ const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1463
+ const generatedResults = await Promise.all(sources.map(async (source) => {
1464
+ const generator = require_generator.createWeappTailwindcssGenerator(source);
1465
+ const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1466
+ const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
1467
+ const isolateCssSource = shouldIsolateMatchedCssSource(source, sourceEntries);
1468
+ const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, {
1469
+ cssHandlerOptions,
1470
+ isolateCssSource
1471
+ }) : runtime;
1472
+ const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
1473
+ return generator.generate({
1474
+ candidates: generatorRuntime,
1475
+ incrementalCache: majorVersion === 3 || majorVersion === 4,
1476
+ scanSources: majorVersion === 4 && generatorRuntime.size === 0 && !isolateCssSource,
1477
+ styleOptions: generatorStyleOptions,
1478
+ tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1479
+ target: generatorOptions.target
1480
+ });
1481
+ }));
1482
+ const firstGenerated = generatedResults[0];
1483
+ if (!firstGenerated) return;
1484
+ const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
1485
+ const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
1486
+ const generated = generatedResults.length === 1 ? firstGenerated : {
1487
+ ...firstGenerated,
1488
+ css: generatedResults.map((item) => item.css).join("\n"),
1489
+ rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
1490
+ incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
1491
+ incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
1492
+ classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
1493
+ dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
1494
+ sources: generatedResults.flatMap((item) => item.sources)
1495
+ };
1496
+ debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
1497
+ if (typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
1498
+ const incrementalCss = stripTailwindBanner(generated.incrementalCss);
1499
+ return {
1500
+ css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1501
+ target: generated.target,
1502
+ source: "generator",
1503
+ dependencies: generated.dependencies,
1504
+ incremental: true
1505
+ };
1506
+ }
1507
+ const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
1508
+ const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1509
+ if (orderedExtraCss) {
1510
+ let css = stripTailwindBanner(generated.css);
1511
+ if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1512
+ const userCssOptions = {
1513
+ generatorTarget: generated.target,
1514
+ generatorStyleOptions,
1515
+ cssUserHandlerOptions,
1516
+ styleHandler,
1517
+ importFallback: generatorOptions.importFallback
1518
+ };
1519
+ const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
1520
+ const afterUserCss = await transformGeneratorUserCss(orderedExtraCss.after, userCssOptions);
1521
+ css = createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, css), afterUserCss);
1522
+ if (generated.target === "weapp") {
1523
+ css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1524
+ css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1525
+ }
1526
+ return {
1527
+ css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1528
+ target: generated.target,
1529
+ source: "generator",
1530
+ dependencies: generated.dependencies
1531
+ };
1532
+ }
1533
+ debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
1534
+ let css = stripTailwindBanner(generated.css);
1535
+ if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1536
+ if (hasMatchedCssSourceFile || generated.target === "web") return {
1537
+ css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1538
+ target: generated.target,
1539
+ source: "generator",
1540
+ dependencies: generated.dependencies
1541
+ };
1542
+ css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1543
+ css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1544
+ return {
1545
+ css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1546
+ target: generated.target,
1547
+ source: "generator",
1548
+ dependencies: generated.dependencies
1549
+ };
1550
+ } catch (error) {
1551
+ debug("tailwind direct css generation failed: %s %O", file, error);
1552
+ throw error;
1553
+ }
1554
+ }
1555
+ async function validateCandidatesByGenerator(options) {
1556
+ const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
1557
+ const majorVersion = runtimeState.twPatcher.majorVersion;
1558
+ if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
1559
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator), { runtime: candidates });
1560
+ const classSets = await Promise.all(sources.map(async (source) => {
1561
+ const generator = require_generator.createWeappTailwindcssGenerator(source);
1562
+ if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
1563
+ return (await generator.generate({
1564
+ candidates,
1565
+ target: "tailwind"
1566
+ })).classSet;
1567
+ }));
1568
+ const classSet = new Set(classSets.flatMap((item) => [...item]));
1569
+ debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
1570
+ return classSet;
1571
+ }
1572
+ //#endregion
1573
+ //#region src/bundlers/shared/hmr-timing.ts
1574
+ function shouldEmitHmrTiming() {
1575
+ return node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
1576
+ }
1577
+ function shouldEmitHumanReadableTiming() {
1578
+ return node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1" && node_process.default.env["WEAPP_TW_HMR_TIMING_LOG"] !== "0";
1579
+ }
1580
+ function emitHmrTiming(bundler, phase, durationMs, details = {}) {
1581
+ if (!shouldEmitHmrTiming()) return;
1582
+ const serializableDetails = { ...details };
1583
+ delete serializableDetails.emit;
1584
+ const payload = {
1585
+ bundler,
1586
+ phase,
1587
+ durationMs: Math.max(0, Math.round(durationMs)),
1588
+ ...serializableDetails,
1589
+ ...typeof details.wallMs === "number" ? { wallMs: Math.max(0, Math.round(details.wallMs)) } : {}
1590
+ };
1591
+ node_process.default.stdout.write(`[weapp-tailwindcss:hmr] ${JSON.stringify(payload)}\n`);
1592
+ if (shouldEmitHumanReadableTiming()) {
1593
+ const fileSuffix = details.file ? ` file=${details.file}` : "";
1594
+ if (details.metric === "total") {
1595
+ const hooks = details.hooks ? Object.entries(details.hooks).map(([hook, summary]) => `${hook}=${Math.max(0, Math.round(summary.durationMs))}ms/${summary.count}`).join(", ") : "";
1596
+ const hookSuffix = hooks ? ` (${hooks})` : "";
1597
+ const wallSuffix = typeof payload.wallMs === "number" ? ` wall=${payload.wallMs}ms` : "";
1598
+ node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:weapp-tailwindcss 总耗时 ${payload.durationMs}ms${wallSuffix}${hookSuffix}\n`);
1599
+ return;
1600
+ }
1601
+ node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:${phase} 耗时 ${payload.durationMs}ms${fileSuffix}\n`);
1602
+ }
1603
+ }
1604
+ function createHmrTimingRecorder(bundler) {
1605
+ const session = {
1606
+ hooks: {},
1607
+ totalMs: 0
1608
+ };
1609
+ const record = (phase, durationMs, details = {}) => {
1610
+ const roundedDuration = Math.max(0, Math.round(durationMs));
1611
+ if (session.startedAt === void 0) session.startedAt = performance.now() - Math.max(0, durationMs);
1612
+ session.totalMs += Math.max(0, durationMs);
1613
+ const current = session.hooks[phase] ?? {
1614
+ count: 0,
1615
+ durationMs: 0,
1616
+ maxMs: 0
1617
+ };
1618
+ current.count += 1;
1619
+ current.durationMs += roundedDuration;
1620
+ current.maxMs = Math.max(current.maxMs, roundedDuration);
1621
+ session.hooks[phase] = current;
1622
+ if (details.emit !== false) emitHmrTiming(bundler, phase, durationMs, details);
1623
+ };
1624
+ const measure = async (phase, task, details = {}) => {
1625
+ const startedAt = performance.now();
1626
+ try {
1627
+ return await task();
1628
+ } finally {
1629
+ record(phase, performance.now() - startedAt, details);
1630
+ }
1631
+ };
1632
+ const emitTotal = (phase = "total") => {
1633
+ if (session.totalMs <= 0) return;
1634
+ const wallMs = session.startedAt === void 0 ? session.totalMs : performance.now() - session.startedAt;
1635
+ emitHmrTiming(bundler, phase, session.totalMs, {
1636
+ hooks: session.hooks,
1637
+ metric: "total",
1638
+ wallMs
1639
+ });
1640
+ session.hooks = {};
1641
+ delete session.startedAt;
1642
+ session.totalMs = 0;
1643
+ };
1644
+ return {
1645
+ emitTotal,
1646
+ measure,
1647
+ record
1648
+ };
1649
+ }
1650
+ //#endregion
1651
+ //#region src/bundlers/vite/incremental-runtime-class-set.ts
1652
+ const debug = require_v3_engine.createDebug("[vite:runtime-set] ");
1653
+ const EXTENSION_DOT_PREFIX_RE = /^\./;
1654
+ const VENDOR_CHUNK_BASENAME_RE = /^(?:vendor|vendors|chunk-vendors|common_vendor)(?:[.-]|$)/i;
1655
+ const COMMON_VENDOR_CHUNK_RE = /^(?:common|static|assets|chunks?)\/(?:vendor|vendors|chunk-vendors|common_vendor|runtime)(?:[.-]|$)/i;
1656
+ function toPosixPath(value) {
1657
+ return value.split("\\").join("/");
1658
+ }
1659
+ function isDependencyModuleId(id) {
1660
+ const normalized = toPosixPath(id);
1661
+ return normalized.includes("/node_modules/") || normalized.includes("/.pnpm/") || normalized.includes("/node_modules_");
1662
+ }
1663
+ function collectChunkModuleIds(entry) {
1664
+ if (entry.output.type !== "chunk") return [];
1665
+ return [...entry.output.moduleIds, ...Object.keys(entry.output.modules ?? {})].filter((id, index, ids) => ids.indexOf(id) === index);
1666
+ }
1667
+ function isKnownVendorChunkFile(file) {
1668
+ const normalized = toPosixPath(file).replace(/^\.\//, "");
1669
+ const basename = normalized.slice(normalized.lastIndexOf("/") + 1);
1670
+ return VENDOR_CHUNK_BASENAME_RE.test(basename) || COMMON_VENDOR_CHUNK_RE.test(normalized) || normalized.includes("/node_modules/") || normalized.includes("/node_modules_");
1671
+ }
1672
+ function isDependencyOnlyChunk(entry) {
1673
+ if (entry.output.type !== "chunk") return false;
1674
+ if (entry.output.isEntry || entry.output.isDynamicEntry || entry.output.isImplicitEntry) return false;
1675
+ const moduleIds = collectChunkModuleIds(entry);
1676
+ return moduleIds.length > 0 && moduleIds.every(isDependencyModuleId);
1677
+ }
1678
+ function isRuntimeCandidateEntry(entry) {
1679
+ if (entry.type === "html") return true;
1680
+ if (entry.type !== "js") return false;
1681
+ if (isDependencyOnlyChunk(entry)) return false;
1682
+ if (!isKnownVendorChunkFile(entry.file)) return true;
1683
+ if (entry.output.type !== "chunk") return false;
1684
+ if (entry.output.facadeModuleId && !isDependencyModuleId(entry.output.facadeModuleId)) return true;
1685
+ return collectChunkModuleIds(entry).some((id) => !isDependencyModuleId(id));
1686
+ }
1687
+ function createExtractOptions(context, source) {
1688
+ return {
1689
+ cwd: context.projectRoot,
1690
+ base: context.base,
1691
+ baseFallbacks: context.baseFallbacks,
1692
+ css: context.css,
1693
+ content: source,
1694
+ extension: "html"
1695
+ };
1696
+ }
1697
+ function createRuntimeEntries(snapshot) {
1698
+ return snapshot.entries.filter(isRuntimeCandidateEntry);
1699
+ }
1700
+ function collectChangedRuntimeFiles(snapshot) {
1701
+ return new Set([...snapshot.runtimeAffectingChangedByType.html, ...snapshot.runtimeAffectingChangedByType.js]);
1702
+ }
1703
+ function resolveEntryExtension(entry) {
1704
+ if (entry.type === "html") return "html";
1705
+ const ext = entry.file.split(/[?#]/, 1)[0]?.split(".").pop()?.replace(EXTENSION_DOT_PREFIX_RE, "") ?? "";
1706
+ if (ext.length > 0) return ext;
1707
+ return "js";
1708
+ }
1709
+ function createCandidateValidationSource(candidates) {
1710
+ return [...new Set(candidates)].sort().join("\n");
1711
+ }
1712
+ function removeCandidateSet(candidateCountByClass, candidates) {
1713
+ for (const className of candidates) {
1714
+ const count = candidateCountByClass.get(className);
1715
+ if (count == null) continue;
1716
+ if (count <= 1) {
1717
+ candidateCountByClass.delete(className);
1718
+ continue;
1719
+ }
1720
+ candidateCountByClass.set(className, count - 1);
1721
+ }
1722
+ }
1723
+ function addCandidateSet(candidateCountByClass, candidates) {
1724
+ for (const className of candidates) {
1725
+ const nextCount = (candidateCountByClass.get(className) ?? 0) + 1;
1726
+ candidateCountByClass.set(className, nextCount);
1727
+ }
1728
+ }
1729
+ function createRuntimeClassSet(baseClassSet, candidateCountByClass) {
1730
+ return new Set([...baseClassSet, ...candidateCountByClass.keys()]);
1731
+ }
1732
+ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
1733
+ const nextBaseClassSet = new Set(baseClassSet);
1734
+ for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
1735
+ return nextBaseClassSet;
1736
+ }
1737
+ function createBundleRuntimeClassSetManager(options = {}) {
1738
+ const customExtractCandidates = options.extractCandidates;
1739
+ const extractCandidates = customExtractCandidates ?? tailwindcss_patch.extractValidCandidates;
1740
+ const extractRawCandidates = options.extractRawCandidates ?? tailwindcss_patch.extractRawCandidatesWithPositions;
1741
+ let baseClassSet = /* @__PURE__ */ new Set();
1742
+ const candidateCountByClass = /* @__PURE__ */ new Map();
1743
+ const candidatesByFile = /* @__PURE__ */ new Map();
1744
+ const candidateValidityCache = /* @__PURE__ */ new Map();
1745
+ let runtimeSignature;
1746
+ let validationContext;
1747
+ let designSystemPromise;
1748
+ async function reset() {
1749
+ baseClassSet = /* @__PURE__ */ new Set();
1750
+ candidateCountByClass.clear();
1751
+ candidatesByFile.clear();
1752
+ candidateValidityCache.clear();
1753
+ runtimeSignature = void 0;
1754
+ validationContext = void 0;
1755
+ designSystemPromise = void 0;
1756
+ }
1757
+ async function resolveValidationContextCached(patcher) {
1758
+ if (!validationContext) validationContext = await require_v3_engine.resolveTailwindV4SourceFromPatcher(patcher);
1759
+ return validationContext;
1760
+ }
1761
+ async function loadDesignSystem(context) {
1762
+ if (!designSystemPromise) designSystemPromise = (0, tailwindcss_patch.loadTailwindV4DesignSystem)(context);
1763
+ return designSystemPromise;
1764
+ }
1765
+ function populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates) {
1766
+ const parsedCandidates = [...unknownCandidates].filter((candidate) => designSystem.parseCandidate(candidate).length > 0);
1767
+ const cssByCandidate = parsedCandidates.length > 0 ? designSystem.candidatesToCss(parsedCandidates) : [];
1768
+ const validCandidates = /* @__PURE__ */ new Set();
1769
+ for (let index = 0; index < parsedCandidates.length; index += 1) {
1770
+ const candidate = parsedCandidates[index];
1771
+ const css = cssByCandidate[index];
1772
+ if (candidate && typeof css === "string" && css.trim().length > 0) validCandidates.add(candidate);
1773
+ }
1774
+ for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
1775
+ }
1776
+ async function validateUnknownCandidates(patcher, unknownCandidates) {
1777
+ if (unknownCandidates.size === 0) return;
1778
+ if (patcher.majorVersion === 3 && !customExtractCandidates) {
1779
+ for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, true);
1780
+ return;
1781
+ }
1782
+ const context = await resolveValidationContextCached(patcher);
1783
+ if (!customExtractCandidates) try {
1784
+ populateCandidateValidityCacheFromDesignSystem(await loadDesignSystem(context), unknownCandidates);
1785
+ return;
1786
+ } catch (error) {
1787
+ debug("incremental design-system validation failed: %O", error);
1788
+ designSystemPromise = void 0;
1789
+ throw error;
1790
+ }
1791
+ const source = createCandidateValidationSource(unknownCandidates);
1792
+ const validCandidates = new Set(await extractCandidates(createExtractOptions(context, source)));
1793
+ for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
1794
+ }
1795
+ async function extractEntryRawCandidates(entry) {
1796
+ const matches = await extractRawCandidates(entry.source, resolveEntryExtension(entry));
1797
+ const candidates = /* @__PURE__ */ new Set();
1798
+ for (const match of matches) {
1799
+ const candidate = match?.rawCandidate;
1800
+ if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
1801
+ }
1802
+ return candidates;
1803
+ }
1804
+ async function sync(patcher, snapshot, options = {}) {
1805
+ const nextSignature = require_v3_engine.getRuntimeClassSetSignature(patcher) ?? "runtime:missing";
1806
+ const runtimeEntries = createRuntimeEntries(snapshot);
1807
+ const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
1808
+ const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
1809
+ const hadTrackedRuntimeFiles = candidatesByFile.size > 0;
1810
+ const fullRebuild = runtimeSignature !== nextSignature || candidatesByFile.size === 0;
1811
+ if (runtimeSignature !== nextSignature) {
1812
+ debug("runtime signature changed, reset incremental runtime set: %s", nextSignature);
1813
+ await reset();
1814
+ }
1815
+ runtimeSignature = nextSignature;
1816
+ const nextBaseClassSet = options.baseClassSet;
1817
+ const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
1818
+ for (const [file, previousCandidates] of candidatesByFile) {
1819
+ if (currentRuntimeFiles.has(file)) continue;
1820
+ removeCandidateSet(candidateCountByClass, previousCandidates);
1821
+ candidatesByFile.delete(file);
1822
+ }
1823
+ const changedRuntimeFiles = canUseBaseWithoutInitialFullScan ? [...collectChangedRuntimeFiles(snapshot)] : fullRebuild ? [...runtimeEntriesByFile.keys()] : [...collectChangedRuntimeFiles(snapshot)];
1824
+ if (changedRuntimeFiles.length === 0) {
1825
+ if (nextBaseClassSet) baseClassSet = canUseBaseWithoutInitialFullScan ? new Set(nextBaseClassSet) : createNonSourceBaseClassSet(nextBaseClassSet, candidateCountByClass);
1826
+ return createRuntimeClassSet(baseClassSet, candidateCountByClass);
1827
+ }
1828
+ const rawCandidatesByFile = /* @__PURE__ */ new Map();
1829
+ const unknownCandidates = /* @__PURE__ */ new Set();
1830
+ await Promise.all(changedRuntimeFiles.map(async (file) => {
1831
+ const entry = runtimeEntriesByFile.get(file);
1832
+ if (!entry) return;
1833
+ const candidates = await extractEntryRawCandidates(entry);
1834
+ rawCandidatesByFile.set(file, candidates);
1835
+ for (const candidate of candidates) if (!candidateValidityCache.has(candidate)) unknownCandidates.add(candidate);
1836
+ }));
1837
+ await validateUnknownCandidates(patcher, unknownCandidates);
1838
+ let rawCandidateCount = 0;
1839
+ for (const file of changedRuntimeFiles) {
1840
+ const nextRawCandidates = rawCandidatesByFile.get(file);
1841
+ const previousCandidates = candidatesByFile.get(file);
1842
+ if (previousCandidates) removeCandidateSet(candidateCountByClass, previousCandidates);
1843
+ if (!nextRawCandidates || nextRawCandidates.size === 0) {
1844
+ candidatesByFile.delete(file);
1845
+ continue;
1846
+ }
1847
+ rawCandidateCount += nextRawCandidates.size;
1848
+ const nextCandidates = new Set([...nextRawCandidates].filter((candidate) => candidateValidityCache.get(candidate) === true));
1849
+ if (nextCandidates.size === 0) {
1850
+ candidatesByFile.delete(file);
1851
+ continue;
1852
+ }
1853
+ addCandidateSet(candidateCountByClass, nextCandidates);
1854
+ candidatesByFile.set(file, nextCandidates);
1855
+ }
1856
+ if (nextBaseClassSet) baseClassSet = canUseBaseWithoutInitialFullScan ? new Set(nextBaseClassSet) : createNonSourceBaseClassSet(nextBaseClassSet, candidateCountByClass);
1857
+ const runtimeSet = createRuntimeClassSet(baseClassSet, candidateCountByClass);
1858
+ debug("incremental runtime set synced, changedFiles=%d rawCandidates=%d validateMisses=%d runtimeSize=%d trackedFiles=%d", changedRuntimeFiles.length, rawCandidateCount, unknownCandidates.size, runtimeSet.size, candidatesByFile.size);
1859
+ return new Set(runtimeSet);
1860
+ }
1861
+ return {
1862
+ sync,
1863
+ reset
1864
+ };
1865
+ }
1866
+ //#endregion
1867
+ Object.defineProperty(exports, "createBundleRuntimeClassSetManager", {
1868
+ enumerable: true,
1869
+ get: function() {
1870
+ return createBundleRuntimeClassSetManager;
1871
+ }
1872
+ });
1873
+ Object.defineProperty(exports, "createHmrTimingRecorder", {
1874
+ enumerable: true,
1875
+ get: function() {
1876
+ return createHmrTimingRecorder;
1877
+ }
1878
+ });
1879
+ Object.defineProperty(exports, "emitHmrTiming", {
1880
+ enumerable: true,
1881
+ get: function() {
1882
+ return emitHmrTiming;
1883
+ }
1884
+ });
1885
+ Object.defineProperty(exports, "generateCssByGenerator", {
1886
+ enumerable: true,
1887
+ get: function() {
1888
+ return generateCssByGenerator;
1889
+ }
1890
+ });
1891
+ Object.defineProperty(exports, "hasTailwindGeneratedCssMarkers", {
1892
+ enumerable: true,
1893
+ get: function() {
1894
+ return hasTailwindGeneratedCssMarkers;
1895
+ }
1896
+ });
1897
+ Object.defineProperty(exports, "hasTailwindRootDirectives", {
1898
+ enumerable: true,
1899
+ get: function() {
1900
+ return hasTailwindRootDirectives;
1901
+ }
1902
+ });
1903
+ Object.defineProperty(exports, "hasTailwindSourceDirectives", {
1904
+ enumerable: true,
1905
+ get: function() {
1906
+ return hasTailwindSourceDirectives;
1907
+ }
1908
+ });
1909
+ Object.defineProperty(exports, "normalizeTailwindSourceForGenerator", {
1910
+ enumerable: true,
1911
+ get: function() {
1912
+ return normalizeTailwindSourceForGenerator;
1913
+ }
1914
+ });
1915
+ Object.defineProperty(exports, "processCachedTask", {
1916
+ enumerable: true,
1917
+ get: function() {
1918
+ return processCachedTask;
1919
+ }
1920
+ });
1921
+ Object.defineProperty(exports, "validateCandidatesByGenerator", {
1922
+ enumerable: true,
1923
+ get: function() {
1924
+ return validateCandidatesByGenerator;
1925
+ }
1926
+ });