weapp-tailwindcss 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{bundle-state-DgGEhk_z.js → bundle-state-Bvj01pW7.js} +35 -3
  2. package/dist/{bundle-state-CnaJxkFY.mjs → bundle-state-DY3eq4Gz.mjs} +24 -4
  3. package/dist/bundlers/shared/generated-css-marker.d.ts +6 -0
  4. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
  5. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -5
  6. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css.d.ts +1 -0
  8. package/dist/bundlers/vite/bundle-state.d.ts +5 -1
  9. package/dist/bundlers/vite/css-finalizer.d.ts +12 -3
  10. package/dist/bundlers/vite/generate-bundle.d.ts +22 -6
  11. package/dist/bundlers/vite/processed-css-assets.d.ts +10 -2
  12. package/dist/bundlers/vite/source-candidates.d.ts +2 -0
  13. package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +8 -0
  14. package/dist/cli.js +1 -0
  15. package/dist/cli.mjs +1 -0
  16. package/dist/core.js +1 -1
  17. package/dist/core.mjs +1 -1
  18. package/dist/{generator--0-ekuVO.js → generator-Bd1LntD3.js} +1 -1
  19. package/dist/{generator-B76ovqsv.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-CN6K_97P.js → incremental-runtime-class-set-Bl18sFqt.js} +540 -694
  25. package/dist/{incremental-runtime-class-set-x10M9bn_.mjs → incremental-runtime-class-set-CAEuUesH.mjs} +495 -619
  26. package/dist/index.js +4 -4
  27. package/dist/index.mjs +4 -4
  28. package/dist/{postcss-CR9UCaIK.mjs → postcss-CJrmfXvi.mjs} +4 -4
  29. package/dist/{postcss-hYimKoN_.js → postcss-DfnqZ4Bm.js} +4 -4
  30. package/dist/postcss.js +1 -1
  31. package/dist/postcss.mjs +1 -1
  32. package/dist/{precheck-DPtJjZmV.js → precheck-Bj5ReSOU.js} +2 -2
  33. package/dist/{precheck-BrNwLG2e.mjs → precheck-CUr1DYyy.mjs} +2 -2
  34. package/dist/presets.js +2 -2
  35. package/dist/presets.mjs +2 -2
  36. package/dist/{source-candidates-DN1mihlU.mjs → source-candidates-D7b-Jzsx.mjs} +44 -11
  37. package/dist/{source-candidates-DSxme_O2.js → source-candidates-DQxvGPSw.js} +49 -10
  38. package/dist/tailwindcss/source-scan.d.ts +3 -1
  39. package/dist/{tailwindcss-DWtPieNE.mjs → tailwindcss-D5RogwtV.mjs} +14 -49
  40. package/dist/{tailwindcss-glCm_d3H.js → tailwindcss-jvoYizzX.js} +19 -48
  41. package/dist/{v3-engine-DCxNPBVs.mjs → v3-engine-BCUGX3gX.mjs} +644 -36
  42. package/dist/{v3-engine-D3BMLVAN.js → v3-engine-CmIF_gsq.js} +775 -35
  43. package/dist/{vite-Ec0uX6kF.js → vite-D1ZdgbWa.js} +533 -290
  44. package/dist/{vite-DOprpdH-.mjs → vite-jBTi5CwO.mjs} +532 -289
  45. package/dist/vite.js +1 -1
  46. package/dist/vite.mjs +1 -1
  47. package/dist/{runtime-registry-DpcR3IHI.js → watch-dependencies-zwx4EhBn.js} +39 -0
  48. package/dist/weapp-tw-css-import-rewrite-loader.js +1953 -1630
  49. package/dist/weapp-tw-runtime-classset-loader.js +6 -6
  50. package/dist/{webpack-DFlZcqAU.mjs → webpack-CChDqRrl.mjs} +6 -6
  51. package/dist/{webpack-Ccohlg3A.js → webpack-vk2uqSnK.js} +7 -7
  52. package/dist/webpack.js +1 -1
  53. package/dist/webpack.mjs +1 -1
  54. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require("./chunk-C5U5_Hdc.js");
2
- const require_v3_engine = require("./v3-engine-D3BMLVAN.js");
3
- const require_generator = require("./generator--0-ekuVO.js");
4
- const require_precheck = require("./precheck-DPtJjZmV.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-Bj5ReSOU.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
@@ -1529,11 +1263,12 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
1529
1263
  });
1530
1264
  }
1531
1265
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
1532
- if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.isolateCssSource) return scopedRuntime;
1266
+ if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
1267
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
1533
1268
  return new Set([...scopedRuntime, ...runtime]);
1534
1269
  }
1535
- function shouldIsolateMatchedCssSource(source, sourceEntries) {
1536
- return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile && sourceEntries !== void 0);
1270
+ function shouldIsolateScopedCssSource(source, sourceEntries) {
1271
+ return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
1537
1272
  }
1538
1273
  function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
1539
1274
  if (majorVersion !== 4 || isolateCssSource) return false;
@@ -1595,11 +1330,11 @@ function shouldFinalizeMarkedUserLayerComponentsCss(file) {
1595
1330
  return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
1596
1331
  }
1597
1332
  function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
1598
- const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
1333
+ const placeholderParts = require_v3_engine.splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
1599
1334
  if (placeholderParts) return placeholderParts;
1600
- const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
1335
+ const exactParts = require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
1601
1336
  if (exactParts) return exactParts;
1602
- return splitTailwindGeneratedCssByBanner(rawSource);
1337
+ return require_v3_engine.splitTailwindGeneratedCssByBanner(rawSource);
1603
1338
  }
1604
1339
  function splitUserCssLayerBlocks(source) {
1605
1340
  if (!source.includes("@layer")) return {
@@ -1681,9 +1416,9 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
1681
1416
  }
1682
1417
  async function transformGeneratorUserCss(source, options) {
1683
1418
  if (source.trim().length === 0) return "";
1684
- const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1419
+ const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1685
1420
  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 }));
1421
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
1687
1422
  if (userSource.trim().length === 0) return "";
1688
1423
  if (isCommentOnlyCss(userSource)) return userSource;
1689
1424
  if (options.generatorTarget !== "weapp") return userSource;
@@ -1700,7 +1435,7 @@ function isPureLocalCssImportWrapper(css) {
1700
1435
  for (const node of root.nodes) {
1701
1436
  if (node.type === "comment") continue;
1702
1437
  if (node.type !== "atrule" || node.name !== "import") return false;
1703
- const request = parseImportRequest(node.params);
1438
+ const request = require_v3_engine.parseImportRequest(node.params);
1704
1439
  if (!request || !isLocalImportRequest(request)) return false;
1705
1440
  hasImport = true;
1706
1441
  }
@@ -1717,7 +1452,7 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1717
1452
  for (const node of root.nodes) {
1718
1453
  if (node.type === "comment") continue;
1719
1454
  if (node.type === "atrule" && node.name === "import") {
1720
- const request = parseImportRequest(node.params);
1455
+ const request = require_v3_engine.parseImportRequest(node.params);
1721
1456
  if (!request || !isLocalImportRequest(request)) return;
1722
1457
  hasLocalImport = true;
1723
1458
  continue;
@@ -1731,13 +1466,13 @@ function cleanLocalCssImportWrapperTailwindDirectives(css) {
1731
1466
  } catch {
1732
1467
  return;
1733
1468
  }
1734
- return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
1469
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(require_v3_engine.removeTailwindSourceDirectives(css)) : void 0;
1735
1470
  }
1736
1471
  function prefixLocalCssImportsWithWebpackIgnore(css) {
1737
1472
  try {
1738
1473
  const root = postcss.default.parse(css);
1739
1474
  root.walkAtRules("import", (atRule) => {
1740
- const request = parseImportRequest(atRule.params);
1475
+ const request = require_v3_engine.parseImportRequest(atRule.params);
1741
1476
  if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
1742
1477
  });
1743
1478
  return root.toString();
@@ -1752,7 +1487,7 @@ async function generateCssByGenerator(options) {
1752
1487
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1753
1488
  };
1754
1489
  const majorVersion = runtimeState.twPatcher.majorVersion;
1755
- const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1490
+ const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1756
1491
  const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
1757
1492
  if (cleanedLocalImportWrapper !== void 0) return {
1758
1493
  css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
@@ -1761,29 +1496,37 @@ async function generateCssByGenerator(options) {
1761
1496
  dependencies: []
1762
1497
  };
1763
1498
  if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
1764
- const hasGeneratedCss = hasTailwindGeneratedCss(effectiveRawSource);
1765
- const hasSourceDirectives = hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1766
- const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(effectiveRawSource);
1499
+ const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(effectiveRawSource);
1500
+ const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1501
+ const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(effectiveRawSource);
1767
1502
  const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1768
1503
  if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1769
1504
  try {
1770
1505
  await runtimeState.readyPromise;
1771
- const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { bareArbitraryValues: generatorOptions.bareArbitraryValues }) : [];
1506
+ const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
1772
1507
  const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
1773
1508
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
1509
+ cssEntries: opts.cssEntries,
1774
1510
  getSourceCandidatesForEntries,
1775
1511
  runtime: runtimeWithCurrentCss
1776
1512
  });
1777
1513
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1778
1514
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1779
- const generatedResults = await Promise.all(sources.map(async (source) => {
1515
+ const generatedResults = (await Promise.all(sources.map(async (source) => {
1780
1516
  const generator = require_generator.createWeappTailwindcssGenerator(source);
1781
- const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1517
+ const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1782
1518
  const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
1783
- const isolateCssSource = shouldIsolateMatchedCssSource(source, sourceEntries);
1519
+ const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
1520
+ const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
1521
+ if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
1522
+ debug("defer empty scoped css source generation: %s", file);
1523
+ return;
1524
+ }
1784
1525
  const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
1526
+ currentCssCandidates,
1785
1527
  cssHandlerOptions,
1786
- isolateCssSource
1528
+ isolateCssSource,
1529
+ matchedCssSourceFile
1787
1530
  }) : runtimeWithCurrentCss;
1788
1531
  const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
1789
1532
  return generator.generate({
@@ -1795,7 +1538,7 @@ async function generateCssByGenerator(options) {
1795
1538
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1796
1539
  target: generatorOptions.target
1797
1540
  });
1798
- }));
1541
+ }))).filter((item) => Boolean(item));
1799
1542
  const firstGenerated = generatedResults[0];
1800
1543
  if (!firstGenerated) return;
1801
1544
  const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
@@ -1812,9 +1555,9 @@ async function generateCssByGenerator(options) {
1812
1555
  };
1813
1556
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
1814
1557
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
1815
- const incrementalCss = stripTailwindBanner(generated.incrementalCss);
1558
+ const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
1816
1559
  return {
1817
- css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1560
+ css: incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1818
1561
  target: generated.target,
1819
1562
  source: "generator",
1820
1563
  dependencies: generated.dependencies,
@@ -1822,9 +1565,10 @@ async function generateCssByGenerator(options) {
1822
1565
  };
1823
1566
  }
1824
1567
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
1825
- const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1568
+ const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1569
+ const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
1826
1570
  if (orderedExtraCss) {
1827
- let css = stripTailwindBanner(generated.css);
1571
+ let css = require_v3_engine.stripTailwindBanner(generated.css);
1828
1572
  if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1829
1573
  const userCssOptions = {
1830
1574
  generatorTarget: generated.target,
@@ -1848,11 +1592,11 @@ async function generateCssByGenerator(options) {
1848
1592
  const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
1849
1593
  css = createCssSourceOrderAppend(css, userCss);
1850
1594
  }
1851
- if (generated.target === "weapp") {
1595
+ if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
1852
1596
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1853
1597
  css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1854
1598
  css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1855
- }
1599
+ } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1856
1600
  return {
1857
1601
  css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1858
1602
  target: generated.target,
@@ -1861,7 +1605,7 @@ async function generateCssByGenerator(options) {
1861
1605
  };
1862
1606
  }
1863
1607
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
1864
- let css = stripTailwindBanner(generated.css);
1608
+ let css = require_v3_engine.stripTailwindBanner(generated.css);
1865
1609
  if (generated.target === "weapp") {
1866
1610
  css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1867
1611
  if (hasUserCssLayerBlocks(effectiveRawSource)) {
@@ -1873,7 +1617,7 @@ async function generateCssByGenerator(options) {
1873
1617
  styleHandler,
1874
1618
  importFallback: generatorOptions.importFallback
1875
1619
  });
1876
- const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
1620
+ const layerCss = layerUserCss.trim().length > 0 && !require_v3_engine.hasTailwindApplyDirective(layerUserCss) ? {
1877
1621
  layer: layerUserCss,
1878
1622
  rest: css
1879
1623
  } : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
@@ -1884,6 +1628,17 @@ async function generateCssByGenerator(options) {
1884
1628
  }
1885
1629
  }
1886
1630
  if (hasMatchedCssSourceFile || generated.target === "web") {
1631
+ if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
1632
+ const userCss = await transformGeneratorUserCss(effectiveRawSource, {
1633
+ generatorTarget: generated.target,
1634
+ generatorStyleOptions,
1635
+ cssUserHandlerOptions,
1636
+ styleHandler,
1637
+ importFallback: generatorOptions.importFallback
1638
+ });
1639
+ css = createCssSourceOrderAppend(css, userCss);
1640
+ }
1641
+ if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1887
1642
  if (shouldAppendWebBundleCssFallback(generated.target, {
1888
1643
  hasSourceDirectives,
1889
1644
  hasMatchedCssSourceFile
@@ -1925,7 +1680,10 @@ async function validateCandidatesByGenerator(options) {
1925
1680
  ...require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator),
1926
1681
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1927
1682
  };
1928
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, { runtime: candidates });
1683
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
1684
+ cssEntries: opts.cssEntries,
1685
+ runtime: candidates
1686
+ });
1929
1687
  const classSets = await Promise.all(sources.map(async (source) => {
1930
1688
  const generator = require_generator.createWeappTailwindcssGenerator(source);
1931
1689
  if (generatorOptions.bareArbitraryValues === void 0 || generatorOptions.bareArbitraryValues === false) {
@@ -2107,8 +1865,126 @@ function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
2107
1865
  for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
2108
1866
  return nextBaseClassSet;
2109
1867
  }
1868
+ function isUrlLikeCandidate(candidate) {
1869
+ return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
1870
+ }
1871
+ const TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES = new Set([
1872
+ "accent",
1873
+ "animate",
1874
+ "basis",
1875
+ "bg",
1876
+ "blur",
1877
+ "border",
1878
+ "bottom",
1879
+ "brightness",
1880
+ "caret",
1881
+ "col",
1882
+ "columns",
1883
+ "content",
1884
+ "contrast",
1885
+ "decoration",
1886
+ "delay",
1887
+ "divide",
1888
+ "drop-shadow",
1889
+ "duration",
1890
+ "ease",
1891
+ "fill",
1892
+ "font",
1893
+ "gap",
1894
+ "gradient",
1895
+ "grid",
1896
+ "grayscale",
1897
+ "grow",
1898
+ "h",
1899
+ "hue-rotate",
1900
+ "indent",
1901
+ "inset",
1902
+ "invert",
1903
+ "leading",
1904
+ "left",
1905
+ "list",
1906
+ "m",
1907
+ "max",
1908
+ "mb",
1909
+ "min",
1910
+ "ml",
1911
+ "mr",
1912
+ "mt",
1913
+ "mx",
1914
+ "my",
1915
+ "object",
1916
+ "opacity",
1917
+ "order",
1918
+ "outline",
1919
+ "overflow",
1920
+ "p",
1921
+ "pb",
1922
+ "pl",
1923
+ "pr",
1924
+ "pt",
1925
+ "px",
1926
+ "py",
1927
+ "right",
1928
+ "ring",
1929
+ "rotate",
1930
+ "rounded",
1931
+ "row",
1932
+ "saturate",
1933
+ "scale",
1934
+ "scroll",
1935
+ "sepia",
1936
+ "shadow",
1937
+ "shrink",
1938
+ "skew",
1939
+ "space",
1940
+ "stroke",
1941
+ "text",
1942
+ "top",
1943
+ "tracking",
1944
+ "translate",
1945
+ "underline",
1946
+ "w",
1947
+ "z"
1948
+ ]);
1949
+ function getBaseUtilityCandidate(candidate) {
1950
+ let bracketDepth = 0;
1951
+ let lastVariantSeparator = -1;
1952
+ for (let index = 0; index < candidate.length; index++) {
1953
+ const char = candidate[index];
1954
+ if (char === "[") bracketDepth += 1;
1955
+ else if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
1956
+ else if (char === ":" && bracketDepth === 0) lastVariantSeparator = index;
1957
+ }
1958
+ let utility = lastVariantSeparator >= 0 ? candidate.slice(lastVariantSeparator + 1) : candidate;
1959
+ if (utility.startsWith("!")) utility = utility.slice(1);
1960
+ if (utility.startsWith("-")) utility = utility.slice(1);
1961
+ return utility;
1962
+ }
1963
+ function getArbitraryUtilityPrefix(utility) {
1964
+ const bracketIndex = utility.indexOf("[");
1965
+ if (bracketIndex <= 0 || !utility.endsWith("]")) return;
1966
+ const prefix = utility.slice(0, bracketIndex).replace(/-$/, "");
1967
+ const firstDash = prefix.indexOf("-");
1968
+ return firstDash >= 0 ? prefix.slice(0, firstDash) : prefix;
1969
+ }
1970
+ function isLikelyTailwindV3ArbitraryUtility(candidate) {
1971
+ const utility = getBaseUtilityCandidate(candidate);
1972
+ if (utility.startsWith("[") && utility.endsWith("]") && utility.includes(":")) return true;
1973
+ const prefix = getArbitraryUtilityPrefix(utility);
1974
+ return Boolean(prefix && TAILWIND_V3_ARBITRARY_UTILITY_PREFIXES.has(prefix));
1975
+ }
1976
+ function isLikelyTailwindV3VariantUtility(candidate) {
1977
+ if (!candidate.includes(":") || isUrlLikeCandidate(candidate)) return false;
1978
+ const utility = getBaseUtilityCandidate(candidate);
1979
+ return /^[!-]?[a-z@[]/.test(utility);
1980
+ }
1981
+ function isLikelyTailwindV3OpacityModifier(candidate) {
1982
+ if (!candidate.includes("/") || isUrlLikeCandidate(candidate)) return false;
1983
+ const utility = getBaseUtilityCandidate(candidate);
1984
+ return /^[!-]?[a-z][\w-]*-\w[\w-]*\/(?:\d+|\[[^\]]+\])$/.test(utility);
1985
+ }
2110
1986
  function isHighConfidenceV3Candidate(candidate) {
2111
- return candidate.includes("[") || candidate.includes(":") || candidate.includes("/");
1987
+ return isLikelyTailwindV3ArbitraryUtility(candidate) || isLikelyTailwindV3VariantUtility(candidate) || isLikelyTailwindV3OpacityModifier(candidate);
2112
1988
  }
2113
1989
  function isRawCandidateInClassContext(source, start, extension) {
2114
1990
  if (typeof start !== "number" || start <= 0) return false;
@@ -2153,7 +2029,7 @@ function createHighConfidenceLiteralRanges(source, matches) {
2153
2029
  for (const match of matches) {
2154
2030
  const candidate = match?.rawCandidate;
2155
2031
  if (typeof candidate !== "string" || !isHighConfidenceV3Candidate(candidate)) continue;
2156
- const range = resolveQuotedLiteralRange(source, match.start);
2032
+ const range = resolveQuotedLiteralRange(source, match.start ?? source.indexOf(candidate));
2157
2033
  if (range) ranges.push(range);
2158
2034
  }
2159
2035
  return ranges;
@@ -2244,7 +2120,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
2244
2120
  const nextBaseClassSet = options.baseClassSet;
2245
2121
  const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
2246
2122
  for (const [file, previousCandidates] of candidatesByFile) {
2247
- if (currentRuntimeFiles.has(file)) continue;
2123
+ if (currentRuntimeFiles.has(file) || snapshot.hasOmittedKnownFiles) continue;
2248
2124
  removeCandidateSet(candidateCountByClass, previousCandidates);
2249
2125
  candidatesByFile.delete(file);
2250
2126
  }
@@ -2316,48 +2192,18 @@ Object.defineProperty(exports, "generateCssByGenerator", {
2316
2192
  return generateCssByGenerator;
2317
2193
  }
2318
2194
  });
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
2195
  Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
2338
2196
  enumerable: true,
2339
2197
  get: function() {
2340
2198
  return mergeMarkedUserLayerComponentsCss;
2341
2199
  }
2342
2200
  });
2343
- Object.defineProperty(exports, "normalizeTailwindSourceForGenerator", {
2344
- enumerable: true,
2345
- get: function() {
2346
- return normalizeTailwindSourceForGenerator;
2347
- }
2348
- });
2349
2201
  Object.defineProperty(exports, "processCachedTask", {
2350
2202
  enumerable: true,
2351
2203
  get: function() {
2352
2204
  return processCachedTask;
2353
2205
  }
2354
2206
  });
2355
- Object.defineProperty(exports, "removeTailwindSourceDirectives", {
2356
- enumerable: true,
2357
- get: function() {
2358
- return removeTailwindSourceDirectives;
2359
- }
2360
- });
2361
2207
  Object.defineProperty(exports, "validateCandidatesByGenerator", {
2362
2208
  enumerable: true,
2363
2209
  get: function() {