weapp-tailwindcss 5.0.5 → 5.0.7
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/{bundle-state-Cso_ceUo.js → bundle-state-BzwPS-UI.js} +2 -1
- package/dist/{bundle-state-DEyxCR4f.mjs → bundle-state-ChcOKb9w.mjs} +2 -1
- package/dist/bundlers/gulp/index.d.ts +3 -4
- package/dist/bundlers/gulp/module-graph.d.ts +2 -0
- package/dist/bundlers/gulp/runtime-snapshot.d.ts +5 -0
- package/dist/bundlers/gulp/vinyl-transform.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/css-source-trace.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/directives/fallback.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +56 -0
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +27 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +26 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +4 -32
- package/dist/bundlers/vite/css-finalizer.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/css-config-directives.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +14 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +11 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/style-matching.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/subpackages.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +68 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +4 -62
- package/dist/bundlers/vite/incremental-runtime-class-set/entries.d.ts +4 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +2 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +13 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +17 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/scan-root.d.ts +10 -0
- package/dist/bundlers/vite/source-candidates/script.d.ts +7 -0
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +1 -0
- package/dist/bundlers/vite/source-candidates.d.ts +8 -3
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +20 -0
- package/dist/bundlers/vite/source-scan/dependencies.d.ts +2 -0
- package/dist/bundlers/vite/source-scan.d.ts +2 -12
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -20
- package/dist/cli.js +69 -69
- package/dist/cli.mjs +69 -69
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{defaults-BPUuNYcD.js → defaults-Boc26eel.js} +1 -0
- package/dist/{defaults-8xrgzxFY.mjs → defaults-DH0ZQRhy.mjs} +1 -0
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-AD-eX8Tr.js → generator-6yF8wjxR.js} +1 -1
- package/dist/{generator-DVWLNO0n.mjs → generator-BON6M1bL.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp-_7p1Z2vc.js +473 -0
- package/dist/gulp-oE-Byqk6.mjs +463 -0
- package/dist/gulp.js +4 -414
- package/dist/gulp.mjs +1 -406
- package/dist/{incremental-runtime-class-set-vOetpdWs.js → hmr-timing-BKQNRxHr.js} +1257 -459
- package/dist/{incremental-runtime-class-set-xf49kky6.mjs → hmr-timing-BVTGf5ch.mjs} +1221 -477
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/dist/{postcss-Cbi6RFpf.js → postcss-BTIunhWl.js} +7 -7
- package/dist/{postcss-hSUxK7oR.mjs → postcss-BtmrrZ31.mjs} +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-Bsn_LMmo.mjs → precheck-CZjr87m_.mjs} +19 -5
- package/dist/{precheck-b8Y8qZg0.js → precheck-fhIkzCSU.js} +19 -5
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/tailwindcss/source-scan/inline-source.d.ts +7 -0
- package/dist/tailwindcss/source-scan.d.ts +2 -7
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +3 -0
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +10 -0
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +6 -0
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/{tailwindcss-AWaPVF2B.mjs → tailwindcss-bbQUg25J.mjs} +2 -2
- package/dist/{tailwindcss-CpQ6X4l6.js → tailwindcss-vswd1gc3.js} +2 -2
- package/dist/{transform-BkGtbxb1.js → transform-CReJxxh_.js} +11 -2
- package/dist/{transform-DumSZmTh.mjs → transform-DEsFlG9k.mjs} +11 -2
- package/dist/types/typedoc-tailwindcss-patch.d.ts +4 -2
- package/dist/types/user-defined-options/general.d.ts +5 -0
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/harmony.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +16 -0
- package/dist/uni-app-x/style-asset.d.ts +20 -0
- package/dist/uni-app-x/transform.d.ts +1 -0
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v3-engine-CM0TRa8V.js → v3-engine-CEMXFegG.js} +714 -663
- package/dist/{v3-engine-Cczrkzqt.mjs → v3-engine-CdIwmHuc.mjs} +758 -707
- package/dist/{vite-CTuHPC91.js → vite-0jFbh9hx.js} +1797 -386
- package/dist/{vite-DLXDMHON.mjs → vite-C7BGAlCE.mjs} +1779 -369
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +1169 -1002
- package/dist/{webpack-DJFw08SK.mjs → webpack-Dx6_eg5k.mjs} +96 -36
- package/dist/{webpack-BBHJYKqB.js → webpack-aEuDoYfQ.js} +105 -44
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -5
- package/dist/source-candidates-BsWYoIPN.mjs +0 -355
- package/dist/source-candidates-o2ZrKWzu.js +0 -374
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
-
const require_v3_engine = require("./v3-engine-
|
|
3
|
-
const require_generator = require("./generator-
|
|
4
|
-
const require_precheck = require("./precheck-
|
|
5
|
-
const require_tailwindcss = require("./tailwindcss-
|
|
6
|
-
let
|
|
2
|
+
const require_v3_engine = require("./v3-engine-CEMXFegG.js");
|
|
3
|
+
const require_generator = require("./generator-6yF8wjxR.js");
|
|
4
|
+
const require_precheck = require("./precheck-fhIkzCSU.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-vswd1gc3.js");
|
|
6
|
+
let node_module = require("node:module");
|
|
7
7
|
let postcss = require("postcss");
|
|
8
8
|
postcss = require_chunk.__toESM(postcss);
|
|
9
9
|
let tailwindcss_patch = require("tailwindcss-patch");
|
|
10
10
|
let node_process = require("node:process");
|
|
11
11
|
node_process = require_chunk.__toESM(node_process);
|
|
12
|
+
let node_fs = require("node:fs");
|
|
12
13
|
let node_path = require("node:path");
|
|
13
14
|
node_path = require_chunk.__toESM(node_path);
|
|
15
|
+
let node_fs_promises = require("node:fs/promises");
|
|
14
16
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
17
|
+
let _weapp_core_escape = require("@weapp-core/escape");
|
|
15
18
|
//#region src/bundlers/shared/cache.ts
|
|
16
19
|
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
17
20
|
let cacheHit = false;
|
|
@@ -31,6 +34,199 @@ async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSourc
|
|
|
31
34
|
if (!cacheHit) await applyResult(result, { cacheHit: false });
|
|
32
35
|
}
|
|
33
36
|
//#endregion
|
|
37
|
+
//#region src/bundlers/shared/css-source-trace.ts
|
|
38
|
+
const CSS_SOURCE_TRACE_COMMENT_RE = /^\s*tokens:\s/;
|
|
39
|
+
const TAILWIND_GENERATED_CONTAINER_TRACE_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
40
|
+
function normalizeSelectorTokenCandidate(candidate) {
|
|
41
|
+
return candidate.replace(/(?<!\\)\\:/g, ":").replace(/(?<!\\)\\\//g, "/");
|
|
42
|
+
}
|
|
43
|
+
function normalizeSourcePath(source, root) {
|
|
44
|
+
const resolvedRoot = node_path.default.resolve(root);
|
|
45
|
+
const resolvedSource = node_path.default.resolve(source);
|
|
46
|
+
const relative = node_path.default.relative(resolvedRoot, resolvedSource);
|
|
47
|
+
if (relative && !relative.startsWith("..") && !node_path.default.isAbsolute(relative)) return relative.split(node_path.default.sep).join("/");
|
|
48
|
+
return source.split(node_path.default.sep).join("/");
|
|
49
|
+
}
|
|
50
|
+
function getSourceTraceRoot(opts) {
|
|
51
|
+
const configured = opts.cssSourceTrace;
|
|
52
|
+
if (configured && typeof configured === "object" && configured.root) return configured.root;
|
|
53
|
+
return opts.tailwindcssBasedir ?? node_process.default.cwd();
|
|
54
|
+
}
|
|
55
|
+
function isCssSourceTraceEnabled(opts) {
|
|
56
|
+
return opts.cssSourceTrace === true || typeof opts.cssSourceTrace === "object" && opts.cssSourceTrace !== null;
|
|
57
|
+
}
|
|
58
|
+
function createCssTokenSourceMap(sourcesByToken, opts) {
|
|
59
|
+
const root = getSourceTraceRoot(opts);
|
|
60
|
+
const tokenSources = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const [token, sources] of [...sourcesByToken.entries()].sort(([a], [b]) => a.localeCompare(b))) {
|
|
62
|
+
const source = {
|
|
63
|
+
token,
|
|
64
|
+
sources: [...sources].map((file) => normalizeSourcePath(file, root)).sort()
|
|
65
|
+
};
|
|
66
|
+
tokenSources.set(token, source);
|
|
67
|
+
const escaped = require_precheck.replaceWxml(token, { escapeMap: opts.escapeMap });
|
|
68
|
+
tokenSources.set(escaped, source);
|
|
69
|
+
tokenSources.set(escaped.replaceAll("\\", ""), source);
|
|
70
|
+
}
|
|
71
|
+
return tokenSources;
|
|
72
|
+
}
|
|
73
|
+
function createCssSourceTraceCacheSignature(tokenSources, opts) {
|
|
74
|
+
if (!isCssSourceTraceEnabled(opts)) return "css-source-trace:0";
|
|
75
|
+
if (!tokenSources?.size) return "css-source-trace:1:empty";
|
|
76
|
+
return `css-source-trace:1:${[...tokenSources.values()].map(({ token, sources }) => `${token}<=${sources.join(",")}`).sort().join("|")}`;
|
|
77
|
+
}
|
|
78
|
+
function getTokenSource(tokenSources, token) {
|
|
79
|
+
return tokenSources.get(token);
|
|
80
|
+
}
|
|
81
|
+
function collectRuleSourceTokens(rule, tokenSources) {
|
|
82
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const selector of rule.selectors) {
|
|
84
|
+
const classMatches = selector.matchAll(/\.((?:\\.|[^\s.#:[{>,])*)/g);
|
|
85
|
+
for (const match of classMatches) {
|
|
86
|
+
const rawCandidate = match[1];
|
|
87
|
+
if (!rawCandidate) continue;
|
|
88
|
+
const candidates = [normalizeSelectorTokenCandidate(rawCandidate), rawCandidate];
|
|
89
|
+
for (const candidate of candidates) {
|
|
90
|
+
const source = getTokenSource(tokenSources, candidate);
|
|
91
|
+
if (!source) continue;
|
|
92
|
+
tokens.set(source.token, source);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return tokens;
|
|
98
|
+
}
|
|
99
|
+
function removeTracedTailwindGeneratedContainerRules(root) {
|
|
100
|
+
root.walkRules((rule) => {
|
|
101
|
+
if (!rule.selectors || rule.selectors.length !== 1 || rule.selectors[0] !== ".container") return;
|
|
102
|
+
const previous = rule.prev();
|
|
103
|
+
if (previous?.type !== "comment" || !TAILWIND_GENERATED_CONTAINER_TRACE_COMMENT_RE.test(previous.text)) return;
|
|
104
|
+
previous.remove();
|
|
105
|
+
rule.remove();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function annotateCssSourceTrace(css, options) {
|
|
109
|
+
if (!isCssSourceTraceEnabled(options.opts) || !options.tokenSources?.size) return css;
|
|
110
|
+
try {
|
|
111
|
+
const root = postcss.default.parse(css);
|
|
112
|
+
root.walkComments((comment) => {
|
|
113
|
+
if (CSS_SOURCE_TRACE_COMMENT_RE.test(comment.text)) comment.remove();
|
|
114
|
+
});
|
|
115
|
+
root.walkRules((rule) => {
|
|
116
|
+
const tokens = collectRuleSourceTokens(rule, options.tokenSources);
|
|
117
|
+
if (tokens.size === 0 || !rule.parent) return;
|
|
118
|
+
const lines = [...tokens.values()].map(({ token, sources }) => {
|
|
119
|
+
return `${token} <= ${sources.length > 0 ? sources.join(", ") : "<tailwind generated>"}`;
|
|
120
|
+
});
|
|
121
|
+
const comment = postcss.default.comment({ text: `tokens: ${lines.join(" | ")}` });
|
|
122
|
+
if (rule.raws.before !== void 0) comment.raws.before = rule.raws.before;
|
|
123
|
+
rule.raws.before = "\n";
|
|
124
|
+
rule.parent.insertBefore(rule, comment);
|
|
125
|
+
});
|
|
126
|
+
removeTracedTailwindGeneratedContainerRules(root);
|
|
127
|
+
return root.toString();
|
|
128
|
+
} catch {
|
|
129
|
+
return css;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/bundlers/shared/generator-css/generation-helpers.ts
|
|
134
|
+
function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
|
|
135
|
+
if (target !== "weapp") return css;
|
|
136
|
+
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
137
|
+
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
138
|
+
isTailwindcssV4: majorVersion === 4,
|
|
139
|
+
preservePseudoContentInit: majorVersion === 3
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
143
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
144
|
+
if (!options.isolateCurrentCssCandidates) return true;
|
|
145
|
+
return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
146
|
+
}
|
|
147
|
+
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
148
|
+
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
149
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
150
|
+
return new Set([...scopedRuntime, ...runtime]);
|
|
151
|
+
}
|
|
152
|
+
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
153
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
154
|
+
}
|
|
155
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
156
|
+
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(options.rawSource) && !require_v3_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
157
|
+
}
|
|
158
|
+
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
159
|
+
if (majorVersion !== 4) return false;
|
|
160
|
+
if (target === "web") return true;
|
|
161
|
+
if (isolateCssSource) return false;
|
|
162
|
+
return generatorRuntime.size === 0;
|
|
163
|
+
}
|
|
164
|
+
function shouldAppendWebBundleCssFallback(target, options) {
|
|
165
|
+
return target === "web" && !options.hasMatchedCssSourceFile && !options.hasSourceDirectives;
|
|
166
|
+
}
|
|
167
|
+
function isEmptyCssSourceOrderParts(parts) {
|
|
168
|
+
return parts.before.trim().length === 0 && parts.after.trim().length === 0;
|
|
169
|
+
}
|
|
170
|
+
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
171
|
+
const preflightStyleOptions = {
|
|
172
|
+
cssPreflight: opts.cssPreflight,
|
|
173
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
...require_precheck.resolveStyleOptionsFromContext(opts),
|
|
177
|
+
atRules: opts.atRules,
|
|
178
|
+
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
179
|
+
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
180
|
+
...cssHandlerOptions,
|
|
181
|
+
...preflightStyleOptions,
|
|
182
|
+
...generatorStyleOptions
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function createCssSourceOrderAppend$1(base, extra) {
|
|
186
|
+
if (!base) return extra;
|
|
187
|
+
if (!extra) return base;
|
|
188
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
189
|
+
return `${base}\n${extra}`;
|
|
190
|
+
}
|
|
191
|
+
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
192
|
+
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
193
|
+
}
|
|
194
|
+
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
195
|
+
const placeholderParts = require_v3_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
196
|
+
if (placeholderParts) return placeholderParts;
|
|
197
|
+
const exactParts = require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
|
|
198
|
+
if (exactParts) return exactParts;
|
|
199
|
+
return require_v3_engine.splitTailwindGeneratedCssByBanner(rawSource);
|
|
200
|
+
}
|
|
201
|
+
function shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, options) {
|
|
202
|
+
const hasApplyDirectives = require_v3_engine.hasTailwindApplyDirective(options.rawSource);
|
|
203
|
+
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || majorVersion === 4 && hasApplyDirectives || cssHandlerOptions.isMainChunk;
|
|
204
|
+
}
|
|
205
|
+
function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
|
|
206
|
+
return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
207
|
+
}
|
|
208
|
+
function mergeGeneratorResults(generatedResults) {
|
|
209
|
+
const firstGenerated = generatedResults[0];
|
|
210
|
+
if (!firstGenerated) return;
|
|
211
|
+
if (generatedResults.length === 1) return firstGenerated;
|
|
212
|
+
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
213
|
+
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
214
|
+
return {
|
|
215
|
+
...firstGenerated,
|
|
216
|
+
css: generatedResults.map((item) => item.css).join("\n"),
|
|
217
|
+
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
218
|
+
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
219
|
+
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
220
|
+
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
221
|
+
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
222
|
+
sources: generatedResults.flatMap((item) => item.sources)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS$1 = new Set([3, 4]);
|
|
226
|
+
function isSupportedGeneratorMajorVersion(majorVersion) {
|
|
227
|
+
return SUPPORTED_GENERATOR_MAJOR_VERSIONS$1.has(majorVersion ?? 0);
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
34
230
|
//#region src/bundlers/shared/generator-css/legacy-selectors.ts
|
|
35
231
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
36
232
|
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
@@ -267,13 +463,6 @@ function isPathWithinRoot$1(file, root) {
|
|
|
267
463
|
const relative = node_path.default.relative(root, file);
|
|
268
464
|
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
269
465
|
}
|
|
270
|
-
function countCommonSuffixSegments(a, b) {
|
|
271
|
-
const aSegments = a.split("/").filter(Boolean);
|
|
272
|
-
const bSegments = b.split("/").filter(Boolean);
|
|
273
|
-
let count = 0;
|
|
274
|
-
while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
|
|
275
|
-
return count;
|
|
276
|
-
}
|
|
277
466
|
function collectOutputMatchBases(file, sourceOptions) {
|
|
278
467
|
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
279
468
|
const roots = [
|
|
@@ -308,7 +497,7 @@ function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
|
308
497
|
const normalizedRoot = node_path.default.resolve(root);
|
|
309
498
|
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
310
499
|
}
|
|
311
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)
|
|
500
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
312
501
|
return false;
|
|
313
502
|
}
|
|
314
503
|
function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
@@ -326,13 +515,9 @@ function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
|
326
515
|
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
327
516
|
}
|
|
328
517
|
let bestScore = 0;
|
|
329
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
333
|
-
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
334
|
-
else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
|
|
335
|
-
}
|
|
518
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
519
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
520
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
336
521
|
return bestScore;
|
|
337
522
|
}
|
|
338
523
|
function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
|
|
@@ -491,7 +676,7 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
|
491
676
|
return true;
|
|
492
677
|
}
|
|
493
678
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
494
|
-
return rawSource.includes("@apply") || require_v3_engine.hasTailwindGeneratedCss(rawSource) || require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource);
|
|
679
|
+
return rawSource.includes("@apply") || require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v3_engine.hasTailwindGeneratedCss(rawSource) || require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource);
|
|
495
680
|
}
|
|
496
681
|
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
497
682
|
return Boolean(sourceSideEntrySource) && !require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
@@ -536,17 +721,6 @@ function collectCssSourceMatchBases(file, roots) {
|
|
|
536
721
|
} else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
537
722
|
return bases;
|
|
538
723
|
}
|
|
539
|
-
function hasMatchingCssSourceBase(outputBases, sourceBases) {
|
|
540
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
|
|
544
|
-
return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
|
|
545
|
-
sourceOptions.outputRoot,
|
|
546
|
-
sourceOptions.projectRoot,
|
|
547
|
-
sourceOptions.cwd
|
|
548
|
-
]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
|
|
549
|
-
}
|
|
550
724
|
function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
551
725
|
const outputBases = collectCssSourceMatchBases(file, [
|
|
552
726
|
sourceOptions.outputRoot,
|
|
@@ -633,12 +807,29 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
633
807
|
if (!cssSources?.length) return;
|
|
634
808
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
635
809
|
const sourceFile = resolvePostcssSourceFile(cssHandlerOptions);
|
|
636
|
-
const
|
|
637
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return
|
|
638
|
-
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
810
|
+
const matches = cssSources.map((cssSource, index) => {
|
|
811
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
|
|
812
|
+
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return {
|
|
813
|
+
cssSource,
|
|
814
|
+
index,
|
|
815
|
+
score: 1e6
|
|
816
|
+
};
|
|
817
|
+
if (typeof cssSource.file === "string") {
|
|
818
|
+
const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions);
|
|
819
|
+
if (pathScore > 0) return {
|
|
820
|
+
cssSource,
|
|
821
|
+
index,
|
|
822
|
+
score: pathScore
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
if (normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource) return {
|
|
826
|
+
cssSource,
|
|
827
|
+
index,
|
|
828
|
+
score: 1
|
|
829
|
+
};
|
|
830
|
+
}).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score || a.index - b.index);
|
|
831
|
+
const bestScore = matches[0]?.score;
|
|
832
|
+
const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
|
|
642
833
|
if (!matchingSource) return;
|
|
643
834
|
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
|
|
644
835
|
}
|
|
@@ -710,7 +901,10 @@ function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
|
710
901
|
async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
|
|
711
902
|
if (!resolvedEntrySource) return;
|
|
712
903
|
const resolvedSourceOptions = require_v3_engine.omitUndefined(sourceOptions);
|
|
713
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file,
|
|
904
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, {
|
|
905
|
+
...resolvedSourceOptions,
|
|
906
|
+
sourceFile: resolvedEntrySource.file
|
|
907
|
+
});
|
|
714
908
|
const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
715
909
|
return withMatchedSourceSideMetadata(await require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
716
910
|
base: resolvedEntrySource.base,
|
|
@@ -741,7 +935,25 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
741
935
|
}
|
|
742
936
|
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
743
937
|
if (!require_v3_engine.hasTailwindApplyDirective(css) || require_v3_engine.hasTailwindRootDirectives(css)) return css;
|
|
744
|
-
|
|
938
|
+
const utilities = collectTailwindApplyUtilities(css);
|
|
939
|
+
return [
|
|
940
|
+
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
941
|
+
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
942
|
+
css
|
|
943
|
+
].filter(Boolean).join("\n");
|
|
944
|
+
}
|
|
945
|
+
function collectTailwindApplyUtilities(css) {
|
|
946
|
+
let root;
|
|
947
|
+
try {
|
|
948
|
+
root = postcss.default.parse(css);
|
|
949
|
+
} catch {
|
|
950
|
+
return [];
|
|
951
|
+
}
|
|
952
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
953
|
+
root.walkAtRules("apply", (rule) => {
|
|
954
|
+
for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
955
|
+
});
|
|
956
|
+
return [...utilities].sort();
|
|
745
957
|
}
|
|
746
958
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
747
959
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -854,11 +1066,15 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
854
1066
|
return resolved ? [resolved] : [];
|
|
855
1067
|
}
|
|
856
1068
|
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1069
|
+
if (matchedCssEntrySource) return [generatorOptions?.config ? {
|
|
1070
|
+
...matchedCssEntrySource,
|
|
1071
|
+
css: require_v3_engine.prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
1072
|
+
} : matchedCssEntrySource];
|
|
1073
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1074
|
+
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
857
1075
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
858
1076
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
859
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
860
1077
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
861
|
-
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
862
1078
|
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
863
1079
|
...preferredCssEntrySource,
|
|
864
1080
|
css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -1036,6 +1252,27 @@ function resolveLegacyCompatCssSource(rawSource) {
|
|
|
1036
1252
|
setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
|
|
1037
1253
|
return resolved;
|
|
1038
1254
|
}
|
|
1255
|
+
function removeMiniProgramContainerCompatCss(css) {
|
|
1256
|
+
try {
|
|
1257
|
+
const root = postcss.default.parse(css);
|
|
1258
|
+
let removed = false;
|
|
1259
|
+
root.walkRules((rule) => {
|
|
1260
|
+
if (rule.selectors?.length === 1 && rule.selectors[0] === ".container") {
|
|
1261
|
+
rule.remove();
|
|
1262
|
+
removed = true;
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
root.walkAtRules((atRule) => {
|
|
1266
|
+
if (atRule.nodes && atRule.nodes.length === 0) {
|
|
1267
|
+
atRule.remove();
|
|
1268
|
+
removed = true;
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
return removed ? root.toString() : css;
|
|
1272
|
+
} catch {
|
|
1273
|
+
return css;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1039
1276
|
function hasContainerConfigToken(rawSource) {
|
|
1040
1277
|
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
1041
1278
|
}
|
|
@@ -1064,7 +1301,8 @@ function hasConfiguredContainerCompatSources(sources) {
|
|
|
1064
1301
|
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
1065
1302
|
}
|
|
1066
1303
|
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1067
|
-
const
|
|
1304
|
+
const resolvedCompatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1305
|
+
const compatSource = removeGeneratedSelectorCompatCss(generatorTarget === "weapp" ? removeMiniProgramContainerCompatCss(resolvedCompatSource) : resolvedCompatSource, css);
|
|
1068
1306
|
if (compatSource.trim().length === 0) return css;
|
|
1069
1307
|
if (generatorTarget !== "weapp") return require_v3_engine.createCssAppend(css, compatSource);
|
|
1070
1308
|
const styleOptions = {
|
|
@@ -1082,6 +1320,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
|
|
|
1082
1320
|
return require_v3_engine.createCssAppend(css, cleanedCompatCss);
|
|
1083
1321
|
}
|
|
1084
1322
|
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1323
|
+
if (generatorTarget === "weapp") return css;
|
|
1085
1324
|
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1086
1325
|
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1087
1326
|
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
@@ -1144,152 +1383,106 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
1144
1383
|
}
|
|
1145
1384
|
}
|
|
1146
1385
|
//#endregion
|
|
1147
|
-
//#region src/bundlers/shared/generator-css/
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
const UTILITY_LAYER_INSERTION_RES = [
|
|
1151
|
-
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
1152
|
-
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
1153
|
-
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
1154
|
-
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
1155
|
-
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
1156
|
-
];
|
|
1157
|
-
function appendCss(base, extra) {
|
|
1386
|
+
//#region src/bundlers/shared/generator-css/local-imports.ts
|
|
1387
|
+
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1388
|
+
function createCssSourceOrderAppend(base, extra) {
|
|
1158
1389
|
if (!base) return extra;
|
|
1159
1390
|
if (!extra) return base;
|
|
1160
1391
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1161
1392
|
return `${base}\n${extra}`;
|
|
1162
1393
|
}
|
|
1163
|
-
function
|
|
1164
|
-
|
|
1165
|
-
if (!trimmed) return css;
|
|
1166
|
-
const index = css.indexOf(trimmed);
|
|
1167
|
-
if (index === -1) return css;
|
|
1168
|
-
return appendCss(css.slice(0, index).trimEnd(), css.slice(index + trimmed.length).trimStart());
|
|
1394
|
+
function isLocalImportRequest(request) {
|
|
1395
|
+
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1169
1396
|
}
|
|
1170
|
-
function
|
|
1171
|
-
|
|
1397
|
+
function isPureLocalCssImportWrapper(css) {
|
|
1398
|
+
let hasImport = false;
|
|
1172
1399
|
try {
|
|
1173
|
-
postcss.default.parse(css)
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1400
|
+
const root = postcss.default.parse(css);
|
|
1401
|
+
for (const node of root.nodes) {
|
|
1402
|
+
if (node.type === "comment") continue;
|
|
1403
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
1404
|
+
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1405
|
+
if (!request || !isLocalImportRequest(request)) return false;
|
|
1406
|
+
hasImport = true;
|
|
1407
|
+
}
|
|
1408
|
+
} catch {
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
return hasImport;
|
|
1181
1412
|
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1413
|
+
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
1414
|
+
let hasLocalImport = false;
|
|
1415
|
+
let hasTailwindDirective = false;
|
|
1416
|
+
try {
|
|
1417
|
+
const root = postcss.default.parse(css);
|
|
1418
|
+
for (const node of root.nodes) {
|
|
1419
|
+
if (node.type === "comment") continue;
|
|
1420
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
1421
|
+
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1422
|
+
if (!request || !isLocalImportRequest(request)) return;
|
|
1423
|
+
hasLocalImport = true;
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (node.type === "atrule" && node.name === "source") {
|
|
1427
|
+
hasTailwindDirective = true;
|
|
1428
|
+
continue;
|
|
1429
|
+
}
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
} catch {
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v3_engine.removeTailwindSourceDirectives(css)) : void 0;
|
|
1187
1436
|
}
|
|
1188
|
-
function
|
|
1189
|
-
const selectors = [...collectSelectorsFromCss(layerCss)];
|
|
1190
|
-
if (selectors.length === 0) return css;
|
|
1437
|
+
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
1191
1438
|
try {
|
|
1192
1439
|
const root = postcss.default.parse(css);
|
|
1193
|
-
root.
|
|
1194
|
-
|
|
1440
|
+
root.walkAtRules("import", (atRule) => {
|
|
1441
|
+
const request = require_v3_engine.parseImportRequest(atRule.params);
|
|
1442
|
+
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
1195
1443
|
});
|
|
1196
1444
|
return root.toString();
|
|
1197
1445
|
} catch {
|
|
1198
|
-
return
|
|
1446
|
+
return css;
|
|
1199
1447
|
}
|
|
1200
1448
|
}
|
|
1201
|
-
function
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1449
|
+
function splitLocalCssImports(source) {
|
|
1450
|
+
try {
|
|
1451
|
+
const root = postcss.default.parse(source);
|
|
1452
|
+
const importRoot = postcss.default.root();
|
|
1453
|
+
let changed = false;
|
|
1454
|
+
for (const node of [...root.nodes]) {
|
|
1455
|
+
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
1456
|
+
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1457
|
+
if (!request || !isLocalImportRequest(request)) continue;
|
|
1458
|
+
importRoot.append(node.clone());
|
|
1459
|
+
node.remove();
|
|
1460
|
+
changed = true;
|
|
1213
1461
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
1222
|
-
if (layerCss) layers.push(layerCss);
|
|
1223
|
-
cursor = endIndex + 45;
|
|
1224
|
-
}
|
|
1225
|
-
return {
|
|
1226
|
-
layers,
|
|
1227
|
-
rest
|
|
1228
|
-
};
|
|
1229
|
-
}
|
|
1230
|
-
function findUtilityLayerInsertionIndex(css) {
|
|
1231
|
-
let index = -1;
|
|
1232
|
-
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
1233
|
-
const match = pattern.exec(css);
|
|
1234
|
-
if (!match) continue;
|
|
1235
|
-
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
1236
|
-
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
1462
|
+
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
1463
|
+
return changed ? {
|
|
1464
|
+
imports,
|
|
1465
|
+
source: root.toString()
|
|
1466
|
+
} : void 0;
|
|
1467
|
+
} catch {
|
|
1468
|
+
return;
|
|
1237
1469
|
}
|
|
1238
|
-
return index;
|
|
1239
|
-
}
|
|
1240
|
-
function reorderMarkedUserLayerComponentsCss(css) {
|
|
1241
|
-
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
1242
|
-
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
1243
|
-
if (layers.length === 0) return rest;
|
|
1244
|
-
const layerCss = layers.join("\n");
|
|
1245
|
-
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
1246
|
-
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
1247
|
-
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
1248
1470
|
}
|
|
1249
|
-
function
|
|
1250
|
-
if (!
|
|
1251
|
-
|
|
1252
|
-
merged: false
|
|
1253
|
-
};
|
|
1254
|
-
const { layers } = extractMarkedUserLayerComponentsCss(markedCss);
|
|
1255
|
-
if (layers.length === 0) return {
|
|
1256
|
-
css: baseCss,
|
|
1257
|
-
merged: false
|
|
1258
|
-
};
|
|
1259
|
-
const layerCss = layers.join("\n");
|
|
1260
|
-
return {
|
|
1261
|
-
css: reorderMarkedUserLayerComponentsCss(appendCss(removeCssRulesForSelectors(baseCss, layerCss), wrapUserLayerComponentsCss(layerCss))),
|
|
1262
|
-
merged: true
|
|
1263
|
-
};
|
|
1471
|
+
function restoreLocalCssImports(css, imports) {
|
|
1472
|
+
if (!imports?.trim()) return css;
|
|
1473
|
+
return createCssSourceOrderAppend(imports, css);
|
|
1264
1474
|
}
|
|
1265
1475
|
//#endregion
|
|
1266
|
-
//#region src/bundlers/shared/generator-css.ts
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}
|
|
1277
|
-
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
1278
|
-
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
1279
|
-
if (!options.isolateCurrentCssCandidates) return true;
|
|
1280
|
-
return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
1281
|
-
}
|
|
1282
|
-
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1283
|
-
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
1284
|
-
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
1285
|
-
return new Set([...scopedRuntime, ...runtime]);
|
|
1286
|
-
}
|
|
1287
|
-
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
1288
|
-
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
1289
|
-
}
|
|
1290
|
-
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
1291
|
-
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(options.rawSource) && !require_v3_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
1292
|
-
}
|
|
1476
|
+
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
1477
|
+
const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
|
|
1478
|
+
"config",
|
|
1479
|
+
"custom-variant",
|
|
1480
|
+
"plugin",
|
|
1481
|
+
"source",
|
|
1482
|
+
"theme",
|
|
1483
|
+
"utility",
|
|
1484
|
+
"variant"
|
|
1485
|
+
]);
|
|
1293
1486
|
function removeTailwindApplyAtRules(source) {
|
|
1294
1487
|
if (!source.includes("@apply")) return source;
|
|
1295
1488
|
try {
|
|
@@ -1307,33 +1500,25 @@ function removeTailwindApplyAtRules(source) {
|
|
|
1307
1500
|
return source;
|
|
1308
1501
|
}
|
|
1309
1502
|
}
|
|
1310
|
-
function
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
1330
|
-
...cssHandlerOptions,
|
|
1331
|
-
...preflightStyleOptions,
|
|
1332
|
-
...generatorStyleOptions
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
function isLocalImportRequest(request) {
|
|
1336
|
-
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1503
|
+
function removeTailwindV4GeneratorAtRules(source) {
|
|
1504
|
+
try {
|
|
1505
|
+
const root = postcss.default.parse(source);
|
|
1506
|
+
let changed = false;
|
|
1507
|
+
root.walkAtRules((rule) => {
|
|
1508
|
+
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
1509
|
+
rule.remove();
|
|
1510
|
+
changed = true;
|
|
1511
|
+
});
|
|
1512
|
+
root.walk((node) => {
|
|
1513
|
+
if ("nodes" in node && node.nodes?.length === 0) {
|
|
1514
|
+
node.remove();
|
|
1515
|
+
changed = true;
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
return changed ? root.toString() : source;
|
|
1519
|
+
} catch {
|
|
1520
|
+
return source;
|
|
1521
|
+
}
|
|
1337
1522
|
}
|
|
1338
1523
|
function isCommentOnlyCss(source) {
|
|
1339
1524
|
try {
|
|
@@ -1344,7 +1529,19 @@ function isCommentOnlyCss(source) {
|
|
|
1344
1529
|
}
|
|
1345
1530
|
}
|
|
1346
1531
|
function stripTailwindSourceMediaFragments(source) {
|
|
1347
|
-
|
|
1532
|
+
let removedSourceMediaStart = false;
|
|
1533
|
+
return source.split(/\r?\n/).filter((line) => {
|
|
1534
|
+
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
1535
|
+
removedSourceMediaStart = true;
|
|
1536
|
+
return false;
|
|
1537
|
+
}
|
|
1538
|
+
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
1539
|
+
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
1540
|
+
removedSourceMediaStart = false;
|
|
1541
|
+
return false;
|
|
1542
|
+
}
|
|
1543
|
+
return true;
|
|
1544
|
+
}).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
|
|
1348
1545
|
}
|
|
1349
1546
|
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1350
1547
|
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
@@ -1357,22 +1554,6 @@ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
|
1357
1554
|
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
1358
1555
|
}
|
|
1359
1556
|
}
|
|
1360
|
-
function createCssSourceOrderAppend(base, extra) {
|
|
1361
|
-
if (!base) return extra;
|
|
1362
|
-
if (!extra) return base;
|
|
1363
|
-
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1364
|
-
return `${base}\n${extra}`;
|
|
1365
|
-
}
|
|
1366
|
-
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
1367
|
-
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
1368
|
-
}
|
|
1369
|
-
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
1370
|
-
const placeholderParts = require_v3_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1371
|
-
if (placeholderParts) return placeholderParts;
|
|
1372
|
-
const exactParts = require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1373
|
-
if (exactParts) return exactParts;
|
|
1374
|
-
return require_v3_engine.splitTailwindGeneratedCssByBanner(rawSource);
|
|
1375
|
-
}
|
|
1376
1557
|
function splitUserCssLayerBlocks(source) {
|
|
1377
1558
|
if (!source.includes("@layer")) return {
|
|
1378
1559
|
layer: "",
|
|
@@ -1512,7 +1693,7 @@ function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options
|
|
|
1512
1693
|
}
|
|
1513
1694
|
async function transformGeneratorUserCss(source, options) {
|
|
1514
1695
|
if (source.trim().length === 0) return "";
|
|
1515
|
-
const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
1696
|
+
const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1516
1697
|
if (cleanedSource.trim().length === 0) return "";
|
|
1517
1698
|
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1518
1699
|
if (userSource.trim().length === 0) return "";
|
|
@@ -1524,84 +1705,157 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
1524
1705
|
});
|
|
1525
1706
|
return (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css);
|
|
1526
1707
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
return
|
|
1708
|
+
//#endregion
|
|
1709
|
+
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
1710
|
+
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
1711
|
+
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
1712
|
+
const UTILITY_LAYER_INSERTION_RES = [
|
|
1713
|
+
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
1714
|
+
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
1715
|
+
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
1716
|
+
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
1717
|
+
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
1718
|
+
];
|
|
1719
|
+
function appendCss(base, extra) {
|
|
1720
|
+
if (!base) return extra;
|
|
1721
|
+
if (!extra) return base;
|
|
1722
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1723
|
+
return `${base}\n${extra}`;
|
|
1542
1724
|
}
|
|
1543
|
-
function
|
|
1544
|
-
|
|
1545
|
-
|
|
1725
|
+
function removeFirstCssOccurrence(css, chunk) {
|
|
1726
|
+
const trimmed = chunk.trim();
|
|
1727
|
+
if (!trimmed) return css;
|
|
1728
|
+
const index = css.indexOf(trimmed);
|
|
1729
|
+
if (index === -1) return css;
|
|
1730
|
+
return appendCss(css.slice(0, index).trimEnd(), css.slice(index + trimmed.length).trimStart());
|
|
1731
|
+
}
|
|
1732
|
+
function collectSelectorsFromCss(css) {
|
|
1733
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1546
1734
|
try {
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1552
|
-
if (!request || !isLocalImportRequest(request)) return;
|
|
1553
|
-
hasLocalImport = true;
|
|
1554
|
-
continue;
|
|
1555
|
-
}
|
|
1556
|
-
if (node.type === "atrule" && node.name === "source") {
|
|
1557
|
-
hasTailwindDirective = true;
|
|
1558
|
-
continue;
|
|
1735
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
1736
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1737
|
+
const normalized = selector.trim();
|
|
1738
|
+
if (normalized) selectors.add(normalized);
|
|
1559
1739
|
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
return;
|
|
1564
|
-
}
|
|
1565
|
-
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v3_engine.removeTailwindSourceDirectives(css)) : void 0;
|
|
1740
|
+
});
|
|
1741
|
+
} catch {}
|
|
1742
|
+
return selectors;
|
|
1566
1743
|
}
|
|
1567
|
-
function
|
|
1744
|
+
function matchesLayerSelector(selector, layerSelector) {
|
|
1745
|
+
if (selector === layerSelector) return true;
|
|
1746
|
+
if (!selector.startsWith(layerSelector)) return false;
|
|
1747
|
+
const next = selector[layerSelector.length];
|
|
1748
|
+
return next === ":" || next === "[";
|
|
1749
|
+
}
|
|
1750
|
+
function removeCssRulesForSelectors(css, layerCss) {
|
|
1751
|
+
const selectors = [...collectSelectorsFromCss(layerCss)];
|
|
1752
|
+
if (selectors.length === 0) return css;
|
|
1568
1753
|
try {
|
|
1569
1754
|
const root = postcss.default.parse(css);
|
|
1570
|
-
root.
|
|
1571
|
-
|
|
1572
|
-
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
1755
|
+
root.walkRules((rule) => {
|
|
1756
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectors.some((layerSelector) => matchesLayerSelector(selector.trim(), layerSelector)))) rule.remove();
|
|
1573
1757
|
});
|
|
1574
1758
|
return root.toString();
|
|
1575
1759
|
} catch {
|
|
1576
|
-
return css;
|
|
1760
|
+
return removeFirstCssOccurrence(css, layerCss);
|
|
1577
1761
|
}
|
|
1578
1762
|
}
|
|
1579
|
-
function
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1763
|
+
function wrapUserLayerComponentsCss(css) {
|
|
1764
|
+
return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
|
|
1765
|
+
}
|
|
1766
|
+
function extractMarkedUserLayerComponentsCss(css) {
|
|
1767
|
+
const layers = [];
|
|
1768
|
+
let rest = "";
|
|
1769
|
+
let cursor = 0;
|
|
1770
|
+
while (cursor < css.length) {
|
|
1771
|
+
const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
|
|
1772
|
+
if (startIndex === -1) {
|
|
1773
|
+
rest += css.slice(cursor);
|
|
1774
|
+
break;
|
|
1591
1775
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1776
|
+
rest += css.slice(cursor, startIndex);
|
|
1777
|
+
const contentStart = startIndex + 47;
|
|
1778
|
+
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
1779
|
+
if (endIndex === -1) {
|
|
1780
|
+
rest += css.slice(startIndex);
|
|
1781
|
+
break;
|
|
1782
|
+
}
|
|
1783
|
+
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
1784
|
+
if (layerCss) layers.push(layerCss);
|
|
1785
|
+
cursor = endIndex + 45;
|
|
1599
1786
|
}
|
|
1787
|
+
return {
|
|
1788
|
+
layers,
|
|
1789
|
+
rest
|
|
1790
|
+
};
|
|
1600
1791
|
}
|
|
1601
|
-
function
|
|
1602
|
-
|
|
1603
|
-
|
|
1792
|
+
function findUtilityLayerInsertionIndex(css) {
|
|
1793
|
+
let index = -1;
|
|
1794
|
+
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
1795
|
+
const match = pattern.exec(css);
|
|
1796
|
+
if (!match) continue;
|
|
1797
|
+
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
1798
|
+
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
1799
|
+
}
|
|
1800
|
+
return index;
|
|
1801
|
+
}
|
|
1802
|
+
function reorderMarkedUserLayerComponentsCss(css) {
|
|
1803
|
+
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
1804
|
+
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
1805
|
+
if (layers.length === 0) return rest;
|
|
1806
|
+
const layerCss = layers.join("\n");
|
|
1807
|
+
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
1808
|
+
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
1809
|
+
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
1810
|
+
}
|
|
1811
|
+
function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
|
|
1812
|
+
if (!markedCss.includes(USER_LAYER_COMPONENTS_START)) return {
|
|
1813
|
+
css: baseCss,
|
|
1814
|
+
merged: false
|
|
1815
|
+
};
|
|
1816
|
+
const { layers } = extractMarkedUserLayerComponentsCss(markedCss);
|
|
1817
|
+
if (layers.length === 0) return {
|
|
1818
|
+
css: baseCss,
|
|
1819
|
+
merged: false
|
|
1820
|
+
};
|
|
1821
|
+
const layerCss = layers.join("\n");
|
|
1822
|
+
return {
|
|
1823
|
+
css: reorderMarkedUserLayerComponentsCss(appendCss(removeCssRulesForSelectors(baseCss, layerCss), wrapUserLayerComponentsCss(layerCss))),
|
|
1824
|
+
merged: true
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
//#endregion
|
|
1828
|
+
//#region src/bundlers/shared/generator-css/validate.ts
|
|
1829
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1830
|
+
async function validateCandidatesByGenerator(options) {
|
|
1831
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1832
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1833
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1834
|
+
const generatorOptions = {
|
|
1835
|
+
...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
|
|
1836
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
|
|
1837
|
+
};
|
|
1838
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1839
|
+
cssEntries: opts.cssEntries,
|
|
1840
|
+
runtime: candidates
|
|
1841
|
+
});
|
|
1842
|
+
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1843
|
+
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1844
|
+
if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
|
|
1845
|
+
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1846
|
+
}
|
|
1847
|
+
return (await generator.generate({
|
|
1848
|
+
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1849
|
+
candidates,
|
|
1850
|
+
target: "tailwind"
|
|
1851
|
+
})).classSet;
|
|
1852
|
+
}));
|
|
1853
|
+
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
1854
|
+
debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
|
|
1855
|
+
return classSet;
|
|
1604
1856
|
}
|
|
1857
|
+
//#endregion
|
|
1858
|
+
//#region src/bundlers/shared/generator-css.ts
|
|
1605
1859
|
async function generateCssByGenerator(options) {
|
|
1606
1860
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1607
1861
|
const generatorOptions = {
|
|
@@ -1612,6 +1866,7 @@ async function generateCssByGenerator(options) {
|
|
|
1612
1866
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1613
1867
|
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
1614
1868
|
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
1869
|
+
const userCssRawSource = majorVersion === 4 ? removeTailwindV4GeneratorAtRules(generatorRawSource) : generatorRawSource;
|
|
1615
1870
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1616
1871
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1617
1872
|
css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
@@ -1623,8 +1878,13 @@ async function generateCssByGenerator(options) {
|
|
|
1623
1878
|
const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(generatorRawSource);
|
|
1624
1879
|
const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
1625
1880
|
const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1626
|
-
const shouldGenerateCurrentCss =
|
|
1627
|
-
|
|
1881
|
+
const shouldGenerateCurrentCss = shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
|
|
1882
|
+
hasGeneratedCss,
|
|
1883
|
+
hasGeneratedMarkers,
|
|
1884
|
+
hasSourceDirectives,
|
|
1885
|
+
rawSource: generatorRawSource
|
|
1886
|
+
});
|
|
1887
|
+
if (!isSupportedGeneratorMajorVersion(majorVersion) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1628
1888
|
try {
|
|
1629
1889
|
await runtimeState.readyPromise;
|
|
1630
1890
|
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
@@ -1633,7 +1893,7 @@ async function generateCssByGenerator(options) {
|
|
|
1633
1893
|
hasGeneratedMarkers,
|
|
1634
1894
|
rawSource: generatorRawSource
|
|
1635
1895
|
});
|
|
1636
|
-
const runtimeWithCurrentCss =
|
|
1896
|
+
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
1637
1897
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1638
1898
|
cssEntries: opts.cssEntries,
|
|
1639
1899
|
getSourceCandidatesForEntries,
|
|
@@ -1641,12 +1901,13 @@ async function generateCssByGenerator(options) {
|
|
|
1641
1901
|
});
|
|
1642
1902
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1643
1903
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1644
|
-
const
|
|
1904
|
+
const generated = mergeGeneratorResults((await Promise.all(sources.map(async (source) => {
|
|
1645
1905
|
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1646
1906
|
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
1647
1907
|
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
1648
1908
|
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
|
|
1649
|
-
const
|
|
1909
|
+
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
1910
|
+
const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
|
|
1650
1911
|
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
1651
1912
|
debug("defer empty scoped css source generation: %s", file);
|
|
1652
1913
|
return;
|
|
@@ -1668,21 +1929,8 @@ async function generateCssByGenerator(options) {
|
|
|
1668
1929
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1669
1930
|
target: generatorOptions.target
|
|
1670
1931
|
});
|
|
1671
|
-
}))).filter((item) => Boolean(item));
|
|
1672
|
-
|
|
1673
|
-
if (!firstGenerated) return;
|
|
1674
|
-
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
1675
|
-
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
1676
|
-
const generated = generatedResults.length === 1 ? firstGenerated : {
|
|
1677
|
-
...firstGenerated,
|
|
1678
|
-
css: generatedResults.map((item) => item.css).join("\n"),
|
|
1679
|
-
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
1680
|
-
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
1681
|
-
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
1682
|
-
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
1683
|
-
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
1684
|
-
sources: generatedResults.flatMap((item) => item.sources)
|
|
1685
|
-
};
|
|
1932
|
+
}))).filter((item) => Boolean(item)));
|
|
1933
|
+
if (!generated) return;
|
|
1686
1934
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1687
1935
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1688
1936
|
const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
|
|
@@ -1700,7 +1948,7 @@ async function generateCssByGenerator(options) {
|
|
|
1700
1948
|
});
|
|
1701
1949
|
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(require_v3_engine.stripTailwindBanner(generated.css), generatorRawSource) : require_v3_engine.stripTailwindBanner(generated.css);
|
|
1702
1950
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1703
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(
|
|
1951
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssRawSource, generated.rawCss);
|
|
1704
1952
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1705
1953
|
if (orderedExtraCss) {
|
|
1706
1954
|
let css = generatedCss;
|
|
@@ -1719,19 +1967,19 @@ async function generateCssByGenerator(options) {
|
|
|
1719
1967
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
1720
1968
|
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
1721
1969
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
1722
|
-
css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
1970
|
+
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
1723
1971
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
1724
1972
|
hasSourceDirectives,
|
|
1725
1973
|
hasMatchedCssSourceFile
|
|
1726
1974
|
})) {
|
|
1727
|
-
const userCss = await transformGeneratorUserCss(
|
|
1728
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
1975
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
1976
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
1729
1977
|
}
|
|
1730
1978
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
1731
1979
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1732
1980
|
if (!shouldFilterApplyOnlyCss) {
|
|
1733
|
-
css = await appendLegacyCompatCss(css,
|
|
1734
|
-
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css,
|
|
1981
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1982
|
+
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1735
1983
|
}
|
|
1736
1984
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1737
1985
|
return {
|
|
@@ -1763,37 +2011,37 @@ async function generateCssByGenerator(options) {
|
|
|
1763
2011
|
rest: css
|
|
1764
2012
|
} : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
|
|
1765
2013
|
if (layerCss.layer.trim().length > 0) {
|
|
1766
|
-
css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
2014
|
+
css = createCssSourceOrderAppend$1(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
1767
2015
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1768
2016
|
}
|
|
1769
2017
|
}
|
|
1770
2018
|
}
|
|
1771
2019
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1772
2020
|
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
1773
|
-
const userCss = await transformGeneratorUserCss(
|
|
2021
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
1774
2022
|
generatorTarget: generated.target,
|
|
1775
2023
|
generatorStyleOptions,
|
|
1776
2024
|
cssUserHandlerOptions,
|
|
1777
2025
|
styleHandler,
|
|
1778
2026
|
importFallback: generatorOptions.importFallback
|
|
1779
2027
|
});
|
|
1780
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
2028
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
1781
2029
|
}
|
|
1782
2030
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
1783
|
-
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css,
|
|
2031
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1784
2032
|
}
|
|
1785
2033
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1786
2034
|
hasSourceDirectives,
|
|
1787
2035
|
hasMatchedCssSourceFile
|
|
1788
2036
|
})) {
|
|
1789
|
-
const userCss = await transformGeneratorUserCss(
|
|
2037
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
1790
2038
|
generatorTarget: generated.target,
|
|
1791
2039
|
generatorStyleOptions,
|
|
1792
2040
|
cssUserHandlerOptions,
|
|
1793
2041
|
styleHandler,
|
|
1794
2042
|
importFallback: generatorOptions.importFallback
|
|
1795
2043
|
});
|
|
1796
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
2044
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
1797
2045
|
}
|
|
1798
2046
|
return {
|
|
1799
2047
|
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
@@ -1807,8 +2055,8 @@ async function generateCssByGenerator(options) {
|
|
|
1807
2055
|
};
|
|
1808
2056
|
}
|
|
1809
2057
|
if (!shouldFilterApplyOnlyCss) {
|
|
1810
|
-
css = await appendLegacyCompatCss(css,
|
|
1811
|
-
css = await appendLegacyContainerCompatCss(css,
|
|
2058
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
2059
|
+
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1812
2060
|
}
|
|
1813
2061
|
return {
|
|
1814
2062
|
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
@@ -1822,117 +2070,11 @@ async function generateCssByGenerator(options) {
|
|
|
1822
2070
|
};
|
|
1823
2071
|
} catch (error) {
|
|
1824
2072
|
debug("tailwind direct css generation failed: %s %O", file, error);
|
|
1825
|
-
throw error;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
async function validateCandidatesByGenerator(options) {
|
|
1829
|
-
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1830
|
-
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1831
|
-
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1832
|
-
const generatorOptions = {
|
|
1833
|
-
...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
|
|
1834
|
-
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
|
|
1835
|
-
};
|
|
1836
|
-
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1837
|
-
cssEntries: opts.cssEntries,
|
|
1838
|
-
runtime: candidates
|
|
1839
|
-
});
|
|
1840
|
-
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1841
|
-
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1842
|
-
if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
|
|
1843
|
-
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1844
|
-
}
|
|
1845
|
-
return (await generator.generate({
|
|
1846
|
-
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1847
|
-
candidates,
|
|
1848
|
-
target: "tailwind"
|
|
1849
|
-
})).classSet;
|
|
1850
|
-
}));
|
|
1851
|
-
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
1852
|
-
debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
|
|
1853
|
-
return classSet;
|
|
1854
|
-
}
|
|
1855
|
-
//#endregion
|
|
1856
|
-
//#region src/bundlers/shared/hmr-timing.ts
|
|
1857
|
-
function shouldEmitHmrTiming() {
|
|
1858
|
-
return node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
1859
|
-
}
|
|
1860
|
-
function shouldEmitHumanReadableTiming() {
|
|
1861
|
-
return node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1" && node_process.default.env["WEAPP_TW_HMR_TIMING_LOG"] !== "0";
|
|
1862
|
-
}
|
|
1863
|
-
function emitHmrTiming(bundler, phase, durationMs, details = {}) {
|
|
1864
|
-
if (!shouldEmitHmrTiming()) return;
|
|
1865
|
-
const serializableDetails = { ...details };
|
|
1866
|
-
delete serializableDetails.emit;
|
|
1867
|
-
const payload = {
|
|
1868
|
-
bundler,
|
|
1869
|
-
phase,
|
|
1870
|
-
durationMs: Math.max(0, Math.round(durationMs)),
|
|
1871
|
-
...serializableDetails,
|
|
1872
|
-
...typeof details.wallMs === "number" ? { wallMs: Math.max(0, Math.round(details.wallMs)) } : {}
|
|
1873
|
-
};
|
|
1874
|
-
node_process.default.stdout.write(`[weapp-tailwindcss:hmr] ${JSON.stringify(payload)}\n`);
|
|
1875
|
-
if (shouldEmitHumanReadableTiming()) {
|
|
1876
|
-
const fileSuffix = details.file ? ` file=${details.file}` : "";
|
|
1877
|
-
if (details.metric === "total") {
|
|
1878
|
-
const hooks = details.hooks ? Object.entries(details.hooks).map(([hook, summary]) => `${hook}=${Math.max(0, Math.round(summary.durationMs))}ms/${summary.count}`).join(", ") : "";
|
|
1879
|
-
const hookSuffix = hooks ? ` (${hooks})` : "";
|
|
1880
|
-
const wallSuffix = typeof payload.wallMs === "number" ? ` wall=${payload.wallMs}ms` : "";
|
|
1881
|
-
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:weapp-tailwindcss 总耗时 ${payload.durationMs}ms${wallSuffix}${hookSuffix}\n`);
|
|
1882
|
-
return;
|
|
1883
|
-
}
|
|
1884
|
-
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:${phase} 耗时 ${payload.durationMs}ms${fileSuffix}\n`);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
function createHmrTimingRecorder(bundler) {
|
|
1888
|
-
const session = {
|
|
1889
|
-
hooks: {},
|
|
1890
|
-
totalMs: 0
|
|
1891
|
-
};
|
|
1892
|
-
const record = (phase, durationMs, details = {}) => {
|
|
1893
|
-
const roundedDuration = Math.max(0, Math.round(durationMs));
|
|
1894
|
-
if (session.startedAt === void 0) session.startedAt = performance.now() - Math.max(0, durationMs);
|
|
1895
|
-
session.totalMs += Math.max(0, durationMs);
|
|
1896
|
-
const current = session.hooks[phase] ?? {
|
|
1897
|
-
count: 0,
|
|
1898
|
-
durationMs: 0,
|
|
1899
|
-
maxMs: 0
|
|
1900
|
-
};
|
|
1901
|
-
current.count += 1;
|
|
1902
|
-
current.durationMs += roundedDuration;
|
|
1903
|
-
current.maxMs = Math.max(current.maxMs, roundedDuration);
|
|
1904
|
-
session.hooks[phase] = current;
|
|
1905
|
-
if (details.emit !== false) emitHmrTiming(bundler, phase, durationMs, details);
|
|
1906
|
-
};
|
|
1907
|
-
const measure = async (phase, task, details = {}) => {
|
|
1908
|
-
const startedAt = performance.now();
|
|
1909
|
-
try {
|
|
1910
|
-
return await task();
|
|
1911
|
-
} finally {
|
|
1912
|
-
record(phase, performance.now() - startedAt, details);
|
|
1913
|
-
}
|
|
1914
|
-
};
|
|
1915
|
-
const emitTotal = (phase = "total") => {
|
|
1916
|
-
if (session.totalMs <= 0) return;
|
|
1917
|
-
const wallMs = session.startedAt === void 0 ? session.totalMs : performance.now() - session.startedAt;
|
|
1918
|
-
emitHmrTiming(bundler, phase, session.totalMs, {
|
|
1919
|
-
hooks: session.hooks,
|
|
1920
|
-
metric: "total",
|
|
1921
|
-
wallMs
|
|
1922
|
-
});
|
|
1923
|
-
session.hooks = {};
|
|
1924
|
-
delete session.startedAt;
|
|
1925
|
-
session.totalMs = 0;
|
|
1926
|
-
};
|
|
1927
|
-
return {
|
|
1928
|
-
emitTotal,
|
|
1929
|
-
measure,
|
|
1930
|
-
record
|
|
1931
|
-
};
|
|
2073
|
+
throw error;
|
|
2074
|
+
}
|
|
1932
2075
|
}
|
|
1933
2076
|
//#endregion
|
|
1934
|
-
//#region src/bundlers/vite/incremental-runtime-class-set.ts
|
|
1935
|
-
const debug = require_v3_engine.createDebug("[vite:runtime-set] ");
|
|
2077
|
+
//#region src/bundlers/vite/incremental-runtime-class-set/entries.ts
|
|
1936
2078
|
const EXTENSION_DOT_PREFIX_RE = /^\./;
|
|
1937
2079
|
const VENDOR_CHUNK_BASENAME_RE = /^(?:vendor|vendors|chunk-vendors|common_vendor)(?:[.-]|$)/i;
|
|
1938
2080
|
const COMMON_VENDOR_CHUNK_RE = /^(?:common|static|assets|chunks?)\/(?:vendor|vendors|chunk-vendors|common_vendor|runtime)(?:[.-]|$)/i;
|
|
@@ -1967,17 +2109,6 @@ function isRuntimeCandidateEntry(entry) {
|
|
|
1967
2109
|
if (entry.output.facadeModuleId && !isDependencyModuleId(entry.output.facadeModuleId)) return true;
|
|
1968
2110
|
return collectChunkModuleIds(entry).some((id) => !isDependencyModuleId(id));
|
|
1969
2111
|
}
|
|
1970
|
-
function createExtractOptions(context, source, bareArbitraryValues) {
|
|
1971
|
-
return {
|
|
1972
|
-
cwd: context.projectRoot,
|
|
1973
|
-
base: context.base,
|
|
1974
|
-
baseFallbacks: context.baseFallbacks,
|
|
1975
|
-
css: context.css,
|
|
1976
|
-
content: source,
|
|
1977
|
-
extension: "html",
|
|
1978
|
-
bareArbitraryValues
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
2112
|
function createRuntimeEntries(snapshot) {
|
|
1982
2113
|
return snapshot.entries.filter(isRuntimeCandidateEntry);
|
|
1983
2114
|
}
|
|
@@ -1990,37 +2121,54 @@ function resolveEntryExtension(entry) {
|
|
|
1990
2121
|
if (ext.length > 0) return ext;
|
|
1991
2122
|
return "js";
|
|
1992
2123
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2124
|
+
//#endregion
|
|
2125
|
+
//#region src/bundlers/vite/incremental-runtime-class-set/escaped-candidates.ts
|
|
2126
|
+
const ESCAPED_CLASS_TOKEN_RE = /[\w-]+_[A-Z][\w-]*/gi;
|
|
2127
|
+
const TAILWIND_RESTORED_CANDIDATE_SIGNAL_RE = /[[\]:/#!.]/;
|
|
2128
|
+
const MAX_RESTORED_CANDIDATE_VARIANTS = 512;
|
|
2129
|
+
function createEscapeFragments(escapeMap) {
|
|
2130
|
+
return [...new Set(Object.values(escapeMap).filter(Boolean))].sort((a, b) => b.length - a.length);
|
|
2131
|
+
}
|
|
2132
|
+
function hasEscapeFragment(token, escapeFragments) {
|
|
2133
|
+
return escapeFragments.some((fragment) => token.includes(fragment));
|
|
2134
|
+
}
|
|
2135
|
+
function createAmbiguousRestoredRuntimeCandidates(token, escapeMap, escapeFragments) {
|
|
2136
|
+
if (!hasEscapeFragment(token, escapeFragments)) return [];
|
|
2137
|
+
const unescapedByFragment = new Map(Object.entries(escapeMap).map(([char, fragment]) => [fragment, char]));
|
|
2138
|
+
let variants = [""];
|
|
2139
|
+
let index = 0;
|
|
2140
|
+
while (index < token.length) {
|
|
2141
|
+
const fragment = escapeFragments.find((item) => token.startsWith(item, index));
|
|
2142
|
+
if (!fragment) {
|
|
2143
|
+
variants = variants.map((item) => item + token[index]);
|
|
2144
|
+
index += 1;
|
|
2002
2145
|
continue;
|
|
2003
2146
|
}
|
|
2004
|
-
|
|
2147
|
+
const nextVariants = [];
|
|
2148
|
+
const unescaped = unescapedByFragment.get(fragment);
|
|
2149
|
+
for (const variant of variants) {
|
|
2150
|
+
nextVariants.push(variant + fragment);
|
|
2151
|
+
if (unescaped) nextVariants.push(variant + unescaped);
|
|
2152
|
+
if (nextVariants.length >= MAX_RESTORED_CANDIDATE_VARIANTS) break;
|
|
2153
|
+
}
|
|
2154
|
+
variants = nextVariants;
|
|
2155
|
+
index += fragment.length;
|
|
2005
2156
|
}
|
|
2157
|
+
variants.push((0, _weapp_core_escape.unescape)(token, { map: escapeMap }));
|
|
2158
|
+
return [...new Set(variants)].filter((restored) => restored !== token && TAILWIND_RESTORED_CANDIDATE_SIGNAL_RE.test(restored) && !/\s/.test(restored));
|
|
2006
2159
|
}
|
|
2007
|
-
function
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2160
|
+
function collectEscapedRuntimeCandidates(source, escapeMap, escapeFragments) {
|
|
2161
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2162
|
+
ESCAPED_CLASS_TOKEN_RE.lastIndex = 0;
|
|
2163
|
+
let match = ESCAPED_CLASS_TOKEN_RE.exec(source);
|
|
2164
|
+
while (match) {
|
|
2165
|
+
for (const restored of createAmbiguousRestoredRuntimeCandidates(match[0], escapeMap, escapeFragments)) candidates.add(restored);
|
|
2166
|
+
match = ESCAPED_CLASS_TOKEN_RE.exec(source);
|
|
2011
2167
|
}
|
|
2168
|
+
return candidates;
|
|
2012
2169
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
}
|
|
2016
|
-
function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
|
|
2017
|
-
const nextBaseClassSet = new Set(baseClassSet);
|
|
2018
|
-
for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
|
|
2019
|
-
return nextBaseClassSet;
|
|
2020
|
-
}
|
|
2021
|
-
function isUrlLikeCandidate(candidate) {
|
|
2022
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2023
|
-
}
|
|
2170
|
+
//#endregion
|
|
2171
|
+
//#region src/bundlers/vite/incremental-runtime-class-set/v3-candidates.ts
|
|
2024
2172
|
const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
|
|
2025
2173
|
"accent",
|
|
2026
2174
|
"animate",
|
|
@@ -2099,6 +2247,9 @@ const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
|
|
|
2099
2247
|
"w",
|
|
2100
2248
|
"z"
|
|
2101
2249
|
]);
|
|
2250
|
+
function isUrlLikeCandidate(candidate) {
|
|
2251
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2252
|
+
}
|
|
2102
2253
|
function getBaseUtilityCandidate(candidate) {
|
|
2103
2254
|
let bracketDepth = 0;
|
|
2104
2255
|
let lastVariantSeparator = -1;
|
|
@@ -2193,10 +2344,54 @@ function isRawCandidateInRanges(start, ranges) {
|
|
|
2193
2344
|
function isRawCandidateAllowedForV3(source, candidate, start, extension, knownSourceCandidates, highConfidenceLiteralRanges = []) {
|
|
2194
2345
|
return isHighConfidenceV3Candidate(candidate) || knownSourceCandidates?.has(candidate) === true || isRawCandidateInClassContext(source, start, extension) || isRawCandidateInRanges(start, highConfidenceLiteralRanges);
|
|
2195
2346
|
}
|
|
2347
|
+
//#endregion
|
|
2348
|
+
//#region src/bundlers/vite/incremental-runtime-class-set.ts
|
|
2349
|
+
const debug = require_v3_engine.createDebug("[vite:runtime-set] ");
|
|
2350
|
+
function createExtractOptions(context, source, bareArbitraryValues) {
|
|
2351
|
+
return {
|
|
2352
|
+
cwd: context.projectRoot,
|
|
2353
|
+
base: context.base,
|
|
2354
|
+
baseFallbacks: context.baseFallbacks,
|
|
2355
|
+
css: context.css,
|
|
2356
|
+
content: source,
|
|
2357
|
+
extension: "html",
|
|
2358
|
+
...bareArbitraryValues === void 0 ? {} : { bareArbitraryValues }
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
function createCandidateValidationSource(candidates) {
|
|
2362
|
+
return [...new Set(candidates)].sort().join("\n");
|
|
2363
|
+
}
|
|
2364
|
+
function removeCandidateSet$1(candidateCountByClass, candidates) {
|
|
2365
|
+
for (const className of candidates) {
|
|
2366
|
+
const count = candidateCountByClass.get(className);
|
|
2367
|
+
if (count == null) continue;
|
|
2368
|
+
if (count <= 1) {
|
|
2369
|
+
candidateCountByClass.delete(className);
|
|
2370
|
+
continue;
|
|
2371
|
+
}
|
|
2372
|
+
candidateCountByClass.set(className, count - 1);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
function addCandidateSet$1(candidateCountByClass, candidates) {
|
|
2376
|
+
for (const className of candidates) {
|
|
2377
|
+
const nextCount = (candidateCountByClass.get(className) ?? 0) + 1;
|
|
2378
|
+
candidateCountByClass.set(className, nextCount);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
function createRuntimeClassSet(baseClassSet, candidateCountByClass) {
|
|
2382
|
+
return new Set([...baseClassSet, ...candidateCountByClass.keys()]);
|
|
2383
|
+
}
|
|
2384
|
+
function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
|
|
2385
|
+
const nextBaseClassSet = new Set(baseClassSet);
|
|
2386
|
+
for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
|
|
2387
|
+
return nextBaseClassSet;
|
|
2388
|
+
}
|
|
2196
2389
|
function createBundleRuntimeClassSetManager(options = {}) {
|
|
2197
2390
|
const customExtractCandidates = options.extractCandidates;
|
|
2198
2391
|
const extractCandidates = customExtractCandidates ?? tailwindcss_patch.extractValidCandidates;
|
|
2199
2392
|
const extractRawCandidates = options.extractRawCandidates ?? tailwindcss_patch.extractRawCandidatesWithPositions;
|
|
2393
|
+
const escapeMap = options.escapeMap ?? _weapp_core_escape.MappingChars2String;
|
|
2394
|
+
const escapeFragments = createEscapeFragments(escapeMap);
|
|
2200
2395
|
let baseClassSet = /* @__PURE__ */ new Set();
|
|
2201
2396
|
const candidateCountByClass = /* @__PURE__ */ new Map();
|
|
2202
2397
|
const candidatesByFile = /* @__PURE__ */ new Map();
|
|
@@ -2222,7 +2417,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2222
2417
|
return designSystemPromise;
|
|
2223
2418
|
}
|
|
2224
2419
|
function populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates) {
|
|
2225
|
-
const validCandidates = (0, tailwindcss_patch.resolveValidTailwindV4Candidates)(designSystem, unknownCandidates, { bareArbitraryValues: options.bareArbitraryValues });
|
|
2420
|
+
const validCandidates = (0, tailwindcss_patch.resolveValidTailwindV4Candidates)(designSystem, unknownCandidates, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
2226
2421
|
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
2227
2422
|
}
|
|
2228
2423
|
async function validateUnknownCandidates(patcher, unknownCandidates) {
|
|
@@ -2256,6 +2451,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2256
2451
|
candidates.add(candidate);
|
|
2257
2452
|
}
|
|
2258
2453
|
}
|
|
2454
|
+
if (patcher.majorVersion === 4) for (const candidate of collectEscapedRuntimeCandidates(entry.source, escapeMap, escapeFragments)) candidates.add(candidate);
|
|
2259
2455
|
return candidates;
|
|
2260
2456
|
}
|
|
2261
2457
|
async function sync(patcher, snapshot, options = {}) {
|
|
@@ -2274,7 +2470,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2274
2470
|
const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
|
|
2275
2471
|
for (const [file, previousCandidates] of candidatesByFile) {
|
|
2276
2472
|
if (currentRuntimeFiles.has(file) || snapshot.hasOmittedKnownFiles) continue;
|
|
2277
|
-
removeCandidateSet(candidateCountByClass, previousCandidates);
|
|
2473
|
+
removeCandidateSet$1(candidateCountByClass, previousCandidates);
|
|
2278
2474
|
candidatesByFile.delete(file);
|
|
2279
2475
|
}
|
|
2280
2476
|
const changedRuntimeFiles = canUseBaseWithoutInitialFullScan ? [...collectChangedRuntimeFiles(snapshot)] : fullRebuild ? [...runtimeEntriesByFile.keys()] : [...collectChangedRuntimeFiles(snapshot)];
|
|
@@ -2296,7 +2492,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2296
2492
|
for (const file of changedRuntimeFiles) {
|
|
2297
2493
|
const nextRawCandidates = rawCandidatesByFile.get(file);
|
|
2298
2494
|
const previousCandidates = candidatesByFile.get(file);
|
|
2299
|
-
if (previousCandidates) removeCandidateSet(candidateCountByClass, previousCandidates);
|
|
2495
|
+
if (previousCandidates) removeCandidateSet$1(candidateCountByClass, previousCandidates);
|
|
2300
2496
|
if (!nextRawCandidates || nextRawCandidates.size === 0) {
|
|
2301
2497
|
candidatesByFile.delete(file);
|
|
2302
2498
|
continue;
|
|
@@ -2307,7 +2503,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2307
2503
|
candidatesByFile.delete(file);
|
|
2308
2504
|
continue;
|
|
2309
2505
|
}
|
|
2310
|
-
addCandidateSet(candidateCountByClass, nextCandidates);
|
|
2506
|
+
addCandidateSet$1(candidateCountByClass, nextCandidates);
|
|
2311
2507
|
candidatesByFile.set(file, nextCandidates);
|
|
2312
2508
|
}
|
|
2313
2509
|
if (nextBaseClassSet) baseClassSet = canUseBaseWithoutInitialFullScan ? new Set(nextBaseClassSet) : createNonSourceBaseClassSet(nextBaseClassSet, candidateCountByClass);
|
|
@@ -2321,30 +2517,632 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2321
2517
|
};
|
|
2322
2518
|
}
|
|
2323
2519
|
//#endregion
|
|
2520
|
+
//#region src/bundlers/vite/source-candidates/scan-root.ts
|
|
2521
|
+
const TAILWIND_V4_IGNORED_CONTENT_DIRS = [
|
|
2522
|
+
".git",
|
|
2523
|
+
".hg",
|
|
2524
|
+
".jj",
|
|
2525
|
+
".next",
|
|
2526
|
+
".parcel-cache",
|
|
2527
|
+
".pnpm-store",
|
|
2528
|
+
".svelte-kit",
|
|
2529
|
+
".svn",
|
|
2530
|
+
".turbo",
|
|
2531
|
+
".venv",
|
|
2532
|
+
".vercel",
|
|
2533
|
+
".yarn",
|
|
2534
|
+
"__pycache__",
|
|
2535
|
+
"node_modules",
|
|
2536
|
+
"venv"
|
|
2537
|
+
];
|
|
2538
|
+
const TAILWIND_V4_IGNORED_EXTENSIONS = [
|
|
2539
|
+
"css",
|
|
2540
|
+
"less",
|
|
2541
|
+
"postcss",
|
|
2542
|
+
"pcss",
|
|
2543
|
+
"lock",
|
|
2544
|
+
"sass",
|
|
2545
|
+
"scss",
|
|
2546
|
+
"styl",
|
|
2547
|
+
"stylus",
|
|
2548
|
+
"log",
|
|
2549
|
+
"wxss",
|
|
2550
|
+
"acss",
|
|
2551
|
+
"jxss",
|
|
2552
|
+
"ttss",
|
|
2553
|
+
"qss",
|
|
2554
|
+
"tyss"
|
|
2555
|
+
];
|
|
2556
|
+
const TAILWIND_V4_IGNORED_FILES = [
|
|
2557
|
+
"package-lock.json",
|
|
2558
|
+
"pnpm-lock.yaml",
|
|
2559
|
+
"bun.lockb",
|
|
2560
|
+
".gitignore",
|
|
2561
|
+
".env",
|
|
2562
|
+
".env.*"
|
|
2563
|
+
];
|
|
2564
|
+
function resolveOutDirIgnorePattern(root, outDir) {
|
|
2565
|
+
if (!outDir) return;
|
|
2566
|
+
const relative = node_path.default.relative(root, node_path.default.resolve(root, outDir));
|
|
2567
|
+
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) return;
|
|
2568
|
+
return `${require_v3_engine.toPosixPath(relative)}/**`;
|
|
2569
|
+
}
|
|
2570
|
+
function normalizeScanEntries(root, entries, outDirIgnore) {
|
|
2571
|
+
const hasPositiveEntry = entries?.some((entry) => !entry.negated) === true;
|
|
2572
|
+
const scanEntries = entries?.length ? hasPositiveEntry ? entries : [{
|
|
2573
|
+
base: root,
|
|
2574
|
+
pattern: "**/*",
|
|
2575
|
+
negated: false
|
|
2576
|
+
}, ...entries] : void 0;
|
|
2577
|
+
if (!outDirIgnore) return scanEntries;
|
|
2578
|
+
return [...scanEntries ?? [{
|
|
2579
|
+
base: root,
|
|
2580
|
+
pattern: "**/*",
|
|
2581
|
+
negated: false
|
|
2582
|
+
}], {
|
|
2583
|
+
base: root,
|
|
2584
|
+
pattern: outDirIgnore,
|
|
2585
|
+
negated: true
|
|
2586
|
+
}];
|
|
2587
|
+
}
|
|
2588
|
+
function shouldApplyDefaultIgnoredSources(entries) {
|
|
2589
|
+
return entries?.length === void 0 ? false : entries.length > 0 && entries.every((entry) => entry.negated);
|
|
2590
|
+
}
|
|
2591
|
+
function createDefaultIgnoredSources(root, outDirIgnore, entries, explicit) {
|
|
2592
|
+
return [...!explicit || shouldApplyDefaultIgnoredSources(entries) ? [
|
|
2593
|
+
...TAILWIND_V4_IGNORED_CONTENT_DIRS.map((pattern) => ({
|
|
2594
|
+
base: root,
|
|
2595
|
+
pattern: `**/${pattern}/**`,
|
|
2596
|
+
negated: true
|
|
2597
|
+
})),
|
|
2598
|
+
...TAILWIND_V4_IGNORED_EXTENSIONS.map((extension) => ({
|
|
2599
|
+
base: root,
|
|
2600
|
+
pattern: `**/*.${extension}`,
|
|
2601
|
+
negated: true
|
|
2602
|
+
})),
|
|
2603
|
+
...TAILWIND_V4_IGNORED_FILES.map((pattern) => ({
|
|
2604
|
+
base: root,
|
|
2605
|
+
pattern: `**/${pattern}`,
|
|
2606
|
+
negated: true
|
|
2607
|
+
}))
|
|
2608
|
+
] : [], ...outDirIgnore ? [{
|
|
2609
|
+
base: root,
|
|
2610
|
+
pattern: outDirIgnore,
|
|
2611
|
+
negated: true
|
|
2612
|
+
}] : []];
|
|
2613
|
+
}
|
|
2614
|
+
function resolveSourceCandidateScanFiles(options) {
|
|
2615
|
+
const resolvedRoot = node_path.default.resolve(options.root);
|
|
2616
|
+
const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, options.outDir);
|
|
2617
|
+
const scanEntries = normalizeScanEntries(resolvedRoot, options.entries, outDirIgnore);
|
|
2618
|
+
const ignoredSources = createDefaultIgnoredSources(resolvedRoot, outDirIgnore, options.entries, options.explicit);
|
|
2619
|
+
return (0, tailwindcss_patch.resolveProjectSourceFiles)({
|
|
2620
|
+
cwd: resolvedRoot,
|
|
2621
|
+
...scanEntries === void 0 ? {} : { sources: scanEntries },
|
|
2622
|
+
...ignoredSources.length > 0 ? { ignoredSources } : {},
|
|
2623
|
+
filter: options.filter
|
|
2624
|
+
});
|
|
2625
|
+
}
|
|
2626
|
+
//#endregion
|
|
2627
|
+
//#region src/bundlers/vite/source-candidates/script.ts
|
|
2628
|
+
const SCRIPT_SOURCE_CANDIDATE_EXTENSIONS = new Set([
|
|
2629
|
+
"js",
|
|
2630
|
+
"jsx",
|
|
2631
|
+
"mjs",
|
|
2632
|
+
"cjs",
|
|
2633
|
+
"ts",
|
|
2634
|
+
"tsx",
|
|
2635
|
+
"mts",
|
|
2636
|
+
"cts"
|
|
2637
|
+
]);
|
|
2638
|
+
const CLASS_LIKE_NAME_RE = /class/i;
|
|
2639
|
+
function getPropertyName(node) {
|
|
2640
|
+
if (!node) return;
|
|
2641
|
+
if (node.type === "Identifier") return node.name;
|
|
2642
|
+
if (node.type === "StringLiteral") return node.value;
|
|
2643
|
+
}
|
|
2644
|
+
function isClassLikeStringPath(path) {
|
|
2645
|
+
const parent = path.parentPath;
|
|
2646
|
+
if (!parent) return false;
|
|
2647
|
+
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2648
|
+
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2649
|
+
if (parent.isAssignmentExpression?.()) {
|
|
2650
|
+
const left = parent.node.left;
|
|
2651
|
+
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2652
|
+
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2653
|
+
}
|
|
2654
|
+
if (parent.isJSXAttribute?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.name) ?? "");
|
|
2655
|
+
return false;
|
|
2656
|
+
}
|
|
2657
|
+
function isTemplateElementInClassLikePath(path) {
|
|
2658
|
+
const templateLiteralPath = path.parentPath;
|
|
2659
|
+
if (!templateLiteralPath?.isTemplateLiteral?.()) return false;
|
|
2660
|
+
const parent = templateLiteralPath.parentPath;
|
|
2661
|
+
if (!parent) return false;
|
|
2662
|
+
if (parent.isVariableDeclarator?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.id) ?? "");
|
|
2663
|
+
if (parent.isObjectProperty?.() || parent.isObjectMethod?.()) return CLASS_LIKE_NAME_RE.test(getPropertyName(parent.node.key) ?? "");
|
|
2664
|
+
if (parent.isAssignmentExpression?.()) {
|
|
2665
|
+
const left = parent.node.left;
|
|
2666
|
+
if (left?.type === "Identifier") return CLASS_LIKE_NAME_RE.test(left.name);
|
|
2667
|
+
if (left?.type === "MemberExpression") return CLASS_LIKE_NAME_RE.test(getPropertyName(left.property) ?? "");
|
|
2668
|
+
}
|
|
2669
|
+
return false;
|
|
2670
|
+
}
|
|
2671
|
+
async function extractScriptStringCandidates(source, extension, options) {
|
|
2672
|
+
if (!SCRIPT_SOURCE_CANDIDATE_EXTENSIONS.has(extension)) return [];
|
|
2673
|
+
const values = /* @__PURE__ */ new Set();
|
|
2674
|
+
try {
|
|
2675
|
+
require_precheck.traverse(require_precheck.babelParse(source, {
|
|
2676
|
+
cache: true,
|
|
2677
|
+
cacheKey: `vite-source-candidates:${extension}`,
|
|
2678
|
+
plugins: ["jsx", "typescript"],
|
|
2679
|
+
sourceType: "unambiguous"
|
|
2680
|
+
}), {
|
|
2681
|
+
noScope: true,
|
|
2682
|
+
StringLiteral(path) {
|
|
2683
|
+
if (isClassLikeStringPath(path)) values.add(path.node.value);
|
|
2684
|
+
},
|
|
2685
|
+
TemplateElement(path) {
|
|
2686
|
+
if (isTemplateElementInClassLikePath(path)) values.add(path.node.value.raw);
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
} catch {
|
|
2690
|
+
return [];
|
|
2691
|
+
}
|
|
2692
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2693
|
+
for (const value of values) {
|
|
2694
|
+
const extractedCandidates = options.extractor ? await options.extractor(value, "html") : await (0, tailwindcss_patch.extractSourceCandidates)(value, "html", { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
2695
|
+
for (const candidate of extractedCandidates) candidates.add(candidate);
|
|
2696
|
+
}
|
|
2697
|
+
return candidates;
|
|
2698
|
+
}
|
|
2699
|
+
//#endregion
|
|
2700
|
+
//#region src/bundlers/vite/source-candidates/tailwind-v3-default-extractor.ts
|
|
2701
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2702
|
+
const TAILWIND_V3_HTML_TOKEN_CANDIDATES = new Set([
|
|
2703
|
+
"/block",
|
|
2704
|
+
"/div",
|
|
2705
|
+
"/span",
|
|
2706
|
+
"/template",
|
|
2707
|
+
"/text",
|
|
2708
|
+
"/view",
|
|
2709
|
+
"class",
|
|
2710
|
+
"className",
|
|
2711
|
+
"div",
|
|
2712
|
+
"hover-class",
|
|
2713
|
+
"span",
|
|
2714
|
+
"template",
|
|
2715
|
+
"text",
|
|
2716
|
+
"view"
|
|
2717
|
+
]);
|
|
2718
|
+
function createTailwindV3DefaultExtractor() {
|
|
2719
|
+
try {
|
|
2720
|
+
const defaultExtractorModule = require$1("tailwindcss/lib/lib/defaultExtractor");
|
|
2721
|
+
const resolveConfigModule = require$1("tailwindcss/resolveConfig");
|
|
2722
|
+
const resolveConfig = resolveConfigModule.default ?? resolveConfigModule;
|
|
2723
|
+
const extractor = (defaultExtractorModule.defaultExtractor ?? defaultExtractorModule.default ?? defaultExtractorModule)({ tailwindConfig: resolveConfig({ content: [] }) });
|
|
2724
|
+
return (source) => new Set(extractor(source).filter((candidate) => !TAILWIND_V3_HTML_TOKEN_CANDIDATES.has(candidate)));
|
|
2725
|
+
} catch {
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
//#endregion
|
|
2730
|
+
//#region src/bundlers/vite/source-candidates.ts
|
|
2731
|
+
const CLEAN_URL_RE = /[?#].*$/;
|
|
2732
|
+
const sourceCandidateContentCache = /* @__PURE__ */ new Map();
|
|
2733
|
+
function cleanUrl(id) {
|
|
2734
|
+
return require_v3_engine.resolveSourceScanPath(id.replace(CLEAN_URL_RE, ""));
|
|
2735
|
+
}
|
|
2736
|
+
function resolveSourceCandidateExtension(id) {
|
|
2737
|
+
const normalized = cleanUrl(id);
|
|
2738
|
+
return /\.([^.\\/]+)$/.exec(normalized)?.[1] ?? "html";
|
|
2739
|
+
}
|
|
2740
|
+
function createSourceCandidateContentCacheKey(extension, source, bareArbitraryValues, extractor) {
|
|
2741
|
+
return `${extension}\0${JSON.stringify(bareArbitraryValues ?? false)}\0${extractor ? "custom" : "default"}\0${source}`;
|
|
2742
|
+
}
|
|
2743
|
+
async function extractCandidates(source, extension, options) {
|
|
2744
|
+
const candidates = options.extractor ? new Set(await options.extractor(source, extension)) : new Set(await (0, tailwindcss_patch.extractSourceCandidates)(source, extension, { ...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } }));
|
|
2745
|
+
const scriptCandidates = await extractScriptStringCandidates(source, extension, options);
|
|
2746
|
+
for (const candidate of scriptCandidates) candidates.add(candidate);
|
|
2747
|
+
return candidates;
|
|
2748
|
+
}
|
|
2749
|
+
function isSourceCandidateRequest(id) {
|
|
2750
|
+
return require_v3_engine.FULL_SOURCE_SCAN_EXTENSION_RE.test(cleanUrl(id));
|
|
2751
|
+
}
|
|
2752
|
+
function removeCandidateSet(candidateCount, candidates) {
|
|
2753
|
+
for (const candidate of candidates) {
|
|
2754
|
+
const count = candidateCount.get(candidate);
|
|
2755
|
+
if (count == null) continue;
|
|
2756
|
+
if (count <= 1) {
|
|
2757
|
+
candidateCount.delete(candidate);
|
|
2758
|
+
continue;
|
|
2759
|
+
}
|
|
2760
|
+
candidateCount.set(candidate, count - 1);
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
function addCandidateSet(candidateCount, candidates) {
|
|
2764
|
+
for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
|
|
2765
|
+
}
|
|
2766
|
+
function createSourceCandidateCollector(options = {}) {
|
|
2767
|
+
const candidatesById = /* @__PURE__ */ new Map();
|
|
2768
|
+
const scanCandidatesById = /* @__PURE__ */ new Map();
|
|
2769
|
+
const transformCandidatesById = /* @__PURE__ */ new Map();
|
|
2770
|
+
const cssCandidatesById = /* @__PURE__ */ new Map();
|
|
2771
|
+
const sourceById = /* @__PURE__ */ new Map();
|
|
2772
|
+
const candidateCount = /* @__PURE__ */ new Map();
|
|
2773
|
+
let inlineIncludedCandidates = /* @__PURE__ */ new Set();
|
|
2774
|
+
let inlineExcludedCandidates = /* @__PURE__ */ new Set();
|
|
2775
|
+
async function sync(id, source) {
|
|
2776
|
+
const normalizedId = cleanUrl(id);
|
|
2777
|
+
sourceById.set(normalizedId, source);
|
|
2778
|
+
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
2779
|
+
const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
|
|
2780
|
+
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
2781
|
+
if (cachedCandidates) {
|
|
2782
|
+
replaceScanLayer(normalizedId, new Set(cachedCandidates));
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
const nextCandidates = await extractCandidates(source, extension, options);
|
|
2786
|
+
sourceCandidateContentCache.set(contentCacheKey, [...nextCandidates]);
|
|
2787
|
+
replaceScanLayer(normalizedId, nextCandidates);
|
|
2788
|
+
}
|
|
2789
|
+
async function syncCss(id, source) {
|
|
2790
|
+
const normalizedId = cleanUrl(id);
|
|
2791
|
+
const contentCacheKey = createSourceCandidateContentCacheKey("css", source, options.bareArbitraryValues, options.extractor);
|
|
2792
|
+
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
2793
|
+
if (cachedCandidates) {
|
|
2794
|
+
replaceCssLayer(normalizedId, new Set(cachedCandidates));
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
const nextCandidates = await extractCandidates(source, "css", options);
|
|
2798
|
+
sourceCandidateContentCache.set(contentCacheKey, [...nextCandidates]);
|
|
2799
|
+
replaceCssLayer(normalizedId, nextCandidates);
|
|
2800
|
+
}
|
|
2801
|
+
async function merge(id, source) {
|
|
2802
|
+
const normalizedId = cleanUrl(id);
|
|
2803
|
+
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
2804
|
+
const contentCacheKey = createSourceCandidateContentCacheKey(extension, source, options.bareArbitraryValues, options.extractor);
|
|
2805
|
+
const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
|
|
2806
|
+
const extractedCandidates = cachedCandidates ? new Set(cachedCandidates) : await extractCandidates(source, extension, options);
|
|
2807
|
+
if (!cachedCandidates) sourceCandidateContentCache.set(contentCacheKey, [...extractedCandidates]);
|
|
2808
|
+
replaceTransformLayer(normalizedId, extractedCandidates);
|
|
2809
|
+
}
|
|
2810
|
+
async function syncFile(id) {
|
|
2811
|
+
const normalizedId = cleanUrl(id);
|
|
2812
|
+
await sync(normalizedId, await (0, node_fs_promises.readFile)(normalizedId, "utf8"));
|
|
2813
|
+
}
|
|
2814
|
+
async function syncCurrentFile(id) {
|
|
2815
|
+
const normalizedId = cleanUrl(id);
|
|
2816
|
+
transformCandidatesById.delete(normalizedId);
|
|
2817
|
+
await syncFile(normalizedId);
|
|
2818
|
+
}
|
|
2819
|
+
async function scanRoot({ entries, explicit, root, outDir }) {
|
|
2820
|
+
const files = await resolveSourceCandidateScanFiles({
|
|
2821
|
+
entries,
|
|
2822
|
+
explicit,
|
|
2823
|
+
filter: isSourceCandidateRequest,
|
|
2824
|
+
outDir,
|
|
2825
|
+
root
|
|
2826
|
+
});
|
|
2827
|
+
await Promise.all(files.map((file) => syncFile(require_v3_engine.resolveSourceScanPath(file))));
|
|
2828
|
+
}
|
|
2829
|
+
function replaceFinal(id, nextCandidates) {
|
|
2830
|
+
const normalizedId = cleanUrl(id);
|
|
2831
|
+
const previousCandidates = candidatesById.get(normalizedId);
|
|
2832
|
+
if (previousCandidates) {
|
|
2833
|
+
removeCandidateSet(candidateCount, previousCandidates);
|
|
2834
|
+
candidatesById.delete(normalizedId);
|
|
2835
|
+
}
|
|
2836
|
+
if (nextCandidates.size === 0) return;
|
|
2837
|
+
candidatesById.set(normalizedId, nextCandidates);
|
|
2838
|
+
addCandidateSet(candidateCount, nextCandidates);
|
|
2839
|
+
}
|
|
2840
|
+
function replaceScanLayer(id, nextCandidates) {
|
|
2841
|
+
const normalizedId = cleanUrl(id);
|
|
2842
|
+
if (nextCandidates.size === 0) scanCandidatesById.delete(normalizedId);
|
|
2843
|
+
else scanCandidatesById.set(normalizedId, nextCandidates);
|
|
2844
|
+
recompute(normalizedId);
|
|
2845
|
+
}
|
|
2846
|
+
function replaceTransformLayer(id, nextCandidates) {
|
|
2847
|
+
const normalizedId = cleanUrl(id);
|
|
2848
|
+
if (nextCandidates.size === 0) transformCandidatesById.delete(normalizedId);
|
|
2849
|
+
else transformCandidatesById.set(normalizedId, nextCandidates);
|
|
2850
|
+
recompute(normalizedId);
|
|
2851
|
+
}
|
|
2852
|
+
function replaceCssLayer(id, nextCandidates) {
|
|
2853
|
+
const normalizedId = cleanUrl(id);
|
|
2854
|
+
if (nextCandidates.size === 0) cssCandidatesById.delete(normalizedId);
|
|
2855
|
+
else cssCandidatesById.set(normalizedId, nextCandidates);
|
|
2856
|
+
recompute(normalizedId);
|
|
2857
|
+
}
|
|
2858
|
+
function recompute(id) {
|
|
2859
|
+
const normalizedId = cleanUrl(id);
|
|
2860
|
+
replaceFinal(normalizedId, new Set([
|
|
2861
|
+
...scanCandidatesById.get(normalizedId) ?? [],
|
|
2862
|
+
...transformCandidatesById.get(normalizedId) ?? [],
|
|
2863
|
+
...cssCandidatesById.get(normalizedId) ?? []
|
|
2864
|
+
]));
|
|
2865
|
+
}
|
|
2866
|
+
function syncInline(inlineCandidates) {
|
|
2867
|
+
inlineIncludedCandidates = new Set(inlineCandidates?.included ?? []);
|
|
2868
|
+
inlineExcludedCandidates = new Set(inlineCandidates?.excluded ?? []);
|
|
2869
|
+
}
|
|
2870
|
+
function remove(id) {
|
|
2871
|
+
const normalizedId = cleanUrl(id);
|
|
2872
|
+
scanCandidatesById.delete(normalizedId);
|
|
2873
|
+
transformCandidatesById.delete(normalizedId);
|
|
2874
|
+
cssCandidatesById.delete(normalizedId);
|
|
2875
|
+
sourceById.delete(normalizedId);
|
|
2876
|
+
const previousCandidates = candidatesById.get(normalizedId);
|
|
2877
|
+
if (!previousCandidates) return;
|
|
2878
|
+
removeCandidateSet(candidateCount, previousCandidates);
|
|
2879
|
+
candidatesById.delete(normalizedId);
|
|
2880
|
+
}
|
|
2881
|
+
function source(id) {
|
|
2882
|
+
return sourceById.get(cleanUrl(id));
|
|
2883
|
+
}
|
|
2884
|
+
function values() {
|
|
2885
|
+
const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
|
|
2886
|
+
for (const candidate of inlineExcludedCandidates) values.delete(candidate);
|
|
2887
|
+
return values;
|
|
2888
|
+
}
|
|
2889
|
+
function valuesForEntries(entries, options = {}) {
|
|
2890
|
+
if (entries === void 0) {
|
|
2891
|
+
if (!options.excludeEntries?.length) return values();
|
|
2892
|
+
}
|
|
2893
|
+
const filtered = /* @__PURE__ */ new Set();
|
|
2894
|
+
for (const [id, candidates] of candidatesById) {
|
|
2895
|
+
if (entries !== void 0 && !require_v3_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
2896
|
+
if (options.excludeEntries?.length && require_v3_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
|
|
2897
|
+
for (const candidate of candidates) filtered.add(candidate);
|
|
2898
|
+
}
|
|
2899
|
+
for (const candidate of inlineIncludedCandidates) filtered.add(candidate);
|
|
2900
|
+
for (const candidate of inlineExcludedCandidates) filtered.delete(candidate);
|
|
2901
|
+
return filtered;
|
|
2902
|
+
}
|
|
2903
|
+
function sourcesForEntries(entries, options = {}) {
|
|
2904
|
+
const sources = /* @__PURE__ */ new Map();
|
|
2905
|
+
const addCandidateSource = (candidate, id) => {
|
|
2906
|
+
let candidateSources = sources.get(candidate);
|
|
2907
|
+
if (!candidateSources) {
|
|
2908
|
+
candidateSources = /* @__PURE__ */ new Set();
|
|
2909
|
+
sources.set(candidate, candidateSources);
|
|
2910
|
+
}
|
|
2911
|
+
if (id) candidateSources.add(id);
|
|
2912
|
+
};
|
|
2913
|
+
for (const [id, candidates] of candidatesById) {
|
|
2914
|
+
if (entries !== void 0 && !require_v3_engine.isFileMatchedByTailwindSourceEntries(id, entries)) continue;
|
|
2915
|
+
if (options.excludeEntries?.length && require_v3_engine.isFileMatchedByTailwindSourceEntries(id, options.excludeEntries)) continue;
|
|
2916
|
+
for (const candidate of candidates) addCandidateSource(candidate, id);
|
|
2917
|
+
}
|
|
2918
|
+
for (const candidate of inlineIncludedCandidates) addCandidateSource(candidate, void 0);
|
|
2919
|
+
for (const candidate of inlineExcludedCandidates) sources.delete(candidate);
|
|
2920
|
+
return sources;
|
|
2921
|
+
}
|
|
2922
|
+
function clear() {
|
|
2923
|
+
candidatesById.clear();
|
|
2924
|
+
scanCandidatesById.clear();
|
|
2925
|
+
transformCandidatesById.clear();
|
|
2926
|
+
cssCandidatesById.clear();
|
|
2927
|
+
sourceById.clear();
|
|
2928
|
+
candidateCount.clear();
|
|
2929
|
+
inlineIncludedCandidates.clear();
|
|
2930
|
+
inlineExcludedCandidates.clear();
|
|
2931
|
+
}
|
|
2932
|
+
function snapshot() {
|
|
2933
|
+
return {
|
|
2934
|
+
candidatesById: [...candidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2935
|
+
cssCandidatesById: [...cssCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2936
|
+
scanCandidatesById: [...scanCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2937
|
+
sourceById: [...sourceById.entries()],
|
|
2938
|
+
transformCandidatesById: [...transformCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
|
|
2939
|
+
inlineExcludedCandidates: [...inlineExcludedCandidates],
|
|
2940
|
+
inlineIncludedCandidates: [...inlineIncludedCandidates]
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
function restore(snapshot) {
|
|
2944
|
+
clear();
|
|
2945
|
+
inlineExcludedCandidates = new Set(snapshot.inlineExcludedCandidates);
|
|
2946
|
+
inlineIncludedCandidates = new Set(snapshot.inlineIncludedCandidates);
|
|
2947
|
+
const scanEntries = snapshot.scanCandidatesById ?? snapshot.candidatesById;
|
|
2948
|
+
for (const [id, candidates] of scanEntries) {
|
|
2949
|
+
const candidateSet = new Set(candidates);
|
|
2950
|
+
if (candidateSet.size === 0) continue;
|
|
2951
|
+
scanCandidatesById.set(id, candidateSet);
|
|
2952
|
+
}
|
|
2953
|
+
for (const [id, candidates] of snapshot.transformCandidatesById ?? []) {
|
|
2954
|
+
const candidateSet = new Set(candidates);
|
|
2955
|
+
if (candidateSet.size === 0) continue;
|
|
2956
|
+
transformCandidatesById.set(id, candidateSet);
|
|
2957
|
+
}
|
|
2958
|
+
for (const [id, candidates] of snapshot.cssCandidatesById ?? []) {
|
|
2959
|
+
const candidateSet = new Set(candidates);
|
|
2960
|
+
if (candidateSet.size === 0) continue;
|
|
2961
|
+
cssCandidatesById.set(id, candidateSet);
|
|
2962
|
+
}
|
|
2963
|
+
for (const [id, candidates] of snapshot.candidatesById) {
|
|
2964
|
+
const candidateSet = new Set(candidates);
|
|
2965
|
+
if (candidateSet.size === 0) continue;
|
|
2966
|
+
candidatesById.set(id, candidateSet);
|
|
2967
|
+
addCandidateSet(candidateCount, candidateSet);
|
|
2968
|
+
}
|
|
2969
|
+
for (const [id, source] of snapshot.sourceById ?? []) sourceById.set(id, source);
|
|
2970
|
+
}
|
|
2971
|
+
return {
|
|
2972
|
+
sync,
|
|
2973
|
+
syncCss,
|
|
2974
|
+
merge,
|
|
2975
|
+
syncFile,
|
|
2976
|
+
syncCurrentFile,
|
|
2977
|
+
scanRoot,
|
|
2978
|
+
syncInline,
|
|
2979
|
+
remove,
|
|
2980
|
+
source,
|
|
2981
|
+
values,
|
|
2982
|
+
valuesForEntries,
|
|
2983
|
+
sourcesForEntries,
|
|
2984
|
+
snapshot,
|
|
2985
|
+
restore,
|
|
2986
|
+
clear
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
//#endregion
|
|
2990
|
+
//#region src/bundlers/shared/hmr-timing.ts
|
|
2991
|
+
function shouldEmitHmrTiming() {
|
|
2992
|
+
return node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
2993
|
+
}
|
|
2994
|
+
function shouldEmitHumanReadableTiming() {
|
|
2995
|
+
return node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1" && node_process.default.env["WEAPP_TW_HMR_TIMING_LOG"] !== "0";
|
|
2996
|
+
}
|
|
2997
|
+
function emitHmrTiming(bundler, phase, durationMs, details = {}) {
|
|
2998
|
+
if (!shouldEmitHmrTiming()) return;
|
|
2999
|
+
const serializableDetails = { ...details };
|
|
3000
|
+
delete serializableDetails.emit;
|
|
3001
|
+
const payload = {
|
|
3002
|
+
bundler,
|
|
3003
|
+
phase,
|
|
3004
|
+
durationMs: Math.max(0, Math.round(durationMs)),
|
|
3005
|
+
...serializableDetails,
|
|
3006
|
+
...typeof details.wallMs === "number" ? { wallMs: Math.max(0, Math.round(details.wallMs)) } : {}
|
|
3007
|
+
};
|
|
3008
|
+
node_process.default.stdout.write(`[weapp-tailwindcss:hmr] ${JSON.stringify(payload)}\n`);
|
|
3009
|
+
if (shouldEmitHumanReadableTiming()) {
|
|
3010
|
+
const fileSuffix = details.file ? ` file=${details.file}` : "";
|
|
3011
|
+
if (details.metric === "total") {
|
|
3012
|
+
const hooks = details.hooks ? Object.entries(details.hooks).map(([hook, summary]) => `${hook}=${Math.max(0, Math.round(summary.durationMs))}ms/${summary.count}`).join(", ") : "";
|
|
3013
|
+
const hookSuffix = hooks ? ` (${hooks})` : "";
|
|
3014
|
+
const wallSuffix = typeof payload.wallMs === "number" ? ` wall=${payload.wallMs}ms` : "";
|
|
3015
|
+
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:weapp-tailwindcss 总耗时 ${payload.durationMs}ms${wallSuffix}${hookSuffix}\n`);
|
|
3016
|
+
return;
|
|
3017
|
+
}
|
|
3018
|
+
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:${phase} 耗时 ${payload.durationMs}ms${fileSuffix}\n`);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
function createHmrTimingRecorder(bundler) {
|
|
3022
|
+
const session = {
|
|
3023
|
+
hooks: {},
|
|
3024
|
+
totalMs: 0
|
|
3025
|
+
};
|
|
3026
|
+
const record = (phase, durationMs, details = {}) => {
|
|
3027
|
+
const roundedDuration = Math.max(0, Math.round(durationMs));
|
|
3028
|
+
if (session.startedAt === void 0) session.startedAt = performance.now() - Math.max(0, durationMs);
|
|
3029
|
+
session.totalMs += Math.max(0, durationMs);
|
|
3030
|
+
const current = session.hooks[phase] ?? {
|
|
3031
|
+
count: 0,
|
|
3032
|
+
durationMs: 0,
|
|
3033
|
+
maxMs: 0
|
|
3034
|
+
};
|
|
3035
|
+
current.count += 1;
|
|
3036
|
+
current.durationMs += roundedDuration;
|
|
3037
|
+
current.maxMs = Math.max(current.maxMs, roundedDuration);
|
|
3038
|
+
session.hooks[phase] = current;
|
|
3039
|
+
if (details.emit !== false) emitHmrTiming(bundler, phase, durationMs, details);
|
|
3040
|
+
};
|
|
3041
|
+
const measure = async (phase, task, details = {}) => {
|
|
3042
|
+
const startedAt = performance.now();
|
|
3043
|
+
try {
|
|
3044
|
+
return await task();
|
|
3045
|
+
} finally {
|
|
3046
|
+
record(phase, performance.now() - startedAt, details);
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
const emitTotal = (phase = "total") => {
|
|
3050
|
+
if (session.totalMs <= 0) return;
|
|
3051
|
+
const wallMs = session.startedAt === void 0 ? session.totalMs : performance.now() - session.startedAt;
|
|
3052
|
+
emitHmrTiming(bundler, phase, session.totalMs, {
|
|
3053
|
+
hooks: session.hooks,
|
|
3054
|
+
metric: "total",
|
|
3055
|
+
wallMs
|
|
3056
|
+
});
|
|
3057
|
+
session.hooks = {};
|
|
3058
|
+
delete session.startedAt;
|
|
3059
|
+
session.totalMs = 0;
|
|
3060
|
+
};
|
|
3061
|
+
return {
|
|
3062
|
+
emitTotal,
|
|
3063
|
+
measure,
|
|
3064
|
+
record
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
//#endregion
|
|
3068
|
+
Object.defineProperty(exports, "annotateCssSourceTrace", {
|
|
3069
|
+
enumerable: true,
|
|
3070
|
+
get: function() {
|
|
3071
|
+
return annotateCssSourceTrace;
|
|
3072
|
+
}
|
|
3073
|
+
});
|
|
2324
3074
|
Object.defineProperty(exports, "createBundleRuntimeClassSetManager", {
|
|
2325
3075
|
enumerable: true,
|
|
2326
3076
|
get: function() {
|
|
2327
3077
|
return createBundleRuntimeClassSetManager;
|
|
2328
3078
|
}
|
|
2329
3079
|
});
|
|
3080
|
+
Object.defineProperty(exports, "createCssSourceTraceCacheSignature", {
|
|
3081
|
+
enumerable: true,
|
|
3082
|
+
get: function() {
|
|
3083
|
+
return createCssSourceTraceCacheSignature;
|
|
3084
|
+
}
|
|
3085
|
+
});
|
|
3086
|
+
Object.defineProperty(exports, "createCssTokenSourceMap", {
|
|
3087
|
+
enumerable: true,
|
|
3088
|
+
get: function() {
|
|
3089
|
+
return createCssTokenSourceMap;
|
|
3090
|
+
}
|
|
3091
|
+
});
|
|
2330
3092
|
Object.defineProperty(exports, "createHmrTimingRecorder", {
|
|
2331
3093
|
enumerable: true,
|
|
2332
3094
|
get: function() {
|
|
2333
3095
|
return createHmrTimingRecorder;
|
|
2334
3096
|
}
|
|
2335
3097
|
});
|
|
3098
|
+
Object.defineProperty(exports, "createSourceCandidateCollector", {
|
|
3099
|
+
enumerable: true,
|
|
3100
|
+
get: function() {
|
|
3101
|
+
return createSourceCandidateCollector;
|
|
3102
|
+
}
|
|
3103
|
+
});
|
|
3104
|
+
Object.defineProperty(exports, "createTailwindV3DefaultExtractor", {
|
|
3105
|
+
enumerable: true,
|
|
3106
|
+
get: function() {
|
|
3107
|
+
return createTailwindV3DefaultExtractor;
|
|
3108
|
+
}
|
|
3109
|
+
});
|
|
2336
3110
|
Object.defineProperty(exports, "emitHmrTiming", {
|
|
2337
3111
|
enumerable: true,
|
|
2338
3112
|
get: function() {
|
|
2339
3113
|
return emitHmrTiming;
|
|
2340
3114
|
}
|
|
2341
3115
|
});
|
|
3116
|
+
Object.defineProperty(exports, "extractMarkedUserLayerComponentsCss", {
|
|
3117
|
+
enumerable: true,
|
|
3118
|
+
get: function() {
|
|
3119
|
+
return extractMarkedUserLayerComponentsCss;
|
|
3120
|
+
}
|
|
3121
|
+
});
|
|
2342
3122
|
Object.defineProperty(exports, "generateCssByGenerator", {
|
|
2343
3123
|
enumerable: true,
|
|
2344
3124
|
get: function() {
|
|
2345
3125
|
return generateCssByGenerator;
|
|
2346
3126
|
}
|
|
2347
3127
|
});
|
|
3128
|
+
Object.defineProperty(exports, "isCssSourceTraceEnabled", {
|
|
3129
|
+
enumerable: true,
|
|
3130
|
+
get: function() {
|
|
3131
|
+
return isCssSourceTraceEnabled;
|
|
3132
|
+
}
|
|
3133
|
+
});
|
|
3134
|
+
Object.defineProperty(exports, "isPureLocalCssImportWrapper", {
|
|
3135
|
+
enumerable: true,
|
|
3136
|
+
get: function() {
|
|
3137
|
+
return isPureLocalCssImportWrapper;
|
|
3138
|
+
}
|
|
3139
|
+
});
|
|
3140
|
+
Object.defineProperty(exports, "isSourceCandidateRequest", {
|
|
3141
|
+
enumerable: true,
|
|
3142
|
+
get: function() {
|
|
3143
|
+
return isSourceCandidateRequest;
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
2348
3146
|
Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
|
|
2349
3147
|
enumerable: true,
|
|
2350
3148
|
get: function() {
|