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
@@ -0,0 +1,1418 @@
1
+ import { Q as expandTailwindSourceEntries, X as FULL_SOURCE_SCAN_PATTERN, Z as createTailwindSourceEntryMatcher, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, c as groupCssEntriesByBase, ct as omitUndefined, d as normalizeCssEntries, et as normalizeLegacyContentEntries, f as findNearestPackageRoot, g as normalizeTailwindcssRuntimeOptions, h as normalizeExtendLengthUnits, i as resolveTailwindV4SourceOptionsFromRuntime, it as resolveTailwindV4CssSourceBase, l as guessBasedirFromEntries, m as findWorkspaceRoot, n as resolveTailwindV4SourceFromRuntime, nt as resolveCssSourceEntries, o as hasConfiguredTailwindV4CssRoots, ot as collectCssInlineSourceCandidates, p as findWorkspacePackageDir, tt as parseConfigParam, u as isTailwindV4CssEntry, v as normalizeStringListOption } from "./v4-engine-CF9zt4Cw.mjs";
2
+ import { n as defuOverrideArray$1 } from "./utils-DodxWHGz.mjs";
3
+ import { createRequire } from "node:module";
4
+ import { existsSync, readFileSync, statSync } from "node:fs";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import { extractProjectCandidatesWithPositions } from "@tailwindcss-mangle/engine";
8
+ import { postcss } from "@weapp-tailwindcss/postcss";
9
+ import { stat } from "node:fs/promises";
10
+ import { defuOverrideArray } from "@weapp-tailwindcss/shared";
11
+ import { logger } from "@weapp-tailwindcss/logger";
12
+ import fg from "fast-glob";
13
+ import { loadConfig } from "tailwindcss-config";
14
+ import { fileURLToPath } from "node:url";
15
+ //#region src/bundlers/vite/static-config-content.ts
16
+ function skipWhitespaceAndComments(source, start) {
17
+ let index = start;
18
+ while (index < source.length) {
19
+ const char = source[index];
20
+ if (/\s/.test(char ?? "")) {
21
+ index += 1;
22
+ continue;
23
+ }
24
+ if (char === "/" && source[index + 1] === "/") {
25
+ index += 2;
26
+ while (index < source.length && source[index] !== "\n") index += 1;
27
+ continue;
28
+ }
29
+ if (char === "/" && source[index + 1] === "*") {
30
+ index += 2;
31
+ while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) index += 1;
32
+ index = Math.min(index + 2, source.length);
33
+ continue;
34
+ }
35
+ break;
36
+ }
37
+ return index;
38
+ }
39
+ function readQuotedString(source, start) {
40
+ const quote = source[start];
41
+ if (quote !== "\"" && quote !== "'") return;
42
+ let value = "";
43
+ for (let index = start + 1; index < source.length; index++) {
44
+ const char = source[index];
45
+ if (char === "\\") {
46
+ const next = source[index + 1];
47
+ if (next === void 0) return;
48
+ value += next;
49
+ index += 1;
50
+ continue;
51
+ }
52
+ if (char === quote) return {
53
+ end: index + 1,
54
+ value
55
+ };
56
+ value += char;
57
+ }
58
+ }
59
+ function readIdentifier(source, start) {
60
+ return /^[A-Z_$][\w$]*/i.exec(source.slice(start))?.[0];
61
+ }
62
+ function findMatchingBracket(source, start, open, close) {
63
+ let depth = 0;
64
+ let quote;
65
+ for (let index = start; index < source.length; index++) {
66
+ const char = source[index];
67
+ if (char === "\\") {
68
+ index += 1;
69
+ continue;
70
+ }
71
+ if (quote) {
72
+ if (char === quote) quote = void 0;
73
+ continue;
74
+ }
75
+ if (char === "\"" || char === "'") {
76
+ quote = char;
77
+ continue;
78
+ }
79
+ if (char === "`") return;
80
+ if (char === open) {
81
+ depth += 1;
82
+ continue;
83
+ }
84
+ if (char === close) {
85
+ depth -= 1;
86
+ if (depth === 0) return index;
87
+ }
88
+ }
89
+ }
90
+ function findContentPropertyValue(source) {
91
+ let index = 0;
92
+ while (index < source.length) {
93
+ const nextIndex = source.indexOf("content", index);
94
+ if (nextIndex === -1) return;
95
+ const previous = source[nextIndex - 1];
96
+ const next = source[nextIndex + 7];
97
+ if (previous && /[\w$]/.test(previous) || next && /[\w$]/.test(next)) {
98
+ index = nextIndex + 7;
99
+ continue;
100
+ }
101
+ let colonIndex = skipWhitespaceAndComments(source, nextIndex + 7);
102
+ if (source[colonIndex] !== ":") {
103
+ index = nextIndex + 7;
104
+ continue;
105
+ }
106
+ colonIndex = skipWhitespaceAndComments(source, colonIndex + 1);
107
+ return { start: colonIndex };
108
+ }
109
+ }
110
+ function parseStaticContentArray(source, start) {
111
+ if (source[start] !== "[") return;
112
+ const value = [];
113
+ let index = skipWhitespaceAndComments(source, start + 1);
114
+ while (index < source.length) {
115
+ if (source[index] === "]") return {
116
+ end: index + 1,
117
+ value
118
+ };
119
+ const parsed = parseStaticContentValue(source, index);
120
+ if (!parsed) return;
121
+ value.push(parsed.value);
122
+ index = skipWhitespaceAndComments(source, parsed.end);
123
+ if (source[index] === ",") {
124
+ index = skipWhitespaceAndComments(source, index + 1);
125
+ continue;
126
+ }
127
+ if (source[index] === "]") continue;
128
+ return;
129
+ }
130
+ }
131
+ function parseStaticContentObject(source, start) {
132
+ if (source[start] !== "{") return;
133
+ const end = findMatchingBracket(source, start, "{", "}");
134
+ if (end === void 0) return;
135
+ let index = skipWhitespaceAndComments(source, start + 1);
136
+ let files;
137
+ while (index < end) {
138
+ let key;
139
+ const quotedKey = readQuotedString(source, index);
140
+ if (quotedKey) {
141
+ key = quotedKey.value;
142
+ index = quotedKey.end;
143
+ } else {
144
+ key = readIdentifier(source, index);
145
+ if (!key) return;
146
+ index += key.length;
147
+ }
148
+ index = skipWhitespaceAndComments(source, index);
149
+ if (source[index] !== ":") return;
150
+ index = skipWhitespaceAndComments(source, index + 1);
151
+ const parsedValue = parseStaticContentValue(source, index);
152
+ if (!parsedValue) return;
153
+ if (key === "files") files = parsedValue.value;
154
+ index = skipWhitespaceAndComments(source, parsedValue.end);
155
+ if (source[index] === ",") {
156
+ index = skipWhitespaceAndComments(source, index + 1);
157
+ continue;
158
+ }
159
+ if (index < end) return;
160
+ }
161
+ return files === void 0 ? void 0 : {
162
+ end: end + 1,
163
+ value: { files }
164
+ };
165
+ }
166
+ function parseStaticContentValue(source, start) {
167
+ const index = skipWhitespaceAndComments(source, start);
168
+ const quoted = readQuotedString(source, index);
169
+ if (quoted) return quoted;
170
+ if (source[index] === "[") return parseStaticContentArray(source, index);
171
+ if (source[index] === "{") return parseStaticContentObject(source, index);
172
+ }
173
+ function readStaticConfigContent(configPath) {
174
+ let source;
175
+ try {
176
+ source = readFileSync(configPath, "utf8");
177
+ } catch {
178
+ return;
179
+ }
180
+ const contentProperty = findContentPropertyValue(source);
181
+ if (!contentProperty) return;
182
+ return parseStaticContentValue(source, contentProperty.start)?.value;
183
+ }
184
+ //#endregion
185
+ //#region src/bundlers/vite/source-scan/css-entries.ts
186
+ const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
187
+ const VITE_TAILWIND_CSS_ENTRY_PATTERN = "**/*.css";
188
+ const tailwindV4CssEntriesCache = /* @__PURE__ */ new Map();
189
+ function parseImportSourceParam(params) {
190
+ const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
191
+ if (!match) return;
192
+ return {
193
+ none: match[1] === "none",
194
+ sourcePath: match[3]
195
+ };
196
+ }
197
+ function parseCssImportSpecifier(params) {
198
+ const value = params.trim();
199
+ const quoted = /^(['"])(.*?)\1/.exec(value);
200
+ if (quoted) return quoted[2];
201
+ const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
202
+ return url?.[2] ?? url?.[3];
203
+ }
204
+ function isTailwindCssImport(params) {
205
+ const specifier = parseCssImportSpecifier(params);
206
+ return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
207
+ }
208
+ function resolveSourceBase(base, sourcePath) {
209
+ return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
210
+ }
211
+ function resolveConfigPath(base, configPath) {
212
+ if (path.isAbsolute(configPath)) return path.resolve(configPath);
213
+ return path.resolve(base, configPath);
214
+ }
215
+ function createCssEntriesCacheKey(css, base, dependencies) {
216
+ return JSON.stringify({
217
+ base: path.resolve(base),
218
+ css,
219
+ dependencies
220
+ });
221
+ }
222
+ async function statConfigDependency(file) {
223
+ try {
224
+ const stats = await stat(file);
225
+ return {
226
+ file,
227
+ mtimeMs: stats.mtimeMs,
228
+ size: stats.size
229
+ };
230
+ } catch {
231
+ return {
232
+ file,
233
+ mtimeMs: -1,
234
+ size: -1
235
+ };
236
+ }
237
+ }
238
+ async function collectConfigDependencySignatures(root, base) {
239
+ const configPaths = /* @__PURE__ */ new Set();
240
+ root.walkAtRules("config", (rule) => {
241
+ const configPath = parseConfigParam(rule.params);
242
+ if (configPath) configPaths.add(resolveConfigPath(base, configPath));
243
+ });
244
+ return Promise.all([...configPaths].sort().map(statConfigDependency));
245
+ }
246
+ function mergeTailwindInlineSourceCandidates(allInlineCandidates) {
247
+ const merged = {
248
+ included: /* @__PURE__ */ new Set(),
249
+ excluded: /* @__PURE__ */ new Set()
250
+ };
251
+ for (const inlineCandidates of allInlineCandidates) {
252
+ if (!inlineCandidates) continue;
253
+ for (const candidate of inlineCandidates.included) if (!merged.excluded.has(candidate)) merged.included.add(candidate);
254
+ for (const candidate of inlineCandidates.excluded) {
255
+ merged.excluded.add(candidate);
256
+ merged.included.delete(candidate);
257
+ }
258
+ }
259
+ return merged.included.size > 0 || merged.excluded.size > 0 ? merged : void 0;
260
+ }
261
+ async function resolveConfigContentEntries(root, base) {
262
+ const configPaths = /* @__PURE__ */ new Set();
263
+ root.walkAtRules("config", (rule) => {
264
+ const configPath = parseConfigParam(rule.params);
265
+ if (configPath) configPaths.add(resolveConfigPath(base, configPath));
266
+ });
267
+ const entries = [];
268
+ for (const configPath of configPaths) {
269
+ const staticContent = readStaticConfigContent(configPath);
270
+ if (staticContent !== void 0) {
271
+ entries.push(...normalizeLegacyContentEntries(staticContent, path.dirname(configPath), { relativeBase: path.dirname(configPath) }));
272
+ continue;
273
+ }
274
+ try {
275
+ const loaded = await loadConfig({
276
+ config: configPath,
277
+ cwd: path.dirname(configPath)
278
+ });
279
+ entries.push(...normalizeLegacyContentEntries(loaded?.config.content, path.dirname(configPath), { relativeBase: path.dirname(configPath) }));
280
+ } catch {}
281
+ }
282
+ return {
283
+ dependencies: [...configPaths],
284
+ entries
285
+ };
286
+ }
287
+ async function resolveTailwindV4EntriesFromCss(css, base) {
288
+ let root;
289
+ try {
290
+ root = postcss.parse(css);
291
+ } catch {
292
+ return;
293
+ }
294
+ let importSourceBase;
295
+ let hasSourceNone = false;
296
+ let hasTailwindCssImport = false;
297
+ const [sourceEntries, configEntries] = await Promise.all([resolveCssSourceEntries(root, base, VITE_SOURCE_CANDIDATE_PATTERN), resolveConfigContentEntries(root, base)]);
298
+ const entries = [...configEntries.entries, ...sourceEntries];
299
+ const hasPositiveEntries = entries.some((entry) => !entry.negated);
300
+ const inlineCandidates = collectCssInlineSourceCandidates(root);
301
+ root.walkAtRules("import", (rule) => {
302
+ if (!isTailwindCssImport(rule.params)) return;
303
+ hasTailwindCssImport = true;
304
+ const sourceParam = parseImportSourceParam(rule.params);
305
+ if (sourceParam?.none) hasSourceNone = true;
306
+ if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(base, sourceParam.sourcePath);
307
+ });
308
+ if (importSourceBase) return {
309
+ entries: [{
310
+ base: importSourceBase,
311
+ negated: false,
312
+ pattern: VITE_SOURCE_CANDIDATE_PATTERN
313
+ }, ...entries],
314
+ explicit: true,
315
+ inlineCandidates,
316
+ dependencies: configEntries.dependencies
317
+ };
318
+ if (hasSourceNone) return {
319
+ entries,
320
+ explicit: true,
321
+ inlineCandidates,
322
+ dependencies: configEntries.dependencies
323
+ };
324
+ if (hasPositiveEntries) return {
325
+ entries,
326
+ explicit: true,
327
+ inlineCandidates,
328
+ dependencies: configEntries.dependencies
329
+ };
330
+ if (inlineCandidates.included.size > 0 || inlineCandidates.excluded.size > 0) return {
331
+ entries: [],
332
+ explicit: true,
333
+ inlineCandidates,
334
+ dependencies: configEntries.dependencies
335
+ };
336
+ return hasTailwindCssImport ? {
337
+ entries,
338
+ explicit: false,
339
+ inlineCandidates,
340
+ dependencies: configEntries.dependencies
341
+ } : void 0;
342
+ }
343
+ async function resolveViteTailwindV4CssDependencies(css, base) {
344
+ return (await resolveTailwindV4EntriesFromCss(css, base))?.dependencies ?? [];
345
+ }
346
+ function collectExistingCssEntries(options) {
347
+ return [
348
+ ...options.cssEntries ?? [],
349
+ ...options.tailwindcss?.v4?.cssEntries ?? [],
350
+ ...options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
351
+ ].filter((item) => typeof item === "string" && item.length > 0).filter(isTailwindV4CssEntry).map((item) => path.resolve(item)).filter((item) => existsSync(item));
352
+ }
353
+ async function pathExistsAsFile(file) {
354
+ try {
355
+ return (await stat(file)).isFile();
356
+ } catch {
357
+ return false;
358
+ }
359
+ }
360
+ async function resolveTailwindV4EntriesFromCssCached(css, base) {
361
+ let root;
362
+ try {
363
+ root = postcss.parse(css);
364
+ } catch {
365
+ return;
366
+ }
367
+ const cacheKey = createCssEntriesCacheKey(css, base, await collectConfigDependencySignatures(root, base));
368
+ const cached = tailwindV4CssEntriesCache.get(cacheKey);
369
+ if (cached) return cached;
370
+ const task = resolveTailwindV4EntriesFromCss(css, base).catch((error) => {
371
+ tailwindV4CssEntriesCache.delete(cacheKey);
372
+ throw error;
373
+ });
374
+ tailwindV4CssEntriesCache.set(cacheKey, task);
375
+ return task;
376
+ }
377
+ async function discoverTailwindV4CssEntries(root, outDir) {
378
+ const resolvedRoot = path.resolve(root);
379
+ const ignore = ["**/node_modules/**", "**/.git/**"];
380
+ const resolvedOutDir = outDir ? path.resolve(resolvedRoot, outDir) : void 0;
381
+ if (resolvedOutDir) {
382
+ const relativeOutDir = path.relative(resolvedRoot, resolvedOutDir);
383
+ if (relativeOutDir && !relativeOutDir.startsWith("..") && !path.isAbsolute(relativeOutDir)) ignore.push(`${relativeOutDir.split(path.sep).join("/")}/**`);
384
+ }
385
+ const candidates = await fg(VITE_TAILWIND_CSS_ENTRY_PATTERN, {
386
+ absolute: true,
387
+ cwd: resolvedRoot,
388
+ ignore,
389
+ onlyFiles: true,
390
+ unique: true
391
+ });
392
+ const entries = [];
393
+ for (const file of candidates) {
394
+ if (!await pathExistsAsFile(file)) continue;
395
+ try {
396
+ const css = readFileSync(file, "utf8");
397
+ if (css.includes("tailwindcss") || css.includes("@source") || css.includes("@config")) {
398
+ if (await resolveTailwindV4EntriesFromCssCached(css, path.dirname(file))) entries.push(file);
399
+ }
400
+ } catch {}
401
+ }
402
+ return entries;
403
+ }
404
+ function collectConfiguredCssSources(options) {
405
+ return filterTailwindV4CssSourceRoots([...options.tailwindcss?.v4?.cssSources ?? [], ...options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? []]) ?? [];
406
+ }
407
+ //#endregion
408
+ //#region src/bundlers/vite/source-scan/dependencies.ts
409
+ function addSourceScanDependency(dependencies, file) {
410
+ if (typeof file === "string" && file.length > 0) dependencies.add(path.resolve(file));
411
+ }
412
+ function addSourceScanDependencies(dependencies, files) {
413
+ for (const file of files ?? []) addSourceScanDependency(dependencies, file);
414
+ }
415
+ //#endregion
416
+ //#region src/bundlers/vite/source-scan.ts
417
+ function createResolvedViteSourceScan(input, dependencies) {
418
+ return {
419
+ ...input,
420
+ ...dependencies.size > 0 ? { dependencies: [...dependencies].sort() } : {}
421
+ };
422
+ }
423
+ function createMergedCssEntrySourceScanEntries(entries, options) {
424
+ if (options.sourceCount <= 1) return entries;
425
+ const positiveEntries = entries.filter((entry) => !entry.negated);
426
+ return positiveEntries.length > 0 ? positiveEntries : entries;
427
+ }
428
+ function createResolvedV4CssScanInput(entries, inlineCandidates, explicit) {
429
+ return {
430
+ entries: explicit ? entries : entries.length > 0 ? entries : void 0,
431
+ explicit,
432
+ inlineCandidates
433
+ };
434
+ }
435
+ async function resolveViteSourceScanEntries(options, runtime, scanOptions = {}) {
436
+ const sourceOptions = resolveTailwindV4SourceOptionsFromRuntime(runtime);
437
+ const cssEntries = collectExistingCssEntries(options);
438
+ if (cssEntries.length === 0 && !sourceOptions.css && !sourceOptions.cssSources?.length) {
439
+ const scanRoot = scanOptions.root;
440
+ const sourceProjectRoot = sourceOptions.projectRoot;
441
+ if (scanRoot && sourceProjectRoot && path.resolve(scanRoot) === path.resolve(sourceProjectRoot)) {
442
+ const discoveredCssEntries = await discoverTailwindV4CssEntries(scanRoot, scanOptions.outDir);
443
+ cssEntries.push(...discoveredCssEntries);
444
+ }
445
+ }
446
+ const entries = [];
447
+ const cssInlineCandidates = [];
448
+ const dependencies = /* @__PURE__ */ new Set();
449
+ let explicit = false;
450
+ let readableCssEntryCount = 0;
451
+ for (const cssEntry of cssEntries) {
452
+ addSourceScanDependency(dependencies, cssEntry);
453
+ let css;
454
+ try {
455
+ css = readFileSync(cssEntry, "utf8");
456
+ } catch {
457
+ continue;
458
+ }
459
+ readableCssEntryCount++;
460
+ const resolved = await resolveTailwindV4EntriesFromCssCached(css, path.dirname(cssEntry));
461
+ if (resolved) {
462
+ entries.push(...resolved.entries);
463
+ cssInlineCandidates.push(resolved.inlineCandidates);
464
+ addSourceScanDependencies(dependencies, resolved.dependencies);
465
+ explicit || (explicit = resolved.explicit);
466
+ }
467
+ }
468
+ const inlineCandidates = mergeTailwindInlineSourceCandidates(cssInlineCandidates);
469
+ const scanEntries = createMergedCssEntrySourceScanEntries(entries, { sourceCount: readableCssEntryCount });
470
+ if (scanEntries.length > 0 || inlineCandidates || explicit || readableCssEntryCount > 0) return createResolvedViteSourceScan({
471
+ entries: explicit ? scanEntries : scanEntries.length > 0 ? scanEntries : void 0,
472
+ explicit,
473
+ inlineCandidates
474
+ }, dependencies);
475
+ if (typeof sourceOptions.css === "string" && sourceOptions.css.length > 0) {
476
+ const resolved = await resolveTailwindV4EntriesFromCssCached(sourceOptions.css, sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd());
477
+ return resolved ? createResolvedViteSourceScan(createResolvedV4CssScanInput(resolved.entries, resolved.inlineCandidates, resolved.explicit), new Set(resolved.dependencies)) : void 0;
478
+ }
479
+ const sourceOptionBase = sourceOptions.base ?? sourceOptions.projectRoot ?? process.cwd();
480
+ const configuredCssSources = collectConfiguredCssSources(options);
481
+ for (const cssSource of [...configuredCssSources, ...sourceOptions.cssSources ?? []]) {
482
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
483
+ addSourceScanDependency(dependencies, cssSource.file);
484
+ addSourceScanDependencies(dependencies, cssSource.dependencies);
485
+ const resolved = await resolveTailwindV4EntriesFromCssCached(cssSource.css, resolveTailwindV4CssSourceBase(cssSource, sourceOptionBase));
486
+ if (resolved) {
487
+ entries.push(...resolved.entries);
488
+ cssInlineCandidates.push(resolved.inlineCandidates);
489
+ addSourceScanDependencies(dependencies, resolved.dependencies);
490
+ explicit || (explicit = resolved.explicit);
491
+ }
492
+ }
493
+ const cssSourceInlineCandidates = mergeTailwindInlineSourceCandidates(cssInlineCandidates);
494
+ const cssSourceScanEntries = createMergedCssEntrySourceScanEntries(entries, { sourceCount: (sourceOptions.cssSources?.length ?? 0) + configuredCssSources.length });
495
+ if (cssSourceScanEntries.length > 0 || cssSourceInlineCandidates || explicit || sourceOptions.cssSources?.length || configuredCssSources.length > 0) return createResolvedViteSourceScan({
496
+ entries: explicit ? cssSourceScanEntries : cssSourceScanEntries.length > 0 ? cssSourceScanEntries : void 0,
497
+ explicit,
498
+ inlineCandidates: cssSourceInlineCandidates
499
+ }, dependencies);
500
+ const source = await resolveTailwindV4SourceFromRuntime(runtime);
501
+ addSourceScanDependency(dependencies, source.file);
502
+ addSourceScanDependencies(dependencies, source.dependencies);
503
+ const resolved = await resolveTailwindV4EntriesFromCssCached(source.css, source.base);
504
+ return resolved ? createResolvedViteSourceScan(createResolvedV4CssScanInput(resolved.entries.length > 0 ? resolved.entries : [], resolved.inlineCandidates, resolved.entries.length > 0 ? resolved.explicit : false), new Set([...dependencies, ...resolved.dependencies])) : void 0;
505
+ }
506
+ function createViteSourceScanMatcher(entries) {
507
+ if (entries?.length === 0) return;
508
+ return createTailwindSourceEntryMatcher(entries);
509
+ }
510
+ //#endregion
511
+ //#region src/tailwindcss/runtime/cache.ts
512
+ const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
513
+ const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
514
+ const runtimeTrackedSourceFilesCache = /* @__PURE__ */ new Map();
515
+ let runtimeFileSignatureCacheClearTimer;
516
+ const runtimeSignatureRuntimesSymbol = Symbol.for("weapp-tailwindcss.runtimeSignatureRuntimes");
517
+ function getCacheEntry(tailwindRuntime) {
518
+ let entry = runtimeClassSetCache.get(tailwindRuntime);
519
+ if (!entry) {
520
+ entry = {};
521
+ runtimeClassSetCache.set(tailwindRuntime, entry);
522
+ }
523
+ return entry;
524
+ }
525
+ function scheduleRuntimeConfigSignatureCacheClear() {
526
+ if (runtimeFileSignatureCacheClearTimer) return;
527
+ runtimeFileSignatureCacheClearTimer = setTimeout(() => {
528
+ runtimeFileSignatureCache.clear();
529
+ runtimeTrackedSourceFilesCache.clear();
530
+ runtimeFileSignatureCacheClearTimer = void 0;
531
+ }, 0);
532
+ runtimeFileSignatureCacheClearTimer.unref?.();
533
+ }
534
+ function getFileSignature(filePath) {
535
+ const cached = runtimeFileSignatureCache.get(filePath);
536
+ if (cached !== void 0) return cached;
537
+ let signature;
538
+ try {
539
+ const stats = statSync(filePath);
540
+ signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
541
+ } catch {
542
+ signature = `${filePath}:missing`;
543
+ }
544
+ runtimeFileSignatureCache.set(filePath, signature);
545
+ scheduleRuntimeConfigSignatureCacheClear();
546
+ return signature;
547
+ }
548
+ function getTailwindTrackedFiles(tailwindRuntime) {
549
+ const tailwindOptions = resolveTailwindcssOptions(tailwindRuntime.options);
550
+ const tracked = /* @__PURE__ */ new Set();
551
+ const configPath = tailwindOptions?.config;
552
+ if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
553
+ for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
554
+ for (const source of tailwindOptions?.v4?.cssSources ?? []) {
555
+ if (typeof source.file === "string" && source.file.length > 0) tracked.add(source.file);
556
+ for (const dependency of source.dependencies ?? []) if (typeof dependency === "string" && dependency.length > 0) tracked.add(dependency);
557
+ }
558
+ return tracked;
559
+ }
560
+ function normalizeTrackedSourceSignature(cssEntries, cssSources) {
561
+ return normalizeSignatureValue({
562
+ cssEntries: cssEntries?.map((entry) => {
563
+ if (!existsSync(entry)) return `${entry}:missing`;
564
+ return getFileSignature(entry);
565
+ }),
566
+ cssSources
567
+ });
568
+ }
569
+ async function collectTailwindV4TrackedSourceFiles(tailwindRuntime) {
570
+ const tailwindOptions = resolveTailwindcssOptions(tailwindRuntime.options);
571
+ const signature = normalizeTrackedSourceSignature(tailwindOptions?.v4?.cssEntries, tailwindOptions?.v4?.cssSources);
572
+ const cached = runtimeTrackedSourceFilesCache.get(signature);
573
+ if (cached) return cached;
574
+ const files = /* @__PURE__ */ new Set();
575
+ for (const cssEntry of tailwindOptions?.v4?.cssEntries ?? []) {
576
+ if (!existsSync(cssEntry)) continue;
577
+ const resolved = await resolveTailwindV4EntriesFromCssCached(readFileSync(cssEntry, "utf8"), path.dirname(cssEntry));
578
+ const expanded = resolved?.entries?.length ? await expandTailwindSourceEntries(resolved.entries) : [];
579
+ for (const file of expanded) files.add(file);
580
+ }
581
+ for (const cssSource of tailwindOptions?.v4?.cssSources ?? []) {
582
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
583
+ const base = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.dirname(cssSource.file) : tailwindOptions?.v4?.base ?? tailwindOptions?.cwd ?? tailwindRuntime.options?.projectRoot ?? process.cwd();
584
+ const resolved = await resolveTailwindV4EntriesFromCssCached(cssSource.css, base);
585
+ const expanded = resolved?.entries?.length ? await expandTailwindSourceEntries(resolved.entries) : [];
586
+ for (const file of expanded) files.add(file);
587
+ }
588
+ const result = [...files].sort((a, b) => a.localeCompare(b));
589
+ runtimeTrackedSourceFilesCache.set(signature, result);
590
+ return result;
591
+ }
592
+ function normalizeSignatureValue(value) {
593
+ if (value == null) return "null";
594
+ if (typeof value === "string") return value;
595
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
596
+ if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
597
+ if (typeof value === "object") return `{${Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${key}:${normalizeSignatureValue(item)}`).join(",")}}`;
598
+ return String(value);
599
+ }
600
+ function readOptionalProperty(value, key) {
601
+ if (typeof value !== "object" || value === null || !(key in value)) return;
602
+ return value[key];
603
+ }
604
+ function getTailwindOptionsSignature(tailwindRuntime) {
605
+ const options = tailwindRuntime.options;
606
+ const tailwindOptions = resolveTailwindcssOptions(options);
607
+ return normalizeSignatureValue({
608
+ projectRoot: options?.projectRoot,
609
+ packageName: tailwindOptions?.packageName,
610
+ versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
611
+ cwd: tailwindOptions?.cwd,
612
+ config: tailwindOptions?.config,
613
+ v4: {
614
+ base: tailwindOptions?.v4?.base,
615
+ configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
616
+ css: tailwindOptions?.v4?.css,
617
+ cssEntries: tailwindOptions?.v4?.cssEntries,
618
+ cssSources: tailwindOptions?.v4?.cssSources,
619
+ hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
620
+ sources: tailwindOptions?.v4?.sources
621
+ }
622
+ });
623
+ }
624
+ function getRuntimeTargetSignature(tailwindRuntime) {
625
+ const packageInfo = tailwindRuntime.packageInfo;
626
+ return [
627
+ packageInfo?.name ?? "missing",
628
+ packageInfo?.rootPath ?? "missing",
629
+ packageInfo?.version ?? "unknown",
630
+ tailwindRuntime.majorVersion ?? "unknown",
631
+ getTailwindOptionsSignature(tailwindRuntime)
632
+ ].join(":");
633
+ }
634
+ function getNestedRuntimes(tailwindRuntime) {
635
+ const nested = tailwindRuntime[runtimeSignatureRuntimesSymbol];
636
+ return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
637
+ }
638
+ function getOwnRuntimeClassSetSignature(tailwindRuntime) {
639
+ const trackedFiles = [...getTailwindTrackedFiles(tailwindRuntime)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
640
+ return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|runtime:${getRuntimeTargetSignature(tailwindRuntime)}`;
641
+ }
642
+ function invalidateRuntimeClassSet(tailwindRuntime) {
643
+ if (!tailwindRuntime) return;
644
+ const nestedRuntimes = getNestedRuntimes(tailwindRuntime);
645
+ if (nestedRuntimes) for (const runtime of nestedRuntimes) invalidateRuntimeClassSet(runtime);
646
+ for (const trackedFile of getTailwindTrackedFiles(tailwindRuntime)) runtimeFileSignatureCache.delete(trackedFile);
647
+ runtimeTrackedSourceFilesCache.clear();
648
+ runtimeClassSetCache.delete(tailwindRuntime);
649
+ }
650
+ function getRuntimeClassSetCacheEntry(tailwindRuntime) {
651
+ return getCacheEntry(tailwindRuntime);
652
+ }
653
+ function getRuntimeClassSetSignature(tailwindRuntime) {
654
+ const nestedRuntimes = getNestedRuntimes(tailwindRuntime);
655
+ if (nestedRuntimes) return nestedRuntimes.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
656
+ return getOwnRuntimeClassSetSignature(tailwindRuntime);
657
+ }
658
+ async function getRuntimeClassSetSignatureWithSources(tailwindRuntime) {
659
+ const baseSignature = getRuntimeClassSetSignature(tailwindRuntime);
660
+ const trackedSourceFiles = await collectTailwindV4TrackedSourceFiles(tailwindRuntime);
661
+ if (trackedSourceFiles.length === 0) return baseSignature;
662
+ return [baseSignature, trackedSourceFiles.map(getFileSignature).join("|")].join("|sources:");
663
+ }
664
+ //#endregion
665
+ //#region src/tailwindcss/v4/config.ts
666
+ const DEFAULT_CSS_CALC_CUSTOM_PROPERTIES = [];
667
+ function includesToken(list, token) {
668
+ return list.some((candidate) => {
669
+ if (typeof token === "string") {
670
+ if (typeof candidate === "string") return candidate === token;
671
+ candidate.lastIndex = 0;
672
+ return candidate.test(token);
673
+ }
674
+ if (typeof candidate === "string") {
675
+ token.lastIndex = 0;
676
+ return token.test(candidate);
677
+ }
678
+ return candidate.source === token.source && candidate.flags === token.flags;
679
+ });
680
+ }
681
+ function ensureDefaultsIncluded(value) {
682
+ if (value === true) return { includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES] };
683
+ if (Array.isArray(value)) {
684
+ if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) return value;
685
+ const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(value, token));
686
+ return missing.length > 0 ? [...value, ...missing] : value;
687
+ }
688
+ if (value && typeof value === "object") {
689
+ const include = value.includeCustomProperties;
690
+ if (!Array.isArray(include)) return {
691
+ ...value,
692
+ includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
693
+ };
694
+ if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) return value;
695
+ const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(include, token));
696
+ return missing.length > 0 ? {
697
+ ...value,
698
+ includeCustomProperties: [...include, ...missing]
699
+ } : value;
700
+ }
701
+ return value;
702
+ }
703
+ function normalizeCssEntriesConfig(entries) {
704
+ const normalized = normalizeStringListOption(entries)?.filter(isTailwindV4CssEntry);
705
+ return normalized && normalized.length > 0 ? normalized : void 0;
706
+ }
707
+ function hasConfiguredCssEntries(ctx) {
708
+ if (normalizeCssEntriesConfig(ctx.cssEntries)) return true;
709
+ if (normalizeCssEntriesConfig(ctx.tailwindcss?.v4?.cssEntries)) return true;
710
+ const runtimeOptions = ctx.tailwindcssRuntimeOptions;
711
+ if (runtimeOptions) {
712
+ if (normalizeCssEntriesConfig(runtimeOptions.tailwindcss?.v4?.cssEntries)) return true;
713
+ }
714
+ return false;
715
+ }
716
+ let hasWarnedMissingCssEntries = false;
717
+ function warnMissingCssEntries(ctx, tailwindRuntime) {
718
+ if (hasWarnedMissingCssEntries) return;
719
+ if (!tailwindRuntime) return;
720
+ if (hasConfiguredCssEntries(ctx) || hasConfiguredTailwindV4CssRoots(ctx)) return;
721
+ hasWarnedMissingCssEntries = true;
722
+ logger.warn("[tailwindcss@4] 未检测到 cssEntries 配置。请传入包含 tailwindcss 引用的 CSS 绝对路径,例如 cssEntries: [\"/absolute/path/to/src/app.css\"],否则 tailwindcss 生成的类名不会参与转译。");
723
+ }
724
+ function applyV4CssCalcDefaults(cssCalc, tailwindRuntime) {
725
+ const cssCalcOptions = cssCalc ?? true;
726
+ if (tailwindRuntime && cssCalcOptions) return ensureDefaultsIncluded(cssCalcOptions);
727
+ return cssCalcOptions;
728
+ }
729
+ //#endregion
730
+ //#region src/tailwindcss/runtime-resolve.ts
731
+ const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
732
+ const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
733
+ const TAILWIND_CONFIG_FILES = [
734
+ "tailwind.config.js",
735
+ "tailwind.config.cjs",
736
+ "tailwind.config.mjs",
737
+ "tailwind.config.ts",
738
+ "tailwind.config.cts",
739
+ "tailwind.config.mts"
740
+ ];
741
+ function isPathSpecifier(specifier) {
742
+ if (!specifier) return false;
743
+ if (specifier.startsWith("file://")) return true;
744
+ if (path.isAbsolute(specifier)) return true;
745
+ return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
746
+ }
747
+ function resolveModuleFromPaths(specifier, paths) {
748
+ if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
749
+ try {
750
+ return createRequire(import.meta.url).resolve(specifier, { paths });
751
+ } catch {
752
+ return;
753
+ }
754
+ }
755
+ function resolveTailwindConfigFallback(packageName, paths) {
756
+ if (!packageName) return;
757
+ for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
758
+ const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
759
+ if (resolved) return resolved;
760
+ }
761
+ }
762
+ function appendNodeModules(paths, dir) {
763
+ if (!dir) return;
764
+ const nodeModulesDir = path.join(dir, "node_modules");
765
+ if (existsSync(nodeModulesDir)) paths.add(nodeModulesDir);
766
+ }
767
+ function findTailwindConfig(searchRoots) {
768
+ for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
769
+ const candidate = path.resolve(root, file);
770
+ if (existsSync(candidate)) return candidate;
771
+ }
772
+ }
773
+ function createDefaultResolvePaths(basedir) {
774
+ const paths = /* @__PURE__ */ new Set();
775
+ let fallbackCandidates = [];
776
+ if (basedir) {
777
+ const resolvedBase = path.resolve(basedir);
778
+ appendNodeModules(paths, resolvedBase);
779
+ fallbackCandidates.push(resolvedBase);
780
+ const packageRoot = findNearestPackageRoot(resolvedBase);
781
+ if (packageRoot) {
782
+ appendNodeModules(paths, packageRoot);
783
+ fallbackCandidates.push(packageRoot);
784
+ }
785
+ const workspaceRoot = findWorkspaceRoot(resolvedBase);
786
+ if (workspaceRoot) {
787
+ appendNodeModules(paths, workspaceRoot);
788
+ fallbackCandidates.push(workspaceRoot);
789
+ }
790
+ }
791
+ const cwd = process.cwd();
792
+ appendNodeModules(paths, cwd);
793
+ try {
794
+ const modulePath = fileURLToPath(import.meta.url);
795
+ const candidate = existsSync(modulePath) && !path.extname(modulePath) ? modulePath : path.dirname(modulePath);
796
+ paths.add(candidate);
797
+ } catch {
798
+ paths.add(import.meta.url);
799
+ }
800
+ if (paths.size === 0) {
801
+ fallbackCandidates = fallbackCandidates.filter(Boolean);
802
+ if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
803
+ for (const candidate of fallbackCandidates) paths.add(candidate);
804
+ }
805
+ return [...paths];
806
+ }
807
+ //#endregion
808
+ //#region src/tailwindcss/version.ts
809
+ function normalizeSupportedTailwindcssMajorVersion(version) {
810
+ return version === 4 ? version : void 0;
811
+ }
812
+ function readPackageJson(packageJsonPath) {
813
+ try {
814
+ return JSON.parse(readFileSync(packageJsonPath, "utf8"));
815
+ } catch {
816
+ return;
817
+ }
818
+ }
819
+ function findPackageJsonDeclaringPackage(packageName, base) {
820
+ let current = path.resolve(base);
821
+ while (true) {
822
+ const pkgPath = path.join(current, "package.json");
823
+ if (existsSync(pkgPath)) {
824
+ const pkg = readPackageJson(pkgPath);
825
+ if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
826
+ if (pkg?.name !== "weapp-tailwindcss") return;
827
+ }
828
+ const parent = path.dirname(current);
829
+ if (parent === current) return;
830
+ current = parent;
831
+ }
832
+ }
833
+ function readDeclaredPackageVersion(packageName, pkg) {
834
+ return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
835
+ }
836
+ function readDeclaredPackageMajorVersion(version) {
837
+ const match = version?.match(/(?:^|\D)(4)(?:\.|\b)/);
838
+ return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
839
+ }
840
+ function readInstalledPackageMajorVersion(packageName, base) {
841
+ const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
842
+ if (!packageJsonPath) return;
843
+ const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
844
+ if (!declaredVersion) return;
845
+ try {
846
+ const pkg = createRequire(packageJsonPath)(`${packageName}/package.json`);
847
+ return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
848
+ } catch {
849
+ return readDeclaredPackageMajorVersion(declaredVersion);
850
+ }
851
+ }
852
+ //#endregion
853
+ //#region src/tailwindcss/runtime-factory.ts
854
+ const require = createRequire(import.meta.url);
855
+ function createPackageInfo(tailwindOptions) {
856
+ const packageName = tailwindOptions?.packageName ?? "tailwindcss";
857
+ const resolvePaths = tailwindOptions?.resolve?.paths;
858
+ let rootPath;
859
+ const cwdPackageJsonPath = tailwindOptions?.cwd ? path.join(tailwindOptions.cwd, "package.json") : void 0;
860
+ if (cwdPackageJsonPath) try {
861
+ if (require(cwdPackageJsonPath).name === packageName) rootPath = cwdPackageJsonPath;
862
+ } catch {}
863
+ rootPath ?? (rootPath = resolveModuleFromPaths(`${packageName}/package.json`, resolvePaths ?? []));
864
+ if (!rootPath) for (const resolvePath of [tailwindOptions?.cwd, ...resolvePaths ?? []]) {
865
+ if (!resolvePath) continue;
866
+ try {
867
+ rootPath = createRequire(path.join(resolvePath, "package.json")).resolve(`${packageName}/package.json`);
868
+ break;
869
+ } catch {}
870
+ }
871
+ if (rootPath) {
872
+ const packageJsonPath = rootPath;
873
+ const packageRoot = path.dirname(packageJsonPath);
874
+ try {
875
+ const packageJson = require(packageJsonPath);
876
+ return {
877
+ name: packageName,
878
+ version: packageJson.version,
879
+ rootPath: packageRoot,
880
+ packageJsonPath,
881
+ packageJson
882
+ };
883
+ } catch {
884
+ return {
885
+ name: packageName,
886
+ version: void 0,
887
+ rootPath: packageRoot,
888
+ packageJsonPath,
889
+ packageJson: {}
890
+ };
891
+ }
892
+ }
893
+ return {
894
+ name: packageName,
895
+ version: void 0,
896
+ rootPath: "",
897
+ packageJsonPath: "",
898
+ packageJson: {}
899
+ };
900
+ }
901
+ function resolveMajorVersion(tailwindOptions, packageInfo) {
902
+ if (tailwindOptions?.version === 4) return tailwindOptions.version;
903
+ if (packageInfo.version?.startsWith("4.")) return 4;
904
+ return 4;
905
+ }
906
+ function createFallbackTailwindcssRuntime(options) {
907
+ const packageInfo = createPackageInfo(options?.tailwindcss);
908
+ return {
909
+ packageInfo,
910
+ majorVersion: resolveMajorVersion(options?.tailwindcss, packageInfo),
911
+ options,
912
+ async getClassSet() {
913
+ return /* @__PURE__ */ new Set();
914
+ },
915
+ async extract(_options) {
916
+ return {
917
+ classList: [],
918
+ classSet: /* @__PURE__ */ new Set()
919
+ };
920
+ },
921
+ async collectContentTokens() {
922
+ return {
923
+ entries: [],
924
+ filesScanned: 0,
925
+ sources: [],
926
+ skippedFiles: []
927
+ };
928
+ }
929
+ };
930
+ }
931
+ function createEngineTailwindcssRuntime(options) {
932
+ const tailwindOptions = options.tailwindcss;
933
+ const packageInfo = createPackageInfo(tailwindOptions);
934
+ const majorVersion = resolveMajorVersion(tailwindOptions, packageInfo);
935
+ let classSetCache;
936
+ let runtime;
937
+ function applyClassSetFilter(classSet) {
938
+ if (typeof options.filter !== "function") return classSet;
939
+ return new Set([...classSet].filter((className) => options.filter?.(className) !== false));
940
+ }
941
+ async function collectClassSet() {
942
+ const report = await collectContentTokens();
943
+ const candidates = new Set(report.entries.map((entry) => {
944
+ return typeof entry === "string" ? entry : entry.rawCandidate;
945
+ }).filter((entry) => typeof entry === "string" && entry.length > 0));
946
+ await collectTailwindV4CssCandidates(candidates);
947
+ return applyClassSetFilter(candidates);
948
+ }
949
+ async function collectTailwindV4CssCandidates(candidates) {
950
+ const source = await resolveTailwindV4SourceFromRuntime(runtime);
951
+ const cssList = [source.css, ...(source.cssSources ?? []).map((cssSource) => cssSource.css).filter((css) => typeof css === "string")];
952
+ for (const css of cssList) {
953
+ if (!css.includes("@apply")) continue;
954
+ try {
955
+ postcss.parse(css).walkAtRules("apply", (rule) => {
956
+ for (const candidate of rule.params.split(/\s+/)) {
957
+ const normalized = candidate.replace(/!important$/, "").trim();
958
+ if (normalized) candidates.add(normalized);
959
+ }
960
+ });
961
+ } catch {}
962
+ }
963
+ }
964
+ async function collectContentTokens() {
965
+ const source = await resolveTailwindV4SourceFromRuntime(runtime);
966
+ const report = await extractProjectCandidatesWithPositions({
967
+ base: source.base,
968
+ baseFallbacks: source.baseFallbacks,
969
+ css: source.css,
970
+ cwd: source.projectRoot,
971
+ sources: source.sources
972
+ });
973
+ return {
974
+ entries: report.entries,
975
+ filesScanned: report.filesScanned,
976
+ sources: source.sources,
977
+ skippedFiles: report.skippedFiles
978
+ };
979
+ }
980
+ async function extract(options) {
981
+ let classSet = await collectClassSet();
982
+ const filter = options?.removeUniversalSelector === true ? (className) => className !== "*" : void 0;
983
+ if (filter) classSet = new Set([...classSet].filter(filter));
984
+ if (typeof options?.write === "boolean") {}
985
+ classSetCache = classSet;
986
+ return {
987
+ classList: [...classSet],
988
+ classSet
989
+ };
990
+ }
991
+ runtime = {
992
+ packageInfo,
993
+ majorVersion,
994
+ options,
995
+ async getClassSet() {
996
+ return (await extract({ write: false })).classSet;
997
+ },
998
+ getClassSetSync() {
999
+ return classSetCache ?? /* @__PURE__ */ new Set();
1000
+ },
1001
+ extract,
1002
+ collectContentTokens
1003
+ };
1004
+ return runtime;
1005
+ }
1006
+ let hasLoggedMissingTailwind = false;
1007
+ const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
1008
+ const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
1009
+ function createTailwindcssRuntime(options) {
1010
+ const { basedir, cacheDir, supportCustomLengthUnits, tailwindcss, tailwindcssRuntimeOptions } = options || {};
1011
+ const cache = {
1012
+ enabled: true,
1013
+ driver: "memory"
1014
+ };
1015
+ const normalizedBasedir = basedir ? path.resolve(basedir) : void 0;
1016
+ const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
1017
+ if (cacheDir) if (path.isAbsolute(cacheDir)) cache.dir = cacheDir;
1018
+ else if (normalizedBasedir) cache.dir = path.resolve(normalizedBasedir, cacheDir);
1019
+ else cache.dir = path.resolve(process.cwd(), cacheDir);
1020
+ else cache.dir = path.join(cacheRoot, "node_modules", ".cache", "@tailwindcss-mangle", "engine");
1021
+ if (normalizedBasedir) cache.cwd = normalizedBasedir;
1022
+ const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? process.cwd());
1023
+ const normalizedUserOptions = normalizeTailwindcssRuntimeOptions(tailwindcssRuntimeOptions);
1024
+ const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnits ?? true);
1025
+ const baseTailwindOptions = defuOverrideArray(tailwindcss ?? {}, omitUndefined({
1026
+ cwd: normalizedBasedir,
1027
+ resolve: { paths: resolvePaths }
1028
+ }));
1029
+ baseTailwindOptions.packageName = tailwindcss?.packageName ?? normalizedUserOptions?.tailwindcss?.packageName ?? baseTailwindOptions.packageName ?? "tailwindcss";
1030
+ if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = "tailwindcss";
1031
+ if (typeof baseTailwindOptions.postcssPlugin === "string") {
1032
+ const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
1033
+ if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
1034
+ }
1035
+ const baseOptions = omitUndefined({
1036
+ projectRoot: normalizedBasedir,
1037
+ cache,
1038
+ tailwindcss: baseTailwindOptions,
1039
+ apply: omitUndefined({
1040
+ exposeContext: true,
1041
+ extendLengthUnits
1042
+ })
1043
+ });
1044
+ const resolvedOptions = defuOverrideArray(normalizedUserOptions ?? {}, baseOptions);
1045
+ const resolvedTailwindOptions = resolvedOptions.tailwindcss;
1046
+ if (resolvedTailwindOptions) {
1047
+ const existingResolve = resolvedTailwindOptions.resolve ?? {};
1048
+ const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths ?? [], ...resolvePaths] : resolvePaths;
1049
+ resolvedTailwindOptions.resolve = {
1050
+ ...existingResolve,
1051
+ paths: [...new Set(sourcePaths)]
1052
+ };
1053
+ logger.debug("Tailwind resolve config %O", {
1054
+ packageName: resolvedTailwindOptions.packageName,
1055
+ version: resolvedTailwindOptions.version,
1056
+ resolve: resolvedTailwindOptions.resolve,
1057
+ cwd: resolvedTailwindOptions.cwd
1058
+ });
1059
+ if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
1060
+ const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
1061
+ if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
1062
+ }
1063
+ const searchRoots = /* @__PURE__ */ new Set();
1064
+ if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
1065
+ for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
1066
+ const parentDir = path.dirname(resolvePath);
1067
+ searchRoots.add(parentDir);
1068
+ }
1069
+ const configPath = findTailwindConfig(searchRoots);
1070
+ if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
1071
+ else {
1072
+ const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
1073
+ if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
1074
+ }
1075
+ if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = path.dirname(configPath);
1076
+ resolvedOptions.tailwindcss = resolvedTailwindOptions;
1077
+ }
1078
+ try {
1079
+ return createEngineTailwindcssRuntime(resolvedOptions);
1080
+ } catch (error) {
1081
+ const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
1082
+ if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
1083
+ if (!hasLoggedMissingTailwind) {
1084
+ logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 运行时能力。若需使用 Tailwind 能力,请安装 tailwindcss。");
1085
+ hasLoggedMissingTailwind = true;
1086
+ }
1087
+ return createFallbackTailwindcssRuntime(resolvedOptions);
1088
+ }
1089
+ if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
1090
+ throw error;
1091
+ }
1092
+ }
1093
+ //#endregion
1094
+ //#region src/tailwindcss/v4/multi-runtime.ts
1095
+ function createMultiTailwindcssRuntime(runtimes) {
1096
+ if (runtimes.length <= 1) {
1097
+ const [runtime] = runtimes;
1098
+ if (!runtime) throw new Error("createMultiTailwindcssRuntime requires at least one runtime.");
1099
+ return runtime;
1100
+ }
1101
+ const first = runtimes[0];
1102
+ const multiRuntime = {
1103
+ ...first,
1104
+ packageInfo: first?.packageInfo,
1105
+ majorVersion: first?.majorVersion,
1106
+ options: first?.options,
1107
+ async getClassSet() {
1108
+ const aggregated = /* @__PURE__ */ new Set();
1109
+ for (const runtime of runtimes) {
1110
+ const current = await runtime.getClassSet();
1111
+ for (const className of current) aggregated.add(className);
1112
+ }
1113
+ return aggregated;
1114
+ },
1115
+ async extract(options) {
1116
+ const aggregatedSet = /* @__PURE__ */ new Set();
1117
+ const aggregatedList = [];
1118
+ let filename;
1119
+ for (const runtime of runtimes) {
1120
+ const result = await runtime.extract(options);
1121
+ if (!result) continue;
1122
+ if (filename === void 0 && result.filename) filename = result.filename;
1123
+ if (result.classList) for (const className of result.classList) {
1124
+ if (!aggregatedSet.has(className)) aggregatedList.push(className);
1125
+ aggregatedSet.add(className);
1126
+ }
1127
+ if (result.classSet) for (const className of result.classSet) aggregatedSet.add(className);
1128
+ }
1129
+ return omitUndefined({
1130
+ classList: aggregatedList,
1131
+ classSet: aggregatedSet,
1132
+ filename
1133
+ });
1134
+ }
1135
+ };
1136
+ if (runtimes.every((runtime) => typeof runtime.getClassSetSync === "function")) multiRuntime.getClassSetSync = () => {
1137
+ const aggregated = /* @__PURE__ */ new Set();
1138
+ for (const runtime of runtimes) {
1139
+ const current = runtime.getClassSetSync?.();
1140
+ if (!current) continue;
1141
+ for (const className of current) aggregated.add(className);
1142
+ }
1143
+ return aggregated;
1144
+ };
1145
+ Object.defineProperty(multiRuntime, runtimeSignatureRuntimesSymbol, {
1146
+ value: [...runtimes],
1147
+ configurable: true
1148
+ });
1149
+ return multiRuntime;
1150
+ }
1151
+ //#endregion
1152
+ //#region src/tailwindcss/v4/runtime-options.ts
1153
+ function overrideTailwindcssRuntimeOptionsForBase(options, baseDir, cssEntries) {
1154
+ const hasCssEntries = cssEntries.length > 0;
1155
+ if (!options) return options;
1156
+ const modernTailwind = options.tailwindcss;
1157
+ if (!modernTailwind) return options;
1158
+ return {
1159
+ ...options,
1160
+ tailwindcss: {
1161
+ ...modernTailwind,
1162
+ v4: {
1163
+ ...modernTailwind.v4 ?? {},
1164
+ ...hasCssEntries ? {} : { base: modernTailwind.v4?.base ?? baseDir },
1165
+ cssEntries: hasCssEntries ? cssEntries : modernTailwind.v4?.cssEntries ?? cssEntries
1166
+ }
1167
+ }
1168
+ };
1169
+ }
1170
+ //#endregion
1171
+ //#region src/tailwindcss/v4/runtime-factory.ts
1172
+ function isTailwindcss4Package(packageName) {
1173
+ return Boolean(packageName && (packageName === "tailwindcss4" || packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")));
1174
+ }
1175
+ function resolveExplicitTailwindVersion(configuredVersion, configuredPackageName) {
1176
+ if (typeof configuredVersion === "number") return configuredVersion;
1177
+ if (isTailwindcss4Package(configuredPackageName)) return 4;
1178
+ }
1179
+ function readPackageNameFromBaseDir(baseDir) {
1180
+ try {
1181
+ if (!existsSync(path.join(baseDir, "index.css"))) return;
1182
+ const name = JSON.parse(readFileSync(path.join(baseDir, "package.json"), "utf8")).name;
1183
+ return typeof name === "string" && (name === "tailwindcss" || name.includes("tailwindcss4")) ? name : void 0;
1184
+ } catch {
1185
+ return;
1186
+ }
1187
+ }
1188
+ function createTailwindcssRuntimeForBase(baseDir, cssEntries, options) {
1189
+ const { tailwindcss, tailwindcssRuntimeOptions, supportCustomLengthUnits, bareArbitraryValues } = options;
1190
+ const hasCssEntries = Boolean(cssEntries?.length);
1191
+ const defaultTailwindcssConfig = {
1192
+ cwd: baseDir,
1193
+ v4: hasCssEntries ? omitUndefined({ cssEntries }) : omitUndefined({
1194
+ base: baseDir,
1195
+ cssEntries
1196
+ })
1197
+ };
1198
+ const mergedTailwindOptions = defuOverrideArray$1(tailwindcss ?? {}, defaultTailwindcssConfig);
1199
+ if (!mergedTailwindOptions.v4 || typeof mergedTailwindOptions.v4 !== "object") mergedTailwindOptions.v4 = hasCssEntries ? { cssEntries: cssEntries ?? [] } : {
1200
+ base: baseDir,
1201
+ cssEntries: cssEntries ?? []
1202
+ };
1203
+ else if (hasCssEntries) {
1204
+ if (cssEntries?.length) mergedTailwindOptions.v4.cssEntries = cssEntries;
1205
+ else if (!mergedTailwindOptions.v4.cssEntries) mergedTailwindOptions.v4.cssEntries = [];
1206
+ } else if (!mergedTailwindOptions.v4.cssEntries) {
1207
+ if (!mergedTailwindOptions.v4.base) mergedTailwindOptions.v4.base = baseDir;
1208
+ mergedTailwindOptions.v4.cssEntries = cssEntries ?? [];
1209
+ }
1210
+ if (bareArbitraryValues !== void 0 && bareArbitraryValues !== false) mergedTailwindOptions.v4.bareArbitraryValues = bareArbitraryValues;
1211
+ const patchedOptions = overrideTailwindcssRuntimeOptionsForBase(tailwindcssRuntimeOptions, baseDir, cssEntries ?? []);
1212
+ const configuredPackageName = tailwindcss?.packageName || tailwindcssRuntimeOptions?.tailwindcss?.packageName;
1213
+ const explicitTailwindVersion = resolveExplicitTailwindVersion(tailwindcss?.version || tailwindcssRuntimeOptions?.tailwindcss?.version || mergedTailwindOptions.version, configuredPackageName);
1214
+ const resolvedTailwindVersion = readInstalledPackageMajorVersion(configuredPackageName ?? mergedTailwindOptions.packageName ?? "tailwindcss", baseDir) ?? explicitTailwindVersion;
1215
+ const supportedResolvedTailwindVersion = resolvedTailwindVersion === 4 ? resolvedTailwindVersion : void 0;
1216
+ const tailwindOptionsForPackage = {
1217
+ ...mergedTailwindOptions,
1218
+ packageName: configuredPackageName ?? mergedTailwindOptions.packageName ?? readPackageNameFromBaseDir(baseDir) ?? "tailwindcss"
1219
+ };
1220
+ if (supportedResolvedTailwindVersion) tailwindOptionsForPackage.version = supportedResolvedTailwindVersion;
1221
+ return createTailwindcssRuntime(omitUndefined({
1222
+ basedir: baseDir,
1223
+ supportCustomLengthUnits: supportCustomLengthUnits ?? true,
1224
+ tailwindcss: tailwindOptionsForPackage,
1225
+ tailwindcssRuntimeOptions: patchedOptions
1226
+ }));
1227
+ }
1228
+ function tryCreateMultiTailwindcssRuntime(groups, options) {
1229
+ if (groups.size <= 1) return;
1230
+ logger.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
1231
+ const runtimes = [];
1232
+ for (const [baseDir, entries] of groups) {
1233
+ const runtime = createTailwindcssRuntimeForBase(baseDir, entries, options);
1234
+ if (runtime) runtimes.push(runtime);
1235
+ }
1236
+ return createMultiTailwindcssRuntime(runtimes);
1237
+ }
1238
+ //#endregion
1239
+ //#region src/uni-app-x/options.ts
1240
+ const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
1241
+ enabled: true,
1242
+ onlyWhenStyleIsolationVersion2: true
1243
+ };
1244
+ const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
1245
+ enabled: false,
1246
+ onlyWhenStyleIsolationVersion2: true
1247
+ };
1248
+ function isBooleanUniAppXShortcut(option) {
1249
+ return option === true || option === false || option === void 0;
1250
+ }
1251
+ function resolveComponentLocalStyles(option) {
1252
+ if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
1253
+ const componentLocalStyles = option.componentLocalStyles;
1254
+ if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
1255
+ if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
1256
+ return {
1257
+ enabled: componentLocalStyles.enabled !== false,
1258
+ onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
1259
+ };
1260
+ }
1261
+ function resolveUniAppXOptions(option) {
1262
+ if (typeof option === "object" && option) return {
1263
+ enabled: option.enabled !== false,
1264
+ componentLocalStyles: resolveComponentLocalStyles(option),
1265
+ uvueUnsupported: option.uvueUnsupported ?? "warn"
1266
+ };
1267
+ return {
1268
+ enabled: Boolean(option),
1269
+ componentLocalStyles: resolveComponentLocalStyles(option),
1270
+ uvueUnsupported: "warn"
1271
+ };
1272
+ }
1273
+ function isUniAppXEnabled(option) {
1274
+ return resolveUniAppXOptions(option).enabled;
1275
+ }
1276
+ //#endregion
1277
+ //#region src/context/tailwindcss/basedir.ts
1278
+ const ENV_BASEDIR_KEYS = [
1279
+ "WEAPP_TAILWINDCSS_BASEDIR",
1280
+ "WEAPP_TAILWINDCSS_BASE_DIR",
1281
+ "TAILWINDCSS_BASEDIR",
1282
+ "TAILWINDCSS_BASE_DIR",
1283
+ "UNI_INPUT_DIR",
1284
+ "UNI_INPUT_ROOT",
1285
+ "UNI_CLI_ROOT",
1286
+ "UNI_APP_INPUT_DIR",
1287
+ "INIT_CWD",
1288
+ "PWD"
1289
+ ];
1290
+ const GENERIC_ENV_BASEDIR_KEYS = new Set(["INIT_CWD", "PWD"]);
1291
+ function pickEnvBasedir() {
1292
+ for (const key of ENV_BASEDIR_KEYS) {
1293
+ const value = process.env[key];
1294
+ if (value && path.isAbsolute(value)) return {
1295
+ key,
1296
+ value
1297
+ };
1298
+ }
1299
+ }
1300
+ function pickPackageEnvBasedir() {
1301
+ const packageJsonPath = process.env["npm_package_json"];
1302
+ if (packageJsonPath) {
1303
+ const packageDir = path.dirname(packageJsonPath);
1304
+ if (packageDir && path.isAbsolute(packageDir)) return packageDir;
1305
+ }
1306
+ const localPrefix = process.env["npm_config_local_prefix"];
1307
+ if (localPrefix && path.isAbsolute(localPrefix)) return localPrefix;
1308
+ }
1309
+ const STACK_PAREN_RE = /\(([^)]+)\)/u;
1310
+ const STACK_AT_RE = /at\s+(\S.*)$/u;
1311
+ function detectCallerBasedir() {
1312
+ const stack = (/* @__PURE__ */ new Error("resolveTailwindcssBasedir stack probe")).stack;
1313
+ if (!stack) return;
1314
+ if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("caller stack: %s", stack);
1315
+ const lines = stack.split("\n");
1316
+ for (const line of lines) {
1317
+ const location = (line.match(STACK_PAREN_RE) ?? line.match(STACK_AT_RE))?.[1];
1318
+ if (!location) continue;
1319
+ let filePath = location;
1320
+ if (filePath.startsWith("file://")) try {
1321
+ filePath = fileURLToPath(filePath);
1322
+ } catch {
1323
+ continue;
1324
+ }
1325
+ const [candidate = ""] = filePath.split(":");
1326
+ const resolvedPath = path.isAbsolute(filePath) ? filePath : candidate;
1327
+ if (!path.isAbsolute(resolvedPath)) continue;
1328
+ if (resolvedPath.includes("node_modules") && resolvedPath.includes("weapp-tailwindcss")) continue;
1329
+ try {
1330
+ return path.dirname(resolvedPath);
1331
+ } catch {
1332
+ continue;
1333
+ }
1334
+ }
1335
+ }
1336
+ function resolveTailwindcssBasedir(basedir, fallback) {
1337
+ const envBasedirResult = pickEnvBasedir();
1338
+ const envBasedir = envBasedirResult?.value;
1339
+ const envBasedirKey = envBasedirResult?.key;
1340
+ const envBasedirIsGeneric = envBasedirKey ? GENERIC_ENV_BASEDIR_KEYS.has(envBasedirKey) : false;
1341
+ const packageEnvBasedir = pickPackageEnvBasedir();
1342
+ const callerBasedir = !envBasedir || envBasedirIsGeneric ? detectCallerBasedir() : void 0;
1343
+ const cwd = process.cwd();
1344
+ const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? cwd;
1345
+ const resolveRelative = (value) => path.isAbsolute(value) ? path.normalize(value) : path.normalize(path.resolve(anchor, value));
1346
+ if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("resolveTailwindcssBasedir anchor %O", {
1347
+ basedir,
1348
+ envBasedir,
1349
+ envBasedirKey,
1350
+ envBasedirIsGeneric,
1351
+ packageEnvBasedir,
1352
+ fallback,
1353
+ callerBasedir,
1354
+ npm_package_json: process.env["npm_package_json"],
1355
+ cwd,
1356
+ anchor
1357
+ });
1358
+ if (basedir && basedir.trim().length > 0) return resolveRelative(basedir);
1359
+ if (envBasedir && !envBasedirIsGeneric) return path.normalize(envBasedir);
1360
+ if (fallback && fallback.trim().length > 0) return resolveRelative(fallback);
1361
+ if (packageEnvBasedir) return path.normalize(packageEnvBasedir);
1362
+ if (callerBasedir) {
1363
+ const normalizedCaller = path.normalize(callerBasedir);
1364
+ const librarySegment = `${path.sep}weapp-tailwindcss${path.sep}`;
1365
+ if (!normalizedCaller.includes(librarySegment)) return normalizedCaller;
1366
+ }
1367
+ const packageName = process.env["PNPM_PACKAGE_NAME"];
1368
+ if (packageName) try {
1369
+ const packageJsonPath = createRequire(path.join(anchor, "__resolve_tailwindcss_basedir__.cjs")).resolve(`${packageName}/package.json`);
1370
+ if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
1371
+ return path.normalize(path.dirname(packageJsonPath));
1372
+ } catch {
1373
+ if (process.env["WEAPP_TW_DEBUG_STACK"] === "1") logger.debug("failed to resolve package json for %s", packageName);
1374
+ const workspaceRoot = findWorkspaceRoot(anchor);
1375
+ if (workspaceRoot) {
1376
+ const packageDir = findWorkspacePackageDir(workspaceRoot, packageName);
1377
+ if (packageDir) return packageDir;
1378
+ }
1379
+ }
1380
+ if (envBasedir) return path.normalize(envBasedir);
1381
+ return path.normalize(cwd);
1382
+ }
1383
+ //#endregion
1384
+ //#region src/context/tailwindcss.ts
1385
+ function createTailwindcssRuntimeFromContext(ctx) {
1386
+ const { tailwindcssBasedir, supportCustomLengthUnits, tailwindcss, tailwindcssRuntimeOptions, cssEntries: rawCssEntries, appType, arbitraryValues } = ctx;
1387
+ const effectiveSupportCustomLengthUnits = ctx.generator?.target === "web" ? false : supportCustomLengthUnits;
1388
+ const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
1389
+ const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
1390
+ ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
1391
+ logger.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
1392
+ const normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
1393
+ if (normalizedCssEntries) ctx.cssEntries = normalizedCssEntries;
1394
+ const runtimeOptions = {
1395
+ tailwindcss,
1396
+ tailwindcssRuntimeOptions,
1397
+ supportCustomLengthUnits: effectiveSupportCustomLengthUnits,
1398
+ appType,
1399
+ bareArbitraryValues: arbitraryValues?.bareArbitraryValues
1400
+ };
1401
+ const workspaceRoot = findWorkspaceRoot(resolvedTailwindcssBasedir) ?? (absoluteCssEntryBasedir ? findWorkspaceRoot(absoluteCssEntryBasedir) : void 0);
1402
+ const groupedCssEntries = normalizedCssEntries ? groupCssEntriesByBase(normalizedCssEntries, omitUndefined({
1403
+ preferredBaseDir: resolvedTailwindcssBasedir,
1404
+ workspaceRoot
1405
+ })) : void 0;
1406
+ const multiRuntime = groupedCssEntries ? tryCreateMultiTailwindcssRuntime(groupedCssEntries, runtimeOptions) : void 0;
1407
+ if (multiRuntime) return multiRuntime;
1408
+ if (groupedCssEntries?.size === 1) {
1409
+ const firstGroup = groupedCssEntries.entries().next().value;
1410
+ if (firstGroup) {
1411
+ const [baseDir, entries] = firstGroup;
1412
+ return createTailwindcssRuntimeForBase(baseDir, entries, runtimeOptions);
1413
+ }
1414
+ }
1415
+ return createTailwindcssRuntimeForBase(resolvedTailwindcssBasedir, normalizedCssEntries ?? rawCssEntries, runtimeOptions);
1416
+ }
1417
+ //#endregion
1418
+ export { resolveViteTailwindV4CssDependencies as _, findTailwindConfig as a, getRuntimeClassSetCacheEntry as c, invalidateRuntimeClassSet as d, createViteSourceScanMatcher as f, resolveTailwindV4EntriesFromCssCached as g, resolveTailwindV4EntriesFromCss as h, resolveUniAppXOptions as i, getRuntimeClassSetSignature as l, discoverTailwindV4CssEntries as m, resolveTailwindcssBasedir as n, applyV4CssCalcDefaults as o, resolveViteSourceScanEntries as p, isUniAppXEnabled as r, warnMissingCssEntries as s, createTailwindcssRuntimeFromContext as t, getRuntimeClassSetSignatureWithSources as u };