weapp-tailwindcss 5.0.13 → 5.1.0

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 (178) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/auto-Ba6hDrse.mjs +13 -0
  4. package/dist/auto-DtU6f3X6.js +18 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
  7. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +21 -9
  8. package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
  9. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
  11. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
  12. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
  14. package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
  15. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
  16. package/dist/bundlers/shared/run-tasks.d.ts +1 -0
  17. package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
  18. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  19. package/dist/bundlers/vite/css-memory.d.ts +10 -0
  20. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
  21. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
  23. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +0 -1
  24. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
  25. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -0
  26. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
  27. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
  28. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
  29. package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -1
  30. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
  31. package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
  32. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
  33. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
  34. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  35. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
  36. package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
  37. package/dist/bundlers/vite/source-candidates.d.ts +9 -2
  38. package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
  39. package/dist/bundlers/vite/source-scan.d.ts +2 -2
  40. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
  41. package/dist/bundlers/vite/utils.d.ts +1 -0
  42. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
  43. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
  44. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
  45. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
  46. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
  47. package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
  48. package/dist/cache/index.d.ts +1 -0
  49. package/dist/cli/mount-options.d.ts +2 -2
  50. package/dist/cli.js +124 -437
  51. package/dist/cli.mjs +120 -433
  52. package/dist/context/index.d.ts +3 -3
  53. package/dist/context/style-options.d.ts +4 -1
  54. package/dist/context/tailwindcss.d.ts +1 -1
  55. package/dist/{precheck-B0Z8yW7E.js → context-BHxLe743.js} +391 -153
  56. package/dist/{precheck-CRI90iL1.mjs → context-Mbzkek1q.mjs} +368 -137
  57. package/dist/core.js +15 -12
  58. package/dist/core.mjs +10 -7
  59. package/dist/css-macro.js +1 -1
  60. package/dist/css-macro.mjs +1 -1
  61. package/dist/{defaults-C_J_kBpw.js → defaults-CVcKbXBG.js} +4 -15
  62. package/dist/{defaults-Bqx18S1f.mjs → defaults-ZElj1zKc.mjs} +5 -10
  63. package/dist/defaults.d.ts +1 -7
  64. package/dist/defaults.js +1 -2
  65. package/dist/defaults.mjs +2 -2
  66. package/dist/generator/index.d.ts +6 -7
  67. package/dist/generator/options.d.ts +3 -3
  68. package/dist/generator/types.d.ts +9 -10
  69. package/dist/generator-9rUz4Hcb.js +170 -0
  70. package/dist/generator-Dc4qaPmT.mjs +123 -0
  71. package/dist/generator.js +10 -16
  72. package/dist/generator.mjs +3 -3
  73. package/dist/{gulp-XT8Jc7lH.js → gulp-B_sdP6dx.js} +47 -87
  74. package/dist/{gulp-DfOQERcV.mjs → gulp-uM36oIJs.mjs} +40 -80
  75. package/dist/gulp.js +1 -1
  76. package/dist/gulp.mjs +1 -1
  77. package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-BXMLsF4b.mjs} +1145 -842
  78. package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CogqkFaF.js} +1262 -881
  79. package/dist/index.js +4 -4
  80. package/dist/index.mjs +4 -4
  81. package/dist/js/fast-path/oxc.d.ts +4 -0
  82. package/dist/js/precheck.d.ts +1 -0
  83. package/dist/postcss.js +3 -4
  84. package/dist/postcss.mjs +2 -3
  85. package/dist/presets.js +9 -19
  86. package/dist/presets.mjs +8 -18
  87. package/dist/runtime-branch/create-branch.d.ts +2 -0
  88. package/dist/runtime-branch/generator-target-env.d.ts +4 -0
  89. package/dist/runtime-branch/index.d.ts +6 -0
  90. package/dist/runtime-branch/mini-program.d.ts +2 -0
  91. package/dist/runtime-branch/native-app.d.ts +2 -0
  92. package/dist/runtime-branch/platform.d.ts +6 -0
  93. package/dist/runtime-branch/tailwind-version.d.ts +2 -0
  94. package/dist/runtime-branch/types.d.ts +37 -0
  95. package/dist/runtime-branch/web.d.ts +2 -0
  96. package/dist/runtime-branch.d.ts +1 -0
  97. package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-2ybpptAK.js} +261 -19
  98. package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
  99. package/dist/tailwindcss/candidates.d.ts +7 -0
  100. package/dist/tailwindcss/index.d.ts +2 -2
  101. package/dist/tailwindcss/runtime/cache.d.ts +6 -6
  102. package/dist/tailwindcss/runtime-factory.d.ts +12 -0
  103. package/dist/tailwindcss/runtime-options.d.ts +8 -0
  104. package/dist/tailwindcss/runtime-types.d.ts +86 -0
  105. package/dist/tailwindcss/runtime.d.ts +6 -6
  106. package/dist/tailwindcss/source-scan.d.ts +1 -1
  107. package/dist/tailwindcss/targets.d.ts +2 -2
  108. package/dist/tailwindcss/v4/config.d.ts +3 -3
  109. package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
  110. package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
  111. package/dist/tailwindcss/v4/index.d.ts +1 -1
  112. package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
  113. package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
  114. package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
  115. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  116. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
  117. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
  118. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
  119. package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
  120. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  121. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
  122. package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
  123. package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
  124. package/dist/tailwindcss/version.d.ts +1 -1
  125. package/dist/tailwindcss-DHIYcqXT.js +1523 -0
  126. package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
  127. package/dist/{transform-YmrmxuF3.js → transform-CQVOgmzM.js} +17 -17
  128. package/dist/{transform-DfcEjsZF.mjs → transform-tExdt40m.mjs} +2 -2
  129. package/dist/typedoc.export.d.ts +1 -1
  130. package/dist/types/index.d.ts +16 -17
  131. package/dist/types/shared.d.ts +1 -1
  132. package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
  133. package/dist/types/user-defined-options/general.d.ts +5 -3
  134. package/dist/types/user-defined-options/important.d.ts +2 -2
  135. package/dist/uni-app-x/style-asset.d.ts +1 -0
  136. package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
  137. package/dist/v4-engine-D4ubP7N5.js +2778 -0
  138. package/dist/{vite-CXHVsHmX.js → vite-CP0ylSxZ.js} +1081 -542
  139. package/dist/{vite-DjI09vVN.mjs → vite-CPO83EhA.mjs} +916 -376
  140. package/dist/vite.js +1 -1
  141. package/dist/vite.mjs +1 -1
  142. package/dist/weapp-tw-css-import-rewrite-loader.js +5350 -4165
  143. package/dist/weapp-tw-runtime-classset-loader.js +15 -4
  144. package/dist/webpack-Bsek8VhR.js +2094 -0
  145. package/dist/webpack-BzqhJ8yK.mjs +2082 -0
  146. package/dist/webpack.js +1 -1
  147. package/dist/webpack.mjs +1 -1
  148. package/package.json +4 -5
  149. package/dist/auto-CTp6wE5a.js +0 -33
  150. package/dist/auto-Cl8_hsG6.mjs +0 -22
  151. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
  152. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
  153. package/dist/context/tailwindcss/rax.d.ts +0 -2
  154. package/dist/generator-CzpArpCL.js +0 -92
  155. package/dist/generator-ITLd7PTl.mjs +0 -67
  156. package/dist/tailwindcss/patcher-options.d.ts +0 -8
  157. package/dist/tailwindcss/patcher.d.ts +0 -12
  158. package/dist/tailwindcss/runtime-patch.d.ts +0 -5
  159. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
  160. package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
  161. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
  162. package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
  163. package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
  164. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
  165. package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
  166. package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
  167. package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
  168. package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
  169. package/dist/tailwindcss/v4/patcher.d.ts +0 -15
  170. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
  171. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
  172. package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
  173. package/dist/tailwindcss-DZEwT3C_.js +0 -613
  174. package/dist/v3-engine-2rrgylhn.js +0 -4686
  175. package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
  176. package/dist/webpack-BcPpnT90.mjs +0 -1184
  177. package/dist/webpack-CfkUkMXG.js +0 -1196
  178. /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
@@ -1,556 +0,0 @@
1
- import { ct as readInstalledPackageMajorVersion, dt as normalizeStringListOption, gt as omitUndefined, ht as findWorkspaceRoot, mt as findWorkspacePackageDir, p as runtimeSignaturePatchersSymbol, pt as findNearestPackageRoot, st as createTailwindcssPatcher } from "./v3-engine-C6eJ0YzK.mjs";
2
- import { n as defuOverrideArray } from "./utils-DodxWHGz.mjs";
3
- import { createRequire } from "node:module";
4
- import { existsSync, readFileSync } from "node:fs";
5
- import path from "node:path";
6
- import process from "node:process";
7
- import { logger } from "@weapp-tailwindcss/logger";
8
- import { fileURLToPath } from "node:url";
9
- //#region src/tailwindcss/v4/css-sources.ts
10
- function hasCssEntriesValue(value) {
11
- if (typeof value === "string") return value.trim().length > 0;
12
- return Array.isArray(value) && value.some((entry) => typeof entry === "string" && entry.trim().length > 0);
13
- }
14
- function hasCssSourcesValue(value) {
15
- return Array.isArray(value) && value.some((source) => {
16
- return typeof source === "object" && source !== null && typeof source.css === "string" && source.css.trim().length > 0;
17
- });
18
- }
19
- function hasConfiguredTailwindV4CssRoots(options) {
20
- return hasCssEntriesValue(options.cssEntries) || hasCssEntriesValue(options.tailwindcss?.v4?.cssEntries) || hasCssEntriesValue(options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries) || hasCssSourcesValue(options.tailwindcss?.v4?.cssSources) || hasCssSourcesValue(options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources);
21
- }
22
- function normalizeCssSourceFile(file) {
23
- if (!file) return;
24
- return path.isAbsolute(file) ? path.normalize(file) : file;
25
- }
26
- function normalizeCssSourceBase(base) {
27
- if (!base) return;
28
- return path.resolve(base);
29
- }
30
- function normalizeDependencies(dependencies) {
31
- return dependencies?.map(normalizeCssSourceFile).filter((dependency) => typeof dependency === "string" && dependency.length > 0);
32
- }
33
- function isSameCssSource(a, b) {
34
- return a.css === b.css && normalizeCssSourceBase(a.base) === normalizeCssSourceBase(b.base) && normalizeCssSourceFile(a.file) === normalizeCssSourceFile(b.file) && JSON.stringify(normalizeDependencies(a.dependencies)) === JSON.stringify(normalizeDependencies(b.dependencies));
35
- }
36
- function upsertTailwindV4CssSource(opts, source) {
37
- const normalizedSource = omitUndefined({
38
- ...source,
39
- ...source.base === void 0 ? {} : { base: normalizeCssSourceBase(source.base) },
40
- ...source.file === void 0 ? {} : { file: normalizeCssSourceFile(source.file) },
41
- ...source.dependencies === void 0 ? {} : { dependencies: normalizeDependencies(source.dependencies) }
42
- });
43
- const tailwindcss = opts.tailwindcss ?? {};
44
- const v4 = tailwindcss.v4 ?? {};
45
- const cssSources = [...v4.cssSources ?? []];
46
- const sourceFile = normalizeCssSourceFile(normalizedSource.file);
47
- const existingIndex = cssSources.findIndex((candidate) => normalizeCssSourceFile(candidate.file) === sourceFile);
48
- if (existingIndex >= 0) {
49
- const existing = cssSources[existingIndex];
50
- if (!existing) {
51
- cssSources[existingIndex] = normalizedSource;
52
- return true;
53
- }
54
- const nextSource = {
55
- ...existing,
56
- ...normalizedSource
57
- };
58
- if (isSameCssSource(existing, nextSource)) return false;
59
- cssSources[existingIndex] = nextSource;
60
- } else cssSources.push(normalizedSource);
61
- opts.tailwindcss = {
62
- ...tailwindcss,
63
- v4: {
64
- ...v4,
65
- cssSources
66
- }
67
- };
68
- return true;
69
- }
70
- //#endregion
71
- //#region src/tailwindcss/v4/config.ts
72
- const DEFAULT_CSS_CALC_CUSTOM_PROPERTIES = [];
73
- function includesToken(list, token) {
74
- return list.some((candidate) => {
75
- if (typeof token === "string") {
76
- if (typeof candidate === "string") return candidate === token;
77
- candidate.lastIndex = 0;
78
- return candidate.test(token);
79
- }
80
- if (typeof candidate === "string") {
81
- token.lastIndex = 0;
82
- return token.test(candidate);
83
- }
84
- return candidate.source === token.source && candidate.flags === token.flags;
85
- });
86
- }
87
- function ensureDefaultsIncluded(value) {
88
- if (value === true) return { includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES] };
89
- if (Array.isArray(value)) {
90
- if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) return value;
91
- const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(value, token));
92
- return missing.length > 0 ? [...value, ...missing] : value;
93
- }
94
- if (value && typeof value === "object") {
95
- const include = value.includeCustomProperties;
96
- if (!Array.isArray(include)) return {
97
- ...value,
98
- includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
99
- };
100
- if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) return value;
101
- const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(include, token));
102
- return missing.length > 0 ? {
103
- ...value,
104
- includeCustomProperties: [...include, ...missing]
105
- } : value;
106
- }
107
- return value;
108
- }
109
- function normalizeCssEntriesConfig(entries) {
110
- return normalizeStringListOption(entries);
111
- }
112
- function hasConfiguredCssEntries(ctx) {
113
- if (normalizeCssEntriesConfig(ctx.cssEntries)) return true;
114
- if (normalizeCssEntriesConfig(ctx.tailwindcss?.v4?.cssEntries)) return true;
115
- const patcherOptions = ctx.tailwindcssPatcherOptions;
116
- if (patcherOptions) {
117
- if (normalizeCssEntriesConfig(patcherOptions.tailwindcss?.v4?.cssEntries)) return true;
118
- }
119
- return false;
120
- }
121
- let hasWarnedMissingCssEntries = false;
122
- function warnMissingCssEntries(ctx, patcher) {
123
- if (hasWarnedMissingCssEntries) return;
124
- if (patcher?.majorVersion !== 4) return;
125
- if (hasConfiguredCssEntries(ctx) || hasConfiguredTailwindV4CssRoots(ctx)) return;
126
- hasWarnedMissingCssEntries = true;
127
- logger.warn("[tailwindcss@4] 未检测到 cssEntries 配置。请传入包含 tailwindcss 引用的 CSS 绝对路径,例如 cssEntries: [\"/absolute/path/to/src/app.css\"],否则 tailwindcss 生成的类名不会参与转译。");
128
- }
129
- function applyV4CssCalcDefaults(cssCalc, patcher) {
130
- const cssCalcOptions = cssCalc ?? patcher?.majorVersion === 4;
131
- if (patcher?.majorVersion === 4 && cssCalcOptions) return ensureDefaultsIncluded(cssCalcOptions);
132
- return cssCalcOptions;
133
- }
134
- //#endregion
135
- //#region src/tailwindcss/v4/multi-patcher.ts
136
- function createMultiTailwindcssPatcher(patchers) {
137
- if (patchers.length <= 1) {
138
- const [patcher] = patchers;
139
- if (!patcher) throw new Error("createMultiTailwindcssPatcher requires at least one patcher.");
140
- return patcher;
141
- }
142
- const first = patchers[0];
143
- const firstWithoutPatch = { ...first };
144
- delete firstWithoutPatch.patch;
145
- const multiPatcher = {
146
- ...firstWithoutPatch,
147
- packageInfo: first?.packageInfo,
148
- majorVersion: first?.majorVersion,
149
- options: first?.options,
150
- async getClassSet() {
151
- const aggregated = /* @__PURE__ */ new Set();
152
- for (const patcher of patchers) {
153
- const current = await patcher.getClassSet();
154
- for (const className of current) aggregated.add(className);
155
- }
156
- return aggregated;
157
- },
158
- async extract(options) {
159
- const aggregatedSet = /* @__PURE__ */ new Set();
160
- const aggregatedList = [];
161
- let filename;
162
- for (const patcher of patchers) {
163
- const result = await patcher.extract(options);
164
- if (!result) continue;
165
- if (filename === void 0 && result.filename) filename = result.filename;
166
- if (result.classList) for (const className of result.classList) {
167
- if (!aggregatedSet.has(className)) aggregatedList.push(className);
168
- aggregatedSet.add(className);
169
- }
170
- if (result.classSet) for (const className of result.classSet) aggregatedSet.add(className);
171
- }
172
- return omitUndefined({
173
- classList: aggregatedList,
174
- classSet: aggregatedSet,
175
- filename
176
- });
177
- }
178
- };
179
- if (patchers.every((patcher) => typeof patcher.getClassSetSync === "function")) multiPatcher.getClassSetSync = () => {
180
- const aggregated = /* @__PURE__ */ new Set();
181
- for (const patcher of patchers) {
182
- const current = patcher.getClassSetSync?.();
183
- if (!current) continue;
184
- for (const className of current) aggregated.add(className);
185
- }
186
- return aggregated;
187
- };
188
- Object.defineProperty(multiPatcher, runtimeSignaturePatchersSymbol, {
189
- value: [...patchers],
190
- configurable: true
191
- });
192
- return multiPatcher;
193
- }
194
- //#endregion
195
- //#region src/tailwindcss/v4/patcher-options.ts
196
- function overrideTailwindcssPatcherOptionsForBase(options, baseDir, cssEntries) {
197
- const hasCssEntries = cssEntries.length > 0;
198
- if (!options) return options;
199
- const modernTailwind = options.tailwindcss;
200
- if (!modernTailwind) return options;
201
- return {
202
- ...options,
203
- tailwindcss: {
204
- ...modernTailwind,
205
- v4: {
206
- ...modernTailwind.v4 ?? {},
207
- ...hasCssEntries ? {} : { base: modernTailwind.v4?.base ?? baseDir },
208
- cssEntries: hasCssEntries ? cssEntries : modernTailwind.v4?.cssEntries ?? cssEntries
209
- }
210
- }
211
- };
212
- }
213
- //#endregion
214
- //#region src/tailwindcss/v4/css-entries.ts
215
- function guessBasedirFromEntries(entries) {
216
- if (!entries) return;
217
- for (const entry of entries) {
218
- if (typeof entry !== "string") continue;
219
- const trimmed = entry.trim();
220
- if (!trimmed || !path.isAbsolute(trimmed)) continue;
221
- const entryDir = path.dirname(trimmed);
222
- const resolved = findNearestPackageRoot(entryDir) ?? entryDir;
223
- if (resolved) return resolved;
224
- }
225
- }
226
- function normalizeCssEntries(entries, anchor) {
227
- if (!entries || entries.length === 0) return;
228
- const normalized = /* @__PURE__ */ new Set();
229
- for (const entry of entries) {
230
- if (typeof entry !== "string") continue;
231
- const trimmed = entry.trim();
232
- if (trimmed.length === 0) continue;
233
- const resolved = path.isAbsolute(trimmed) ? path.normalize(trimmed) : path.normalize(path.resolve(anchor, trimmed));
234
- normalized.add(resolved);
235
- }
236
- return normalized.size > 0 ? [...normalized] : void 0;
237
- }
238
- function isSubPath(parent, child) {
239
- if (!parent || !child) return false;
240
- const relative = path.relative(parent, child);
241
- return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
242
- }
243
- function resolveCssEntryBase(entryDir, options) {
244
- const normalizedDir = path.normalize(entryDir);
245
- const { preferredBaseDir, workspaceRoot } = options;
246
- if (preferredBaseDir && isSubPath(preferredBaseDir, normalizedDir)) return preferredBaseDir;
247
- if (workspaceRoot && isSubPath(workspaceRoot, normalizedDir)) return workspaceRoot;
248
- const packageRoot = findNearestPackageRoot(normalizedDir);
249
- if (packageRoot) return path.normalize(packageRoot);
250
- return normalizedDir;
251
- }
252
- function groupCssEntriesByBase(entries, options = {}) {
253
- const normalizedOptions = {
254
- preferredBaseDir: options.preferredBaseDir ? path.normalize(options.preferredBaseDir) : void 0,
255
- workspaceRoot: options.workspaceRoot ? path.normalize(options.workspaceRoot) : void 0
256
- };
257
- const groups = /* @__PURE__ */ new Map();
258
- for (const entry of entries) {
259
- const baseDir = resolveCssEntryBase(path.dirname(entry), normalizedOptions);
260
- const bucket = groups.get(baseDir);
261
- if (bucket) bucket.push(entry);
262
- else groups.set(baseDir, [entry]);
263
- }
264
- return groups;
265
- }
266
- //#endregion
267
- //#region src/tailwindcss/v4/patcher.ts
268
- function isTailwindcss4Package(packageName) {
269
- return Boolean(packageName && (packageName === "tailwindcss4" || packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")));
270
- }
271
- function resolveExplicitTailwindVersion(configuredVersion, configuredPackageName) {
272
- if (typeof configuredVersion === "number") return configuredVersion;
273
- if (isTailwindcss4Package(configuredPackageName)) return 4;
274
- }
275
- function createPatcherForBase(baseDir, cssEntries, options) {
276
- const { tailwindcss, tailwindcssPatcherOptions, supportCustomLengthUnitsPatch, bareArbitraryValues } = options;
277
- const hasCssEntries = Boolean(cssEntries?.length);
278
- const defaultTailwindcssConfig = {
279
- cwd: baseDir,
280
- v2: { cwd: baseDir },
281
- v3: { cwd: baseDir },
282
- v4: hasCssEntries ? omitUndefined({ cssEntries }) : omitUndefined({
283
- base: baseDir,
284
- cssEntries
285
- })
286
- };
287
- const mergedTailwindOptions = defuOverrideArray(tailwindcss ?? {}, defaultTailwindcssConfig);
288
- if (!mergedTailwindOptions.v4) mergedTailwindOptions.v4 = hasCssEntries ? { cssEntries: cssEntries ?? [] } : {
289
- base: baseDir,
290
- cssEntries: cssEntries ?? []
291
- };
292
- else {
293
- if (!hasCssEntries && !mergedTailwindOptions.v4.base) mergedTailwindOptions.v4.base = baseDir;
294
- if (hasCssEntries) {
295
- if (cssEntries?.length) mergedTailwindOptions.v4.cssEntries = cssEntries;
296
- else if (!mergedTailwindOptions.v4.cssEntries) mergedTailwindOptions.v4.cssEntries = [];
297
- } else if (!mergedTailwindOptions.v4.cssEntries) mergedTailwindOptions.v4.cssEntries = cssEntries ?? [];
298
- }
299
- if (bareArbitraryValues !== void 0 && bareArbitraryValues !== false) mergedTailwindOptions.v4.bareArbitraryValues = bareArbitraryValues;
300
- const patchedOptions = overrideTailwindcssPatcherOptionsForBase(tailwindcssPatcherOptions, baseDir, cssEntries ?? []);
301
- const configuredPackageName = tailwindcss?.packageName || tailwindcssPatcherOptions?.tailwindcss?.packageName;
302
- const explicitTailwindVersion = resolveExplicitTailwindVersion(tailwindcss?.version || tailwindcssPatcherOptions?.tailwindcss?.version || mergedTailwindOptions.version, configuredPackageName);
303
- const resolvedTailwindVersion = readInstalledPackageMajorVersion(configuredPackageName ?? mergedTailwindOptions.packageName ?? "tailwindcss", baseDir) ?? explicitTailwindVersion;
304
- const supportedResolvedTailwindVersion = resolvedTailwindVersion === 2 || resolvedTailwindVersion === 3 || resolvedTailwindVersion === 4 ? resolvedTailwindVersion : void 0;
305
- const tailwindOptionsForPackage = {
306
- ...mergedTailwindOptions,
307
- packageName: mergedTailwindOptions.packageName ?? configuredPackageName ?? "tailwindcss"
308
- };
309
- if (supportedResolvedTailwindVersion) tailwindOptionsForPackage.version = supportedResolvedTailwindVersion;
310
- return createTailwindcssPatcher(omitUndefined({
311
- basedir: baseDir,
312
- supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
313
- tailwindcss: tailwindOptionsForPackage,
314
- tailwindcssPatcherOptions: patchedOptions
315
- }));
316
- }
317
- function tryCreateMultiTailwindcssPatcher(groups, options) {
318
- if (groups.size <= 1) return;
319
- logger.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
320
- const patchers = [];
321
- for (const [baseDir, entries] of groups) {
322
- const patcher = createPatcherForBase(baseDir, entries, options);
323
- if (patcher) patchers.push(patcher);
324
- }
325
- return createMultiTailwindcssPatcher(patchers);
326
- }
327
- //#endregion
328
- //#region src/uni-app-x/options.ts
329
- const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
330
- enabled: true,
331
- onlyWhenStyleIsolationVersion2: true
332
- };
333
- const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
334
- enabled: false,
335
- onlyWhenStyleIsolationVersion2: true
336
- };
337
- function isBooleanUniAppXShortcut(option) {
338
- return option === true || option === false || option === void 0;
339
- }
340
- function resolveComponentLocalStyles(option) {
341
- if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
342
- const componentLocalStyles = option.componentLocalStyles;
343
- if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
344
- if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
345
- return {
346
- enabled: componentLocalStyles.enabled !== false,
347
- onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
348
- };
349
- }
350
- function resolveUniAppXOptions(option) {
351
- if (typeof option === "object" && option) return {
352
- enabled: option.enabled !== false,
353
- componentLocalStyles: resolveComponentLocalStyles(option),
354
- uvueUnsupported: option.uvueUnsupported ?? "warn"
355
- };
356
- return {
357
- enabled: Boolean(option),
358
- componentLocalStyles: resolveComponentLocalStyles(option),
359
- uvueUnsupported: "warn"
360
- };
361
- }
362
- function isUniAppXEnabled(option) {
363
- return resolveUniAppXOptions(option).enabled;
364
- }
365
- //#endregion
366
- //#region src/context/tailwindcss/basedir.ts
367
- const ENV_BASEDIR_KEYS = [
368
- "WEAPP_TAILWINDCSS_BASEDIR",
369
- "WEAPP_TAILWINDCSS_BASE_DIR",
370
- "TAILWINDCSS_BASEDIR",
371
- "TAILWINDCSS_BASE_DIR",
372
- "UNI_INPUT_DIR",
373
- "UNI_INPUT_ROOT",
374
- "UNI_CLI_ROOT",
375
- "UNI_APP_INPUT_DIR",
376
- "INIT_CWD",
377
- "PWD"
378
- ];
379
- const GENERIC_ENV_BASEDIR_KEYS = new Set(["INIT_CWD", "PWD"]);
380
- function pickEnvBasedir() {
381
- for (const key of ENV_BASEDIR_KEYS) {
382
- const value = process.env[key];
383
- if (value && path.isAbsolute(value)) return {
384
- key,
385
- value
386
- };
387
- }
388
- }
389
- function pickPackageEnvBasedir() {
390
- const packageJsonPath = process.env["npm_package_json"];
391
- if (packageJsonPath) {
392
- const packageDir = path.dirname(packageJsonPath);
393
- if (packageDir && path.isAbsolute(packageDir)) return packageDir;
394
- }
395
- const localPrefix = process.env["npm_config_local_prefix"];
396
- if (localPrefix && path.isAbsolute(localPrefix)) return localPrefix;
397
- }
398
- const STACK_PAREN_RE = /\(([^)]+)\)/u;
399
- const STACK_AT_RE = /at\s+(\S.*)$/u;
400
- function detectCallerBasedir() {
401
- const stack = (/* @__PURE__ */ new Error("resolveTailwindcssBasedir stack probe")).stack;
402
- if (!stack) return;
403
- if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("caller stack: %s", stack);
404
- const lines = stack.split("\n");
405
- for (const line of lines) {
406
- const location = (line.match(STACK_PAREN_RE) ?? line.match(STACK_AT_RE))?.[1];
407
- if (!location) continue;
408
- let filePath = location;
409
- if (filePath.startsWith("file://")) try {
410
- filePath = fileURLToPath(filePath);
411
- } catch {
412
- continue;
413
- }
414
- const [candidate = ""] = filePath.split(":");
415
- const resolvedPath = path.isAbsolute(filePath) ? filePath : candidate;
416
- if (!path.isAbsolute(resolvedPath)) continue;
417
- if (resolvedPath.includes("node_modules") && resolvedPath.includes("weapp-tailwindcss")) continue;
418
- try {
419
- return path.dirname(resolvedPath);
420
- } catch {
421
- continue;
422
- }
423
- }
424
- }
425
- function resolveTailwindcssBasedir(basedir, fallback) {
426
- const envBasedirResult = pickEnvBasedir();
427
- const envBasedir = envBasedirResult?.value;
428
- const envBasedirKey = envBasedirResult?.key;
429
- const envBasedirIsGeneric = envBasedirKey ? GENERIC_ENV_BASEDIR_KEYS.has(envBasedirKey) : false;
430
- const packageEnvBasedir = pickPackageEnvBasedir();
431
- const callerBasedir = !envBasedir || envBasedirIsGeneric ? detectCallerBasedir() : void 0;
432
- const cwd = process.cwd();
433
- const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? cwd;
434
- const resolveRelative = (value) => path.isAbsolute(value) ? path.normalize(value) : path.normalize(path.resolve(anchor, value));
435
- if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("resolveTailwindcssBasedir anchor %O", {
436
- basedir,
437
- envBasedir,
438
- envBasedirKey,
439
- envBasedirIsGeneric,
440
- packageEnvBasedir,
441
- fallback,
442
- callerBasedir,
443
- npm_package_json: process.env["npm_package_json"],
444
- cwd,
445
- anchor
446
- });
447
- if (basedir && basedir.trim().length > 0) return resolveRelative(basedir);
448
- if (envBasedir && !envBasedirIsGeneric) return path.normalize(envBasedir);
449
- if (fallback && fallback.trim().length > 0) return resolveRelative(fallback);
450
- if (packageEnvBasedir) return path.normalize(packageEnvBasedir);
451
- if (callerBasedir) {
452
- const normalizedCaller = path.normalize(callerBasedir);
453
- const librarySegment = `${path.sep}weapp-tailwindcss${path.sep}`;
454
- if (!normalizedCaller.includes(librarySegment)) return normalizedCaller;
455
- }
456
- const packageName = process.env["PNPM_PACKAGE_NAME"];
457
- if (packageName) try {
458
- const packageJsonPath = createRequire(path.join(anchor, "__resolve_tailwindcss_basedir__.cjs")).resolve(`${packageName}/package.json`);
459
- if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
460
- return path.normalize(path.dirname(packageJsonPath));
461
- } catch {
462
- if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("failed to resolve package json for %s", packageName);
463
- const workspaceRoot = findWorkspaceRoot(anchor);
464
- if (workspaceRoot) {
465
- const packageDir = findWorkspacePackageDir(workspaceRoot, packageName);
466
- if (packageDir) return packageDir;
467
- }
468
- }
469
- if (envBasedir) return path.normalize(envBasedir);
470
- return path.normalize(cwd);
471
- }
472
- //#endregion
473
- //#region src/context/tailwindcss/rax.ts
474
- function isRaxWorkspace(appType, baseDir) {
475
- if (appType === "rax") return true;
476
- try {
477
- const pkgPath = path.join(baseDir, "package.json");
478
- if (!existsSync(pkgPath)) return false;
479
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
480
- const deps = {
481
- ...pkg["dependencies"] ?? {},
482
- ...pkg["devDependencies"] ?? {}
483
- };
484
- if (deps["rax-app"] || deps.rax) return true;
485
- } catch {
486
- return false;
487
- }
488
- return false;
489
- }
490
- function collectRaxStyleEntries(baseDir) {
491
- const STYLE_CANDIDATES = [
492
- "src/global.css",
493
- "src/global.scss",
494
- "src/global.less",
495
- "src/global.sass",
496
- "src/global.styl",
497
- "src/global.stylus"
498
- ];
499
- const discovered = [];
500
- for (const relative of STYLE_CANDIDATES) {
501
- const candidate = path.resolve(baseDir, relative);
502
- if (existsSync(candidate)) discovered.push(path.normalize(candidate));
503
- }
504
- return discovered;
505
- }
506
- function detectImplicitCssEntries(appType, baseDir) {
507
- const baseCandidates = /* @__PURE__ */ new Set();
508
- baseCandidates.add(path.normalize(baseDir));
509
- const envCandidates = [
510
- process.cwd(),
511
- process.env["INIT_CWD"],
512
- process.env["PWD"]
513
- ];
514
- for (const candidate of envCandidates) if (candidate) baseCandidates.add(path.normalize(candidate));
515
- for (const candidateBase of baseCandidates) {
516
- if (!isRaxWorkspace(appType, candidateBase)) continue;
517
- const entries = collectRaxStyleEntries(candidateBase);
518
- if (entries.length) return entries;
519
- }
520
- }
521
- //#endregion
522
- //#region src/context/tailwindcss.ts
523
- function createTailwindcssPatcherFromContext(ctx) {
524
- const { tailwindcssBasedir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions, cssEntries: rawCssEntries, appType, arbitraryValues } = ctx;
525
- const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
526
- const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
527
- ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
528
- logger.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
529
- let normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
530
- if (!normalizedCssEntries) normalizedCssEntries = detectImplicitCssEntries(ctx.appType, resolvedTailwindcssBasedir);
531
- if (normalizedCssEntries) ctx.cssEntries = normalizedCssEntries;
532
- const patcherOptions = {
533
- tailwindcss,
534
- tailwindcssPatcherOptions,
535
- supportCustomLengthUnitsPatch,
536
- appType,
537
- bareArbitraryValues: arbitraryValues?.bareArbitraryValues
538
- };
539
- const workspaceRoot = findWorkspaceRoot(resolvedTailwindcssBasedir) ?? (absoluteCssEntryBasedir ? findWorkspaceRoot(absoluteCssEntryBasedir) : void 0);
540
- const groupedCssEntries = normalizedCssEntries ? groupCssEntriesByBase(normalizedCssEntries, omitUndefined({
541
- preferredBaseDir: resolvedTailwindcssBasedir,
542
- workspaceRoot
543
- })) : void 0;
544
- const multiPatcher = groupedCssEntries ? tryCreateMultiTailwindcssPatcher(groupedCssEntries, patcherOptions) : void 0;
545
- if (multiPatcher) return multiPatcher;
546
- if (groupedCssEntries?.size === 1) {
547
- const firstGroup = groupedCssEntries.entries().next().value;
548
- if (firstGroup) {
549
- const [baseDir, entries] = firstGroup;
550
- return createPatcherForBase(baseDir, entries, patcherOptions);
551
- }
552
- }
553
- return createPatcherForBase(resolvedTailwindcssBasedir, normalizedCssEntries ?? rawCssEntries, patcherOptions);
554
- }
555
- //#endregion
556
- export { normalizeCssEntries as a, hasConfiguredTailwindV4CssRoots as c, resolveUniAppXOptions as i, upsertTailwindV4CssSource as l, resolveTailwindcssBasedir as n, applyV4CssCalcDefaults as o, isUniAppXEnabled as r, warnMissingCssEntries as s, createTailwindcssPatcherFromContext as t };