weapp-tailwindcss 5.1.14 → 5.1.16

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 (149) hide show
  1. package/dist/auto-2dg_uhEJ.mjs +13 -0
  2. package/dist/bundlers/gulp/frameworks/native/index.d.ts +2 -0
  3. package/dist/bundlers/gulp/index.d.ts +2 -0
  4. package/dist/bundlers/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
  5. package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
  6. package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +4 -2
  7. package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
  8. package/dist/bundlers/shared/generated-css-marker.d.ts +2 -2
  9. package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
  10. package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
  11. package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
  12. package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
  14. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
  15. package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -1
  16. package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
  17. package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
  18. package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
  19. package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
  20. package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
  21. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
  22. package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
  23. package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
  24. package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +2 -0
  25. package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
  26. package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
  27. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
  28. package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
  29. package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
  30. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
  31. package/dist/bundlers/shared/generator-css/types.d.ts +5 -0
  32. package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
  33. package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
  34. package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
  35. package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
  36. package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
  37. package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
  38. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
  39. package/dist/bundlers/shared/generator-css.d.ts +1 -2
  40. package/dist/bundlers/shared/style-requests.d.ts +1 -0
  41. package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
  42. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  43. package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
  44. package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
  45. package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
  46. package/dist/bundlers/vite/generate-bundle/bundle-markup-candidates.d.ts +20 -0
  47. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
  48. package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
  49. package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
  50. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
  51. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
  52. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
  53. package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +1 -0
  54. package/dist/bundlers/vite/generate-bundle/types.d.ts +5 -0
  55. package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
  56. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  57. package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
  58. package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
  59. package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
  60. package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
  61. package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
  62. package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
  63. package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
  64. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  65. package/dist/bundlers/vite/serve-css-generation.d.ts +4 -2
  66. package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
  67. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +5 -4
  68. package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
  69. package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
  70. package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
  71. package/dist/bundlers/vite/source-candidates.d.ts +4 -68
  72. package/dist/bundlers/vite/watch-css-post.d.ts +10 -0
  73. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
  74. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +1 -0
  75. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
  76. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
  77. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
  78. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
  79. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
  80. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
  81. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
  82. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
  83. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
  84. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
  85. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
  86. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
  87. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
  88. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -217
  89. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
  90. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
  91. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +6 -0
  92. package/dist/bundlers/webpack/loaders/weapp-tw-css-generation-loader.d.ts +4 -0
  93. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -0
  94. package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
  95. package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
  96. package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
  97. package/dist/cli.js +14 -18
  98. package/dist/cli.mjs +14 -18
  99. package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
  100. package/dist/{context-BL8Gy71H.mjs → context-JzwzSX36.mjs} +3 -3
  101. package/dist/core.js +1 -1
  102. package/dist/core.mjs +1 -1
  103. package/dist/css-macro.mjs +1 -1
  104. package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
  105. package/dist/{generator-B59OA64h.mjs → generator-Bv7myuhY.mjs} +557 -432
  106. package/dist/generator.js +1 -1
  107. package/dist/generator.mjs +1 -1
  108. package/dist/{gulp-DUYWxmZC.mjs → gulp-CKSklPlH.mjs} +218 -153
  109. package/dist/{gulp-C1Q3LRzg.js → gulp-Q1wITegn.js} +218 -153
  110. package/dist/gulp.js +1 -1
  111. package/dist/gulp.mjs +1 -1
  112. package/dist/{hmr-timing-C3ed5vCx.mjs → hmr-timing-BXg7nI8N.mjs} +3406 -3145
  113. package/dist/{hmr-timing-BZ5sWIqO.js → hmr-timing-CMPaWn9P.js} +3474 -3147
  114. package/dist/index.js +4 -4
  115. package/dist/index.mjs +4 -4
  116. package/dist/postcss.js +1 -1
  117. package/dist/postcss.mjs +1 -1
  118. package/dist/presets.js +1 -1
  119. package/dist/presets.mjs +1 -1
  120. package/dist/rspack.js +1 -1
  121. package/dist/rspack.mjs +1 -1
  122. package/dist/shared/mpx-plugin-owner.d.ts +2 -0
  123. package/dist/shared/mpx.d.ts +4 -1
  124. package/dist/{source-candidate-scan-signature-R3dzamcm.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -96
  125. package/dist/{source-candidate-scan-signature-D7RWjWsY.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -60
  126. package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
  127. package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
  128. package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
  129. package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
  130. package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
  131. package/dist/{tailwindcss-DPcKMLxL.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
  132. package/dist/{transform-D5JUgMpE.mjs → transform-B_KM9sLX.mjs} +47 -5
  133. package/dist/{transform-COFRlmDF.js → transform-CcYptivi.js} +47 -5
  134. package/dist/uni-app-x/component-local-style.d.ts +1 -0
  135. package/dist/uni-app-x/style-asset/style-value.d.ts +1 -1
  136. package/dist/{vite-CBU5NXTX.mjs → vite-BwQWl9ft.mjs} +1269 -878
  137. package/dist/{vite-BNlPdsGM.js → vite-DhVnXvAQ.js} +1314 -923
  138. package/dist/vite.js +1 -1
  139. package/dist/vite.mjs +1 -1
  140. package/dist/weapp-tw-css-generation-loader.js +12 -0
  141. package/dist/weapp-tw-css-import-rewrite-loader-B0tVkJLH.js +10524 -0
  142. package/dist/weapp-tw-css-import-rewrite-loader.js +6 -10255
  143. package/dist/weapp-tw-runtime-classset-loader.js +10 -4
  144. package/dist/{webpack-CZ38fMGC.mjs → webpack-Bo1QrFPf.mjs} +1518 -1079
  145. package/dist/{webpack-Jpe048pQ.js → webpack-kh78iMSS.js} +1519 -1080
  146. package/dist/webpack.js +1 -1
  147. package/dist/webpack.mjs +1 -1
  148. package/package.json +17 -7
  149. package/dist/auto-CrJJc5rK.mjs +0 -13
@@ -1,12 +1,12 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.js");
2
- const require_generator = require("./generator-CEnUsjed.js");
3
- const require_tailwindcss = require("./tailwindcss-KBYPJ2DW.js");
2
+ const require_generator = require("./generator-B91GhUJQ.js");
3
+ const require_tailwindcss = require("./tailwindcss-B4phC0kB.js");
4
4
  const require_utils = require("./utils-CuKLf1Zv.js");
5
5
  const require_wxml = require("./wxml-Ce10eREX.js");
6
- const require_context = require("./context-VeFq_8vW.js");
6
+ const require_context = require("./context-BtLIID4m.js");
7
7
  const require_defaults = require("./defaults.js");
8
- const require_hmr_timing = require("./hmr-timing-BZ5sWIqO.js");
9
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-R3dzamcm.js");
8
+ const require_hmr_timing = require("./hmr-timing-CMPaWn9P.js");
9
+ const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BKZZk_e6.js");
10
10
  let node_fs = require("node:fs");
11
11
  node_fs = require_rolldown_runtime.__toESM(node_fs);
12
12
  let node_path = require("node:path");
@@ -27,13 +27,13 @@ function getCacheKey(filename) {
27
27
  }
28
28
  function stripResourceQuery(resource) {
29
29
  if (typeof resource !== "string") return resource;
30
- return require_source_candidate_scan_signature.stripRequestQuery(resource);
30
+ return require_hmr_timing.stripRequestQuery(resource);
31
31
  }
32
32
  function isCssLikeModuleResource(resource, cssMatcher) {
33
33
  if (typeof resource !== "string") return false;
34
34
  const normalizedResource = stripResourceQuery(resource);
35
35
  if (normalizedResource && cssMatcher(normalizedResource)) return true;
36
- if (require_source_candidate_scan_signature.isSourceStyleRequest(resource)) return true;
36
+ if (require_hmr_timing.isSourceStyleRequest(resource)) return true;
37
37
  return false;
38
38
  }
39
39
  function hasLoaderEntry(entries, target) {
@@ -73,17 +73,27 @@ function resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAsse
73
73
  const activeAssetResourceMatches = [...assetResources ?? []].map((sourceFile) => node_path.default.resolve(sourceFile)).filter((sourceFile) => activeWebpackAssetResourceFiles.has(sourceFile)).sort();
74
74
  return activeAssetResourceMatches.length === 1 ? activeAssetResourceMatches[0] : void 0;
75
75
  }
76
- function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
76
+ function resolveWebpackCssModuleIdentifierResource(module) {
77
+ if (!module.type?.startsWith("css/") || typeof module.identifier !== "function") return;
78
+ const identifier = module.identifier();
79
+ const request = identifier.startsWith("css|") ? identifier.slice(4) : identifier;
80
+ const resourceWithMetadata = request.slice(request.lastIndexOf("!") + 1);
81
+ const metadataIndex = resourceWithMetadata.indexOf("|");
82
+ return metadataIndex === -1 ? resourceWithMetadata : resourceWithMetadata.slice(0, metadataIndex);
83
+ }
84
+ function createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, onlyUnambiguousCssAssets) {
77
85
  const resourcesByAsset = /* @__PURE__ */ new Map();
78
86
  if (!chunkGraph?.getChunkModulesIterable) return resourcesByAsset;
79
87
  const collectModuleResources = (module, resources, seen = /* @__PURE__ */ new Set()) => {
80
88
  if (!module || seen.has(module)) return;
81
89
  seen.add(module);
82
- for (const candidate of [
90
+ const candidates = [
83
91
  module.resource,
84
92
  module.request,
85
93
  module.userRequest
86
- ]) {
94
+ ];
95
+ if (onlyUnambiguousCssAssets) candidates.push(resolveWebpackCssModuleIdentifierResource(module));
96
+ for (const candidate of candidates) {
87
97
  if (typeof candidate !== "string") continue;
88
98
  const normalized = normalizeResource(candidate, module);
89
99
  if (normalized) resources.add(normalized);
@@ -103,7 +113,7 @@ function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normal
103
113
  };
104
114
  for (const chunk of chunks) {
105
115
  const cssFiles = toChunkFiles(chunk.files).filter((file) => cssMatcher(file));
106
- if (cssFiles.length === 0) continue;
116
+ if (cssFiles.length === 0 || onlyUnambiguousCssAssets && cssFiles.length !== 1) continue;
107
117
  const modules = chunkGraph.getChunkModulesIterable(chunk);
108
118
  if (!modules) continue;
109
119
  const cssResources = /* @__PURE__ */ new Set();
@@ -113,6 +123,12 @@ function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normal
113
123
  }
114
124
  return resourcesByAsset;
115
125
  }
126
+ function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
127
+ return createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, false);
128
+ }
129
+ function createWebpackDirectCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
130
+ return createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, true);
131
+ }
116
132
  function createAssetHashByChunkMap(chunks) {
117
133
  const partsByFile = /* @__PURE__ */ new Map();
118
134
  for (const chunk of chunks) {
@@ -143,13 +159,243 @@ function isWatchFileInRuntimeDependencies(file, dependencies) {
143
159
  return false;
144
160
  }
145
161
  //#endregion
146
- //#region src/bundlers/webpack/shared/css-loader-runtime.ts
147
- function isWebpackCssLoaderRuntimeSource(source) {
148
- return source.includes("___CSS_LOADER_EXPORT___") && source.includes("___CSS_LOADER_API_IMPORT___") && source.includes("module.exports = ___CSS_LOADER_EXPORT___");
162
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.ts
163
+ function isRuntimeTransformCandidate(candidate) {
164
+ return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
165
+ }
166
+ //#endregion
167
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.ts
168
+ function collectWebpackAssetUserCssMarkers(source) {
169
+ const markers = /* @__PURE__ */ new Set();
170
+ for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
171
+ for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
172
+ try {
173
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
174
+ root.walkRules((rule) => {
175
+ for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
176
+ rule.walkDecls((decl) => {
177
+ if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
178
+ });
179
+ });
180
+ root.walkAtRules("font-face", (rule) => {
181
+ rule.walkDecls("font-family", (decl) => {
182
+ markers.add(`font-face:${decl.value.trim()}`);
183
+ });
184
+ });
185
+ } catch {}
186
+ return markers;
149
187
  }
150
188
  //#endregion
151
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.ts
152
- const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
189
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.ts
190
+ const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = /* @__PURE__ */ new Set([
191
+ "theme",
192
+ "base",
193
+ "utilities"
194
+ ]);
195
+ const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
196
+ const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
197
+ const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
198
+ const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
199
+ "*",
200
+ ":after",
201
+ ":before",
202
+ "::after",
203
+ "::before",
204
+ "::backdrop",
205
+ "view",
206
+ "text"
207
+ ]);
208
+ const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
209
+ "box-sizing",
210
+ "border",
211
+ "border-width",
212
+ "border-style",
213
+ "border-color",
214
+ "margin",
215
+ "padding"
216
+ ]);
217
+ const WEBPACK_TAILWIND_THEME_TOKEN_RE = /^--(?:tw-|color-|spacing|breakpoint-|container-|text-|font-|tracking-|leading-|radius-|shadow-|inset-shadow-|drop-shadow-|ease-|animate-|blur-|perspective-|aspect-|default-)/;
218
+ function parseWebpackCssLayerNames(params) {
219
+ return params.split(",").map((name) => name.trim()).filter(Boolean);
220
+ }
221
+ function removeWebpackTailwindGeneratedAssetCss(source) {
222
+ const cleaned = require_generator.removeTailwindV4GeneratedUserCssArtifacts(source);
223
+ try {
224
+ const root = _weapp_tailwindcss_postcss.postcss.parse(cleaned);
225
+ let changed = false;
226
+ let removingBannerPrefix = false;
227
+ for (const node of [...root.nodes]) {
228
+ if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
229
+ node.remove();
230
+ changed = true;
231
+ removingBannerPrefix = true;
232
+ continue;
233
+ }
234
+ if (!removingBannerPrefix) continue;
235
+ if (isWebpackTailwindGeneratedPrefixNode(node)) {
236
+ node.remove();
237
+ changed = true;
238
+ continue;
239
+ }
240
+ removingBannerPrefix = false;
241
+ }
242
+ root.walkAtRules("layer", (rule) => {
243
+ const names = parseWebpackCssLayerNames(rule.params);
244
+ const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
245
+ const isLayerDeclaration = rule.nodes === void 0;
246
+ const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
247
+ if (shouldRemoveLayer && isLayerDeclaration) {
248
+ rule.remove();
249
+ changed = true;
250
+ return;
251
+ }
252
+ if (shouldRemoveLayer && !names.includes("utilities")) {
253
+ for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
254
+ child.remove();
255
+ changed = true;
256
+ }
257
+ if (rule.nodes?.length === 0) {
258
+ rule.remove();
259
+ changed = true;
260
+ }
261
+ return;
262
+ }
263
+ if (shouldRemoveLayer) {
264
+ for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
265
+ child.remove();
266
+ changed = true;
267
+ }
268
+ if (rule.nodes?.length === 0) {
269
+ rule.remove();
270
+ changed = true;
271
+ }
272
+ }
273
+ });
274
+ root.walkRules((rule) => {
275
+ if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
276
+ const selector = rule.selector.trim();
277
+ if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
278
+ rule.remove();
279
+ changed = true;
280
+ }
281
+ });
282
+ root.walkComments((comment) => {
283
+ if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
284
+ comment.remove();
285
+ changed = true;
286
+ }
287
+ });
288
+ root.walkAtRules((rule) => {
289
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) {
290
+ rule.remove();
291
+ changed = true;
292
+ }
293
+ });
294
+ return changed ? root.toString() : cleaned;
295
+ } catch {
296
+ return cleaned;
297
+ }
298
+ }
299
+ function isWebpackTailwindGeneratedPrefixNode(node) {
300
+ if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
301
+ "theme",
302
+ "base",
303
+ "utilities"
304
+ ], true);
305
+ if (node.type !== "atrule") return false;
306
+ const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
307
+ if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
308
+ if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
309
+ if (node.nodes === void 0) return true;
310
+ return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
311
+ }
312
+ if (node.nodes === void 0 || node.nodes.length === 0) return false;
313
+ return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
314
+ }
315
+ function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
316
+ if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
317
+ if (node.type !== "atrule") return false;
318
+ if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
319
+ if (node.nodes === void 0 || node.nodes.length === 0) return false;
320
+ return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
321
+ }
322
+ function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
323
+ const selectors = rule.selectors ?? [rule.selector];
324
+ if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
325
+ if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
326
+ if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
327
+ if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
328
+ return false;
329
+ }
330
+ function isWebpackTailwindGeneratedThemeRule(rule) {
331
+ const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
332
+ return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
333
+ }
334
+ function isWebpackTailwindGeneratedPreflightRule(rule) {
335
+ const selectors = rule.selectors ?? [rule.selector];
336
+ const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
337
+ return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
338
+ const normalized = selector.trim().replace(/\s+/g, " ");
339
+ return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
340
+ }) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
341
+ }
342
+ function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
343
+ try {
344
+ const nodes = _weapp_tailwindcss_postcss.postcss.parse(source).nodes ?? [];
345
+ return nodes.length > 0 && nodes.every((node) => {
346
+ if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
347
+ return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
348
+ });
349
+ } catch {
350
+ return false;
351
+ }
352
+ }
353
+ function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
354
+ return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
355
+ }
356
+ function collectWebpackCssRuleIdentityMarkers(source) {
357
+ const markers = /* @__PURE__ */ new Set();
358
+ try {
359
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
360
+ root.walkRules((rule) => {
361
+ for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
362
+ });
363
+ root.walkAtRules("keyframes", (rule) => {
364
+ if (rule.params) markers.add(`keyframes:${rule.params}`);
365
+ });
366
+ } catch {}
367
+ return markers;
368
+ }
369
+ function unescapeCssIdentifier(value) {
370
+ return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
371
+ const hex = escaped.trim();
372
+ if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
373
+ return escaped;
374
+ });
375
+ }
376
+ function collectGeneratedCssRuntimeCandidates(source) {
377
+ const candidates = /* @__PURE__ */ new Set();
378
+ if (require_hmr_timing.hasBundlerGeneratedCssMarker(source) || !require_generator.hasTailwindGeneratedCss(source) && !require_generator.hasTailwindGeneratedCssMarkers(source)) return candidates;
379
+ try {
380
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
381
+ for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
382
+ const candidate = unescapeCssIdentifier(match[1]);
383
+ if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
384
+ }
385
+ });
386
+ } catch {}
387
+ return candidates;
388
+ }
389
+ function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
390
+ const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
391
+ if (rawMarkers.size === 0) return false;
392
+ const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
393
+ for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
394
+ return false;
395
+ }
396
+ function hasWebpackTailwindSourceDirectives(source) {
397
+ return Boolean(source) && (require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source) || require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source));
398
+ }
153
399
  function resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) {
154
400
  return styleOptions.cssPreflight ?? compilerOptions.cssPreflight ?? require_defaults.getDefaultCssPreflight();
155
401
  }
@@ -259,9 +505,6 @@ function removeTailwindV4StandaloneHostPreflightRule(source) {
259
505
  return source;
260
506
  }
261
507
  }
262
- function isRuntimeTransformCandidate(candidate) {
263
- return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
264
- }
265
508
  function collectRuntimeTokenSignatureParts(source) {
266
509
  return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
267
510
  }
@@ -305,25 +548,247 @@ function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandl
305
548
  const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
306
549
  for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
307
550
  for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
308
- pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
309
- pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
310
- }
311
- function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
312
- const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
313
- if (sourceCss && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss) || require_generator.hasTailwindGeneratedCss(sourceCss) || require_generator.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
314
- return rawSource;
315
- }
316
- function shouldConsumeWebpackLoaderGeneratedCss(options) {
317
- if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
318
- if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && (hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) || hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates))) return false;
319
- return options.hasBundlerGeneratedCssMarker;
320
- }
321
- function hasUsableWebpackGeneratorCssSources(cssSources) {
322
- return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
551
+ pruneMapToMaxSize(cssHandlerOptionsCache, 128);
552
+ pruneMapToMaxSize(cssUserHandlerOptionsCache, 128);
323
553
  }
324
- function normalizeWebpackGeneratorCssSources(cssSources) {
325
- if (!Array.isArray(cssSources)) return;
326
- const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
554
+ //#endregion
555
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.ts
556
+ function resolveWebpackMemoryDebugStats(context) {
557
+ if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
558
+ const memory = node_process.default.memoryUsage();
559
+ const processCacheInstanceSize = context.cache.instance.size;
560
+ const processCacheHashMapSize = context.cache.hashMap.size;
561
+ return {
562
+ phase: context.phase,
563
+ process: {
564
+ rssMb: toMb(memory.rss),
565
+ heapTotalMb: toMb(memory.heapTotal),
566
+ heapUsedMb: toMb(memory.heapUsed),
567
+ externalMb: toMb(memory.external),
568
+ arrayBuffersMb: toMb(memory.arrayBuffers)
569
+ },
570
+ assets: {
571
+ active: context.activeAssetFiles,
572
+ activeCss: context.activeCssFiles
573
+ },
574
+ processCache: {
575
+ instance: processCacheInstanceSize,
576
+ hashMap: processCacheHashMapSize,
577
+ activeCacheKeys: context.activeProcessCacheKeys.size,
578
+ activeHashKeys: context.activeProcessHashKeys.size,
579
+ staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
580
+ staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
581
+ pruned: true,
582
+ pruneSkipped: false
583
+ },
584
+ webpackCss: {
585
+ handlerOptions: context.cssHandlerOptionsCache.size,
586
+ userHandlerOptions: context.cssUserHandlerOptionsCache.size,
587
+ maxHandlerOptions: 128
588
+ },
589
+ sourceCandidateScan: context.sourceCandidateScan,
590
+ tailwind: { v4: require_generator.getTailwindV4IncrementalGenerateCacheStats() }
591
+ };
592
+ }
593
+ function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
594
+ if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
595
+ return cssHandlerOptions.isMainChunk !== false;
596
+ }
597
+ function includesTailwindPreflightImport(source) {
598
+ if (!source) return false;
599
+ try {
600
+ let includesPreflight = false;
601
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules((rule) => {
602
+ if (rule.name === "tailwind") {
603
+ includesPreflight || (includesPreflight = rule.params.trim() === "base");
604
+ return;
605
+ }
606
+ if (rule.name !== "import") return;
607
+ const request = require_generator.parseImportRequest(rule.params)?.replaceAll("\\", "/");
608
+ includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
609
+ });
610
+ return includesPreflight;
611
+ } catch {
612
+ return false;
613
+ }
614
+ }
615
+ function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
616
+ const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
617
+ if (isWebGeneratorTarget) return source;
618
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_generator.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
619
+ cssPreflight: options.cssPreflight === false ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
620
+ isTailwindcssV4: true,
621
+ tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
622
+ })));
623
+ }
624
+ function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
625
+ return !require_generator.hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
626
+ }
627
+ //#endregion
628
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.ts
629
+ function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
630
+ if (options.finalized === true) return options.annotateCss(css);
631
+ if (options.isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
632
+ const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
633
+ return options.annotateCss(finalized);
634
+ }
635
+ function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
636
+ const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
637
+ if (isWebGeneratorTarget) {
638
+ if (options.generatedCss === true) return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_hmr_timing.stripBundlerGeneratedCssMarkers(source))));
639
+ return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
640
+ }
641
+ let finalized = require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
642
+ if (options.generatedCss !== true) {
643
+ finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
644
+ cssPreflight: false,
645
+ isTailwindcssV4: true,
646
+ tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
647
+ });
648
+ finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
649
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
650
+ }
651
+ try {
652
+ finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: options.cssPreflight !== false });
653
+ } catch {}
654
+ const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
655
+ if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
656
+ const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
657
+ finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
658
+ cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
659
+ isTailwindcssV4: true,
660
+ tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
661
+ });
662
+ finalized = ensureWebpackMiniProgramTwContentInit(finalized);
663
+ if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
664
+ else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
665
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
666
+ }
667
+ function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
668
+ if (isWebGeneratorTarget) return source;
669
+ const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
670
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors((0, _weapp_tailwindcss_postcss.dedupeCoveredCssRules)(dedupeMiniProgramPreflightSelectorRules(source)), styleOptions.cssRemoveHoverPseudoClass));
671
+ }
672
+ function collectWebpackJsRuntimeCandidatesFromAssets(options) {
673
+ if (options.isWebGeneratorTarget) return;
674
+ const candidates = /* @__PURE__ */ new Set();
675
+ for (const file of options.jsAssets) {
676
+ const sourceLike = options.getAssetSource(file);
677
+ if (sourceLike === void 0) continue;
678
+ const source = stringifyWebpackSourceLike(sourceLike);
679
+ for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
680
+ }
681
+ return candidates;
682
+ }
683
+ function collectWebpackJsRuntimeTokenSignature(options) {
684
+ if (options.isWebGeneratorTarget) return "";
685
+ const tokens = [];
686
+ for (const file of options.jsAssets) {
687
+ const sourceLike = options.getAssetSource(file);
688
+ if (sourceLike === void 0) continue;
689
+ tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
690
+ }
691
+ return tokens.sort().join("\n");
692
+ }
693
+ function addRuntimeTransformCandidates(target, candidates) {
694
+ if (!candidates?.size) return;
695
+ for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
696
+ }
697
+ function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
698
+ if (!require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
699
+ return require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
700
+ }
701
+ function stringifyOptionalWebpackSourceValue(value) {
702
+ return typeof value === "string" ? value : value?.toString() ?? "";
703
+ }
704
+ function stringifyWebpackSourceLike(source) {
705
+ if (typeof source === "string") return source;
706
+ const value = source.source();
707
+ return typeof value === "string" ? value : value.toString();
708
+ }
709
+ //#endregion
710
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.ts
711
+ function isWindowsAbsoluteResourcePath(file) {
712
+ return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
713
+ }
714
+ function isPosixAbsoluteResourcePath(file) {
715
+ return file.startsWith("/");
716
+ }
717
+ function resolveWebpackResourcePath(file, base) {
718
+ if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.resolve(file);
719
+ if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.resolve(file);
720
+ if (base) {
721
+ if (isWindowsAbsoluteResourcePath(base)) return node_path.default.win32.resolve(base, file);
722
+ if (isPosixAbsoluteResourcePath(base)) return node_path.default.posix.resolve(base, file);
723
+ return node_path.default.resolve(base, file);
724
+ }
725
+ }
726
+ function dirnameWebpackResourcePath(file) {
727
+ if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.dirname(file);
728
+ if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.dirname(file);
729
+ return node_path.default.dirname(file);
730
+ }
731
+ function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
732
+ if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
733
+ const normalized = stripResourceQuery(resource);
734
+ if (!normalized) return;
735
+ const absoluteResource = resolveWebpackResourcePath(normalized);
736
+ if (absoluteResource) return absoluteResource;
737
+ const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
738
+ const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
739
+ return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
740
+ }
741
+ function isSameWebpackCssSourceScope(options) {
742
+ if (!options.currentSourceFile) return false;
743
+ const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? node_path.default.resolve(options.candidateSourceFile);
744
+ if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? node_path.default.resolve(options.currentSourceFile))) return true;
745
+ const outputResources = options.resourcesByAsset.get(options.outputFile);
746
+ if (!outputResources) return false;
747
+ return [...outputResources].some((resource) => {
748
+ return (resolveWebpackResourcePath(resource) ?? node_path.default.resolve(resource)) === candidateKey;
749
+ });
750
+ }
751
+ function shouldAppendCurrentWebpackAssetUserCss(options) {
752
+ const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
753
+ return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
754
+ }
755
+ function createWebpackCurrentAssetUserRawSource(options) {
756
+ if (!options.shouldAppendCurrentAssetUserCss) return;
757
+ if (options.sourceCssProcessed) return {
758
+ css: options.currentAssetUserCssSource,
759
+ processed: true
760
+ };
761
+ if (!options.currentAssetHasUserCss) return;
762
+ return {
763
+ css: options.currentAssetUserCssSource,
764
+ processed: options.currentAssetLooksGenerated
765
+ };
766
+ }
767
+ //#endregion
768
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.ts
769
+ function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
770
+ const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
771
+ if (sourceCss && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss) || require_generator.hasTailwindGeneratedCss(sourceCss) || require_generator.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
772
+ return rawSource;
773
+ }
774
+ function shouldConsumeWebpackLoaderGeneratedCss(options) {
775
+ if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
776
+ if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
777
+ if (options.hasBundlerGeneratedCssMarker) return true;
778
+ if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
779
+ return Boolean(options.allowMarkerlessRegistryMatch && options.loaderGeneratedClassSet && options.sourceCandidates && !hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) && !hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates));
780
+ }
781
+ function hasDeferredWebpackGeneratedCss(source, generatedClassSets) {
782
+ const selectors = require_hmr_timing.collectRawSourceClassSelectors(source);
783
+ for (const classSet of generatedClassSets) for (const candidate of classSet) if (selectors.has(candidate)) return true;
784
+ return false;
785
+ }
786
+ function hasUsableWebpackGeneratorCssSources(cssSources) {
787
+ return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
788
+ }
789
+ function normalizeWebpackGeneratorCssSources(cssSources) {
790
+ if (!Array.isArray(cssSources)) return;
791
+ const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
327
792
  return normalized.length > 0 ? normalized : void 0;
328
793
  }
329
794
  function scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, options = {}) {
@@ -372,26 +837,6 @@ function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource,
372
837
  const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
373
838
  return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !require_generator.hasTailwindRootDirectives(rawSource, { importFallback: true }) && !require_generator.hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !require_generator.hasTailwindApplyDirective(rawSource) && rawMarkers.size > 0 && !isOnlyWebpackTailwindGeneratedPreflightCss(rawSource) && (!require_generator.hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
374
839
  }
375
- function collectWebpackAssetUserCssMarkers(source) {
376
- const markers = /* @__PURE__ */ new Set();
377
- for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
378
- for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
379
- try {
380
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
381
- root.walkRules((rule) => {
382
- for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
383
- rule.walkDecls((decl) => {
384
- if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
385
- });
386
- });
387
- root.walkAtRules("font-face", (rule) => {
388
- rule.walkDecls("font-family", (decl) => {
389
- markers.add(`font-face:${decl.value.trim()}`);
390
- });
391
- });
392
- } catch {}
393
- return markers;
394
- }
395
840
  function hasWebpackClassSelector(selector) {
396
841
  return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
397
842
  }
@@ -405,7 +850,8 @@ function isWebpackKeyframesRule(rule) {
405
850
  }
406
851
  function collectWebpackBareSelectorUserCss(source) {
407
852
  try {
408
- const root = _weapp_tailwindcss_postcss.postcss.parse(require_generator.removeTailwindSourceDirectives(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(source)), { importFallback: true }));
853
+ const normalizedSource = require_generator.removeTailwindSourceDirectives(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(source)), { importFallback: true });
854
+ const root = _weapp_tailwindcss_postcss.postcss.parse(normalizedSource);
409
855
  let changed = false;
410
856
  root.walkAtRules((rule) => {
411
857
  if (rule.name === "import" || rule.name === "font-face" || rule.name.endsWith("keyframes")) {
@@ -425,220 +871,13 @@ function collectWebpackBareSelectorUserCss(source) {
425
871
  changed = true;
426
872
  }
427
873
  });
428
- return changed ? root.toString() : source;
874
+ return changed ? root.toString() : normalizedSource;
429
875
  } catch {
430
876
  return "";
431
877
  }
432
878
  }
433
- const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = /* @__PURE__ */ new Set([
434
- "theme",
435
- "base",
436
- "utilities"
437
- ]);
438
- const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
439
- const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
440
- const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
441
- const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
442
- "*",
443
- ":after",
444
- ":before",
445
- "::after",
446
- "::before",
447
- "::backdrop",
448
- "view",
449
- "text"
450
- ]);
451
- const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
452
- "box-sizing",
453
- "border",
454
- "border-width",
455
- "border-style",
456
- "border-color",
457
- "margin",
458
- "padding"
459
- ]);
460
- const WEBPACK_TAILWIND_THEME_TOKEN_RE = /^--(?:tw-|color-|spacing|breakpoint-|container-|text-|font-|tracking-|leading-|radius-|shadow-|inset-shadow-|drop-shadow-|ease-|animate-|blur-|perspective-|aspect-|default-)/;
461
- function parseWebpackCssLayerNames(params) {
462
- return params.split(",").map((name) => name.trim()).filter(Boolean);
463
- }
464
- function removeWebpackTailwindGeneratedAssetCss(source) {
465
- const cleaned = require_generator.removeTailwindV4GeneratedUserCssArtifacts(source);
466
- try {
467
- const root = _weapp_tailwindcss_postcss.postcss.parse(cleaned);
468
- let changed = false;
469
- let removingBannerPrefix = false;
470
- for (const node of [...root.nodes]) {
471
- if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
472
- node.remove();
473
- changed = true;
474
- removingBannerPrefix = true;
475
- continue;
476
- }
477
- if (!removingBannerPrefix) continue;
478
- if (isWebpackTailwindGeneratedPrefixNode(node)) {
479
- node.remove();
480
- changed = true;
481
- continue;
482
- }
483
- removingBannerPrefix = false;
484
- }
485
- root.walkAtRules("layer", (rule) => {
486
- const names = parseWebpackCssLayerNames(rule.params);
487
- const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
488
- const isLayerDeclaration = rule.nodes === void 0;
489
- const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
490
- if (shouldRemoveLayer && isLayerDeclaration) {
491
- rule.remove();
492
- changed = true;
493
- return;
494
- }
495
- if (shouldRemoveLayer && !names.includes("utilities")) {
496
- for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
497
- child.remove();
498
- changed = true;
499
- }
500
- if (rule.nodes?.length === 0) {
501
- rule.remove();
502
- changed = true;
503
- }
504
- return;
505
- }
506
- if (shouldRemoveLayer) {
507
- for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
508
- child.remove();
509
- changed = true;
510
- }
511
- if (rule.nodes?.length === 0) {
512
- rule.remove();
513
- changed = true;
514
- }
515
- }
516
- });
517
- root.walkRules((rule) => {
518
- if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
519
- const selector = rule.selector.trim();
520
- if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
521
- rule.remove();
522
- changed = true;
523
- }
524
- });
525
- root.walkComments((comment) => {
526
- if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
527
- comment.remove();
528
- changed = true;
529
- }
530
- });
531
- root.walkAtRules((rule) => {
532
- if (rule.nodes !== void 0 && rule.nodes.length === 0) {
533
- rule.remove();
534
- changed = true;
535
- }
536
- });
537
- return changed ? root.toString() : cleaned;
538
- } catch {
539
- return cleaned;
540
- }
541
- }
542
- function isWebpackTailwindGeneratedPrefixNode(node) {
543
- if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
544
- "theme",
545
- "base",
546
- "utilities"
547
- ], true);
548
- if (node.type !== "atrule") return false;
549
- const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
550
- if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
551
- if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
552
- if (node.nodes === void 0) return true;
553
- return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
554
- }
555
- if (node.nodes === void 0 || node.nodes.length === 0) return false;
556
- return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
557
- }
558
- function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
559
- if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
560
- if (node.type !== "atrule") return false;
561
- if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
562
- if (node.nodes === void 0 || node.nodes.length === 0) return false;
563
- return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
564
- }
565
- function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
566
- const selectors = rule.selectors ?? [rule.selector];
567
- if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
568
- if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
569
- if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
570
- if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
571
- return false;
572
- }
573
- function isWebpackTailwindGeneratedThemeRule(rule) {
574
- const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
575
- return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
576
- }
577
- function isWebpackTailwindGeneratedPreflightRule(rule) {
578
- const selectors = rule.selectors ?? [rule.selector];
579
- const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
580
- return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
581
- const normalized = selector.trim().replace(/\s+/g, " ");
582
- return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
583
- }) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
584
- }
585
- function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
586
- try {
587
- const nodes = _weapp_tailwindcss_postcss.postcss.parse(source).nodes ?? [];
588
- return nodes.length > 0 && nodes.every((node) => {
589
- if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
590
- return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
591
- });
592
- } catch {
593
- return false;
594
- }
595
- }
596
- function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
597
- return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
598
- }
599
- function collectWebpackCssRuleIdentityMarkers(source) {
600
- const markers = /* @__PURE__ */ new Set();
601
- try {
602
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
603
- root.walkRules((rule) => {
604
- for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
605
- });
606
- root.walkAtRules("keyframes", (rule) => {
607
- if (rule.params) markers.add(`keyframes:${rule.params}`);
608
- });
609
- } catch {}
610
- return markers;
611
- }
612
- function unescapeCssIdentifier(value) {
613
- return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
614
- const hex = escaped.trim();
615
- if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
616
- return escaped;
617
- });
618
- }
619
- function collectGeneratedCssRuntimeCandidates(source) {
620
- const candidates = /* @__PURE__ */ new Set();
621
- if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) || !require_generator.hasTailwindGeneratedCss(source) && !require_generator.hasTailwindGeneratedCssMarkers(source)) return candidates;
622
- try {
623
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
624
- for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
625
- const candidate = unescapeCssIdentifier(match[1]);
626
- if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
627
- }
628
- });
629
- } catch {}
630
- return candidates;
631
- }
632
- function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
633
- const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
634
- if (rawMarkers.size === 0) return false;
635
- const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
636
- for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
637
- return false;
638
- }
639
- function hasWebpackTailwindSourceDirectives(source) {
640
- return Boolean(source) && (require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source) || require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source));
641
- }
879
+ //#endregion
880
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.ts
642
881
  function isWebpackTailwindImportRequest(request) {
643
882
  return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
644
883
  }
@@ -683,244 +922,39 @@ function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSo
683
922
  if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
684
923
  seen.add(css);
685
924
  if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
686
- css,
687
- file: source.file,
688
- processed: source.processed === true
689
- });
690
- }
691
- const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
692
- const parts = matchedSources.sort((a, b) => {
693
- const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
694
- if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
695
- return a.file.localeCompare(b.file);
696
- }).map((source) => source.css);
697
- return parts.length > 0 ? {
698
- css: parts.join("\n"),
699
- processed: matchedSources.every((source) => source.processed)
700
- } : void 0;
701
- }
702
- function createWebpackGeneratorUserCssSourceAppend(...sources) {
703
- const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
704
- if (parts.length === 0) return;
705
- let css = "";
706
- const usedParts = [];
707
- for (const source of parts) {
708
- const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, source.css) : source.css;
709
- if (!(nextCss.trim().length > 0)) continue;
710
- css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
711
- usedParts.push(source);
712
- }
713
- return {
714
- css,
715
- processed: usedParts.every((source) => source.processed)
716
- };
717
- }
718
- function resolveWebpackMemoryDebugStats(context) {
719
- if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
720
- const memory = node_process.default.memoryUsage();
721
- const processCacheInstanceSize = context.cache.instance.size;
722
- const processCacheHashMapSize = context.cache.hashMap.size;
723
- return {
724
- phase: context.phase,
725
- process: {
726
- rssMb: toMb(memory.rss),
727
- heapTotalMb: toMb(memory.heapTotal),
728
- heapUsedMb: toMb(memory.heapUsed),
729
- externalMb: toMb(memory.external),
730
- arrayBuffersMb: toMb(memory.arrayBuffers)
731
- },
732
- assets: {
733
- active: context.activeAssetFiles,
734
- activeCss: context.activeCssFiles
735
- },
736
- processCache: {
737
- instance: processCacheInstanceSize,
738
- hashMap: processCacheHashMapSize,
739
- activeCacheKeys: context.activeProcessCacheKeys.size,
740
- activeHashKeys: context.activeProcessHashKeys.size,
741
- staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
742
- staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
743
- pruned: true,
744
- pruneSkipped: false
745
- },
746
- webpackCss: {
747
- handlerOptions: context.cssHandlerOptionsCache.size,
748
- userHandlerOptions: context.cssUserHandlerOptionsCache.size,
749
- maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
750
- },
751
- sourceCandidateScan: context.sourceCandidateScan,
752
- tailwind: { v4: require_generator.getTailwindV4IncrementalGenerateCacheStats() }
753
- };
754
- }
755
- function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
756
- if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
757
- return cssHandlerOptions.isMainChunk !== false;
758
- }
759
- function includesTailwindPreflightImport(source) {
760
- if (!source) return false;
761
- try {
762
- let includesPreflight = false;
763
- _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules((rule) => {
764
- if (rule.name === "tailwind") {
765
- includesPreflight || (includesPreflight = rule.params.trim() === "base");
766
- return;
767
- }
768
- if (rule.name !== "import") return;
769
- const request = require_generator.parseImportRequest(rule.params)?.replaceAll("\\", "/");
770
- includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
771
- });
772
- return includesPreflight;
773
- } catch {
774
- return false;
775
- }
776
- }
777
- function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
778
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
779
- if (isWebGeneratorTarget) return source;
780
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_generator.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
781
- cssPreflight: options.cssPreflight === false ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
782
- isTailwindcssV4: true,
783
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
784
- })));
785
- }
786
- function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
787
- return !require_generator.hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
788
- }
789
- function isWindowsAbsoluteResourcePath(file) {
790
- return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
791
- }
792
- function isPosixAbsoluteResourcePath(file) {
793
- return file.startsWith("/");
794
- }
795
- function resolveWebpackResourcePath(file, base) {
796
- if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.resolve(file);
797
- if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.resolve(file);
798
- if (base) {
799
- if (isWindowsAbsoluteResourcePath(base)) return node_path.default.win32.resolve(base, file);
800
- if (isPosixAbsoluteResourcePath(base)) return node_path.default.posix.resolve(base, file);
801
- return node_path.default.resolve(base, file);
802
- }
803
- }
804
- function dirnameWebpackResourcePath(file) {
805
- if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.dirname(file);
806
- if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.dirname(file);
807
- return node_path.default.dirname(file);
808
- }
809
- function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
810
- if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
811
- const normalized = stripResourceQuery(resource);
812
- if (!normalized) return;
813
- const absoluteResource = resolveWebpackResourcePath(normalized);
814
- if (absoluteResource) return absoluteResource;
815
- const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
816
- const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
817
- return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
818
- }
819
- function isSameWebpackCssSourceScope(options) {
820
- if (!options.currentSourceFile) return false;
821
- const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? node_path.default.resolve(options.candidateSourceFile);
822
- if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? node_path.default.resolve(options.currentSourceFile))) return true;
823
- const outputResources = options.resourcesByAsset.get(options.outputFile);
824
- if (!outputResources) return false;
825
- return [...outputResources].some((resource) => {
826
- return (resolveWebpackResourcePath(resource) ?? node_path.default.resolve(resource)) === candidateKey;
827
- });
828
- }
829
- function shouldAppendCurrentWebpackAssetUserCss(options) {
830
- const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
831
- return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
832
- }
833
- function createWebpackCurrentAssetUserRawSource(options) {
834
- if (!options.shouldAppendCurrentAssetUserCss) return;
835
- if (options.sourceCssProcessed) return {
836
- css: options.currentAssetUserCssSource,
837
- processed: true
838
- };
839
- if (!options.currentAssetHasUserCss) return;
840
- return {
841
- css: options.currentAssetUserCssSource,
842
- processed: options.currentAssetLooksGenerated
843
- };
844
- }
845
- function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
846
- if (options.finalized === true) return options.annotateCss(css);
847
- if (options.isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
848
- const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
849
- return options.annotateCss(finalized);
850
- }
851
- function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
852
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
853
- if (isWebGeneratorTarget) {
854
- if (options.generatedCss === true) return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source))));
855
- return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(require_generator.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
856
- }
857
- let finalized = require_generator.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
858
- if (options.generatedCss !== true) {
859
- finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
860
- cssPreflight: false,
861
- isTailwindcssV4: true,
862
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
863
- });
864
- finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
865
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
866
- }
867
- try {
868
- finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: options.cssPreflight !== false });
869
- } catch {}
870
- const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
871
- if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
872
- const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
873
- finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
874
- cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
875
- isTailwindcssV4: true,
876
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
877
- });
878
- finalized = ensureWebpackMiniProgramTwContentInit(finalized);
879
- if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
880
- else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
881
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
882
- }
883
- function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
884
- if (isWebGeneratorTarget) return source;
885
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
886
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(dedupeMiniProgramPreflightSelectorRules(source), styleOptions.cssRemoveHoverPseudoClass));
887
- }
888
- function collectWebpackJsRuntimeCandidatesFromAssets(options) {
889
- if (options.isWebGeneratorTarget) return;
890
- const candidates = /* @__PURE__ */ new Set();
891
- for (const file of options.jsAssets) {
892
- const sourceLike = options.getAssetSource(file);
893
- if (sourceLike === void 0) continue;
894
- const source = stringifyWebpackSourceLike(sourceLike);
895
- for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
896
- }
897
- return candidates;
898
- }
899
- function collectWebpackJsRuntimeTokenSignature(options) {
900
- if (options.isWebGeneratorTarget) return "";
901
- const tokens = [];
902
- for (const file of options.jsAssets) {
903
- const sourceLike = options.getAssetSource(file);
904
- if (sourceLike === void 0) continue;
905
- tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
906
- }
907
- return tokens.sort().join("\n");
908
- }
909
- function addRuntimeTransformCandidates(target, candidates) {
910
- if (!candidates?.size) return;
911
- for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
912
- }
913
- function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
914
- if (!require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
915
- return require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
916
- }
917
- function stringifyOptionalWebpackSourceValue(value) {
918
- return typeof value === "string" ? value : value?.toString() ?? "";
925
+ css,
926
+ file: source.file,
927
+ processed: source.processed === true
928
+ });
929
+ }
930
+ const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
931
+ const parts = matchedSources.sort((a, b) => {
932
+ const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
933
+ if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
934
+ return a.file.localeCompare(b.file);
935
+ }).map((source) => source.css);
936
+ return parts.length > 0 ? {
937
+ css: parts.join("\n"),
938
+ processed: matchedSources.every((source) => source.processed)
939
+ } : void 0;
919
940
  }
920
- function stringifyWebpackSourceLike(source) {
921
- if (typeof source === "string") return source;
922
- const value = source.source();
923
- return typeof value === "string" ? value : value.toString();
941
+ function createWebpackGeneratorUserCssSourceAppend(...sources) {
942
+ const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
943
+ if (parts.length === 0) return;
944
+ let css = "";
945
+ const usedParts = [];
946
+ for (const source of parts) {
947
+ const merged = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.mergeCoveredCssRuleDeclarations)(css, source.css) : void 0;
948
+ if (merged?.changed) css = merged.baseCss;
949
+ const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, merged?.css ?? source.css) : source.css;
950
+ if (!(nextCss.trim().length > 0)) continue;
951
+ css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
952
+ usedParts.push(source);
953
+ }
954
+ return {
955
+ css,
956
+ processed: usedParts.every((source) => source.processed)
957
+ };
924
958
  }
925
959
  //#endregion
926
960
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.ts
@@ -974,7 +1008,7 @@ function collectMainImportedCssFiles(compilation, cssAssetFiles, cssMatcher, isM
974
1008
  return files;
975
1009
  }
976
1010
  function createWebpackCssSourceResolvers(options) {
977
- const { activeWebpackAssetResourceFiles, appType, compilerOptions, compilation, cssAssetFiles, cssAssetResources, cssHandlerOptionsCache, cssSources, cssUserHandlerOptionsCache, groupedCssEntriesLength, singleCssAssetFile, isWebGeneratorTarget, outputDir, runtimeState } = options;
1011
+ const { activeWebpackAssetResourceFiles, appType, compilerOptions, compilation, cssAssetFiles, cssAssetResources, directCssAssetResources, cssHandlerOptionsCache, cssSources, cssUserHandlerOptionsCache, groupedCssEntriesLength, singleCssAssetFile, isWebGeneratorTarget, outputDir, runtimeState } = options;
978
1012
  const hasConfiguredTailwindV4SourceRoots = () => {
979
1013
  const tailwindOptions = require_generator.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
980
1014
  return (tailwindOptions?.v4?.cssEntries?.length ?? 0) > 0 || (tailwindOptions?.v4?.cssSources?.length ?? 0) > 0;
@@ -991,7 +1025,7 @@ function createWebpackCssSourceResolvers(options) {
991
1025
  cwd: compilerOptions.tailwindcssBasedir
992
1026
  });
993
1027
  const isConfiguredMainCssEntryFile = (sourceFile) => configuredMainCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
994
- const isCssSourceAllowedForOutput = (file, sourceFile) => !isConfiguredMainCssEntryFile(sourceFile) || scoreCssSourceOutputMatch(file, sourceFile) > 0;
1028
+ const isCssSourceAllowedForOutput = (file, sourceFile) => !isConfiguredMainCssEntryFile(sourceFile) || directCssAssetResources.get(file)?.has(sourceFile) === true || scoreCssSourceOutputMatch(file, sourceFile) > 0;
995
1029
  const inferredMainCssFiles = new Set([...inferWebpackMainCssFiles(compilation.chunks, compilerOptions.cssMatcher, {
996
1030
  mainSourceFiles: new Set(configuredMainCssEntryFiles),
997
1031
  resourcesByAsset: cssAssetResources
@@ -1032,6 +1066,12 @@ function createWebpackCssSourceResolvers(options) {
1032
1066
  return resolveConfiguredMainCssSourceFile(file);
1033
1067
  }
1034
1068
  const resourceMatches = [...assetResources ?? []].filter((sourceFile) => cssSources.has(sourceFile)).filter((sourceFile) => isCssSourceAllowedForOutput(file, sourceFile)).sort();
1069
+ const configuredResourceMatches = resourceMatches.filter((sourceFile) => configuredCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile)));
1070
+ if (configuredResourceMatches.length === 1) {
1071
+ const sourceFile = configuredResourceMatches[0];
1072
+ activeWebpackCssSourceFiles.add(sourceFile);
1073
+ return sourceFile;
1074
+ }
1035
1075
  if (resourceMatches.length === 1) {
1036
1076
  const sourceFile = resourceMatches[0];
1037
1077
  activeWebpackCssSourceFiles.add(sourceFile);
@@ -1170,6 +1210,343 @@ function createWebpackCssSourceResolvers(options) {
1170
1210
  };
1171
1211
  }
1172
1212
  //#endregion
1213
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.ts
1214
+ async function finalizeWebpackProcessAssets(context) {
1215
+ const { activeProcessCacheKeys, activeProcessHashKeys, activeWebpackCssSourceFiles, compilerOptions, cssAssetResources, cssHandlerOptionsCache, cssTaskFactories, cssUserHandlerOptionsCache, debug, entries, groupedEntries, hmrTimingStartedAt, htmlTaskFactories, jsTaskFactories, pruneWebpackCssSources, recordTimingDetail, registeredWebpackCssSourceFiles, taskConcurrency, tasks, timingDetails, watchMode, webpackSourceCandidateScanCache } = context;
1216
+ if (!watchMode) {
1217
+ require_hmr_timing.pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
1218
+ await Promise.all(tasks);
1219
+ tasks.length = 0;
1220
+ require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
1221
+ await Promise.all(tasks);
1222
+ tasks.length = 0;
1223
+ require_hmr_timing.pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
1224
+ }
1225
+ const taskWaitStartedAt = performance.now();
1226
+ await Promise.all(tasks);
1227
+ recordTimingDetail("tasks.wait", taskWaitStartedAt);
1228
+ const pruneStartedAt = performance.now();
1229
+ compilerOptions.cache.prune?.({
1230
+ cacheKeys: activeProcessCacheKeys,
1231
+ hashKeys: activeProcessHashKeys
1232
+ });
1233
+ const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
1234
+ pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
1235
+ if (activeCssFiles.size > 0) pruneWebpackCssSources?.(/* @__PURE__ */ new Set([
1236
+ ...registeredWebpackCssSourceFiles,
1237
+ ...activeWebpackCssSourceFiles,
1238
+ ...[...cssAssetResources.values()].flatMap((resources) => [...resources])
1239
+ ]), { watchMode });
1240
+ recordTimingDetail("cache.prune", pruneStartedAt);
1241
+ debug("end");
1242
+ require_hmr_timing.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, {
1243
+ ...timingDetails,
1244
+ memoryDebug: resolveWebpackMemoryDebugStats({
1245
+ activeAssetFiles: entries.length,
1246
+ activeCssFiles: activeCssFiles.size,
1247
+ activeProcessCacheKeys,
1248
+ activeProcessHashKeys,
1249
+ cache: compilerOptions.cache,
1250
+ cssHandlerOptionsCache,
1251
+ cssUserHandlerOptionsCache,
1252
+ phase: "processAssets",
1253
+ sourceCandidateScan: webpackSourceCandidateScanCache.getMemoryStats()
1254
+ })
1255
+ });
1256
+ compilerOptions.onEnd();
1257
+ }
1258
+ //#endregion
1259
+ //#region src/bundlers/webpack/shared/css-loader-runtime.ts
1260
+ function isWebpackCssLoaderRuntimeSource(source) {
1261
+ return source.includes("___CSS_LOADER_EXPORT___") && source.includes("___CSS_LOADER_API_IMPORT___") && source.includes("module.exports = ___CSS_LOADER_EXPORT___");
1262
+ }
1263
+ //#endregion
1264
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.ts
1265
+ async function finalizeWebpackGeneratedCssResult(context) {
1266
+ const { ConcatSource, compilerOptions, cssHandlerOptions, currentRawSource, debug, file, finalizeCssAssetSource, finalizeTracedCss, generated, generatorRawSource, generatorRuntimeSet, isWebGeneratorTarget, runtimeState, shouldPreserveExistingPreflight, sourceCss, sourceCssProcessed, userRawSource } = context;
1267
+ const finalizedGeneratedCss = generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
1268
+ css: generated.css,
1269
+ processed: true
1270
+ }, {
1271
+ css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
1272
+ processed: true
1273
+ })?.css ?? generated.css : generated.css, {
1274
+ cssPreflight: cssHandlerOptions.isMainChunk,
1275
+ generatedCss: true,
1276
+ preserveExistingPreflight: shouldPreserveExistingPreflight
1277
+ }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false });
1278
+ const sourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[
1279
+ userRawSource,
1280
+ sourceCss === void 0 ? void 0 : {
1281
+ css: sourceCss,
1282
+ processed: sourceCssProcessed
1283
+ },
1284
+ {
1285
+ css: generatorRawSource,
1286
+ processed: false
1287
+ }
1288
+ ].map((source) => {
1289
+ if (source === void 0) return;
1290
+ return {
1291
+ css: collectWebpackBareSelectorUserCss(source.css),
1292
+ processed: source.processed
1293
+ };
1294
+ }));
1295
+ const handledSourceBareUserCss = sourceBareUserCss === void 0 ? "" : sourceBareUserCss.processed ? sourceBareUserCss.css : (await compilerOptions.styleHandler(sourceBareUserCss.css, cssHandlerOptions)).css;
1296
+ const finalizedSourceBareUserCss = handledSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledSourceBareUserCss, {
1297
+ cssPreflight: false,
1298
+ generatedCss: false
1299
+ });
1300
+ const missingSourceBareUserCss = finalizedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedGeneratedCss, finalizedSourceBareUserCss);
1301
+ const source = new ConcatSource(finalizeTracedCss(missingSourceBareUserCss.trim().length === 0 ? finalizedGeneratedCss : createWebpackGeneratorUserCssSourceAppend({
1302
+ css: finalizedGeneratedCss,
1303
+ processed: true
1304
+ }, {
1305
+ css: missingSourceBareUserCss,
1306
+ processed: true
1307
+ }).css, cssHandlerOptions, { finalized: true }));
1308
+ if (generated) {
1309
+ for (const className of generated.classSet) generatorRuntimeSet.add(className);
1310
+ debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
1311
+ } else debug("css handle: %s", file);
1312
+ return { result: source };
1313
+ }
1314
+ //#endregion
1315
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.ts
1316
+ async function processWebpackGeneratedCssAsset(element, context) {
1317
+ const { ConcatSource, assetHashByChunk, compilation, compilerOptions, configuredCssEntryFiles, configuredMainCssEntryFiles, createRuntimeSetHash, cssSourceTraceSignature, cssSources, cssTaskFactories, debug, enqueueTask, finalizeCssAssetSource, finalizeTracedCss, generatedCssSources, generatorRuntimeSet, getCssHandlerOptions, getCssUserHandlerOptions, getGeneratorRuntimeSet, hasConfiguredTailwindV4SourceRoots, isSameWebpackSourceScope, isWebGeneratorTarget, rememberProcessCacheKey, resolveWebpackCssSourceFile, runtimeAffectingSourceHash, runtimeState, transformRuntimeSet, updateAssetIfChanged, watchMode, webpackSourceCandidateValueSignature, webpackSourceCandidates } = context;
1318
+ const [file, originalSource] = element;
1319
+ const currentRawSource = originalSource.source().toString();
1320
+ const chunkHash = assetHashByChunk.get(file);
1321
+ const cacheKey = file;
1322
+ const hashKey = `${file}:asset`;
1323
+ rememberProcessCacheKey(cacheKey, hashKey);
1324
+ const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
1325
+ const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
1326
+ const cssSourceHash = (() => {
1327
+ const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
1328
+ const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
1329
+ const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
1330
+ if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
1331
+ return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
1332
+ })();
1333
+ const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
1334
+ await enqueueTask(async () => {
1335
+ await require_hmr_timing.processCachedTask({
1336
+ cache: compilerOptions.cache,
1337
+ cacheKey,
1338
+ hashKey,
1339
+ rawSource: currentRawSource,
1340
+ hash: runtimeAwareHash,
1341
+ applyResult(source, { cacheHit }) {
1342
+ updateAssetIfChanged(file, source, {
1343
+ compare: !cacheHit,
1344
+ notifyUpdate: !cacheHit
1345
+ });
1346
+ },
1347
+ onCacheHit() {
1348
+ debug("css cache hit: %s", file);
1349
+ },
1350
+ transform: async () => {
1351
+ await runtimeState.readyPromise;
1352
+ const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
1353
+ const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
1354
+ if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
1355
+ const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
1356
+ const sourceCss = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css : void 0;
1357
+ const isConfiguredCssSource = sourceFile !== void 0 && configuredCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
1358
+ const isConfiguredMainCssSource = sourceFile !== void 0 && configuredMainCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
1359
+ const sourceCssHasTailwindRoot = sourceCss !== void 0 && require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true });
1360
+ const shouldPreserveExistingPreflight = cssHandlerOptions.isMainChunk || !isConfiguredMainCssSource && (isConfiguredCssSource || sourceCssHasTailwindRoot);
1361
+ const loaderGeneratedCss = sourceFile ? generatedCssSources.get(node_path.default.resolve(sourceFile)) : void 0;
1362
+ const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
1363
+ const explicitTailwindV4SourceCandidates = shouldRegenerateExplicitTailwindV4CssSource && sourceCss && sourceFile && webpackSourceCandidates?.getSourceCandidatesForEntries ? await require_tailwindcss.resolveTailwindV4EntriesFromCssCached(sourceCss, node_path.default.dirname(sourceFile)).then((resolved) => resolved?.entries ? webpackSourceCandidates.getSourceCandidatesForEntries(resolved.entries) : void 0) : void 0;
1364
+ if (loaderGeneratedCss && shouldConsumeWebpackLoaderGeneratedCss({
1365
+ allowMarkerlessRegistryMatch: configuredCssEntryFiles.length === 1,
1366
+ hasBundlerGeneratedCssMarker: require_hmr_timing.hasBundlerGeneratedCssMarker(currentRawSource),
1367
+ loaderGeneratedClassSet: loaderGeneratedCss.classSet,
1368
+ sourceCandidates: explicitTailwindV4SourceCandidates,
1369
+ shouldRegenerateExplicitTailwindV4CssSource,
1370
+ watchMode
1371
+ })) {
1372
+ for (const className of loaderGeneratedCss.classSet) {
1373
+ generatorRuntimeSet.add(className);
1374
+ transformRuntimeSet.add(className);
1375
+ }
1376
+ for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
1377
+ const currentRawSourceWithoutBundlerMarkers = require_hmr_timing.stripBundlerGeneratedCssMarkers(currentRawSource);
1378
+ const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
1379
+ const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? require_hmr_timing.removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
1380
+ const loaderGeneratedCssWithoutMarkers = require_hmr_timing.stripBundlerGeneratedCssMarkers(loaderGeneratedCss.css);
1381
+ const currentAssetUserCssWithoutMarkers = currentAssetUserCss === void 0 ? "" : require_hmr_timing.stripBundlerGeneratedCssMarkers(currentAssetUserCss);
1382
+ const currentAssetMissingUserCss = !(currentAssetUserCssWithoutMarkers.trim().length > 0 && !require_generator.isCommentOnlyCss(currentAssetUserCssWithoutMarkers)) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCssWithoutMarkers, loaderGeneratedCssWithoutMarkers);
1383
+ if (isConfiguredMainCssSource && !cssHandlerOptions.isMainChunk) {
1384
+ debug("css skip duplicate webpack loader main generation: %s <- %s", file, sourceFile);
1385
+ const userCss = currentAssetMissingUserCss.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetMissingUserCss) ? "" : finalizeCssAssetSource(currentAssetMissingUserCss, {
1386
+ cssPreflight: false,
1387
+ generatedCss: false
1388
+ });
1389
+ return { result: new ConcatSource(finalizeTracedCss(userCss, cssHandlerOptions)) };
1390
+ }
1391
+ const mergedLoaderCss = currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
1392
+ css: currentAssetUserCss === void 0 ? loaderGeneratedCss.css : currentAssetHasProcessedUrl ? require_hmr_timing.removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCss, loaderGeneratedCss.css),
1393
+ processed: true
1394
+ }, currentAssetUserCss === void 0 ? void 0 : {
1395
+ css: currentAssetUserCss,
1396
+ processed: true
1397
+ }).css;
1398
+ const handledLoaderCss = isWebGeneratorTarget ? mergedLoaderCss : (await compilerOptions.styleHandler(mergedLoaderCss, cssHandlerOptions)).css;
1399
+ const finalizedLoaderCss = finalizeCssAssetSource(handledLoaderCss, {
1400
+ cssPreflight: cssHandlerOptions.isMainChunk,
1401
+ generatedCss: true,
1402
+ preserveExistingPreflight: shouldPreserveExistingPreflight
1403
+ });
1404
+ const loaderSourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[currentAssetUserCss === void 0 ? void 0 : {
1405
+ css: currentAssetUserCss,
1406
+ processed: true
1407
+ }, sourceCss === void 0 ? void 0 : {
1408
+ css: sourceCss,
1409
+ processed: false
1410
+ }].map((source) => {
1411
+ if (source === void 0) return;
1412
+ return {
1413
+ css: collectWebpackBareSelectorUserCss(source.css),
1414
+ processed: source.processed
1415
+ };
1416
+ }));
1417
+ const handledLoaderSourceBareUserCss = loaderSourceBareUserCss === void 0 ? "" : loaderSourceBareUserCss.processed ? loaderSourceBareUserCss.css : (await compilerOptions.styleHandler(loaderSourceBareUserCss.css, cssHandlerOptions)).css;
1418
+ const finalizedLoaderSourceBareUserCss = handledLoaderSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledLoaderSourceBareUserCss, {
1419
+ cssPreflight: false,
1420
+ generatedCss: false
1421
+ });
1422
+ const missingLoaderSourceBareUserCss = finalizedLoaderSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedLoaderCss, finalizedLoaderSourceBareUserCss);
1423
+ const css = finalizeTracedCss(missingLoaderSourceBareUserCss.trim().length === 0 ? finalizedLoaderCss : createWebpackGeneratorUserCssSourceAppend({
1424
+ css: finalizedLoaderCss,
1425
+ processed: true
1426
+ }, {
1427
+ css: missingLoaderSourceBareUserCss,
1428
+ processed: true
1429
+ }).css, cssHandlerOptions, { finalized: true });
1430
+ debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
1431
+ return { result: new ConcatSource(css) };
1432
+ }
1433
+ const sourceCssProcessed = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.processed === true : false;
1434
+ const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
1435
+ ...source,
1436
+ file: registeredSourceFile
1437
+ })), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
1438
+ const currentAssetLooksGenerated = require_generator.hasTailwindGeneratedCss(currentRawSource) || require_generator.hasTailwindGeneratedCssMarkers(currentRawSource);
1439
+ const currentAssetHasBundlerGeneratedMarker = require_hmr_timing.hasBundlerGeneratedCssMarker(currentRawSource);
1440
+ const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
1441
+ if (sourceFile === void 0 && currentAssetHasBundlerGeneratedMarker && (currentAssetUserCssSource.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetUserCssSource))) return { result: new ConcatSource(finalizeTracedCss("", cssHandlerOptions)) };
1442
+ const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
1443
+ const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
1444
+ const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss));
1445
+ const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
1446
+ const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
1447
+ currentAssetHasUserCss,
1448
+ currentAssetLooksGenerated,
1449
+ currentAssetUserCssSource,
1450
+ shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
1451
+ currentAssetHasBundlerGeneratedMarker,
1452
+ currentAssetHasUserCss,
1453
+ currentAssetLooksGenerated,
1454
+ registeredUserRawSource,
1455
+ shouldPreserveGeneratedWebAssetUserCss,
1456
+ sourceCssProcessed
1457
+ }),
1458
+ sourceCssProcessed
1459
+ }), registeredUserRawSource);
1460
+ if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(currentRawSource)) return { result: new ConcatSource(require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
1461
+ const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
1462
+ const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
1463
+ const currentAssetHasTailwindDirectives = require_generator.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindApplyDirective(generatorRawSource);
1464
+ const shouldForceTailwindV4Generation = hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 && sourceFile !== void 0 || currentAssetHasTailwindDirectives || hasExplicitTailwindV4SourceCss);
1465
+ const shouldSkipUnmatchedMainCssGeneration = !isWebGeneratorTarget && cssHandlerOptions.isMainChunk && sourceFile === void 0 && configuredMainCssEntryFiles.length > 0 && !currentAssetHasTailwindDirectives;
1466
+ const shouldSkipPlainNonMainCssGeneration = !cssHandlerOptions.isMainChunk && sourceCss !== void 0 && !hasExplicitSourceCssForCurrentAsset && !hasExplicitTailwindV4SourceCss && !currentAssetHasTailwindDirectives;
1467
+ const shouldMergeFallbackGeneratorRuntime = cssHandlerOptions.isMainChunk || currentAssetHasTailwindDirectives || hasExplicitSourceCssForCurrentAsset;
1468
+ const scopedFallbackGeneratorRuntimeSet = hasExplicitTailwindV4SourceCss || !shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet;
1469
+ const resolvedScopedGeneratorRuntimeSet = await require_source_candidate_scan_signature.createScopedGeneratorRuntime({
1470
+ cssHandlerOptions,
1471
+ fallbackRuntime: scopedFallbackGeneratorRuntimeSet,
1472
+ getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
1473
+ majorVersion: runtimeState.tailwindRuntime.majorVersion,
1474
+ outputFile: file,
1475
+ rawSource: sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
1476
+ shouldExcludeSubpackageSourceCandidates: () => false,
1477
+ sourceFile: sourceFile ?? file,
1478
+ scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
1479
+ });
1480
+ const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== scopedFallbackGeneratorRuntimeSet && shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
1481
+ const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
1482
+ const scopedGeneratorCompilerOptions = scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, { disableUnmatchedCssEntries: !isWebGeneratorTarget && cssHandlerOptions.isMainChunk });
1483
+ const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
1484
+ ...cssHandlerOptions,
1485
+ sourceOptions: {
1486
+ ...cssHandlerOptions.sourceOptions,
1487
+ cssSources: generatorCssSources
1488
+ }
1489
+ };
1490
+ const generatorOptions = {
1491
+ opts: scopedGeneratorCompilerOptions,
1492
+ runtimeState,
1493
+ runtime: scopedGeneratorRuntimeSet,
1494
+ rawSource: generatorRawSource,
1495
+ forceGenerator: shouldForceTailwindV4Generation,
1496
+ ...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
1497
+ ...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
1498
+ ...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
1499
+ file,
1500
+ cssHandlerOptions: generatorCssHandlerOptions,
1501
+ cssUserHandlerOptions: getCssUserHandlerOptions(file),
1502
+ frameworkPostcssOwner: compilerOptions,
1503
+ frameworkPostcssStage: "complete",
1504
+ getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
1505
+ sourceCandidates: scopedGeneratorRuntimeSet,
1506
+ restoreLocalCssImports: false,
1507
+ styleHandler: compilerOptions.styleHandler,
1508
+ debug
1509
+ };
1510
+ let generated;
1511
+ if (!shouldSkipUnmatchedMainCssGeneration && !shouldSkipPlainNonMainCssGeneration) try {
1512
+ generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
1513
+ ...generatorOptions,
1514
+ outputFile: file
1515
+ });
1516
+ } catch (error) {
1517
+ if (!shouldFallbackToWebpackUserCssOnGeneratorError({
1518
+ configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
1519
+ generatorRawSource,
1520
+ hasExplicitTailwindV4SourceCss
1521
+ })) throw error;
1522
+ debug("css generator skipped for plain webpack css asset: %s %O", file, error);
1523
+ generated = void 0;
1524
+ }
1525
+ else debug("css generator skipped for plain webpack css asset: %s", file);
1526
+ return finalizeWebpackGeneratedCssResult({
1527
+ ConcatSource,
1528
+ compilerOptions,
1529
+ cssHandlerOptions,
1530
+ currentRawSource,
1531
+ debug,
1532
+ file,
1533
+ finalizeCssAssetSource,
1534
+ finalizeTracedCss,
1535
+ generated,
1536
+ generatorRawSource,
1537
+ generatorRuntimeSet,
1538
+ isWebGeneratorTarget,
1539
+ runtimeState,
1540
+ shouldPreserveExistingPreflight,
1541
+ sourceCss,
1542
+ sourceCssProcessed,
1543
+ userRawSource
1544
+ });
1545
+ }
1546
+ });
1547
+ }, cssTaskFactories, "tasks.css");
1548
+ }
1549
+ //#endregion
1173
1550
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
1174
1551
  function createChangedByType() {
1175
1552
  return {
@@ -1285,6 +1662,112 @@ function createWebpackAssetUpdater(options) {
1285
1662
  };
1286
1663
  }
1287
1664
  //#endregion
1665
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.ts
1666
+ async function enqueueWebpackHtmlAndJsTasks(context) {
1667
+ const { ConcatSource, applyWebpackLinkedJsResults, assetHashByChunk, compilation, compilerOptions, debug, defaultTemplateHandlerOptions, enqueueTask, groupedEntries, isWebGeneratorTarget, jsAssets, moduleGraphOptions, outputDir, rememberProcessCacheKey, rememberTransformedRuntimeCandidates, runtimeState, transformRuntimeSet, updateAssetIfChanged } = context;
1668
+ const htmlTaskFactories = [];
1669
+ if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
1670
+ const [file, originalSource] = element;
1671
+ let rawSource;
1672
+ const readRawSource = () => {
1673
+ rawSource ?? (rawSource = originalSource.source().toString());
1674
+ return rawSource;
1675
+ };
1676
+ const cacheKey = file;
1677
+ const hashKey = `${file}:asset`;
1678
+ rememberProcessCacheKey(cacheKey, hashKey);
1679
+ const chunkHash = assetHashByChunk.get(file);
1680
+ await enqueueTask(async () => {
1681
+ await require_hmr_timing.processCachedTask({
1682
+ cache: compilerOptions.cache,
1683
+ cacheKey,
1684
+ hashKey,
1685
+ rawSource: chunkHash === void 0 ? readRawSource() : void 0,
1686
+ hash: chunkHash,
1687
+ applyResult(source, { cacheHit }) {
1688
+ updateAssetIfChanged(file, source, {
1689
+ compare: !cacheHit,
1690
+ notifyUpdate: !cacheHit
1691
+ });
1692
+ },
1693
+ onCacheHit() {
1694
+ debug("html cache hit: %s", file);
1695
+ },
1696
+ transform: async () => {
1697
+ const wxml = await compilerOptions.templateHandler(readRawSource(), defaultTemplateHandlerOptions);
1698
+ const source = new ConcatSource(wxml);
1699
+ debug("html handle: %s", file);
1700
+ return { result: source };
1701
+ }
1702
+ });
1703
+ }, htmlTaskFactories, "tasks.html");
1704
+ }
1705
+ const jsTaskFactories = [];
1706
+ const enqueueJsTask = async (factory) => {
1707
+ await enqueueTask(factory, jsTaskFactories, "tasks.js");
1708
+ };
1709
+ if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
1710
+ const cacheKey = getCacheKey(file);
1711
+ const asset = compilation.getAsset(file);
1712
+ if (!asset) continue;
1713
+ const hashKey = `${file}:asset`;
1714
+ rememberProcessCacheKey(cacheKey, hashKey);
1715
+ const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
1716
+ const initialSource = asset.source.source();
1717
+ const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
1718
+ const chunkHash = assetHashByChunk.get(file);
1719
+ await enqueueJsTask(async () => {
1720
+ await require_hmr_timing.processCachedTask({
1721
+ cache: compilerOptions.cache,
1722
+ cacheKey,
1723
+ hashKey,
1724
+ rawSource: chunkHash === void 0 ? initialRawSource : void 0,
1725
+ hash: chunkHash,
1726
+ applyResult(source, { cacheHit }) {
1727
+ if (updateAssetIfChanged(file, source, {
1728
+ compare: !cacheHit,
1729
+ notifyUpdate: !cacheHit
1730
+ })) rememberTransformedRuntimeCandidates(source);
1731
+ },
1732
+ onCacheHit() {
1733
+ debug("js cache hit: %s", file);
1734
+ },
1735
+ transform: async () => {
1736
+ const currentSourceValue = compilation.getAsset(file)?.source.source();
1737
+ const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
1738
+ const handlerOptions = {
1739
+ tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
1740
+ generateMap: false,
1741
+ filename: absoluteFile,
1742
+ moduleGraph: moduleGraphOptions,
1743
+ babelParserOptions: { sourceFilename: absoluteFile }
1744
+ };
1745
+ if (require_context.shouldSkipJsTransform(currentSource, {
1746
+ ...handlerOptions,
1747
+ classNameSet: transformRuntimeSet
1748
+ })) return { result: new ConcatSource(currentSource) };
1749
+ const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
1750
+ const source = new ConcatSource(code);
1751
+ debug("js handle: %s", file);
1752
+ applyWebpackLinkedJsResults({
1753
+ ConcatSource,
1754
+ compilation,
1755
+ compilerOptions,
1756
+ debug,
1757
+ jsAssets,
1758
+ linked
1759
+ });
1760
+ return { result: source };
1761
+ }
1762
+ });
1763
+ });
1764
+ }
1765
+ return {
1766
+ htmlTaskFactories,
1767
+ jsTaskFactories
1768
+ };
1769
+ }
1770
+ //#endregion
1288
1771
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.ts
1289
1772
  function createWebpackJsAssetModuleGraph(options) {
1290
1773
  const jsAssets = /* @__PURE__ */ new Map();
@@ -1329,6 +1812,144 @@ function applyWebpackLinkedJsResults(options) {
1329
1812
  }
1330
1813
  }
1331
1814
  //#endregion
1815
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.ts
1816
+ async function processWebpackProcessedCssAsset(element, context) {
1817
+ const { ConcatSource, assetHashByChunk, compilerOptions, configuredMainCssEntryFiles, createRuntimeSetHash, cssSourceTraceSignature, cssSources, cssTaskFactories, debug, enqueueTask, finalizeCssAssetSource, finalizeTracedCss, generatedCssSources, getCssHandlerOptions, getGeneratorRuntimeSet, hasConfiguredTailwindV4SourceRoots, isKnownWebpackProcessedCssAsset, isWebGeneratorTarget, isWebpackProcessedCssAsset, processedCssAssetSkipDecisionCache, rememberProcessCacheKey, runtimeAffectingSourceHash, updateAssetIfChanged, watchMode, webpackSourceCandidateSet, webpackSourceCandidateValueSignature, webpackSourceCandidates } = context;
1818
+ const [file, originalSource] = element;
1819
+ let rawSource;
1820
+ const readRawSource = () => {
1821
+ rawSource ?? (rawSource = originalSource.source().toString());
1822
+ return rawSource;
1823
+ };
1824
+ const chunkHash = assetHashByChunk.get(file);
1825
+ const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file, readRawSource());
1826
+ const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
1827
+ const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
1828
+ const processedSourceCss = processedSourceFile ? cssSources.get(node_path.default.resolve(processedSourceFile))?.css : void 0;
1829
+ const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
1830
+ const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
1831
+ const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(node_path.default.resolve(processedSourceFile)) : void 0;
1832
+ const processedAssetSourceHash = watchMode && isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk ? compilerOptions.cache.computeHash(readRawSource()) : chunkHash === void 0 ? processedCssAssetKnown ? "webpack-css-asset:known" : compilerOptions.cache.computeHash(readRawSource()) : "webpack-css-asset:chunk";
1833
+ const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
1834
+ let currentProcessedRawSource;
1835
+ let hasGeneratedCssMarker = false;
1836
+ let hasTailwindGeneratedAssetCss = false;
1837
+ const readCurrentProcessedRawSource = () => {
1838
+ currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
1839
+ return currentProcessedRawSource;
1840
+ };
1841
+ const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
1842
+ const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
1843
+ if (cachedSkipProcessedCssAsset !== void 0) {
1844
+ hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
1845
+ hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
1846
+ } else {
1847
+ const source = readCurrentProcessedRawSource();
1848
+ hasGeneratedCssMarker = require_hmr_timing.hasBundlerGeneratedCssMarker(source);
1849
+ hasTailwindGeneratedAssetCss = require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source);
1850
+ }
1851
+ const hasProcessedAssetTailwindDirectives = () => {
1852
+ const source = readCurrentProcessedRawSource();
1853
+ return require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source);
1854
+ };
1855
+ const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
1856
+ const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
1857
+ ...source,
1858
+ file: sourceFile
1859
+ })), readCurrentProcessedRawSource()) !== void 0;
1860
+ const hasProcessedLoaderGeneratedUserCss = cachedSkipProcessedCssAsset === void 0 && processedLoaderGeneratedCss !== void 0 && hasAdditionalWebpackAssetUserCssMarkers(processedLoaderGeneratedCss.css, readCurrentProcessedRawSource());
1861
+ const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && require_generator.hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
1862
+ const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1863
+ const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && !hasProcessedLoaderGeneratedUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1864
+ const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
1865
+ if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
1866
+ if (shouldSkipProcessedCssAsset) {
1867
+ const hashKey = `${file}:asset`;
1868
+ const sourceHash = processedAssetSourceHash;
1869
+ rememberProcessCacheKey(file, hashKey);
1870
+ await enqueueTask(async () => {
1871
+ await require_hmr_timing.processCachedTask({
1872
+ cache: compilerOptions.cache,
1873
+ cacheKey: file,
1874
+ hashKey,
1875
+ rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
1876
+ hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
1877
+ applyResult(source, { cacheHit }) {
1878
+ updateAssetIfChanged(file, source, {
1879
+ compare: !cacheHit,
1880
+ notifyUpdate: !cacheHit
1881
+ });
1882
+ },
1883
+ onCacheHit() {
1884
+ debug("css webpack-loader-pipeline cache hit: %s", file);
1885
+ },
1886
+ transform: async () => {
1887
+ const source = readCurrentProcessedRawSource();
1888
+ const missingProcessedLoaderGeneratedCss = isWebGeneratorTarget && processedLoaderGeneratedCss ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(source, require_hmr_timing.stripBundlerGeneratedCssMarkers(processedLoaderGeneratedCss.css)) : "";
1889
+ const sourceWithLoaderGeneratedCss = missingProcessedLoaderGeneratedCss.trim().length === 0 ? source : createWebpackGeneratorUserCssSourceAppend({
1890
+ css: source,
1891
+ processed: true
1892
+ }, {
1893
+ css: missingProcessedLoaderGeneratedCss,
1894
+ processed: true
1895
+ }).css;
1896
+ const processedBareSelectorSourceCss = processedSourceCss ?? (hasTailwindGeneratedAssetCss ? removeWebpackTailwindGeneratedAssetCss(sourceWithLoaderGeneratedCss) : void 0);
1897
+ const handledCss = hasTailwindGeneratedAssetCss && (!hasGeneratedCssMarker || !isWebGeneratorTarget && hasDeferredWebpackGeneratedCss(source, [...generatedCssSources.values()].map((item) => item.classSet))) ? isWebGeneratorTarget ? sourceWithLoaderGeneratedCss : (await compilerOptions.styleHandler(sourceWithLoaderGeneratedCss, cssHandlerOptionsForProcessedAsset)).css : sourceWithLoaderGeneratedCss;
1898
+ const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(handledCss, {
1899
+ cssPreflight: cssHandlerOptionsForProcessedAsset.isMainChunk,
1900
+ generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss
1901
+ }));
1902
+ const processedSourceBareUserCss = isWebGeneratorTarget || processedBareSelectorSourceCss === void 0 ? void 0 : createWebpackGeneratorUserCssSourceAppend({
1903
+ css: collectWebpackBareSelectorUserCss(processedBareSelectorSourceCss),
1904
+ processed: false
1905
+ });
1906
+ const finalizedProcessedSourceBareUserCss = processedSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(processedSourceBareUserCss.css, {
1907
+ cssPreflight: false,
1908
+ generatedCss: false
1909
+ });
1910
+ const missingProcessedSourceBareUserCss = finalizedProcessedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, finalizedProcessedSourceBareUserCss);
1911
+ const css = missingProcessedSourceBareUserCss.trim().length === 0 ? nextCss : createWebpackGeneratorUserCssSourceAppend({
1912
+ css: nextCss,
1913
+ processed: true
1914
+ }, {
1915
+ css: missingProcessedSourceBareUserCss,
1916
+ processed: true
1917
+ }).css;
1918
+ debug("css skip webpack-loader-pipeline asset: %s", file);
1919
+ return { result: new ConcatSource(finalizeTracedCss(css, cssHandlerOptionsForProcessedAsset, { finalized: true })) };
1920
+ }
1921
+ });
1922
+ }, cssTaskFactories, "tasks.css");
1923
+ return true;
1924
+ }
1925
+ const currentRawSource = readRawSource();
1926
+ if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
1927
+ const hashKey = `${file}:asset`;
1928
+ rememberProcessCacheKey(file, hashKey);
1929
+ await enqueueTask(async () => {
1930
+ await require_hmr_timing.processCachedTask({
1931
+ cache: compilerOptions.cache,
1932
+ cacheKey: file,
1933
+ hashKey,
1934
+ rawSource: currentRawSource,
1935
+ hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
1936
+ applyResult(source, { cacheHit }) {
1937
+ updateAssetIfChanged(file, source, {
1938
+ compare: !cacheHit,
1939
+ notifyUpdate: !cacheHit
1940
+ });
1941
+ },
1942
+ onCacheHit() {
1943
+ debug("css-loader runtime cache hit: %s", file);
1944
+ },
1945
+ transform: async () => ({ result: new ConcatSource(currentRawSource) })
1946
+ });
1947
+ }, cssTaskFactories, "tasks.css");
1948
+ return true;
1949
+ }
1950
+ return false;
1951
+ }
1952
+ //#endregion
1332
1953
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.ts
1333
1954
  const WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX = 2;
1334
1955
  function trimScanCache(cache) {
@@ -1561,6 +2182,11 @@ function setupWebpackV5ProcessAssetsHook(options) {
1561
2182
  debug("start");
1562
2183
  await runtimeState.readyPromise;
1563
2184
  const hmrTimingStartedAt = performance.now();
2185
+ const timingDetails = {};
2186
+ const recordTimingDetail = (name, startedAt) => {
2187
+ timingDetails[name] = (timingDetails[name] ?? 0) + Math.max(0, performance.now() - startedAt);
2188
+ };
2189
+ const setupStartedAt = performance.now();
1564
2190
  for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
1565
2191
  const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
1566
2192
  const { updateAssetIfChanged } = createWebpackAssetUpdater({
@@ -1582,6 +2208,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
1582
2208
  appType,
1583
2209
  cssMatcher: compilerOptions.cssMatcher
1584
2210
  }));
2211
+ const directCssAssetResources = createWebpackDirectCssAssetResourceMap(compilation.chunks, compilation.chunkGraph, compilerOptions.cssMatcher, (resource, issuer) => resolveWebpackCssAssetModuleResource(resource, issuer, {
2212
+ appType,
2213
+ cssMatcher: compilerOptions.cssMatcher
2214
+ }));
1585
2215
  const watchChangedFiles = new Set([...getWatchChangedFiles?.() ?? []].map((file) => node_path.default.resolve(file)));
1586
2216
  const taskConcurrency = watchMode ? require_hmr_timing.resolveTaskConcurrency(1) : void 0;
1587
2217
  const activeProcessCacheKeys = /* @__PURE__ */ new Set();
@@ -1602,6 +2232,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1602
2232
  compilation,
1603
2233
  cssAssetFiles: entries.map(([file]) => file),
1604
2234
  cssAssetResources,
2235
+ directCssAssetResources,
1605
2236
  cssHandlerOptionsCache,
1606
2237
  cssSources,
1607
2238
  cssUserHandlerOptionsCache,
@@ -1612,7 +2243,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
1612
2243
  runtimeState
1613
2244
  });
1614
2245
  const finalizeCssAssetSource = (source, options = {}) => finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options);
1615
- const webpackSourceCandidates = !isWebGeneratorTarget && groupedEntries.css.length > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates({
2246
+ const shouldRefreshWebpackSourceCandidates = !isWebGeneratorTarget && groupedEntries.css.length > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions);
2247
+ recordTimingDetail("setup", setupStartedAt);
2248
+ const sourceCandidatesStartedAt = performance.now();
2249
+ const webpackSourceCandidates = shouldRefreshWebpackSourceCandidates ? await refreshWebpackSourceCandidates({
1616
2250
  compilerOptions,
1617
2251
  debug,
1618
2252
  outputDir,
@@ -1622,6 +2256,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1622
2256
  watchMode
1623
2257
  }) : void 0;
1624
2258
  const webpackSourceCandidateValueSignature = webpackSourceCandidates ? require_source_candidate_scan_signature.createCandidateSignature(webpackSourceCandidates.getSourceCandidatesForEntries(void 0)) : "source-candidates:0";
2259
+ recordTimingDetail("sourceCandidates", sourceCandidatesStartedAt);
1625
2260
  const cssSourceTraceTokenSources = createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates);
1626
2261
  const cssSourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
1627
2262
  const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
@@ -1635,6 +2270,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1635
2270
  isWebGeneratorTarget
1636
2271
  });
1637
2272
  const hasRuntimeTransformAssets = Boolean(!isWebGeneratorTarget && ((groupedEntries.html?.length ?? 0) > 0 || (groupedEntries.js?.length ?? 0) > 0));
2273
+ const runtimeStartedAt = performance.now();
1638
2274
  const forceRuntimeRefresh = getRuntimeRefreshRequirement();
1639
2275
  debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.tailwindRuntime.majorVersion ?? "unknown");
1640
2276
  let runtimeSet;
@@ -1672,6 +2308,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1672
2308
  }
1673
2309
  await refreshRuntimeMetadata(forceRuntimeRefresh);
1674
2310
  consumeRuntimeRefreshRequirement();
2311
+ recordTimingDetail("runtime", runtimeStartedAt);
1675
2312
  const webpackSourceCandidateSet = webpackSourceCandidates?.getSourceCandidatesForEntries(void 0);
1676
2313
  const generatorRuntimeSet = new Set(runtimeSet);
1677
2314
  addRuntimeTransformCandidates(generatorRuntimeSet, webpackSourceCandidateSet);
@@ -1726,520 +2363,107 @@ function setupWebpackV5ProcessAssetsHook(options) {
1726
2363
  const defaultTemplateHandlerOptions = { runtimeSet: transformRuntimeSet };
1727
2364
  debug("get runtimeSet, class count: %d, transform class count: %d", runtimeSet.size, transformRuntimeSet.size);
1728
2365
  const tasks = [];
1729
- const htmlTaskFactories = [];
1730
2366
  const cssTaskFactories = [];
1731
- const enqueueTask = async (factory, target) => {
2367
+ const enqueueTask = async (factory, target, phase) => {
2368
+ const timedFactory = async () => {
2369
+ const startedAt = performance.now();
2370
+ try {
2371
+ await factory();
2372
+ } finally {
2373
+ recordTimingDetail(phase, startedAt);
2374
+ }
2375
+ };
1732
2376
  if (watchMode) {
1733
- await factory();
2377
+ await timedFactory();
1734
2378
  return;
1735
2379
  }
1736
- target.push(factory);
2380
+ target.push(timedFactory);
1737
2381
  };
1738
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
1739
- const [file, originalSource] = element;
1740
- let rawSource;
1741
- const readRawSource = () => {
1742
- rawSource ?? (rawSource = originalSource.source().toString());
1743
- return rawSource;
1744
- };
1745
- const cacheKey = file;
1746
- const hashKey = `${file}:asset`;
1747
- rememberProcessCacheKey(cacheKey, hashKey);
1748
- const chunkHash = assetHashByChunk.get(file);
1749
- await enqueueTask(async () => {
1750
- await require_hmr_timing.processCachedTask({
1751
- cache: compilerOptions.cache,
1752
- cacheKey,
1753
- hashKey,
1754
- rawSource: chunkHash === void 0 ? readRawSource() : void 0,
1755
- hash: chunkHash,
1756
- applyResult(source, { cacheHit }) {
1757
- updateAssetIfChanged(file, source, {
1758
- compare: !cacheHit,
1759
- notifyUpdate: !cacheHit
1760
- });
1761
- },
1762
- onCacheHit() {
1763
- debug("html cache hit: %s", file);
1764
- },
1765
- transform: async () => {
1766
- const wxml = await compilerOptions.templateHandler(readRawSource(), defaultTemplateHandlerOptions);
1767
- const source = new ConcatSource(wxml);
1768
- debug("html handle: %s", file);
1769
- return { result: source };
1770
- }
1771
- });
1772
- }, htmlTaskFactories);
1773
- }
1774
- const jsTaskFactories = [];
1775
- const enqueueJsTask = async (factory) => {
1776
- await enqueueTask(factory, jsTaskFactories);
2382
+ const { htmlTaskFactories, jsTaskFactories } = await enqueueWebpackHtmlAndJsTasks({
2383
+ ConcatSource,
2384
+ applyWebpackLinkedJsResults,
2385
+ assetHashByChunk,
2386
+ compilation,
2387
+ compilerOptions,
2388
+ debug,
2389
+ defaultTemplateHandlerOptions,
2390
+ enqueueTask,
2391
+ groupedEntries,
2392
+ isWebGeneratorTarget,
2393
+ jsAssets,
2394
+ moduleGraphOptions,
2395
+ outputDir,
2396
+ rememberProcessCacheKey,
2397
+ rememberTransformedRuntimeCandidates,
2398
+ runtimeState,
2399
+ transformRuntimeSet,
2400
+ updateAssetIfChanged
2401
+ });
2402
+ const cssTaskContext = {
2403
+ ConcatSource,
2404
+ assetHashByChunk,
2405
+ compilation,
2406
+ compilerOptions,
2407
+ configuredCssEntryFiles,
2408
+ configuredMainCssEntryFiles,
2409
+ createRuntimeSetHash,
2410
+ cssSourceTraceSignature,
2411
+ cssSources,
2412
+ cssTaskFactories,
2413
+ debug,
2414
+ enqueueTask,
2415
+ finalizeCssAssetSource,
2416
+ finalizeTracedCss,
2417
+ generatedCssSources,
2418
+ generatorRuntimeSet,
2419
+ getCssHandlerOptions,
2420
+ getCssUserHandlerOptions,
2421
+ getGeneratorRuntimeSet,
2422
+ hasConfiguredTailwindV4SourceRoots,
2423
+ isKnownWebpackProcessedCssAsset,
2424
+ isSameWebpackSourceScope,
2425
+ isWebGeneratorTarget,
2426
+ isWebpackProcessedCssAsset,
2427
+ processedCssAssetSkipDecisionCache,
2428
+ rememberProcessCacheKey,
2429
+ resolveWebpackCssSourceFile,
2430
+ runtimeAffectingSourceHash,
2431
+ runtimeState,
2432
+ transformRuntimeSet,
2433
+ updateAssetIfChanged,
2434
+ watchMode,
2435
+ webpackSourceCandidateSet,
2436
+ webpackSourceCandidateValueSignature,
2437
+ webpackSourceCandidates
1777
2438
  };
1778
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
1779
- const cacheKey = getCacheKey(file);
1780
- const asset = compilation.getAsset(file);
1781
- if (!asset) continue;
1782
- const hashKey = `${file}:asset`;
1783
- rememberProcessCacheKey(cacheKey, hashKey);
1784
- const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
1785
- const initialSource = asset.source.source();
1786
- const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
1787
- const chunkHash = assetHashByChunk.get(file);
1788
- await enqueueJsTask(async () => {
1789
- await require_hmr_timing.processCachedTask({
1790
- cache: compilerOptions.cache,
1791
- cacheKey,
1792
- hashKey,
1793
- rawSource: chunkHash === void 0 ? initialRawSource : void 0,
1794
- hash: chunkHash,
1795
- applyResult(source, { cacheHit }) {
1796
- if (updateAssetIfChanged(file, source, {
1797
- compare: !cacheHit,
1798
- notifyUpdate: !cacheHit
1799
- })) rememberTransformedRuntimeCandidates(source);
1800
- },
1801
- onCacheHit() {
1802
- debug("js cache hit: %s", file);
1803
- },
1804
- transform: async () => {
1805
- const currentSourceValue = compilation.getAsset(file)?.source.source();
1806
- const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
1807
- const handlerOptions = {
1808
- tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
1809
- generateMap: false,
1810
- filename: absoluteFile,
1811
- moduleGraph: moduleGraphOptions,
1812
- babelParserOptions: { sourceFilename: absoluteFile }
1813
- };
1814
- if (require_context.shouldSkipJsTransform(currentSource, {
1815
- ...handlerOptions,
1816
- classNameSet: transformRuntimeSet
1817
- })) return { result: new ConcatSource(currentSource) };
1818
- const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
1819
- const source = new ConcatSource(code);
1820
- debug("js handle: %s", file);
1821
- applyWebpackLinkedJsResults({
1822
- ConcatSource,
1823
- compilation,
1824
- compilerOptions,
1825
- debug,
1826
- jsAssets,
1827
- linked
1828
- });
1829
- return { result: source };
1830
- }
1831
- });
1832
- });
1833
- }
1834
2439
  for (const element of groupedEntries.css) {
1835
- const [file, originalSource] = element;
1836
- let rawSource;
1837
- const readRawSource = () => {
1838
- rawSource ?? (rawSource = originalSource.source().toString());
1839
- return rawSource;
1840
- };
1841
- const chunkHash = assetHashByChunk.get(file);
1842
- const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file, readRawSource());
1843
- const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
1844
- const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
1845
- const processedSourceCss = processedSourceFile ? cssSources.get(node_path.default.resolve(processedSourceFile))?.css : void 0;
1846
- const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
1847
- const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
1848
- const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(node_path.default.resolve(processedSourceFile)) : void 0;
1849
- const processedAssetSourceHash = watchMode && isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk ? compilerOptions.cache.computeHash(readRawSource()) : chunkHash === void 0 ? processedCssAssetKnown ? "webpack-css-asset:known" : compilerOptions.cache.computeHash(readRawSource()) : "webpack-css-asset:chunk";
1850
- const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
1851
- let currentProcessedRawSource;
1852
- let hasGeneratedCssMarker = false;
1853
- let hasTailwindGeneratedAssetCss = false;
1854
- const readCurrentProcessedRawSource = () => {
1855
- currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
1856
- return currentProcessedRawSource;
1857
- };
1858
- const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
1859
- const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
1860
- if (cachedSkipProcessedCssAsset !== void 0) {
1861
- hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
1862
- hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
1863
- } else {
1864
- const source = readCurrentProcessedRawSource();
1865
- hasGeneratedCssMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source);
1866
- hasTailwindGeneratedAssetCss = require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source);
1867
- }
1868
- const hasProcessedAssetTailwindDirectives = () => {
1869
- const source = readCurrentProcessedRawSource();
1870
- return require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source);
1871
- };
1872
- const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
1873
- const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
1874
- ...source,
1875
- file: sourceFile
1876
- })), readCurrentProcessedRawSource()) !== void 0;
1877
- const hasProcessedLoaderGeneratedUserCss = cachedSkipProcessedCssAsset === void 0 && processedLoaderGeneratedCss !== void 0 && hasAdditionalWebpackAssetUserCssMarkers(processedLoaderGeneratedCss.css, readCurrentProcessedRawSource());
1878
- const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && require_generator.hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
1879
- const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1880
- const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && !hasProcessedLoaderGeneratedUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1881
- const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
1882
- if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
1883
- if (shouldSkipProcessedCssAsset) {
1884
- const hashKey = `${file}:asset`;
1885
- const sourceHash = processedAssetSourceHash;
1886
- rememberProcessCacheKey(file, hashKey);
1887
- await enqueueTask(async () => {
1888
- await require_hmr_timing.processCachedTask({
1889
- cache: compilerOptions.cache,
1890
- cacheKey: file,
1891
- hashKey,
1892
- rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
1893
- hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
1894
- applyResult(source, { cacheHit }) {
1895
- updateAssetIfChanged(file, source, {
1896
- compare: !cacheHit,
1897
- notifyUpdate: !cacheHit
1898
- });
1899
- },
1900
- onCacheHit() {
1901
- debug("css webpack-loader-pipeline cache hit: %s", file);
1902
- },
1903
- transform: async () => {
1904
- const source = readCurrentProcessedRawSource();
1905
- const processedBareSelectorSourceCss = processedSourceCss ?? (hasTailwindGeneratedAssetCss ? removeWebpackTailwindGeneratedAssetCss(source) : void 0);
1906
- const handledCss = hasTailwindGeneratedAssetCss && !hasGeneratedCssMarker ? isWebGeneratorTarget ? source : (await compilerOptions.styleHandler(source, cssHandlerOptionsForProcessedAsset)).css : source;
1907
- const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(handledCss, {
1908
- cssPreflight: cssHandlerOptionsForProcessedAsset.isMainChunk,
1909
- generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss
1910
- }));
1911
- const processedSourceBareUserCss = isWebGeneratorTarget || processedBareSelectorSourceCss === void 0 ? void 0 : createWebpackGeneratorUserCssSourceAppend({
1912
- css: collectWebpackBareSelectorUserCss(processedBareSelectorSourceCss),
1913
- processed: false
1914
- });
1915
- const finalizedProcessedSourceBareUserCss = processedSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(processedSourceBareUserCss.css, {
1916
- cssPreflight: false,
1917
- generatedCss: false
1918
- });
1919
- const missingProcessedSourceBareUserCss = finalizedProcessedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, finalizedProcessedSourceBareUserCss);
1920
- const css = missingProcessedSourceBareUserCss.trim().length === 0 ? nextCss : createWebpackGeneratorUserCssSourceAppend({
1921
- css: nextCss,
1922
- processed: true
1923
- }, {
1924
- css: missingProcessedSourceBareUserCss,
1925
- processed: true
1926
- }).css;
1927
- debug("css skip webpack-loader-pipeline asset: %s", file);
1928
- return { result: new ConcatSource(finalizeTracedCss(css, cssHandlerOptionsForProcessedAsset, { finalized: true })) };
1929
- }
1930
- });
1931
- }, cssTaskFactories);
1932
- continue;
1933
- }
1934
- const currentRawSource = readRawSource();
1935
- if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
1936
- const hashKey = `${file}:asset`;
1937
- rememberProcessCacheKey(file, hashKey);
1938
- await enqueueTask(async () => {
1939
- await require_hmr_timing.processCachedTask({
1940
- cache: compilerOptions.cache,
1941
- cacheKey: file,
1942
- hashKey,
1943
- rawSource: currentRawSource,
1944
- hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
1945
- applyResult(source, { cacheHit }) {
1946
- updateAssetIfChanged(file, source, {
1947
- compare: !cacheHit,
1948
- notifyUpdate: !cacheHit
1949
- });
1950
- },
1951
- onCacheHit() {
1952
- debug("css-loader runtime cache hit: %s", file);
1953
- },
1954
- transform: async () => ({ result: new ConcatSource(currentRawSource) })
1955
- });
1956
- }, cssTaskFactories);
1957
- continue;
1958
- }
1959
- const cacheKey = file;
1960
- const hashKey = `${file}:asset`;
1961
- rememberProcessCacheKey(cacheKey, hashKey);
1962
- const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
1963
- const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
1964
- const cssSourceHash = (() => {
1965
- const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
1966
- const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
1967
- const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
1968
- if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
1969
- return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
1970
- })();
1971
- const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
1972
- await enqueueTask(async () => {
1973
- await require_hmr_timing.processCachedTask({
1974
- cache: compilerOptions.cache,
1975
- cacheKey,
1976
- hashKey,
1977
- rawSource: currentRawSource,
1978
- hash: runtimeAwareHash,
1979
- applyResult(source, { cacheHit }) {
1980
- updateAssetIfChanged(file, source, {
1981
- compare: !cacheHit,
1982
- notifyUpdate: !cacheHit
1983
- });
1984
- },
1985
- onCacheHit() {
1986
- debug("css cache hit: %s", file);
1987
- },
1988
- transform: async () => {
1989
- await runtimeState.readyPromise;
1990
- const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
1991
- const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
1992
- if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
1993
- const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
1994
- const sourceCss = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css : void 0;
1995
- const isConfiguredCssSource = sourceFile !== void 0 && configuredCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
1996
- const isConfiguredMainCssSource = sourceFile !== void 0 && configuredMainCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
1997
- const sourceCssHasTailwindRoot = sourceCss !== void 0 && require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true });
1998
- const shouldPreserveExistingPreflight = cssHandlerOptions.isMainChunk || !isConfiguredMainCssSource && (isConfiguredCssSource || sourceCssHasTailwindRoot);
1999
- const loaderGeneratedCss = sourceFile && !isWebGeneratorTarget ? generatedCssSources.get(node_path.default.resolve(sourceFile)) : void 0;
2000
- const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
2001
- const explicitTailwindV4SourceCandidates = shouldRegenerateExplicitTailwindV4CssSource && sourceCss && sourceFile && webpackSourceCandidates?.getSourceCandidatesForEntries ? await require_tailwindcss.resolveTailwindV4EntriesFromCssCached(sourceCss, node_path.default.dirname(sourceFile)).then((resolved) => resolved?.entries ? webpackSourceCandidates.getSourceCandidatesForEntries(resolved.entries) : void 0) : void 0;
2002
- if (loaderGeneratedCss && shouldConsumeWebpackLoaderGeneratedCss({
2003
- hasBundlerGeneratedCssMarker: require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(currentRawSource),
2004
- loaderGeneratedClassSet: loaderGeneratedCss.classSet,
2005
- sourceCandidates: explicitTailwindV4SourceCandidates,
2006
- shouldRegenerateExplicitTailwindV4CssSource,
2007
- watchMode
2008
- })) {
2009
- for (const className of loaderGeneratedCss.classSet) {
2010
- generatorRuntimeSet.add(className);
2011
- transformRuntimeSet.add(className);
2012
- }
2013
- for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
2014
- const currentRawSourceWithoutBundlerMarkers = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentRawSource);
2015
- const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
2016
- const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? require_hmr_timing.removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
2017
- const loaderGeneratedCssWithoutMarkers = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(loaderGeneratedCss.css);
2018
- const currentAssetUserCssWithoutMarkers = currentAssetUserCss === void 0 ? "" : require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentAssetUserCss);
2019
- const currentAssetMissingUserCss = !(currentAssetUserCssWithoutMarkers.trim().length > 0 && !require_generator.isCommentOnlyCss(currentAssetUserCssWithoutMarkers)) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCssWithoutMarkers, loaderGeneratedCssWithoutMarkers);
2020
- if (isConfiguredMainCssSource && !cssHandlerOptions.isMainChunk) {
2021
- debug("css skip duplicate webpack loader main generation: %s <- %s", file, sourceFile);
2022
- const userCss = currentAssetMissingUserCss.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetMissingUserCss) ? "" : finalizeCssAssetSource(currentAssetMissingUserCss, {
2023
- cssPreflight: false,
2024
- generatedCss: false
2025
- });
2026
- return { result: new ConcatSource(finalizeTracedCss(userCss, cssHandlerOptions)) };
2027
- }
2028
- const mergedLoaderCss = currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
2029
- css: currentAssetUserCss === void 0 ? loaderGeneratedCss.css : currentAssetHasProcessedUrl ? require_hmr_timing.removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCss, loaderGeneratedCss.css),
2030
- processed: true
2031
- }, currentAssetUserCss === void 0 ? void 0 : {
2032
- css: currentAssetUserCss,
2033
- processed: true
2034
- }).css;
2035
- const finalizedLoaderCss = finalizeCssAssetSource(mergedLoaderCss, {
2036
- cssPreflight: cssHandlerOptions.isMainChunk,
2037
- generatedCss: true,
2038
- preserveExistingPreflight: shouldPreserveExistingPreflight
2039
- });
2040
- const loaderSourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[currentAssetUserCss === void 0 ? void 0 : {
2041
- css: currentAssetUserCss,
2042
- processed: true
2043
- }, sourceCss === void 0 ? void 0 : {
2044
- css: sourceCss,
2045
- processed: false
2046
- }].map((source) => {
2047
- if (source === void 0) return;
2048
- return {
2049
- css: collectWebpackBareSelectorUserCss(source.css),
2050
- processed: source.processed
2051
- };
2052
- }));
2053
- const finalizedLoaderSourceBareUserCss = loaderSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(loaderSourceBareUserCss.css, {
2054
- cssPreflight: false,
2055
- generatedCss: false
2056
- });
2057
- const missingLoaderSourceBareUserCss = finalizedLoaderSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedLoaderCss, finalizedLoaderSourceBareUserCss);
2058
- const css = finalizeTracedCss(missingLoaderSourceBareUserCss.trim().length === 0 ? finalizedLoaderCss : createWebpackGeneratorUserCssSourceAppend({
2059
- css: finalizedLoaderCss,
2060
- processed: true
2061
- }, {
2062
- css: missingLoaderSourceBareUserCss,
2063
- processed: true
2064
- }).css, cssHandlerOptions, { finalized: true });
2065
- debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
2066
- return { result: new ConcatSource(css) };
2067
- }
2068
- const sourceCssProcessed = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.processed === true : false;
2069
- const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
2070
- ...source,
2071
- file: registeredSourceFile
2072
- })), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
2073
- const currentAssetLooksGenerated = require_generator.hasTailwindGeneratedCss(currentRawSource) || require_generator.hasTailwindGeneratedCssMarkers(currentRawSource);
2074
- const currentAssetHasBundlerGeneratedMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(currentRawSource);
2075
- const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
2076
- if (sourceFile === void 0 && currentAssetHasBundlerGeneratedMarker && (currentAssetUserCssSource.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetUserCssSource))) return { result: new ConcatSource(finalizeTracedCss("", cssHandlerOptions)) };
2077
- const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
2078
- const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
2079
- const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss));
2080
- const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
2081
- const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
2082
- currentAssetHasUserCss,
2083
- currentAssetLooksGenerated,
2084
- currentAssetUserCssSource,
2085
- shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
2086
- currentAssetHasBundlerGeneratedMarker,
2087
- currentAssetHasUserCss,
2088
- currentAssetLooksGenerated,
2089
- registeredUserRawSource,
2090
- shouldPreserveGeneratedWebAssetUserCss,
2091
- sourceCssProcessed
2092
- }),
2093
- sourceCssProcessed
2094
- }), registeredUserRawSource);
2095
- if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(currentRawSource)) return { result: new ConcatSource(require_generator.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
2096
- const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
2097
- const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
2098
- const currentAssetHasTailwindDirectives = require_generator.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindApplyDirective(generatorRawSource);
2099
- const shouldForceTailwindV4Generation = hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 && sourceFile !== void 0 || currentAssetHasTailwindDirectives || hasExplicitTailwindV4SourceCss);
2100
- const shouldSkipUnmatchedMainCssGeneration = !isWebGeneratorTarget && cssHandlerOptions.isMainChunk && sourceFile === void 0 && configuredMainCssEntryFiles.length > 0 && !currentAssetHasTailwindDirectives;
2101
- const shouldSkipPlainNonMainCssGeneration = !cssHandlerOptions.isMainChunk && sourceCss !== void 0 && !hasExplicitSourceCssForCurrentAsset && !hasExplicitTailwindV4SourceCss && !currentAssetHasTailwindDirectives;
2102
- const shouldMergeFallbackGeneratorRuntime = cssHandlerOptions.isMainChunk || currentAssetHasTailwindDirectives || hasExplicitSourceCssForCurrentAsset;
2103
- const scopedFallbackGeneratorRuntimeSet = hasExplicitTailwindV4SourceCss || !shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet;
2104
- const resolvedScopedGeneratorRuntimeSet = await require_source_candidate_scan_signature.createScopedGeneratorRuntime({
2105
- cssHandlerOptions,
2106
- fallbackRuntime: scopedFallbackGeneratorRuntimeSet,
2107
- getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
2108
- majorVersion: runtimeState.tailwindRuntime.majorVersion,
2109
- outputFile: file,
2110
- rawSource: sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
2111
- shouldExcludeSubpackageSourceCandidates: () => false,
2112
- sourceFile: sourceFile ?? file,
2113
- scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
2114
- });
2115
- const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== scopedFallbackGeneratorRuntimeSet && shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
2116
- const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
2117
- const scopedGeneratorCompilerOptions = scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, { disableUnmatchedCssEntries: !isWebGeneratorTarget && cssHandlerOptions.isMainChunk });
2118
- const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
2119
- ...cssHandlerOptions,
2120
- sourceOptions: {
2121
- ...cssHandlerOptions.sourceOptions,
2122
- cssSources: generatorCssSources
2123
- }
2124
- };
2125
- const generatorOptions = {
2126
- opts: scopedGeneratorCompilerOptions,
2127
- runtimeState,
2128
- runtime: scopedGeneratorRuntimeSet,
2129
- rawSource: generatorRawSource,
2130
- forceGenerator: shouldForceTailwindV4Generation,
2131
- ...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
2132
- ...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
2133
- ...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
2134
- file,
2135
- cssHandlerOptions: generatorCssHandlerOptions,
2136
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
2137
- getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
2138
- sourceCandidates: scopedGeneratorRuntimeSet,
2139
- restoreLocalCssImports: false,
2140
- styleHandler: compilerOptions.styleHandler,
2141
- debug
2142
- };
2143
- let generated;
2144
- if (!shouldSkipUnmatchedMainCssGeneration && !shouldSkipPlainNonMainCssGeneration) try {
2145
- generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
2146
- ...generatorOptions,
2147
- outputFile: file
2148
- });
2149
- } catch (error) {
2150
- if (!shouldFallbackToWebpackUserCssOnGeneratorError({
2151
- configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
2152
- generatorRawSource,
2153
- hasExplicitTailwindV4SourceCss
2154
- })) throw error;
2155
- debug("css generator skipped for plain webpack css asset: %s %O", file, error);
2156
- generated = void 0;
2157
- }
2158
- else debug("css generator skipped for plain webpack css asset: %s", file);
2159
- const finalizedGeneratedCss = generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
2160
- css: generated.css,
2161
- processed: true
2162
- }, {
2163
- css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
2164
- processed: true
2165
- })?.css ?? generated.css : generated.css, {
2166
- cssPreflight: cssHandlerOptions.isMainChunk,
2167
- generatedCss: true,
2168
- preserveExistingPreflight: shouldPreserveExistingPreflight
2169
- }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false });
2170
- const sourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[
2171
- userRawSource,
2172
- sourceCss === void 0 ? void 0 : {
2173
- css: sourceCss,
2174
- processed: sourceCssProcessed
2175
- },
2176
- {
2177
- css: generatorRawSource,
2178
- processed: false
2179
- }
2180
- ].map((source) => {
2181
- if (source === void 0) return;
2182
- return {
2183
- css: collectWebpackBareSelectorUserCss(source.css),
2184
- processed: source.processed
2185
- };
2186
- }));
2187
- const finalizedSourceBareUserCss = sourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(sourceBareUserCss.css, {
2188
- cssPreflight: false,
2189
- generatedCss: false
2190
- });
2191
- const missingSourceBareUserCss = finalizedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedGeneratedCss, finalizedSourceBareUserCss);
2192
- const css = finalizeTracedCss(missingSourceBareUserCss.trim().length === 0 ? finalizedGeneratedCss : createWebpackGeneratorUserCssSourceAppend({
2193
- css: finalizedGeneratedCss,
2194
- processed: true
2195
- }, {
2196
- css: missingSourceBareUserCss,
2197
- processed: true
2198
- }).css, cssHandlerOptions, { finalized: true });
2199
- const source = new ConcatSource(css);
2200
- if (generated) {
2201
- for (const className of generated.classSet) generatorRuntimeSet.add(className);
2202
- debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
2203
- } else debug("css handle: %s", file);
2204
- return { result: source };
2205
- }
2206
- });
2207
- }, cssTaskFactories);
2440
+ if (await processWebpackProcessedCssAsset(element, cssTaskContext)) continue;
2441
+ await processWebpackGeneratedCssAsset(element, cssTaskContext);
2208
2442
  }
2209
- if (!watchMode) {
2210
- require_hmr_timing.pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
2211
- await Promise.all(tasks);
2212
- tasks.length = 0;
2213
- require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
2214
- await Promise.all(tasks);
2215
- tasks.length = 0;
2216
- require_hmr_timing.pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
2217
- }
2218
- await Promise.all(tasks);
2219
- compilerOptions.cache.prune?.({
2220
- cacheKeys: activeProcessCacheKeys,
2221
- hashKeys: activeProcessHashKeys
2222
- });
2223
- const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
2224
- pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
2225
- if (activeCssFiles.size > 0) pruneWebpackCssSources?.(/* @__PURE__ */ new Set([
2226
- ...registeredWebpackCssSourceFiles,
2227
- ...activeWebpackCssSourceFiles,
2228
- ...[...cssAssetResources.values()].flatMap((resources) => [...resources])
2229
- ]), { watchMode });
2230
- debug("end");
2231
- require_hmr_timing.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
2232
- activeAssetFiles: entries.length,
2233
- activeCssFiles: activeCssFiles.size,
2443
+ await finalizeWebpackProcessAssets({
2234
2444
  activeProcessCacheKeys,
2235
2445
  activeProcessHashKeys,
2236
- cache: compilerOptions.cache,
2446
+ activeWebpackCssSourceFiles,
2447
+ compilerOptions,
2448
+ cssAssetResources,
2237
2449
  cssHandlerOptionsCache,
2450
+ cssTaskFactories,
2238
2451
  cssUserHandlerOptionsCache,
2239
- phase: "processAssets",
2240
- sourceCandidateScan: webpackSourceCandidateScanCache.getMemoryStats()
2241
- }) });
2242
- compilerOptions.onEnd();
2452
+ debug,
2453
+ entries,
2454
+ groupedEntries,
2455
+ hmrTimingStartedAt,
2456
+ htmlTaskFactories,
2457
+ jsTaskFactories,
2458
+ pruneWebpackCssSources,
2459
+ recordTimingDetail,
2460
+ registeredWebpackCssSourceFiles,
2461
+ taskConcurrency,
2462
+ tasks,
2463
+ timingDetails,
2464
+ watchMode,
2465
+ webpackSourceCandidateScanCache
2466
+ });
2243
2467
  });
2244
2468
  if (!isWebGeneratorTarget) compilation.hooks.processAssets.tapPromise({
2245
2469
  name: `${require_context.pluginName}:finalize-css-assets`,
@@ -2260,6 +2484,101 @@ function setupWebpackV5ProcessAssetsHook(options) {
2260
2484
  });
2261
2485
  }
2262
2486
  //#endregion
2487
+ //#region src/shared/mpx-plugin-owner.ts
2488
+ const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
2489
+ const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
2490
+ const MPX_WEBPACK_PLUGIN_LIB_RE = /^(.*[\\/]@mpxjs[\\/]webpack-plugin)[\\/]lib[\\/]/;
2491
+ const MPX_RECORD_RESOURCE_MAP_DEPENDENCY_RE = /@mpxjs[\\/]webpack-plugin[\\/]lib[\\/]dependencies[\\/]RecordResourceMapDependency(?:\.js)?$/;
2492
+ const compilationOwnerDirs = /* @__PURE__ */ new WeakMap();
2493
+ function findMpxWebpackPluginDir(value) {
2494
+ if (typeof value === "string") return value.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1];
2495
+ if (Array.isArray(value)) {
2496
+ for (const item of value) {
2497
+ const result = findMpxWebpackPluginDir(item);
2498
+ if (result) return result;
2499
+ }
2500
+ return;
2501
+ }
2502
+ if (value && typeof value === "object") for (const key of [
2503
+ "loader",
2504
+ "use",
2505
+ "rules",
2506
+ "oneOf"
2507
+ ]) {
2508
+ const result = findMpxWebpackPluginDir(value[key]);
2509
+ if (result) return result;
2510
+ }
2511
+ }
2512
+ function resolveContextPluginDir(context) {
2513
+ if (typeof context !== "string" || context.length === 0) return;
2514
+ try {
2515
+ const projectRequire = (0, node_module.createRequire)(node_path.default.join(context, "package.json"));
2516
+ return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2517
+ } catch {
2518
+ return;
2519
+ }
2520
+ }
2521
+ function resolveCompilationPluginDir(compilation, candidates) {
2522
+ const getTemplate = compilation?.dependencyTemplates?.get;
2523
+ if (typeof getTemplate !== "function") return;
2524
+ if (compilation && typeof compilation === "object") {
2525
+ const cached = compilationOwnerDirs.get(compilation);
2526
+ if (cached) return cached;
2527
+ }
2528
+ const rememberOwner = (pluginDir) => {
2529
+ if (pluginDir && compilation && typeof compilation === "object") compilationOwnerDirs.set(compilation, pluginDir);
2530
+ return pluginDir;
2531
+ };
2532
+ for (const [file, module] of Object.entries(localRequire.cache)) {
2533
+ if (!MPX_RECORD_RESOURCE_MAP_DEPENDENCY_RE.test(file)) continue;
2534
+ if (getTemplate.call(compilation.dependencyTemplates, module?.exports)) return rememberOwner(file.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1]);
2535
+ }
2536
+ for (const pluginDir of candidates) try {
2537
+ const dependency = (0, node_module.createRequire)(node_path.default.join(pluginDir, "package.json"))(node_path.default.join(pluginDir, "lib/dependencies/RecordResourceMapDependency"));
2538
+ if (getTemplate.call(compilation.dependencyTemplates, dependency)) return rememberOwner(pluginDir);
2539
+ } catch {}
2540
+ }
2541
+ function collectMpxWebpackPluginDirs(owner, fallback) {
2542
+ const activeLoaderPluginDir = findMpxWebpackPluginDir([owner?._module?.loaders, owner?.loaders]);
2543
+ const contextPluginDirs = [
2544
+ owner?.rootContext,
2545
+ owner?.context,
2546
+ owner?.options?.context,
2547
+ node_process.default.cwd()
2548
+ ].map(resolveContextPluginDir).filter((item) => Boolean(item));
2549
+ const configuredRulePluginDir = findMpxWebpackPluginDir(owner?.options?.module?.rules);
2550
+ const cachedPluginDirs = Object.keys(localRequire.cache).map((file) => file.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1] ?? (MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file) ? node_path.default.dirname(file) : void 0)).filter((item) => Boolean(item));
2551
+ const localPluginDir = (() => {
2552
+ try {
2553
+ return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2554
+ } catch {
2555
+ return;
2556
+ }
2557
+ })();
2558
+ return {
2559
+ activeLoaderPluginDir,
2560
+ candidates: new Set([
2561
+ activeLoaderPluginDir,
2562
+ ...contextPluginDirs,
2563
+ configuredRulePluginDir,
2564
+ fallback,
2565
+ ...cachedPluginDirs,
2566
+ localPluginDir
2567
+ ].filter((item) => Boolean(item))),
2568
+ configuredRulePluginDir,
2569
+ contextPluginDirs,
2570
+ cachedPluginDirs,
2571
+ localPluginDir
2572
+ };
2573
+ }
2574
+ function resolveMpxWebpackPluginCompilationOwnerDir(owner, compilation, fallback) {
2575
+ return resolveCompilationPluginDir(compilation, collectMpxWebpackPluginDirs(owner, fallback).candidates);
2576
+ }
2577
+ function resolveMpxWebpackPluginDir(owner, fallback, compilation = owner?._compilation ?? owner?.compilation) {
2578
+ const { activeLoaderPluginDir, candidates, configuredRulePluginDir, contextPluginDirs, cachedPluginDirs, localPluginDir } = collectMpxWebpackPluginDirs(owner, fallback);
2579
+ return resolveCompilationPluginDir(compilation, candidates) ?? activeLoaderPluginDir ?? contextPluginDirs[0] ?? configuredRulePluginDir ?? fallback ?? cachedPluginDirs[0] ?? localPluginDir;
2580
+ }
2581
+ //#endregion
2263
2582
  //#region src/shared/tailwindcss-css-redirect.ts
2264
2583
  const moduleWithMutableResolve = node_module.default;
2265
2584
  const patched = /* @__PURE__ */ new WeakSet();
@@ -2278,9 +2597,8 @@ function installTailwindcssCssRedirect(pkgDir) {
2278
2597
  }
2279
2598
  //#endregion
2280
2599
  //#region src/shared/mpx.ts
2281
- const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
2282
2600
  const MPX_STYLE_RESOURCE_QUERY_RE = /(?:^|[?&])type=styles(?:&|$)/;
2283
- const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
2601
+ const MPX_WEBPACK_PLUGIN_REQUEST_PATH_RE = /(?:^|[\\/])@mpxjs[\\/]webpack-plugin(?:[\\/](.+))?$/;
2284
2602
  function isMpxStyleResourceQuery(query) {
2285
2603
  if (typeof query !== "string") return false;
2286
2604
  return MPX_STYLE_RESOURCE_QUERY_RE.test(query);
@@ -2288,23 +2606,61 @@ function isMpxStyleResourceQuery(query) {
2288
2606
  function getTailwindcssCssEntry(pkgDir) {
2289
2607
  return node_path.default.join(pkgDir, "index.css");
2290
2608
  }
2291
- function resolveMpxWebpackPluginDir(compiler) {
2292
- const candidates = [
2293
- compiler?.context,
2294
- compiler?.options?.context,
2295
- node_process.default.cwd()
2296
- ].filter((item) => typeof item === "string" && item.length > 0);
2297
- for (const candidate of candidates) try {
2298
- const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
2299
- return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2300
- } catch {}
2301
- const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
2302
- if (cachedPackageJson) return node_path.default.dirname(cachedPackageJson);
2303
- try {
2304
- return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2305
- } catch {
2306
- return;
2307
- }
2609
+ function rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir, pathImpl = node_path.default) {
2610
+ return request.split("!").map((segment) => {
2611
+ const queryIndex = segment.indexOf("?");
2612
+ const requestPath = queryIndex === -1 ? segment : segment.slice(0, queryIndex);
2613
+ const query = queryIndex === -1 ? "" : segment.slice(queryIndex);
2614
+ const match = requestPath.match(MPX_WEBPACK_PLUGIN_REQUEST_PATH_RE);
2615
+ if (!match) return segment;
2616
+ const subpath = match[1];
2617
+ return `${subpath ? pathImpl.join(mpxWebpackPluginDir, ...subpath.split(/[\\/]/)) : mpxWebpackPluginDir}${query}`;
2618
+ }).join("!");
2619
+ }
2620
+ function patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir) {
2621
+ if (!mpxWebpackPluginDir || !compiler) return false;
2622
+ const pluginName = "weapp-tailwindcss-mpx-loader-resolve";
2623
+ const patchedCompilers = /* @__PURE__ */ new WeakSet();
2624
+ const patchedLoaderResolvers = /* @__PURE__ */ new WeakSet();
2625
+ const patchedResolverFactories = /* @__PURE__ */ new WeakSet();
2626
+ let activePluginDir = mpxWebpackPluginDir;
2627
+ const getActivePluginDir = () => activePluginDir;
2628
+ const install = (targetCompiler) => {
2629
+ if (!targetCompiler || typeof targetCompiler !== "object" || patchedCompilers.has(targetCompiler)) return;
2630
+ patchedCompilers.add(targetCompiler);
2631
+ ensureResolveLoaderAlias(targetCompiler, activePluginDir);
2632
+ const resolverFactory = targetCompiler.resolverFactory;
2633
+ if (resolverFactory && typeof resolverFactory === "object" && !patchedResolverFactories.has(resolverFactory)) {
2634
+ patchedResolverFactories.add(resolverFactory);
2635
+ installMpxResolveLoaderAlias(targetCompiler, getActivePluginDir);
2636
+ }
2637
+ targetCompiler.hooks?.normalModuleFactory?.tap?.(pluginName, (normalModuleFactory) => {
2638
+ const loaderResolver = normalModuleFactory.getResolver?.("loader");
2639
+ if (loaderResolver && typeof loaderResolver === "object" && !patchedLoaderResolvers.has(loaderResolver)) {
2640
+ patchedLoaderResolvers.add(loaderResolver);
2641
+ patchMpxLoaderResolver(loaderResolver, getActivePluginDir);
2642
+ }
2643
+ normalModuleFactory.hooks.beforeResolve.tap(pluginName, (resolveData) => {
2644
+ const pluginDir = getActivePluginDir();
2645
+ if (pluginDir && typeof resolveData?.request === "string") resolveData.request = rewriteMpxWebpackPluginRequests(resolveData.request, pluginDir);
2646
+ });
2647
+ });
2648
+ targetCompiler.hooks?.compilation?.tap?.(pluginName, (compilation) => {
2649
+ const compilationPluginDir = resolveMpxWebpackPluginCompilationOwnerDir(targetCompiler, compilation, activePluginDir);
2650
+ if (compilationPluginDir) {
2651
+ activePluginDir = compilationPluginDir;
2652
+ patchMpxWebpackPluginNormalizeLib(targetCompiler, compilationPluginDir);
2653
+ ensureResolveLoaderAlias(targetCompiler, compilationPluginDir);
2654
+ const alias = targetCompiler.options?.resolve?.alias;
2655
+ if (alias) addMpxWebpackPluginAlias(alias, compilationPluginDir);
2656
+ }
2657
+ compilation.hooks?.childCompiler?.tap?.(pluginName, (childCompiler) => {
2658
+ install(childCompiler);
2659
+ });
2660
+ });
2661
+ };
2662
+ install(compiler);
2663
+ return true;
2308
2664
  }
2309
2665
  function isMpxWebpackPluginRequest(request) {
2310
2666
  return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
@@ -2317,20 +2673,33 @@ function addMpxWebpackPluginAlias(alias, pkgDir) {
2317
2673
  const recordLoader = node_path.default.join(pkgDir, "lib/record-loader");
2318
2674
  const styleCompiler = node_path.default.join(pkgDir, "lib/style-compiler/index");
2319
2675
  const stripConditionalLoader = node_path.default.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
2320
- if (Array.isArray(alias)) alias.push({
2321
- name: "@mpxjs/webpack-plugin/lib/record-loader",
2322
- alias: recordLoader
2323
- }, {
2324
- name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
2325
- alias: styleCompiler
2326
- }, {
2327
- name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
2328
- alias: stripConditionalLoader
2329
- }, {
2330
- name: /^@mpxjs\/webpack-plugin\//,
2331
- alias: pkgDir
2332
- });
2333
- else {
2676
+ if (Array.isArray(alias)) {
2677
+ const entries = [
2678
+ {
2679
+ name: "@mpxjs/webpack-plugin/lib/record-loader",
2680
+ alias: recordLoader
2681
+ },
2682
+ {
2683
+ name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
2684
+ alias: styleCompiler
2685
+ },
2686
+ {
2687
+ name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
2688
+ alias: stripConditionalLoader
2689
+ },
2690
+ {
2691
+ name: /^@mpxjs\/webpack-plugin\//,
2692
+ alias: pkgDir
2693
+ }
2694
+ ];
2695
+ const managedNames = new Set(entries.filter((entry) => typeof entry.name === "string").map((entry) => entry.name));
2696
+ const managedPatterns = new Set(entries.filter((entry) => entry.name instanceof RegExp).map((entry) => `${entry.name.source}/${entry.name.flags}`));
2697
+ for (let index = alias.length - 1; index >= 0; index--) {
2698
+ const name = alias[index]?.name;
2699
+ if (managedNames.has(name) || name instanceof RegExp && managedPatterns.has(`${name.source}/${name.flags}`)) alias.splice(index, 1);
2700
+ }
2701
+ alias.unshift(...entries);
2702
+ } else {
2334
2703
  alias["@mpxjs/webpack-plugin"] = pkgDir;
2335
2704
  alias["@mpxjs/webpack-plugin$"] = pkgDir;
2336
2705
  alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
@@ -2344,27 +2713,42 @@ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
2344
2713
  compiler.options.resolveLoader.alias = alias;
2345
2714
  addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
2346
2715
  }
2347
- function resolveMpxWebpackPluginRequire(compiler) {
2348
- const candidates = [
2349
- compiler?.context,
2350
- compiler?.options?.context,
2351
- node_process.default.cwd()
2352
- ].filter((item) => typeof item === "string" && item.length > 0);
2353
- for (const candidate of candidates) try {
2354
- const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
2355
- projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
2356
- return projectRequire;
2357
- } catch {}
2358
- const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
2359
- if (cachedPackageJson) return (0, node_module.createRequire)(cachedPackageJson);
2360
- return localRequire;
2716
+ function installMpxResolveLoaderAlias(compiler, getMpxWebpackPluginDir) {
2717
+ const resolveOptionsHook = compiler?.resolverFactory?.hooks?.resolveOptions?.for?.("loader");
2718
+ if (!resolveOptionsHook?.tap) return;
2719
+ resolveOptionsHook.tap({
2720
+ name: "weapp-tailwindcss-mpx-loader-resolve",
2721
+ stage: 100
2722
+ }, (resolveOptions) => {
2723
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2724
+ if (!mpxWebpackPluginDir) return resolveOptions;
2725
+ const alias = Array.isArray(resolveOptions.alias) ? [...resolveOptions.alias] : { ...resolveOptions.alias };
2726
+ addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
2727
+ return {
2728
+ ...resolveOptions,
2729
+ alias
2730
+ };
2731
+ });
2732
+ }
2733
+ function patchMpxLoaderResolver(resolver, getMpxWebpackPluginDir) {
2734
+ const originalResolve = resolver?.resolve;
2735
+ if (typeof originalResolve !== "function" || originalResolve.__weappTwPatched) return;
2736
+ const wrappedResolve = function(...args) {
2737
+ const requestIndex = typeof args[0] === "string" ? 1 : 2;
2738
+ const request = args[requestIndex];
2739
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2740
+ if (mpxWebpackPluginDir && typeof request === "string" && isMpxWebpackPluginRequest(request)) args[requestIndex] = resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir);
2741
+ return originalResolve.apply(this, args);
2742
+ };
2743
+ wrappedResolve.__weappTwPatched = true;
2744
+ wrappedResolve.__weappTwOriginal = originalResolve;
2745
+ resolver.resolve = wrappedResolve;
2361
2746
  }
2362
- function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
2747
+ function patchMpxWebpackPluginNormalizeLib(_compiler, mpxWebpackPluginDir) {
2363
2748
  if (!mpxWebpackPluginDir) return false;
2364
- const projectRequire = resolveMpxWebpackPluginRequire(compiler);
2365
2749
  let normalize;
2366
2750
  try {
2367
- normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
2751
+ normalize = (0, node_module.createRequire)(node_path.default.join(mpxWebpackPluginDir, "package.json"))(node_path.default.join(mpxWebpackPluginDir, "lib/utils/normalize"));
2368
2752
  } catch {
2369
2753
  return false;
2370
2754
  }
@@ -2382,6 +2766,7 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
2382
2766
  compiler.options.resolve = compiler.options.resolve || {};
2383
2767
  const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
2384
2768
  patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
2769
+ patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir);
2385
2770
  if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
2386
2771
  const alias = compiler.options.resolve.alias ?? {};
2387
2772
  compiler.options.resolve.alias = alias;
@@ -2400,19 +2785,31 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
2400
2785
  return tailwindcssCssEntry;
2401
2786
  }
2402
2787
  function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
2403
- if (!enabled || typeof loaderContext.resolve !== "function") return;
2404
- const originalResolve = loaderContext.resolve;
2405
- if (originalResolve.__weappTwPatched) return;
2788
+ if (!enabled) return;
2406
2789
  const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
2407
- const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
2408
- const wrappedResolve = function(context, request, callback) {
2409
- if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
2410
- if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
2411
- if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
2412
- return originalResolve.call(this, context, request, callback);
2413
- };
2414
- wrappedResolve.__weappTwPatched = true;
2415
- loaderContext.resolve = wrappedResolve;
2790
+ const getMpxWebpackPluginDir = () => resolveMpxWebpackPluginDir(loaderContext);
2791
+ const originalResolve = loaderContext.resolve;
2792
+ if (typeof originalResolve === "function" && !originalResolve.__weappTwPatched) {
2793
+ const wrappedResolve = function(context, request, callback) {
2794
+ if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
2795
+ if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
2796
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2797
+ if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
2798
+ return originalResolve.call(this, context, request, callback);
2799
+ };
2800
+ wrappedResolve.__weappTwPatched = true;
2801
+ loaderContext.resolve = wrappedResolve;
2802
+ }
2803
+ const originalImportModule = loaderContext.importModule;
2804
+ if (typeof originalImportModule === "function" && !originalImportModule.__weappTwPatched) {
2805
+ const wrappedImportModule = function(request, ...args) {
2806
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2807
+ const resolvedRequest = mpxWebpackPluginDir && typeof request === "string" ? rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir) : request;
2808
+ return originalImportModule.call(this, resolvedRequest, ...args);
2809
+ };
2810
+ wrappedImportModule.__weappTwPatched = true;
2811
+ loaderContext.importModule = wrappedImportModule;
2812
+ }
2416
2813
  }
2417
2814
  function setupMpxTailwindcssRedirect(pkgDir, enabled) {
2418
2815
  if (enabled) installTailwindcssCssRedirect(pkgDir);
@@ -2479,7 +2876,7 @@ function createDefaultLoaderAnchorFinders() {
2479
2876
  //#endregion
2480
2877
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
2481
2878
  function setupWebpackV5Loaders(options) {
2482
- const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, loaderAnchorFinders = createDefaultLoaderAnchorFinders(), mpxCssImportRewrite = false, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
2879
+ const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, updateWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, loaderAnchorFinders = createDefaultLoaderAnchorFinders(), mpxCssImportRewrite = false, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
2483
2880
  const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(compilerOptions.generator, {
2484
2881
  appType: compilerOptions.appType,
2485
2882
  platform: compilerOptions.cssOptions?.platform ?? compilerOptions.platform,
@@ -2497,11 +2894,14 @@ function setupWebpackV5Loaders(options) {
2497
2894
  if (shouldRewriteCssImports && mpxCssImportRewrite) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
2498
2895
  const runtimeClassSetLoader = runtimeLoaderPath ?? node_path.default.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
2499
2896
  const shouldInjectRuntimeClassSetLoader = !generatorBranch.isWeb;
2500
- const shouldInjectCssImportRewriteLoader = shouldRewriteCssImports || generatorOptions.enabled && (!generatorBranch.isWeb || runtimeState.tailwindRuntime.majorVersion === 4);
2897
+ const shouldInjectCssGenerationLoader = generatorOptions.enabled && runtimeState.tailwindRuntime.majorVersion === 4 && (generatorTarget === "web" || generatorTarget === "weapp");
2898
+ const shouldInjectCssImportRewriteLoader = shouldRewriteCssImports || shouldInjectCssGenerationLoader;
2899
+ const runtimeCssGenerationLoader = shouldInjectCssGenerationLoader ? node_path.default.resolve(__dirname, "./weapp-tw-css-generation-loader.js") : void 0;
2501
2900
  const runtimeCssImportRewriteLoader = shouldInjectCssImportRewriteLoader ? node_path.default.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
2502
2901
  const runtimeClassSetLoaderExists = node_fs.default.existsSync(runtimeClassSetLoader);
2902
+ const runtimeCssGenerationLoaderExists = runtimeCssGenerationLoader ? node_fs.default.existsSync(runtimeCssGenerationLoader) : false;
2503
2903
  const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? node_fs.default.existsSync(runtimeCssImportRewriteLoader) : false;
2504
- const runtimeLoaderRewriteOptions = shouldInjectCssImportRewriteLoader ? {
2904
+ const runtimeLoaderRewriteOptions = shouldInjectCssImportRewriteLoader || shouldInjectCssGenerationLoader ? {
2505
2905
  pkgDir: weappTailwindcssPackageDir,
2506
2906
  compilerOptions,
2507
2907
  runtimeState,
@@ -2516,7 +2916,8 @@ function setupWebpackV5Loaders(options) {
2516
2916
  classSet: {
2517
2917
  getClassSet: getClassSetInLoader,
2518
2918
  getWatchDependencies: getRuntimeWatchDependencies,
2519
- ...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
2919
+ ...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile },
2920
+ ...updateWebpackGeneratedCss === void 0 ? {} : { updateGeneratedCss: updateWebpackGeneratedCss }
2520
2921
  },
2521
2922
  ...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
2522
2923
  });
@@ -2526,7 +2927,11 @@ function setupWebpackV5Loaders(options) {
2526
2927
  compiler.hooks.watchClose?.tap?.(require_context.pluginName, cleanupWebpackLoaderRuntime);
2527
2928
  compiler.hooks.shutdown?.tap?.(require_context.pluginName, cleanupWebpackLoaderRuntime);
2528
2929
  const { findRewriteAnchor, findClassSetAnchor } = loaderAnchorFinders;
2529
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
2930
+ const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions && shouldInjectCssImportRewriteLoader ? {
2931
+ generateCss: false,
2932
+ tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey
2933
+ } : void 0;
2934
+ const cssGenerationLoaderOptions = runtimeLoaderRewriteOptions && shouldInjectCssGenerationLoader ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
2530
2935
  if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && mpxCssImportRewrite) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
2531
2936
  const createRuntimeClassSetLoaderEntry = () => ({
2532
2937
  loader: runtimeClassSetLoader,
@@ -2543,15 +2948,31 @@ function setupWebpackV5Loaders(options) {
2543
2948
  type: null
2544
2949
  };
2545
2950
  };
2951
+ const createCssGenerationLoaderEntry = () => {
2952
+ if (!runtimeCssGenerationLoader || !cssGenerationLoaderOptions) return null;
2953
+ return {
2954
+ loader: runtimeCssGenerationLoader,
2955
+ options: cssGenerationLoaderOptions,
2956
+ ident: null,
2957
+ type: null
2958
+ };
2959
+ };
2546
2960
  const { NormalModule } = compiler.webpack;
2547
2961
  compiler.hooks.compilation.tap(require_context.pluginName, (compilation) => {
2548
- NormalModule.getCompilationHooks(compilation).loader.tap(require_context.pluginName, (_loaderContext, module) => {
2549
- if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
2962
+ NormalModule.getCompilationHooks(compilation).loader.tap({
2963
+ name: require_context.pluginName,
2964
+ stage: 100
2965
+ }, (_loaderContext, module) => {
2966
+ if (!(runtimeClassSetLoaderExists || runtimeCssGenerationLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
2550
2967
  patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && mpxCssImportRewrite);
2551
2968
  const loaderEntries = module.loaders || [];
2552
2969
  let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
2553
2970
  const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
2554
2971
  const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
2972
+ if (isCssModule) {
2973
+ const frameworkPostcssOptions = require_source_candidate_scan_signature.collectFrameworkPostcssOptionsFromLoaderEntries(loaderEntries, _loaderContext);
2974
+ if (frameworkPostcssOptions) require_source_candidate_scan_signature.captureResolvedFrameworkPostcssOptions(compilerOptions, frameworkPostcssOptions);
2975
+ }
2555
2976
  if (isCssModule && typeof module.resource === "string") markWebpackCssSourceModule?.(module.resource);
2556
2977
  if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
2557
2978
  rewriteAnchorIdx,
@@ -2566,6 +2987,12 @@ function setupWebpackV5Loaders(options) {
2566
2987
  if (position === "after") loaderEntries.push(entry);
2567
2988
  else loaderEntries.unshift(entry);
2568
2989
  };
2990
+ if (cssGenerationLoaderOptions && runtimeCssGenerationLoaderExists && runtimeCssGenerationLoader && isCssModule && !hasLoaderEntry(loaderEntries, runtimeCssGenerationLoader)) {
2991
+ const generationLoaderEntry = createCssGenerationLoaderEntry();
2992
+ const anchorIndex = findRewriteAnchor(loaderEntries);
2993
+ if (generationLoaderEntry) if (anchorIndex === -1) anchorlessInsert(generationLoaderEntry, "after");
2994
+ else loaderEntries.splice(anchorIndex + 1, 0, generationLoaderEntry);
2995
+ }
2569
2996
  if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader && isCssModule) {
2570
2997
  const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
2571
2998
  const rewriteLoaderEntry = existingIndex !== -1 ? {
@@ -2593,7 +3020,7 @@ function setupWebpackV5Loaders(options) {
2593
3020
  });
2594
3021
  }
2595
3022
  //#endregion
2596
- //#region src/bundlers/webpack/shared/create-framework-plugin.ts
3023
+ //#region src/bundlers/webpack/shared/create-framework-plugin/watch-output.ts
2597
3024
  const debug = require_wxml.createDebug();
2598
3025
  const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
2599
3026
  const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
@@ -2659,6 +3086,8 @@ function setupWebpackWatchOutputIgnore(compiler) {
2659
3086
  }
2660
3087
  });
2661
3088
  }
3089
+ //#endregion
3090
+ //#region src/bundlers/webpack/shared/create-framework-plugin/plugin.ts
2662
3091
  function isInternalUserDefinedOptions(options) {
2663
3092
  return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
2664
3093
  }
@@ -2804,6 +3233,15 @@ var WebpackFrameworkPlugin = class {
2804
3233
  });
2805
3234
  currentWebpackCssSourceFiles.add(file);
2806
3235
  };
3236
+ const updateWebpackGeneratedCss = (source) => {
3237
+ const file = node_path.default.resolve(source.file);
3238
+ const previous = webpackGeneratedCssSources.get(file);
3239
+ if (!previous) return;
3240
+ webpackGeneratedCssSources.set(file, {
3241
+ ...previous,
3242
+ css: source.css
3243
+ });
3244
+ };
2807
3245
  const pruneWebpackCssSources = (activeSourceFiles, _options = {}) => {
2808
3246
  const tailwindOptions = require_generator.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
2809
3247
  const configuredSourceFiles = /* @__PURE__ */ new Set();
@@ -2881,6 +3319,7 @@ var WebpackFrameworkPlugin = class {
2881
3319
  markWebpackCssSourceModule,
2882
3320
  registerWebpackCssSourceFile,
2883
3321
  registerWebpackGeneratedCss,
3322
+ updateWebpackGeneratedCss,
2884
3323
  getRuntimeWatchDependencies() {
2885
3324
  return {
2886
3325
  files: runtimeWatchDependencyFiles,