weapp-tailwindcss 5.0.1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{bundle-state-CBF5YX1m.js → bundle-state-Bvj01pW7.js} +35 -3
  2. package/dist/{bundle-state-CQmxxx0R.mjs → bundle-state-DY3eq4Gz.mjs} +24 -4
  3. package/dist/bundlers/shared/generated-css-marker.d.ts +6 -0
  4. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
  5. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -5
  6. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css.d.ts +1 -0
  8. package/dist/bundlers/vite/bundle-state.d.ts +5 -1
  9. package/dist/bundlers/vite/css-finalizer.d.ts +12 -3
  10. package/dist/bundlers/vite/generate-bundle.d.ts +22 -6
  11. package/dist/bundlers/vite/processed-css-assets.d.ts +10 -2
  12. package/dist/bundlers/vite/source-candidates.d.ts +2 -0
  13. package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +8 -0
  14. package/dist/cli.js +1 -0
  15. package/dist/cli.mjs +1 -0
  16. package/dist/core.js +1 -1
  17. package/dist/core.mjs +1 -1
  18. package/dist/{generator-CvmsIQFI.js → generator-Bd1LntD3.js} +1 -1
  19. package/dist/{generator-DDtsUvkH.mjs → generator-DRHWC1t-.mjs} +1 -1
  20. package/dist/generator.js +2 -2
  21. package/dist/generator.mjs +2 -2
  22. package/dist/gulp.js +16 -10
  23. package/dist/gulp.mjs +14 -8
  24. package/dist/{incremental-runtime-class-set-BffodqHh.js → incremental-runtime-class-set-Bl18sFqt.js} +540 -694
  25. package/dist/{incremental-runtime-class-set-DArodvWs.mjs → incremental-runtime-class-set-CAEuUesH.mjs} +495 -619
  26. package/dist/index.js +4 -4
  27. package/dist/index.mjs +4 -4
  28. package/dist/{postcss-BzNYQUOH.mjs → postcss-CJrmfXvi.mjs} +4 -4
  29. package/dist/{postcss-DE0TOtV9.js → postcss-DfnqZ4Bm.js} +4 -4
  30. package/dist/postcss.js +1 -1
  31. package/dist/postcss.mjs +1 -1
  32. package/dist/{precheck-BzYPm-EG.js → precheck-Bj5ReSOU.js} +2 -2
  33. package/dist/{precheck-jZvTVXXG.mjs → precheck-CUr1DYyy.mjs} +2 -2
  34. package/dist/presets.js +2 -2
  35. package/dist/presets.mjs +2 -2
  36. package/dist/{source-candidates-BuTlMabx.mjs → source-candidates-D7b-Jzsx.mjs} +44 -11
  37. package/dist/{source-candidates-CxoIaS88.js → source-candidates-DQxvGPSw.js} +49 -10
  38. package/dist/tailwindcss/source-scan.d.ts +3 -1
  39. package/dist/{tailwindcss-CCZcu0lr.mjs → tailwindcss-D5RogwtV.mjs} +2 -2
  40. package/dist/{tailwindcss-DZckITp1.js → tailwindcss-jvoYizzX.js} +7 -1
  41. package/dist/{v3-engine-DGBhUnjn.mjs → v3-engine-BCUGX3gX.mjs} +637 -31
  42. package/dist/{v3-engine-M6Aqru5T.js → v3-engine-CmIF_gsq.js} +768 -30
  43. package/dist/{vite-DgRkWVPG.js → vite-D1ZdgbWa.js} +533 -290
  44. package/dist/{vite-BBcQIJpD.mjs → vite-jBTi5CwO.mjs} +532 -289
  45. package/dist/vite.js +1 -1
  46. package/dist/vite.mjs +1 -1
  47. package/dist/{runtime-registry-DpcR3IHI.js → watch-dependencies-zwx4EhBn.js} +39 -0
  48. package/dist/weapp-tw-css-import-rewrite-loader.js +1932 -1621
  49. package/dist/weapp-tw-runtime-classset-loader.js +6 -6
  50. package/dist/{webpack-D43aMQzO.mjs → webpack-CChDqRrl.mjs} +6 -6
  51. package/dist/{webpack-D-gb4ZvO.js → webpack-vk2uqSnK.js} +7 -7
  52. package/dist/webpack.js +1 -1
  53. package/dist/webpack.mjs +1 -1
  54. package/package.json +2 -2
@@ -1,472 +1,12 @@
1
- import { m as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-jZvTVXXG.mjs";
2
- import { B as createDebug, D as loadTailwindV4DesignSystem, E as filterUnsupportedMiniProgramTailwindV4Candidates, R as resolveTailwindV4CssSourceBase, S as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, n as resolveTailwindV3SourceFromPatcher, q as omitUndefined, r as resolveTailwindV3SourceOptionsFromPatcher, t as resolveTailwindV3Source, x as resolveTailwindV4SourceFromPatcher, y as resolveTailwindV4Source$1 } from "./v3-engine-DGBhUnjn.mjs";
3
- import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DDtsUvkH.mjs";
1
+ import { m as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-CUr1DYyy.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
- return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
254
+ const normalized = file.replace(/[?#].*$/, "");
255
+ const ext = path.extname(normalized);
256
+ return ext ? normalized.slice(0, -ext.length) : normalized;
747
257
  }
748
- function createSourceStylePathCandidates(file, sourceOptions) {
749
- const bases = [
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 outputRoots = [sourceOptions.outputRoot].filter((item) => typeof item === "string" && item.length > 0);
755
- const strippedFile = stripStyleExtension(file);
756
- const relativeFiles = /* @__PURE__ */ new Set();
757
- const addOutputRelativePath = (absoluteFile) => {
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
- if (path.isAbsolute(strippedFile)) {
765
- addOutputRelativePath(strippedFile);
766
- for (const base of bases) {
767
- const relative = path.relative(base, strippedFile);
768
- if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) continue;
769
- relativeFiles.add(relative);
770
- }
771
- } else relativeFiles.add(strippedFile);
772
- const candidates = /* @__PURE__ */ new Set();
773
- for (const relativeFile of relativeFiles) {
774
- if (!relativeFile || path.isAbsolute(relativeFile)) continue;
775
- for (const base of bases) for (const sourceRoot of ["", "src"]) {
776
- const prefix = sourceRoot ? path.resolve(base, sourceRoot, relativeFile) : path.resolve(base, relativeFile);
777
- for (const extension of SOURCE_STYLE_EXTENSIONS) candidates.add(`${prefix}${extension}`);
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
- const candidates = [
849
- path.resolve(base, configRequest),
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 stripKnownBuildRootPrefix(file) {
885
- const segments = normalizeMatchPath(file).split("/");
886
- const knownRoots = new Set(["dist", "src"]);
887
- for (let index = segments.length - 1; index >= 0; index--) if (knownRoots.has(segments[index])) return segments.slice(index + 1).join("/");
888
- return segments.join("/");
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 isMatchingTailwindV4CssSourceFile(file, cssSourceFile) {
891
- const outputBase = normalizeMatchPath(getOutputFileWithoutExtension(path.resolve(file)));
892
- const sourceBase = normalizeMatchPath(getOutputFileWithoutExtension(path.resolve(cssSourceFile)));
893
- const outputRelativeBase = stripKnownBuildRootPrefix(outputBase);
894
- const sourceRelativeBase = stripKnownBuildRootPrefix(sourceBase);
895
- return outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || outputRelativeBase.length > 0 && outputRelativeBase === sourceRelativeBase;
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 matchingEntry = cssEntries.find((cssEntry) => {
903
- if (!existsSync(cssEntry)) return false;
560
+ const matches = cssEntries.map((cssEntry) => {
561
+ if (!existsSync(cssEntry)) return;
904
562
  try {
905
- if (normalizeCssSourceForCompare(readFileSync(cssEntry, "utf8")) === normalizedRawSource) return true;
906
- return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
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 false;
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 resolveTailwindV4Source$1({
913
- ...omitUndefined(sourceOptions),
914
- cssEntries: [matchingEntry]
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 source = await resolveTailwindV4Source$1({
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: [cssSource]
945
- });
946
- const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd();
947
- return withGeneratorSourceMetadata(source, {
948
- matchedCssSourceFile: typeof cssSource.file === "string" ? cssSource.file : void 0,
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, cssHandlerOptions, sourceOptions, selectionOptions) {
670
+ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandlerOptions, sourceOptions, selectionOptions) {
965
671
  const cssSources = sourceOptions.cssSources;
966
672
  const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
967
- if (!cssHandlerOptions.isMainChunk || !cssSources?.length || !getSourceCandidatesForEntries) return;
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) => resolveTailwindV4Source$1({
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
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
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 resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
1045
- if (!resolvedEntrySource) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
1046
- if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
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
- return resolveTailwindV3Source({
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
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
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 shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
1061
- const sourceSideEntrySource = resolvedSourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, resolvedSourceOptions, { removeConfig: false }) : void 0;
1062
- const matchedCssSource = sourceOptions ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) : void 0;
1063
- const candidateMatchedCssSource = sourceOptions ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions) : void 0;
1064
- const configuredCssSource = sourceOptions && hasConfiguredTailwindV4CssSource(sourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await resolveTailwindV4Source$1(sourceOptions) : void 0;
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 matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
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 && resolvedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, resolvedSourceOptions, generatorOptions, file);
808
+ if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
1088
809
  const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
1089
- const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions ?? {});
1090
- return resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(resolvedSourceOptions ?? {}, {
1091
- base: resolvedEntrySource.base,
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
- ...resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher),
1108
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
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 = cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
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
- const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4Source$1({
1130
- ...omitUndefined(sourceOptions),
1131
- cssEntries: [cssEntry]
1132
- }).then((source) => generatorOptions?.config ? {
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) => {
@@ -1525,11 +1259,12 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
1525
1259
  });
1526
1260
  }
1527
1261
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
1528
- if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.isolateCssSource) return scopedRuntime;
1262
+ if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
1263
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
1529
1264
  return new Set([...scopedRuntime, ...runtime]);
1530
1265
  }
1531
- function shouldIsolateMatchedCssSource(source, sourceEntries) {
1532
- return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile && sourceEntries !== void 0);
1266
+ function shouldIsolateScopedCssSource(source, sourceEntries) {
1267
+ return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
1533
1268
  }
1534
1269
  function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
1535
1270
  if (majorVersion !== 4 || isolateCssSource) return false;
@@ -1764,22 +1499,30 @@ async function generateCssByGenerator(options) {
1764
1499
  if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1765
1500
  try {
1766
1501
  await runtimeState.readyPromise;
1767
- const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(effectiveRawSource, "css", { bareArbitraryValues: generatorOptions.bareArbitraryValues }) : [];
1502
+ const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
1768
1503
  const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
1769
1504
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
1505
+ cssEntries: opts.cssEntries,
1770
1506
  getSourceCandidatesForEntries,
1771
1507
  runtime: runtimeWithCurrentCss
1772
1508
  });
1773
1509
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1774
1510
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1775
- const generatedResults = await Promise.all(sources.map(async (source) => {
1511
+ const generatedResults = (await Promise.all(sources.map(async (source) => {
1776
1512
  const generator = createWeappTailwindcssGenerator(source);
1777
- const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1513
+ const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1778
1514
  const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
1779
- const isolateCssSource = shouldIsolateMatchedCssSource(source, sourceEntries);
1515
+ const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
1516
+ const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
1517
+ if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
1518
+ debug("defer empty scoped css source generation: %s", file);
1519
+ return;
1520
+ }
1780
1521
  const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
1522
+ currentCssCandidates,
1781
1523
  cssHandlerOptions,
1782
- isolateCssSource
1524
+ isolateCssSource,
1525
+ matchedCssSourceFile
1783
1526
  }) : runtimeWithCurrentCss;
1784
1527
  const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
1785
1528
  return generator.generate({
@@ -1791,7 +1534,7 @@ async function generateCssByGenerator(options) {
1791
1534
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1792
1535
  target: generatorOptions.target
1793
1536
  });
1794
- }));
1537
+ }))).filter((item) => Boolean(item));
1795
1538
  const firstGenerated = generatedResults[0];
1796
1539
  if (!firstGenerated) return;
1797
1540
  const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
@@ -1819,6 +1562,7 @@ async function generateCssByGenerator(options) {
1819
1562
  }
1820
1563
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
1821
1564
  const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1565
+ const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
1822
1566
  if (orderedExtraCss) {
1823
1567
  let css = stripTailwindBanner(generated.css);
1824
1568
  if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
@@ -1844,11 +1588,11 @@ async function generateCssByGenerator(options) {
1844
1588
  const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
1845
1589
  css = createCssSourceOrderAppend(css, userCss);
1846
1590
  }
1847
- if (generated.target === "weapp") {
1591
+ if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
1848
1592
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1849
1593
  css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1850
1594
  css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1851
- }
1595
+ } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1852
1596
  return {
1853
1597
  css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1854
1598
  target: generated.target,
@@ -1880,6 +1624,17 @@ async function generateCssByGenerator(options) {
1880
1624
  }
1881
1625
  }
1882
1626
  if (hasMatchedCssSourceFile || generated.target === "web") {
1627
+ if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
1628
+ const userCss = await transformGeneratorUserCss(effectiveRawSource, {
1629
+ generatorTarget: generated.target,
1630
+ generatorStyleOptions,
1631
+ cssUserHandlerOptions,
1632
+ styleHandler,
1633
+ importFallback: generatorOptions.importFallback
1634
+ });
1635
+ css = createCssSourceOrderAppend(css, userCss);
1636
+ }
1637
+ if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1883
1638
  if (shouldAppendWebBundleCssFallback(generated.target, {
1884
1639
  hasSourceDirectives,
1885
1640
  hasMatchedCssSourceFile
@@ -1921,7 +1676,10 @@ async function validateCandidatesByGenerator(options) {
1921
1676
  ...normalizeWeappTailwindcssGeneratorOptions(opts.generator),
1922
1677
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1923
1678
  };
1924
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, { runtime: candidates });
1679
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
1680
+ cssEntries: opts.cssEntries,
1681
+ runtime: candidates
1682
+ });
1925
1683
  const classSets = await Promise.all(sources.map(async (source) => {
1926
1684
  const generator = createWeappTailwindcssGenerator(source);
1927
1685
  if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
@@ -2103,8 +1861,126 @@ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
2103
1861
  for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
2104
1862
  return nextBaseClassSet;
2105
1863
  }
1864
+ function isUrlLikeCandidate(candidate) {
1865
+ return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
1866
+ }
1867
+ const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
1868
+ "accent",
1869
+ "animate",
1870
+ "basis",
1871
+ "bg",
1872
+ "blur",
1873
+ "border",
1874
+ "bottom",
1875
+ "brightness",
1876
+ "caret",
1877
+ "col",
1878
+ "columns",
1879
+ "content",
1880
+ "contrast",
1881
+ "decoration",
1882
+ "delay",
1883
+ "divide",
1884
+ "drop-shadow",
1885
+ "duration",
1886
+ "ease",
1887
+ "fill",
1888
+ "font",
1889
+ "gap",
1890
+ "gradient",
1891
+ "grid",
1892
+ "grayscale",
1893
+ "grow",
1894
+ "h",
1895
+ "hue-rotate",
1896
+ "indent",
1897
+ "inset",
1898
+ "invert",
1899
+ "leading",
1900
+ "left",
1901
+ "list",
1902
+ "m",
1903
+ "max",
1904
+ "mb",
1905
+ "min",
1906
+ "ml",
1907
+ "mr",
1908
+ "mt",
1909
+ "mx",
1910
+ "my",
1911
+ "object",
1912
+ "opacity",
1913
+ "order",
1914
+ "outline",
1915
+ "overflow",
1916
+ "p",
1917
+ "pb",
1918
+ "pl",
1919
+ "pr",
1920
+ "pt",
1921
+ "px",
1922
+ "py",
1923
+ "right",
1924
+ "ring",
1925
+ "rotate",
1926
+ "rounded",
1927
+ "row",
1928
+ "saturate",
1929
+ "scale",
1930
+ "scroll",
1931
+ "sepia",
1932
+ "shadow",
1933
+ "shrink",
1934
+ "skew",
1935
+ "space",
1936
+ "stroke",
1937
+ "text",
1938
+ "top",
1939
+ "tracking",
1940
+ "translate",
1941
+ "underline",
1942
+ "w",
1943
+ "z"
1944
+ ]);
1945
+ function getBaseUtilityCandidate(candidate) {
1946
+ let bracketDepth = 0;
1947
+ let lastVariantSeparator = -1;
1948
+ for (let index = 0; index < candidate.length; index++) {
1949
+ const char = candidate[index];
1950
+ if (char === "[") bracketDepth += 1;
1951
+ else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
1952
+ else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
1953
+ }
1954
+ let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
1955
+ if (utility.startsWith("!")) utility = utility.slice(1);
1956
+ if (utility.startsWith("-")) utility = utility.slice(1);
1957
+ return utility;
1958
+ }
1959
+ function getArbitraryUtilityPrefix(utility) {
1960
+ const bracketIndex = utility.indexOf("[");
1961
+ if (bracketIndex <= 0 || !utility.endsWith("]")) return;
1962
+ const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
1963
+ const firstDash = prefix.indexOf("-");
1964
+ return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
1965
+ }
1966
+ function isLikelyTailwindV3ArbitraryUtility(candidate) {
1967
+ const utility = getBaseUtilityCandidate(candidate);
1968
+ if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
1969
+ const prefix = getArbitraryUtilityPrefix(utility);
1970
+ return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
1971
+ }
1972
+ function isLikelyTailwindV3VariantUtility(candidate) {
1973
+ if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
1974
+ const utility = getBaseUtilityCandidate(candidate);
1975
+ return /^[!-]?[a-z@[]/.test(utility);
1976
+ }
1977
+ function isLikelyTailwindV3OpacityModifier(candidate) {
1978
+ if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
1979
+ const utility = getBaseUtilityCandidate(candidate);
1980
+ return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
1981
+ }
2106
1982
  function isHighConfidenceV3Candidate(candidate) {
2107
- return candidate.includes("[") || candidate.includes(":") || candidate.includes("/");
1983
+ return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
2108
1984
  }
2109
1985
  function isRawCandidateInClassContext(source, start, extension) {
2110
1986
  if (typeof start !== "number" || start <= 0) return false;
@@ -2149,7 +2025,7 @@ function createHighConfidenceLiteralRanges(source, matches) {
2149
2025
  for (const match of matches) {
2150
2026
  const candidate = match?.rawCandidate;
2151
2027
  if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
2152
- const range = resolveQuotedLiteralRange(source, match.start);
2028
+ const range = resolveQuotedLiteralRange(source, match.start ?? source.indexOf(candidate));
2153
2029
  if (range) ranges.push(range);
2154
2030
  }
2155
2031
  return ranges;
@@ -2240,7 +2116,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
2240
2116
  const nextBaseClassSet = options.baseClassSet;
2241
2117
  const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
2242
2118
  for (const [file, previousCandidates] of candidatesByFile) {
2243
- if (currentRuntimeFiles.has(file)) continue;
2119
+ if (currentRuntimeFiles.has(file) || snapshot.hasOmittedKnownFiles) continue;
2244
2120
  removeCandidateSet(candidateCountByClass, previousCandidates);
2245
2121
  candidatesByFile.delete(file);
2246
2122
  }
@@ -2288,4 +2164,4 @@ function createBundleRuntimeClassSetManager(options = {}) {
2288
2164
  };
2289
2165
  }
2290
2166
  //#endregion
2291
- export { validateCandidatesByGenerator as a, hasTailwindRootDirectives as c, removeTailwindSourceDirectives as d, hasTailwindGeneratedCssMarkers as f, generateCssByGenerator as i, hasTailwindSourceDirectives as l, createHmrTimingRecorder as n, mergeMarkedUserLayerComponentsCss as o, emitHmrTiming as r, processCachedTask as s, createBundleRuntimeClassSetManager as t, normalizeTailwindSourceForGenerator as u };
2167
+ export { validateCandidatesByGenerator as a, generateCssByGenerator as i, createHmrTimingRecorder as n, mergeMarkedUserLayerComponentsCss as o, emitHmrTiming as r, processCachedTask as s, createBundleRuntimeClassSetManager as t };