weapp-tailwindcss 5.1.2 → 5.1.4

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 (75) hide show
  1. package/README.md +1 -1
  2. package/dist/auto-CrJJc5rK.mjs +13 -0
  3. package/dist/bundlers/gulp/index.d.ts +3 -3
  4. package/dist/bundlers/rspack/index.d.ts +20 -0
  5. package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -10
  6. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
  7. package/dist/bundlers/vite/css-memory.d.ts +1 -0
  8. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
  9. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -1
  10. package/dist/bundlers/vite/generate-bundle/temporary-css-assets.d.ts +12 -0
  11. package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -0
  12. package/dist/bundlers/vite/processed-css-assets.d.ts +1 -0
  13. package/dist/bundlers/vite/serve-js-transform.d.ts +11 -0
  14. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +4 -1
  15. package/dist/cli.js +8 -8
  16. package/dist/cli.mjs +8 -8
  17. package/dist/{context-C-r8ki7x.mjs → context-Bkpmt3ja.mjs} +62 -36
  18. package/dist/{context-CH4HFZP2.js → context-DCVMkTRj.js} +76 -44
  19. package/dist/core.js +1 -1
  20. package/dist/core.mjs +1 -1
  21. package/dist/css-macro/auto.d.ts +1 -1
  22. package/dist/css-macro/postcss.js +2 -2
  23. package/dist/css-macro.js +3 -3
  24. package/dist/css-macro.mjs +1 -1
  25. package/dist/{defaults-CmFBmxsr.js → defaults-DQhgnnn-.js} +1 -1
  26. package/dist/defaults.js +1 -1
  27. package/dist/framework/index.d.ts +7 -2
  28. package/dist/framework/platform.d.ts +2 -0
  29. package/dist/framework.js +39 -8
  30. package/dist/framework.mjs +33 -6
  31. package/dist/{generator-BsPIaLtV.mjs → generator-24-HgU9F.mjs} +5 -3
  32. package/dist/{generator-B6pUjNdD.js → generator-CilgHtxb.js} +6 -4
  33. package/dist/generator.js +2 -2
  34. package/dist/generator.mjs +2 -2
  35. package/dist/{gulp-CTdcASq8.mjs → gulp-0RsqkF_d.mjs} +4 -4
  36. package/dist/{gulp-BBCeA7ky.js → gulp-Bogfnoki.js} +12 -11
  37. package/dist/gulp.js +1 -1
  38. package/dist/gulp.mjs +1 -1
  39. package/dist/{hmr-timing-BRx-KnBh.mjs → hmr-timing-BRNaz8Od.mjs} +62 -166
  40. package/dist/{hmr-timing-Da1eI8S0.js → hmr-timing-BV6nFPoT.js} +65 -187
  41. package/dist/index.js +9 -4
  42. package/dist/index.mjs +7 -6
  43. package/dist/postcss-html-transform.js +2 -2
  44. package/dist/postcss.js +2 -2
  45. package/dist/postcss.mjs +2 -2
  46. package/dist/presets/shared.d.ts +4 -0
  47. package/dist/presets.js +32 -16
  48. package/dist/presets.mjs +28 -14
  49. package/dist/reset.js +2 -2
  50. package/dist/rspack.d.ts +3 -0
  51. package/dist/rspack.js +68 -0
  52. package/dist/rspack.mjs +62 -0
  53. package/dist/{source-candidate-scan-signature-Dugfplms.mjs → source-candidate-scan-signature-BB1hvW68.mjs} +12 -6
  54. package/dist/{source-candidate-scan-signature-BO6JSskQ.js → source-candidate-scan-signature-CaDT0gkj.js} +16 -9
  55. package/dist/tailwindcss/v4-engine/css-macro-source.d.ts +2 -0
  56. package/dist/{tailwindcss-B5mRo0-M.mjs → tailwindcss-D0JF0fuZ.mjs} +6 -6
  57. package/dist/{tailwindcss-dbrbY4cd.js → tailwindcss-D2xs4OEu.js} +11 -11
  58. package/dist/{transform-DeqFRp1D.mjs → transform-BP86eSZp.mjs} +19 -19
  59. package/dist/{transform-BLleu_bA.js → transform-CXCQ28Tc.js} +47 -47
  60. package/dist/{utils-BCa37Wqj.js → utils-D3h8j7Mk.js} +2 -2
  61. package/dist/{v4-engine-C3qSwQ-e.mjs → v4-engine-BuuYDXt1.mjs} +58 -118
  62. package/dist/{v4-engine-ON_oSLfO.js → v4-engine-CKtsdKxK.js} +66 -120
  63. package/dist/{vite-CXmUiI9f.mjs → vite-B1SlBmqO.mjs} +436 -73
  64. package/dist/{vite-Da4uEG_u.js → vite-BYgT1ir9.js} +443 -80
  65. package/dist/vite.js +1 -1
  66. package/dist/vite.mjs +1 -1
  67. package/dist/weapp-tw-css-import-rewrite-loader.js +143 -216
  68. package/dist/weapp-tw-runtime-classset-loader.js +2 -2
  69. package/dist/{webpack-CrFZmdo7.mjs → webpack-Bg6pefpb.mjs} +109 -18
  70. package/dist/{webpack-Cwqnznng.js → webpack-khSwkXP5.js} +115 -24
  71. package/dist/webpack.js +1 -1
  72. package/dist/webpack.mjs +1 -1
  73. package/package.json +9 -4
  74. package/dist/auto-Ba6hDrse.mjs +0 -13
  75. /package/dist/{chunk-emK7D4bc.js → rolldown-runtime-emK7D4bc.js} +0 -0
@@ -1,17 +1,17 @@
1
1
  import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
2
- import { C as hasTailwindRootDirectives, D as normalizeTailwindSourceForGenerator, F as hasTailwindGeneratedCssMarkers, G as getTailwindV4IncrementalGenerateCacheStats, O as parseImportRequest, S as hasTailwindNonRootGenerationDirectives, T as normalizeTailwindConfigDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, b as hasLocalCssImport, d as normalizeCssEntries, f as findNearestPackageRoot, k as removeTailwindSourceDirectives, o as hasConfiguredTailwindV4CssRoots, ot as filterUnsupportedMiniProgramTailwindV4Candidates, rt as resolveTailwindV4CssSourceBase, s as upsertTailwindV4CssSource, st as omitUndefined, u as isTailwindV4CssEntry, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective } from "./v4-engine-C3qSwQ-e.mjs";
3
- import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-BsPIaLtV.mjs";
2
+ import { C as hasTailwindRootDirectives, D as normalizeTailwindSourceForGenerator, F as hasTailwindGeneratedCssMarkers, G as getTailwindV4IncrementalGenerateCacheStats, O as parseImportRequest, S as hasTailwindNonRootGenerationDirectives, T as normalizeTailwindConfigDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, b as hasLocalCssImport, ct as omitUndefined, d as normalizeCssEntries, f as findNearestPackageRoot, k as removeTailwindSourceDirectives, o as hasConfiguredTailwindV4CssRoots, rt as resolveTailwindV4CssSourceBase, s as upsertTailwindV4CssSource, st as filterUnsupportedMiniProgramTailwindV4Candidates, u as isTailwindV4CssEntry, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective } from "./v4-engine-BuuYDXt1.mjs";
3
+ import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-24-HgU9F.mjs";
4
4
  import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
5
- import { S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-C-r8ki7x.mjs";
6
- import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-B5mRo0-M.mjs";
7
- import { A as hasMiniProgramCssSpecificityPlaceholders, F as createCssTokenSourceMap, L as processCachedTask, M as stripMiniProgramCssSpecificityPlaceholders, N as annotateCssSourceTrace, P as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder } from "./hmr-timing-BRx-KnBh.mjs";
8
- import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-Dugfplms.mjs";
5
+ import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-Bkpmt3ja.mjs";
6
+ import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-D0JF0fuZ.mjs";
7
+ import { A as hasMiniProgramCssSpecificityPlaceholders, F as createCssTokenSourceMap, L as processCachedTask, M as stripMiniProgramCssSpecificityPlaceholders, N as annotateCssSourceTrace, P as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder } from "./hmr-timing-BRNaz8Od.mjs";
8
+ import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-BB1hvW68.mjs";
9
9
  import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
10
- import fs, { existsSync, realpathSync } from "node:fs";
10
+ import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
11
11
  import path from "node:path";
12
12
  import process$1 from "node:process";
13
13
  import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
14
- import { containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
14
+ import { compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig, transformWebCssCompat, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
15
15
  import { LRUCache } from "lru-cache";
16
16
  import { readFile } from "node:fs/promises";
17
17
  import micromatch from "micromatch";
@@ -250,7 +250,7 @@ const UVUE_TS_RE = /\.uvue\.ts$/;
250
250
  const JS_RE = /\.js$/;
251
251
  const APP_JS_RE = /(?:^|\/)App\.js$/;
252
252
  const COMPONENT_JS_RE = /(?:^|\/)components\/.+\.js$/;
253
- const HARMONY_BUNDLE_MARKER_FILES = new Set([
253
+ const HARMONY_BUNDLE_MARKER_FILES = /* @__PURE__ */ new Set([
254
254
  "import/app-service.ets",
255
255
  "import/dynamic.ets",
256
256
  "uni_modules/oh-package.json5"
@@ -509,10 +509,10 @@ function resolveUniAppXStyleIsolationEnabled(root) {
509
509
  //#region src/uni-app-x/vite.ts
510
510
  let transformUVuePromise;
511
511
  function loadTransformUVue() {
512
- transformUVuePromise ?? (transformUVuePromise = import("./transform-DeqFRp1D.mjs").then((mod) => mod.transformUVue));
512
+ transformUVuePromise ?? (transformUVuePromise = import("./transform-BP86eSZp.mjs").then((mod) => mod.transformUVue));
513
513
  return transformUVuePromise;
514
514
  }
515
- const preprocessorLangs = new Set([
515
+ const preprocessorLangs = /* @__PURE__ */ new Set([
516
516
  "scss",
517
517
  "sass",
518
518
  "less",
@@ -683,7 +683,7 @@ function createUniAppXPlugins(options) {
683
683
  if (isHarmonyTarget) {
684
684
  const cssSources = [];
685
685
  const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
686
- const applyUtilities = new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
686
+ const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
687
687
  if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
688
688
  const harmonyApplyCssFile = path.resolve(getResolvedConfig()?.root ?? process$1.cwd(), "uni-app-x-harmony-apply.css");
689
689
  const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
@@ -749,9 +749,31 @@ function collectConfiguredTailwindV4CssSources(opts) {
749
749
  const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
750
750
  return filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
751
751
  }
752
+ function collectExplicitTailwindV4CssEntries(opts) {
753
+ const entries = [
754
+ ...opts.cssEntries ?? [],
755
+ ...opts.tailwindcss?.v4?.cssEntries ?? [],
756
+ ...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
757
+ ];
758
+ return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
759
+ }
752
760
  function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
753
761
  const entries = [];
754
762
  const seen = /* @__PURE__ */ new Set();
763
+ const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
764
+ for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
765
+ if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
766
+ const resolvedFile = path.isAbsolute(cssEntry) ? path.resolve(cssEntry) : path.resolve(fallbackBase, cssEntry);
767
+ if (!existsSync(resolvedFile)) continue;
768
+ const source = readFileSync(resolvedFile, "utf8");
769
+ const key = `${resolvedFile}\0${source}`;
770
+ if (seen.has(key)) continue;
771
+ seen.add(key);
772
+ entries.push({
773
+ file: resolvedFile,
774
+ source
775
+ });
776
+ }
755
777
  for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
756
778
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
757
779
  const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
@@ -1097,12 +1119,14 @@ function createCssHandlerOptionsCache(options) {
1097
1119
  const outputRoot = options.getOutputRoot?.();
1098
1120
  const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
1099
1121
  const extraOptions = options.getExtraOptions?.(file) ?? {};
1100
- const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
1122
+ const dynamicCssOptions = options.getDynamicCssOptions?.() ?? {};
1123
+ const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}:${JSON.stringify(dynamicCssOptions)}`;
1101
1124
  const cached = cssHandlerOptionsCache.get(cacheKey);
1102
1125
  if (cached) return cached;
1103
1126
  const created = {
1104
1127
  isMainChunk,
1105
1128
  ...extraOptions,
1129
+ ...dynamicCssOptions,
1106
1130
  postcssOptions: { options: { from } },
1107
1131
  majorVersion: normalizeStyleHandlerMajorVersion(majorVersion),
1108
1132
  sourceOptions: { outputRoot }
@@ -1182,8 +1206,15 @@ function createMatchedCssSourceOutputResolver(options) {
1182
1206
  const { assetSourceFile, file, originalFileNames, resolveOutputFileFromMatchedCssSource } = options;
1183
1207
  return (sourceFile) => {
1184
1208
  if (!sourceFile) return;
1185
- if (normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalFileNames?.some((originalFile) => normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
1186
- return resolveOutputFileFromMatchedCssSource(sourceFile);
1209
+ const cleanAssetSourceFile = assetSourceFile.replace(/[?#].*$/, "");
1210
+ const cleanSourceFile = sourceFile.replace(/[?#].*$/, "");
1211
+ const sourceHasQuery = cleanSourceFile !== sourceFile;
1212
+ const resolvedSourceOutputFile = resolveOutputFileFromMatchedCssSource(sourceFile);
1213
+ if (normalizeOutputPathKey(cleanAssetSourceFile) === normalizeOutputPathKey(cleanSourceFile) || originalFileNames?.some((originalFile) => normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(cleanSourceFile))) {
1214
+ if (!sourceHasQuery && normalizeOutputPathKey(cleanAssetSourceFile) === normalizeOutputPathKey(cleanSourceFile) && typeof resolvedSourceOutputFile === "string" && normalizeOutputPathKey(resolvedSourceOutputFile) !== normalizeOutputPathKey(file)) return resolvedSourceOutputFile;
1215
+ return file;
1216
+ }
1217
+ return resolvedSourceOutputFile;
1187
1218
  };
1188
1219
  }
1189
1220
  function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAssetResults) {
@@ -1205,7 +1236,7 @@ function applyCssResultToBundle(options) {
1205
1236
  const replayAsset = emitOrReplayCssAsset(outputFile, source);
1206
1237
  if (replayAsset) bundle[outputFile] = replayAsset;
1207
1238
  }
1208
- originalSource.source = importShellSource ?? source;
1239
+ originalSource.source = importShellSource ?? "";
1209
1240
  return;
1210
1241
  }
1211
1242
  const existingOutput = bundle[outputFile];
@@ -1936,7 +1967,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
1936
1967
  const sourceEntries = [];
1937
1968
  for (const entry of snapshot.entries) {
1938
1969
  if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
1939
- const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
1970
+ const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
1940
1971
  if (!matchedSubpackageRoot) continue;
1941
1972
  for (const moduleId of collectChunkModuleIds$2(entry.output)) {
1942
1973
  if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
@@ -2105,8 +2136,17 @@ function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, option
2105
2136
  if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) === normalizeOutputPathKey(targetFile);
2106
2137
  if (options.injectIntoMain === false) return false;
2107
2138
  const targetFileKey = normalizeOutputPathKey(targetFile);
2139
+ if (typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) === targetFileKey) return true;
2108
2140
  return normalizeOutputPathKey(sourceFile) !== targetFileKey && (opts.mainCssChunkMatcher(sourceFile, opts.appType) || typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) !== targetFileKey && opts.mainCssChunkMatcher(options.outputFile, opts.appType));
2109
2141
  }
2142
+ function shouldReplayViteProcessedCssIntoMainCss(opts, file, sourceFile, outputFile, subpackageRoots) {
2143
+ if (subpackageRoots) {
2144
+ const sourceIsSubpackage = isSubpackageOutputFile(sourceFile ?? file, subpackageRoots);
2145
+ const outputIsSubpackage = isSubpackageOutputFile(outputFile, subpackageRoots);
2146
+ if (sourceIsSubpackage || outputIsSubpackage) return false;
2147
+ }
2148
+ return isRootStyleOutputFile(file) && opts.mainCssChunkMatcher(file, opts.appType) || isSourceRootPrefixedOutputFile(file, outputFile) && isRootStyleOutputFile(outputFile) && opts.mainCssChunkMatcher(outputFile, opts.appType);
2149
+ }
2110
2150
  function isRootStyleOutputFile(file) {
2111
2151
  const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
2112
2152
  return isCssOutputFile(normalized) && !normalized.includes("/");
@@ -2132,7 +2172,7 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
2132
2172
  }
2133
2173
  function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
2134
2174
  const fileKey = normalizeOutputPathKey(file);
2135
- if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return false;
2175
+ if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
2136
2176
  if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
2137
2177
  if (records.some((record) => {
2138
2178
  if (record.injectIntoMain !== true) return false;
@@ -2180,6 +2220,12 @@ function collectBundleAssetFiles(bundle) {
2180
2220
  }
2181
2221
  return files;
2182
2222
  }
2223
+ function findBundleAssetByOutputFile(bundle, file) {
2224
+ const fileKey = normalizeOutputPathKey(file);
2225
+ return Object.entries(bundle).find(([bundleFile, output]) => {
2226
+ return output.type === "asset" && normalizeOutputPathKey(getAssetFile$1(bundleFile, output)) === fileKey;
2227
+ })?.[1];
2228
+ }
2183
2229
  function isCssImportOnlyBundleAsset(bundle, file, css) {
2184
2230
  const importedStyleFiles = collectImportedStyleFiles(css, file);
2185
2231
  if (importedStyleFiles.size === 0) return false;
@@ -2199,6 +2245,13 @@ function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveVite
2199
2245
  const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
2200
2246
  return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
2201
2247
  }
2248
+ function resolveViteGeneratedCssMarkerOutputFile(file, markerFile, existingAssetFiles, resolveViteProcessedCssOutputFile) {
2249
+ const resolvedFromFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
2250
+ if (!markerFile) return resolvedFromFile;
2251
+ const resolvedFromMarker = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile);
2252
+ if (resolvedFromMarker !== resolvedFromFile && existingAssetFiles.has(resolvedFromMarker)) return resolvedFromMarker;
2253
+ return resolvedFromFile;
2254
+ }
2202
2255
  function isSourceRootPrefixedOutputFile(file, outputFile) {
2203
2256
  const fileKey = normalizeOutputPathKey(file);
2204
2257
  const outputFileKey = normalizeOutputPathKey(outputFile);
@@ -2215,11 +2268,31 @@ function collectViteProcessedCssAssetResults(bundle, options) {
2215
2268
  let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
2216
2269
  const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
2217
2270
  if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
2271
+ nextCss = options.transformCss?.(nextCss, file) ?? nextCss;
2218
2272
  if (nextCss !== rawSource) output.source = nextCss;
2219
2273
  options.markCssAssetProcessed?.(output, file);
2220
2274
  options.recordCssAssetResult?.(file, nextCss);
2221
- const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
2222
- const shouldReplayIntoMainCss = options.opts != null && (isRootStyleOutputFile(file) && options.opts.mainCssChunkMatcher(file, options.opts.appType) || isSourceRootPrefixedOutputFile(file, resolvedOutputFile) && isRootStyleOutputFile(resolvedOutputFile) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType));
2275
+ const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
2276
+ if (singleMarkerFile && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(normalizeOutputPathKey(resolvedOutputFile))) {
2277
+ const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
2278
+ if (targetAsset) {
2279
+ const targetRawSource = readAssetSource$2(targetAsset);
2280
+ const targetNextCss = appendCss$1(targetRawSource, filterExistingCssRules(targetRawSource, nextCss).trim());
2281
+ if (targetNextCss !== targetRawSource) {
2282
+ targetAsset.source = targetNextCss;
2283
+ options.markCssAssetProcessed?.(targetAsset, resolvedOutputFile);
2284
+ options.recordCssAssetResult?.(resolvedOutputFile, targetNextCss);
2285
+ }
2286
+ clearAssetSource(output);
2287
+ options.recordCssAssetResult?.(file, "");
2288
+ options.recordViteProcessedCssAssetResult?.(resolvedOutputFile, targetNextCss, { outputFile: resolvedOutputFile });
2289
+ if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) delete bundle[bundleFile];
2290
+ options.debug?.("move vite-generated css asset by marker source: %s -> %s bytes=%d", file, resolvedOutputFile, nextCss.length);
2291
+ collected++;
2292
+ continue;
2293
+ }
2294
+ }
2295
+ const shouldReplayIntoMainCss = options.opts != null && shouldReplayViteProcessedCssIntoMainCss(options.opts, file, singleMarkerFile, resolvedOutputFile, options.subpackageRoots);
2223
2296
  options.recordViteProcessedCssAssetResult?.(file, nextCss, {
2224
2297
  injectIntoMain: shouldReplayIntoMainCss || void 0,
2225
2298
  outputFile: resolvedOutputFile
@@ -2544,7 +2617,7 @@ async function handleUniAppXPostCssTasks(options) {
2544
2617
  const generated = await generateTailwindV4Css({
2545
2618
  opts,
2546
2619
  runtimeState,
2547
- runtime: new Set([...generatorRuntime, ...applyUtilities]),
2620
+ runtime: /* @__PURE__ */ new Set([...generatorRuntime, ...applyUtilities]),
2548
2621
  rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
2549
2622
  file: outputFile,
2550
2623
  outputFile,
@@ -2793,7 +2866,7 @@ async function finalizeGenerateBundle(options) {
2793
2866
  pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
2794
2867
  pruneViteCssCaches?.({
2795
2868
  activeFiles: activeViteCssCacheFiles,
2796
- activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
2869
+ activeKnownSfcFiles: /* @__PURE__ */ new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
2797
2870
  });
2798
2871
  }
2799
2872
  recordTimingDetail("state.update", stateUpdateStart);
@@ -2894,7 +2967,7 @@ function processHtmlBundleEntry(options) {
2894
2967
  const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
2895
2968
  const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
2896
2969
  const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
2897
- const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
2970
+ const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
2898
2971
  const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
2899
2972
  const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
2900
2973
  const cacheKey = `${file}:html:${htmlProcessHash}`;
@@ -2920,7 +2993,7 @@ function processHtmlBundleEntry(options) {
2920
2993
  if (unresolvedDynamicCandidates.length > 0) {
2921
2994
  const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
2922
2995
  const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
2923
- retryRuntimeSet = new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
2996
+ retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
2924
2997
  unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
2925
2998
  }
2926
2999
  if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
@@ -3135,6 +3208,15 @@ function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffe
3135
3208
  function normalizeRememberedSourceIdentity(file) {
3136
3209
  return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
3137
3210
  }
3211
+ function selectBestRememberedCssSourceMatches(sources, outputFile, outputRoot, sourceRoot) {
3212
+ if (sources.length <= 1) return sources;
3213
+ const scoredMatches = sources.map((remembered) => ({
3214
+ remembered,
3215
+ score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
3216
+ })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
3217
+ const bestScore = scoredMatches[0]?.score;
3218
+ return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : sources;
3219
+ }
3138
3220
  function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
3139
3221
  if (!sources) return [];
3140
3222
  const rememberedSources = [...sources].map(([, remembered]) => remembered);
@@ -3142,7 +3224,7 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
3142
3224
  const markerFiles = new Set(parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => normalizeOutputPathKey(block.file)));
3143
3225
  if (markerFiles.size > 0) {
3144
3226
  const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeRememberedSourceIdentity(remembered.sourceFile)));
3145
- if (markerMatched.length > 0) return markerMatched;
3227
+ if (markerMatched.length > 0) return selectBestRememberedCssSourceMatches(markerMatched, outputFile, outputRoot, sourceRoot);
3146
3228
  }
3147
3229
  const originalFiles = [
3148
3230
  file,
@@ -3154,12 +3236,8 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
3154
3236
  const outputMatched = rememberedSources.filter((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
3155
3237
  if (outputMatched.length > 0) return outputMatched;
3156
3238
  if (!hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
3157
- const scoredMatches = rememberedSources.map((remembered) => ({
3158
- remembered,
3159
- score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
3160
- })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
3161
- const bestScore = scoredMatches[0]?.score;
3162
- return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : [];
3239
+ const scoredMatches = selectBestRememberedCssSourceMatches(rememberedSources, outputFile, outputRoot, sourceRoot);
3240
+ return scoredMatches.length === rememberedSources.length ? [] : scoredMatches;
3163
3241
  }
3164
3242
  function mergeRememberedCssSources(sources, outputFile) {
3165
3243
  if (sources.length <= 1) return sources[0];
@@ -3394,7 +3472,7 @@ function createSubpackageSourceCandidateScope(options) {
3394
3472
  const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
3395
3473
  const resolveSubpackageOutputSourceEntries = (outputFile) => {
3396
3474
  if (!options.subpackageRoots) return;
3397
- const matchedRoots = [...options.subpackageRoots].filter((root) => isSubpackageOutputFile(outputFile, new Set([root])));
3475
+ const matchedRoots = [...options.subpackageRoots].filter((root) => isSubpackageOutputFile(outputFile, /* @__PURE__ */ new Set([root])));
3398
3476
  if (matchedRoots.length !== 1) return;
3399
3477
  const root = matchedRoots[0];
3400
3478
  if (!root) return;
@@ -3455,7 +3533,7 @@ function createSubpackageSourceCandidateScope(options) {
3455
3533
  excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
3456
3534
  }) ?? /* @__PURE__ */ new Map();
3457
3535
  };
3458
- const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
3536
+ const shouldInjectCssIntoMainFromOutput = (outputFile, sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile) && isMainPackageStyleOutputFile(sourceFile);
3459
3537
  return {
3460
3538
  createScopedSourceCandidateGetter,
3461
3539
  createScopedSourceCandidateSourceGetter,
@@ -3510,6 +3588,14 @@ function resolveCurrentSourceCandidateSource(options) {
3510
3588
  }
3511
3589
  //#endregion
3512
3590
  //#region src/bundlers/vite/generate-bundle/tailwind-v4-css-source.ts
3591
+ function createStableTextSignature(input) {
3592
+ let hash = 2166136261;
3593
+ for (let i = 0; i < input.length; i++) {
3594
+ hash ^= input.charCodeAt(i);
3595
+ hash = Math.imul(hash, 16777619);
3596
+ }
3597
+ return (hash >>> 0).toString(36);
3598
+ }
3513
3599
  function collectTailwindV4SourceFingerprint(source) {
3514
3600
  const tokens = /* @__PURE__ */ new Set();
3515
3601
  const add = (prefix, value) => {
@@ -3521,6 +3607,22 @@ function collectTailwindV4SourceFingerprint(source) {
3521
3607
  add("config-request", configRequest.replace(/\\/g, "/"));
3522
3608
  }
3523
3609
  for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
3610
+ for (const match of source.matchAll(/@plugin\s+(["'])(.+?)\1\s*(?:\{([\s\S]*?)\}|;)/g)) {
3611
+ const request = match[2];
3612
+ const optionBlock = match[3];
3613
+ add("plugin", request);
3614
+ add("plugin-request", request.replace(/\\/g, "/"));
3615
+ if (optionBlock !== void 0) add("plugin-options", `${request}:${createStableTextSignature(optionBlock)}`);
3616
+ }
3617
+ try {
3618
+ postcss.parse(source).walkAtRules("plugin", (rule) => {
3619
+ const request = /^(['"])(.+?)\1/.exec(rule.params.trim())?.[2];
3620
+ if (!request || !rule.nodes?.length) return;
3621
+ rule.walkDecls((decl) => {
3622
+ add("plugin-option", `${request}:${decl.prop}:${decl.value}`);
3623
+ });
3624
+ });
3625
+ } catch {}
3524
3626
  for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
3525
3627
  for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
3526
3628
  for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
@@ -3538,7 +3640,7 @@ function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
3538
3640
  }
3539
3641
  function resolveSubpackageRootForFile(file, subpackageRoots) {
3540
3642
  if (!file || !subpackageRoots) return;
3541
- return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
3643
+ return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, /* @__PURE__ */ new Set([root])));
3542
3644
  }
3543
3645
  function isSameSubpackageScope(outputFile, sourceFile, subpackageRoots) {
3544
3646
  return resolveSubpackageRootForFile(outputFile, subpackageRoots) === resolveSubpackageRootForFile(sourceFile, subpackageRoots);
@@ -3561,7 +3663,7 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
3561
3663
  const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, subpackageRoots);
3562
3664
  const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, subpackageRoots);
3563
3665
  if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
3564
- return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
3666
+ return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, /* @__PURE__ */ new Set([root])) && isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
3565
3667
  }) : generationSources;
3566
3668
  const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
3567
3669
  const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
@@ -3569,6 +3671,51 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
3569
3671
  return selectByRawSourceFingerprint(candidates);
3570
3672
  }
3571
3673
  //#endregion
3674
+ //#region src/bundlers/vite/generate-bundle/temporary-css-assets.ts
3675
+ function isTemporaryCssAssetFile(file) {
3676
+ const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
3677
+ return /\.css$/i.test(normalized) && !normalized.includes("/");
3678
+ }
3679
+ function normalizeCssSourceKey(file) {
3680
+ return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
3681
+ }
3682
+ function createTemporaryCssAssetSourceResolver(entries) {
3683
+ const seenEntryFiles = /* @__PURE__ */ new Set();
3684
+ const queuedEntries = entries.filter((entry) => {
3685
+ const entryFile = normalizeCssSourceKey(entry.file);
3686
+ const outputFile = normalizeCssSourceKey(entry.outputFile);
3687
+ if (outputFile === entryFile || !outputFile.includes("/") || seenEntryFiles.has(entryFile)) return false;
3688
+ seenEntryFiles.add(entryFile);
3689
+ return true;
3690
+ });
3691
+ const usedEntryFiles = /* @__PURE__ */ new Set();
3692
+ return {
3693
+ entries: queuedEntries,
3694
+ markUsed(sourceFile) {
3695
+ if (!sourceFile) return;
3696
+ usedEntryFiles.add(normalizeCssSourceKey(sourceFile));
3697
+ },
3698
+ resolve(outputFile, rawSource) {
3699
+ if (!isTemporaryCssAssetFile(outputFile)) return;
3700
+ const availableEntries = queuedEntries.filter((item) => !usedEntryFiles.has(normalizeCssSourceKey(item.file)));
3701
+ const scoredEntries = rawSource ? availableEntries.map((entry) => ({
3702
+ entry,
3703
+ score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
3704
+ })).filter((item) => item.score > 0).sort((a, b) => b.score - a.score) : [];
3705
+ const bestScore = scoredEntries[0]?.score;
3706
+ const bestEntries = bestScore ? scoredEntries.filter((item) => item.score === bestScore) : [];
3707
+ const entry = bestEntries.length === 1 ? bestEntries[0]?.entry : availableEntries.find((item) => hasTailwindGenerationSource(item.source));
3708
+ if (!entry) return;
3709
+ usedEntryFiles.add(normalizeCssSourceKey(entry.file));
3710
+ return {
3711
+ outputFile: entry.outputFile,
3712
+ rawSource: entry.source,
3713
+ sourceFile: entry.file
3714
+ };
3715
+ }
3716
+ };
3717
+ }
3718
+ //#endregion
3572
3719
  //#region src/bundlers/vite/generate-bundle/timing.ts
3573
3720
  function createBundleTaskTimer(recordTimingDetail) {
3574
3721
  return async (name, task) => {
@@ -3772,12 +3919,13 @@ function createGenerateBundleHook(context) {
3772
3919
  });
3773
3920
  return async function generateBundle(_opt, bundle) {
3774
3921
  const addWatchFile = (id) => this.addWatchFile?.(id);
3775
- const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
3922
+ const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownCssSource, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
3776
3923
  const getBundlerSfcSource = (sourceFile) => {
3777
3924
  const code = this.getModuleInfo?.(sourceFile)?.code;
3778
3925
  return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
3779
3926
  };
3780
3927
  const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
3928
+ const getCssSource = (sourceFile) => getKnownCssSource?.(sourceFile) ?? getSourceCandidateSource?.(sourceFile);
3781
3929
  const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
3782
3930
  const resolvedConfig = getResolvedConfig();
3783
3931
  const uniUtsPlatform = resolveUniUtsPlatform();
@@ -3913,7 +4061,7 @@ function createGenerateBundleHook(context) {
3913
4061
  refreshBySource: forceV4RuntimeRefreshBySource
3914
4062
  }) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
3915
4063
  const shouldFilterTailwindV4MiniProgramCandidates = shouldUseMiniProgramCssBranch(generatorBranch);
3916
- const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
4064
+ const collectedGeneratorCandidates = /* @__PURE__ */ new Set([...runtime, ...sourceCandidates]);
3917
4065
  const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
3918
4066
  const filteredSourceCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceCandidates) : sourceCandidates;
3919
4067
  const transformRuntime = shouldFilterTailwindV4MiniProgramCandidates ? new Set(runtime) : new Set(filteredGeneratorCandidates);
@@ -3949,7 +4097,7 @@ function createGenerateBundleHook(context) {
3949
4097
  const generatorCandidatesChanged = state.generatorCandidateSignature !== generatorCandidateSignature;
3950
4098
  const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
3951
4099
  const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
3952
- const runtimeLinkedCssFiles = new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
4100
+ const runtimeLinkedCssFiles = /* @__PURE__ */ new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
3953
4101
  rememberRuntimeLinkedCssSources({
3954
4102
  bundleFiles,
3955
4103
  debug,
@@ -3968,8 +4116,40 @@ function createGenerateBundleHook(context) {
3968
4116
  snapshot,
3969
4117
  sourceRoot
3970
4118
  });
4119
+ const temporaryCssAssetSourceResolver = createTemporaryCssAssetSourceResolver([
4120
+ ...[...runtimeLinkedCssFiles].filter((file) => !snapshot.sourceHashByFile.has(file)).map((file) => {
4121
+ const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
4122
+ const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
4123
+ return inferredSourceStyle && currentSubpackageRoots ? {
4124
+ file: inferredSourceStyle.sourceFile,
4125
+ outputFile,
4126
+ source: inferredSourceStyle.rawSource
4127
+ } : void 0;
4128
+ }).filter((entry) => entry != null),
4129
+ ...[...getRememberedCssSources?.() ?? []].map(([, remembered]) => ({
4130
+ file: remembered.sourceFile,
4131
+ outputFile: remembered.outputFile,
4132
+ source: remembered.rawSource
4133
+ })),
4134
+ ...getConfiguredTailwindV4CssSourceEntries().map((entry) => {
4135
+ const outputFile = resolveMatchedCssSourceOutputFile(entry.file);
4136
+ return outputFile ? {
4137
+ file: entry.file,
4138
+ outputFile,
4139
+ source: entry.source
4140
+ } : void 0;
4141
+ }).filter((entry) => entry != null),
4142
+ ...configuredTailwindV4CssSourceEntriesForScope.map((entry) => {
4143
+ const outputFile = resolveMatchedCssSourceOutputFile(entry.file);
4144
+ return outputFile && currentSubpackageRoots && isSubpackageOutputFile(outputFile, currentSubpackageRoots) ? {
4145
+ file: entry.file,
4146
+ outputFile,
4147
+ source: entry.source
4148
+ } : void 0;
4149
+ }).filter((entry) => entry != null)
4150
+ ]);
3971
4151
  recordGeneratorCandidates?.(generatorRuntime);
3972
- const dynamicRetryCandidates = new Set([
4152
+ const dynamicRetryCandidates = /* @__PURE__ */ new Set([
3973
4153
  ...sourceCandidates,
3974
4154
  ...generatorRuntime,
3975
4155
  ...transformRuntime
@@ -4068,6 +4248,7 @@ function createGenerateBundleHook(context) {
4068
4248
  }
4069
4249
  const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
4070
4250
  const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
4251
+ let resolvedFromTemporaryCssAsset = false;
4071
4252
  const applyCssResult = (source) => {
4072
4253
  applyCssResultToBundle({
4073
4254
  appType: opts.appType,
@@ -4109,14 +4290,39 @@ function createGenerateBundleHook(context) {
4109
4290
  const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
4110
4291
  if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
4111
4292
  }
4293
+ if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))))) {
4294
+ rememberedCssSources = [];
4295
+ hasUsableRememberedTailwindSource = false;
4296
+ }
4112
4297
  let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
4113
4298
  if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile, currentSubpackageRoots))) {
4114
4299
  rememberedCssSources = [];
4115
4300
  hasUsableRememberedTailwindSource = false;
4116
4301
  }
4302
+ if (isTemporaryCssAssetFile(outputFile) && hasTailwindGenerationSource(rawSource)) {
4303
+ const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
4304
+ if (resolvedTemporarySource) {
4305
+ outputFile = resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
4306
+ activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
4307
+ outputCssHandlerOptions = getCssHandlerOptions(outputFile);
4308
+ outputCssHandlerOptions = {
4309
+ ...outputCssHandlerOptions,
4310
+ isMainChunk: false
4311
+ };
4312
+ resolvedFromTemporaryCssAsset = true;
4313
+ usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(resolvedTemporarySource.sourceFile));
4314
+ rememberedCssSources = [{
4315
+ outputFile,
4316
+ rawSource: resolvedTemporarySource.rawSource,
4317
+ sourceFile: resolvedTemporarySource.sourceFile
4318
+ }];
4319
+ hasUsableRememberedTailwindSource = true;
4320
+ debug("source style source inferred from temporary remembered tailwind v4 css source: %s -> %s", outputFile, resolvedTemporarySource.sourceFile);
4321
+ }
4322
+ }
4117
4323
  if (!hasUsableRememberedTailwindSource) {
4118
4324
  const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
4119
- const inferredOriginalSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug) ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug));
4325
+ const inferredOriginalSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug) ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug));
4120
4326
  if (inferredOriginalSourceStyle) {
4121
4327
  outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
4122
4328
  activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
@@ -4125,6 +4331,25 @@ function createGenerateBundleHook(context) {
4125
4331
  ...inferredOriginalSourceStyle,
4126
4332
  outputFile
4127
4333
  }];
4334
+ } else if (isTemporaryCssAssetFile(outputFile) && configuredTailwindV4CssSourceEntries.length > 1) {
4335
+ const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
4336
+ if (resolvedTemporarySource) {
4337
+ outputFile = resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
4338
+ activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
4339
+ outputCssHandlerOptions = getCssHandlerOptions(outputFile);
4340
+ outputCssHandlerOptions = {
4341
+ ...outputCssHandlerOptions,
4342
+ isMainChunk: false
4343
+ };
4344
+ resolvedFromTemporaryCssAsset = true;
4345
+ usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(resolvedTemporarySource.sourceFile));
4346
+ rememberedCssSources = [{
4347
+ outputFile,
4348
+ rawSource: resolvedTemporarySource.rawSource,
4349
+ sourceFile: resolvedTemporarySource.sourceFile
4350
+ }];
4351
+ debug("source style source inferred from temporary configured tailwind v4 css source: %s -> %s", outputFile, resolvedTemporarySource.sourceFile);
4352
+ }
4128
4353
  } else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
4129
4354
  const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
4130
4355
  const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, currentSubpackageRoots);
@@ -4176,10 +4401,13 @@ function createGenerateBundleHook(context) {
4176
4401
  const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
4177
4402
  const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
4178
4403
  const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
4179
- if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(generatorSourceFile.replace(/[?#].*$/, "")))) usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
4404
+ if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(generatorSourceFile.replace(/[?#].*$/, "")))) {
4405
+ usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
4406
+ temporaryCssAssetSourceResolver.markUsed(generatorSourceFile);
4407
+ }
4180
4408
  const cssHandlerOptions = vitePipelineCssAsset ? {
4181
4409
  ...getCssHandlerOptions(generatorSourceFile),
4182
- isMainChunk: outputCssHandlerOptions.isMainChunk
4410
+ isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
4183
4411
  } : getCssHandlerOptions(file);
4184
4412
  const generatorCssHandlerOptions = {
4185
4413
  ...cssHandlerOptions,
@@ -4490,6 +4718,7 @@ function registerGeneratorDependencies(ctx, dependencies) {
4490
4718
  function createCssHandlerOptions(opts, majorVersion, file) {
4491
4719
  return {
4492
4720
  ...resolveUniAppXNativeCssHandlerOptions(opts),
4721
+ cssPreflight: opts.cssPreflight,
4493
4722
  isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
4494
4723
  postcssOptions: { options: { from: file } },
4495
4724
  ...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
@@ -4513,6 +4742,9 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
4513
4742
  function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
4514
4743
  return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
4515
4744
  }
4745
+ function finalizeWebCss(css, enabled, webCompat) {
4746
+ return enabled ? transformWebCssCompat(css, webCompat) : css;
4747
+ }
4516
4748
  function createViteCssFinalizerOutputPlugin(context) {
4517
4749
  return {
4518
4750
  name: "weapp-tailwindcss:adaptor:css-finalizer",
@@ -4523,13 +4755,14 @@ function createViteCssFinalizerOutputPlugin(context) {
4523
4755
  const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
4524
4756
  const resolvedConfig = getResolvedConfig();
4525
4757
  const uniUtsPlatform = resolveUniUtsPlatform();
4526
- const generatorBranch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
4758
+ const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
4527
4759
  appType: opts.appType,
4528
4760
  platform: opts.cssOptions?.platform ?? opts.platform,
4529
4761
  tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
4530
4762
  uniAppX: opts.uniAppX,
4531
4763
  uniUtsPlatform
4532
- }), {
4764
+ });
4765
+ const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
4533
4766
  appType: opts.appType,
4534
4767
  platform: opts.cssOptions?.platform ?? opts.platform,
4535
4768
  tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
@@ -4556,6 +4789,7 @@ function createViteCssFinalizerOutputPlugin(context) {
4556
4789
  recordCssAssetResult,
4557
4790
  recordViteProcessedCssAssetResult,
4558
4791
  resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
4792
+ transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat),
4559
4793
  debug
4560
4794
  });
4561
4795
  };
@@ -4575,7 +4809,7 @@ function createViteCssFinalizerOutputPlugin(context) {
4575
4809
  const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
4576
4810
  const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
4577
4811
  if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
4578
- const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
4812
+ const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
4579
4813
  const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
4580
4814
  const generated = await generateTailwindV4Css({
4581
4815
  opts,
@@ -4622,13 +4856,13 @@ function createViteCssFinalizerOutputPlugin(context) {
4622
4856
  await runtimeState.readyPromise;
4623
4857
  await waitForSourceCandidateSyncs?.();
4624
4858
  const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
4625
- const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
4859
+ const collectedGeneratorCandidates = /* @__PURE__ */ new Set([...runtime, ...getSourceCandidates?.() ?? []]);
4626
4860
  const generatorRuntime = shouldUseMiniProgramCssBranch(generatorBranch) ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
4627
4861
  await Promise.all(entries.map(async ([bundleFile, output]) => {
4628
4862
  const file = output.fileName || bundleFile;
4629
4863
  const rawSource = output.source.toString();
4630
4864
  if (isViteProcessedCssAsset?.(output, file)) {
4631
- const nextCss = annotateCss(stripBundlerGeneratedCssMarkers(rawSource));
4865
+ const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat));
4632
4866
  output.source = nextCss;
4633
4867
  markCssAssetProcessed(output, file);
4634
4868
  recordCssAssetResult?.(file, nextCss);
@@ -4662,7 +4896,7 @@ function createViteCssFinalizerOutputPlugin(context) {
4662
4896
  styleHandler: opts.styleHandler,
4663
4897
  debug
4664
4898
  }) : void 0;
4665
- const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
4899
+ const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
4666
4900
  if (generated) {
4667
4901
  registerGeneratorDependencies(this, generated.dependencies);
4668
4902
  debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
@@ -4795,6 +5029,11 @@ function createViteCssMemory(options) {
4795
5029
  if (source != null) touchMapEntry(knownSfcSources, key, source);
4796
5030
  return source;
4797
5031
  };
5032
+ const getKnownCssSource = (file) => {
5033
+ const source = knownCssSources.get(normalizeCssSourceIdentity(file));
5034
+ if (source != null) touchMapEntry(knownCssSources, normalizeCssSourceIdentity(file), source);
5035
+ return source;
5036
+ };
4798
5037
  const rememberCssSource = (entry, cssRuntimeSignature) => {
4799
5038
  const outputKey = normalizeOutputPathKey(entry.outputFile);
4800
5039
  const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
@@ -4913,6 +5152,7 @@ function createViteCssMemory(options) {
4913
5152
  };
4914
5153
  return {
4915
5154
  getKnownSfcSource,
5155
+ getKnownCssSource,
4916
5156
  getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(normalizeOutputPathKey(file)),
4917
5157
  getRememberedCssSourceEntry: (file) => rememberedCssSources.get(normalizeOutputPathKey(file)),
4918
5158
  getRememberedCssSources: () => rememberedCssSources,
@@ -5299,7 +5539,7 @@ function createViteRuntimeClassSet(options) {
5299
5539
  }
5300
5540
  //#endregion
5301
5541
  //#region src/bundlers/vite/serve-css-generation.ts
5302
- const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
5542
+ const SPECIAL_QUERY_RE$1 = /[?&](?:worker|sharedworker|raw|url)\b/;
5303
5543
  const COMMON_JS_PROXY_RE = /\?commonjs-proxy/;
5304
5544
  const VITE_CSS_HMR_MODULE_RE = /\b__vite__updateStyle\s*\(/;
5305
5545
  const VITE_CSS_CONST_RE = /\bconst\s+__vite__css\s*=\s*("(?:\\[\s\S]|[^"])*")/;
@@ -5330,10 +5570,10 @@ function replaceViteCssHmrModuleCss(code, css) {
5330
5570
  return `${code.slice(0, extracted.start)}${encodeJsStringLiteral(css)}${code.slice(extracted.end)}`;
5331
5571
  }
5332
5572
  function isViteServeStyleRequest(id, command) {
5333
- return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
5573
+ return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
5334
5574
  }
5335
5575
  function isViteServeCssRootRequest(id, command) {
5336
- return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
5576
+ return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
5337
5577
  }
5338
5578
  function isViteCssHmrModule(code, id, command) {
5339
5579
  return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
@@ -5375,6 +5615,32 @@ function createViteServeCssGenerationPlugins(options) {
5375
5615
  }];
5376
5616
  }
5377
5617
  //#endregion
5618
+ //#region src/bundlers/vite/serve-js-transform.ts
5619
+ const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
5620
+ function isViteServeJsRequest(id, command) {
5621
+ if (command !== "serve" || SPECIAL_QUERY_RE.test(id) || isCSSRequest(id) || isHTMLRequest(id)) return false;
5622
+ return /\.(?:[cm]?[jt]sx?|vue|svelte)(?:$|\?)/.test(id);
5623
+ }
5624
+ function createViteServeJsTransformPlugin(options) {
5625
+ return {
5626
+ name: `${vitePluginName}:js:serve`,
5627
+ apply: "serve",
5628
+ enforce: "post",
5629
+ async transform(code, id) {
5630
+ if (!options.shouldTransform() || !isViteServeJsRequest(id, options.getCommand())) return;
5631
+ const handlerOptions = options.createHandlerOptions(id);
5632
+ if (shouldSkipJsTransform(code, handlerOptions)) return;
5633
+ const runtime = await options.transformRuntime();
5634
+ const { code: transformed } = await options.jsHandler(code, runtime, handlerOptions);
5635
+ if (transformed === code) return;
5636
+ return {
5637
+ code: transformed,
5638
+ map: null
5639
+ };
5640
+ }
5641
+ };
5642
+ }
5643
+ //#endregion
5378
5644
  //#region src/bundlers/vite/tailwind-basedir.ts
5379
5645
  const PACKAGE_JSON_FILE = "package.json";
5380
5646
  function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
@@ -5401,6 +5667,30 @@ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
5401
5667
  const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
5402
5668
  const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
5403
5669
  const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
5670
+ const ENV_PLATFORM_KEYS = [
5671
+ "UNI_PLATFORM",
5672
+ "UNI_UTS_PLATFORM",
5673
+ "TARO_ENV",
5674
+ "MPX_CURRENT_TARGET_MODE",
5675
+ "MPX_CLI_MODE"
5676
+ ];
5677
+ function sameStringList(first, second) {
5678
+ if (first === second) return true;
5679
+ if (!first || !second || first.length !== second.length) return false;
5680
+ return first.every((item, index) => item === second[index]);
5681
+ }
5682
+ function normalizeViteStylePlatform(value, appType) {
5683
+ return normalizeFrameworkStylePlatform(value, appType);
5684
+ }
5685
+ function inferPlatformFromOutDir(outDir) {
5686
+ const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
5687
+ if (!segment) return;
5688
+ const normalized = segment.trim().toLowerCase();
5689
+ if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
5690
+ }
5691
+ function isWebOrNativeAppPlatform(platform) {
5692
+ return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
5693
+ }
5404
5694
  /**
5405
5695
  * @name WeappTailwindcss
5406
5696
  * @description uni-app vite / uni-app-x 版本插件
@@ -5409,18 +5699,25 @@ const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SC
5409
5699
  function WeappTailwindcss(options = {}) {
5410
5700
  const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
5411
5701
  const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
5702
+ const rawCssEntries = Array.isArray(options.cssEntries) ? [...options.cssEntries] : void 0;
5412
5703
  const opts = getCompilerContext({
5413
5704
  ...options,
5414
5705
  __internalDeferMissingCssEntriesWarning: true
5415
5706
  });
5416
- const normalizedCssEntries = normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? process$1.cwd());
5417
- if (normalizedCssEntries) opts.cssEntries ?? (opts.cssEntries = normalizedCssEntries);
5418
- if (opts.cssEntries?.length) {
5419
- var _opts$tailwindcss, _opts$tailwindcss$v;
5707
+ const syncCssEntriesFromAnchor = (anchor) => {
5708
+ var _opts$tailwindcss;
5709
+ const normalizedCssEntries = normalizeCssEntries(rawCssEntries, anchor ?? process$1.cwd());
5710
+ if (!normalizedCssEntries) return false;
5711
+ const changed = !sameStringList(opts.cssEntries, normalizedCssEntries);
5712
+ opts.cssEntries = normalizedCssEntries;
5420
5713
  opts.tailwindcss ?? (opts.tailwindcss = {});
5421
5714
  (_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
5422
- (_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
5423
- }
5715
+ opts.tailwindcss.v4.cssEntries = normalizedCssEntries;
5716
+ if (opts.tailwindcssRuntimeOptions?.tailwindcss?.v4) opts.tailwindcssRuntimeOptions.tailwindcss.v4.cssEntries = normalizedCssEntries;
5717
+ if (opts.tailwindRuntime?.options?.tailwindcss?.v4) opts.tailwindRuntime.options.tailwindcss.v4.cssEntries = normalizedCssEntries;
5718
+ return changed;
5719
+ };
5720
+ syncCssEntriesFromAnchor(opts.tailwindcssBasedir);
5424
5721
  const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
5425
5722
  const initialTailwindRuntime = tailwindRuntime;
5426
5723
  const refreshTailwindRuntime = refreshTailwindcssRuntime;
@@ -5442,6 +5739,28 @@ function WeappTailwindcss(options = {}) {
5442
5739
  tailwindcssMajorVersion,
5443
5740
  uniAppX
5444
5741
  });
5742
+ const resolveViteStylePlatform = () => {
5743
+ const explicit = normalizeViteStylePlatform(opts.cssOptions?.platform ?? opts.platform, opts.appType);
5744
+ if (explicit) return explicit;
5745
+ for (const key of ENV_PLATFORM_KEYS) {
5746
+ const envPlatform = normalizeViteStylePlatform(process$1.env[key], opts.appType);
5747
+ if (envPlatform) return envPlatform;
5748
+ }
5749
+ return inferPlatformFromOutDir(resolvedConfig?.build?.outDir);
5750
+ };
5751
+ const transformEarlyMiniProgramCss = (code) => {
5752
+ const platform = resolveViteStylePlatform();
5753
+ if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : generatorBranch.isWeb)) return code;
5754
+ let transformedCode = code;
5755
+ if (transformedCode.includes("#if")) transformedCode = compileCssMacroConditionalComments(transformedCode, { platform: resolveViteStylePlatform() });
5756
+ if (transformedCode.includes("@layer")) transformedCode = unwrapUnsupportedCascadeLayers(transformedCode);
5757
+ return transformedCode;
5758
+ };
5759
+ const finalizeViteMiniProgramCss = (css) => {
5760
+ const platform = resolveViteStylePlatform();
5761
+ if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : generatorBranch.isWeb)) return css;
5762
+ return unwrapUnsupportedCascadeLayers(css);
5763
+ };
5445
5764
  const shouldInferAppType = !hasExplicitAppType && !generatorBranch.isWeb;
5446
5765
  const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
5447
5766
  ...options,
@@ -5469,6 +5788,7 @@ function WeappTailwindcss(options = {}) {
5469
5788
  if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
5470
5789
  autoCssSourceContent.set(sourceFile, sourceCss);
5471
5790
  await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
5791
+ cssMemory.refreshRememberedCssSourceBySourceFile(sourceFile, sourceCss);
5472
5792
  const transientSource = {
5473
5793
  file: sourceFile,
5474
5794
  base: sourceBase,
@@ -5595,7 +5915,7 @@ function WeappTailwindcss(options = {}) {
5595
5915
  root
5596
5916
  }];
5597
5917
  const normalizedRoot = path.resolve(root);
5598
- const seenRoots = new Set([normalizedRoot]);
5918
+ const seenRoots = /* @__PURE__ */ new Set([normalizedRoot]);
5599
5919
  const basedir = opts.tailwindcssBasedir ? path.resolve(opts.tailwindcssBasedir) : void 0;
5600
5920
  if (basedir && !seenRoots.has(basedir)) {
5601
5921
  roots.push({ root: basedir });
@@ -5776,7 +6096,12 @@ function WeappTailwindcss(options = {}) {
5776
6096
  getExtraOptions: (file) => ({
5777
6097
  ...resolveViteCssHandlerExtraOptions(file),
5778
6098
  ...resolveUniAppXNativeCssHandlerOptions(opts)
5779
- })
6099
+ }),
6100
+ getDynamicCssOptions: () => ({ cssPreflight: opts.cssPreflight })
6101
+ });
6102
+ const serveJsHandlerOptions = createJsHandlerOptionsFactory({
6103
+ getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
6104
+ moduleGraph: void 0
5780
6105
  });
5781
6106
  const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
5782
6107
  if (!shouldOwnTailwindGeneration) return;
@@ -5796,7 +6121,11 @@ function WeappTailwindcss(options = {}) {
5796
6121
  ...transformCssHandlerOptions.getCssHandlerOptions(file),
5797
6122
  isMainChunk: outputCssHandlerOptions.isMainChunk
5798
6123
  };
5799
- const transientCssSource = transientAutoCssSources.get(file);
6124
+ const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }) || hasTailwindSourceDirectives(code, { importFallback: generatorOptions.importFallback }) || hasTailwindApplyDirective(code) ? {
6125
+ base: path.dirname(path.resolve(file)),
6126
+ css: code,
6127
+ file: path.resolve(file)
6128
+ } : void 0);
5800
6129
  const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(code));
5801
6130
  const generated = await generateTailwindV4Css({
5802
6131
  opts,
@@ -5815,7 +6144,7 @@ function WeappTailwindcss(options = {}) {
5815
6144
  deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource
5816
6145
  });
5817
6146
  if (!generated) return;
5818
- const tracedCss = annotateCssSourceTrace(generated.css, {
6147
+ const tracedCss = annotateCssSourceTrace(finalizeViteMiniProgramCss(generated.css), {
5819
6148
  opts,
5820
6149
  tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
5821
6150
  });
@@ -5884,6 +6213,7 @@ function WeappTailwindcss(options = {}) {
5884
6213
  getRememberedCssSources: cssMemory.getRememberedCssSources,
5885
6214
  getRememberedCssSignature: cssMemory.getRememberedCssSignature,
5886
6215
  setRememberedCssSignature: cssMemory.setRememberedCssSignature,
6216
+ getKnownCssSource: cssMemory.getKnownCssSource,
5887
6217
  getKnownSfcSource: cssMemory.getKnownSfcSource,
5888
6218
  recordGeneratorCandidates,
5889
6219
  pruneViteCssCaches,
@@ -5938,20 +6268,45 @@ function WeappTailwindcss(options = {}) {
5938
6268
  {
5939
6269
  name: `${vitePluginName}:source-candidates`,
5940
6270
  enforce: "pre",
5941
- async transform(code, id) {
5942
- if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, code);
5943
- if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
5944
- return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
5945
- invalidateRecordedGeneratorCandidates();
5946
- const file = cleanUrl(id);
5947
- if (sourceScanMatcher && !sourceScanMatcher(file)) {
5948
- sourceCandidateCollector.remove(file);
5949
- cacheCurrentSourceCandidateScan();
6271
+ async load(id) {
6272
+ if (!shouldOwnTailwindGeneration || isWebOrNativeAppPlatform(resolveViteStylePlatform()) || !isCSSRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
6273
+ const rawCode = await readFile(cleanUrl(id), "utf8").catch(() => void 0);
6274
+ if (typeof rawCode !== "string") return;
6275
+ const transformedCode = transformEarlyMiniProgramCss(rawCode);
6276
+ if (transformedCode === rawCode) return;
6277
+ cssMemory.rememberKnownSfcSource(id, transformedCode);
6278
+ return transformedCode;
6279
+ },
6280
+ transform: {
6281
+ order: "pre",
6282
+ async handler(code, id) {
6283
+ let transformedCode = code;
6284
+ if (shouldOwnTailwindGeneration && !generatorBranch.isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
6285
+ const shouldReturnTransformedCode = transformedCode !== code;
6286
+ if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, transformedCode);
6287
+ if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) {
6288
+ if (shouldReturnTransformedCode) return {
6289
+ code: transformedCode,
6290
+ map: null
6291
+ };
5950
6292
  return;
5951
6293
  }
5952
- await sourceCandidateCollector.merge(id, code);
5953
- cacheCurrentSourceCandidateScan();
5954
- }, { emit: false });
6294
+ return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
6295
+ invalidateRecordedGeneratorCandidates();
6296
+ const file = cleanUrl(id);
6297
+ if (sourceScanMatcher && !sourceScanMatcher(file)) {
6298
+ sourceCandidateCollector.remove(file);
6299
+ cacheCurrentSourceCandidateScan();
6300
+ return;
6301
+ }
6302
+ await sourceCandidateCollector.merge(id, transformedCode);
6303
+ cacheCurrentSourceCandidateScan();
6304
+ if (shouldReturnTransformedCode) return {
6305
+ code: transformedCode,
6306
+ map: null
6307
+ };
6308
+ }, { emit: false });
6309
+ }
5955
6310
  },
5956
6311
  async watchChange(id, change) {
5957
6312
  await hmrTimingRecorder.measure("sourceCandidates.watchChange", async () => {
@@ -5991,6 +6346,13 @@ function WeappTailwindcss(options = {}) {
5991
6346
  onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
5992
6347
  shouldGenerate: () => shouldOwnTailwindGeneration
5993
6348
  }),
6349
+ createViteServeJsTransformPlugin({
6350
+ createHandlerOptions: serveJsHandlerOptions,
6351
+ getCommand: () => resolvedConfig?.command,
6352
+ jsHandler,
6353
+ shouldTransform: () => shouldOwnTailwindGeneration && !generatorBranch.isWeb,
6354
+ transformRuntime: ensureRuntimeClassSet
6355
+ }),
5994
6356
  {
5995
6357
  name: `${vitePluginName}:post`,
5996
6358
  enforce: "post",
@@ -6032,6 +6394,7 @@ function WeappTailwindcss(options = {}) {
6032
6394
  if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
6033
6395
  const previousBasedir = opts.tailwindcssBasedir;
6034
6396
  opts.tailwindcssBasedir = nextTailwindcssBasedir;
6397
+ shouldRefreshRuntime = syncCssEntriesFromAnchor(nextTailwindcssBasedir) || shouldRefreshRuntime;
6035
6398
  debug("align tailwindcss basedir with vite root: %s -> %s", previousBasedir ?? "undefined", nextTailwindcssBasedir);
6036
6399
  shouldRefreshRuntime = true;
6037
6400
  }