weapp-tailwindcss 5.1.9 → 5.1.11

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 (55) hide show
  1. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +1 -0
  2. package/dist/bundlers/shared/generator-css/output-import-shell.d.ts +4 -0
  3. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -0
  4. package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
  5. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
  6. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +2 -0
  7. package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +1 -0
  8. package/dist/bundlers/vite/hot-css-modules.d.ts +1 -1
  9. package/dist/bundlers/vite/source-candidates.d.ts +7 -2
  10. package/dist/bundlers/vite/web-css-compat.d.ts +3 -0
  11. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +9 -0
  12. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +3 -0
  13. package/dist/cli.js +3 -2
  14. package/dist/cli.mjs +2 -1
  15. package/dist/{context-CfXr3hWz.mjs → context-DzkSFEVL.mjs} +4 -4
  16. package/dist/{context-CRhUs_5e.js → context-y2BGCok4.js} +10 -10
  17. package/dist/core.js +1 -1
  18. package/dist/core.mjs +1 -1
  19. package/dist/generator/options.d.ts +8 -1
  20. package/dist/{v4-engine-BZP2462H.js → generator-Bz94KTkH.js} +229 -17
  21. package/dist/{v4-engine-CjjWONB0.mjs → generator-ROzBodj6.mjs} +185 -9
  22. package/dist/generator.js +7 -8
  23. package/dist/generator.mjs +1 -2
  24. package/dist/{gulp-CRjkPsbX.mjs → gulp-BKqMb_Ds.mjs} +4 -4
  25. package/dist/{gulp-JUfnhOOo.js → gulp-DfOLvYLs.js} +10 -10
  26. package/dist/gulp.js +1 -1
  27. package/dist/gulp.mjs +1 -1
  28. package/dist/{hmr-timing-DcIEXnf8.js → hmr-timing-DOTdH18A.js} +556 -170
  29. package/dist/{hmr-timing-BecOXMd8.mjs → hmr-timing-DwtYJdwb.mjs} +430 -56
  30. package/dist/index.js +4 -4
  31. package/dist/index.mjs +4 -4
  32. package/dist/postcss.js +2 -3
  33. package/dist/postcss.mjs +1 -2
  34. package/dist/presets.js +7 -6
  35. package/dist/presets.mjs +5 -4
  36. package/dist/rspack.js +1 -1
  37. package/dist/rspack.mjs +1 -1
  38. package/dist/{source-candidate-scan-signature-10tvdJVC.js → source-candidate-scan-signature-BrWuBTjY.js} +34 -6
  39. package/dist/{source-candidate-scan-signature-DAg8QSgh.mjs → source-candidate-scan-signature-CQ04hiox.mjs} +29 -7
  40. package/dist/{tailwindcss-BZjZZi60.js → tailwindcss-Dn5DVlkI.js} +55 -47
  41. package/dist/{tailwindcss-PA2jHHpx.mjs → tailwindcss-hzy_WaC9.mjs} +14 -6
  42. package/dist/{transform-wNEbcZeQ.mjs → transform-BgnNYkIG.mjs} +1 -1
  43. package/dist/{transform-B0BxX3XB.js → transform-DZQETx51.js} +1 -1
  44. package/dist/{vite-CHk7V9EA.js → vite-DODC15Fr.js} +865 -254
  45. package/dist/{vite-ClpyoD9e.mjs → vite-oI2ReOic.mjs} +818 -207
  46. package/dist/vite.js +1 -1
  47. package/dist/vite.mjs +1 -1
  48. package/dist/weapp-tw-css-import-rewrite-loader.js +613 -63
  49. package/dist/{webpack-2s-TFhgm.mjs → webpack-CCapGlNg.mjs} +235 -38
  50. package/dist/{webpack-BhM4Hqla.js → webpack-XxBCIrBp.js} +276 -79
  51. package/dist/webpack.js +1 -1
  52. package/dist/webpack.mjs +1 -1
  53. package/package.json +5 -5
  54. package/dist/generator-DaaFxR5V.js +0 -174
  55. package/dist/generator-DugIHBgl.mjs +0 -127
@@ -1,7 +1,6 @@
1
- import { $ as hasTailwindGeneratedCssMarkers, A as stripTailwindSourceMediaFragments, C as isCommentOnlyCss, D as removeTailwindV4GeneratorAtRules, E as removeTailwindV4GeneratedUserCssArtifacts, Et as omitUndefined, H as hasTailwindSourceDirectives, I as removeUnsupportedMiniProgramAtRules, J as resolveCssEntrySource, K as parseImportRequest, M as transformGeneratorUserCss, N as finalizeMiniProgramCss, O as shouldFilterApplyOnlyGeneratedCss, Q as hasTailwindGeneratedCss, S as hasUserCssLayerBlocks, St as toPosixPath$1, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, V as hasTailwindRootDirectives, W as normalizeTailwindSourceDirectives, X as VITE_MARKER_RE, Y as GENERATOR_PLACEHOLDER_MARKER_RE, Z as createCssAppend, at as stripTailwindBanners, b as extractGeneratedCssForUserLayerSelectors, bt as resolveSourceScanPath, et as splitGeneratorPlaceholderCssBySourceOrder, ft as FULL_SOURCE_SCAN_EXTENSION_RE, gt as isFileMatchedByTailwindSourceEntries, i as resolveTailwindV4SourceOptionsFromRuntime, it as stripTailwindBanner, j as stripUnmatchedTailwindSourceMediaCloseFragments, k as splitUserCssLayerBlocks, kt as loadTailwindV4DesignSystem, n as resolveTailwindV4SourceFromRuntime, nt as splitTailwindV4GeneratedCssBySourceOrder, ot as normalizeConfigDirective, q as removeTailwindSourceDirectives, rt as stripGeneratorPlaceholderMarkers, st as prependConfigDirective, t as resolveTailwindV4Source$1, tt as splitTailwindGeneratedCssByBanner, w as normalizeEmptyTailwindCustomVariants, x as filterApplyOnlyGeneratedCss, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-CjjWONB0.mjs";
2
- import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-DugIHBgl.mjs";
3
- import { S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext, w as md5Hash } from "./context-CfXr3hWz.mjs";
4
- import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled, v as includesTailwindV4PreflightDirective } from "./tailwindcss-PA2jHHpx.mjs";
1
+ import { A as hasUserCssLayerBlocks, At as toPosixPath$1, B as transformGeneratorUserCss, F as removeTailwindV4GeneratorAtRules, Ft as loadTailwindV4DesignSystem, I as shouldFilterApplyOnlyGeneratedCss, L as splitUserCssLayerBlocks, M as normalizeEmptyTailwindCustomVariants, Nt as filterUnsupportedMiniProgramTailwindV4Candidates, O as extractGeneratedCssForUserLayerSelectors, Ot as resolveSourceScanPath, P as removeTailwindV4GeneratedUserCssArtifacts, Pt as omitUndefined, Q as normalizeTailwindSourceDirectives, R as stripTailwindSourceMediaFragments, V as finalizeMiniProgramCss, W as removeUnsupportedMiniProgramAtRules, X as hasTailwindSourceDirectives, Y as hasTailwindRootDirectives, a as resolveGeneratorRuntimeBranch, at as createCssAppend, bt as FULL_SOURCE_SCAN_EXTENSION_RE, ct as splitGeneratorPlaceholderCssBySourceOrder, dt as stripGeneratorPlaceholderMarkers, et as parseImportRequest, f as resolveTailwindV4SourceOptionsFromRuntime, ft as stripTailwindBanner, ht as prependConfigDirective, i as normalizeWeappTailwindcssGeneratorOptions, it as VITE_MARKER_RE, j as isCommentOnlyCss, k as filterApplyOnlyGeneratedCss, kt as resolveTailwindV4CssSourceBase, l as resolveTailwindV4Source$1, lt as splitTailwindGeneratedCssByBanner, mt as normalizeConfigDirective, nt as resolveCssEntrySource, ot as hasTailwindGeneratedCss, pt as stripTailwindBanners, q as hasTailwindApplyDirective, rt as GENERATOR_PLACEHOLDER_MARKER_RE, s as shouldUseMiniProgramCssBranch, st as hasTailwindGeneratedCssMarkers, t as createWeappTailwindcssGenerator, tt as removeTailwindSourceDirectives, u as resolveTailwindV4SourceFromRuntime, ut as splitTailwindV4GeneratedCssBySourceOrder, wt as isFileMatchedByTailwindSourceEntries, z as stripUnmatchedTailwindSourceMediaCloseFragments } from "./generator-ROzBodj6.mjs";
2
+ import { S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext, w as md5Hash } from "./context-DzkSFEVL.mjs";
3
+ import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled, v as includesTailwindV4PreflightDirective } from "./tailwindcss-hzy_WaC9.mjs";
5
4
  import { existsSync, readFileSync } from "node:fs";
6
5
  import path from "node:path";
7
6
  import process from "node:process";
@@ -293,6 +292,119 @@ function createCssSourceOrderAppend$1(base, extra) {
293
292
  if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
294
293
  return `${base}\n${extra}`;
295
294
  }
295
+ const LEGACY_PSEUDO_ELEMENTS$1 = [
296
+ "before",
297
+ "after",
298
+ "first-letter",
299
+ "first-line"
300
+ ];
301
+ const CSS_STRING_LITERAL_RE = /(["'])((?:\\[\s\S]|(?!\1)[\s\S])*)\1/g;
302
+ function isLegacyPseudoElementAt$1(selector, index) {
303
+ for (const name of LEGACY_PSEUDO_ELEMENTS$1) {
304
+ if (!selector.startsWith(name, index)) continue;
305
+ const next = selector[index + name.length];
306
+ if (next === void 0 || !/[\w-]/.test(next)) return name;
307
+ }
308
+ }
309
+ function normalizeLegacyPseudoElements$1(selector) {
310
+ let result = "";
311
+ let quote;
312
+ let bracketDepth = 0;
313
+ let index = 0;
314
+ while (index < selector.length) {
315
+ const char = selector[index];
316
+ if (char === "\\") {
317
+ result += selector.slice(index, index + 2);
318
+ index += 2;
319
+ continue;
320
+ }
321
+ if (quote !== void 0) {
322
+ result += char;
323
+ if (char === quote) quote = void 0;
324
+ index += 1;
325
+ continue;
326
+ }
327
+ if (char === "\"" || char === "'") {
328
+ quote = char;
329
+ result += char;
330
+ index += 1;
331
+ continue;
332
+ }
333
+ if (char === "[") {
334
+ bracketDepth++;
335
+ result += char;
336
+ index += 1;
337
+ continue;
338
+ }
339
+ if (char === "]") {
340
+ bracketDepth = Math.max(0, bracketDepth - 1);
341
+ result += char;
342
+ index += 1;
343
+ continue;
344
+ }
345
+ if (bracketDepth === 0 && char === ":" && selector[index + 1] === ":") {
346
+ result += "::";
347
+ index += 2;
348
+ continue;
349
+ }
350
+ if (bracketDepth === 0 && char === ":") {
351
+ const name = isLegacyPseudoElementAt$1(selector, index + 1);
352
+ if (name) {
353
+ result += `::${name}`;
354
+ index += name.length + 1;
355
+ continue;
356
+ }
357
+ }
358
+ result += char;
359
+ index += 1;
360
+ }
361
+ return result;
362
+ }
363
+ function normalizeCssRuleDeduplicationSelector(selector) {
364
+ return normalizeLegacyPseudoElements$1(selector).replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
365
+ }
366
+ function normalizeCssRuleDeduplicationValue(value) {
367
+ return value.replace(/\s+/g, " ").replace(CSS_STRING_LITERAL_RE, (_match, _quote, content) => {
368
+ return `'${content.replace(/\\(["'])/g, "$1").replace(/'/g, "\\'")}'`;
369
+ }).trim();
370
+ }
371
+ function createRuleDeduplicationKey(rule) {
372
+ const parents = [];
373
+ let parent = rule.parent;
374
+ while (parent && parent.type !== "root") {
375
+ if (parent.type === "atrule") parents.push(`${parent.name}:${parent.params}`);
376
+ parent = parent.parent;
377
+ }
378
+ const declarations = (rule.nodes ?? []).map((node) => {
379
+ if (node.type === "decl") return `${node.prop}:${normalizeCssRuleDeduplicationValue(node.value)}:${node.important ? "1" : "0"}`;
380
+ if (node.type === "comment") return "";
381
+ return normalizeCssRuleDeduplicationValue(node.toString());
382
+ }).filter(Boolean);
383
+ const selectors = (rule.selectors?.length ? rule.selectors : [rule.selector]).map(normalizeCssRuleDeduplicationSelector);
384
+ return [
385
+ parents.reverse().join("|"),
386
+ selectors.join(","),
387
+ declarations.join(";")
388
+ ].join("\n");
389
+ }
390
+ function deduplicateGeneratedCssRules(css) {
391
+ if (!css) return css;
392
+ try {
393
+ const root = postcss.parse(css);
394
+ const seen = /* @__PURE__ */ new Set();
395
+ root.walkRules((rule) => {
396
+ const key = createRuleDeduplicationKey(rule);
397
+ if (seen.has(key)) {
398
+ rule.remove();
399
+ return;
400
+ }
401
+ seen.add(key);
402
+ });
403
+ return root.toString();
404
+ } catch {
405
+ return css;
406
+ }
407
+ }
296
408
  function shouldFinalizeMarkedUserLayerComponentsCss(file) {
297
409
  return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
298
410
  }
@@ -320,8 +432,8 @@ function mergeGeneratorResults(generatedResults) {
320
432
  const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
321
433
  return {
322
434
  ...firstGenerated,
323
- css: generatedResults.map((item) => item.css).join("\n"),
324
- rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
435
+ css: deduplicateGeneratedCssRules(generatedResults.map((item) => item.css).join("\n")),
436
+ rawCss: deduplicateGeneratedCssRules(generatedResults.map((item) => item.rawCss).join("\n")),
325
437
  incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
326
438
  incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
327
439
  classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
@@ -340,6 +452,12 @@ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
340
452
  ]);
341
453
  const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
342
454
  const SELECTOR_CACHE_LIMIT = 64;
455
+ const LEGACY_PSEUDO_ELEMENTS = [
456
+ "before",
457
+ "after",
458
+ "first-letter",
459
+ "first-line"
460
+ ];
343
461
  const generatedSelectorCache = /* @__PURE__ */ new Map();
344
462
  function setGeneratedSelectorCache(css, selectors) {
345
463
  if (generatedSelectorCache.size >= SELECTOR_CACHE_LIMIT) {
@@ -351,6 +469,67 @@ function setGeneratedSelectorCache(css, selectors) {
351
469
  function normalizeCompatSelector(selector) {
352
470
  return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
353
471
  }
472
+ function isLegacyPseudoElementAt(selector, index) {
473
+ for (const name of LEGACY_PSEUDO_ELEMENTS) {
474
+ if (!selector.startsWith(name, index)) continue;
475
+ const next = selector[index + name.length];
476
+ if (next === void 0 || !/[\w-]/.test(next)) return name;
477
+ }
478
+ }
479
+ function normalizeLegacyPseudoElements(selector) {
480
+ let result = "";
481
+ let quote;
482
+ let bracketDepth = 0;
483
+ let index = 0;
484
+ while (index < selector.length) {
485
+ const char = selector[index];
486
+ if (char === "\\") {
487
+ result += selector.slice(index, index + 2);
488
+ index += 2;
489
+ continue;
490
+ }
491
+ if (quote !== void 0) {
492
+ result += char;
493
+ if (char === quote) quote = void 0;
494
+ index += 1;
495
+ continue;
496
+ }
497
+ if (char === "\"" || char === "'") {
498
+ quote = char;
499
+ result += char;
500
+ index += 1;
501
+ continue;
502
+ }
503
+ if (char === "[") {
504
+ bracketDepth++;
505
+ result += char;
506
+ index += 1;
507
+ continue;
508
+ }
509
+ if (char === "]") {
510
+ bracketDepth = Math.max(0, bracketDepth - 1);
511
+ result += char;
512
+ index += 1;
513
+ continue;
514
+ }
515
+ if (bracketDepth === 0 && char === ":" && selector[index + 1] === ":") {
516
+ result += "::";
517
+ index += 2;
518
+ continue;
519
+ }
520
+ if (bracketDepth === 0 && char === ":") {
521
+ const name = isLegacyPseudoElementAt(selector, index + 1);
522
+ if (name) {
523
+ result += `::${name}`;
524
+ index += name.length + 1;
525
+ continue;
526
+ }
527
+ }
528
+ result += char;
529
+ index += 1;
530
+ }
531
+ return result;
532
+ }
354
533
  function isClassSelectorTerminator(char) {
355
534
  return /[\s>+~#,.:()[\]]/.test(char);
356
535
  }
@@ -401,7 +580,7 @@ function normalizeCompatSelectors(selector) {
401
580
  return [...selectors];
402
581
  }
403
582
  function normalizeCssSelector(selector) {
404
- return selector.trim().replace(/\s+/g, "");
583
+ return normalizeLegacyPseudoElements(selector).trim().replace(/\s+/g, "");
405
584
  }
406
585
  function getCompatSelectorKeys(selector) {
407
586
  return normalizeCompatSelectors(selector).map(normalizeCssSelector);
@@ -855,10 +1034,26 @@ function stripBundlerContentHash(name) {
855
1034
  function getMatchBasename(file) {
856
1035
  return stripBundlerContentHash(path.basename(getOutputFileWithoutExtension(file.replace(/[?#].*$/, ""))));
857
1036
  }
1037
+ function getMatchDirname(file) {
1038
+ const normalized = normalizeMatchPath(file);
1039
+ const dirname = path.posix.dirname(normalized);
1040
+ return dirname === "." ? "" : dirname;
1041
+ }
858
1042
  function isPathWithinRoot(file, root) {
859
1043
  const relative = path.relative(root, file);
860
1044
  return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
861
1045
  }
1046
+ function collectParentDirectories(file) {
1047
+ const directories = [];
1048
+ let current = path.dirname(path.resolve(file.replace(/[?#].*$/, "")));
1049
+ while (true) {
1050
+ directories.push(current);
1051
+ const parent = path.dirname(current);
1052
+ if (parent === current) break;
1053
+ current = parent;
1054
+ }
1055
+ return directories;
1056
+ }
862
1057
  function collectCssSourceMatchBases(file, roots) {
863
1058
  const normalizedFile = file.replace(/[?#].*$/, "");
864
1059
  const bases = /* @__PURE__ */ new Set();
@@ -880,13 +1075,18 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
880
1075
  sourceOptions.cwd
881
1076
  ]);
882
1077
  const sourceBases = collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]);
1078
+ const sourceDirectoryIndexBases = collectCssSourceMatchBases(cssSourceFile, collectParentDirectories(cssSourceFile));
883
1079
  const outputBasename = getMatchBasename(file);
884
1080
  const sourceBasename = getMatchBasename(cssSourceFile);
885
1081
  let bestScore = 0;
886
- for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
887
- else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
888
- else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
889
- if (outputBasename && outputBasename === sourceBasename) bestScore = Math.max(bestScore, 100 + outputBasename.length);
1082
+ for (const outputBase of outputBases) {
1083
+ for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
1084
+ else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
1085
+ else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
1086
+ else if (getMatchBasename(sourceBase) === "index" && getMatchDirname(sourceBase).length > 0 && outputBase.startsWith(`${getMatchDirname(sourceBase)}/`)) bestScore = Math.max(bestScore, 25e3 + getMatchDirname(sourceBase).length);
1087
+ for (const sourceBase of sourceDirectoryIndexBases) if (getMatchBasename(sourceBase) === "index" && getMatchDirname(sourceBase).length > 0 && outputBase.startsWith(`${getMatchDirname(sourceBase)}/`)) bestScore = Math.max(bestScore, 25e3 + getMatchDirname(sourceBase).length);
1088
+ }
1089
+ if (outputBasename && outputBasename === sourceBasename && outputBasename !== "index") bestScore = Math.max(bestScore, 100 + outputBasename.length);
890
1090
  return bestScore;
891
1091
  }
892
1092
  //#endregion
@@ -946,6 +1146,7 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options
946
1146
  ...omitUndefined(singleEntrySourceOptions),
947
1147
  cssEntries: [cssEntry]
948
1148
  }), {
1149
+ candidateMatchedCssSource: options.candidateMatched,
949
1150
  cssEntryIndex: options.index,
950
1151
  includesPreflight: options.includesPreflight,
951
1152
  primaryCssSource: options.index === 0
@@ -963,6 +1164,7 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options
963
1164
  css: normalizeConfigDirective(css, config),
964
1165
  cssEntries: [cssEntry]
965
1166
  }), {
1167
+ candidateMatchedCssSource: options.candidateMatched,
966
1168
  cssEntryIndex: options.index,
967
1169
  includesPreflight: options.includesPreflight,
968
1170
  matchedCssSourceFile: cssEntry,
@@ -1196,6 +1398,7 @@ async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectio
1196
1398
  if (!best) return;
1197
1399
  if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
1198
1400
  return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
1401
+ candidateMatched: true,
1199
1402
  includesPreflight: best.includesPreflight,
1200
1403
  index: best.index
1201
1404
  });
@@ -1219,13 +1422,14 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
1219
1422
  css,
1220
1423
  cssEntries: [resolvedEntrySource.file]
1221
1424
  }));
1222
- const cssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1223
- const cssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && path.resolve(cssSource.file.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1425
+ const matchedCssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1426
+ const matchedCssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && path.resolve(cssSource.file.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1427
+ const resolvedEntries = await resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base);
1224
1428
  return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
1225
- cssEntryIndex,
1226
- cssSourceIndex,
1227
- includesPreflight: (await resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base))?.includesPreflight,
1228
- primaryCssSource: cssEntryIndex === 0 || !sourceOptions.cssEntries?.length && cssSourceIndex === 0
1429
+ cssEntryIndex: matchedCssEntryIndex !== void 0 && matchedCssEntryIndex >= 0 ? matchedCssEntryIndex : void 0,
1430
+ cssSourceIndex: matchedCssSourceIndex !== void 0 && matchedCssSourceIndex >= 0 ? matchedCssSourceIndex : void 0,
1431
+ includesPreflight: resolvedEntries?.includesPreflight,
1432
+ primaryCssSource: matchedCssEntryIndex === 0 || !sourceOptions.cssEntries?.length && matchedCssSourceIndex === 0
1229
1433
  });
1230
1434
  }
1231
1435
  async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
@@ -1645,6 +1849,81 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
1645
1849
  }
1646
1850
  }
1647
1851
  //#endregion
1852
+ //#region src/bundlers/shared/generator-css/output-import-shell.ts
1853
+ const MINI_PROGRAM_OUTPUT_IMPORT_RE = /(@import\s+(?:url\(\s*)?)(["'])([^"']+\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:[?#][^"']*)?)\2([^;]*;)/gi;
1854
+ const MINI_PROGRAM_OUTPUT_STYLE_RE = /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
1855
+ function normalizeMiniProgramOutputImportRequest(request) {
1856
+ if (request.startsWith(".") || request.startsWith("/") || /^(?:[a-z][a-z\d+.-]*:|#)/i.test(request)) return request;
1857
+ return `./${request}`;
1858
+ }
1859
+ function normalizeMiniProgramImportShell(css) {
1860
+ return css.replace(MINI_PROGRAM_OUTPUT_IMPORT_RE, (_match, prefix, quote, request, suffix) => {
1861
+ return `${prefix}${quote}${normalizeMiniProgramOutputImportRequest(request)}${quote}${suffix}`;
1862
+ });
1863
+ }
1864
+ function normalizeOutputPath(file) {
1865
+ const segments = [];
1866
+ for (const segment of file.replace(/\\/g, "/").replace(/^\/+/, "").split("/")) {
1867
+ if (!segment || segment === ".") continue;
1868
+ if (segment === "..") {
1869
+ if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
1870
+ else segments.push(segment);
1871
+ continue;
1872
+ }
1873
+ segments.push(segment);
1874
+ }
1875
+ return segments.join("/");
1876
+ }
1877
+ function splitRequestSuffix(request) {
1878
+ const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
1879
+ const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
1880
+ return suffixIndex < 0 ? request : request.slice(0, suffixIndex);
1881
+ }
1882
+ function resolveOutputImportRequest(file, request) {
1883
+ const cleanRequest = splitRequestSuffix(request.replace(/\\/g, "/"));
1884
+ if (cleanRequest.startsWith("/")) return normalizeOutputPath(cleanRequest);
1885
+ const normalizedFile = normalizeOutputPath(file);
1886
+ const baseDir = normalizedFile.includes("/") ? normalizedFile.slice(0, normalizedFile.lastIndexOf("/")) : "";
1887
+ return normalizeOutputPath(baseDir ? `${baseDir}/${cleanRequest}` : cleanRequest);
1888
+ }
1889
+ function isMiniProgramOutputImport(node) {
1890
+ if (node.type !== "atrule" || node.name !== "import") return false;
1891
+ const request = parseImportRequest(node.params);
1892
+ return request !== void 0 && MINI_PROGRAM_OUTPUT_STYLE_RE.test(request);
1893
+ }
1894
+ function isSelfMiniProgramOutputImport(outputFile, node) {
1895
+ if (!isMiniProgramOutputImport(node) || node.type !== "atrule") return false;
1896
+ const request = parseImportRequest(node.params);
1897
+ return request !== void 0 && resolveOutputImportRequest(outputFile, request) === normalizeOutputPath(outputFile);
1898
+ }
1899
+ function removeMiniProgramOutputImportsBy(css, predicate) {
1900
+ if (!css.includes("@import")) return css;
1901
+ try {
1902
+ const root = postcss.parse(css);
1903
+ let changed = false;
1904
+ root.walk((node) => {
1905
+ if (predicate(node)) {
1906
+ node.remove();
1907
+ changed = true;
1908
+ }
1909
+ });
1910
+ return changed ? root.toString() : css;
1911
+ } catch {
1912
+ return css;
1913
+ }
1914
+ }
1915
+ function removeSelfMiniProgramOutputImports(css, outputFile) {
1916
+ return removeMiniProgramOutputImportsBy(css, (node) => isSelfMiniProgramOutputImport(outputFile, node));
1917
+ }
1918
+ function removeMiniProgramOutputImports(css) {
1919
+ return removeMiniProgramOutputImportsBy(css, isMiniProgramOutputImport);
1920
+ }
1921
+ function normalizeMiniProgramGeneratorCssSource(css, outputFile) {
1922
+ const normalized = normalizeMiniProgramImportShell(css);
1923
+ if (outputFile) return removeSelfMiniProgramOutputImports(normalized, outputFile);
1924
+ return isPureLocalCssImportWrapper(normalized) ? normalized : removeMiniProgramOutputImports(normalized);
1925
+ }
1926
+ //#endregion
1648
1927
  //#region src/bundlers/shared/generator-css/user-layer-order.ts
1649
1928
  const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
1650
1929
  const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
@@ -1808,19 +2087,22 @@ async function validateCandidatesByGenerator(options) {
1808
2087
  if (majorVersion !== 4 || candidates.size === 0) return /* @__PURE__ */ new Set();
1809
2088
  const classSet = /* @__PURE__ */ new Set();
1810
2089
  try {
1811
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, {
2090
+ const generatorOptions = {
1812
2091
  ...normalizeWeappTailwindcssGeneratorOptions(opts.generator),
1813
2092
  bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues
1814
- }, {
1815
- cssEntries: opts.cssEntries,
1816
- runtime: candidates
1817
- });
1818
- const classSets = await Promise.all(sources.map(async (source) => {
1819
- const generator = createWeappTailwindcssGenerator(source);
1820
- if (typeof generator.validateCandidates !== "function") return /* @__PURE__ */ new Set();
1821
- return generator.validateCandidates(candidates);
1822
- }));
1823
- for (const candidate of classSets.flatMap((item) => [...item])) classSet.add(candidate);
2093
+ };
2094
+ if (generatorOptions.enabled) {
2095
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, {
2096
+ cssEntries: opts.cssEntries,
2097
+ runtime: candidates
2098
+ });
2099
+ const classSets = await Promise.all(sources.map(async (source) => {
2100
+ const generator = createWeappTailwindcssGenerator(source);
2101
+ if (typeof generator.validateCandidates !== "function") return /* @__PURE__ */ new Set();
2102
+ return generator.validateCandidates(candidates);
2103
+ }));
2104
+ for (const candidate of classSets.flatMap((item) => [...item])) classSet.add(candidate);
2105
+ }
1824
2106
  } catch {}
1825
2107
  const rawSourceCandidates = collectGeneratedRawSourceCandidates(candidates, rawSource, opts.escapeMap);
1826
2108
  for (const candidate of rawSourceCandidates) classSet.add(candidate);
@@ -1835,6 +2117,15 @@ function resolveGeneratorSourceConcurrency() {
1835
2117
  if (Number.isFinite(configured) && configured > 0) return configured;
1836
2118
  return 1;
1837
2119
  }
2120
+ function hasPostcssUserPlugins(options) {
2121
+ const plugins = options.postcssOptions?.plugins;
2122
+ if (Array.isArray(plugins)) return plugins.length > 0;
2123
+ return typeof plugins === "object" && plugins !== null && Object.keys(plugins).length > 0;
2124
+ }
2125
+ function shouldProcessDisabledGeneratorCss(rawSource, options) {
2126
+ if (!hasPostcssUserPlugins(options)) return false;
2127
+ return /@import\s+(?:url\(\s*)?["']tailwindcss(?:\/[^"')\s]*)?["']/.test(rawSource) || hasTailwindApplyDirective(rawSource);
2128
+ }
1838
2129
  function intersectCandidateSets(left, right) {
1839
2130
  if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
1840
2131
  const [small, large] = left.size <= right.size ? [left, right] : [right, left];
@@ -1890,9 +2181,18 @@ function mergeGeneratedCssClassSet(classSet, candidates, css, escapeMap) {
1890
2181
  for (const candidate of collectGeneratedRawSourceCandidates(candidates, css, escapeMap)) merged.add(candidate);
1891
2182
  return merged;
1892
2183
  }
2184
+ function resolveGeneratedCssClassSet(target, classSet, candidates, css, escapeMap, previousClassSet) {
2185
+ if (target === "web") return /* @__PURE__ */ new Set([...previousClassSet ?? [], ...classSet]);
2186
+ return mergeGeneratedCssClassSet(classSet, candidates, css, escapeMap);
2187
+ }
1893
2188
  function finalizeWebGeneratorCss(css, target, webCompat) {
1894
2189
  return target === "web" ? transformWebCssCompat(css, webCompat) : css;
1895
2190
  }
2191
+ function finalizeIncrementalGeneratorCss(previousCss, incrementalCss, target, majorVersion, cssPreflight, options, webCompat) {
2192
+ const finalizedIncrementalCss = finalizeMiniProgramGeneratorCss(incrementalCss, target, majorVersion, cssPreflight, options);
2193
+ if (target === "web") return createCssAppend(previousCss, finalizeWebGeneratorCss(finalizedIncrementalCss, target, webCompat));
2194
+ return createCssAppend(previousCss, finalizedIncrementalCss);
2195
+ }
1896
2196
  async function generateCssByGenerator(options) {
1897
2197
  const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, generatorPlatform, userRawSource, userRawSourceProcessed, debug } = options;
1898
2198
  const platform = generatorPlatform ?? opts.cssOptions?.platform ?? opts.platform;
@@ -1913,7 +2213,37 @@ async function generateCssByGenerator(options) {
1913
2213
  });
1914
2214
  const majorVersion = runtimeState.tailwindRuntime.majorVersion;
1915
2215
  if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
1916
- const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback }))));
2216
+ const useMiniProgramCssBranch = shouldUseMiniProgramCssBranch(generatorBranch);
2217
+ const normalizeGeneratorCssSource = (css) => {
2218
+ return useMiniProgramCssBranch ? normalizeMiniProgramGeneratorCssSource(css, file) : css;
2219
+ };
2220
+ const normalizeGeneratorSource = (source) => {
2221
+ const css = normalizeGeneratorCssSource(source.css);
2222
+ return css === source.css ? source : {
2223
+ ...source,
2224
+ css
2225
+ };
2226
+ };
2227
+ if (!generatorOptions.enabled) {
2228
+ debug("tailwind direct css generation disabled: %s", file);
2229
+ if (shouldProcessDisabledGeneratorCss(rawSource, cssHandlerOptions)) {
2230
+ const handled = await styleHandler(rawSource, cssHandlerOptions);
2231
+ return {
2232
+ css: finalizeWebGeneratorCss(handled.css, generatorOptions.target, generatorOptions.webCompat),
2233
+ classSet: resolveGeneratedCssClassSet(generatorOptions.target, /* @__PURE__ */ new Set(), runtime, handled.css, opts.escapeMap, options.previousClassSet),
2234
+ target: generatorOptions.target,
2235
+ source: "generator",
2236
+ dependencies: [],
2237
+ metadata: {
2238
+ file,
2239
+ majorVersion,
2240
+ rawCss: rawSource
2241
+ }
2242
+ };
2243
+ }
2244
+ return;
2245
+ }
2246
+ const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeGeneratorCssSource(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })))));
1917
2247
  const effectiveRawSourceRoot = parseCssSourceRoot(effectiveRawSource);
1918
2248
  const cleanedLocalImportWrapper = cleanLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
1919
2249
  if (cleanedLocalImportWrapper !== void 0) return {
@@ -1934,9 +2264,10 @@ async function generateCssByGenerator(options) {
1934
2264
  return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports, { outputFile: file }), target, generatorOptions.webCompat);
1935
2265
  };
1936
2266
  const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
1937
- const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback }))));
2267
+ const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeEmptyTailwindCustomVariants(normalizeGeneratorCssSource(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })))));
1938
2268
  const userSource = (rawUserSource === generatorRawSource ? void 0 : splitLocalCssImports(rawUserSource))?.source ?? rawUserSource;
1939
2269
  const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
2270
+ const hasWebUserCssFallbackSource = userCssRawSource.trim().length > 0 && !isCommentOnlyCss(userCssRawSource);
1940
2271
  const generatedUserCssOrderSource = hasTailwindGeneratedCss(userSource) ? splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
1941
2272
  const generatedUserCssRawSource = generatedUserCssOrderSource ? createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
1942
2273
  const userCssOrderSource = GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
@@ -1944,10 +2275,13 @@ async function generateCssByGenerator(options) {
1944
2275
  const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
1945
2276
  const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
1946
2277
  const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
1947
- const normalizedCssSources = options.cssSources?.map((source) => ({
1948
- ...source,
1949
- css: normalizeEmptyTailwindCustomVariants(source.css)
1950
- }));
2278
+ const normalizedCssSources = options.cssSources?.map((source) => {
2279
+ const css = normalizeGeneratorCssSource(normalizeEmptyTailwindCustomVariants(source.css));
2280
+ return css === source.css ? source : {
2281
+ ...source,
2282
+ css
2283
+ };
2284
+ });
1951
2285
  if (!shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
1952
2286
  forceGenerator: options.forceGenerator,
1953
2287
  hasGeneratedCss,
@@ -1973,11 +2307,15 @@ async function generateCssByGenerator(options) {
1973
2307
  getSourceCandidatesForEntries,
1974
2308
  runtime: runtimeWithCurrentCss
1975
2309
  });
2310
+ const generatorSources = useMiniProgramCssBranch ? sources.map(normalizeGeneratorSource) : sources;
1976
2311
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1977
- const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
2312
+ const configuredContainerCompat = hasConfiguredContainerCompatSources(generatorSources);
1978
2313
  const sourceConcurrency = resolveGeneratorSourceConcurrency();
1979
- const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
1980
- const generator = createWeappTailwindcssGenerator(source);
2314
+ const generated = mergeGeneratorResults((await runWithConcurrency(generatorSources.map((source) => async () => {
2315
+ const generator = createWeappTailwindcssGenerator(options.disableSourceScan === true ? {
2316
+ ...source,
2317
+ css: removeTailwindSourceDirectives(source.css, { importFallback: generatorOptions.importFallback })
2318
+ } : source);
1981
2319
  const sourceEntries = getSourceCandidatesForEntries ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
1982
2320
  const sourceScopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
1983
2321
  const scopedRuntime = resolveScopedRuntimeCandidates(options.sourceCandidates, sourceScopedRuntime);
@@ -2003,7 +2341,7 @@ async function generateCssByGenerator(options) {
2003
2341
  bareArbitraryValues: generatorOptions.bareArbitraryValues,
2004
2342
  candidates: generatorRuntime,
2005
2343
  incrementalCache: true,
2006
- scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
2344
+ scanSources: options.disableSourceScan === true ? false : shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
2007
2345
  styleOptions: generatorStyleOptions,
2008
2346
  target: generatorOptions.target
2009
2347
  });
@@ -2012,13 +2350,14 @@ async function generateCssByGenerator(options) {
2012
2350
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
2013
2351
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
2014
2352
  const incrementalCss = stripTailwindBanner(generated.incrementalCss);
2015
- const finalCss = finalizeWebGeneratorCss(restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
2353
+ const css = incrementalCss.trim().length > 0 ? finalizeIncrementalGeneratorCss(options.previousCss, incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
2016
2354
  injectPreflight: false,
2017
2355
  styleOptions: generatorStyleOptions
2018
- })) : options.previousCss, localImports, { outputFile: file }), generated.target, generatorOptions.webCompat);
2356
+ }, generatorOptions.webCompat) : options.previousCss;
2357
+ const finalCss = generated.target === "web" ? restoreLocalCssImports(css, localImports, { outputFile: file }) : finalizeWebGeneratorCss(restoreLocalCssImports(css, localImports, { outputFile: file }), generated.target, generatorOptions.webCompat);
2019
2358
  return {
2020
2359
  css: finalCss,
2021
- classSet: mergeGeneratedCssClassSet(generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap),
2360
+ classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
2022
2361
  target: generated.target,
2023
2362
  source: "generator",
2024
2363
  dependencies: generated.dependencies,
@@ -2036,19 +2375,26 @@ async function generateCssByGenerator(options) {
2036
2375
  });
2037
2376
  const generatedCssSource = generated.target === "web" ? generated.css : stripTailwindBanner(generated.css);
2038
2377
  const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource, { preserveVariables: generated.target !== "web" }) : generatedCssSource;
2039
- const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
2040
- const hasExplicitCssSource = sources.some((source) => {
2378
+ const hasMatchedCssSourceFile = generatorSources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
2379
+ const hasExplicitCssSource = generatorSources.some((source) => {
2380
+ const metadata = source.__weappTailwindcssMeta;
2381
+ return metadata?.candidateMatchedCssSource !== true && (metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0);
2382
+ });
2383
+ const hasPreflightCssSource = generatorSources.some((source) => {
2041
2384
  const metadata = source.__weappTailwindcssMeta;
2042
- return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
2385
+ const appEntryMatchedByCandidates = metadata?.candidateMatchedCssSource === true && metadata.cssEntryIndex === 0 && metadata.cssSourceIndex === void 0;
2386
+ return metadata?.includesPreflight === true && !appEntryMatchedByCandidates;
2043
2387
  });
2044
- const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
2045
2388
  const hasPreflightRawSource = includesTailwindV4PreflightDirective(generatorRawSource);
2046
2389
  const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
2047
2390
  cssHandlerOptions,
2048
2391
  isolateCurrentCssCandidates,
2049
2392
  localImports,
2050
2393
  explicitCssSource: hasExplicitCssSource,
2051
- primaryCssSource: sources.length > 0 && sources.every((source) => source.__weappTailwindcssMeta?.primaryCssSource === true) || hasPreflightCssSource || hasPreflightRawSource
2394
+ primaryCssSource: generatorSources.length > 0 && generatorSources.every((source) => {
2395
+ const metadata = source.__weappTailwindcssMeta;
2396
+ return metadata?.candidateMatchedCssSource !== true && metadata?.primaryCssSource === true;
2397
+ }) || hasPreflightCssSource || hasPreflightRawSource
2052
2398
  });
2053
2399
  const orderedExtraCss = splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
2054
2400
  const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
@@ -2072,14 +2418,14 @@ async function generateCssByGenerator(options) {
2072
2418
  const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
2073
2419
  const fallbackLayerUserCss = generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource) ? filterExistingCssRules(afterLayerUserCss, await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions)) : "";
2074
2420
  css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
2075
- if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
2421
+ if (hasWebUserCssFallbackSource && isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
2076
2422
  hasSourceDirectives,
2077
2423
  hasMatchedCssSourceFile
2078
2424
  })) {
2079
2425
  const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
2080
2426
  css = createCssSourceOrderAppend$1(css, userCss);
2081
2427
  }
2082
- if (generated.target === "web") {
2428
+ if (generated.target === "web" && hasWebUserCssFallbackSource) {
2083
2429
  const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
2084
2430
  const missingUserCss = isCommentOnlyCss(userCss) ? "" : filterExistingCssRules(css, userCss);
2085
2431
  css = createCssSourceOrderAppend$1(css, missingUserCss);
@@ -2103,7 +2449,7 @@ async function generateCssByGenerator(options) {
2103
2449
  });
2104
2450
  return {
2105
2451
  css: finalCss,
2106
- classSet: mergeGeneratedCssClassSet(generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap),
2452
+ classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
2107
2453
  target: generated.target,
2108
2454
  source: "generator",
2109
2455
  dependencies: generated.dependencies,
@@ -2186,7 +2532,7 @@ async function generateCssByGenerator(options) {
2186
2532
  if (hasMatchedCssSourceFile && generated.target === "weapp") {
2187
2533
  if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss && !userRawSourceProcessed && !hasGeneratedCss && !hasGeneratedMarkers) css = await appendLegacyContainerCompatCss(css, generatedUserCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
2188
2534
  }
2189
- if (shouldAppendWebBundleCssFallback(generated.target, {
2535
+ if (hasWebUserCssFallbackSource && shouldAppendWebBundleCssFallback(generated.target, {
2190
2536
  hasSourceDirectives,
2191
2537
  hasMatchedCssSourceFile
2192
2538
  })) {
@@ -2208,7 +2554,7 @@ async function generateCssByGenerator(options) {
2208
2554
  });
2209
2555
  return {
2210
2556
  css: finalCss,
2211
- classSet: mergeGeneratedCssClassSet(generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap),
2557
+ classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
2212
2558
  target: generated.target,
2213
2559
  source: "generator",
2214
2560
  dependencies: generated.dependencies,
@@ -2242,7 +2588,7 @@ async function generateCssByGenerator(options) {
2242
2588
  });
2243
2589
  return {
2244
2590
  css: finalCss,
2245
- classSet: mergeGeneratedCssClassSet(generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap),
2591
+ classSet: resolveGeneratedCssClassSet(generated.target, generated.classSet, runtimeWithCurrentCss, finalCss, opts.escapeMap, options.previousClassSet),
2246
2592
  target: generated.target,
2247
2593
  source: "generator",
2248
2594
  dependencies: generated.dependencies,
@@ -2672,6 +3018,7 @@ function createDefaultIgnoredSources(root, outDirIgnore, entries, explicit) {
2672
3018
  }
2673
3019
  function resolveSourceCandidateScanFiles(options) {
2674
3020
  const resolvedRoot = path.resolve(options.root);
3021
+ if (options.explicit && options.entries?.length && options.entries.every((entry) => entry.negated)) return Promise.resolve([]);
2675
3022
  const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, options.outDir);
2676
3023
  const scanEntries = normalizeScanEntries(resolvedRoot, options.entries, outDirIgnore);
2677
3024
  const ignoredSources = createDefaultIgnoredSources(resolvedRoot, outDirIgnore, options.entries, options.explicit);
@@ -2716,6 +3063,16 @@ function removeCandidateSet(candidateCount, candidates) {
2716
3063
  function addCandidateSet(candidateCount, candidates) {
2717
3064
  for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
2718
3065
  }
3066
+ function diffCandidateSets(previous, next) {
3067
+ const addedCandidates = /* @__PURE__ */ new Set();
3068
+ const removedCandidates = /* @__PURE__ */ new Set();
3069
+ for (const candidate of next) if (!previous.has(candidate)) addedCandidates.add(candidate);
3070
+ for (const candidate of previous) if (!next.has(candidate)) removedCandidates.add(candidate);
3071
+ return {
3072
+ addedCandidates,
3073
+ removedCandidates
3074
+ };
3075
+ }
2719
3076
  function createSourceCandidateStore(options = {}) {
2720
3077
  const candidatesById = /* @__PURE__ */ new Map();
2721
3078
  const scanCandidatesById = /* @__PURE__ */ new Map();
@@ -2776,11 +3133,25 @@ function createSourceCandidateStore(options = {}) {
2776
3133
  throw error;
2777
3134
  }
2778
3135
  }
2779
- async function syncCurrentFile(id) {
3136
+ async function syncCurrentSource(id, source) {
2780
3137
  const normalizedId = cleanUrl(id);
2781
3138
  transformCandidatesById.delete(normalizedId);
2782
3139
  cssCandidatesById.delete(normalizedId);
2783
- await syncFile(normalizedId);
3140
+ transformSourceById.delete(normalizedId);
3141
+ cssSourceById.delete(normalizedId);
3142
+ recompute(normalizedId);
3143
+ const previousCandidates = values();
3144
+ await sync(normalizedId, source);
3145
+ return diffCandidateSets(previousCandidates, values());
3146
+ }
3147
+ async function syncCurrentFile(id) {
3148
+ const normalizedId = cleanUrl(id);
3149
+ try {
3150
+ return await syncCurrentSource(normalizedId, await readFile(normalizedId, "utf8"));
3151
+ } catch (error) {
3152
+ if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) === "ENOENT") return remove(normalizedId);
3153
+ throw error;
3154
+ }
2784
3155
  }
2785
3156
  async function scanRoot({ entries, explicit, root, outDir }) {
2786
3157
  const files = await resolveSourceCandidateScanFiles({
@@ -2835,6 +3206,7 @@ function createSourceCandidateStore(options = {}) {
2835
3206
  }
2836
3207
  function remove(id) {
2837
3208
  const normalizedId = cleanUrl(id);
3209
+ const previousValues = values();
2838
3210
  scanCandidatesById.delete(normalizedId);
2839
3211
  transformCandidatesById.delete(normalizedId);
2840
3212
  cssCandidatesById.delete(normalizedId);
@@ -2842,9 +3214,10 @@ function createSourceCandidateStore(options = {}) {
2842
3214
  transformSourceById.delete(normalizedId);
2843
3215
  cssSourceById.delete(normalizedId);
2844
3216
  const previousCandidates = candidatesById.get(normalizedId);
2845
- if (!previousCandidates) return;
3217
+ if (!previousCandidates) return diffCandidateSets(previousValues, values());
2846
3218
  removeCandidateSet(candidateCount, previousCandidates);
2847
3219
  candidatesById.delete(normalizedId);
3220
+ return diffCandidateSets(previousValues, values());
2848
3221
  }
2849
3222
  function source(id) {
2850
3223
  const normalizedId = cleanUrl(id);
@@ -2971,6 +3344,7 @@ function createSourceCandidateStore(options = {}) {
2971
3344
  syncCss,
2972
3345
  merge,
2973
3346
  syncFile,
3347
+ syncCurrentSource,
2974
3348
  syncCurrentFile,
2975
3349
  scanRoot,
2976
3350
  syncInline,
@@ -3076,4 +3450,4 @@ function createHmrTimingRecorder(bundler) {
3076
3450
  };
3077
3451
  }
3078
3452
  //#endregion
3079
- export { hasMiniProgramTailwindV4PreflightReset as C, isCssSourceTraceEnabled as D, createCssTokenSourceMap as E, processCachedTask as O, createCssSourceOrderAppend$1 as S, createCssSourceTraceCacheSignature as T, isPureLocalCssImportWrapper as _, isSourceCandidateRequest as a, scoreTailwindV4CssSourceFileMatch as b, collectStrictEscapedRuntimeCandidates as c, validateCandidatesByGenerator as d, pushConcurrentTaskFactories as f, mergeMarkedUserLayerComponentsCss as g, extractMarkedUserLayerComponentsCss as h, createSourceCandidateStore as i, createEscapeFragments as l, runWithConcurrency as m, emitHmrTiming as n, resolveSourceCandidateScanFiles as o, resolveTaskConcurrency as p, createSourceCandidateCollector as r, createBundleRuntimeClassSetManager as s, createHmrTimingRecorder as t, generateCssByGenerator as u, rewriteLocalCssImportRequestsForOutput as v, annotateCssSourceTrace as w, removeGeneratedSelectorCompatCss as x, splitLocalCssImports as y };
3453
+ export { processCachedTask as A, removeGeneratedSelectorCompatCss as C, createCssSourceTraceCacheSignature as D, annotateCssSourceTrace as E, createCssTokenSourceMap as O, scoreTailwindV4CssSourceFileMatch as S, hasMiniProgramTailwindV4PreflightReset as T, normalizeMiniProgramGeneratorCssSource as _, isSourceCandidateRequest as a, rewriteLocalCssImportRequestsForOutput as b, collectStrictEscapedRuntimeCandidates as c, validateCandidatesByGenerator as d, pushConcurrentTaskFactories as f, mergeMarkedUserLayerComponentsCss as g, extractMarkedUserLayerComponentsCss as h, createSourceCandidateStore as i, isCssSourceTraceEnabled as k, createEscapeFragments as l, runWithConcurrency as m, emitHmrTiming as n, resolveSourceCandidateScanFiles as o, resolveTaskConcurrency as p, createSourceCandidateCollector as r, createBundleRuntimeClassSetManager as s, createHmrTimingRecorder as t, generateCssByGenerator as u, normalizeMiniProgramImportShell as v, createCssSourceOrderAppend$1 as w, splitLocalCssImports as x, isPureLocalCssImportWrapper as y };