weapp-tailwindcss 5.0.13 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/auto-Ba6hDrse.mjs +13 -0
  4. package/dist/auto-DtU6f3X6.js +18 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
  7. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +21 -9
  8. package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
  9. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
  11. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
  12. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
  14. package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
  15. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
  16. package/dist/bundlers/shared/run-tasks.d.ts +1 -0
  17. package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
  18. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  19. package/dist/bundlers/vite/css-memory.d.ts +10 -0
  20. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
  21. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
  23. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +0 -1
  24. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
  25. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -0
  26. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
  27. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
  28. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
  29. package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -1
  30. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
  31. package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
  32. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
  33. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
  34. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  35. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
  36. package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
  37. package/dist/bundlers/vite/source-candidates.d.ts +9 -2
  38. package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
  39. package/dist/bundlers/vite/source-scan.d.ts +2 -2
  40. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
  41. package/dist/bundlers/vite/utils.d.ts +1 -0
  42. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
  43. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
  44. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
  45. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
  46. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
  47. package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
  48. package/dist/cache/index.d.ts +1 -0
  49. package/dist/cli/mount-options.d.ts +2 -2
  50. package/dist/cli.js +124 -437
  51. package/dist/cli.mjs +120 -433
  52. package/dist/context/index.d.ts +3 -3
  53. package/dist/context/style-options.d.ts +4 -1
  54. package/dist/context/tailwindcss.d.ts +1 -1
  55. package/dist/{precheck-B0Z8yW7E.js → context-BHxLe743.js} +391 -153
  56. package/dist/{precheck-CRI90iL1.mjs → context-Mbzkek1q.mjs} +368 -137
  57. package/dist/core.js +15 -12
  58. package/dist/core.mjs +10 -7
  59. package/dist/css-macro.js +1 -1
  60. package/dist/css-macro.mjs +1 -1
  61. package/dist/{defaults-C_J_kBpw.js → defaults-CVcKbXBG.js} +4 -15
  62. package/dist/{defaults-Bqx18S1f.mjs → defaults-ZElj1zKc.mjs} +5 -10
  63. package/dist/defaults.d.ts +1 -7
  64. package/dist/defaults.js +1 -2
  65. package/dist/defaults.mjs +2 -2
  66. package/dist/generator/index.d.ts +6 -7
  67. package/dist/generator/options.d.ts +3 -3
  68. package/dist/generator/types.d.ts +9 -10
  69. package/dist/generator-9rUz4Hcb.js +170 -0
  70. package/dist/generator-Dc4qaPmT.mjs +123 -0
  71. package/dist/generator.js +10 -16
  72. package/dist/generator.mjs +3 -3
  73. package/dist/{gulp-XT8Jc7lH.js → gulp-B_sdP6dx.js} +47 -87
  74. package/dist/{gulp-DfOQERcV.mjs → gulp-uM36oIJs.mjs} +40 -80
  75. package/dist/gulp.js +1 -1
  76. package/dist/gulp.mjs +1 -1
  77. package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-BXMLsF4b.mjs} +1145 -842
  78. package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CogqkFaF.js} +1262 -881
  79. package/dist/index.js +4 -4
  80. package/dist/index.mjs +4 -4
  81. package/dist/js/fast-path/oxc.d.ts +4 -0
  82. package/dist/js/precheck.d.ts +1 -0
  83. package/dist/postcss.js +3 -4
  84. package/dist/postcss.mjs +2 -3
  85. package/dist/presets.js +9 -19
  86. package/dist/presets.mjs +8 -18
  87. package/dist/runtime-branch/create-branch.d.ts +2 -0
  88. package/dist/runtime-branch/generator-target-env.d.ts +4 -0
  89. package/dist/runtime-branch/index.d.ts +6 -0
  90. package/dist/runtime-branch/mini-program.d.ts +2 -0
  91. package/dist/runtime-branch/native-app.d.ts +2 -0
  92. package/dist/runtime-branch/platform.d.ts +6 -0
  93. package/dist/runtime-branch/tailwind-version.d.ts +2 -0
  94. package/dist/runtime-branch/types.d.ts +37 -0
  95. package/dist/runtime-branch/web.d.ts +2 -0
  96. package/dist/runtime-branch.d.ts +1 -0
  97. package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-2ybpptAK.js} +261 -19
  98. package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
  99. package/dist/tailwindcss/candidates.d.ts +7 -0
  100. package/dist/tailwindcss/index.d.ts +2 -2
  101. package/dist/tailwindcss/runtime/cache.d.ts +6 -6
  102. package/dist/tailwindcss/runtime-factory.d.ts +12 -0
  103. package/dist/tailwindcss/runtime-options.d.ts +8 -0
  104. package/dist/tailwindcss/runtime-types.d.ts +86 -0
  105. package/dist/tailwindcss/runtime.d.ts +6 -6
  106. package/dist/tailwindcss/source-scan.d.ts +1 -1
  107. package/dist/tailwindcss/targets.d.ts +2 -2
  108. package/dist/tailwindcss/v4/config.d.ts +3 -3
  109. package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
  110. package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
  111. package/dist/tailwindcss/v4/index.d.ts +1 -1
  112. package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
  113. package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
  114. package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
  115. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  116. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
  117. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
  118. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
  119. package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
  120. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  121. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
  122. package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
  123. package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
  124. package/dist/tailwindcss/version.d.ts +1 -1
  125. package/dist/tailwindcss-DHIYcqXT.js +1523 -0
  126. package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
  127. package/dist/{transform-YmrmxuF3.js → transform-CQVOgmzM.js} +17 -17
  128. package/dist/{transform-DfcEjsZF.mjs → transform-tExdt40m.mjs} +2 -2
  129. package/dist/typedoc.export.d.ts +1 -1
  130. package/dist/types/index.d.ts +16 -17
  131. package/dist/types/shared.d.ts +1 -1
  132. package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
  133. package/dist/types/user-defined-options/general.d.ts +5 -3
  134. package/dist/types/user-defined-options/important.d.ts +2 -2
  135. package/dist/uni-app-x/style-asset.d.ts +1 -0
  136. package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
  137. package/dist/v4-engine-D4ubP7N5.js +2778 -0
  138. package/dist/{vite-CXHVsHmX.js → vite-CP0ylSxZ.js} +1081 -542
  139. package/dist/{vite-DjI09vVN.mjs → vite-CPO83EhA.mjs} +916 -376
  140. package/dist/vite.js +1 -1
  141. package/dist/vite.mjs +1 -1
  142. package/dist/weapp-tw-css-import-rewrite-loader.js +5350 -4165
  143. package/dist/weapp-tw-runtime-classset-loader.js +15 -4
  144. package/dist/webpack-Bsek8VhR.js +2094 -0
  145. package/dist/webpack-BzqhJ8yK.mjs +2082 -0
  146. package/dist/webpack.js +1 -1
  147. package/dist/webpack.mjs +1 -1
  148. package/package.json +4 -5
  149. package/dist/auto-CTp6wE5a.js +0 -33
  150. package/dist/auto-Cl8_hsG6.mjs +0 -22
  151. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
  152. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
  153. package/dist/context/tailwindcss/rax.d.ts +0 -2
  154. package/dist/generator-CzpArpCL.js +0 -92
  155. package/dist/generator-ITLd7PTl.mjs +0 -67
  156. package/dist/tailwindcss/patcher-options.d.ts +0 -8
  157. package/dist/tailwindcss/patcher.d.ts +0 -12
  158. package/dist/tailwindcss/runtime-patch.d.ts +0 -5
  159. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
  160. package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
  161. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
  162. package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
  163. package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
  164. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
  165. package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
  166. package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
  167. package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
  168. package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
  169. package/dist/tailwindcss/v4/patcher.d.ts +0 -15
  170. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
  171. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
  172. package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
  173. package/dist/tailwindcss-DZEwT3C_.js +0 -613
  174. package/dist/v3-engine-2rrgylhn.js +0 -4686
  175. package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
  176. package/dist/webpack-BcPpnT90.mjs +0 -1184
  177. package/dist/webpack-CfkUkMXG.js +0 -1196
  178. /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
@@ -1,17 +1,20 @@
1
- import { C as resolveTailwindV4SourceFromPatcher, J as createTailwindV4Engine$1, c as ensureTailwindcssRuntimePatch, d as getRuntimeClassSetSignatureWithSources, f as invalidateRuntimeClassSet, ft as resolveBooleanObjectOption, gt as omitUndefined, l as getRuntimeClassSetCacheEntry, ot as createDebug } from "./v3-engine-C6eJ0YzK.mjs";
2
- import { a as resolveDefaultCssPreflight, i as getDefaultOptions, o as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, s as HARD_PARSE_CACHE_MAX_ENTRIES } from "./defaults-Bqx18S1f.mjs";
1
+ import { G as createTailwindV4Engine$1, ct as omitUndefined, n as resolveTailwindV4SourceFromRuntime, y as resolveBooleanObjectOption } from "./v4-engine-CF9zt4Cw.mjs";
2
+ import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Dc4qaPmT.mjs";
3
3
  import { i as isMap, n as defuOverrideArray } from "./utils-DodxWHGz.mjs";
4
- import { i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssPatcherFromContext } from "./tailwindcss-DTq3uYBK.mjs";
4
+ import { a as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, i as resolveDefaultCssPreflight, o as HARD_PARSE_CACHE_MAX_ENTRIES, r as getDefaultOptions } from "./defaults-ZElj1zKc.mjs";
5
+ import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-wyUHrfil.mjs";
6
+ import { createRequire } from "node:module";
5
7
  import path from "node:path";
6
8
  import process from "node:process";
9
+ import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
7
10
  import { createStyleHandler } from "@weapp-tailwindcss/postcss";
8
11
  import { LRUCache } from "lru-cache";
9
- import { splitCandidateTokens } from "tailwindcss-patch";
10
- import { logger, pc } from "@weapp-tailwindcss/logger";
11
12
  import { rm } from "node:fs/promises";
12
13
  import { Buffer } from "node:buffer";
14
+ import { logger, pc } from "@weapp-tailwindcss/logger";
13
15
  import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
14
16
  import { MappingChars2String, escape } from "@weapp-core/escape";
17
+ import _createDebug from "debug";
15
18
  import _babelTraverse from "@babel/traverse";
16
19
  import { parse, parseExpression } from "@babel/parser";
17
20
  import MagicString from "magic-string";
@@ -62,15 +65,16 @@ function createCache(options) {
62
65
  });
63
66
  return cache;
64
67
  },
68
+ pruneHashKeys(hashKeys) {
69
+ const activeHashKeys = new Set(hashKeys);
70
+ for (const key of hashMap.keys()) if (!activeHashKeys.has(key)) hashMap.delete(key);
71
+ },
65
72
  prune(options) {
66
73
  if (options.cacheKeys) {
67
74
  const cacheKeys = new Set(options.cacheKeys);
68
75
  for (const key of instance.keys()) if (!cacheKeys.has(key)) instance.delete(key);
69
76
  }
70
- if (options.hashKeys) {
71
- const hashKeys = new Set(options.hashKeys);
72
- for (const key of hashMap.keys()) if (!hashKeys.has(key)) hashMap.delete(key);
73
- }
77
+ if (options.hashKeys) cache.pruneHashKeys?.(options.hashKeys);
74
78
  },
75
79
  has(key) {
76
80
  return instance.has(key);
@@ -109,13 +113,28 @@ function initializeCache(cacheConfig) {
109
113
  return cacheConfig;
110
114
  }
111
115
  //#endregion
116
+ //#region src/debug/index.ts
117
+ const _debug = _createDebug("weapp-tw");
118
+ function createDebug(prefix) {
119
+ const debug = ((formatter, ...args) => {
120
+ return _debug((prefix ?? "") + formatter, ...args);
121
+ });
122
+ Object.defineProperty(debug, "enabled", {
123
+ enumerable: false,
124
+ configurable: false,
125
+ get() {
126
+ return _debug.enabled;
127
+ }
128
+ });
129
+ return debug;
130
+ }
131
+ //#endregion
112
132
  //#region src/tailwindcss/runtime.ts
113
133
  const debug$1 = createDebug("[tailwindcss:runtime] ");
114
- const refreshTailwindcssPatcherSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
115
- function createTailwindRuntimeReadyPromise(twPatcher) {
134
+ const refreshTailwindcssRuntimeSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssRuntime");
135
+ function createTailwindRuntimeReadyPromise(tailwindRuntime) {
116
136
  return Promise.resolve().then(async () => {
117
- await ensureTailwindcssRuntimePatch(twPatcher);
118
- invalidateRuntimeClassSet(twPatcher);
137
+ invalidateRuntimeClassSet(tailwindRuntime);
119
138
  });
120
139
  }
121
140
  const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
@@ -127,21 +146,31 @@ function getRuntimeClassSetStateEntry(state) {
127
146
  }
128
147
  return entry;
129
148
  }
149
+ function getTailwindRuntime(state) {
150
+ return state.tailwindRuntime;
151
+ }
152
+ function setTailwindRuntime(state, runtime) {
153
+ state.tailwindRuntime = runtime;
154
+ }
155
+ function getRefreshTailwindRuntime(state) {
156
+ return state.refreshTailwindcssRuntime;
157
+ }
130
158
  async function refreshTailwindRuntimeState(state, forceOrOptions) {
131
159
  const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
132
160
  const force = normalizedOptions.force;
133
161
  const clearCache = normalizedOptions.clearCache === true;
134
162
  if (!force) return false;
135
- debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, state.twPatcher.majorVersion ?? "unknown");
163
+ debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, getTailwindRuntime(state).majorVersion ?? "unknown");
136
164
  await state.readyPromise;
137
165
  let refreshed = false;
138
- if (typeof state.refreshTailwindcssPatcher === "function") {
139
- const next = await state.refreshTailwindcssPatcher({ clearCache });
140
- if (next !== state.twPatcher) state.twPatcher = next;
166
+ const refreshTailwindRuntime = getRefreshTailwindRuntime(state);
167
+ if (typeof refreshTailwindRuntime === "function") {
168
+ const next = await refreshTailwindRuntime({ clearCache });
169
+ if (next !== getTailwindRuntime(state)) setTailwindRuntime(state, next);
141
170
  refreshed = true;
142
171
  }
143
- if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(state.twPatcher);
144
- debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, state.twPatcher.majorVersion ?? "unknown");
172
+ if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(getTailwindRuntime(state));
173
+ debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, getTailwindRuntime(state).majorVersion ?? "unknown");
145
174
  return refreshed;
146
175
  }
147
176
  async function ensureRuntimeClassSet(state, options = {}) {
@@ -155,7 +184,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
155
184
  });
156
185
  await state.readyPromise;
157
186
  const entry = getRuntimeClassSetStateEntry(state);
158
- const signature = await getRuntimeClassSetSignatureWithSources(state.twPatcher);
187
+ const signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
159
188
  const signatureChanged = entry.signature !== signature;
160
189
  const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
161
190
  if (!shouldForceCollect) {
@@ -163,7 +192,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
163
192
  if (entry.promise) return entry.promise;
164
193
  }
165
194
  const task = (async () => {
166
- const collected = await collectRuntimeClassSet(state.twPatcher, {
195
+ const collected = await collectRuntimeClassSet(getTailwindRuntime(state), {
167
196
  force: shouldForceCollect,
168
197
  skipRefresh: true,
169
198
  clearCache
@@ -174,7 +203,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
174
203
  clearCache: true
175
204
  });
176
205
  await state.readyPromise;
177
- return collectRuntimeClassSet(state.twPatcher, {
206
+ return collectRuntimeClassSet(getTailwindRuntime(state), {
178
207
  force: true,
179
208
  skipRefresh: true,
180
209
  clearCache: true
@@ -184,36 +213,29 @@ async function ensureRuntimeClassSet(state, options = {}) {
184
213
  try {
185
214
  const runtimeSet = await task;
186
215
  entry.value = runtimeSet;
187
- entry.signature = await getRuntimeClassSetSignatureWithSources(state.twPatcher);
216
+ entry.signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
188
217
  return runtimeSet;
189
218
  } finally {
190
219
  if (entry.promise === task) entry.promise = void 0;
191
220
  }
192
221
  }
193
- function shouldPreferSync(majorVersion) {
194
- if (majorVersion == null) return true;
195
- if (majorVersion === 3) return true;
196
- if (majorVersion === 4) return true;
197
- return false;
198
- }
199
- function tryGetRuntimeClassSetSync(twPatcher) {
200
- if (typeof twPatcher.getClassSetSync !== "function") return;
201
- if (!shouldPreferSync(twPatcher.majorVersion)) return;
222
+ function tryGetRuntimeClassSetSync(tailwindRuntime) {
223
+ if (typeof tailwindRuntime.getClassSetSync !== "function") return;
202
224
  try {
203
- const set = twPatcher.getClassSetSync();
225
+ const set = tailwindRuntime.getClassSetSync();
204
226
  if (set && set.size === 0) return;
205
227
  return set;
206
228
  } catch (error) {
207
- if (twPatcher.majorVersion === 4) debug$1("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
208
- else debug$1("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
229
+ debug$1("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
209
230
  return;
210
231
  }
211
232
  }
212
- async function collectTailwindV4GeneratorClassSet(twPatcher) {
233
+ async function collectTailwindV4GeneratorClassSet(tailwindRuntime) {
234
+ if (typeof tailwindRuntime.collectContentTokens !== "function") return;
213
235
  try {
214
- const generated = await createTailwindV4Engine$1(await resolveTailwindV4SourceFromPatcher(twPatcher)).generate({
236
+ const generated = await createTailwindV4Engine$1(await resolveTailwindV4SourceFromRuntime(tailwindRuntime)).generate({
215
237
  scanSources: true,
216
- target: "tailwind"
238
+ target: "web"
217
239
  });
218
240
  debug$1("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
219
241
  return generated.classSet;
@@ -222,74 +244,53 @@ async function collectTailwindV4GeneratorClassSet(twPatcher) {
222
244
  return;
223
245
  }
224
246
  }
225
- async function mergeTailwindV4GeneratorClassSet(twPatcher, classSet) {
226
- if (twPatcher.majorVersion !== 4) return classSet;
227
- const generatorClassSet = await collectTailwindV4GeneratorClassSet(twPatcher);
247
+ async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
248
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
228
249
  if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
229
250
  return new Set([...classSet, ...generatorClassSet]);
230
251
  }
231
- function canReturnExtractClassSetImmediately(twPatcher) {
232
- return twPatcher.majorVersion !== 4;
233
- }
234
- async function collectRuntimeClassSet(twPatcher, options = {}) {
235
- let activePatcher = twPatcher;
252
+ async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
253
+ let activeRuntime = tailwindRuntime;
236
254
  if (options.force && !options.skipRefresh) {
237
- const refresh = activePatcher[refreshTailwindcssPatcherSymbol];
255
+ const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
238
256
  if (typeof refresh === "function") try {
239
257
  const refreshed = await refresh({ clearCache: options.clearCache === true });
240
- if (refreshed) activePatcher = refreshed;
258
+ if (refreshed) activeRuntime = refreshed;
241
259
  } catch (error) {
242
- debug$1("refreshTailwindcssPatcher failed, continuing with existing patcher: %O", error);
260
+ debug$1("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
243
261
  }
244
262
  }
245
- const entry = getRuntimeClassSetCacheEntry(activePatcher);
246
- const signature = await getRuntimeClassSetSignatureWithSources(activePatcher);
263
+ const entry = getRuntimeClassSetCacheEntry(activeRuntime);
264
+ const signature = await getRuntimeClassSetSignatureWithSources(activeRuntime);
247
265
  if (!options.force) {
248
266
  if (entry.value && entry.signature === signature) return entry.value;
249
267
  if (entry.promise) return entry.promise;
250
268
  } else entry.value = void 0;
251
269
  const task = (async () => {
252
- await ensureTailwindcssRuntimePatch(activePatcher);
253
- const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
254
- if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
255
270
  const preferExtract = options.force === true;
256
271
  try {
257
- const result = await activePatcher.extract({ write: false });
272
+ const result = await activeRuntime.extract({ write: false });
258
273
  if (result?.classSet) {
259
274
  if (result.classSet.size > 0) {
260
- if (canReturnExtractClassSetImmediately(activePatcher)) {
261
- debug$1("runtime class set resolved via extract(), size=%d", result.classSet.size);
262
- return result.classSet;
263
- }
264
- const merged = await mergeTailwindV4GeneratorClassSet(activePatcher, result.classSet);
275
+ const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
265
276
  debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
266
277
  return merged;
267
278
  }
268
- if (preferExtract && activePatcher.majorVersion !== 4) {
269
- debug$1("runtime class set resolved via empty extract() on force collect, size=0");
270
- return result.classSet;
271
- }
272
279
  if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
273
280
  else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
274
281
  }
275
282
  } catch (error) {
276
283
  debug$1("extract() failed, fallback to getClassSet(): %O", error);
277
284
  }
278
- if (activePatcher.majorVersion === 4) {
279
- const generatorClassSet = await collectTailwindV4GeneratorClassSet(activePatcher);
280
- if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
281
- }
282
- if (preExtractSyncSet) {
283
- debug$1("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
284
- return preExtractSyncSet;
285
- }
286
- const syncSet = tryGetRuntimeClassSetSync(activePatcher);
285
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
286
+ if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
287
+ const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
287
288
  if (syncSet) {
288
289
  debug$1("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
289
290
  return syncSet;
290
291
  }
291
292
  try {
292
- const fallbackSet = await Promise.resolve(activePatcher.getClassSet());
293
+ const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
293
294
  if (fallbackSet) {
294
295
  debug$1("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
295
296
  return fallbackSet;
@@ -354,8 +355,8 @@ function formatRelativeToBase(targetPath, baseDir) {
354
355
  if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
355
356
  return path.join(".", relative).replace(/\\/g, "/");
356
357
  }
357
- function logTailwindcssTarget(patcher, baseDir) {
358
- const packageInfo = patcher?.packageInfo;
358
+ function logTailwindcssTarget(tailwindRuntime, baseDir) {
359
+ const packageInfo = tailwindRuntime?.packageInfo;
359
360
  const label = "Weapp-tailwindcss";
360
361
  if (!packageInfo?.rootPath) {
361
362
  logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
@@ -388,10 +389,28 @@ function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
388
389
  const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
389
390
  const AT_LOCATION_RE = /at\s+(\S.*)$/u;
390
391
  const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
392
+ const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
393
+ const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
391
394
  const globalCacheHolder = globalThis;
392
395
  const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
393
396
  const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
394
397
  const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
398
+ function resolveCompilerContextCacheMax(defaultValue) {
399
+ const raw = Number.parseInt(process.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
400
+ if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
401
+ return Math.floor(raw);
402
+ }
403
+ function touchMapValue(map, key, value) {
404
+ map.delete(key);
405
+ map.set(key, value);
406
+ }
407
+ function pruneMapToMaxSize(map, maxSize) {
408
+ while (map.size > maxSize) {
409
+ const firstKey = map.keys().next().value;
410
+ if (firstKey === void 0) break;
411
+ map.delete(firstKey);
412
+ }
413
+ }
395
414
  function withCircularGuard(value, stack, factory) {
396
415
  if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
397
416
  stack.add(value);
@@ -561,7 +580,8 @@ function createCompilerContextCacheKey(opts) {
561
580
  const cached = keyStore.get(runtimeCacheScopeKey);
562
581
  if (cached !== void 0) return cached;
563
582
  const cacheKey = md5Hash(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
564
- keyStore.set(runtimeCacheScopeKey, cacheKey);
583
+ touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
584
+ pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
565
585
  return cacheKey;
566
586
  } catch (error) {
567
587
  logger.debug("skip compiler context cache: %O", error);
@@ -572,10 +592,16 @@ function withCompilerContextCache(opts, factory) {
572
592
  const cacheKey = createCompilerContextCacheKey(opts);
573
593
  if (cacheKey) {
574
594
  const cached = compilerContextCache.get(cacheKey);
575
- if (cached) return cached;
595
+ if (cached) {
596
+ touchMapValue(compilerContextCache, cacheKey, cached);
597
+ return cached;
598
+ }
576
599
  }
577
600
  const ctx = factory();
578
- if (cacheKey) compilerContextCache.set(cacheKey, ctx);
601
+ if (cacheKey) {
602
+ touchMapValue(compilerContextCache, cacheKey, ctx);
603
+ pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
604
+ }
579
605
  return ctx;
580
606
  }
581
607
  //#endregion
@@ -939,6 +965,19 @@ function hasIgnoreComment(node) {
939
965
  }
940
966
  return false;
941
967
  }
968
+ function isConditionTestLiteral(path) {
969
+ let current = path;
970
+ while (current?.parentPath) {
971
+ const parent = current.parentPath;
972
+ if (parent.isConditionalExpression()) return parent.node.test === current.node;
973
+ if (parent.isBinaryExpression() || parent.isCallExpression() || parent.isLogicalExpression() || parent.isMemberExpression() || parent.isUnaryExpression()) {
974
+ current = parent;
975
+ continue;
976
+ }
977
+ return false;
978
+ }
979
+ return false;
980
+ }
942
981
  function extractLiteralValue(path, { unescapeUnicode }) {
943
982
  const { node } = path;
944
983
  let offset = 0;
@@ -1004,6 +1043,7 @@ function replaceHandleValue(path, options) {
1004
1043
  const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
1005
1044
  if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) return;
1006
1045
  if (hasIgnoreComment(path.node)) return;
1046
+ if (isConditionTestLiteral(path)) return;
1007
1047
  const { literal, original, offset } = extractLiteralValue(path, options);
1008
1048
  const candidates = splitCandidateTokens(literal);
1009
1049
  if (candidates.length === 0) return;
@@ -2019,6 +2059,198 @@ function jsHandler(rawSource, options) {
2019
2059
  }
2020
2060
  defaultEvalHandler = jsHandler;
2021
2061
  //#endregion
2062
+ //#region src/js/literal-transform.ts
2063
+ function transformLiteralText(literal, options) {
2064
+ const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
2065
+ if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
2066
+ const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
2067
+ const candidates = splitCandidateTokens(source);
2068
+ if (candidates.length === 0) return;
2069
+ const transformOptions = {
2070
+ ...options,
2071
+ classContext: true
2072
+ };
2073
+ const replacementCache = getReplacementCacheStore(options.escapeMap);
2074
+ let transformed = source;
2075
+ let mutated = false;
2076
+ for (const candidate of candidates) {
2077
+ const result = resolveClassNameTransformWithResult(candidate, transformOptions);
2078
+ if (result.decision === "skip" || !transformed.includes(candidate)) continue;
2079
+ const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
2080
+ const replaced = transformed.replace(candidate, replacement);
2081
+ if (replaced !== transformed) {
2082
+ transformed = replaced;
2083
+ mutated = true;
2084
+ }
2085
+ }
2086
+ return mutated ? transformed : void 0;
2087
+ }
2088
+ //#endregion
2089
+ //#region src/js/fast-path/oxc.ts
2090
+ const require = createRequire(import.meta.url);
2091
+ let oxcParser;
2092
+ let oxcWalker;
2093
+ function isOxcParserRuntimeSupported(version = process.versions.node) {
2094
+ const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
2095
+ if (!match) return false;
2096
+ const major = Number(match[1]);
2097
+ const minor = Number(match[2]);
2098
+ if (major === 20) return minor >= 19;
2099
+ if (major === 21) return false;
2100
+ if (major === 22) return minor >= 12;
2101
+ return major > 22;
2102
+ }
2103
+ function loadOxcParser() {
2104
+ if (!isOxcParserRuntimeSupported()) return;
2105
+ if (oxcParser === false) return;
2106
+ if (oxcParser) return oxcParser;
2107
+ try {
2108
+ oxcParser = require("oxc-parser");
2109
+ } catch {
2110
+ oxcParser = false;
2111
+ return;
2112
+ }
2113
+ return oxcParser;
2114
+ }
2115
+ function loadOxcWalker() {
2116
+ if (!isOxcParserRuntimeSupported()) return;
2117
+ if (oxcWalker === false) return;
2118
+ if (oxcWalker) return oxcWalker;
2119
+ try {
2120
+ oxcWalker = require("oxc-walker");
2121
+ } catch {
2122
+ oxcWalker = false;
2123
+ return;
2124
+ }
2125
+ return oxcWalker;
2126
+ }
2127
+ function hasValues(values) {
2128
+ return Array.isArray(values) && values.length > 0;
2129
+ }
2130
+ function hasUnsupportedSourceMarker(rawSource) {
2131
+ return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
2132
+ }
2133
+ function hasSupportedClassMatchSource(options) {
2134
+ return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
2135
+ }
2136
+ function canUseOxcJsFastPath(options) {
2137
+ if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
2138
+ return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
2139
+ }
2140
+ function getParserLang(filename) {
2141
+ if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
2142
+ if (filename?.endsWith(".tsx")) return "tsx";
2143
+ if (filename?.endsWith(".jsx")) return "jsx";
2144
+ return "js";
2145
+ }
2146
+ function getParserSourceType(sourceType) {
2147
+ return sourceType === "script" || sourceType === "module" ? sourceType : "module";
2148
+ }
2149
+ function isRangeValid(start, end) {
2150
+ return typeof start === "number" && typeof end === "number" && start < end;
2151
+ }
2152
+ function getMagicString(rawSource, context) {
2153
+ if (!context.ms) context.ms = new MagicString(rawSource);
2154
+ return context.ms;
2155
+ }
2156
+ function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
2157
+ if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2158
+ const transformed = transformLiteralText(node.value, transformOptions);
2159
+ if (!transformed) return false;
2160
+ const start = node.start + 1;
2161
+ const end = node.end - 1;
2162
+ if (start >= end || transformed === rawSource.slice(start, end)) return false;
2163
+ getMagicString(rawSource, context).update(start, end, jsStringEscape(transformed));
2164
+ return true;
2165
+ }
2166
+ function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
2167
+ const raw = node.value?.raw;
2168
+ if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2169
+ const transformed = transformLiteralText(raw, transformOptions);
2170
+ if (!transformed || transformed === raw) return false;
2171
+ const first = rawSource[node.start];
2172
+ const last = rawSource[node.end - 1];
2173
+ const start = node.start + (first === "`" || first === "}" ? 1 : 0);
2174
+ const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
2175
+ if (start >= end) return false;
2176
+ getMagicString(rawSource, context).update(start, end, transformed);
2177
+ return true;
2178
+ }
2179
+ function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
2180
+ let changed = false;
2181
+ walker.walk(program, { enter(node) {
2182
+ if (node.type === "Literal") {
2183
+ changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
2184
+ return;
2185
+ }
2186
+ if (node.type === "TemplateElement") {
2187
+ changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
2188
+ this.skip();
2189
+ }
2190
+ } });
2191
+ return changed;
2192
+ }
2193
+ function oxcJsHandler(rawSource, options) {
2194
+ if (!canUseOxcJsFastPath(options)) return;
2195
+ if (hasUnsupportedSourceMarker(rawSource)) return;
2196
+ const parser = loadOxcParser();
2197
+ const walker = loadOxcWalker();
2198
+ if (!parser || !walker) return;
2199
+ let result;
2200
+ try {
2201
+ result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
2202
+ sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
2203
+ lang: getParserLang(options.filename)
2204
+ });
2205
+ } catch {
2206
+ return;
2207
+ }
2208
+ if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
2209
+ const stringLiteralOptions = options.needEscaped === true ? options : {
2210
+ ...options,
2211
+ needEscaped: true
2212
+ };
2213
+ const templateLiteralOptions = options.needEscaped === false ? options : {
2214
+ ...options,
2215
+ needEscaped: false
2216
+ };
2217
+ const replacementContext = {};
2218
+ if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
2219
+ return { code: replacementContext.ms.toString() };
2220
+ }
2221
+ //#endregion
2222
+ //#region src/js/precheck.ts
2223
+ /** 用于检测源码中是否包含类名相关模式的正则表达式 */
2224
+ const FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
2225
+ /** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
2226
+ const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
2227
+ /**
2228
+ * 判断源码是否可能声明跨模块依赖。
2229
+ *
2230
+ * 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
2231
+ * 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
2232
+ */
2233
+ function hasDependencyHint(rawSource) {
2234
+ return DEPENDENCY_HINT_RE.test(rawSource);
2235
+ }
2236
+ /**
2237
+ * 判断是否可以跳过 JS 转换。
2238
+ * 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
2239
+ *
2240
+ * @param rawSource - 原始 JS 源码字符串
2241
+ * @param options - 可选的 JS 处理器配置选项
2242
+ * @returns 如果可以跳过转换返回 `true`,否则返回 `false`
2243
+ */
2244
+ function shouldSkipJsTransform(rawSource, options) {
2245
+ if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
2246
+ if (!rawSource) return true;
2247
+ if (options?.alwaysEscape) return false;
2248
+ if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
2249
+ if (options?.wrapExpression) return false;
2250
+ if (hasDependencyHint(rawSource)) return false;
2251
+ return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
2252
+ }
2253
+ //#endregion
2022
2254
  //#region src/js/index.ts
2023
2255
  /** 默认 LRU 缓存最大条目数 */
2024
2256
  const RESULT_CACHE_MAX = 512;
@@ -2063,6 +2295,7 @@ function getOptionsFingerprint(options) {
2063
2295
  JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
2064
2296
  JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
2065
2297
  JSON.stringify(options.moduleSpecifierReplacements ?? null),
2298
+ String(options.experimentalJsFastPath ?? ""),
2066
2299
  JSON.stringify(options.babelParserOptions ?? null)
2067
2300
  ].join("|");
2068
2301
  fingerprintCache.set(options, fingerprint);
@@ -2078,6 +2311,13 @@ function shouldCacheJsResult(rawSource, options) {
2078
2311
  if (options.moduleGraph || options.filename) return false;
2079
2312
  return true;
2080
2313
  }
2314
+ function resolveFastPathOptions(rawSource, options) {
2315
+ if (!options.moduleGraph) return options;
2316
+ if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
2317
+ if (hasDependencyHint(rawSource)) return options;
2318
+ const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
2319
+ return fastPathOptions;
2320
+ }
2081
2321
  function createJsHandler(options) {
2082
2322
  const defaults = {
2083
2323
  escapeMap: options.escapeMap,
@@ -2090,6 +2330,7 @@ function createJsHandler(options) {
2090
2330
  alwaysEscape: options.alwaysEscape,
2091
2331
  unescapeUnicode: options.unescapeUnicode,
2092
2332
  babelParserOptions: options.babelParserOptions,
2333
+ experimentalJsFastPath: options.experimentalJsFastPath,
2093
2334
  ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
2094
2335
  ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
2095
2336
  uniAppX: options.uniAppX,
@@ -2158,7 +2399,7 @@ function createJsHandler(options) {
2158
2399
  const resolvedOptions = resolveOptions(classNameSet, options);
2159
2400
  const cached = getCachedJsResult(rawSource, resolvedOptions);
2160
2401
  if (cached) return cached;
2161
- return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
2402
+ return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
2162
2403
  }
2163
2404
  return handler;
2164
2405
  }
@@ -4543,8 +4784,19 @@ function resolveRuntimePackageReplacements(option) {
4543
4784
  }
4544
4785
  //#endregion
4545
4786
  //#region src/context/style-options.ts
4546
- function resolveStyleOptionsFromContext(ctx) {
4787
+ function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
4547
4788
  const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
4789
+ const branch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
4790
+ appType: ctx.appType,
4791
+ platform: ctx.cssOptions?.platform ?? ctx.platform,
4792
+ tailwindcssMajorVersion,
4793
+ uniAppX: resolvedUniAppXOptions
4794
+ }), {
4795
+ appType: ctx.appType,
4796
+ platform: ctx.cssOptions?.platform ?? ctx.platform,
4797
+ tailwindcssMajorVersion,
4798
+ uniAppX: resolvedUniAppXOptions
4799
+ });
4548
4800
  const hasCssOptions = ctx.cssOptions !== void 0;
4549
4801
  const cssOptions = {
4550
4802
  cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
@@ -4559,13 +4811,14 @@ function resolveStyleOptionsFromContext(ctx) {
4559
4811
  atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
4560
4812
  autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
4561
4813
  cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
4562
- platform: ctx.cssOptions?.platform ?? ctx.platform,
4814
+ platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
4563
4815
  px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
4564
4816
  unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
4565
4817
  unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
4566
4818
  injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
4567
4819
  };
4568
4820
  return {
4821
+ appType: ctx.appType,
4569
4822
  cssPreflight: cssOptions.cssPreflight,
4570
4823
  cssPreflightRange: cssOptions.cssPreflightRange,
4571
4824
  cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
@@ -4579,7 +4832,7 @@ function resolveStyleOptionsFromContext(ctx) {
4579
4832
  atRules: cssOptions.atRules,
4580
4833
  autoprefixer: cssOptions.autoprefixer,
4581
4834
  cssCalc: cssOptions.cssCalc,
4582
- uniAppX: resolvedUniAppXOptions.enabled,
4835
+ uniAppX: branch.isNativeApp,
4583
4836
  platform: cssOptions.platform,
4584
4837
  px2rpx: cssOptions.px2rpx,
4585
4838
  unitsToPx: cssOptions.unitsToPx,
@@ -4589,9 +4842,9 @@ function resolveStyleOptionsFromContext(ctx) {
4589
4842
  //#endregion
4590
4843
  //#region src/context/handlers.ts
4591
4844
  function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
4592
- const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
4845
+ const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
4593
4846
  const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
4594
- const styleOptions = resolveStyleOptionsFromContext(ctx);
4847
+ const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
4595
4848
  const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
4596
4849
  const uniAppXEnabled = styleOptions.uniAppX === true;
4597
4850
  const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
@@ -4612,6 +4865,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
4612
4865
  tailwindcssMajorVersion,
4613
4866
  generateMap: true,
4614
4867
  babelParserOptions,
4868
+ experimentalJsFastPath,
4615
4869
  ignoreCallExpressionIdentifiers,
4616
4870
  ignoreTaggedTemplateExpressionIdentifiers,
4617
4871
  uniAppX: uniAppXEnabled,
@@ -4645,7 +4899,7 @@ function applyLoggerLevel(logLevel) {
4645
4899
  function resolveContextCssPreflight(opts, ctx, majorVersion) {
4646
4900
  const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
4647
4901
  const cssPreflight = resolveDefaultCssPreflight(userCssPreflight, majorVersion);
4648
- if (majorVersion !== 4 || cssPreflight === false || !resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
4902
+ if (cssPreflight === false || !resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
4649
4903
  const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
4650
4904
  return {
4651
4905
  ...cssPreflight,
@@ -4698,20 +4952,20 @@ function syncLegacyFieldsToCssOptions(ctx) {
4698
4952
  injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
4699
4953
  };
4700
4954
  }
4701
- async function clearTailwindcssPatcherCache(patcher, options) {
4702
- if (!patcher) return;
4703
- const cacheOptions = patcher.options?.cache;
4955
+ async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
4956
+ if (!tailwindRuntime) return;
4957
+ const cacheOptions = tailwindRuntime.options?.cache;
4704
4958
  if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
4705
- if (typeof patcher.clearCache === "function") try {
4706
- await patcher.clearCache({ scope: "all" });
4959
+ if (typeof tailwindRuntime.clearCache === "function") try {
4960
+ await tailwindRuntime.clearCache({ scope: "all" });
4707
4961
  } catch (error) {
4708
- logger.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
4962
+ logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
4709
4963
  }
4710
4964
  if (!options?.removeDirectory) return;
4711
4965
  const cachePaths = /* @__PURE__ */ new Map();
4712
4966
  const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
4713
4967
  if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
4714
- const privateCachePath = patcher?.cacheStore?.options?.path;
4968
+ const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
4715
4969
  if (privateCachePath) cachePaths.set(privateCachePath, false);
4716
4970
  if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
4717
4971
  if (!cachePaths.size) return;
@@ -4723,7 +4977,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
4723
4977
  } catch (error) {
4724
4978
  const err = error;
4725
4979
  if (err?.code === "ENOENT") continue;
4726
- logger.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
4980
+ logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
4727
4981
  }
4728
4982
  }
4729
4983
  function createInternalCompilerContext(opts) {
@@ -4732,32 +4986,32 @@ function createInternalCompilerContext(opts) {
4732
4986
  ctx.escapeMap = ctx.customReplaceDictionary;
4733
4987
  syncCssOptionsToLegacyFields(ctx);
4734
4988
  applyLoggerLevel(ctx.logLevel);
4735
- const twPatcher = createTailwindcssPatcherFromContext(ctx);
4736
- logTailwindcssTarget(twPatcher, ctx.tailwindcssBasedir);
4737
- logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, twPatcher.packageInfo?.rootPath, twPatcher.packageInfo?.version);
4738
- if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, twPatcher);
4739
- ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, twPatcher.majorVersion);
4740
- const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, twPatcher);
4989
+ const tailwindRuntime = createTailwindcssRuntimeFromContext(ctx);
4990
+ logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
4991
+ logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
4992
+ if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, tailwindRuntime);
4993
+ ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
4994
+ const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
4741
4995
  ctx.cssCalc = cssCalcOptions;
4742
4996
  syncLegacyFieldsToCssOptions(ctx);
4743
- const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, twPatcher.majorVersion);
4997
+ const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
4744
4998
  ctx.styleHandler = styleHandler;
4745
4999
  ctx.jsHandler = jsHandler;
4746
5000
  ctx.templateHandler = templateHandler;
4747
5001
  ctx.cache = initializeCache(ctx.cache);
4748
- ctx.twPatcher = twPatcher;
4749
- const refreshTailwindcssPatcher = async (options) => {
4750
- const previousPatcher = ctx.twPatcher;
4751
- if (options?.clearCache !== false) await clearTailwindcssPatcherCache(previousPatcher);
4752
- invalidateRuntimeClassSet(previousPatcher);
4753
- const nextPatcher = createTailwindcssPatcherFromContext(ctx);
4754
- Object.assign(previousPatcher, nextPatcher);
4755
- ctx.twPatcher = previousPatcher;
4756
- return previousPatcher;
5002
+ ctx.tailwindRuntime = tailwindRuntime;
5003
+ const refreshTailwindcssRuntime = async (options) => {
5004
+ const previousRuntime = ctx.tailwindRuntime;
5005
+ if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
5006
+ invalidateRuntimeClassSet(previousRuntime);
5007
+ const nextRuntime = createTailwindcssRuntimeFromContext(ctx);
5008
+ Object.assign(previousRuntime, nextRuntime);
5009
+ ctx.tailwindRuntime = previousRuntime;
5010
+ return previousRuntime;
4757
5011
  };
4758
- ctx.refreshTailwindcssPatcher = refreshTailwindcssPatcher;
4759
- Object.defineProperty(ctx.twPatcher, refreshTailwindcssPatcherSymbol, {
4760
- value: refreshTailwindcssPatcher,
5012
+ ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
5013
+ Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
5014
+ value: refreshTailwindcssRuntime,
4761
5015
  configurable: true
4762
5016
  });
4763
5017
  return ctx;
@@ -4771,27 +5025,4 @@ function getCompilerContext(opts) {
4771
5025
  return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
4772
5026
  }
4773
5027
  //#endregion
4774
- //#region src/js/precheck.ts
4775
- /** 用于检测源码中是否包含类名相关模式的正则表达式 */
4776
- const FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
4777
- /** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
4778
- const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
4779
- /**
4780
- * 判断是否可以跳过 JS 转换。
4781
- * 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
4782
- *
4783
- * @param rawSource - 原始 JS 源码字符串
4784
- * @param options - 可选的 JS 处理器配置选项
4785
- * @returns 如果可以跳过转换返回 `true`,否则返回 `false`
4786
- */
4787
- function shouldSkipJsTransform(rawSource, options) {
4788
- if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
4789
- if (!rawSource) return true;
4790
- if (options?.alwaysEscape) return false;
4791
- if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
4792
- if (options?.wrapExpression) return false;
4793
- if (DEPENDENCY_HINT_RE.test(rawSource)) return false;
4794
- return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
4795
- }
4796
- //#endregion
4797
- export { collectRuntimeClassSet as _, vitePluginName as a, refreshTailwindRuntimeState as b, createAttributeMatcher as c, _defineProperty as d, isClassContextLiteralPath as f, toCustomAttributesEntities as g, traverse as h, pluginName as i, analyzeSource as l, babelParse as m, getCompilerContext as n, Parser as o, replaceWxml as p, resolveStyleOptionsFromContext as r, generateCode as s, shouldSkipJsTransform as t, JsTokenUpdater as u, createTailwindRuntimeReadyPromise as v, md5Hash as x, ensureRuntimeClassSet as y };
5028
+ export { md5Hash as S, collectRuntimeClassSet as _, Parser as a, refreshTailwindRuntimeState as b, shouldSkipJsTransform as c, _defineProperty as d, isClassContextLiteralPath as f, toCustomAttributesEntities as g, traverse as h, vitePluginName as i, analyzeSource as l, babelParse as m, resolveStyleOptionsFromContext as n, generateCode as o, replaceWxml as p, pluginName as r, createAttributeMatcher as s, getCompilerContext as t, JsTokenUpdater as u, createTailwindRuntimeReadyPromise as v, createDebug as x, ensureRuntimeClassSet as y };