weapp-tailwindcss 5.2.6 → 5.2.8

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 (65) hide show
  1. package/dist/bundlers/shared/final-css-cleanup.d.ts +2 -0
  2. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
  3. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +8 -0
  4. package/dist/bundlers/vite/hot-css-modules.d.ts +5 -3
  5. package/dist/bundlers/vite/module-identity.d.ts +9 -0
  6. package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +0 -1
  7. package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +1 -0
  8. package/dist/bundlers/vite/processed-css-assets/scoped-tailwind-noise.d.ts +4 -0
  9. package/dist/bundlers/vite/serve-css-generation.d.ts +1 -0
  10. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +2 -1
  11. package/dist/bundlers/vite/shared/framework-hmr-candidate-state.d.ts +1 -0
  12. package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +2 -0
  13. package/dist/bundlers/vite/shared/framework-strategy.d.ts +4 -0
  14. package/dist/cli.js +1 -0
  15. package/dist/{context-YAvTyPV2.js → context-BMkbwnH8.js} +10 -23
  16. package/dist/{context-OqD_eBxQ.cjs → context-CByXWyhQ.cjs} +179 -25
  17. package/dist/core.cjs +1 -1
  18. package/dist/core.js +1 -1
  19. package/dist/{generator-BE34PYSC.cjs → generator-B0dCFlP1.cjs} +10 -0
  20. package/dist/{generator-DYeAa2-5.js → generator-BLpOsd5O.js} +10 -0
  21. package/dist/generator.cjs +1 -1
  22. package/dist/generator.js +1 -1
  23. package/dist/{gulp-DCItlfoq.js → gulp-BWhCahA2.js} +7 -7
  24. package/dist/{gulp-CPIE1yPk.cjs → gulp-BdoorWb5.cjs} +10 -10
  25. package/dist/gulp.cjs +1 -1
  26. package/dist/gulp.js +1 -1
  27. package/dist/{hmr-timing-BevXxu6p.js → hmr-timing-CJocHeZr.js} +122 -16
  28. package/dist/{hmr-timing-Chyd_Yfw.cjs → hmr-timing-DiYnyg_W.cjs} +3 -3
  29. package/dist/index.cjs +4 -4
  30. package/dist/index.js +4 -4
  31. package/dist/{options-hVsoTfwL.cjs → options-zpZez7qe.cjs} +1 -1
  32. package/dist/{pipeline-helpers-Cwv-X4Rj.cjs → pipeline-helpers-CsNLoEX1.cjs} +4 -4
  33. package/dist/postcss.cjs +1 -1
  34. package/dist/postcss.js +1 -1
  35. package/dist/presets.cjs +2 -2
  36. package/dist/presets.js +1 -1
  37. package/dist/rspack.cjs +1 -1
  38. package/dist/rspack.js +1 -1
  39. package/dist/{source-candidate-scan-signature-DG5mQZ8o.cjs → source-candidate-scan-signature-D9FXTD9a.cjs} +3 -3
  40. package/dist/{source-candidate-scan-signature-DLFqYads.js → source-candidate-scan-signature-of-TmeOs.js} +3 -3
  41. package/dist/{style-options-B_ppaVIg.cjs → style-options-COpQc8fr.cjs} +2 -2
  42. package/dist/{tailwindcss-CTpCc_nd.js → tailwindcss-2zdmASlM.js} +1 -1
  43. package/dist/{tailwindcss-DcpiKvmJ.cjs → tailwindcss-LtnGCxF0.cjs} +2 -2
  44. package/dist/{transform-BbaPIji9.js → transform-DVGsr8cV.js} +24 -7
  45. package/dist/{transform-BUEyOCT7.cjs → transform-DzVJW6Dp.cjs} +24 -7
  46. package/dist/uni-app-x/component-local-style.d.ts +1 -0
  47. package/dist/uni-app-x/vite/author-apply.d.ts +1 -0
  48. package/dist/uni-app-x/vite/harmony-apply.d.ts +4 -1
  49. package/dist/uni-app-x/vite/native-hmr.d.ts +2 -0
  50. package/dist/uni-app-x/vite/plugin-options.d.ts +27 -0
  51. package/dist/uni-app-x/vite/style-request.d.ts +3 -0
  52. package/dist/uni-app-x/vite.d.ts +3 -24
  53. package/dist/{v4-generation-core-Dtmu8Yax.cjs → v4-generation-core-BjHT6qGC.cjs} +132 -14
  54. package/dist/{vite-Bk1YU9L0.js → vite-BJJqWc_F.js} +567 -292
  55. package/dist/{vite-DmN_Y8Uk.cjs → vite-V86H6PZa.cjs} +570 -295
  56. package/dist/vite.cjs +1 -1
  57. package/dist/vite.js +1 -1
  58. package/dist/weapp-tw-css-generation-loader.cjs +1 -1
  59. package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
  60. package/dist/{webpack-DtkSnYyR.js → webpack-CkeFhPY2.js} +7 -7
  61. package/dist/{webpack-DvmrFist.cjs → webpack-CzQrloDg.cjs} +9 -9
  62. package/dist/webpack.cjs +1 -1
  63. package/dist/webpack.js +1 -1
  64. package/package.json +4 -4
  65. package/dist/bundlers/vite/processed-css-assets/empty-at-rule.d.ts +0 -1
@@ -1,16 +1,16 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs");
2
2
  const require_framework = require("./framework.cjs");
3
- const require_generator = require("./generator-BE34PYSC.cjs");
3
+ const require_generator = require("./generator-B0dCFlP1.cjs");
4
4
  const require_object = require("./object-C_Vr6_S5.cjs");
5
- const require_options = require("./options-hVsoTfwL.cjs");
5
+ const require_options = require("./options-zpZez7qe.cjs");
6
6
  require("./utils-CuKLf1Zv.cjs");
7
- const require_v4_generation_core = require("./v4-generation-core-Dtmu8Yax.cjs");
7
+ const require_v4_generation_core = require("./v4-generation-core-BjHT6qGC.cjs");
8
8
  const require_wxml = require("./wxml-DSMNuUaP.cjs");
9
- const require_hmr_timing = require("./hmr-timing-Chyd_Yfw.cjs");
10
- const require_context = require("./context-OqD_eBxQ.cjs");
11
- const require_tailwindcss = require("./tailwindcss-DcpiKvmJ.cjs");
12
- const require_style_options = require("./style-options-B_ppaVIg.cjs");
13
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-DG5mQZ8o.cjs");
9
+ const require_hmr_timing = require("./hmr-timing-DiYnyg_W.cjs");
10
+ const require_context = require("./context-CByXWyhQ.cjs");
11
+ const require_tailwindcss = require("./tailwindcss-LtnGCxF0.cjs");
12
+ const require_style_options = require("./style-options-COpQc8fr.cjs");
13
+ const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-D9FXTD9a.cjs");
14
14
  require("./logger-TlKT3xmR.cjs");
15
15
  const require_css_imports = require("./css-imports-DfNC3e6a.cjs");
16
16
  let node_fs = require("node:fs");
@@ -27,6 +27,7 @@ let micromatch = require("micromatch");
27
27
  micromatch = require_rolldown_runtime.__toESM(micromatch, 1);
28
28
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
29
29
  let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
30
+ let node_url = require("node:url");
30
31
  let node_buffer = require("node:buffer");
31
32
  let node_async_hooks = require("node:async_hooks");
32
33
  let comment_json = require("comment-json");
@@ -408,6 +409,7 @@ function resolveReferencePaths(styleSource, sourceId) {
408
409
  return styleSource;
409
410
  }
410
411
  const cleanSourceId = sourceId.replace(/\?.*$/, "");
412
+ const pathApi = /^[a-z]:[\\/]/i.test(cleanSourceId) ? node_path.default.win32 : node_path.default;
411
413
  root.walkAtRules("reference", (rule) => {
412
414
  const quote = rule.params[0];
413
415
  if (quote !== "\"" && quote !== "'") return;
@@ -415,7 +417,7 @@ function resolveReferencePaths(styleSource, sourceId) {
415
417
  if (closingQuoteIndex <= 1) return;
416
418
  const referencePath = rule.params.slice(1, closingQuoteIndex);
417
419
  if (!referencePath.startsWith(".")) return;
418
- rule.params = `${quote}${node_path.default.resolve(node_path.default.dirname(cleanSourceId), referencePath)}${quote}${rule.params.slice(closingQuoteIndex + 1)}`;
420
+ rule.params = `${quote}${pathApi.resolve(pathApi.dirname(cleanSourceId), referencePath).replaceAll("\\", "/")}${quote}${rule.params.slice(closingQuoteIndex + 1)}`;
419
421
  });
420
422
  return root.toString();
421
423
  }
@@ -1340,86 +1342,6 @@ const mix = (del = delimiter) => {
1340
1342
  const posix = /* @__PURE__ */ mix(":");
1341
1343
  const win32 = /* @__PURE__ */ mix(";");
1342
1344
  //#endregion
1343
- //#region src/bundlers/vite/processed-css-assets/empty-at-rule.ts
1344
- function isAtRuleNameCharacter(code) {
1345
- return code === 45 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
1346
- }
1347
- function isCssWhitespace(code) {
1348
- return code === 9 || code === 10 || code === 12 || code === 13 || code === 32;
1349
- }
1350
- function findAtRuleBlockStart(css, start) {
1351
- let parenthesisDepth = 0;
1352
- let quote = 0;
1353
- let squareBracketDepth = 0;
1354
- for (let index = start; index < css.length; index++) {
1355
- const code = css.charCodeAt(index);
1356
- if (quote !== 0) {
1357
- if (code === 92) index++;
1358
- else if (code === quote) quote = 0;
1359
- continue;
1360
- }
1361
- if (code === 34 || code === 39) {
1362
- quote = code;
1363
- continue;
1364
- }
1365
- if (code === 92) {
1366
- index++;
1367
- continue;
1368
- }
1369
- if (code === 47 && css.charCodeAt(index + 1) === 42) {
1370
- const commentEnd = css.indexOf("*/", index + 2);
1371
- if (commentEnd < 0) return -1;
1372
- index = commentEnd + 1;
1373
- continue;
1374
- }
1375
- if (code === 40) {
1376
- parenthesisDepth++;
1377
- continue;
1378
- }
1379
- if (code === 41 && parenthesisDepth > 0) {
1380
- parenthesisDepth--;
1381
- continue;
1382
- }
1383
- if (code === 91) {
1384
- squareBracketDepth++;
1385
- continue;
1386
- }
1387
- if (code === 93 && squareBracketDepth > 0) {
1388
- squareBracketDepth--;
1389
- continue;
1390
- }
1391
- if (code === 123 && parenthesisDepth === 0 && squareBracketDepth === 0) return index;
1392
- if ((code === 59 || code === 125) && parenthesisDepth === 0 && squareBracketDepth === 0) return -1;
1393
- }
1394
- return -1;
1395
- }
1396
- function isEmptyAtRuleBody(css, blockStart) {
1397
- for (let index = blockStart + 1; index < css.length; index++) {
1398
- const code = css.charCodeAt(index);
1399
- if (isCssWhitespace(code)) continue;
1400
- if (code === 47 && css.charCodeAt(index + 1) === 42) {
1401
- const commentEnd = css.indexOf("*/", index + 2);
1402
- if (commentEnd < 0) return false;
1403
- index = commentEnd + 1;
1404
- continue;
1405
- }
1406
- return code === 125;
1407
- }
1408
- return false;
1409
- }
1410
- function hasEmptyAtRuleBlockCandidate(css) {
1411
- let searchFrom = 0;
1412
- while (searchFrom < css.length) {
1413
- const atRuleStart = css.indexOf("@", searchFrom);
1414
- if (atRuleStart < 0) return false;
1415
- searchFrom = atRuleStart + 1;
1416
- if (!isAtRuleNameCharacter(css.charCodeAt(searchFrom))) continue;
1417
- const blockStart = findAtRuleBlockStart(css, searchFrom + 1);
1418
- if (blockStart >= 0 && isEmptyAtRuleBody(css, blockStart)) return true;
1419
- }
1420
- return false;
1421
- }
1422
- //#endregion
1423
1345
  //#region src/bundlers/vite/processed-css-assets/style-files.ts
1424
1346
  const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
1425
1347
  function isCssOutputFile(file) {
@@ -1695,7 +1617,7 @@ function restoreCssImportAtRules(source, filtered, file) {
1695
1617
  return appendCss$1(missingImports.join("\n"), filtered);
1696
1618
  }
1697
1619
  function removeCommentOnlyAtRules(css) {
1698
- if (!hasEmptyAtRuleBlockCandidate(css)) return css;
1620
+ if (!require_v4_generation_core.hasEmptyAtRuleBlockCandidate(css)) return css;
1699
1621
  try {
1700
1622
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1701
1623
  let changed = false;
@@ -1710,21 +1632,6 @@ function removeCommentOnlyAtRules(css) {
1710
1632
  return css;
1711
1633
  }
1712
1634
  }
1713
- function removeEmptyCssAtRules(css) {
1714
- if (!hasEmptyAtRuleBlockCandidate(css)) return css;
1715
- try {
1716
- const root = _weapp_tailwindcss_postcss.postcss.parse(css);
1717
- let removed = 0;
1718
- let passRemoved = 0;
1719
- do {
1720
- passRemoved = (0, _weapp_tailwindcss_postcss.removeEmptyAtRules)(root);
1721
- removed += passRemoved;
1722
- } while (passRemoved > 0);
1723
- return removed > 0 ? root.toString() : css;
1724
- } catch {
1725
- return css;
1726
- }
1727
- }
1728
1635
  function collectImportedBundleCssSources(bundle, importedStyleFiles) {
1729
1636
  if (importedStyleFiles.size === 0) return [];
1730
1637
  const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
@@ -2416,6 +2323,8 @@ const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
2416
2323
  const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
2417
2324
  const SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
2418
2325
  "*",
2326
+ ":after",
2327
+ ":before",
2419
2328
  "::after",
2420
2329
  "::before",
2421
2330
  "::backdrop",
@@ -2427,6 +2336,14 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
2427
2336
  "::after",
2428
2337
  "::before"
2429
2338
  ]);
2339
+ const UNI_APP_WEB_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
2340
+ "uni-view",
2341
+ "uni-text",
2342
+ ":after",
2343
+ ":before",
2344
+ "::after",
2345
+ "::before"
2346
+ ]);
2430
2347
  const MINI_PROGRAM_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
2431
2348
  "box-sizing",
2432
2349
  "margin",
@@ -2533,14 +2450,24 @@ function isScopedUniversalTailwindPreflightRule(rule) {
2533
2450
  const declarations = getRuleDeclarations(rule);
2534
2451
  return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && SCOPED_UNIVERSAL_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop));
2535
2452
  }
2453
+ function isScopedUniAppWebTailwindPreflightRule(rule) {
2454
+ const selectors = rule.selectors ?? [rule.selector];
2455
+ const declarations = getRuleDeclarations(rule);
2456
+ return selectors.length > 0 && selectors.every((selector) => hasVueScopedAttr(selector) && UNI_APP_WEB_PREFLIGHT_SELECTORS.has(normalizeCssSignatureValue(selector))) && declarations.length > 0 && declarations.every((decl) => decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop));
2457
+ }
2536
2458
  function isLikelyTailwindGlobalRule(rule) {
2537
2459
  const selectors = rule.selectors ?? [rule.selector];
2538
2460
  const declarations = getRuleDeclarations(rule);
2539
- return isScopedTailwindThemeCarrierRule(rule) || isScopedUniversalTailwindPreflightRule(rule) || selectors.every((selector) => !hasClassSelector(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
2461
+ return isScopedTailwindThemeCarrierRule(rule) || isScopedUniversalTailwindPreflightRule(rule) || isScopedUniAppWebTailwindPreflightRule(rule) || selectors.every((selector) => !hasClassSelector(selector) && isLikelyTailwindGlobalSelector(selector)) && declarations.length > 0 && declarations.every(isTailwindPreflightDeclaration);
2540
2462
  }
2541
2463
  function isLikelyTailwindPropertyAtRule(atRule) {
2542
2464
  return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
2543
2465
  }
2466
+ function isLikelyTailwindLayerOrderAtRule(atRule) {
2467
+ if (atRule.name.toLowerCase() !== "layer" || atRule.nodes !== void 0) return false;
2468
+ const params = normalizeCssSignatureValue(atRule.params).replace(/\s+/g, "");
2469
+ return params === "properties" || params === "theme" || params === "base" || params === "theme,base,components,utilities";
2470
+ }
2544
2471
  function isUnscopedMiniProgramTailwindPreflightRule(rule) {
2545
2472
  const selectors = rule.selectors ?? [rule.selector];
2546
2473
  if (selectors.length === 0 || !selectors.every((selector) => {
@@ -2559,12 +2486,6 @@ function isScopedMiniProgramTailwindContentInitRule(rule) {
2559
2486
  const declarations = getRuleDeclarations(rule);
2560
2487
  return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
2561
2488
  }
2562
- function hasUnscopedMiniProgramTailwindPreflightRule(css) {
2563
- return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
2564
- }
2565
- function hasScopedMiniProgramTailwindContentInitRule(css) {
2566
- return /(?:^|[{}])[^{}]*\.data-v-[\w-][^{}]*\{\s*--tw-content\s*:/.test(css);
2567
- }
2568
2489
  //#endregion
2569
2490
  //#region src/bundlers/vite/processed-css-assets/coverage.ts
2570
2491
  function createDeclarationSignature(rule) {
@@ -2631,10 +2552,7 @@ function isRuleCoveredByRootCss(rule, coverage) {
2631
2552
  function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
2632
2553
  if (!hasVueScopedAttr(css)) return css;
2633
2554
  const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
2634
- const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
2635
- const hasScopedMiniProgramContentInit = hasScopedMiniProgramTailwindContentInitRule(css);
2636
2555
  const coverage = collectRootScopedComparableCssCoverage(rootSources);
2637
- if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight && !hasScopedMiniProgramContentInit) return css;
2638
2556
  try {
2639
2557
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2640
2558
  let changed = false;
@@ -2645,13 +2563,13 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
2645
2563
  }
2646
2564
  });
2647
2565
  root.walkRules((rule) => {
2648
- if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule)) {
2566
+ if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule) || isScopedUniAppWebTailwindPreflightRule(rule) || isScopedUniversalTailwindPreflightRule(rule)) {
2649
2567
  rule.remove();
2650
2568
  changed = true;
2651
2569
  }
2652
2570
  });
2653
2571
  root.walkAtRules((atRule) => {
2654
- if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || hasScopedTailwindGeneratedCss && isLikelyTailwindPropertyAtRule(atRule)) {
2572
+ if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || isLikelyTailwindPropertyAtRule(atRule) || isLikelyTailwindLayerOrderAtRule(atRule)) {
2655
2573
  atRule.remove();
2656
2574
  changed = true;
2657
2575
  return;
@@ -2685,22 +2603,20 @@ function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
2685
2603
  if (css.trim().length === 0) return css;
2686
2604
  const hasScopedCss = hasVueScopedAttr(css);
2687
2605
  const hasScopedTailwindGeneratedCss = hasScopedCss && /tailwindcss v\d/i.test(css);
2688
- const hasUnscopedMiniProgramPreflight = hasScopedCss && hasUnscopedMiniProgramTailwindPreflightRule(css);
2689
- const hasScopedMiniProgramContentInit = hasScopedCss && hasScopedMiniProgramTailwindContentInitRule(css);
2690
- if (rootSources.length === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight && !hasScopedMiniProgramContentInit) return css;
2606
+ if (rootSources.length === 0 && !hasScopedCss) return css;
2691
2607
  const coverage = collectRootScopedComparableCssCoverage(rootSources);
2692
2608
  let nextCss = css;
2693
2609
  try {
2694
2610
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2695
2611
  let changed = false;
2696
2612
  root.walkRules((rule) => {
2697
- if (coverage.normalizedRuleCss.has(normalizeCssSignatureValue(rule.toString())) || hasScopedCss && (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule))) {
2613
+ if (coverage.normalizedRuleCss.has(normalizeCssSignatureValue(rule.toString())) || hasScopedCss && (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule) || isScopedUniAppWebTailwindPreflightRule(rule) || isScopedUniversalTailwindPreflightRule(rule))) {
2698
2614
  rule.remove();
2699
2615
  changed = true;
2700
2616
  }
2701
2617
  });
2702
2618
  if (hasScopedCss) root.walkAtRules((atRule) => {
2703
- if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || hasScopedTailwindGeneratedCss && isLikelyTailwindPropertyAtRule(atRule)) {
2619
+ if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || isLikelyTailwindPropertyAtRule(atRule) || isLikelyTailwindLayerOrderAtRule(atRule)) {
2704
2620
  atRule.remove();
2705
2621
  changed = true;
2706
2622
  return;
@@ -3045,7 +2961,10 @@ function collectViteProcessedCssAssetResults(bundle, options) {
3045
2961
  const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
3046
2962
  if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
3047
2963
  nextCss = options.transformCss?.(nextCss, file) ?? nextCss;
3048
- if (nextCss !== rawSource) output.source = nextCss;
2964
+ if (nextCss !== rawSource) {
2965
+ output.source = nextCss;
2966
+ options.onAssetWrite?.(file);
2967
+ }
3049
2968
  options.markCssAssetProcessed?.(output, file);
3050
2969
  options.recordCssAssetResult?.(file, nextCss);
3051
2970
  const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
@@ -3058,6 +2977,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
3058
2977
  const targetNextCss = appendCss$1(targetRawSource, (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(targetRawSource, nextCss).trim());
3059
2978
  if (targetNextCss !== targetRawSource) {
3060
2979
  targetAsset.source = targetNextCss;
2980
+ options.onAssetWrite?.(resolvedOutputFile);
3061
2981
  options.markCssAssetProcessed?.(targetAsset, resolvedOutputFile);
3062
2982
  options.recordCssAssetResult?.(resolvedOutputFile, targetNextCss);
3063
2983
  }
@@ -4832,9 +4752,10 @@ function resolveViteCssTransformCachePlan(options) {
4832
4752
  const cssRuntimeSignature = createCssRuntimeSignature(options.runtimeSignature, options.scopedGeneratorCandidateSignature);
4833
4753
  const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, options.cssRuntimeAffectingHash);
4834
4754
  const tailwindcssMajorVersion = options.tailwindcssMajorVersion ?? "unknown";
4755
+ const cssCacheKey = `${options.outputFile}:css:${cssRuntimeSignature}:${tailwindcssMajorVersion}`;
4835
4756
  return {
4836
- cssCacheKey: options.outputFile,
4837
- cssHashKey: `${options.outputFile}:css:${cssRuntimeSignature}:${tailwindcssMajorVersion}`,
4757
+ cssCacheKey,
4758
+ cssHashKey: cssCacheKey,
4838
4759
  cssRuntimeSignature,
4839
4760
  cssSharedCacheKey: [
4840
4761
  options.cssShareScope,
@@ -4971,6 +4892,31 @@ function readAssetSource$1(output) {
4971
4892
  function shouldFinalizeMiniProgramCssAsset(source) {
4972
4893
  return source.includes(":hover") || source.includes("does-not-exist") || (0, _weapp_tailwindcss_postcss.hasMiniProgramCssSpecificityPlaceholders)(source);
4973
4894
  }
4895
+ function finalizeMiniProgramCssAssetStructures(bundle, options) {
4896
+ if (options.isWebGeneratorTarget) return 0;
4897
+ const plan = new require_v4_generation_core.AssetEmissionPlan();
4898
+ const writeTargets = /* @__PURE__ */ new Map();
4899
+ let updated = 0;
4900
+ for (const [bundleFile, output] of Object.entries(bundle)) {
4901
+ if (output.type !== "asset") continue;
4902
+ const file = output.fileName || bundleFile;
4903
+ if (!options.cssMatcher(file) || options.files && !options.files.has(file)) continue;
4904
+ const rawSource = readAssetSource$1(output);
4905
+ const outputCss = require_v4_generation_core.finalizeMiniProgramCssStructure(rawSource);
4906
+ if (outputCss === rawSource) continue;
4907
+ plan.write(file, outputCss);
4908
+ writeTargets.set(file, output);
4909
+ options.recordCssAssetResult?.(file, outputCss);
4910
+ options.onUpdate(file, rawSource, outputCss);
4911
+ options.debug?.("remove final empty mini-program css at-rules: %s bytes=%d", file, outputCss.length);
4912
+ updated++;
4913
+ }
4914
+ applyViteAssetEmissionPlan(plan, {
4915
+ bundle,
4916
+ writeTargets
4917
+ });
4918
+ return updated;
4919
+ }
4974
4920
  async function finalizeMiniProgramCssAssets(bundle, options) {
4975
4921
  if (options.isWebGeneratorTarget) return 0;
4976
4922
  const plan = new require_v4_generation_core.AssetEmissionPlan();
@@ -4983,7 +4929,7 @@ async function finalizeMiniProgramCssAssets(bundle, options) {
4983
4929
  const rawSource = readAssetSource$1(output);
4984
4930
  if (rawSource.trim().length === 0) continue;
4985
4931
  if (options.lastCssResultByFile?.has(file)) {
4986
- const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeEmptyCssAtRules(rawSource));
4932
+ const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_v4_generation_core.finalizeMiniProgramCssStructure(rawSource));
4987
4933
  if (outputCss !== rawSource) {
4988
4934
  plan.write(file, outputCss);
4989
4935
  writeTargets.set(file, output);
@@ -4995,7 +4941,7 @@ async function finalizeMiniProgramCssAssets(bundle, options) {
4995
4941
  continue;
4996
4942
  }
4997
4943
  if (!shouldFinalizeMiniProgramCssAsset(rawSource)) {
4998
- const structurallyCleanSource = removeEmptyCssAtRules(rawSource);
4944
+ const structurallyCleanSource = require_v4_generation_core.finalizeMiniProgramCssStructure(rawSource);
4999
4945
  if (structurallyCleanSource !== rawSource) {
5000
4946
  plan.write(file, structurallyCleanSource);
5001
4947
  writeTargets.set(file, output);
@@ -5017,7 +4963,7 @@ async function finalizeMiniProgramCssAssets(bundle, options) {
5017
4963
  },
5018
4964
  cssPresetEnv: {}
5019
4965
  });
5020
- const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeEmptyCssAtRules(css));
4966
+ const outputCss = (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_v4_generation_core.finalizeMiniProgramCssStructure(css));
5021
4967
  if (outputCss === rawSource) continue;
5022
4968
  plan.write(file, outputCss);
5023
4969
  writeTargets.set(file, output);
@@ -5154,7 +5100,7 @@ function injectHarmonyCssIntoMainAsset(bundle, cssSources, isMainCssAsset, plan,
5154
5100
  return true;
5155
5101
  }
5156
5102
  async function handleUniAppXPostCssTasks(options) {
5157
- const { bundle, debug, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler, deferStylePlaceholderInjection } = options;
5103
+ const { bundle, debug, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler, deferStylePlaceholderInjection } = options;
5158
5104
  const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
5159
5105
  if (opts.appType !== "uni-app-x" && !isNativeAppStyleTarget && !isHarmonyAppStyleTarget) return applyStyleSources;
5160
5106
  const emissionPlan = new require_v4_generation_core.AssetEmissionPlan();
@@ -5176,7 +5122,7 @@ async function handleUniAppXPostCssTasks(options) {
5176
5122
  const generated = await require_v4_generation_core.generateTailwindV4Css({
5177
5123
  opts,
5178
5124
  runtimeState,
5179
- runtime: /* @__PURE__ */ new Set([...generatorRuntime, ...applyUtilities]),
5125
+ runtime: /* @__PURE__ */ new Set(),
5180
5126
  rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
5181
5127
  file: outputFile,
5182
5128
  outputFile,
@@ -5186,6 +5132,7 @@ async function handleUniAppXPostCssTasks(options) {
5186
5132
  isMainChunk: false
5187
5133
  },
5188
5134
  cssStage: "framework-processed",
5135
+ disableSourceScan: true,
5189
5136
  getSourceCandidatesForEntries,
5190
5137
  styleHandler,
5191
5138
  debug
@@ -5716,6 +5663,53 @@ function resolveUniAppXStyleIsolationEnabled(root) {
5716
5663
  return enabled;
5717
5664
  }
5718
5665
  //#endregion
5666
+ //#region src/uni-app-x/vite/author-apply.ts
5667
+ function normalizeSelector(selector) {
5668
+ return selector.replace(/\s+/g, " ").trim();
5669
+ }
5670
+ function atRuleKey(name, params) {
5671
+ return `${name.toLowerCase()}\0${params.replace(/\s+/g, " ").trim()}`;
5672
+ }
5673
+ /**
5674
+ * `@apply` 只应把声明带回作者样式,不能把 Tailwind 根入口的 preflight、
5675
+ * utilities 和 property 注册复制进 scoped style 模块。
5676
+ */
5677
+ function retainUniAppXAuthorApplyCss(generatedCss, authorCss) {
5678
+ try {
5679
+ const authorRoot = _weapp_tailwindcss_postcss.postcss.parse(require_generator.removeTailwindSourceDirectives(authorCss, { importFallback: true }));
5680
+ const authorSelectors = /* @__PURE__ */ new Set();
5681
+ const authorAtRules = /* @__PURE__ */ new Set();
5682
+ authorRoot.walkRules((rule) => {
5683
+ for (const selector of rule.selectors ?? [rule.selector]) authorSelectors.add(normalizeSelector(selector));
5684
+ });
5685
+ authorRoot.walkAtRules((atRule) => {
5686
+ if (atRule.name !== "apply" && atRule.name !== "reference") authorAtRules.add(atRuleKey(atRule.name, atRule.params));
5687
+ });
5688
+ const root = _weapp_tailwindcss_postcss.postcss.parse(generatedCss);
5689
+ let changed = false;
5690
+ root.walkRules((rule) => {
5691
+ if ((rule.selectors ?? [rule.selector]).every((selector) => authorSelectors.has(normalizeSelector(selector)))) return;
5692
+ rule.remove();
5693
+ changed = true;
5694
+ });
5695
+ root.walkAtRules((atRule) => {
5696
+ if (authorAtRules.has(atRuleKey(atRule.name, atRule.params))) return;
5697
+ if (atRule.nodes?.some((node) => node.type === "rule" || node.type === "atrule")) return;
5698
+ atRule.remove();
5699
+ changed = true;
5700
+ });
5701
+ root.walkComments((comment) => {
5702
+ if (/tailwindcss v\d|weapp-tailwindcss (?:vite-generated-css|layer|uni-app-x web preflight reset)/i.test(comment.text)) {
5703
+ comment.remove();
5704
+ changed = true;
5705
+ }
5706
+ });
5707
+ return changed ? root.toString().trim() : generatedCss;
5708
+ } catch {
5709
+ return generatedCss;
5710
+ }
5711
+ }
5712
+ //#endregion
5719
5713
  //#region src/uni-app-x/vite/harmony-apply.ts
5720
5714
  function createStableHash(input) {
5721
5715
  let hash = 2166136261;
@@ -5726,23 +5720,43 @@ function createStableHash(input) {
5726
5720
  return (hash >>> 0).toString(36);
5727
5721
  }
5728
5722
  function createUniAppXHarmonyApplyExpander(options) {
5723
+ const referenceBySourceId = /* @__PURE__ */ new Map();
5729
5724
  const styleSources = /* @__PURE__ */ new Set();
5730
5725
  const utilities = /* @__PURE__ */ new Set();
5731
- function rememberSource(code, id) {
5726
+ function rememberSource(code, id, authoritative = false) {
5732
5727
  const sources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code, id);
5728
+ const sourceKey = normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id));
5729
+ const references = authoritative ? /* @__PURE__ */ new Set() : new Set(referenceBySourceId.get(sourceKey));
5733
5730
  for (const source of sources) {
5734
5731
  styleSources.add(source);
5732
+ try {
5733
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("reference", (rule) => {
5734
+ const reference = rule.toString();
5735
+ references.add(reference.endsWith(";") ? reference : `${reference};`);
5736
+ });
5737
+ } catch {}
5735
5738
  for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([source])) utilities.add(utility);
5736
5739
  }
5740
+ if (references.size > 0) referenceBySourceId.set(sourceKey, references);
5741
+ else if (authoritative) referenceBySourceId.delete(sourceKey);
5742
+ }
5743
+ function prepareStyles(code, id) {
5744
+ if (!code.includes("@apply") || code.includes("@reference")) return code;
5745
+ const references = referenceBySourceId.get(normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
5746
+ if (references?.size !== 1) return code;
5747
+ return `${references.values().next().value}\n${code}`;
5737
5748
  }
5738
5749
  async function expandStyles(code, id, hookContext) {
5739
5750
  if (!options.isHarmonyBuildTarget() || !code.includes("@apply")) return code;
5740
- const sources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code, id);
5751
+ const sources = collectUniAppXHarmonyApplyStyleSourcesFromSource(prepareStyles(code, id), id);
5741
5752
  const sourceUtilities = collectUniAppXHarmonyApplyUtilitiesFromSources(sources);
5742
5753
  if (sources.length === 0 || sourceUtilities.size === 0) return code;
5743
5754
  const cssFile = node_path.default.resolve(options.getResolvedConfig()?.root ?? node_process.default.cwd(), `uni-app-x-harmony-apply-${createStableHash(normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)))}.css`);
5744
- const generatedCss = await options.generateCss?.(cssFile, createUniAppXHarmonyApplyGeneratorSource(sources, sourceUtilities), {
5755
+ const generatorSource = createUniAppXHarmonyApplyGeneratorSource(sources, sourceUtilities);
5756
+ const generatedCss = await options.generateCss?.(cssFile, generatorSource, {
5745
5757
  addWatchFile: hookContext.addWatchFile?.bind(hookContext),
5758
+ disableSourceScan: true,
5759
+ sourceCandidates: [],
5746
5760
  transient: true
5747
5761
  });
5748
5762
  if (typeof generatedCss !== "string" || generatedCss.trim().length === 0) return code;
@@ -5750,49 +5764,178 @@ function createUniAppXHarmonyApplyExpander(options) {
5750
5764
  }
5751
5765
  return {
5752
5766
  expandStyles,
5767
+ prepareStyles,
5753
5768
  rememberSource,
5754
5769
  styleSources,
5755
5770
  utilities
5756
5771
  };
5757
5772
  }
5758
5773
  //#endregion
5774
+ //#region src/bundlers/vite/module-identity.ts
5775
+ const WINDOWS_DRIVE_RE = /^\/?[a-z]:[\\/]/i;
5776
+ const WINDOWS_UNC_RE = /^(?:\\\\|\/\/)/;
5777
+ function unique(values) {
5778
+ return [...new Set([...values].filter((value) => typeof value === "string" && value.length > 0))];
5779
+ }
5780
+ function decodeFileId(id) {
5781
+ try {
5782
+ return decodeURIComponent(id);
5783
+ } catch {
5784
+ return id;
5785
+ }
5786
+ }
5787
+ function stripViteFsPrefix(id) {
5788
+ if (!id.startsWith("/@fs/")) return id;
5789
+ const file = id.slice(5);
5790
+ return file.startsWith("/") || WINDOWS_DRIVE_RE.test(file) ? file : `/${file}`;
5791
+ }
5792
+ function stripFileProtocol(id) {
5793
+ if (!id.startsWith("file://")) return id;
5794
+ try {
5795
+ return (0, node_url.fileURLToPath)(id);
5796
+ } catch {
5797
+ return id;
5798
+ }
5799
+ }
5800
+ function isWindowsFile(file) {
5801
+ return WINDOWS_DRIVE_RE.test(file) || WINDOWS_UNC_RE.test(file);
5802
+ }
5803
+ function normalizeWindowsFile(file) {
5804
+ const withoutDriveSlash = /^\/[a-z]:[\\/]/i.test(file) ? file.slice(1) : file;
5805
+ return slash(node_path.default.win32.resolve(withoutDriveSlash));
5806
+ }
5807
+ function normalizeFile(file, root) {
5808
+ if (isWindowsFile(file) || isWindowsFile(root)) return normalizeWindowsFile(isWindowsFile(file) ? file : node_path.default.win32.resolve(root, file.replace(/^\//, "")));
5809
+ if (node_path.default.isAbsolute(file)) {
5810
+ if (file === root || file.startsWith(`${root}${node_path.default.sep}`) || (0, node_fs.existsSync)(file) || (0, node_fs.existsSync)(node_path.default.dirname(file))) return slash(node_path.default.resolve(file));
5811
+ const rootRelativeFile = node_path.default.resolve(root, file.slice(1));
5812
+ return (0, node_fs.existsSync)(rootRelativeFile) || (0, node_fs.existsSync)(node_path.default.dirname(rootRelativeFile)) ? slash(rootRelativeFile) : slash(node_path.default.resolve(file));
5813
+ }
5814
+ return slash(node_path.default.resolve(root, file));
5815
+ }
5816
+ function resolveRealFile(file) {
5817
+ if (node_process.default.platform !== "win32" && isWindowsFile(file)) return file;
5818
+ let current = file;
5819
+ const missingSegments = [];
5820
+ try {
5821
+ while (true) try {
5822
+ const resolvedParent = node_fs.realpathSync.native(current);
5823
+ return slash(node_path.default.join(resolvedParent, ...missingSegments));
5824
+ } catch {
5825
+ const parent = node_path.default.dirname(current);
5826
+ if (parent === current) return file;
5827
+ missingSegments.unshift(node_path.default.basename(current));
5828
+ current = parent;
5829
+ }
5830
+ } catch {
5831
+ return file;
5832
+ }
5833
+ }
5834
+ function normalizeIdentityKey(file) {
5835
+ return isWindowsFile(file) || node_process.default.platform === "win32" ? file.toLowerCase() : file;
5836
+ }
5837
+ /**
5838
+ * 将 Vite URL、文件路径和 Windows 的等价路径收敛为同一个模块身份。
5839
+ */
5840
+ function resolveViteModuleIdentity(id, root = node_process.default.cwd()) {
5841
+ const cleanId = decodeFileId((0, _weapp_tailwindcss_shared.cleanUrl)(id));
5842
+ const decodedRoot = decodeFileId((0, _weapp_tailwindcss_shared.cleanUrl)(root));
5843
+ const normalizedRoot = isWindowsFile(decodedRoot) ? normalizeWindowsFile(decodedRoot) : slash(node_path.default.resolve(decodedRoot));
5844
+ const unwrappedId = stripFileProtocol(stripViteFsPrefix(cleanId));
5845
+ const file = unwrappedId.startsWith("\0") ? void 0 : normalizeFile(unwrappedId, normalizedRoot);
5846
+ const realFile = file ? resolveRealFile(file) : void 0;
5847
+ const key = realFile ? normalizeIdentityKey(realFile) : cleanId;
5848
+ const pathApi = isWindowsFile(normalizedRoot) ? node_path.default.win32 : node_path.default.posix;
5849
+ const relativeUrl = realFile && normalizeIdentityKey(realFile).startsWith(`${normalizeIdentityKey(normalizedRoot)}/`) ? `/${slash(pathApi.relative(normalizedRoot, realFile))}` : void 0;
5850
+ return {
5851
+ cleanId,
5852
+ file: realFile,
5853
+ key,
5854
+ lookupFiles: unique([file, realFile]),
5855
+ lookupIds: unique([
5856
+ id,
5857
+ cleanId,
5858
+ unwrappedId,
5859
+ file,
5860
+ realFile,
5861
+ realFile ? `/@fs/${realFile}` : void 0,
5862
+ relativeUrl
5863
+ ])
5864
+ };
5865
+ }
5866
+ function hasSameViteModuleIdentity(left, right, root = node_process.default.cwd()) {
5867
+ if (!left || !right) return false;
5868
+ return resolveViteModuleIdentity(left, root).key === resolveViteModuleIdentity(right, root).key;
5869
+ }
5870
+ //#endregion
5759
5871
  //#region src/bundlers/vite/hot-css-modules.ts
5760
- function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
5872
+ async function resolveHotModulesByIds(ctx, ids, acceptModule) {
5761
5873
  const modules = [];
5762
5874
  const seenModules = /* @__PURE__ */ new Set();
5763
5875
  const seenModuleIds = /* @__PURE__ */ new Set();
5876
+ const seenFileIdentities = /* @__PURE__ */ new Set();
5764
5877
  const root = ctx.server.config?.root ?? node_process.default.cwd();
5765
- const outDir = ctx.server.config?.build?.outDir ? normalizeAbsoluteFilePath(node_path.default.resolve(root, ctx.server.config.build.outDir)) : void 0;
5878
+ const collectModule = (mod) => {
5879
+ if (mod == null || seenModules.has(mod) || !acceptModule(mod)) return;
5880
+ seenModules.add(mod);
5881
+ modules.push(mod);
5882
+ };
5883
+ for (const id of ids) {
5884
+ if (typeof id !== "string" || id.length === 0) continue;
5885
+ const identity = resolveViteModuleIdentity(id, root);
5886
+ for (const moduleId of identity.lookupIds) {
5887
+ if (seenModuleIds.has(moduleId)) continue;
5888
+ seenModuleIds.add(moduleId);
5889
+ collectModule(ctx.server.moduleGraph.getModuleById?.(moduleId));
5890
+ if (moduleId.startsWith("/")) collectModule(await ctx.server.moduleGraph.getModuleByUrl?.(moduleId));
5891
+ }
5892
+ if (seenFileIdentities.has(identity.key)) continue;
5893
+ seenFileIdentities.add(identity.key);
5894
+ for (const file of identity.lookupFiles) for (const mod of ctx.server.moduleGraph.getModulesByFile?.(file) ?? []) collectModule(mod);
5895
+ }
5896
+ return modules;
5897
+ }
5898
+ async function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
5899
+ const root = ctx.server.config?.root ?? node_process.default.cwd();
5900
+ const outDir = ctx.server.config?.build?.outDir ? resolveViteModuleIdentity(ctx.server.config.build.outDir, root) : void 0;
5766
5901
  const isHotSourceStyleModule = (id) => {
5767
5902
  if (!require_v4_generation_core.isSourceStyleRequest(id)) return false;
5768
5903
  const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
5769
5904
  if (isRootMiniProgramStyleUrl(file) || !isAbsoluteFilePath(file) && !file.startsWith("/")) return false;
5770
- if (outDir && isAbsoluteFilePath(file)) {
5771
- const normalizedFile = normalizeAbsoluteFilePath(file);
5772
- if (normalizedFile === outDir || normalizedFile.startsWith(`${outDir}/`)) return false;
5905
+ if (outDir) {
5906
+ const identity = resolveViteModuleIdentity(file, root);
5907
+ if (identity.key === outDir.key || identity.key.startsWith(`${outDir.key}/`)) return false;
5773
5908
  }
5774
5909
  return true;
5775
5910
  };
5776
- const collectModule = (mod) => {
5777
- if (mod == null || seenModules.has(mod)) return;
5911
+ const modules = await resolveHotModulesByIds(ctx, tailwindRootCssModuleIds, (mod) => {
5778
5912
  const modId = mod.id ?? mod.url;
5779
- if (!isHotSourceStyleModule(modId)) return;
5780
- seenModules.add(mod);
5781
- ctx.server.moduleGraph.invalidateModule(mod);
5782
- modules.push(mod);
5783
- };
5784
- for (const id of tailwindRootCssModuleIds) {
5785
- if (typeof id !== "string" || id.length === 0) continue;
5786
- for (const moduleId of [id, (0, _weapp_tailwindcss_shared.cleanUrl)(id)]) {
5787
- if (moduleId.length === 0 || seenModuleIds.has(moduleId)) continue;
5788
- seenModuleIds.add(moduleId);
5789
- const candidates = [ctx.server.moduleGraph.getModuleById(moduleId), ...ctx.server.moduleGraph.getModulesByFile(moduleId) ?? []];
5790
- for (const mod of candidates) collectModule(mod);
5913
+ return isHotSourceStyleModule(modId);
5914
+ });
5915
+ const seenHotModules = new Set(modules);
5916
+ for (let index = 0; index < modules.length; index++) for (const importer of modules[index]?.importers ?? []) {
5917
+ const importerId = importer.id ?? importer.url;
5918
+ if (!seenHotModules.has(importer) && isHotSourceStyleModule(importerId)) {
5919
+ seenHotModules.add(importer);
5920
+ modules.push(importer);
5791
5921
  }
5792
5922
  }
5923
+ for (const mod of modules) ctx.server.moduleGraph.invalidateModule(mod);
5793
5924
  return modules;
5794
5925
  }
5795
- function resolveHotSourceModules(ctx) {
5926
+ async function resolveHotSourceModulesByIds(ctx, ids) {
5927
+ const root = ctx.server.config?.root ?? node_process.default.cwd();
5928
+ const sourceIds = new Set(ids);
5929
+ for (const id of ids) {
5930
+ if (typeof id !== "string" || !/\.(?:uvue|nvue)(?:$|[?#])/i.test(id)) continue;
5931
+ const identity = resolveViteModuleIdentity(id, root);
5932
+ for (const lookupId of identity.lookupIds) if (!/[?&]import(?:[=&]|$)/.test(lookupId)) sourceIds.add(`${(0, _weapp_tailwindcss_shared.cleanUrl)(lookupId)}?import`);
5933
+ }
5934
+ return resolveHotModulesByIds(ctx, sourceIds, (mod) => {
5935
+ return !require_v4_generation_core.isSourceStyleRequest(mod.id ?? mod.url);
5936
+ });
5937
+ }
5938
+ async function resolveHotSourceModules(ctx) {
5796
5939
  const modules = [];
5797
5940
  const seenModules = /* @__PURE__ */ new Set();
5798
5941
  const collectModule = (mod) => {
@@ -5802,10 +5945,27 @@ function resolveHotSourceModules(ctx) {
5802
5945
  modules.push(mod);
5803
5946
  };
5804
5947
  for (const mod of ctx.modules) collectModule(mod);
5805
- for (const mod of ctx.server.moduleGraph.getModulesByFile(ctx.file) ?? []) collectModule(mod);
5806
- for (const mod of ctx.server.moduleGraph.getModulesByFile((0, _weapp_tailwindcss_shared.cleanUrl)(ctx.file)) ?? []) collectModule(mod);
5807
- collectModule(ctx.server.moduleGraph.getModuleById?.(ctx.file));
5808
- collectModule(ctx.server.moduleGraph.getModuleById?.((0, _weapp_tailwindcss_shared.cleanUrl)(ctx.file)));
5948
+ for (const mod of await resolveHotSourceModulesByIds(ctx, [ctx.file])) collectModule(mod);
5949
+ return modules;
5950
+ }
5951
+ function mergeHotModulesByIdentity(root, ...groups) {
5952
+ const modules = [];
5953
+ const seenModules = /* @__PURE__ */ new Set();
5954
+ const seenIdentities = /* @__PURE__ */ new Set();
5955
+ for (const mod of groups.flat()) {
5956
+ if (seenModules.has(mod)) continue;
5957
+ const ids = [
5958
+ mod.id,
5959
+ mod.url,
5960
+ mod.file
5961
+ ].filter((id) => typeof id === "string" && id.length > 0);
5962
+ const moduleKind = ids.some(require_v4_generation_core.isSourceStyleRequest) ? "style" : "source";
5963
+ const keys = ids.map((id) => `${moduleKind}:${resolveViteModuleIdentity(id, root).key}`);
5964
+ if (keys.some((key) => seenIdentities.has(key))) continue;
5965
+ seenModules.add(mod);
5966
+ keys.forEach((key) => seenIdentities.add(key));
5967
+ modules.push(mod);
5968
+ }
5809
5969
  return modules;
5810
5970
  }
5811
5971
  function resolveModuleHotUrl(mod) {
@@ -5824,23 +5984,32 @@ function isRootMiniProgramStyleUrl(file) {
5824
5984
  }
5825
5985
  function resolveCssHotUrl(id, root) {
5826
5986
  const suffix = /[?#]/.test(id) ? id.slice(id.search(/[?#]/)) : "";
5827
- const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
5828
- if (/^\/(?![A-Z]:)/i.test(file) && !file.startsWith(slash(root))) {
5829
- if (isRootMiniProgramStyleUrl(file)) return;
5830
- return `${file}${suffix}`;
5987
+ const cleanId = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
5988
+ if (/^\/(?!@fs\/|[A-Z]:)/i.test(cleanId) && !cleanId.startsWith(slash(root))) {
5989
+ if (isRootMiniProgramStyleUrl(cleanId)) return;
5990
+ return `${cleanId}${suffix}`;
5831
5991
  }
5992
+ const file = resolveViteModuleIdentity(id, root).file ?? cleanId;
5832
5993
  if (!isAbsoluteFilePath(file)) return;
5833
5994
  const normalizedRoot = normalizeAbsoluteFilePath(root);
5834
5995
  const normalizedFile = normalizeAbsoluteFilePath(file);
5835
5996
  if (!normalizedFile.startsWith(`${normalizedRoot}/`)) return;
5836
5997
  return `/${slash(node_path.default.relative(normalizedRoot, normalizedFile))}${suffix}`;
5837
5998
  }
5838
- function includesHotModule(modules, target) {
5999
+ function includesHotModule(modules, target, root) {
5839
6000
  const targetUrl = resolveModuleHotUrl(target);
5840
6001
  const targetId = target.id;
5841
6002
  return modules.some((mod) => {
5842
6003
  if (mod === target) return true;
5843
- return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId;
6004
+ return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId || [
6005
+ target.id,
6006
+ target.url,
6007
+ target.file
6008
+ ].some((targetIdentity) => [
6009
+ mod.id,
6010
+ mod.url,
6011
+ mod.file
6012
+ ].some((moduleIdentity) => hasSameViteModuleIdentity(targetIdentity, moduleIdentity, root)));
5844
6013
  });
5845
6014
  }
5846
6015
  function createSupplementalHotUpdate(hotUrl, timestamp) {
@@ -5858,10 +6027,16 @@ function hasSelfAcceptingNonStyleHotModule(modules) {
5858
6027
  return !require_v4_generation_core.isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
5859
6028
  });
5860
6029
  }
5861
- function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = []) {
6030
+ function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = [], fallbackSourceIds = []) {
5862
6031
  const seenUrls = /* @__PURE__ */ new Set();
5863
6032
  const root = ctx.server.config?.root ?? node_process.default.cwd();
5864
6033
  const updates = [];
6034
+ for (const id of fallbackSourceIds) {
6035
+ const hotUrl = resolveCssHotUrl(id, root);
6036
+ if (!hotUrl || seenUrls.has(hotUrl)) continue;
6037
+ seenUrls.add(hotUrl);
6038
+ updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
6039
+ }
5865
6040
  for (const id of fallbackCssIds) {
5866
6041
  if (!require_v4_generation_core.isSourceStyleRequest(id)) continue;
5867
6042
  const hotUrl = resolveCssHotUrl(id, root);
@@ -5870,7 +6045,7 @@ function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = []) {
5870
6045
  updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
5871
6046
  }
5872
6047
  for (const mod of cssModules) {
5873
- if (includesHotModule(ctx.modules, mod)) continue;
6048
+ if (includesHotModule(ctx.modules, mod, root)) continue;
5874
6049
  const moduleHotUrl = resolveModuleHotUrl(mod);
5875
6050
  const hotUrl = moduleHotUrl ? resolveCssHotUrl(moduleHotUrl, root) : void 0;
5876
6051
  if (!hotUrl || seenUrls.has(hotUrl)) continue;
@@ -5905,12 +6080,25 @@ function createUniAppXNativeHmrReloader(options) {
5905
6080
  }
5906
6081
  async function handleHotUpdate(ctx) {
5907
6082
  if (!options.isNativeAppBuildTarget(ctx.file)) return;
5908
- const cssModules = ctx.server?.moduleGraph ? resolveHotTailwindCssModules(ctx, /* @__PURE__ */ new Set([...options.tailwindRootCssModuleIds, ...options.viteProcessedCssSourceFiles])) : [];
6083
+ await options.syncSourceCandidates?.(ctx);
5909
6084
  const currentRuntimeClassSet = await options.ensureRuntimeClassSet(true);
5910
- const hasAddedClass = previousRuntimeClassSet !== void 0 && [...currentRuntimeClassSet].some((candidate) => !previousRuntimeClassSet.has(candidate));
6085
+ const hasRuntimeClassChange = previousRuntimeClassSet !== void 0 && (currentRuntimeClassSet.size !== previousRuntimeClassSet.size || [...currentRuntimeClassSet].some((candidate) => !previousRuntimeClassSet.has(candidate)));
5911
6086
  remember(currentRuntimeClassSet);
5912
- if (hasAddedClass) sendFullReloadForUnresolvedHotUpdate(ctx);
5913
- return cssModules.length > 0 ? [.../* @__PURE__ */ new Set([...ctx.modules, ...cssModules])] : void 0;
6087
+ const cssModules = ctx.server?.moduleGraph ? await resolveHotTailwindCssModules(ctx, /* @__PURE__ */ new Set([...options.tailwindRootCssModuleIds, ...options.viteProcessedCssSourceFiles])) : [];
6088
+ const sourceModules = ctx.server?.moduleGraph ? await resolveHotSourceModules(ctx) : ctx.modules ?? [];
6089
+ const localStyleModules = hasRuntimeClassChange && ctx.server?.moduleGraph ? await resolveHotSourceModulesByIds(ctx, options.localStyleModuleIds) : [];
6090
+ for (const mod of /* @__PURE__ */ new Set([...sourceModules, ...localStyleModules])) ctx.server?.moduleGraph?.invalidateModule(mod);
6091
+ const modules = [.../* @__PURE__ */ new Set([
6092
+ ...sourceModules,
6093
+ ...localStyleModules,
6094
+ ...cssModules
6095
+ ])];
6096
+ const canAcceptUpdate = hasSelfAcceptingNonStyleHotModule([...sourceModules, ...localStyleModules]) || cssModules.length > 0;
6097
+ if (hasRuntimeClassChange && !canAcceptUpdate) {
6098
+ sendFullReloadForUnresolvedHotUpdate(ctx);
6099
+ return [];
6100
+ }
6101
+ return modules.length > 0 ? modules : void 0;
5914
6102
  }
5915
6103
  return {
5916
6104
  handleHotUpdate,
@@ -5930,12 +6118,7 @@ function createUniAppXNativeBuildTargetResolver(getResolvedConfig) {
5930
6118
  };
5931
6119
  }
5932
6120
  //#endregion
5933
- //#region src/uni-app-x/vite.ts
5934
- let transformUVuePromise;
5935
- function loadTransformUVue() {
5936
- transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-BUEyOCT7.cjs")).then((mod) => mod.transformUVue));
5937
- return transformUVuePromise;
5938
- }
6121
+ //#region src/uni-app-x/vite/style-request.ts
5939
6122
  const preprocessorLangs = /* @__PURE__ */ new Set([
5940
6123
  "scss",
5941
6124
  "sass",
@@ -5945,8 +6128,7 @@ const preprocessorLangs = /* @__PURE__ */ new Set([
5945
6128
  ]);
5946
6129
  const INLINE_LANG_RE = /lang\.([a-z]+)/i;
5947
6130
  const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
5948
- const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
5949
- const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
6131
+ const UVUE_NVUE_RE$1 = /\.(?:uvue|nvue)$/;
5950
6132
  const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
5951
6133
  function isPreprocessorRequest(id, lang) {
5952
6134
  const normalizedLang = lang?.toLowerCase();
@@ -5956,25 +6138,37 @@ function isPreprocessorRequest(id, lang) {
5956
6138
  return PREPROCESSOR_EXT_RE.test(id);
5957
6139
  }
5958
6140
  function resolveUniAppXCssTarget(id) {
5959
- return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
5960
- }
5961
- function resolveUniAppXJsTransformEnabled(uniAppX) {
5962
- return uniAppX === void 0 ? true : require_options.isUniAppXEnabled(uniAppX);
6141
+ return UVUE_NVUE_RE$1.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
5963
6142
  }
5964
6143
  function isCssModuleExport(code) {
5965
6144
  return CSS_MODULE_EXPORT_RE.test(code);
5966
6145
  }
6146
+ //#endregion
6147
+ //#region src/uni-app-x/vite.ts
6148
+ let transformUVuePromise;
6149
+ function loadTransformUVue() {
6150
+ transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-DzVJW6Dp.cjs")).then((mod) => mod.transformUVue));
6151
+ return transformUVuePromise;
6152
+ }
6153
+ const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
6154
+ const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
6155
+ function resolveUniAppXJsTransformEnabled(uniAppX) {
6156
+ return uniAppX === void 0 ? true : require_options.isUniAppXEnabled(uniAppX);
6157
+ }
5967
6158
  function createUniAppXPlugins(options) {
5968
- const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, tailwindRootCssModuleIds = [], generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX, viteProcessedCssSourceFiles = [] } = options;
6159
+ const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, syncSourceCandidatesForHotUpdate, tailwindRootCssModuleIds = [], generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX, viteProcessedCssSourceFiles = [] } = options;
5969
6160
  const resolvedUniAppXOptions = require_options.resolveUniAppXOptions(uniAppX);
5970
6161
  const utsPlatform = require_generator.resolveUniUtsPlatform();
5971
6162
  const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
5972
6163
  const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
6164
+ const nativeLocalStyleModuleIds = /* @__PURE__ */ new Set();
5973
6165
  let componentLocalStyleEnabled;
5974
6166
  const isNativeAppBuildTarget = createUniAppXNativeBuildTargetResolver(getResolvedConfig);
5975
6167
  const nativeHmrReloader = createUniAppXNativeHmrReloader({
5976
6168
  ensureRuntimeClassSet,
5977
6169
  isNativeAppBuildTarget,
6170
+ localStyleModuleIds: nativeLocalStyleModuleIds,
6171
+ syncSourceCandidates: syncSourceCandidatesForHotUpdate,
5978
6172
  tailwindRootCssModuleIds,
5979
6173
  viteProcessedCssSourceFiles
5980
6174
  });
@@ -5999,13 +6193,15 @@ function createUniAppXPlugins(options) {
5999
6193
  if (require_generator.resolveUniUtsPlatform().isAppHarmony) return true;
6000
6194
  return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
6001
6195
  }
6002
- function getStyleHandlerOptions(id) {
6003
- const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
6196
+ function getStyleHandlerOptions(id, source) {
6197
+ const isMainChunk = source === "tailwind-root" || mainCssChunkMatcher(id, appType);
6198
+ const cacheKey = `${isMainChunk ? "1" : "0"}:${source ?? ""}:${id}`;
6004
6199
  let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
6005
6200
  if (!styleHandlerOptions) {
6006
6201
  styleHandlerOptions = require_object.omitUndefined({
6007
- isMainChunk: mainCssChunkMatcher(id, appType),
6202
+ isMainChunk,
6008
6203
  uniAppXCssTarget: isNativeAppBuildTarget(id) ? resolveUniAppXCssTarget(id) : void 0,
6204
+ uniAppXCssSource: isNativeAppBuildTarget(id) ? source : void 0,
6009
6205
  uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
6010
6206
  postcssOptions: { options: {
6011
6207
  from: id,
@@ -6025,16 +6221,24 @@ function createUniAppXPlugins(options) {
6025
6221
  for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
6026
6222
  }
6027
6223
  async function transformStyle(code, id, query, hookContext) {
6028
- isNativeAppBuildTarget(id);
6224
+ const isNativeStyle = isNativeAppBuildTarget(id);
6029
6225
  const parsed = query ?? parseVueRequest(id).query;
6030
6226
  if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
6031
6227
  if (isCssModuleExport(code)) return;
6032
- const shouldGenerateCss = require_generator.hasTailwindSourceDirectives(code, { importFallback: true }) || require_generator.hasTailwindApplyDirective(code);
6033
- if (!isNativeAppBuildTarget(id) && !shouldGenerateCss) return;
6228
+ const hasTailwindRoot = require_generator.hasTailwindRootDirectives(code, { importFallback: true });
6229
+ const hasTailwindApply = require_generator.hasTailwindApplyDirective(code);
6230
+ const shouldGenerateCss = hasTailwindRoot || hasTailwindApply;
6231
+ const isNativeSfcAuthorStyle = isNativeStyle && resolveUniAppXCssTarget(id) === "uvue";
6232
+ if (!shouldGenerateCss && (!isNativeStyle || isNativeSfcAuthorStyle)) return;
6034
6233
  harmonyApply.rememberSource(code, id);
6035
- const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
6036
- const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
6037
- const styleHandlerOptions = getStyleHandlerOptions(id);
6234
+ const generatedCss = shouldGenerateCss ? await generateCss?.(id, isNativeSfcAuthorStyle && hasTailwindApply && !hasTailwindRoot ? harmonyApply.prepareStyles(code, id) : code, {
6235
+ ...hookContext,
6236
+ disableSourceScan: isNativeSfcAuthorStyle && hasTailwindApply && !hasTailwindRoot,
6237
+ sourceCandidates: isNativeSfcAuthorStyle && hasTailwindApply && !hasTailwindRoot ? [] : void 0,
6238
+ transient: isNativeSfcAuthorStyle && hasTailwindApply && !hasTailwindRoot
6239
+ }) : void 0;
6240
+ const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? hasTailwindApply && !hasTailwindRoot ? retainUniAppXAuthorApplyCss(generatedCss, code) : generatedCss : code;
6241
+ const styleHandlerOptions = getStyleHandlerOptions(id, isNativeStyle && hasTailwindRoot ? "tailwind-root" : isNativeStyle ? "author-apply" : void 0);
6038
6242
  const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
6039
6243
  reportStyleWarnings(postcssResult);
6040
6244
  const postcssMap = await formatPostcssSourceMap(postcssResult.map.toJSON(), normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
@@ -6049,7 +6253,7 @@ function createUniAppXPlugins(options) {
6049
6253
  getResolvedConfig,
6050
6254
  isHarmonyBuildTarget,
6051
6255
  async transformCss(css, id) {
6052
- const result = await styleHandler(css, getStyleHandlerOptions(id));
6256
+ const result = await styleHandler(css, getStyleHandlerOptions(id, "author-apply"));
6053
6257
  reportStyleWarnings(result);
6054
6258
  return result.css;
6055
6259
  }
@@ -6086,40 +6290,46 @@ function createUniAppXPlugins(options) {
6086
6290
  if (!isEnabled()) return;
6087
6291
  await nativeHmrReloader.refreshBaseline();
6088
6292
  },
6089
- async transform(code, id) {
6090
- if (!isEnabled()) return;
6091
- if (!UVUE_NVUE_QUERY_RE.test(id)) return;
6092
- isNativeAppBuildTarget(id);
6093
- harmonyApply.rememberSource(code, id);
6094
- const resolvedConfig = getResolvedConfig();
6095
- const isServeCommand = resolvedConfig?.command === "serve";
6096
- const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
6097
- const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
6098
- const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
6099
- nativeHmrReloader.remember(currentRuntimeSet);
6100
- const transformUVue = await loadTransformUVue();
6101
- const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
6102
- const enablePageLocalStyle = shouldEnableNativePageLocalStyle(id);
6103
- const result = customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle ? transformUVue(code, id, jsHandler, currentRuntimeSet, require_object.omitUndefined({
6104
- ...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
6105
- ...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
6106
- ...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
6107
- ...enablePageLocalStyle ? { enablePageLocalStyle } : {}
6108
- })) : transformUVue(code, id, jsHandler, currentRuntimeSet);
6109
- if (result?.code) {
6110
- harmonyApply.rememberSource(result.code, id);
6111
- const expandedCode = await harmonyApply.expandStyles(result.code, id, this);
6112
- if (expandedCode !== result.code) return {
6113
- code: expandedCode,
6114
- map: null
6115
- };
6293
+ transform: {
6294
+ order: "pre",
6295
+ async handler(code, id) {
6296
+ if (!isEnabled()) return;
6297
+ if (!UVUE_NVUE_QUERY_RE.test(id)) return;
6298
+ if (isNativeAppBuildTarget(id)) {
6299
+ nativeLocalStyleModuleIds.add(id);
6300
+ nativeLocalStyleModuleIds.add((0, _weapp_tailwindcss_shared.cleanUrl)(id));
6301
+ }
6302
+ harmonyApply.rememberSource(code, id, true);
6303
+ const resolvedConfig = getResolvedConfig();
6304
+ const isServeCommand = resolvedConfig?.command === "serve";
6305
+ const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
6306
+ const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
6307
+ const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
6308
+ nativeHmrReloader.remember(currentRuntimeSet);
6309
+ const transformUVue = await loadTransformUVue();
6310
+ const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
6311
+ const enablePageLocalStyle = shouldEnableNativePageLocalStyle(id);
6312
+ const result = customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle ? transformUVue(code, id, jsHandler, currentRuntimeSet, require_object.omitUndefined({
6313
+ ...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
6314
+ ...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
6315
+ ...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
6316
+ ...enablePageLocalStyle ? { enablePageLocalStyle } : {}
6317
+ })) : transformUVue(code, id, jsHandler, currentRuntimeSet);
6318
+ if (result?.code) {
6319
+ harmonyApply.rememberSource(result.code, id);
6320
+ const expandedCode = await harmonyApply.expandStyles(result.code, id, this);
6321
+ if (expandedCode !== result.code) return {
6322
+ code: expandedCode,
6323
+ map: null
6324
+ };
6325
+ }
6326
+ return result;
6116
6327
  }
6117
- return result;
6118
6328
  },
6119
6329
  async handleHotUpdate(ctx) {
6120
6330
  if (!isEnabled()) return;
6121
6331
  if (getResolvedConfig()?.command !== "serve") return;
6122
- if (!UVUE_NVUE_RE.test(ctx.file)) return;
6332
+ if (!UVUE_NVUE_RE.test(ctx.file) && !isCSSRequest(ctx.file)) return;
6123
6333
  return nativeHmrReloader.handleHotUpdate(ctx);
6124
6334
  },
6125
6335
  async watchChange(id) {
@@ -6148,7 +6358,12 @@ function createUniAppXPlugins(options) {
6148
6358
  const applyUtilities = /* @__PURE__ */ new Set([...harmonyApply.utilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
6149
6359
  if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
6150
6360
  const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
6151
- const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
6361
+ const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), {
6362
+ addWatchFile: this?.addWatchFile?.bind(this),
6363
+ disableSourceScan: true,
6364
+ sourceCandidates: [],
6365
+ transient: true
6366
+ });
6152
6367
  if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
6153
6368
  }
6154
6369
  injectUniAppXHarmonyBundleStyles(bundle, {
@@ -7807,11 +8022,16 @@ function createViteCssFinalizerOutputPlugin(context) {
7807
8022
  const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
7808
8023
  const outDir = resolvedConfig?.build?.outDir ? node_path.default.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
7809
8024
  const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
8025
+ const finalCssAssetFiles = /* @__PURE__ */ new Set();
8026
+ const trackFinalCssAssetUpdate = (file, original, generated) => {
8027
+ finalCssAssetFiles.add(file);
8028
+ opts.onUpdate(file, original, generated);
8029
+ };
7810
8030
  restoreFrameworkRootMiniProgramImportShellAssets(bundle, {
7811
8031
  debug,
7812
8032
  isWebGeneratorTarget,
7813
8033
  matchesCss: opts.cssMatcher,
7814
- onUpdate: opts.onUpdate,
8034
+ onUpdate: trackFinalCssAssetUpdate,
7815
8035
  recordCssAssetResult,
7816
8036
  shouldKeep: (file, css) => cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
7817
8037
  ...createCssPipelineContext(file),
@@ -7834,6 +8054,7 @@ function createViteCssFinalizerOutputPlugin(context) {
7834
8054
  markCssAssetProcessed,
7835
8055
  recordCssAssetResult,
7836
8056
  recordViteProcessedCssAssetResult,
8057
+ onAssetWrite: (file) => finalCssAssetFiles.add(file),
7837
8058
  resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
7838
8059
  transformCss: (css, file) => finalizeWebCss(css, {
7839
8060
  ...createCssPipelineContext(file),
@@ -7855,16 +8076,15 @@ function createViteCssFinalizerOutputPlugin(context) {
7855
8076
  file
7856
8077
  }, cssPipelineStrategy),
7857
8078
  debug,
7858
- onUpdate: opts.onUpdate
8079
+ onUpdate: trackFinalCssAssetUpdate
7859
8080
  });
7860
8081
  };
7861
8082
  collectViteProcessedCssAssets();
7862
- const createHarmonyBundleStyleSources = async (runtime) => {
8083
+ const createHarmonyBundleStyleSources = async () => {
7863
8084
  const cssSources = collectViteProcessedCssSources(getViteProcessedCssAssetResults);
7864
8085
  const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
7865
8086
  const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
7866
8087
  if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
7867
- const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
7868
8088
  const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
7869
8089
  ...createCssPipelineContext("uni-app-x-harmony-apply.css"),
7870
8090
  file: "uni-app-x-harmony-apply.css"
@@ -7872,7 +8092,7 @@ function createViteCssFinalizerOutputPlugin(context) {
7872
8092
  const generated = await require_v4_generation_core.generateTailwindV4Css({
7873
8093
  opts,
7874
8094
  runtimeState,
7875
- runtime: harmonyRuntime,
8095
+ runtime: /* @__PURE__ */ new Set(),
7876
8096
  rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
7877
8097
  file: "uni-app-x-harmony-apply.css",
7878
8098
  outputFile: "uni-app-x-harmony-apply.css",
@@ -7882,6 +8102,7 @@ function createViteCssFinalizerOutputPlugin(context) {
7882
8102
  isMainChunk: false
7883
8103
  },
7884
8104
  cssStage: "framework-processed",
8105
+ disableSourceScan: true,
7885
8106
  getSourceCandidatesForEntries,
7886
8107
  generatorPlatform,
7887
8108
  styleHandler: opts.styleHandler,
@@ -7890,9 +8111,9 @@ function createViteCssFinalizerOutputPlugin(context) {
7890
8111
  if (generated?.css) cssSources.push(annotateCss(generated.css));
7891
8112
  return cssSources;
7892
8113
  };
7893
- const injectHarmonyBundleStyles = async (runtime) => {
8114
+ const injectHarmonyBundleStyles = async () => {
7894
8115
  if (!isHarmonyAppStyleTarget) return;
7895
- if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
8116
+ if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources() })) debug("uni-app-x harmony bundle styles inject");
7896
8117
  };
7897
8118
  const isCssOutputAssetEntry = (entry) => {
7898
8119
  const [bundleFile, output] = entry;
@@ -7908,6 +8129,14 @@ function createViteCssFinalizerOutputPlugin(context) {
7908
8129
  cssMatcher: opts.cssMatcher,
7909
8130
  debug,
7910
8131
  enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
8132
+ onUpdate: trackFinalCssAssetUpdate,
8133
+ recordCssAssetResult
8134
+ });
8135
+ finalizeMiniProgramCssAssetStructures(bundle, {
8136
+ cssMatcher: opts.cssMatcher,
8137
+ debug,
8138
+ files: finalCssAssetFiles,
8139
+ isWebGeneratorTarget,
7911
8140
  onUpdate: opts.onUpdate,
7912
8141
  recordCssAssetResult
7913
8142
  });
@@ -7923,6 +8152,7 @@ function createViteCssFinalizerOutputPlugin(context) {
7923
8152
  const writeTargets = /* @__PURE__ */ new Map();
7924
8153
  const writeCssAsset = (file, output, source) => {
7925
8154
  emissionPlan.write(file, source);
8155
+ finalCssAssetFiles.add(file);
7926
8156
  writeTargets.set(file, output);
7927
8157
  };
7928
8158
  await Promise.all(entries.map(async ([bundleFile, output]) => {
@@ -8020,13 +8250,21 @@ function createViteCssFinalizerOutputPlugin(context) {
8020
8250
  bundle,
8021
8251
  writeTargets
8022
8252
  });
8023
- await injectHarmonyBundleStyles(generatorRuntime);
8253
+ await injectHarmonyBundleStyles();
8024
8254
  collectViteProcessedCssAssets();
8025
8255
  injectViteProcessedCssIntoMainCss();
8026
8256
  normalizeRootMiniProgramImportShellAssets(bundle, {
8027
8257
  cssMatcher: opts.cssMatcher,
8028
8258
  debug,
8029
8259
  enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
8260
+ onUpdate: trackFinalCssAssetUpdate,
8261
+ recordCssAssetResult
8262
+ });
8263
+ finalizeMiniProgramCssAssetStructures(bundle, {
8264
+ cssMatcher: opts.cssMatcher,
8265
+ debug,
8266
+ files: finalCssAssetFiles,
8267
+ isWebGeneratorTarget,
8030
8268
  onUpdate: opts.onUpdate,
8031
8269
  recordCssAssetResult
8032
8270
  });
@@ -8575,6 +8813,7 @@ function createViteCssGenerationPlugins(options) {
8575
8813
  async transform(code, id) {
8576
8814
  if (!options.shouldGenerate() || options.shouldGenerateBuild?.() === false || !isViteBuildStyleRequest(id, options.getCommand())) return;
8577
8815
  if (!hasViteCssGenerationDirective(code)) return;
8816
+ if (options.shouldDeferGeneration?.(id, code)) return;
8578
8817
  if (hasViteServeCssRootDirective(code)) await options.onTailwindRootCss?.(id, code);
8579
8818
  const generatedCss = await options.generateCss(id, code, {
8580
8819
  ...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
@@ -8731,15 +8970,19 @@ function createViteHmrCandidateState(options) {
8731
8970
  const createChange = (file, change, changeOptions = {}) => ({
8732
8971
  ...change,
8733
8972
  file,
8734
- runtimeAffecting: changeOptions.runtimeAffecting === true || require_v4_generation_core.isSourceStyleRequest(file) || WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE.test(options.getSourceCandidate(file) ?? "")
8973
+ runtimeAffecting: changeOptions.runtimeAffecting === true || options.isRuntimeAffectingSource?.(file) === true || require_v4_generation_core.isSourceStyleRequest(file) || WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE.test(options.getSourceCandidate(file) ?? "")
8735
8974
  });
8736
8975
  const apply = (change) => {
8737
8976
  if (require_v4_generation_core.isSourceStyleRequest(change.file)) {
8738
8977
  clear();
8739
8978
  return change;
8740
8979
  }
8980
+ if (change.runtimeAffecting) {
8981
+ queueFullRegeneration();
8982
+ return change;
8983
+ }
8741
8984
  const preserveDeletedCss = options.getGeneratorOptions().hmr.preserveDeletedCss;
8742
- if (preserveDeletedCss && !change.runtimeAffecting) {
8985
+ if (preserveDeletedCss) {
8743
8986
  if (change.addedCandidates.size > 0) queueChange(change);
8744
8987
  else if (!pendingChange) clear();
8745
8988
  return change;
@@ -8999,6 +9242,11 @@ function sameStringList(first, second) {
8999
9242
  //#endregion
9000
9243
  //#region src/bundlers/vite/shared/framework-source-candidates-plugin.ts
9001
9244
  function createFrameworkSourceCandidatesPlugin(options) {
9245
+ const hasDifferentHotModules = (left, right) => left.length !== right.length || left.some((mod, index) => mod !== right[index]);
9246
+ const hasTemplateHotSourceModule = (modules) => modules.some((mod) => {
9247
+ const request = mod.url ?? mod.id;
9248
+ return typeof request === "string" && /\.(?:uvue|nvue)(?:\?import)?$/i.test(request);
9249
+ });
9002
9250
  return {
9003
9251
  name: `${require_context.vitePluginName}:source-candidates`,
9004
9252
  enforce: "pre",
@@ -9064,60 +9312,68 @@ function createFrameworkSourceCandidatesPlugin(options) {
9064
9312
  await options.sourceScanSession.syncChangedFile(id, changedSource);
9065
9313
  }, { emit: false });
9066
9314
  },
9067
- async handleHotUpdate(ctx) {
9068
- require_v4_generation_core.recordCompilationDependencyChanges(options.runtimeState, require_v4_generation_core.createCompilationDependencyChanges([node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(ctx.file))]));
9069
- return options.hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
9070
- const isSourceCandidateHotUpdate = options.shouldOwnTailwindGeneration && require_v4_generation_core.isSourceCandidateRequest(ctx.file);
9071
- if (isSourceCandidateHotUpdate && require_v4_generation_core.isSourceStyleRequest(ctx.file)) {
9072
- for (const mod of ctx.modules) for (const id of [
9073
- mod.id,
9074
- mod.url,
9075
- mod.file
9076
- ]) if (typeof id === "string" && id.length > 0) options.rememberTailwindRootCssModule(id);
9077
- }
9078
- const hotSource = isSourceCandidateHotUpdate && typeof ctx.read === "function" ? await ctx.read().catch(() => void 0) : void 0;
9079
- if (typeof hotSource === "string" && isCSSRequest(ctx.file)) {
9080
- options.rememberOriginalCssLayerSource(ctx.file, hotSource);
9081
- await options.refreshTailwindRootCssSource(ctx.file, hotSource);
9082
- }
9083
- const sourceCandidateChange = await options.sourceScanSession.syncChangedFile(ctx.file, hotSource);
9084
- const isWebLikeHotUpdate = options.isCurrentWebLikeStylePlatform();
9085
- let canUseHmrCandidateAppend = false;
9086
- if (isSourceCandidateHotUpdate) {
9087
- options.invalidateRecordedGeneratorCandidates();
9088
- const preserveDeletedCssInHmr = options.resolveCurrentGeneratorOptions().hmr.preserveDeletedCss;
9089
- canUseHmrCandidateAppend = preserveDeletedCssInHmr && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting;
9090
- if (!canUseHmrCandidateAppend) {
9091
- if (sourceCandidateChange === void 0) {
9092
- options.hmrCandidateState.clear();
9093
- if (!preserveDeletedCssInHmr && !require_v4_generation_core.isSourceStyleRequest(ctx.file)) options.hmrCandidateState.queueFullRegeneration();
9094
- }
9095
- if (isWebLikeHotUpdate) {
9096
- await options.refreshRuntimeStateForAutoCssSources?.(true);
9097
- await options.sourceScanSession.sync({ force: true });
9315
+ handleHotUpdate: {
9316
+ order: "post",
9317
+ async handler(ctx) {
9318
+ require_v4_generation_core.recordCompilationDependencyChanges(options.runtimeState, require_v4_generation_core.createCompilationDependencyChanges([node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(ctx.file))]));
9319
+ return options.hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
9320
+ const isSourceCandidateHotUpdate = options.shouldOwnTailwindGeneration && require_v4_generation_core.isSourceCandidateRequest(ctx.file);
9321
+ if (isSourceCandidateHotUpdate && require_v4_generation_core.isSourceStyleRequest(ctx.file)) {
9322
+ for (const mod of ctx.modules) for (const id of [
9323
+ mod.id,
9324
+ mod.url,
9325
+ mod.file
9326
+ ]) if (typeof id === "string" && id.length > 0) options.rememberTailwindRootCssModule(id);
9327
+ }
9328
+ const hotSource = isSourceCandidateHotUpdate && typeof ctx.read === "function" ? await ctx.read().catch(() => void 0) : void 0;
9329
+ if (typeof hotSource === "string" && isCSSRequest(ctx.file)) {
9330
+ options.rememberOriginalCssLayerSource(ctx.file, hotSource);
9331
+ await options.refreshTailwindRootCssSource(ctx.file, hotSource);
9332
+ }
9333
+ const sourceCandidateChange = await options.sourceScanSession.syncChangedFile(ctx.file, hotSource);
9334
+ const isWebLikeHotUpdate = options.isCurrentWebLikeStylePlatform();
9335
+ let canUseHmrCandidateAppend = false;
9336
+ if (isSourceCandidateHotUpdate) {
9337
+ options.invalidateRecordedGeneratorCandidates();
9338
+ const preserveDeletedCssInHmr = options.resolveCurrentGeneratorOptions().hmr.preserveDeletedCss;
9339
+ canUseHmrCandidateAppend = preserveDeletedCssInHmr && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting;
9340
+ if (!canUseHmrCandidateAppend) {
9341
+ if (sourceCandidateChange === void 0) {
9342
+ options.hmrCandidateState.clear();
9343
+ if (!preserveDeletedCssInHmr && !require_v4_generation_core.isSourceStyleRequest(ctx.file)) options.hmrCandidateState.queueFullRegeneration();
9344
+ }
9345
+ if (isWebLikeHotUpdate) {
9346
+ await options.refreshRuntimeStateForAutoCssSources?.(true);
9347
+ await options.sourceScanSession.sync({ force: true });
9348
+ }
9098
9349
  }
9099
9350
  }
9100
- }
9101
- if (isSourceCandidateHotUpdate) await options.sourceScanSession.waitForPendingSyncs();
9102
- const cssModules = resolveHotTailwindCssModules(ctx, options.tailwindRootCssModuleIds);
9103
- const sourceModules = isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) ? resolveHotSourceModules(ctx) : ctx.modules;
9104
- const hasHmrCandidateAppend = options.hmrCandidateState.hasPendingCandidateAppend() || canUseHmrCandidateAppend && sourceCandidateChange !== void 0 && sourceCandidateChange.addedCandidates.size > 0;
9105
- if (isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && !hasHmrCandidateAppend && !isWebLikeHotUpdate && (!hasSelfAcceptingNonStyleHotModule(sourceModules) && cssModules.length === 0 || cssModules.length > 0 && options.isUniViteProject())) {
9106
- sendFullReloadForUnresolvedHotUpdate(ctx);
9107
- return [];
9108
- }
9109
- if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && ctx.modules.some((mod) => options.isNuxtPageMacroHotModule(mod.id ?? mod.url))) {
9110
- sendFullReloadForUnresolvedHotUpdate(ctx);
9111
- return [];
9112
- }
9113
- const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && options.resolveCurrentGeneratorOptions().hmr.preserveDeletedCss && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting && sourceCandidateChange.addedCandidates.size === 0 && sourceCandidateChange.removedCandidates.size > 0);
9114
- const supplementalCssFallbackIds = /* @__PURE__ */ new Set([...options.tailwindRootCssModuleIds, ...options.viteProcessedCssSourceFiles]);
9115
- if (hasHmrCandidateAppend) options.hmrCandidateState.armTargets(cssModules, supplementalCssFallbackIds);
9116
- if (shouldSendSupplementalCssHotUpdates) sendSupplementalCssHotUpdates(ctx, cssModules, supplementalCssFallbackIds);
9117
- if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file)) return;
9118
- if (isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && cssModules.length > 0) return [...sourceModules, ...cssModules];
9119
- return cssModules.length > 0 ? [...ctx.modules, ...cssModules] : void 0;
9120
- }, { emit: false });
9351
+ if (isSourceCandidateHotUpdate) await options.sourceScanSession.waitForPendingSyncs();
9352
+ const cssModules = await resolveHotTailwindCssModules(ctx, require_v4_generation_core.isSourceStyleRequest(ctx.file) ? [ctx.file] : options.tailwindRootCssModuleIds);
9353
+ const hotRoot = ctx.server.config?.root ?? node_process.default.cwd();
9354
+ const sourceModules = isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) ? await resolveHotSourceModules(ctx) : ctx.modules;
9355
+ const hasHmrCandidateAppend = options.hmrCandidateState.hasPendingCandidateAppend() || canUseHmrCandidateAppend && sourceCandidateChange !== void 0 && sourceCandidateChange.addedCandidates.size > 0;
9356
+ if (isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && !hasHmrCandidateAppend && !isWebLikeHotUpdate && (!hasSelfAcceptingNonStyleHotModule(sourceModules) && cssModules.length === 0 || cssModules.length > 0 && options.isUniViteProject())) {
9357
+ sendFullReloadForUnresolvedHotUpdate(ctx);
9358
+ return [];
9359
+ }
9360
+ if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && sourceModules.some((mod) => options.isNuxtPageMacroHotModule(mod.id ?? mod.url))) {
9361
+ sendFullReloadForUnresolvedHotUpdate(ctx);
9362
+ return [];
9363
+ }
9364
+ if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && /\.(?:uvue|nvue)$/i.test((0, _weapp_tailwindcss_shared.cleanUrl)(ctx.file)) && !hasTemplateHotSourceModule(sourceModules)) {
9365
+ sendFullReloadForUnresolvedHotUpdate(ctx);
9366
+ return [];
9367
+ }
9368
+ const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && options.resolveCurrentGeneratorOptions().hmr.preserveDeletedCss && !sourceCandidateChange.runtimeAffecting && sourceCandidateChange.addedCandidates.size === 0 && sourceCandidateChange.removedCandidates.size > 0);
9369
+ const supplementalCssFallbackIds = /* @__PURE__ */ new Set([...options.tailwindRootCssModuleIds, ...options.viteProcessedCssSourceFiles]);
9370
+ if (hasHmrCandidateAppend) options.hmrCandidateState.armTargets(cssModules, supplementalCssFallbackIds);
9371
+ if (shouldSendSupplementalCssHotUpdates) sendSupplementalCssHotUpdates(ctx, cssModules, supplementalCssFallbackIds);
9372
+ if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file)) return cssModules.length > 0 ? mergeHotModulesByIdentity(hotRoot, sourceModules, cssModules) : hasDifferentHotModules(sourceModules, ctx.modules) ? sourceModules : void 0;
9373
+ if (isSourceCandidateHotUpdate && !require_v4_generation_core.isSourceStyleRequest(ctx.file) && cssModules.length > 0) return mergeHotModulesByIdentity(hotRoot, sourceModules, cssModules);
9374
+ return cssModules.length > 0 ? mergeHotModulesByIdentity(hotRoot, ctx.modules, cssModules) : void 0;
9375
+ }, { emit: false });
9376
+ }
9121
9377
  },
9122
9378
  async buildStart() {
9123
9379
  await options.hmrTimingRecorder.measure("sourceCandidates.buildStart", options.prepareTailwindGeneration, { emit: false });
@@ -9129,6 +9385,11 @@ function createFrameworkSourceCandidatesPlugin(options) {
9129
9385
  //#region src/bundlers/vite/shared/framework-source-scan-session.ts
9130
9386
  const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
9131
9387
  const sourceCandidateScanSnapshotCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
9388
+ async function syncFrameworkSourceCandidatesForHotUpdate(sourceScanSession, ctx) {
9389
+ const source = typeof ctx.read === "function" ? await ctx.read().catch(() => void 0) : void 0;
9390
+ await sourceScanSession.syncChangedFile(ctx.file, source);
9391
+ await sourceScanSession.waitForPendingSyncs();
9392
+ }
9132
9393
  function createFrameworkSourceScanSession(options) {
9133
9394
  const sourceCandidateScanCache = new lru_cache.LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
9134
9395
  let sourceScanEntries;
@@ -9291,12 +9552,12 @@ function createFrameworkSourceScanSession(options) {
9291
9552
  function createFrameworkTailwindRootCss(options) {
9292
9553
  const hotSourceByFile = /* @__PURE__ */ new Map();
9293
9554
  const moduleIds = /* @__PURE__ */ new Set();
9294
- const normalizeSourceFile = (id) => node_path.default.normalize(node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
9555
+ const normalizeSourceFile = (id) => resolveViteModuleIdentity(id).key;
9295
9556
  const rememberModule = (id) => {
9296
9557
  if (!options.shouldOwnTailwindGeneration || typeof id !== "string" || id.length === 0) return;
9297
9558
  moduleIds.add(id);
9298
- const cleanId = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
9299
- if (require_v4_generation_core.isSourceStyleRequest(cleanId)) moduleIds.add(cleanId);
9559
+ const identity = resolveViteModuleIdentity(id);
9560
+ if (require_v4_generation_core.isSourceStyleRequest(identity.cleanId)) for (const moduleId of identity.lookupIds) moduleIds.add(moduleId);
9300
9561
  };
9301
9562
  const register = async (id, code) => {
9302
9563
  rememberModule(id);
@@ -9600,7 +9861,8 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
9600
9861
  generatedClassSetByFile,
9601
9862
  getCommand: () => resolvedConfig?.command,
9602
9863
  getGeneratorOptions: resolveCurrentGeneratorOptions,
9603
- getSourceCandidate: (file) => sourceCandidateCollector.source(file)
9864
+ getSourceCandidate: (file) => sourceCandidateCollector.source(file),
9865
+ isRuntimeAffectingSource: (file) => uniAppXEnabled && /\.(?:uvue|nvue)$/i.test((0, _weapp_tailwindcss_shared.cleanUrl)(file))
9604
9866
  });
9605
9867
  const sourceScanSession = createFrameworkSourceScanSession({
9606
9868
  cssMemory,
@@ -9709,7 +9971,7 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
9709
9971
  const transient = hookContext?.transient === true;
9710
9972
  const pendingHmrChange = transient ? void 0 : hmrCandidateState.resolve(generatorCode, file);
9711
9973
  const forceFullHmrCssRegeneration = hmrCandidateState.shouldForceFullRegeneration(pendingHmrChange !== void 0);
9712
- const runtime = fullRuntime;
9974
+ const runtime = hookContext?.sourceCandidates === void 0 ? fullRuntime : new Set(hookContext.sourceCandidates);
9713
9975
  const importShellCss = resolveViteServeRootMiniProgramImportShell({
9714
9976
  css: generatorTransformCode,
9715
9977
  cssPipelineContext,
@@ -9782,8 +10044,8 @@ ${previousTracedCss}`;
9782
10044
  previousCss: previousGeneratorCss,
9783
10045
  previousClassSet: pendingHmrChange && !forceFullHmrCssRegeneration ? generatedClassSetByFile.get(fileKey) : void 0,
9784
10046
  deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
9785
- deferCssAdaptation: !currentGeneratorBranch.isWeb && !shouldAdaptFrameworkWatchCss(),
9786
- disableSourceScan: false,
10047
+ deferCssAdaptation: !transient && !currentGeneratorBranch.isWeb && !shouldAdaptFrameworkWatchCss(),
10048
+ disableSourceScan: hookContext?.disableSourceScan === true,
9787
10049
  cssStage: hookContext?.cssStage,
9788
10050
  restoreLocalCssImports: !currentGeneratorBranch.isWeb
9789
10051
  }), {
@@ -9837,7 +10099,7 @@ ${previousTracedCss}`;
9837
10099
  source: tracedCss
9838
10100
  });
9839
10101
  markViteProcessedCssSource(file);
9840
- rememberTailwindRootCssModule(id);
10102
+ if (require_generator.hasTailwindRootDirectives(generatorTransformCode, { importFallback: currentGeneratorOptions.importFallback })) rememberTailwindRootCssModule(id);
9841
10103
  recordGeneratorCandidates(fullRuntime);
9842
10104
  if (pendingHmrChange) hmrCandidateState.finishTarget(file);
9843
10105
  else if (!hmrCandidateState.hasPendingChange()) hmrCandidateState.clear();
@@ -9850,6 +10112,11 @@ ${previousTracedCss}`;
9850
10112
  return `${require_v4_generation_core.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
9851
10113
  ${tracedCss}`;
9852
10114
  };
10115
+ const shouldDeferFrameworkPreTransformGeneration = (id, code) => frameworkCssPipelineStrategy?.shouldDeferPreTransformTailwindGeneration?.({
10116
+ ...createCssPipelineContext(),
10117
+ code,
10118
+ id
10119
+ }) === true;
9853
10120
  const rewritePlugins = createRewriteCssImportsPlugins({
9854
10121
  getAppType: () => opts.appType,
9855
10122
  generateTailwindCss: generateTailwindCssForVitePipeline,
@@ -9857,7 +10124,7 @@ ${tracedCss}`;
9857
10124
  onTailwindRootCss: registerTailwindRootCss,
9858
10125
  onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
9859
10126
  shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
9860
- shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && require_generator.hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }),
10127
+ shouldDeferGeneration: (id, code) => !shouldRewriteCssImports && require_generator.hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }) || shouldDeferFrameworkPreTransformGeneration(id, code),
9861
10128
  shouldOwnTailwindGeneration,
9862
10129
  shouldRewrite: shouldRewriteCssImports,
9863
10130
  weappTailwindcssDirPosix
@@ -9940,6 +10207,7 @@ ${tracedCss}`;
9940
10207
  getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
9941
10208
  });
9942
10209
  const extraPluginPlatform = frameworkBranch.getExtraPluginPlatform?.() ?? {};
10210
+ const syncSourceCandidatesForHotUpdate = (ctx) => syncFrameworkSourceCandidatesForHotUpdate(sourceScanSession, ctx);
9943
10211
  const prepareTailwindGeneration = async () => {
9944
10212
  if (sourceScanSession.shouldDiscoverAutoCssSources(autoCssSourcesDiscovered)) await discoverAndRegisterAutoCssSources();
9945
10213
  await sourceScanSession.sync();
@@ -9956,6 +10224,7 @@ ${tracedCss}`;
9956
10224
  mainCssChunkMatcher,
9957
10225
  runtimeState,
9958
10226
  styleHandler,
10227
+ syncSourceCandidatesForHotUpdate,
9959
10228
  tailwindRootCssModuleIds,
9960
10229
  uniAppX,
9961
10230
  viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles
@@ -10025,12 +10294,14 @@ ${tracedCss}`;
10025
10294
  syncCssEntriesFromAnchor
10026
10295
  });
10027
10296
  const plugins = [
10297
+ ...extraPlugins,
10028
10298
  ...rewritePlugins,
10029
10299
  sourceCandidatesPlugin,
10030
10300
  ...createViteCssGenerationPlugins({
10031
10301
  generateCss: generateTailwindCssForVitePipeline,
10032
10302
  getCommand: () => resolvedConfig?.command,
10033
10303
  onTailwindRootCss: registerTailwindRootCss,
10304
+ shouldDeferGeneration: shouldDeferFrameworkPreTransformGeneration,
10034
10305
  shouldGenerate: () => shouldOwnTailwindGeneration,
10035
10306
  shouldGenerateBuild: () => resolveCurrentGeneratorBranch().isWeb
10036
10307
  }),
@@ -10053,7 +10324,6 @@ ${tracedCss}`;
10053
10324
  },
10054
10325
  postPlugin
10055
10326
  ];
10056
- plugins.push(...extraPlugins);
10057
10327
  plugins.push(cssFinalizerOutputPlugin);
10058
10328
  plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
10059
10329
  return plugins;
@@ -10315,7 +10585,8 @@ function resolveUniAppXNativeCssHandlerOptions(opts) {
10315
10585
  //#endregion
10316
10586
  //#region src/bundlers/vite/frameworks/uni-app-x/index.ts
10317
10587
  function isUniAppXNativeAppStyleTarget(context) {
10318
- return require_generator.resolveUniUtsPlatform().isApp || isUniAppXNativeAppOutDir(context?.resolvedConfig?.build?.outDir) || isUniAppXNativeAppOutDir(context?.resolvedConfig?.root);
10588
+ const stylePlatform = context?.resolveStylePlatform?.();
10589
+ return require_generator.resolveUniUtsPlatform().isApp || stylePlatform === "app" || stylePlatform === "app-plus" || stylePlatform?.startsWith("app-") === true || isUniAppXNativeAppOutDir(context?.resolvedConfig?.build?.outDir) || isUniAppXNativeAppOutDir(context?.resolvedConfig?.root);
10319
10590
  }
10320
10591
  function isUniAppXHarmonyAppStyleTarget(context) {
10321
10592
  const uniUtsPlatform = require_generator.resolveUniUtsPlatform();
@@ -10342,6 +10613,9 @@ const uniAppXCssPipelineStrategy = {
10342
10613
  if (!context.cssHandlerOptions.isMainChunk && require_generator.hasTailwindApplyDirective(context.generatorCode)) return false;
10343
10614
  return true;
10344
10615
  },
10616
+ shouldDeferPreTransformTailwindGeneration(context) {
10617
+ return resolveUniAppXCssTarget(context.id) === "uvue" && require_generator.hasTailwindApplyDirective(context.code) && !require_generator.hasTailwindRootDirectives(context.code, { importFallback: true });
10618
+ },
10345
10619
  transformGeneratedCss(css, context) {
10346
10620
  const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
10347
10621
  return withUniAppXWebPreflightReset(context.removeScopedPreflight(webCss), context.currentGeneratorBranch.isWeb);
@@ -10368,6 +10642,7 @@ function createUniAppXVitePlugins(options = {}) {
10368
10642
  mainCssChunkMatcher: context.mainCssChunkMatcher,
10369
10643
  runtimeState: context.runtimeState,
10370
10644
  styleHandler: context.styleHandler,
10645
+ syncSourceCandidatesForHotUpdate: context.syncSourceCandidatesForHotUpdate,
10371
10646
  tailwindRootCssModuleIds: context.tailwindRootCssModuleIds,
10372
10647
  uniAppX: context.uniAppX,
10373
10648
  viteProcessedCssSourceFiles: context.viteProcessedCssSourceFiles