weapp-tailwindcss 5.1.15 → 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 (122) hide show
  1. package/dist/bundlers/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
  2. package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
  3. package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -2
  4. package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
  5. package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
  6. package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
  7. package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
  8. package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
  9. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
  10. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
  11. package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
  12. package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
  13. package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
  14. package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
  15. package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
  16. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
  17. package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
  18. package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
  20. package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
  21. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
  22. package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
  23. package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
  24. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
  25. package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
  26. package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
  27. package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
  28. package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
  29. package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
  30. package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
  31. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
  32. package/dist/bundlers/shared/generator-css.d.ts +1 -2
  33. package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
  34. package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
  35. package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
  36. package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
  37. package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
  38. package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
  39. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
  40. package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
  41. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  42. package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
  43. package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
  44. package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
  45. package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
  46. package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
  47. package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
  48. package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
  49. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  50. package/dist/bundlers/vite/serve-css-generation.d.ts +1 -0
  51. package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
  52. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +4 -4
  53. package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
  54. package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
  55. package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
  56. package/dist/bundlers/vite/source-candidates.d.ts +4 -68
  57. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
  58. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
  59. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
  60. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
  61. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
  62. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
  63. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
  64. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
  65. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
  66. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
  67. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
  68. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
  69. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
  70. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -219
  71. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
  72. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
  73. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
  74. package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
  75. package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
  76. package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
  77. package/dist/cli.js +14 -18
  78. package/dist/cli.mjs +14 -18
  79. package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
  80. package/dist/{context-BgGWVAmN.mjs → context-JzwzSX36.mjs} +3 -3
  81. package/dist/core.js +1 -1
  82. package/dist/core.mjs +1 -1
  83. package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
  84. package/dist/{generator-CEo920So.mjs → generator-Bv7myuhY.mjs} +556 -431
  85. package/dist/generator.js +1 -1
  86. package/dist/generator.mjs +1 -1
  87. package/dist/{gulp-DP71z1jG.mjs → gulp-CKSklPlH.mjs} +217 -186
  88. package/dist/{gulp-3m1dAiig.js → gulp-Q1wITegn.js} +217 -186
  89. package/dist/gulp.js +1 -1
  90. package/dist/gulp.mjs +1 -1
  91. package/dist/{hmr-timing-1aS6--U7.mjs → hmr-timing-BXg7nI8N.mjs} +3411 -3276
  92. package/dist/{hmr-timing-B8p4f0ca.js → hmr-timing-CMPaWn9P.js} +3425 -3278
  93. package/dist/index.js +4 -4
  94. package/dist/index.mjs +4 -4
  95. package/dist/postcss.js +1 -1
  96. package/dist/postcss.mjs +1 -1
  97. package/dist/presets.js +1 -1
  98. package/dist/presets.mjs +1 -1
  99. package/dist/rspack.js +1 -1
  100. package/dist/rspack.mjs +1 -1
  101. package/dist/shared/mpx-plugin-owner.d.ts +2 -0
  102. package/dist/{source-candidate-scan-signature-BAahhiwb.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -4
  103. package/dist/{source-candidate-scan-signature-Cf7259PR.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -4
  104. package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
  105. package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
  106. package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
  107. package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
  108. package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
  109. package/dist/{tailwindcss-xs704TRw.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
  110. package/dist/{vite-nXZEiwG0.mjs → vite-BwQWl9ft.mjs} +806 -692
  111. package/dist/{vite-DUVjMduj.js → vite-DhVnXvAQ.js} +805 -691
  112. package/dist/vite.js +1 -1
  113. package/dist/vite.mjs +1 -1
  114. package/dist/weapp-tw-css-generation-loader.js +1 -1
  115. package/dist/{weapp-tw-css-import-rewrite-loader-DNk0IxAt.js → weapp-tw-css-import-rewrite-loader-B0tVkJLH.js} +2410 -2084
  116. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  117. package/dist/weapp-tw-runtime-classset-loader.js +10 -4
  118. package/dist/{webpack-C_UUFRgj.mjs → webpack-Bo1QrFPf.mjs} +1387 -1114
  119. package/dist/{webpack-nppysF4B.js → webpack-kh78iMSS.js} +1386 -1113
  120. package/dist/webpack.js +1 -1
  121. package/dist/webpack.mjs +1 -1
  122. package/package.json +9 -7
@@ -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-B8p4f0ca.js");
9
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BAahhiwb.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");
@@ -159,13 +159,243 @@ function isWatchFileInRuntimeDependencies(file, dependencies) {
159
159
  return false;
160
160
  }
161
161
  //#endregion
162
- //#region src/bundlers/webpack/shared/css-loader-runtime.ts
163
- function isWebpackCssLoaderRuntimeSource(source) {
164
- 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;
165
187
  }
166
188
  //#endregion
167
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.ts
168
- 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
+ }
169
399
  function resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) {
170
400
  return styleOptions.cssPreflight ?? compilerOptions.cssPreflight ?? require_defaults.getDefaultCssPreflight();
171
401
  }
@@ -275,9 +505,6 @@ function removeTailwindV4StandaloneHostPreflightRule(source) {
275
505
  return source;
276
506
  }
277
507
  }
278
- function isRuntimeTransformCandidate(candidate) {
279
- return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
280
- }
281
508
  function collectRuntimeTokenSignatureParts(source) {
282
509
  return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
283
510
  }
@@ -321,27 +548,242 @@ function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandl
321
548
  const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
322
549
  for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
323
550
  for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
324
- pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
325
- pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
326
- }
327
- function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
328
- const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
329
- 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;
330
- return rawSource;
331
- }
332
- function shouldConsumeWebpackLoaderGeneratedCss(options) {
333
- if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
334
- if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
335
- if (options.hasBundlerGeneratedCssMarker) return true;
336
- if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
337
- return Boolean(options.allowMarkerlessRegistryMatch && options.loaderGeneratedClassSet && options.sourceCandidates && !hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) && !hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates));
338
- }
339
- function hasDeferredWebpackGeneratedCss(source, generatedClassSets) {
340
- const selectors = require_hmr_timing.collectRawSourceClassSelectors(source);
341
- for (const classSet of generatedClassSets) for (const candidate of classSet) if (selectors.has(candidate)) return true;
342
- return false;
551
+ pruneMapToMaxSize(cssHandlerOptionsCache, 128);
552
+ pruneMapToMaxSize(cssUserHandlerOptionsCache, 128);
343
553
  }
344
- function hasUsableWebpackGeneratorCssSources(cssSources) {
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) {
345
787
  return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
346
788
  }
347
789
  function normalizeWebpackGeneratorCssSources(cssSources) {
@@ -395,26 +837,6 @@ function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource,
395
837
  const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
396
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));
397
839
  }
398
- function collectWebpackAssetUserCssMarkers(source) {
399
- const markers = /* @__PURE__ */ new Set();
400
- for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
401
- for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
402
- try {
403
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
404
- root.walkRules((rule) => {
405
- for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
406
- rule.walkDecls((decl) => {
407
- if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
408
- });
409
- });
410
- root.walkAtRules("font-face", (rule) => {
411
- rule.walkDecls("font-family", (decl) => {
412
- markers.add(`font-face:${decl.value.trim()}`);
413
- });
414
- });
415
- } catch {}
416
- return markers;
417
- }
418
840
  function hasWebpackClassSelector(selector) {
419
841
  return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
420
842
  }
@@ -454,215 +876,8 @@ function collectWebpackBareSelectorUserCss(source) {
454
876
  return "";
455
877
  }
456
878
  }
457
- const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = /* @__PURE__ */ new Set([
458
- "theme",
459
- "base",
460
- "utilities"
461
- ]);
462
- const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
463
- 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)(?:[\-\\{]|$)|\\\[)/;
464
- const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
465
- const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
466
- "*",
467
- ":after",
468
- ":before",
469
- "::after",
470
- "::before",
471
- "::backdrop",
472
- "view",
473
- "text"
474
- ]);
475
- const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
476
- "box-sizing",
477
- "border",
478
- "border-width",
479
- "border-style",
480
- "border-color",
481
- "margin",
482
- "padding"
483
- ]);
484
- 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-)/;
485
- function parseWebpackCssLayerNames(params) {
486
- return params.split(",").map((name) => name.trim()).filter(Boolean);
487
- }
488
- function removeWebpackTailwindGeneratedAssetCss(source) {
489
- const cleaned = require_generator.removeTailwindV4GeneratedUserCssArtifacts(source);
490
- try {
491
- const root = _weapp_tailwindcss_postcss.postcss.parse(cleaned);
492
- let changed = false;
493
- let removingBannerPrefix = false;
494
- for (const node of [...root.nodes]) {
495
- if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
496
- node.remove();
497
- changed = true;
498
- removingBannerPrefix = true;
499
- continue;
500
- }
501
- if (!removingBannerPrefix) continue;
502
- if (isWebpackTailwindGeneratedPrefixNode(node)) {
503
- node.remove();
504
- changed = true;
505
- continue;
506
- }
507
- removingBannerPrefix = false;
508
- }
509
- root.walkAtRules("layer", (rule) => {
510
- const names = parseWebpackCssLayerNames(rule.params);
511
- const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
512
- const isLayerDeclaration = rule.nodes === void 0;
513
- const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
514
- if (shouldRemoveLayer && isLayerDeclaration) {
515
- rule.remove();
516
- changed = true;
517
- return;
518
- }
519
- if (shouldRemoveLayer && !names.includes("utilities")) {
520
- for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
521
- child.remove();
522
- changed = true;
523
- }
524
- if (rule.nodes?.length === 0) {
525
- rule.remove();
526
- changed = true;
527
- }
528
- return;
529
- }
530
- if (shouldRemoveLayer) {
531
- for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
532
- child.remove();
533
- changed = true;
534
- }
535
- if (rule.nodes?.length === 0) {
536
- rule.remove();
537
- changed = true;
538
- }
539
- }
540
- });
541
- root.walkRules((rule) => {
542
- if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
543
- const selector = rule.selector.trim();
544
- if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
545
- rule.remove();
546
- changed = true;
547
- }
548
- });
549
- root.walkComments((comment) => {
550
- if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
551
- comment.remove();
552
- changed = true;
553
- }
554
- });
555
- root.walkAtRules((rule) => {
556
- if (rule.nodes !== void 0 && rule.nodes.length === 0) {
557
- rule.remove();
558
- changed = true;
559
- }
560
- });
561
- return changed ? root.toString() : cleaned;
562
- } catch {
563
- return cleaned;
564
- }
565
- }
566
- function isWebpackTailwindGeneratedPrefixNode(node) {
567
- if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
568
- "theme",
569
- "base",
570
- "utilities"
571
- ], true);
572
- if (node.type !== "atrule") return false;
573
- const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
574
- if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
575
- if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
576
- if (node.nodes === void 0) return true;
577
- return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
578
- }
579
- if (node.nodes === void 0 || node.nodes.length === 0) return false;
580
- return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
581
- }
582
- function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
583
- if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
584
- if (node.type !== "atrule") return false;
585
- if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
586
- if (node.nodes === void 0 || node.nodes.length === 0) return false;
587
- return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
588
- }
589
- function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
590
- const selectors = rule.selectors ?? [rule.selector];
591
- if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
592
- if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
593
- if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
594
- if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
595
- return false;
596
- }
597
- function isWebpackTailwindGeneratedThemeRule(rule) {
598
- const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
599
- return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
600
- }
601
- function isWebpackTailwindGeneratedPreflightRule(rule) {
602
- const selectors = rule.selectors ?? [rule.selector];
603
- const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
604
- return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
605
- const normalized = selector.trim().replace(/\s+/g, " ");
606
- return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
607
- }) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
608
- }
609
- function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
610
- try {
611
- const nodes = _weapp_tailwindcss_postcss.postcss.parse(source).nodes ?? [];
612
- return nodes.length > 0 && nodes.every((node) => {
613
- if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
614
- return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
615
- });
616
- } catch {
617
- return false;
618
- }
619
- }
620
- function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
621
- return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
622
- }
623
- function collectWebpackCssRuleIdentityMarkers(source) {
624
- const markers = /* @__PURE__ */ new Set();
625
- try {
626
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
627
- root.walkRules((rule) => {
628
- 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]}`);
629
- });
630
- root.walkAtRules("keyframes", (rule) => {
631
- if (rule.params) markers.add(`keyframes:${rule.params}`);
632
- });
633
- } catch {}
634
- return markers;
635
- }
636
- function unescapeCssIdentifier(value) {
637
- return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
638
- const hex = escaped.trim();
639
- if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
640
- return escaped;
641
- });
642
- }
643
- function collectGeneratedCssRuntimeCandidates(source) {
644
- const candidates = /* @__PURE__ */ new Set();
645
- if (require_hmr_timing.hasBundlerGeneratedCssMarker(source) || !require_generator.hasTailwindGeneratedCss(source) && !require_generator.hasTailwindGeneratedCssMarkers(source)) return candidates;
646
- try {
647
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
648
- for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
649
- const candidate = unescapeCssIdentifier(match[1]);
650
- if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
651
- }
652
- });
653
- } catch {}
654
- return candidates;
655
- }
656
- function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
657
- const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
658
- if (rawMarkers.size === 0) return false;
659
- const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
660
- for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
661
- return false;
662
- }
663
- function hasWebpackTailwindSourceDirectives(source) {
664
- 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));
665
- }
879
+ //#endregion
880
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.ts
666
881
  function isWebpackTailwindImportRequest(request) {
667
882
  return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
668
883
  }
@@ -689,264 +904,57 @@ function isWebpackCssSourceRepresentedInAsset(rawSource, sourceCss) {
689
904
  for (const marker of sourceMarkers) if (!rawMarkers.has(marker)) return false;
690
905
  return true;
691
906
  }
692
- function createWebpackGeneratorCssSource(file, css) {
693
- if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
694
- return {
695
- file,
696
- base: node_path.default.dirname(file),
697
- css,
698
- dependencies: [file]
699
- };
700
- }
701
- function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
702
- const matchedSources = [];
703
- const seen = /* @__PURE__ */ new Set();
704
- for (const source of sources) {
705
- const css = source.css;
706
- if (!css || seen.has(css)) continue;
707
- if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
708
- seen.add(css);
709
- if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
710
- css,
711
- file: source.file,
712
- processed: source.processed === true
713
- });
714
- }
715
- const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
716
- const parts = matchedSources.sort((a, b) => {
717
- const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
718
- if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
719
- return a.file.localeCompare(b.file);
720
- }).map((source) => source.css);
721
- return parts.length > 0 ? {
722
- css: parts.join("\n"),
723
- processed: matchedSources.every((source) => source.processed)
724
- } : void 0;
725
- }
726
- function createWebpackGeneratorUserCssSourceAppend(...sources) {
727
- const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
728
- if (parts.length === 0) return;
729
- let css = "";
730
- const usedParts = [];
731
- for (const source of parts) {
732
- const merged = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.mergeCoveredCssRuleDeclarations)(css, source.css) : void 0;
733
- if (merged?.changed) css = merged.baseCss;
734
- const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, merged?.css ?? source.css) : source.css;
735
- if (!(nextCss.trim().length > 0)) continue;
736
- css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
737
- usedParts.push(source);
738
- }
739
- return {
740
- css,
741
- processed: usedParts.every((source) => source.processed)
742
- };
743
- }
744
- function resolveWebpackMemoryDebugStats(context) {
745
- if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
746
- const memory = node_process.default.memoryUsage();
747
- const processCacheInstanceSize = context.cache.instance.size;
748
- const processCacheHashMapSize = context.cache.hashMap.size;
749
- return {
750
- phase: context.phase,
751
- process: {
752
- rssMb: toMb(memory.rss),
753
- heapTotalMb: toMb(memory.heapTotal),
754
- heapUsedMb: toMb(memory.heapUsed),
755
- externalMb: toMb(memory.external),
756
- arrayBuffersMb: toMb(memory.arrayBuffers)
757
- },
758
- assets: {
759
- active: context.activeAssetFiles,
760
- activeCss: context.activeCssFiles
761
- },
762
- processCache: {
763
- instance: processCacheInstanceSize,
764
- hashMap: processCacheHashMapSize,
765
- activeCacheKeys: context.activeProcessCacheKeys.size,
766
- activeHashKeys: context.activeProcessHashKeys.size,
767
- staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
768
- staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
769
- pruned: true,
770
- pruneSkipped: false
771
- },
772
- webpackCss: {
773
- handlerOptions: context.cssHandlerOptionsCache.size,
774
- userHandlerOptions: context.cssUserHandlerOptionsCache.size,
775
- maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
776
- },
777
- sourceCandidateScan: context.sourceCandidateScan,
778
- tailwind: { v4: require_generator.getTailwindV4IncrementalGenerateCacheStats() }
779
- };
780
- }
781
- function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
782
- if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
783
- return cssHandlerOptions.isMainChunk !== false;
784
- }
785
- function includesTailwindPreflightImport(source) {
786
- if (!source) return false;
787
- try {
788
- let includesPreflight = false;
789
- _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules((rule) => {
790
- if (rule.name === "tailwind") {
791
- includesPreflight || (includesPreflight = rule.params.trim() === "base");
792
- return;
793
- }
794
- if (rule.name !== "import") return;
795
- const request = require_generator.parseImportRequest(rule.params)?.replaceAll("\\", "/");
796
- includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
797
- });
798
- return includesPreflight;
799
- } catch {
800
- return false;
801
- }
802
- }
803
- function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
804
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
805
- if (isWebGeneratorTarget) return source;
806
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_generator.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
807
- cssPreflight: options.cssPreflight === false ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
808
- isTailwindcssV4: true,
809
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
810
- })));
811
- }
812
- function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
813
- 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;
814
- }
815
- function isWindowsAbsoluteResourcePath(file) {
816
- return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
817
- }
818
- function isPosixAbsoluteResourcePath(file) {
819
- return file.startsWith("/");
820
- }
821
- function resolveWebpackResourcePath(file, base) {
822
- if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.resolve(file);
823
- if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.resolve(file);
824
- if (base) {
825
- if (isWindowsAbsoluteResourcePath(base)) return node_path.default.win32.resolve(base, file);
826
- if (isPosixAbsoluteResourcePath(base)) return node_path.default.posix.resolve(base, file);
827
- return node_path.default.resolve(base, file);
828
- }
829
- }
830
- function dirnameWebpackResourcePath(file) {
831
- if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.dirname(file);
832
- if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.dirname(file);
833
- return node_path.default.dirname(file);
834
- }
835
- function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
836
- if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
837
- const normalized = stripResourceQuery(resource);
838
- if (!normalized) return;
839
- const absoluteResource = resolveWebpackResourcePath(normalized);
840
- if (absoluteResource) return absoluteResource;
841
- const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
842
- const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
843
- return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
844
- }
845
- function isSameWebpackCssSourceScope(options) {
846
- if (!options.currentSourceFile) return false;
847
- const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? node_path.default.resolve(options.candidateSourceFile);
848
- if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? node_path.default.resolve(options.currentSourceFile))) return true;
849
- const outputResources = options.resourcesByAsset.get(options.outputFile);
850
- if (!outputResources) return false;
851
- return [...outputResources].some((resource) => {
852
- return (resolveWebpackResourcePath(resource) ?? node_path.default.resolve(resource)) === candidateKey;
853
- });
854
- }
855
- function shouldAppendCurrentWebpackAssetUserCss(options) {
856
- const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
857
- return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
858
- }
859
- function createWebpackCurrentAssetUserRawSource(options) {
860
- if (!options.shouldAppendCurrentAssetUserCss) return;
861
- if (options.sourceCssProcessed) return {
862
- css: options.currentAssetUserCssSource,
863
- processed: true
864
- };
865
- if (!options.currentAssetHasUserCss) return;
866
- return {
867
- css: options.currentAssetUserCssSource,
868
- processed: options.currentAssetLooksGenerated
869
- };
870
- }
871
- function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
872
- if (options.finalized === true) return options.annotateCss(css);
873
- if (options.isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
874
- const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
875
- return options.annotateCss(finalized);
876
- }
877
- function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
878
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
879
- if (isWebGeneratorTarget) {
880
- if (options.generatedCss === true) return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_hmr_timing.stripBundlerGeneratedCssMarkers(source))));
881
- return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
882
- }
883
- let finalized = require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
884
- if (options.generatedCss !== true) {
885
- finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
886
- cssPreflight: false,
887
- isTailwindcssV4: true,
888
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
889
- });
890
- finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
891
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
892
- }
893
- try {
894
- finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: options.cssPreflight !== false });
895
- } catch {}
896
- const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
897
- if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
898
- const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
899
- finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
900
- cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
901
- isTailwindcssV4: true,
902
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
903
- });
904
- finalized = ensureWebpackMiniProgramTwContentInit(finalized);
905
- if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
906
- else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
907
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
908
- }
909
- function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
910
- if (isWebGeneratorTarget) return source;
911
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
912
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors((0, _weapp_tailwindcss_postcss.dedupeCoveredCssRules)(dedupeMiniProgramPreflightSelectorRules(source)), styleOptions.cssRemoveHoverPseudoClass));
913
- }
914
- function collectWebpackJsRuntimeCandidatesFromAssets(options) {
915
- if (options.isWebGeneratorTarget) return;
916
- const candidates = /* @__PURE__ */ new Set();
917
- for (const file of options.jsAssets) {
918
- const sourceLike = options.getAssetSource(file);
919
- if (sourceLike === void 0) continue;
920
- const source = stringifyWebpackSourceLike(sourceLike);
921
- for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
922
- }
923
- return candidates;
924
- }
925
- function collectWebpackJsRuntimeTokenSignature(options) {
926
- if (options.isWebGeneratorTarget) return "";
927
- const tokens = [];
928
- for (const file of options.jsAssets) {
929
- const sourceLike = options.getAssetSource(file);
930
- if (sourceLike === void 0) continue;
931
- tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
932
- }
933
- return tokens.sort().join("\n");
934
- }
935
- function addRuntimeTransformCandidates(target, candidates) {
936
- if (!candidates?.size) return;
937
- for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
938
- }
939
- function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
940
- if (!require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
941
- return require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
907
+ function createWebpackGeneratorCssSource(file, css) {
908
+ if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
909
+ return {
910
+ file,
911
+ base: node_path.default.dirname(file),
912
+ css,
913
+ dependencies: [file]
914
+ };
942
915
  }
943
- function stringifyOptionalWebpackSourceValue(value) {
944
- return typeof value === "string" ? value : value?.toString() ?? "";
916
+ function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
917
+ const matchedSources = [];
918
+ const seen = /* @__PURE__ */ new Set();
919
+ for (const source of sources) {
920
+ const css = source.css;
921
+ if (!css || seen.has(css)) continue;
922
+ if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
923
+ seen.add(css);
924
+ if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
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;
945
940
  }
946
- function stringifyWebpackSourceLike(source) {
947
- if (typeof source === "string") return source;
948
- const value = source.source();
949
- 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
+ };
950
958
  }
951
959
  //#endregion
952
960
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.ts
@@ -1202,6 +1210,343 @@ function createWebpackCssSourceResolvers(options) {
1202
1210
  };
1203
1211
  }
1204
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
1205
1550
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
1206
1551
  function createChangedByType() {
1207
1552
  return {
@@ -1317,6 +1662,112 @@ function createWebpackAssetUpdater(options) {
1317
1662
  };
1318
1663
  }
1319
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
1320
1771
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.ts
1321
1772
  function createWebpackJsAssetModuleGraph(options) {
1322
1773
  const jsAssets = /* @__PURE__ */ new Map();
@@ -1361,6 +1812,144 @@ function applyWebpackLinkedJsResults(options) {
1361
1812
  }
1362
1813
  }
1363
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
1364
1953
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.ts
1365
1954
  const WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX = 2;
1366
1955
  function trimScanCache(cache) {
@@ -1593,6 +2182,11 @@ function setupWebpackV5ProcessAssetsHook(options) {
1593
2182
  debug("start");
1594
2183
  await runtimeState.readyPromise;
1595
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();
1596
2190
  for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
1597
2191
  const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
1598
2192
  const { updateAssetIfChanged } = createWebpackAssetUpdater({
@@ -1649,7 +2243,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
1649
2243
  runtimeState
1650
2244
  });
1651
2245
  const finalizeCssAssetSource = (source, options = {}) => finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options);
1652
- 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({
1653
2250
  compilerOptions,
1654
2251
  debug,
1655
2252
  outputDir,
@@ -1659,6 +2256,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1659
2256
  watchMode
1660
2257
  }) : void 0;
1661
2258
  const webpackSourceCandidateValueSignature = webpackSourceCandidates ? require_source_candidate_scan_signature.createCandidateSignature(webpackSourceCandidates.getSourceCandidatesForEntries(void 0)) : "source-candidates:0";
2259
+ recordTimingDetail("sourceCandidates", sourceCandidatesStartedAt);
1662
2260
  const cssSourceTraceTokenSources = createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates);
1663
2261
  const cssSourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
1664
2262
  const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
@@ -1672,6 +2270,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1672
2270
  isWebGeneratorTarget
1673
2271
  });
1674
2272
  const hasRuntimeTransformAssets = Boolean(!isWebGeneratorTarget && ((groupedEntries.html?.length ?? 0) > 0 || (groupedEntries.js?.length ?? 0) > 0));
2273
+ const runtimeStartedAt = performance.now();
1675
2274
  const forceRuntimeRefresh = getRuntimeRefreshRequirement();
1676
2275
  debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.tailwindRuntime.majorVersion ?? "unknown");
1677
2276
  let runtimeSet;
@@ -1709,6 +2308,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1709
2308
  }
1710
2309
  await refreshRuntimeMetadata(forceRuntimeRefresh);
1711
2310
  consumeRuntimeRefreshRequirement();
2311
+ recordTimingDetail("runtime", runtimeStartedAt);
1712
2312
  const webpackSourceCandidateSet = webpackSourceCandidates?.getSourceCandidatesForEntries(void 0);
1713
2313
  const generatorRuntimeSet = new Set(runtimeSet);
1714
2314
  addRuntimeTransformCandidates(generatorRuntimeSet, webpackSourceCandidateSet);
@@ -1763,532 +2363,107 @@ function setupWebpackV5ProcessAssetsHook(options) {
1763
2363
  const defaultTemplateHandlerOptions = { runtimeSet: transformRuntimeSet };
1764
2364
  debug("get runtimeSet, class count: %d, transform class count: %d", runtimeSet.size, transformRuntimeSet.size);
1765
2365
  const tasks = [];
1766
- const htmlTaskFactories = [];
1767
2366
  const cssTaskFactories = [];
1768
- 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
+ };
1769
2376
  if (watchMode) {
1770
- await factory();
2377
+ await timedFactory();
1771
2378
  return;
1772
2379
  }
1773
- target.push(factory);
2380
+ target.push(timedFactory);
1774
2381
  };
1775
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
1776
- const [file, originalSource] = element;
1777
- let rawSource;
1778
- const readRawSource = () => {
1779
- rawSource ?? (rawSource = originalSource.source().toString());
1780
- return rawSource;
1781
- };
1782
- const cacheKey = file;
1783
- const hashKey = `${file}:asset`;
1784
- rememberProcessCacheKey(cacheKey, hashKey);
1785
- const chunkHash = assetHashByChunk.get(file);
1786
- await enqueueTask(async () => {
1787
- await require_hmr_timing.processCachedTask({
1788
- cache: compilerOptions.cache,
1789
- cacheKey,
1790
- hashKey,
1791
- rawSource: chunkHash === void 0 ? readRawSource() : void 0,
1792
- hash: chunkHash,
1793
- applyResult(source, { cacheHit }) {
1794
- updateAssetIfChanged(file, source, {
1795
- compare: !cacheHit,
1796
- notifyUpdate: !cacheHit
1797
- });
1798
- },
1799
- onCacheHit() {
1800
- debug("html cache hit: %s", file);
1801
- },
1802
- transform: async () => {
1803
- const wxml = await compilerOptions.templateHandler(readRawSource(), defaultTemplateHandlerOptions);
1804
- const source = new ConcatSource(wxml);
1805
- debug("html handle: %s", file);
1806
- return { result: source };
1807
- }
1808
- });
1809
- }, htmlTaskFactories);
1810
- }
1811
- const jsTaskFactories = [];
1812
- const enqueueJsTask = async (factory) => {
1813
- 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
1814
2438
  };
1815
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
1816
- const cacheKey = getCacheKey(file);
1817
- const asset = compilation.getAsset(file);
1818
- if (!asset) continue;
1819
- const hashKey = `${file}:asset`;
1820
- rememberProcessCacheKey(cacheKey, hashKey);
1821
- const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
1822
- const initialSource = asset.source.source();
1823
- const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
1824
- const chunkHash = assetHashByChunk.get(file);
1825
- await enqueueJsTask(async () => {
1826
- await require_hmr_timing.processCachedTask({
1827
- cache: compilerOptions.cache,
1828
- cacheKey,
1829
- hashKey,
1830
- rawSource: chunkHash === void 0 ? initialRawSource : void 0,
1831
- hash: chunkHash,
1832
- applyResult(source, { cacheHit }) {
1833
- if (updateAssetIfChanged(file, source, {
1834
- compare: !cacheHit,
1835
- notifyUpdate: !cacheHit
1836
- })) rememberTransformedRuntimeCandidates(source);
1837
- },
1838
- onCacheHit() {
1839
- debug("js cache hit: %s", file);
1840
- },
1841
- transform: async () => {
1842
- const currentSourceValue = compilation.getAsset(file)?.source.source();
1843
- const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
1844
- const handlerOptions = {
1845
- tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
1846
- generateMap: false,
1847
- filename: absoluteFile,
1848
- moduleGraph: moduleGraphOptions,
1849
- babelParserOptions: { sourceFilename: absoluteFile }
1850
- };
1851
- if (require_context.shouldSkipJsTransform(currentSource, {
1852
- ...handlerOptions,
1853
- classNameSet: transformRuntimeSet
1854
- })) return { result: new ConcatSource(currentSource) };
1855
- const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
1856
- const source = new ConcatSource(code);
1857
- debug("js handle: %s", file);
1858
- applyWebpackLinkedJsResults({
1859
- ConcatSource,
1860
- compilation,
1861
- compilerOptions,
1862
- debug,
1863
- jsAssets,
1864
- linked
1865
- });
1866
- return { result: source };
1867
- }
1868
- });
1869
- });
1870
- }
1871
2439
  for (const element of groupedEntries.css) {
1872
- const [file, originalSource] = element;
1873
- let rawSource;
1874
- const readRawSource = () => {
1875
- rawSource ?? (rawSource = originalSource.source().toString());
1876
- return rawSource;
1877
- };
1878
- const chunkHash = assetHashByChunk.get(file);
1879
- const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file, readRawSource());
1880
- const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
1881
- const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
1882
- const processedSourceCss = processedSourceFile ? cssSources.get(node_path.default.resolve(processedSourceFile))?.css : void 0;
1883
- const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
1884
- const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
1885
- const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(node_path.default.resolve(processedSourceFile)) : void 0;
1886
- 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";
1887
- const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
1888
- let currentProcessedRawSource;
1889
- let hasGeneratedCssMarker = false;
1890
- let hasTailwindGeneratedAssetCss = false;
1891
- const readCurrentProcessedRawSource = () => {
1892
- currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
1893
- return currentProcessedRawSource;
1894
- };
1895
- const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
1896
- const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
1897
- if (cachedSkipProcessedCssAsset !== void 0) {
1898
- hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
1899
- hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
1900
- } else {
1901
- const source = readCurrentProcessedRawSource();
1902
- hasGeneratedCssMarker = require_hmr_timing.hasBundlerGeneratedCssMarker(source);
1903
- hasTailwindGeneratedAssetCss = require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source);
1904
- }
1905
- const hasProcessedAssetTailwindDirectives = () => {
1906
- const source = readCurrentProcessedRawSource();
1907
- return require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source);
1908
- };
1909
- const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
1910
- const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
1911
- ...source,
1912
- file: sourceFile
1913
- })), readCurrentProcessedRawSource()) !== void 0;
1914
- const hasProcessedLoaderGeneratedUserCss = cachedSkipProcessedCssAsset === void 0 && processedLoaderGeneratedCss !== void 0 && hasAdditionalWebpackAssetUserCssMarkers(processedLoaderGeneratedCss.css, readCurrentProcessedRawSource());
1915
- const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && require_generator.hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
1916
- const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1917
- const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && !hasProcessedLoaderGeneratedUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1918
- const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
1919
- if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
1920
- if (shouldSkipProcessedCssAsset) {
1921
- const hashKey = `${file}:asset`;
1922
- const sourceHash = processedAssetSourceHash;
1923
- rememberProcessCacheKey(file, hashKey);
1924
- await enqueueTask(async () => {
1925
- await require_hmr_timing.processCachedTask({
1926
- cache: compilerOptions.cache,
1927
- cacheKey: file,
1928
- hashKey,
1929
- rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
1930
- hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
1931
- applyResult(source, { cacheHit }) {
1932
- updateAssetIfChanged(file, source, {
1933
- compare: !cacheHit,
1934
- notifyUpdate: !cacheHit
1935
- });
1936
- },
1937
- onCacheHit() {
1938
- debug("css webpack-loader-pipeline cache hit: %s", file);
1939
- },
1940
- transform: async () => {
1941
- const source = readCurrentProcessedRawSource();
1942
- const missingProcessedLoaderGeneratedCss = isWebGeneratorTarget && processedLoaderGeneratedCss ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(source, require_hmr_timing.stripBundlerGeneratedCssMarkers(processedLoaderGeneratedCss.css)) : "";
1943
- const sourceWithLoaderGeneratedCss = missingProcessedLoaderGeneratedCss.trim().length === 0 ? source : createWebpackGeneratorUserCssSourceAppend({
1944
- css: source,
1945
- processed: true
1946
- }, {
1947
- css: missingProcessedLoaderGeneratedCss,
1948
- processed: true
1949
- }).css;
1950
- const processedBareSelectorSourceCss = processedSourceCss ?? (hasTailwindGeneratedAssetCss ? removeWebpackTailwindGeneratedAssetCss(sourceWithLoaderGeneratedCss) : void 0);
1951
- const handledCss = hasTailwindGeneratedAssetCss && (!hasGeneratedCssMarker || !isWebGeneratorTarget && hasDeferredWebpackGeneratedCss(source, [...generatedCssSources.values()].map((item) => item.classSet))) ? isWebGeneratorTarget ? sourceWithLoaderGeneratedCss : (await compilerOptions.styleHandler(sourceWithLoaderGeneratedCss, cssHandlerOptionsForProcessedAsset)).css : sourceWithLoaderGeneratedCss;
1952
- const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(handledCss, {
1953
- cssPreflight: cssHandlerOptionsForProcessedAsset.isMainChunk,
1954
- generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss
1955
- }));
1956
- const processedSourceBareUserCss = isWebGeneratorTarget || processedBareSelectorSourceCss === void 0 ? void 0 : createWebpackGeneratorUserCssSourceAppend({
1957
- css: collectWebpackBareSelectorUserCss(processedBareSelectorSourceCss),
1958
- processed: false
1959
- });
1960
- const finalizedProcessedSourceBareUserCss = processedSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(processedSourceBareUserCss.css, {
1961
- cssPreflight: false,
1962
- generatedCss: false
1963
- });
1964
- const missingProcessedSourceBareUserCss = finalizedProcessedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(nextCss, finalizedProcessedSourceBareUserCss);
1965
- const css = missingProcessedSourceBareUserCss.trim().length === 0 ? nextCss : createWebpackGeneratorUserCssSourceAppend({
1966
- css: nextCss,
1967
- processed: true
1968
- }, {
1969
- css: missingProcessedSourceBareUserCss,
1970
- processed: true
1971
- }).css;
1972
- debug("css skip webpack-loader-pipeline asset: %s", file);
1973
- return { result: new ConcatSource(finalizeTracedCss(css, cssHandlerOptionsForProcessedAsset, { finalized: true })) };
1974
- }
1975
- });
1976
- }, cssTaskFactories);
1977
- continue;
1978
- }
1979
- const currentRawSource = readRawSource();
1980
- if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
1981
- const hashKey = `${file}:asset`;
1982
- rememberProcessCacheKey(file, hashKey);
1983
- await enqueueTask(async () => {
1984
- await require_hmr_timing.processCachedTask({
1985
- cache: compilerOptions.cache,
1986
- cacheKey: file,
1987
- hashKey,
1988
- rawSource: currentRawSource,
1989
- hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
1990
- applyResult(source, { cacheHit }) {
1991
- updateAssetIfChanged(file, source, {
1992
- compare: !cacheHit,
1993
- notifyUpdate: !cacheHit
1994
- });
1995
- },
1996
- onCacheHit() {
1997
- debug("css-loader runtime cache hit: %s", file);
1998
- },
1999
- transform: async () => ({ result: new ConcatSource(currentRawSource) })
2000
- });
2001
- }, cssTaskFactories);
2002
- continue;
2003
- }
2004
- const cacheKey = file;
2005
- const hashKey = `${file}:asset`;
2006
- rememberProcessCacheKey(cacheKey, hashKey);
2007
- const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
2008
- const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
2009
- const cssSourceHash = (() => {
2010
- const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
2011
- const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
2012
- const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
2013
- if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
2014
- return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
2015
- })();
2016
- const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
2017
- await enqueueTask(async () => {
2018
- await require_hmr_timing.processCachedTask({
2019
- cache: compilerOptions.cache,
2020
- cacheKey,
2021
- hashKey,
2022
- rawSource: currentRawSource,
2023
- hash: runtimeAwareHash,
2024
- applyResult(source, { cacheHit }) {
2025
- updateAssetIfChanged(file, source, {
2026
- compare: !cacheHit,
2027
- notifyUpdate: !cacheHit
2028
- });
2029
- },
2030
- onCacheHit() {
2031
- debug("css cache hit: %s", file);
2032
- },
2033
- transform: async () => {
2034
- await runtimeState.readyPromise;
2035
- const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
2036
- const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
2037
- if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
2038
- const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
2039
- const sourceCss = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css : void 0;
2040
- const isConfiguredCssSource = sourceFile !== void 0 && configuredCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
2041
- const isConfiguredMainCssSource = sourceFile !== void 0 && configuredMainCssEntryFiles.some((entry) => node_path.default.resolve(entry) === node_path.default.resolve(sourceFile));
2042
- const sourceCssHasTailwindRoot = sourceCss !== void 0 && require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true });
2043
- const shouldPreserveExistingPreflight = cssHandlerOptions.isMainChunk || !isConfiguredMainCssSource && (isConfiguredCssSource || sourceCssHasTailwindRoot);
2044
- const loaderGeneratedCss = sourceFile ? generatedCssSources.get(node_path.default.resolve(sourceFile)) : void 0;
2045
- const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
2046
- 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;
2047
- if (loaderGeneratedCss && shouldConsumeWebpackLoaderGeneratedCss({
2048
- allowMarkerlessRegistryMatch: configuredCssEntryFiles.length === 1,
2049
- hasBundlerGeneratedCssMarker: require_hmr_timing.hasBundlerGeneratedCssMarker(currentRawSource),
2050
- loaderGeneratedClassSet: loaderGeneratedCss.classSet,
2051
- sourceCandidates: explicitTailwindV4SourceCandidates,
2052
- shouldRegenerateExplicitTailwindV4CssSource,
2053
- watchMode
2054
- })) {
2055
- for (const className of loaderGeneratedCss.classSet) {
2056
- generatorRuntimeSet.add(className);
2057
- transformRuntimeSet.add(className);
2058
- }
2059
- for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
2060
- const currentRawSourceWithoutBundlerMarkers = require_hmr_timing.stripBundlerGeneratedCssMarkers(currentRawSource);
2061
- const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
2062
- const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? require_hmr_timing.removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
2063
- const loaderGeneratedCssWithoutMarkers = require_hmr_timing.stripBundlerGeneratedCssMarkers(loaderGeneratedCss.css);
2064
- const currentAssetUserCssWithoutMarkers = currentAssetUserCss === void 0 ? "" : require_hmr_timing.stripBundlerGeneratedCssMarkers(currentAssetUserCss);
2065
- const currentAssetMissingUserCss = !(currentAssetUserCssWithoutMarkers.trim().length > 0 && !require_generator.isCommentOnlyCss(currentAssetUserCssWithoutMarkers)) ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCssWithoutMarkers, loaderGeneratedCssWithoutMarkers);
2066
- if (isConfiguredMainCssSource && !cssHandlerOptions.isMainChunk) {
2067
- debug("css skip duplicate webpack loader main generation: %s <- %s", file, sourceFile);
2068
- const userCss = currentAssetMissingUserCss.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetMissingUserCss) ? "" : finalizeCssAssetSource(currentAssetMissingUserCss, {
2069
- cssPreflight: false,
2070
- generatedCss: false
2071
- });
2072
- return { result: new ConcatSource(finalizeTracedCss(userCss, cssHandlerOptions)) };
2073
- }
2074
- const mergedLoaderCss = currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
2075
- css: currentAssetUserCss === void 0 ? loaderGeneratedCss.css : currentAssetHasProcessedUrl ? require_hmr_timing.removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCss, loaderGeneratedCss.css),
2076
- processed: true
2077
- }, currentAssetUserCss === void 0 ? void 0 : {
2078
- css: currentAssetUserCss,
2079
- processed: true
2080
- }).css;
2081
- const handledLoaderCss = isWebGeneratorTarget ? mergedLoaderCss : (await compilerOptions.styleHandler(mergedLoaderCss, cssHandlerOptions)).css;
2082
- const finalizedLoaderCss = finalizeCssAssetSource(handledLoaderCss, {
2083
- cssPreflight: cssHandlerOptions.isMainChunk,
2084
- generatedCss: true,
2085
- preserveExistingPreflight: shouldPreserveExistingPreflight
2086
- });
2087
- const loaderSourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[currentAssetUserCss === void 0 ? void 0 : {
2088
- css: currentAssetUserCss,
2089
- processed: true
2090
- }, sourceCss === void 0 ? void 0 : {
2091
- css: sourceCss,
2092
- processed: false
2093
- }].map((source) => {
2094
- if (source === void 0) return;
2095
- return {
2096
- css: collectWebpackBareSelectorUserCss(source.css),
2097
- processed: source.processed
2098
- };
2099
- }));
2100
- const handledLoaderSourceBareUserCss = loaderSourceBareUserCss === void 0 ? "" : loaderSourceBareUserCss.processed ? loaderSourceBareUserCss.css : (await compilerOptions.styleHandler(loaderSourceBareUserCss.css, cssHandlerOptions)).css;
2101
- const finalizedLoaderSourceBareUserCss = handledLoaderSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledLoaderSourceBareUserCss, {
2102
- cssPreflight: false,
2103
- generatedCss: false
2104
- });
2105
- const missingLoaderSourceBareUserCss = finalizedLoaderSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedLoaderCss, finalizedLoaderSourceBareUserCss);
2106
- const css = finalizeTracedCss(missingLoaderSourceBareUserCss.trim().length === 0 ? finalizedLoaderCss : createWebpackGeneratorUserCssSourceAppend({
2107
- css: finalizedLoaderCss,
2108
- processed: true
2109
- }, {
2110
- css: missingLoaderSourceBareUserCss,
2111
- processed: true
2112
- }).css, cssHandlerOptions, { finalized: true });
2113
- debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
2114
- return { result: new ConcatSource(css) };
2115
- }
2116
- const sourceCssProcessed = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.processed === true : false;
2117
- const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
2118
- ...source,
2119
- file: registeredSourceFile
2120
- })), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
2121
- const currentAssetLooksGenerated = require_generator.hasTailwindGeneratedCss(currentRawSource) || require_generator.hasTailwindGeneratedCssMarkers(currentRawSource);
2122
- const currentAssetHasBundlerGeneratedMarker = require_hmr_timing.hasBundlerGeneratedCssMarker(currentRawSource);
2123
- const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
2124
- if (sourceFile === void 0 && currentAssetHasBundlerGeneratedMarker && (currentAssetUserCssSource.trim().length === 0 || require_generator.isCommentOnlyCss(currentAssetUserCssSource))) return { result: new ConcatSource(finalizeTracedCss("", cssHandlerOptions)) };
2125
- const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
2126
- const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
2127
- const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss));
2128
- const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
2129
- const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
2130
- currentAssetHasUserCss,
2131
- currentAssetLooksGenerated,
2132
- currentAssetUserCssSource,
2133
- shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
2134
- currentAssetHasBundlerGeneratedMarker,
2135
- currentAssetHasUserCss,
2136
- currentAssetLooksGenerated,
2137
- registeredUserRawSource,
2138
- shouldPreserveGeneratedWebAssetUserCss,
2139
- sourceCssProcessed
2140
- }),
2141
- sourceCssProcessed
2142
- }), registeredUserRawSource);
2143
- if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(currentRawSource)) return { result: new ConcatSource(require_generator.removeTailwindSourceDirectives(require_hmr_timing.stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
2144
- const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
2145
- const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
2146
- const currentAssetHasTailwindDirectives = require_generator.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || require_generator.hasTailwindApplyDirective(generatorRawSource);
2147
- const shouldForceTailwindV4Generation = hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 && sourceFile !== void 0 || currentAssetHasTailwindDirectives || hasExplicitTailwindV4SourceCss);
2148
- const shouldSkipUnmatchedMainCssGeneration = !isWebGeneratorTarget && cssHandlerOptions.isMainChunk && sourceFile === void 0 && configuredMainCssEntryFiles.length > 0 && !currentAssetHasTailwindDirectives;
2149
- const shouldSkipPlainNonMainCssGeneration = !cssHandlerOptions.isMainChunk && sourceCss !== void 0 && !hasExplicitSourceCssForCurrentAsset && !hasExplicitTailwindV4SourceCss && !currentAssetHasTailwindDirectives;
2150
- const shouldMergeFallbackGeneratorRuntime = cssHandlerOptions.isMainChunk || currentAssetHasTailwindDirectives || hasExplicitSourceCssForCurrentAsset;
2151
- const scopedFallbackGeneratorRuntimeSet = hasExplicitTailwindV4SourceCss || !shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet;
2152
- const resolvedScopedGeneratorRuntimeSet = await require_source_candidate_scan_signature.createScopedGeneratorRuntime({
2153
- cssHandlerOptions,
2154
- fallbackRuntime: scopedFallbackGeneratorRuntimeSet,
2155
- getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
2156
- majorVersion: runtimeState.tailwindRuntime.majorVersion,
2157
- outputFile: file,
2158
- rawSource: sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
2159
- shouldExcludeSubpackageSourceCandidates: () => false,
2160
- sourceFile: sourceFile ?? file,
2161
- scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
2162
- });
2163
- const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== scopedFallbackGeneratorRuntimeSet && shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
2164
- const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
2165
- const scopedGeneratorCompilerOptions = scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, { disableUnmatchedCssEntries: !isWebGeneratorTarget && cssHandlerOptions.isMainChunk });
2166
- const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
2167
- ...cssHandlerOptions,
2168
- sourceOptions: {
2169
- ...cssHandlerOptions.sourceOptions,
2170
- cssSources: generatorCssSources
2171
- }
2172
- };
2173
- const generatorOptions = {
2174
- opts: scopedGeneratorCompilerOptions,
2175
- runtimeState,
2176
- runtime: scopedGeneratorRuntimeSet,
2177
- rawSource: generatorRawSource,
2178
- forceGenerator: shouldForceTailwindV4Generation,
2179
- ...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
2180
- ...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
2181
- ...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
2182
- file,
2183
- cssHandlerOptions: generatorCssHandlerOptions,
2184
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
2185
- getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
2186
- sourceCandidates: scopedGeneratorRuntimeSet,
2187
- restoreLocalCssImports: false,
2188
- styleHandler: compilerOptions.styleHandler,
2189
- debug
2190
- };
2191
- let generated;
2192
- if (!shouldSkipUnmatchedMainCssGeneration && !shouldSkipPlainNonMainCssGeneration) try {
2193
- generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
2194
- ...generatorOptions,
2195
- outputFile: file
2196
- });
2197
- } catch (error) {
2198
- if (!shouldFallbackToWebpackUserCssOnGeneratorError({
2199
- configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
2200
- generatorRawSource,
2201
- hasExplicitTailwindV4SourceCss
2202
- })) throw error;
2203
- debug("css generator skipped for plain webpack css asset: %s %O", file, error);
2204
- generated = void 0;
2205
- }
2206
- else debug("css generator skipped for plain webpack css asset: %s", file);
2207
- const finalizedGeneratedCss = generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
2208
- css: generated.css,
2209
- processed: true
2210
- }, {
2211
- css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
2212
- processed: true
2213
- })?.css ?? generated.css : generated.css, {
2214
- cssPreflight: cssHandlerOptions.isMainChunk,
2215
- generatedCss: true,
2216
- preserveExistingPreflight: shouldPreserveExistingPreflight
2217
- }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false });
2218
- const sourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[
2219
- userRawSource,
2220
- sourceCss === void 0 ? void 0 : {
2221
- css: sourceCss,
2222
- processed: sourceCssProcessed
2223
- },
2224
- {
2225
- css: generatorRawSource,
2226
- processed: false
2227
- }
2228
- ].map((source) => {
2229
- if (source === void 0) return;
2230
- return {
2231
- css: collectWebpackBareSelectorUserCss(source.css),
2232
- processed: source.processed
2233
- };
2234
- }));
2235
- const handledSourceBareUserCss = sourceBareUserCss === void 0 ? "" : sourceBareUserCss.processed ? sourceBareUserCss.css : (await compilerOptions.styleHandler(sourceBareUserCss.css, cssHandlerOptions)).css;
2236
- const finalizedSourceBareUserCss = handledSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledSourceBareUserCss, {
2237
- cssPreflight: false,
2238
- generatedCss: false
2239
- });
2240
- const missingSourceBareUserCss = finalizedSourceBareUserCss.trim().length === 0 ? "" : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(finalizedGeneratedCss, finalizedSourceBareUserCss);
2241
- const css = finalizeTracedCss(missingSourceBareUserCss.trim().length === 0 ? finalizedGeneratedCss : createWebpackGeneratorUserCssSourceAppend({
2242
- css: finalizedGeneratedCss,
2243
- processed: true
2244
- }, {
2245
- css: missingSourceBareUserCss,
2246
- processed: true
2247
- }).css, cssHandlerOptions, { finalized: true });
2248
- const source = new ConcatSource(css);
2249
- if (generated) {
2250
- for (const className of generated.classSet) generatorRuntimeSet.add(className);
2251
- debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
2252
- } else debug("css handle: %s", file);
2253
- return { result: source };
2254
- }
2255
- });
2256
- }, cssTaskFactories);
2257
- }
2258
- if (!watchMode) {
2259
- require_hmr_timing.pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
2260
- await Promise.all(tasks);
2261
- tasks.length = 0;
2262
- require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
2263
- await Promise.all(tasks);
2264
- tasks.length = 0;
2265
- require_hmr_timing.pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
2440
+ if (await processWebpackProcessedCssAsset(element, cssTaskContext)) continue;
2441
+ await processWebpackGeneratedCssAsset(element, cssTaskContext);
2266
2442
  }
2267
- await Promise.all(tasks);
2268
- compilerOptions.cache.prune?.({
2269
- cacheKeys: activeProcessCacheKeys,
2270
- hashKeys: activeProcessHashKeys
2271
- });
2272
- const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
2273
- pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
2274
- if (activeCssFiles.size > 0) pruneWebpackCssSources?.(/* @__PURE__ */ new Set([
2275
- ...registeredWebpackCssSourceFiles,
2276
- ...activeWebpackCssSourceFiles,
2277
- ...[...cssAssetResources.values()].flatMap((resources) => [...resources])
2278
- ]), { watchMode });
2279
- debug("end");
2280
- require_hmr_timing.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
2281
- activeAssetFiles: entries.length,
2282
- activeCssFiles: activeCssFiles.size,
2443
+ await finalizeWebpackProcessAssets({
2283
2444
  activeProcessCacheKeys,
2284
2445
  activeProcessHashKeys,
2285
- cache: compilerOptions.cache,
2446
+ activeWebpackCssSourceFiles,
2447
+ compilerOptions,
2448
+ cssAssetResources,
2286
2449
  cssHandlerOptionsCache,
2450
+ cssTaskFactories,
2287
2451
  cssUserHandlerOptionsCache,
2288
- phase: "processAssets",
2289
- sourceCandidateScan: webpackSourceCandidateScanCache.getMemoryStats()
2290
- }) });
2291
- 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
+ });
2292
2467
  });
2293
2468
  if (!isWebGeneratorTarget) compilation.hooks.processAssets.tapPromise({
2294
2469
  name: `${require_context.pluginName}:finalize-css-assets`,
@@ -2309,6 +2484,101 @@ function setupWebpackV5ProcessAssetsHook(options) {
2309
2484
  });
2310
2485
  }
2311
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
2312
2582
  //#region src/shared/tailwindcss-css-redirect.ts
2313
2583
  const moduleWithMutableResolve = node_module.default;
2314
2584
  const patched = /* @__PURE__ */ new WeakSet();
@@ -2327,33 +2597,8 @@ function installTailwindcssCssRedirect(pkgDir) {
2327
2597
  }
2328
2598
  //#endregion
2329
2599
  //#region src/shared/mpx.ts
2330
- const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
2331
2600
  const MPX_STYLE_RESOURCE_QUERY_RE = /(?:^|[?&])type=styles(?:&|$)/;
2332
- const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
2333
- const MPX_WEBPACK_PLUGIN_LIB_RE = /^(.*[\\/]@mpxjs[\\/]webpack-plugin)[\\/]lib[\\/]/;
2334
- const MPX_WEBPACK_PLUGIN_REQUEST_RE = /@mpxjs\/webpack-plugin\/([^!?]+)/g;
2335
- function findMpxWebpackPluginDirFromRules(rules) {
2336
- const visit = (value) => {
2337
- if (typeof value === "string") return value.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1];
2338
- if (Array.isArray(value)) {
2339
- for (const item of value) {
2340
- const result = visit(item);
2341
- if (result) return result;
2342
- }
2343
- return;
2344
- }
2345
- if (value && typeof value === "object") for (const key of [
2346
- "loader",
2347
- "use",
2348
- "rules",
2349
- "oneOf"
2350
- ]) {
2351
- const result = visit(value[key]);
2352
- if (result) return result;
2353
- }
2354
- };
2355
- return visit(rules);
2356
- }
2601
+ const MPX_WEBPACK_PLUGIN_REQUEST_PATH_RE = /(?:^|[\\/])@mpxjs[\\/]webpack-plugin(?:[\\/](.+))?$/;
2357
2602
  function isMpxStyleResourceQuery(query) {
2358
2603
  if (typeof query !== "string") return false;
2359
2604
  return MPX_STYLE_RESOURCE_QUERY_RE.test(query);
@@ -2361,34 +2606,16 @@ function isMpxStyleResourceQuery(query) {
2361
2606
  function getTailwindcssCssEntry(pkgDir) {
2362
2607
  return node_path.default.join(pkgDir, "index.css");
2363
2608
  }
2364
- function resolveMpxWebpackPluginDir(compiler) {
2365
- const rulePluginDir = findMpxWebpackPluginDirFromRules([
2366
- compiler?._module?.loaders,
2367
- compiler?.loaders,
2368
- compiler?.options?.module?.rules
2369
- ]);
2370
- if (rulePluginDir) return rulePluginDir;
2371
- const candidates = [
2372
- compiler?.context,
2373
- compiler?.options?.context,
2374
- node_process.default.cwd()
2375
- ].filter((item) => typeof item === "string" && item.length > 0);
2376
- for (const candidate of candidates) try {
2377
- const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
2378
- return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2379
- } catch {}
2380
- const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
2381
- if (cachedPackageJson) return node_path.default.dirname(cachedPackageJson);
2382
- try {
2383
- return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
2384
- } catch {
2385
- return;
2386
- }
2387
- }
2388
2609
  function rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir, pathImpl = node_path.default) {
2389
- return request.replace(MPX_WEBPACK_PLUGIN_REQUEST_RE, (_full, subpath) => {
2390
- return pathImpl.join(mpxWebpackPluginDir, ...subpath.split("/"));
2391
- });
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("!");
2392
2619
  }
2393
2620
  function patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir) {
2394
2621
  if (!mpxWebpackPluginDir || !compiler) return false;
@@ -2396,26 +2623,37 @@ function patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir) {
2396
2623
  const patchedCompilers = /* @__PURE__ */ new WeakSet();
2397
2624
  const patchedLoaderResolvers = /* @__PURE__ */ new WeakSet();
2398
2625
  const patchedResolverFactories = /* @__PURE__ */ new WeakSet();
2626
+ let activePluginDir = mpxWebpackPluginDir;
2627
+ const getActivePluginDir = () => activePluginDir;
2399
2628
  const install = (targetCompiler) => {
2400
2629
  if (!targetCompiler || typeof targetCompiler !== "object" || patchedCompilers.has(targetCompiler)) return;
2401
2630
  patchedCompilers.add(targetCompiler);
2402
- ensureResolveLoaderAlias(targetCompiler, mpxWebpackPluginDir);
2631
+ ensureResolveLoaderAlias(targetCompiler, activePluginDir);
2403
2632
  const resolverFactory = targetCompiler.resolverFactory;
2404
2633
  if (resolverFactory && typeof resolverFactory === "object" && !patchedResolverFactories.has(resolverFactory)) {
2405
2634
  patchedResolverFactories.add(resolverFactory);
2406
- installMpxResolveLoaderAlias(targetCompiler, mpxWebpackPluginDir);
2635
+ installMpxResolveLoaderAlias(targetCompiler, getActivePluginDir);
2407
2636
  }
2408
2637
  targetCompiler.hooks?.normalModuleFactory?.tap?.(pluginName, (normalModuleFactory) => {
2409
2638
  const loaderResolver = normalModuleFactory.getResolver?.("loader");
2410
2639
  if (loaderResolver && typeof loaderResolver === "object" && !patchedLoaderResolvers.has(loaderResolver)) {
2411
2640
  patchedLoaderResolvers.add(loaderResolver);
2412
- patchMpxLoaderResolver(loaderResolver, mpxWebpackPluginDir);
2641
+ patchMpxLoaderResolver(loaderResolver, getActivePluginDir);
2413
2642
  }
2414
2643
  normalModuleFactory.hooks.beforeResolve.tap(pluginName, (resolveData) => {
2415
- if (typeof resolveData?.request === "string") resolveData.request = rewriteMpxWebpackPluginRequests(resolveData.request, mpxWebpackPluginDir);
2644
+ const pluginDir = getActivePluginDir();
2645
+ if (pluginDir && typeof resolveData?.request === "string") resolveData.request = rewriteMpxWebpackPluginRequests(resolveData.request, pluginDir);
2416
2646
  });
2417
2647
  });
2418
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
+ }
2419
2657
  compilation.hooks?.childCompiler?.tap?.(pluginName, (childCompiler) => {
2420
2658
  install(childCompiler);
2421
2659
  });
@@ -2435,20 +2673,33 @@ function addMpxWebpackPluginAlias(alias, pkgDir) {
2435
2673
  const recordLoader = node_path.default.join(pkgDir, "lib/record-loader");
2436
2674
  const styleCompiler = node_path.default.join(pkgDir, "lib/style-compiler/index");
2437
2675
  const stripConditionalLoader = node_path.default.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
2438
- if (Array.isArray(alias)) alias.push({
2439
- name: "@mpxjs/webpack-plugin/lib/record-loader",
2440
- alias: recordLoader
2441
- }, {
2442
- name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
2443
- alias: styleCompiler
2444
- }, {
2445
- name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
2446
- alias: stripConditionalLoader
2447
- }, {
2448
- name: /^@mpxjs\/webpack-plugin\//,
2449
- alias: pkgDir
2450
- });
2451
- 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 {
2452
2703
  alias["@mpxjs/webpack-plugin"] = pkgDir;
2453
2704
  alias["@mpxjs/webpack-plugin$"] = pkgDir;
2454
2705
  alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
@@ -2462,13 +2713,15 @@ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
2462
2713
  compiler.options.resolveLoader.alias = alias;
2463
2714
  addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
2464
2715
  }
2465
- function installMpxResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
2716
+ function installMpxResolveLoaderAlias(compiler, getMpxWebpackPluginDir) {
2466
2717
  const resolveOptionsHook = compiler?.resolverFactory?.hooks?.resolveOptions?.for?.("loader");
2467
2718
  if (!resolveOptionsHook?.tap) return;
2468
2719
  resolveOptionsHook.tap({
2469
2720
  name: "weapp-tailwindcss-mpx-loader-resolve",
2470
2721
  stage: 100
2471
2722
  }, (resolveOptions) => {
2723
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2724
+ if (!mpxWebpackPluginDir) return resolveOptions;
2472
2725
  const alias = Array.isArray(resolveOptions.alias) ? [...resolveOptions.alias] : { ...resolveOptions.alias };
2473
2726
  addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
2474
2727
  return {
@@ -2477,13 +2730,14 @@ function installMpxResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
2477
2730
  };
2478
2731
  });
2479
2732
  }
2480
- function patchMpxLoaderResolver(resolver, mpxWebpackPluginDir) {
2733
+ function patchMpxLoaderResolver(resolver, getMpxWebpackPluginDir) {
2481
2734
  const originalResolve = resolver?.resolve;
2482
2735
  if (typeof originalResolve !== "function" || originalResolve.__weappTwPatched) return;
2483
2736
  const wrappedResolve = function(...args) {
2484
2737
  const requestIndex = typeof args[0] === "string" ? 1 : 2;
2485
2738
  const request = args[requestIndex];
2486
- if (typeof request === "string" && isMpxWebpackPluginRequest(request)) args[requestIndex] = resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir);
2739
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2740
+ if (mpxWebpackPluginDir && typeof request === "string" && isMpxWebpackPluginRequest(request)) args[requestIndex] = resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir);
2487
2741
  return originalResolve.apply(this, args);
2488
2742
  };
2489
2743
  wrappedResolve.__weappTwPatched = true;
@@ -2533,12 +2787,13 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
2533
2787
  function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
2534
2788
  if (!enabled) return;
2535
2789
  const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
2536
- const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
2790
+ const getMpxWebpackPluginDir = () => resolveMpxWebpackPluginDir(loaderContext);
2537
2791
  const originalResolve = loaderContext.resolve;
2538
2792
  if (typeof originalResolve === "function" && !originalResolve.__weappTwPatched) {
2539
2793
  const wrappedResolve = function(context, request, callback) {
2540
2794
  if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
2541
2795
  if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
2796
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2542
2797
  if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
2543
2798
  return originalResolve.call(this, context, request, callback);
2544
2799
  };
@@ -2546,9 +2801,10 @@ function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
2546
2801
  loaderContext.resolve = wrappedResolve;
2547
2802
  }
2548
2803
  const originalImportModule = loaderContext.importModule;
2549
- if (mpxWebpackPluginDir && typeof originalImportModule === "function" && !originalImportModule.__weappTwPatched) {
2804
+ if (typeof originalImportModule === "function" && !originalImportModule.__weappTwPatched) {
2550
2805
  const wrappedImportModule = function(request, ...args) {
2551
- const resolvedRequest = typeof request === "string" ? rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir) : request;
2806
+ const mpxWebpackPluginDir = getMpxWebpackPluginDir();
2807
+ const resolvedRequest = mpxWebpackPluginDir && typeof request === "string" ? rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir) : request;
2552
2808
  return originalImportModule.call(this, resolvedRequest, ...args);
2553
2809
  };
2554
2810
  wrappedImportModule.__weappTwPatched = true;
@@ -2620,7 +2876,7 @@ function createDefaultLoaderAnchorFinders() {
2620
2876
  //#endregion
2621
2877
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
2622
2878
  function setupWebpackV5Loaders(options) {
2623
- 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;
2624
2880
  const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(compilerOptions.generator, {
2625
2881
  appType: compilerOptions.appType,
2626
2882
  platform: compilerOptions.cssOptions?.platform ?? compilerOptions.platform,
@@ -2660,7 +2916,8 @@ function setupWebpackV5Loaders(options) {
2660
2916
  classSet: {
2661
2917
  getClassSet: getClassSetInLoader,
2662
2918
  getWatchDependencies: getRuntimeWatchDependencies,
2663
- ...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
2919
+ ...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile },
2920
+ ...updateWebpackGeneratedCss === void 0 ? {} : { updateGeneratedCss: updateWebpackGeneratedCss }
2664
2921
  },
2665
2922
  ...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
2666
2923
  });
@@ -2712,6 +2969,10 @@ function setupWebpackV5Loaders(options) {
2712
2969
  let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
2713
2970
  const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
2714
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
+ }
2715
2976
  if (isCssModule && typeof module.resource === "string") markWebpackCssSourceModule?.(module.resource);
2716
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), {
2717
2978
  rewriteAnchorIdx,
@@ -2759,7 +3020,7 @@ function setupWebpackV5Loaders(options) {
2759
3020
  });
2760
3021
  }
2761
3022
  //#endregion
2762
- //#region src/bundlers/webpack/shared/create-framework-plugin.ts
3023
+ //#region src/bundlers/webpack/shared/create-framework-plugin/watch-output.ts
2763
3024
  const debug = require_wxml.createDebug();
2764
3025
  const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
2765
3026
  const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
@@ -2825,6 +3086,8 @@ function setupWebpackWatchOutputIgnore(compiler) {
2825
3086
  }
2826
3087
  });
2827
3088
  }
3089
+ //#endregion
3090
+ //#region src/bundlers/webpack/shared/create-framework-plugin/plugin.ts
2828
3091
  function isInternalUserDefinedOptions(options) {
2829
3092
  return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
2830
3093
  }
@@ -2970,6 +3233,15 @@ var WebpackFrameworkPlugin = class {
2970
3233
  });
2971
3234
  currentWebpackCssSourceFiles.add(file);
2972
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
+ };
2973
3245
  const pruneWebpackCssSources = (activeSourceFiles, _options = {}) => {
2974
3246
  const tailwindOptions = require_generator.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
2975
3247
  const configuredSourceFiles = /* @__PURE__ */ new Set();
@@ -3047,6 +3319,7 @@ var WebpackFrameworkPlugin = class {
3047
3319
  markWebpackCssSourceModule,
3048
3320
  registerWebpackCssSourceFile,
3049
3321
  registerWebpackGeneratedCss,
3322
+ updateWebpackGeneratedCss,
3050
3323
  getRuntimeWatchDependencies() {
3051
3324
  return {
3052
3325
  files: runtimeWatchDependencyFiles,