weapp-tailwindcss 5.5.8 → 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.
- package/dist/bundlers/vite/css-calc-stage.d.ts +8 -0
- package/dist/bundlers/vite/css-finalizer/css-calc.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer/css-scope-graph.d.ts +5 -0
- package/dist/bundlers/vite/css-finalizer/final-assets.d.ts +1 -1
- package/dist/bundlers/vite/css-finalizer/options.d.ts +1 -0
- package/dist/{compiler-DbwS3329.cjs → compiler-TvqqdOMD.cjs} +50 -38
- package/dist/{compiler-CThodfGH.js → compiler-v9sYta8W.js} +35 -30
- package/dist/core/compiler/generation-cache.d.ts +4 -2
- package/dist/core/compiler/root-store.d.ts +1 -1
- package/dist/core/compiler/source.d.ts +7 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{generated-css-marker-B0RyziOH.cjs → generated-css-marker-C21q8hGM.cjs} +48 -20
- package/dist/generation/pipeline/style-context.d.ts +3 -0
- package/dist/{generator-CxauQbx3.cjs → generator-B1sYQpWu.cjs} +165 -90
- package/dist/{generator-oKZ5mCJ5.js → generator-LqofzXgr.js} +155 -92
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/dist/{gulp-CngHA9cU.cjs → gulp-BhQhrDCx.cjs} +5 -5
- package/dist/{gulp-DhddVxGA.js → gulp-ComuY3KW.js} +4 -4
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-xPpat-km.js → hmr-timing-CNo2hmaX.js} +48 -20
- package/dist/{hmr-timing-Dc4c1VRg.cjs → hmr-timing-CXBDn0dl.cjs} +4 -4
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/{pipeline-helpers-EUud9R2K.cjs → pipeline-helpers-B9ZqLXma.cjs} +3 -3
- package/dist/postcss.cjs +1 -1
- package/dist/postcss.js +1 -1
- package/dist/presets.cjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +2 -2
- package/dist/{scoped-generator-lbTwL6mD.cjs → scoped-generator-BAiZDC_4.cjs} +4 -4
- package/dist/{scoped-generator-DlQrVbuC.js → scoped-generator-CF0ROe7B.js} +4 -4
- package/dist/{source-candidate-scan-signature-BjVQYL-C.js → source-candidate-scan-signature-BWLf4tuO.js} +2 -2
- package/dist/{source-candidate-scan-signature-nG-rg809.cjs → source-candidate-scan-signature-_ohG0ePd.cjs} +2 -2
- package/dist/tailwindcss/v4/rpx-theme-warning.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/raw-generation.d.ts +30 -0
- package/dist/tailwindcss/v4-engine/generator/style-context.d.ts +3 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +2 -0
- package/dist/{tailwindcss-kSd0ykiX.js → tailwindcss-XNfJSlhp.js} +2 -2
- package/dist/{tailwindcss-U3KIUegn.cjs → tailwindcss-uf04Iolj.cjs} +2 -2
- package/dist/{transform-DVg4q8hh.cjs → transform-DJkkjruV.cjs} +3 -3
- package/dist/{transform-BAon9ykq.js → transform-I-mzwoiv.js} +3 -3
- package/dist/utils/stable-serialize.d.ts +1 -0
- package/dist/vite/web.cjs +1 -1
- package/dist/vite/web.js +1 -1
- package/dist/{vite-IX83wh_L.cjs → vite-BVcj7Ht9.cjs} +18 -14
- package/dist/{vite-D-RGkmOE.js → vite-Bd-Ig5Dy.js} +17 -13
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-generation-loader.cjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
- package/dist/{web--kA4HUTm.js → web-BsFZOq3g.js} +296 -85
- package/dist/{web-DHfZ_KC9.cjs → web-Dq2PzKKQ.cjs} +307 -84
- package/dist/{webpack-BetjemzT.cjs → webpack-CWMoTWzF.cjs} +8 -8
- package/dist/{webpack-Bhkd27Rs.js → webpack-DtAZoEth.js} +6 -6
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +4 -3
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { a as findTailwindConfig, f as resolveSourceScanEntries, l as getRuntimeClassSetSignature, v as source_scan_exports } from "./tailwindcss-
|
|
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-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { c as
|
|
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/
|
|
1717
|
-
function
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
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
|
-
|
|
1886
|
+
addScope(roots);
|
|
1737
1887
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
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
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
if (
|
|
1789
|
-
const
|
|
1790
|
-
const
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
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.
|
|
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
|
-
|
|
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 {
|
|
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 };
|