weapp-tailwindcss 4.11.0-alpha.0 → 4.11.0-alpha.2

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 (73) hide show
  1. package/dist/{chunk-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
  2. package/dist/{chunk-FV4ZRTAK.js → chunk-2W24MRCQ.js} +10 -12
  3. package/dist/chunk-4AFQP74Z.js +24 -0
  4. package/dist/{chunk-7XQXBJL6.js → chunk-4TTPYMVM.js} +12 -8
  5. package/dist/{chunk-RXNSOSCT.js → chunk-5KSBT6GU.js} +448 -270
  6. package/dist/{chunk-QX2A7SBB.mjs → chunk-66E76FQE.mjs} +666 -102
  7. package/dist/{chunk-WGFNCK5B.js → chunk-6O7HJU2F.js} +123 -42
  8. package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
  9. package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
  10. package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
  11. package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
  12. package/dist/{chunk-XGUD52TA.mjs → chunk-EW2K6CO5.mjs} +413 -235
  13. package/dist/{chunk-FMWKBZWX.mjs → chunk-HADJCWHU.mjs} +291 -265
  14. package/dist/{chunk-FKUPQQYX.js → chunk-K7CZXT46.js} +692 -125
  15. package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
  16. package/dist/{chunk-I4EOMKX2.js → chunk-LYGLQCWI.js} +356 -330
  17. package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
  18. package/dist/{chunk-W3JO6LBC.mjs → chunk-RED7Y22U.mjs} +91 -10
  19. package/dist/{chunk-CLNUBO3Q.mjs → chunk-SJ3SG6DU.mjs} +5 -1
  20. package/dist/{chunk-OIDFSOER.mjs → chunk-UCUAXK7F.mjs} +4 -6
  21. package/dist/cli.js +1006 -147
  22. package/dist/cli.mjs +942 -107
  23. package/dist/core.d.mts +2 -2
  24. package/dist/core.d.ts +2 -2
  25. package/dist/core.js +9 -11
  26. package/dist/core.mjs +6 -8
  27. package/dist/css-macro/postcss.js +1 -1
  28. package/dist/css-macro/postcss.mjs +1 -1
  29. package/dist/css-macro.js +3 -3
  30. package/dist/css-macro.mjs +4 -4
  31. package/dist/defaults.d.mts +2 -2
  32. package/dist/defaults.d.ts +2 -2
  33. package/dist/defaults.js +3 -3
  34. package/dist/defaults.mjs +2 -2
  35. package/dist/gulp.d.mts +2 -2
  36. package/dist/gulp.d.ts +2 -2
  37. package/dist/gulp.js +7 -8
  38. package/dist/gulp.mjs +6 -7
  39. package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
  40. package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
  41. package/dist/index.d.mts +2 -2
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +11 -12
  44. package/dist/index.mjs +9 -10
  45. package/dist/postcss-html-transform.js +1 -1
  46. package/dist/postcss-html-transform.mjs +1 -1
  47. package/dist/presets.d.mts +2 -2
  48. package/dist/presets.d.ts +2 -2
  49. package/dist/presets.js +5 -5
  50. package/dist/presets.mjs +2 -2
  51. package/dist/reset.js +1 -1
  52. package/dist/reset.mjs +1 -1
  53. package/dist/types.d.mts +4 -4
  54. package/dist/types.d.ts +4 -4
  55. package/dist/types.js +1 -1
  56. package/dist/types.mjs +1 -1
  57. package/dist/vite.d.mts +2 -2
  58. package/dist/vite.d.ts +2 -2
  59. package/dist/vite.js +8 -9
  60. package/dist/vite.mjs +6 -7
  61. package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
  62. package/dist/weapp-tw-runtime-classset-loader.js +29 -2
  63. package/dist/webpack.d.mts +2 -2
  64. package/dist/webpack.d.ts +2 -2
  65. package/dist/webpack.js +9 -10
  66. package/dist/webpack.mjs +7 -8
  67. package/dist/webpack4.d.mts +2 -2
  68. package/dist/webpack4.d.ts +2 -2
  69. package/dist/webpack4.js +41 -41
  70. package/dist/webpack4.mjs +12 -12
  71. package/package.json +9 -9
  72. package/dist/chunk-EOK3NZVC.mjs +0 -29
  73. package/dist/chunk-PXZUQ7RR.js +0 -29
@@ -2,214 +2,13 @@ import {
2
2
  defuOverrideArray
3
3
  } from "./chunk-OOHJLO5M.mjs";
4
4
 
5
- // src/logger/index.ts
6
- import { logger } from "@weapp-tailwindcss/logger";
7
-
8
- // src/tailwindcss/v4/config.ts
9
- import { logger as logger2 } from "@weapp-tailwindcss/logger";
10
- var DEFAULT_CSS_CALC_CUSTOM_PROPERTIES = [];
11
- function includesToken(list, token) {
12
- return list.some((candidate) => {
13
- if (typeof token === "string") {
14
- if (typeof candidate === "string") {
15
- return candidate === token;
16
- }
17
- candidate.lastIndex = 0;
18
- return candidate.test(token);
19
- }
20
- if (typeof candidate === "string") {
21
- token.lastIndex = 0;
22
- return token.test(candidate);
23
- }
24
- return candidate.source === token.source && candidate.flags === token.flags;
25
- });
26
- }
27
- function ensureDefaultsIncluded(value) {
28
- if (value === true) {
29
- return {
30
- includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
31
- };
32
- }
33
- if (Array.isArray(value)) {
34
- if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
35
- return value;
36
- }
37
- const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(value, token));
38
- return missing.length > 0 ? [...value, ...missing] : value;
39
- }
40
- if (value && typeof value === "object") {
41
- const include = value.includeCustomProperties;
42
- if (!Array.isArray(include)) {
43
- return {
44
- ...value,
45
- includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
46
- };
47
- }
48
- if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
49
- return value;
50
- }
51
- const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(include, token));
52
- return missing.length > 0 ? {
53
- ...value,
54
- includeCustomProperties: [...include, ...missing]
55
- } : value;
56
- }
57
- return value;
58
- }
59
- function normalizeCssEntriesConfig(entries) {
60
- if (!entries) {
61
- return void 0;
62
- }
63
- if (typeof entries === "string") {
64
- const trimmed = entries.trim();
65
- return trimmed ? [trimmed] : void 0;
66
- }
67
- if (!Array.isArray(entries)) {
68
- return void 0;
69
- }
70
- const normalized = entries.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
71
- return normalized.length > 0 ? normalized : void 0;
72
- }
73
- function hasConfiguredCssEntries(ctx) {
74
- if (normalizeCssEntriesConfig(ctx.cssEntries)) {
75
- return true;
76
- }
77
- if (normalizeCssEntriesConfig(ctx.tailwindcss?.v4?.cssEntries)) {
78
- return true;
79
- }
80
- const patcherOptions = ctx.tailwindcssPatcherOptions;
81
- if (patcherOptions) {
82
- if (normalizeCssEntriesConfig(patcherOptions.tailwindcss?.v4?.cssEntries)) {
83
- return true;
84
- }
85
- if (normalizeCssEntriesConfig(patcherOptions.tailwind?.v4?.cssEntries)) {
86
- return true;
87
- }
88
- if (normalizeCssEntriesConfig(patcherOptions.patch?.tailwindcss?.v4?.cssEntries)) {
89
- return true;
90
- }
91
- }
92
- return false;
93
- }
94
- var hasWarnedMissingCssEntries = false;
95
- function warnMissingCssEntries(ctx, patcher) {
96
- if (hasWarnedMissingCssEntries) {
97
- return;
98
- }
99
- if (patcher?.majorVersion !== 4) {
100
- return;
101
- }
102
- if (hasConfiguredCssEntries(ctx)) {
103
- return;
104
- }
105
- hasWarnedMissingCssEntries = true;
106
- logger2.warn(
107
- '[tailwindcss@4] \u672A\u68C0\u6D4B\u5230 cssEntries \u914D\u7F6E\u3002\u8BF7\u4F20\u5165\u5305\u542B tailwindcss \u5F15\u7528\u7684 CSS \u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982 cssEntries: ["/absolute/path/to/src/app.css"]\uFF0C\u5426\u5219 tailwindcss \u751F\u6210\u7684\u7C7B\u540D\u4E0D\u4F1A\u53C2\u4E0E\u8F6C\u8BD1\u3002'
108
- );
109
- }
110
- function applyV4CssCalcDefaults(cssCalc, patcher) {
111
- const cssCalcOptions = cssCalc ?? patcher?.majorVersion === 4;
112
- if (patcher?.majorVersion === 4 && cssCalcOptions) {
113
- return ensureDefaultsIncluded(cssCalcOptions);
114
- }
115
- return cssCalcOptions;
116
- }
117
-
118
- // src/tailwindcss/v4/patcher.ts
119
- import { logger as logger4 } from "@weapp-tailwindcss/logger";
120
-
121
- // src/tailwindcss/patcher.ts
122
- import path3 from "path";
123
- import process2 from "process";
124
- import { logger as logger3 } from "@weapp-tailwindcss/logger";
125
- import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
126
- import { TailwindcssPatcher } from "tailwindcss-patch";
127
-
128
- // src/context/workspace.ts
129
- import { existsSync, readdirSync, readFileSync } from "fs";
130
- import path from "path";
131
- var IGNORED_WORKSPACE_DIRS = /* @__PURE__ */ new Set([
132
- "node_modules",
133
- ".git",
134
- ".hg",
135
- ".svn",
136
- ".turbo",
137
- ".output",
138
- ".next",
139
- "dist",
140
- "build"
141
- ]);
142
- function findWorkspaceRoot(startDir) {
143
- if (!startDir) {
144
- return void 0;
145
- }
146
- let current = path.resolve(startDir);
147
- while (true) {
148
- const workspaceFile = path.join(current, "pnpm-workspace.yaml");
149
- if (existsSync(workspaceFile)) {
150
- return current;
151
- }
152
- const parent = path.dirname(current);
153
- if (parent === current) {
154
- return void 0;
155
- }
156
- current = parent;
157
- }
158
- }
159
- function findNearestPackageRoot(startDir) {
160
- if (!startDir) {
5
+ // src/tailwindcss/patcher-options.ts
6
+ function resolveTailwindcssOptions(options) {
7
+ if (!options) {
161
8
  return void 0;
162
9
  }
163
- let current = path.resolve(startDir);
164
- while (true) {
165
- const pkgPath = path.join(current, "package.json");
166
- if (existsSync(pkgPath)) {
167
- return current;
168
- }
169
- const parent = path.dirname(current);
170
- if (parent === current) {
171
- return void 0;
172
- }
173
- current = parent;
174
- }
175
- }
176
- function findWorkspacePackageDir(rootDir, packageName) {
177
- const visited = /* @__PURE__ */ new Set();
178
- const queue = [path.resolve(rootDir)];
179
- while (queue.length > 0) {
180
- const current = queue.shift();
181
- const normalized = path.normalize(current);
182
- if (visited.has(normalized)) {
183
- continue;
184
- }
185
- visited.add(normalized);
186
- try {
187
- const pkgPath = path.join(normalized, "package.json");
188
- if (existsSync(pkgPath)) {
189
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
190
- if (pkg?.name === packageName) {
191
- return normalized;
192
- }
193
- }
194
- } catch {
195
- }
196
- let entries;
197
- try {
198
- entries = readdirSync(normalized, { withFileTypes: true });
199
- } catch {
200
- continue;
201
- }
202
- for (const entry of entries) {
203
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) {
204
- continue;
205
- }
206
- queue.push(path.join(normalized, entry.name));
207
- }
208
- }
209
- return void 0;
10
+ return options.tailwindcss ?? options.tailwind;
210
11
  }
211
-
212
- // src/tailwindcss/patcher-options.ts
213
12
  function normalizeExtendLengthUnits(value) {
214
13
  if (value === false) {
215
14
  return false;
@@ -313,7 +112,7 @@ function toModernTailwindcssPatchOptions(options) {
313
112
  if (projectRoot) {
314
113
  normalized.projectRoot = projectRoot;
315
114
  }
316
- const tailwindcss = options.tailwindcss ?? options.tailwind;
115
+ const tailwindcss = resolveTailwindcssOptions(options);
317
116
  if (tailwindcss) {
318
117
  normalized.tailwindcss = {
319
118
  ...tailwindcss
@@ -360,6 +159,340 @@ function toModernTailwindcssPatchOptions(options) {
360
159
  return normalized;
361
160
  }
362
161
 
162
+ // src/tailwindcss/runtime/cache.ts
163
+ import { statSync } from "fs";
164
+ var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
165
+ var runtimeFileSignatureCache = /* @__PURE__ */ new Map();
166
+ var runtimeFileSignatureCacheClearTimer;
167
+ var runtimeSignaturePatchersSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
168
+ function getCacheEntry(twPatcher) {
169
+ let entry = runtimeClassSetCache.get(twPatcher);
170
+ if (!entry) {
171
+ entry = {};
172
+ runtimeClassSetCache.set(twPatcher, entry);
173
+ }
174
+ return entry;
175
+ }
176
+ function scheduleRuntimeConfigSignatureCacheClear() {
177
+ if (runtimeFileSignatureCacheClearTimer) {
178
+ return;
179
+ }
180
+ runtimeFileSignatureCacheClearTimer = setTimeout(() => {
181
+ runtimeFileSignatureCache.clear();
182
+ runtimeFileSignatureCacheClearTimer = void 0;
183
+ }, 0);
184
+ runtimeFileSignatureCacheClearTimer.unref?.();
185
+ }
186
+ function getFileSignature(filePath) {
187
+ const cached = runtimeFileSignatureCache.get(filePath);
188
+ if (cached !== void 0) {
189
+ return cached;
190
+ }
191
+ let signature;
192
+ try {
193
+ const stats = statSync(filePath);
194
+ signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
195
+ } catch {
196
+ signature = `${filePath}:missing`;
197
+ }
198
+ runtimeFileSignatureCache.set(filePath, signature);
199
+ scheduleRuntimeConfigSignatureCacheClear();
200
+ return signature;
201
+ }
202
+ function getTailwindTrackedFiles(twPatcher) {
203
+ const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
204
+ const tracked = /* @__PURE__ */ new Set();
205
+ const configPath = tailwindOptions?.config;
206
+ if (typeof configPath === "string" && configPath.length > 0) {
207
+ tracked.add(configPath);
208
+ }
209
+ for (const entry of tailwindOptions?.v4?.cssEntries ?? []) {
210
+ if (typeof entry === "string" && entry.length > 0) {
211
+ tracked.add(entry);
212
+ }
213
+ }
214
+ return tracked;
215
+ }
216
+ function normalizeSignatureValue(value) {
217
+ if (value == null) {
218
+ return "null";
219
+ }
220
+ if (typeof value === "string") {
221
+ return value;
222
+ }
223
+ if (typeof value === "number" || typeof value === "boolean") {
224
+ return String(value);
225
+ }
226
+ if (Array.isArray(value)) {
227
+ return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
228
+ }
229
+ if (typeof value === "object") {
230
+ const entries = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b));
231
+ return `{${entries.map(([key, item]) => `${key}:${normalizeSignatureValue(item)}`).join(",")}}`;
232
+ }
233
+ return String(value);
234
+ }
235
+ function getTailwindOptionsSignature(twPatcher) {
236
+ const options = twPatcher.options;
237
+ const tailwindOptions = resolveTailwindcssOptions(options);
238
+ return normalizeSignatureValue({
239
+ projectRoot: options?.projectRoot,
240
+ packageName: tailwindOptions?.packageName,
241
+ versionHint: tailwindOptions?.versionHint,
242
+ cwd: tailwindOptions?.cwd,
243
+ config: tailwindOptions?.config,
244
+ v2: tailwindOptions?.v2,
245
+ v3: tailwindOptions?.v3,
246
+ v4: {
247
+ base: tailwindOptions?.v4?.base,
248
+ configuredBase: tailwindOptions?.v4?.configuredBase,
249
+ css: tailwindOptions?.v4?.css,
250
+ cssEntries: tailwindOptions?.v4?.cssEntries,
251
+ hasUserDefinedSources: tailwindOptions?.v4?.hasUserDefinedSources,
252
+ sources: tailwindOptions?.v4?.sources
253
+ }
254
+ });
255
+ }
256
+ function getPatchTargetSignature(twPatcher) {
257
+ const packageInfo = twPatcher.packageInfo;
258
+ return [
259
+ packageInfo?.name ?? "missing",
260
+ packageInfo?.rootPath ?? "missing",
261
+ packageInfo?.version ?? "unknown",
262
+ twPatcher.majorVersion ?? "unknown",
263
+ getTailwindOptionsSignature(twPatcher)
264
+ ].join(":");
265
+ }
266
+ function getNestedPatchers(twPatcher) {
267
+ const nested = twPatcher[runtimeSignaturePatchersSymbol];
268
+ return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
269
+ }
270
+ function getOwnRuntimeClassSetSignature(twPatcher) {
271
+ const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
272
+ const configSignature = trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing";
273
+ const patchTargetSignature = getPatchTargetSignature(twPatcher);
274
+ return `${configSignature}|patch:${patchTargetSignature}`;
275
+ }
276
+ function invalidateRuntimeClassSet(twPatcher) {
277
+ if (!twPatcher) {
278
+ return;
279
+ }
280
+ const nestedPatchers = getNestedPatchers(twPatcher);
281
+ if (nestedPatchers) {
282
+ for (const patcher of nestedPatchers) {
283
+ invalidateRuntimeClassSet(patcher);
284
+ }
285
+ }
286
+ for (const trackedFile of getTailwindTrackedFiles(twPatcher)) {
287
+ runtimeFileSignatureCache.delete(trackedFile);
288
+ }
289
+ runtimeClassSetCache.delete(twPatcher);
290
+ }
291
+ function getRuntimeClassSetCacheEntry(twPatcher) {
292
+ return getCacheEntry(twPatcher);
293
+ }
294
+ function getRuntimeClassSetSignature(twPatcher) {
295
+ const nestedPatchers = getNestedPatchers(twPatcher);
296
+ if (nestedPatchers) {
297
+ return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
298
+ }
299
+ return getOwnRuntimeClassSetSignature(twPatcher);
300
+ }
301
+
302
+ // src/context/workspace.ts
303
+ import { existsSync, readdirSync, readFileSync } from "fs";
304
+ import path from "path";
305
+ var IGNORED_WORKSPACE_DIRS = /* @__PURE__ */ new Set([
306
+ "node_modules",
307
+ ".git",
308
+ ".hg",
309
+ ".svn",
310
+ ".turbo",
311
+ ".output",
312
+ ".next",
313
+ "dist",
314
+ "build"
315
+ ]);
316
+ function findWorkspaceRoot(startDir) {
317
+ if (!startDir) {
318
+ return void 0;
319
+ }
320
+ let current = path.resolve(startDir);
321
+ while (true) {
322
+ const workspaceFile = path.join(current, "pnpm-workspace.yaml");
323
+ if (existsSync(workspaceFile)) {
324
+ return current;
325
+ }
326
+ const parent = path.dirname(current);
327
+ if (parent === current) {
328
+ return void 0;
329
+ }
330
+ current = parent;
331
+ }
332
+ }
333
+ function findNearestPackageRoot(startDir) {
334
+ if (!startDir) {
335
+ return void 0;
336
+ }
337
+ let current = path.resolve(startDir);
338
+ while (true) {
339
+ const pkgPath = path.join(current, "package.json");
340
+ if (existsSync(pkgPath)) {
341
+ return current;
342
+ }
343
+ const parent = path.dirname(current);
344
+ if (parent === current) {
345
+ return void 0;
346
+ }
347
+ current = parent;
348
+ }
349
+ }
350
+ function findWorkspacePackageDir(rootDir, packageName) {
351
+ const visited = /* @__PURE__ */ new Set();
352
+ const queue = [path.resolve(rootDir)];
353
+ while (queue.length > 0) {
354
+ const current = queue.shift();
355
+ const normalized = path.normalize(current);
356
+ if (visited.has(normalized)) {
357
+ continue;
358
+ }
359
+ visited.add(normalized);
360
+ try {
361
+ const pkgPath = path.join(normalized, "package.json");
362
+ if (existsSync(pkgPath)) {
363
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
364
+ if (pkg?.name === packageName) {
365
+ return normalized;
366
+ }
367
+ }
368
+ } catch {
369
+ }
370
+ let entries;
371
+ try {
372
+ entries = readdirSync(normalized, { withFileTypes: true });
373
+ } catch {
374
+ continue;
375
+ }
376
+ for (const entry of entries) {
377
+ if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) {
378
+ continue;
379
+ }
380
+ queue.push(path.join(normalized, entry.name));
381
+ }
382
+ }
383
+ return void 0;
384
+ }
385
+
386
+ // src/tailwindcss/v4/config.ts
387
+ import { logger } from "@weapp-tailwindcss/logger";
388
+ var DEFAULT_CSS_CALC_CUSTOM_PROPERTIES = [];
389
+ function includesToken(list, token) {
390
+ return list.some((candidate) => {
391
+ if (typeof token === "string") {
392
+ if (typeof candidate === "string") {
393
+ return candidate === token;
394
+ }
395
+ candidate.lastIndex = 0;
396
+ return candidate.test(token);
397
+ }
398
+ if (typeof candidate === "string") {
399
+ token.lastIndex = 0;
400
+ return token.test(candidate);
401
+ }
402
+ return candidate.source === token.source && candidate.flags === token.flags;
403
+ });
404
+ }
405
+ function ensureDefaultsIncluded(value) {
406
+ if (value === true) {
407
+ return {
408
+ includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
409
+ };
410
+ }
411
+ if (Array.isArray(value)) {
412
+ if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
413
+ return value;
414
+ }
415
+ const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(value, token));
416
+ return missing.length > 0 ? [...value, ...missing] : value;
417
+ }
418
+ if (value && typeof value === "object") {
419
+ const include = value.includeCustomProperties;
420
+ if (!Array.isArray(include)) {
421
+ return {
422
+ ...value,
423
+ includeCustomProperties: [...DEFAULT_CSS_CALC_CUSTOM_PROPERTIES]
424
+ };
425
+ }
426
+ if (!DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.length) {
427
+ return value;
428
+ }
429
+ const missing = DEFAULT_CSS_CALC_CUSTOM_PROPERTIES.filter((token) => !includesToken(include, token));
430
+ return missing.length > 0 ? {
431
+ ...value,
432
+ includeCustomProperties: [...include, ...missing]
433
+ } : value;
434
+ }
435
+ return value;
436
+ }
437
+ function normalizeCssEntriesConfig(entries) {
438
+ if (!entries) {
439
+ return void 0;
440
+ }
441
+ if (typeof entries === "string") {
442
+ const trimmed = entries.trim();
443
+ return trimmed ? [trimmed] : void 0;
444
+ }
445
+ if (!Array.isArray(entries)) {
446
+ return void 0;
447
+ }
448
+ const normalized = entries.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
449
+ return normalized.length > 0 ? normalized : void 0;
450
+ }
451
+ function hasConfiguredCssEntries(ctx) {
452
+ if (normalizeCssEntriesConfig(ctx.cssEntries)) {
453
+ return true;
454
+ }
455
+ if (normalizeCssEntriesConfig(ctx.tailwindcss?.v4?.cssEntries)) {
456
+ return true;
457
+ }
458
+ const patcherOptions = ctx.tailwindcssPatcherOptions;
459
+ if (patcherOptions) {
460
+ if (normalizeCssEntriesConfig(patcherOptions.tailwindcss?.v4?.cssEntries)) {
461
+ return true;
462
+ }
463
+ if (normalizeCssEntriesConfig(patcherOptions.tailwind?.v4?.cssEntries)) {
464
+ return true;
465
+ }
466
+ if (normalizeCssEntriesConfig(patcherOptions.patch?.tailwindcss?.v4?.cssEntries)) {
467
+ return true;
468
+ }
469
+ }
470
+ return false;
471
+ }
472
+ var hasWarnedMissingCssEntries = false;
473
+ function warnMissingCssEntries(ctx, patcher) {
474
+ if (hasWarnedMissingCssEntries) {
475
+ return;
476
+ }
477
+ if (patcher?.majorVersion !== 4) {
478
+ return;
479
+ }
480
+ if (hasConfiguredCssEntries(ctx)) {
481
+ return;
482
+ }
483
+ hasWarnedMissingCssEntries = true;
484
+ logger.warn(
485
+ '[tailwindcss@4] \u672A\u68C0\u6D4B\u5230 cssEntries \u914D\u7F6E\u3002\u8BF7\u4F20\u5165\u5305\u542B tailwindcss \u5F15\u7528\u7684 CSS \u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982 cssEntries: ["/absolute/path/to/src/app.css"]\uFF0C\u5426\u5219 tailwindcss \u751F\u6210\u7684\u7C7B\u540D\u4E0D\u4F1A\u53C2\u4E0E\u8F6C\u8BD1\u3002'
486
+ );
487
+ }
488
+ function applyV4CssCalcDefaults(cssCalc, patcher) {
489
+ const cssCalcOptions = cssCalc ?? patcher?.majorVersion === 4;
490
+ if (patcher?.majorVersion === 4 && cssCalcOptions) {
491
+ return ensureDefaultsIncluded(cssCalcOptions);
492
+ }
493
+ return cssCalcOptions;
494
+ }
495
+
363
496
  // src/tailwindcss/patcher-resolve.ts
364
497
  import { existsSync as existsSync2 } from "fs";
365
498
  import { createRequire } from "module";
@@ -469,7 +602,15 @@ function createDefaultResolvePaths(basedir) {
469
602
  return [...paths];
470
603
  }
471
604
 
605
+ // src/tailwindcss/v4/patcher.ts
606
+ import { logger as logger3 } from "@weapp-tailwindcss/logger";
607
+
472
608
  // src/tailwindcss/patcher.ts
609
+ import path3 from "path";
610
+ import process2 from "process";
611
+ import { logger as logger2 } from "@weapp-tailwindcss/logger";
612
+ import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
613
+ import { TailwindcssPatcher } from "tailwindcss-patch";
473
614
  function createFallbackTailwindcssPatcher() {
474
615
  const packageInfo = {
475
616
  name: "tailwindcss",
@@ -509,6 +650,9 @@ function createFallbackTailwindcssPatcher() {
509
650
  var hasLoggedMissingTailwind = false;
510
651
  var TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
511
652
  var UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
653
+ function isTailwindcssV4PackageName(packageName) {
654
+ return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
655
+ }
512
656
  function createTailwindcssPatcher(options) {
513
657
  const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
514
658
  const cache = {
@@ -553,7 +697,7 @@ function createTailwindcssPatcher(options) {
553
697
  baseTailwindOptions.packageName = "tailwindcss";
554
698
  }
555
699
  if (!baseTailwindOptions.postcssPlugin) {
556
- baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 ? "@tailwindcss/postcss" : "tailwindcss";
700
+ baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 || isTailwindcssV4PackageName(baseTailwindOptions.packageName) ? "@tailwindcss/postcss" : "tailwindcss";
557
701
  }
558
702
  if (typeof baseTailwindOptions.postcssPlugin === "string") {
559
703
  const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
@@ -584,7 +728,7 @@ function createTailwindcssPatcher(options) {
584
728
  ...existingResolve,
585
729
  paths: [...new Set(sourcePaths)]
586
730
  };
587
- logger3.debug("Tailwind resolve config %O", {
731
+ logger2.debug("Tailwind resolve config %O", {
588
732
  packageName: resolvedTailwindOptions.packageName,
589
733
  version: resolvedTailwindOptions.version,
590
734
  resolve: resolvedTailwindOptions.resolve,
@@ -632,13 +776,13 @@ function createTailwindcssPatcher(options) {
632
776
  const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
633
777
  if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
634
778
  if (!hasLoggedMissingTailwind) {
635
- logger3.warn("Tailwind CSS \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7 Tailwind \u76F8\u5173\u8865\u4E01\u3002\u82E5\u9700\u4F7F\u7528 Tailwind \u80FD\u529B\uFF0C\u8BF7\u5B89\u88C5 tailwindcss\u3002");
779
+ logger2.warn("Tailwind CSS \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7 Tailwind \u76F8\u5173\u8865\u4E01\u3002\u82E5\u9700\u4F7F\u7528 Tailwind \u80FD\u529B\uFF0C\u8BF7\u5B89\u88C5 tailwindcss\u3002");
636
780
  hasLoggedMissingTailwind = true;
637
781
  }
638
782
  return createFallbackTailwindcssPatcher();
639
783
  }
640
784
  if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) {
641
- logger3.error('\u65E0\u6CD5\u5B9A\u4F4D Tailwind CSS \u5305 "%s"\uFF0C\u5DF2\u5C1D\u8BD5\u8DEF\u5F84: %O', resolvedOptions.tailwindcss?.packageName, searchPaths);
785
+ logger2.error('\u65E0\u6CD5\u5B9A\u4F4D Tailwind CSS \u5305 "%s"\uFF0C\u5DF2\u5C1D\u8BD5\u8DEF\u5F84: %O', resolvedOptions.tailwindcss?.packageName, searchPaths);
642
786
  }
643
787
  throw error;
644
788
  }
@@ -730,6 +874,10 @@ function createMultiTailwindcssPatcher(patchers) {
730
874
  return aggregated;
731
875
  };
732
876
  }
877
+ Object.defineProperty(multiPatcher, runtimeSignaturePatchersSymbol, {
878
+ value: [...patchers],
879
+ configurable: true
880
+ });
733
881
  return multiPatcher;
734
882
  }
735
883
 
@@ -880,6 +1028,19 @@ function groupCssEntriesByBase(entries, options = {}) {
880
1028
  }
881
1029
 
882
1030
  // src/tailwindcss/v4/patcher.ts
1031
+ var CONFIGURED_TAILWIND_VERSION_RE = /Configured tailwindcss\.version=\d+/u;
1032
+ var RESOLVED_TAILWIND_VERSION_RE = /resolved package ".+" is version /u;
1033
+ function isTailwindcss4Package(packageName) {
1034
+ return Boolean(
1035
+ packageName && (packageName === "tailwindcss4" || packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4"))
1036
+ );
1037
+ }
1038
+ function hasOwnV4Signal(value) {
1039
+ return typeof value === "object" && value !== null && "v4" in value;
1040
+ }
1041
+ function isTailwindVersionMismatchError(error) {
1042
+ return error instanceof Error && CONFIGURED_TAILWIND_VERSION_RE.test(error.message) && RESOLVED_TAILWIND_VERSION_RE.test(error.message);
1043
+ }
883
1044
  function createPatcherForBase(baseDir, cssEntries, options) {
884
1045
  const {
885
1046
  tailwindcss,
@@ -900,9 +1061,6 @@ function createPatcherForBase(baseDir, cssEntries, options) {
900
1061
  cssEntries
901
1062
  }
902
1063
  };
903
- if (hasCssEntries && (tailwindcss == null || tailwindcss.version == null)) {
904
- defaultTailwindcssConfig.version = 4;
905
- }
906
1064
  const mergedTailwindOptions = defuOverrideArray(
907
1065
  tailwindcss ?? {},
908
1066
  defaultTailwindcssConfig
@@ -933,10 +1091,8 @@ function createPatcherForBase(baseDir, cssEntries, options) {
933
1091
  );
934
1092
  const configuredPackageName = tailwindcss?.packageName || tailwindcssPatcherOptions?.tailwindcss?.packageName || tailwindcssPatcherOptions?.tailwind?.packageName || tailwindcssPatcherOptions?.patch?.tailwindcss?.packageName;
935
1093
  const configuredVersion = tailwindcss?.version || tailwindcssPatcherOptions?.tailwindcss?.version || tailwindcssPatcherOptions?.tailwind?.version || tailwindcssPatcherOptions?.patch?.tailwindcss?.version || mergedTailwindOptions.version;
936
- const isTailwindcss4Package = (packageName) => Boolean(
937
- packageName && (packageName === "tailwindcss4" || packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4"))
938
- );
939
- const isV4 = configuredVersion === 4 || mergedTailwindOptions.version === 4 || isTailwindcss4Package(configuredPackageName ?? mergedTailwindOptions.packageName);
1094
+ const hasExplicitV4Signals = hasCssEntries || hasOwnV4Signal(tailwindcss) || hasOwnV4Signal(tailwindcssPatcherOptions?.tailwindcss) || hasOwnV4Signal(tailwindcssPatcherOptions?.tailwind) || hasOwnV4Signal(tailwindcssPatcherOptions?.patch?.tailwindcss);
1095
+ const isV4 = configuredVersion === 4 || mergedTailwindOptions.version === 4 || isTailwindcss4Package(configuredPackageName ?? mergedTailwindOptions.packageName) || hasExplicitV4Signals;
940
1096
  const tailwindPackageConfigured = Boolean(configuredPackageName);
941
1097
  const shouldPatchV4PostcssPackage = isV4 && !tailwindPackageConfigured;
942
1098
  const packageCandidates = /* @__PURE__ */ new Set();
@@ -946,25 +1102,40 @@ function createPatcherForBase(baseDir, cssEntries, options) {
946
1102
  packageCandidates.add(
947
1103
  mergedTailwindOptions.packageName ?? configuredPackageName ?? "tailwindcss"
948
1104
  );
949
- const patchers = Array.from(packageCandidates, (packageName) => {
1105
+ const patchers = [];
1106
+ const packageCandidateList = [...packageCandidates];
1107
+ let firstVersionMismatchError;
1108
+ for (const packageName of packageCandidateList) {
950
1109
  const tailwindOptionsForPackage = {
951
1110
  ...mergedTailwindOptions,
952
1111
  packageName
953
1112
  };
954
- return createTailwindcssPatcher({
955
- basedir: baseDir,
956
- supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
957
- tailwindcss: tailwindOptionsForPackage,
958
- tailwindcssPatcherOptions: patchedOptions
959
- });
960
- });
1113
+ try {
1114
+ patchers.push(createTailwindcssPatcher({
1115
+ basedir: baseDir,
1116
+ supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
1117
+ tailwindcss: tailwindOptionsForPackage,
1118
+ tailwindcssPatcherOptions: patchedOptions
1119
+ }));
1120
+ } catch (error) {
1121
+ if (packageCandidateList.length > 1 && isTailwindVersionMismatchError(error)) {
1122
+ firstVersionMismatchError ?? (firstVersionMismatchError = error);
1123
+ logger3.warn('skip incompatible Tailwind package candidate "%s" for v4 patcher: %s', packageName, error.message);
1124
+ continue;
1125
+ }
1126
+ throw error;
1127
+ }
1128
+ }
1129
+ if (patchers.length === 0 && firstVersionMismatchError) {
1130
+ throw firstVersionMismatchError;
1131
+ }
961
1132
  return patchers.length === 1 ? patchers[0] : createMultiTailwindcssPatcher(patchers);
962
1133
  }
963
1134
  function tryCreateMultiTailwindcssPatcher(groups, options) {
964
1135
  if (groups.size <= 1) {
965
1136
  return void 0;
966
1137
  }
967
- logger4.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
1138
+ logger3.debug("detected multiple Tailwind CSS entry bases: %O", [...groups.keys()]);
968
1139
  const patchers = [];
969
1140
  for (const [baseDir, entries] of groups) {
970
1141
  patchers.push(createPatcherForBase(baseDir, entries, options));
@@ -977,7 +1148,7 @@ import { createRequire as createRequire2 } from "module";
977
1148
  import path5 from "path";
978
1149
  import process3 from "process";
979
1150
  import { fileURLToPath as fileURLToPath2 } from "url";
980
- import { logger as logger5 } from "@weapp-tailwindcss/logger";
1151
+ import { logger as logger4 } from "@weapp-tailwindcss/logger";
981
1152
  var ENV_BASEDIR_KEYS = [
982
1153
  "WEAPP_TAILWINDCSS_BASEDIR",
983
1154
  "WEAPP_TAILWINDCSS_BASE_DIR",
@@ -1022,7 +1193,7 @@ function detectCallerBasedir() {
1022
1193
  return void 0;
1023
1194
  }
1024
1195
  if (process3.env.WEAPP_TW_DEBUG_STACK === "1") {
1025
- logger5.debug("caller stack: %s", stack);
1196
+ logger4.debug("caller stack: %s", stack);
1026
1197
  }
1027
1198
  const lines = stack.split("\n");
1028
1199
  for (const line of lines) {
@@ -1067,7 +1238,7 @@ function resolveTailwindcssBasedir(basedir, fallback) {
1067
1238
  const anchor = envBasedir ?? packageEnvBasedir ?? fallback ?? callerBasedir ?? cwd;
1068
1239
  const resolveRelative = (value) => path5.isAbsolute(value) ? path5.normalize(value) : path5.normalize(path5.resolve(anchor, value));
1069
1240
  if (process3.env.WEAPP_TW_DEBUG_STACK === "1") {
1070
- logger5.debug("resolveTailwindcssBasedir anchor %O", {
1241
+ logger4.debug("resolveTailwindcssBasedir anchor %O", {
1071
1242
  basedir,
1072
1243
  envBasedir,
1073
1244
  envBasedirKey,
@@ -1105,12 +1276,12 @@ function resolveTailwindcssBasedir(basedir, fallback) {
1105
1276
  const anchorRequire = createRequire2(path5.join(anchor, "__resolve_tailwindcss_basedir__.cjs"));
1106
1277
  const packageJsonPath = anchorRequire.resolve(`${packageName}/package.json`);
1107
1278
  if (process3.env.WEAPP_TW_DEBUG_STACK === "1") {
1108
- logger5.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
1279
+ logger4.debug("package basedir resolved from PNPM_PACKAGE_NAME: %s", packageJsonPath);
1109
1280
  }
1110
1281
  return path5.normalize(path5.dirname(packageJsonPath));
1111
1282
  } catch {
1112
1283
  if (process3.env.WEAPP_TW_DEBUG_STACK === "1") {
1113
- logger5.debug("failed to resolve package json for %s", packageName);
1284
+ logger4.debug("failed to resolve package json for %s", packageName);
1114
1285
  }
1115
1286
  const workspaceRoot = findWorkspaceRoot(anchor);
1116
1287
  if (workspaceRoot) {
@@ -1128,7 +1299,7 @@ function resolveTailwindcssBasedir(basedir, fallback) {
1128
1299
  }
1129
1300
 
1130
1301
  // src/context/tailwindcss.ts
1131
- import { logger as logger6 } from "@weapp-tailwindcss/logger";
1302
+ import { logger as logger5 } from "@weapp-tailwindcss/logger";
1132
1303
 
1133
1304
  // src/context/tailwindcss/rax.ts
1134
1305
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
@@ -1208,7 +1379,7 @@ function createTailwindcssPatcherFromContext(ctx) {
1208
1379
  const absoluteCssEntryBasedir = guessBasedirFromEntries(rawCssEntries);
1209
1380
  const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir, absoluteCssEntryBasedir);
1210
1381
  ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
1211
- logger6.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
1382
+ logger5.debug("tailwindcss basedir resolved: %s", resolvedTailwindcssBasedir);
1212
1383
  let normalizedCssEntries = normalizeCssEntries(rawCssEntries, resolvedTailwindcssBasedir);
1213
1384
  if (!normalizedCssEntries) {
1214
1385
  normalizedCssEntries = detectImplicitCssEntries(ctx.appType, resolvedTailwindcssBasedir);
@@ -1254,12 +1425,19 @@ function createTailwindcssPatcherFromContext(ctx) {
1254
1425
  );
1255
1426
  }
1256
1427
 
1428
+ // src/logger/index.ts
1429
+ import { logger as logger6 } from "@weapp-tailwindcss/logger";
1430
+
1257
1431
  export {
1258
- findWorkspaceRoot,
1432
+ resolveTailwindcssOptions,
1433
+ invalidateRuntimeClassSet,
1434
+ getRuntimeClassSetCacheEntry,
1435
+ getRuntimeClassSetSignature,
1259
1436
  findNearestPackageRoot,
1260
1437
  warnMissingCssEntries,
1261
1438
  applyV4CssCalcDefaults,
1439
+ findTailwindConfig,
1262
1440
  resolveTailwindcssBasedir,
1263
1441
  createTailwindcssPatcherFromContext,
1264
- logger
1442
+ logger6 as logger
1265
1443
  };