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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +21 -9
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +10 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +124 -437
- package/dist/cli.mjs +120 -433
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +4 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-BHxLe743.js} +391 -153
- package/dist/{precheck-CRI90iL1.mjs → context-Mbzkek1q.mjs} +368 -137
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-C_J_kBpw.js → defaults-CVcKbXBG.js} +4 -15
- package/dist/{defaults-Bqx18S1f.mjs → defaults-ZElj1zKc.mjs} +5 -10
- package/dist/defaults.d.ts +1 -7
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-9rUz4Hcb.js +170 -0
- package/dist/generator-Dc4qaPmT.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-B_sdP6dx.js} +47 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-uM36oIJs.mjs} +40 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-BXMLsF4b.mjs} +1145 -842
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CogqkFaF.js} +1262 -881
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-2ybpptAK.js} +261 -19
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +86 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
- package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-DHIYcqXT.js +1523 -0
- package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
- package/dist/{transform-YmrmxuF3.js → transform-CQVOgmzM.js} +17 -17
- package/dist/{transform-DfcEjsZF.mjs → transform-tExdt40m.mjs} +2 -2
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
- package/dist/v4-engine-D4ubP7N5.js +2778 -0
- package/dist/{vite-CXHVsHmX.js → vite-CP0ylSxZ.js} +1081 -542
- package/dist/{vite-DjI09vVN.mjs → vite-CPO83EhA.mjs} +916 -376
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5350 -4165
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-Bsek8VhR.js +2094 -0
- package/dist/webpack-BzqhJ8yK.mjs +2082 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +4 -5
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_v4_engine = require("./v4-engine-D4ubP7N5.js");
|
|
3
|
+
const require_generator = require("./generator-9rUz4Hcb.js");
|
|
4
4
|
require("./utils-BCa37Wqj.js");
|
|
5
|
-
const
|
|
5
|
+
const require_defaults = require("./defaults-CVcKbXBG.js");
|
|
6
|
+
const require_tailwindcss = require("./tailwindcss-DHIYcqXT.js");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_chunk.__toESM(node_path);
|
|
8
9
|
let node_process = require("node:process");
|
|
9
10
|
node_process = require_chunk.__toESM(node_process);
|
|
11
|
+
let _tailwindcss_mangle_engine = require("@tailwindcss-mangle/engine");
|
|
10
12
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
11
13
|
let lru_cache = require("lru-cache");
|
|
12
|
-
let tailwindcss_patch = require("tailwindcss-patch");
|
|
13
|
-
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
14
14
|
let node_fs_promises = require("node:fs/promises");
|
|
15
|
+
let node_module = require("node:module");
|
|
15
16
|
let node_buffer = require("node:buffer");
|
|
17
|
+
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
16
18
|
let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
|
|
17
19
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
20
|
+
let debug = require("debug");
|
|
21
|
+
debug = require_chunk.__toESM(debug);
|
|
18
22
|
let _babel_traverse = require("@babel/traverse");
|
|
19
23
|
_babel_traverse = require_chunk.__toESM(_babel_traverse);
|
|
20
24
|
let _babel_parser = require("@babel/parser");
|
|
@@ -69,15 +73,16 @@ function createCache(options) {
|
|
|
69
73
|
});
|
|
70
74
|
return cache;
|
|
71
75
|
},
|
|
76
|
+
pruneHashKeys(hashKeys) {
|
|
77
|
+
const activeHashKeys = new Set(hashKeys);
|
|
78
|
+
for (const key of hashMap.keys()) if (!activeHashKeys.has(key)) hashMap.delete(key);
|
|
79
|
+
},
|
|
72
80
|
prune(options) {
|
|
73
81
|
if (options.cacheKeys) {
|
|
74
82
|
const cacheKeys = new Set(options.cacheKeys);
|
|
75
83
|
for (const key of instance.keys()) if (!cacheKeys.has(key)) instance.delete(key);
|
|
76
84
|
}
|
|
77
|
-
if (options.hashKeys)
|
|
78
|
-
const hashKeys = new Set(options.hashKeys);
|
|
79
|
-
for (const key of hashMap.keys()) if (!hashKeys.has(key)) hashMap.delete(key);
|
|
80
|
-
}
|
|
85
|
+
if (options.hashKeys) cache.pruneHashKeys?.(options.hashKeys);
|
|
81
86
|
},
|
|
82
87
|
has(key) {
|
|
83
88
|
return instance.has(key);
|
|
@@ -116,13 +121,28 @@ function initializeCache(cacheConfig) {
|
|
|
116
121
|
return cacheConfig;
|
|
117
122
|
}
|
|
118
123
|
//#endregion
|
|
124
|
+
//#region src/debug/index.ts
|
|
125
|
+
const _debug = (0, debug.default)("weapp-tw");
|
|
126
|
+
function createDebug(prefix) {
|
|
127
|
+
const debug$3 = ((formatter, ...args) => {
|
|
128
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(debug$3, "enabled", {
|
|
131
|
+
enumerable: false,
|
|
132
|
+
configurable: false,
|
|
133
|
+
get() {
|
|
134
|
+
return _debug.enabled;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return debug$3;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
119
140
|
//#region src/tailwindcss/runtime.ts
|
|
120
|
-
const debug$
|
|
121
|
-
const
|
|
122
|
-
function createTailwindRuntimeReadyPromise(
|
|
141
|
+
const debug$2 = createDebug("[tailwindcss:runtime] ");
|
|
142
|
+
const refreshTailwindcssRuntimeSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssRuntime");
|
|
143
|
+
function createTailwindRuntimeReadyPromise(tailwindRuntime) {
|
|
123
144
|
return Promise.resolve().then(async () => {
|
|
124
|
-
|
|
125
|
-
require_v3_engine.invalidateRuntimeClassSet(twPatcher);
|
|
145
|
+
require_tailwindcss.invalidateRuntimeClassSet(tailwindRuntime);
|
|
126
146
|
});
|
|
127
147
|
}
|
|
128
148
|
const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -134,21 +154,31 @@ function getRuntimeClassSetStateEntry(state) {
|
|
|
134
154
|
}
|
|
135
155
|
return entry;
|
|
136
156
|
}
|
|
157
|
+
function getTailwindRuntime(state) {
|
|
158
|
+
return state.tailwindRuntime;
|
|
159
|
+
}
|
|
160
|
+
function setTailwindRuntime(state, runtime) {
|
|
161
|
+
state.tailwindRuntime = runtime;
|
|
162
|
+
}
|
|
163
|
+
function getRefreshTailwindRuntime(state) {
|
|
164
|
+
return state.refreshTailwindcssRuntime;
|
|
165
|
+
}
|
|
137
166
|
async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
138
167
|
const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
|
|
139
168
|
const force = normalizedOptions.force;
|
|
140
169
|
const clearCache = normalizedOptions.clearCache === true;
|
|
141
170
|
if (!force) return false;
|
|
142
|
-
debug$
|
|
171
|
+
debug$2("refresh runtime state start, clearCache=%s major=%s", clearCache, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
143
172
|
await state.readyPromise;
|
|
144
173
|
let refreshed = false;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
174
|
+
const refreshTailwindRuntime = getRefreshTailwindRuntime(state);
|
|
175
|
+
if (typeof refreshTailwindRuntime === "function") {
|
|
176
|
+
const next = await refreshTailwindRuntime({ clearCache });
|
|
177
|
+
if (next !== getTailwindRuntime(state)) setTailwindRuntime(state, next);
|
|
148
178
|
refreshed = true;
|
|
149
179
|
}
|
|
150
|
-
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(state
|
|
151
|
-
debug$
|
|
180
|
+
if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(getTailwindRuntime(state));
|
|
181
|
+
debug$2("refresh runtime state end, refreshed=%s major=%s", refreshed, getTailwindRuntime(state).majorVersion ?? "unknown");
|
|
152
182
|
return refreshed;
|
|
153
183
|
}
|
|
154
184
|
async function ensureRuntimeClassSet(state, options = {}) {
|
|
@@ -162,7 +192,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
162
192
|
});
|
|
163
193
|
await state.readyPromise;
|
|
164
194
|
const entry = getRuntimeClassSetStateEntry(state);
|
|
165
|
-
const signature = await
|
|
195
|
+
const signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
166
196
|
const signatureChanged = entry.signature !== signature;
|
|
167
197
|
const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
|
|
168
198
|
if (!shouldForceCollect) {
|
|
@@ -170,7 +200,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
170
200
|
if (entry.promise) return entry.promise;
|
|
171
201
|
}
|
|
172
202
|
const task = (async () => {
|
|
173
|
-
const collected = await collectRuntimeClassSet(state
|
|
203
|
+
const collected = await collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
174
204
|
force: shouldForceCollect,
|
|
175
205
|
skipRefresh: true,
|
|
176
206
|
clearCache
|
|
@@ -181,7 +211,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
181
211
|
clearCache: true
|
|
182
212
|
});
|
|
183
213
|
await state.readyPromise;
|
|
184
|
-
return collectRuntimeClassSet(state
|
|
214
|
+
return collectRuntimeClassSet(getTailwindRuntime(state), {
|
|
185
215
|
force: true,
|
|
186
216
|
skipRefresh: true,
|
|
187
217
|
clearCache: true
|
|
@@ -191,118 +221,90 @@ async function ensureRuntimeClassSet(state, options = {}) {
|
|
|
191
221
|
try {
|
|
192
222
|
const runtimeSet = await task;
|
|
193
223
|
entry.value = runtimeSet;
|
|
194
|
-
entry.signature = await
|
|
224
|
+
entry.signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
|
|
195
225
|
return runtimeSet;
|
|
196
226
|
} finally {
|
|
197
227
|
if (entry.promise === task) entry.promise = void 0;
|
|
198
228
|
}
|
|
199
229
|
}
|
|
200
|
-
function
|
|
201
|
-
if (
|
|
202
|
-
if (majorVersion === 3) return true;
|
|
203
|
-
if (majorVersion === 4) return true;
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
207
|
-
if (typeof twPatcher.getClassSetSync !== "function") return;
|
|
208
|
-
if (!shouldPreferSync(twPatcher.majorVersion)) return;
|
|
230
|
+
function tryGetRuntimeClassSetSync(tailwindRuntime) {
|
|
231
|
+
if (typeof tailwindRuntime.getClassSetSync !== "function") return;
|
|
209
232
|
try {
|
|
210
|
-
const set =
|
|
233
|
+
const set = tailwindRuntime.getClassSetSync();
|
|
211
234
|
if (set && set.size === 0) return;
|
|
212
235
|
return set;
|
|
213
236
|
} catch (error) {
|
|
214
|
-
|
|
215
|
-
else debug$1("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
237
|
+
debug$2("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
216
238
|
return;
|
|
217
239
|
}
|
|
218
240
|
}
|
|
219
|
-
async function collectTailwindV4GeneratorClassSet(
|
|
241
|
+
async function collectTailwindV4GeneratorClassSet(tailwindRuntime) {
|
|
242
|
+
if (typeof tailwindRuntime.collectContentTokens !== "function") return;
|
|
220
243
|
try {
|
|
221
|
-
const generated = await
|
|
244
|
+
const generated = await require_v4_engine.createTailwindV4Engine(await require_v4_engine.resolveTailwindV4SourceFromRuntime(tailwindRuntime)).generate({
|
|
222
245
|
scanSources: true,
|
|
223
|
-
target: "
|
|
246
|
+
target: "web"
|
|
224
247
|
});
|
|
225
|
-
debug$
|
|
248
|
+
debug$2("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
|
|
226
249
|
return generated.classSet;
|
|
227
250
|
} catch (error) {
|
|
228
|
-
debug$
|
|
251
|
+
debug$2("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
|
|
229
252
|
return;
|
|
230
253
|
}
|
|
231
254
|
}
|
|
232
|
-
async function mergeTailwindV4GeneratorClassSet(
|
|
233
|
-
|
|
234
|
-
const generatorClassSet = await collectTailwindV4GeneratorClassSet(twPatcher);
|
|
255
|
+
async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
|
|
256
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
|
|
235
257
|
if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
|
|
236
258
|
return new Set([...classSet, ...generatorClassSet]);
|
|
237
259
|
}
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
242
|
-
let activePatcher = twPatcher;
|
|
260
|
+
async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
|
|
261
|
+
let activeRuntime = tailwindRuntime;
|
|
243
262
|
if (options.force && !options.skipRefresh) {
|
|
244
|
-
const refresh =
|
|
263
|
+
const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
|
|
245
264
|
if (typeof refresh === "function") try {
|
|
246
265
|
const refreshed = await refresh({ clearCache: options.clearCache === true });
|
|
247
|
-
if (refreshed)
|
|
266
|
+
if (refreshed) activeRuntime = refreshed;
|
|
248
267
|
} catch (error) {
|
|
249
|
-
debug$
|
|
268
|
+
debug$2("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
|
|
250
269
|
}
|
|
251
270
|
}
|
|
252
|
-
const entry =
|
|
253
|
-
const signature = await
|
|
271
|
+
const entry = require_tailwindcss.getRuntimeClassSetCacheEntry(activeRuntime);
|
|
272
|
+
const signature = await require_tailwindcss.getRuntimeClassSetSignatureWithSources(activeRuntime);
|
|
254
273
|
if (!options.force) {
|
|
255
274
|
if (entry.value && entry.signature === signature) return entry.value;
|
|
256
275
|
if (entry.promise) return entry.promise;
|
|
257
276
|
} else entry.value = void 0;
|
|
258
277
|
const task = (async () => {
|
|
259
|
-
await require_v3_engine.ensureTailwindcssRuntimePatch(activePatcher);
|
|
260
|
-
const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
|
|
261
|
-
if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
|
|
262
278
|
const preferExtract = options.force === true;
|
|
263
279
|
try {
|
|
264
|
-
const result = await
|
|
280
|
+
const result = await activeRuntime.extract({ write: false });
|
|
265
281
|
if (result?.classSet) {
|
|
266
282
|
if (result.classSet.size > 0) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return result.classSet;
|
|
270
|
-
}
|
|
271
|
-
const merged = await mergeTailwindV4GeneratorClassSet(activePatcher, result.classSet);
|
|
272
|
-
debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
|
|
283
|
+
const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
|
|
284
|
+
debug$2("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
|
|
273
285
|
return merged;
|
|
274
286
|
}
|
|
275
|
-
if (preferExtract
|
|
276
|
-
|
|
277
|
-
return result.classSet;
|
|
278
|
-
}
|
|
279
|
-
if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
|
|
280
|
-
else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
287
|
+
if (preferExtract) debug$2("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
|
|
288
|
+
else debug$2("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
281
289
|
}
|
|
282
290
|
} catch (error) {
|
|
283
|
-
debug$
|
|
284
|
-
}
|
|
285
|
-
if (activePatcher.majorVersion === 4) {
|
|
286
|
-
const generatorClassSet = await collectTailwindV4GeneratorClassSet(activePatcher);
|
|
287
|
-
if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
|
|
291
|
+
debug$2("extract() failed, fallback to getClassSet(): %O", error);
|
|
288
292
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
const syncSet = tryGetRuntimeClassSetSync(activePatcher);
|
|
293
|
+
const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
|
|
294
|
+
if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
|
|
295
|
+
const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
|
|
294
296
|
if (syncSet) {
|
|
295
|
-
debug$
|
|
297
|
+
debug$2("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
|
|
296
298
|
return syncSet;
|
|
297
299
|
}
|
|
298
300
|
try {
|
|
299
|
-
const fallbackSet = await Promise.resolve(
|
|
301
|
+
const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
|
|
300
302
|
if (fallbackSet) {
|
|
301
|
-
debug$
|
|
303
|
+
debug$2("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
|
|
302
304
|
return fallbackSet;
|
|
303
305
|
}
|
|
304
306
|
} catch (error) {
|
|
305
|
-
debug$
|
|
307
|
+
debug$2("getClassSet() failed, returning empty set: %O", error);
|
|
306
308
|
}
|
|
307
309
|
return /* @__PURE__ */ new Set();
|
|
308
310
|
})();
|
|
@@ -361,8 +363,8 @@ function formatRelativeToBase(targetPath, baseDir) {
|
|
|
361
363
|
if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
|
|
362
364
|
return node_path.default.join(".", relative).replace(/\\/g, "/");
|
|
363
365
|
}
|
|
364
|
-
function logTailwindcssTarget(
|
|
365
|
-
const packageInfo =
|
|
366
|
+
function logTailwindcssTarget(tailwindRuntime, baseDir) {
|
|
367
|
+
const packageInfo = tailwindRuntime?.packageInfo;
|
|
366
368
|
const label = "Weapp-tailwindcss";
|
|
367
369
|
if (!packageInfo?.rootPath) {
|
|
368
370
|
_weapp_tailwindcss_logger.logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? node_process.default.cwd());
|
|
@@ -376,7 +378,7 @@ function logTailwindcssTarget(patcher, baseDir) {
|
|
|
376
378
|
//#endregion
|
|
377
379
|
//#region src/unocss/index.ts
|
|
378
380
|
function normalizeUnocssOptions(unocss) {
|
|
379
|
-
return
|
|
381
|
+
return require_v4_engine.resolveBooleanObjectOption(unocss, {});
|
|
380
382
|
}
|
|
381
383
|
function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
|
|
382
384
|
const baseArbitraryValues = arbitraryValues ?? {};
|
|
@@ -395,10 +397,28 @@ function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
|
|
|
395
397
|
const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
396
398
|
const AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
397
399
|
const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
|
|
400
|
+
const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
|
|
401
|
+
const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
|
|
398
402
|
const globalCacheHolder = globalThis;
|
|
399
403
|
const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
400
404
|
const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
|
|
401
405
|
const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
|
|
406
|
+
function resolveCompilerContextCacheMax(defaultValue) {
|
|
407
|
+
const raw = Number.parseInt(node_process.default.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
|
|
408
|
+
if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
|
|
409
|
+
return Math.floor(raw);
|
|
410
|
+
}
|
|
411
|
+
function touchMapValue(map, key, value) {
|
|
412
|
+
map.delete(key);
|
|
413
|
+
map.set(key, value);
|
|
414
|
+
}
|
|
415
|
+
function pruneMapToMaxSize(map, maxSize) {
|
|
416
|
+
while (map.size > maxSize) {
|
|
417
|
+
const firstKey = map.keys().next().value;
|
|
418
|
+
if (firstKey === void 0) break;
|
|
419
|
+
map.delete(firstKey);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
402
422
|
function withCircularGuard(value, stack, factory) {
|
|
403
423
|
if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
|
|
404
424
|
stack.add(value);
|
|
@@ -568,7 +588,8 @@ function createCompilerContextCacheKey(opts) {
|
|
|
568
588
|
const cached = keyStore.get(runtimeCacheScopeKey);
|
|
569
589
|
if (cached !== void 0) return cached;
|
|
570
590
|
const cacheKey = (0, _weapp_tailwindcss_shared_node.md5)(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
|
|
571
|
-
keyStore
|
|
591
|
+
touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
|
|
592
|
+
pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
|
|
572
593
|
return cacheKey;
|
|
573
594
|
} catch (error) {
|
|
574
595
|
_weapp_tailwindcss_logger.logger.debug("skip compiler context cache: %O", error);
|
|
@@ -579,10 +600,16 @@ function withCompilerContextCache(opts, factory) {
|
|
|
579
600
|
const cacheKey = createCompilerContextCacheKey(opts);
|
|
580
601
|
if (cacheKey) {
|
|
581
602
|
const cached = compilerContextCache.get(cacheKey);
|
|
582
|
-
if (cached)
|
|
603
|
+
if (cached) {
|
|
604
|
+
touchMapValue(compilerContextCache, cacheKey, cached);
|
|
605
|
+
return cached;
|
|
606
|
+
}
|
|
583
607
|
}
|
|
584
608
|
const ctx = factory();
|
|
585
|
-
if (cacheKey)
|
|
609
|
+
if (cacheKey) {
|
|
610
|
+
touchMapValue(compilerContextCache, cacheKey, ctx);
|
|
611
|
+
pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
|
|
612
|
+
}
|
|
586
613
|
return ctx;
|
|
587
614
|
}
|
|
588
615
|
//#endregion
|
|
@@ -713,7 +740,7 @@ function replaceWxml(original, options = {
|
|
|
713
740
|
const { keepEOL, escapeMap, ignoreHead } = options;
|
|
714
741
|
let res = original;
|
|
715
742
|
if (!keepEOL) res = res.replaceAll(NEWLINE_RE, "");
|
|
716
|
-
res = (0, _weapp_core_escape.escape)(res,
|
|
743
|
+
res = (0, _weapp_core_escape.escape)(res, require_v4_engine.omitUndefined({
|
|
717
744
|
map: escapeMap,
|
|
718
745
|
ignoreHead
|
|
719
746
|
}));
|
|
@@ -934,7 +961,7 @@ function getReplacement(candidate, escapeMap, store = getReplacementCacheStore(e
|
|
|
934
961
|
}
|
|
935
962
|
//#endregion
|
|
936
963
|
//#region src/js/handlers.ts
|
|
937
|
-
const debug =
|
|
964
|
+
const debug$1 = createDebug("[js:handlers] ");
|
|
938
965
|
const WEAPP_TW_IGNORE_MARKER = "weapp-tw";
|
|
939
966
|
const IGNORE_MARKER = "ignore";
|
|
940
967
|
function hasIgnoreComment(node) {
|
|
@@ -946,6 +973,19 @@ function hasIgnoreComment(node) {
|
|
|
946
973
|
}
|
|
947
974
|
return false;
|
|
948
975
|
}
|
|
976
|
+
function isConditionTestLiteral(path) {
|
|
977
|
+
let current = path;
|
|
978
|
+
while (current?.parentPath) {
|
|
979
|
+
const parent = current.parentPath;
|
|
980
|
+
if (parent.isConditionalExpression()) return parent.node.test === current.node;
|
|
981
|
+
if (parent.isBinaryExpression() || parent.isCallExpression() || parent.isLogicalExpression() || parent.isMemberExpression() || parent.isUnaryExpression()) {
|
|
982
|
+
current = parent;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
949
989
|
function extractLiteralValue(path, { unescapeUnicode }) {
|
|
950
990
|
const { node } = path;
|
|
951
991
|
let offset = 0;
|
|
@@ -1011,10 +1051,11 @@ function replaceHandleValue(path, options) {
|
|
|
1011
1051
|
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
1012
1052
|
if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) return;
|
|
1013
1053
|
if (hasIgnoreComment(path.node)) return;
|
|
1054
|
+
if (isConditionTestLiteral(path)) return;
|
|
1014
1055
|
const { literal, original, offset } = extractLiteralValue(path, options);
|
|
1015
|
-
const candidates = (0,
|
|
1056
|
+
const candidates = (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal);
|
|
1016
1057
|
if (candidates.length === 0) return;
|
|
1017
|
-
const debugEnabled = debug.enabled;
|
|
1058
|
+
const debugEnabled = debug$1.enabled;
|
|
1018
1059
|
const classContext = options.wrapExpression || isClassContextLiteralPath(path);
|
|
1019
1060
|
let transformed = literal;
|
|
1020
1061
|
let mutated = false;
|
|
@@ -1050,7 +1091,7 @@ function replaceHandleValue(path, options) {
|
|
|
1050
1091
|
}
|
|
1051
1092
|
const node = path.node;
|
|
1052
1093
|
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") return;
|
|
1053
|
-
if (debugEnabled) debug("runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s", classNameSet?.size ?? 0, fallbackDecisionCount > 0, candidates.length, matchedCandidateCount, escapedDecisionCount, skippedSamples?.length ?? 0, options.filename ?? "unknown", escapedSamples?.join(",") || "-", skippedSamples?.join(",") || "-");
|
|
1094
|
+
if (debugEnabled) debug$1("runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s", classNameSet?.size ?? 0, fallbackDecisionCount > 0, candidates.length, matchedCandidateCount, escapedDecisionCount, skippedSamples?.length ?? 0, options.filename ?? "unknown", escapedSamples?.join(",") || "-", skippedSamples?.join(",") || "-");
|
|
1054
1095
|
const start = node.start + offset;
|
|
1055
1096
|
const end = node.end - offset;
|
|
1056
1097
|
if (start >= end || transformed === original) return;
|
|
@@ -2026,6 +2067,198 @@ function jsHandler(rawSource, options) {
|
|
|
2026
2067
|
}
|
|
2027
2068
|
defaultEvalHandler = jsHandler;
|
|
2028
2069
|
//#endregion
|
|
2070
|
+
//#region src/js/literal-transform.ts
|
|
2071
|
+
function transformLiteralText(literal, options) {
|
|
2072
|
+
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
2073
|
+
if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
|
|
2074
|
+
const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
|
|
2075
|
+
const candidates = (0, _tailwindcss_mangle_engine.splitCandidateTokens)(source);
|
|
2076
|
+
if (candidates.length === 0) return;
|
|
2077
|
+
const transformOptions = {
|
|
2078
|
+
...options,
|
|
2079
|
+
classContext: true
|
|
2080
|
+
};
|
|
2081
|
+
const replacementCache = getReplacementCacheStore(options.escapeMap);
|
|
2082
|
+
let transformed = source;
|
|
2083
|
+
let mutated = false;
|
|
2084
|
+
for (const candidate of candidates) {
|
|
2085
|
+
const result = resolveClassNameTransformWithResult(candidate, transformOptions);
|
|
2086
|
+
if (result.decision === "skip" || !transformed.includes(candidate)) continue;
|
|
2087
|
+
const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
|
|
2088
|
+
const replaced = transformed.replace(candidate, replacement);
|
|
2089
|
+
if (replaced !== transformed) {
|
|
2090
|
+
transformed = replaced;
|
|
2091
|
+
mutated = true;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return mutated ? transformed : void 0;
|
|
2095
|
+
}
|
|
2096
|
+
//#endregion
|
|
2097
|
+
//#region src/js/fast-path/oxc.ts
|
|
2098
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2099
|
+
let oxcParser;
|
|
2100
|
+
let oxcWalker;
|
|
2101
|
+
function isOxcParserRuntimeSupported(version = node_process.default.versions.node) {
|
|
2102
|
+
const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
|
|
2103
|
+
if (!match) return false;
|
|
2104
|
+
const major = Number(match[1]);
|
|
2105
|
+
const minor = Number(match[2]);
|
|
2106
|
+
if (major === 20) return minor >= 19;
|
|
2107
|
+
if (major === 21) return false;
|
|
2108
|
+
if (major === 22) return minor >= 12;
|
|
2109
|
+
return major > 22;
|
|
2110
|
+
}
|
|
2111
|
+
function loadOxcParser() {
|
|
2112
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2113
|
+
if (oxcParser === false) return;
|
|
2114
|
+
if (oxcParser) return oxcParser;
|
|
2115
|
+
try {
|
|
2116
|
+
oxcParser = require$1("oxc-parser");
|
|
2117
|
+
} catch {
|
|
2118
|
+
oxcParser = false;
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
return oxcParser;
|
|
2122
|
+
}
|
|
2123
|
+
function loadOxcWalker() {
|
|
2124
|
+
if (!isOxcParserRuntimeSupported()) return;
|
|
2125
|
+
if (oxcWalker === false) return;
|
|
2126
|
+
if (oxcWalker) return oxcWalker;
|
|
2127
|
+
try {
|
|
2128
|
+
oxcWalker = require$1("oxc-walker");
|
|
2129
|
+
} catch {
|
|
2130
|
+
oxcWalker = false;
|
|
2131
|
+
return;
|
|
2132
|
+
}
|
|
2133
|
+
return oxcWalker;
|
|
2134
|
+
}
|
|
2135
|
+
function hasValues(values) {
|
|
2136
|
+
return Array.isArray(values) && values.length > 0;
|
|
2137
|
+
}
|
|
2138
|
+
function hasUnsupportedSourceMarker(rawSource) {
|
|
2139
|
+
return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
|
|
2140
|
+
}
|
|
2141
|
+
function hasSupportedClassMatchSource(options) {
|
|
2142
|
+
return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
|
|
2143
|
+
}
|
|
2144
|
+
function canUseOxcJsFastPath(options) {
|
|
2145
|
+
if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
|
|
2146
|
+
return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
|
|
2147
|
+
}
|
|
2148
|
+
function getParserLang(filename) {
|
|
2149
|
+
if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
|
|
2150
|
+
if (filename?.endsWith(".tsx")) return "tsx";
|
|
2151
|
+
if (filename?.endsWith(".jsx")) return "jsx";
|
|
2152
|
+
return "js";
|
|
2153
|
+
}
|
|
2154
|
+
function getParserSourceType(sourceType) {
|
|
2155
|
+
return sourceType === "script" || sourceType === "module" ? sourceType : "module";
|
|
2156
|
+
}
|
|
2157
|
+
function isRangeValid(start, end) {
|
|
2158
|
+
return typeof start === "number" && typeof end === "number" && start < end;
|
|
2159
|
+
}
|
|
2160
|
+
function getMagicString(rawSource, context) {
|
|
2161
|
+
if (!context.ms) context.ms = new magic_string.default(rawSource);
|
|
2162
|
+
return context.ms;
|
|
2163
|
+
}
|
|
2164
|
+
function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
|
|
2165
|
+
if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2166
|
+
const transformed = transformLiteralText(node.value, transformOptions);
|
|
2167
|
+
if (!transformed) return false;
|
|
2168
|
+
const start = node.start + 1;
|
|
2169
|
+
const end = node.end - 1;
|
|
2170
|
+
if (start >= end || transformed === rawSource.slice(start, end)) return false;
|
|
2171
|
+
getMagicString(rawSource, context).update(start, end, (0, _ast_core_escape.jsStringEscape)(transformed));
|
|
2172
|
+
return true;
|
|
2173
|
+
}
|
|
2174
|
+
function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
|
|
2175
|
+
const raw = node.value?.raw;
|
|
2176
|
+
if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
|
|
2177
|
+
const transformed = transformLiteralText(raw, transformOptions);
|
|
2178
|
+
if (!transformed || transformed === raw) return false;
|
|
2179
|
+
const first = rawSource[node.start];
|
|
2180
|
+
const last = rawSource[node.end - 1];
|
|
2181
|
+
const start = node.start + (first === "`" || first === "}" ? 1 : 0);
|
|
2182
|
+
const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
|
|
2183
|
+
if (start >= end) return false;
|
|
2184
|
+
getMagicString(rawSource, context).update(start, end, transformed);
|
|
2185
|
+
return true;
|
|
2186
|
+
}
|
|
2187
|
+
function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
|
|
2188
|
+
let changed = false;
|
|
2189
|
+
walker.walk(program, { enter(node) {
|
|
2190
|
+
if (node.type === "Literal") {
|
|
2191
|
+
changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (node.type === "TemplateElement") {
|
|
2195
|
+
changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
|
|
2196
|
+
this.skip();
|
|
2197
|
+
}
|
|
2198
|
+
} });
|
|
2199
|
+
return changed;
|
|
2200
|
+
}
|
|
2201
|
+
function oxcJsHandler(rawSource, options) {
|
|
2202
|
+
if (!canUseOxcJsFastPath(options)) return;
|
|
2203
|
+
if (hasUnsupportedSourceMarker(rawSource)) return;
|
|
2204
|
+
const parser = loadOxcParser();
|
|
2205
|
+
const walker = loadOxcWalker();
|
|
2206
|
+
if (!parser || !walker) return;
|
|
2207
|
+
let result;
|
|
2208
|
+
try {
|
|
2209
|
+
result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
|
|
2210
|
+
sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
|
|
2211
|
+
lang: getParserLang(options.filename)
|
|
2212
|
+
});
|
|
2213
|
+
} catch {
|
|
2214
|
+
return;
|
|
2215
|
+
}
|
|
2216
|
+
if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
|
|
2217
|
+
const stringLiteralOptions = options.needEscaped === true ? options : {
|
|
2218
|
+
...options,
|
|
2219
|
+
needEscaped: true
|
|
2220
|
+
};
|
|
2221
|
+
const templateLiteralOptions = options.needEscaped === false ? options : {
|
|
2222
|
+
...options,
|
|
2223
|
+
needEscaped: false
|
|
2224
|
+
};
|
|
2225
|
+
const replacementContext = {};
|
|
2226
|
+
if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
|
|
2227
|
+
return { code: replacementContext.ms.toString() };
|
|
2228
|
+
}
|
|
2229
|
+
//#endregion
|
|
2230
|
+
//#region src/js/precheck.ts
|
|
2231
|
+
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
2232
|
+
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)-/;
|
|
2233
|
+
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
2234
|
+
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
2235
|
+
/**
|
|
2236
|
+
* 判断源码是否可能声明跨模块依赖。
|
|
2237
|
+
*
|
|
2238
|
+
* 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
|
|
2239
|
+
* 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
|
|
2240
|
+
*/
|
|
2241
|
+
function hasDependencyHint(rawSource) {
|
|
2242
|
+
return DEPENDENCY_HINT_RE.test(rawSource);
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* 判断是否可以跳过 JS 转换。
|
|
2246
|
+
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
2247
|
+
*
|
|
2248
|
+
* @param rawSource - 原始 JS 源码字符串
|
|
2249
|
+
* @param options - 可选的 JS 处理器配置选项
|
|
2250
|
+
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
2251
|
+
*/
|
|
2252
|
+
function shouldSkipJsTransform(rawSource, options) {
|
|
2253
|
+
if (node_process.default.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
2254
|
+
if (!rawSource) return true;
|
|
2255
|
+
if (options?.alwaysEscape) return false;
|
|
2256
|
+
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
2257
|
+
if (options?.wrapExpression) return false;
|
|
2258
|
+
if (hasDependencyHint(rawSource)) return false;
|
|
2259
|
+
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
2260
|
+
}
|
|
2261
|
+
//#endregion
|
|
2029
2262
|
//#region src/js/index.ts
|
|
2030
2263
|
/** 默认 LRU 缓存最大条目数 */
|
|
2031
2264
|
const RESULT_CACHE_MAX = 512;
|
|
@@ -2070,6 +2303,7 @@ function getOptionsFingerprint(options) {
|
|
|
2070
2303
|
JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
|
|
2071
2304
|
JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
|
|
2072
2305
|
JSON.stringify(options.moduleSpecifierReplacements ?? null),
|
|
2306
|
+
String(options.experimentalJsFastPath ?? ""),
|
|
2073
2307
|
JSON.stringify(options.babelParserOptions ?? null)
|
|
2074
2308
|
].join("|");
|
|
2075
2309
|
fingerprintCache.set(options, fingerprint);
|
|
@@ -2085,6 +2319,13 @@ function shouldCacheJsResult(rawSource, options) {
|
|
|
2085
2319
|
if (options.moduleGraph || options.filename) return false;
|
|
2086
2320
|
return true;
|
|
2087
2321
|
}
|
|
2322
|
+
function resolveFastPathOptions(rawSource, options) {
|
|
2323
|
+
if (!options.moduleGraph) return options;
|
|
2324
|
+
if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
|
|
2325
|
+
if (hasDependencyHint(rawSource)) return options;
|
|
2326
|
+
const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
|
|
2327
|
+
return fastPathOptions;
|
|
2328
|
+
}
|
|
2088
2329
|
function createJsHandler(options) {
|
|
2089
2330
|
const defaults = {
|
|
2090
2331
|
escapeMap: options.escapeMap,
|
|
@@ -2097,6 +2338,7 @@ function createJsHandler(options) {
|
|
|
2097
2338
|
alwaysEscape: options.alwaysEscape,
|
|
2098
2339
|
unescapeUnicode: options.unescapeUnicode,
|
|
2099
2340
|
babelParserOptions: options.babelParserOptions,
|
|
2341
|
+
experimentalJsFastPath: options.experimentalJsFastPath,
|
|
2100
2342
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
2101
2343
|
ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
|
|
2102
2344
|
uniAppX: options.uniAppX,
|
|
@@ -2165,7 +2407,7 @@ function createJsHandler(options) {
|
|
|
2165
2407
|
const resolvedOptions = resolveOptions(classNameSet, options);
|
|
2166
2408
|
const cached = getCachedJsResult(rawSource, resolvedOptions);
|
|
2167
2409
|
if (cached) return cached;
|
|
2168
|
-
return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
|
|
2410
|
+
return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
|
|
2169
2411
|
}
|
|
2170
2412
|
return handler;
|
|
2171
2413
|
}
|
|
@@ -4539,7 +4781,7 @@ const DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
|
4539
4781
|
//#endregion
|
|
4540
4782
|
//#region src/context/runtime-package-replacements.ts
|
|
4541
4783
|
function resolveRuntimePackageReplacements(option) {
|
|
4542
|
-
const mapping =
|
|
4784
|
+
const mapping = require_v4_engine.resolveBooleanObjectOption(option, DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS);
|
|
4543
4785
|
if (!mapping) return;
|
|
4544
4786
|
const normalized = {};
|
|
4545
4787
|
for (const [from, to] of Object.entries(mapping)) {
|
|
@@ -4550,8 +4792,19 @@ function resolveRuntimePackageReplacements(option) {
|
|
|
4550
4792
|
}
|
|
4551
4793
|
//#endregion
|
|
4552
4794
|
//#region src/context/style-options.ts
|
|
4553
|
-
function resolveStyleOptionsFromContext(ctx) {
|
|
4795
|
+
function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
|
|
4554
4796
|
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX);
|
|
4797
|
+
const branch = require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
|
|
4798
|
+
appType: ctx.appType,
|
|
4799
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4800
|
+
tailwindcssMajorVersion,
|
|
4801
|
+
uniAppX: resolvedUniAppXOptions
|
|
4802
|
+
}), {
|
|
4803
|
+
appType: ctx.appType,
|
|
4804
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4805
|
+
tailwindcssMajorVersion,
|
|
4806
|
+
uniAppX: resolvedUniAppXOptions
|
|
4807
|
+
});
|
|
4555
4808
|
const hasCssOptions = ctx.cssOptions !== void 0;
|
|
4556
4809
|
const cssOptions = {
|
|
4557
4810
|
cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
|
|
@@ -4566,13 +4819,14 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4566
4819
|
atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
|
|
4567
4820
|
autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
|
|
4568
4821
|
cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
|
|
4569
|
-
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
4822
|
+
platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
|
|
4570
4823
|
px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
|
|
4571
4824
|
unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
|
|
4572
4825
|
unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
|
|
4573
4826
|
injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
|
|
4574
4827
|
};
|
|
4575
4828
|
return {
|
|
4829
|
+
appType: ctx.appType,
|
|
4576
4830
|
cssPreflight: cssOptions.cssPreflight,
|
|
4577
4831
|
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
4578
4832
|
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
@@ -4586,7 +4840,7 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4586
4840
|
atRules: cssOptions.atRules,
|
|
4587
4841
|
autoprefixer: cssOptions.autoprefixer,
|
|
4588
4842
|
cssCalc: cssOptions.cssCalc,
|
|
4589
|
-
uniAppX:
|
|
4843
|
+
uniAppX: branch.isNativeApp,
|
|
4590
4844
|
platform: cssOptions.platform,
|
|
4591
4845
|
px2rpx: cssOptions.px2rpx,
|
|
4592
4846
|
unitsToPx: cssOptions.unitsToPx,
|
|
@@ -4596,9 +4850,9 @@ function resolveStyleOptionsFromContext(ctx) {
|
|
|
4596
4850
|
//#endregion
|
|
4597
4851
|
//#region src/context/handlers.ts
|
|
4598
4852
|
function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
|
|
4599
|
-
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4853
|
+
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
4600
4854
|
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
|
|
4601
|
-
const styleOptions = resolveStyleOptionsFromContext(ctx);
|
|
4855
|
+
const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
|
|
4602
4856
|
const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
|
|
4603
4857
|
const uniAppXEnabled = styleOptions.uniAppX === true;
|
|
4604
4858
|
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
@@ -4619,6 +4873,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
4619
4873
|
tailwindcssMajorVersion,
|
|
4620
4874
|
generateMap: true,
|
|
4621
4875
|
babelParserOptions,
|
|
4876
|
+
experimentalJsFastPath,
|
|
4622
4877
|
ignoreCallExpressionIdentifiers,
|
|
4623
4878
|
ignoreTaggedTemplateExpressionIdentifiers,
|
|
4624
4879
|
uniAppX: uniAppXEnabled,
|
|
@@ -4652,7 +4907,7 @@ function applyLoggerLevel(logLevel) {
|
|
|
4652
4907
|
function resolveContextCssPreflight(opts, ctx, majorVersion) {
|
|
4653
4908
|
const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
|
|
4654
4909
|
const cssPreflight = require_defaults.resolveDefaultCssPreflight(userCssPreflight, majorVersion);
|
|
4655
|
-
if (
|
|
4910
|
+
if (cssPreflight === false || !require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX).enabled) return cssPreflight;
|
|
4656
4911
|
const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
|
|
4657
4912
|
return {
|
|
4658
4913
|
...cssPreflight,
|
|
@@ -4705,20 +4960,20 @@ function syncLegacyFieldsToCssOptions(ctx) {
|
|
|
4705
4960
|
injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
|
|
4706
4961
|
};
|
|
4707
4962
|
}
|
|
4708
|
-
async function
|
|
4709
|
-
if (!
|
|
4710
|
-
const cacheOptions =
|
|
4963
|
+
async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
|
|
4964
|
+
if (!tailwindRuntime) return;
|
|
4965
|
+
const cacheOptions = tailwindRuntime.options?.cache;
|
|
4711
4966
|
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
|
|
4712
|
-
if (typeof
|
|
4713
|
-
await
|
|
4967
|
+
if (typeof tailwindRuntime.clearCache === "function") try {
|
|
4968
|
+
await tailwindRuntime.clearCache({ scope: "all" });
|
|
4714
4969
|
} catch (error) {
|
|
4715
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss
|
|
4970
|
+
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
|
|
4716
4971
|
}
|
|
4717
4972
|
if (!options?.removeDirectory) return;
|
|
4718
4973
|
const cachePaths = /* @__PURE__ */ new Map();
|
|
4719
4974
|
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
4720
4975
|
if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
|
|
4721
|
-
const privateCachePath =
|
|
4976
|
+
const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
|
|
4722
4977
|
if (privateCachePath) cachePaths.set(privateCachePath, false);
|
|
4723
4978
|
if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
|
|
4724
4979
|
if (!cachePaths.size) return;
|
|
@@ -4730,7 +4985,7 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
4730
4985
|
} catch (error) {
|
|
4731
4986
|
const err = error;
|
|
4732
4987
|
if (err?.code === "ENOENT") continue;
|
|
4733
|
-
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss
|
|
4988
|
+
_weapp_tailwindcss_logger.logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
|
|
4734
4989
|
}
|
|
4735
4990
|
}
|
|
4736
4991
|
function createInternalCompilerContext(opts) {
|
|
@@ -4739,32 +4994,32 @@ function createInternalCompilerContext(opts) {
|
|
|
4739
4994
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
4740
4995
|
syncCssOptionsToLegacyFields(ctx);
|
|
4741
4996
|
applyLoggerLevel(ctx.logLevel);
|
|
4742
|
-
const
|
|
4743
|
-
logTailwindcssTarget(
|
|
4744
|
-
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir,
|
|
4745
|
-
if (opts?.__internalDeferMissingCssEntriesWarning !== true) require_tailwindcss.warnMissingCssEntries(ctx,
|
|
4746
|
-
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx,
|
|
4747
|
-
const cssCalcOptions = require_tailwindcss.applyV4CssCalcDefaults(ctx.cssCalc,
|
|
4997
|
+
const tailwindRuntime = require_tailwindcss.createTailwindcssRuntimeFromContext(ctx);
|
|
4998
|
+
logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
|
|
4999
|
+
logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
|
|
5000
|
+
if (opts?.__internalDeferMissingCssEntriesWarning !== true) require_tailwindcss.warnMissingCssEntries(ctx, tailwindRuntime);
|
|
5001
|
+
ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
|
|
5002
|
+
const cssCalcOptions = require_tailwindcss.applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
|
|
4748
5003
|
ctx.cssCalc = cssCalcOptions;
|
|
4749
5004
|
syncLegacyFieldsToCssOptions(ctx);
|
|
4750
|
-
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions,
|
|
5005
|
+
const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
|
|
4751
5006
|
ctx.styleHandler = styleHandler;
|
|
4752
5007
|
ctx.jsHandler = jsHandler;
|
|
4753
5008
|
ctx.templateHandler = templateHandler;
|
|
4754
5009
|
ctx.cache = initializeCache(ctx.cache);
|
|
4755
|
-
ctx.
|
|
4756
|
-
const
|
|
4757
|
-
const
|
|
4758
|
-
if (options?.clearCache !== false) await
|
|
4759
|
-
|
|
4760
|
-
const
|
|
4761
|
-
Object.assign(
|
|
4762
|
-
ctx.
|
|
4763
|
-
return
|
|
5010
|
+
ctx.tailwindRuntime = tailwindRuntime;
|
|
5011
|
+
const refreshTailwindcssRuntime = async (options) => {
|
|
5012
|
+
const previousRuntime = ctx.tailwindRuntime;
|
|
5013
|
+
if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
|
|
5014
|
+
require_tailwindcss.invalidateRuntimeClassSet(previousRuntime);
|
|
5015
|
+
const nextRuntime = require_tailwindcss.createTailwindcssRuntimeFromContext(ctx);
|
|
5016
|
+
Object.assign(previousRuntime, nextRuntime);
|
|
5017
|
+
ctx.tailwindRuntime = previousRuntime;
|
|
5018
|
+
return previousRuntime;
|
|
4764
5019
|
};
|
|
4765
|
-
ctx.
|
|
4766
|
-
Object.defineProperty(ctx.
|
|
4767
|
-
value:
|
|
5020
|
+
ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
|
|
5021
|
+
Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
|
|
5022
|
+
value: refreshTailwindcssRuntime,
|
|
4768
5023
|
configurable: true
|
|
4769
5024
|
});
|
|
4770
5025
|
return ctx;
|
|
@@ -4778,29 +5033,6 @@ function getCompilerContext(opts) {
|
|
|
4778
5033
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
4779
5034
|
}
|
|
4780
5035
|
//#endregion
|
|
4781
|
-
//#region src/js/precheck.ts
|
|
4782
|
-
/** 用于检测源码中是否包含类名相关模式的正则表达式 */
|
|
4783
|
-
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)-/;
|
|
4784
|
-
/** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
|
|
4785
|
-
const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
4786
|
-
/**
|
|
4787
|
-
* 判断是否可以跳过 JS 转换。
|
|
4788
|
-
* 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
|
|
4789
|
-
*
|
|
4790
|
-
* @param rawSource - 原始 JS 源码字符串
|
|
4791
|
-
* @param options - 可选的 JS 处理器配置选项
|
|
4792
|
-
* @returns 如果可以跳过转换返回 `true`,否则返回 `false`
|
|
4793
|
-
*/
|
|
4794
|
-
function shouldSkipJsTransform(rawSource, options) {
|
|
4795
|
-
if (node_process.default.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
|
|
4796
|
-
if (!rawSource) return true;
|
|
4797
|
-
if (options?.alwaysEscape) return false;
|
|
4798
|
-
if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
|
|
4799
|
-
if (options?.wrapExpression) return false;
|
|
4800
|
-
if (DEPENDENCY_HINT_RE.test(rawSource)) return false;
|
|
4801
|
-
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
4802
|
-
}
|
|
4803
|
-
//#endregion
|
|
4804
5036
|
Object.defineProperty(exports, "JsTokenUpdater", {
|
|
4805
5037
|
enumerable: true,
|
|
4806
5038
|
get: function() {
|
|
@@ -4843,6 +5075,12 @@ Object.defineProperty(exports, "createAttributeMatcher", {
|
|
|
4843
5075
|
return createAttributeMatcher;
|
|
4844
5076
|
}
|
|
4845
5077
|
});
|
|
5078
|
+
Object.defineProperty(exports, "createDebug", {
|
|
5079
|
+
enumerable: true,
|
|
5080
|
+
get: function() {
|
|
5081
|
+
return createDebug;
|
|
5082
|
+
}
|
|
5083
|
+
});
|
|
4846
5084
|
Object.defineProperty(exports, "createTailwindRuntimeReadyPromise", {
|
|
4847
5085
|
enumerable: true,
|
|
4848
5086
|
get: function() {
|