weapp-tailwindcss 5.1.0 → 5.1.1

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 (83) hide show
  1. package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
  2. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +6 -14
  3. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
  4. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
  5. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
  6. package/dist/bundlers/vite/css-memory.d.ts +6 -0
  7. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
  8. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
  9. package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
  10. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -0
  11. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +2 -1
  12. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -0
  13. package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
  14. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
  15. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
  16. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
  17. package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
  18. package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
  19. package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
  20. package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
  21. package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
  22. package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -0
  23. package/dist/bundlers/vite/generate-bundle.d.ts +1 -2
  24. package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
  25. package/dist/bundlers/vite/runtime-class-set.d.ts +2 -1
  26. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +3 -3
  27. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
  28. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
  29. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
  30. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
  31. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
  32. package/dist/cli.js +15 -8
  33. package/dist/cli.mjs +15 -8
  34. package/dist/context/style-options.d.ts +1 -0
  35. package/dist/{context-BHxLe743.js → context-B6hVF7dr.js} +20 -9
  36. package/dist/{context-Mbzkek1q.mjs → context-DlpKD7aN.mjs} +15 -10
  37. package/dist/core.js +1 -1
  38. package/dist/core.mjs +1 -1
  39. package/dist/css-macro/index.d.ts +3 -7
  40. package/dist/{defaults-ZElj1zKc.mjs → defaults-BhE26nSw.mjs} +7 -3
  41. package/dist/{defaults-CVcKbXBG.js → defaults-CmFBmxsr.js} +7 -3
  42. package/dist/defaults.d.ts +1 -1
  43. package/dist/defaults.js +1 -1
  44. package/dist/defaults.mjs +1 -1
  45. package/dist/generator/types.d.ts +1 -1
  46. package/dist/{generator-9rUz4Hcb.js → generator-6oMJtTDO.js} +1 -1
  47. package/dist/{generator-Dc4qaPmT.mjs → generator-CjzBK7h-.mjs} +1 -1
  48. package/dist/generator.js +2 -2
  49. package/dist/generator.mjs +2 -2
  50. package/dist/{gulp-B_sdP6dx.js → gulp-BtGq6LP9.js} +11 -9
  51. package/dist/{gulp-uM36oIJs.mjs → gulp-DNU10Vtc.mjs} +11 -9
  52. package/dist/gulp.js +1 -1
  53. package/dist/gulp.mjs +1 -1
  54. package/dist/{hmr-timing-BXMLsF4b.mjs → hmr-timing-B0KuWDjV.mjs} +121 -85
  55. package/dist/{hmr-timing-CogqkFaF.js → hmr-timing-CegXR9O4.js} +132 -84
  56. package/dist/index.js +4 -4
  57. package/dist/index.mjs +4 -4
  58. package/dist/postcss.js +2 -2
  59. package/dist/postcss.mjs +2 -2
  60. package/dist/presets.js +2 -2
  61. package/dist/presets.mjs +2 -2
  62. package/dist/{source-candidate-scan-signature-Cvb5z1ha.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +3 -3
  63. package/dist/{source-candidate-scan-signature-2ybpptAK.js → source-candidate-scan-signature-BKYb9jxa.js} +3 -3
  64. package/dist/tailwindcss/runtime-types.d.ts +1 -0
  65. package/dist/tailwindcss/v4-engine/source.d.ts +5 -14
  66. package/dist/tailwindcss/v4-engine/types.d.ts +10 -2
  67. package/dist/{tailwindcss-wyUHrfil.mjs → tailwindcss-B5mRo0-M.mjs} +12 -7
  68. package/dist/{tailwindcss-DHIYcqXT.js → tailwindcss-dbrbY4cd.js} +11 -6
  69. package/dist/{transform-tExdt40m.mjs → transform-fRBeuuK-.mjs} +1 -1
  70. package/dist/{transform-CQVOgmzM.js → transform-vLwZpiTE.js} +1 -1
  71. package/dist/types/user-defined-options/matcher.d.ts +7 -0
  72. package/dist/{v4-engine-CF9zt4Cw.mjs → v4-engine-C3qSwQ-e.mjs} +7 -27
  73. package/dist/{v4-engine-D4ubP7N5.js → v4-engine-ON_oSLfO.js} +5 -31
  74. package/dist/{vite-CPO83EhA.mjs → vite-CWRooooa.mjs} +730 -393
  75. package/dist/{vite-CP0ylSxZ.js → vite-w-RkgaTY.js} +730 -392
  76. package/dist/vite.js +1 -1
  77. package/dist/vite.mjs +1 -1
  78. package/dist/weapp-tw-css-import-rewrite-loader.js +122 -85
  79. package/dist/{webpack-BzqhJ8yK.mjs → webpack-8PaV1gG3.mjs} +923 -671
  80. package/dist/{webpack-Bsek8VhR.js → webpack-CGgBOx9l.js} +923 -671
  81. package/dist/webpack.js +1 -1
  82. package/dist/webpack.mjs +1 -1
  83. package/package.json +5 -5
@@ -1,11 +1,11 @@
1
1
  const require_chunk = require("./chunk-emK7D4bc.js");
2
- const require_v4_engine = require("./v4-engine-D4ubP7N5.js");
3
- const require_generator = require("./generator-9rUz4Hcb.js");
2
+ const require_v4_engine = require("./v4-engine-ON_oSLfO.js");
3
+ const require_generator = require("./generator-6oMJtTDO.js");
4
4
  const require_utils = require("./utils-BCa37Wqj.js");
5
- const require_context = require("./context-BHxLe743.js");
6
- const require_tailwindcss = require("./tailwindcss-DHIYcqXT.js");
7
- const require_hmr_timing = require("./hmr-timing-CogqkFaF.js");
8
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-2ybpptAK.js");
5
+ const require_context = require("./context-B6hVF7dr.js");
6
+ const require_tailwindcss = require("./tailwindcss-dbrbY4cd.js");
7
+ const require_hmr_timing = require("./hmr-timing-CegXR9O4.js");
8
+ const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BKYb9jxa.js");
9
9
  let node_fs = require("node:fs");
10
10
  node_fs = require_chunk.__toESM(node_fs);
11
11
  let node_path = require("node:path");
@@ -329,6 +329,609 @@ function isWebpackCssLoaderRuntimeSource(source) {
329
329
  return source.includes("___CSS_LOADER_EXPORT___") && source.includes("___CSS_LOADER_API_IMPORT___") && source.includes("module.exports = ___CSS_LOADER_EXPORT___");
330
330
  }
331
331
  //#endregion
332
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.ts
333
+ const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
334
+ function removeTailwindV4StandaloneHostPreflightRule(source) {
335
+ if (!source.includes("--theme(")) return source;
336
+ try {
337
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
338
+ let changed = false;
339
+ root.walkRules((rule) => {
340
+ if (rule.selector.trim() !== ":host") return;
341
+ if (!rule.nodes?.some((node) => node.type === "decl" && node.value?.includes("--theme("))) return;
342
+ rule.remove();
343
+ changed = true;
344
+ });
345
+ return changed ? root.toString() : source;
346
+ } catch {
347
+ return source;
348
+ }
349
+ }
350
+ function isRuntimeTransformCandidate(candidate) {
351
+ return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
352
+ }
353
+ function collectRuntimeTokenSignatureParts(source) {
354
+ return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
355
+ }
356
+ function hasMissingRuntimeCandidates(classSet, candidates) {
357
+ if (!classSet || !candidates?.size) return false;
358
+ for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate) && !classSet.has(candidate)) return true;
359
+ return false;
360
+ }
361
+ function resolveGeneratedCssRuntimeCandidates(source, fallbackClassSet) {
362
+ const classSet = collectGeneratedCssRuntimeCandidates(source);
363
+ if (classSet.size > 0 || fallbackClassSet === void 0) return classSet;
364
+ return fallbackClassSet;
365
+ }
366
+ function getRuntimeClassSetSync(tailwindRuntime) {
367
+ if (typeof tailwindRuntime.getClassSetSync !== "function") return /* @__PURE__ */ new Set();
368
+ try {
369
+ return new Set(tailwindRuntime.getClassSetSync() ?? []);
370
+ } catch {
371
+ return /* @__PURE__ */ new Set();
372
+ }
373
+ }
374
+ function toMb(bytes) {
375
+ return Math.round(bytes / 1024 / 1024);
376
+ }
377
+ function pruneMapToMaxSize(map, maxSize) {
378
+ while (map.size > maxSize) {
379
+ const oldestKey = map.keys().next().value;
380
+ if (oldestKey === void 0) break;
381
+ map.delete(oldestKey);
382
+ }
383
+ }
384
+ function stripTrailingLineWhitespace(source) {
385
+ return source.replace(/[ \t]+$/gm, "");
386
+ }
387
+ function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
388
+ const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
389
+ for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
390
+ for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
391
+ pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
392
+ pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
393
+ }
394
+ function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
395
+ const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
396
+ if (sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
397
+ return rawSource;
398
+ }
399
+ function hasUsableWebpackGeneratorCssSources(cssSources) {
400
+ return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
401
+ }
402
+ function normalizeWebpackGeneratorCssSources(cssSources) {
403
+ if (!Array.isArray(cssSources)) return;
404
+ const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
405
+ return normalized.length > 0 ? normalized : void 0;
406
+ }
407
+ function hasProcessedCssAssetUrl(css) {
408
+ return /url\(\s*["']?data:/i.test(css);
409
+ }
410
+ function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource, options = {}) {
411
+ return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(rawSource) && /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(rawSource) && (!require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
412
+ }
413
+ function collectWebpackAssetUserCssMarkers(source) {
414
+ const markers = /* @__PURE__ */ new Set();
415
+ for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
416
+ for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
417
+ try {
418
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
419
+ root.walkRules((rule) => {
420
+ for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
421
+ rule.walkDecls((decl) => {
422
+ if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
423
+ });
424
+ });
425
+ root.walkAtRules("font-face", (rule) => {
426
+ rule.walkDecls("font-family", (decl) => {
427
+ markers.add(`font-face:${decl.value.trim()}`);
428
+ });
429
+ });
430
+ } catch {}
431
+ return markers;
432
+ }
433
+ const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = new Set([
434
+ "theme",
435
+ "base",
436
+ "utilities"
437
+ ]);
438
+ const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
439
+ const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
440
+ function parseWebpackCssLayerNames(params) {
441
+ return params.split(",").map((name) => name.trim()).filter(Boolean);
442
+ }
443
+ function removeWebpackTailwindGeneratedAssetCss(source) {
444
+ const cleaned = require_hmr_timing.removeTailwindV4GeneratedUserCssArtifacts(source);
445
+ try {
446
+ const root = _weapp_tailwindcss_postcss.postcss.parse(cleaned);
447
+ let changed = false;
448
+ root.walkAtRules("layer", (rule) => {
449
+ const names = parseWebpackCssLayerNames(rule.params);
450
+ const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
451
+ const isLayerDeclaration = rule.nodes === void 0;
452
+ const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
453
+ if (shouldRemoveLayer && isLayerDeclaration) {
454
+ rule.remove();
455
+ changed = true;
456
+ return;
457
+ }
458
+ if (shouldRemoveLayer && !names.includes("utilities")) {
459
+ rule.remove();
460
+ changed = true;
461
+ return;
462
+ }
463
+ if (shouldRemoveLayer) {
464
+ rule.walkRules((nestedRule) => {
465
+ const selector = nestedRule.selector.trim();
466
+ if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector)) {
467
+ nestedRule.remove();
468
+ changed = true;
469
+ }
470
+ });
471
+ if (rule.nodes?.length === 0) {
472
+ rule.remove();
473
+ changed = true;
474
+ }
475
+ }
476
+ });
477
+ root.walkAtRules((rule) => {
478
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) {
479
+ rule.remove();
480
+ changed = true;
481
+ }
482
+ });
483
+ return changed ? root.toString() : cleaned;
484
+ } catch {
485
+ return cleaned;
486
+ }
487
+ }
488
+ function collectWebpackCssRuleIdentityMarkers(source) {
489
+ const markers = /* @__PURE__ */ new Set();
490
+ try {
491
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
492
+ root.walkRules((rule) => {
493
+ 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]}`);
494
+ });
495
+ root.walkAtRules("keyframes", (rule) => {
496
+ if (rule.params) markers.add(`keyframes:${rule.params}`);
497
+ });
498
+ } catch {}
499
+ return markers;
500
+ }
501
+ function unescapeCssIdentifier(value) {
502
+ return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
503
+ const hex = escaped.trim();
504
+ if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
505
+ return escaped;
506
+ });
507
+ }
508
+ function collectGeneratedCssRuntimeCandidates(source) {
509
+ const candidates = /* @__PURE__ */ new Set();
510
+ if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) || !require_v4_engine.hasTailwindGeneratedCss(source) && !require_v4_engine.hasTailwindGeneratedCssMarkers(source)) return candidates;
511
+ try {
512
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
513
+ for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
514
+ const candidate = unescapeCssIdentifier(match[1]);
515
+ if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
516
+ }
517
+ });
518
+ } catch {}
519
+ return candidates;
520
+ }
521
+ function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
522
+ const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
523
+ if (rawMarkers.size === 0) return false;
524
+ const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
525
+ for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
526
+ return false;
527
+ }
528
+ function hasWebpackTailwindSourceDirectives(source) {
529
+ return Boolean(source) && (require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source) || require_v4_engine.hasTailwindGeneratedCss(source) || require_v4_engine.hasTailwindGeneratedCssMarkers(source));
530
+ }
531
+ function isWebpackTailwindImportRequest(request) {
532
+ return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
533
+ }
534
+ function removeWebpackGeneratorNonTailwindImports(source) {
535
+ if (!source?.includes("@import")) return source;
536
+ try {
537
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
538
+ let changed = false;
539
+ root.walkAtRules("import", (rule) => {
540
+ if (isWebpackTailwindImportRequest(require_v4_engine.parseImportRequest(rule.params))) return;
541
+ rule.remove();
542
+ changed = true;
543
+ });
544
+ return changed ? root.toString() : source;
545
+ } catch {
546
+ return source;
547
+ }
548
+ }
549
+ function isWebpackCssSourceRepresentedInAsset(rawSource, sourceCss) {
550
+ if (!sourceCss || !hasWebpackTailwindSourceDirectives(sourceCss)) return false;
551
+ const sourceMarkers = collectWebpackCssRuleIdentityMarkers(sourceCss);
552
+ if (sourceMarkers.size === 0) return false;
553
+ const rawMarkers = collectWebpackCssRuleIdentityMarkers(rawSource);
554
+ for (const marker of sourceMarkers) if (!rawMarkers.has(marker)) return false;
555
+ return true;
556
+ }
557
+ function createWebpackGeneratorCssSource(file, css) {
558
+ if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
559
+ return {
560
+ file,
561
+ base: node_path.default.dirname(file),
562
+ css,
563
+ dependencies: [file]
564
+ };
565
+ }
566
+ function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
567
+ const matchedSources = [];
568
+ const seen = /* @__PURE__ */ new Set();
569
+ for (const source of sources) {
570
+ const css = source.css;
571
+ if (!css || seen.has(css)) continue;
572
+ if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
573
+ seen.add(css);
574
+ if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
575
+ css,
576
+ file: source.file,
577
+ processed: source.processed === true
578
+ });
579
+ }
580
+ const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
581
+ const parts = matchedSources.sort((a, b) => {
582
+ const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
583
+ if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
584
+ return a.file.localeCompare(b.file);
585
+ }).map((source) => source.css);
586
+ return parts.length > 0 ? {
587
+ css: parts.join("\n"),
588
+ processed: matchedSources.every((source) => source.processed)
589
+ } : void 0;
590
+ }
591
+ function createWebpackGeneratorUserCssSourceAppend(...sources) {
592
+ const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
593
+ if (parts.length === 0) return;
594
+ let css = "";
595
+ const usedParts = [];
596
+ for (const source of parts) {
597
+ const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, source.css) : source.css;
598
+ if (!(nextCss.trim().length > 0)) continue;
599
+ css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
600
+ usedParts.push(source);
601
+ }
602
+ return {
603
+ css,
604
+ processed: usedParts.every((source) => source.processed)
605
+ };
606
+ }
607
+ function resolveWebpackMemoryDebugStats(context) {
608
+ if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
609
+ const memory = node_process.default.memoryUsage();
610
+ const processCacheInstanceSize = context.cache.instance.size;
611
+ const processCacheHashMapSize = context.cache.hashMap.size;
612
+ return {
613
+ phase: context.phase,
614
+ process: {
615
+ rssMb: toMb(memory.rss),
616
+ heapTotalMb: toMb(memory.heapTotal),
617
+ heapUsedMb: toMb(memory.heapUsed),
618
+ externalMb: toMb(memory.external),
619
+ arrayBuffersMb: toMb(memory.arrayBuffers)
620
+ },
621
+ assets: {
622
+ active: context.activeAssetFiles,
623
+ activeCss: context.activeCssFiles
624
+ },
625
+ processCache: {
626
+ instance: processCacheInstanceSize,
627
+ hashMap: processCacheHashMapSize,
628
+ activeCacheKeys: context.activeProcessCacheKeys.size,
629
+ activeHashKeys: context.activeProcessHashKeys.size,
630
+ staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
631
+ staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
632
+ pruned: true,
633
+ pruneSkipped: false
634
+ },
635
+ webpackCss: {
636
+ handlerOptions: context.cssHandlerOptionsCache.size,
637
+ userHandlerOptions: context.cssUserHandlerOptionsCache.size,
638
+ maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
639
+ },
640
+ sourceCandidateScan: context.sourceCandidateScan,
641
+ tailwind: { v4: require_v4_engine.getTailwindV4IncrementalGenerateCacheStats() }
642
+ };
643
+ }
644
+ function shouldInjectWebpackCssTracePreflight(appType, cssHandlerOptions) {
645
+ return appType !== "mpx" || cssHandlerOptions.isMainChunk !== false;
646
+ }
647
+ function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
648
+ const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
649
+ if (isWebGeneratorTarget) return source;
650
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_hmr_timing.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
651
+ cssPreflight: options.cssPreflight !== false && !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? compilerOptions.cssPreflight : void 0,
652
+ isTailwindcssV4: true,
653
+ tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
654
+ })));
655
+ }
656
+ function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
657
+ return !require_v4_engine.hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
658
+ }
659
+ function isWindowsAbsoluteResourcePath(file) {
660
+ return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
661
+ }
662
+ function isPosixAbsoluteResourcePath(file) {
663
+ return file.startsWith("/");
664
+ }
665
+ function resolveWebpackResourcePath(file, base) {
666
+ if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.resolve(file);
667
+ if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.resolve(file);
668
+ if (base) {
669
+ if (isWindowsAbsoluteResourcePath(base)) return node_path.default.win32.resolve(base, file);
670
+ if (isPosixAbsoluteResourcePath(base)) return node_path.default.posix.resolve(base, file);
671
+ return node_path.default.resolve(base, file);
672
+ }
673
+ }
674
+ function dirnameWebpackResourcePath(file) {
675
+ if (isWindowsAbsoluteResourcePath(file)) return node_path.default.win32.dirname(file);
676
+ if (isPosixAbsoluteResourcePath(file)) return node_path.default.posix.dirname(file);
677
+ return node_path.default.dirname(file);
678
+ }
679
+ function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
680
+ if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
681
+ const normalized = stripResourceQuery(resource);
682
+ if (!normalized) return;
683
+ const absoluteResource = resolveWebpackResourcePath(normalized);
684
+ if (absoluteResource) return absoluteResource;
685
+ const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
686
+ const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
687
+ return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
688
+ }
689
+ function isSameWebpackCssSourceScope(options) {
690
+ if (!options.currentSourceFile) return false;
691
+ const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? node_path.default.resolve(options.candidateSourceFile);
692
+ if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? node_path.default.resolve(options.currentSourceFile))) return true;
693
+ const outputResources = options.resourcesByAsset.get(options.outputFile);
694
+ if (!outputResources) return false;
695
+ return [...outputResources].some((resource) => {
696
+ return (resolveWebpackResourcePath(resource) ?? node_path.default.resolve(resource)) === candidateKey;
697
+ });
698
+ }
699
+ function shouldAppendCurrentWebpackAssetUserCss(options) {
700
+ const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
701
+ return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
702
+ }
703
+ function createWebpackCurrentAssetUserRawSource(options) {
704
+ if (!options.shouldAppendCurrentAssetUserCss) return;
705
+ if (options.sourceCssProcessed) return {
706
+ css: options.currentAssetUserCssSource,
707
+ processed: true
708
+ };
709
+ if (!options.currentAssetHasUserCss) return;
710
+ return {
711
+ css: options.currentAssetUserCssSource,
712
+ processed: options.currentAssetLooksGenerated
713
+ };
714
+ }
715
+ function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
716
+ const traced = options.annotateCss(css);
717
+ if (options.isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(options.compilerOptions)) return traced;
718
+ return finalizeMiniProgramUserCssAssetSource(traced, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
719
+ }
720
+ function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
721
+ const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
722
+ if (isWebGeneratorTarget) {
723
+ if (options.generatedCss === true) return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source))));
724
+ return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_hmr_timing.removeTailwindV4GeneratorAtRules(require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
725
+ }
726
+ let finalized = require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
727
+ if (options.generatedCss !== true) return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
728
+ try {
729
+ finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: true });
730
+ } catch {
731
+ finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
732
+ cssPreflight: !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? compilerOptions.cssPreflight : void 0,
733
+ isTailwindcssV4: true,
734
+ tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
735
+ });
736
+ }
737
+ return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
738
+ }
739
+ function collectWebpackJsRuntimeCandidatesFromAssets(options) {
740
+ if (options.isWebGeneratorTarget) return;
741
+ const candidates = /* @__PURE__ */ new Set();
742
+ for (const file of options.jsAssets) {
743
+ const sourceLike = options.getAssetSource(file);
744
+ if (sourceLike === void 0) continue;
745
+ const source = stringifyWebpackSourceLike(sourceLike);
746
+ for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
747
+ }
748
+ return candidates;
749
+ }
750
+ function collectWebpackJsRuntimeTokenSignature(options) {
751
+ if (options.isWebGeneratorTarget) return "";
752
+ const tokens = [];
753
+ for (const file of options.jsAssets) {
754
+ const sourceLike = options.getAssetSource(file);
755
+ if (sourceLike === void 0) continue;
756
+ tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
757
+ }
758
+ return tokens.sort().join("\n");
759
+ }
760
+ function addRuntimeTransformCandidates(target, candidates) {
761
+ if (!candidates?.size) return;
762
+ for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
763
+ }
764
+ function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
765
+ if (!require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
766
+ return require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
767
+ }
768
+ function stringifyOptionalWebpackSourceValue(value) {
769
+ return typeof value === "string" ? value : value?.toString() ?? "";
770
+ }
771
+ function stringifyWebpackSourceLike(source) {
772
+ if (typeof source === "string") return source;
773
+ const value = source.source();
774
+ return typeof value === "string" ? value : value.toString();
775
+ }
776
+ //#endregion
777
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.ts
778
+ function createWebpackCssSourceResolvers(options) {
779
+ const { activeWebpackAssetResourceFiles, appType, compilerOptions, compilation, cssAssetResources, cssHandlerOptionsCache, cssSources, cssUserHandlerOptionsCache, groupedCssEntriesLength, singleCssAssetFile, isWebGeneratorTarget, outputDir, runtimeState } = options;
780
+ const hasConfiguredTailwindV4SourceRoots = () => {
781
+ const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
782
+ return (tailwindOptions?.v4?.cssEntries?.length ?? 0) > 0 || (tailwindOptions?.v4?.cssSources?.length ?? 0) > 0;
783
+ };
784
+ const configuredMainCssEntryFiles = (() => {
785
+ return [...require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.v4?.cssEntries ?? []].filter((file) => typeof file === "string" && file.length > 0).map((file) => node_path.default.resolve(file));
786
+ })();
787
+ const inferredMainCssFiles = inferWebpackMainCssFiles(compilation.chunks, compilerOptions.cssMatcher, {
788
+ mainSourceFiles: new Set(configuredMainCssEntryFiles),
789
+ resourcesByAsset: cssAssetResources
790
+ });
791
+ const singleConfiguredCssAsset = isWebGeneratorTarget && configuredMainCssEntryFiles.length > 0 && groupedCssEntriesLength === 1 ? singleCssAssetFile : void 0;
792
+ const isMainCssChunk = (file) => compilerOptions.mainCssChunkMatcher(file, appType) || inferredMainCssFiles.has(file) || file === singleConfiguredCssAsset;
793
+ const activeWebpackCssSourceFiles = /* @__PURE__ */ new Set();
794
+ const resolveConfiguredMainCssSourceFile = (file) => {
795
+ if (!isMainCssChunk(file)) return;
796
+ for (const sourceFile of configuredMainCssEntryFiles) if (cssSources.has(sourceFile)) {
797
+ activeWebpackCssSourceFiles.add(sourceFile);
798
+ return sourceFile;
799
+ }
800
+ };
801
+ const resolveWebpackCssSourceFile = (file, rawSource) => {
802
+ const assetResources = cssAssetResources.get(file);
803
+ const activeAssetResource = resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAssetResourceFiles);
804
+ if (cssSources.size === 0) {
805
+ if (activeAssetResource) {
806
+ activeWebpackCssSourceFiles.add(activeAssetResource);
807
+ return activeAssetResource;
808
+ }
809
+ if (assetResources && assetResources.size > 0) return;
810
+ return resolveConfiguredMainCssSourceFile(file);
811
+ }
812
+ const resourceMatches = [...assetResources ?? []].filter((sourceFile) => cssSources.has(sourceFile)).sort();
813
+ if (resourceMatches.length === 1) {
814
+ const sourceFile = resourceMatches[0];
815
+ activeWebpackCssSourceFiles.add(sourceFile);
816
+ return sourceFile;
817
+ }
818
+ const tailwindSourceMatches = resourceMatches.filter((sourceFile) => {
819
+ const sourceCss = cssSources.get(sourceFile)?.css;
820
+ return sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss));
821
+ });
822
+ if (tailwindSourceMatches.length === 1) {
823
+ const sourceFile = tailwindSourceMatches[0];
824
+ activeWebpackCssSourceFiles.add(sourceFile);
825
+ return sourceFile;
826
+ }
827
+ if (activeAssetResource) {
828
+ activeWebpackCssSourceFiles.add(activeAssetResource);
829
+ return activeAssetResource;
830
+ }
831
+ if (rawSource) {
832
+ const representedTailwindSourceMatches = [...cssSources.entries()].filter(([, source]) => isWebpackCssSourceRepresentedInAsset(rawSource, source.css)).map(([sourceFile]) => ({
833
+ sourceFile,
834
+ score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
835
+ outputRoot: outputDir,
836
+ projectRoot: compilerOptions.tailwindcssBasedir,
837
+ cwd: compilerOptions.tailwindcssBasedir
838
+ })
839
+ })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
840
+ const bestScore = representedTailwindSourceMatches[0]?.score ?? 0;
841
+ const bestMatches = representedTailwindSourceMatches.filter((match) => match.score === bestScore);
842
+ if (bestMatches.length === 1) {
843
+ const sourceFile = bestMatches[0].sourceFile;
844
+ activeWebpackCssSourceFiles.add(sourceFile);
845
+ return sourceFile;
846
+ }
847
+ }
848
+ const pathMatches = [...cssSources.keys()].map((sourceFile) => ({
849
+ sourceFile,
850
+ score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
851
+ outputRoot: outputDir,
852
+ projectRoot: compilerOptions.tailwindcssBasedir,
853
+ cwd: compilerOptions.tailwindcssBasedir
854
+ })
855
+ })).filter((match) => match.score >= 1e3).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
856
+ const bestPathScore = pathMatches[0]?.score ?? 0;
857
+ const bestPathMatches = pathMatches.filter((match) => match.score === bestPathScore);
858
+ if (bestPathMatches.length === 1) {
859
+ const sourceFile = bestPathMatches[0].sourceFile;
860
+ activeWebpackCssSourceFiles.add(sourceFile);
861
+ return sourceFile;
862
+ }
863
+ if (assetResources && assetResources.size > 0) return;
864
+ return resolveConfiguredMainCssSourceFile(file);
865
+ };
866
+ const isSameWebpackSourceScope = (outputFile, candidateSourceFile, currentSourceFile) => isSameWebpackCssSourceScope({
867
+ candidateSourceFile,
868
+ currentSourceFile,
869
+ outputFile,
870
+ resourcesByAsset: cssAssetResources
871
+ });
872
+ const getCssHandlerOptions = (file, rawSource) => {
873
+ const majorVersion = runtimeState.tailwindRuntime.majorVersion;
874
+ const isMainChunk = isMainCssChunk(file);
875
+ const sourceFile = resolveWebpackCssSourceFile(file, rawSource);
876
+ const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
877
+ const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
878
+ const generatorCssSource = createWebpackGeneratorCssSource(sourceFile, generatorSourceCss);
879
+ const cacheKey = [
880
+ majorVersion ?? "unknown",
881
+ isMainChunk ? "1" : "0",
882
+ sourceFile ?? "asset",
883
+ sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
884
+ generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
885
+ file
886
+ ].join(":");
887
+ const cached = cssHandlerOptionsCache.get(cacheKey);
888
+ if (cached) return cached;
889
+ const created = {
890
+ isMainChunk,
891
+ postcssOptions: { options: { from: sourceFile ?? file } },
892
+ sourceOptions: {
893
+ outputRoot: outputDir,
894
+ ...generatorCssSource === void 0 ? {} : { cssSources: [generatorCssSource] },
895
+ ...generatorSourceCss === void 0 ? {} : { sourceCss: generatorSourceCss },
896
+ ...sourceFile === void 0 ? {} : { sourceFile }
897
+ },
898
+ ...require_context.normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
899
+ };
900
+ cssHandlerOptionsCache.set(cacheKey, created);
901
+ return created;
902
+ };
903
+ const getCssUserHandlerOptions = (file) => {
904
+ const majorVersion = runtimeState.tailwindRuntime.majorVersion;
905
+ const sourceFile = resolveWebpackCssSourceFile(file);
906
+ const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
907
+ const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
908
+ const cacheKey = [
909
+ majorVersion ?? "unknown",
910
+ sourceFile ?? "asset",
911
+ sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
912
+ generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
913
+ file
914
+ ].join(":");
915
+ const cached = cssUserHandlerOptionsCache.get(cacheKey);
916
+ if (cached) return cached;
917
+ const created = {
918
+ ...getCssHandlerOptions(file),
919
+ isMainChunk: false
920
+ };
921
+ cssUserHandlerOptionsCache.set(cacheKey, created);
922
+ return created;
923
+ };
924
+ return {
925
+ activeWebpackCssSourceFiles,
926
+ configuredMainCssEntryFiles,
927
+ getCssHandlerOptions,
928
+ getCssUserHandlerOptions,
929
+ hasConfiguredTailwindV4SourceRoots,
930
+ isSameWebpackSourceScope,
931
+ resolveWebpackCssSourceFile
932
+ };
933
+ }
934
+ //#endregion
332
935
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
333
936
  function createChangedByType() {
334
937
  return {
@@ -381,6 +984,11 @@ function buildWebpackBundleSnapshot(assets, opts, state, compilation) {
381
984
  file,
382
985
  output: {
383
986
  fileName: file,
987
+ name: void 0,
988
+ names: [],
989
+ needsCodeReference: false,
990
+ originalFileName: null,
991
+ originalFileNames: [],
384
992
  source,
385
993
  type: "asset"
386
994
  },
@@ -404,7 +1012,8 @@ function buildWebpackBundleSnapshot(assets, opts, state, compilation) {
404
1012
  function releaseWebpackBundleSnapshotSources(snapshot) {
405
1013
  for (const entry of snapshot.entries) {
406
1014
  entry.source = "";
407
- entry.output.source = "";
1015
+ if (entry.output.type === "asset") entry.output.source = "";
1016
+ else entry.output.code = "";
408
1017
  }
409
1018
  }
410
1019
  function stringifyWebpackSource(source) {
@@ -438,6 +1047,50 @@ function createWebpackAssetUpdater(options) {
438
1047
  };
439
1048
  }
440
1049
  //#endregion
1050
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.ts
1051
+ function createWebpackJsAssetModuleGraph(options) {
1052
+ const jsAssets = /* @__PURE__ */ new Map();
1053
+ for (const [file] of options.entries) if (options.compilerOptions.jsMatcher(file) || options.compilerOptions.wxsMatcher(file)) {
1054
+ const absolute = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, options.outputDir);
1055
+ jsAssets.set(absolute, file);
1056
+ }
1057
+ return {
1058
+ jsAssets,
1059
+ moduleGraphOptions: {
1060
+ resolve(specifier, importer) {
1061
+ return require_source_candidate_scan_signature.resolveOutputSpecifier(specifier, importer, options.outputDir, (candidate) => jsAssets.has(candidate));
1062
+ },
1063
+ load: (id) => {
1064
+ const assetName = jsAssets.get(id);
1065
+ if (!assetName) return;
1066
+ const asset = options.compilation.getAsset(assetName);
1067
+ if (!asset) return;
1068
+ const source = asset.source.source();
1069
+ return source == null ? "" : String(source);
1070
+ },
1071
+ filter(id) {
1072
+ return jsAssets.has(id);
1073
+ }
1074
+ }
1075
+ };
1076
+ }
1077
+ function applyWebpackLinkedJsResults(options) {
1078
+ if (!options.linked) return;
1079
+ for (const [id, { code }] of Object.entries(options.linked)) {
1080
+ const assetName = options.jsAssets.get(id);
1081
+ if (!assetName) continue;
1082
+ const asset = options.compilation.getAsset(assetName);
1083
+ if (!asset) continue;
1084
+ const previousSource = asset.source.source();
1085
+ const previous = previousSource == null ? "" : String(previousSource);
1086
+ if (previous === code) continue;
1087
+ const source = new options.ConcatSource(code);
1088
+ options.compilation.updateAsset(assetName, source);
1089
+ options.compilerOptions.onUpdate(assetName, previous, code);
1090
+ options.debug("js linked handle: %s", assetName);
1091
+ }
1092
+ }
1093
+ //#endregion
441
1094
  //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.ts
442
1095
  const WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX = 2;
443
1096
  function trimScanCache(cache) {
@@ -501,359 +1154,140 @@ async function resolveScanFileSnapshot(file) {
501
1154
  try {
502
1155
  const stats = await (0, node_fs_promises.stat)(file);
503
1156
  const source = await (0, node_fs_promises.readFile)(file, "utf8");
504
- return {
505
- meta: {
506
- contentHash: (0, _weapp_tailwindcss_shared_node.md5)(source),
507
- mtimeMs: stats.mtimeMs,
508
- size: stats.size
509
- },
510
- source
511
- };
512
- } catch (error) {
513
- if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") return;
514
- throw error;
515
- }
516
- }
517
- function isSameFileMeta(left, right) {
518
- return left?.contentHash === right?.contentHash && left?.mtimeMs === right?.mtimeMs && left?.size === right?.size;
519
- }
520
- async function resolveScanFiles(roots, outDir) {
521
- const files = /* @__PURE__ */ new Set();
522
- await Promise.all(roots.map(async (root) => {
523
- const rootFiles = await require_hmr_timing.resolveSourceCandidateScanFiles({
524
- entries: root.entries,
525
- explicit: root.explicit,
526
- filter: require_hmr_timing.isSourceCandidateRequest,
527
- outDir,
528
- root: root.root
529
- });
530
- for (const file of rootFiles) files.add(require_v4_engine.resolveSourceScanPath(file));
531
- }));
532
- return files;
533
- }
534
- async function syncChangedScanFiles(collector, cachedScan, scanFiles, changedFiles) {
535
- for (const file of cachedScan.files.keys()) {
536
- if (scanFiles.has(file)) continue;
537
- collector.remove(file);
538
- cachedScan.files.delete(file);
539
- }
540
- await Promise.all([...scanFiles].map(async (file) => {
541
- const nextSnapshot = await resolveScanFileSnapshot(file);
542
- if (!nextSnapshot) {
543
- collector.remove(file);
544
- cachedScan.files.delete(file);
545
- return;
546
- }
547
- const previousMeta = cachedScan.files.get(file);
548
- if (previousMeta && isSameFileMeta(previousMeta, nextSnapshot.meta) && !changedFiles.has(file)) return;
549
- await collector.sync(file, nextSnapshot.source);
550
- cachedScan.files.set(file, nextSnapshot.meta);
551
- }));
552
- }
553
- function createWebpackSourceCandidateScanCache() {
554
- const scans = /* @__PURE__ */ new Map();
555
- let lastHit = false;
556
- let lastSignatureHash;
557
- async function resolve({ changedFiles, collector, outDir, root, sourceScan, watchMode }) {
558
- const explicit = sourceScan?.explicit ?? false;
559
- const roots = collectWebpackSourceCandidateScanRoots(root, sourceScan?.entries, explicit);
560
- const nextSignatureHash = (0, _weapp_tailwindcss_shared_node.md5)(require_source_candidate_scan_signature.createSourceCandidateScanSignature({
561
- inlineCandidates: sourceScan?.inlineCandidates,
562
- outDir,
563
- roots,
564
- scanAllSources: !explicit
565
- }));
566
- const scanFiles = await resolveScanFiles(roots, outDir);
567
- const cachedScan = watchMode ? scans.get(nextSignatureHash) : void 0;
568
- if (cachedScan) {
569
- collector.restore(cachedScan.snapshot);
570
- collector.syncInline(sourceScan?.inlineCandidates);
571
- await syncChangedScanFiles(collector, cachedScan, scanFiles, normalizeChangedFiles(changedFiles));
572
- cachedScan.snapshot = compactSnapshot(collector.snapshot());
573
- lastHit = true;
574
- lastSignatureHash = nextSignatureHash;
575
- return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
576
- }
577
- collector.clearScan();
578
- collector.syncInline(sourceScan?.inlineCandidates);
579
- const files = /* @__PURE__ */ new Map();
580
- await Promise.all([...scanFiles].map(async (file) => {
581
- const nextSnapshot = await resolveScanFileSnapshot(file);
582
- if (!nextSnapshot) return;
583
- await collector.sync(file, nextSnapshot.source);
584
- files.set(file, nextSnapshot.meta);
585
- }));
586
- if (watchMode) {
587
- scans.set(nextSignatureHash, {
588
- files,
589
- snapshot: compactSnapshot(collector.snapshot())
590
- });
591
- trimScanCache(scans);
592
- } else scans.clear();
593
- lastHit = false;
594
- lastSignatureHash = nextSignatureHash;
595
- return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
596
- }
597
- function getMemoryStats() {
598
- const cachedScans = [...scans.values()];
599
- return {
600
- entries: cachedScans.reduce((count, scan) => count + (scan.snapshot.scanCandidatesById?.length ?? scan.snapshot.candidatesById.length), 0),
601
- files: cachedScans.reduce((count, scan) => count + scan.files.size, 0),
602
- lastHit,
603
- signatureHash: lastSignatureHash,
604
- snapshots: scans.size
605
- };
606
- }
607
- return {
608
- getMemoryStats,
609
- resolve
610
- };
611
- }
612
- //#endregion
613
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
614
- const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
615
- function removeTailwindV4StandaloneHostPreflightRule(source) {
616
- if (!source.includes("--theme(")) return source;
617
- try {
618
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
619
- let changed = false;
620
- root.walkRules((rule) => {
621
- if (rule.selector.trim() !== ":host") return;
622
- if (!rule.nodes?.some((node) => node.type === "decl" && node.value?.includes("--theme("))) return;
623
- rule.remove();
624
- changed = true;
625
- });
626
- return changed ? root.toString() : source;
627
- } catch {
628
- return source;
629
- }
630
- }
631
- function isRuntimeTransformCandidate(candidate) {
632
- return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
633
- }
634
- function collectRuntimeTokenSignatureParts(source) {
635
- return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
636
- }
637
- function hasMissingRuntimeCandidates(classSet, candidates) {
638
- if (!classSet || !candidates?.size) return false;
639
- for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate) && !classSet.has(candidate)) return true;
640
- return false;
641
- }
642
- function resolveGeneratedCssRuntimeCandidates(source, fallbackClassSet) {
643
- const classSet = collectGeneratedCssRuntimeCandidates(source);
644
- if (classSet.size > 0 || fallbackClassSet === void 0) return classSet;
645
- return fallbackClassSet;
646
- }
647
- function getRuntimeClassSetSync(tailwindRuntime) {
648
- if (typeof tailwindRuntime.getClassSetSync !== "function") return /* @__PURE__ */ new Set();
649
- try {
650
- return new Set(tailwindRuntime.getClassSetSync() ?? []);
651
- } catch {
652
- return /* @__PURE__ */ new Set();
653
- }
654
- }
655
- function toMb(bytes) {
656
- return Math.round(bytes / 1024 / 1024);
657
- }
658
- function pruneMapToMaxSize(map, maxSize) {
659
- while (map.size > maxSize) {
660
- const oldestKey = map.keys().next().value;
661
- if (oldestKey === void 0) break;
662
- map.delete(oldestKey);
663
- }
664
- }
665
- function stripTrailingLineWhitespace(source) {
666
- return source.replace(/[ \t]+$/gm, "");
667
- }
668
- function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
669
- const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
670
- for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
671
- for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
672
- pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
673
- pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
674
- }
675
- function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
676
- const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
677
- if (sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
678
- return rawSource;
679
- }
680
- function hasUsableWebpackGeneratorCssSources(cssSources) {
681
- return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
682
- }
683
- function normalizeWebpackGeneratorCssSources(cssSources) {
684
- if (!Array.isArray(cssSources)) return;
685
- const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
686
- return normalized.length > 0 ? normalized : void 0;
687
- }
688
- function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource, options = {}) {
689
- return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(rawSource) && /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(rawSource) && (!require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
690
- }
691
- function collectWebpackAssetUserCssMarkers(source) {
692
- const markers = /* @__PURE__ */ new Set();
693
- for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
694
- for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
695
- return markers;
696
- }
697
- function collectWebpackCssRuleIdentityMarkers(source) {
698
- const markers = /* @__PURE__ */ new Set();
699
- try {
700
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
701
- root.walkRules((rule) => {
702
- for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
703
- });
704
- root.walkAtRules("keyframes", (rule) => {
705
- if (rule.params) markers.add(`keyframes:${rule.params}`);
706
- });
707
- } catch {}
708
- return markers;
709
- }
710
- function unescapeCssIdentifier(value) {
711
- return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
712
- const hex = escaped.trim();
713
- if (/^[0-9a-f]+$/i.test(hex)) {
714
- const codePoint = Number.parseInt(hex, 16);
715
- if (Number.isFinite(codePoint)) return String.fromCodePoint(codePoint);
716
- }
717
- return escaped;
718
- });
719
- }
720
- function collectGeneratedCssRuntimeCandidates(source) {
721
- const candidates = /* @__PURE__ */ new Set();
722
- if (require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source) || !require_v4_engine.hasTailwindGeneratedCss(source) && !require_v4_engine.hasTailwindGeneratedCssMarkers(source)) return candidates;
723
- try {
724
- _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
725
- for (const selector of rule.selectors ?? [rule.selector]) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
726
- const candidate = unescapeCssIdentifier(match[1] ?? "");
727
- if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
728
- }
729
- });
730
- } catch {}
731
- return candidates;
732
- }
733
- function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
734
- const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
735
- if (rawMarkers.size === 0) return false;
736
- const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
737
- for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
738
- return false;
739
- }
740
- function hasWebpackTailwindSourceDirectives(source) {
741
- return Boolean(source) && (require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source) || require_v4_engine.hasTailwindGeneratedCss(source) || require_v4_engine.hasTailwindGeneratedCssMarkers(source));
742
- }
743
- function isWebpackTailwindImportRequest(request) {
744
- return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
745
- }
746
- function removeWebpackGeneratorNonTailwindImports(source) {
747
- if (!source?.includes("@import")) return source;
748
- try {
749
- const root = _weapp_tailwindcss_postcss.postcss.parse(source);
750
- let changed = false;
751
- root.walkAtRules("import", (rule) => {
752
- if (isWebpackTailwindImportRequest(require_v4_engine.parseImportRequest(rule.params))) return;
753
- rule.remove();
754
- changed = true;
755
- });
756
- return changed ? root.toString() : source;
757
- } catch {
758
- return source;
1157
+ return {
1158
+ meta: {
1159
+ contentHash: (0, _weapp_tailwindcss_shared_node.md5)(source),
1160
+ mtimeMs: stats.mtimeMs,
1161
+ size: stats.size
1162
+ },
1163
+ source
1164
+ };
1165
+ } catch (error) {
1166
+ if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") return;
1167
+ throw error;
759
1168
  }
760
1169
  }
761
- function isWebpackCssSourceRepresentedInAsset(rawSource, sourceCss) {
762
- if (!sourceCss || !hasWebpackTailwindSourceDirectives(sourceCss)) return false;
763
- const sourceMarkers = collectWebpackCssRuleIdentityMarkers(sourceCss);
764
- if (sourceMarkers.size === 0) return false;
765
- const rawMarkers = collectWebpackCssRuleIdentityMarkers(rawSource);
766
- for (const marker of sourceMarkers) if (!rawMarkers.has(marker)) return false;
767
- return true;
768
- }
769
- function createWebpackGeneratorCssSource(file, css) {
770
- if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
771
- return {
772
- file,
773
- base: node_path.default.dirname(file),
774
- css,
775
- dependencies: [file]
776
- };
1170
+ function isSameFileMeta(left, right) {
1171
+ return left?.contentHash === right?.contentHash && left?.mtimeMs === right?.mtimeMs && left?.size === right?.size;
777
1172
  }
778
- function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
779
- const matchedSources = [];
780
- const seen = /* @__PURE__ */ new Set();
781
- for (const source of sources) {
782
- const css = source.css;
783
- if (!css || seen.has(css)) continue;
784
- if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
785
- seen.add(css);
786
- if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
787
- css,
788
- file: source.file,
789
- processed: source.processed === true
1173
+ async function resolveScanFiles(roots, outDir) {
1174
+ const files = /* @__PURE__ */ new Set();
1175
+ await Promise.all(roots.map(async (root) => {
1176
+ const rootFiles = await require_hmr_timing.resolveSourceCandidateScanFiles({
1177
+ entries: root.entries,
1178
+ explicit: root.explicit,
1179
+ filter: require_hmr_timing.isSourceCandidateRequest,
1180
+ outDir,
1181
+ root: root.root
790
1182
  });
1183
+ for (const file of rootFiles) files.add(require_v4_engine.resolveSourceScanPath(file));
1184
+ }));
1185
+ return files;
1186
+ }
1187
+ async function syncChangedScanFiles(collector, cachedScan, scanFiles, changedFiles) {
1188
+ for (const file of cachedScan.files.keys()) {
1189
+ if (scanFiles.has(file)) continue;
1190
+ collector.remove(file);
1191
+ cachedScan.files.delete(file);
791
1192
  }
792
- const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
793
- const parts = matchedSources.sort((a, b) => {
794
- const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
795
- if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
796
- return a.file.localeCompare(b.file);
797
- }).map((source) => source.css);
798
- return parts.length > 0 ? {
799
- css: parts.join("\n"),
800
- processed: matchedSources.every((source) => source.processed)
801
- } : void 0;
1193
+ await Promise.all([...scanFiles].map(async (file) => {
1194
+ const nextSnapshot = await resolveScanFileSnapshot(file);
1195
+ if (!nextSnapshot) {
1196
+ collector.remove(file);
1197
+ cachedScan.files.delete(file);
1198
+ return;
1199
+ }
1200
+ const previousMeta = cachedScan.files.get(file);
1201
+ if (previousMeta && isSameFileMeta(previousMeta, nextSnapshot.meta) && !changedFiles.has(file)) return;
1202
+ await collector.sync(file, nextSnapshot.source);
1203
+ cachedScan.files.set(file, nextSnapshot.meta);
1204
+ }));
802
1205
  }
803
- function createWebpackGeneratorUserCssSourceAppend(...sources) {
804
- const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
805
- if (parts.length === 0) return;
806
- let css = "";
807
- const usedParts = [];
808
- for (const source of parts) {
809
- const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, source.css) : source.css;
810
- if (nextCss.trim().length === 0) continue;
811
- css = require_hmr_timing.createCssSourceOrderAppend(css, nextCss);
812
- usedParts.push(source);
1206
+ function createWebpackSourceCandidateScanCache() {
1207
+ const scans = /* @__PURE__ */ new Map();
1208
+ let lastHit = false;
1209
+ let lastSignatureHash;
1210
+ async function resolve({ changedFiles, collector, outDir, root, sourceScan, watchMode }) {
1211
+ const explicit = sourceScan?.explicit ?? false;
1212
+ const roots = collectWebpackSourceCandidateScanRoots(root, sourceScan?.entries, explicit);
1213
+ const nextSignatureHash = (0, _weapp_tailwindcss_shared_node.md5)(require_source_candidate_scan_signature.createSourceCandidateScanSignature({
1214
+ inlineCandidates: sourceScan?.inlineCandidates,
1215
+ outDir,
1216
+ roots,
1217
+ scanAllSources: !explicit
1218
+ }));
1219
+ const scanFiles = await resolveScanFiles(roots, outDir);
1220
+ const cachedScan = watchMode ? scans.get(nextSignatureHash) : void 0;
1221
+ if (cachedScan) {
1222
+ collector.restore(cachedScan.snapshot);
1223
+ collector.syncInline(sourceScan?.inlineCandidates);
1224
+ await syncChangedScanFiles(collector, cachedScan, scanFiles, normalizeChangedFiles(changedFiles));
1225
+ cachedScan.snapshot = compactSnapshot(collector.snapshot());
1226
+ lastHit = true;
1227
+ lastSignatureHash = nextSignatureHash;
1228
+ return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
1229
+ }
1230
+ collector.clearScan();
1231
+ collector.syncInline(sourceScan?.inlineCandidates);
1232
+ const files = /* @__PURE__ */ new Map();
1233
+ await Promise.all([...scanFiles].map(async (file) => {
1234
+ const nextSnapshot = await resolveScanFileSnapshot(file);
1235
+ if (!nextSnapshot) return;
1236
+ await collector.sync(file, nextSnapshot.source);
1237
+ files.set(file, nextSnapshot.meta);
1238
+ }));
1239
+ if (watchMode) {
1240
+ scans.set(nextSignatureHash, {
1241
+ files,
1242
+ snapshot: compactSnapshot(collector.snapshot())
1243
+ });
1244
+ trimScanCache(scans);
1245
+ } else scans.clear();
1246
+ lastHit = false;
1247
+ lastSignatureHash = nextSignatureHash;
1248
+ return createWebpackSourceCandidateCacheRecord(collector, sourceScan, nextSignatureHash);
1249
+ }
1250
+ function getMemoryStats() {
1251
+ const cachedScans = [...scans.values()];
1252
+ return {
1253
+ entries: cachedScans.reduce((count, scan) => count + (scan.snapshot.scanCandidatesById?.length ?? scan.snapshot.candidatesById.length), 0),
1254
+ files: cachedScans.reduce((count, scan) => count + scan.files.size, 0),
1255
+ lastHit,
1256
+ signatureHash: lastSignatureHash,
1257
+ snapshots: scans.size
1258
+ };
813
1259
  }
814
- if (css.trim().length === 0) return;
815
1260
  return {
816
- css,
817
- processed: usedParts.every((source) => source.processed)
1261
+ getMemoryStats,
1262
+ resolve
818
1263
  };
819
1264
  }
820
- function resolveWebpackMemoryDebugStats(context) {
821
- if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
822
- const memory = node_process.default.memoryUsage();
823
- const processCacheInstanceSize = context.cache.instance.size;
824
- const processCacheHashMapSize = context.cache.hashMap.size;
825
- return {
826
- phase: context.phase,
827
- process: {
828
- rssMb: toMb(memory.rss),
829
- heapTotalMb: toMb(memory.heapTotal),
830
- heapUsedMb: toMb(memory.heapUsed),
831
- externalMb: toMb(memory.external),
832
- arrayBuffersMb: toMb(memory.arrayBuffers)
833
- },
834
- assets: {
835
- active: context.activeAssetFiles,
836
- activeCss: context.activeCssFiles
837
- },
838
- processCache: {
839
- instance: processCacheInstanceSize,
840
- hashMap: processCacheHashMapSize,
841
- activeCacheKeys: context.activeProcessCacheKeys.size,
842
- activeHashKeys: context.activeProcessHashKeys.size,
843
- staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
844
- staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
845
- pruned: true,
846
- pruneSkipped: false
847
- },
848
- webpackCss: {
849
- handlerOptions: context.cssHandlerOptionsCache.size,
850
- userHandlerOptions: context.cssUserHandlerOptionsCache.size,
851
- maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
852
- },
853
- sourceCandidateScan: context.sourceCandidateScan,
854
- tailwind: { v4: require_v4_engine.getTailwindV4IncrementalGenerateCacheStats() }
855
- };
1265
+ //#endregion
1266
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.ts
1267
+ async function refreshWebpackSourceCandidates(options) {
1268
+ const root = options.compilerOptions.tailwindcssBasedir ?? node_process.default.cwd();
1269
+ let sourceScan;
1270
+ try {
1271
+ sourceScan = await require_tailwindcss.resolveViteSourceScanEntries(options.compilerOptions, options.runtimeState.tailwindRuntime, {
1272
+ root,
1273
+ outDir: options.outputDir
1274
+ });
1275
+ } catch (error) {
1276
+ options.debug("webpack source candidate scan skipped: %O", error);
1277
+ return;
1278
+ }
1279
+ if (!sourceScan || !sourceScan.explicit && !sourceScan.entries?.length && !sourceScan.inlineCandidates) return;
1280
+ return options.scanCache.resolve({
1281
+ changedFiles: options.watchChangedFiles,
1282
+ collector: require_hmr_timing.createSourceCandidateStore({ bareArbitraryValues: options.compilerOptions.arbitraryValues?.bareArbitraryValues }),
1283
+ outDir: options.outputDir,
1284
+ root,
1285
+ sourceScan,
1286
+ watchMode: options.watchMode
1287
+ });
856
1288
  }
1289
+ //#endregion
1290
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
857
1291
  function setupWebpackV5ProcessAssetsHook(options) {
858
1292
  const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isKnownWebpackProcessedCssAsset, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, getWatchChangedFiles, runtimeClassSetManager, getWebpackCssSources, getWebpackGeneratedCssSources, pruneWebpackCssSources, prepareWebpackCssSources, debug } = options;
859
1293
  const { Compilation, sources } = compiler.webpack;
@@ -875,7 +1309,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
875
1309
  const entries = Object.entries(assets);
876
1310
  if (entries.length === 0) return;
877
1311
  const groupedEntries = require_utils.getGroupedEntries(entries, compilerOptions);
878
- if (isWebGeneratorTarget && !groupedEntries.css?.length) return;
1312
+ if (isWebGeneratorTarget && groupedEntries.css.length === 0) return;
879
1313
  compilerOptions.onStart();
880
1314
  debug("start");
881
1315
  await runtimeState.readyPromise;
@@ -890,49 +1324,17 @@ function setupWebpackV5ProcessAssetsHook(options) {
890
1324
  });
891
1325
  const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
892
1326
  const outputDir = compilerOutputPath ? node_path.default.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? node_process.default.cwd();
893
- const jsAssets = /* @__PURE__ */ new Map();
894
- for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
895
- const absolute = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
896
- jsAssets.set(absolute, file);
897
- }
898
- const moduleGraphOptions = {
899
- resolve(specifier, importer) {
900
- return require_source_candidate_scan_signature.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
901
- },
902
- load: (id) => {
903
- const assetName = jsAssets.get(id);
904
- if (!assetName) return;
905
- const asset = compilation.getAsset(assetName);
906
- if (!asset) return;
907
- const source = asset.source.source();
908
- return typeof source === "string" ? source : source.toString();
909
- },
910
- filter(id) {
911
- return jsAssets.has(id);
912
- }
913
- };
914
- const applyLinkedResults = (linked) => {
915
- if (!linked) return;
916
- for (const [id, { code }] of Object.entries(linked)) {
917
- const assetName = jsAssets.get(id);
918
- if (!assetName) continue;
919
- const asset = compilation.getAsset(assetName);
920
- if (!asset) continue;
921
- const previousSource = asset.source.source();
922
- if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
923
- if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
924
- }
925
- };
926
- const watchMode = isWatchMode?.() === true;
927
- const cssAssetResources = createWebpackCssAssetResourceMap(compilation.chunks, compilation.chunkGraph, compilerOptions.cssMatcher, (resource, issuer) => {
928
- if (!isCssLikeModuleResource(resource, compilerOptions.cssMatcher, appType)) return;
929
- const normalized = stripResourceQuery(resource);
930
- if (!normalized) return;
931
- if (node_path.default.isAbsolute(normalized)) return node_path.default.resolve(normalized);
932
- const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
933
- const issuerContext = issuerResource && node_path.default.isAbsolute(issuerResource) ? node_path.default.dirname(issuerResource) : issuer?.context;
934
- return issuerContext ? node_path.default.resolve(issuerContext, normalized) : void 0;
1327
+ const { jsAssets, moduleGraphOptions } = createWebpackJsAssetModuleGraph({
1328
+ compilation,
1329
+ compilerOptions,
1330
+ entries,
1331
+ outputDir
935
1332
  });
1333
+ const watchMode = isWatchMode?.() === true;
1334
+ const cssAssetResources = createWebpackCssAssetResourceMap(compilation.chunks, compilation.chunkGraph, compilerOptions.cssMatcher, (resource, issuer) => resolveWebpackCssAssetModuleResource(resource, issuer, {
1335
+ appType,
1336
+ cssMatcher: compilerOptions.cssMatcher
1337
+ }));
936
1338
  const watchChangedFiles = new Set([...getWatchChangedFiles?.() ?? []].map((file) => node_path.default.resolve(file)));
937
1339
  const taskConcurrency = watchMode ? require_hmr_timing.resolveTaskConcurrency(1) : void 0;
938
1340
  const activeProcessCacheKeys = /* @__PURE__ */ new Set();
@@ -946,215 +1348,43 @@ function setupWebpackV5ProcessAssetsHook(options) {
946
1348
  for (const chunk of compilation.chunks) if (chunk.id) activeProcessHashKeys.add(chunk.id);
947
1349
  const cssSources = new Map([...getWebpackCssSources?.() ?? []].map(([file, source]) => [node_path.default.resolve(file), source]));
948
1350
  const generatedCssSources = new Map([...getWebpackGeneratedCssSources?.() ?? []].map(([file, source]) => [node_path.default.resolve(file), source]));
949
- const hasConfiguredTailwindV4SourceRoots = () => {
950
- const tailwindOptions = require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
951
- return (tailwindOptions?.v4?.cssEntries?.length ?? 0) > 0 || (tailwindOptions?.v4?.cssSources?.length ?? 0) > 0;
952
- };
953
- const configuredMainCssEntryFiles = (() => {
954
- return [...require_v4_engine.resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.v4?.cssEntries ?? []].filter((file) => typeof file === "string" && file.length > 0).map((file) => node_path.default.resolve(file));
955
- })();
956
- const inferredMainCssFiles = inferWebpackMainCssFiles(compilation.chunks, compilerOptions.cssMatcher, {
957
- mainSourceFiles: new Set(configuredMainCssEntryFiles),
958
- resourcesByAsset: cssAssetResources
1351
+ const { activeWebpackCssSourceFiles, configuredMainCssEntryFiles, getCssHandlerOptions, getCssUserHandlerOptions, hasConfiguredTailwindV4SourceRoots, isSameWebpackSourceScope, resolveWebpackCssSourceFile } = createWebpackCssSourceResolvers({
1352
+ activeWebpackAssetResourceFiles,
1353
+ appType,
1354
+ compilerOptions,
1355
+ compilation,
1356
+ cssAssetResources,
1357
+ cssHandlerOptionsCache,
1358
+ cssSources,
1359
+ cssUserHandlerOptionsCache,
1360
+ groupedCssEntriesLength: groupedEntries.css.length,
1361
+ singleCssAssetFile: groupedEntries.css[0]?.[0],
1362
+ isWebGeneratorTarget,
1363
+ outputDir,
1364
+ runtimeState
959
1365
  });
960
- const singleConfiguredCssAsset = isWebGeneratorTarget && configuredMainCssEntryFiles.length > 0 && (groupedEntries.css?.length ?? 0) === 1 ? groupedEntries.css?.[0]?.[0] : void 0;
961
- const isMainCssChunk = (file) => compilerOptions.mainCssChunkMatcher(file, appType) || inferredMainCssFiles.has(file) || file === singleConfiguredCssAsset;
962
- const activeWebpackCssSourceFiles = /* @__PURE__ */ new Set();
963
- const resolveConfiguredMainCssSourceFile = (file) => {
964
- if (!isMainCssChunk(file)) return;
965
- for (const sourceFile of configuredMainCssEntryFiles) if (cssSources.has(sourceFile)) {
966
- activeWebpackCssSourceFiles.add(sourceFile);
967
- return sourceFile;
968
- }
969
- };
970
- const resolveWebpackCssSourceFile = (file, rawSource) => {
971
- const assetResources = cssAssetResources.get(file);
972
- const activeAssetResource = resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAssetResourceFiles);
973
- if (cssSources.size === 0) {
974
- if (activeAssetResource) {
975
- activeWebpackCssSourceFiles.add(activeAssetResource);
976
- return activeAssetResource;
977
- }
978
- if (assetResources && assetResources.size > 0) return;
979
- return resolveConfiguredMainCssSourceFile(file);
980
- }
981
- const resourceMatches = [...assetResources ?? []].filter((sourceFile) => cssSources.has(sourceFile)).sort();
982
- if (resourceMatches.length === 1) {
983
- const sourceFile = resourceMatches[0];
984
- activeWebpackCssSourceFiles.add(sourceFile);
985
- return sourceFile;
986
- }
987
- const tailwindSourceMatches = resourceMatches.filter((sourceFile) => {
988
- const sourceCss = cssSources.get(sourceFile)?.css;
989
- return sourceCss && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss) || require_v4_engine.hasTailwindGeneratedCss(sourceCss) || require_v4_engine.hasTailwindGeneratedCssMarkers(sourceCss));
990
- });
991
- if (tailwindSourceMatches.length === 1) {
992
- const sourceFile = tailwindSourceMatches[0];
993
- activeWebpackCssSourceFiles.add(sourceFile);
994
- return sourceFile;
995
- }
996
- if (activeAssetResource) {
997
- activeWebpackCssSourceFiles.add(activeAssetResource);
998
- return activeAssetResource;
999
- }
1000
- if (rawSource) {
1001
- const representedTailwindSourceMatches = [...cssSources.entries()].filter(([, source]) => isWebpackCssSourceRepresentedInAsset(rawSource, source.css)).map(([sourceFile]) => ({
1002
- sourceFile,
1003
- score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
1004
- outputRoot: outputDir,
1005
- projectRoot: compilerOptions.tailwindcssBasedir,
1006
- cwd: compilerOptions.tailwindcssBasedir
1007
- })
1008
- })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
1009
- const bestScore = representedTailwindSourceMatches[0]?.score ?? 0;
1010
- const bestMatches = representedTailwindSourceMatches.filter((match) => match.score === bestScore);
1011
- if (bestMatches.length === 1) {
1012
- const sourceFile = bestMatches[0]?.sourceFile;
1013
- activeWebpackCssSourceFiles.add(sourceFile);
1014
- return sourceFile;
1015
- }
1016
- }
1017
- const pathMatches = [...cssSources.keys()].map((sourceFile) => ({
1018
- sourceFile,
1019
- score: require_hmr_timing.scoreTailwindV4CssSourceFileMatch(file, sourceFile, {
1020
- outputRoot: outputDir,
1021
- projectRoot: compilerOptions.tailwindcssBasedir,
1022
- cwd: compilerOptions.tailwindcssBasedir
1023
- })
1024
- })).filter((match) => match.score >= 1e3).sort((a, b) => b.score - a.score || a.sourceFile.localeCompare(b.sourceFile));
1025
- const bestPathScore = pathMatches[0]?.score ?? 0;
1026
- const bestPathMatches = pathMatches.filter((match) => match.score === bestPathScore);
1027
- if (bestPathMatches.length === 1) {
1028
- const sourceFile = bestPathMatches[0]?.sourceFile;
1029
- activeWebpackCssSourceFiles.add(sourceFile);
1030
- return sourceFile;
1031
- }
1032
- if (assetResources && assetResources.size > 0) return;
1033
- return resolveConfiguredMainCssSourceFile(file);
1034
- };
1035
- const isSameWebpackSourceScope = (outputFile, candidateSourceFile, currentSourceFile) => {
1036
- if (!currentSourceFile) return false;
1037
- if (node_path.default.resolve(candidateSourceFile) === node_path.default.resolve(currentSourceFile)) return true;
1038
- const candidateKey = node_path.default.resolve(candidateSourceFile);
1039
- return cssAssetResources.get(outputFile)?.has(candidateKey) === true;
1040
- };
1041
- const getCssHandlerOptions = (file, rawSource) => {
1042
- const majorVersion = runtimeState.tailwindRuntime.majorVersion;
1043
- const isMainChunk = isMainCssChunk(file);
1044
- const sourceFile = resolveWebpackCssSourceFile(file, rawSource);
1045
- const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
1046
- const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
1047
- const generatorCssSource = createWebpackGeneratorCssSource(sourceFile, generatorSourceCss);
1048
- const cacheKey = [
1049
- majorVersion ?? "unknown",
1050
- isMainChunk ? "1" : "0",
1051
- sourceFile ?? "asset",
1052
- sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
1053
- generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
1054
- file
1055
- ].join(":");
1056
- const cached = cssHandlerOptionsCache.get(cacheKey);
1057
- if (cached) return cached;
1058
- const created = {
1059
- isMainChunk,
1060
- postcssOptions: { options: { from: sourceFile ?? file } },
1061
- sourceOptions: {
1062
- outputRoot: outputDir,
1063
- ...generatorCssSource === void 0 ? {} : { cssSources: [generatorCssSource] },
1064
- ...generatorSourceCss === void 0 ? {} : { sourceCss: generatorSourceCss },
1065
- ...sourceFile === void 0 ? {} : { sourceFile }
1066
- },
1067
- ...majorVersion === void 0 ? {} : { majorVersion }
1068
- };
1069
- cssHandlerOptionsCache.set(cacheKey, created);
1070
- return created;
1071
- };
1072
- const getCssUserHandlerOptions = (file) => {
1073
- const majorVersion = runtimeState.tailwindRuntime.majorVersion;
1074
- const sourceFile = resolveWebpackCssSourceFile(file);
1075
- const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
1076
- const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
1077
- const cacheKey = [
1078
- majorVersion ?? "unknown",
1079
- sourceFile ?? "asset",
1080
- sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
1081
- generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss),
1082
- file
1083
- ].join(":");
1084
- const cached = cssUserHandlerOptionsCache.get(cacheKey);
1085
- if (cached) return cached;
1086
- const created = {
1087
- ...getCssHandlerOptions(file),
1088
- isMainChunk: false
1089
- };
1090
- cssUserHandlerOptionsCache.set(cacheKey, created);
1091
- return created;
1092
- };
1093
- const refreshWebpackSourceCandidates = async () => {
1094
- const root = compilerOptions.tailwindcssBasedir ?? node_process.default.cwd();
1095
- let sourceScan;
1096
- try {
1097
- sourceScan = await require_tailwindcss.resolveViteSourceScanEntries(compilerOptions, runtimeState.tailwindRuntime, {
1098
- root,
1099
- outDir: outputDir
1100
- });
1101
- } catch (error) {
1102
- debug("webpack source candidate scan skipped: %O", error);
1103
- return;
1104
- }
1105
- return webpackSourceCandidateScanCache.resolve({
1106
- changedFiles: watchChangedFiles,
1107
- collector: require_hmr_timing.createSourceCandidateStore({ bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues }),
1108
- outDir: outputDir,
1109
- root,
1110
- sourceScan,
1111
- watchMode
1112
- });
1113
- };
1114
- const finalizeCssAssetSource = (source, options = {}) => {
1115
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
1116
- if (isWebGeneratorTarget) {
1117
- if (options.generatedCss === true) return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source))));
1118
- return stripTrailingLineWhitespace(require_hmr_timing.stripUnmatchedTailwindSourceMediaCloseFragments(require_hmr_timing.stripTailwindSourceMediaFragments(require_hmr_timing.removeTailwindV4GeneratorAtRules(require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
1119
- }
1120
- let finalized = require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
1121
- if (isWebGeneratorTarget || options.generatedCss !== true) return isWebGeneratorTarget ? finalized : (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
1122
- try {
1123
- finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: true });
1124
- } catch {
1125
- finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
1126
- cssPreflight: !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(finalized) ? compilerOptions.cssPreflight : void 0,
1127
- isTailwindcssV4: true,
1128
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
1129
- });
1130
- }
1131
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_hmr_timing.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
1132
- };
1133
- const finalizeMiniProgramUserCssAssetSource = (source, options = {}) => {
1134
- const styleOptions = require_context.resolveStyleOptionsFromContext(compilerOptions);
1135
- if (isWebGeneratorTarget) return source;
1136
- return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_hmr_timing.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
1137
- cssPreflight: options.cssPreflight !== false && !require_hmr_timing.hasMiniProgramTailwindV4PreflightReset(source) ? compilerOptions.cssPreflight : void 0,
1138
- isTailwindcssV4: true,
1139
- tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
1140
- })));
1141
- };
1142
- const webpackSourceCandidates = !isWebGeneratorTarget && (groupedEntries.css?.length ?? 0) > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates() : void 0;
1366
+ const finalizeCssAssetSource = (source, options = {}) => finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options);
1367
+ const webpackSourceCandidates = !isWebGeneratorTarget && groupedEntries.css.length > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates({
1368
+ compilerOptions,
1369
+ debug,
1370
+ outputDir,
1371
+ runtimeState,
1372
+ scanCache: webpackSourceCandidateScanCache,
1373
+ watchChangedFiles,
1374
+ watchMode
1375
+ }) : void 0;
1143
1376
  const webpackSourceCandidateValueSignature = webpackSourceCandidates ? require_source_candidate_scan_signature.createCandidateSignature(webpackSourceCandidates.getSourceCandidatesForEntries(void 0)) : "source-candidates:0";
1144
- const cssSourceTraceTokenSources = require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) && webpackSourceCandidates ? require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions) : void 0;
1377
+ const cssSourceTraceTokenSources = createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates);
1145
1378
  const cssSourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
1146
1379
  const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
1147
1380
  opts: compilerOptions,
1148
1381
  tokenSources: cssSourceTraceTokenSources
1149
1382
  });
1150
- const shouldInjectCssTracePreflight = (cssHandlerOptions) => {
1151
- return compilerOptions.appType !== "mpx" || cssHandlerOptions.isMainChunk !== false;
1152
- };
1153
- const finalizeTracedCss = (css, cssHandlerOptions) => {
1154
- const traced = annotateCss(css);
1155
- if (isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(compilerOptions)) return traced;
1156
- return finalizeMiniProgramUserCssAssetSource(traced, { cssPreflight: shouldInjectCssTracePreflight(cssHandlerOptions) });
1157
- };
1383
+ const finalizeTracedCss = (css, cssHandlerOptions) => finalizeTracedWebpackCssAsset(css, cssHandlerOptions, {
1384
+ annotateCss,
1385
+ compilerOptions,
1386
+ isWebGeneratorTarget
1387
+ });
1158
1388
  const hasRuntimeTransformAssets = Boolean(!isWebGeneratorTarget && ((groupedEntries.html?.length ?? 0) > 0 || (groupedEntries.js?.length ?? 0) > 0));
1159
1389
  const forceRuntimeRefresh = getRuntimeRefreshRequirement();
1160
1390
  debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.tailwindRuntime.majorVersion ?? "unknown");
@@ -1162,15 +1392,11 @@ function setupWebpackV5ProcessAssetsHook(options) {
1162
1392
  let runtimeAffectingSourceHash = "runtime-affecting:0";
1163
1393
  if (isWebGeneratorTarget && !hasRuntimeTransformAssets && !forceRuntimeRefresh) runtimeSet = getRuntimeClassSetSync(runtimeState.tailwindRuntime);
1164
1394
  else if (watchMode && !forceRuntimeRefresh) {
1165
- const shouldSkipInitialRuntimeBundleScan = isWebGeneratorTarget && !webpackWatchRuntimeScanInitialized;
1166
1395
  const baseRuntimeSet = getRuntimeClassSetSync(runtimeState.tailwindRuntime);
1167
1396
  const snapshot = buildWebpackBundleSnapshot(assets, compilerOptions, bundleBuildState, compilation);
1168
- if (!webpackWatchRuntimeScanInitialized && !shouldSkipInitialRuntimeBundleScan) {
1169
- for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
1170
- }
1171
- runtimeAffectingSourceHash = compilerOptions.cache.computeHash([...(groupedEntries.html ?? []).map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`), ...(groupedEntries.js ?? []).map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`)].sort().join("\n\n"));
1172
- if (shouldSkipInitialRuntimeBundleScan) runtimeSet = baseRuntimeSet;
1173
- else try {
1397
+ if (!webpackWatchRuntimeScanInitialized) for (const entry of snapshot.entries) snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
1398
+ runtimeAffectingSourceHash = compilerOptions.cache.computeHash([...groupedEntries.html.map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`), ...groupedEntries.js.map(([file, source]) => `${file}:${compilerOptions.cache.computeHash(source.source().toString())}`)].sort().join("\n\n"));
1399
+ try {
1174
1400
  runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
1175
1401
  baseClassSet: baseRuntimeSet,
1176
1402
  skipInitialFullScanWithBase: false
@@ -1199,49 +1425,38 @@ function setupWebpackV5ProcessAssetsHook(options) {
1199
1425
  consumeRuntimeRefreshRequirement();
1200
1426
  const webpackSourceCandidateSet = webpackSourceCandidates?.getSourceCandidatesForEntries(void 0);
1201
1427
  const generatorRuntimeSet = new Set(runtimeSet);
1202
- if (webpackSourceCandidateSet?.size) {
1203
- for (const candidate of webpackSourceCandidateSet) if (isRuntimeTransformCandidate(candidate)) generatorRuntimeSet.add(candidate);
1204
- }
1428
+ addRuntimeTransformCandidates(generatorRuntimeSet, webpackSourceCandidateSet);
1205
1429
  const transformRuntimeSet = new Set(runtimeSet);
1206
- if (hasRuntimeTransformAssets && Array.isArray(groupedEntries.css)) for (const [, originalSource] of groupedEntries.css) for (const candidate of collectGeneratedCssRuntimeCandidates(originalSource.source().toString())) transformRuntimeSet.add(candidate);
1430
+ if (hasRuntimeTransformAssets) for (const [, originalSource] of groupedEntries.css) for (const candidate of collectGeneratedCssRuntimeCandidates(originalSource.source().toString())) transformRuntimeSet.add(candidate);
1207
1431
  const transformedJsRuntimeCandidates = /* @__PURE__ */ new Set();
1208
1432
  let currentJsRuntimeCandidates;
1209
1433
  let currentJsRuntimeTokenSignature;
1434
+ const getWebpackAssetSource = (file) => {
1435
+ return compilation.getAsset(file)?.source;
1436
+ };
1210
1437
  const getCurrentJsRuntimeCandidates = () => {
1211
- if (isWebGeneratorTarget) return;
1212
1438
  if (currentJsRuntimeCandidates) return currentJsRuntimeCandidates;
1213
- currentJsRuntimeCandidates = /* @__PURE__ */ new Set();
1214
- for (const file of jsAssets.values()) {
1215
- const asset = compilation.getAsset(file);
1216
- if (!asset) continue;
1217
- const value = asset.source.source();
1218
- const source = typeof value === "string" ? value : value.toString();
1219
- for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, escapeFragments)) if (isRuntimeTransformCandidate(candidate)) currentJsRuntimeCandidates.add(candidate);
1220
- }
1439
+ currentJsRuntimeCandidates = collectWebpackJsRuntimeCandidatesFromAssets({
1440
+ escapeFragments,
1441
+ getAssetSource: getWebpackAssetSource,
1442
+ isWebGeneratorTarget,
1443
+ jsAssets: jsAssets.values()
1444
+ });
1221
1445
  return currentJsRuntimeCandidates;
1222
1446
  };
1223
1447
  const getCurrentJsRuntimeTokenSignature = () => {
1224
1448
  if (currentJsRuntimeTokenSignature !== void 0) return currentJsRuntimeTokenSignature;
1225
- if (isWebGeneratorTarget) {
1226
- currentJsRuntimeTokenSignature = "";
1227
- return currentJsRuntimeTokenSignature;
1228
- }
1229
- const tokens = [];
1230
- for (const file of jsAssets.values()) {
1231
- const asset = compilation.getAsset(file);
1232
- if (!asset) continue;
1233
- const value = asset.source.source();
1234
- const source = typeof value === "string" ? value : value.toString();
1235
- tokens.push(...collectRuntimeTokenSignatureParts(source));
1236
- }
1237
- currentJsRuntimeTokenSignature = tokens.sort().join("\n");
1449
+ currentJsRuntimeTokenSignature = collectWebpackJsRuntimeTokenSignature({
1450
+ getAssetSource: getWebpackAssetSource,
1451
+ isWebGeneratorTarget,
1452
+ jsAssets: jsAssets.values()
1453
+ });
1238
1454
  return currentJsRuntimeTokenSignature;
1239
1455
  };
1240
1456
  const rememberTransformedRuntimeCandidates = (source) => {
1241
1457
  currentJsRuntimeCandidates = void 0;
1242
1458
  currentJsRuntimeTokenSignature = void 0;
1243
- const value = typeof source === "string" ? source : source.source();
1244
- const code = typeof value === "string" ? value : value.toString();
1459
+ const code = stringifyWebpackSourceLike(source);
1245
1460
  for (const candidate of require_hmr_timing.collectStrictEscapedRuntimeCandidates(code, _weapp_core_escape.MappingChars2String, escapeFragments)) if (isRuntimeTransformCandidate(candidate)) transformedJsRuntimeCandidates.add(candidate);
1246
1461
  };
1247
1462
  const createRuntimeSetHash = (generatorRuntimeSet) => compilerOptions.cache.computeHash([
@@ -1254,11 +1469,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
1254
1469
  const getGeneratorRuntimeSet = () => {
1255
1470
  const currentJsCandidates = getCurrentJsRuntimeCandidates();
1256
1471
  if (transformedJsRuntimeCandidates.size === 0 && (!currentJsCandidates || currentJsCandidates.size === 0)) return generatorRuntimeSet;
1257
- return new Set([
1258
- ...generatorRuntimeSet,
1259
- ...currentJsCandidates ?? [],
1260
- ...transformedJsRuntimeCandidates
1261
- ]);
1472
+ const nextRuntimeSet = new Set(generatorRuntimeSet);
1473
+ for (const candidate of currentJsCandidates) nextRuntimeSet.add(candidate);
1474
+ for (const candidate of transformedJsRuntimeCandidates) nextRuntimeSet.add(candidate);
1475
+ return nextRuntimeSet;
1262
1476
  };
1263
1477
  const defaultTemplateHandlerOptions = { runtimeSet: transformRuntimeSet };
1264
1478
  debug("get runtimeSet, class count: %d, transform class count: %d", runtimeSet.size, transformRuntimeSet.size);
@@ -1318,21 +1532,15 @@ function setupWebpackV5ProcessAssetsHook(options) {
1318
1532
  const hashKey = `${file}:asset`;
1319
1533
  rememberProcessCacheKey(cacheKey, hashKey);
1320
1534
  const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outputDir);
1321
- let initialRawSource;
1322
- const readInitialRawSource = () => {
1323
- if (initialRawSource === void 0) {
1324
- const initialSource = asset.source.source();
1325
- initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
1326
- }
1327
- return initialRawSource;
1328
- };
1535
+ const initialSource = asset.source.source();
1536
+ const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
1329
1537
  const chunkHash = assetHashByChunk.get(file);
1330
1538
  await enqueueJsTask(async () => {
1331
1539
  await require_hmr_timing.processCachedTask({
1332
1540
  cache: compilerOptions.cache,
1333
1541
  cacheKey,
1334
1542
  hashKey,
1335
- rawSource: chunkHash === void 0 ? readInitialRawSource() : void 0,
1543
+ rawSource: chunkHash === void 0 ? initialRawSource : void 0,
1336
1544
  hash: chunkHash,
1337
1545
  applyResult(source, { cacheHit }) {
1338
1546
  if (updateAssetIfChanged(file, source, {
@@ -1345,7 +1553,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1345
1553
  },
1346
1554
  transform: async () => {
1347
1555
  const currentSourceValue = compilation.getAsset(file)?.source.source();
1348
- const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
1556
+ const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
1349
1557
  const handlerOptions = {
1350
1558
  tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
1351
1559
  generateMap: false,
@@ -1360,13 +1568,20 @@ function setupWebpackV5ProcessAssetsHook(options) {
1360
1568
  const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
1361
1569
  const source = new ConcatSource(code);
1362
1570
  debug("js handle: %s", file);
1363
- applyLinkedResults(linked);
1571
+ applyWebpackLinkedJsResults({
1572
+ ConcatSource,
1573
+ compilation,
1574
+ compilerOptions,
1575
+ debug,
1576
+ jsAssets,
1577
+ linked
1578
+ });
1364
1579
  return { result: source };
1365
1580
  }
1366
1581
  });
1367
1582
  });
1368
1583
  }
1369
- if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
1584
+ for (const element of groupedEntries.css) {
1370
1585
  const [file, originalSource] = element;
1371
1586
  let rawSource;
1372
1587
  const readRawSource = () => {
@@ -1381,7 +1596,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
1381
1596
  const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
1382
1597
  const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
1383
1598
  const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(node_path.default.resolve(processedSourceFile)) : void 0;
1384
- const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, chunkHash === void 0 ? void 0 : "webpack-css-asset:chunk", `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`) ?? "hash:0"}`;
1599
+ 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";
1600
+ const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
1385
1601
  let currentProcessedRawSource;
1386
1602
  let hasGeneratedCssMarker = false;
1387
1603
  let hasTailwindGeneratedAssetCss = false;
@@ -1389,8 +1605,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
1389
1605
  currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
1390
1606
  return currentProcessedRawSource;
1391
1607
  };
1392
- const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
1393
1608
  const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
1609
+ const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
1394
1610
  if (cachedSkipProcessedCssAsset !== void 0) {
1395
1611
  hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
1396
1612
  hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
@@ -1399,7 +1615,11 @@ function setupWebpackV5ProcessAssetsHook(options) {
1399
1615
  hasGeneratedCssMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(source);
1400
1616
  hasTailwindGeneratedAssetCss = require_v4_engine.hasTailwindGeneratedCss(source) || require_v4_engine.hasTailwindGeneratedCssMarkers(source);
1401
1617
  }
1402
- const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker;
1618
+ const hasProcessedAssetTailwindDirectives = () => {
1619
+ const source = readCurrentProcessedRawSource();
1620
+ return require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source);
1621
+ };
1622
+ const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
1403
1623
  const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
1404
1624
  ...source,
1405
1625
  file: sourceFile
@@ -1408,17 +1628,17 @@ function setupWebpackV5ProcessAssetsHook(options) {
1408
1628
  const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1409
1629
  const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
1410
1630
  const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
1411
- if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset);
1631
+ if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
1412
1632
  if (shouldSkipProcessedCssAsset) {
1413
1633
  const hashKey = `${file}:asset`;
1414
- const sourceHash = chunkHash === void 0 ? compilerOptions.cache.computeHash(readCurrentProcessedRawSource()) : "webpack-css-asset:chunk";
1634
+ const sourceHash = processedAssetSourceHash;
1415
1635
  rememberProcessCacheKey(file, hashKey);
1416
1636
  await enqueueTask(async () => {
1417
1637
  await require_hmr_timing.processCachedTask({
1418
1638
  cache: compilerOptions.cache,
1419
1639
  cacheKey: file,
1420
1640
  hashKey,
1421
- rawSource: chunkHash === void 0 ? readCurrentProcessedRawSource() : void 0,
1641
+ rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
1422
1642
  hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
1423
1643
  applyResult(source, { cacheHit }) {
1424
1644
  updateAssetIfChanged(file, source, {
@@ -1502,13 +1722,22 @@ function setupWebpackV5ProcessAssetsHook(options) {
1502
1722
  const loaderGeneratedCss = sourceFile && !isWebGeneratorTarget ? generatedCssSources.get(node_path.default.resolve(sourceFile)) : void 0;
1503
1723
  const sourceCss = sourceFile ? cssSources.get(node_path.default.resolve(sourceFile))?.css : void 0;
1504
1724
  const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
1505
- if (loaderGeneratedCss && !shouldRegenerateExplicitTailwindV4CssSource) {
1725
+ if (loaderGeneratedCss && (!shouldRegenerateExplicitTailwindV4CssSource || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(currentRawSource))) {
1506
1726
  for (const className of loaderGeneratedCss.classSet) {
1507
1727
  generatorRuntimeSet.add(className);
1508
1728
  transformRuntimeSet.add(className);
1509
1729
  }
1510
1730
  for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
1511
- const css = finalizeTracedCss(finalizeCssAssetSource(loaderGeneratedCss.css, { generatedCss: true }), cssHandlerOptions);
1731
+ const currentRawSourceWithoutBundlerMarkers = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentRawSource);
1732
+ const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
1733
+ const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? require_hmr_timing.removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
1734
+ const css = finalizeTracedCss(finalizeCssAssetSource(currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
1735
+ css: currentAssetHasProcessedUrl ? require_hmr_timing.removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(currentAssetUserCss, loaderGeneratedCss.css),
1736
+ processed: true
1737
+ }, {
1738
+ css: currentAssetUserCss,
1739
+ processed: true
1740
+ }).css, { generatedCss: true }), cssHandlerOptions);
1512
1741
  debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
1513
1742
  return { result: new ConcatSource(css) };
1514
1743
  }
@@ -1519,18 +1748,25 @@ function setupWebpackV5ProcessAssetsHook(options) {
1519
1748
  })), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
1520
1749
  const currentAssetLooksGenerated = require_v4_engine.hasTailwindGeneratedCss(currentRawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(currentRawSource);
1521
1750
  const currentAssetHasBundlerGeneratedMarker = require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(currentRawSource);
1522
- const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker;
1751
+ const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
1752
+ const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
1753
+ const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
1523
1754
  const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (require_v4_engine.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(sourceCss));
1524
- const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && hasAdditionalWebpackAssetUserCssMarkers(currentRawSource, generatorRawSource);
1525
- const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
1526
- const shouldAppendCurrentAssetUserCss = !currentAssetHasBundlerGeneratedMarker && !shouldPreserveGeneratedWebAssetUserCss && (!sourceCssProcessed || registeredUserRawSource === void 0 || currentAssetHasUserCss) && !(sourceCssProcessed && currentAssetLooksGenerated && !currentAssetHasUserCss);
1527
- const userRawSource = createWebpackGeneratorUserCssSourceAppend(sourceCssProcessed && shouldAppendCurrentAssetUserCss ? {
1528
- css: currentRawSource,
1529
- processed: true
1530
- } : shouldAppendCurrentAssetUserCss && currentAssetHasUserCss ? {
1531
- css: currentRawSource,
1532
- processed: currentAssetLooksGenerated
1533
- } : void 0, registeredUserRawSource);
1755
+ const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
1756
+ const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
1757
+ currentAssetHasUserCss,
1758
+ currentAssetLooksGenerated,
1759
+ currentAssetUserCssSource,
1760
+ shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
1761
+ currentAssetHasBundlerGeneratedMarker,
1762
+ currentAssetHasUserCss,
1763
+ currentAssetLooksGenerated,
1764
+ registeredUserRawSource,
1765
+ shouldPreserveGeneratedWebAssetUserCss,
1766
+ sourceCssProcessed
1767
+ }),
1768
+ sourceCssProcessed
1769
+ }), registeredUserRawSource);
1534
1770
  if (require_hmr_timing.isPureLocalCssImportWrapper(currentRawSource)) return { result: new ConcatSource(require_v4_engine.removeTailwindSourceDirectives(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
1535
1771
  const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
1536
1772
  const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (require_v4_engine.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
@@ -1551,7 +1787,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1551
1787
  const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
1552
1788
  ...cssHandlerOptions,
1553
1789
  sourceOptions: {
1554
- ...cssHandlerOptions.sourceOptions ?? {},
1790
+ ...cssHandlerOptions.sourceOptions,
1555
1791
  cssSources: generatorCssSources
1556
1792
  }
1557
1793
  };
@@ -1580,11 +1816,21 @@ function setupWebpackV5ProcessAssetsHook(options) {
1580
1816
  outputFile: file
1581
1817
  });
1582
1818
  } catch (error) {
1583
- if (!(!require_v4_engine.hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) && !require_v4_engine.hasTailwindApplyDirective(generatorRawSource) && !hasExplicitTailwindV4SourceCss && configuredMainCssEntryFiles.length === 0)) throw error;
1819
+ if (!shouldFallbackToWebpackUserCssOnGeneratorError({
1820
+ configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
1821
+ generatorRawSource,
1822
+ hasExplicitTailwindV4SourceCss
1823
+ })) throw error;
1584
1824
  debug("css generator skipped for plain webpack css asset: %s %O", file, error);
1585
1825
  generated = void 0;
1586
1826
  }
1587
- const source = new ConcatSource(finalizeTracedCss(generated ? finalizeCssAssetSource(generated.css, { generatedCss: true }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false }), cssHandlerOptions));
1827
+ const source = new ConcatSource(finalizeTracedCss(generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
1828
+ css: generated.css,
1829
+ processed: true
1830
+ }, {
1831
+ css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
1832
+ processed: true
1833
+ })?.css ?? generated.css : generated.css, { generatedCss: true }) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false }), cssHandlerOptions));
1588
1834
  if (generated) {
1589
1835
  for (const className of generated.classSet) generatorRuntimeSet.add(className);
1590
1836
  debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
@@ -1608,7 +1854,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
1608
1854
  cacheKeys: activeProcessCacheKeys,
1609
1855
  hashKeys: activeProcessHashKeys
1610
1856
  });
1611
- const activeCssFiles = new Set(groupedEntries.css?.map(([file]) => file) ?? []);
1857
+ const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
1612
1858
  pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
1613
1859
  if (activeCssFiles.size > 0) pruneWebpackCssSources?.(new Set([
1614
1860
  ...registeredWebpackCssSourceFiles,
@@ -1900,8 +2146,14 @@ var WeappTailwindcss = class {
1900
2146
  if (typeof runtimeState.tailwindRuntime.collectContentTokens !== "function") return;
1901
2147
  try {
1902
2148
  const report = await runtimeState.tailwindRuntime.collectContentTokens();
1903
- for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
1904
- for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
2149
+ for (const entry of report.entries ?? []) {
2150
+ const file = typeof entry === "object" && entry !== null && "file" in entry ? entry.file : void 0;
2151
+ if (typeof file === "string") runtimeWatchDependencyFiles.add(file);
2152
+ }
2153
+ for (const source of report.sources ?? []) {
2154
+ const base = typeof source === "object" && source !== null && "base" in source ? source.base : void 0;
2155
+ if (typeof base === "string") runtimeWatchDependencyContexts.add(base);
2156
+ }
1905
2157
  } catch (error) {
1906
2158
  debug("collect runtime watch dependencies failed: %O", error);
1907
2159
  }