weapp-tailwindcss 5.5.7 → 5.5.9

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 (61) hide show
  1. package/dist/bundlers/vite/css-calc-stage.d.ts +8 -0
  2. package/dist/bundlers/vite/css-finalizer/css-calc.d.ts +1 -0
  3. package/dist/bundlers/vite/css-finalizer/css-scope-graph.d.ts +5 -0
  4. package/dist/bundlers/vite/css-finalizer/final-assets.d.ts +1 -1
  5. package/dist/bundlers/vite/css-finalizer/options.d.ts +1 -0
  6. package/dist/{compiler-DkGY5Nmh.cjs → compiler-TvqqdOMD.cjs} +15894 -15804
  7. package/dist/{compiler-CThodfGH.js → compiler-v9sYta8W.js} +35 -30
  8. package/dist/core/compiler/generation-cache.d.ts +4 -2
  9. package/dist/core/compiler/root-store.d.ts +1 -1
  10. package/dist/core/compiler/source.d.ts +7 -0
  11. package/dist/core.cjs +1 -1
  12. package/dist/core.js +1 -1
  13. package/dist/{generated-css-marker-jMNbQHpy.cjs → generated-css-marker-C21q8hGM.cjs} +48 -20
  14. package/dist/generation/pipeline/style-context.d.ts +3 -0
  15. package/dist/{generator-CxauQbx3.cjs → generator-B1sYQpWu.cjs} +165 -90
  16. package/dist/{generator-oKZ5mCJ5.js → generator-LqofzXgr.js} +155 -92
  17. package/dist/generator.cjs +1 -1
  18. package/dist/generator.js +1 -1
  19. package/dist/{gulp-CVvBpIlq.cjs → gulp-BhQhrDCx.cjs} +5 -5
  20. package/dist/{gulp-DhddVxGA.js → gulp-ComuY3KW.js} +4 -4
  21. package/dist/gulp.cjs +1 -1
  22. package/dist/gulp.js +1 -1
  23. package/dist/{hmr-timing-xPpat-km.js → hmr-timing-CNo2hmaX.js} +48 -20
  24. package/dist/{hmr-timing-DfMbbZ1E.cjs → hmr-timing-CXBDn0dl.cjs} +4 -4
  25. package/dist/index.cjs +4 -4
  26. package/dist/index.js +4 -4
  27. package/dist/{pipeline-helpers-zMPmp5F3.cjs → pipeline-helpers-B9ZqLXma.cjs} +3 -3
  28. package/dist/postcss.cjs +1 -1
  29. package/dist/postcss.js +1 -1
  30. package/dist/presets.cjs +2 -2
  31. package/dist/presets.js +2 -2
  32. package/dist/rspack.cjs +2 -2
  33. package/dist/rspack.js +2 -2
  34. package/dist/{scoped-generator-BIZ7N_J-.cjs → scoped-generator-BAiZDC_4.cjs} +4 -4
  35. package/dist/{scoped-generator-DlQrVbuC.js → scoped-generator-CF0ROe7B.js} +4 -4
  36. package/dist/{source-candidate-scan-signature-BjVQYL-C.js → source-candidate-scan-signature-BWLf4tuO.js} +2 -2
  37. package/dist/{source-candidate-scan-signature-nG-rg809.cjs → source-candidate-scan-signature-_ohG0ePd.cjs} +2 -2
  38. package/dist/tailwindcss/v4/rpx-theme-warning.d.ts +1 -1
  39. package/dist/tailwindcss/v4-engine/generator/raw-generation.d.ts +30 -0
  40. package/dist/tailwindcss/v4-engine/generator/style-context.d.ts +3 -0
  41. package/dist/tailwindcss/v4-engine/types.d.ts +2 -0
  42. package/dist/{tailwindcss-kSd0ykiX.js → tailwindcss-XNfJSlhp.js} +2 -2
  43. package/dist/{tailwindcss-U3KIUegn.cjs → tailwindcss-uf04Iolj.cjs} +2 -2
  44. package/dist/{transform-D2KFdA3C.cjs → transform-DJkkjruV.cjs} +3 -3
  45. package/dist/{transform-BAon9ykq.js → transform-I-mzwoiv.js} +3 -3
  46. package/dist/utils/stable-serialize.d.ts +1 -0
  47. package/dist/vite/web.cjs +1 -1
  48. package/dist/vite/web.js +1 -1
  49. package/dist/{vite-BxW0qd7J.cjs → vite-BVcj7Ht9.cjs} +18 -14
  50. package/dist/{vite-D-RGkmOE.js → vite-Bd-Ig5Dy.js} +17 -13
  51. package/dist/vite.cjs +1 -1
  52. package/dist/vite.js +1 -1
  53. package/dist/weapp-tw-css-generation-loader.cjs +1 -1
  54. package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
  55. package/dist/{web--kA4HUTm.js → web-BsFZOq3g.js} +296 -85
  56. package/dist/{web-Y-H6I1k6.cjs → web-Dq2PzKKQ.cjs} +307 -84
  57. package/dist/{webpack-DxrWatNB.cjs → webpack-CWMoTWzF.cjs} +8 -8
  58. package/dist/{webpack-BB-kw4Qr.js → webpack-DtAZoEth.js} +7 -7
  59. package/dist/webpack.cjs +1 -1
  60. package/dist/webpack.js +1 -1
  61. package/package.json +6 -5
@@ -1,15 +1,17 @@
1
- import { a as findTailwindConfig, f as resolveSourceScanEntries, l as getRuntimeClassSetSignature, v as source_scan_exports } from "./tailwindcss-kSd0ykiX.js";
1
+ import { a as findTailwindConfig, f as resolveSourceScanEntries, l as getRuntimeClassSetSignature, v as source_scan_exports } from "./tailwindcss-XNfJSlhp.js";
2
2
  import { resolveImplicitAppTypeFromViteRoot } from "./framework.js";
3
- import { S as findNearestPackageRoot, a as resolveGeneratorRuntimeBranch, b as isTailwindV4CssEntry, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveTailwindcssOptions } from "./generator-oKZ5mCJ5.js";
4
- import { A as createTailwindRuntimeReadyPromise, M as refreshTailwindRuntimeState, N as createDebug, f as getCompilerContext, g as vitePluginName, i as disposeCompilerOwner, k as collectRuntimeClassSet, n as createRuntimeAffectingSourceSignature, p as normalizeStyleHandlerMajorVersion, t as createCompilerRuntimeState } from "./compiler-CThodfGH.js";
5
- import { $ as createSourceCandidateEligibilityMatcher, H as stripRequestQuery, I as hasTailwindGeneratedCss, L as hasTailwindGeneratedCssMarkers, M as normalizeEmptyTailwindCustomVariants$1, N as captureFrameworkPostcssOptions, T as hasUserCssLayerBlocks, U as createRuntimeClassSetManager, V as isSourceStyleRequest, Y as createSourceCandidateCollector, Z as isSourceCandidateRequest, at as hasTailwindSourceDirectives, c as annotateCssSourceTrace, d as isCssSourceTraceEnabled, dt as finalizeCompilerShadowRun, f as generateTailwindV4Css, i as createBundlerGeneratedCssMarker, it as hasTailwindRootDirectives, nt as hasTailwindApplyDirective, o as parseBundlerGeneratedCssMarkerBlocks, ot as normalizeTailwindConfigDirectives$1, rt as hasTailwindNonRootGenerationDirectives, s as stripBundlerGeneratedCssMarkers, st as normalizeTailwindSourceForGenerator, t as createHmrTimingRecorder, tt as hasLocalCssImport, u as createCssTokenSourceMap, x as scoreTailwindV4CssSourceFileMatch } from "./hmr-timing-xPpat-km.js";
6
- import { c as getViteHookHandler, n as resolvePackageDir, o as normalizeStyleInjectorOptions, r as normalizeOutputPathKey, t as createSourceCandidateScanSignature } from "./source-candidate-scan-signature-BjVQYL-C.js";
3
+ import { S as findNearestPackageRoot, a as resolveGeneratorRuntimeBranch, b as isTailwindV4CssEntry, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveTailwindcssOptions, l as resolveUniUtsPlatform } from "./generator-LqofzXgr.js";
4
+ import "./utils-MVwpU07P.js";
5
+ import { A as createTailwindRuntimeReadyPromise, M as refreshTailwindRuntimeState, N as createDebug, f as getCompilerContext, g as vitePluginName, i as disposeCompilerOwner, k as collectRuntimeClassSet, m as resolveStyleOptionsFromContext, n as createRuntimeAffectingSourceSignature, p as normalizeStyleHandlerMajorVersion, t as createCompilerRuntimeState } from "./compiler-v9sYta8W.js";
6
+ import { $ as createSourceCandidateEligibilityMatcher, H as stripRequestQuery, I as hasTailwindGeneratedCss, L as hasTailwindGeneratedCssMarkers, M as normalizeEmptyTailwindCustomVariants$1, N as captureFrameworkPostcssOptions, T as hasUserCssLayerBlocks, U as createRuntimeClassSetManager, V as isSourceStyleRequest, Y as createSourceCandidateCollector, Z as isSourceCandidateRequest, at as hasTailwindSourceDirectives, c as annotateCssSourceTrace, d as isCssSourceTraceEnabled, dt as finalizeCompilerShadowRun, f as generateTailwindV4Css, i as createBundlerGeneratedCssMarker, it as hasTailwindRootDirectives, nt as hasTailwindApplyDirective, o as parseBundlerGeneratedCssMarkerBlocks, ot as normalizeTailwindConfigDirectives$1, rt as hasTailwindNonRootGenerationDirectives, s as stripBundlerGeneratedCssMarkers, st as normalizeTailwindSourceForGenerator, t as createHmrTimingRecorder, tt as hasLocalCssImport, u as createCssTokenSourceMap, x as scoreTailwindV4CssSourceFileMatch } from "./hmr-timing-CNo2hmaX.js";
7
+ import { c as getViteHookHandler, n as resolvePackageDir, o as normalizeStyleInjectorOptions, r as normalizeOutputPathKey, t as createSourceCandidateScanSignature } from "./source-candidate-scan-signature-BWLf4tuO.js";
7
8
  import { existsSync, realpathSync } from "node:fs";
8
9
  import path from "node:path";
9
10
  import process$1 from "node:process";
10
- import { applyConfiguredCssCalc, canProcessSourceStyleAsCss, collectImportedCssFiles, hasNonCommentCss, isStyleImportRequest, normalizeInjectableCssWithImports, removeTailwindEntryDirectivesFromCss, removeTailwindPostcssPlugins, resolvePostcssConfig, rewriteTailwindPackageImportStatements, stripTailwindConfigDirectives, transformWebCssCompat } from "@weapp-tailwindcss/postcss/transform";
11
+ import { applyConfiguredCssCalc, applyConfiguredCssUnits, canProcessSourceStyleAsCss, collectImportedCssFiles, hasNonCommentCss, isStyleImportRequest, normalizeInjectableCssWithImports, parseCssImportSpecifier, postcss, removeTailwindEntryDirectivesFromCss, removeTailwindPostcssPlugins, resolvePostcssConfig, rewriteTailwindPackageImportStatements, stripTailwindConfigDirectives, transformWebCssCompat } from "@weapp-tailwindcss/postcss/transform";
11
12
  import { LRUCache } from "lru-cache";
12
13
  import { cleanUrl as cleanUrl$1, ensurePosix } from "@weapp-tailwindcss/shared";
14
+ import { Buffer } from "node:buffer";
13
15
  import { readFile } from "node:fs/promises";
14
16
  import { logger } from "@weapp-tailwindcss/logger";
15
17
  import { fileURLToPath } from "node:url";
@@ -202,6 +204,59 @@ function createViteCssAssetIdentityResolver(options) {
202
204
  };
203
205
  }
204
206
  //#endregion
207
+ //#region src/bundlers/vite/css-calc-stage.ts
208
+ const deferredKeys = [
209
+ "cssCalc",
210
+ "rem2rpx",
211
+ "px2rpx",
212
+ "unitsToPx",
213
+ "unitConversion"
214
+ ];
215
+ const deferredKeySet = new Set(deferredKeys);
216
+ const deferredOptions = Object.fromEntries(deferredKeys.map((key) => [key, false]));
217
+ /** 构建中保留原始单位和表达式;最终输出阶段仍读取用户的真实配置。 */
218
+ function createViteCssCalcStage(original, isBuild, getPlatform = () => void 0) {
219
+ const resolveFinalOptions = () => resolveStyleOptionsFromContext({
220
+ ...original,
221
+ platform: original.cssOptions?.platform ?? original.platform ?? getPlatform()
222
+ }, original.tailwindRuntime.majorVersion);
223
+ const shouldDefer = () => {
224
+ if (!isBuild() || !(original.cssOptions?.cssCalc ?? original.cssCalc)) return false;
225
+ const finalOptions = resolveFinalOptions();
226
+ return finalOptions.uniAppX !== true && !resolveUniUtsPlatform(finalOptions.platform).isApp;
227
+ };
228
+ const defer = (options) => shouldDefer() ? {
229
+ ...options,
230
+ ...deferredOptions,
231
+ cssOptions: {
232
+ ...options?.cssOptions,
233
+ ...deferredOptions
234
+ }
235
+ } : options;
236
+ const styleHandler = Object.assign((css, options) => original.styleHandler(css, defer(options)), {
237
+ transformRoot: ((root, options) => original.styleHandler.transformRoot(root, defer(options))),
238
+ getPipeline: ((options) => original.styleHandler.getPipeline(defer(options)))
239
+ });
240
+ return {
241
+ options: new Proxy(original, { get(target, key, receiver) {
242
+ if (key === "styleHandler") return styleHandler;
243
+ if (shouldDefer()) {
244
+ if (deferredKeySet.has(key)) return false;
245
+ if (key === "cssOptions") return {
246
+ ...target.cssOptions,
247
+ ...deferredOptions
248
+ };
249
+ }
250
+ return Reflect.get(target, key, receiver);
251
+ } }),
252
+ getFinalOptions: () => shouldDefer() ? {
253
+ ...resolveFinalOptions(),
254
+ customPropertyValues: original.customPropertyValues
255
+ } : void 0,
256
+ shouldDefer
257
+ };
258
+ }
259
+ //#endregion
205
260
  //#region src/bundlers/vite/processed-css-assets/style-files.ts
206
261
  const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
207
262
  function isCssOutputFile(file) {
@@ -1713,92 +1768,183 @@ function sendFullReloadForUnresolvedHotUpdate(ctx) {
1713
1768
  });
1714
1769
  }
1715
1770
  //#endregion
1716
- //#region src/bundlers/vite/css-finalizer/options.ts
1717
- function inferPlatformFromViteOutDir(outDir) {
1718
- const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
1719
- if (!segment) return;
1720
- const normalized = segment.trim().toLowerCase();
1721
- if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
1722
- }
1723
- function isAddWatchFileInvalidRollupPhaseError(error) {
1724
- const candidate = error;
1725
- return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
1726
- }
1727
- function registerGeneratorDependencies(ctx, dependencies) {
1728
- if (typeof ctx.addWatchFile !== "function") return;
1729
- for (const dependency of dependencies ?? []) try {
1730
- ctx.addWatchFile(dependency);
1731
- } catch (error) {
1732
- if (isAddWatchFileInvalidRollupPhaseError(error)) {
1733
- logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
1734
- continue;
1771
+ //#region src/bundlers/vite/css-finalizer/css-scope-graph.ts
1772
+ function outputKey(file) {
1773
+ return path.posix.normalize(normalizeOutputPathKey(file));
1774
+ }
1775
+ function collectReachable(graph, roots) {
1776
+ const visited = /* @__PURE__ */ new Set();
1777
+ const pending = [...roots];
1778
+ while (pending.length > 0) {
1779
+ const file = pending.pop();
1780
+ if (visited.has(file) || !graph.has(file)) continue;
1781
+ visited.add(file);
1782
+ pending.push(...graph.get(file));
1783
+ }
1784
+ return visited;
1785
+ }
1786
+ function collectSourceComponents(graph) {
1787
+ let nextIndex = 0;
1788
+ const indexes = /* @__PURE__ */ new Map();
1789
+ const lowLinks = /* @__PURE__ */ new Map();
1790
+ const stack = [];
1791
+ const onStack = /* @__PURE__ */ new Set();
1792
+ const components = [];
1793
+ const owners = /* @__PURE__ */ new Map();
1794
+ const visit = (file) => {
1795
+ const index = nextIndex++;
1796
+ indexes.set(file, index);
1797
+ lowLinks.set(file, index);
1798
+ stack.push(file);
1799
+ onStack.add(file);
1800
+ for (const target of graph.get(file)) if (!indexes.has(target)) {
1801
+ visit(target);
1802
+ lowLinks.set(file, Math.min(lowLinks.get(file), lowLinks.get(target)));
1803
+ } else if (onStack.has(target)) lowLinks.set(file, Math.min(lowLinks.get(file), indexes.get(target)));
1804
+ if (lowLinks.get(file) !== index) return;
1805
+ const component = [];
1806
+ let member;
1807
+ do {
1808
+ member = stack.pop();
1809
+ onStack.delete(member);
1810
+ owners.set(member, components.length);
1811
+ component.push(member);
1812
+ } while (member !== file);
1813
+ components.push(component);
1814
+ };
1815
+ for (const file of graph.keys()) if (!indexes.has(file)) visit(file);
1816
+ const importedComponents = /* @__PURE__ */ new Set();
1817
+ for (const [file, targets] of graph) for (const target of targets) if (owners.get(file) !== owners.get(target)) importedComponents.add(owners.get(target));
1818
+ return components.filter((_, index) => !importedComponents.has(index));
1819
+ }
1820
+ /** 按最终入口及 CSS 导入关系收集每个样式产物可见的变量上下文。 */
1821
+ function collectCssCalcScopes(bundle, options) {
1822
+ const assets = new Map(Object.entries(bundle).flatMap(([key, output]) => {
1823
+ const file = outputKey(output.fileName || key);
1824
+ return output.type === "asset" && options.matchesCss(file) ? [[file, output]] : [];
1825
+ }));
1826
+ const graph = /* @__PURE__ */ new Map();
1827
+ const conditionalRoots = /* @__PURE__ */ new Set();
1828
+ for (const [file, asset] of assets) {
1829
+ const targets = /* @__PURE__ */ new Set();
1830
+ const source = typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString();
1831
+ postcss.parse(source).walkAtRules("import", (rule) => {
1832
+ const params = rule.raws.params?.raw ?? rule.params;
1833
+ const parsed = parseCssImportSpecifier(params);
1834
+ const request = parsed?.specifier;
1835
+ if (!parsed || !request || /^(?:[a-z][a-z\d+.-]*:|\/|\\\\|#)/i.test(request)) return;
1836
+ const target = outputKey(path.posix.join(path.posix.dirname(file), outputKey(request.replace(/[?#].*$/, ""))));
1837
+ if (assets.has(target)) {
1838
+ targets.add(target);
1839
+ let conditional = params.slice(params.indexOf(parsed.raw) + parsed.raw.length).trim().length > 0 || Boolean(rule.raws.between?.trim());
1840
+ let ancestor = rule.parent;
1841
+ while (ancestor && ancestor.type !== "root" && !conditional) {
1842
+ conditional = ancestor.type === "atrule";
1843
+ ancestor = ancestor.parent;
1844
+ }
1845
+ if (conditional) conditionalRoots.add(target);
1846
+ }
1847
+ });
1848
+ graph.set(file, targets);
1849
+ }
1850
+ for (const file of collectReachable(graph, conditionalRoots)) options.onConditionalSource?.(file);
1851
+ const scopes = /* @__PURE__ */ new Map();
1852
+ const addScope = (roots) => {
1853
+ const visible = collectReachable(graph, roots);
1854
+ for (const file of visible) {
1855
+ const scope = scopes.get(file) ?? /* @__PURE__ */ new Set();
1856
+ for (const target of visible) scope.add(target);
1857
+ scopes.set(file, scope);
1858
+ }
1859
+ };
1860
+ const chunks = new Map(Object.entries(bundle).flatMap(([key, output]) => output.type === "chunk" ? [[outputKey(output.fileName || key), output]] : []));
1861
+ for (const [file, entry] of chunks) {
1862
+ if (!entry.isEntry && !entry.isDynamicEntry) continue;
1863
+ const roots = /* @__PURE__ */ new Set();
1864
+ const entryName = path.posix.parse(file);
1865
+ const matchingAssets = [...assets.keys()].filter((assetFile) => {
1866
+ const assetName = path.posix.parse(assetFile);
1867
+ return assetName.dir === entryName.dir && assetName.name === entryName.name;
1868
+ });
1869
+ if (matchingAssets.length === 1) roots.add(matchingAssets[0]);
1870
+ const visited = /* @__PURE__ */ new Set();
1871
+ const pending = [file];
1872
+ while (pending.length > 0) {
1873
+ const chunkFile = pending.pop();
1874
+ const chunk = chunks.get(chunkFile);
1875
+ if (!chunk || visited.has(chunkFile)) continue;
1876
+ visited.add(chunkFile);
1877
+ for (const css of chunk.viteMetadata?.importedCss ?? []) {
1878
+ const key = outputKey(css);
1879
+ if (assets.has(key)) roots.add(key);
1880
+ }
1881
+ for (const imported of chunk.imports) {
1882
+ const key = outputKey(imported);
1883
+ pending.push(chunks.has(key) ? key : outputKey(path.posix.join(path.posix.dirname(chunkFile), key)));
1884
+ }
1735
1885
  }
1736
- throw error;
1886
+ addScope(roots);
1737
1887
  }
1738
- }
1739
- function createCssHandlerOptions(opts, majorVersion, file, outputRoot, extraOptions = {}) {
1740
- const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
1741
- return {
1742
- ...extraOptions,
1743
- cssPreflight: opts.cssPreflight,
1744
- isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
1745
- postcssOptions: { options: { from } },
1746
- ...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
1747
- };
1748
- }
1749
- function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
1750
- const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
1751
- appType: opts.appType,
1752
- platform: opts.cssOptions?.platform ?? opts.platform,
1753
- tailwindcssMajorVersion: majorVersion,
1754
- uniAppX: opts.uniAppX
1755
- });
1756
- if (!generatorOptions.enabled) return false;
1757
- if (hasLocalCssImport(rawSource)) return false;
1758
- if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
1759
- if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
1760
- return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
1761
- }
1762
- function shouldFinalizeProcessedCssAsset(opts, file) {
1763
- return opts.mainCssChunkMatcher(file, opts.appType);
1764
- }
1765
- function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
1766
- return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
1767
- }
1768
- function finalizeWebCss(css, context, cssPipelineStrategy) {
1769
- const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(context, cssPipelineStrategy);
1770
- const defaultWebCssCompat = (value) => transformWebCssCompat(value, resolveViteWebCssCompatOptions(context));
1771
- return cssPipelineStrategy?.transformGeneratedCss?.(css, {
1772
- ...context,
1773
- defaultWebCssCompat,
1774
- removeScopedPreflight: (value) => value,
1775
- shouldApplyWebCssCompat
1776
- }) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
1888
+ for (const component of collectSourceComponents(graph)) if (component.some((file) => !scopes.has(file))) addScope(component);
1889
+ return scopes;
1777
1890
  }
1778
1891
  //#endregion
1779
1892
  //#region src/bundlers/vite/css-finalizer/css-calc.ts
1780
- /** 在所有 CSS 资产完成组装后,为普通 Web 样式补齐显式启用的 calc 计算。 */
1781
- async function finalizeWebCssCalc(bundle, context) {
1782
- const cssCalc = context.opts.cssOptions?.cssCalc ?? context.opts.cssCalc;
1783
- if (!cssCalc) return;
1784
- const pending = Object.values(bundle).filter((output) => output.type === "asset" && context.opts.cssMatcher(output.fileName) && !context.opts.htmlMatcher(output.fileName)).map((asset) => ({
1785
- asset,
1786
- original: typeof asset.source === "string" ? asset.source : new TextDecoder().decode(asset.source)
1787
- })).filter(({ original }) => original.includes("calc("));
1788
- if (pending.length === 0) return;
1789
- const sources = new Set(collectViteProcessedCssSources(context.getViteProcessedCssAssetResults));
1790
- const contextCss = sources.size === 1 ? sources.values().next().value : void 0;
1791
- for (const { asset, original } of pending) {
1792
- const css = await applyConfiguredCssCalc(original, {
1793
- cssCalc,
1893
+ const previousAssets = /* @__PURE__ */ new WeakMap();
1894
+ function readSource(asset) {
1895
+ return typeof asset.source === "string" ? asset.source : new TextDecoder().decode(asset.source);
1896
+ }
1897
+ /** 按最终消费作用域求值;保留原始表达式供后续 watch 构建重新判断。 */
1898
+ async function finalizeCssCalc(bundle, context, convertUnits = false) {
1899
+ const deferredOptions = context.getFinalCssCalcOptions?.();
1900
+ const options = deferredOptions ?? context.opts;
1901
+ if (!(options.cssOptions?.cssCalc ?? options.cssCalc)) return;
1902
+ const previous = previousAssets.get(context) ?? /* @__PURE__ */ new Map();
1903
+ const assets = new Map(Object.entries(bundle).flatMap(([key, output]) => {
1904
+ const file = normalizeOutputPathKey(output.fileName || key);
1905
+ return output.type === "asset" && context.opts.cssMatcher(file) && !context.opts.htmlMatcher(file) ? [[file, output]] : [];
1906
+ }));
1907
+ for (const [file, asset] of assets) {
1908
+ const prior = previous.get(file);
1909
+ if (prior?.asset === asset && readSource(asset) === prior.final) asset.source = prior.original;
1910
+ }
1911
+ const conditionalSources = /* @__PURE__ */ new Set();
1912
+ const scopes = collectCssCalcScopes(bundle, {
1913
+ matchesCss: (file) => assets.has(normalizeOutputPathKey(file)),
1914
+ onConditionalSource: (file) => conditionalSources.add(file)
1915
+ });
1916
+ const sources = new Map([...assets].map(([file, asset]) => [file, readSource(asset)]));
1917
+ const next = /* @__PURE__ */ new Map();
1918
+ for (const [file, asset] of assets) {
1919
+ const original = sources.get(file);
1920
+ const contextCss = [...scopes.get(file) ?? [file]].map((sourceFile) => {
1921
+ const source = sources.get(sourceFile) ?? "";
1922
+ return conditionalSources.has(sourceFile) ? `@media all{${source}}` : source;
1923
+ }).join("\n");
1924
+ const calculated = await applyConfiguredCssCalc(original, {
1925
+ ...options,
1794
1926
  contextCss
1795
1927
  });
1928
+ const outDir = context.getResolvedConfig?.()?.build?.outDir;
1929
+ const root = context.getResolvedConfig?.()?.root;
1930
+ const css = convertUnits && deferredOptions ? await applyConfiguredCssUnits(calculated, {
1931
+ ...options,
1932
+ postcssOptions: { options: { from: path.resolve(root ?? ".", outDir ?? ".", file) } }
1933
+ }) : calculated;
1934
+ next.set(file, {
1935
+ asset,
1936
+ original,
1937
+ final: css
1938
+ });
1796
1939
  if (css !== original) {
1797
1940
  asset.source = css;
1798
- context.recordCssAssetResult?.(asset.fileName, css);
1799
- context.opts.onUpdate(asset.fileName, original, css);
1941
+ context.opts.onUpdate(asset.fileName || file, original, css);
1800
1942
  }
1801
1943
  }
1944
+ previousAssets.set(context, next);
1945
+ }
1946
+ function finalizeWebCssCalc(bundle, context) {
1947
+ return finalizeCssCalc(bundle, context, true);
1802
1948
  }
1803
1949
  //#endregion
1804
1950
  //#region src/bundlers/vite/shared/generic-web-production-fast-path.ts
@@ -1854,6 +2000,69 @@ function createGenericWebProductionBundleHooks(options) {
1854
2000
  };
1855
2001
  }
1856
2002
  //#endregion
2003
+ //#region src/bundlers/vite/css-finalizer/options.ts
2004
+ function inferPlatformFromViteOutDir(outDir) {
2005
+ const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
2006
+ if (!segment) return;
2007
+ const normalized = segment.trim().toLowerCase();
2008
+ if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
2009
+ }
2010
+ function isAddWatchFileInvalidRollupPhaseError(error) {
2011
+ const candidate = error;
2012
+ return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
2013
+ }
2014
+ function registerGeneratorDependencies(ctx, dependencies) {
2015
+ if (typeof ctx.addWatchFile !== "function") return;
2016
+ for (const dependency of dependencies ?? []) try {
2017
+ ctx.addWatchFile(dependency);
2018
+ } catch (error) {
2019
+ if (isAddWatchFileInvalidRollupPhaseError(error)) {
2020
+ logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
2021
+ continue;
2022
+ }
2023
+ throw error;
2024
+ }
2025
+ }
2026
+ function createCssHandlerOptions(opts, majorVersion, file, outputRoot, extraOptions = {}) {
2027
+ const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
2028
+ return {
2029
+ ...extraOptions,
2030
+ cssPreflight: opts.cssPreflight,
2031
+ isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
2032
+ postcssOptions: { options: { from } },
2033
+ ...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
2034
+ };
2035
+ }
2036
+ function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
2037
+ const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
2038
+ appType: opts.appType,
2039
+ platform: opts.cssOptions?.platform ?? opts.platform,
2040
+ tailwindcssMajorVersion: majorVersion,
2041
+ uniAppX: opts.uniAppX
2042
+ });
2043
+ if (!generatorOptions.enabled) return false;
2044
+ if (hasLocalCssImport(rawSource)) return false;
2045
+ if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
2046
+ if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
2047
+ return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
2048
+ }
2049
+ function shouldFinalizeProcessedCssAsset(opts, file) {
2050
+ return opts.mainCssChunkMatcher(file, opts.appType);
2051
+ }
2052
+ function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
2053
+ return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
2054
+ }
2055
+ function finalizeWebCss(css, context, cssPipelineStrategy) {
2056
+ const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(context, cssPipelineStrategy);
2057
+ const defaultWebCssCompat = (value) => transformWebCssCompat(value, resolveViteWebCssCompatOptions(context));
2058
+ return cssPipelineStrategy?.transformGeneratedCss?.(css, {
2059
+ ...context,
2060
+ defaultWebCssCompat,
2061
+ removeScopedPreflight: (value) => value,
2062
+ shouldApplyWebCssCompat
2063
+ }) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
2064
+ }
2065
+ //#endregion
1857
2066
  //#region src/bundlers/vite/css-finalizer/generic-web-fast-path.ts
1858
2067
  function readAssetSource(asset) {
1859
2068
  return typeof asset.source === "string" ? asset.source : asset.source.toString();
@@ -3472,7 +3681,8 @@ function resolveWebGeneratorOptions(opts) {
3472
3681
  /** 创建不含 JS/template、分包和小程序 bundle 处理的 Generic Web Vite 插件。 */
3473
3682
  function createCssOnlyVitePlugins(options = {}) {
3474
3683
  const rawOptions = options;
3475
- const opts = "tailwindRuntime" in options ? options : getCompilerContext({
3684
+ let resolvedConfig;
3685
+ const cssCalcStage = createViteCssCalcStage("tailwindRuntime" in options ? options : getCompilerContext({
3476
3686
  ...rawOptions,
3477
3687
  appType: void 0,
3478
3688
  platform: "web",
@@ -3482,7 +3692,8 @@ function createCssOnlyVitePlugins(options = {}) {
3482
3692
  } : { target: "web" },
3483
3693
  __internalDeferMissingCssEntriesWarning: true,
3484
3694
  __internalViteDeferRuntimeLogs: true
3485
- });
3695
+ }), () => resolvedConfig?.command === "build");
3696
+ const opts = cssCalcStage.options;
3486
3697
  const disabled = opts.disabled === true || typeof opts.disabled === "object" && opts.disabled.plugin === true;
3487
3698
  const shouldGenerate = !disabled && resolveWebGeneratorOptions(opts).enabled;
3488
3699
  const sourceCandidateCollector = createSourceCandidateCollector({
@@ -3512,7 +3723,6 @@ function createCssOnlyVitePlugins(options = {}) {
3512
3723
  getGeneratorOptions: () => resolveWebGeneratorOptions(opts),
3513
3724
  isRuntimeAffectingSource: () => false
3514
3725
  });
3515
- let resolvedConfig;
3516
3726
  let recordedCandidates;
3517
3727
  const processedCssRegistry = createFrameworkProcessedCssRegistry();
3518
3728
  const processedCssAssets = /* @__PURE__ */ new WeakSet();
@@ -3651,6 +3861,7 @@ function createCssOnlyVitePlugins(options = {}) {
3651
3861
  });
3652
3862
  const finalizer = createViteWebCssFinalizerOutputPlugin({
3653
3863
  opts,
3864
+ getFinalCssCalcOptions: cssCalcStage.getFinalOptions,
3654
3865
  runtimeState,
3655
3866
  ensureRuntimeClassSet: collectCssSourceCandidates,
3656
3867
  debug,
@@ -3769,4 +3980,4 @@ function createGenericWebVitePlugins(options = {}) {
3769
3980
  });
3770
3981
  }
3771
3982
  //#endregion
3772
- export { resolveSourceStyleSourceFromOutputFile as $, finalizeWebCss as A, formatPostcssSourceMap as At, sendSupplementalCssHotUpdates as B, isRootStyleOutputFile as Bt, tryFinalizeGenericWebCss as C, normalizeCssSourceForCompare as Ct, finalizeWebCssCalc as D, resolveViteCssPipelineOutputFile as Dt, shouldSkipGenericWebProductionSourceCandidates as E, resolveViteCssOutputFile as Et, mergeHotModulesByIdentity as F, slash as Ft, collectChunkModuleIds as G, createGenericWebViteCapabilityProfile as Gt, parseVueRequest as H, createViteSourceOutputRelationOwner as Ht, resolveHotSourceModules as I, createCssHandlerOptionsCache as It, hasTailwindGenerationSource as J, extractSfcStyleBlocks as K, frameworkViteCapabilityProfile as Kt, resolveHotSourceModulesByIds as L, resolveViteCssHandlerExtraOptions as Lt, registerGeneratorDependencies as M, isHTMLRequest as Mt, shouldGenerateCssByGenerator as N, normalizePath as Nt, collectViteProcessedCssSources as O, resolveViteCssPipelineOutputFileFromSourceFile as Ot, hasSelfAcceptingNonStyleHotModule as P, resolveViteCssPipelineRequestFile as Pt, resolveSfcStyleSourceFromOutputFile as Q, resolveHotTailwindCssModules as R, isCssOutputFile as Rt, createViteWebCssFinalizerOutputPlugin as S, canProcessViteSourceStyleAsCss as St, createGenericWebProductionSourceCandidatesApply as T, resolveReplayCssOutputFile as Tt, resolveViteWebCssCompatOptions as U, getActiveViteSourceOutputRelationOwner as Ut, resolveViteModuleIdentity as V, createViteCssAssetIdentityResolver as Vt, shouldApplyViteWebCssCompat as W, withViteSourceOutputRelationOwner as Wt, normalizeSfcSourceFileForCompare as X, isSfcStyleSourceFile as Y, resolveSfcStyleRequestFromKnownSource as Z, normalizeVitePersistentCacheKey as _, removeTailwindEntryDirectivesFromCss as _t, readViteHmrSource as a, collectMatchingGeneratedCssMarkerFiles as at, shouldCollectTransformedSourceCandidates as b, CSS_SOURCE_OUTPUT_EXT_RE as bt, createViteHmrCssModuleVersionFilterPlugin as c, dedupeViteCssResults as ct, createFrameworkCssGenerationQueue as d, isMatchingGeneratedCssMarkerFile as dt, hasMatchingStyleFileBase as et, createViteCssGenerationPlugins as f, normalizeInjectableCssForTarget as ft, isMissingInternalCssSource as g, removeDuplicateUnlinkedRootCssAssetsReferencedByHtml as gt, hasVitePipelineTailwindGenerationDirective as h, readAssetSource$1 as ht, syncFrameworkSourceCandidatesForHotUpdate as i, collectImportedStyleFiles as it, inferPlatformFromViteOutDir as j, isCSSRequest as jt, createCssHandlerOptions as k, cleanUrl$1 as kt, createViteHmrCssModuleVersionTracker as l, getAssetFile as lt, createRewriteCssImportsPlugins as m, normalizeMarkerOutputFile as mt, createFrameworkTailwindRootCss as n, appendCss as nt, createFrameworkProcessedCssRegistry as o, collectRootStyleBundleCssSources as ot, createViteRuntimeClassSet as p, normalizeInjectableCssForTargetWithImports as pt, hasSfcStyleSources as q, createFrameworkSourceScanSession as r, clearAssetSource as rt, createFrameworkPostPlugin as s, createCssAssetPipelineContext as st, createGenericWebVitePlugins as t, isMatchingCssSourceFile as tt, createViteHmrCandidateState as u, hasNonCommentCss as ut, summarizeStringCache as v, resolveViteProcessedCssAssetSource as vt, createGenericWebProductionBundleHooks as w, resolveMiniProgramStyleOutputExtension as wt, touchMapEntry as x, SOURCE_STYLE_OUTPUT_EXT_RE as xt, createViteCssMemory as y, posix as yt, sendFullReloadForUnresolvedHotUpdate as z, isMiniProgramStyleOutputFile as zt };
3983
+ export { resolveSfcStyleSourceFromOutputFile as $, createGenericWebProductionBundleHooks as A, cleanUrl$1 as At, sendFullReloadForUnresolvedHotUpdate as B, isMiniProgramStyleOutputFile as Bt, tryFinalizeGenericWebCss as C, canProcessViteSourceStyleAsCss as Ct, inferPlatformFromViteOutDir as D, resolveViteCssOutputFile as Dt, finalizeWebCss as E, resolveReplayCssOutputFile as Et, hasSelfAcceptingNonStyleHotModule as F, resolveViteCssPipelineRequestFile as Ft, shouldApplyViteWebCssCompat as G, getActiveViteSourceOutputRelationOwner as Gt, resolveViteModuleIdentity as H, createViteCssCalcStage as Ht, mergeHotModulesByIdentity as I, slash as It, hasSfcStyleSources as J, frameworkViteCapabilityProfile as Jt, collectChunkModuleIds as K, withViteSourceOutputRelationOwner as Kt, resolveHotSourceModules as L, createCssHandlerOptionsCache as Lt, shouldSkipGenericWebProductionSourceCandidates as M, isCSSRequest as Mt, finalizeCssCalc as N, isHTMLRequest as Nt, registerGeneratorDependencies as O, resolveViteCssPipelineOutputFile as Ot, finalizeWebCssCalc as P, normalizePath as Pt, resolveSfcStyleRequestFromKnownSource as Q, resolveHotSourceModulesByIds as R, resolveViteCssHandlerExtraOptions as Rt, createViteWebCssFinalizerOutputPlugin as S, SOURCE_STYLE_OUTPUT_EXT_RE as St, createCssHandlerOptions as T, resolveMiniProgramStyleOutputExtension as Tt, parseVueRequest as U, createViteCssAssetIdentityResolver as Ut, sendSupplementalCssHotUpdates as V, isRootStyleOutputFile as Vt, resolveViteWebCssCompatOptions as W, createViteSourceOutputRelationOwner as Wt, isSfcStyleSourceFile as X, hasTailwindGenerationSource as Y, normalizeSfcSourceFileForCompare as Z, normalizeVitePersistentCacheKey as _, removeDuplicateUnlinkedRootCssAssetsReferencedByHtml as _t, readViteHmrSource as a, collectImportedStyleFiles as at, shouldCollectTransformedSourceCandidates as b, posix as bt, createViteHmrCssModuleVersionFilterPlugin as c, createCssAssetPipelineContext as ct, createFrameworkCssGenerationQueue as d, hasNonCommentCss as dt, resolveSourceStyleSourceFromOutputFile as et, createViteCssGenerationPlugins as f, isMatchingGeneratedCssMarkerFile as ft, isMissingInternalCssSource as g, readAssetSource$1 as gt, hasVitePipelineTailwindGenerationDirective as h, normalizeMarkerOutputFile as ht, syncFrameworkSourceCandidatesForHotUpdate as i, clearAssetSource as it, createGenericWebProductionSourceCandidatesApply as j, formatPostcssSourceMap as jt, shouldGenerateCssByGenerator as k, resolveViteCssPipelineOutputFileFromSourceFile as kt, createViteHmrCssModuleVersionTracker as l, dedupeViteCssResults as lt, createRewriteCssImportsPlugins as m, normalizeInjectableCssForTargetWithImports as mt, createFrameworkTailwindRootCss as n, isMatchingCssSourceFile as nt, createFrameworkProcessedCssRegistry as o, collectMatchingGeneratedCssMarkerFiles as ot, createViteRuntimeClassSet as p, normalizeInjectableCssForTarget as pt, extractSfcStyleBlocks as q, createGenericWebViteCapabilityProfile as qt, createFrameworkSourceScanSession as r, appendCss as rt, createFrameworkPostPlugin as s, collectRootStyleBundleCssSources as st, createGenericWebVitePlugins as t, hasMatchingStyleFileBase as tt, createViteHmrCandidateState as u, getAssetFile as ut, summarizeStringCache as v, removeTailwindEntryDirectivesFromCss as vt, collectViteProcessedCssSources as w, normalizeCssSourceForCompare as wt, touchMapEntry as x, CSS_SOURCE_OUTPUT_EXT_RE as xt, createViteCssMemory as y, resolveViteProcessedCssAssetSource as yt, resolveHotTailwindCssModules as z, isCssOutputFile as zt };