weapp-tailwindcss 5.1.3 → 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 (71) hide show
  1. package/dist/auto-CrJJc5rK.mjs +13 -0
  2. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +8 -2
  3. package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -10
  4. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +5 -1
  5. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
  6. package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +6 -3
  7. package/dist/bundlers/vite/generate-bundle/temporary-css-assets.d.ts +1 -1
  8. package/dist/bundlers/vite/hot-css-modules.d.ts +1 -0
  9. package/dist/bundlers/vite/processed-css-assets.d.ts +1 -0
  10. package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
  11. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -1
  12. package/dist/cli.js +18 -3
  13. package/dist/cli.mjs +16 -1
  14. package/dist/{context-D75pwtBW.js → context-BziwyWy1.js} +56 -9
  15. package/dist/{context-B07Vf584.mjs → context-rrYZuUBU.mjs} +48 -7
  16. package/dist/core.js +1 -1
  17. package/dist/core.mjs +1 -1
  18. package/dist/css-macro/auto.d.ts +1 -1
  19. package/dist/css-macro/index.d.ts +2 -1
  20. package/dist/css-macro.mjs +1 -1
  21. package/dist/{defaults-BhE26nSw.mjs → defaults-9B6aMyZb.mjs} +2 -2
  22. package/dist/{defaults-DQhgnnn-.js → defaults-nsf4VNMX.js} +2 -2
  23. package/dist/defaults.d.ts +1 -1
  24. package/dist/defaults.js +1 -1
  25. package/dist/defaults.mjs +1 -1
  26. package/dist/framework/platform.d.ts +2 -0
  27. package/dist/{generator-DNs6ekoC.mjs → generator-24-HgU9F.mjs} +5 -3
  28. package/dist/{generator-CV_0irKO.js → generator-CilgHtxb.js} +5 -3
  29. package/dist/generator.js +2 -2
  30. package/dist/generator.mjs +2 -2
  31. package/dist/{gulp-B_u8NjQL.js → gulp-CuVsZdO9.js} +7 -6
  32. package/dist/{gulp-aQMZ0M7c.mjs → gulp-ygWfmOqh.mjs} +4 -4
  33. package/dist/gulp.js +1 -1
  34. package/dist/gulp.mjs +1 -1
  35. package/dist/{hmr-timing-DOoHun3i.js → hmr-timing-BKdCeIrn.js} +244 -229
  36. package/dist/{hmr-timing-DLYQTCDb.mjs → hmr-timing-Dh_nn3w5.mjs} +244 -211
  37. package/dist/index.js +4 -4
  38. package/dist/index.mjs +4 -4
  39. package/dist/js/js-string-escape.d.ts +1 -0
  40. package/dist/postcss.js +2 -2
  41. package/dist/postcss.mjs +2 -2
  42. package/dist/presets.js +2 -2
  43. package/dist/presets.mjs +2 -2
  44. package/dist/rspack.js +1 -1
  45. package/dist/rspack.mjs +1 -1
  46. package/dist/{source-candidate-scan-signature-pS87mdHZ.mjs → source-candidate-scan-signature-DATRnS1X.mjs} +165 -8
  47. package/dist/{source-candidate-scan-signature-DzwebZrf.js → source-candidate-scan-signature-DIj9m4wB.js} +177 -7
  48. package/dist/style-injector/internal.d.ts +7 -0
  49. package/dist/style-injector/options.d.ts +25 -0
  50. package/dist/tailwindcss/v4/preflight.d.ts +4 -0
  51. package/dist/tailwindcss/v4-engine/css-macro-source.d.ts +2 -0
  52. package/dist/{tailwindcss-BSCvrs1p.js → tailwindcss-BwoNQ3t8.js} +56 -16
  53. package/dist/{tailwindcss-BwV3_Ryc.mjs → tailwindcss-C-uM4rB8.mjs} +51 -17
  54. package/dist/{transform-Clj7R818.mjs → transform-DHLemtaX.mjs} +1 -1
  55. package/dist/{transform-fin-OTVD.js → transform-KLD1tJdb.js} +1 -1
  56. package/dist/typedoc.export.d.ts +1 -0
  57. package/dist/types/index.d.ts +2 -1
  58. package/dist/types/user-defined-options/general.d.ts +2 -0
  59. package/dist/{v4-engine-BklH3CpJ.mjs → v4-engine-BuuYDXt1.mjs} +54 -114
  60. package/dist/{v4-engine-CKbS27-o.js → v4-engine-CKtsdKxK.js} +57 -111
  61. package/dist/{vite-CkVMSDDp.js → vite-Yp14HNyS.js} +310 -78
  62. package/dist/{vite-5Wn0PIzJ.mjs → vite-cH0tTMHc.mjs} +308 -76
  63. package/dist/vite.js +1 -1
  64. package/dist/vite.mjs +1 -1
  65. package/dist/weapp-tw-css-import-rewrite-loader.js +363 -272
  66. package/dist/{webpack-DEag6ueE.mjs → webpack-DBhmJ-_P.mjs} +107 -20
  67. package/dist/{webpack-hvSFaicc.js → webpack-DN3tgLbF.js} +107 -20
  68. package/dist/webpack.js +1 -1
  69. package/dist/webpack.mjs +1 -1
  70. package/package.json +16 -5
  71. package/dist/auto-Ba6hDrse.mjs +0 -13
@@ -1,12 +1,12 @@
1
- import { A as resolveCssEntrySource, B as stripTailwindBanner, C as hasTailwindRootDirectives, E as normalizeTailwindSourceDirectives, F as hasTailwindGeneratedCssMarkers, H as normalizeConfigDirective, I as splitGeneratorPlaceholderCssBySourceOrder, J as FULL_SOURCE_SCAN_EXTENSION_RE, L as splitTailwindGeneratedCssByBanner, M as VITE_MARKER_RE, N as createCssAppend, O as parseImportRequest, P as hasTailwindGeneratedCss, Q as isFileMatchedByTailwindSourceEntries, R as splitTailwindV4GeneratedCssBySourceOrder, U as prependConfigDirective, V as stripTailwindBanners, i as resolveTailwindV4SourceOptionsFromRuntime, it as toPosixPath$1, j as GENERATOR_PLACEHOLDER_MARKER_RE, k as removeTailwindSourceDirectives, lt as loadTailwindV4DesignSystem, n as resolveTailwindV4SourceFromRuntime, nt as resolveSourceScanPath, ot as filterUnsupportedMiniProgramTailwindV4Candidates, rt as resolveTailwindV4CssSourceBase, st as omitUndefined, t as resolveTailwindV4Source$1, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective, z as stripGeneratorPlaceholderMarkers } from "./v4-engine-BklH3CpJ.mjs";
2
- import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-DNs6ekoC.mjs";
3
- import { C as md5Hash, S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext } from "./context-B07Vf584.mjs";
4
- import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled } from "./tailwindcss-BwV3_Ryc.mjs";
1
+ import { A as resolveCssEntrySource, B as stripTailwindBanner, C as hasTailwindRootDirectives, E as normalizeTailwindSourceDirectives, F as hasTailwindGeneratedCssMarkers, H as normalizeConfigDirective, I as splitGeneratorPlaceholderCssBySourceOrder, J as FULL_SOURCE_SCAN_EXTENSION_RE, L as splitTailwindGeneratedCssByBanner, M as VITE_MARKER_RE, N as createCssAppend, O as parseImportRequest, P as hasTailwindGeneratedCss, Q as isFileMatchedByTailwindSourceEntries, R as splitTailwindV4GeneratedCssBySourceOrder, U as prependConfigDirective, V as stripTailwindBanners, ct as omitUndefined, i as resolveTailwindV4SourceOptionsFromRuntime, it as toPosixPath$1, j as GENERATOR_PLACEHOLDER_MARKER_RE, k as removeTailwindSourceDirectives, n as resolveTailwindV4SourceFromRuntime, nt as resolveSourceScanPath, rt as resolveTailwindV4CssSourceBase, st as filterUnsupportedMiniProgramTailwindV4Candidates, t as resolveTailwindV4Source$1, ut as loadTailwindV4DesignSystem, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective, z as stripGeneratorPlaceholderMarkers } from "./v4-engine-BuuYDXt1.mjs";
2
+ import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch, t as createWeappTailwindcssGenerator } from "./generator-24-HgU9F.mjs";
3
+ import { S as createDebug, g as traverse, h as babelParse, m as replaceWxml, r as resolveStyleOptionsFromContext, w as md5Hash } from "./context-rrYZuUBU.mjs";
4
+ import { h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled, v as includesTailwindV4PreflightDirective } from "./tailwindcss-C-uM4rB8.mjs";
5
5
  import { existsSync, readFileSync } from "node:fs";
6
6
  import path from "node:path";
7
7
  import process from "node:process";
8
8
  import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "@tailwindcss-mangle/engine";
9
- import { filterExistingCssRules, finalizeMiniProgramCss, hasMiniProgramCssSpecificityPlaceholders, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, stripMiniProgramCssSpecificityPlaceholders, transformWebCssCompat } from "@weapp-tailwindcss/postcss";
9
+ import { cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, filterExistingCssRules, finalizeMiniProgramCss, hasMiniProgramCssSpecificityPlaceholders, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, postcss, pruneMiniProgramGeneratedCss, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, splitLocalCssImports, splitLocalCssImportsRoot, stripMiniProgramCssSpecificityPlaceholders, transformWebCssCompat } from "@weapp-tailwindcss/postcss";
10
10
  import { LRUCache } from "lru-cache";
11
11
  import { readFile } from "node:fs/promises";
12
12
  import { MappingChars2String, unescape } from "@weapp-core/escape";
@@ -152,22 +152,91 @@ function collectGeneratedRawSourceCandidates(candidates, rawSource, escapeMap) {
152
152
  return matched;
153
153
  }
154
154
  //#endregion
155
+ //#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
156
+ function resolvePostcssFromOption(cssHandlerOptions) {
157
+ const from = cssHandlerOptions.postcssOptions?.options?.from;
158
+ return typeof from === "string" && from.length > 0 ? from : void 0;
159
+ }
160
+ function resolvePostcssSourceFile(cssHandlerOptions) {
161
+ const from = resolvePostcssFromOption(cssHandlerOptions);
162
+ if (!from || !path.isAbsolute(from)) return;
163
+ return from.replace(/[?#].*$/, "");
164
+ }
165
+ function resolveCssHandlerSourceOptions(cssHandlerOptions) {
166
+ return cssHandlerOptions.sourceOptions;
167
+ }
168
+ function resolveCssSourceBase(file, cssHandlerOptions) {
169
+ const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
170
+ return path.dirname(path.resolve(normalized));
171
+ }
172
+ //#endregion
155
173
  //#region src/bundlers/shared/generator-css/generation-helpers.ts
174
+ function isVueScopedStyleSource(from) {
175
+ if (typeof from !== "string" || from.length === 0) return false;
176
+ const queryIndex = from.indexOf("?");
177
+ if (queryIndex === -1) return false;
178
+ const query = from.slice(queryIndex + 1);
179
+ return /(?:^|&)type=style(?:&|$)/.test(query) && /(?:^|&)scoped(?:=(?:true|1))?(?:&|$)/.test(query);
180
+ }
156
181
  function hasMiniProgramTailwindV4PreflightReset(css) {
157
182
  return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\bborder\s*:\s*0\s+solid\b/.test(css);
158
183
  }
159
184
  function finalizeMiniProgramGeneratorCss(css, target, _majorVersion, cssPreflight, options = {}) {
160
185
  if (target !== "weapp") return css;
186
+ if (isVueScopedStyleSource(options.styleOptions?.postcssOptions?.options?.from)) return finalizeMiniProgramCss(css, {
187
+ cssPreflight: false,
188
+ cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
189
+ isTailwindcssV4: true,
190
+ tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
191
+ });
192
+ const hasPreflightReset = hasMiniProgramTailwindV4PreflightReset(css);
193
+ const injectPreflight = options.injectPreflight !== false && !hasPreflightReset;
194
+ const preservePreflight = options.preservePreflight !== false;
161
195
  return finalizeMiniProgramCss(css, {
162
- cssPreflight: options.injectPreflight !== false && !hasMiniProgramTailwindV4PreflightReset(css) ? cssPreflight : void 0,
196
+ cssPreflight: cssPreflight === false || options.injectPreflight === false && (!hasPreflightReset || !preservePreflight) ? false : injectPreflight ? cssPreflight : hasPreflightReset && preservePreflight ? cssPreflight : void 0,
197
+ cssSelectorReplacement: options.styleOptions?.cssOptions?.cssSelectorReplacement ?? options.styleOptions?.cssSelectorReplacement,
163
198
  isTailwindcssV4: true,
164
199
  tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
165
200
  });
166
201
  }
167
- function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
168
- if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
169
- if (!options.isolateCurrentCssCandidates) return true;
170
- return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
202
+ function resolveMiniProgramPreflightModeForGeneratorCss(opts, options) {
203
+ if (isVueScopedStyleSource(resolvePostcssFromOption(options.cssHandlerOptions))) return {
204
+ inject: false,
205
+ preserve: false
206
+ };
207
+ if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return {
208
+ inject: false,
209
+ preserve: false
210
+ };
211
+ const shouldInjectUniAppXLocalImportPreflight = isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
212
+ if (opts.cssPreflight === false) return {
213
+ inject: false,
214
+ preserve: false
215
+ };
216
+ if (options.primaryCssSource) return {
217
+ inject: true,
218
+ preserve: true
219
+ };
220
+ if (options.explicitCssSource) return {
221
+ inject: false,
222
+ preserve: true
223
+ };
224
+ if (options.cssHandlerOptions.isMainChunk) return {
225
+ inject: true,
226
+ preserve: true
227
+ };
228
+ if (!options.cssHandlerOptions.isMainChunk && !options.primaryCssSource && !options.explicitCssSource) return {
229
+ inject: shouldInjectUniAppXLocalImportPreflight,
230
+ preserve: shouldInjectUniAppXLocalImportPreflight
231
+ };
232
+ if (!options.isolateCurrentCssCandidates) return {
233
+ inject: true,
234
+ preserve: true
235
+ };
236
+ return {
237
+ inject: shouldInjectUniAppXLocalImportPreflight,
238
+ preserve: shouldInjectUniAppXLocalImportPreflight
239
+ };
171
240
  }
172
241
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
173
242
  if (options.isolateCssSource) {
@@ -201,9 +270,10 @@ function isEmptyCssSourceOrderParts(parts) {
201
270
  }
202
271
  function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
203
272
  const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
273
+ const scopedVueStyleSource = isVueScopedStyleSource(resolvePostcssFromOption(cssHandlerOptions));
204
274
  const preflightStyleOptions = {
205
- cssPreflight: resolvedStyleOptions.cssPreflight,
206
- cssPreflightRange: resolvedStyleOptions.cssPreflightRange
275
+ cssPreflight: scopedVueStyleSource ? false : resolvedStyleOptions.cssPreflight,
276
+ cssPreflightRange: scopedVueStyleSource ? void 0 : resolvedStyleOptions.cssPreflightRange
207
277
  };
208
278
  return {
209
279
  ...resolvedStyleOptions,
@@ -824,8 +894,9 @@ function withGeneratorSourceMetadata(source, metadata) {
824
894
  __weappTailwindcssMeta: metadata
825
895
  };
826
896
  }
827
- function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
897
+ function withMatchedSourceSideMetadata(source, resolvedEntrySource, metadata = {}) {
828
898
  return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
899
+ ...metadata,
829
900
  isolateCssSource: true,
830
901
  matchedCssSourceFile: resolvedEntrySource.file,
831
902
  sourceBase: resolvedEntrySource.base,
@@ -833,24 +904,6 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
833
904
  }) : source;
834
905
  }
835
906
  //#endregion
836
- //#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
837
- function resolvePostcssFromOption(cssHandlerOptions) {
838
- const from = cssHandlerOptions.postcssOptions?.options?.from;
839
- return typeof from === "string" && from.length > 0 ? from : void 0;
840
- }
841
- function resolvePostcssSourceFile(cssHandlerOptions) {
842
- const from = resolvePostcssFromOption(cssHandlerOptions);
843
- if (!from || !path.isAbsolute(from)) return;
844
- return from.replace(/[?#].*$/, "");
845
- }
846
- function resolveCssHandlerSourceOptions(cssHandlerOptions) {
847
- return cssHandlerOptions.sourceOptions;
848
- }
849
- function resolveCssSourceBase(file, cssHandlerOptions) {
850
- const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
851
- return path.dirname(path.resolve(normalized));
852
- }
853
- //#endregion
854
907
  //#region src/bundlers/shared/generator-css/source-resolver.ts
855
908
  function createCssEntrySources(cssEntries) {
856
909
  return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && path.isAbsolute(entry)).map((entry) => ({ file: path.resolve(entry) }));
@@ -884,11 +937,15 @@ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
884
937
  cssEntries: options.cssEntries
885
938
  });
886
939
  }
887
- async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
940
+ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions, options = {}) {
888
941
  const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
889
- if (!existsSync(cssEntry)) return resolveTailwindV4Source$1({
942
+ if (!existsSync(cssEntry)) return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
890
943
  ...omitUndefined(singleEntrySourceOptions),
891
944
  cssEntries: [cssEntry]
945
+ }), {
946
+ cssEntryIndex: options.index,
947
+ includesPreflight: options.includesPreflight,
948
+ primaryCssSource: options.index === 0
892
949
  });
893
950
  const css = readFileSync(cssEntry, "utf8");
894
951
  const base = path.dirname(path.resolve(cssEntry));
@@ -903,7 +960,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
903
960
  css: normalizeConfigDirective(css, config),
904
961
  cssEntries: [cssEntry]
905
962
  }), {
963
+ cssEntryIndex: options.index,
964
+ includesPreflight: options.includesPreflight,
906
965
  matchedCssSourceFile: cssEntry,
966
+ primaryCssSource: options.index === 0,
907
967
  sourceBase: base,
908
968
  sourceCss: css
909
969
  });
@@ -916,12 +976,15 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
916
976
  function shouldResolveSourceSideCssEntry(rawSource) {
917
977
  return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
918
978
  }
919
- function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
979
+ async function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
920
980
  const cssEntries = sourceOptions.cssEntries;
921
981
  if (!cssEntries?.length) return;
922
982
  const normalizedFile = path.resolve(file.replace(/[?#].*$/, ""));
923
983
  const pathMatchedEntries = cssEntries.filter((cssEntry) => path.resolve(cssEntry.replace(/[?#].*$/, "")) === normalizedFile);
924
- if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions);
984
+ if (pathMatchedEntries.length === 1) return resolveTailwindV4CssEntrySource(pathMatchedEntries[0], sourceOptions, {
985
+ includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(pathMatchedEntries[0]),
986
+ index: cssEntries.indexOf(pathMatchedEntries[0])
987
+ });
925
988
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
926
989
  const matches = cssEntries.map((cssEntry) => {
927
990
  if (!existsSync(cssEntry)) return;
@@ -940,7 +1003,10 @@ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
940
1003
  const bestScore = matches[0]?.score;
941
1004
  const matchingEntry = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssEntry : void 0;
942
1005
  if (!matchingEntry) return;
943
- return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions);
1006
+ return resolveTailwindV4CssEntrySource(matchingEntry, sourceOptions, {
1007
+ includesPreflight: await resolveTailwindV4CssEntryIncludesPreflight(matchingEntry),
1008
+ index: cssEntries.indexOf(matchingEntry)
1009
+ });
944
1010
  }
945
1011
  function normalizeTailwindV4CssSourceConfig(cssSource, sourceBase) {
946
1012
  if (typeof cssSource.css !== "string" || cssSource.css.length === 0 || !cssSource.css.includes("@config")) return cssSource;
@@ -990,7 +1056,7 @@ function normalizeTailwindV4CssSourceConfigs(sourceOptions) {
990
1056
  cssSources
991
1057
  } : sourceOptions;
992
1058
  }
993
- async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
1059
+ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions) {
994
1060
  const cssSources = sourceOptions.cssSources;
995
1061
  if (!cssSources?.length) return;
996
1062
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
@@ -1011,7 +1077,12 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
1011
1077
  const bestScore = matches[0]?.score;
1012
1078
  const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
1013
1079
  if (!matchingSource) return;
1014
- return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
1080
+ return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, {
1081
+ includesPreflight: await resolveTailwindV4CssSourceEntries(matchingSource, sourceOptions).then((resolved) => resolved?.includesPreflight),
1082
+ index: matches[0]?.index,
1083
+ matched: true,
1084
+ primary: isSameTailwindV4CssSource(matchingSource, selectionOptions?.cssSources?.[0])
1085
+ });
1015
1086
  }
1016
1087
  function tryResolveTailwindV4SourceOptions(runtimeState) {
1017
1088
  try {
@@ -1023,14 +1094,24 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
1023
1094
  function hasConfiguredTailwindV4CssSource(sourceOptions) {
1024
1095
  return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
1025
1096
  }
1097
+ function isSameTailwindV4CssSource(a, b) {
1098
+ if (!a || !b) return false;
1099
+ if (typeof a.file === "string" && typeof b.file === "string") return path.resolve(a.file) === path.resolve(b.file);
1100
+ return typeof a.css === "string" && typeof b.css === "string" && normalizeCssSourceForCompare(a.css) === normalizeCssSourceForCompare(b.css);
1101
+ }
1026
1102
  async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions, options = {}) {
1027
1103
  const sourceBase = resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
1028
1104
  const normalizedCssSource = normalizeTailwindV4CssSourceConfig(cssSource, sourceBase);
1029
- return withGeneratorSourceMetadata(await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(sourceOptions, {
1105
+ const source = await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(sourceOptions, {
1030
1106
  base: sourceBase,
1031
1107
  css: normalizedCssSource.css
1032
- })), {
1108
+ }));
1109
+ const resolvedEntries = options.includesPreflight === void 0 ? await resolveTailwindV4CssSourceEntries(normalizedCssSource, sourceOptions) : void 0;
1110
+ return withGeneratorSourceMetadata(source, {
1111
+ cssSourceIndex: options.index,
1112
+ includesPreflight: options.includesPreflight ?? resolvedEntries?.includesPreflight,
1033
1113
  matchedCssSourceFile: options.matched && typeof normalizedCssSource.file === "string" ? normalizedCssSource.file : void 0,
1114
+ primaryCssSource: options.primary === true || !sourceOptions.cssEntries?.length && options.index === 0 || void 0,
1034
1115
  sourceBase,
1035
1116
  sourceCss: normalizedCssSource.css
1036
1117
  });
@@ -1059,6 +1140,47 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
1059
1140
  if (runtimeHits === 0) return;
1060
1141
  matches.push({
1061
1142
  cssSource,
1143
+ includesPreflight: resolved.includesPreflight,
1144
+ index,
1145
+ runtimeHits,
1146
+ totalCandidates: scopedCandidates.size
1147
+ });
1148
+ }));
1149
+ if (matches.length === 0) return;
1150
+ matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
1151
+ const best = matches[0];
1152
+ const second = matches[1];
1153
+ if (!best) return;
1154
+ if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
1155
+ return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, {
1156
+ includesPreflight: best.includesPreflight,
1157
+ index: best.index,
1158
+ matched: true,
1159
+ primary: isSameTailwindV4CssSource(best.cssSource, selectionOptions?.cssSources?.[0])
1160
+ });
1161
+ }
1162
+ async function resolveTailwindV4CssEntryEntries(cssEntry) {
1163
+ if (!existsSync(cssEntry)) return;
1164
+ const file = path.resolve(cssEntry);
1165
+ return resolveTailwindV4EntriesFromCss(readFileSync(file, "utf8"), path.dirname(file));
1166
+ }
1167
+ async function resolveTailwindV4CssEntryIncludesPreflight(cssEntry) {
1168
+ return resolveTailwindV4CssEntryEntries(cssEntry).then((resolved) => resolved?.includesPreflight);
1169
+ }
1170
+ async function resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions) {
1171
+ const cssEntries = sourceOptions.cssEntries;
1172
+ const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
1173
+ if (!cssEntries?.length || !getSourceCandidatesForEntries) return;
1174
+ const matches = [];
1175
+ await Promise.all(cssEntries.map(async (cssEntry, index) => {
1176
+ const resolved = await resolveTailwindV4CssEntryEntries(cssEntry);
1177
+ if (resolved?.entries === void 0) return;
1178
+ const scopedCandidates = getSourceCandidatesForEntries(resolved.entries);
1179
+ const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
1180
+ if (runtimeHits === 0) return;
1181
+ matches.push({
1182
+ cssEntry,
1183
+ includesPreflight: resolved.includesPreflight,
1062
1184
  index,
1063
1185
  runtimeHits,
1064
1186
  totalCandidates: scopedCandidates.size
@@ -1070,10 +1192,13 @@ async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, _cssHandle
1070
1192
  const second = matches[1];
1071
1193
  if (!best) return;
1072
1194
  if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
1073
- return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions, { matched: true });
1195
+ return resolveTailwindV4CssEntrySource(best.cssEntry, sourceOptions, {
1196
+ includesPreflight: best.includesPreflight,
1197
+ index: best.index
1198
+ });
1074
1199
  }
1075
1200
  function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
1076
- return (cssSource) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions).then((source) => generatorOptions?.config ? {
1201
+ return (cssSource, index) => resolveSingleTailwindV4CssSource(cssSource, sourceOptions, { index }).then((source) => generatorOptions?.config ? {
1077
1202
  ...source,
1078
1203
  css: prependConfigDirective(source.css, generatorOptions.config)
1079
1204
  } : source);
@@ -1086,11 +1211,19 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
1086
1211
  sourceFile: resolvedEntrySource.file
1087
1212
  });
1088
1213
  const css = createTailwindV4SourceReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
1089
- return withMatchedSourceSideMetadata(await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1214
+ const source = await resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
1090
1215
  base: resolvedEntrySource.base,
1091
1216
  css,
1092
1217
  cssEntries: [resolvedEntrySource.file]
1093
- })), resolvedEntrySource);
1218
+ }));
1219
+ const cssEntryIndex = sourceOptions.cssEntries?.findIndex((cssEntry) => typeof resolvedEntrySource.file === "string" && path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1220
+ const cssSourceIndex = sourceOptions.cssSources?.findIndex((cssSource) => typeof cssSource.file === "string" && typeof resolvedEntrySource.file === "string" && path.resolve(cssSource.file.replace(/[?#].*$/, "")) === path.resolve(resolvedEntrySource.file));
1221
+ return withMatchedSourceSideMetadata(source, resolvedEntrySource, {
1222
+ cssEntryIndex,
1223
+ cssSourceIndex,
1224
+ includesPreflight: (await resolveTailwindV4EntriesFromCss(resolvedEntrySource.css, resolvedEntrySource.base))?.includesPreflight,
1225
+ primaryCssSource: cssEntryIndex === 0 || !sourceOptions.cssEntries?.length && cssSourceIndex === 0
1226
+ });
1094
1227
  }
1095
1228
  async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
1096
1229
  const base = resolveCssSourceBase(file, cssHandlerOptions);
@@ -1108,7 +1241,7 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
1108
1241
  sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
1109
1242
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
1110
1243
  cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
1111
- cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1244
+ cssSources: mergeCssSources(mergeCssSources(sourceOptions.cssSources, selectionOptions?.cssSources), sourceOptions.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
1112
1245
  }) : void 0;
1113
1246
  const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
1114
1247
  if (applyEntrySource && !cssHandlerOptions.isMainChunk && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
@@ -1123,16 +1256,20 @@ async function resolveGeneratorSource(_majorVersion, runtimeState, rawSource, fi
1123
1256
  const sourceSideCssSource = sourceSideEntrySource?.file && normalizedSourceOptions.cssEntries?.some((cssEntry) => path.resolve(cssEntry.replace(/[?#].*$/, "")) === path.resolve(sourceSideEntrySource.file)) ? await resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, normalizedSourceOptions, generatorOptions, file) : void 0;
1124
1257
  if (sourceSideCssSource) return sourceSideCssSource;
1125
1258
  const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
1126
- const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
1259
+ const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
1260
+ const candidateMatchedCssEntrySource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssEntry(normalizedSourceOptions, selectionOptions) : void 0;
1127
1261
  const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
1128
- const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
1262
+ const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, {
1263
+ index: 0,
1264
+ matched: true
1265
+ }) : void 0;
1129
1266
  const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source$1(normalizedSourceOptions) : void 0;
1130
1267
  if (configuredCssSource) return generatorOptions?.config ? {
1131
1268
  ...configuredCssSource,
1132
1269
  css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
1133
1270
  } : configuredCssSource;
1134
1271
  const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
1135
- const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
1272
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
1136
1273
  if (preferredCssEntrySource) return generatorOptions?.config ? {
1137
1274
  ...preferredCssEntrySource,
1138
1275
  css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
@@ -1188,19 +1325,20 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
1188
1325
  } : matchedCssEntrySource, matchedCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1189
1326
  const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
1190
1327
  if (sourceSideCssSource) return [sourceSideCssSource];
1191
- const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
1328
+ const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions, selectionOptions);
1329
+ const candidateMatchedCssEntrySource = await resolveCandidateMatchedTailwindV4CssEntry(sourceOptions, selectionOptions);
1192
1330
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
1193
- const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
1331
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssEntrySource ?? candidateMatchedCssSource;
1194
1332
  if (preferredCssEntrySource) return [normalizeResolvedTailwindV4SourceConfig(generatorOptions?.config ? {
1195
1333
  ...preferredCssEntrySource,
1196
1334
  css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
1197
1335
  } : preferredCssEntrySource, preferredCssEntrySource.__weappTailwindcssMeta?.matchedCssSourceFile, sourceOptions)];
1198
1336
  if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
1199
- if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions)).then((source) => generatorOptions?.config ? {
1337
+ if (cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1) return [await resolveTailwindV4CssEntrySource(sourceOptions.cssEntries[0], normalizeTailwindV4CssSourceConfigs(sourceOptions), { index: 0 }).then((source) => generatorOptions?.config ? {
1200
1338
  ...source,
1201
1339
  css: prependConfigDirective(source.css, generatorOptions.config)
1202
1340
  } : source)];
1203
- if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0]), sourceOptions.cssSources[0]?.file, sourceOptions)];
1341
+ if (sourceOptions.cssSources?.length === 1) return [normalizeResolvedTailwindV4SourceConfig(await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0], 0), sourceOptions.cssSources[0]?.file, sourceOptions)];
1204
1342
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
1205
1343
  return resolved ? [resolved] : [];
1206
1344
  }
@@ -1209,7 +1347,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
1209
1347
  return resolved ? [resolved] : [];
1210
1348
  }
1211
1349
  const normalizedCssSourceOptions = normalizeTailwindV4CssSourceConfigs(sourceOptions);
1212
- const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions).then((source) => generatorOptions?.config ? {
1350
+ const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry, index) => resolveTailwindV4CssEntrySource(cssEntry, normalizedCssSourceOptions, { index }).then((source) => generatorOptions?.config ? {
1213
1351
  ...source,
1214
1352
  css: prependConfigDirective(source.css, generatorOptions.config)
1215
1353
  } : source)));
@@ -1999,133 +2137,6 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
1999
2137
  }
2000
2138
  }
2001
2139
  //#endregion
2002
- //#region src/bundlers/shared/generator-css/local-imports.ts
2003
- const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
2004
- const CSS_STYLE_EXTENSION_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
2005
- const SOURCE_STYLE_EXTENSION_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|[?#])/i;
2006
- function createCssSourceOrderAppend(base, extra) {
2007
- if (!base) return extra;
2008
- if (!extra) return base;
2009
- if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
2010
- return `${base}\n${extra}`;
2011
- }
2012
- function isLocalImportRequest(request) {
2013
- return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
2014
- }
2015
- function isPureLocalCssImportWrapper(css) {
2016
- let hasImport = false;
2017
- try {
2018
- const root = postcss.parse(css);
2019
- for (const node of root.nodes) {
2020
- if (node.type === "comment") continue;
2021
- if (node.type !== "atrule" || node.name !== "import") return false;
2022
- const request = parseImportRequest(node.params);
2023
- if (!request || !isLocalImportRequest(request)) return false;
2024
- hasImport = true;
2025
- }
2026
- } catch {
2027
- return false;
2028
- }
2029
- return hasImport;
2030
- }
2031
- function cleanLocalCssImportWrapperTailwindDirectives(css) {
2032
- let hasLocalImport = false;
2033
- let hasTailwindDirective = false;
2034
- try {
2035
- const root = postcss.parse(css);
2036
- for (const node of root.nodes) {
2037
- if (node.type === "comment") continue;
2038
- if (node.type === "atrule" && node.name === "import") {
2039
- const request = parseImportRequest(node.params);
2040
- if (!request || !isLocalImportRequest(request)) return;
2041
- hasLocalImport = true;
2042
- continue;
2043
- }
2044
- if (node.type === "atrule" && node.name === "source") {
2045
- hasTailwindDirective = true;
2046
- continue;
2047
- }
2048
- return;
2049
- }
2050
- } catch {
2051
- return;
2052
- }
2053
- return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
2054
- }
2055
- function prefixLocalCssImportsWithWebpackIgnore(css) {
2056
- try {
2057
- const root = postcss.parse(css);
2058
- root.walkAtRules("import", (atRule) => {
2059
- const request = parseImportRequest(atRule.params);
2060
- if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
2061
- });
2062
- return root.toString();
2063
- } catch {
2064
- return css;
2065
- }
2066
- }
2067
- function splitLocalCssImports(source) {
2068
- try {
2069
- const root = postcss.parse(source);
2070
- const importRoot = postcss.root();
2071
- let changed = false;
2072
- for (const node of [...root.nodes]) {
2073
- if (node.type !== "atrule" || node.name !== "import") continue;
2074
- const request = parseImportRequest(node.params);
2075
- if (!request || !isLocalImportRequest(request)) continue;
2076
- importRoot.append(node.clone());
2077
- node.remove();
2078
- changed = true;
2079
- }
2080
- const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
2081
- return changed ? {
2082
- imports,
2083
- source: root.toString()
2084
- } : void 0;
2085
- } catch {
2086
- return;
2087
- }
2088
- }
2089
- function restoreLocalCssImports(css, imports) {
2090
- if (!imports?.trim()) return css;
2091
- return createCssSourceOrderAppend(imports, css);
2092
- }
2093
- function splitRequestSuffix(request) {
2094
- const suffixIndexCandidates = [request.indexOf("?"), request.indexOf("#")].filter((index) => index >= 0);
2095
- const suffixIndex = suffixIndexCandidates.length > 0 ? Math.min(...suffixIndexCandidates) : -1;
2096
- if (suffixIndex < 0) return {
2097
- clean: request,
2098
- suffix: ""
2099
- };
2100
- return {
2101
- clean: request.slice(0, suffixIndex),
2102
- suffix: request.slice(suffixIndex)
2103
- };
2104
- }
2105
- function normalizeOutputImportRequest(request, styleOutputExtension) {
2106
- const normalizedStyleOutputExtension = styleOutputExtension?.startsWith(".") ? styleOutputExtension : styleOutputExtension ? `.${styleOutputExtension}` : void 0;
2107
- const { clean, suffix } = splitRequestSuffix(request.replace(/\\/g, "/"));
2108
- return `${clean.replace(/^(?:\.\/)?src\//, "./").replace(SOURCE_STYLE_EXTENSION_RE, normalizedStyleOutputExtension ?? ".css")}${suffix}`;
2109
- }
2110
- function rewriteLocalCssImportRequestsForOutput(css, options = {}) {
2111
- if (!css.includes("@import")) return css;
2112
- try {
2113
- const root = postcss.parse(css);
2114
- let changed = false;
2115
- root.walkAtRules("import", (atRule) => {
2116
- const request = parseImportRequest(atRule.params);
2117
- if (!request || !isLocalImportRequest(request) || !CSS_STYLE_EXTENSION_RE.test(request)) return;
2118
- const rewritten = normalizeOutputImportRequest(request, options.styleOutputExtension);
2119
- if (rewritten === request) return;
2120
- atRule.params = atRule.params.replace(request, rewritten);
2121
- changed = true;
2122
- });
2123
- return changed ? root.toString() : css;
2124
- } catch {
2125
- return css;
2126
- }
2127
- }
2128
- //#endregion
2129
2140
  //#region src/bundlers/shared/generator-css/user-layer-order.ts
2130
2141
  const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
2131
2142
  const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
@@ -2323,6 +2334,23 @@ function intersectCandidateSets(left, right) {
2323
2334
  for (const candidate of small) if (large.has(candidate)) matched.add(candidate);
2324
2335
  return matched;
2325
2336
  }
2337
+ function parseCssSourceRoot(rawSource) {
2338
+ try {
2339
+ return postcss.parse(rawSource);
2340
+ } catch {
2341
+ return;
2342
+ }
2343
+ }
2344
+ function cleanLocalCssImportWrapperFromParsedRoot(rawSource, root) {
2345
+ if (!root) return cleanLocalCssImportWrapperTailwindDirectives(rawSource);
2346
+ return cleanLocalCssImportWrapperTailwindDirectivesRoot(root) ? root.toString() : void 0;
2347
+ }
2348
+ function isPureLocalCssImportWrapperFromParsedRoot(rawSource, root) {
2349
+ return root ? isPureLocalCssImportWrapperRoot(root) : isPureLocalCssImportWrapper(rawSource);
2350
+ }
2351
+ function splitLocalCssImportsFromParsedRoot(rawSource, root) {
2352
+ return root ? splitLocalCssImportsRoot(root) : splitLocalCssImports(rawSource);
2353
+ }
2326
2354
  function collectCssRuleIdentityMarkers(source) {
2327
2355
  const markers = /* @__PURE__ */ new Set();
2328
2356
  try {
@@ -2371,20 +2399,8 @@ async function generateCssByGenerator(options) {
2371
2399
  const majorVersion = runtimeState.tailwindRuntime.majorVersion;
2372
2400
  if (majorVersion !== 4) throw new Error("weapp-tailwindcss 生成管线仅支持 Tailwind CSS v4。");
2373
2401
  const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
2374
- const localImportParts = splitLocalCssImports(effectiveRawSource);
2375
- const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
2376
- const finalizeGeneratorCss = (css, target, finalizeOptions = {}) => {
2377
- return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports), target, generatorOptions.webCompat);
2378
- };
2379
- const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
2380
- const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
2381
- const userSource = splitLocalCssImports(rawUserSource)?.source ?? rawUserSource;
2382
- const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
2383
- const generatedUserCssOrderSource = hasTailwindGeneratedCss(userSource) ? splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
2384
- const generatedUserCssRawSource = generatedUserCssOrderSource ? createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
2385
- const userCssOrderSource = GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
2386
- const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(generatedUserCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
2387
- const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
2402
+ const effectiveRawSourceRoot = parseCssSourceRoot(effectiveRawSource);
2403
+ const cleanedLocalImportWrapper = cleanLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
2388
2404
  if (cleanedLocalImportWrapper !== void 0) return {
2389
2405
  css: shouldUseMiniProgramCssBranch(generatorBranch) ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
2390
2406
  classSet: /* @__PURE__ */ new Set(),
@@ -2396,7 +2412,20 @@ async function generateCssByGenerator(options) {
2396
2412
  majorVersion
2397
2413
  }
2398
2414
  };
2399
- if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
2415
+ if (isPureLocalCssImportWrapperFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot)) return;
2416
+ const localImportParts = splitLocalCssImportsFromParsedRoot(effectiveRawSource, effectiveRawSourceRoot);
2417
+ const localImports = options.restoreLocalCssImports === false ? void 0 : localImportParts?.imports;
2418
+ const finalizeGeneratorCss = (css, target, finalizeOptions = {}) => {
2419
+ return finalizeWebGeneratorCss(restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, target, majorVersion, opts.cssPreflight, finalizeOptions), localImports), target, generatorOptions.webCompat);
2420
+ };
2421
+ const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
2422
+ const rawUserSource = userRawSource === void 0 ? generatorRawSource : userRawSourceProcessed ? userRawSource : stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(userRawSource, { importFallback: generatorOptions.importFallback })));
2423
+ const userSource = (rawUserSource === generatorRawSource ? void 0 : splitLocalCssImports(rawUserSource))?.source ?? rawUserSource;
2424
+ const userCssRawSource = removeTailwindV4GeneratorAtRules(userSource);
2425
+ const generatedUserCssOrderSource = hasTailwindGeneratedCss(userSource) ? splitTailwindV4GeneratedCssBySourceOrder(userSource, generatorRawSource) : void 0;
2426
+ const generatedUserCssRawSource = generatedUserCssOrderSource ? createCssAppend(generatedUserCssOrderSource.before, generatedUserCssOrderSource.after) : hasTailwindGeneratedCss(userSource) ? "" : userCssRawSource;
2427
+ const userCssOrderSource = GENERATOR_PLACEHOLDER_MARKER_RE.test(userSource) ? userSource : hasTailwindGeneratedCss(userSource) ? userSource : generatedUserCssRawSource;
2428
+ const hasDistinctUserRawSource = typeof userRawSource === "string" && normalizeCssSourceForCompare(generatedUserCssRawSource) !== normalizeCssSourceForCompare(generatorRawSource);
2400
2429
  const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
2401
2430
  const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
2402
2431
  const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
@@ -2420,7 +2449,7 @@ async function generateCssByGenerator(options) {
2420
2449
  });
2421
2450
  const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
2422
2451
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
2423
- cssEntries: opts.cssEntries,
2452
+ cssEntries: cssHandlerOptions.sourceOptions?.cssEntries ?? opts.cssEntries,
2424
2453
  cssSources: options.cssSources,
2425
2454
  getSourceCandidatesForEntries,
2426
2455
  runtime: runtimeWithCurrentCss
@@ -2489,6 +2518,19 @@ async function generateCssByGenerator(options) {
2489
2518
  const generatedCssSource = generated.target === "web" ? generated.css : stripTailwindBanner(generated.css);
2490
2519
  const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(generatedCssSource, generatorRawSource) : generatedCssSource;
2491
2520
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
2521
+ const hasExplicitCssSource = sources.some((source) => {
2522
+ const metadata = source.__weappTailwindcssMeta;
2523
+ return metadata?.cssEntryIndex !== void 0 || metadata?.cssSourceIndex !== void 0;
2524
+ });
2525
+ const hasPreflightCssSource = sources.some((source) => source.__weappTailwindcssMeta?.includesPreflight === true);
2526
+ const hasPreflightRawSource = includesTailwindV4PreflightDirective(generatorRawSource);
2527
+ const preflightMode = resolveMiniProgramPreflightModeForGeneratorCss(opts, {
2528
+ cssHandlerOptions,
2529
+ isolateCurrentCssCandidates,
2530
+ localImports,
2531
+ explicitCssSource: hasExplicitCssSource,
2532
+ primaryCssSource: sources.length > 0 && sources.every((source) => source.__weappTailwindcssMeta?.primaryCssSource === true) || hasPreflightCssSource || hasPreflightRawSource
2533
+ });
2492
2534
  const orderedExtraCss = splitGeneratorPlaceholderCssBySourceOrder(userCssOrderSource, generated.rawCss) ?? (hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssOrderSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssOrderSource, generated.rawCss));
2493
2535
  const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
2494
2536
  if (orderedExtraCss) {
@@ -2536,11 +2578,8 @@ async function generateCssByGenerator(options) {
2536
2578
  }
2537
2579
  } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
2538
2580
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2539
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2540
- cssHandlerOptions,
2541
- isolateCurrentCssCandidates,
2542
- localImports
2543
- }),
2581
+ injectPreflight: preflightMode.inject,
2582
+ preservePreflight: preflightMode.preserve,
2544
2583
  styleOptions: generatorStyleOptions
2545
2584
  });
2546
2585
  return {
@@ -2644,11 +2683,8 @@ async function generateCssByGenerator(options) {
2644
2683
  css = createCssSourceOrderAppend$1(css, missingUserCss);
2645
2684
  }
2646
2685
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2647
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2648
- cssHandlerOptions,
2649
- isolateCurrentCssCandidates,
2650
- localImports
2651
- }),
2686
+ injectPreflight: preflightMode.inject,
2687
+ preservePreflight: preflightMode.preserve,
2652
2688
  styleOptions: generatorStyleOptions
2653
2689
  });
2654
2690
  return {
@@ -2681,11 +2717,8 @@ async function generateCssByGenerator(options) {
2681
2717
  css = createCssSourceOrderAppend$1(css, missingUserCss);
2682
2718
  }
2683
2719
  const finalCss = finalizeGeneratorCss(css, generated.target, {
2684
- injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
2685
- cssHandlerOptions,
2686
- isolateCurrentCssCandidates,
2687
- localImports
2688
- }),
2720
+ injectPreflight: preflightMode.inject,
2721
+ preservePreflight: preflightMode.preserve,
2689
2722
  styleOptions: generatorStyleOptions
2690
2723
  });
2691
2724
  return {