weapp-tailwindcss 5.0.13 → 5.1.0

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 (178) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/auto-Ba6hDrse.mjs +13 -0
  4. package/dist/auto-DtU6f3X6.js +18 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
  7. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +21 -9
  8. package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
  9. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
  11. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
  12. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
  14. package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
  15. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
  16. package/dist/bundlers/shared/run-tasks.d.ts +1 -0
  17. package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
  18. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  19. package/dist/bundlers/vite/css-memory.d.ts +10 -0
  20. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
  21. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
  23. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +0 -1
  24. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
  25. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -0
  26. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
  27. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
  28. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
  29. package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -1
  30. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
  31. package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
  32. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
  33. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
  34. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  35. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
  36. package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
  37. package/dist/bundlers/vite/source-candidates.d.ts +9 -2
  38. package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
  39. package/dist/bundlers/vite/source-scan.d.ts +2 -2
  40. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
  41. package/dist/bundlers/vite/utils.d.ts +1 -0
  42. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
  43. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
  44. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
  45. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
  46. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
  47. package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
  48. package/dist/cache/index.d.ts +1 -0
  49. package/dist/cli/mount-options.d.ts +2 -2
  50. package/dist/cli.js +124 -437
  51. package/dist/cli.mjs +120 -433
  52. package/dist/context/index.d.ts +3 -3
  53. package/dist/context/style-options.d.ts +4 -1
  54. package/dist/context/tailwindcss.d.ts +1 -1
  55. package/dist/{precheck-B0Z8yW7E.js → context-BHxLe743.js} +391 -153
  56. package/dist/{precheck-CRI90iL1.mjs → context-Mbzkek1q.mjs} +368 -137
  57. package/dist/core.js +15 -12
  58. package/dist/core.mjs +10 -7
  59. package/dist/css-macro.js +1 -1
  60. package/dist/css-macro.mjs +1 -1
  61. package/dist/{defaults-C_J_kBpw.js → defaults-CVcKbXBG.js} +4 -15
  62. package/dist/{defaults-Bqx18S1f.mjs → defaults-ZElj1zKc.mjs} +5 -10
  63. package/dist/defaults.d.ts +1 -7
  64. package/dist/defaults.js +1 -2
  65. package/dist/defaults.mjs +2 -2
  66. package/dist/generator/index.d.ts +6 -7
  67. package/dist/generator/options.d.ts +3 -3
  68. package/dist/generator/types.d.ts +9 -10
  69. package/dist/generator-9rUz4Hcb.js +170 -0
  70. package/dist/generator-Dc4qaPmT.mjs +123 -0
  71. package/dist/generator.js +10 -16
  72. package/dist/generator.mjs +3 -3
  73. package/dist/{gulp-XT8Jc7lH.js → gulp-B_sdP6dx.js} +47 -87
  74. package/dist/{gulp-DfOQERcV.mjs → gulp-uM36oIJs.mjs} +40 -80
  75. package/dist/gulp.js +1 -1
  76. package/dist/gulp.mjs +1 -1
  77. package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-BXMLsF4b.mjs} +1145 -842
  78. package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CogqkFaF.js} +1262 -881
  79. package/dist/index.js +4 -4
  80. package/dist/index.mjs +4 -4
  81. package/dist/js/fast-path/oxc.d.ts +4 -0
  82. package/dist/js/precheck.d.ts +1 -0
  83. package/dist/postcss.js +3 -4
  84. package/dist/postcss.mjs +2 -3
  85. package/dist/presets.js +9 -19
  86. package/dist/presets.mjs +8 -18
  87. package/dist/runtime-branch/create-branch.d.ts +2 -0
  88. package/dist/runtime-branch/generator-target-env.d.ts +4 -0
  89. package/dist/runtime-branch/index.d.ts +6 -0
  90. package/dist/runtime-branch/mini-program.d.ts +2 -0
  91. package/dist/runtime-branch/native-app.d.ts +2 -0
  92. package/dist/runtime-branch/platform.d.ts +6 -0
  93. package/dist/runtime-branch/tailwind-version.d.ts +2 -0
  94. package/dist/runtime-branch/types.d.ts +37 -0
  95. package/dist/runtime-branch/web.d.ts +2 -0
  96. package/dist/runtime-branch.d.ts +1 -0
  97. package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-2ybpptAK.js} +261 -19
  98. package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
  99. package/dist/tailwindcss/candidates.d.ts +7 -0
  100. package/dist/tailwindcss/index.d.ts +2 -2
  101. package/dist/tailwindcss/runtime/cache.d.ts +6 -6
  102. package/dist/tailwindcss/runtime-factory.d.ts +12 -0
  103. package/dist/tailwindcss/runtime-options.d.ts +8 -0
  104. package/dist/tailwindcss/runtime-types.d.ts +86 -0
  105. package/dist/tailwindcss/runtime.d.ts +6 -6
  106. package/dist/tailwindcss/source-scan.d.ts +1 -1
  107. package/dist/tailwindcss/targets.d.ts +2 -2
  108. package/dist/tailwindcss/v4/config.d.ts +3 -3
  109. package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
  110. package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
  111. package/dist/tailwindcss/v4/index.d.ts +1 -1
  112. package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
  113. package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
  114. package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
  115. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  116. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
  117. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
  118. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
  119. package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
  120. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  121. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
  122. package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
  123. package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
  124. package/dist/tailwindcss/version.d.ts +1 -1
  125. package/dist/tailwindcss-DHIYcqXT.js +1523 -0
  126. package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
  127. package/dist/{transform-YmrmxuF3.js → transform-CQVOgmzM.js} +17 -17
  128. package/dist/{transform-DfcEjsZF.mjs → transform-tExdt40m.mjs} +2 -2
  129. package/dist/typedoc.export.d.ts +1 -1
  130. package/dist/types/index.d.ts +16 -17
  131. package/dist/types/shared.d.ts +1 -1
  132. package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
  133. package/dist/types/user-defined-options/general.d.ts +5 -3
  134. package/dist/types/user-defined-options/important.d.ts +2 -2
  135. package/dist/uni-app-x/style-asset.d.ts +1 -0
  136. package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
  137. package/dist/v4-engine-D4ubP7N5.js +2778 -0
  138. package/dist/{vite-CXHVsHmX.js → vite-CP0ylSxZ.js} +1081 -542
  139. package/dist/{vite-DjI09vVN.mjs → vite-CPO83EhA.mjs} +916 -376
  140. package/dist/vite.js +1 -1
  141. package/dist/vite.mjs +1 -1
  142. package/dist/weapp-tw-css-import-rewrite-loader.js +5350 -4165
  143. package/dist/weapp-tw-runtime-classset-loader.js +15 -4
  144. package/dist/webpack-Bsek8VhR.js +2094 -0
  145. package/dist/webpack-BzqhJ8yK.mjs +2082 -0
  146. package/dist/webpack.js +1 -1
  147. package/dist/webpack.mjs +1 -1
  148. package/package.json +4 -5
  149. package/dist/auto-CTp6wE5a.js +0 -33
  150. package/dist/auto-Cl8_hsG6.mjs +0 -22
  151. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
  152. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
  153. package/dist/context/tailwindcss/rax.d.ts +0 -2
  154. package/dist/generator-CzpArpCL.js +0 -92
  155. package/dist/generator-ITLd7PTl.mjs +0 -67
  156. package/dist/tailwindcss/patcher-options.d.ts +0 -8
  157. package/dist/tailwindcss/patcher.d.ts +0 -12
  158. package/dist/tailwindcss/runtime-patch.d.ts +0 -5
  159. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
  160. package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
  161. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
  162. package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
  163. package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
  164. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
  165. package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
  166. package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
  167. package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
  168. package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
  169. package/dist/tailwindcss/v4/patcher.d.ts +0 -15
  170. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
  171. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
  172. package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
  173. package/dist/tailwindcss-DZEwT3C_.js +0 -613
  174. package/dist/v3-engine-2rrgylhn.js +0 -4686
  175. package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
  176. package/dist/webpack-BcPpnT90.mjs +0 -1184
  177. package/dist/webpack-CfkUkMXG.js +0 -1196
  178. /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
@@ -1,17 +1,16 @@
1
1
  const require_chunk = require("./chunk-emK7D4bc.js");
2
- const require_v3_engine = require("./v3-engine-2rrgylhn.js");
3
- const require_generator = require("./generator-CzpArpCL.js");
4
- const require_precheck = require("./precheck-B0Z8yW7E.js");
5
- const require_tailwindcss = require("./tailwindcss-DZEwT3C_.js");
2
+ const require_v4_engine = require("./v4-engine-D4ubP7N5.js");
3
+ const require_generator = require("./generator-9rUz4Hcb.js");
4
+ const require_context = require("./context-BHxLe743.js");
5
+ const require_tailwindcss = require("./tailwindcss-DHIYcqXT.js");
6
6
  let node_fs = require("node:fs");
7
7
  let node_path = require("node:path");
8
8
  node_path = require_chunk.__toESM(node_path);
9
9
  let node_process = require("node:process");
10
10
  node_process = require_chunk.__toESM(node_process);
11
- let node_module = require("node:module");
11
+ let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
12
12
  let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
13
13
  let lru_cache = require("lru-cache");
14
- let tailwindcss_patch = require("tailwindcss-patch");
15
14
  let node_fs_promises = require("node:fs/promises");
16
15
  let _weapp_core_escape = require("@weapp-core/escape");
17
16
  let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
@@ -64,7 +63,7 @@ function createCssTokenSourceMap(sourcesByToken, opts) {
64
63
  sources: [...sources].map((file) => normalizeSourcePath(file, root)).sort()
65
64
  };
66
65
  tokenSources.set(token, source);
67
- const escaped = require_precheck.replaceWxml(token, { escapeMap: opts.escapeMap });
66
+ const escaped = require_context.replaceWxml(token, { escapeMap: opts.escapeMap });
68
67
  tokenSources.set(escaped, source);
69
68
  tokenSources.set(escaped.replaceAll("\\", ""), source);
70
69
  }
@@ -134,12 +133,14 @@ function annotateCssSourceTrace(css, options) {
134
133
  }
135
134
  //#endregion
136
135
  //#region src/bundlers/shared/generator-css/generation-helpers.ts
137
- function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
136
+ function hasMiniProgramTailwindV4PreflightReset(css) {
137
+ return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
138
+ }
139
+ function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
138
140
  if (target !== "weapp") return css;
139
141
  return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
140
- cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
141
- isTailwindcssV4: majorVersion === 4,
142
- preservePseudoContentInit: majorVersion === 3,
142
+ cssPreflight: options.injectPreflight !== false && !hasMiniProgramTailwindV4PreflightReset(css) ? cssPreflight : void 0,
143
+ isTailwindcssV4: true,
143
144
  tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
144
145
  });
145
146
  }
@@ -149,11 +150,6 @@ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
149
150
  return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
150
151
  }
151
152
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
152
- if (options.majorVersion === 3 && !options.isolateCssSource) return new Set([
153
- ...scopedRuntime,
154
- ...runtime,
155
- ...options.currentCssCandidates ?? []
156
- ]);
157
153
  if (options.isolateCssSource) {
158
154
  if (options.matchedCssSourceFile) return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
159
155
  return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
@@ -161,30 +157,30 @@ function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
161
157
  if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk) return scopedRuntime;
162
158
  return new Set([...scopedRuntime, ...runtime]);
163
159
  }
164
- function shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, options) {
160
+ function shouldIsolateScopedCssSource(_majorVersion, source, sourceEntries, options) {
165
161
  if (options.target !== "weapp") return false;
166
162
  if (source.__weappTailwindcssMeta?.isolateCssSource) return true;
167
163
  if (source.__weappTailwindcssMeta?.matchedCssSourceFile && (sourceEntries?.length ?? 0) > 0) return true;
168
164
  if (sourceEntries?.length === 0) return false;
169
- return (majorVersion === 3 || majorVersion === 4) && sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
165
+ return sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
170
166
  }
171
- function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
172
- return majorVersion === 4 && !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(options.rawSource) && !require_v3_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
167
+ function shouldIsolateCurrentTailwindV4CssCandidates(_majorVersion, cssHandlerOptions, options) {
168
+ return !cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(options.rawSource) && !require_v4_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
173
169
  }
174
170
  function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
175
- if (majorVersion !== 4) return false;
171
+ if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
176
172
  if (target === "web") return true;
177
173
  if (isolateCssSource) return false;
178
174
  return generatorRuntime.size === 0;
179
175
  }
180
- function shouldAppendWebBundleCssFallback(target, options) {
181
- return target === "web" && !options.hasMatchedCssSourceFile && !options.hasSourceDirectives;
176
+ function shouldAppendWebBundleCssFallback(target, _options) {
177
+ return target === "web";
182
178
  }
183
179
  function isEmptyCssSourceOrderParts(parts) {
184
180
  return parts.before.trim().length === 0 && parts.after.trim().length === 0;
185
181
  }
186
182
  function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
187
- const resolvedStyleOptions = require_precheck.resolveStyleOptionsFromContext(opts);
183
+ const resolvedStyleOptions = require_context.resolveStyleOptionsFromContext(opts);
188
184
  const preflightStyleOptions = {
189
185
  cssPreflight: resolvedStyleOptions.cssPreflight,
190
186
  cssPreflightRange: resolvedStyleOptions.cssPreflightRange
@@ -208,15 +204,17 @@ function shouldFinalizeMarkedUserLayerComponentsCss(file) {
208
204
  return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
209
205
  }
210
206
  function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
211
- const placeholderParts = require_v3_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
207
+ const placeholderParts = require_v4_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
212
208
  if (placeholderParts) return placeholderParts;
213
- const exactParts = require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
209
+ const exactParts = require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
214
210
  if (exactParts) return exactParts;
215
- return require_v3_engine.splitTailwindGeneratedCssByBanner(rawSource);
211
+ return require_v4_engine.splitTailwindGeneratedCssByBanner(rawSource);
216
212
  }
217
213
  function shouldUseGeneratorForCurrentCss(_majorVersion, cssHandlerOptions, options) {
218
- const hasApplyDirectives = require_v3_engine.hasTailwindApplyDirective(options.rawSource);
219
- return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || cssHandlerOptions.isMainChunk;
214
+ const hasApplyDirectives = require_v4_engine.hasTailwindApplyDirective(options.rawSource);
215
+ const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
216
+ const hasSourceCssDirectives = typeof sourceCss === "string" && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss));
217
+ return options.forceGenerator === true || options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || hasSourceCssDirectives;
220
218
  }
221
219
  function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
222
220
  return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
@@ -238,10 +236,6 @@ function mergeGeneratorResults(generatedResults) {
238
236
  sources: generatedResults.flatMap((item) => item.sources)
239
237
  };
240
238
  }
241
- const SUPPORTED_GENERATOR_MAJOR_VERSIONS$1 = new Set([3, 4]);
242
- function isSupportedGeneratorMajorVersion(majorVersion) {
243
- return SUPPORTED_GENERATOR_MAJOR_VERSIONS$1.has(majorVersion ?? 0);
244
- }
245
239
  //#endregion
246
240
  //#region src/bundlers/shared/generator-css/legacy-selectors.ts
247
241
  const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
@@ -298,7 +292,7 @@ function escapeCompatSelectorClasses(selector) {
298
292
  end += 1;
299
293
  }
300
294
  if (className.includes("\\")) {
301
- result += `.${require_precheck.replaceWxml(unescapeSimpleCssIdent(className))}`;
295
+ result += `.${require_context.replaceWxml(unescapeSimpleCssIdent(className))}`;
302
296
  changed = true;
303
297
  } else result += `.${className}`;
304
298
  index = end;
@@ -391,6 +385,21 @@ function collectGeneratedDeclarationPropsBySelector(generatedCss, selectors) {
391
385
  }
392
386
  return propsBySelector;
393
387
  }
388
+ function isRuleCoveredByGeneratedProps(rule, generatedDeclarationPropsBySelector) {
389
+ const nodeSelectors = getRuleCompatSelectorKeys(rule);
390
+ if (nodeSelectors.length === 0) return false;
391
+ const props = /* @__PURE__ */ new Set();
392
+ rule.walkDecls((decl) => {
393
+ props.add(decl.prop);
394
+ });
395
+ if (props.size === 0) return false;
396
+ for (const selector of nodeSelectors) {
397
+ const generatedProps = generatedDeclarationPropsBySelector.get(selector);
398
+ if (!generatedProps) continue;
399
+ if ([...props].every((prop) => generatedProps.has(prop))) return true;
400
+ }
401
+ return false;
402
+ }
394
403
  function removeGeneratedSelectorCompatCss(css, generatedCss) {
395
404
  const generatedSelectors = collectGeneratedSelectors(generatedCss);
396
405
  if (generatedSelectors.size === 0) return css;
@@ -431,6 +440,7 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
431
440
  preservedNodes.push(node.clone());
432
441
  return;
433
442
  }
443
+ if (isRuleCoveredByGeneratedProps(node, generatedDeclarationPropsBySelector)) return;
434
444
  if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
435
445
  const declarationProps = /* @__PURE__ */ new Set();
436
446
  node.walkDecls((decl) => {
@@ -460,13 +470,23 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
460
470
  }
461
471
  }
462
472
  function removeDuplicatedViteMarkers(css, baseCss) {
463
- if (!require_v3_engine.VITE_MARKER_RE.test(baseCss)) return css;
464
- require_v3_engine.VITE_MARKER_RE.lastIndex = 0;
465
- return css.replace(require_v3_engine.VITE_MARKER_RE, "");
473
+ if (!require_v4_engine.VITE_MARKER_RE.test(baseCss)) return css;
474
+ require_v4_engine.VITE_MARKER_RE.lastIndex = 0;
475
+ return css.replace(require_v4_engine.VITE_MARKER_RE, "");
466
476
  }
467
477
  //#endregion
468
478
  //#region src/bundlers/shared/generator-css/source-files.ts
469
479
  const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
480
+ const STYLE_IMPORT_EXTENSIONS = [
481
+ ".css",
482
+ ".scss",
483
+ ".sass",
484
+ ".less",
485
+ ".styl",
486
+ ".stylus",
487
+ ".pcss",
488
+ ".postcss"
489
+ ];
470
490
  function stripStyleExtension(file) {
471
491
  const normalized = file.replace(/[?#].*$/, "");
472
492
  const ext = node_path.default.extname(normalized);
@@ -568,21 +588,77 @@ function extractStyleDirectiveSources(source) {
568
588
  let match = SFC_STYLE_BLOCK_RE.exec(source);
569
589
  while (match !== null) {
570
590
  const styleSource = match[1] ?? "";
571
- if (require_v3_engine.hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
591
+ if (require_v4_engine.hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
572
592
  match = SFC_STYLE_BLOCK_RE.exec(source);
573
593
  }
574
594
  if (styleSources.length > 0) return styleSources;
575
- return require_v3_engine.hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
595
+ return require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
596
+ }
597
+ function extractSfcStyleSources(source) {
598
+ const styleSources = [];
599
+ SFC_STYLE_BLOCK_RE.lastIndex = 0;
600
+ let match = SFC_STYLE_BLOCK_RE.exec(source);
601
+ while (match !== null) {
602
+ styleSources.push(match[1] ?? "");
603
+ match = SFC_STYLE_BLOCK_RE.exec(source);
604
+ }
605
+ return styleSources;
606
+ }
607
+ function isLocalStyleImportRequest(request) {
608
+ return typeof request === "string" && request.length > 0 && (request.startsWith(".") || request.startsWith("/"));
609
+ }
610
+ function resolveLocalStyleImportFile(request, base) {
611
+ const normalized = (node_path.default.isAbsolute(request) ? request : node_path.default.resolve(base, request)).replace(/[?#].*$/, "");
612
+ if ((0, node_fs.existsSync)(normalized)) return normalized;
613
+ if (node_path.default.extname(normalized)) return;
614
+ for (const extension of STYLE_IMPORT_EXTENSIONS) {
615
+ const candidate = `${normalized}${extension}`;
616
+ if ((0, node_fs.existsSync)(candidate)) return candidate;
617
+ }
618
+ }
619
+ function collectLocalStyleImportFiles(source, base) {
620
+ const files = [];
621
+ const sources = extractSfcStyleSources(source);
622
+ if (sources.length === 0) sources.push(source);
623
+ for (const styleSource of sources) try {
624
+ _weapp_tailwindcss_postcss.postcss.parse(styleSource).walkAtRules("import", (rule) => {
625
+ const request = require_v4_engine.parseImportRequest(rule.params);
626
+ if (!isLocalStyleImportRequest(request)) return;
627
+ const file = resolveLocalStyleImportFile(request, base);
628
+ if (file) files.push(file);
629
+ });
630
+ } catch {}
631
+ return files;
632
+ }
633
+ function extractStyleDirectiveSourcesDeep(source, sourceFile, seen) {
634
+ const ownSources = extractStyleDirectiveSources(source);
635
+ if (ownSources.length > 0) return ownSources.map((styleSource) => ({
636
+ source: styleSource,
637
+ file: sourceFile
638
+ }));
639
+ const sources = [];
640
+ const base = node_path.default.dirname(sourceFile);
641
+ for (const importedFile of collectLocalStyleImportFiles(source, base)) {
642
+ const normalizedImportedFile = node_path.default.resolve(importedFile);
643
+ if (seen.has(normalizedImportedFile)) continue;
644
+ seen.add(normalizedImportedFile);
645
+ try {
646
+ const importedSource = (0, node_fs.readFileSync)(normalizedImportedFile, "utf8");
647
+ sources.push(...extractStyleDirectiveSourcesDeep(importedSource, normalizedImportedFile, seen));
648
+ } catch {}
649
+ }
650
+ return sources;
576
651
  }
577
652
  function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
578
653
  for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) try {
579
654
  const source = sourceOptions.sourceFile && node_path.default.resolve(sourceOptions.sourceFile) === node_path.default.resolve(sourceFile) && typeof sourceOptions.sourceCss === "string" ? sourceOptions.sourceCss : (0, node_fs.existsSync)(sourceFile) ? (0, node_fs.readFileSync)(sourceFile, "utf8") : void 0;
580
655
  if (source === void 0) continue;
581
- for (const styleSource of extractStyleDirectiveSources(source)) {
582
- const cssEntrySource = require_v3_engine.resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
656
+ const directiveSources = extractStyleDirectiveSourcesDeep(source, sourceFile, new Set([node_path.default.resolve(sourceFile)]));
657
+ for (const styleSource of directiveSources) {
658
+ const cssEntrySource = require_v4_engine.resolveCssEntrySource(styleSource.source, node_path.default.dirname(styleSource.file), resolveOptions);
583
659
  if (cssEntrySource) return {
584
660
  ...cssEntrySource,
585
- file: sourceFile
661
+ file: styleSource.file
586
662
  };
587
663
  }
588
664
  } catch {
@@ -592,14 +668,40 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
592
668
  //#endregion
593
669
  //#region src/bundlers/shared/generator-css/source-resolver/apply-reference.ts
594
670
  function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
595
- if (!require_v3_engine.hasTailwindApplyDirective(css) || require_v3_engine.hasTailwindRootDirectives(css)) return css;
596
- const utilities = collectTailwindApplyUtilities(css);
671
+ return createTailwindV4SourceReferenceSource(css, sourceOptions);
672
+ }
673
+ function createTailwindV4SourceReferenceSource(css, sourceOptions) {
674
+ if (hasTailwindV4RootImport(css, sourceOptions)) return css;
675
+ const hasApplyDirective = require_v4_engine.hasTailwindApplyDirective(css);
676
+ if (!hasApplyDirective && !require_v4_engine.hasTailwindSourceDirectives(css, { importFallback: true })) return css;
677
+ const utilities = hasApplyDirective ? collectTailwindApplyUtilities(css) : [];
597
678
  return [
598
679
  `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
599
680
  utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
600
681
  css
601
682
  ].filter(Boolean).join("\n");
602
683
  }
684
+ function hasTailwindV4RootImport(css, sourceOptions) {
685
+ try {
686
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
687
+ let found = false;
688
+ root.walkAtRules((rule) => {
689
+ if (rule.name === "tailwind") {
690
+ found = true;
691
+ return false;
692
+ }
693
+ if (rule.name !== "import" && rule.name !== "use" && rule.name !== "forward") return;
694
+ const request = require_v4_engine.parseImportRequest(rule.params);
695
+ if (request === (sourceOptions.packageName ?? "tailwindcss") || request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/")) {
696
+ found = true;
697
+ return false;
698
+ }
699
+ });
700
+ return found;
701
+ } catch {
702
+ return /@(?:import|use|forward|tailwind)(?:[\s"'(;]|$)/.test(css) && (css.includes("tailwindcss") || css.includes("tailwindcss4") || css.includes("weapp-tailwindcss"));
703
+ }
704
+ }
603
705
  function collectTailwindApplyUtilities(css) {
604
706
  let root;
605
707
  try {
@@ -609,7 +711,7 @@ function collectTailwindApplyUtilities(css) {
609
711
  }
610
712
  const utilities = /* @__PURE__ */ new Set();
611
713
  root.walkAtRules("apply", (rule) => {
612
- for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
714
+ for (const utility of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(rule.params)) utilities.add(utility);
613
715
  });
614
716
  return [...utilities].sort();
615
717
  }
@@ -644,11 +746,7 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
644
746
  //#endregion
645
747
  //#region src/bundlers/shared/generator-css/source-resolver/matching.ts
646
748
  function normalizeCssSourceForCompare(css) {
647
- return require_v3_engine.stripGeneratorPlaceholderMarkers(require_v3_engine.stripTailwindBanners(css)).trim();
648
- }
649
- function getOutputFileStem(file) {
650
- const normalized = file.replace(/[?#].*$/, "");
651
- return node_path.default.basename(normalized, node_path.default.extname(normalized));
749
+ return require_v4_engine.stripGeneratorPlaceholderMarkers(require_v4_engine.stripTailwindBanners(css)).trim();
652
750
  }
653
751
  function getOutputFileWithoutExtension(file) {
654
752
  const normalized = file.replace(/[?#].*$/, "");
@@ -658,6 +756,12 @@ function getOutputFileWithoutExtension(file) {
658
756
  function normalizeMatchPath(file) {
659
757
  return file.split(node_path.default.sep).join("/");
660
758
  }
759
+ function stripBundlerContentHash(name) {
760
+ return name.replace(/[._-]?[a-f0-9]{6,32}$/i, "");
761
+ }
762
+ function getMatchBasename(file) {
763
+ return stripBundlerContentHash(node_path.default.basename(getOutputFileWithoutExtension(file.replace(/[?#].*$/, ""))));
764
+ }
661
765
  function isPathWithinRoot(file, root) {
662
766
  const relative = node_path.default.relative(root, file);
663
767
  return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
@@ -667,11 +771,7 @@ function collectCssSourceMatchBases(file, roots) {
667
771
  const bases = /* @__PURE__ */ new Set();
668
772
  const addBase = (candidate) => {
669
773
  const base = normalizeMatchPath(getOutputFileWithoutExtension(candidate));
670
- if (base.length > 0) {
671
- bases.add(base);
672
- const withoutWorkspaceSegment = base.replace(/^(?:src|dist)\//, "");
673
- if (withoutWorkspaceSegment !== base && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
674
- }
774
+ if (base.length > 0) bases.add(base);
675
775
  };
676
776
  addBase(normalizedFile);
677
777
  const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => node_path.default.resolve(root));
@@ -687,10 +787,13 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
687
787
  sourceOptions.cwd
688
788
  ]);
689
789
  const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
790
+ const outputBasename = getMatchBasename(file);
791
+ const sourceBasename = getMatchBasename(cssSourceFile);
690
792
  let bestScore = 0;
691
793
  for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
692
794
  else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
693
795
  else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
796
+ if (outputBasename && outputBasename === sourceBasename) bestScore = Math.max(bestScore, 100 + outputBasename.length);
694
797
  return bestScore;
695
798
  }
696
799
  //#endregion
@@ -734,12 +837,16 @@ function createCssEntrySources(cssEntries) {
734
837
  }
735
838
  function mergeCssSources(cssSources, cssEntrySources) {
736
839
  const merged = [];
737
- const seenFiles = /* @__PURE__ */ new Set();
840
+ const fileIndex = /* @__PURE__ */ new Map();
738
841
  const addSource = (cssSource) => {
739
842
  const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
740
843
  if (file) {
741
- if (seenFiles.has(file)) return;
742
- seenFiles.add(file);
844
+ const previousIndex = fileIndex.get(file);
845
+ if (previousIndex !== void 0) {
846
+ if (typeof merged[previousIndex]?.css !== "string" && typeof cssSource.css === "string") merged[previousIndex] = cssSource;
847
+ return;
848
+ }
849
+ fileIndex.set(file, merged.length);
743
850
  }
744
851
  merged.push(cssSource);
745
852
  };
@@ -748,7 +855,7 @@ function mergeCssSources(cssSources, cssEntrySources) {
748
855
  return merged.length > 0 ? merged : void 0;
749
856
  }
750
857
  function createSingleTailwindV4SourceOptions(sourceOptions, options) {
751
- return require_v3_engine.omitUndefined({
858
+ return require_v4_engine.omitUndefined({
752
859
  projectRoot: sourceOptions.projectRoot,
753
860
  baseFallbacks: sourceOptions.baseFallbacks,
754
861
  packageName: sourceOptions.packageName,
@@ -758,21 +865,21 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
758
865
  }
759
866
  async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
760
867
  const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
761
- if (!(0, node_fs.existsSync)(cssEntry)) return require_v3_engine.resolveTailwindV4Source({
762
- ...require_v3_engine.omitUndefined(singleEntrySourceOptions),
868
+ if (!(0, node_fs.existsSync)(cssEntry)) return require_v4_engine.resolveTailwindV4Source({
869
+ ...require_v4_engine.omitUndefined(singleEntrySourceOptions),
763
870
  cssEntries: [cssEntry]
764
871
  });
765
872
  const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
766
873
  const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
767
- const entrySource = require_v3_engine.resolveCssEntrySource(css, base, { removeConfig: false });
874
+ const entrySource = require_v4_engine.resolveCssEntrySource(css, base, { removeConfig: false });
768
875
  const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
769
876
  ...sourceOptions,
770
877
  sourceFile: sourceOptions.sourceFile ?? cssEntry
771
878
  });
772
- return withGeneratorSourceMetadata(await require_v3_engine.resolveTailwindV4Source({
773
- ...require_v3_engine.omitUndefined(singleEntrySourceOptions),
879
+ return withGeneratorSourceMetadata(await require_v4_engine.resolveTailwindV4Source({
880
+ ...require_v4_engine.omitUndefined(singleEntrySourceOptions),
774
881
  base,
775
- css: require_v3_engine.normalizeConfigDirective(css, config),
882
+ css: require_v4_engine.normalizeConfigDirective(css, config),
776
883
  cssEntries: [cssEntry]
777
884
  }), {
778
885
  matchedCssSourceFile: cssEntry,
@@ -786,19 +893,15 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
786
893
  return true;
787
894
  }
788
895
  function shouldResolveSourceSideCssEntry(rawSource) {
789
- return rawSource.includes("@apply") || require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v3_engine.hasTailwindGeneratedCss(rawSource) || require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource);
790
- }
791
- function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
792
- return Boolean(sourceSideEntrySource) && !require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true });
793
- }
794
- function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
795
- return Boolean(sourceSideEntrySource?.config) && (Boolean(cssEntrySource?.configRequest) || !cssEntrySource?.config) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
896
+ return rawSource.includes("@apply") || require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindGeneratedCss(rawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource);
796
897
  }
797
898
  function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
798
899
  const cssEntries = sourceOptions.cssEntries;
799
900
  if (!cssEntries?.length) return;
901
+ const normalizedFile = node_path.default.resolve(file.replace(/[?#].*$/, ""));
902
+ const pathMatchedEntries = cssEntries.filter((cssEntry) => node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
903
+ if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions);
800
904
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
801
- const outputStem = getOutputFileStem(file);
802
905
  const matches = cssEntries.map((cssEntry) => {
803
906
  if (!(0, node_fs.existsSync)(cssEntry)) return;
804
907
  try {
@@ -808,14 +911,6 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
808
911
  cssEntry,
809
912
  score: 1e6 + pathScore
810
913
  };
811
- if (pathScore > 0) return {
812
- cssEntry,
813
- score: pathScore
814
- };
815
- if (cssEntries.length === 1 && outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem) return {
816
- cssEntry,
817
- score: 1
818
- };
819
914
  return;
820
915
  } catch {
821
916
  return;
@@ -828,11 +923,23 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
828
923
  }
829
924
  function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
830
925
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
831
- const entrySource = require_v3_engine.resolveCssEntrySource(cssSource.css, sourceBase, { removeConfig: false });
926
+ const entrySource = require_v4_engine.resolveCssEntrySource(cssSource.css, sourceBase, { removeConfig: false });
832
927
  if (!entrySource?.config) return cssSource;
833
928
  return {
834
929
  ...cssSource,
835
- css: require_v3_engine.normalizeConfigDirective(cssSource.css, entrySource.config)
930
+ css: require_v4_engine.normalizeConfigDirective(cssSource.css, entrySource.config)
931
+ };
932
+ }
933
+ function normalizeResolvedTailwindV4SourceConfig(source, file, sourceOptions) {
934
+ if (!("css" in source) || typeof source.css !== "string" || !source.css.includes("@config")) return source;
935
+ const sourceFile = typeof file === "string" && file.length > 0 ? file : source.__weappTailwindcssMeta?.matchedCssSourceFile;
936
+ if (!sourceFile) return source;
937
+ const entrySource = require_v4_engine.resolveCssEntrySource(source.css, node_path.default.dirname(node_path.default.resolve(sourceFile)), { removeConfig: false });
938
+ const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, sourceFile, sourceOptions ?? {});
939
+ const normalizedCss = require_v4_engine.normalizeConfigDirective(source.css, config);
940
+ return normalizedCss === source.css ? source : {
941
+ ...source,
942
+ css: normalizedCss
836
943
  };
837
944
  }
838
945
  function hydrateTailwindV4CssSource(cssSource) {
@@ -853,7 +960,7 @@ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
853
960
  let changed = false;
854
961
  const cssSources = sourceOptions.cssSources.map((cssSource) => {
855
962
  const hydratedCssSource = hydrateTailwindV4CssSource(cssSource);
856
- const normalizedCssSource = normalizeTailwindV4CssSourceConfig(hydratedCssSource, require_v3_engine.resolveTailwindV4CssSourceBase(hydratedCssSource, sourceBaseFallback));
963
+ const normalizedCssSource = normalizeTailwindV4CssSourceConfig(hydratedCssSource, require_v4_engine.resolveTailwindV4CssSourceBase(hydratedCssSource, sourceBaseFallback));
857
964
  changed || (changed = normalizedCssSource !== cssSource);
858
965
  return normalizedCssSource;
859
966
  });
@@ -874,18 +981,10 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
874
981
  index,
875
982
  score: 1e6
876
983
  };
877
- if (typeof cssSource.file === "string") {
878
- const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions);
879
- if (pathScore > 0) return {
880
- cssSource,
881
- index,
882
- score: pathScore
883
- };
884
- }
885
984
  if (normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource) return {
886
985
  cssSource,
887
986
  index,
888
- score: 1
987
+ score: 1 + (typeof cssSource.file === "string" ? scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions) : 0)
889
988
  };
890
989
  }).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score || a.index - b.index);
891
990
  const bestScore = matches[0]?.score;
@@ -895,7 +994,7 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
895
994
  }
896
995
  function tryResolveTailwindV4SourceOptions(runtimeState) {
897
996
  try {
898
- return require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
997
+ return require_v4_engine.resolveTailwindV4SourceOptionsFromRuntime(runtimeState.tailwindRuntime);
899
998
  } catch {
900
999
  return;
901
1000
  }
@@ -904,12 +1003,12 @@ function hasConfiguredTailwindV4CssSource(sourceOptions) {
904
1003
  return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
905
1004
  }
906
1005
  async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
907
- const sourceBase = require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
1006
+ const sourceBase = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
908
1007
  const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
909
- return withGeneratorSourceMetadata(await require_v3_engine.resolveTailwindV4Source({
910
- ...require_v3_engine.omitUndefined(sourceOptions),
911
- cssSources: [normalizedCssSource]
912
- }), {
1008
+ return withGeneratorSourceMetadata(await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(sourceOptions, {
1009
+ base: sourceBase,
1010
+ css: normalizedCssSource.css
1011
+ })), {
913
1012
  matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
914
1013
  sourceBase,
915
1014
  sourceCss: normalizedCssSource.css
@@ -917,8 +1016,8 @@ async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, option
917
1016
  }
918
1017
  async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
919
1018
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
920
- const sourceBase = require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
921
- return require_v3_engine.resolveTailwindV4EntriesFromCss(cssSource.css, sourceBase);
1019
+ const sourceBase = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
1020
+ return require_tailwindcss.resolveTailwindV4EntriesFromCss(cssSource.css, sourceBase);
922
1021
  }
923
1022
  function countRuntimeCandidateHits(candidates, runtime) {
924
1023
  if (!runtime?.size) return 0;
@@ -955,74 +1054,34 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
955
1054
  function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
956
1055
  return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
957
1056
  ...source,
958
- css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1057
+ css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
959
1058
  } : source);
960
1059
  }
961
1060
  async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
962
1061
  if (!resolvedEntrySource) return;
963
- const resolvedSourceOptions = require_v3_engine.omitUndefined(sourceOptions);
1062
+ const resolvedSourceOptions = require_v4_engine.omitUndefined(sourceOptions);
964
1063
  const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, {
965
1064
  ...resolvedSourceOptions,
966
1065
  sourceFile: resolvedEntrySource.file
967
1066
  });
968
- const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
969
- return withMatchedSourceSideMetadata(await require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1067
+ const css = createTailwindV4SourceReferenceSource(require_v4_engine.normalizeConfigDirective(require_v4_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
1068
+ return withMatchedSourceSideMetadata(await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
970
1069
  base: resolvedEntrySource.base,
971
1070
  css
972
1071
  })), resolvedEntrySource);
973
1072
  }
974
- function resolveTailwindV3SourceEntries(source) {
975
- if (!("version" in source) || source.version !== 3) return;
976
- const entries = require_v3_engine.normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? node_path.default.dirname(source.config) : source.cwd });
977
- return entries.length > 0 ? entries : void 0;
978
- }
979
- function withTailwindV3SourceMetadata(source) {
980
- const sourceEntries = resolveTailwindV3SourceEntries(source);
981
- return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
982
- }
983
- async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1073
+ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
984
1074
  const base = resolveCssSourceBase(file, cssHandlerOptions);
985
- const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, base, {
1075
+ const cssEntrySource = require_v4_engine.resolveCssEntrySource(rawSource, base, {
986
1076
  importFallback: generatorOptions?.importFallback ?? false,
987
- removeConfig: majorVersion === 3
1077
+ removeConfig: false
988
1078
  });
989
- const applyEntrySource = require_v3_engine.hasTailwindApplyDirective(rawSource) ? {
1079
+ const applyEntrySource = require_v4_engine.hasTailwindApplyDirective(rawSource) ? {
990
1080
  base,
991
1081
  css: rawSource
992
1082
  } : void 0;
993
- if (majorVersion === 3) {
994
- const sourceOptions = require_v3_engine.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
995
- const mergedSourceOptions = require_v3_engine.omitUndefined({
996
- ...sourceOptions,
997
- config: generatorOptions?.config ?? sourceOptions.config,
998
- sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
999
- ...resolveCssHandlerSourceOptions(cssHandlerOptions),
1000
- cssEntries: selectionOptions?.cssEntries,
1001
- cssSources: createCssEntrySources(selectionOptions?.cssEntries)
1002
- });
1003
- const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
1004
- const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
1005
- const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
1006
- if (!resolvedEntrySource) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
1007
- if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: true })) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
1008
- const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v3_engine.omitUndefined(mergedSourceOptions));
1009
- const sourceWithMetadata = withTailwindV3SourceMetadata(await require_v3_engine.resolveTailwindV3Source({
1010
- ...mergedSourceOptions,
1011
- base: resolvedEntrySource.base,
1012
- css: require_v3_engine.normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
1013
- ...config ? { config } : {}
1014
- }));
1015
- const cssEntrySourceEntries = await require_v3_engine.resolveTailwindConfigEntriesFromCssCached(rawSource, resolvedEntrySource.base);
1016
- const sourceMetadata = sourceWithMetadata.__weappTailwindcssMeta;
1017
- const matchedSourceFile = resolvedEntrySource.file ?? sourceSideEntrySource?.file;
1018
- return withGeneratorSourceMetadata(sourceWithMetadata, {
1019
- ...sourceMetadata,
1020
- matchedCssSourceFile: matchedSourceFile,
1021
- sourceEntries: cssEntrySourceEntries?.entries ?? sourceMetadata?.sourceEntries
1022
- });
1023
- }
1024
1083
  const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
1025
- const resolvedSourceOptions = sourceOptions ? require_v3_engine.omitUndefined({
1084
+ const resolvedSourceOptions = sourceOptions ? require_v4_engine.omitUndefined({
1026
1085
  ...sourceOptions,
1027
1086
  sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
1028
1087
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
@@ -1030,9 +1089,9 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
1030
1089
  cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1031
1090
  }) : void 0;
1032
1091
  const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
1033
- if (applyEntrySource && !cssHandlerOptions.isMainChunk && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
1034
- const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(applyEntrySource.css, generatorOptions?.config), void 0), normalizedSourceOptions ?? {});
1035
- return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
1092
+ if (applyEntrySource && !cssHandlerOptions.isMainChunk && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
1093
+ const css = createTailwindV4ApplyReferenceSource(require_v4_engine.normalizeConfigDirective(require_v4_engine.prependConfigDirective(applyEntrySource.css, generatorOptions?.config), void 0), normalizedSourceOptions ?? {});
1094
+ return require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
1036
1095
  base: applyEntrySource.base,
1037
1096
  css
1038
1097
  }));
@@ -1043,89 +1102,93 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
1043
1102
  const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
1044
1103
  const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
1045
1104
  const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
1046
- const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await require_v3_engine.resolveTailwindV4Source(normalizedSourceOptions) : void 0;
1105
+ const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await require_v4_engine.resolveTailwindV4Source(normalizedSourceOptions) : void 0;
1047
1106
  if (configuredCssSource) return generatorOptions?.config ? {
1048
1107
  ...configuredCssSource,
1049
- css: require_v3_engine.prependConfigDirective(configuredCssSource.css, generatorOptions.config)
1108
+ css: require_v4_engine.prependConfigDirective(configuredCssSource.css, generatorOptions.config)
1050
1109
  } : configuredCssSource;
1051
1110
  const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
1052
1111
  const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
1053
1112
  if (preferredCssEntrySource) return generatorOptions?.config ? {
1054
1113
  ...preferredCssEntrySource,
1055
- css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1114
+ css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1056
1115
  } : preferredCssEntrySource;
1057
1116
  const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource;
1058
1117
  if (!resolvedEntrySource) {
1059
- const source = await require_v3_engine.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
1118
+ const source = await require_v4_engine.resolveTailwindV4SourceFromRuntime(runtimeState.tailwindRuntime);
1060
1119
  return generatorOptions?.config ? {
1061
1120
  ...source,
1062
- css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1121
+ css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1063
1122
  } : source;
1064
1123
  }
1065
1124
  if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
1066
- const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
1125
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v4_engine.omitUndefined({
1126
+ ...resolvedSourceOptions ?? {},
1127
+ sourceFile: resolvedEntrySource.file ?? resolvedSourceOptions?.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions)
1128
+ }));
1067
1129
  const sourceBase = resolvedEntrySource === cssEntrySource && config ? node_path.default.dirname(config) : resolvedEntrySource.base;
1068
- const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
1069
- return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
1130
+ const css = createTailwindV4SourceReferenceSource(require_v4_engine.normalizeConfigDirective(require_v4_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
1131
+ return require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
1070
1132
  base: sourceBase,
1071
1133
  css
1072
1134
  }));
1073
1135
  }
1074
1136
  async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1075
- const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
1137
+ const cssEntrySource = require_v4_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
1076
1138
  importFallback: generatorOptions?.importFallback ?? false,
1077
- removeConfig: majorVersion === 3
1139
+ removeConfig: false
1078
1140
  });
1079
- if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(rawSource) && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
1141
+ if (cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(rawSource) && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
1080
1142
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1081
1143
  return resolved ? [resolved] : [];
1082
1144
  }
1083
1145
  let sourceOptions;
1084
1146
  try {
1085
- const sourceOptionsFromPatcher = require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
1086
- const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromPatcher.cssEntries;
1087
- sourceOptions = require_v3_engine.omitUndefined({
1088
- ...sourceOptionsFromPatcher,
1147
+ const sourceOptionsFromRuntime = require_v4_engine.resolveTailwindV4SourceOptionsFromRuntime(runtimeState.tailwindRuntime);
1148
+ const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromRuntime.cssEntries;
1149
+ const runtimeCssSources = selectionOptions?.cssEntries ? void 0 : sourceOptionsFromRuntime.cssSources;
1150
+ sourceOptions = require_v4_engine.omitUndefined({
1151
+ ...sourceOptionsFromRuntime,
1089
1152
  sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
1090
1153
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
1091
1154
  cssEntries,
1092
- cssSources: mergeCssSources(mergeCssSources(sourceOptionsFromPatcher.cssSources, selectionOptions?.cssSources), sourceOptionsFromPatcher.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
1155
+ cssSources: mergeCssSources(mergeCssSources(runtimeCssSources, selectionOptions?.cssSources), void 0)
1093
1156
  });
1094
1157
  } catch {
1095
1158
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1096
1159
  return resolved ? [resolved] : [];
1097
1160
  }
1098
1161
  const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
1099
- if (matchedCssEntrySource) return [generatorOptions?.config ? {
1162
+ if (matchedCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
1100
1163
  ...matchedCssEntrySource,
1101
- css: require_v3_engine.prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
1102
- } : matchedCssEntrySource];
1164
+ css: require_v4_engine.prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
1165
+ } : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1103
1166
  const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
1104
1167
  if (sourceSideCssSource) return [sourceSideCssSource];
1105
1168
  const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
1106
1169
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
1107
1170
  const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
1108
- if (preferredCssEntrySource) return [generatorOptions?.config ? {
1171
+ if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
1109
1172
  ...preferredCssEntrySource,
1110
- css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1111
- } : preferredCssEntrySource];
1173
+ css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1174
+ } : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1112
1175
  if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
1113
1176
  if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
1114
1177
  ...source,
1115
- css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1178
+ css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1116
1179
  } : source)];
1117
- if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
1180
+ if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
1118
1181
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1119
1182
  return resolved ? [resolved] : [];
1120
1183
  }
1121
- if (cssHandlerOptions.isMainChunk && !cssEntrySource && !require_v3_engine.hasTailwindGeneratedCss(rawSource) && !require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource) && !require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
1184
+ if (cssHandlerOptions.isMainChunk && !cssEntrySource && !require_v4_engine.hasTailwindGeneratedCss(rawSource) && !require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) && !require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
1122
1185
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1123
1186
  return resolved ? [resolved] : [];
1124
1187
  }
1125
1188
  const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
1126
1189
  const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
1127
1190
  ...source,
1128
- css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1191
+ css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1129
1192
  } : source)));
1130
1193
  const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
1131
1194
  return [...cssEntrySources, ...cssSources];
@@ -1134,7 +1197,7 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
1134
1197
  const sourceMetadata = source.__weappTailwindcssMeta;
1135
1198
  if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
1136
1199
  if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
1137
- const resolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
1200
+ const resolved = await require_tailwindcss.resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
1138
1201
  if (resolved?.entries.length === 0 && !resolved.inlineCandidates.included.size && !resolved.inlineCandidates.excluded.size && !resolved.dependencies.length) {
1139
1202
  if (sourceMetadata?.matchedCssSourceFile) return [];
1140
1203
  return;
@@ -1145,150 +1208,645 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
1145
1208
  return cssSource.css === source.css;
1146
1209
  });
1147
1210
  if (!matchingCssSource) return resolved?.entries;
1148
- 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);
1211
+ const sourceResolved = await require_tailwindcss.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);
1149
1212
  if (sourceResolved?.entries.length) return sourceResolved.entries;
1150
1213
  for (const dependency of matchingCssSource.dependencies ?? []) {
1151
1214
  if (!(0, node_fs.existsSync)(dependency)) continue;
1152
1215
  try {
1153
- const dependencyResolved = await require_v3_engine.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(dependency, "utf8"), node_path.default.dirname(dependency));
1216
+ const dependencyResolved = await require_tailwindcss.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(dependency, "utf8"), node_path.default.dirname(dependency));
1154
1217
  if (dependencyResolved?.entries.length) return dependencyResolved.entries;
1155
1218
  } catch {}
1156
1219
  }
1157
1220
  return resolved?.entries;
1158
1221
  }
1159
1222
  //#endregion
1160
- //#region src/bundlers/shared/generator-css/legacy-compat.ts
1161
- const LEGACY_CONTAINER_COMPAT_CSS = [
1162
- ".container {",
1163
- " width: 100%;",
1164
- "}",
1165
- "@media (min-width: 40rem) {",
1166
- " .container {",
1167
- " max-width: 40rem;",
1168
- " }",
1169
- "}",
1170
- "@media (min-width: 48rem) {",
1171
- " .container {",
1172
- " max-width: 48rem;",
1173
- " }",
1174
- "}",
1175
- "@media (min-width: 64rem) {",
1176
- " .container {",
1177
- " max-width: 64rem;",
1178
- " }",
1179
- "}",
1180
- "@media (min-width: 80rem) {",
1181
- " .container {",
1182
- " max-width: 80rem;",
1183
- " }",
1184
- "}",
1185
- "@media (min-width: 96rem) {",
1186
- " .container {",
1187
- " max-width: 96rem;",
1188
- " }",
1189
- "}"
1190
- ].join("\n");
1191
- const LEGACY_COMPAT_CACHE_LIMIT = 128;
1192
- const legacyCompatSourceCache = /* @__PURE__ */ new Map();
1193
- const legacyCompatTransformCache = /* @__PURE__ */ new Map();
1194
- function setLimitedCacheValue(cache, key, value) {
1195
- if (cache.size >= LEGACY_COMPAT_CACHE_LIMIT) {
1196
- const firstKey = cache.keys().next().value;
1197
- if (firstKey !== void 0) cache.delete(firstKey);
1223
+ //#region src/bundlers/shared/generator-css/user-css.ts
1224
+ const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
1225
+ "config",
1226
+ "custom-variant",
1227
+ "plugin",
1228
+ "source",
1229
+ "theme",
1230
+ "utility",
1231
+ "variant"
1232
+ ]);
1233
+ function removeBalancedAtRuleBlock(source, atRuleStart) {
1234
+ const blockStart = source.indexOf("{", atRuleStart);
1235
+ if (blockStart === -1) {
1236
+ const semicolon = source.indexOf(";", atRuleStart);
1237
+ return semicolon === -1 ? source.slice(0, atRuleStart) : `${source.slice(0, atRuleStart)}${source.slice(semicolon + 1)}`;
1198
1238
  }
1199
- cache.set(key, value);
1239
+ let depth = 0;
1240
+ for (let index = blockStart; index < source.length; index++) {
1241
+ const char = source[index];
1242
+ if (char === "{") {
1243
+ depth++;
1244
+ continue;
1245
+ }
1246
+ if (char !== "}") continue;
1247
+ depth--;
1248
+ if (depth === 0) return `${source.slice(0, atRuleStart)}${source.slice(index + 1)}`;
1249
+ }
1250
+ return source.slice(0, atRuleStart);
1200
1251
  }
1201
- function createStableJson(value) {
1202
- if (value === void 0) return "undefined";
1203
- if (value === null || typeof value !== "object") return JSON.stringify(value);
1204
- if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
1205
- return `{${Object.keys(value).sort().map((key) => {
1206
- const record = value;
1207
- return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
1208
- }).join(",")}}`;
1252
+ function removeTailwindV4GeneratorAtRulesFallback(source) {
1253
+ let next = source;
1254
+ let changed = false;
1255
+ const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
1256
+ for (;;) {
1257
+ sourceMediaRE.lastIndex = 0;
1258
+ const match = sourceMediaRE.exec(next);
1259
+ if (!match) break;
1260
+ next = removeBalancedAtRuleBlock(next, match.index);
1261
+ changed = true;
1262
+ }
1263
+ const atRuleRE = /@(?:config|custom-variant|plugin|source|theme|utility|variant)\b/g;
1264
+ for (;;) {
1265
+ atRuleRE.lastIndex = 0;
1266
+ const match = atRuleRE.exec(next);
1267
+ if (!match) break;
1268
+ next = removeBalancedAtRuleBlock(next, match.index);
1269
+ changed = true;
1270
+ }
1271
+ return changed ? next : source;
1272
+ }
1273
+ function isTailwindGeneratedPreflightComment(text) {
1274
+ return text.includes("cssremedy") || text.includes("Use the user's configured") || text.includes("tailwindlabs/tailwindcss") || text.includes("Prevent padding and border from affecting element width") || text.includes("Remove default margins and padding") || text.includes("Deprecated") || text.includes("Reset all borders") || text.includes("Add the correct text decoration") || text.includes("Make elements with the HTML hidden attribute stay hidden") || text.includes("Inherit font styles in all browsers") || text.includes("Add the correct height in Firefox") || text.includes("Remove the default font size and weight for headings") || text.includes("Reset links to optimize for opt-in styling") || text.includes("Add the correct font weight in Edge and Safari") || text.includes("Use the user's configured `mono` font-family") || text.includes("Add the correct font size in all browsers") || text.includes("Prevent `sub` and `sup` elements from affecting the line height") || text.includes("Remove text indentation from table contents") || text.includes("Use the modern Firefox focus style") || text.includes("Add the correct vertical alignment") || text.includes("Add the correct display") || text.includes("Make lists unstyled by default") || text.includes("Make replaced elements `display: block` by default") || text.includes("Constrain images and videos to the parent width") || text.includes("Restore default font weight") || text.includes("Restore indentation") || text.includes("Restore space after button") || text.includes("Prevent resizing textareas horizontally") || text.includes("Remove the inner padding in Chrome and Safari") || text.includes("Ensure date/time inputs have the same height") || text.includes("Prevent height from changing on date/time inputs") || text.includes("Remove excess padding from pseudo-elements") || text.includes("Center dropdown marker shown on inputs") || text.includes("Remove the additional `:invalid` styles") || text.includes("Correct the inability to style the border radius") || text.includes("Correct the cursor style of increment and decrement buttons");
1275
+ }
1276
+ function isTailwindGeneratedThemeRule(selector, node) {
1277
+ if (!/(?:^|,)\s*(?::host|page|\.tw-root|wx-root-portal-content)\b/.test(selector)) return false;
1278
+ return node.nodes?.some((child) => child.type === "decl" && /^--(?:color|spacing|text|font|default|radius|tw-)/.test(child.prop)) ?? false;
1279
+ }
1280
+ function isTailwindGeneratedPreflightRule(selector, node) {
1281
+ if (selector === "view,text,::after,::before" || selector === "view, text, ::after, ::before" || selector === "*" || selector === "::after" || selector === "::before" || selector === "::backdrop" || selector === ":host" || selector === "[hidden]:not([hidden=\"until-found\"])" || selector === "[hidden]:not([hidden='until-found'])" || selector === "button,input[type=\"button\"],input[type=\"reset\"],input[type=\"submit\"]" || selector === "button, input[type=\"button\"], input[type=\"reset\"], input[type=\"submit\"]" || selector === "button,input[type='button'],input[type='reset'],input[type='submit']" || selector === "button, input[type='button'], input[type='reset'], input[type='submit']") return true;
1282
+ if (selector === "abbr[title]") return node.nodes?.some((child) => child.type === "decl" && child.prop === "text-decoration") ?? false;
1283
+ if (selector === ":host") return node.nodes?.some((child) => child.type === "decl" && child.value?.includes("--theme(")) ?? false;
1284
+ return false;
1209
1285
  }
1210
- function createLegacyCompatTransformCacheKey(source, options) {
1211
- return `${createStableJson(options)}\0${source}`;
1286
+ function removeTailwindV4GeneratedUserCssArtifacts(source) {
1287
+ try {
1288
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1289
+ let changed = false;
1290
+ root.walkComments((comment) => {
1291
+ if (!isTailwindGeneratedPreflightComment(comment.text)) return;
1292
+ comment.remove();
1293
+ changed = true;
1294
+ });
1295
+ root.walkRules((rule) => {
1296
+ const selector = rule.selector.replace(/\s+/g, " ").trim();
1297
+ if (isTailwindGeneratedThemeRule(selector, rule) || isTailwindGeneratedPreflightRule(selector, rule)) {
1298
+ rule.remove();
1299
+ changed = true;
1300
+ }
1301
+ });
1302
+ root.walkAtRules((rule) => {
1303
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) {
1304
+ rule.remove();
1305
+ changed = true;
1306
+ }
1307
+ });
1308
+ return changed ? root.toString() : source;
1309
+ } catch {
1310
+ return source;
1311
+ }
1212
1312
  }
1213
- function countUnclosedBlocks(source) {
1214
- let depth = 0;
1215
- let quote;
1216
- let inComment = false;
1217
- let escaped = false;
1218
- for (let index = 0; index < source.length; index += 1) {
1219
- const char = source[index];
1220
- const next = source[index + 1];
1221
- if (inComment) {
1222
- if (char === "*" && next === "/") {
1223
- inComment = false;
1224
- index += 1;
1313
+ function removeTailwindSourceMediaBlocks(source) {
1314
+ let next = source;
1315
+ let changed = false;
1316
+ const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
1317
+ for (;;) {
1318
+ sourceMediaRE.lastIndex = 0;
1319
+ const match = sourceMediaRE.exec(next);
1320
+ if (!match) break;
1321
+ const blockStart = next.indexOf("{", match.index);
1322
+ if (blockStart === -1) break;
1323
+ let depth = 0;
1324
+ let blockEnd = -1;
1325
+ for (let index = blockStart; index < next.length; index++) {
1326
+ const char = next[index];
1327
+ if (char === "{") {
1328
+ depth++;
1329
+ continue;
1330
+ }
1331
+ if (char !== "}") continue;
1332
+ depth--;
1333
+ if (depth === 0) {
1334
+ blockEnd = index;
1335
+ break;
1225
1336
  }
1337
+ }
1338
+ if (blockEnd === -1) break;
1339
+ next = `${next.slice(0, match.index)}${next.slice(blockEnd + 1)}`;
1340
+ changed = true;
1341
+ }
1342
+ for (;;) {
1343
+ const atRuleStart = findTailwindSourceWrapperBlockStart(next);
1344
+ if (atRuleStart === -1) break;
1345
+ next = removeBalancedAtRuleBlock(next, atRuleStart);
1346
+ changed = true;
1347
+ }
1348
+ return changed ? next : source;
1349
+ }
1350
+ function terminateTailwindSourceAtRulesBeforeNextDirective(source) {
1351
+ if (!source.includes("@source")) return source;
1352
+ let next = "";
1353
+ let searchIndex = 0;
1354
+ for (;;) {
1355
+ const atRuleStart = source.indexOf("@source", searchIndex);
1356
+ if (atRuleStart === -1) {
1357
+ next += source.slice(searchIndex);
1358
+ break;
1359
+ }
1360
+ const nextChar = source[atRuleStart + 7];
1361
+ if (nextChar && /[\w-]/.test(nextChar)) {
1362
+ next += source.slice(searchIndex, atRuleStart + 7);
1363
+ searchIndex = atRuleStart + 7;
1226
1364
  continue;
1227
1365
  }
1228
- if (quote) {
1229
- if (escaped) {
1230
- escaped = false;
1366
+ next += source.slice(searchIndex, atRuleStart);
1367
+ let quote;
1368
+ let parenDepth = 0;
1369
+ let terminated = false;
1370
+ let index = atRuleStart + 7;
1371
+ for (; index < source.length; index++) {
1372
+ const char = source[index];
1373
+ if (quote) {
1374
+ if (char === "\\") {
1375
+ index++;
1376
+ continue;
1377
+ }
1378
+ if (char === quote) quote = void 0;
1231
1379
  continue;
1232
1380
  }
1233
- if (char === "\\") {
1234
- escaped = true;
1381
+ if (char === "\"" || char === "'") {
1382
+ quote = char;
1235
1383
  continue;
1236
1384
  }
1237
- if (char === quote) quote = void 0;
1238
- continue;
1385
+ if (char === "(") {
1386
+ parenDepth++;
1387
+ continue;
1388
+ }
1389
+ if (char === ")" && parenDepth > 0) {
1390
+ parenDepth--;
1391
+ continue;
1392
+ }
1393
+ if (parenDepth > 0) continue;
1394
+ if (char === ";" || char === "{") {
1395
+ terminated = true;
1396
+ index++;
1397
+ break;
1398
+ }
1399
+ if (char === "@" && /^(?:config|custom-variant|plugin|source|theme|utility|variant)\b/.test(source.slice(index + 1))) break;
1239
1400
  }
1240
- if (char === "/" && next === "*") {
1241
- inComment = true;
1242
- index += 1;
1401
+ const segment = source.slice(atRuleStart, index);
1402
+ const trimmedSegment = segment.trimEnd();
1403
+ next += terminated || trimmedSegment.endsWith(";") || trimmedSegment.endsWith("{") ? segment : `${trimmedSegment};${segment.slice(trimmedSegment.length)}`;
1404
+ searchIndex = index;
1405
+ }
1406
+ return next;
1407
+ }
1408
+ function findTailwindSourceWrapperBlockStart(source) {
1409
+ let searchIndex = 0;
1410
+ for (;;) {
1411
+ const atRuleStart = source.indexOf("@source", searchIndex);
1412
+ if (atRuleStart === -1) return -1;
1413
+ const nextChar = source[atRuleStart + 7];
1414
+ if (nextChar && /[\w-]/.test(nextChar)) {
1415
+ searchIndex = atRuleStart + 7;
1243
1416
  continue;
1244
1417
  }
1245
- if (char === "\"" || char === "'") {
1246
- quote = char;
1247
- continue;
1418
+ let quote;
1419
+ let parenDepth = 0;
1420
+ for (let index = atRuleStart + 7; index < source.length; index++) {
1421
+ const char = source[index];
1422
+ if (quote) {
1423
+ if (char === "\\") {
1424
+ index++;
1425
+ continue;
1426
+ }
1427
+ if (char === quote) quote = void 0;
1428
+ continue;
1429
+ }
1430
+ if (char === "\"" || char === "'") {
1431
+ quote = char;
1432
+ continue;
1433
+ }
1434
+ if (char === "(") {
1435
+ parenDepth++;
1436
+ continue;
1437
+ }
1438
+ if (char === ")" && parenDepth > 0) {
1439
+ parenDepth--;
1440
+ continue;
1441
+ }
1442
+ if (parenDepth > 0) continue;
1443
+ if (char === ";") {
1444
+ searchIndex = index + 1;
1445
+ break;
1446
+ }
1447
+ if (char === "{") return atRuleStart;
1248
1448
  }
1249
- if (char === "{") depth += 1;
1250
- else if (char === "}" && depth > 0) depth -= 1;
1449
+ if (searchIndex <= atRuleStart) return -1;
1251
1450
  }
1252
- return depth;
1253
1451
  }
1254
- function closeTrailingUnclosedBlocks(source) {
1452
+ function removeTailwindApplyAtRules(source) {
1453
+ if (!source.includes("@apply")) return source;
1255
1454
  try {
1256
- _weapp_tailwindcss_postcss.postcss.parse(source);
1455
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1456
+ let changed = false;
1457
+ root.walkAtRules("apply", (rule) => {
1458
+ rule.remove();
1459
+ changed = true;
1460
+ });
1461
+ root.walk((node) => {
1462
+ if ("nodes" in node && node.nodes?.length === 0) node.remove();
1463
+ });
1464
+ return changed ? root.toString() : source;
1465
+ } catch {
1257
1466
  return source;
1258
- } catch (error) {
1259
- if (error.reason !== "Unclosed block") return source;
1260
- const unclosedBlocks = countUnclosedBlocks(source);
1261
- return unclosedBlocks > 0 ? `${source}${"}".repeat(unclosedBlocks)}` : source;
1262
1467
  }
1263
1468
  }
1264
- function removeTailwindApplyRules(rawSource) {
1469
+ function removeTailwindV4GeneratorAtRules(source) {
1265
1470
  try {
1266
- const root = _weapp_tailwindcss_postcss.postcss.parse(rawSource);
1267
- let removed = false;
1268
- root.walkAtRules("apply", (rule) => {
1269
- const parent = rule.parent;
1270
- if (parent?.type === "rule") parent.remove();
1271
- else rule.remove();
1272
- removed = true;
1273
- });
1471
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1472
+ let changed = false;
1274
1473
  root.walkAtRules((rule) => {
1275
- if (rule.nodes && rule.nodes.length === 0) rule.remove();
1474
+ if (rule.name === "media" && /^source\(/.test(rule.params.trim())) {
1475
+ rule.remove();
1476
+ changed = true;
1477
+ return;
1478
+ }
1479
+ if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
1480
+ rule.remove();
1481
+ changed = true;
1276
1482
  });
1277
- return removed ? root.toString() : rawSource;
1483
+ return changed ? root.toString() : source;
1278
1484
  } catch {
1279
- return rawSource;
1485
+ return removeTailwindV4GeneratorAtRulesFallback(source);
1280
1486
  }
1281
1487
  }
1282
- function resolveLegacyCompatCssSource(rawSource) {
1283
- const cached = legacyCompatSourceCache.get(rawSource);
1284
- if (cached !== void 0) return cached;
1285
- const resolved = closeTrailingUnclosedBlocks((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(removeTailwindApplyRules(require_v3_engine.removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(require_v3_engine.stripTailwindBanners(rawSource))))));
1286
- setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
1287
- return resolved;
1488
+ function isCommentOnlyCss(source) {
1489
+ try {
1490
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1491
+ return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
1492
+ } catch {
1493
+ return false;
1494
+ }
1288
1495
  }
1289
- function removeMiniProgramContainerCompatCss(css) {
1496
+ function removeMiniProgramHoverSelectors(source, enabled = true) {
1497
+ if (!enabled || !source.includes(":hover")) return source;
1290
1498
  try {
1291
- const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1499
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1500
+ let changed = false;
1501
+ root.walkRules((rule) => {
1502
+ const selectors = rule.selectors ?? [rule.selector];
1503
+ const keptSelectors = selectors.filter((selector) => !selector.includes(":hover"));
1504
+ if (keptSelectors.length === selectors.length) return;
1505
+ changed = true;
1506
+ if (keptSelectors.length === 0) {
1507
+ rule.remove();
1508
+ return;
1509
+ }
1510
+ rule.selectors = keptSelectors;
1511
+ });
1512
+ root.walk((node) => {
1513
+ if ("nodes" in node && node.nodes?.length === 0) {
1514
+ node.remove();
1515
+ changed = true;
1516
+ }
1517
+ });
1518
+ return changed ? root.toString() : source;
1519
+ } catch {
1520
+ return source;
1521
+ }
1522
+ }
1523
+ function removeProcessedMiniProgramUnsupportedCss(source, options) {
1524
+ return removeMiniProgramHoverSelectors((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(source), options.cssRemoveHoverPseudoClass);
1525
+ }
1526
+ function unwrapMiniProgramCascadeLayers(source) {
1527
+ if (!source.includes("@layer")) return source;
1528
+ try {
1529
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1530
+ (0, _weapp_tailwindcss_postcss.removeUnsupportedCascadeLayers)(root);
1531
+ return root.toString();
1532
+ } catch {
1533
+ return source;
1534
+ }
1535
+ }
1536
+ function stripTailwindSourceMediaFragments(source) {
1537
+ let removedSourceMediaStart = false;
1538
+ return terminateTailwindSourceAtRulesBeforeNextDirective(removeTailwindSourceMediaBlocks(source)).split(/\r?\n/).filter((line) => {
1539
+ if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
1540
+ removedSourceMediaStart = true;
1541
+ return false;
1542
+ }
1543
+ if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
1544
+ if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
1545
+ removedSourceMediaStart = false;
1546
+ return false;
1547
+ }
1548
+ return true;
1549
+ }).join("\n");
1550
+ }
1551
+ function stripLeadingTailwindSourceMediaCloseFragment(source) {
1552
+ return source.replace(/^\s*\}\s*(?:\n|$)/, "");
1553
+ }
1554
+ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
1555
+ try {
1556
+ _weapp_tailwindcss_postcss.postcss.parse(source);
1557
+ return source;
1558
+ } catch {
1559
+ return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
1560
+ }
1561
+ }
1562
+ function splitUserCssLayerBlocks(source) {
1563
+ if (!source.includes("@layer")) return {
1564
+ layer: "",
1565
+ rest: source
1566
+ };
1567
+ try {
1568
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1569
+ const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
1570
+ const restRoot = _weapp_tailwindcss_postcss.postcss.root();
1571
+ for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
1572
+ return {
1573
+ layer: layerRoot.toString(),
1574
+ rest: restRoot.toString()
1575
+ };
1576
+ } catch {
1577
+ return {
1578
+ layer: source,
1579
+ rest: ""
1580
+ };
1581
+ }
1582
+ }
1583
+ function hasUserCssLayerBlocks(source) {
1584
+ if (!source.includes("@layer")) return false;
1585
+ try {
1586
+ let hasLayerBlock = false;
1587
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("layer", (node) => {
1588
+ if (node.nodes?.length) hasLayerBlock = true;
1589
+ });
1590
+ return hasLayerBlock;
1591
+ } catch {
1592
+ return true;
1593
+ }
1594
+ }
1595
+ function collectUserLayerSelectors(source) {
1596
+ const selectors = /* @__PURE__ */ new Set();
1597
+ try {
1598
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1599
+ for (const selector of rule.selectors ?? [rule.selector]) {
1600
+ const normalized = selector.trim();
1601
+ if (normalized) selectors.add(normalized);
1602
+ }
1603
+ });
1604
+ } catch {}
1605
+ return selectors;
1606
+ }
1607
+ function matchesUserLayerSelector(selector, userLayerSelector) {
1608
+ if (selector === userLayerSelector) return true;
1609
+ if (!selector.startsWith(userLayerSelector)) return false;
1610
+ const next = selector[userLayerSelector.length];
1611
+ return next === ":" || next === "[";
1612
+ }
1613
+ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
1614
+ const selectors = collectUserLayerSelectors(userLayerSource);
1615
+ if (selectors.size === 0) return {
1616
+ layer: "",
1617
+ rest: css
1618
+ };
1619
+ try {
1620
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1621
+ const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
1622
+ const selectorList = [...selectors];
1623
+ root.walkRules((rule) => {
1624
+ if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
1625
+ layerRoot.append(rule.clone());
1626
+ rule.remove();
1627
+ }
1628
+ });
1629
+ return {
1630
+ layer: layerRoot.toString(),
1631
+ rest: root.toString()
1632
+ };
1633
+ } catch {
1634
+ return {
1635
+ layer: "",
1636
+ rest: css
1637
+ };
1638
+ }
1639
+ }
1640
+ function normalizeGeneratedSelector(selector) {
1641
+ return selector.replace(/:not\(#\\#\)/g, "").trim();
1642
+ }
1643
+ function collectApplyOnlySourceSelectors(source) {
1644
+ const selectors = /* @__PURE__ */ new Set();
1645
+ try {
1646
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1647
+ if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
1648
+ for (const selector of rule.selectors ?? [rule.selector]) {
1649
+ const normalized = normalizeGeneratedSelector(selector);
1650
+ if (normalized) selectors.add(normalized);
1651
+ }
1652
+ });
1653
+ } catch {}
1654
+ return selectors;
1655
+ }
1656
+ function hasOnlyApplyBackedSourceRules(source) {
1657
+ let hasApplyRule = false;
1658
+ let hasNonApplyRule = false;
1659
+ try {
1660
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1661
+ if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
1662
+ else hasNonApplyRule = true;
1663
+ });
1664
+ } catch {
1665
+ return false;
1666
+ }
1667
+ return hasApplyRule && !hasNonApplyRule;
1668
+ }
1669
+ function filterApplyOnlyGeneratedCss(css, source) {
1670
+ const selectors = collectApplyOnlySourceSelectors(source);
1671
+ if (selectors.size === 0) return css;
1672
+ const selectorList = [...selectors];
1673
+ try {
1674
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1675
+ root.walkRules((rule) => {
1676
+ const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
1677
+ const normalized = normalizeGeneratedSelector(selector);
1678
+ return selectorList.some((sourceSelector) => {
1679
+ if (normalized === sourceSelector) return true;
1680
+ if (!normalized.startsWith(sourceSelector)) return false;
1681
+ const next = normalized[sourceSelector.length];
1682
+ return next === ":" || next === "[" || next === ".";
1683
+ });
1684
+ });
1685
+ const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
1686
+ if (!isApplySelector && !isVariableRule) rule.remove();
1687
+ });
1688
+ root.walkAtRules((rule) => {
1689
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
1690
+ });
1691
+ return root.toString();
1692
+ } catch {
1693
+ return css;
1694
+ }
1695
+ }
1696
+ function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
1697
+ return target === "weapp" && require_v4_engine.hasTailwindApplyDirective(source) && !require_v4_engine.hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
1698
+ }
1699
+ async function transformGeneratorUserCss(source, options) {
1700
+ if (source.trim().length === 0) return "";
1701
+ if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeProcessedMiniProgramUnsupportedCss(source, {
1702
+ ...options.generatorStyleOptions,
1703
+ ...options.cssUserHandlerOptions
1704
+ })) : source)));
1705
+ const cleanedSource = require_v4_engine.removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
1706
+ if (cleanedSource.trim().length === 0) return "";
1707
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(require_v4_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource))) : cleanedSource)), { importFallback: options.importFallback })));
1708
+ if (userSource.trim().length === 0) return "";
1709
+ if (isCommentOnlyCss(userSource)) return userSource;
1710
+ if (options.generatorTarget !== "weapp") return userSource;
1711
+ const { css } = await options.styleHandler(userSource, {
1712
+ ...options.generatorStyleOptions,
1713
+ ...options.cssUserHandlerOptions
1714
+ });
1715
+ return removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css));
1716
+ }
1717
+ //#endregion
1718
+ //#region src/bundlers/shared/generator-css/legacy-compat.ts
1719
+ const LEGACY_CONTAINER_COMPAT_CSS = [
1720
+ ".container {",
1721
+ " width: 100%;",
1722
+ "}",
1723
+ "@media (min-width: 40rem) {",
1724
+ " .container {",
1725
+ " max-width: 40rem;",
1726
+ " }",
1727
+ "}",
1728
+ "@media (min-width: 48rem) {",
1729
+ " .container {",
1730
+ " max-width: 48rem;",
1731
+ " }",
1732
+ "}",
1733
+ "@media (min-width: 64rem) {",
1734
+ " .container {",
1735
+ " max-width: 64rem;",
1736
+ " }",
1737
+ "}",
1738
+ "@media (min-width: 80rem) {",
1739
+ " .container {",
1740
+ " max-width: 80rem;",
1741
+ " }",
1742
+ "}",
1743
+ "@media (min-width: 96rem) {",
1744
+ " .container {",
1745
+ " max-width: 96rem;",
1746
+ " }",
1747
+ "}"
1748
+ ].join("\n");
1749
+ const LEGACY_COMPAT_CACHE_LIMIT = 128;
1750
+ const legacyCompatSourceCache = /* @__PURE__ */ new Map();
1751
+ const legacyCompatTransformCache = /* @__PURE__ */ new Map();
1752
+ function setLimitedCacheValue(cache, key, value) {
1753
+ if (cache.size >= LEGACY_COMPAT_CACHE_LIMIT) {
1754
+ const firstKey = cache.keys().next().value;
1755
+ if (firstKey !== void 0) cache.delete(firstKey);
1756
+ }
1757
+ cache.set(key, value);
1758
+ }
1759
+ function createStableJson(value) {
1760
+ if (value === void 0) return "undefined";
1761
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
1762
+ if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
1763
+ return `{${Object.keys(value).sort().map((key) => {
1764
+ const record = value;
1765
+ return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
1766
+ }).join(",")}}`;
1767
+ }
1768
+ function createLegacyCompatTransformCacheKey(source, options) {
1769
+ return `${createStableJson(options)}\0${source}`;
1770
+ }
1771
+ function countUnclosedBlocks(source) {
1772
+ let depth = 0;
1773
+ let quote;
1774
+ let inComment = false;
1775
+ let escaped = false;
1776
+ for (let index = 0; index < source.length; index += 1) {
1777
+ const char = source[index];
1778
+ const next = source[index + 1];
1779
+ if (inComment) {
1780
+ if (char === "*" && next === "/") {
1781
+ inComment = false;
1782
+ index += 1;
1783
+ }
1784
+ continue;
1785
+ }
1786
+ if (quote) {
1787
+ if (escaped) {
1788
+ escaped = false;
1789
+ continue;
1790
+ }
1791
+ if (char === "\\") {
1792
+ escaped = true;
1793
+ continue;
1794
+ }
1795
+ if (char === quote) quote = void 0;
1796
+ continue;
1797
+ }
1798
+ if (char === "/" && next === "*") {
1799
+ inComment = true;
1800
+ index += 1;
1801
+ continue;
1802
+ }
1803
+ if (char === "\"" || char === "'") {
1804
+ quote = char;
1805
+ continue;
1806
+ }
1807
+ if (char === "{") depth += 1;
1808
+ else if (char === "}" && depth > 0) depth -= 1;
1809
+ }
1810
+ return depth;
1811
+ }
1812
+ function closeTrailingUnclosedBlocks(source) {
1813
+ try {
1814
+ _weapp_tailwindcss_postcss.postcss.parse(source);
1815
+ return source;
1816
+ } catch (error) {
1817
+ if (error.reason !== "Unclosed block") return source;
1818
+ const unclosedBlocks = countUnclosedBlocks(source);
1819
+ return unclosedBlocks > 0 ? `${source}${"}".repeat(unclosedBlocks)}` : source;
1820
+ }
1821
+ }
1822
+ function removeTailwindApplyRules(rawSource) {
1823
+ try {
1824
+ const root = _weapp_tailwindcss_postcss.postcss.parse(rawSource);
1825
+ let removed = false;
1826
+ root.walkAtRules("apply", (rule) => {
1827
+ const parent = rule.parent;
1828
+ if (parent?.type === "rule") parent.remove();
1829
+ else rule.remove();
1830
+ removed = true;
1831
+ });
1832
+ root.walkAtRules((rule) => {
1833
+ if (rule.nodes && rule.nodes.length === 0) rule.remove();
1834
+ });
1835
+ return removed ? root.toString() : rawSource;
1836
+ } catch {
1837
+ return rawSource;
1838
+ }
1839
+ }
1840
+ function resolveLegacyCompatCssSource(rawSource) {
1841
+ const cached = legacyCompatSourceCache.get(rawSource);
1842
+ if (cached !== void 0) return cached;
1843
+ const resolved = closeTrailingUnclosedBlocks(removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(removeTailwindApplyRules(require_v4_engine.removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(require_v4_engine.stripTailwindBanners(rawSource)))))));
1844
+ setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
1845
+ return resolved;
1846
+ }
1847
+ function removeMiniProgramContainerCompatCss(css) {
1848
+ try {
1849
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1292
1850
  let removed = false;
1293
1851
  root.walkRules((rule) => {
1294
1852
  if (rule.selectors?.length === 1 && rule.selectors[0] === ".container") {
@@ -1312,7 +1870,7 @@ function hasContainerConfigToken(rawSource) {
1312
1870
  }
1313
1871
  function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
1314
1872
  if (hasContainerConfigToken(rawSource)) return true;
1315
- const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
1873
+ const cssEntrySource = require_v4_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
1316
1874
  if (!cssEntrySource?.config) return false;
1317
1875
  try {
1318
1876
  return /\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"));
@@ -1321,8 +1879,9 @@ function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
1321
1879
  }
1322
1880
  }
1323
1881
  function hasConfiguredContainerCompatSource(source) {
1882
+ if (typeof source.css !== "string") return false;
1324
1883
  if (hasContainerConfigToken(source.css)) return true;
1325
- const cssEntrySource = require_v3_engine.resolveCssEntrySource(source.css, source.base);
1884
+ const cssEntrySource = require_v4_engine.resolveCssEntrySource(source.css, source.base);
1326
1885
  if (cssEntrySource?.config) try {
1327
1886
  if (/\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"))) return true;
1328
1887
  } catch {}
@@ -1338,7 +1897,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
1338
1897
  const resolvedCompatSource = resolveLegacyCompatCssSource(rawSource);
1339
1898
  const compatSource = removeGeneratedSelectorCompatCss(generatorTarget === "weapp" ? removeMiniProgramContainerCompatCss(resolvedCompatSource) : resolvedCompatSource, css);
1340
1899
  if (compatSource.trim().length === 0) return css;
1341
- if (generatorTarget !== "weapp") return require_v3_engine.createCssAppend(css, compatSource);
1900
+ if (generatorTarget !== "weapp") return require_v4_engine.createCssAppend(css, compatSource);
1342
1901
  const styleOptions = {
1343
1902
  ...cssHandlerOptions,
1344
1903
  ...generatorStyleOptions
@@ -1349,9 +1908,9 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
1349
1908
  compatCss = (await styleHandler(compatSource, styleOptions)).css;
1350
1909
  setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
1351
1910
  }
1352
- const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css), css);
1911
+ const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeTailwindV4GeneratedUserCssArtifacts(removeDuplicatedViteMarkers((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css)), css);
1353
1912
  if (cleanedCompatCss.trim().length === 0) return css;
1354
- return require_v3_engine.createCssAppend(css, cleanedCompatCss);
1913
+ return require_v4_engine.createCssAppend(css, cleanedCompatCss);
1355
1914
  }
1356
1915
  async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1357
1916
  if (generatorTarget === "weapp") return css;
@@ -1370,7 +1929,7 @@ async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, con
1370
1929
  }
1371
1930
  const cleanedCompatCss = collectDedupedPostTransformCompatCss((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css);
1372
1931
  if (cleanedCompatCss.trim().length === 0) return css;
1373
- return require_v3_engine.createCssAppend(css, cleanedCompatCss);
1932
+ return require_v4_engine.createCssAppend(css, cleanedCompatCss);
1374
1933
  }
1375
1934
  //#endregion
1376
1935
  //#region src/bundlers/shared/generator-css/legacy-units.ts
@@ -1419,6 +1978,8 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
1419
1978
  //#endregion
1420
1979
  //#region src/bundlers/shared/generator-css/local-imports.ts
1421
1980
  const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
1981
+ const CSS_STYLE_EXTENSION_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
1982
+ const SOURCE_STYLE_EXTENSION_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
1422
1983
  function createCssSourceOrderAppend(base, extra) {
1423
1984
  if (!base) return extra;
1424
1985
  if (!extra) return base;
@@ -1435,7 +1996,7 @@ function isPureLocalCssImportWrapper(css) {
1435
1996
  for (const node of root.nodes) {
1436
1997
  if (node.type === "comment") continue;
1437
1998
  if (node.type !== "atrule" || node.name !== "import") return false;
1438
- const request = require_v3_engine.parseImportRequest(node.params);
1999
+ const request = require_v4_engine.parseImportRequest(node.params);
1439
2000
  if (!request || !isLocalImportRequest(request)) return false;
1440
2001
  hasImport = true;
1441
2002
  }
@@ -1452,7 +2013,7 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1452
2013
  for (const node of root.nodes) {
1453
2014
  if (node.type === "comment") continue;
1454
2015
  if (node.type === "atrule" && node.name === "import") {
1455
- const request = require_v3_engine.parseImportRequest(node.params);
2016
+ const request = require_v4_engine.parseImportRequest(node.params);
1456
2017
  if (!request || !isLocalImportRequest(request)) return;
1457
2018
  hasLocalImport = true;
1458
2019
  continue;
@@ -1466,13 +2027,13 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1466
2027
  } catch {
1467
2028
  return;
1468
2029
  }
1469
- return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v3_engine.removeTailwindSourceDirectives(css)) : void 0;
2030
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v4_engine.removeTailwindSourceDirectives(css)) : void 0;
1470
2031
  }
1471
2032
  function prefixLocalCssImportsWithWebpackIgnore(css) {
1472
2033
  try {
1473
2034
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1474
2035
  root.walkAtRules("import", (atRule) => {
1475
- const request = require_v3_engine.parseImportRequest(atRule.params);
2036
+ const request = require_v4_engine.parseImportRequest(atRule.params);
1476
2037
  if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
1477
2038
  });
1478
2039
  return root.toString();
@@ -1487,7 +2048,7 @@ function splitLocalCssImports(source) {
1487
2048
  let changed = false;
1488
2049
  for (const node of [...root.nodes]) {
1489
2050
  if (node.type !== "atrule" || node.name !== "import") continue;
1490
- const request = require_v3_engine.parseImportRequest(node.params);
2051
+ const request = require_v4_engine.parseImportRequest(node.params);
1491
2052
  if (!request || !isLocalImportRequest(request)) continue;
1492
2053
  importRoot.append(node.clone());
1493
2054
  node.remove();
@@ -1504,251 +2065,43 @@ function splitLocalCssImports(source) {
1504
2065
  }
1505
2066
  function restoreLocalCssImports(css, imports) {
1506
2067
  if (!imports?.trim()) return css;
1507
- return createCssSourceOrderAppend(imports, css);
1508
- }
1509
- //#endregion
1510
- //#region src/bundlers/shared/generator-css/user-css.ts
1511
- const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
1512
- "config",
1513
- "custom-variant",
1514
- "plugin",
1515
- "source",
1516
- "theme",
1517
- "utility",
1518
- "variant"
1519
- ]);
1520
- function removeTailwindApplyAtRules(source) {
1521
- if (!source.includes("@apply")) return source;
1522
- try {
1523
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1524
- let changed = false;
1525
- root.walkAtRules("apply", (rule) => {
1526
- rule.remove();
1527
- changed = true;
1528
- });
1529
- root.walk((node) => {
1530
- if ("nodes" in node && node.nodes?.length === 0) node.remove();
1531
- });
1532
- return changed ? root.toString() : source;
1533
- } catch {
1534
- return source;
1535
- }
1536
- }
1537
- function removeTailwindV4GeneratorAtRules(source) {
1538
- try {
1539
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1540
- let changed = false;
1541
- root.walkAtRules((rule) => {
1542
- if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
1543
- rule.remove();
1544
- changed = true;
1545
- });
1546
- root.walk((node) => {
1547
- if ("nodes" in node && node.nodes?.length === 0) {
1548
- node.remove();
1549
- changed = true;
1550
- }
1551
- });
1552
- return changed ? root.toString() : source;
1553
- } catch {
1554
- return source;
1555
- }
1556
- }
1557
- function isCommentOnlyCss(source) {
1558
- try {
1559
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1560
- return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
1561
- } catch {
1562
- return false;
1563
- }
1564
- }
1565
- function unwrapMiniProgramCascadeLayers(source) {
1566
- if (!source.includes("@layer")) return source;
1567
- try {
1568
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1569
- (0, _weapp_tailwindcss_postcss.removeUnsupportedCascadeLayers)(root);
1570
- return root.toString();
1571
- } catch {
1572
- return source;
1573
- }
1574
- }
1575
- function stripTailwindSourceMediaFragments(source) {
1576
- let removedSourceMediaStart = false;
1577
- return source.split(/\r?\n/).filter((line) => {
1578
- if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
1579
- removedSourceMediaStart = true;
1580
- return false;
1581
- }
1582
- if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
1583
- if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
1584
- removedSourceMediaStart = false;
1585
- return false;
1586
- }
1587
- return true;
1588
- }).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
1589
- }
1590
- function stripLeadingTailwindSourceMediaCloseFragment(source) {
1591
- return source.replace(/^\s*\}\s*(?:\n|$)/, "");
1592
- }
1593
- function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
1594
- try {
1595
- _weapp_tailwindcss_postcss.postcss.parse(source);
1596
- return source;
1597
- } catch {
1598
- return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
1599
- }
1600
- }
1601
- function splitUserCssLayerBlocks(source) {
1602
- if (!source.includes("@layer")) return {
1603
- layer: "",
1604
- rest: source
1605
- };
1606
- try {
1607
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1608
- const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
1609
- const restRoot = _weapp_tailwindcss_postcss.postcss.root();
1610
- for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
1611
- return {
1612
- layer: layerRoot.toString(),
1613
- rest: restRoot.toString()
1614
- };
1615
- } catch {
1616
- return {
1617
- layer: source,
1618
- rest: ""
1619
- };
1620
- }
1621
- }
1622
- function hasUserCssLayerBlocks(source) {
1623
- if (!source.includes("@layer")) return false;
1624
- try {
1625
- let hasLayerBlock = false;
1626
- _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("layer", (node) => {
1627
- if (node.nodes?.length) hasLayerBlock = true;
1628
- });
1629
- return hasLayerBlock;
1630
- } catch {
1631
- return true;
1632
- }
1633
- }
1634
- function collectUserLayerSelectors(source) {
1635
- const selectors = /* @__PURE__ */ new Set();
1636
- try {
1637
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1638
- for (const selector of rule.selectors ?? [rule.selector]) {
1639
- const normalized = selector.trim();
1640
- if (normalized) selectors.add(normalized);
1641
- }
1642
- });
1643
- } catch {}
1644
- return selectors;
1645
- }
1646
- function matchesUserLayerSelector(selector, userLayerSelector) {
1647
- if (selector === userLayerSelector) return true;
1648
- if (!selector.startsWith(userLayerSelector)) return false;
1649
- const next = selector[userLayerSelector.length];
1650
- return next === ":" || next === "[";
1651
- }
1652
- function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
1653
- const selectors = collectUserLayerSelectors(userLayerSource);
1654
- if (selectors.size === 0) return {
1655
- layer: "",
1656
- rest: css
1657
- };
1658
- try {
1659
- const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1660
- const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
1661
- const selectorList = [...selectors];
1662
- root.walkRules((rule) => {
1663
- if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
1664
- layerRoot.append(rule.clone());
1665
- rule.remove();
1666
- }
1667
- });
1668
- return {
1669
- layer: layerRoot.toString(),
1670
- rest: root.toString()
1671
- };
1672
- } catch {
1673
- return {
1674
- layer: "",
1675
- rest: css
1676
- };
1677
- }
1678
- }
1679
- function normalizeGeneratedSelector(selector) {
1680
- return selector.replace(/:not\(#\\#\)/g, "").trim();
1681
- }
1682
- function collectApplyOnlySourceSelectors(source) {
1683
- const selectors = /* @__PURE__ */ new Set();
1684
- try {
1685
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1686
- if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
1687
- for (const selector of rule.selectors ?? [rule.selector]) {
1688
- const normalized = normalizeGeneratedSelector(selector);
1689
- if (normalized) selectors.add(normalized);
1690
- }
1691
- });
1692
- } catch {}
1693
- return selectors;
1694
- }
1695
- function hasOnlyApplyBackedSourceRules(source) {
1696
- let hasApplyRule = false;
1697
- let hasNonApplyRule = false;
1698
- try {
1699
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
1700
- if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
1701
- else hasNonApplyRule = true;
1702
- });
1703
- } catch {
1704
- return false;
1705
- }
1706
- return hasApplyRule && !hasNonApplyRule;
2068
+ return createCssSourceOrderAppend(imports, css);
1707
2069
  }
1708
- function filterApplyOnlyGeneratedCss(css, source) {
1709
- const selectors = collectApplyOnlySourceSelectors(source);
1710
- if (selectors.size === 0) return css;
1711
- const selectorList = [...selectors];
2070
+ function splitRequestSuffix(request) {
2071
+ const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
2072
+ const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
2073
+ if (suffixIndex < 0) return {
2074
+ clean: request,
2075
+ suffix: ""
2076
+ };
2077
+ return {
2078
+ clean: request.slice(0, suffixIndex),
2079
+ suffix: request.slice(suffixIndex)
2080
+ };
2081
+ }
2082
+ function normalizeOutputImportRequest(request, styleOutputExtension) {
2083
+ const normalizedStyleOutputExtension = styleOutputExtension?.startsWith(".") ? styleOutputExtension : styleOutputExtension ? `.${styleOutputExtension}` : void 0;
2084
+ const { clean, suffix } = splitRequestSuffix(request.replace(/\\/g, "/"));
2085
+ return `${clean.replace(/^(?:\.\/)?src\//, "./").replace(SOURCE_STYLE_EXTENSION_RE, normalizedStyleOutputExtension ?? ".css")}${suffix}`;
2086
+ }
2087
+ function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
2088
+ if (!css.includes("@import")) return css;
1712
2089
  try {
1713
2090
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1714
- root.walkRules((rule) => {
1715
- const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
1716
- const normalized = normalizeGeneratedSelector(selector);
1717
- return selectorList.some((sourceSelector) => {
1718
- if (normalized === sourceSelector) return true;
1719
- if (!normalized.startsWith(sourceSelector)) return false;
1720
- const next = normalized[sourceSelector.length];
1721
- return next === ":" || next === "[" || next === ".";
1722
- });
1723
- });
1724
- const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
1725
- if (!isApplySelector && !isVariableRule) rule.remove();
1726
- });
1727
- root.walkAtRules((rule) => {
1728
- if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
2091
+ let changed = false;
2092
+ root.walkAtRules("import", (atRule) => {
2093
+ const request = require_v4_engine.parseImportRequest(atRule.params);
2094
+ if (!request || !isLocalImportRequest(request) || !CSS_STYLE_EXTENSION_RE.test(request)) return;
2095
+ const rewritten = normalizeOutputImportRequest(request, options.styleOutputExtension);
2096
+ if (rewritten === request) return;
2097
+ atRule.params = atRule.params.replace(request, rewritten);
2098
+ changed = true;
1729
2099
  });
1730
- return root.toString();
2100
+ return changed ? root.toString() : css;
1731
2101
  } catch {
1732
2102
  return css;
1733
2103
  }
1734
2104
  }
1735
- function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
1736
- return majorVersion === 4 && target === "weapp" && require_v3_engine.hasTailwindApplyDirective(source) && !require_v3_engine.hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
1737
- }
1738
- async function transformGeneratorUserCss(source, options) {
1739
- if (source.trim().length === 0) return "";
1740
- const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
1741
- if (cleanedSource.trim().length === 0) return "";
1742
- const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource)) : cleanedSource)), { importFallback: options.importFallback })));
1743
- if (userSource.trim().length === 0) return "";
1744
- if (isCommentOnlyCss(userSource)) return userSource;
1745
- if (options.generatorTarget !== "weapp") return userSource;
1746
- const { css } = await options.styleHandler(userSource, {
1747
- ...options.generatorStyleOptions,
1748
- ...options.cssUserHandlerOptions
1749
- });
1750
- return (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css);
1751
- }
1752
2105
  //#endregion
1753
2106
  //#region src/bundlers/shared/generator-css/user-layer-order.ts
1754
2107
  const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
@@ -1896,17 +2249,21 @@ async function runWithConcurrency(factories, limit = Math.min(4, Math.max(1, fac
1896
2249
  await Promise.all(executing);
1897
2250
  return results;
1898
2251
  }
2252
+ function resolveTaskConcurrency(defaultLimit = 1) {
2253
+ const configured = Number.parseInt(node_process.default.env["WEAPP_TW_TASK_CONCURRENCY"] ?? "", 10);
2254
+ if (Number.isFinite(configured) && configured > 0) return configured;
2255
+ return defaultLimit;
2256
+ }
1899
2257
  function pushConcurrentTaskFactories(queue, factories, limit) {
1900
2258
  if (factories.length === 0) return;
1901
2259
  queue.push(runWithConcurrency(factories, limit).then(() => void 0));
1902
2260
  }
1903
2261
  //#endregion
1904
2262
  //#region src/bundlers/shared/generator-css/validate.ts
1905
- const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
1906
2263
  async function validateCandidatesByGenerator(options) {
1907
2264
  const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState, skipGenerateFallback } = options;
1908
- const majorVersion = runtimeState.twPatcher.majorVersion;
1909
- if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
2265
+ const majorVersion = runtimeState.tailwindRuntime.majorVersion;
2266
+ if (majorVersion !== 4 || candidates.size === 0) return /* @__PURE__ */ new Set();
1910
2267
  const generatorOptions = {
1911
2268
  ...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
1912
2269
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
@@ -1924,7 +2281,7 @@ async function validateCandidatesByGenerator(options) {
1924
2281
  return (await generator.generate({
1925
2282
  bareArbitraryValues: generatorOptions.bareArbitraryValues,
1926
2283
  candidates,
1927
- target: "tailwind"
2284
+ target: "web"
1928
2285
  })).classSet;
1929
2286
  }));
1930
2287
  const classSet = new Set(classSets.flatMap((item) => [...item]));
@@ -1938,38 +2295,87 @@ function resolveGeneratorSourceConcurrency() {
1938
2295
  if (Number.isFinite(configured) && configured > 0) return configured;
1939
2296
  return 1;
1940
2297
  }
2298
+ function intersectCandidateSets(left, right) {
2299
+ if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
2300
+ const [small, large] = left.size <= right.size ? [left, right] : [right, left];
2301
+ const matched = /* @__PURE__ */ new Set();
2302
+ for (const candidate of small) if (large.has(candidate)) matched.add(candidate);
2303
+ return matched;
2304
+ }
2305
+ function collectCssRuleIdentityMarkers(source) {
2306
+ const markers = /* @__PURE__ */ new Set();
2307
+ try {
2308
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2309
+ root.walkRules((rule) => {
2310
+ for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
2311
+ });
2312
+ root.walkAtRules("keyframes", (rule) => {
2313
+ if (rule.params) markers.add(`keyframes:${rule.params}`);
2314
+ });
2315
+ } catch {}
2316
+ return markers;
2317
+ }
2318
+ function isCssAlreadyRepresentedByMarkers(css, source) {
2319
+ const sourceMarkers = collectCssRuleIdentityMarkers(source);
2320
+ if (sourceMarkers.size === 0) return false;
2321
+ const cssMarkers = collectCssRuleIdentityMarkers(css);
2322
+ for (const marker of sourceMarkers) if (!cssMarkers.has(marker)) return false;
2323
+ return true;
2324
+ }
1941
2325
  async function generateCssByGenerator(options) {
1942
- const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
2326
+ const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, userRawSource, userRawSourceProcessed, debug } = options;
1943
2327
  const generatorOptions = {
1944
- ...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
2328
+ ...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
2329
+ appType: opts.appType,
2330
+ platform: opts.cssOptions?.platform ?? opts.platform,
2331
+ tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
2332
+ uniAppX: opts.uniAppX
2333
+ }),
1945
2334
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1946
2335
  };
1947
- const majorVersion = runtimeState.twPatcher.majorVersion;
1948
- const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
2336
+ const generatorBranch = require_generator.resolveGeneratorRuntimeBranch(generatorOptions, {
2337
+ appType: opts.appType,
2338
+ platform: opts.cssOptions?.platform ?? opts.platform,
2339
+ tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
2340
+ uniAppX: opts.uniAppX
2341
+ });
2342
+ const majorVersion = runtimeState.tailwindRuntime.majorVersion;
2343
+ if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
2344
+ const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v4_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1949
2345
  const localImportParts = splitLocalCssImports(effectiveRawSource);
2346
+ const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
1950
2347
  const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
1951
- const userCssRawSource = majorVersion === 4 ? removeTailwindV4GeneratorAtRules(generatorRawSource) : generatorRawSource;
2348
+ const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v4_engine.normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
2349
+ const userSource = splitLocalCssImports(rawUserSource)?.source ?? rawUserSource;
2350
+ const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
2351
+ const userCssOrderSource = require_v4_engine.GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : userCssRawSource;
2352
+ const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(userCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
1952
2353
  const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
1953
2354
  if (cleanedLocalImportWrapper !== void 0) return {
1954
- css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
2355
+ css: require_generator.shouldUseMiniProgramCssBranch(generatorBranch) ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
2356
+ classSet: /* @__PURE__ */ new Set(),
1955
2357
  target: generatorOptions.target,
1956
2358
  source: "generator",
1957
- dependencies: []
2359
+ dependencies: [],
2360
+ metadata: {
2361
+ file,
2362
+ majorVersion
2363
+ }
1958
2364
  };
1959
2365
  if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
1960
- const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(generatorRawSource);
1961
- const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
1962
- const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
1963
- const shouldGenerateCurrentCss = shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
2366
+ const hasGeneratedCss = require_v4_engine.hasTailwindGeneratedCss(generatorRawSource);
2367
+ const hasSourceDirectives = require_v4_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
2368
+ const hasGeneratedMarkers = require_v4_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
2369
+ if (!shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
2370
+ forceGenerator: options.forceGenerator,
1964
2371
  hasGeneratedCss,
1965
2372
  hasGeneratedMarkers,
1966
2373
  hasSourceDirectives,
1967
2374
  rawSource: generatorRawSource
1968
- });
1969
- if (!isSupportedGeneratorMajorVersion(majorVersion) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
2375
+ })) return;
1970
2376
  try {
1971
2377
  await runtimeState.readyPromise;
1972
- const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
2378
+ const currentCssCandidates = await (0, _tailwindcss_mangle_engine.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } });
1973
2379
  const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
1974
2380
  hasGeneratedCss,
1975
2381
  hasGeneratedMarkers,
@@ -1987,8 +2393,9 @@ async function generateCssByGenerator(options) {
1987
2393
  const sourceConcurrency = resolveGeneratorSourceConcurrency();
1988
2394
  const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
1989
2395
  const generator = require_generator.createWeappTailwindcssGenerator(source);
1990
- const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1991
- const scopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
2396
+ const sourceEntries = getSourceCandidatesForEntries ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
2397
+ const sourceScopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
2398
+ const scopedRuntime = options.sourceCandidates && sourceScopedRuntime ? intersectCandidateSets(options.sourceCandidates, sourceScopedRuntime) : options.sourceCandidates ?? sourceScopedRuntime;
1992
2399
  const isolateCssSource = shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, {
1993
2400
  cssHandlerOptions,
1994
2401
  target: generatorOptions.target
@@ -2006,40 +2413,45 @@ async function generateCssByGenerator(options) {
2006
2413
  majorVersion,
2007
2414
  matchedCssSourceFile
2008
2415
  }) : runtimeWithCurrentCss;
2009
- const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
2010
- const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
2416
+ const generatorRuntime = require_generator.shouldUseMiniProgramCssBranch(generatorBranch) ? require_v4_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
2011
2417
  return generator.generate({
2012
2418
  bareArbitraryValues: generatorOptions.bareArbitraryValues,
2013
2419
  candidates: generatorRuntime,
2014
- incrementalCache: useIncrementalCache,
2420
+ incrementalCache: true,
2015
2421
  scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
2016
2422
  styleOptions: generatorStyleOptions,
2017
- tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
2018
2423
  target: generatorOptions.target
2019
2424
  });
2020
2425
  }), sourceConcurrency)).filter((item) => Boolean(item)));
2021
2426
  if (!generated) return;
2022
2427
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
2023
2428
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
2024
- const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
2429
+ const incrementalCss = require_v4_engine.stripTailwindBanner(generated.incrementalCss);
2025
2430
  return {
2026
- css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
2431
+ css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? require_v4_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
2027
2432
  injectPreflight: false,
2028
2433
  styleOptions: generatorStyleOptions
2029
- })) : options.previousCss, localImportParts?.imports),
2434
+ })) : options.previousCss, localImports),
2435
+ classSet: generated.classSet,
2030
2436
  target: generated.target,
2031
2437
  source: "generator",
2032
2438
  dependencies: generated.dependencies,
2033
- incremental: true
2439
+ incremental: true,
2440
+ metadata: {
2441
+ file,
2442
+ majorVersion,
2443
+ rawCss: generated.rawCss
2444
+ }
2034
2445
  };
2035
2446
  }
2036
2447
  const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
2037
2448
  hasGeneratedCss,
2038
2449
  hasGeneratedMarkers
2039
2450
  });
2040
- const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(require_v3_engine.stripTailwindBanner(generated.css), generatorRawSource) : require_v3_engine.stripTailwindBanner(generated.css);
2451
+ const generatedCssSource = generated.target === "web" ? generated.css : require_v4_engine.stripTailwindBanner(generated.css);
2452
+ const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
2041
2453
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
2042
- const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssRawSource, generated.rawCss);
2454
+ const orderedExtraCss = require_v4_engine.splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
2043
2455
  const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
2044
2456
  if (orderedExtraCss) {
2045
2457
  let css = generatedCss;
@@ -2049,7 +2461,8 @@ async function generateCssByGenerator(options) {
2049
2461
  generatorStyleOptions,
2050
2462
  cssUserHandlerOptions,
2051
2463
  styleHandler,
2052
- importFallback: generatorOptions.importFallback
2464
+ importFallback: generatorOptions.importFallback,
2465
+ processed: userRawSourceProcessed
2053
2466
  };
2054
2467
  const afterLayerParts = generated.target === "weapp" ? splitUserCssLayerBlocks(orderedExtraCss.after) : {
2055
2468
  layer: "",
@@ -2067,9 +2480,19 @@ async function generateCssByGenerator(options) {
2067
2480
  const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
2068
2481
  css = createCssSourceOrderAppend$1(css, userCss);
2069
2482
  }
2483
+ if (generated.target === "web") {
2484
+ const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
2485
+ const missingUserCss = isCommentOnlyCss(userCss) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss);
2486
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2487
+ }
2488
+ if (generated.target === "weapp" && isEmptyCssSourceOrderParts(orderedExtraCss) && hasDistinctUserRawSource && !hasGeneratedCss && !hasGeneratedMarkers && !require_v4_engine.hasTailwindApplyDirective(userCssRawSource)) {
2489
+ const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
2490
+ const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss) : userCss;
2491
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2492
+ }
2070
2493
  if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
2071
2494
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
2072
- if (!shouldFilterApplyOnlyCss) {
2495
+ if (!shouldFilterApplyOnlyCss && !userRawSourceProcessed) {
2073
2496
  css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2074
2497
  if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2075
2498
  }
@@ -2079,17 +2502,31 @@ async function generateCssByGenerator(options) {
2079
2502
  injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2080
2503
  cssHandlerOptions,
2081
2504
  isolateCurrentCssCandidates,
2082
- localImports: localImportParts?.imports
2505
+ localImports
2083
2506
  }),
2084
2507
  styleOptions: generatorStyleOptions
2085
- }), localImportParts?.imports),
2508
+ }), localImports),
2509
+ classSet: generated.classSet,
2086
2510
  target: generated.target,
2087
2511
  source: "generator",
2088
- dependencies: generated.dependencies
2512
+ dependencies: generated.dependencies,
2513
+ metadata: {
2514
+ file,
2515
+ majorVersion,
2516
+ rawCss: generated.rawCss
2517
+ }
2089
2518
  };
2090
2519
  }
2091
2520
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
2092
2521
  let css = generatedCss;
2522
+ if (generated.target === "weapp" && generatorRawSource.includes("weapp-tailwindcss generator-placeholder") && !hasUserCssLayerBlocks(generatorRawSource)) css = createCssSourceOrderAppend$1(await transformGeneratorUserCss(userCssRawSource, {
2523
+ generatorTarget: generated.target,
2524
+ generatorStyleOptions,
2525
+ cssUserHandlerOptions,
2526
+ styleHandler,
2527
+ importFallback: generatorOptions.importFallback,
2528
+ processed: userRawSourceProcessed
2529
+ }), css);
2093
2530
  if (generated.target === "weapp") {
2094
2531
  css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
2095
2532
  if (hasUserCssLayerBlocks(generatorRawSource)) {
@@ -2099,9 +2536,10 @@ async function generateCssByGenerator(options) {
2099
2536
  generatorStyleOptions,
2100
2537
  cssUserHandlerOptions,
2101
2538
  styleHandler,
2102
- importFallback: generatorOptions.importFallback
2539
+ importFallback: generatorOptions.importFallback,
2540
+ processed: userRawSourceProcessed
2103
2541
  });
2104
- const layerCss = layerUserCss.trim().length > 0 && !require_v3_engine.hasTailwindApplyDirective(layerUserCss) ? {
2542
+ const layerCss = layerUserCss.trim().length > 0 && !require_v4_engine.hasTailwindApplyDirective(layerUserCss) ? {
2105
2543
  layer: layerUserCss,
2106
2544
  rest: css
2107
2545
  } : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
@@ -2112,22 +2550,36 @@ async function generateCssByGenerator(options) {
2112
2550
  }
2113
2551
  }
2114
2552
  if (hasMatchedCssSourceFile || generated.target === "web") {
2115
- if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
2553
+ if (generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
2116
2554
  const userCss = await transformGeneratorUserCss(userCssRawSource, {
2117
2555
  generatorTarget: generated.target,
2118
2556
  generatorStyleOptions,
2119
2557
  cssUserHandlerOptions,
2120
2558
  styleHandler,
2121
- importFallback: generatorOptions.importFallback
2559
+ importFallback: generatorOptions.importFallback,
2560
+ processed: userRawSourceProcessed
2122
2561
  });
2123
- css = createCssSourceOrderAppend$1(css, userCss);
2562
+ const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss) : userCss;
2563
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2564
+ } else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasGeneratedMarkers) {
2565
+ const userCss = await transformGeneratorUserCss(removeTailwindV4GeneratedUserCssArtifacts(userCssRawSource), {
2566
+ generatorTarget: generated.target,
2567
+ generatorStyleOptions,
2568
+ cssUserHandlerOptions,
2569
+ styleHandler,
2570
+ importFallback: generatorOptions.importFallback,
2571
+ processed: userRawSourceProcessed
2572
+ });
2573
+ const missingUserCss = (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss);
2574
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2124
2575
  } else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource)) {
2125
2576
  const layerUserCss = await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, {
2126
2577
  generatorTarget: generated.target,
2127
2578
  generatorStyleOptions,
2128
2579
  cssUserHandlerOptions,
2129
2580
  styleHandler,
2130
- importFallback: generatorOptions.importFallback
2581
+ importFallback: generatorOptions.importFallback,
2582
+ processed: userRawSourceProcessed
2131
2583
  });
2132
2584
  if (layerUserCss.trim().length > 0) {
2133
2585
  css = createCssSourceOrderAppend$1(css, wrapUserLayerComponentsCss(layerUserCss));
@@ -2135,7 +2587,7 @@ async function generateCssByGenerator(options) {
2135
2587
  }
2136
2588
  }
2137
2589
  if (hasMatchedCssSourceFile && generated.target === "weapp") {
2138
- if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2590
+ if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss && !userRawSourceProcessed) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2139
2591
  }
2140
2592
  if (shouldAppendWebBundleCssFallback(generated.target, {
2141
2593
  hasSourceDirectives,
@@ -2146,40 +2598,66 @@ async function generateCssByGenerator(options) {
2146
2598
  generatorStyleOptions,
2147
2599
  cssUserHandlerOptions,
2148
2600
  styleHandler,
2149
- importFallback: generatorOptions.importFallback
2601
+ importFallback: generatorOptions.importFallback,
2602
+ processed: userRawSourceProcessed
2150
2603
  });
2151
- css = createCssSourceOrderAppend$1(css, userCss);
2604
+ const missingUserCss = isCommentOnlyCss(userCss) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss);
2605
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2152
2606
  }
2153
2607
  return {
2154
2608
  css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
2155
2609
  injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2156
2610
  cssHandlerOptions,
2157
2611
  isolateCurrentCssCandidates,
2158
- localImports: localImportParts?.imports
2612
+ localImports
2159
2613
  }),
2160
2614
  styleOptions: generatorStyleOptions
2161
- }), localImportParts?.imports),
2615
+ }), localImports),
2616
+ classSet: generated.classSet,
2162
2617
  target: generated.target,
2163
2618
  source: "generator",
2164
- dependencies: generated.dependencies
2619
+ dependencies: generated.dependencies,
2620
+ metadata: {
2621
+ file,
2622
+ majorVersion,
2623
+ rawCss: generated.rawCss
2624
+ }
2165
2625
  };
2166
2626
  }
2167
- if (!shouldFilterApplyOnlyCss) {
2627
+ if (!shouldFilterApplyOnlyCss && !userRawSourceProcessed) {
2168
2628
  css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2169
2629
  css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2170
2630
  }
2631
+ if (generated.target === "weapp" && hasDistinctUserRawSource && !hasGeneratedCss && !hasGeneratedMarkers && !require_v4_engine.hasTailwindApplyDirective(userCssRawSource)) {
2632
+ const userCss = await transformGeneratorUserCss(userCssRawSource, {
2633
+ generatorTarget: generated.target,
2634
+ generatorStyleOptions,
2635
+ cssUserHandlerOptions,
2636
+ styleHandler,
2637
+ importFallback: generatorOptions.importFallback,
2638
+ processed: userRawSourceProcessed
2639
+ });
2640
+ const missingUserCss = isCssAlreadyRepresentedByMarkers(css, userCssRawSource) ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, userCss) : userCss;
2641
+ css = createCssSourceOrderAppend$1(css, missingUserCss);
2642
+ }
2171
2643
  return {
2172
2644
  css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
2173
2645
  injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2174
2646
  cssHandlerOptions,
2175
2647
  isolateCurrentCssCandidates,
2176
- localImports: localImportParts?.imports
2648
+ localImports
2177
2649
  }),
2178
2650
  styleOptions: generatorStyleOptions
2179
- }), localImportParts?.imports),
2651
+ }), localImports),
2652
+ classSet: generated.classSet,
2180
2653
  target: generated.target,
2181
2654
  source: "generator",
2182
- dependencies: generated.dependencies
2655
+ dependencies: generated.dependencies,
2656
+ metadata: {
2657
+ file,
2658
+ majorVersion,
2659
+ rawCss: generated.rawCss
2660
+ }
2183
2661
  };
2184
2662
  } catch (error) {
2185
2663
  debug("tailwind direct css generation failed: %s %O", file, error);
@@ -2280,186 +2758,23 @@ function collectEscapedRuntimeCandidates(source, escapeMap, escapeFragments) {
2280
2758
  }
2281
2759
  return candidates;
2282
2760
  }
2283
- //#endregion
2284
- //#region src/bundlers/vite/incremental-runtime-class-set/v3-candidates.ts
2285
- const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
2286
- "accent",
2287
- "animate",
2288
- "basis",
2289
- "bg",
2290
- "blur",
2291
- "border",
2292
- "bottom",
2293
- "brightness",
2294
- "caret",
2295
- "col",
2296
- "columns",
2297
- "content",
2298
- "contrast",
2299
- "decoration",
2300
- "delay",
2301
- "divide",
2302
- "drop-shadow",
2303
- "duration",
2304
- "ease",
2305
- "fill",
2306
- "font",
2307
- "gap",
2308
- "gradient",
2309
- "grid",
2310
- "grayscale",
2311
- "grow",
2312
- "h",
2313
- "hue-rotate",
2314
- "indent",
2315
- "inset",
2316
- "invert",
2317
- "leading",
2318
- "left",
2319
- "list",
2320
- "m",
2321
- "max",
2322
- "mb",
2323
- "min",
2324
- "ml",
2325
- "mr",
2326
- "mt",
2327
- "mx",
2328
- "my",
2329
- "object",
2330
- "opacity",
2331
- "order",
2332
- "outline",
2333
- "overflow",
2334
- "p",
2335
- "pb",
2336
- "pl",
2337
- "pr",
2338
- "pt",
2339
- "px",
2340
- "py",
2341
- "right",
2342
- "ring",
2343
- "rotate",
2344
- "rounded",
2345
- "row",
2346
- "saturate",
2347
- "scale",
2348
- "scroll",
2349
- "sepia",
2350
- "shadow",
2351
- "shrink",
2352
- "skew",
2353
- "space",
2354
- "stroke",
2355
- "text",
2356
- "top",
2357
- "tracking",
2358
- "translate",
2359
- "underline",
2360
- "w",
2361
- "z"
2362
- ]);
2363
- function isUrlLikeCandidate(candidate) {
2364
- return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
2365
- }
2366
- function getBaseUtilityCandidate(candidate) {
2367
- let bracketDepth = 0;
2368
- let lastVariantSeparator = -1;
2369
- for (let index = 0; index < candidate.length; index++) {
2370
- const char = candidate[index];
2371
- if (char === "[") bracketDepth += 1;
2372
- else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
2373
- else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
2374
- }
2375
- let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
2376
- if (utility.startsWith("!")) utility = utility.slice(1);
2377
- if (utility.startsWith("-")) utility = utility.slice(1);
2378
- return utility;
2379
- }
2380
- function getArbitraryUtilityPrefix(utility) {
2381
- const bracketIndex = utility.indexOf("[");
2382
- if (bracketIndex <= 0 || !utility.endsWith("]")) return;
2383
- const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
2384
- const firstDash = prefix.indexOf("-");
2385
- return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
2386
- }
2387
- function isLikelyTailwindV3ArbitraryUtility(candidate) {
2388
- const utility = getBaseUtilityCandidate(candidate);
2389
- if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
2390
- const prefix = getArbitraryUtilityPrefix(utility);
2391
- return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
2392
- }
2393
- function isLikelyTailwindV3VariantUtility(candidate) {
2394
- if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
2395
- const utility = getBaseUtilityCandidate(candidate);
2396
- return /^[!-]?[a-z@[]/.test(utility);
2397
- }
2398
- function isLikelyTailwindV3OpacityModifier(candidate) {
2399
- if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
2400
- const utility = getBaseUtilityCandidate(candidate);
2401
- return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
2402
- }
2403
- function isHighConfidenceV3Candidate(candidate) {
2404
- return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
2405
- }
2406
- function isRawCandidateInClassContext(source, start, extension) {
2407
- if (typeof start !== "number" || start <= 0) return false;
2408
- const before = source.slice(Math.max(0, start - 200), start);
2409
- if (extension === "html") return /\bclass\s*=\s*["'][^"']*$/i.test(before);
2410
- return /\bclass(?:Name)?\s*[:=]\s*["'][^"']*$/i.test(before) || /\.classList\.(?:add|remove|toggle|contains)\([^)]*$/i.test(before);
2411
- }
2412
- function resolveQuotedLiteralRange(source, start) {
2413
- if (typeof start !== "number" || start <= 0) return;
2414
- let quote;
2415
- let literalStart = -1;
2416
- for (let index = start - 1; index >= 0; index--) {
2417
- const char = source[index];
2418
- if (char !== "\"" && char !== "'" && char !== "`") continue;
2419
- quote = char;
2420
- literalStart = index;
2421
- break;
2422
- }
2423
- if (!quote) return;
2424
- let escaped = false;
2425
- for (let index = literalStart + 1; index < source.length; index++) {
2426
- const char = source[index];
2427
- if (escaped) {
2428
- escaped = false;
2429
- continue;
2430
- }
2431
- if (char === "\\") {
2432
- escaped = true;
2433
- continue;
2434
- }
2435
- if (char === quote) {
2436
- if (start < index) return {
2437
- start: literalStart,
2438
- end: index
2439
- };
2440
- return;
2761
+ function collectStrictEscapedRuntimeCandidates(source, escapeMap, escapeFragments) {
2762
+ const candidates = /* @__PURE__ */ new Set();
2763
+ ESCAPED_CLASS_TOKEN_RE.lastIndex = 0;
2764
+ let match = ESCAPED_CLASS_TOKEN_RE.exec(source);
2765
+ while (match) {
2766
+ const token = match[0];
2767
+ if (hasEscapeFragment(token, escapeFragments)) {
2768
+ const restored = (0, _weapp_core_escape.unescape)(token, { map: escapeMap });
2769
+ if (restored !== token && TAILWIND_RESTORED_CANDIDATE_SIGNAL_RE.test(restored) && !/\s/.test(restored)) candidates.add(restored);
2441
2770
  }
2771
+ match = ESCAPED_CLASS_TOKEN_RE.exec(source);
2442
2772
  }
2443
- }
2444
- function createHighConfidenceLiteralRanges(source, matches) {
2445
- const ranges = [];
2446
- for (const match of matches) {
2447
- const candidate = match?.rawCandidate;
2448
- if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
2449
- const range = resolveQuotedLiteralRange(source, match?.start ?? source.indexOf(candidate));
2450
- if (range) ranges.push(range);
2451
- }
2452
- return ranges;
2453
- }
2454
- function isRawCandidateInRanges(start, ranges) {
2455
- return typeof start === "number" && ranges.some((range) => start > range.start && start < range.end);
2456
- }
2457
- function isRawCandidateAllowedForV3(source, candidate, start, extension, knownSourceCandidates, highConfidenceLiteralRanges = []) {
2458
- return isHighConfidenceV3Candidate(candidate) || knownSourceCandidates?.has(candidate) === true || isRawCandidateInClassContext(source, start, extension) || isRawCandidateInRanges(start, highConfidenceLiteralRanges);
2773
+ return candidates;
2459
2774
  }
2460
2775
  //#endregion
2461
2776
  //#region src/bundlers/vite/incremental-runtime-class-set.ts
2462
- const debug = require_v3_engine.createDebug("[vite:runtime-set] ");
2777
+ const debug = require_context.createDebug("[vite:runtime-set] ");
2463
2778
  function createExtractOptions(context, source, bareArbitraryValues) {
2464
2779
  return {
2465
2780
  cwd: context.projectRoot,
@@ -2501,8 +2816,8 @@ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
2501
2816
  }
2502
2817
  function createBundleRuntimeClassSetManager(options = {}) {
2503
2818
  const customExtractCandidates = options.extractCandidates;
2504
- const extractCandidates = customExtractCandidates ?? tailwindcss_patch.extractValidCandidates;
2505
- const extractRawCandidates = options.extractRawCandidates ?? tailwindcss_patch.extractRawCandidatesWithPositions;
2819
+ const extractCandidates = customExtractCandidates ?? _tailwindcss_mangle_engine.extractValidCandidates;
2820
+ const extractRawCandidates = options.extractRawCandidates ?? _tailwindcss_mangle_engine.extractRawCandidatesWithPositions;
2506
2821
  const escapeMap = options.escapeMap ?? _weapp_core_escape.MappingChars2String;
2507
2822
  const escapeFragments = createEscapeFragments(escapeMap);
2508
2823
  let baseClassSet = /* @__PURE__ */ new Set();
@@ -2521,25 +2836,21 @@ function createBundleRuntimeClassSetManager(options = {}) {
2521
2836
  validationContext = void 0;
2522
2837
  designSystemPromise = void 0;
2523
2838
  }
2524
- async function resolveValidationContextCached(patcher) {
2525
- if (!validationContext) validationContext = await require_v3_engine.resolveTailwindV4SourceFromPatcher(patcher);
2839
+ async function resolveValidationContextCached(runtime) {
2840
+ if (!validationContext) validationContext = await require_v4_engine.resolveTailwindV4SourceFromRuntime(runtime);
2526
2841
  return validationContext;
2527
2842
  }
2528
2843
  async function loadDesignSystem(context) {
2529
- if (!designSystemPromise) designSystemPromise = (0, tailwindcss_patch.loadTailwindV4DesignSystem)(context);
2844
+ if (!designSystemPromise) designSystemPromise = (0, _tailwindcss_mangle_engine.loadTailwindV4DesignSystem)(context);
2530
2845
  return designSystemPromise;
2531
2846
  }
2532
2847
  function populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates) {
2533
- const validCandidates = (0, tailwindcss_patch.resolveValidTailwindV4Candidates)(designSystem, unknownCandidates, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
2848
+ const validCandidates = (0, _tailwindcss_mangle_engine.resolveValidTailwindV4Candidates)(designSystem, unknownCandidates, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
2534
2849
  for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
2535
2850
  }
2536
- async function validateUnknownCandidates(patcher, unknownCandidates) {
2851
+ async function validateUnknownCandidates(runtime, unknownCandidates) {
2537
2852
  if (unknownCandidates.size === 0) return;
2538
- if (patcher.majorVersion === 3 && !customExtractCandidates) {
2539
- for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, true);
2540
- return;
2541
- }
2542
- const context = await resolveValidationContextCached(patcher);
2853
+ const context = await resolveValidationContextCached(runtime);
2543
2854
  if (!customExtractCandidates) try {
2544
2855
  populateCandidateValidityCacheFromDesignSystem(await loadDesignSystem(context), unknownCandidates);
2545
2856
  return;
@@ -2552,23 +2863,19 @@ function createBundleRuntimeClassSetManager(options = {}) {
2552
2863
  const validCandidates = new Set(await extractCandidates(createExtractOptions(context, source, options.bareArbitraryValues)));
2553
2864
  for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
2554
2865
  }
2555
- async function extractEntryRawCandidates(entry, patcher, knownSourceCandidates) {
2866
+ async function extractEntryRawCandidates(entry, _runtime, _knownSourceCandidates) {
2556
2867
  const extension = resolveEntryExtension(entry);
2557
2868
  const matches = options.bareArbitraryValues === void 0 || options.bareArbitraryValues === false ? await extractRawCandidates(entry.source, extension) : await extractRawCandidates(entry.source, extension, { bareArbitraryValues: options.bareArbitraryValues });
2558
- const highConfidenceLiteralRanges = patcher.majorVersion === 3 && !customExtractCandidates ? createHighConfidenceLiteralRanges(entry.source, matches) : [];
2559
2869
  const candidates = /* @__PURE__ */ new Set();
2560
2870
  for (const match of matches) {
2561
2871
  const candidate = match?.rawCandidate;
2562
- if (typeof candidate === "string" && candidate.length > 0) {
2563
- if (patcher.majorVersion === 3 && !customExtractCandidates && !isRawCandidateAllowedForV3(entry.source, candidate, match.start, extension, knownSourceCandidates, highConfidenceLiteralRanges)) continue;
2564
- candidates.add(candidate);
2565
- }
2872
+ if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
2566
2873
  }
2567
- if (patcher.majorVersion === 4) for (const candidate of collectEscapedRuntimeCandidates(entry.source, escapeMap, escapeFragments)) candidates.add(candidate);
2874
+ for (const candidate of collectEscapedRuntimeCandidates(entry.source, escapeMap, escapeFragments)) candidates.add(candidate);
2568
2875
  return candidates;
2569
2876
  }
2570
- async function sync(patcher, snapshot, options = {}) {
2571
- const nextSignature = require_v3_engine.getRuntimeClassSetSignature(patcher) ?? "runtime:missing";
2877
+ async function sync(runtime, snapshot, options = {}) {
2878
+ const nextSignature = require_tailwindcss.getRuntimeClassSetSignature(runtime) ?? "runtime:missing";
2572
2879
  const runtimeEntries = createRuntimeEntries(snapshot);
2573
2880
  const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
2574
2881
  const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
@@ -2593,14 +2900,14 @@ function createBundleRuntimeClassSetManager(options = {}) {
2593
2900
  }
2594
2901
  const rawCandidatesByFile = /* @__PURE__ */ new Map();
2595
2902
  const unknownCandidates = /* @__PURE__ */ new Set();
2596
- await Promise.all(changedRuntimeFiles.map(async (file) => {
2903
+ for (const file of changedRuntimeFiles) {
2597
2904
  const entry = runtimeEntriesByFile.get(file);
2598
- if (!entry) return;
2599
- const candidates = await extractEntryRawCandidates(entry, patcher, nextBaseClassSet);
2905
+ if (!entry) continue;
2906
+ const candidates = await extractEntryRawCandidates(entry, runtime, nextBaseClassSet);
2600
2907
  rawCandidatesByFile.set(file, candidates);
2601
2908
  for (const candidate of candidates) if (!candidateValidityCache.has(candidate)) unknownCandidates.add(candidate);
2602
- }));
2603
- await validateUnknownCandidates(patcher, unknownCandidates);
2909
+ }
2910
+ await validateUnknownCandidates(runtime, unknownCandidates);
2604
2911
  let rawCandidateCount = 0;
2605
2912
  for (const file of changedRuntimeFiles) {
2606
2913
  const nextRawCandidates = rawCandidatesByFile.get(file);
@@ -2630,6 +2937,52 @@ function createBundleRuntimeClassSetManager(options = {}) {
2630
2937
  };
2631
2938
  }
2632
2939
  //#endregion
2940
+ //#region src/tailwindcss/candidates.ts
2941
+ const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
2942
+ "js",
2943
+ "jsx",
2944
+ "mjs",
2945
+ "cjs",
2946
+ "ts",
2947
+ "tsx",
2948
+ "mts",
2949
+ "cts"
2950
+ ]);
2951
+ async function extractCandidatesFromSource(source, extension, options = {}) {
2952
+ const candidates = options.extractor ? new Set(await options.extractor(source, extension)) : new Set(await (0, _tailwindcss_mangle_engine.extractSourceCandidates)(source, extension, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } }));
2953
+ const scriptCandidates = await extractScriptStringCandidates(source, extension, options);
2954
+ for (const candidate of scriptCandidates) candidates.add(candidate);
2955
+ return candidates;
2956
+ }
2957
+ async function extractScriptStringCandidates(source, extension, options) {
2958
+ if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
2959
+ const values = /* @__PURE__ */ new Set();
2960
+ try {
2961
+ require_context.traverse(require_context.babelParse(source, {
2962
+ cache: true,
2963
+ cacheKey: `source-candidates:${extension}`,
2964
+ plugins: ["jsx", "typescript"],
2965
+ sourceType: "unambiguous"
2966
+ }), {
2967
+ noScope: true,
2968
+ StringLiteral(path) {
2969
+ values.add(path.node.value);
2970
+ },
2971
+ TemplateElement(path) {
2972
+ values.add(path.node.value.raw);
2973
+ }
2974
+ });
2975
+ } catch {
2976
+ return [];
2977
+ }
2978
+ const candidates = /* @__PURE__ */ new Set();
2979
+ for (const value of values) {
2980
+ const extractedCandidates = options.extractor ? await options.extractor(value, "html") : await (0, _tailwindcss_mangle_engine.extractSourceCandidates)(value, "html", { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
2981
+ for (const candidate of extractedCandidates) candidates.add(candidate);
2982
+ }
2983
+ return candidates;
2984
+ }
2985
+ //#endregion
2633
2986
  //#region src/bundlers/vite/source-candidates/scan-root.ts
2634
2987
  const TAILWIND_V4_IGNORED_CONTENT_DIRS = [
2635
2988
  ".git",
@@ -2678,7 +3031,7 @@ function resolveOutDirIgnorePattern(root, outDir) {
2678
3031
  if (!outDir) return;
2679
3032
  const relative = node_path.default.relative(root, node_path.default.resolve(root, outDir));
2680
3033
  if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) return;
2681
- return `${require_v3_engine.toPosixPath(relative)}/**`;
3034
+ return `${require_v4_engine.toPosixPath(relative)}/**`;
2682
3035
  }
2683
3036
  function normalizeScanEntries(root, entries, outDirIgnore) {
2684
3037
  const hasPositiveEntry = entries?.some((entry) => !entry.negated) === true;
@@ -2729,7 +3082,7 @@ function resolveSourceCandidateScanFiles(options) {
2729
3082
  const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, options.outDir);
2730
3083
  const scanEntries = normalizeScanEntries(resolvedRoot, options.entries, outDirIgnore);
2731
3084
  const ignoredSources = createDefaultIgnoredSources(resolvedRoot, outDirIgnore, options.entries, options.explicit);
2732
- return (0, tailwindcss_patch.resolveProjectSourceFiles)({
3085
+ return (0, _tailwindcss_mangle_engine.resolveProjectSourceFiles)({
2733
3086
  cwd: resolvedRoot,
2734
3087
  ...scanEntries === void 0 ? {} : { sources: scanEntries },
2735
3088
  ...ignoredSources.length > 0 ? { ignoredSources } : {},
@@ -2737,81 +3090,11 @@ function resolveSourceCandidateScanFiles(options) {
2737
3090
  });
2738
3091
  }
2739
3092
  //#endregion
2740
- //#region src/bundlers/vite/source-candidates/script.ts
2741
- const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
2742
- "js",
2743
- "jsx",
2744
- "mjs",
2745
- "cjs",
2746
- "ts",
2747
- "tsx",
2748
- "mts",
2749
- "cts"
2750
- ]);
2751
- async function extractScriptStringCandidates(source, extension, options) {
2752
- if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
2753
- const values = /* @__PURE__ */ new Set();
2754
- try {
2755
- require_precheck.traverse(require_precheck.babelParse(source, {
2756
- cache: true,
2757
- cacheKey: `vite-source-candidates:${extension}`,
2758
- plugins: ["jsx", "typescript"],
2759
- sourceType: "unambiguous"
2760
- }), {
2761
- noScope: true,
2762
- StringLiteral(path) {
2763
- values.add(path.node.value);
2764
- },
2765
- TemplateElement(path) {
2766
- values.add(path.node.value.raw);
2767
- }
2768
- });
2769
- } catch {
2770
- return [];
2771
- }
2772
- const candidates = /* @__PURE__ */ new Set();
2773
- for (const value of values) {
2774
- const extractedCandidates = options.extractor ? await options.extractor(value, "html") : await (0, tailwindcss_patch.extractSourceCandidates)(value, "html", { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
2775
- for (const candidate of extractedCandidates) candidates.add(candidate);
2776
- }
2777
- return candidates;
2778
- }
2779
- //#endregion
2780
- //#region src/bundlers/vite/source-candidates/tailwind-v3-default-extractor.ts
2781
- const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
2782
- const TAILWIND_V3_HTML_TOKEN_CANDIDATES = new Set([
2783
- "/block",
2784
- "/div",
2785
- "/span",
2786
- "/template",
2787
- "/text",
2788
- "/view",
2789
- "class",
2790
- "className",
2791
- "div",
2792
- "hover-class",
2793
- "span",
2794
- "template",
2795
- "text",
2796
- "view"
2797
- ]);
2798
- function createTailwindV3DefaultExtractor() {
2799
- try {
2800
- const defaultExtractorModule = require$1("tailwindcss/lib/lib/defaultExtractor");
2801
- const resolveConfigModule = require$1("tailwindcss/resolveConfig");
2802
- const resolveConfig = resolveConfigModule.default ?? resolveConfigModule;
2803
- const extractor = (defaultExtractorModule.defaultExtractor ?? defaultExtractorModule.default ?? defaultExtractorModule)({ tailwindConfig: resolveConfig({ content: [] }) });
2804
- return (source) => new Set(extractor(source).filter((candidate) => !TAILWIND_V3_HTML_TOKEN_CANDIDATES.has(candidate)));
2805
- } catch {
2806
- return;
2807
- }
2808
- }
2809
- //#endregion
2810
3093
  //#region src/bundlers/vite/source-candidates.ts
2811
3094
  const CLEAN_URL_RE = /[?#].*$/;
2812
3095
  const sourceCandidateContentCache = new lru_cache.LRUCache({ max: 128 });
2813
3096
  function cleanUrl(id) {
2814
- return require_v3_engine.resolveSourceScanPath(id.replace(CLEAN_URL_RE, ""));
3097
+ return require_v4_engine.resolveSourceScanPath(id.replace(CLEAN_URL_RE, ""));
2815
3098
  }
2816
3099
  function resolveSourceCandidateExtension(id) {
2817
3100
  const normalized = cleanUrl(id);
@@ -2821,13 +3104,10 @@ function createSourceCandidateContentCacheKey(extension, source, bareArbitraryVa
2821
3104
  return `${extension}\0${JSON.stringify(bareArbitraryValues ?? false)}\0${extractor ? "custom" : "default"}\0${(0, _weapp_tailwindcss_shared_node.md5)(source)}`;
2822
3105
  }
2823
3106
  async function extractCandidates(source, extension, options) {
2824
- const candidates = options.extractor ? new Set(await options.extractor(source, extension)) : new Set(await (0, tailwindcss_patch.extractSourceCandidates)(source, extension, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } }));
2825
- const scriptCandidates = await extractScriptStringCandidates(source, extension, options);
2826
- for (const candidate of scriptCandidates) candidates.add(candidate);
2827
- return candidates;
3107
+ return extractCandidatesFromSource(source, extension, options);
2828
3108
  }
2829
3109
  function isSourceCandidateRequest(id) {
2830
- return require_v3_engine.FULL_SOURCE_SCAN_EXTENSION_RE.test(cleanUrl(id));
3110
+ return require_v4_engine.FULL_SOURCE_SCAN_EXTENSION_RE.test(cleanUrl(id));
2831
3111
  }
2832
3112
  function removeCandidateSet(candidateCount, candidates) {
2833
3113
  for (const candidate of candidates) {
@@ -2843,18 +3123,20 @@ function removeCandidateSet(candidateCount, candidates) {
2843
3123
  function addCandidateSet(candidateCount, candidates) {
2844
3124
  for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
2845
3125
  }
2846
- function createSourceCandidateCollector(options = {}) {
3126
+ function createSourceCandidateStore(options = {}) {
2847
3127
  const candidatesById = /* @__PURE__ */ new Map();
2848
3128
  const scanCandidatesById = /* @__PURE__ */ new Map();
2849
3129
  const transformCandidatesById = /* @__PURE__ */ new Map();
2850
3130
  const cssCandidatesById = /* @__PURE__ */ new Map();
2851
- const sourceById = /* @__PURE__ */ new Map();
3131
+ const scanSourceById = /* @__PURE__ */ new Map();
3132
+ const transformSourceById = /* @__PURE__ */ new Map();
3133
+ const cssSourceById = /* @__PURE__ */ new Map();
2852
3134
  const candidateCount = /* @__PURE__ */ new Map();
2853
3135
  let inlineIncludedCandidates = /* @__PURE__ */ new Set();
2854
3136
  let inlineExcludedCandidates = /* @__PURE__ */ new Set();
2855
3137
  async function sync(id, source) {
2856
3138
  const normalizedId = cleanUrl(id);
2857
- sourceById.set(normalizedId, source);
3139
+ scanSourceById.set(normalizedId, source);
2858
3140
  const extension = resolveSourceCandidateExtension(normalizedId);
2859
3141
  const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
2860
3142
  const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
@@ -2868,7 +3150,7 @@ function createSourceCandidateCollector(options = {}) {
2868
3150
  }
2869
3151
  async function syncCss(id, source) {
2870
3152
  const normalizedId = cleanUrl(id);
2871
- sourceById.set(normalizedId, source);
3153
+ cssSourceById.set(normalizedId, source);
2872
3154
  const contentCacheKey = createSourceCandidateContentCacheKey("css", source, options.bareArbitraryValues, options.extractor);
2873
3155
  const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
2874
3156
  if (cachedCandidates) {
@@ -2881,7 +3163,7 @@ function createSourceCandidateCollector(options = {}) {
2881
3163
  }
2882
3164
  async function merge(id, source) {
2883
3165
  const normalizedId = cleanUrl(id);
2884
- sourceById.set(normalizedId, source);
3166
+ transformSourceById.set(normalizedId, source);
2885
3167
  const extension = resolveSourceCandidateExtension(normalizedId);
2886
3168
  const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
2887
3169
  const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
@@ -2915,7 +3197,7 @@ function createSourceCandidateCollector(options = {}) {
2915
3197
  outDir,
2916
3198
  root
2917
3199
  });
2918
- await Promise.all(files.map((file) => syncFile(require_v3_engine.resolveSourceScanPath(file))));
3200
+ await Promise.all(files.map((file) => syncFile(require_v4_engine.resolveSourceScanPath(file))));
2919
3201
  }
2920
3202
  function replaceFinal(id, nextCandidates) {
2921
3203
  const normalizedId = cleanUrl(id);
@@ -2963,17 +3245,20 @@ function createSourceCandidateCollector(options = {}) {
2963
3245
  scanCandidatesById.delete(normalizedId);
2964
3246
  transformCandidatesById.delete(normalizedId);
2965
3247
  cssCandidatesById.delete(normalizedId);
2966
- sourceById.delete(normalizedId);
3248
+ scanSourceById.delete(normalizedId);
3249
+ transformSourceById.delete(normalizedId);
3250
+ cssSourceById.delete(normalizedId);
2967
3251
  const previousCandidates = candidatesById.get(normalizedId);
2968
3252
  if (!previousCandidates) return;
2969
3253
  removeCandidateSet(candidateCount, previousCandidates);
2970
3254
  candidatesById.delete(normalizedId);
2971
3255
  }
2972
3256
  function source(id) {
2973
- return sourceById.get(cleanUrl(id));
3257
+ const normalizedId = cleanUrl(id);
3258
+ return scanSourceById.get(normalizedId) ?? cssSourceById.get(normalizedId) ?? transformSourceById.get(normalizedId);
2974
3259
  }
2975
3260
  function sources() {
2976
- return sourceById.entries();
3261
+ return mergeSourcesByPriority().entries();
2977
3262
  }
2978
3263
  function values() {
2979
3264
  const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
@@ -2987,8 +3272,8 @@ function createSourceCandidateCollector(options = {}) {
2987
3272
  if (entries?.length === 0) return new Set(inlineIncludedCandidates);
2988
3273
  const filtered = /* @__PURE__ */ new Set();
2989
3274
  for (const [id, candidates] of candidatesById) {
2990
- if (entries !== void 0 && !require_v3_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
2991
- if (options.excludeEntries?.length && require_v3_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
3275
+ if (entries !== void 0 && !require_v4_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
3276
+ if (options.excludeEntries?.length && require_v4_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
2992
3277
  for (const candidate of candidates) filtered.add(candidate);
2993
3278
  }
2994
3279
  for (const candidate of inlineIncludedCandidates) filtered.add(candidate);
@@ -3011,8 +3296,8 @@ function createSourceCandidateCollector(options = {}) {
3011
3296
  return sources;
3012
3297
  }
3013
3298
  for (const [id, candidates] of candidatesById) {
3014
- if (entries !== void 0 && !require_v3_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
3015
- if (options.excludeEntries?.length && require_v3_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
3299
+ if (entries !== void 0 && !require_v4_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
3300
+ if (options.excludeEntries?.length && require_v4_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
3016
3301
  for (const candidate of candidates) addCandidateSource(candidate, id);
3017
3302
  }
3018
3303
  for (const candidate of inlineIncludedCandidates) addCandidateSource(candidate, void 0);
@@ -3024,7 +3309,9 @@ function createSourceCandidateCollector(options = {}) {
3024
3309
  scanCandidatesById.clear();
3025
3310
  transformCandidatesById.clear();
3026
3311
  cssCandidatesById.clear();
3027
- sourceById.clear();
3312
+ scanSourceById.clear();
3313
+ transformSourceById.clear();
3314
+ cssSourceById.clear();
3028
3315
  candidateCount.clear();
3029
3316
  inlineIncludedCandidates.clear();
3030
3317
  inlineExcludedCandidates.clear();
@@ -3045,9 +3332,12 @@ function createSourceCandidateCollector(options = {}) {
3045
3332
  return {
3046
3333
  candidatesById: [...candidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
3047
3334
  cssCandidatesById: [...cssCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
3335
+ cssSourceById: [...cssSourceById.entries()],
3048
3336
  scanCandidatesById: [...scanCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
3049
- sourceById: [...sourceById.entries()],
3337
+ scanSourceById: [...scanSourceById.entries()],
3338
+ sourceById: [...mergeSourcesByPriority().entries()],
3050
3339
  transformCandidatesById: [...transformCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
3340
+ transformSourceById: [...transformSourceById.entries()],
3051
3341
  inlineExcludedCandidates: [...inlineExcludedCandidates],
3052
3342
  inlineIncludedCandidates: [...inlineIncludedCandidates]
3053
3343
  };
@@ -3072,7 +3362,9 @@ function createSourceCandidateCollector(options = {}) {
3072
3362
  if (candidateSet.size === 0) continue;
3073
3363
  cssCandidatesById.set(id, candidateSet);
3074
3364
  }
3075
- for (const [id, source] of snapshot.sourceById ?? []) sourceById.set(id, source);
3365
+ for (const [id, source] of snapshot.scanSourceById ?? snapshot.sourceById ?? []) scanSourceById.set(id, source);
3366
+ for (const [id, source] of snapshot.transformSourceById ?? []) transformSourceById.set(id, source);
3367
+ for (const [id, source] of snapshot.cssSourceById ?? []) cssSourceById.set(id, source);
3076
3368
  const ids = new Set([
3077
3369
  ...scanCandidatesById.keys(),
3078
3370
  ...transformCandidatesById.keys(),
@@ -3081,6 +3373,7 @@ function createSourceCandidateCollector(options = {}) {
3081
3373
  for (const id of ids) recompute(id);
3082
3374
  }
3083
3375
  return {
3376
+ syncSource: sync,
3084
3377
  sync,
3085
3378
  syncCss,
3086
3379
  merge,
@@ -3100,6 +3393,16 @@ function createSourceCandidateCollector(options = {}) {
3100
3393
  resetScan,
3101
3394
  clear
3102
3395
  };
3396
+ function mergeSourcesByPriority() {
3397
+ const sources = /* @__PURE__ */ new Map();
3398
+ for (const [id, source] of transformSourceById) sources.set(id, source);
3399
+ for (const [id, source] of cssSourceById) sources.set(id, source);
3400
+ for (const [id, source] of scanSourceById) sources.set(id, source);
3401
+ return sources;
3402
+ }
3403
+ }
3404
+ function createSourceCandidateCollector(options = {}) {
3405
+ return createSourceCandidateStore(options);
3103
3406
  }
3104
3407
  //#endregion
3105
3408
  //#region src/bundlers/shared/hmr-timing.ts
@@ -3186,12 +3489,24 @@ Object.defineProperty(exports, "annotateCssSourceTrace", {
3186
3489
  return annotateCssSourceTrace;
3187
3490
  }
3188
3491
  });
3492
+ Object.defineProperty(exports, "collectStrictEscapedRuntimeCandidates", {
3493
+ enumerable: true,
3494
+ get: function() {
3495
+ return collectStrictEscapedRuntimeCandidates;
3496
+ }
3497
+ });
3189
3498
  Object.defineProperty(exports, "createBundleRuntimeClassSetManager", {
3190
3499
  enumerable: true,
3191
3500
  get: function() {
3192
3501
  return createBundleRuntimeClassSetManager;
3193
3502
  }
3194
3503
  });
3504
+ Object.defineProperty(exports, "createCssSourceOrderAppend", {
3505
+ enumerable: true,
3506
+ get: function() {
3507
+ return createCssSourceOrderAppend$1;
3508
+ }
3509
+ });
3195
3510
  Object.defineProperty(exports, "createCssSourceTraceCacheSignature", {
3196
3511
  enumerable: true,
3197
3512
  get: function() {
@@ -3204,6 +3519,12 @@ Object.defineProperty(exports, "createCssTokenSourceMap", {
3204
3519
  return createCssTokenSourceMap;
3205
3520
  }
3206
3521
  });
3522
+ Object.defineProperty(exports, "createEscapeFragments", {
3523
+ enumerable: true,
3524
+ get: function() {
3525
+ return createEscapeFragments;
3526
+ }
3527
+ });
3207
3528
  Object.defineProperty(exports, "createHmrTimingRecorder", {
3208
3529
  enumerable: true,
3209
3530
  get: function() {
@@ -3216,10 +3537,10 @@ Object.defineProperty(exports, "createSourceCandidateCollector", {
3216
3537
  return createSourceCandidateCollector;
3217
3538
  }
3218
3539
  });
3219
- Object.defineProperty(exports, "createTailwindV3DefaultExtractor", {
3540
+ Object.defineProperty(exports, "createSourceCandidateStore", {
3220
3541
  enumerable: true,
3221
3542
  get: function() {
3222
- return createTailwindV3DefaultExtractor;
3543
+ return createSourceCandidateStore;
3223
3544
  }
3224
3545
  });
3225
3546
  Object.defineProperty(exports, "emitHmrTiming", {
@@ -3240,6 +3561,12 @@ Object.defineProperty(exports, "generateCssByGenerator", {
3240
3561
  return generateCssByGenerator;
3241
3562
  }
3242
3563
  });
3564
+ Object.defineProperty(exports, "hasMiniProgramTailwindV4PreflightReset", {
3565
+ enumerable: true,
3566
+ get: function() {
3567
+ return hasMiniProgramTailwindV4PreflightReset;
3568
+ }
3569
+ });
3243
3570
  Object.defineProperty(exports, "isCssSourceTraceEnabled", {
3244
3571
  enumerable: true,
3245
3572
  get: function() {
@@ -3276,12 +3603,66 @@ Object.defineProperty(exports, "pushConcurrentTaskFactories", {
3276
3603
  return pushConcurrentTaskFactories;
3277
3604
  }
3278
3605
  });
3606
+ Object.defineProperty(exports, "removeMiniProgramHoverSelectors", {
3607
+ enumerable: true,
3608
+ get: function() {
3609
+ return removeMiniProgramHoverSelectors;
3610
+ }
3611
+ });
3612
+ Object.defineProperty(exports, "removeTailwindV4GeneratorAtRules", {
3613
+ enumerable: true,
3614
+ get: function() {
3615
+ return removeTailwindV4GeneratorAtRules;
3616
+ }
3617
+ });
3618
+ Object.defineProperty(exports, "resolveSourceCandidateScanFiles", {
3619
+ enumerable: true,
3620
+ get: function() {
3621
+ return resolveSourceCandidateScanFiles;
3622
+ }
3623
+ });
3624
+ Object.defineProperty(exports, "resolveTaskConcurrency", {
3625
+ enumerable: true,
3626
+ get: function() {
3627
+ return resolveTaskConcurrency;
3628
+ }
3629
+ });
3630
+ Object.defineProperty(exports, "rewriteLocalCssImportRequestsForOutput", {
3631
+ enumerable: true,
3632
+ get: function() {
3633
+ return rewriteLocalCssImportRequestsForOutput;
3634
+ }
3635
+ });
3279
3636
  Object.defineProperty(exports, "runWithConcurrency", {
3280
3637
  enumerable: true,
3281
3638
  get: function() {
3282
3639
  return runWithConcurrency;
3283
3640
  }
3284
3641
  });
3642
+ Object.defineProperty(exports, "scoreTailwindV4CssSourceFileMatch", {
3643
+ enumerable: true,
3644
+ get: function() {
3645
+ return scoreTailwindV4CssSourceFileMatch;
3646
+ }
3647
+ });
3648
+ Object.defineProperty(exports, "splitLocalCssImports", {
3649
+ enumerable: true,
3650
+ get: function() {
3651
+ return splitLocalCssImports;
3652
+ }
3653
+ });
3654
+ Object.defineProperty(exports, "stripTailwindSourceMediaFragments", {
3655
+ enumerable: true,
3656
+ get: function() {
3657
+ return stripTailwindSourceMediaFragments;
3658
+ }
3659
+ });
3660
+ Object.defineProperty(exports, "stripUnmatchedTailwindSourceMediaCloseFragments", {
3661
+ enumerable: true,
3662
+ get: function() {
3663
+ return stripUnmatchedTailwindSourceMediaCloseFragments;
3664
+ }
3665
+ });
3285
3666
  Object.defineProperty(exports, "validateCandidatesByGenerator", {
3286
3667
  enumerable: true,
3287
3668
  get: function() {