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.
Files changed (54) hide show
  1. package/dist/{bundle-state-CBF5YX1m.js → bundle-state-CW1X7QIy.js} +35 -3
  2. package/dist/{bundle-state-CQmxxx0R.mjs → bundle-state-s5HwfrmR.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 +5 -4
  15. package/dist/cli.mjs +5 -4
  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-DArodvWs.mjs → incremental-runtime-class-set-BcAFhVvu.mjs} +496 -619
  25. package/dist/{incremental-runtime-class-set-BffodqHh.js → incremental-runtime-class-set-BdCWIuPW.js} +541 -694
  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-8Ik4q0yI.js} +6 -6
  33. package/dist/{precheck-jZvTVXXG.mjs → precheck-h6TNzFbF.mjs} +6 -6
  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-DT-VUrl0.js} +539 -296
  44. package/dist/{vite-BBcQIJpD.mjs → vite-yCeZWm7n.mjs} +538 -295
  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 +1933 -1621
  49. package/dist/weapp-tw-runtime-classset-loader.js +6 -6
  50. package/dist/{webpack-D-gb4ZvO.js → webpack-BFMJqCH9.js} +7 -7
  51. package/dist/{webpack-D43aMQzO.mjs → webpack-E0gT72EX.mjs} +7 -7
  52. package/dist/webpack.js +1 -1
  53. package/dist/webpack.mjs +1 -1
  54. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require("./chunk-C5U5_Hdc.js");
2
- const require_v3_engine = require("./v3-engine-M6Aqru5T.js");
3
- const require_generator = require("./generator-CvmsIQFI.js");
4
- const require_precheck = require("./precheck-BzYPm-EG.js");
2
+ const require_v3_engine = require("./v3-engine-CmIF_gsq.js");
3
+ const require_generator = require("./generator-Bd1LntD3.js");
4
+ const require_precheck = require("./precheck-8Ik4q0yI.js");
5
5
  let node_fs = require("node:fs");
6
6
  let postcss = require("postcss");
7
7
  postcss = require_chunk.__toESM(postcss);
@@ -11,466 +11,6 @@ node_process = require_chunk.__toESM(node_process);
11
11
  let node_path = require("node:path");
12
12
  node_path = require_chunk.__toESM(node_path);
13
13
  let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
14
- //#region src/bundlers/shared/generator-css/markers.ts
15
- const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
16
- 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)-/;
17
- const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
18
- const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
19
- const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
20
- const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
21
- const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
22
- const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
23
- function createCssAppend(base, extra) {
24
- if (!base) return extra;
25
- if (!extra) return base;
26
- return `${base}\n${extra}`;
27
- }
28
- function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
29
- const trimmedRaw = rawSource.trim();
30
- const trimmedTailwind = rawTailwindCss.trim();
31
- if (trimmedRaw === trimmedTailwind) return {
32
- before: "",
33
- after: ""
34
- };
35
- if (trimmedTailwind.startsWith(trimmedRaw)) return {
36
- before: "",
37
- after: ""
38
- };
39
- const start = rawSource.indexOf(rawTailwindCss);
40
- if (start === -1) return;
41
- return {
42
- before: rawSource.slice(0, start),
43
- after: rawSource.slice(start + rawTailwindCss.length)
44
- };
45
- }
46
- function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
47
- const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
48
- if (!match || match.index === void 0) return;
49
- let afterStart = match.index + match[0].length;
50
- while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
51
- if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
52
- afterStart += rawTailwindCss.length;
53
- while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
54
- }
55
- return {
56
- before: rawSource.slice(0, match.index),
57
- after: rawSource.slice(afterStart)
58
- };
59
- }
60
- function splitTailwindGeneratedCssByBanner(rawSource, start) {
61
- const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
62
- if (!match || match.index === void 0) return;
63
- return {
64
- before: rawSource.slice(0, match.index),
65
- after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
66
- };
67
- }
68
- function stripTailwindBanner(css) {
69
- return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
70
- }
71
- function stripTailwindBanners(css) {
72
- return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
73
- }
74
- function stripGeneratorPlaceholderMarkers(css) {
75
- return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
76
- }
77
- function hasTailwindGeneratedCss(rawSource) {
78
- return TAILWIND_V4_BANNER_RE.test(rawSource);
79
- }
80
- function hasTailwindGeneratedCssMarkers(rawSource) {
81
- return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
82
- }
83
- //#endregion
84
- //#region src/bundlers/shared/generator-css/directives.ts
85
- const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
86
- "config",
87
- "custom-variant",
88
- "layer",
89
- "plugin",
90
- "reference",
91
- "source",
92
- "tailwind",
93
- "theme",
94
- "utility",
95
- "variant"
96
- ]);
97
- const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
98
- "config",
99
- "custom-variant",
100
- "plugin",
101
- "source",
102
- "tailwind",
103
- "theme",
104
- "utility",
105
- "variant"
106
- ]);
107
- 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/;
108
- const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
109
- const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
110
- const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
111
- const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
112
- ["tailwindcss/base", "base"],
113
- ["tailwindcss/components", "components"],
114
- ["tailwindcss/utilities", "utilities"]
115
- ]);
116
- function parseImportRequest(params) {
117
- return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
118
- }
119
- function parseConfigRequest(params) {
120
- return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
121
- }
122
- function isPackageJsonImportRequest(request) {
123
- return typeof request === "string" && request.startsWith("#");
124
- }
125
- function isWeappTailwindcssImportRequest(request) {
126
- return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
127
- }
128
- function normalizeTailwindImportRequest(request, options = {}) {
129
- if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
130
- return request;
131
- }
132
- function replaceImportRequest(params, request, replacement) {
133
- const index = params.indexOf(request);
134
- if (index === -1) return params;
135
- return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
136
- }
137
- function normalizeTailwindImportAtRules(root, options = {}) {
138
- if (!options.importFallback) return false;
139
- let changed = false;
140
- const seenCanonicalImports = /* @__PURE__ */ new Set();
141
- root.walkAtRules("import", (node) => {
142
- const request = parseImportRequest(node.params);
143
- const normalizedRequest = normalizeTailwindImportRequest(request, options);
144
- if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
145
- const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
146
- const normalizedKey = normalizedParams.trim();
147
- if (seenCanonicalImports.has(normalizedKey)) {
148
- node.remove();
149
- changed = true;
150
- return;
151
- }
152
- seenCanonicalImports.add(normalizedKey);
153
- if (normalizedParams !== node.params) {
154
- node.params = normalizedParams;
155
- changed = true;
156
- }
157
- });
158
- return changed;
159
- }
160
- function normalizeTailwindDirectiveLine(line, options = {}) {
161
- const trimmed = line.trimStart();
162
- if (/^@(?:use|forward)\b/.test(trimmed)) {
163
- const request = parseImportRequest(trimmed.replace(/^@(?:use|forward)\b/, ""));
164
- if (isTailwindImportRequest(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
165
- const normalizedRequest = normalizeTailwindImportRequest(request, options);
166
- return replaceImportRequest(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
167
- }
168
- return line;
169
- }
170
- if (!options.importFallback || !trimmed.startsWith("@import")) return line;
171
- const request = parseImportRequest(trimmed.replace(/^@import\b/, ""));
172
- if (!request || !isWeappTailwindcssImportRequest(request)) return line;
173
- return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
174
- }
175
- function extractTailwindDirectiveLines(rawSource, options = {}) {
176
- const directives = [];
177
- const seenImports = /* @__PURE__ */ new Set();
178
- for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
179
- const trimmed = line.trim();
180
- if (!trimmed || trimmed.startsWith("//")) continue;
181
- const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
182
- if (!directive) continue;
183
- const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
184
- const normalizedTrimmed = normalized.trim();
185
- if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
186
- const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
187
- if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest(request)) continue;
188
- if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
189
- if (request && isTailwindImportRequest(request)) {
190
- const key = normalizedTrimmed;
191
- if (seenImports.has(key)) continue;
192
- seenImports.add(key);
193
- }
194
- directives.push(normalized);
195
- }
196
- return directives;
197
- }
198
- function stripPreprocessorLineComment(line) {
199
- let quote;
200
- let escaped = false;
201
- for (let index = 0; index < line.length; index++) {
202
- const char = line[index];
203
- if (escaped) {
204
- escaped = false;
205
- continue;
206
- }
207
- if (char === "\\") {
208
- escaped = true;
209
- continue;
210
- }
211
- if (quote) {
212
- if (char === quote) quote = void 0;
213
- continue;
214
- }
215
- if (char === "\"" || char === "'") {
216
- quote = char;
217
- continue;
218
- }
219
- if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
220
- }
221
- return line;
222
- }
223
- function countBlockBraceDelta(line) {
224
- let quote;
225
- let escaped = false;
226
- let delta = 0;
227
- for (let index = 0; index < line.length; index++) {
228
- const char = line[index];
229
- if (escaped) {
230
- escaped = false;
231
- continue;
232
- }
233
- if (char === "\\") {
234
- escaped = true;
235
- continue;
236
- }
237
- if (quote) {
238
- if (char === quote) quote = void 0;
239
- continue;
240
- }
241
- if (char === "\"" || char === "'") {
242
- quote = char;
243
- continue;
244
- }
245
- if (char === "{") delta++;
246
- else if (char === "}") delta--;
247
- }
248
- return delta;
249
- }
250
- function extractTailwindFallbackBlocks(rawSource) {
251
- const blocks = [];
252
- let current;
253
- let depth = 0;
254
- for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
255
- const line = stripPreprocessorLineComment(rawLine);
256
- if (!line.trim()) continue;
257
- if (!current) {
258
- if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
259
- current = [line];
260
- depth = countBlockBraceDelta(line);
261
- if (depth <= 0) {
262
- blocks.push(current.join("\n"));
263
- current = void 0;
264
- depth = 0;
265
- }
266
- continue;
267
- }
268
- current.push(line);
269
- depth += countBlockBraceDelta(line);
270
- if (depth <= 0) {
271
- blocks.push(current.join("\n"));
272
- current = void 0;
273
- depth = 0;
274
- }
275
- }
276
- return blocks;
277
- }
278
- function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
279
- const directives = [...extractTailwindDirectiveLines(rawSource, options), ...extractTailwindFallbackBlocks(rawSource)];
280
- return directives.length > 0 ? directives.join("\n") : void 0;
281
- }
282
- function extractConfigRequestFromSource(rawSource) {
283
- for (const line of rawSource.split(/\r?\n/)) {
284
- const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
285
- const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
286
- if (request) return request;
287
- }
288
- }
289
- function hasPreprocessorOnlySyntax(rawSource) {
290
- return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
291
- }
292
- function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
293
- return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
294
- }
295
- function normalizeTailwindV3CssEntrySource(rawSource) {
296
- try {
297
- const root = postcss.default.parse(rawSource);
298
- let changed = false;
299
- root.walkAtRules("import", (node) => {
300
- const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
301
- if (!layer) return;
302
- node.replaceWith(postcss.default.atRule({
303
- name: "tailwind",
304
- params: layer
305
- }));
306
- changed = true;
307
- });
308
- return changed ? root.toString() : rawSource;
309
- } catch {
310
- return rawSource;
311
- }
312
- }
313
- function normalizeTailwindSourceDirectives(rawSource, options = {}) {
314
- if (!options.importFallback) return rawSource;
315
- try {
316
- const root = postcss.default.parse(rawSource);
317
- return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
318
- } catch {
319
- return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
320
- }
321
- }
322
- function isTailwindImportRequest(request) {
323
- return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
324
- }
325
- function isTailwindImportAtRule(node, options = {}) {
326
- if (node.name === "tailwind") return true;
327
- if (node.name !== "import" && node.name !== "use" && node.name !== "forward") return false;
328
- return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
329
- }
330
- function isTailwindSourceDirective(node, options = {}) {
331
- if (node.type !== "atrule") return false;
332
- const atRule = node;
333
- if (isTailwindImportAtRule(atRule, options)) return true;
334
- if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
335
- if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
336
- return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
337
- }
338
- function hasGeneratedCssArtifacts(rawSource) {
339
- return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
340
- }
341
- function isTailwindGenerationDirective(node, options = {}) {
342
- if (node.type !== "atrule") return false;
343
- const atRule = node;
344
- const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
345
- return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
346
- }
347
- function removeTailwindSourceDirectives(rawSource, options = {}) {
348
- try {
349
- const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
350
- if (!source) return "";
351
- const root = postcss.default.parse(source);
352
- let removed = false;
353
- root.walk((node) => {
354
- if (isTailwindSourceDirective(node, options)) {
355
- node.remove();
356
- removed = true;
357
- }
358
- });
359
- return removed ? root.toString() : source;
360
- } catch {
361
- return stripGeneratorPlaceholderMarkers(rawSource);
362
- }
363
- }
364
- function hasTailwindSourceDirectives(rawSource, options = {}) {
365
- try {
366
- if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
367
- const root = postcss.default.parse(rawSource);
368
- let found = false;
369
- const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
370
- root.walk((node) => {
371
- if (isTailwindGenerationDirective(node, {
372
- ...options,
373
- ignoreLayer
374
- })) {
375
- found = true;
376
- return false;
377
- }
378
- });
379
- return found;
380
- } catch {
381
- return extractTailwindDirectiveLines(rawSource, options).length > 0;
382
- }
383
- }
384
- function hasTailwindRootDirectives(rawSource, options = {}) {
385
- if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
386
- try {
387
- const root = postcss.default.parse(rawSource);
388
- let found = false;
389
- root.walkAtRules((node) => {
390
- const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
391
- if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
392
- found = true;
393
- return false;
394
- }
395
- });
396
- return found;
397
- } catch {
398
- return extractTailwindDirectiveLines(rawSource, options).length > 0;
399
- }
400
- }
401
- function hasTailwindApplyDirective(rawSource) {
402
- if (!rawSource.includes("@apply")) return false;
403
- try {
404
- const root = postcss.default.parse(rawSource);
405
- let found = false;
406
- root.walkAtRules("apply", () => {
407
- found = true;
408
- return false;
409
- });
410
- return found;
411
- } catch {
412
- return false;
413
- }
414
- }
415
- function resolveCssEntrySource(rawSource, base, options = {}) {
416
- try {
417
- const root = postcss.default.parse(rawSource);
418
- const normalizedImports = normalizeTailwindImportAtRules(root, options);
419
- let found = false;
420
- let config;
421
- let configRequest;
422
- let removedConfig = false;
423
- const removeConfig = options.removeConfig ?? true;
424
- const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
425
- root.walk((node) => {
426
- if (isTailwindGenerationDirective(node, {
427
- ...options,
428
- ignoreLayer
429
- })) found = true;
430
- if (node.type === "atrule" && node.name === "config") {
431
- const configPath = parseConfigRequest(node.params);
432
- if (configPath && !config) {
433
- configRequest = configPath;
434
- config = isPackageJsonImportRequest(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
435
- }
436
- if (removeConfig) {
437
- node.remove();
438
- removedConfig = true;
439
- }
440
- }
441
- });
442
- if (!found) return;
443
- if (hasPreprocessorOnlySyntax(rawSource)) {
444
- const css = extractTailwindSourceForPostcssFallback(rawSource, {
445
- ...options,
446
- removeConfig
447
- });
448
- if (css) return {
449
- css,
450
- config,
451
- configRequest,
452
- base
453
- };
454
- }
455
- return {
456
- css: removedConfig || normalizedImports ? root.toString() : rawSource,
457
- config,
458
- configRequest,
459
- base
460
- };
461
- } catch {
462
- const css = extractTailwindSourceForPostcssFallback(rawSource, options);
463
- const configRequest = extractConfigRequestFromSource(rawSource);
464
- const config = configRequest && !isPackageJsonImportRequest(configRequest) ? node_path.default.isAbsolute(configRequest) ? configRequest : node_path.default.resolve(base, configRequest) : void 0;
465
- return css ? {
466
- css,
467
- config,
468
- configRequest,
469
- base
470
- } : void 0;
471
- }
472
- }
473
- //#endregion
474
14
  //#region src/bundlers/shared/cache.ts
475
15
  async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
476
16
  let cacheHit = false;
@@ -707,80 +247,117 @@ function collectDedupedPostTransformCompatCss(css, generatedCss) {
707
247
  }
708
248
  }
709
249
  function removeDuplicatedViteMarkers(css, baseCss) {
710
- if (!VITE_MARKER_RE.test(baseCss)) return css;
711
- VITE_MARKER_RE.lastIndex = 0;
712
- return css.replace(VITE_MARKER_RE, "");
713
- }
714
- //#endregion
715
- //#region src/bundlers/shared/generator-css/config-directive.ts
716
- function quoteCssString(value) {
717
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
718
- }
719
- function toCssPath(value) {
720
- return value.replaceAll("\\", "/");
721
- }
722
- function prependConfigDirective(css, config) {
723
- if (!config || /@config\s+/.test(css)) return css;
724
- return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
725
- }
726
- function normalizeConfigDirective(css, config) {
727
- if (!config || !/@config\s+/.test(css)) return css;
728
- return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
250
+ if (!require_v3_engine.VITE_MARKER_RE.test(baseCss)) return css;
251
+ require_v3_engine.VITE_MARKER_RE.lastIndex = 0;
252
+ return css.replace(require_v3_engine.VITE_MARKER_RE, "");
729
253
  }
730
254
  //#endregion
731
255
  //#region src/bundlers/shared/generator-css/source-files.ts
732
- const SOURCE_STYLE_EXTENSIONS = [
733
- ".vue",
734
- ".uvue",
735
- ".nvue",
736
- ".css",
737
- ".scss",
738
- ".sass",
739
- ".less",
740
- ".styl",
741
- ".stylus",
742
- ".wxss",
743
- ".acss",
744
- ".jxss",
745
- ".ttss",
746
- ".qss"
747
- ];
748
256
  const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
749
257
  function stripStyleExtension(file) {
750
- return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
258
+ const normalized = file.replace(/[?#].*$/, "");
259
+ const ext = node_path.default.extname(normalized);
260
+ return ext ? normalized.slice(0, -ext.length) : normalized;
751
261
  }
752
- function createSourceStylePathCandidates(file, sourceOptions) {
753
- const bases = [
262
+ function normalizeMatchPath$1(file) {
263
+ return file.split(node_path.default.sep).join("/");
264
+ }
265
+ function isPathWithinRoot$1(file, root) {
266
+ const relative = node_path.default.relative(root, file);
267
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
268
+ }
269
+ function countCommonSuffixSegments(a, b) {
270
+ const aSegments = a.split("/").filter(Boolean);
271
+ const bSegments = b.split("/").filter(Boolean);
272
+ let count = 0;
273
+ while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
274
+ return count;
275
+ }
276
+ function collectOutputMatchBases(file, sourceOptions) {
277
+ const normalizedFile = file.replace(/[?#].*$/, "");
278
+ const roots = [
279
+ sourceOptions.outputRoot,
754
280
  sourceOptions.projectRoot,
755
- sourceOptions.cwd,
756
- node_process.default.cwd()
281
+ sourceOptions.cwd
757
282
  ].filter((item) => typeof item === "string" && item.length > 0);
758
- const outputRoots = [sourceOptions.outputRoot].filter((item) => typeof item === "string" && item.length > 0);
759
- const strippedFile = stripStyleExtension(file);
760
- const relativeFiles = /* @__PURE__ */ new Set();
761
- const addOutputRelativePath = (absoluteFile) => {
762
- for (const outputRoot of outputRoots) {
763
- const relative = node_path.default.relative(outputRoot, absoluteFile);
764
- if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
765
- relativeFiles.add(relative);
766
- }
283
+ const bases = /* @__PURE__ */ new Set();
284
+ const addBase = (candidate) => {
285
+ const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
286
+ if (stripped.length > 0) bases.add(stripped);
767
287
  };
768
- if (node_path.default.isAbsolute(strippedFile)) {
769
- addOutputRelativePath(strippedFile);
770
- for (const base of bases) {
771
- const relative = node_path.default.relative(base, strippedFile);
772
- if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
773
- relativeFiles.add(relative);
774
- }
775
- } else relativeFiles.add(strippedFile);
776
- const candidates = /* @__PURE__ */ new Set();
777
- for (const relativeFile of relativeFiles) {
778
- if (!relativeFile || node_path.default.isAbsolute(relativeFile)) continue;
779
- for (const base of bases) for (const sourceRoot of ["", "src"]) {
780
- const prefix = sourceRoot ? node_path.default.resolve(base, sourceRoot, relativeFile) : node_path.default.resolve(base, relativeFile);
781
- for (const extension of SOURCE_STYLE_EXTENSIONS) candidates.add(`${prefix}${extension}`);
782
- }
288
+ addBase(normalizedFile);
289
+ if (node_path.default.isAbsolute(normalizedFile)) for (const root of roots) {
290
+ const normalizedRoot = node_path.default.resolve(root);
291
+ if (isPathWithinRoot$1(normalizedFile, normalizedRoot)) addBase(node_path.default.relative(normalizedRoot, normalizedFile));
292
+ }
293
+ else for (const root of roots) addBase(node_path.default.resolve(root, normalizedFile));
294
+ return bases;
295
+ }
296
+ function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
297
+ const outputBases = collectOutputMatchBases(file, sourceOptions);
298
+ const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
299
+ const sourceBases = /* @__PURE__ */ new Set();
300
+ const addSourceBase = (candidate) => {
301
+ const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
302
+ if (stripped.length > 0) sourceBases.add(stripped);
303
+ };
304
+ addSourceBase(normalizedSourceFile);
305
+ if (node_path.default.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
306
+ if (!root) continue;
307
+ const normalizedRoot = node_path.default.resolve(root);
308
+ if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
783
309
  }
310
+ 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;
311
+ return false;
312
+ }
313
+ function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
314
+ const outputBases = collectOutputMatchBases(file, sourceOptions);
315
+ const normalizedSourceFile = sourceFile.replace(/[?#].*$/, "");
316
+ const sourceBases = /* @__PURE__ */ new Set();
317
+ const addSourceBase = (candidate) => {
318
+ const stripped = normalizeMatchPath$1(stripStyleExtension(candidate));
319
+ if (stripped.length > 0) sourceBases.add(stripped);
320
+ };
321
+ addSourceBase(normalizedSourceFile);
322
+ if (node_path.default.isAbsolute(normalizedSourceFile)) for (const root of [sourceOptions.projectRoot, sourceOptions.cwd]) {
323
+ if (!root) continue;
324
+ const normalizedRoot = node_path.default.resolve(root);
325
+ if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
326
+ }
327
+ let bestScore = 0;
328
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) {
329
+ const commonSuffixSegments = countCommonSuffixSegments(outputBase, sourceBase);
330
+ if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
331
+ else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
332
+ else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
333
+ else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
334
+ }
335
+ return bestScore;
336
+ }
337
+ function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
338
+ const matches = [...(sourceOptions.cssSources ?? []).map((cssSource) => cssSource.file), ...sourceOptions.cssEntries ?? []].filter((sourceFile) => typeof sourceFile === "string" && node_path.default.isAbsolute(sourceFile)).map((sourceFile) => node_path.default.resolve(sourceFile.replace(/[?#].*$/, ""))).filter((sourceFile, index, files) => files.indexOf(sourceFile) === index).map((sourceFile) => ({
339
+ sourceFile,
340
+ score: scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions)
341
+ })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
342
+ const bestScore = matches[0]?.score ?? 0;
343
+ return matches.filter((match) => match.score === bestScore).map((match) => match.sourceFile);
344
+ }
345
+ function hasConfiguredSourceFiles(sourceOptions) {
346
+ return Boolean(sourceOptions.cssEntries?.length) || Boolean(sourceOptions.cssSources?.some((cssSource) => typeof cssSource.file === "string" && cssSource.file.length > 0));
347
+ }
348
+ function createSourceStylePathCandidates(file, sourceOptions) {
349
+ const candidates = /* @__PURE__ */ new Set();
350
+ const addCandidate = (candidate) => {
351
+ if (candidate && node_path.default.isAbsolute(candidate)) candidates.add(candidate.replace(/[?#].*$/, ""));
352
+ };
353
+ const matchedConfiguredSourceFiles = collectMatchedConfiguredSourceFiles(file, sourceOptions);
354
+ if (matchedConfiguredSourceFiles.length === 1) addCandidate(matchedConfiguredSourceFiles[0]);
355
+ else if (matchedConfiguredSourceFiles.length === 0) for (const cssSource of sourceOptions.cssSources ?? []) {
356
+ const sourceFile = cssSource.file;
357
+ if (typeof sourceFile === "string" && node_path.default.isAbsolute(sourceFile) && isMatchingSourceStyleFile(file, sourceFile, sourceOptions)) addCandidate(sourceFile);
358
+ }
359
+ if (hasConfiguredSourceFiles(sourceOptions)) return [...candidates];
360
+ if (!hasConfiguredSourceFiles(sourceOptions)) addCandidate(sourceOptions.sourceFile);
784
361
  return [...candidates];
785
362
  }
786
363
  function extractStyleDirectiveSources(source) {
@@ -789,11 +366,11 @@ function extractStyleDirectiveSources(source) {
789
366
  let match = SFC_STYLE_BLOCK_RE.exec(source);
790
367
  while (match !== null) {
791
368
  const styleSource = match[1] ?? "";
792
- if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
369
+ if (require_v3_engine.hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
793
370
  match = SFC_STYLE_BLOCK_RE.exec(source);
794
371
  }
795
372
  if (styleSources.length > 0) return styleSources;
796
- return hasTailwindSourceDirectives(source) ? [source] : [];
373
+ return require_v3_engine.hasTailwindSourceDirectives(source) ? [source] : [];
797
374
  }
798
375
  function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
799
376
  for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
@@ -801,7 +378,7 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
801
378
  try {
802
379
  const source = (0, node_fs.readFileSync)(sourceFile, "utf8");
803
380
  for (const styleSource of extractStyleDirectiveSources(source)) {
804
- const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
381
+ const cssEntrySource = require_v3_engine.resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
805
382
  if (cssEntrySource) return {
806
383
  ...cssEntrySource,
807
384
  file: sourceFile
@@ -826,6 +403,24 @@ function resolvePostcssSourceFile(cssHandlerOptions) {
826
403
  function resolveCssHandlerSourceOptions(cssHandlerOptions) {
827
404
  return cssHandlerOptions.sourceOptions;
828
405
  }
406
+ function createCssEntrySources(cssEntries) {
407
+ return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
408
+ }
409
+ function mergeCssSources(cssSources, cssEntrySources) {
410
+ const merged = [];
411
+ const seenFiles = /* @__PURE__ */ new Set();
412
+ const addSource = (cssSource) => {
413
+ const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
414
+ if (file) {
415
+ if (seenFiles.has(file)) return;
416
+ seenFiles.add(file);
417
+ }
418
+ merged.push(cssSource);
419
+ };
420
+ for (const cssSource of cssSources ?? []) addSource(cssSource);
421
+ for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
422
+ return merged.length > 0 ? merged : void 0;
423
+ }
829
424
  function createSingleTailwindV4SourceOptions(sourceOptions, options) {
830
425
  return require_v3_engine.omitUndefined({
831
426
  projectRoot: sourceOptions.projectRoot,
@@ -835,6 +430,27 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
835
430
  css: options.css
836
431
  });
837
432
  }
433
+ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
434
+ const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
435
+ if (!(0, node_fs.existsSync)(cssEntry)) return require_v3_engine.resolveTailwindV4Source({
436
+ ...require_v3_engine.omitUndefined(singleEntrySourceOptions),
437
+ cssEntries: [cssEntry]
438
+ });
439
+ const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
440
+ const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
441
+ const entrySource = require_v3_engine.resolveCssEntrySource(css, base, { removeConfig: false });
442
+ const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, sourceOptions);
443
+ return withGeneratorSourceMetadata(await require_v3_engine.resolveTailwindV4Source({
444
+ ...require_v3_engine.omitUndefined(singleEntrySourceOptions),
445
+ base,
446
+ css: require_v3_engine.normalizeConfigDirective(css, config),
447
+ cssEntries: [cssEntry]
448
+ }), {
449
+ matchedCssSourceFile: cssEntry,
450
+ sourceBase: base,
451
+ sourceCss: css
452
+ });
453
+ }
838
454
  function resolveCssSourceBase(file, cssHandlerOptions) {
839
455
  const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
840
456
  return node_path.default.dirname(node_path.default.resolve(normalized));
@@ -844,34 +460,43 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
844
460
  if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
845
461
  const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
846
462
  const baseCandidates = [
463
+ sourceOptions.sourceFile ? node_path.default.dirname(sourceOptions.sourceFile.replace(/[?#].*$/, "")) : void 0,
464
+ node_path.default.isAbsolute(outputDir) ? outputDir : void 0,
847
465
  sourceOptions.projectRoot,
848
- sourceOptions.cwd,
849
- node_process.default.cwd()
466
+ sourceOptions.cwd
850
467
  ].filter((item) => typeof item === "string" && item.length > 0);
468
+ const seenCandidates = /* @__PURE__ */ new Set();
469
+ const configCandidates = [];
470
+ const addConfigCandidate = (candidate) => {
471
+ if (!candidate) return;
472
+ const normalized = node_path.default.resolve(candidate);
473
+ if (seenCandidates.has(normalized)) return;
474
+ seenCandidates.add(normalized);
475
+ configCandidates.push(normalized);
476
+ };
851
477
  for (const base of baseCandidates) {
852
- const candidates = [
853
- node_path.default.resolve(base, configRequest),
854
- node_path.default.resolve(base, "src", configRequest),
855
- node_path.default.resolve(base, outputDir, configRequest),
856
- node_path.default.resolve(base, "src", outputDir, configRequest)
857
- ];
858
- for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
478
+ addConfigCandidate(node_path.default.resolve(base, configRequest));
479
+ if (!node_path.default.isAbsolute(outputDir)) addConfigCandidate(node_path.default.resolve(base, outputDir, configRequest));
859
480
  }
481
+ for (const candidate of configCandidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
860
482
  return sourceOptions.config;
861
483
  }
862
- function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
484
+ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
863
485
  const from = resolvePostcssFromOption(cssHandlerOptions);
864
- if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
486
+ if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
865
487
  return true;
866
488
  }
867
489
  function shouldResolveSourceSideCssEntry(rawSource) {
868
- return rawSource.includes("@apply") || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
490
+ return rawSource.includes("@apply") || require_v3_engine.hasTailwindGeneratedCss(rawSource) || require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource);
869
491
  }
870
492
  function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
871
- return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
493
+ return Boolean(sourceSideEntrySource) && !require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true });
494
+ }
495
+ function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
496
+ return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
872
497
  }
873
498
  function normalizeCssSourceForCompare(css) {
874
- return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
499
+ return require_v3_engine.stripGeneratorPlaceholderMarkers(require_v3_engine.stripTailwindBanners(css)).trim();
875
500
  }
876
501
  function getOutputFileStem(file) {
877
502
  const normalized = file.replace(/[?#].*$/, "");
@@ -885,38 +510,119 @@ function getOutputFileWithoutExtension(file) {
885
510
  function normalizeMatchPath(file) {
886
511
  return file.split(node_path.default.sep).join("/");
887
512
  }
888
- function stripKnownBuildRootPrefix(file) {
889
- const segments = normalizeMatchPath(file).split("/");
890
- const knownRoots = new Set(["dist", "src"]);
891
- for (let index = segments.length - 1; index >= 0; index--) if (knownRoots.has(segments[index])) return segments.slice(index + 1).join("/");
892
- return segments.join("/");
513
+ function isPathWithinRoot(file, root) {
514
+ const relative = node_path.default.relative(root, file);
515
+ return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
516
+ }
517
+ function collectCssSourceMatchBases(file, roots) {
518
+ const normalizedFile = file.replace(/[?#].*$/, "");
519
+ const bases = /* @__PURE__ */ new Set();
520
+ const addBase = (candidate) => {
521
+ const base = normalizeMatchPath(getOutputFileWithoutExtension(candidate));
522
+ if (base.length > 0) {
523
+ bases.add(base);
524
+ const withoutWorkspaceSegment = base.replace(/^(?:src|dist)\//, "");
525
+ if (withoutWorkspaceSegment !== base && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
526
+ }
527
+ };
528
+ addBase(normalizedFile);
529
+ const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => node_path.default.resolve(root));
530
+ if (node_path.default.isAbsolute(normalizedFile)) {
531
+ for (const root of resolvedRoots) if (isPathWithinRoot(normalizedFile, root)) addBase(node_path.default.relative(root, normalizedFile));
532
+ } else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
533
+ return bases;
534
+ }
535
+ function hasMatchingCssSourceBase(outputBases, sourceBases) {
536
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
537
+ return false;
538
+ }
539
+ function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
540
+ return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
541
+ sourceOptions.outputRoot,
542
+ sourceOptions.projectRoot,
543
+ sourceOptions.cwd
544
+ ]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
893
545
  }
894
- function isMatchingTailwindV4CssSourceFile(file, cssSourceFile) {
895
- const outputBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(file)));
896
- const sourceBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(cssSourceFile)));
897
- const outputRelativeBase = stripKnownBuildRootPrefix(outputBase);
898
- const sourceRelativeBase = stripKnownBuildRootPrefix(sourceBase);
899
- return outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || outputRelativeBase.length > 0 && outputRelativeBase === sourceRelativeBase;
546
+ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
547
+ const outputBases = collectCssSourceMatchBases(file, [
548
+ sourceOptions.outputRoot,
549
+ sourceOptions.projectRoot,
550
+ sourceOptions.cwd
551
+ ]);
552
+ const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
553
+ let bestScore = 0;
554
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
555
+ else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
556
+ else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
557
+ return bestScore;
900
558
  }
901
559
  function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
902
560
  const cssEntries = sourceOptions.cssEntries;
903
561
  if (!cssEntries?.length) return;
904
562
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
905
563
  const outputStem = getOutputFileStem(file);
906
- const matchingEntry = cssEntries.find((cssEntry) => {
907
- if (!(0, node_fs.existsSync)(cssEntry)) return false;
564
+ const matches = cssEntries.map((cssEntry) => {
565
+ if (!(0, node_fs.existsSync)(cssEntry)) return;
908
566
  try {
909
- if (normalizeCssSourceForCompare((0, node_fs.readFileSync)(cssEntry, "utf8")) === normalizedRawSource) return true;
910
- return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
567
+ const entrySource = (0, node_fs.readFileSync)(cssEntry, "utf8");
568
+ const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssEntry, sourceOptions);
569
+ if (normalizeCssSourceForCompare(entrySource) === normalizedRawSource) return {
570
+ cssEntry,
571
+ score: 1e6 + pathScore
572
+ };
573
+ if (pathScore > 0) return {
574
+ cssEntry,
575
+ score: pathScore
576
+ };
577
+ if (cssEntries.length === 1 && outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem) return {
578
+ cssEntry,
579
+ score: 1
580
+ };
581
+ return;
911
582
  } catch {
912
- return false;
583
+ return;
913
584
  }
914
- });
585
+ }).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score);
586
+ const bestScore = matches[0]?.score;
587
+ const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
915
588
  if (!matchingEntry) return;
916
- return require_v3_engine.resolveTailwindV4Source({
917
- ...require_v3_engine.omitUndefined(sourceOptions),
918
- cssEntries: [matchingEntry]
589
+ return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions);
590
+ }
591
+ function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
592
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
593
+ const entrySource = require_v3_engine.resolveCssEntrySource(cssSource.css, sourceBase, { removeConfig: false });
594
+ if (!entrySource?.config) return cssSource;
595
+ return {
596
+ ...cssSource,
597
+ css: require_v3_engine.normalizeConfigDirective(cssSource.css, entrySource.config)
598
+ };
599
+ }
600
+ function hydrateTailwindV4CssSource(cssSource) {
601
+ if (typeof cssSource.css === "string" && cssSource.css.length > 0) return cssSource;
602
+ if (typeof cssSource.file !== "string" || !(0, node_fs.existsSync)(cssSource.file)) return cssSource;
603
+ const file = node_path.default.resolve(cssSource.file);
604
+ return {
605
+ ...cssSource,
606
+ file,
607
+ base: cssSource.base ?? node_path.default.dirname(file),
608
+ css: (0, node_fs.readFileSync)(file, "utf8"),
609
+ dependencies: [...new Set([...cssSource.dependencies ?? [], file])]
610
+ };
611
+ }
612
+ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
613
+ if (!sourceOptions.cssSources?.length) return sourceOptions;
614
+ const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd();
615
+ let changed = false;
616
+ const cssSources = sourceOptions.cssSources.map((cssSource) => {
617
+ const hydratedCssSource = hydrateTailwindV4CssSource(cssSource);
618
+ const normalizedCssSource = normalizeTailwindV4CssSourceConfig(hydratedCssSource, require_v3_engine.resolveTailwindV4CssSourceBase(hydratedCssSource, sourceBaseFallback));
619
+ changed || (changed = normalizedCssSource !== cssSource);
620
+ return normalizedCssSource;
919
621
  });
622
+ return changed ? {
623
+ ...sourceOptions,
624
+ cssSources
625
+ } : sourceOptions;
920
626
  }
921
627
  async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
922
628
  const cssSources = sourceOptions.cssSources;
@@ -926,11 +632,11 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
926
632
  const matchingSource = cssSources.find((cssSource) => {
927
633
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
928
634
  if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return true;
929
- if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file)) return true;
635
+ if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file, sourceOptions)) return true;
930
636
  return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
931
637
  });
932
638
  if (!matchingSource) return;
933
- return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions);
639
+ return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
934
640
  }
935
641
  function tryResolveTailwindV4SourceOptions(runtimeState) {
936
642
  try {
@@ -942,16 +648,16 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
942
648
  function hasConfiguredTailwindV4CssSource(sourceOptions) {
943
649
  return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
944
650
  }
945
- async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions) {
946
- const source = await require_v3_engine.resolveTailwindV4Source({
651
+ async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
652
+ const sourceBase = require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
653
+ const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
654
+ return withGeneratorSourceMetadata(await require_v3_engine.resolveTailwindV4Source({
947
655
  ...require_v3_engine.omitUndefined(sourceOptions),
948
- cssSources: [cssSource]
949
- });
950
- const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd();
951
- return withGeneratorSourceMetadata(source, {
952
- matchedCssSourceFile: typeof cssSource.file === "string" ? cssSource.file : void 0,
953
- sourceBase: require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback),
954
- sourceCss: cssSource.css
656
+ cssSources: [normalizedCssSource]
657
+ }), {
658
+ matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
659
+ sourceBase,
660
+ sourceCss: normalizedCssSource.css
955
661
  });
956
662
  }
957
663
  async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
@@ -965,10 +671,10 @@ function countRuntimeCandidateHits(candidates, runtime) {
965
671
  for (const candidate of candidates) if (runtime.has(candidate)) hits += 1;
966
672
  return hits;
967
673
  }
968
- async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandlerOptions, sourceOptions, selectionOptions) {
674
+ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandlerOptions, sourceOptions, selectionOptions) {
969
675
  const cssSources = sourceOptions.cssSources;
970
676
  const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
971
- if (!cssHandlerOptions.isMainChunk || !cssSources?.length || !getSourceCandidatesForEntries) return;
677
+ if (!cssSources?.length || !getSourceCandidatesForEntries) return;
972
678
  const matches = [];
973
679
  await Promise.all(cssSources.map(async (cssSource, index) => {
974
680
  const resolved = await resolveTailwindV4CssSourceEntries(cssSource, sourceOptions);
@@ -989,22 +695,19 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandler
989
695
  const second = matches[1];
990
696
  if (!best) return;
991
697
  if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
992
- return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions);
698
+ return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, { matched: true });
993
699
  }
994
700
  function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
995
- return (cssSource) => require_v3_engine.resolveTailwindV4Source({
996
- ...require_v3_engine.omitUndefined(sourceOptions),
997
- cssSources: [cssSource]
998
- }).then((source) => generatorOptions?.config ? {
701
+ return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
999
702
  ...source,
1000
- css: prependConfigDirective(source.css, generatorOptions.config)
703
+ css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1001
704
  } : source);
1002
705
  }
1003
706
  async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
1004
707
  if (!resolvedEntrySource) return;
1005
708
  const resolvedSourceOptions = require_v3_engine.omitUndefined(sourceOptions);
1006
709
  const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
1007
- const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
710
+ const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
1008
711
  return withMatchedSourceSideMetadata(await require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1009
712
  base: resolvedEntrySource.base,
1010
713
  css
@@ -1016,6 +719,15 @@ function withGeneratorSourceMetadata(source, metadata) {
1016
719
  __weappTailwindcssMeta: metadata
1017
720
  };
1018
721
  }
722
+ function resolveTailwindV3SourceEntries(source) {
723
+ if (!("version" in source) || source.version !== 3) return;
724
+ const entries = require_v3_engine.normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? node_path.default.dirname(source.config) : source.cwd });
725
+ return entries.length > 0 ? entries : void 0;
726
+ }
727
+ function withTailwindV3SourceMetadata(source) {
728
+ const sourceEntries = resolveTailwindV3SourceEntries(source);
729
+ return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
730
+ }
1019
731
  function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
1020
732
  return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
1021
733
  matchedCssSourceFile: resolvedEntrySource.file,
@@ -1024,12 +736,12 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
1024
736
  }) : source;
1025
737
  }
1026
738
  function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
1027
- if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
739
+ if (!require_v3_engine.hasTailwindApplyDirective(css) || require_v3_engine.hasTailwindRootDirectives(css)) return css;
1028
740
  return `@reference "${sourceOptions.packageName ?? "tailwindcss"}";\n${css}`;
1029
741
  }
1030
742
  async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1031
743
  const base = resolveCssSourceBase(file, cssHandlerOptions);
1032
- const cssEntrySource = resolveCssEntrySource(rawSource, base, {
744
+ const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, base, {
1033
745
  importFallback: generatorOptions?.importFallback ?? false,
1034
746
  removeConfig: majorVersion === 3
1035
747
  });
@@ -1038,66 +750,76 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
1038
750
  const mergedSourceOptions = require_v3_engine.omitUndefined({
1039
751
  ...sourceOptions,
1040
752
  config: generatorOptions?.config ?? sourceOptions.config,
1041
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
753
+ sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
754
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions),
755
+ cssEntries: selectionOptions?.cssEntries,
756
+ cssSources: createCssEntrySources(selectionOptions?.cssEntries)
1042
757
  });
1043
- const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
758
+ const applyEntrySource = require_v3_engine.hasTailwindApplyDirective(rawSource) ? {
1044
759
  base,
1045
760
  css: rawSource
1046
761
  } : void 0;
1047
- const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
1048
- const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
1049
- if (!resolvedEntrySource) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
1050
- if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
762
+ const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
763
+ const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
764
+ const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
765
+ if (!resolvedEntrySource) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
766
+ if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: true })) return withTailwindV3SourceMetadata(await (generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher)));
1051
767
  const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v3_engine.omitUndefined(mergedSourceOptions));
1052
- return require_v3_engine.resolveTailwindV3Source({
768
+ const sourceWithMetadata = withTailwindV3SourceMetadata(await require_v3_engine.resolveTailwindV3Source({
1053
769
  ...mergedSourceOptions,
1054
770
  base: resolvedEntrySource.base,
1055
- css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
771
+ css: require_v3_engine.normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
1056
772
  ...config ? { config } : {}
773
+ }));
774
+ return withGeneratorSourceMetadata(sourceWithMetadata, {
775
+ ...sourceWithMetadata.__weappTailwindcssMeta,
776
+ matchedCssSourceFile: resolvedEntrySource.file
1057
777
  });
1058
778
  }
1059
779
  const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
1060
780
  const resolvedSourceOptions = sourceOptions ? require_v3_engine.omitUndefined({
1061
781
  ...sourceOptions,
1062
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
782
+ sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
783
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions),
784
+ cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
785
+ cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1063
786
  }) : void 0;
1064
- const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
1065
- const sourceSideEntrySource = resolvedSourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, resolvedSourceOptions, { removeConfig: false }) : void 0;
1066
- const matchedCssSource = sourceOptions ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) : void 0;
1067
- const candidateMatchedCssSource = sourceOptions ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions) : void 0;
1068
- const configuredCssSource = sourceOptions && hasConfiguredTailwindV4CssSource(sourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await require_v3_engine.resolveTailwindV4Source(sourceOptions) : void 0;
787
+ const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
788
+ const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
789
+ const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
790
+ const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
791
+ const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
792
+ const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
793
+ const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await require_v3_engine.resolveTailwindV4Source(normalizedSourceOptions) : void 0;
1069
794
  if (configuredCssSource) return generatorOptions?.config ? {
1070
795
  ...configuredCssSource,
1071
- css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
796
+ css: require_v3_engine.prependConfigDirective(configuredCssSource.css, generatorOptions.config)
1072
797
  } : configuredCssSource;
1073
- const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
1074
- const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await require_v3_engine.resolveTailwindV4Source({
1075
- ...require_v3_engine.omitUndefined(sourceOptions),
1076
- cssEntries: [sourceOptions.cssEntries[0]]
1077
- }) : void 0;
798
+ const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
1078
799
  const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
1079
800
  if (preferredCssEntrySource) return generatorOptions?.config ? {
1080
801
  ...preferredCssEntrySource,
1081
- css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
802
+ css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1082
803
  } : preferredCssEntrySource;
1083
804
  const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
1084
805
  if (!resolvedEntrySource) {
1085
806
  const source = await require_v3_engine.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
1086
807
  return generatorOptions?.config ? {
1087
808
  ...source,
1088
- css: prependConfigDirective(source.css, generatorOptions.config)
809
+ css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1089
810
  } : source;
1090
811
  }
1091
- if (sourceSideEntrySource && resolvedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, resolvedSourceOptions, generatorOptions, file);
812
+ if (sourceSideEntrySource && normalizedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file);
1092
813
  const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
1093
- const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions ?? {});
1094
- return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions ?? {}, {
1095
- base: resolvedEntrySource.base,
814
+ const sourceBase = resolvedEntrySource === cssEntrySource && config ? node_path.default.dirname(config) : resolvedEntrySource.base;
815
+ const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), normalizedSourceOptions ?? {});
816
+ return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
817
+ base: sourceBase,
1096
818
  css
1097
819
  }));
1098
820
  }
1099
821
  async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1100
- const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
822
+ const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
1101
823
  importFallback: generatorOptions?.importFallback ?? false,
1102
824
  removeConfig: majorVersion === 3
1103
825
  });
@@ -1107,42 +829,54 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
1107
829
  }
1108
830
  let sourceOptions;
1109
831
  try {
832
+ const sourceOptionsFromPatcher = require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
833
+ const cssEntries = selectionOptions?.cssEntries ?? sourceOptionsFromPatcher.cssEntries;
1110
834
  sourceOptions = require_v3_engine.omitUndefined({
1111
- ...require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher),
1112
- ...resolveCssHandlerSourceOptions(cssHandlerOptions)
835
+ ...sourceOptionsFromPatcher,
836
+ sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
837
+ ...resolveCssHandlerSourceOptions(cssHandlerOptions),
838
+ cssEntries,
839
+ cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
1113
840
  });
1114
841
  } catch {
1115
842
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1116
843
  return resolved ? [resolved] : [];
1117
844
  }
1118
- const matchedCssEntrySource = cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
845
+ const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
1119
846
  const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
1120
847
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
1121
- const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
848
+ 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);
1122
849
  const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
1123
850
  if (sourceSideCssSource) return [sourceSideCssSource];
1124
851
  if (preferredCssEntrySource) return [generatorOptions?.config ? {
1125
852
  ...preferredCssEntrySource,
1126
- css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
853
+ css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1127
854
  } : preferredCssEntrySource];
1128
855
  if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
856
+ if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
857
+ ...source,
858
+ css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
859
+ } : source)];
1129
860
  if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
1130
861
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1131
862
  return resolved ? [resolved] : [];
1132
863
  }
1133
- const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_v3_engine.resolveTailwindV4Source({
1134
- ...require_v3_engine.omitUndefined(sourceOptions),
1135
- cssEntries: [cssEntry]
1136
- }).then((source) => generatorOptions?.config ? {
864
+ if (cssHandlerOptions.isMainChunk && !cssEntrySource && !require_v3_engine.hasTailwindGeneratedCss(rawSource) && !require_v3_engine.hasTailwindGeneratedCssMarkers(rawSource) && !require_v3_engine.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false }) && !rawSource.includes("weapp-tailwindcss generator-placeholder") && !hasConfiguredTailwindV4CssSource(sourceOptions)) {
865
+ const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
866
+ return resolved ? [resolved] : [];
867
+ }
868
+ const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
869
+ const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
1137
870
  ...source,
1138
- css: prependConfigDirective(source.css, generatorOptions.config)
871
+ css: require_v3_engine.prependConfigDirective(source.css, generatorOptions.config)
1139
872
  } : source)));
1140
873
  const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
1141
874
  return [...cssEntrySources, ...cssSources];
1142
875
  }
1143
876
  async function resolveGeneratorSourceEntries(source, runtimeState) {
1144
- if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
1145
877
  const sourceMetadata = source.__weappTailwindcssMeta;
878
+ if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
879
+ if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
1146
880
  const resolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
1147
881
  if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
1148
882
  const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
@@ -1287,7 +1021,7 @@ function removeTailwindApplyRules(rawSource) {
1287
1021
  function resolveLegacyCompatCssSource(rawSource) {
1288
1022
  const cached = legacyCompatSourceCache.get(rawSource);
1289
1023
  if (cached !== void 0) return cached;
1290
- const resolved = closeTrailingUnclosedBlocks((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(removeTailwindApplyRules(removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(stripTailwindBanners(rawSource))))));
1024
+ const resolved = closeTrailingUnclosedBlocks((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(removeTailwindApplyRules(require_v3_engine.removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(require_v3_engine.stripTailwindBanners(rawSource))))));
1291
1025
  setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
1292
1026
  return resolved;
1293
1027
  }
@@ -1296,7 +1030,7 @@ function hasContainerConfigToken(rawSource) {
1296
1030
  }
1297
1031
  function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
1298
1032
  if (hasContainerConfigToken(rawSource)) return true;
1299
- const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
1033
+ const cssEntrySource = require_v3_engine.resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
1300
1034
  if (!cssEntrySource?.config) return false;
1301
1035
  try {
1302
1036
  return /\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"));
@@ -1306,7 +1040,7 @@ function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
1306
1040
  }
1307
1041
  function hasConfiguredContainerCompatSource(source) {
1308
1042
  if (hasContainerConfigToken(source.css)) return true;
1309
- const cssEntrySource = resolveCssEntrySource(source.css, source.base);
1043
+ const cssEntrySource = require_v3_engine.resolveCssEntrySource(source.css, source.base);
1310
1044
  if (cssEntrySource?.config) try {
1311
1045
  if (/\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"))) return true;
1312
1046
  } catch {}
@@ -1321,7 +1055,7 @@ function hasConfiguredContainerCompatSources(sources) {
1321
1055
  async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1322
1056
  const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
1323
1057
  if (compatSource.trim().length === 0) return css;
1324
- if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
1058
+ if (generatorTarget !== "weapp") return require_v3_engine.createCssAppend(css, compatSource);
1325
1059
  const styleOptions = {
1326
1060
  ...cssHandlerOptions,
1327
1061
  ...generatorStyleOptions
@@ -1334,7 +1068,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
1334
1068
  }
1335
1069
  const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css), css);
1336
1070
  if (cleanedCompatCss.trim().length === 0) return css;
1337
- return createCssAppend(css, cleanedCompatCss);
1071
+ return require_v3_engine.createCssAppend(css, cleanedCompatCss);
1338
1072
  }
1339
1073
  async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
1340
1074
  const compatSource = resolveLegacyCompatCssSource(rawSource);
@@ -1352,7 +1086,7 @@ async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, con
1352
1086
  }
1353
1087
  const cleanedCompatCss = collectDedupedPostTransformCompatCss((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(compatCss), css);
1354
1088
  if (cleanedCompatCss.trim().length === 0) return css;
1355
- return createCssAppend(css, cleanedCompatCss);
1089
+ return require_v3_engine.createCssAppend(css, cleanedCompatCss);
1356
1090
  }
1357
1091
  //#endregion
1358
1092
  //#region src/bundlers/shared/generator-css/legacy-units.ts
@@ -1525,15 +1259,17 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
1525
1259
  if (target !== "weapp") return css;
1526
1260
  return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
1527
1261
  cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
1262
+ isTailwindcssV4: majorVersion === 4,
1528
1263
  preservePseudoContentInit: majorVersion === 3
1529
1264
  });
1530
1265
  }
1531
1266
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
1532
- if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.isolateCssSource) return scopedRuntime;
1267
+ if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
1268
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
1533
1269
  return new Set([...scopedRuntime, ...runtime]);
1534
1270
  }
1535
- function shouldIsolateMatchedCssSource(source, sourceEntries) {
1536
- return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile && sourceEntries !== void 0);
1271
+ function shouldIsolateScopedCssSource(source, sourceEntries) {
1272
+ return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
1537
1273
  }
1538
1274
  function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
1539
1275
  if (majorVersion !== 4 || isolateCssSource) return false;
@@ -1595,11 +1331,11 @@ function shouldFinalizeMarkedUserLayerComponentsCss(file) {
1595
1331
  return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
1596
1332
  }
1597
1333
  function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
1598
- const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
1334
+ const placeholderParts = require_v3_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
1599
1335
  if (placeholderParts) return placeholderParts;
1600
- const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
1336
+ const exactParts = require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
1601
1337
  if (exactParts) return exactParts;
1602
- return splitTailwindGeneratedCssByBanner(rawSource);
1338
+ return require_v3_engine.splitTailwindGeneratedCssByBanner(rawSource);
1603
1339
  }
1604
1340
  function splitUserCssLayerBlocks(source) {
1605
1341
  if (!source.includes("@layer")) return {
@@ -1681,9 +1417,9 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
1681
1417
  }
1682
1418
  async function transformGeneratorUserCss(source, options) {
1683
1419
  if (source.trim().length === 0) return "";
1684
- const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1420
+ const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1685
1421
  if (cleanedSource.trim().length === 0) return "";
1686
- const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
1422
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
1687
1423
  if (userSource.trim().length === 0) return "";
1688
1424
  if (isCommentOnlyCss(userSource)) return userSource;
1689
1425
  if (options.generatorTarget !== "weapp") return userSource;
@@ -1700,7 +1436,7 @@ function isPureLocalCssImportWrapper(css) {
1700
1436
  for (const node of root.nodes) {
1701
1437
  if (node.type === "comment") continue;
1702
1438
  if (node.type !== "atrule" || node.name !== "import") return false;
1703
- const request = parseImportRequest(node.params);
1439
+ const request = require_v3_engine.parseImportRequest(node.params);
1704
1440
  if (!request || !isLocalImportRequest(request)) return false;
1705
1441
  hasImport = true;
1706
1442
  }
@@ -1717,7 +1453,7 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1717
1453
  for (const node of root.nodes) {
1718
1454
  if (node.type === "comment") continue;
1719
1455
  if (node.type === "atrule" && node.name === "import") {
1720
- const request = parseImportRequest(node.params);
1456
+ const request = require_v3_engine.parseImportRequest(node.params);
1721
1457
  if (!request || !isLocalImportRequest(request)) return;
1722
1458
  hasLocalImport = true;
1723
1459
  continue;
@@ -1731,13 +1467,13 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1731
1467
  } catch {
1732
1468
  return;
1733
1469
  }
1734
- return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
1470
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v3_engine.removeTailwindSourceDirectives(css)) : void 0;
1735
1471
  }
1736
1472
  function prefixLocalCssImportsWithWebpackIgnore(css) {
1737
1473
  try {
1738
1474
  const root = postcss.default.parse(css);
1739
1475
  root.walkAtRules("import", (atRule) => {
1740
- const request = parseImportRequest(atRule.params);
1476
+ const request = require_v3_engine.parseImportRequest(atRule.params);
1741
1477
  if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
1742
1478
  });
1743
1479
  return root.toString();
@@ -1752,7 +1488,7 @@ async function generateCssByGenerator(options) {
1752
1488
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1753
1489
  };
1754
1490
  const majorVersion = runtimeState.twPatcher.majorVersion;
1755
- const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1491
+ const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1756
1492
  const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
1757
1493
  if (cleanedLocalImportWrapper !== void 0) return {
1758
1494
  css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
@@ -1761,29 +1497,37 @@ async function generateCssByGenerator(options) {
1761
1497
  dependencies: []
1762
1498
  };
1763
1499
  if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
1764
- const hasGeneratedCss = hasTailwindGeneratedCss(effectiveRawSource);
1765
- const hasSourceDirectives = hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1766
- const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(effectiveRawSource);
1500
+ const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(effectiveRawSource);
1501
+ const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1502
+ const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(effectiveRawSource);
1767
1503
  const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1768
1504
  if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1769
1505
  try {
1770
1506
  await runtimeState.readyPromise;
1771
- const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { bareArbitraryValues: generatorOptions.bareArbitraryValues }) : [];
1507
+ const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
1772
1508
  const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
1773
1509
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
1510
+ cssEntries: opts.cssEntries,
1774
1511
  getSourceCandidatesForEntries,
1775
1512
  runtime: runtimeWithCurrentCss
1776
1513
  });
1777
1514
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1778
1515
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1779
- const generatedResults = await Promise.all(sources.map(async (source) => {
1516
+ const generatedResults = (await Promise.all(sources.map(async (source) => {
1780
1517
  const generator = require_generator.createWeappTailwindcssGenerator(source);
1781
- const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1518
+ const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1782
1519
  const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
1783
- const isolateCssSource = shouldIsolateMatchedCssSource(source, sourceEntries);
1520
+ const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
1521
+ const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
1522
+ if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
1523
+ debug("defer empty scoped css source generation: %s", file);
1524
+ return;
1525
+ }
1784
1526
  const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
1527
+ currentCssCandidates,
1785
1528
  cssHandlerOptions,
1786
- isolateCssSource
1529
+ isolateCssSource,
1530
+ matchedCssSourceFile
1787
1531
  }) : runtimeWithCurrentCss;
1788
1532
  const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
1789
1533
  return generator.generate({
@@ -1795,7 +1539,7 @@ async function generateCssByGenerator(options) {
1795
1539
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1796
1540
  target: generatorOptions.target
1797
1541
  });
1798
- }));
1542
+ }))).filter((item) => Boolean(item));
1799
1543
  const firstGenerated = generatedResults[0];
1800
1544
  if (!firstGenerated) return;
1801
1545
  const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
@@ -1812,9 +1556,9 @@ async function generateCssByGenerator(options) {
1812
1556
  };
1813
1557
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
1814
1558
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
1815
- const incrementalCss = stripTailwindBanner(generated.incrementalCss);
1559
+ const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
1816
1560
  return {
1817
- css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1561
+ css: incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1818
1562
  target: generated.target,
1819
1563
  source: "generator",
1820
1564
  dependencies: generated.dependencies,
@@ -1822,9 +1566,10 @@ async function generateCssByGenerator(options) {
1822
1566
  };
1823
1567
  }
1824
1568
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
1825
- const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1569
+ const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1570
+ const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
1826
1571
  if (orderedExtraCss) {
1827
- let css = stripTailwindBanner(generated.css);
1572
+ let css = require_v3_engine.stripTailwindBanner(generated.css);
1828
1573
  if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1829
1574
  const userCssOptions = {
1830
1575
  generatorTarget: generated.target,
@@ -1848,11 +1593,11 @@ async function generateCssByGenerator(options) {
1848
1593
  const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
1849
1594
  css = createCssSourceOrderAppend(css, userCss);
1850
1595
  }
1851
- if (generated.target === "weapp") {
1596
+ if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
1852
1597
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1853
1598
  css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1854
1599
  css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1855
- }
1600
+ } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1856
1601
  return {
1857
1602
  css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1858
1603
  target: generated.target,
@@ -1861,7 +1606,7 @@ async function generateCssByGenerator(options) {
1861
1606
  };
1862
1607
  }
1863
1608
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
1864
- let css = stripTailwindBanner(generated.css);
1609
+ let css = require_v3_engine.stripTailwindBanner(generated.css);
1865
1610
  if (generated.target === "weapp") {
1866
1611
  css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1867
1612
  if (hasUserCssLayerBlocks(effectiveRawSource)) {
@@ -1873,7 +1618,7 @@ async function generateCssByGenerator(options) {
1873
1618
  styleHandler,
1874
1619
  importFallback: generatorOptions.importFallback
1875
1620
  });
1876
- const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
1621
+ const layerCss = layerUserCss.trim().length > 0 && !require_v3_engine.hasTailwindApplyDirective(layerUserCss) ? {
1877
1622
  layer: layerUserCss,
1878
1623
  rest: css
1879
1624
  } : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
@@ -1884,6 +1629,17 @@ async function generateCssByGenerator(options) {
1884
1629
  }
1885
1630
  }
1886
1631
  if (hasMatchedCssSourceFile || generated.target === "web") {
1632
+ if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
1633
+ const userCss = await transformGeneratorUserCss(effectiveRawSource, {
1634
+ generatorTarget: generated.target,
1635
+ generatorStyleOptions,
1636
+ cssUserHandlerOptions,
1637
+ styleHandler,
1638
+ importFallback: generatorOptions.importFallback
1639
+ });
1640
+ css = createCssSourceOrderAppend(css, userCss);
1641
+ }
1642
+ if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1887
1643
  if (shouldAppendWebBundleCssFallback(generated.target, {
1888
1644
  hasSourceDirectives,
1889
1645
  hasMatchedCssSourceFile
@@ -1925,7 +1681,10 @@ async function validateCandidatesByGenerator(options) {
1925
1681
  ...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
1926
1682
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1927
1683
  };
1928
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, { runtime: candidates });
1684
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
1685
+ cssEntries: opts.cssEntries,
1686
+ runtime: candidates
1687
+ });
1929
1688
  const classSets = await Promise.all(sources.map(async (source) => {
1930
1689
  const generator = require_generator.createWeappTailwindcssGenerator(source);
1931
1690
  if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
@@ -2107,8 +1866,126 @@ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
2107
1866
  for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
2108
1867
  return nextBaseClassSet;
2109
1868
  }
1869
+ function isUrlLikeCandidate(candidate) {
1870
+ return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
1871
+ }
1872
+ const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
1873
+ "accent",
1874
+ "animate",
1875
+ "basis",
1876
+ "bg",
1877
+ "blur",
1878
+ "border",
1879
+ "bottom",
1880
+ "brightness",
1881
+ "caret",
1882
+ "col",
1883
+ "columns",
1884
+ "content",
1885
+ "contrast",
1886
+ "decoration",
1887
+ "delay",
1888
+ "divide",
1889
+ "drop-shadow",
1890
+ "duration",
1891
+ "ease",
1892
+ "fill",
1893
+ "font",
1894
+ "gap",
1895
+ "gradient",
1896
+ "grid",
1897
+ "grayscale",
1898
+ "grow",
1899
+ "h",
1900
+ "hue-rotate",
1901
+ "indent",
1902
+ "inset",
1903
+ "invert",
1904
+ "leading",
1905
+ "left",
1906
+ "list",
1907
+ "m",
1908
+ "max",
1909
+ "mb",
1910
+ "min",
1911
+ "ml",
1912
+ "mr",
1913
+ "mt",
1914
+ "mx",
1915
+ "my",
1916
+ "object",
1917
+ "opacity",
1918
+ "order",
1919
+ "outline",
1920
+ "overflow",
1921
+ "p",
1922
+ "pb",
1923
+ "pl",
1924
+ "pr",
1925
+ "pt",
1926
+ "px",
1927
+ "py",
1928
+ "right",
1929
+ "ring",
1930
+ "rotate",
1931
+ "rounded",
1932
+ "row",
1933
+ "saturate",
1934
+ "scale",
1935
+ "scroll",
1936
+ "sepia",
1937
+ "shadow",
1938
+ "shrink",
1939
+ "skew",
1940
+ "space",
1941
+ "stroke",
1942
+ "text",
1943
+ "top",
1944
+ "tracking",
1945
+ "translate",
1946
+ "underline",
1947
+ "w",
1948
+ "z"
1949
+ ]);
1950
+ function getBaseUtilityCandidate(candidate) {
1951
+ let bracketDepth = 0;
1952
+ let lastVariantSeparator = -1;
1953
+ for (let index = 0; index < candidate.length; index++) {
1954
+ const char = candidate[index];
1955
+ if (char === "[") bracketDepth += 1;
1956
+ else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
1957
+ else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
1958
+ }
1959
+ let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
1960
+ if (utility.startsWith("!")) utility = utility.slice(1);
1961
+ if (utility.startsWith("-")) utility = utility.slice(1);
1962
+ return utility;
1963
+ }
1964
+ function getArbitraryUtilityPrefix(utility) {
1965
+ const bracketIndex = utility.indexOf("[");
1966
+ if (bracketIndex <= 0 || !utility.endsWith("]")) return;
1967
+ const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
1968
+ const firstDash = prefix.indexOf("-");
1969
+ return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
1970
+ }
1971
+ function isLikelyTailwindV3ArbitraryUtility(candidate) {
1972
+ const utility = getBaseUtilityCandidate(candidate);
1973
+ if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
1974
+ const prefix = getArbitraryUtilityPrefix(utility);
1975
+ return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
1976
+ }
1977
+ function isLikelyTailwindV3VariantUtility(candidate) {
1978
+ if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
1979
+ const utility = getBaseUtilityCandidate(candidate);
1980
+ return /^[!-]?[a-z@[]/.test(utility);
1981
+ }
1982
+ function isLikelyTailwindV3OpacityModifier(candidate) {
1983
+ if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
1984
+ const utility = getBaseUtilityCandidate(candidate);
1985
+ return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
1986
+ }
2110
1987
  function isHighConfidenceV3Candidate(candidate) {
2111
- return candidate.includes("[") || candidate.includes(":") || candidate.includes("/");
1988
+ return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
2112
1989
  }
2113
1990
  function isRawCandidateInClassContext(source, start, extension) {
2114
1991
  if (typeof start !== "number" || start <= 0) return false;
@@ -2153,7 +2030,7 @@ function createHighConfidenceLiteralRanges(source, matches) {
2153
2030
  for (const match of matches) {
2154
2031
  const candidate = match?.rawCandidate;
2155
2032
  if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
2156
- const range = resolveQuotedLiteralRange(source, match.start);
2033
+ const range = resolveQuotedLiteralRange(source, match.start ?? source.indexOf(candidate));
2157
2034
  if (range) ranges.push(range);
2158
2035
  }
2159
2036
  return ranges;
@@ -2244,7 +2121,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
2244
2121
  const nextBaseClassSet = options.baseClassSet;
2245
2122
  const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
2246
2123
  for (const [file, previousCandidates] of candidatesByFile) {
2247
- if (currentRuntimeFiles.has(file)) continue;
2124
+ if (currentRuntimeFiles.has(file) || snapshot.hasOmittedKnownFiles) continue;
2248
2125
  removeCandidateSet(candidateCountByClass, previousCandidates);
2249
2126
  candidatesByFile.delete(file);
2250
2127
  }
@@ -2316,48 +2193,18 @@ Object.defineProperty(exports, "generateCssByGenerator", {
2316
2193
  return generateCssByGenerator;
2317
2194
  }
2318
2195
  });
2319
- Object.defineProperty(exports, "hasTailwindGeneratedCssMarkers", {
2320
- enumerable: true,
2321
- get: function() {
2322
- return hasTailwindGeneratedCssMarkers;
2323
- }
2324
- });
2325
- Object.defineProperty(exports, "hasTailwindRootDirectives", {
2326
- enumerable: true,
2327
- get: function() {
2328
- return hasTailwindRootDirectives;
2329
- }
2330
- });
2331
- Object.defineProperty(exports, "hasTailwindSourceDirectives", {
2332
- enumerable: true,
2333
- get: function() {
2334
- return hasTailwindSourceDirectives;
2335
- }
2336
- });
2337
2196
  Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
2338
2197
  enumerable: true,
2339
2198
  get: function() {
2340
2199
  return mergeMarkedUserLayerComponentsCss;
2341
2200
  }
2342
2201
  });
2343
- Object.defineProperty(exports, "normalizeTailwindSourceForGenerator", {
2344
- enumerable: true,
2345
- get: function() {
2346
- return normalizeTailwindSourceForGenerator;
2347
- }
2348
- });
2349
2202
  Object.defineProperty(exports, "processCachedTask", {
2350
2203
  enumerable: true,
2351
2204
  get: function() {
2352
2205
  return processCachedTask;
2353
2206
  }
2354
2207
  });
2355
- Object.defineProperty(exports, "removeTailwindSourceDirectives", {
2356
- enumerable: true,
2357
- get: function() {
2358
- return removeTailwindSourceDirectives;
2359
- }
2360
- });
2361
2208
  Object.defineProperty(exports, "validateCandidatesByGenerator", {
2362
2209
  enumerable: true,
2363
2210
  get: function() {