weapp-tailwindcss 5.0.12 → 5.0.13

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 (99) hide show
  1. package/dist/{bundle-state-DU2ATDhw.js → bundle-state-CKWeTEhv.js} +2 -2
  2. package/dist/{bundle-state-BxMNKjBV.mjs → bundle-state-zQ2MrDdi.mjs} +1 -1
  3. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
  4. package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
  5. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  6. package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
  7. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
  8. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
  9. package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
  11. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
  12. package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
  14. package/dist/bundlers/vite/css-memory.d.ts +27 -0
  15. package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
  16. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
  17. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
  18. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
  19. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +8 -7
  20. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
  21. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
  22. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
  23. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
  24. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
  25. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
  26. package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
  27. package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
  28. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
  29. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
  30. package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
  31. package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
  32. package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
  33. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
  34. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  35. package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
  36. package/dist/bundlers/vite/map-cache.d.ts +2 -0
  37. package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
  38. package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
  39. package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
  40. package/dist/bundlers/vite/source-candidates.d.ts +3 -0
  41. package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
  42. package/dist/bundlers/vite/source-scan.d.ts +1 -1
  43. package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
  44. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +1 -0
  45. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
  46. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
  47. package/dist/cli.js +2 -2
  48. package/dist/cli.mjs +1 -1
  49. package/dist/core.js +1 -1
  50. package/dist/core.mjs +1 -1
  51. package/dist/css-macro.js +1 -1
  52. package/dist/css-macro.mjs +1 -1
  53. package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
  54. package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
  55. package/dist/defaults.js +1 -1
  56. package/dist/defaults.mjs +1 -1
  57. package/dist/framework/index.d.ts +59 -0
  58. package/dist/framework.d.ts +1 -0
  59. package/dist/framework.js +198 -0
  60. package/dist/framework.mjs +180 -0
  61. package/dist/{generator-Cb1Zp3Al.js → generator-CzpArpCL.js} +1 -1
  62. package/dist/{generator-mvNFUvns.mjs → generator-ITLd7PTl.mjs} +1 -1
  63. package/dist/generator.js +2 -2
  64. package/dist/generator.mjs +2 -2
  65. package/dist/{gulp-BfZpaYSQ.mjs → gulp-DfOQERcV.mjs} +44 -16
  66. package/dist/{gulp-CxGZU0-v.js → gulp-XT8Jc7lH.js} +44 -16
  67. package/dist/gulp.js +1 -1
  68. package/dist/gulp.mjs +1 -1
  69. package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-BMftW7Us.js} +298 -221
  70. package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-DQIP_8qP.mjs} +297 -220
  71. package/dist/index.d.ts +1 -0
  72. package/dist/index.js +20 -4
  73. package/dist/index.mjs +6 -5
  74. package/dist/postcss.js +2 -2
  75. package/dist/postcss.mjs +2 -2
  76. package/dist/{precheck-30zNPRlI.js → precheck-B0Z8yW7E.js} +98 -27
  77. package/dist/{precheck-CsFr1q2l.mjs → precheck-CRI90iL1.mjs} +97 -26
  78. package/dist/presets.js +3 -3
  79. package/dist/presets.mjs +3 -3
  80. package/dist/{tailwindcss-CK84uGBp.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
  81. package/dist/{tailwindcss-Clpkz1oR.js → tailwindcss-DZEwT3C_.js} +3 -3
  82. package/dist/{transform-Cju08-aJ.mjs → transform-DfcEjsZF.mjs} +29 -21
  83. package/dist/{transform-CaVEBOuR.js → transform-YmrmxuF3.js} +29 -21
  84. package/dist/types/user-defined-options/general.d.ts +3 -1
  85. package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
  86. package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
  87. package/dist/{v3-engine-CQE5JJNZ.js → v3-engine-2rrgylhn.js} +53 -6
  88. package/dist/{v3-engine-DKBaKWGL.mjs → v3-engine-C6eJ0YzK.mjs} +46 -5
  89. package/dist/{vite-BBGOjh9e.js → vite-CXHVsHmX.js} +1945 -1280
  90. package/dist/{vite-CS5DE-HD.mjs → vite-DjI09vVN.mjs} +1944 -1279
  91. package/dist/vite.js +1 -1
  92. package/dist/vite.mjs +1 -1
  93. package/dist/weapp-tw-css-import-rewrite-loader.js +346 -186
  94. package/dist/weapp-tw-runtime-classset-loader.js +25 -0
  95. package/dist/{webpack-SPcri_D8.mjs → webpack-BcPpnT90.mjs} +165 -35
  96. package/dist/{webpack-DIWrcpRo.js → webpack-CfkUkMXG.js} +167 -37
  97. package/dist/webpack.js +1 -1
  98. package/dist/webpack.mjs +1 -1
  99. package/package.json +9 -4
@@ -4,13 +4,13 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  const require_watch_dependencies = require("./watch-dependencies-bpG6kmAf.js");
6
6
  let node_buffer = require("node:buffer");
7
- let node_process = require("node:process");
8
- node_process = require_watch_dependencies.__toESM(node_process);
9
- let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
10
7
  let node_fs = require("node:fs");
11
8
  node_fs = require_watch_dependencies.__toESM(node_fs);
12
9
  let node_path = require("node:path");
13
10
  node_path = require_watch_dependencies.__toESM(node_path);
11
+ let node_process = require("node:process");
12
+ node_process = require_watch_dependencies.__toESM(node_process);
13
+ let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
14
14
  let node_util = require("node:util");
15
15
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
16
16
  let tailwindcss_patch = require("tailwindcss-patch");
@@ -2943,6 +2943,7 @@ function readStaticConfigContent(configPath) {
2943
2943
  //#endregion
2944
2944
  //#region src/bundlers/vite/source-scan/css-entries.ts
2945
2945
  const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
2946
+ const tailwindConfigCssEntriesCache = /* @__PURE__ */ new Map();
2946
2947
  function parseImportSourceParam(params) {
2947
2948
  const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
2948
2949
  if (!match) return;
@@ -2969,6 +2970,44 @@ function resolveConfigPath(base, configPath) {
2969
2970
  if (node_path.default.isAbsolute(configPath)) return node_path.default.resolve(configPath);
2970
2971
  return node_path.default.resolve(base, configPath);
2971
2972
  }
2973
+ function createCssEntriesCacheKey(css, base, dependencies) {
2974
+ return JSON.stringify({
2975
+ base: node_path.default.resolve(base),
2976
+ css,
2977
+ dependencies
2978
+ });
2979
+ }
2980
+ function createDependencyExcludeEntries(files) {
2981
+ return [...files].map((file) => ({
2982
+ base: node_path.default.dirname(file),
2983
+ negated: true,
2984
+ pattern: node_path.default.basename(file)
2985
+ }));
2986
+ }
2987
+ async function statConfigDependency(file) {
2988
+ try {
2989
+ const stats = await (0, node_fs_promises.stat)(file);
2990
+ return {
2991
+ file,
2992
+ mtimeMs: stats.mtimeMs,
2993
+ size: stats.size
2994
+ };
2995
+ } catch {
2996
+ return {
2997
+ file,
2998
+ mtimeMs: -1,
2999
+ size: -1
3000
+ };
3001
+ }
3002
+ }
3003
+ async function collectConfigDependencySignatures(root, base) {
3004
+ const configPaths = /* @__PURE__ */ new Set();
3005
+ root.walkAtRules("config", (rule) => {
3006
+ const configPath = parseConfigParam$1(rule.params);
3007
+ if (configPath) configPaths.add(resolveConfigPath(base, configPath));
3008
+ });
3009
+ return Promise.all([...configPaths].sort().map(statConfigDependency));
3010
+ }
2972
3011
  async function resolveConfigContentEntries(root, base) {
2973
3012
  const configPaths = /* @__PURE__ */ new Set();
2974
3013
  root.walkAtRules("config", (rule) => {
@@ -3051,6 +3090,32 @@ async function resolveTailwindV4EntriesFromCss(css, base) {
3051
3090
  dependencies: configEntries.dependencies
3052
3091
  } : void 0;
3053
3092
  }
3093
+ async function resolveTailwindConfigEntriesFromCssCached(css, base) {
3094
+ let root;
3095
+ try {
3096
+ root = _weapp_tailwindcss_postcss.postcss.parse(css);
3097
+ } catch {
3098
+ return;
3099
+ }
3100
+ const dependencies = await collectConfigDependencySignatures(root, base);
3101
+ if (dependencies.length === 0) return;
3102
+ const cacheKey = createCssEntriesCacheKey(css, base, dependencies);
3103
+ const cached = tailwindConfigCssEntriesCache.get(cacheKey);
3104
+ if (cached) return cached;
3105
+ const task = resolveConfigContentEntries(root, base).then((resolved) => {
3106
+ return {
3107
+ entries: [...resolved.entries, ...createDependencyExcludeEntries(resolved.dependencies)],
3108
+ explicit: true,
3109
+ inlineCandidates: {
3110
+ excluded: /* @__PURE__ */ new Set(),
3111
+ included: /* @__PURE__ */ new Set()
3112
+ },
3113
+ dependencies: resolved.dependencies
3114
+ };
3115
+ });
3116
+ tailwindConfigCssEntriesCache.set(cacheKey, task);
3117
+ return task;
3118
+ }
3054
3119
  //#endregion
3055
3120
  //#region src/tailwindcss/runtime/cache.ts
3056
3121
  const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
@@ -3772,22 +3837,45 @@ function isUniAppXEnabled(option) {
3772
3837
  //#region src/context/style-options.ts
3773
3838
  function resolveStyleOptionsFromContext(ctx) {
3774
3839
  const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
3840
+ const hasCssOptions = ctx.cssOptions !== void 0;
3841
+ const cssOptions = {
3842
+ cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
3843
+ cssPreflightRange: ctx.cssOptions?.cssPreflightRange ?? ctx.cssPreflightRange,
3844
+ cssChildCombinatorReplaceValue: ctx.cssOptions?.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue,
3845
+ cssSelectorReplacement: ctx.cssOptions?.cssSelectorReplacement ?? ctx.cssSelectorReplacement,
3846
+ rem2rpx: ctx.cssOptions?.rem2rpx ?? ctx.rem2rpx,
3847
+ cssRemoveProperty: ctx.cssOptions?.cssRemoveProperty ?? ctx.cssRemoveProperty,
3848
+ cssRemoveHoverPseudoClass: ctx.cssOptions?.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass,
3849
+ tailwindcssV4GradientFallback: ctx.cssOptions?.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback,
3850
+ cssPresetEnv: ctx.cssOptions?.cssPresetEnv ?? ctx.cssPresetEnv,
3851
+ atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
3852
+ autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
3853
+ cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
3854
+ platform: ctx.cssOptions?.platform ?? ctx.platform,
3855
+ px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
3856
+ unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
3857
+ unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
3858
+ injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
3859
+ };
3775
3860
  return {
3776
- cssPreflight: ctx.cssPreflight,
3777
- cssPreflightRange: ctx.cssPreflightRange,
3778
- cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
3779
- cssSelectorReplacement: ctx.cssSelectorReplacement,
3780
- rem2rpx: ctx.rem2rpx,
3781
- cssRemoveProperty: ctx.cssRemoveProperty,
3782
- cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
3783
- cssPresetEnv: ctx.cssPresetEnv,
3784
- autoprefixer: ctx.autoprefixer,
3785
- cssCalc: ctx.cssCalc,
3861
+ cssPreflight: cssOptions.cssPreflight,
3862
+ cssPreflightRange: cssOptions.cssPreflightRange,
3863
+ cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
3864
+ cssSelectorReplacement: cssOptions.cssSelectorReplacement,
3865
+ rem2rpx: cssOptions.rem2rpx,
3866
+ ...hasCssOptions ? { cssOptions } : {},
3867
+ cssRemoveProperty: cssOptions.cssRemoveProperty,
3868
+ cssRemoveHoverPseudoClass: cssOptions.cssRemoveHoverPseudoClass,
3869
+ tailwindcssV4GradientFallback: cssOptions.tailwindcssV4GradientFallback,
3870
+ cssPresetEnv: cssOptions.cssPresetEnv,
3871
+ atRules: cssOptions.atRules,
3872
+ autoprefixer: cssOptions.autoprefixer,
3873
+ cssCalc: cssOptions.cssCalc,
3786
3874
  uniAppX: resolvedUniAppXOptions.enabled,
3787
- platform: ctx.platform,
3788
- px2rpx: ctx.px2rpx,
3789
- unitsToPx: ctx.unitsToPx,
3790
- unitConversion: ctx.unitConversion
3875
+ platform: cssOptions.platform,
3876
+ px2rpx: cssOptions.px2rpx,
3877
+ unitsToPx: cssOptions.unitsToPx,
3878
+ unitConversion: cssOptions.unitConversion
3791
3879
  };
3792
3880
  }
3793
3881
  //#endregion
@@ -3797,7 +3885,8 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
3797
3885
  return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
3798
3886
  cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
3799
3887
  isTailwindcssV4: majorVersion === 4,
3800
- preservePseudoContentInit: majorVersion === 3
3888
+ preservePseudoContentInit: majorVersion === 3,
3889
+ tailwindcssV4GradientFallback: options.styleOptions?.cssOptions?.tailwindcssV4GradientFallback ?? options.styleOptions?.tailwindcssV4GradientFallback
3801
3890
  });
3802
3891
  }
3803
3892
  function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
@@ -3806,12 +3895,24 @@ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
3806
3895
  return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
3807
3896
  }
3808
3897
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
3809
- if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
3810
- if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
3898
+ if (options.majorVersion === 3 && !options.isolateCssSource) return new Set([
3899
+ ...scopedRuntime,
3900
+ ...runtime,
3901
+ ...options.currentCssCandidates ?? []
3902
+ ]);
3903
+ if (options.isolateCssSource) {
3904
+ if (options.matchedCssSourceFile) return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
3905
+ return new Set([...scopedRuntime, ...options.currentCssCandidates ?? []]);
3906
+ }
3907
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk) return scopedRuntime;
3811
3908
  return new Set([...scopedRuntime, ...runtime]);
3812
3909
  }
3813
- function shouldIsolateScopedCssSource(source, sourceEntries) {
3814
- return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
3910
+ function shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, options) {
3911
+ if (options.target !== "weapp") return false;
3912
+ if (source.__weappTailwindcssMeta?.isolateCssSource) return true;
3913
+ if (source.__weappTailwindcssMeta?.matchedCssSourceFile && (sourceEntries?.length ?? 0) > 0) return true;
3914
+ if (sourceEntries?.length === 0) return false;
3915
+ return (majorVersion === 3 || majorVersion === 4) && sourceEntries !== void 0 && options.cssHandlerOptions?.isMainChunk !== true;
3815
3916
  }
3816
3917
  function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
3817
3918
  return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
@@ -3829,13 +3930,13 @@ function isEmptyCssSourceOrderParts(parts) {
3829
3930
  return parts.before.trim().length === 0 && parts.after.trim().length === 0;
3830
3931
  }
3831
3932
  function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
3933
+ const resolvedStyleOptions = resolveStyleOptionsFromContext(opts);
3832
3934
  const preflightStyleOptions = {
3833
- cssPreflight: opts.cssPreflight,
3834
- cssPreflightRange: opts.cssPreflightRange
3935
+ cssPreflight: resolvedStyleOptions.cssPreflight,
3936
+ cssPreflightRange: resolvedStyleOptions.cssPreflightRange
3835
3937
  };
3836
3938
  return {
3837
- ...resolveStyleOptionsFromContext(opts),
3838
- atRules: opts.atRules,
3939
+ ...resolvedStyleOptions,
3839
3940
  uniAppXCssTarget: opts.uniAppXCssTarget,
3840
3941
  uniAppXUnsupported: opts.uniAppXUnsupported,
3841
3942
  ...cssHandlerOptions,
@@ -3859,9 +3960,9 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
3859
3960
  if (exactParts) return exactParts;
3860
3961
  return splitTailwindGeneratedCssByBanner(rawSource);
3861
3962
  }
3862
- function shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, options) {
3963
+ function shouldUseGeneratorForCurrentCss(_majorVersion, cssHandlerOptions, options) {
3863
3964
  const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
3864
- return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || majorVersion === 4 && hasApplyDirectives || cssHandlerOptions.isMainChunk;
3965
+ return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || hasApplyDirectives || cssHandlerOptions.isMainChunk;
3865
3966
  }
3866
3967
  function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
3867
3968
  return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
@@ -4378,98 +4479,53 @@ function extractStyleDirectiveSources(source) {
4378
4479
  let match = SFC_STYLE_BLOCK_RE.exec(source);
4379
4480
  while (match !== null) {
4380
4481
  const styleSource = match[1] ?? "";
4381
- if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
4482
+ if (hasTailwindSourceDirectives(styleSource, { importFallback: true })) styleSources.push(styleSource);
4382
4483
  match = SFC_STYLE_BLOCK_RE.exec(source);
4383
4484
  }
4384
4485
  if (styleSources.length > 0) return styleSources;
4385
- return hasTailwindSourceDirectives(source) ? [source] : [];
4486
+ return hasTailwindSourceDirectives(source, { importFallback: true }) ? [source] : [];
4386
4487
  }
4387
4488
  function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
4388
- for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
4389
- if (!(0, node_fs.existsSync)(sourceFile)) continue;
4390
- try {
4391
- const source = (0, node_fs.readFileSync)(sourceFile, "utf8");
4392
- for (const styleSource of extractStyleDirectiveSources(source)) {
4393
- const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
4394
- if (cssEntrySource) return {
4395
- ...cssEntrySource,
4396
- file: sourceFile
4397
- };
4398
- }
4399
- } catch {
4400
- continue;
4489
+ for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) try {
4490
+ const source = sourceOptions.sourceFile && node_path.default.resolve(sourceOptions.sourceFile) === node_path.default.resolve(sourceFile) && typeof sourceOptions.sourceCss === "string" ? sourceOptions.sourceCss : (0, node_fs.existsSync)(sourceFile) ? (0, node_fs.readFileSync)(sourceFile, "utf8") : void 0;
4491
+ if (source === void 0) continue;
4492
+ for (const styleSource of extractStyleDirectiveSources(source)) {
4493
+ const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
4494
+ if (cssEntrySource) return {
4495
+ ...cssEntrySource,
4496
+ file: sourceFile
4497
+ };
4401
4498
  }
4499
+ } catch {
4500
+ continue;
4402
4501
  }
4403
4502
  }
4404
4503
  //#endregion
4405
- //#region src/bundlers/shared/generator-css/source-resolver.ts
4406
- function resolvePostcssFromOption(cssHandlerOptions) {
4407
- const from = cssHandlerOptions.postcssOptions?.options?.from;
4408
- return typeof from === "string" && from.length > 0 ? from : void 0;
4409
- }
4410
- function resolvePostcssSourceFile(cssHandlerOptions) {
4411
- const from = resolvePostcssFromOption(cssHandlerOptions);
4412
- if (!from || !node_path.default.isAbsolute(from)) return;
4413
- return from.replace(/[?#].*$/, "");
4414
- }
4415
- function resolveCssHandlerSourceOptions(cssHandlerOptions) {
4416
- return cssHandlerOptions.sourceOptions;
4417
- }
4418
- function createCssEntrySources(cssEntries) {
4419
- return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
4420
- }
4421
- function mergeCssSources(cssSources, cssEntrySources) {
4422
- const merged = [];
4423
- const seenFiles = /* @__PURE__ */ new Set();
4424
- const addSource = (cssSource) => {
4425
- const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
4426
- if (file) {
4427
- if (seenFiles.has(file)) return;
4428
- seenFiles.add(file);
4429
- }
4430
- merged.push(cssSource);
4431
- };
4432
- for (const cssSource of cssSources ?? []) addSource(cssSource);
4433
- for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
4434
- return merged.length > 0 ? merged : void 0;
4435
- }
4436
- function createSingleTailwindV4SourceOptions(sourceOptions, options) {
4437
- return omitUndefined({
4438
- projectRoot: sourceOptions.projectRoot,
4439
- baseFallbacks: sourceOptions.baseFallbacks,
4440
- packageName: sourceOptions.packageName,
4441
- base: options.base,
4442
- css: options.css
4443
- });
4504
+ //#region src/bundlers/shared/generator-css/source-resolver/apply-reference.ts
4505
+ function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
4506
+ if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
4507
+ const utilities = collectTailwindApplyUtilities(css);
4508
+ return [
4509
+ `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
4510
+ utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
4511
+ css
4512
+ ].filter(Boolean).join("\n");
4444
4513
  }
4445
- async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
4446
- const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
4447
- if (!(0, node_fs.existsSync)(cssEntry)) return resolveTailwindV4Source({
4448
- ...omitUndefined(singleEntrySourceOptions),
4449
- cssEntries: [cssEntry]
4450
- });
4451
- const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
4452
- const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
4453
- const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
4454
- const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
4455
- ...sourceOptions,
4456
- sourceFile: sourceOptions.sourceFile ?? cssEntry
4457
- });
4458
- return withGeneratorSourceMetadata(await resolveTailwindV4Source({
4459
- ...omitUndefined(singleEntrySourceOptions),
4460
- base,
4461
- css: normalizeConfigDirective(css, config),
4462
- cssEntries: [cssEntry]
4463
- }), {
4464
- matchedCssSourceFile: cssEntry,
4465
- sourceBase: base,
4466
- sourceCss: css
4514
+ function collectTailwindApplyUtilities(css) {
4515
+ let root;
4516
+ try {
4517
+ root = _weapp_tailwindcss_postcss.postcss.parse(css);
4518
+ } catch {
4519
+ return [];
4520
+ }
4521
+ const utilities = /* @__PURE__ */ new Set();
4522
+ root.walkAtRules("apply", (rule) => {
4523
+ for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
4467
4524
  });
4525
+ return [...utilities].sort();
4468
4526
  }
4469
- function resolveCssSourceBase(file, cssHandlerOptions) {
4470
- const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
4471
- return node_path.default.dirname(node_path.default.resolve(normalized));
4472
- }
4527
+ //#endregion
4528
+ //#region src/bundlers/shared/generator-css/source-resolver/config.ts
4473
4529
  function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
4474
4530
  if (config && (0, node_fs.existsSync)(config)) return config;
4475
4531
  if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
@@ -4496,20 +4552,8 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
4496
4552
  for (const candidate of configCandidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
4497
4553
  return sourceOptions.config;
4498
4554
  }
4499
- function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
4500
- const from = resolvePostcssFromOption(cssHandlerOptions);
4501
- if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
4502
- return true;
4503
- }
4504
- function shouldResolveSourceSideCssEntry(rawSource) {
4505
- return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
4506
- }
4507
- function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
4508
- return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
4509
- }
4510
- function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
4511
- return Boolean(sourceSideEntrySource?.config) && Boolean(cssEntrySource?.configRequest) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
4512
- }
4555
+ //#endregion
4556
+ //#region src/bundlers/shared/generator-css/source-resolver/matching.ts
4513
4557
  function normalizeCssSourceForCompare(css) {
4514
4558
  return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
4515
4559
  }
@@ -4560,6 +4604,107 @@ function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
4560
4604
  else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
4561
4605
  return bestScore;
4562
4606
  }
4607
+ //#endregion
4608
+ //#region src/bundlers/shared/generator-css/source-resolver/metadata.ts
4609
+ function withGeneratorSourceMetadata(source, metadata) {
4610
+ return {
4611
+ ...source,
4612
+ __weappTailwindcssMeta: metadata
4613
+ };
4614
+ }
4615
+ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
4616
+ return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
4617
+ isolateCssSource: true,
4618
+ matchedCssSourceFile: resolvedEntrySource.file,
4619
+ sourceBase: resolvedEntrySource.base,
4620
+ sourceCss: resolvedEntrySource.css
4621
+ }) : source;
4622
+ }
4623
+ //#endregion
4624
+ //#region src/bundlers/shared/generator-css/source-resolver/postcss-source.ts
4625
+ function resolvePostcssFromOption(cssHandlerOptions) {
4626
+ const from = cssHandlerOptions.postcssOptions?.options?.from;
4627
+ return typeof from === "string" && from.length > 0 ? from : void 0;
4628
+ }
4629
+ function resolvePostcssSourceFile(cssHandlerOptions) {
4630
+ const from = resolvePostcssFromOption(cssHandlerOptions);
4631
+ if (!from || !node_path.default.isAbsolute(from)) return;
4632
+ return from.replace(/[?#].*$/, "");
4633
+ }
4634
+ function resolveCssHandlerSourceOptions(cssHandlerOptions) {
4635
+ return cssHandlerOptions.sourceOptions;
4636
+ }
4637
+ function resolveCssSourceBase(file, cssHandlerOptions) {
4638
+ const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
4639
+ return node_path.default.dirname(node_path.default.resolve(normalized));
4640
+ }
4641
+ //#endregion
4642
+ //#region src/bundlers/shared/generator-css/source-resolver.ts
4643
+ function createCssEntrySources(cssEntries) {
4644
+ return cssEntries?.filter((entry) => typeof entry === "string" && entry.length > 0 && node_path.default.isAbsolute(entry)).map((entry) => ({ file: node_path.default.resolve(entry) }));
4645
+ }
4646
+ function mergeCssSources(cssSources, cssEntrySources) {
4647
+ const merged = [];
4648
+ const seenFiles = /* @__PURE__ */ new Set();
4649
+ const addSource = (cssSource) => {
4650
+ const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? node_path.default.resolve(cssSource.file) : void 0;
4651
+ if (file) {
4652
+ if (seenFiles.has(file)) return;
4653
+ seenFiles.add(file);
4654
+ }
4655
+ merged.push(cssSource);
4656
+ };
4657
+ for (const cssSource of cssSources ?? []) addSource(cssSource);
4658
+ for (const cssSource of cssEntrySources ?? []) addSource(cssSource);
4659
+ return merged.length > 0 ? merged : void 0;
4660
+ }
4661
+ function createSingleTailwindV4SourceOptions(sourceOptions, options) {
4662
+ return omitUndefined({
4663
+ projectRoot: sourceOptions.projectRoot,
4664
+ baseFallbacks: sourceOptions.baseFallbacks,
4665
+ packageName: sourceOptions.packageName,
4666
+ base: options.base,
4667
+ css: options.css
4668
+ });
4669
+ }
4670
+ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
4671
+ const { cssEntries: _cssEntries, cssSources: _cssSources, ...singleEntrySourceOptions } = sourceOptions;
4672
+ if (!(0, node_fs.existsSync)(cssEntry)) return resolveTailwindV4Source({
4673
+ ...omitUndefined(singleEntrySourceOptions),
4674
+ cssEntries: [cssEntry]
4675
+ });
4676
+ const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
4677
+ const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
4678
+ const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
4679
+ const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
4680
+ ...sourceOptions,
4681
+ sourceFile: sourceOptions.sourceFile ?? cssEntry
4682
+ });
4683
+ return withGeneratorSourceMetadata(await resolveTailwindV4Source({
4684
+ ...omitUndefined(singleEntrySourceOptions),
4685
+ base,
4686
+ css: normalizeConfigDirective(css, config),
4687
+ cssEntries: [cssEntry]
4688
+ }), {
4689
+ matchedCssSourceFile: cssEntry,
4690
+ sourceBase: base,
4691
+ sourceCss: css
4692
+ });
4693
+ }
4694
+ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
4695
+ const from = resolvePostcssFromOption(cssHandlerOptions);
4696
+ if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file) || Boolean(sourceOptions?.sourceFile) || Boolean(sourceOptions?.cssSources?.length);
4697
+ return true;
4698
+ }
4699
+ function shouldResolveSourceSideCssEntry(rawSource) {
4700
+ return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
4701
+ }
4702
+ function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
4703
+ return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
4704
+ }
4705
+ function shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource) {
4706
+ return Boolean(sourceSideEntrySource?.config) && (Boolean(cssEntrySource?.configRequest) || !cssEntrySource?.config) && (!cssEntrySource?.config || !(0, node_fs.existsSync)(cssEntrySource.config));
4707
+ }
4563
4708
  function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
4564
4709
  const cssEntries = sourceOptions.cssEntries;
4565
4710
  if (!cssEntries?.length) return;
@@ -4737,12 +4882,6 @@ async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourc
4737
4882
  css
4738
4883
  })), resolvedEntrySource);
4739
4884
  }
4740
- function withGeneratorSourceMetadata(source, metadata) {
4741
- return {
4742
- ...source,
4743
- __weappTailwindcssMeta: metadata
4744
- };
4745
- }
4746
4885
  function resolveTailwindV3SourceEntries(source) {
4747
4886
  if (!("version" in source) || source.version !== 3) return;
4748
4887
  const entries = normalizeLegacyContentEntries(source.configObject?.content, source.cwd, { relativeBase: source.config ? node_path.default.dirname(source.config) : source.cwd });
@@ -4752,35 +4891,6 @@ function withTailwindV3SourceMetadata(source) {
4752
4891
  const sourceEntries = resolveTailwindV3SourceEntries(source);
4753
4892
  return sourceEntries ? withGeneratorSourceMetadata(source, { sourceEntries }) : source;
4754
4893
  }
4755
- function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
4756
- return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
4757
- matchedCssSourceFile: resolvedEntrySource.file,
4758
- sourceBase: resolvedEntrySource.base,
4759
- sourceCss: resolvedEntrySource.css
4760
- }) : source;
4761
- }
4762
- function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
4763
- if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
4764
- const utilities = collectTailwindApplyUtilities(css);
4765
- return [
4766
- `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
4767
- utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
4768
- css
4769
- ].filter(Boolean).join("\n");
4770
- }
4771
- function collectTailwindApplyUtilities(css) {
4772
- let root;
4773
- try {
4774
- root = _weapp_tailwindcss_postcss.postcss.parse(css);
4775
- } catch {
4776
- return [];
4777
- }
4778
- const utilities = /* @__PURE__ */ new Set();
4779
- root.walkAtRules("apply", (rule) => {
4780
- for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
4781
- });
4782
- return [...utilities].sort();
4783
- }
4784
4894
  async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
4785
4895
  const base = resolveCssSourceBase(file, cssHandlerOptions);
4786
4896
  const cssEntrySource = resolveCssEntrySource(rawSource, base, {
@@ -4813,15 +4923,19 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
4813
4923
  css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
4814
4924
  ...config ? { config } : {}
4815
4925
  }));
4926
+ const cssEntrySourceEntries = await resolveTailwindConfigEntriesFromCssCached(rawSource, resolvedEntrySource.base);
4927
+ const sourceMetadata = sourceWithMetadata.__weappTailwindcssMeta;
4928
+ const matchedSourceFile = resolvedEntrySource.file ?? sourceSideEntrySource?.file;
4816
4929
  return withGeneratorSourceMetadata(sourceWithMetadata, {
4817
- ...sourceWithMetadata.__weappTailwindcssMeta,
4818
- matchedCssSourceFile: resolvedEntrySource.file
4930
+ ...sourceMetadata,
4931
+ matchedCssSourceFile: matchedSourceFile,
4932
+ sourceEntries: cssEntrySourceEntries?.entries ?? sourceMetadata?.sourceEntries
4819
4933
  });
4820
4934
  }
4821
4935
  const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
4822
4936
  const resolvedSourceOptions = sourceOptions ? omitUndefined({
4823
4937
  ...sourceOptions,
4824
- sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
4938
+ sourceFile: sourceOptions.sourceFile ?? resolvePostcssSourceFile(cssHandlerOptions),
4825
4939
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
4826
4940
  cssEntries: selectionOptions?.cssEntries ?? sourceOptions.cssEntries,
4827
4941
  cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
@@ -4835,17 +4949,18 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
4835
4949
  }));
4836
4950
  }
4837
4951
  const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
4838
- const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
4952
+ const sourceSideEntrySource = normalizedSourceOptions && (shouldPreferSourceSideEntry || normalizedSourceOptions.sourceFile !== void 0) && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
4839
4953
  const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
4840
4954
  const matchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, normalizedSourceOptions) : void 0;
4841
4955
  const candidateMatchedCssSource = normalizedSourceOptions && !matchedCssEntrySource ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, normalizedSourceOptions, selectionOptions) : void 0;
4842
- const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await resolveTailwindV4Source(normalizedSourceOptions) : void 0;
4956
+ const singleConfiguredCssSource = normalizedSourceOptions?.cssSources?.length === 1 ? await resolveSingleTailwindV4CssSource(normalizedSourceOptions.cssSources[0], normalizedSourceOptions, { matched: true }) : void 0;
4957
+ const configuredCssSource = normalizedSourceOptions && hasConfiguredTailwindV4CssSource(normalizedSourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? singleConfiguredCssSource ?? await resolveTailwindV4Source(normalizedSourceOptions) : void 0;
4843
4958
  if (configuredCssSource) return generatorOptions?.config ? {
4844
4959
  ...configuredCssSource,
4845
4960
  css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
4846
4961
  } : configuredCssSource;
4847
4962
  const mainCssEntrySource = normalizedSourceOptions && cssHandlerOptions.isMainChunk && normalizedSourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4CssEntrySource(normalizedSourceOptions.cssEntries[0], normalizedSourceOptions) : void 0;
4848
- const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
4963
+ const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource ?? singleConfiguredCssSource;
4849
4964
  if (preferredCssEntrySource) return generatorOptions?.config ? {
4850
4965
  ...preferredCssEntrySource,
4851
4966
  css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
@@ -4885,7 +5000,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
4885
5000
  sourceFile: resolvePostcssSourceFile(cssHandlerOptions),
4886
5001
  ...resolveCssHandlerSourceOptions(cssHandlerOptions),
4887
5002
  cssEntries,
4888
- cssSources: mergeCssSources(sourceOptionsFromPatcher.cssSources, sourceOptionsFromPatcher.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
5003
+ cssSources: mergeCssSources(mergeCssSources(sourceOptionsFromPatcher.cssSources, selectionOptions?.cssSources), sourceOptionsFromPatcher.cssSources?.length || selectionOptions?.cssSources?.length ? void 0 : createCssEntrySources(cssEntries))
4889
5004
  });
4890
5005
  } catch {
4891
5006
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
@@ -4896,7 +5011,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
4896
5011
  ...matchedCssEntrySource,
4897
5012
  css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
4898
5013
  } : matchedCssEntrySource];
4899
- const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
5014
+ const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
4900
5015
  if (sourceSideCssSource) return [sourceSideCssSource];
4901
5016
  const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
4902
5017
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
@@ -4931,6 +5046,10 @@ async function resolveGeneratorSourceEntries(source, runtimeState) {
4931
5046
  if (sourceMetadata?.sourceEntries) return sourceMetadata.sourceEntries;
4932
5047
  if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
4933
5048
  const resolved = await resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
5049
+ if (resolved?.entries.length === 0 && !resolved.inlineCandidates.included.size && !resolved.inlineCandidates.excluded.size && !resolved.dependencies.length) {
5050
+ if (sourceMetadata?.matchedCssSourceFile) return [];
5051
+ return;
5052
+ }
4934
5053
  if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
4935
5054
  const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
4936
5055
  if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && node_path.default.resolve(cssSource.file) === node_path.default.resolve(sourceMetadata.matchedCssSourceFile)) return true;
@@ -5354,6 +5473,16 @@ function isCommentOnlyCss(source) {
5354
5473
  return false;
5355
5474
  }
5356
5475
  }
5476
+ function unwrapMiniProgramCascadeLayers(source) {
5477
+ if (!source.includes("@layer")) return source;
5478
+ try {
5479
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
5480
+ (0, _weapp_tailwindcss_postcss.removeUnsupportedCascadeLayers)(root);
5481
+ return root.toString();
5482
+ } catch {
5483
+ return source;
5484
+ }
5485
+ }
5357
5486
  function stripTailwindSourceMediaFragments(source) {
5358
5487
  let removedSourceMediaStart = false;
5359
5488
  return source.split(/\r?\n/).filter((line) => {
@@ -5521,7 +5650,7 @@ async function transformGeneratorUserCss(source, options) {
5521
5650
  if (source.trim().length === 0) return "";
5522
5651
  const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
5523
5652
  if (cleanedSource.trim().length === 0) return "";
5524
- const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
5653
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource)) : cleanedSource)), { importFallback: options.importFallback })));
5525
5654
  if (userSource.trim().length === 0) return "";
5526
5655
  if (isCommentOnlyCss(userSource)) return userSource;
5527
5656
  if (options.generatorTarget !== "weapp") return userSource;
@@ -5671,6 +5800,7 @@ async function generateCssByGenerator(options) {
5671
5800
  const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
5672
5801
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
5673
5802
  cssEntries: opts.cssEntries,
5803
+ cssSources: options.cssSources,
5674
5804
  getSourceCandidatesForEntries,
5675
5805
  runtime: runtimeWithCurrentCss
5676
5806
  });
@@ -5680,18 +5810,22 @@ async function generateCssByGenerator(options) {
5680
5810
  const generated = mergeGeneratorResults((await runWithConcurrency(sources.map((source) => async () => {
5681
5811
  const generator = createWeappTailwindcssGenerator(source);
5682
5812
  const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
5683
- const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
5684
- const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
5813
+ const scopedRuntime = sourceEntries && sourceEntries.length > 0 ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
5814
+ const isolateCssSource = shouldIsolateScopedCssSource(majorVersion, source, sourceEntries, {
5815
+ cssHandlerOptions,
5816
+ target: generatorOptions.target
5817
+ });
5685
5818
  const sourceMetadata = source.__weappTailwindcssMeta;
5686
5819
  const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
5687
5820
  if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
5688
5821
  debug("defer empty scoped css source generation: %s", file);
5689
5822
  return;
5690
5823
  }
5691
- const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
5824
+ const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) || isolateCssSource ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime ?? /* @__PURE__ */ new Set(), runtimeWithCurrentCss, {
5692
5825
  currentCssCandidates,
5693
5826
  cssHandlerOptions,
5694
5827
  isolateCssSource,
5828
+ majorVersion,
5695
5829
  matchedCssSourceFile
5696
5830
  }) : runtimeWithCurrentCss;
5697
5831
  const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
@@ -5711,7 +5845,10 @@ async function generateCssByGenerator(options) {
5711
5845
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
5712
5846
  const incrementalCss = stripTailwindBanner(generated.incrementalCss);
5713
5847
  return {
5714
- css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss, localImportParts?.imports),
5848
+ css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, {
5849
+ injectPreflight: false,
5850
+ styleOptions: generatorStyleOptions
5851
+ })) : options.previousCss, localImportParts?.imports),
5715
5852
  target: generated.target,
5716
5853
  source: "generator",
5717
5854
  dependencies: generated.dependencies,
@@ -5743,7 +5880,8 @@ async function generateCssByGenerator(options) {
5743
5880
  const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
5744
5881
  const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
5745
5882
  const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
5746
- css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
5883
+ const fallbackLayerUserCss = generated.target === "weapp" && afterLayerParts.layer.trim().length === 0 && hasUserCssLayerBlocks(userCssRawSource) ? await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, userCssOptions) : "";
5884
+ css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(createCssSourceOrderAppend$1(afterLayerUserCss, fallbackLayerUserCss)) : afterLayerUserCss), css), afterUserCss);
5747
5885
  if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
5748
5886
  hasSourceDirectives,
5749
5887
  hasMatchedCssSourceFile
@@ -5759,11 +5897,14 @@ async function generateCssByGenerator(options) {
5759
5897
  }
5760
5898
  } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
5761
5899
  return {
5762
- css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5763
- cssHandlerOptions,
5764
- isolateCurrentCssCandidates,
5765
- localImports: localImportParts?.imports
5766
- }) }), localImportParts?.imports),
5900
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
5901
+ injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5902
+ cssHandlerOptions,
5903
+ isolateCurrentCssCandidates,
5904
+ localImports: localImportParts?.imports
5905
+ }),
5906
+ styleOptions: generatorStyleOptions
5907
+ }), localImportParts?.imports),
5767
5908
  target: generated.target,
5768
5909
  source: "generator",
5769
5910
  dependencies: generated.dependencies
@@ -5802,6 +5943,18 @@ async function generateCssByGenerator(options) {
5802
5943
  importFallback: generatorOptions.importFallback
5803
5944
  });
5804
5945
  css = createCssSourceOrderAppend$1(css, userCss);
5946
+ } else if (hasMatchedCssSourceFile && generated.target === "weapp" && hasUserCssLayerBlocks(userCssRawSource)) {
5947
+ const layerUserCss = await transformGeneratorUserCss(splitUserCssLayerBlocks(userCssRawSource).layer, {
5948
+ generatorTarget: generated.target,
5949
+ generatorStyleOptions,
5950
+ cssUserHandlerOptions,
5951
+ styleHandler,
5952
+ importFallback: generatorOptions.importFallback
5953
+ });
5954
+ if (layerUserCss.trim().length > 0) {
5955
+ css = createCssSourceOrderAppend$1(css, wrapUserLayerComponentsCss(layerUserCss));
5956
+ if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
5957
+ }
5805
5958
  }
5806
5959
  if (hasMatchedCssSourceFile && generated.target === "weapp") {
5807
5960
  if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
@@ -5820,11 +5973,14 @@ async function generateCssByGenerator(options) {
5820
5973
  css = createCssSourceOrderAppend$1(css, userCss);
5821
5974
  }
5822
5975
  return {
5823
- css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5824
- cssHandlerOptions,
5825
- isolateCurrentCssCandidates,
5826
- localImports: localImportParts?.imports
5827
- }) }), localImportParts?.imports),
5976
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
5977
+ injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5978
+ cssHandlerOptions,
5979
+ isolateCurrentCssCandidates,
5980
+ localImports: localImportParts?.imports
5981
+ }),
5982
+ styleOptions: generatorStyleOptions
5983
+ }), localImportParts?.imports),
5828
5984
  target: generated.target,
5829
5985
  source: "generator",
5830
5986
  dependencies: generated.dependencies
@@ -5835,11 +5991,14 @@ async function generateCssByGenerator(options) {
5835
5991
  css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
5836
5992
  }
5837
5993
  return {
5838
- css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5839
- cssHandlerOptions,
5840
- isolateCurrentCssCandidates,
5841
- localImports: localImportParts?.imports
5842
- }) }), localImportParts?.imports),
5994
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, {
5995
+ injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
5996
+ cssHandlerOptions,
5997
+ isolateCurrentCssCandidates,
5998
+ localImports: localImportParts?.imports
5999
+ }),
6000
+ styleOptions: generatorStyleOptions
6001
+ }), localImportParts?.imports),
5843
6002
  target: generated.target,
5844
6003
  source: "generator",
5845
6004
  dependencies: generated.dependencies
@@ -5897,6 +6056,7 @@ async function generateCssForWebpackPipeline(source, loaderContext, options) {
5897
6056
  if (!compilerOptions || !runtimeState || !getRuntimeSet) return;
5898
6057
  await runtimeState.readyPromise;
5899
6058
  const runtime = await getRuntimeSet();
6059
+ if (compilerOptions.generator?.target !== "web") return;
5900
6060
  const file = loaderContext.resourcePath;
5901
6061
  const normalizedSource = normalizeCssConfigDirectives(source, file);
5902
6062
  const cssHandlerOptions = createCssHandlerOptions(compilerOptions, runtimeState.twPatcher.majorVersion, file, rewriteOptions.appType);