weapp-tailwindcss 5.0.1 → 5.0.3
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-CBF5YX1m.js → bundle-state-CW1X7QIy.js} +35 -3
- package/dist/{bundle-state-CQmxxx0R.mjs → bundle-state-s5HwfrmR.mjs} +24 -4
- package/dist/bundlers/shared/generated-css-marker.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -5
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -0
- package/dist/bundlers/shared/generator-css.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +5 -1
- package/dist/bundlers/vite/css-finalizer.d.ts +12 -3
- package/dist/bundlers/vite/generate-bundle.d.ts +22 -6
- package/dist/bundlers/vite/processed-css-assets.d.ts +10 -2
- package/dist/bundlers/vite/source-candidates.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +8 -0
- package/dist/cli.js +5 -4
- package/dist/cli.mjs +5 -4
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-CvmsIQFI.js → generator-Bd1LntD3.js} +1 -1
- package/dist/{generator-DDtsUvkH.mjs → generator-DRHWC1t-.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +16 -10
- package/dist/gulp.mjs +14 -8
- package/dist/{incremental-runtime-class-set-DArodvWs.mjs → incremental-runtime-class-set-BcAFhVvu.mjs} +496 -619
- package/dist/{incremental-runtime-class-set-BffodqHh.js → incremental-runtime-class-set-BdCWIuPW.js} +541 -694
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-BzNYQUOH.mjs → postcss-CJrmfXvi.mjs} +4 -4
- package/dist/{postcss-DE0TOtV9.js → postcss-DfnqZ4Bm.js} +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-BzYPm-EG.js → precheck-8Ik4q0yI.js} +6 -6
- package/dist/{precheck-jZvTVXXG.mjs → precheck-h6TNzFbF.mjs} +6 -6
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{source-candidates-BuTlMabx.mjs → source-candidates-D7b-Jzsx.mjs} +44 -11
- package/dist/{source-candidates-CxoIaS88.js → source-candidates-DQxvGPSw.js} +49 -10
- package/dist/tailwindcss/source-scan.d.ts +3 -1
- package/dist/{tailwindcss-CCZcu0lr.mjs → tailwindcss-D5RogwtV.mjs} +2 -2
- package/dist/{tailwindcss-DZckITp1.js → tailwindcss-jvoYizzX.js} +7 -1
- package/dist/{v3-engine-DGBhUnjn.mjs → v3-engine-BCUGX3gX.mjs} +637 -31
- package/dist/{v3-engine-M6Aqru5T.js → v3-engine-CmIF_gsq.js} +768 -30
- package/dist/{vite-DgRkWVPG.js → vite-DT-VUrl0.js} +539 -296
- package/dist/{vite-BBcQIJpD.mjs → vite-yCeZWm7n.mjs} +538 -295
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/{runtime-registry-DpcR3IHI.js → watch-dependencies-zwx4EhBn.js} +39 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +1933 -1621
- package/dist/weapp-tw-runtime-classset-loader.js +6 -6
- package/dist/{webpack-D-gb4ZvO.js → webpack-BFMJqCH9.js} +7 -7
- package/dist/{webpack-D43aMQzO.mjs → webpack-E0gT72EX.mjs} +7 -7
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,472 +1,12 @@
|
|
|
1
|
-
import { m as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-
|
|
2
|
-
import { B as
|
|
3
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-
|
|
1
|
+
import { m as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-h6TNzFbF.mjs";
|
|
2
|
+
import { A as parseImportRequest, B as stripGeneratorPlaceholderMarkers, C as hasTailwindApplyDirective, D as normalizeTailwindSourceDirectives, F as hasTailwindGeneratedCss, H as stripTailwindBanners, I as hasTailwindGeneratedCssMarkers, J as filterUnsupportedMiniProgramTailwindV4Candidates, L as splitGeneratorPlaceholderCssBySourceOrder, M as resolveCssEntrySource, N as VITE_MARKER_RE, P as createCssAppend, R as splitTailwindGeneratedCssByBanner, S as resolveTailwindV4SourceOptionsFromPatcher, T as hasTailwindSourceDirectives, U as normalizeConfigDirective, V as stripTailwindBanner, W as prependConfigDirective, Y as loadTailwindV4DesignSystem, ct as createDebug, h as resolveTailwindV4EntriesFromCss, ht as omitUndefined, j as removeTailwindSourceDirectives, k as normalizeTailwindV3CssEntrySource, l as getRuntimeClassSetSignature, n as resolveTailwindV3SourceFromPatcher, nt as normalizeLegacyContentEntries, ot as resolveTailwindV4CssSourceBase, r as resolveTailwindV3SourceOptionsFromPatcher, t as resolveTailwindV3Source, w as hasTailwindRootDirectives, x as resolveTailwindV4SourceFromPatcher, y as resolveTailwindV4Source$1, z as splitTailwindV4GeneratedCssBySourceOrder } from "./v3-engine-BCUGX3gX.mjs";
|
|
3
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DRHWC1t-.mjs";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import postcss from "postcss";
|
|
6
6
|
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveValidTailwindV4Candidates } from "tailwindcss-patch";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { finalizeMiniProgramCss, removeUnsupportedMiniProgramAtRules } from "@weapp-tailwindcss/postcss";
|
|
10
|
-
//#region src/bundlers/shared/generator-css/markers.ts
|
|
11
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
12
|
-
const TAILWIND_GENERATED_CSS_MARKER_RE = /\/\*!\s*tailwindcss v|@property\s+--tw-|--tw-|:not\(#\\#\)|\.[^,{]*(?:\\:|\\\[|\\#)|(?::host|page|\.tw-root|wx-root-portal-content)[^{]*\{[^}]*--(?:color|spacing|text|font-weight|radius)-/;
|
|
13
|
-
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
14
|
-
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
15
|
-
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
16
|
-
const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
|
|
17
|
-
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
18
|
-
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
19
|
-
function createCssAppend(base, extra) {
|
|
20
|
-
if (!base) return extra;
|
|
21
|
-
if (!extra) return base;
|
|
22
|
-
return `${base}\n${extra}`;
|
|
23
|
-
}
|
|
24
|
-
function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
25
|
-
const trimmedRaw = rawSource.trim();
|
|
26
|
-
const trimmedTailwind = rawTailwindCss.trim();
|
|
27
|
-
if (trimmedRaw === trimmedTailwind) return {
|
|
28
|
-
before: "",
|
|
29
|
-
after: ""
|
|
30
|
-
};
|
|
31
|
-
if (trimmedTailwind.startsWith(trimmedRaw)) return {
|
|
32
|
-
before: "",
|
|
33
|
-
after: ""
|
|
34
|
-
};
|
|
35
|
-
const start = rawSource.indexOf(rawTailwindCss);
|
|
36
|
-
if (start === -1) return;
|
|
37
|
-
return {
|
|
38
|
-
before: rawSource.slice(0, start),
|
|
39
|
-
after: rawSource.slice(start + rawTailwindCss.length)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
43
|
-
const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
|
|
44
|
-
if (!match || match.index === void 0) return;
|
|
45
|
-
let afterStart = match.index + match[0].length;
|
|
46
|
-
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
47
|
-
if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
|
|
48
|
-
afterStart += rawTailwindCss.length;
|
|
49
|
-
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
before: rawSource.slice(0, match.index),
|
|
53
|
-
after: rawSource.slice(afterStart)
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function splitTailwindGeneratedCssByBanner(rawSource, start) {
|
|
57
|
-
const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
|
|
58
|
-
if (!match || match.index === void 0) return;
|
|
59
|
-
return {
|
|
60
|
-
before: rawSource.slice(0, match.index),
|
|
61
|
-
after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function stripTailwindBanner(css) {
|
|
65
|
-
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
66
|
-
}
|
|
67
|
-
function stripTailwindBanners(css) {
|
|
68
|
-
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
69
|
-
}
|
|
70
|
-
function stripGeneratorPlaceholderMarkers(css) {
|
|
71
|
-
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
72
|
-
}
|
|
73
|
-
function hasTailwindGeneratedCss(rawSource) {
|
|
74
|
-
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
75
|
-
}
|
|
76
|
-
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
77
|
-
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/bundlers/shared/generator-css/directives.ts
|
|
81
|
-
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
82
|
-
"config",
|
|
83
|
-
"custom-variant",
|
|
84
|
-
"layer",
|
|
85
|
-
"plugin",
|
|
86
|
-
"reference",
|
|
87
|
-
"source",
|
|
88
|
-
"tailwind",
|
|
89
|
-
"theme",
|
|
90
|
-
"utility",
|
|
91
|
-
"variant"
|
|
92
|
-
]);
|
|
93
|
-
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
94
|
-
"config",
|
|
95
|
-
"custom-variant",
|
|
96
|
-
"plugin",
|
|
97
|
-
"source",
|
|
98
|
-
"tailwind",
|
|
99
|
-
"theme",
|
|
100
|
-
"utility",
|
|
101
|
-
"variant"
|
|
102
|
-
]);
|
|
103
|
-
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
104
|
-
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
105
|
-
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
106
|
-
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
107
|
-
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
108
|
-
["tailwindcss/base", "base"],
|
|
109
|
-
["tailwindcss/components", "components"],
|
|
110
|
-
["tailwindcss/utilities", "utilities"]
|
|
111
|
-
]);
|
|
112
|
-
function parseImportRequest(params) {
|
|
113
|
-
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
114
|
-
}
|
|
115
|
-
function parseConfigRequest(params) {
|
|
116
|
-
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
117
|
-
}
|
|
118
|
-
function isPackageJsonImportRequest(request) {
|
|
119
|
-
return typeof request === "string" && request.startsWith("#");
|
|
120
|
-
}
|
|
121
|
-
function isWeappTailwindcssImportRequest(request) {
|
|
122
|
-
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
123
|
-
}
|
|
124
|
-
function normalizeTailwindImportRequest(request, options = {}) {
|
|
125
|
-
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
126
|
-
return request;
|
|
127
|
-
}
|
|
128
|
-
function replaceImportRequest(params, request, replacement) {
|
|
129
|
-
const index = params.indexOf(request);
|
|
130
|
-
if (index === -1) return params;
|
|
131
|
-
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
132
|
-
}
|
|
133
|
-
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
134
|
-
if (!options.importFallback) return false;
|
|
135
|
-
let changed = false;
|
|
136
|
-
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
137
|
-
root.walkAtRules("import", (node) => {
|
|
138
|
-
const request = parseImportRequest(node.params);
|
|
139
|
-
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
140
|
-
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
141
|
-
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
142
|
-
const normalizedKey = normalizedParams.trim();
|
|
143
|
-
if (seenCanonicalImports.has(normalizedKey)) {
|
|
144
|
-
node.remove();
|
|
145
|
-
changed = true;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
seenCanonicalImports.add(normalizedKey);
|
|
149
|
-
if (normalizedParams !== node.params) {
|
|
150
|
-
node.params = normalizedParams;
|
|
151
|
-
changed = true;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return changed;
|
|
155
|
-
}
|
|
156
|
-
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
157
|
-
const trimmed = line.trimStart();
|
|
158
|
-
if (/^@(?:use|forward)\b/.test(trimmed)) {
|
|
159
|
-
const request = parseImportRequest(trimmed.replace(/^@(?:use|forward)\b/, ""));
|
|
160
|
-
if (isTailwindImportRequest(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
|
|
161
|
-
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
162
|
-
return replaceImportRequest(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
|
|
163
|
-
}
|
|
164
|
-
return line;
|
|
165
|
-
}
|
|
166
|
-
if (!options.importFallback || !trimmed.startsWith("@import")) return line;
|
|
167
|
-
const request = parseImportRequest(trimmed.replace(/^@import\b/, ""));
|
|
168
|
-
if (!request || !isWeappTailwindcssImportRequest(request)) return line;
|
|
169
|
-
return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
170
|
-
}
|
|
171
|
-
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
172
|
-
const directives = [];
|
|
173
|
-
const seenImports = /* @__PURE__ */ new Set();
|
|
174
|
-
for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
175
|
-
const trimmed = line.trim();
|
|
176
|
-
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
177
|
-
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
|
|
178
|
-
if (!directive) continue;
|
|
179
|
-
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
180
|
-
const normalizedTrimmed = normalized.trim();
|
|
181
|
-
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
182
|
-
const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
|
|
183
|
-
if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest(request)) continue;
|
|
184
|
-
if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
|
|
185
|
-
if (request && isTailwindImportRequest(request)) {
|
|
186
|
-
const key = normalizedTrimmed;
|
|
187
|
-
if (seenImports.has(key)) continue;
|
|
188
|
-
seenImports.add(key);
|
|
189
|
-
}
|
|
190
|
-
directives.push(normalized);
|
|
191
|
-
}
|
|
192
|
-
return directives;
|
|
193
|
-
}
|
|
194
|
-
function stripPreprocessorLineComment(line) {
|
|
195
|
-
let quote;
|
|
196
|
-
let escaped = false;
|
|
197
|
-
for (let index = 0; index < line.length; index++) {
|
|
198
|
-
const char = line[index];
|
|
199
|
-
if (escaped) {
|
|
200
|
-
escaped = false;
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (char === "\\") {
|
|
204
|
-
escaped = true;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (quote) {
|
|
208
|
-
if (char === quote) quote = void 0;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (char === "\"" || char === "'") {
|
|
212
|
-
quote = char;
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
|
|
216
|
-
}
|
|
217
|
-
return line;
|
|
218
|
-
}
|
|
219
|
-
function countBlockBraceDelta(line) {
|
|
220
|
-
let quote;
|
|
221
|
-
let escaped = false;
|
|
222
|
-
let delta = 0;
|
|
223
|
-
for (let index = 0; index < line.length; index++) {
|
|
224
|
-
const char = line[index];
|
|
225
|
-
if (escaped) {
|
|
226
|
-
escaped = false;
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (char === "\\") {
|
|
230
|
-
escaped = true;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
if (quote) {
|
|
234
|
-
if (char === quote) quote = void 0;
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (char === "\"" || char === "'") {
|
|
238
|
-
quote = char;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (char === "{") delta++;
|
|
242
|
-
else if (char === "}") delta--;
|
|
243
|
-
}
|
|
244
|
-
return delta;
|
|
245
|
-
}
|
|
246
|
-
function extractTailwindFallbackBlocks(rawSource) {
|
|
247
|
-
const blocks = [];
|
|
248
|
-
let current;
|
|
249
|
-
let depth = 0;
|
|
250
|
-
for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
251
|
-
const line = stripPreprocessorLineComment(rawLine);
|
|
252
|
-
if (!line.trim()) continue;
|
|
253
|
-
if (!current) {
|
|
254
|
-
if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
|
|
255
|
-
current = [line];
|
|
256
|
-
depth = countBlockBraceDelta(line);
|
|
257
|
-
if (depth <= 0) {
|
|
258
|
-
blocks.push(current.join("\n"));
|
|
259
|
-
current = void 0;
|
|
260
|
-
depth = 0;
|
|
261
|
-
}
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
current.push(line);
|
|
265
|
-
depth += countBlockBraceDelta(line);
|
|
266
|
-
if (depth <= 0) {
|
|
267
|
-
blocks.push(current.join("\n"));
|
|
268
|
-
current = void 0;
|
|
269
|
-
depth = 0;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return blocks;
|
|
273
|
-
}
|
|
274
|
-
function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
275
|
-
const directives = [...extractTailwindDirectiveLines(rawSource, options), ...extractTailwindFallbackBlocks(rawSource)];
|
|
276
|
-
return directives.length > 0 ? directives.join("\n") : void 0;
|
|
277
|
-
}
|
|
278
|
-
function extractConfigRequestFromSource(rawSource) {
|
|
279
|
-
for (const line of rawSource.split(/\r?\n/)) {
|
|
280
|
-
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
281
|
-
const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
|
|
282
|
-
if (request) return request;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
function hasPreprocessorOnlySyntax(rawSource) {
|
|
286
|
-
return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
|
|
287
|
-
}
|
|
288
|
-
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
289
|
-
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
290
|
-
}
|
|
291
|
-
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
292
|
-
try {
|
|
293
|
-
const root = postcss.parse(rawSource);
|
|
294
|
-
let changed = false;
|
|
295
|
-
root.walkAtRules("import", (node) => {
|
|
296
|
-
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
297
|
-
if (!layer) return;
|
|
298
|
-
node.replaceWith(postcss.atRule({
|
|
299
|
-
name: "tailwind",
|
|
300
|
-
params: layer
|
|
301
|
-
}));
|
|
302
|
-
changed = true;
|
|
303
|
-
});
|
|
304
|
-
return changed ? root.toString() : rawSource;
|
|
305
|
-
} catch {
|
|
306
|
-
return rawSource;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
310
|
-
if (!options.importFallback) return rawSource;
|
|
311
|
-
try {
|
|
312
|
-
const root = postcss.parse(rawSource);
|
|
313
|
-
return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
|
|
314
|
-
} catch {
|
|
315
|
-
return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function isTailwindImportRequest(request) {
|
|
319
|
-
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
320
|
-
}
|
|
321
|
-
function isTailwindImportAtRule(node, options = {}) {
|
|
322
|
-
if (node.name === "tailwind") return true;
|
|
323
|
-
if (node.name !== "import" && node.name !== "use" && node.name !== "forward") return false;
|
|
324
|
-
return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
|
|
325
|
-
}
|
|
326
|
-
function isTailwindSourceDirective(node, options = {}) {
|
|
327
|
-
if (node.type !== "atrule") return false;
|
|
328
|
-
const atRule = node;
|
|
329
|
-
if (isTailwindImportAtRule(atRule, options)) return true;
|
|
330
|
-
if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
|
|
331
|
-
if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
|
|
332
|
-
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
333
|
-
}
|
|
334
|
-
function hasGeneratedCssArtifacts(rawSource) {
|
|
335
|
-
return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
336
|
-
}
|
|
337
|
-
function isTailwindGenerationDirective(node, options = {}) {
|
|
338
|
-
if (node.type !== "atrule") return false;
|
|
339
|
-
const atRule = node;
|
|
340
|
-
const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
|
|
341
|
-
return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
|
|
342
|
-
}
|
|
343
|
-
function removeTailwindSourceDirectives(rawSource, options = {}) {
|
|
344
|
-
try {
|
|
345
|
-
const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
|
|
346
|
-
if (!source) return "";
|
|
347
|
-
const root = postcss.parse(source);
|
|
348
|
-
let removed = false;
|
|
349
|
-
root.walk((node) => {
|
|
350
|
-
if (isTailwindSourceDirective(node, options)) {
|
|
351
|
-
node.remove();
|
|
352
|
-
removed = true;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
return removed ? root.toString() : source;
|
|
356
|
-
} catch {
|
|
357
|
-
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function hasTailwindSourceDirectives(rawSource, options = {}) {
|
|
361
|
-
try {
|
|
362
|
-
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
363
|
-
const root = postcss.parse(rawSource);
|
|
364
|
-
let found = false;
|
|
365
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
366
|
-
root.walk((node) => {
|
|
367
|
-
if (isTailwindGenerationDirective(node, {
|
|
368
|
-
...options,
|
|
369
|
-
ignoreLayer
|
|
370
|
-
})) {
|
|
371
|
-
found = true;
|
|
372
|
-
return false;
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
return found;
|
|
376
|
-
} catch {
|
|
377
|
-
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function hasTailwindRootDirectives(rawSource, options = {}) {
|
|
381
|
-
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
|
|
382
|
-
try {
|
|
383
|
-
const root = postcss.parse(rawSource);
|
|
384
|
-
let found = false;
|
|
385
|
-
root.walkAtRules((node) => {
|
|
386
|
-
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
387
|
-
if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
388
|
-
found = true;
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
return found;
|
|
393
|
-
} catch {
|
|
394
|
-
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
function hasTailwindApplyDirective(rawSource) {
|
|
398
|
-
if (!rawSource.includes("@apply")) return false;
|
|
399
|
-
try {
|
|
400
|
-
const root = postcss.parse(rawSource);
|
|
401
|
-
let found = false;
|
|
402
|
-
root.walkAtRules("apply", () => {
|
|
403
|
-
found = true;
|
|
404
|
-
return false;
|
|
405
|
-
});
|
|
406
|
-
return found;
|
|
407
|
-
} catch {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
412
|
-
try {
|
|
413
|
-
const root = postcss.parse(rawSource);
|
|
414
|
-
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
415
|
-
let found = false;
|
|
416
|
-
let config;
|
|
417
|
-
let configRequest;
|
|
418
|
-
let removedConfig = false;
|
|
419
|
-
const removeConfig = options.removeConfig ?? true;
|
|
420
|
-
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
421
|
-
root.walk((node) => {
|
|
422
|
-
if (isTailwindGenerationDirective(node, {
|
|
423
|
-
...options,
|
|
424
|
-
ignoreLayer
|
|
425
|
-
})) found = true;
|
|
426
|
-
if (node.type === "atrule" && node.name === "config") {
|
|
427
|
-
const configPath = parseConfigRequest(node.params);
|
|
428
|
-
if (configPath && !config) {
|
|
429
|
-
configRequest = configPath;
|
|
430
|
-
config = isPackageJsonImportRequest(configPath) ? void 0 : path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
|
|
431
|
-
}
|
|
432
|
-
if (removeConfig) {
|
|
433
|
-
node.remove();
|
|
434
|
-
removedConfig = true;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
if (!found) return;
|
|
439
|
-
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
440
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
441
|
-
...options,
|
|
442
|
-
removeConfig
|
|
443
|
-
});
|
|
444
|
-
if (css) return {
|
|
445
|
-
css,
|
|
446
|
-
config,
|
|
447
|
-
configRequest,
|
|
448
|
-
base
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
return {
|
|
452
|
-
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
453
|
-
config,
|
|
454
|
-
configRequest,
|
|
455
|
-
base
|
|
456
|
-
};
|
|
457
|
-
} catch {
|
|
458
|
-
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
459
|
-
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
460
|
-
const config = configRequest && !isPackageJsonImportRequest(configRequest) ? path.isAbsolute(configRequest) ? configRequest : path.resolve(base, configRequest) : void 0;
|
|
461
|
-
return css ? {
|
|
462
|
-
css,
|
|
463
|
-
config,
|
|
464
|
-
configRequest,
|
|
465
|
-
base
|
|
466
|
-
} : void 0;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
//#endregion
|
|
470
10
|
//#region src/bundlers/shared/cache.ts
|
|
471
11
|
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
472
12
|
let cacheHit = false;
|
|
@@ -708,75 +248,112 @@ function removeDuplicatedViteMarkers(css, baseCss) {
|
|
|
708
248
|
return css.replace(VITE_MARKER_RE, "");
|
|
709
249
|
}
|
|
710
250
|
//#endregion
|
|
711
|
-
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
712
|
-
function quoteCssString(value) {
|
|
713
|
-
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
714
|
-
}
|
|
715
|
-
function toCssPath(value) {
|
|
716
|
-
return value.replaceAll("\\", "/");
|
|
717
|
-
}
|
|
718
|
-
function prependConfigDirective(css, config) {
|
|
719
|
-
if (!config || /@config\s+/.test(css)) return css;
|
|
720
|
-
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
721
|
-
}
|
|
722
|
-
function normalizeConfigDirective(css, config) {
|
|
723
|
-
if (!config || !/@config\s+/.test(css)) return css;
|
|
724
|
-
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
725
|
-
}
|
|
726
|
-
//#endregion
|
|
727
251
|
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
728
|
-
const SOURCE_STYLE_EXTENSIONS = [
|
|
729
|
-
".vue",
|
|
730
|
-
".uvue",
|
|
731
|
-
".nvue",
|
|
732
|
-
".css",
|
|
733
|
-
".scss",
|
|
734
|
-
".sass",
|
|
735
|
-
".less",
|
|
736
|
-
".styl",
|
|
737
|
-
".stylus",
|
|
738
|
-
".wxss",
|
|
739
|
-
".acss",
|
|
740
|
-
".jxss",
|
|
741
|
-
".ttss",
|
|
742
|
-
".qss"
|
|
743
|
-
];
|
|
744
252
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
745
253
|
function stripStyleExtension(file) {
|
|
746
|
-
|
|
254
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
255
|
+
const ext = path.extname(normalized);
|
|
256
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
747
257
|
}
|
|
748
|
-
function
|
|
749
|
-
|
|
258
|
+
function normalizeMatchPath$1(file) {
|
|
259
|
+
return file.split(path.sep).join("/");
|
|
260
|
+
}
|
|
261
|
+
function isPathWithinRoot$1(file, root) {
|
|
262
|
+
const relative = path.relative(root, file);
|
|
263
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
264
|
+
}
|
|
265
|
+
function countCommonSuffixSegments(a, b) {
|
|
266
|
+
const aSegments = a.split("/").filter(Boolean);
|
|
267
|
+
const bSegments = b.split("/").filter(Boolean);
|
|
268
|
+
let count = 0;
|
|
269
|
+
while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
|
|
270
|
+
return count;
|
|
271
|
+
}
|
|
272
|
+
function collectOutputMatchBases(file, sourceOptions) {
|
|
273
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
274
|
+
const roots = [
|
|
275
|
+
sourceOptions.outputRoot,
|
|
750
276
|
sourceOptions.projectRoot,
|
|
751
|
-
sourceOptions.cwd
|
|
752
|
-
process.cwd()
|
|
277
|
+
sourceOptions.cwd
|
|
753
278
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
754
|
-
const
|
|
755
|
-
const
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
for (const outputRoot of outputRoots) {
|
|
759
|
-
const relative = path.relative(outputRoot, absoluteFile);
|
|
760
|
-
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) continue;
|
|
761
|
-
relativeFiles.add(relative);
|
|
762
|
-
}
|
|
279
|
+
const bases = /* @__PURE__ */ new Set();
|
|
280
|
+
const addBase = (candidate) => {
|
|
281
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
282
|
+
if (stripped.length > 0) bases.add(stripped);
|
|
763
283
|
};
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
284
|
+
addBase(normalizedFile);
|
|
285
|
+
if (path.isAbsolute(normalizedFile)) for (const root of roots) {
|
|
286
|
+
const normalizedRoot = path.resolve(root);
|
|
287
|
+
if (isPathWithinRoot$1(normalizedFile, normalizedRoot)) addBase(path.relative(normalizedRoot, normalizedFile));
|
|
288
|
+
}
|
|
289
|
+
else for (const root of roots) addBase(path.resolve(root, normalizedFile));
|
|
290
|
+
return bases;
|
|
291
|
+
}
|
|
292
|
+
function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
293
|
+
const outputBases = collectOutputMatchBases(file, sourceOptions);
|
|
294
|
+
const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
295
|
+
const sourceBases = /* @__PURE__ */ new Set();
|
|
296
|
+
const addSourceBase = (candidate) => {
|
|
297
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
298
|
+
if (stripped.length > 0) sourceBases.add(stripped);
|
|
299
|
+
};
|
|
300
|
+
addSourceBase(normalizedSourceFile);
|
|
301
|
+
if (path.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
|
|
302
|
+
if (!root) continue;
|
|
303
|
+
const normalizedRoot = path.resolve(root);
|
|
304
|
+
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(path.relative(normalizedRoot, normalizedSourceFile));
|
|
779
305
|
}
|
|
306
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || countCommonSuffixSegments(outputBase, sourceBase) >= 2) return true;
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
310
|
+
const outputBases = collectOutputMatchBases(file, sourceOptions);
|
|
311
|
+
const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
312
|
+
const sourceBases = /* @__PURE__ */ new Set();
|
|
313
|
+
const addSourceBase = (candidate) => {
|
|
314
|
+
const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
|
|
315
|
+
if (stripped.length > 0) sourceBases.add(stripped);
|
|
316
|
+
};
|
|
317
|
+
addSourceBase(normalizedSourceFile);
|
|
318
|
+
if (path.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
|
|
319
|
+
if (!root) continue;
|
|
320
|
+
const normalizedRoot = path.resolve(root);
|
|
321
|
+
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(path.relative(normalizedRoot, normalizedSourceFile));
|
|
322
|
+
}
|
|
323
|
+
let bestScore = 0;
|
|
324
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) {
|
|
325
|
+
const commonSuffixSegments = countCommonSuffixSegments(outputBase, sourceBase);
|
|
326
|
+
if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
327
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
328
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
329
|
+
else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
|
|
330
|
+
}
|
|
331
|
+
return bestScore;
|
|
332
|
+
}
|
|
333
|
+
function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
|
|
334
|
+
const matches = [...(sourceOptions.cssSources ?? []).map((cssSource) => cssSource.file), ...sourceOptions.cssEntries ?? []].filter((sourceFile) => typeof sourceFile === "string" && path.isAbsolute(sourceFile)).map((sourceFile) => path.resolve(sourceFile.replace(/[?#].*$/, ""))).filter((sourceFile, index, files) => files.indexOf(sourceFile) === index).map((sourceFile) => ({
|
|
335
|
+
sourceFile,
|
|
336
|
+
score: scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions)
|
|
337
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
338
|
+
const bestScore = matches[0]?.score ?? 0;
|
|
339
|
+
return matches.filter((match) => match.score === bestScore).map((match) => match.sourceFile);
|
|
340
|
+
}
|
|
341
|
+
function hasConfiguredSourceFiles(sourceOptions) {
|
|
342
|
+
return Boolean(sourceOptions.cssEntries?.length) || Boolean(sourceOptions.cssSources?.some((cssSource) => typeof cssSource.file === "string" && cssSource.file.length > 0));
|
|
343
|
+
}
|
|
344
|
+
function createSourceStylePathCandidates(file, sourceOptions) {
|
|
345
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
346
|
+
const addCandidate = (candidate) => {
|
|
347
|
+
if (candidate && path.isAbsolute(candidate)) candidates.add(candidate.replace(/[?#].*$/, ""));
|
|
348
|
+
};
|
|
349
|
+
const matchedConfiguredSourceFiles = collectMatchedConfiguredSourceFiles(file, sourceOptions);
|
|
350
|
+
if (matchedConfiguredSourceFiles.length === 1) addCandidate(matchedConfiguredSourceFiles[0]);
|
|
351
|
+
else if (matchedConfiguredSourceFiles.length === 0) for (const cssSource of sourceOptions.cssSources ?? []) {
|
|
352
|
+
const sourceFile = cssSource.file;
|
|
353
|
+
if (typeof sourceFile === "string" && path.isAbsolute(sourceFile) && isMatchingSourceStyleFile(file, sourceFile, sourceOptions)) addCandidate(sourceFile);
|
|
354
|
+
}
|
|
355
|
+
if (hasConfiguredSourceFiles(sourceOptions)) return [...candidates];
|
|
356
|
+
if (!hasConfiguredSourceFiles(sourceOptions)) addCandidate(sourceOptions.sourceFile);
|
|
780
357
|
return [...candidates];
|
|
781
358
|
}
|
|
782
359
|
function extractStyleDirectiveSources(source) {
|
|
@@ -822,6 +399,24 @@ function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
|
822
399
|
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
823
400
|
return cssHandlerOptions.sourceOptions;
|
|
824
401
|
}
|
|
402
|
+
function createCssEntrySources(cssEntries) {
|
|
403
|
+
return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
|
|
404
|
+
}
|
|
405
|
+
function mergeCssSources(cssSources, cssEntrySources) {
|
|
406
|
+
const merged = [];
|
|
407
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
408
|
+
const addSource = (cssSource) => {
|
|
409
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.resolve(cssSource.file) : void 0;
|
|
410
|
+
if (file) {
|
|
411
|
+
if (seenFiles.has(file)) return;
|
|
412
|
+
seenFiles.add(file);
|
|
413
|
+
}
|
|
414
|
+
merged.push(cssSource);
|
|
415
|
+
};
|
|
416
|
+
for (const cssSource of cssSources ?? []) addSource(cssSource);
|
|
417
|
+
for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
|
|
418
|
+
return merged.length > 0 ? merged : void 0;
|
|
419
|
+
}
|
|
825
420
|
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
826
421
|
return omitUndefined({
|
|
827
422
|
projectRoot: sourceOptions.projectRoot,
|
|
@@ -831,6 +426,27 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
|
831
426
|
css: options.css
|
|
832
427
|
});
|
|
833
428
|
}
|
|
429
|
+
async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
430
|
+
const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
|
|
431
|
+
if (!existsSync(cssEntry)) return resolveTailwindV4Source$1({
|
|
432
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
433
|
+
cssEntries: [cssEntry]
|
|
434
|
+
});
|
|
435
|
+
const css = readFileSync(cssEntry, "utf8");
|
|
436
|
+
const base = path.dirname(path.resolve(cssEntry));
|
|
437
|
+
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
438
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, sourceOptions);
|
|
439
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
440
|
+
...omitUndefined(singleEntrySourceOptions),
|
|
441
|
+
base,
|
|
442
|
+
css: normalizeConfigDirective(css, config),
|
|
443
|
+
cssEntries: [cssEntry]
|
|
444
|
+
}), {
|
|
445
|
+
matchedCssSourceFile: cssEntry,
|
|
446
|
+
sourceBase: base,
|
|
447
|
+
sourceCss: css
|
|
448
|
+
});
|
|
449
|
+
}
|
|
834
450
|
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
835
451
|
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
836
452
|
return path.dirname(path.resolve(normalized));
|
|
@@ -840,24 +456,30 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
840
456
|
if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
|
|
841
457
|
const outputDir = path.dirname(file.replace(/[?#].*$/, ""));
|
|
842
458
|
const baseCandidates = [
|
|
459
|
+
sourceOptions.sourceFile ? path.dirname(sourceOptions.sourceFile.replace(/[?#].*$/, "")) : void 0,
|
|
460
|
+
path.isAbsolute(outputDir) ? outputDir : void 0,
|
|
843
461
|
sourceOptions.projectRoot,
|
|
844
|
-
sourceOptions.cwd
|
|
845
|
-
process.cwd()
|
|
462
|
+
sourceOptions.cwd
|
|
846
463
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
464
|
+
const seenCandidates = /* @__PURE__ */ new Set();
|
|
465
|
+
const configCandidates = [];
|
|
466
|
+
const addConfigCandidate = (candidate) => {
|
|
467
|
+
if (!candidate) return;
|
|
468
|
+
const normalized = path.resolve(candidate);
|
|
469
|
+
if (seenCandidates.has(normalized)) return;
|
|
470
|
+
seenCandidates.add(normalized);
|
|
471
|
+
configCandidates.push(normalized);
|
|
472
|
+
};
|
|
847
473
|
for (const base of baseCandidates) {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
path.resolve(base, "src", configRequest),
|
|
851
|
-
path.resolve(base, outputDir, configRequest),
|
|
852
|
-
path.resolve(base, "src", outputDir, configRequest)
|
|
853
|
-
];
|
|
854
|
-
for (const candidate of candidates) if (existsSync(candidate)) return candidate;
|
|
474
|
+
addConfigCandidate(path.resolve(base, configRequest));
|
|
475
|
+
if (!path.isAbsolute(outputDir)) addConfigCandidate(path.resolve(base, outputDir, configRequest));
|
|
855
476
|
}
|
|
477
|
+
for (const candidate of configCandidates) if (existsSync(candidate)) return candidate;
|
|
856
478
|
return sourceOptions.config;
|
|
857
479
|
}
|
|
858
|
-
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
480
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
859
481
|
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
860
|
-
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file);
|
|
482
|
+
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
|
|
861
483
|
return true;
|
|
862
484
|
}
|
|
863
485
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
@@ -866,6 +488,9 @@ function shouldResolveSourceSideCssEntry(rawSource) {
|
|
|
866
488
|
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
867
489
|
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
868
490
|
}
|
|
491
|
+
function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
|
|
492
|
+
return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !existsSync(cssEntrySource.config));
|
|
493
|
+
}
|
|
869
494
|
function normalizeCssSourceForCompare(css) {
|
|
870
495
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
871
496
|
}
|
|
@@ -881,38 +506,119 @@ function getOutputFileWithoutExtension(file) {
|
|
|
881
506
|
function normalizeMatchPath(file) {
|
|
882
507
|
return file.split(path.sep).join("/");
|
|
883
508
|
}
|
|
884
|
-
function
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
509
|
+
function isPathWithinRoot(file, root) {
|
|
510
|
+
const relative = path.relative(root, file);
|
|
511
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
512
|
+
}
|
|
513
|
+
function collectCssSourceMatchBases(file, roots) {
|
|
514
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
515
|
+
const bases = /* @__PURE__ */ new Set();
|
|
516
|
+
const addBase = (candidate) => {
|
|
517
|
+
const base = normalizeMatchPath(getOutputFileWithoutExtension(candidate));
|
|
518
|
+
if (base.length > 0) {
|
|
519
|
+
bases.add(base);
|
|
520
|
+
const withoutWorkspaceSegment = base.replace(/^(?:src|dist)\//, "");
|
|
521
|
+
if (withoutWorkspaceSegment !== base && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
addBase(normalizedFile);
|
|
525
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
526
|
+
if (path.isAbsolute(normalizedFile)) {
|
|
527
|
+
for (const root of resolvedRoots) if (isPathWithinRoot(normalizedFile, root)) addBase(path.relative(root, normalizedFile));
|
|
528
|
+
} else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
529
|
+
return bases;
|
|
530
|
+
}
|
|
531
|
+
function hasMatchingCssSourceBase(outputBases, sourceBases) {
|
|
532
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
|
|
536
|
+
return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
|
|
537
|
+
sourceOptions.outputRoot,
|
|
538
|
+
sourceOptions.projectRoot,
|
|
539
|
+
sourceOptions.cwd
|
|
540
|
+
]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
|
|
889
541
|
}
|
|
890
|
-
function
|
|
891
|
-
const
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
542
|
+
function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
543
|
+
const outputBases = collectCssSourceMatchBases(file, [
|
|
544
|
+
sourceOptions.outputRoot,
|
|
545
|
+
sourceOptions.projectRoot,
|
|
546
|
+
sourceOptions.cwd
|
|
547
|
+
]);
|
|
548
|
+
const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
|
|
549
|
+
let bestScore = 0;
|
|
550
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
551
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
552
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
553
|
+
return bestScore;
|
|
896
554
|
}
|
|
897
555
|
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
898
556
|
const cssEntries = sourceOptions.cssEntries;
|
|
899
557
|
if (!cssEntries?.length) return;
|
|
900
558
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
901
559
|
const outputStem = getOutputFileStem(file);
|
|
902
|
-
const
|
|
903
|
-
if (!existsSync(cssEntry)) return
|
|
560
|
+
const matches = cssEntries.map((cssEntry) => {
|
|
561
|
+
if (!existsSync(cssEntry)) return;
|
|
904
562
|
try {
|
|
905
|
-
|
|
906
|
-
|
|
563
|
+
const entrySource = readFileSync(cssEntry, "utf8");
|
|
564
|
+
const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssEntry, sourceOptions);
|
|
565
|
+
if (normalizeCssSourceForCompare(entrySource) === normalizedRawSource) return {
|
|
566
|
+
cssEntry,
|
|
567
|
+
score: 1e6 + pathScore
|
|
568
|
+
};
|
|
569
|
+
if (pathScore > 0) return {
|
|
570
|
+
cssEntry,
|
|
571
|
+
score: pathScore
|
|
572
|
+
};
|
|
573
|
+
if (cssEntries.length === 1 && outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem) return {
|
|
574
|
+
cssEntry,
|
|
575
|
+
score: 1
|
|
576
|
+
};
|
|
577
|
+
return;
|
|
907
578
|
} catch {
|
|
908
|
-
return
|
|
579
|
+
return;
|
|
909
580
|
}
|
|
910
|
-
});
|
|
581
|
+
}).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score);
|
|
582
|
+
const bestScore = matches[0]?.score;
|
|
583
|
+
const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
|
|
911
584
|
if (!matchingEntry) return;
|
|
912
|
-
return
|
|
913
|
-
|
|
914
|
-
|
|
585
|
+
return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions);
|
|
586
|
+
}
|
|
587
|
+
function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
|
|
588
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
|
|
589
|
+
const entrySource = resolveCssEntrySource(cssSource.css, sourceBase, { removeConfig: false });
|
|
590
|
+
if (!entrySource?.config) return cssSource;
|
|
591
|
+
return {
|
|
592
|
+
...cssSource,
|
|
593
|
+
css: normalizeConfigDirective(cssSource.css, entrySource.config)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function hydrateTailwindV4CssSource(cssSource) {
|
|
597
|
+
if (typeof cssSource.css === "string" && cssSource.css.length > 0) return cssSource;
|
|
598
|
+
if (typeof cssSource.file !== "string" || !existsSync(cssSource.file)) return cssSource;
|
|
599
|
+
const file = path.resolve(cssSource.file);
|
|
600
|
+
return {
|
|
601
|
+
...cssSource,
|
|
602
|
+
file,
|
|
603
|
+
base: cssSource.base ?? path.dirname(file),
|
|
604
|
+
css: readFileSync(file, "utf8"),
|
|
605
|
+
dependencies: [...new Set([...cssSource.dependencies ?? [], file])]
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
|
|
609
|
+
if (!sourceOptions.cssSources?.length) return sourceOptions;
|
|
610
|
+
const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd();
|
|
611
|
+
let changed = false;
|
|
612
|
+
const cssSources = sourceOptions.cssSources.map((cssSource) => {
|
|
613
|
+
const hydratedCssSource = hydrateTailwindV4CssSource(cssSource);
|
|
614
|
+
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(hydratedCssSource, resolveTailwindV4CssSourceBase(hydratedCssSource, sourceBaseFallback));
|
|
615
|
+
changed || (changed = normalizedCssSource !== cssSource);
|
|
616
|
+
return normalizedCssSource;
|
|
915
617
|
});
|
|
618
|
+
return changed ? {
|
|
619
|
+
...sourceOptions,
|
|
620
|
+
cssSources
|
|
621
|
+
} : sourceOptions;
|
|
916
622
|
}
|
|
917
623
|
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
|
|
918
624
|
const cssSources = sourceOptions.cssSources;
|
|
@@ -922,11 +628,11 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
922
628
|
const matchingSource = cssSources.find((cssSource) => {
|
|
923
629
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
|
|
924
630
|
if (sourceFile && typeof cssSource.file === "string" && path.resolve(sourceFile) === path.resolve(cssSource.file)) return true;
|
|
925
|
-
if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file)) return true;
|
|
631
|
+
if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file, sourceOptions)) return true;
|
|
926
632
|
return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
|
|
927
633
|
});
|
|
928
634
|
if (!matchingSource) return;
|
|
929
|
-
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions);
|
|
635
|
+
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
|
|
930
636
|
}
|
|
931
637
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
932
638
|
try {
|
|
@@ -938,16 +644,16 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
938
644
|
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
939
645
|
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
940
646
|
}
|
|
941
|
-
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions) {
|
|
942
|
-
const
|
|
647
|
+
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
|
|
648
|
+
const sourceBase = resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
|
|
649
|
+
const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
|
|
650
|
+
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
943
651
|
...omitUndefined(sourceOptions),
|
|
944
|
-
cssSources: [
|
|
945
|
-
})
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
sourceBase: resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback),
|
|
950
|
-
sourceCss: cssSource.css
|
|
652
|
+
cssSources: [normalizedCssSource]
|
|
653
|
+
}), {
|
|
654
|
+
matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
|
|
655
|
+
sourceBase,
|
|
656
|
+
sourceCss: normalizedCssSource.css
|
|
951
657
|
});
|
|
952
658
|
}
|
|
953
659
|
async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
|
|
@@ -961,10 +667,10 @@ function countRuntimeCandidateHits(candidates, runtime) {
|
|
|
961
667
|
for (const candidate of candidates) if (runtime.has(candidate)) hits += 1;
|
|
962
668
|
return hits;
|
|
963
669
|
}
|
|
964
|
-
async function resolveCandidateMatchedTailwindV4CssSource(_rawSource,
|
|
670
|
+
async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandlerOptions, sourceOptions, selectionOptions) {
|
|
965
671
|
const cssSources = sourceOptions.cssSources;
|
|
966
672
|
const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
|
|
967
|
-
if (!
|
|
673
|
+
if (!cssSources?.length || !getSourceCandidatesForEntries) return;
|
|
968
674
|
const matches = [];
|
|
969
675
|
await Promise.all(cssSources.map(async (cssSource, index) => {
|
|
970
676
|
const resolved = await resolveTailwindV4CssSourceEntries(cssSource, sourceOptions);
|
|
@@ -985,13 +691,10 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandler
|
|
|
985
691
|
const second = matches[1];
|
|
986
692
|
if (!best) return;
|
|
987
693
|
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
988
|
-
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions);
|
|
694
|
+
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, { matched: true });
|
|
989
695
|
}
|
|
990
696
|
function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
991
|
-
return (cssSource) =>
|
|
992
|
-
...omitUndefined(sourceOptions),
|
|
993
|
-
cssSources: [cssSource]
|
|
994
|
-
}).then((source) => generatorOptions?.config ? {
|
|
697
|
+
return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
|
|
995
698
|
...source,
|
|
996
699
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
997
700
|
} : source);
|
|
@@ -1012,6 +715,15 @@ function withGeneratorSourceMetadata(source, metadata) {
|
|
|
1012
715
|
__weappTailwindcssMeta: metadata
|
|
1013
716
|
};
|
|
1014
717
|
}
|
|
718
|
+
function resolveTailwindV3SourceEntries(source) {
|
|
719
|
+
if (!("version" in source) || source.version !== 3) return;
|
|
720
|
+
const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? path.dirname(source.config) : source.cwd });
|
|
721
|
+
return entries.length > 0 ? entries : void 0;
|
|
722
|
+
}
|
|
723
|
+
function withTailwindV3SourceMetadata(source) {
|
|
724
|
+
const sourceEntries = resolveTailwindV3SourceEntries(source);
|
|
725
|
+
return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
|
|
726
|
+
}
|
|
1015
727
|
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
1016
728
|
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
1017
729
|
matchedCssSourceFile: resolvedEntrySource.file,
|
|
@@ -1034,43 +746,52 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1034
746
|
const mergedSourceOptions = omitUndefined({
|
|
1035
747
|
...sourceOptions,
|
|
1036
748
|
config: generatorOptions?.config ?? sourceOptions.config,
|
|
1037
|
-
|
|
749
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
750
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
751
|
+
cssEntries: selectionOptions?.cssEntries,
|
|
752
|
+
cssSources: createCssEntrySources(selectionOptions?.cssEntries)
|
|
1038
753
|
});
|
|
1039
754
|
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
1040
755
|
base,
|
|
1041
756
|
css: rawSource
|
|
1042
757
|
} : void 0;
|
|
1043
|
-
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
if (
|
|
758
|
+
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
759
|
+
const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
|
|
760
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
761
|
+
if (!resolvedEntrySource) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
762
|
+
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
|
|
1047
763
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined(mergedSourceOptions));
|
|
1048
|
-
|
|
764
|
+
const sourceWithMetadata = withTailwindV3SourceMetadata(await resolveTailwindV3Source({
|
|
1049
765
|
...mergedSourceOptions,
|
|
1050
766
|
base: resolvedEntrySource.base,
|
|
1051
767
|
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
1052
768
|
...config ? { config } : {}
|
|
769
|
+
}));
|
|
770
|
+
return withGeneratorSourceMetadata(sourceWithMetadata, {
|
|
771
|
+
...sourceWithMetadata.__weappTailwindcssMeta,
|
|
772
|
+
matchedCssSourceFile: resolvedEntrySource.file
|
|
1053
773
|
});
|
|
1054
774
|
}
|
|
1055
775
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
1056
776
|
const resolvedSourceOptions = sourceOptions ? omitUndefined({
|
|
1057
777
|
...sourceOptions,
|
|
1058
|
-
|
|
778
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
779
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
780
|
+
cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
|
|
781
|
+
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
1059
782
|
}) : void 0;
|
|
1060
|
-
const
|
|
1061
|
-
const
|
|
1062
|
-
const
|
|
1063
|
-
const
|
|
1064
|
-
const
|
|
783
|
+
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
784
|
+
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
785
|
+
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
786
|
+
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
787
|
+
const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
|
|
788
|
+
const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
|
|
789
|
+
const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await resolveTailwindV4Source$1(normalizedSourceOptions) : void 0;
|
|
1065
790
|
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1066
791
|
...configuredCssSource,
|
|
1067
792
|
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1068
793
|
} : configuredCssSource;
|
|
1069
|
-
const
|
|
1070
|
-
const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4Source$1({
|
|
1071
|
-
...omitUndefined(sourceOptions),
|
|
1072
|
-
cssEntries: [sourceOptions.cssEntries[0]]
|
|
1073
|
-
}) : void 0;
|
|
794
|
+
const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
|
|
1074
795
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
1075
796
|
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1076
797
|
...preferredCssEntrySource,
|
|
@@ -1084,11 +805,12 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1084
805
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1085
806
|
} : source;
|
|
1086
807
|
}
|
|
1087
|
-
if (sourceSideEntrySource &&
|
|
808
|
+
if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
|
|
1088
809
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
|
|
810
|
+
const sourceBase = resolvedEntrySource === cssEntrySource && config ? path.dirname(config) : resolvedEntrySource.base;
|
|
811
|
+
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
|
|
812
|
+
return resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
|
|
813
|
+
base: sourceBase,
|
|
1092
814
|
css
|
|
1093
815
|
}));
|
|
1094
816
|
}
|
|
@@ -1103,18 +825,23 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1103
825
|
}
|
|
1104
826
|
let sourceOptions;
|
|
1105
827
|
try {
|
|
828
|
+
const sourceOptionsFromPatcher = resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
829
|
+
const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromPatcher.cssEntries;
|
|
1106
830
|
sourceOptions = omitUndefined({
|
|
1107
|
-
...
|
|
1108
|
-
|
|
831
|
+
...sourceOptionsFromPatcher,
|
|
832
|
+
sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
|
|
833
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions),
|
|
834
|
+
cssEntries,
|
|
835
|
+
cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
|
|
1109
836
|
});
|
|
1110
837
|
} catch {
|
|
1111
838
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1112
839
|
return resolved ? [resolved] : [];
|
|
1113
840
|
}
|
|
1114
|
-
const matchedCssEntrySource =
|
|
841
|
+
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1115
842
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1116
843
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1117
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
844
|
+
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);
|
|
1118
845
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1119
846
|
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1120
847
|
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
@@ -1122,14 +849,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1122
849
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1123
850
|
} : preferredCssEntrySource];
|
|
1124
851
|
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
852
|
+
if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
|
|
853
|
+
...source,
|
|
854
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
855
|
+
} : source)];
|
|
1125
856
|
if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
|
|
1126
857
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1127
858
|
return resolved ? [resolved] : [];
|
|
1128
859
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
}
|
|
860
|
+
if (cssHandlerOptions.isMainChunk && !cssEntrySource && !hasTailwindGeneratedCss(rawSource) && !hasTailwindGeneratedCssMarkers(rawSource) && !hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
|
|
861
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
862
|
+
return resolved ? [resolved] : [];
|
|
863
|
+
}
|
|
864
|
+
const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
|
|
865
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
|
|
1133
866
|
...source,
|
|
1134
867
|
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1135
868
|
} : source)));
|
|
@@ -1137,8 +870,9 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
1137
870
|
return [...cssEntrySources, ...cssSources];
|
|
1138
871
|
}
|
|
1139
872
|
async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
1140
|
-
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
1141
873
|
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
874
|
+
if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
|
|
875
|
+
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
1142
876
|
const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
1143
877
|
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
1144
878
|
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
@@ -1521,15 +1255,17 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
1521
1255
|
if (target !== "weapp") return css;
|
|
1522
1256
|
return finalizeMiniProgramCss(css, {
|
|
1523
1257
|
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
1258
|
+
isTailwindcssV4: majorVersion === 4,
|
|
1524
1259
|
preservePseudoContentInit: majorVersion === 3
|
|
1525
1260
|
});
|
|
1526
1261
|
}
|
|
1527
1262
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1528
|
-
if (
|
|
1263
|
+
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
1264
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
1529
1265
|
return new Set([...scopedRuntime, ...runtime]);
|
|
1530
1266
|
}
|
|
1531
|
-
function
|
|
1532
|
-
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile
|
|
1267
|
+
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
1268
|
+
return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
|
|
1533
1269
|
}
|
|
1534
1270
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
1535
1271
|
if (majorVersion !== 4 || isolateCssSource) return false;
|
|
@@ -1764,22 +1500,30 @@ async function generateCssByGenerator(options) {
|
|
|
1764
1500
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1765
1501
|
try {
|
|
1766
1502
|
await runtimeState.readyPromise;
|
|
1767
|
-
const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(effectiveRawSource, "css", { bareArbitraryValues: generatorOptions.bareArbitraryValues }) : [];
|
|
1503
|
+
const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
1768
1504
|
const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
1769
1505
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1506
|
+
cssEntries: opts.cssEntries,
|
|
1770
1507
|
getSourceCandidatesForEntries,
|
|
1771
1508
|
runtime: runtimeWithCurrentCss
|
|
1772
1509
|
});
|
|
1773
1510
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1774
1511
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1775
|
-
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
1512
|
+
const generatedResults = (await Promise.all(sources.map(async (source) => {
|
|
1776
1513
|
const generator = createWeappTailwindcssGenerator(source);
|
|
1777
|
-
const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
1514
|
+
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
1778
1515
|
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
1779
|
-
const isolateCssSource =
|
|
1516
|
+
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
|
|
1517
|
+
const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1518
|
+
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
1519
|
+
debug("defer empty scoped css source generation: %s", file);
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1780
1522
|
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1523
|
+
currentCssCandidates,
|
|
1781
1524
|
cssHandlerOptions,
|
|
1782
|
-
isolateCssSource
|
|
1525
|
+
isolateCssSource,
|
|
1526
|
+
matchedCssSourceFile
|
|
1783
1527
|
}) : runtimeWithCurrentCss;
|
|
1784
1528
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1785
1529
|
return generator.generate({
|
|
@@ -1791,7 +1535,7 @@ async function generateCssByGenerator(options) {
|
|
|
1791
1535
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1792
1536
|
target: generatorOptions.target
|
|
1793
1537
|
});
|
|
1794
|
-
}));
|
|
1538
|
+
}))).filter((item) => Boolean(item));
|
|
1795
1539
|
const firstGenerated = generatedResults[0];
|
|
1796
1540
|
if (!firstGenerated) return;
|
|
1797
1541
|
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
@@ -1819,6 +1563,7 @@ async function generateCssByGenerator(options) {
|
|
|
1819
1563
|
}
|
|
1820
1564
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1821
1565
|
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
|
|
1566
|
+
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1822
1567
|
if (orderedExtraCss) {
|
|
1823
1568
|
let css = stripTailwindBanner(generated.css);
|
|
1824
1569
|
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
@@ -1844,11 +1589,11 @@ async function generateCssByGenerator(options) {
|
|
|
1844
1589
|
const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
|
|
1845
1590
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1846
1591
|
}
|
|
1847
|
-
if (generated.target === "weapp") {
|
|
1592
|
+
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
1848
1593
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1849
1594
|
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1850
1595
|
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1851
|
-
}
|
|
1596
|
+
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1852
1597
|
return {
|
|
1853
1598
|
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
|
|
1854
1599
|
target: generated.target,
|
|
@@ -1880,6 +1625,17 @@ async function generateCssByGenerator(options) {
|
|
|
1880
1625
|
}
|
|
1881
1626
|
}
|
|
1882
1627
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1628
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
1629
|
+
const userCss = await transformGeneratorUserCss(effectiveRawSource, {
|
|
1630
|
+
generatorTarget: generated.target,
|
|
1631
|
+
generatorStyleOptions,
|
|
1632
|
+
cssUserHandlerOptions,
|
|
1633
|
+
styleHandler,
|
|
1634
|
+
importFallback: generatorOptions.importFallback
|
|
1635
|
+
});
|
|
1636
|
+
css = createCssSourceOrderAppend(css, userCss);
|
|
1637
|
+
}
|
|
1638
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1883
1639
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1884
1640
|
hasSourceDirectives,
|
|
1885
1641
|
hasMatchedCssSourceFile
|
|
@@ -1921,7 +1677,10 @@ async function validateCandidatesByGenerator(options) {
|
|
|
1921
1677
|
...normalizeWeappTailwindcssGeneratorOptions(opts.generator),
|
|
1922
1678
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
|
|
1923
1679
|
};
|
|
1924
|
-
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1680
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1681
|
+
cssEntries: opts.cssEntries,
|
|
1682
|
+
runtime: candidates
|
|
1683
|
+
});
|
|
1925
1684
|
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1926
1685
|
const generator = createWeappTailwindcssGenerator(source);
|
|
1927
1686
|
if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
|
|
@@ -2103,8 +1862,126 @@ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
|
|
|
2103
1862
|
for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
|
|
2104
1863
|
return nextBaseClassSet;
|
|
2105
1864
|
}
|
|
1865
|
+
function isUrlLikeCandidate(candidate) {
|
|
1866
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
1867
|
+
}
|
|
1868
|
+
const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
|
|
1869
|
+
"accent",
|
|
1870
|
+
"animate",
|
|
1871
|
+
"basis",
|
|
1872
|
+
"bg",
|
|
1873
|
+
"blur",
|
|
1874
|
+
"border",
|
|
1875
|
+
"bottom",
|
|
1876
|
+
"brightness",
|
|
1877
|
+
"caret",
|
|
1878
|
+
"col",
|
|
1879
|
+
"columns",
|
|
1880
|
+
"content",
|
|
1881
|
+
"contrast",
|
|
1882
|
+
"decoration",
|
|
1883
|
+
"delay",
|
|
1884
|
+
"divide",
|
|
1885
|
+
"drop-shadow",
|
|
1886
|
+
"duration",
|
|
1887
|
+
"ease",
|
|
1888
|
+
"fill",
|
|
1889
|
+
"font",
|
|
1890
|
+
"gap",
|
|
1891
|
+
"gradient",
|
|
1892
|
+
"grid",
|
|
1893
|
+
"grayscale",
|
|
1894
|
+
"grow",
|
|
1895
|
+
"h",
|
|
1896
|
+
"hue-rotate",
|
|
1897
|
+
"indent",
|
|
1898
|
+
"inset",
|
|
1899
|
+
"invert",
|
|
1900
|
+
"leading",
|
|
1901
|
+
"left",
|
|
1902
|
+
"list",
|
|
1903
|
+
"m",
|
|
1904
|
+
"max",
|
|
1905
|
+
"mb",
|
|
1906
|
+
"min",
|
|
1907
|
+
"ml",
|
|
1908
|
+
"mr",
|
|
1909
|
+
"mt",
|
|
1910
|
+
"mx",
|
|
1911
|
+
"my",
|
|
1912
|
+
"object",
|
|
1913
|
+
"opacity",
|
|
1914
|
+
"order",
|
|
1915
|
+
"outline",
|
|
1916
|
+
"overflow",
|
|
1917
|
+
"p",
|
|
1918
|
+
"pb",
|
|
1919
|
+
"pl",
|
|
1920
|
+
"pr",
|
|
1921
|
+
"pt",
|
|
1922
|
+
"px",
|
|
1923
|
+
"py",
|
|
1924
|
+
"right",
|
|
1925
|
+
"ring",
|
|
1926
|
+
"rotate",
|
|
1927
|
+
"rounded",
|
|
1928
|
+
"row",
|
|
1929
|
+
"saturate",
|
|
1930
|
+
"scale",
|
|
1931
|
+
"scroll",
|
|
1932
|
+
"sepia",
|
|
1933
|
+
"shadow",
|
|
1934
|
+
"shrink",
|
|
1935
|
+
"skew",
|
|
1936
|
+
"space",
|
|
1937
|
+
"stroke",
|
|
1938
|
+
"text",
|
|
1939
|
+
"top",
|
|
1940
|
+
"tracking",
|
|
1941
|
+
"translate",
|
|
1942
|
+
"underline",
|
|
1943
|
+
"w",
|
|
1944
|
+
"z"
|
|
1945
|
+
]);
|
|
1946
|
+
function getBaseUtilityCandidate(candidate) {
|
|
1947
|
+
let bracketDepth = 0;
|
|
1948
|
+
let lastVariantSeparator = -1;
|
|
1949
|
+
for (let index = 0; index < candidate.length; index++) {
|
|
1950
|
+
const char = candidate[index];
|
|
1951
|
+
if (char === "[") bracketDepth += 1;
|
|
1952
|
+
else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
1953
|
+
else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
|
|
1954
|
+
}
|
|
1955
|
+
let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
|
|
1956
|
+
if (utility.startsWith("!")) utility = utility.slice(1);
|
|
1957
|
+
if (utility.startsWith("-")) utility = utility.slice(1);
|
|
1958
|
+
return utility;
|
|
1959
|
+
}
|
|
1960
|
+
function getArbitraryUtilityPrefix(utility) {
|
|
1961
|
+
const bracketIndex = utility.indexOf("[");
|
|
1962
|
+
if (bracketIndex <= 0 || !utility.endsWith("]")) return;
|
|
1963
|
+
const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
|
|
1964
|
+
const firstDash = prefix.indexOf("-");
|
|
1965
|
+
return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
|
|
1966
|
+
}
|
|
1967
|
+
function isLikelyTailwindV3ArbitraryUtility(candidate) {
|
|
1968
|
+
const utility = getBaseUtilityCandidate(candidate);
|
|
1969
|
+
if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
|
|
1970
|
+
const prefix = getArbitraryUtilityPrefix(utility);
|
|
1971
|
+
return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
|
|
1972
|
+
}
|
|
1973
|
+
function isLikelyTailwindV3VariantUtility(candidate) {
|
|
1974
|
+
if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
|
|
1975
|
+
const utility = getBaseUtilityCandidate(candidate);
|
|
1976
|
+
return /^[!-]?[a-z@[]/.test(utility);
|
|
1977
|
+
}
|
|
1978
|
+
function isLikelyTailwindV3OpacityModifier(candidate) {
|
|
1979
|
+
if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
|
|
1980
|
+
const utility = getBaseUtilityCandidate(candidate);
|
|
1981
|
+
return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
|
|
1982
|
+
}
|
|
2106
1983
|
function isHighConfidenceV3Candidate(candidate) {
|
|
2107
|
-
return candidate
|
|
1984
|
+
return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
|
|
2108
1985
|
}
|
|
2109
1986
|
function isRawCandidateInClassContext(source, start, extension) {
|
|
2110
1987
|
if (typeof start !== "number" || start <= 0) return false;
|
|
@@ -2149,7 +2026,7 @@ function createHighConfidenceLiteralRanges(source, matches) {
|
|
|
2149
2026
|
for (const match of matches) {
|
|
2150
2027
|
const candidate = match?.rawCandidate;
|
|
2151
2028
|
if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
|
|
2152
|
-
const range = resolveQuotedLiteralRange(source, match.start);
|
|
2029
|
+
const range = resolveQuotedLiteralRange(source, match.start ?? source.indexOf(candidate));
|
|
2153
2030
|
if (range) ranges.push(range);
|
|
2154
2031
|
}
|
|
2155
2032
|
return ranges;
|
|
@@ -2240,7 +2117,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2240
2117
|
const nextBaseClassSet = options.baseClassSet;
|
|
2241
2118
|
const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
|
|
2242
2119
|
for (const [file, previousCandidates] of candidatesByFile) {
|
|
2243
|
-
if (currentRuntimeFiles.has(file)) continue;
|
|
2120
|
+
if (currentRuntimeFiles.has(file) || snapshot.hasOmittedKnownFiles) continue;
|
|
2244
2121
|
removeCandidateSet(candidateCountByClass, previousCandidates);
|
|
2245
2122
|
candidatesByFile.delete(file);
|
|
2246
2123
|
}
|
|
@@ -2288,4 +2165,4 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
2288
2165
|
};
|
|
2289
2166
|
}
|
|
2290
2167
|
//#endregion
|
|
2291
|
-
export { validateCandidatesByGenerator as a,
|
|
2168
|
+
export { validateCandidatesByGenerator as a, generateCssByGenerator as i, createHmrTimingRecorder as n, mergeMarkedUserLayerComponentsCss as o, emitHmrTiming as r, processCachedTask as s, createBundleRuntimeClassSetManager as t };
|