weapp-tailwindcss 5.1.4 → 5.1.5

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 (53) hide show
  1. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +8 -2
  2. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +5 -1
  3. package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +6 -3
  4. package/dist/bundlers/vite/hot-css-modules.d.ts +1 -0
  5. package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
  6. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -1
  7. package/dist/cli.js +18 -3
  8. package/dist/cli.mjs +16 -1
  9. package/dist/{context-DCVMkTRj.js → context-BziwyWy1.js} +21 -6
  10. package/dist/{context-Bkpmt3ja.mjs → context-rrYZuUBU.mjs} +18 -3
  11. package/dist/core.js +1 -1
  12. package/dist/core.mjs +1 -1
  13. package/dist/css-macro/index.d.ts +2 -1
  14. package/dist/{defaults-BhE26nSw.mjs → defaults-9B6aMyZb.mjs} +2 -2
  15. package/dist/{defaults-DQhgnnn-.js → defaults-nsf4VNMX.js} +2 -2
  16. package/dist/defaults.d.ts +1 -1
  17. package/dist/defaults.js +1 -1
  18. package/dist/defaults.mjs +1 -1
  19. package/dist/{gulp-Bogfnoki.js → gulp-CuVsZdO9.js} +3 -3
  20. package/dist/{gulp-0RsqkF_d.mjs → gulp-ygWfmOqh.mjs} +3 -3
  21. package/dist/gulp.js +1 -1
  22. package/dist/gulp.mjs +1 -1
  23. package/dist/{hmr-timing-BV6nFPoT.js → hmr-timing-BKdCeIrn.js} +207 -67
  24. package/dist/{hmr-timing-BRNaz8Od.mjs → hmr-timing-Dh_nn3w5.mjs} +207 -67
  25. package/dist/index.js +3 -3
  26. package/dist/index.mjs +3 -3
  27. package/dist/js/js-string-escape.d.ts +1 -0
  28. package/dist/presets.js +1 -1
  29. package/dist/presets.mjs +1 -1
  30. package/dist/rspack.js +1 -1
  31. package/dist/rspack.mjs +1 -1
  32. package/dist/{source-candidate-scan-signature-BB1hvW68.mjs → source-candidate-scan-signature-DATRnS1X.mjs} +157 -6
  33. package/dist/{source-candidate-scan-signature-CaDT0gkj.js → source-candidate-scan-signature-DIj9m4wB.js} +168 -5
  34. package/dist/style-injector/internal.d.ts +7 -0
  35. package/dist/style-injector/options.d.ts +25 -0
  36. package/dist/tailwindcss/v4/preflight.d.ts +4 -0
  37. package/dist/{tailwindcss-D2xs4OEu.js → tailwindcss-BwoNQ3t8.js} +52 -12
  38. package/dist/{tailwindcss-D0JF0fuZ.mjs → tailwindcss-C-uM4rB8.mjs} +47 -13
  39. package/dist/{transform-BP86eSZp.mjs → transform-DHLemtaX.mjs} +1 -1
  40. package/dist/{transform-CXCQ28Tc.js → transform-KLD1tJdb.js} +1 -1
  41. package/dist/typedoc.export.d.ts +1 -0
  42. package/dist/types/index.d.ts +2 -1
  43. package/dist/types/user-defined-options/general.d.ts +2 -0
  44. package/dist/{vite-BYgT1ir9.js → vite-Yp14HNyS.js} +101 -37
  45. package/dist/{vite-B1SlBmqO.mjs → vite-cH0tTMHc.mjs} +101 -37
  46. package/dist/vite.js +1 -1
  47. package/dist/vite.mjs +1 -1
  48. package/dist/weapp-tw-css-import-rewrite-loader.js +276 -83
  49. package/dist/{webpack-Bg6pefpb.mjs → webpack-DBhmJ-_P.mjs} +62 -18
  50. package/dist/{webpack-khSwkXP5.js → webpack-DN3tgLbF.js} +61 -17
  51. package/dist/webpack.js +1 -1
  52. package/dist/webpack.mjs +1 -1
  53. package/package.json +16 -5
@@ -1,8 +1,8 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.js");
2
2
  const require_v4_engine = require("./v4-engine-CKtsdKxK.js");
3
3
  const require_generator = require("./generator-CilgHtxb.js");
4
- const require_context = require("./context-DCVMkTRj.js");
5
- const require_tailwindcss = require("./tailwindcss-D2xs4OEu.js");
4
+ const require_context = require("./context-BziwyWy1.js");
5
+ const require_tailwindcss = require("./tailwindcss-BwoNQ3t8.js");
6
6
  let node_fs = require("node:fs");
7
7
  let node_path = require("node:path");
8
8
  node_path = require_rolldown_runtime.__toESM(node_path);
@@ -156,24 +156,91 @@ function collectGeneratedRawSourceCandidates(candidates, rawSource, escapeMap) {
156
156
  return matched;
157
157
  }
158
158
  //#endregion
159
+ //#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
160
+ function resolvePostcssFromOption(cssHandlerOptions) {
161
+ const from = cssHandlerOptions.postcssOptions?.options?.from;
162
+ return typeof from === "string" && from.length > 0 ? from : void 0;
163
+ }
164
+ function resolvePostcssSourceFile(cssHandlerOptions) {
165
+ const from = resolvePostcssFromOption(cssHandlerOptions);
166
+ if (!from || !node_path.default.isAbsolute(from)) return;
167
+ return from.replace(/[?#].*$/, "");
168
+ }
169
+ function resolveCssHandlerSourceOptions(cssHandlerOptions) {
170
+ return cssHandlerOptions.sourceOptions;
171
+ }
172
+ function resolveCssSourceBase(file, cssHandlerOptions) {
173
+ const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
174
+ return node_path.default.dirname(node_path.default.resolve(normalized));
175
+ }
176
+ //#endregion
159
177
  //#region src/bundlers/shared/generator-css/generation-helpers.ts
178
+ function isVueScopedStyleSource(from) {
179
+ if (typeof from !== "string" || from.length === 0) return false;
180
+ const queryIndex = from.indexOf("?");
181
+ if (queryIndex === -1) return false;
182
+ const query = from.slice(queryIndex + 1);
183
+ return /(?:^|&)type=style(?:&|$)/.test(query) && /(?:^|&)scoped(?:=(?:true|1))?(?:&|$)/.test(query);
184
+ }
160
185
  function hasMiniProgramTailwindV4PreflightReset(css) {
161
186
  return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
162
187
  }
163
188
  function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
164
189
  if (target !== "weapp") return css;
165
- const injectPreflight = options.injectPreflight !== false && !hasMiniProgramTailwindV4PreflightReset(css);
190
+ if (isVueScopedStyleSource(options.styleOptions?.postcssOptions?.options?.from)) return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
191
+ cssPreflight: false,
192
+ cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
193
+ isTailwindcssV4: true,
194
+ tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
195
+ });
196
+ const hasPreflightReset = hasMiniProgramTailwindV4PreflightReset(css);
197
+ const injectPreflight = options.injectPreflight !== false && !hasPreflightReset;
198
+ const preservePreflight = options.preservePreflight !== false;
166
199
  return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
167
- cssPreflight: cssPreflight === false ? false : injectPreflight ? cssPreflight : void 0,
200
+ cssPreflight: cssPreflight === false || options.injectPreflight === false && (!hasPreflightReset || !preservePreflight) ? false : injectPreflight ? cssPreflight : hasPreflightReset && preservePreflight ? cssPreflight : void 0,
168
201
  cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
169
202
  isTailwindcssV4: true,
170
203
  tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
171
204
  });
172
205
  }
173
- function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
174
- if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
175
- if (!options.isolateCurrentCssCandidates) return true;
176
- return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
206
+ function resolveMiniProgramPreflightModeForGeneratorCss(opts, options) {
207
+ if (isVueScopedStyleSource(resolvePostcssFromOption(options.cssHandlerOptions))) return {
208
+ inject: false,
209
+ preserve: false
210
+ };
211
+ if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return {
212
+ inject: false,
213
+ preserve: false
214
+ };
215
+ const shouldInjectUniAppXLocalImportPreflight = require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
216
+ if (opts.cssPreflight === false) return {
217
+ inject: false,
218
+ preserve: false
219
+ };
220
+ if (options.primaryCssSource) return {
221
+ inject: true,
222
+ preserve: true
223
+ };
224
+ if (options.explicitCssSource) return {
225
+ inject: false,
226
+ preserve: true
227
+ };
228
+ if (options.cssHandlerOptions.isMainChunk) return {
229
+ inject: true,
230
+ preserve: true
231
+ };
232
+ if (!options.cssHandlerOptions.isMainChunk && !options.primaryCssSource && !options.explicitCssSource) return {
233
+ inject: shouldInjectUniAppXLocalImportPreflight,
234
+ preserve: shouldInjectUniAppXLocalImportPreflight
235
+ };
236
+ if (!options.isolateCurrentCssCandidates) return {
237
+ inject: true,
238
+ preserve: true
239
+ };
240
+ return {
241
+ inject: shouldInjectUniAppXLocalImportPreflight,
242
+ preserve: shouldInjectUniAppXLocalImportPreflight
243
+ };
177
244
  }
178
245
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
179
246
  if (options.isolateCssSource) {
@@ -207,9 +274,10 @@ function isEmptyCssSourceOrderParts(parts) {
207
274
  }
208
275
  function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
209
276
  const resolvedStyleOptions = require_context.resolveStyleOptionsFromContext(opts);
277
+ const scopedVueStyleSource = isVueScopedStyleSource(resolvePostcssFromOption(cssHandlerOptions));
210
278
  const preflightStyleOptions = {
211
- cssPreflight: resolvedStyleOptions.cssPreflight,
212
- cssPreflightRange: resolvedStyleOptions.cssPreflightRange
279
+ cssPreflight: scopedVueStyleSource ? false : resolvedStyleOptions.cssPreflight,
280
+ cssPreflightRange: scopedVueStyleSource ? void 0 : resolvedStyleOptions.cssPreflightRange
213
281
  };
214
282
  return {
215
283
  ...resolvedStyleOptions,
@@ -830,8 +898,9 @@ function withGeneratorSourceMetadata(source, metadata) {
830
898
  __weappTailwindcssMeta: metadata
831
899
  };
832
900
  }
833
- function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
901
+ function withMatchedSourceSideMetadata(source, resolvedEntrySource, metadata = {}) {
834
902
  return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
903
+ ...metadata,
835
904
  isolateCssSource: true,
836
905
  matchedCssSourceFile: resolvedEntrySource.file,
837
906
  sourceBase: resolvedEntrySource.base,
@@ -839,24 +908,6 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
839
908
  }) : source;
840
909
  }
841
910
  //#endregion
842
- //#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
843
- function resolvePostcssFromOption(cssHandlerOptions) {
844
- const from = cssHandlerOptions.postcssOptions?.options?.from;
845
- return typeof from === "string" && from.length > 0 ? from : void 0;
846
- }
847
- function resolvePostcssSourceFile(cssHandlerOptions) {
848
- const from = resolvePostcssFromOption(cssHandlerOptions);
849
- if (!from || !node_path.default.isAbsolute(from)) return;
850
- return from.replace(/[?#].*$/, "");
851
- }
852
- function resolveCssHandlerSourceOptions(cssHandlerOptions) {
853
- return cssHandlerOptions.sourceOptions;
854
- }
855
- function resolveCssSourceBase(file, cssHandlerOptions) {
856
- const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
857
- return node_path.default.dirname(node_path.default.resolve(normalized));
858
- }
859
- //#endregion
860
911
  //#region src/bundlers/shared/generator-css/source-resolver.ts
861
912
  function createCssEntrySources(cssEntries) {
862
913
  return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
@@ -890,11 +941,15 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
890
941
  cssEntries: options.cssEntries
891
942
  });
892
943
  }
893
- async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
944
+ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options = {}) {
894
945
  const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
895
- if (!(0, node_fs.existsSync)(cssEntry)) return require_v4_engine.resolveTailwindV4Source({
946
+ if (!(0, node_fs.existsSync)(cssEntry)) return withGeneratorSourceMetadata(await require_v4_engine.resolveTailwindV4Source({
896
947
  ...require_v4_engine.omitUndefined(singleEntrySourceOptions),
897
948
  cssEntries: [cssEntry]
949
+ }), {
950
+ cssEntryIndex: options.index,
951
+ includesPreflight: options.includesPreflight,
952
+ primaryCssSource: options.index === 0
898
953
  });
899
954
  const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
900
955
  const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
@@ -909,7 +964,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
909
964
  css: require_v4_engine.normalizeConfigDirective(css, config),
910
965
  cssEntries: [cssEntry]
911
966
  }), {
967
+ cssEntryIndex: options.index,
968
+ includesPreflight: options.includesPreflight,
912
969
  matchedCssSourceFile: cssEntry,
970
+ primaryCssSource: options.index === 0,
913
971
  sourceBase: base,
914
972
  sourceCss: css
915
973
  });
@@ -922,12 +980,15 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
922
980
  function shouldResolveSourceSideCssEntry(rawSource) {
923
981
  return rawSource.includes("@apply") || require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindSourceDirectives(rawSource, { importFallback: true }) || require_v4_engine.hasTailwindGeneratedCss(rawSource) || require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource);
924
982
  }
925
- function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
983
+ async function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
926
984
  const cssEntries = sourceOptions.cssEntries;
927
985
  if (!cssEntries?.length) return;
928
986
  const normalizedFile = node_path.default.resolve(file.replace(/[?#].*$/, ""));
929
987
  const pathMatchedEntries = cssEntries.filter((cssEntry) => node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
930
- if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions);
988
+ if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions, {
989
+ includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(pathMatchedEntries[0]),
990
+ index: cssEntries.indexOf(pathMatchedEntries[0])
991
+ });
931
992
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
932
993
  const matches = cssEntries.map((cssEntry) => {
933
994
  if (!(0, node_fs.existsSync)(cssEntry)) return;
@@ -946,7 +1007,10 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
946
1007
  const bestScore = matches[0]?.score;
947
1008
  const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
948
1009
  if (!matchingEntry) return;
949
- return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions);
1010
+ return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions, {
1011
+ includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(matchingEntry),
1012
+ index: cssEntries.indexOf(matchingEntry)
1013
+ });
950
1014
  }
951
1015
  function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
952
1016
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
@@ -996,7 +1060,7 @@ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
996
1060
  cssSources
997
1061
  } : sourceOptions;
998
1062
  }
999
- async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
1063
+ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions) {
1000
1064
  const cssSources = sourceOptions.cssSources;
1001
1065
  if (!cssSources?.length) return;
1002
1066
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
@@ -1017,7 +1081,12 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
1017
1081
  const bestScore = matches[0]?.score;
1018
1082
  const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
1019
1083
  if (!matchingSource) return;
1020
- return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
1084
+ return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
1085
+ includesPreflight: await resolveTailwindV4CssSourceEntries(matchingSource, sourceOptions).then((resolved) => resolved?.includesPreflight),
1086
+ index: matches[0]?.index,
1087
+ matched: true,
1088
+ primary: isSameTailwindV4CssSource(matchingSource, selectionOptions?.cssSources?.[0])
1089
+ });
1021
1090
  }
1022
1091
  function tryResolveTailwindV4SourceOptions(runtimeState) {
1023
1092
  try {
@@ -1029,14 +1098,24 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
1029
1098
  function hasConfiguredTailwindV4CssSource(sourceOptions) {
1030
1099
  return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
1031
1100
  }
1101
+ function isSameTailwindV4CssSource(a, b) {
1102
+ if (!a || !b) return false;
1103
+ if (typeof a.file === "string" && typeof b.file === "string") return node_path.default.resolve(a.file) === node_path.default.resolve(b.file);
1104
+ return typeof a.css === "string" && typeof b.css === "string" && normalizeCssSourceForCompare(a.css) === normalizeCssSourceForCompare(b.css);
1105
+ }
1032
1106
  async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
1033
1107
  const sourceBase = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
1034
1108
  const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
1035
- return withGeneratorSourceMetadata(await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(sourceOptions, {
1109
+ const source = await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(sourceOptions, {
1036
1110
  base: sourceBase,
1037
1111
  css: normalizedCssSource.css
1038
- })), {
1112
+ }));
1113
+ const resolvedEntries = options.includesPreflight === void 0 ? await resolveTailwindV4CssSourceEntries(normalizedCssSource, sourceOptions) : void 0;
1114
+ return withGeneratorSourceMetadata(source, {
1115
+ cssSourceIndex: options.index,
1116
+ includesPreflight: options.includesPreflight ?? resolvedEntries?.includesPreflight,
1039
1117
  matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
1118
+ primaryCssSource: options.primary === true || !sourceOptions.cssEntries?.length && options.index === 0 || void 0,
1040
1119
  sourceBase,
1041
1120
  sourceCss: normalizedCssSource.css
1042
1121
  });
@@ -1065,6 +1144,7 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
1065
1144
  if (runtimeHits === 0) return;
1066
1145
  matches.push({
1067
1146
  cssSource,
1147
+ includesPreflight: resolved.includesPreflight,
1068
1148
  index,
1069
1149
  runtimeHits,
1070
1150
  totalCandidates: scopedCandidates.size
@@ -1076,10 +1156,53 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
1076
1156
  const second = matches[1];
1077
1157
  if (!best) return;
1078
1158
  if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
1079
- return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, { matched: true });
1159
+ return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, {
1160
+ includesPreflight: best.includesPreflight,
1161
+ index: best.index,
1162
+ matched: true,
1163
+ primary: isSameTailwindV4CssSource(best.cssSource, selectionOptions?.cssSources?.[0])
1164
+ });
1165
+ }
1166
+ async function resolveTailwindV4CssEntryEntries(cssEntry) {
1167
+ if (!(0, node_fs.existsSync)(cssEntry)) return;
1168
+ const file = node_path.default.resolve(cssEntry);
1169
+ return require_tailwindcss.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(file, "utf8"), node_path.default.dirname(file));
1170
+ }
1171
+ async function resolveTailwindV4CssEntryIncludesPreflight(cssEntry) {
1172
+ return resolveTailwindV4CssEntryEntries(cssEntry).then((resolved) => resolved?.includesPreflight);
1173
+ }
1174
+ async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions) {
1175
+ const cssEntries = sourceOptions.cssEntries;
1176
+ const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
1177
+ if (!cssEntries?.length || !getSourceCandidatesForEntries) return;
1178
+ const matches = [];
1179
+ await Promise.all(cssEntries.map(async (cssEntry, index) => {
1180
+ const resolved = await resolveTailwindV4CssEntryEntries(cssEntry);
1181
+ if (resolved?.entries === void 0) return;
1182
+ const scopedCandidates = getSourceCandidatesForEntries(resolved.entries);
1183
+ const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
1184
+ if (runtimeHits === 0) return;
1185
+ matches.push({
1186
+ cssEntry,
1187
+ includesPreflight: resolved.includesPreflight,
1188
+ index,
1189
+ runtimeHits,
1190
+ totalCandidates: scopedCandidates.size
1191
+ });
1192
+ }));
1193
+ if (matches.length === 0) return;
1194
+ matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
1195
+ const best = matches[0];
1196
+ const second = matches[1];
1197
+ if (!best) return;
1198
+ if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
1199
+ return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
1200
+ includesPreflight: best.includesPreflight,
1201
+ index: best.index
1202
+ });
1080
1203
  }
1081
1204
  function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
1082
- return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
1205
+ return (cssSource, index) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions, { index }).then((source) => generatorOptions?.config ? {
1083
1206
  ...source,
1084
1207
  css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1085
1208
  } : source);
@@ -1092,11 +1215,19 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
1092
1215
  sourceFile: resolvedEntrySource.file
1093
1216
  });
1094
1217
  const css = createTailwindV4SourceReferenceSource(require_v4_engine.normalizeConfigDirective(require_v4_engine.prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
1095
- return withMatchedSourceSideMetadata(await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1218
+ const source = await require_v4_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1096
1219
  base: resolvedEntrySource.base,
1097
1220
  css,
1098
1221
  cssEntries: [resolvedEntrySource.file]
1099
- })), resolvedEntrySource);
1222
+ }));
1223
+ const cssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
1224
+ const cssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && node_path.default.resolve(cssSource.file.replace(/[?#].*$/, "")) === node_path.default.resolve(resolvedEntrySource.file));
1225
+ return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
1226
+ cssEntryIndex,
1227
+ cssSourceIndex,
1228
+ includesPreflight: (await require_tailwindcss.resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base))?.includesPreflight,
1229
+ primaryCssSource: cssEntryIndex === 0 || !sourceOptions.cssEntries?.length && cssSourceIndex === 0
1230
+ });
1100
1231
  }
1101
1232
  async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1102
1233
  const base = resolveCssSourceBase(file, cssHandlerOptions);
@@ -1114,7 +1245,7 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
1114
1245
  sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
1115
1246
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
1116
1247
  cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
1117
- cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1248
+ cssSources: mergeCssSources(mergeCssSources(sourceOptions.cssSources, selectionOptions?.cssSources), sourceOptions.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1118
1249
  }) : void 0;
1119
1250
  const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
1120
1251
  if (applyEntrySource && !cssHandlerOptions.isMainChunk && !require_v4_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
@@ -1129,16 +1260,20 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
1129
1260
  const sourceSideCssSource = sourceSideEntrySource?.file && normalizedSourceOptions.cssEntries?.some((cssEntry) => node_path.default.resolve(cssEntry.replace(/[?#].*$/, "")) === node_path.default.resolve(sourceSideEntrySource.file)) ? await resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file) : void 0;
1130
1261
  if (sourceSideCssSource) return sourceSideCssSource;
1131
1262
  const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
1132
- const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
1263
+ const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
1264
+ const candidateMatchedCssEntrySource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssEntry(normalizedSourceOptions, selectionOptions) : void 0;
1133
1265
  const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
1134
- const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
1266
+ const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
1267
+ index: 0,
1268
+ matched: true
1269
+ }) : void 0;
1135
1270
  const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && require_v4_engine.hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await require_v4_engine.resolveTailwindV4Source(normalizedSourceOptions) : void 0;
1136
1271
  if (configuredCssSource) return generatorOptions?.config ? {
1137
1272
  ...configuredCssSource,
1138
1273
  css: require_v4_engine.prependConfigDirective(configuredCssSource.css, generatorOptions.config)
1139
1274
  } : configuredCssSource;
1140
1275
  const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
1141
- const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
1276
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
1142
1277
  if (preferredCssEntrySource) return generatorOptions?.config ? {
1143
1278
  ...preferredCssEntrySource,
1144
1279
  css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
@@ -1194,19 +1329,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
1194
1329
  } : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1195
1330
  const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
1196
1331
  if (sourceSideCssSource) return [sourceSideCssSource];
1197
- const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
1332
+ const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions);
1333
+ const candidateMatchedCssEntrySource = await resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions);
1198
1334
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
1199
- const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
1335
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource;
1200
1336
  if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
1201
1337
  ...preferredCssEntrySource,
1202
1338
  css: require_v4_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1203
1339
  } : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1204
1340
  if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
1205
- if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
1341
+ if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions), { index: 0 }).then((source) => generatorOptions?.config ? {
1206
1342
  ...source,
1207
1343
  css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1208
1344
  } : source)];
1209
- if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
1345
+ if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0], 0), sourceOptions.cssSources[0]?.file, sourceOptions)];
1210
1346
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1211
1347
  return resolved ? [resolved] : [];
1212
1348
  }
@@ -1215,7 +1351,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
1215
1351
  return resolved ? [resolved] : [];
1216
1352
  }
1217
1353
  const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
1218
- const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
1354
+ const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry, index) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions, { index }).then((source) => generatorOptions?.config ? {
1219
1355
  ...source,
1220
1356
  css: require_v4_engine.prependConfigDirective(source.css, generatorOptions.config)
1221
1357
  } : source)));
@@ -2317,7 +2453,7 @@ async function generateCssByGenerator(options) {
2317
2453
  });
2318
2454
  const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
2319
2455
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
2320
- cssEntries: opts.cssEntries,
2456
+ cssEntries: cssHandlerOptions.sourceOptions?.cssEntries ?? opts.cssEntries,
2321
2457
  cssSources: options.cssSources,
2322
2458
  getSourceCandidatesForEntries,
2323
2459
  runtime: runtimeWithCurrentCss
@@ -2386,6 +2522,19 @@ async function generateCssByGenerator(options) {
2386
2522
  const generatedCssSource = generated.target === "web" ? generated.css : require_v4_engine.stripTailwindBanner(generated.css);
2387
2523
  const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
2388
2524
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
2525
+ const hasExplicitCssSource = sources.some((source) => {
2526
+ const metadata = source.__weappTailwindcssMeta;
2527
+ return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
2528
+ });
2529
+ const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
2530
+ const hasPreflightRawSource = require_tailwindcss.includesTailwindV4PreflightDirective(generatorRawSource);
2531
+ const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
2532
+ cssHandlerOptions,
2533
+ isolateCurrentCssCandidates,
2534
+ localImports,
2535
+ explicitCssSource: hasExplicitCssSource,
2536
+ primaryCssSource: sources.length > 0 && sources.every((source) => source.__weappTailwindcssMeta?.primaryCssSource === true) || hasPreflightCssSource || hasPreflightRawSource
2537
+ });
2389
2538
  const orderedExtraCss = require_v4_engine.splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? require_v4_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
2390
2539
  const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
2391
2540
  if (orderedExtraCss) {
@@ -2433,11 +2582,8 @@ async function generateCssByGenerator(options) {
2433
2582
  }
2434
2583
  } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
2435
2584
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2436
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2437
- cssHandlerOptions,
2438
- isolateCurrentCssCandidates,
2439
- localImports
2440
- }),
2585
+ injectPreflight: preflightMode.inject,
2586
+ preservePreflight: preflightMode.preserve,
2441
2587
  styleOptions: generatorStyleOptions
2442
2588
  });
2443
2589
  return {
@@ -2541,11 +2687,8 @@ async function generateCssByGenerator(options) {
2541
2687
  css = createCssSourceOrderAppend$1(css, missingUserCss);
2542
2688
  }
2543
2689
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2544
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2545
- cssHandlerOptions,
2546
- isolateCurrentCssCandidates,
2547
- localImports
2548
- }),
2690
+ injectPreflight: preflightMode.inject,
2691
+ preservePreflight: preflightMode.preserve,
2549
2692
  styleOptions: generatorStyleOptions
2550
2693
  });
2551
2694
  return {
@@ -2578,11 +2721,8 @@ async function generateCssByGenerator(options) {
2578
2721
  css = createCssSourceOrderAppend$1(css, missingUserCss);
2579
2722
  }
2580
2723
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2581
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2582
- cssHandlerOptions,
2583
- isolateCurrentCssCandidates,
2584
- localImports
2585
- }),
2724
+ injectPreflight: preflightMode.inject,
2725
+ preservePreflight: preflightMode.preserve,
2586
2726
  styleOptions: generatorStyleOptions
2587
2727
  });
2588
2728
  return {