weapp-tailwindcss 5.0.13 → 5.1.1

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 (200) 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/class-selectors.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
  8. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
  9. package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  11. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
  12. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
  13. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
  14. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
  15. package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
  16. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
  17. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
  18. package/dist/bundlers/shared/run-tasks.d.ts +1 -0
  19. package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
  20. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  21. package/dist/bundlers/vite/css-memory.d.ts +16 -0
  22. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
  23. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
  24. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
  25. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
  26. package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
  27. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
  28. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
  29. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
  30. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
  31. package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
  32. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
  33. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
  34. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
  35. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
  36. package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
  37. package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
  38. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
  39. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
  40. package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
  41. package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
  42. package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
  43. package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
  44. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
  45. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  46. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
  47. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
  48. package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
  49. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  50. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
  51. package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
  52. package/dist/bundlers/vite/source-candidates.d.ts +9 -2
  53. package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
  54. package/dist/bundlers/vite/source-scan.d.ts +2 -2
  55. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
  56. package/dist/bundlers/vite/utils.d.ts +1 -0
  57. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
  58. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
  59. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
  60. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
  61. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
  62. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
  63. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
  64. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
  65. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
  66. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
  67. package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
  68. package/dist/cache/index.d.ts +1 -0
  69. package/dist/cli/mount-options.d.ts +2 -2
  70. package/dist/cli.js +138 -444
  71. package/dist/cli.mjs +134 -440
  72. package/dist/context/index.d.ts +3 -3
  73. package/dist/context/style-options.d.ts +5 -1
  74. package/dist/context/tailwindcss.d.ts +1 -1
  75. package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
  76. package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
  77. package/dist/core.js +15 -12
  78. package/dist/core.mjs +10 -7
  79. package/dist/css-macro/index.d.ts +3 -7
  80. package/dist/css-macro.js +1 -1
  81. package/dist/css-macro.mjs +1 -1
  82. package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
  83. package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
  84. package/dist/defaults.d.ts +2 -8
  85. package/dist/defaults.js +1 -2
  86. package/dist/defaults.mjs +2 -2
  87. package/dist/generator/index.d.ts +6 -7
  88. package/dist/generator/options.d.ts +3 -3
  89. package/dist/generator/types.d.ts +9 -10
  90. package/dist/generator-6oMJtTDO.js +170 -0
  91. package/dist/generator-CjzBK7h-.mjs +123 -0
  92. package/dist/generator.js +10 -16
  93. package/dist/generator.mjs +3 -3
  94. package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
  95. package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
  96. package/dist/gulp.js +1 -1
  97. package/dist/gulp.mjs +1 -1
  98. package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
  99. package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
  100. package/dist/index.js +4 -4
  101. package/dist/index.mjs +4 -4
  102. package/dist/js/fast-path/oxc.d.ts +4 -0
  103. package/dist/js/precheck.d.ts +1 -0
  104. package/dist/postcss.js +3 -4
  105. package/dist/postcss.mjs +2 -3
  106. package/dist/presets.js +9 -19
  107. package/dist/presets.mjs +8 -18
  108. package/dist/runtime-branch/create-branch.d.ts +2 -0
  109. package/dist/runtime-branch/generator-target-env.d.ts +4 -0
  110. package/dist/runtime-branch/index.d.ts +6 -0
  111. package/dist/runtime-branch/mini-program.d.ts +2 -0
  112. package/dist/runtime-branch/native-app.d.ts +2 -0
  113. package/dist/runtime-branch/platform.d.ts +6 -0
  114. package/dist/runtime-branch/tailwind-version.d.ts +2 -0
  115. package/dist/runtime-branch/types.d.ts +37 -0
  116. package/dist/runtime-branch/web.d.ts +2 -0
  117. package/dist/runtime-branch.d.ts +1 -0
  118. package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
  119. package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
  120. package/dist/tailwindcss/candidates.d.ts +7 -0
  121. package/dist/tailwindcss/index.d.ts +2 -2
  122. package/dist/tailwindcss/runtime/cache.d.ts +6 -6
  123. package/dist/tailwindcss/runtime-factory.d.ts +12 -0
  124. package/dist/tailwindcss/runtime-options.d.ts +8 -0
  125. package/dist/tailwindcss/runtime-types.d.ts +87 -0
  126. package/dist/tailwindcss/runtime.d.ts +6 -6
  127. package/dist/tailwindcss/source-scan.d.ts +1 -1
  128. package/dist/tailwindcss/targets.d.ts +2 -2
  129. package/dist/tailwindcss/v4/config.d.ts +3 -3
  130. package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
  131. package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
  132. package/dist/tailwindcss/v4/index.d.ts +1 -1
  133. package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
  134. package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
  135. package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
  136. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  137. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
  138. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
  139. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
  140. package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
  141. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  142. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
  143. package/dist/tailwindcss/v4-engine/source.d.ts +15 -7
  144. package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
  145. package/dist/tailwindcss/version.d.ts +1 -1
  146. package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
  147. package/dist/tailwindcss-dbrbY4cd.js +1528 -0
  148. package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
  149. package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
  150. package/dist/typedoc.export.d.ts +1 -1
  151. package/dist/types/index.d.ts +16 -17
  152. package/dist/types/shared.d.ts +1 -1
  153. package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
  154. package/dist/types/user-defined-options/general.d.ts +5 -3
  155. package/dist/types/user-defined-options/important.d.ts +2 -2
  156. package/dist/types/user-defined-options/matcher.d.ts +7 -0
  157. package/dist/uni-app-x/style-asset.d.ts +1 -0
  158. package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
  159. package/dist/v4-engine-ON_oSLfO.js +2752 -0
  160. package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
  161. package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
  162. package/dist/vite.js +1 -1
  163. package/dist/vite.mjs +1 -1
  164. package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
  165. package/dist/weapp-tw-runtime-classset-loader.js +15 -4
  166. package/dist/webpack-8PaV1gG3.mjs +2334 -0
  167. package/dist/webpack-CGgBOx9l.js +2346 -0
  168. package/dist/webpack.js +1 -1
  169. package/dist/webpack.mjs +1 -1
  170. package/package.json +6 -7
  171. package/dist/auto-CTp6wE5a.js +0 -33
  172. package/dist/auto-Cl8_hsG6.mjs +0 -22
  173. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
  174. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
  175. package/dist/context/tailwindcss/rax.d.ts +0 -2
  176. package/dist/generator-CzpArpCL.js +0 -92
  177. package/dist/generator-ITLd7PTl.mjs +0 -67
  178. package/dist/tailwindcss/patcher-options.d.ts +0 -8
  179. package/dist/tailwindcss/patcher.d.ts +0 -12
  180. package/dist/tailwindcss/runtime-patch.d.ts +0 -5
  181. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
  182. package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
  183. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
  184. package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
  185. package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
  186. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
  187. package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
  188. package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
  189. package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
  190. package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
  191. package/dist/tailwindcss/v4/patcher.d.ts +0 -15
  192. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
  193. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
  194. package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
  195. package/dist/tailwindcss-DZEwT3C_.js +0 -613
  196. package/dist/v3-engine-2rrgylhn.js +0 -4686
  197. package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
  198. package/dist/webpack-BcPpnT90.mjs +0 -1184
  199. package/dist/webpack-CfkUkMXG.js +0 -1196
  200. /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 { W as createTailwindV4Engine$1, lt as loadTailwindV4DesignSystem, n as resolveTailwindV4SourceFromRuntime, st as omitUndefined, ut as resolveValidTailwindV4Candidates$1, y as resolveBooleanObjectOption } from "./v4-engine-C3qSwQ-e.mjs";
2
+ import { a as resolveGeneratorRuntimeBranch, i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-CjzBK7h-.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-BhE26nSw.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-B5mRo0-M.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,112 +213,86 @@ 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 source = await resolveTailwindV4SourceFromRuntime(tailwindRuntime);
237
+ const generated = await createTailwindV4Engine$1(source).generate({
215
238
  scanSources: true,
216
- target: "tailwind"
239
+ target: "web"
217
240
  });
218
- debug$1("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
219
- return generated.classSet;
241
+ const classSet = resolveValidTailwindV4Candidates$1(await loadTailwindV4DesignSystem(source), generated.classSet, { ...source.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: source.bareArbitraryValues } });
242
+ debug$1("runtime class set resolved via tailwindcss v4 generator source scan, raw=%d valid=%d", generated.classSet.size, classSet.size);
243
+ return classSet;
220
244
  } catch (error) {
221
245
  debug$1("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
222
246
  return;
223
247
  }
224
248
  }
225
- async function mergeTailwindV4GeneratorClassSet(twPatcher, classSet) {
226
- if (twPatcher.majorVersion !== 4) return classSet;
227
- const generatorClassSet = await collectTailwindV4GeneratorClassSet(twPatcher);
249
+ async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
250
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
228
251
  if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
229
252
  return new Set([...classSet, ...generatorClassSet]);
230
253
  }
231
- function canReturnExtractClassSetImmediately(twPatcher) {
232
- return twPatcher.majorVersion !== 4;
233
- }
234
- async function collectRuntimeClassSet(twPatcher, options = {}) {
235
- let activePatcher = twPatcher;
254
+ async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
255
+ let activeRuntime = tailwindRuntime;
236
256
  if (options.force && !options.skipRefresh) {
237
- const refresh = activePatcher[refreshTailwindcssPatcherSymbol];
257
+ const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
238
258
  if (typeof refresh === "function") try {
239
259
  const refreshed = await refresh({ clearCache: options.clearCache === true });
240
- if (refreshed) activePatcher = refreshed;
260
+ if (refreshed) activeRuntime = refreshed;
241
261
  } catch (error) {
242
- debug$1("refreshTailwindcssPatcher failed, continuing with existing patcher: %O", error);
262
+ debug$1("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
243
263
  }
244
264
  }
245
- const entry = getRuntimeClassSetCacheEntry(activePatcher);
246
- const signature = await getRuntimeClassSetSignatureWithSources(activePatcher);
265
+ const entry = getRuntimeClassSetCacheEntry(activeRuntime);
266
+ const signature = await getRuntimeClassSetSignatureWithSources(activeRuntime);
247
267
  if (!options.force) {
248
268
  if (entry.value && entry.signature === signature) return entry.value;
249
269
  if (entry.promise) return entry.promise;
250
270
  } else entry.value = void 0;
251
271
  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
272
  const preferExtract = options.force === true;
256
273
  try {
257
- const result = await activePatcher.extract({ write: false });
274
+ const result = await activeRuntime.extract({ write: false });
258
275
  if (result?.classSet) {
259
276
  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);
277
+ const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
265
278
  debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
266
279
  return merged;
267
280
  }
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
281
  if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
273
282
  else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
274
283
  }
275
284
  } catch (error) {
276
285
  debug$1("extract() failed, fallback to getClassSet(): %O", error);
277
286
  }
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);
287
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
288
+ if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
289
+ const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
287
290
  if (syncSet) {
288
291
  debug$1("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
289
292
  return syncSet;
290
293
  }
291
294
  try {
292
- const fallbackSet = await Promise.resolve(activePatcher.getClassSet());
295
+ const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
293
296
  if (fallbackSet) {
294
297
  debug$1("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
295
298
  return fallbackSet;
@@ -354,8 +357,8 @@ function formatRelativeToBase(targetPath, baseDir) {
354
357
  if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
355
358
  return path.join(".", relative).replace(/\\/g, "/");
356
359
  }
357
- function logTailwindcssTarget(patcher, baseDir) {
358
- const packageInfo = patcher?.packageInfo;
360
+ function logTailwindcssTarget(tailwindRuntime, baseDir) {
361
+ const packageInfo = tailwindRuntime?.packageInfo;
359
362
  const label = "Weapp-tailwindcss";
360
363
  if (!packageInfo?.rootPath) {
361
364
  logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
@@ -388,10 +391,28 @@ function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
388
391
  const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
389
392
  const AT_LOCATION_RE = /at\s+(\S.*)$/u;
390
393
  const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
394
+ const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
395
+ const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
391
396
  const globalCacheHolder = globalThis;
392
397
  const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
393
398
  const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
394
399
  const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
400
+ function resolveCompilerContextCacheMax(defaultValue) {
401
+ const raw = Number.parseInt(process.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
402
+ if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
403
+ return Math.floor(raw);
404
+ }
405
+ function touchMapValue(map, key, value) {
406
+ map.delete(key);
407
+ map.set(key, value);
408
+ }
409
+ function pruneMapToMaxSize(map, maxSize) {
410
+ while (map.size > maxSize) {
411
+ const firstKey = map.keys().next().value;
412
+ if (firstKey === void 0) break;
413
+ map.delete(firstKey);
414
+ }
415
+ }
395
416
  function withCircularGuard(value, stack, factory) {
396
417
  if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
397
418
  stack.add(value);
@@ -561,7 +582,8 @@ function createCompilerContextCacheKey(opts) {
561
582
  const cached = keyStore.get(runtimeCacheScopeKey);
562
583
  if (cached !== void 0) return cached;
563
584
  const cacheKey = md5Hash(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
564
- keyStore.set(runtimeCacheScopeKey, cacheKey);
585
+ touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
586
+ pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
565
587
  return cacheKey;
566
588
  } catch (error) {
567
589
  logger.debug("skip compiler context cache: %O", error);
@@ -572,10 +594,16 @@ function withCompilerContextCache(opts, factory) {
572
594
  const cacheKey = createCompilerContextCacheKey(opts);
573
595
  if (cacheKey) {
574
596
  const cached = compilerContextCache.get(cacheKey);
575
- if (cached) return cached;
597
+ if (cached) {
598
+ touchMapValue(compilerContextCache, cacheKey, cached);
599
+ return cached;
600
+ }
576
601
  }
577
602
  const ctx = factory();
578
- if (cacheKey) compilerContextCache.set(cacheKey, ctx);
603
+ if (cacheKey) {
604
+ touchMapValue(compilerContextCache, cacheKey, ctx);
605
+ pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
606
+ }
579
607
  return ctx;
580
608
  }
581
609
  //#endregion
@@ -939,6 +967,19 @@ function hasIgnoreComment(node) {
939
967
  }
940
968
  return false;
941
969
  }
970
+ function isConditionTestLiteral(path) {
971
+ let current = path;
972
+ while (current?.parentPath) {
973
+ const parent = current.parentPath;
974
+ if (parent.isConditionalExpression()) return parent.node.test === current.node;
975
+ if (parent.isBinaryExpression() || parent.isCallExpression() || parent.isLogicalExpression() || parent.isMemberExpression() || parent.isUnaryExpression()) {
976
+ current = parent;
977
+ continue;
978
+ }
979
+ return false;
980
+ }
981
+ return false;
982
+ }
942
983
  function extractLiteralValue(path, { unescapeUnicode }) {
943
984
  const { node } = path;
944
985
  let offset = 0;
@@ -1004,6 +1045,7 @@ function replaceHandleValue(path, options) {
1004
1045
  const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
1005
1046
  if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) return;
1006
1047
  if (hasIgnoreComment(path.node)) return;
1048
+ if (isConditionTestLiteral(path)) return;
1007
1049
  const { literal, original, offset } = extractLiteralValue(path, options);
1008
1050
  const candidates = splitCandidateTokens(literal);
1009
1051
  if (candidates.length === 0) return;
@@ -2019,6 +2061,198 @@ function jsHandler(rawSource, options) {
2019
2061
  }
2020
2062
  defaultEvalHandler = jsHandler;
2021
2063
  //#endregion
2064
+ //#region src/js/literal-transform.ts
2065
+ function transformLiteralText(literal, options) {
2066
+ const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
2067
+ if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
2068
+ const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
2069
+ const candidates = splitCandidateTokens(source);
2070
+ if (candidates.length === 0) return;
2071
+ const transformOptions = {
2072
+ ...options,
2073
+ classContext: true
2074
+ };
2075
+ const replacementCache = getReplacementCacheStore(options.escapeMap);
2076
+ let transformed = source;
2077
+ let mutated = false;
2078
+ for (const candidate of candidates) {
2079
+ const result = resolveClassNameTransformWithResult(candidate, transformOptions);
2080
+ if (result.decision === "skip" || !transformed.includes(candidate)) continue;
2081
+ const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
2082
+ const replaced = transformed.replace(candidate, replacement);
2083
+ if (replaced !== transformed) {
2084
+ transformed = replaced;
2085
+ mutated = true;
2086
+ }
2087
+ }
2088
+ return mutated ? transformed : void 0;
2089
+ }
2090
+ //#endregion
2091
+ //#region src/js/fast-path/oxc.ts
2092
+ const require = createRequire(import.meta.url);
2093
+ let oxcParser;
2094
+ let oxcWalker;
2095
+ function isOxcParserRuntimeSupported(version = process.versions.node) {
2096
+ const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
2097
+ if (!match) return false;
2098
+ const major = Number(match[1]);
2099
+ const minor = Number(match[2]);
2100
+ if (major === 20) return minor >= 19;
2101
+ if (major === 21) return false;
2102
+ if (major === 22) return minor >= 12;
2103
+ return major > 22;
2104
+ }
2105
+ function loadOxcParser() {
2106
+ if (!isOxcParserRuntimeSupported()) return;
2107
+ if (oxcParser === false) return;
2108
+ if (oxcParser) return oxcParser;
2109
+ try {
2110
+ oxcParser = require("oxc-parser");
2111
+ } catch {
2112
+ oxcParser = false;
2113
+ return;
2114
+ }
2115
+ return oxcParser;
2116
+ }
2117
+ function loadOxcWalker() {
2118
+ if (!isOxcParserRuntimeSupported()) return;
2119
+ if (oxcWalker === false) return;
2120
+ if (oxcWalker) return oxcWalker;
2121
+ try {
2122
+ oxcWalker = require("oxc-walker");
2123
+ } catch {
2124
+ oxcWalker = false;
2125
+ return;
2126
+ }
2127
+ return oxcWalker;
2128
+ }
2129
+ function hasValues(values) {
2130
+ return Array.isArray(values) && values.length > 0;
2131
+ }
2132
+ function hasUnsupportedSourceMarker(rawSource) {
2133
+ return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
2134
+ }
2135
+ function hasSupportedClassMatchSource(options) {
2136
+ return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
2137
+ }
2138
+ function canUseOxcJsFastPath(options) {
2139
+ if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
2140
+ return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
2141
+ }
2142
+ function getParserLang(filename) {
2143
+ if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
2144
+ if (filename?.endsWith(".tsx")) return "tsx";
2145
+ if (filename?.endsWith(".jsx")) return "jsx";
2146
+ return "js";
2147
+ }
2148
+ function getParserSourceType(sourceType) {
2149
+ return sourceType === "script" || sourceType === "module" ? sourceType : "module";
2150
+ }
2151
+ function isRangeValid(start, end) {
2152
+ return typeof start === "number" && typeof end === "number" && start < end;
2153
+ }
2154
+ function getMagicString(rawSource, context) {
2155
+ if (!context.ms) context.ms = new MagicString(rawSource);
2156
+ return context.ms;
2157
+ }
2158
+ function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
2159
+ if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2160
+ const transformed = transformLiteralText(node.value, transformOptions);
2161
+ if (!transformed) return false;
2162
+ const start = node.start + 1;
2163
+ const end = node.end - 1;
2164
+ if (start >= end || transformed === rawSource.slice(start, end)) return false;
2165
+ getMagicString(rawSource, context).update(start, end, jsStringEscape(transformed));
2166
+ return true;
2167
+ }
2168
+ function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
2169
+ const raw = node.value?.raw;
2170
+ if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2171
+ const transformed = transformLiteralText(raw, transformOptions);
2172
+ if (!transformed || transformed === raw) return false;
2173
+ const first = rawSource[node.start];
2174
+ const last = rawSource[node.end - 1];
2175
+ const start = node.start + (first === "`" || first === "}" ? 1 : 0);
2176
+ const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
2177
+ if (start >= end) return false;
2178
+ getMagicString(rawSource, context).update(start, end, transformed);
2179
+ return true;
2180
+ }
2181
+ function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
2182
+ let changed = false;
2183
+ walker.walk(program, { enter(node) {
2184
+ if (node.type === "Literal") {
2185
+ changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
2186
+ return;
2187
+ }
2188
+ if (node.type === "TemplateElement") {
2189
+ changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
2190
+ this.skip();
2191
+ }
2192
+ } });
2193
+ return changed;
2194
+ }
2195
+ function oxcJsHandler(rawSource, options) {
2196
+ if (!canUseOxcJsFastPath(options)) return;
2197
+ if (hasUnsupportedSourceMarker(rawSource)) return;
2198
+ const parser = loadOxcParser();
2199
+ const walker = loadOxcWalker();
2200
+ if (!parser || !walker) return;
2201
+ let result;
2202
+ try {
2203
+ result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
2204
+ sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
2205
+ lang: getParserLang(options.filename)
2206
+ });
2207
+ } catch {
2208
+ return;
2209
+ }
2210
+ if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
2211
+ const stringLiteralOptions = options.needEscaped === true ? options : {
2212
+ ...options,
2213
+ needEscaped: true
2214
+ };
2215
+ const templateLiteralOptions = options.needEscaped === false ? options : {
2216
+ ...options,
2217
+ needEscaped: false
2218
+ };
2219
+ const replacementContext = {};
2220
+ if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
2221
+ return { code: replacementContext.ms.toString() };
2222
+ }
2223
+ //#endregion
2224
+ //#region src/js/precheck.ts
2225
+ /** 用于检测源码中是否包含类名相关模式的正则表达式 */
2226
+ 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)-/;
2227
+ /** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
2228
+ const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
2229
+ /**
2230
+ * 判断源码是否可能声明跨模块依赖。
2231
+ *
2232
+ * 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
2233
+ * 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
2234
+ */
2235
+ function hasDependencyHint(rawSource) {
2236
+ return DEPENDENCY_HINT_RE.test(rawSource);
2237
+ }
2238
+ /**
2239
+ * 判断是否可以跳过 JS 转换。
2240
+ * 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
2241
+ *
2242
+ * @param rawSource - 原始 JS 源码字符串
2243
+ * @param options - 可选的 JS 处理器配置选项
2244
+ * @returns 如果可以跳过转换返回 `true`,否则返回 `false`
2245
+ */
2246
+ function shouldSkipJsTransform(rawSource, options) {
2247
+ if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
2248
+ if (!rawSource) return true;
2249
+ if (options?.alwaysEscape) return false;
2250
+ if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
2251
+ if (options?.wrapExpression) return false;
2252
+ if (hasDependencyHint(rawSource)) return false;
2253
+ return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
2254
+ }
2255
+ //#endregion
2022
2256
  //#region src/js/index.ts
2023
2257
  /** 默认 LRU 缓存最大条目数 */
2024
2258
  const RESULT_CACHE_MAX = 512;
@@ -2063,6 +2297,7 @@ function getOptionsFingerprint(options) {
2063
2297
  JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
2064
2298
  JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
2065
2299
  JSON.stringify(options.moduleSpecifierReplacements ?? null),
2300
+ String(options.experimentalJsFastPath ?? ""),
2066
2301
  JSON.stringify(options.babelParserOptions ?? null)
2067
2302
  ].join("|");
2068
2303
  fingerprintCache.set(options, fingerprint);
@@ -2078,6 +2313,13 @@ function shouldCacheJsResult(rawSource, options) {
2078
2313
  if (options.moduleGraph || options.filename) return false;
2079
2314
  return true;
2080
2315
  }
2316
+ function resolveFastPathOptions(rawSource, options) {
2317
+ if (!options.moduleGraph) return options;
2318
+ if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
2319
+ if (hasDependencyHint(rawSource)) return options;
2320
+ const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
2321
+ return fastPathOptions;
2322
+ }
2081
2323
  function createJsHandler(options) {
2082
2324
  const defaults = {
2083
2325
  escapeMap: options.escapeMap,
@@ -2090,6 +2332,7 @@ function createJsHandler(options) {
2090
2332
  alwaysEscape: options.alwaysEscape,
2091
2333
  unescapeUnicode: options.unescapeUnicode,
2092
2334
  babelParserOptions: options.babelParserOptions,
2335
+ experimentalJsFastPath: options.experimentalJsFastPath,
2093
2336
  ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
2094
2337
  ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
2095
2338
  uniAppX: options.uniAppX,
@@ -2158,7 +2401,7 @@ function createJsHandler(options) {
2158
2401
  const resolvedOptions = resolveOptions(classNameSet, options);
2159
2402
  const cached = getCachedJsResult(rawSource, resolvedOptions);
2160
2403
  if (cached) return cached;
2161
- return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
2404
+ return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
2162
2405
  }
2163
2406
  return handler;
2164
2407
  }
@@ -4543,8 +4786,22 @@ function resolveRuntimePackageReplacements(option) {
4543
4786
  }
4544
4787
  //#endregion
4545
4788
  //#region src/context/style-options.ts
4546
- function resolveStyleOptionsFromContext(ctx) {
4789
+ function normalizeStyleHandlerMajorVersion(majorVersion) {
4790
+ return majorVersion === 4 ? 4 : void 0;
4791
+ }
4792
+ function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
4547
4793
  const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
4794
+ const branch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
4795
+ appType: ctx.appType,
4796
+ platform: ctx.cssOptions?.platform ?? ctx.platform,
4797
+ tailwindcssMajorVersion,
4798
+ uniAppX: resolvedUniAppXOptions
4799
+ }), {
4800
+ appType: ctx.appType,
4801
+ platform: ctx.cssOptions?.platform ?? ctx.platform,
4802
+ tailwindcssMajorVersion,
4803
+ uniAppX: resolvedUniAppXOptions
4804
+ });
4548
4805
  const hasCssOptions = ctx.cssOptions !== void 0;
4549
4806
  const cssOptions = {
4550
4807
  cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
@@ -4559,13 +4816,14 @@ function resolveStyleOptionsFromContext(ctx) {
4559
4816
  atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
4560
4817
  autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
4561
4818
  cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
4562
- platform: ctx.cssOptions?.platform ?? ctx.platform,
4819
+ platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
4563
4820
  px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
4564
4821
  unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
4565
4822
  unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
4566
4823
  injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
4567
4824
  };
4568
4825
  return {
4826
+ appType: ctx.appType,
4569
4827
  cssPreflight: cssOptions.cssPreflight,
4570
4828
  cssPreflightRange: cssOptions.cssPreflightRange,
4571
4829
  cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
@@ -4579,7 +4837,7 @@ function resolveStyleOptionsFromContext(ctx) {
4579
4837
  atRules: cssOptions.atRules,
4580
4838
  autoprefixer: cssOptions.autoprefixer,
4581
4839
  cssCalc: cssOptions.cssCalc,
4582
- uniAppX: resolvedUniAppXOptions.enabled,
4840
+ uniAppX: branch.isNativeApp,
4583
4841
  platform: cssOptions.platform,
4584
4842
  px2rpx: cssOptions.px2rpx,
4585
4843
  unitsToPx: cssOptions.unitsToPx,
@@ -4589,9 +4847,9 @@ function resolveStyleOptionsFromContext(ctx) {
4589
4847
  //#endregion
4590
4848
  //#region src/context/handlers.ts
4591
4849
  function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
4592
- const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
4850
+ const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
4593
4851
  const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
4594
- const styleOptions = resolveStyleOptionsFromContext(ctx);
4852
+ const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
4595
4853
  const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
4596
4854
  const uniAppXEnabled = styleOptions.uniAppX === true;
4597
4855
  const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
@@ -4602,7 +4860,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
4602
4860
  postcssOptions,
4603
4861
  uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
4604
4862
  cssCalc: cssCalcOptions,
4605
- majorVersion: tailwindcssMajorVersion
4863
+ majorVersion: normalizeStyleHandlerMajorVersion(tailwindcssMajorVersion)
4606
4864
  });
4607
4865
  const jsHandler = createJsHandler({
4608
4866
  escapeMap,
@@ -4612,6 +4870,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
4612
4870
  tailwindcssMajorVersion,
4613
4871
  generateMap: true,
4614
4872
  babelParserOptions,
4873
+ experimentalJsFastPath,
4615
4874
  ignoreCallExpressionIdentifiers,
4616
4875
  ignoreTaggedTemplateExpressionIdentifiers,
4617
4876
  uniAppX: uniAppXEnabled,
@@ -4645,7 +4904,7 @@ function applyLoggerLevel(logLevel) {
4645
4904
  function resolveContextCssPreflight(opts, ctx, majorVersion) {
4646
4905
  const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
4647
4906
  const cssPreflight = resolveDefaultCssPreflight(userCssPreflight, majorVersion);
4648
- if (majorVersion !== 4 || cssPreflight === false || !resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
4907
+ if (cssPreflight === false || !resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
4649
4908
  const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
4650
4909
  return {
4651
4910
  ...cssPreflight,
@@ -4698,21 +4957,21 @@ function syncLegacyFieldsToCssOptions(ctx) {
4698
4957
  injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
4699
4958
  };
4700
4959
  }
4701
- async function clearTailwindcssPatcherCache(patcher, options) {
4702
- if (!patcher) return;
4703
- const cacheOptions = patcher.options?.cache;
4960
+ async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
4961
+ if (!tailwindRuntime) return;
4962
+ const cacheOptions = tailwindRuntime.options?.cache;
4704
4963
  if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
4705
- if (typeof patcher.clearCache === "function") try {
4706
- await patcher.clearCache({ scope: "all" });
4964
+ if (typeof tailwindRuntime.clearCache === "function") try {
4965
+ await tailwindRuntime.clearCache({ scope: "all" });
4707
4966
  } catch (error) {
4708
- logger.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
4967
+ logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
4709
4968
  }
4710
4969
  if (!options?.removeDirectory) return;
4711
4970
  const cachePaths = /* @__PURE__ */ new Map();
4712
4971
  const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
4713
- if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
4714
- const privateCachePath = patcher?.cacheStore?.options?.path;
4972
+ const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
4715
4973
  if (privateCachePath) cachePaths.set(privateCachePath, false);
4974
+ if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
4716
4975
  if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
4717
4976
  if (!cachePaths.size) return;
4718
4977
  for (const [cachePath, recursive] of cachePaths.entries()) try {
@@ -4723,7 +4982,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
4723
4982
  } catch (error) {
4724
4983
  const err = error;
4725
4984
  if (err?.code === "ENOENT") continue;
4726
- logger.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
4985
+ logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
4727
4986
  }
4728
4987
  }
4729
4988
  function createInternalCompilerContext(opts) {
@@ -4732,32 +4991,32 @@ function createInternalCompilerContext(opts) {
4732
4991
  ctx.escapeMap = ctx.customReplaceDictionary;
4733
4992
  syncCssOptionsToLegacyFields(ctx);
4734
4993
  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);
4994
+ const tailwindRuntime = createTailwindcssRuntimeFromContext(ctx);
4995
+ logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
4996
+ logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
4997
+ if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, tailwindRuntime);
4998
+ ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
4999
+ const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
4741
5000
  ctx.cssCalc = cssCalcOptions;
4742
5001
  syncLegacyFieldsToCssOptions(ctx);
4743
- const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, twPatcher.majorVersion);
5002
+ const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
4744
5003
  ctx.styleHandler = styleHandler;
4745
5004
  ctx.jsHandler = jsHandler;
4746
5005
  ctx.templateHandler = templateHandler;
4747
5006
  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;
5007
+ ctx.tailwindRuntime = tailwindRuntime;
5008
+ const refreshTailwindcssRuntime = async (options) => {
5009
+ const previousRuntime = ctx.tailwindRuntime;
5010
+ if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
5011
+ invalidateRuntimeClassSet(previousRuntime);
5012
+ const nextRuntime = createTailwindcssRuntimeFromContext(ctx);
5013
+ Object.assign(previousRuntime, nextRuntime);
5014
+ ctx.tailwindRuntime = previousRuntime;
5015
+ return previousRuntime;
4757
5016
  };
4758
- ctx.refreshTailwindcssPatcher = refreshTailwindcssPatcher;
4759
- Object.defineProperty(ctx.twPatcher, refreshTailwindcssPatcherSymbol, {
4760
- value: refreshTailwindcssPatcher,
5017
+ ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
5018
+ Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
5019
+ value: refreshTailwindcssRuntime,
4761
5020
  configurable: true
4762
5021
  });
4763
5022
  return ctx;
@@ -4771,27 +5030,4 @@ function getCompilerContext(opts) {
4771
5030
  return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
4772
5031
  }
4773
5032
  //#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 };
5033
+ export { md5Hash as C, createDebug as S, toCustomAttributesEntities as _, vitePluginName as a, ensureRuntimeClassSet as b, createAttributeMatcher as c, JsTokenUpdater as d, _defineProperty as f, traverse as g, babelParse as h, pluginName as i, shouldSkipJsTransform as l, replaceWxml as m, normalizeStyleHandlerMajorVersion as n, Parser as o, isClassContextLiteralPath as p, resolveStyleOptionsFromContext as r, generateCode as s, getCompilerContext as t, analyzeSource as u, collectRuntimeClassSet as v, refreshTailwindRuntimeState as x, createTailwindRuntimeReadyPromise as y };