weapp-tailwindcss 5.1.10 → 5.1.12

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 (54) hide show
  1. package/dist/cache-options-DavPxrhC.js +16 -0
  2. package/dist/cache-options-DwBtLwQe.mjs +5 -0
  3. package/dist/cli.js +10 -6
  4. package/dist/cli.mjs +10 -6
  5. package/dist/context-DRRgW7i2.js +1311 -0
  6. package/dist/context-xSJE588m.mjs +1234 -0
  7. package/dist/core.js +1 -1
  8. package/dist/core.mjs +1 -1
  9. package/dist/css-macro.js +1 -1
  10. package/dist/css-macro.mjs +1 -1
  11. package/dist/defaults.js +119 -5
  12. package/dist/defaults.mjs +114 -1
  13. package/dist/{generator-ROzBodj6.mjs → generator-BvPcmqxU.mjs} +9 -139
  14. package/dist/{generator-Bz94KTkH.js → generator-CS10c9g1.js} +18 -154
  15. package/dist/generator.js +1 -1
  16. package/dist/generator.mjs +1 -1
  17. package/dist/{gulp-BKqMb_Ds.mjs → gulp-BEOzXrbp.mjs} +5 -4
  18. package/dist/{gulp-DfOLvYLs.js → gulp-DNZZvUMq.js} +6 -5
  19. package/dist/gulp.js +1 -1
  20. package/dist/gulp.mjs +1 -1
  21. package/dist/{hmr-timing-DOTdH18A.js → hmr-timing-DW1g3zjl.js} +17 -15
  22. package/dist/{hmr-timing-DwtYJdwb.mjs → hmr-timing-hRhRAjYV.mjs} +5 -3
  23. package/dist/index.js +4 -4
  24. package/dist/index.mjs +4 -4
  25. package/dist/object-BJSWl-E5.mjs +9 -0
  26. package/dist/object-COs_Mw6p.js +14 -0
  27. package/dist/postcss.js +1 -1
  28. package/dist/postcss.mjs +1 -1
  29. package/dist/presets.js +5 -5
  30. package/dist/presets.mjs +3 -3
  31. package/dist/rspack.js +1 -1
  32. package/dist/rspack.mjs +1 -1
  33. package/dist/{source-candidate-scan-signature-BrWuBTjY.js → source-candidate-scan-signature-CMgu5bJk.js} +6 -6
  34. package/dist/{source-candidate-scan-signature-CQ04hiox.mjs → source-candidate-scan-signature-t4XKAQ04.mjs} +3 -3
  35. package/dist/{tailwindcss-hzy_WaC9.mjs → tailwindcss-DZT_pWrd.mjs} +132 -2
  36. package/dist/{tailwindcss-Dn5DVlkI.js → tailwindcss-z9JMF-qU.js} +140 -10
  37. package/dist/{transform-DZQETx51.js → transform-COFRlmDF.js} +13 -13
  38. package/dist/{transform-BgnNYkIG.mjs → transform-D5JUgMpE.mjs} +1 -1
  39. package/dist/{utils-D3h8j7Mk.js → utils-CuKLf1Zv.js} +0 -15
  40. package/dist/{utils-DodxWHGz.mjs → utils-MVwpU07P.mjs} +1 -8
  41. package/dist/{vite-BimHmlSp.mjs → vite-DF1gE6a5.mjs} +36 -30
  42. package/dist/{vite-bztpcI8_.js → vite-VGfkFQkC.js} +51 -45
  43. package/dist/vite.js +1 -1
  44. package/dist/vite.mjs +1 -1
  45. package/dist/weapp-tw-css-import-rewrite-loader.js +6 -2
  46. package/dist/{webpack-CCapGlNg.mjs → webpack-CTYm19zA.mjs} +22 -16
  47. package/dist/{webpack-XxBCIrBp.js → webpack-CzXjfvYS.js} +28 -22
  48. package/dist/webpack.js +1 -1
  49. package/dist/webpack.mjs +1 -1
  50. package/dist/{context-y2BGCok4.js → wxml-Ce10eREX.js} +37 -1286
  51. package/dist/{context-DzkSFEVL.mjs → wxml-DdGdeqaH.mjs} +13 -1235
  52. package/package.json +2 -2
  53. package/dist/defaults-9B6aMyZb.mjs +0 -118
  54. package/dist/defaults-nsf4VNMX.js +0 -154
@@ -1,17 +1,7 @@
1
- import { resolveMpxPlatform } from "./framework.mjs";
2
- import { D as resolveBooleanObjectOption, Ft as loadTailwindV4DesignSystem, It as resolveValidTailwindV4Candidates$1, Mt as resolveCssMacroTailwindV4Source, Pt as omitUndefined, a as resolveGeneratorRuntimeBranch, gt as createTailwindV4Engine$1, i as normalizeWeappTailwindcssGeneratorOptions, u as resolveTailwindV4SourceFromRuntime } from "./generator-ROzBodj6.mjs";
3
- import { i as isMap, n as defuOverrideArray } from "./utils-DodxWHGz.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-9B6aMyZb.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-hzy_WaC9.mjs";
6
- import { createRequire } from "node:module";
7
- import path from "node:path";
8
- import process from "node:process";
1
+ import { t as omitUndefined } from "./object-BJSWl-E5.mjs";
2
+ import { n as HARD_PARSE_CACHE_MAX_ENTRIES, t as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH } from "./cache-options-DwBtLwQe.mjs";
9
3
  import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
10
- import { createStyleHandler } from "@weapp-tailwindcss/postcss";
11
4
  import { LRUCache } from "lru-cache";
12
- import { rm } from "node:fs/promises";
13
- import { Buffer } from "node:buffer";
14
- import { logger, pc } from "@weapp-tailwindcss/logger";
15
5
  import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
16
6
  import { MappingChars2String, escape } from "@weapp-core/escape";
17
7
  import _createDebug from "debug";
@@ -19,116 +9,6 @@ import _babelTraverse from "@babel/traverse";
19
9
  import { parse, parseExpression } from "@babel/parser";
20
10
  import MagicString from "magic-string";
21
11
  import * as t from "@babel/types";
22
- //#region src/cache/index.ts
23
- function isProcessResult(value) {
24
- return typeof value === "object" && value !== null && "result" in value;
25
- }
26
- function createCache(options) {
27
- const disabled = options === false;
28
- const hashMap = /* @__PURE__ */ new Map();
29
- const instance = new LRUCache({
30
- max: 1024,
31
- ttl: 0,
32
- ttlAutopurge: false
33
- });
34
- const cache = {
35
- hashMap,
36
- instance,
37
- hasHashKey(key) {
38
- return hashMap.has(key);
39
- },
40
- getHashValue(key) {
41
- return hashMap.get(key);
42
- },
43
- setHashValue(key, value) {
44
- return hashMap.set(key, value);
45
- },
46
- get(key) {
47
- return instance.get(key);
48
- },
49
- set(key, value) {
50
- return instance.set(key, value);
51
- },
52
- computeHash(message) {
53
- return md5Hash(message);
54
- },
55
- calcHashValueChanged(key, hash) {
56
- const hit = hashMap.get(key);
57
- if (hit) hashMap.set(key, {
58
- changed: hash !== hit.hash,
59
- hash
60
- });
61
- else hashMap.set(key, {
62
- changed: true,
63
- hash
64
- });
65
- return cache;
66
- },
67
- pruneHashKeys(hashKeys) {
68
- const activeHashKeys = new Set(hashKeys);
69
- for (const key of hashMap.keys()) if (!activeHashKeys.has(key)) hashMap.delete(key);
70
- },
71
- prune(options) {
72
- if (options.cacheKeys) {
73
- const cacheKeys = new Set(options.cacheKeys);
74
- for (const key of instance.keys()) if (!cacheKeys.has(key)) instance.delete(key);
75
- }
76
- if (options.hashKeys) cache.pruneHashKeys?.(options.hashKeys);
77
- },
78
- has(key) {
79
- return instance.has(key);
80
- },
81
- async process({ key, hashKey, rawSource, hash, resolveCache, transform, onCacheHit }) {
82
- if (disabled) {
83
- const value = await transform();
84
- return isProcessResult(value) ? value.result : value;
85
- }
86
- const cacheHashKey = hashKey ?? key;
87
- let hasChanged = true;
88
- if (hash != null || rawSource != null) {
89
- const nextHash = hash ?? cache.computeHash(rawSource);
90
- cache.calcHashValueChanged(cacheHashKey, nextHash);
91
- hasChanged = cache.getHashValue(cacheHashKey)?.changed ?? true;
92
- }
93
- const readCache = resolveCache ?? (() => cache.get(key));
94
- if (!hasChanged) {
95
- const cached = readCache();
96
- if (cached !== void 0) {
97
- await onCacheHit?.(cached);
98
- return cached;
99
- }
100
- }
101
- const value = await transform();
102
- const normalized = isProcessResult(value) ? value : { result: value };
103
- const stored = normalized.cacheValue ?? normalized.result;
104
- cache.set(key, stored);
105
- return normalized.result;
106
- }
107
- };
108
- return cache;
109
- }
110
- function initializeCache(cacheConfig) {
111
- if (typeof cacheConfig === "boolean" || cacheConfig === void 0) return createCache(cacheConfig);
112
- return cacheConfig;
113
- }
114
- //#endregion
115
- //#region src/framework/platform.ts
116
- const MPX_TO_UNI_PLATFORM = {
117
- ali: "mp-alipay",
118
- dd: "mp-dingtalk",
119
- jd: "mp-jd",
120
- qq: "mp-qq",
121
- swan: "mp-baidu",
122
- tt: "mp-toutiao",
123
- wx: "mp-weixin"
124
- };
125
- function normalizeFrameworkStylePlatform(platform, appType) {
126
- const normalized = platform?.trim().toLowerCase();
127
- if (!normalized) return;
128
- if (appType === "mpx") return MPX_TO_UNI_PLATFORM[normalized] ?? normalized;
129
- return normalized;
130
- }
131
- //#endregion
132
12
  //#region src/debug/index.ts
133
13
  const _debug = _createDebug("weapp-tw");
134
14
  function createDebug(prefix) {
@@ -145,491 +25,6 @@ function createDebug(prefix) {
145
25
  return debug;
146
26
  }
147
27
  //#endregion
148
- //#region src/tailwindcss/runtime.ts
149
- const debug$1 = createDebug("[tailwindcss:runtime] ");
150
- const refreshTailwindcssRuntimeSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssRuntime");
151
- function createTailwindRuntimeReadyPromise(tailwindRuntime) {
152
- return Promise.resolve().then(async () => {
153
- invalidateRuntimeClassSet(tailwindRuntime);
154
- });
155
- }
156
- const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
157
- function getRuntimeClassSetStateEntry(state) {
158
- let entry = runtimeClassSetStateCache.get(state);
159
- if (!entry) {
160
- entry = {};
161
- runtimeClassSetStateCache.set(state, entry);
162
- }
163
- return entry;
164
- }
165
- function getTailwindRuntime(state) {
166
- return state.tailwindRuntime;
167
- }
168
- function setTailwindRuntime(state, runtime) {
169
- state.tailwindRuntime = runtime;
170
- }
171
- function getRefreshTailwindRuntime(state) {
172
- return state.refreshTailwindcssRuntime;
173
- }
174
- async function refreshTailwindRuntimeState(state, forceOrOptions) {
175
- const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
176
- const force = normalizedOptions.force;
177
- const clearCache = normalizedOptions.clearCache === true;
178
- if (!force) return false;
179
- debug$1("refresh runtime state start, clearCache=%s major=%s", clearCache, getTailwindRuntime(state).majorVersion ?? "unknown");
180
- await state.readyPromise;
181
- let refreshed = false;
182
- const refreshTailwindRuntime = getRefreshTailwindRuntime(state);
183
- if (typeof refreshTailwindRuntime === "function") {
184
- const next = await refreshTailwindRuntime({ clearCache });
185
- if (next !== getTailwindRuntime(state)) setTailwindRuntime(state, next);
186
- refreshed = true;
187
- }
188
- if (refreshed) state.readyPromise = createTailwindRuntimeReadyPromise(getTailwindRuntime(state));
189
- debug$1("refresh runtime state end, refreshed=%s major=%s", refreshed, getTailwindRuntime(state).majorVersion ?? "unknown");
190
- return refreshed;
191
- }
192
- async function ensureRuntimeClassSet(state, options = {}) {
193
- const forceRefresh = options.forceRefresh === true;
194
- const forceCollect = options.forceCollect === true;
195
- const clearCache = options.clearCache === true;
196
- const allowEmpty = options.allowEmpty === true;
197
- if (forceRefresh) await refreshTailwindRuntimeState(state, {
198
- force: true,
199
- clearCache
200
- });
201
- await state.readyPromise;
202
- const entry = getRuntimeClassSetStateEntry(state);
203
- const signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
204
- const signatureChanged = entry.signature !== signature;
205
- const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
206
- if (!shouldForceCollect) {
207
- if (entry.value && (allowEmpty || entry.value.size > 0)) return entry.value;
208
- if (entry.promise) return entry.promise;
209
- }
210
- const task = (async () => {
211
- const collected = await collectRuntimeClassSet(getTailwindRuntime(state), {
212
- force: shouldForceCollect,
213
- skipRefresh: true,
214
- clearCache
215
- });
216
- if (allowEmpty || collected.size > 0) return collected;
217
- await refreshTailwindRuntimeState(state, {
218
- force: true,
219
- clearCache: true
220
- });
221
- await state.readyPromise;
222
- return collectRuntimeClassSet(getTailwindRuntime(state), {
223
- force: true,
224
- skipRefresh: true,
225
- clearCache: true
226
- });
227
- })();
228
- entry.promise = task;
229
- try {
230
- const runtimeSet = await task;
231
- entry.value = runtimeSet;
232
- entry.signature = await getRuntimeClassSetSignatureWithSources(getTailwindRuntime(state));
233
- return runtimeSet;
234
- } finally {
235
- if (entry.promise === task) entry.promise = void 0;
236
- }
237
- }
238
- function tryGetRuntimeClassSetSync(tailwindRuntime) {
239
- if (typeof tailwindRuntime.getClassSetSync !== "function") return;
240
- try {
241
- const set = tailwindRuntime.getClassSetSync();
242
- if (set && set.size === 0) return;
243
- return set;
244
- } catch (error) {
245
- debug$1("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
246
- return;
247
- }
248
- }
249
- async function collectTailwindV4GeneratorClassSet(tailwindRuntime) {
250
- if (typeof tailwindRuntime.collectContentTokens !== "function") return;
251
- try {
252
- const source = resolveCssMacroTailwindV4Source(await resolveTailwindV4SourceFromRuntime(tailwindRuntime));
253
- const generated = await createTailwindV4Engine$1(source).generate({
254
- scanSources: true,
255
- target: "web"
256
- });
257
- const classSet = resolveValidTailwindV4Candidates$1(await loadTailwindV4DesignSystem(source), generated.classSet, { ...source.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: source.bareArbitraryValues } });
258
- debug$1("runtime class set resolved via tailwindcss v4 generator source scan, raw=%d valid=%d", generated.classSet.size, classSet.size);
259
- return classSet;
260
- } catch (error) {
261
- debug$1("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
262
- return;
263
- }
264
- }
265
- async function mergeTailwindV4GeneratorClassSet(tailwindRuntime, classSet) {
266
- const generatorClassSet = await collectTailwindV4GeneratorClassSet(tailwindRuntime).catch(() => void 0);
267
- if (!generatorClassSet || generatorClassSet.size === 0) return classSet;
268
- return /* @__PURE__ */ new Set([...classSet, ...generatorClassSet]);
269
- }
270
- async function collectRuntimeClassSet(tailwindRuntime, options = {}) {
271
- let activeRuntime = tailwindRuntime;
272
- if (options.force && !options.skipRefresh) {
273
- const refresh = activeRuntime[refreshTailwindcssRuntimeSymbol];
274
- if (typeof refresh === "function") try {
275
- const refreshed = await refresh({ clearCache: options.clearCache === true });
276
- if (refreshed) activeRuntime = refreshed;
277
- } catch (error) {
278
- debug$1("refreshTailwindcssRuntime failed, continuing with existing runtime: %O", error);
279
- }
280
- }
281
- const entry = getRuntimeClassSetCacheEntry(activeRuntime);
282
- const signature = await getRuntimeClassSetSignatureWithSources(activeRuntime);
283
- if (!options.force) {
284
- if (entry.value && entry.signature === signature) return entry.value;
285
- if (entry.promise) return entry.promise;
286
- } else entry.value = void 0;
287
- const task = (async () => {
288
- const preferExtract = options.force === true;
289
- try {
290
- const result = await activeRuntime.extract({ write: false });
291
- if (result?.classSet) {
292
- if (result.classSet.size > 0) {
293
- const merged = await mergeTailwindV4GeneratorClassSet(activeRuntime, result.classSet);
294
- debug$1("runtime class set resolved via extract() + tailwindcss v4 source scan, extract=%d merged=%d", result.classSet.size, merged.size);
295
- return merged;
296
- }
297
- if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
298
- else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
299
- }
300
- } catch (error) {
301
- debug$1("extract() failed, fallback to getClassSet(): %O", error);
302
- }
303
- const generatorClassSet = await collectTailwindV4GeneratorClassSet(activeRuntime);
304
- if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
305
- const syncSet = tryGetRuntimeClassSetSync(activeRuntime);
306
- if (syncSet) {
307
- debug$1("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
308
- return syncSet;
309
- }
310
- try {
311
- const fallbackSet = await Promise.resolve(activeRuntime.getClassSet());
312
- if (fallbackSet) {
313
- debug$1("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
314
- return fallbackSet;
315
- }
316
- } catch (error) {
317
- debug$1("getClassSet() failed, returning empty set: %O", error);
318
- }
319
- return /* @__PURE__ */ new Set();
320
- })();
321
- entry.promise = task;
322
- entry.signature = signature;
323
- try {
324
- const resolved = await task;
325
- entry.value = resolved;
326
- entry.promise = void 0;
327
- entry.signature = signature;
328
- return resolved;
329
- } catch (error) {
330
- entry.promise = void 0;
331
- throw error;
332
- }
333
- }
334
- //#endregion
335
- //#region src/tailwindcss/runtime-logs.ts
336
- const runtimeLogDedupeHolder = globalThis;
337
- const runtimeLogDedupe = runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set());
338
- function createRuntimeLogKey(category, baseDir, rootPath, version) {
339
- return JSON.stringify([
340
- category,
341
- baseDir ?? process.cwd(),
342
- rootPath ?? "",
343
- version ?? ""
344
- ]);
345
- }
346
- function markRuntimeLog(category, baseDir, rootPath, version) {
347
- const key = createRuntimeLogKey(category, baseDir, rootPath, version);
348
- if (runtimeLogDedupe.has(key)) return false;
349
- runtimeLogDedupe.add(key);
350
- return true;
351
- }
352
- function logRuntimeTailwindcssTarget(baseDir, rootPath, version) {
353
- if (!markRuntimeLog("target", baseDir, rootPath, version)) return;
354
- const versionText = version ? ` (v${version})` : "";
355
- logger.info("%s 使用 Tailwind CSS%s", "Weapp-tailwindcss", versionText);
356
- }
357
- function logRuntimeTailwindcssVersion(baseDir, rootPath, version) {
358
- if (version) {
359
- if (!markRuntimeLog("version", baseDir, rootPath, version)) return;
360
- logger.success(`当前使用 ${pc.cyanBright("Tailwind CSS")} 版本为: ${pc.underline(pc.bold(pc.green(version)))}`);
361
- return;
362
- }
363
- if (!markRuntimeLog("missing", baseDir, rootPath, version)) return;
364
- logger.warn(`${pc.cyanBright("Tailwind CSS")} 未安装,已跳过版本检测与运行时初始化。`);
365
- }
366
- //#endregion
367
- //#region src/tailwindcss/targets.ts
368
- function formatRelativeToBase(targetPath, baseDir) {
369
- const normalized = path.normalize(targetPath);
370
- if (!baseDir) return normalized.replace(/\\/g, "/");
371
- const relative = path.relative(baseDir, normalized);
372
- if (!relative || relative === ".") return ".";
373
- if (relative.startsWith("..")) return normalized.replace(/\\/g, "/");
374
- return path.join(".", relative).replace(/\\/g, "/");
375
- }
376
- function logTailwindcssTarget(tailwindRuntime, baseDir) {
377
- const packageInfo = tailwindRuntime?.packageInfo;
378
- const label = "Weapp-tailwindcss";
379
- if (!packageInfo?.rootPath) {
380
- logger.warn("%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss", label, baseDir ?? process.cwd());
381
- return;
382
- }
383
- const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
384
- const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
385
- logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
386
- logger.debug("%s 解析 Tailwind CSS -> %s%s", label, displayPath, version);
387
- }
388
- //#endregion
389
- //#region src/unocss/index.ts
390
- function normalizeUnocssOptions(unocss) {
391
- return resolveBooleanObjectOption(unocss, {});
392
- }
393
- function resolveUnocssBareArbitraryValues(arbitraryValues, unocss) {
394
- const baseArbitraryValues = arbitraryValues ?? {};
395
- const options = normalizeUnocssOptions(unocss);
396
- if (!options) return baseArbitraryValues;
397
- if (baseArbitraryValues.bareArbitraryValues !== void 0 && baseArbitraryValues.bareArbitraryValues !== false) return baseArbitraryValues;
398
- const bareArbitraryValues = options.bareArbitraryValues ?? true;
399
- if (bareArbitraryValues === false) return baseArbitraryValues;
400
- return {
401
- ...baseArbitraryValues,
402
- bareArbitraryValues
403
- };
404
- }
405
- //#endregion
406
- //#region src/context/compiler-context-cache.ts
407
- const PAREN_CONTENT_RE = /\(([^)]+)\)/u;
408
- const AT_LOCATION_RE = /at\s+(\S.*)$/u;
409
- const TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
410
- const DEFAULT_COMPILER_CONTEXT_CACHE_MAX = 32;
411
- const DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX = DEFAULT_COMPILER_CONTEXT_CACHE_MAX * 2;
412
- const globalCacheHolder = globalThis;
413
- const compilerContextCache = globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
414
- const compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
415
- const compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
416
- function resolveCompilerContextCacheMax(defaultValue) {
417
- const raw = Number.parseInt(process.env["WEAPP_TW_COMPILER_CONTEXT_CACHE_MAX"] ?? "", 10);
418
- if (!Number.isFinite(raw) || raw <= 0) return defaultValue;
419
- return Math.floor(raw);
420
- }
421
- function touchMapValue(map, key, value) {
422
- map.delete(key);
423
- map.set(key, value);
424
- }
425
- function pruneMapToMaxSize(map, maxSize) {
426
- while (map.size > maxSize) {
427
- const firstKey = map.keys().next().value;
428
- if (firstKey === void 0) break;
429
- map.delete(firstKey);
430
- }
431
- }
432
- function withCircularGuard(value, stack, factory) {
433
- if (stack.has(value)) throw new TypeError("Cannot serialize circular structure in compiler context options");
434
- stack.add(value);
435
- try {
436
- return factory();
437
- } finally {
438
- stack.delete(value);
439
- }
440
- }
441
- function encodeTaggedValue(type, value) {
442
- const record = { __type: type };
443
- if (value !== void 0) record["value"] = value;
444
- return record;
445
- }
446
- function hasExplicitOptionBasedir(opts) {
447
- return typeof opts?.tailwindcssBasedir === "string" && opts.tailwindcssBasedir.length > 0;
448
- }
449
- function shouldProbeCallerLocation(opts) {
450
- if (hasExplicitOptionBasedir(opts)) return false;
451
- return !(process.env["WEAPP_TAILWINDCSS_BASEDIR"] || process.env["WEAPP_TAILWINDCSS_BASE_DIR"] || process.env["TAILWINDCSS_BASEDIR"] || process.env["TAILWINDCSS_BASE_DIR"]);
452
- }
453
- function detectCallerLocation() {
454
- const stack = (/* @__PURE__ */ new Error("compiler-context-cache stack probe")).stack;
455
- if (!stack) return;
456
- const lines = stack.split("\n");
457
- for (const line of lines) {
458
- const location = (line.match(PAREN_CONTENT_RE) ?? line.match(AT_LOCATION_RE))?.[1];
459
- if (!location) continue;
460
- const candidatePath = location.replace(TRAILING_LINE_COL_RE, "");
461
- if (!candidatePath || !path.isAbsolute(candidatePath)) continue;
462
- if (candidatePath.includes(`${path.sep}weapp-tailwindcss${path.sep}src${path.sep}`) || candidatePath.includes(`${path.sep}weapp-tailwindcss${path.sep}dist${path.sep}`) || candidatePath.includes(`${path.sep}node_modules${path.sep}weapp-tailwindcss${path.sep}`)) continue;
463
- return candidatePath;
464
- }
465
- }
466
- function getRuntimeCacheScope(opts) {
467
- if (hasExplicitOptionBasedir(opts)) return { caller: void 0 };
468
- const runtimeScope = {
469
- caller: void 0,
470
- cwd: process.cwd(),
471
- init_cwd: process.env["INIT_CWD"],
472
- npm_config_local_prefix: process.env["npm_config_local_prefix"],
473
- npm_package_json: process.env["npm_package_json"],
474
- pnpm_package_name: process.env["PNPM_PACKAGE_NAME"],
475
- pwd: process.env["PWD"],
476
- tailwindcss_base_dir: process.env["TAILWINDCSS_BASE_DIR"],
477
- tailwindcss_basedir: process.env["TAILWINDCSS_BASEDIR"],
478
- uni_app_input_dir: process.env["UNI_APP_INPUT_DIR"],
479
- uni_cli_root: process.env["UNI_CLI_ROOT"],
480
- uni_input_dir: process.env["UNI_INPUT_DIR"],
481
- uni_input_root: process.env["UNI_INPUT_ROOT"],
482
- weapp_tailwindcss_base_dir: process.env["WEAPP_TAILWINDCSS_BASE_DIR"],
483
- weapp_tailwindcss_basedir: process.env["WEAPP_TAILWINDCSS_BASEDIR"]
484
- };
485
- if (shouldProbeCallerLocation(opts)) runtimeScope.caller = detectCallerLocation();
486
- return runtimeScope;
487
- }
488
- function serializeNormalizedValue(value) {
489
- return JSON.stringify(value);
490
- }
491
- function createRuntimeCacheScopeKey(opts) {
492
- return serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScope(opts)));
493
- }
494
- function getCompilerContextKeyCacheStore(opts) {
495
- if (!opts) return compilerContextKeyCacheWithoutOptions;
496
- let store = compilerContextKeyCacheByOptions.get(opts);
497
- if (!store) {
498
- store = /* @__PURE__ */ new Map();
499
- compilerContextKeyCacheByOptions.set(opts, store);
500
- }
501
- return store;
502
- }
503
- function createComparableNormalizedValue(rawValue, stack) {
504
- const normalized = normalizeOptionsValue(rawValue, stack);
505
- return {
506
- normalized,
507
- sortKey: serializeNormalizedValue(normalized)
508
- };
509
- }
510
- function getRuntimeCacheScopeValue(opts) {
511
- return {
512
- options: opts ?? {},
513
- runtime: getRuntimeCacheScope(opts)
514
- };
515
- }
516
- function normalizeOptionsValue(rawValue, stack = /* @__PURE__ */ new WeakSet()) {
517
- if (rawValue === null) return null;
518
- if (rawValue === void 0) return encodeTaggedValue("Undefined");
519
- const type = typeof rawValue;
520
- if (type === "string") return rawValue;
521
- if (type === "boolean") return rawValue;
522
- if (type === "number") {
523
- const numericValue = rawValue;
524
- if (Number.isNaN(numericValue)) return encodeTaggedValue("Number", "NaN");
525
- if (!Number.isFinite(numericValue)) return encodeTaggedValue("Number", numericValue > 0 ? "Infinity" : "-Infinity");
526
- if (Object.is(numericValue, -0)) return encodeTaggedValue("Number", "-0");
527
- return numericValue;
528
- }
529
- if (type === "bigint") return encodeTaggedValue("BigInt", rawValue.toString());
530
- if (type === "symbol") {
531
- const symbolValue = rawValue;
532
- return encodeTaggedValue("Symbol", symbolValue.description ?? String(symbolValue));
533
- }
534
- if (type === "function") return encodeTaggedValue("Function", rawValue.toString());
535
- if (Array.isArray(rawValue)) return withCircularGuard(rawValue, stack, () => rawValue.map((item) => normalizeOptionsValue(item, stack)));
536
- if (rawValue instanceof Date) return encodeTaggedValue("Date", rawValue.toISOString());
537
- if (rawValue instanceof RegExp) return {
538
- __type: "RegExp",
539
- source: rawValue.source,
540
- flags: rawValue.flags
541
- };
542
- if (typeof Buffer !== "undefined" && Buffer.isBuffer(rawValue)) return encodeTaggedValue("Buffer", rawValue.toString("base64"));
543
- if (ArrayBuffer.isView(rawValue)) {
544
- const view = rawValue;
545
- const buffer = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
546
- return encodeTaggedValue(view.constructor?.name ?? "ArrayBufferView", buffer.toString("base64"));
547
- }
548
- if (rawValue instanceof ArrayBuffer) return encodeTaggedValue("ArrayBuffer", Buffer.from(rawValue).toString("base64"));
549
- if (rawValue instanceof Set) return withCircularGuard(rawValue, stack, () => {
550
- const normalizedEntries = Array.from(rawValue, (element) => createComparableNormalizedValue(element, stack));
551
- normalizedEntries.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
552
- return {
553
- __type: "Set",
554
- value: normalizedEntries.map((entry) => entry.normalized)
555
- };
556
- });
557
- if (rawValue instanceof Map) return withCircularGuard(rawValue, stack, () => {
558
- const normalizedEntries = Array.from(rawValue.entries(), ([key, entryValue]) => {
559
- const normalizedKey = createComparableNormalizedValue(key, stack);
560
- return {
561
- key: normalizedKey.normalized,
562
- sortKey: normalizedKey.sortKey,
563
- value: normalizeOptionsValue(entryValue, stack)
564
- };
565
- });
566
- normalizedEntries.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
567
- return {
568
- __type: "Map",
569
- value: normalizedEntries.map((entry) => [entry.key, entry.value])
570
- };
571
- });
572
- if (typeof URL !== "undefined" && rawValue instanceof URL) return encodeTaggedValue("URL", rawValue.toString());
573
- if (rawValue instanceof Error) {
574
- const errorValue = rawValue;
575
- return {
576
- __type: "Error",
577
- name: errorValue.name,
578
- message: errorValue.message,
579
- stack: errorValue.stack ?? ""
580
- };
581
- }
582
- if (rawValue instanceof Promise) return encodeTaggedValue("Promise");
583
- if (rawValue instanceof WeakMap) return encodeTaggedValue("WeakMap");
584
- if (rawValue instanceof WeakSet) return encodeTaggedValue("WeakSet");
585
- if (rawValue && typeof rawValue === "object") return withCircularGuard(rawValue, stack, () => {
586
- const result = {};
587
- const entries = Object.entries(rawValue);
588
- entries.sort(([a], [b]) => a.localeCompare(b));
589
- for (const [key, entryValue] of entries) result[key] = normalizeOptionsValue(entryValue, stack);
590
- return result;
591
- });
592
- return encodeTaggedValue(typeof rawValue, String(rawValue));
593
- }
594
- function createCompilerContextCacheKey(opts) {
595
- try {
596
- const runtimeCacheScopeKey = createRuntimeCacheScopeKey(opts);
597
- const keyStore = getCompilerContextKeyCacheStore(opts);
598
- const cached = keyStore.get(runtimeCacheScopeKey);
599
- if (cached !== void 0) return cached;
600
- const cacheKey = md5Hash(serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScopeValue(opts))));
601
- touchMapValue(keyStore, runtimeCacheScopeKey, cacheKey);
602
- pruneMapToMaxSize(keyStore, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_KEY_CACHE_MAX));
603
- return cacheKey;
604
- } catch (error) {
605
- logger.debug("skip compiler context cache: %O", error);
606
- return;
607
- }
608
- }
609
- function withCompilerContextCache(opts, factory) {
610
- const cacheKey = createCompilerContextCacheKey(opts);
611
- if (cacheKey) {
612
- const cached = compilerContextCache.get(cacheKey);
613
- if (cached) {
614
- touchMapValue(compilerContextCache, cacheKey, cached);
615
- return cached;
616
- }
617
- }
618
- const ctx = factory();
619
- if (cacheKey) {
620
- touchMapValue(compilerContextCache, cacheKey, ctx);
621
- pruneMapToMaxSize(compilerContextCache, resolveCompilerContextCacheMax(DEFAULT_COMPILER_CONTEXT_CACHE_MAX));
622
- }
623
- return ctx;
624
- }
625
- //#endregion
626
- //#region src/context/custom-attributes.ts
627
- function toCustomAttributesEntities(customAttributes) {
628
- if (!customAttributes) return [];
629
- if (isMap(customAttributes)) return [...customAttributes.entries()];
630
- return Object.entries(customAttributes);
631
- }
632
- //#endregion
633
28
  //#region src/babel/index.ts
634
29
  function _interopDefaultCompat(e) {
635
30
  return e && typeof e === "object" && "default" in e ? e.default : e;
@@ -1329,7 +724,7 @@ function walkEvalExpression(path, options, updater, handler) {
1329
724
  }
1330
725
  }
1331
726
  //#endregion
1332
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
727
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
1333
728
  function _typeof(o) {
1334
729
  "@babel/helpers - typeof";
1335
730
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -1339,7 +734,7 @@ function _typeof(o) {
1339
734
  }, _typeof(o);
1340
735
  }
1341
736
  //#endregion
1342
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
737
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
1343
738
  function toPrimitive(t, r) {
1344
739
  if ("object" != _typeof(t) || !t) return t;
1345
740
  var e = t[Symbol.toPrimitive];
@@ -1351,13 +746,13 @@ function toPrimitive(t, r) {
1351
746
  return ("string" === r ? String : Number)(t);
1352
747
  }
1353
748
  //#endregion
1354
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
749
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
1355
750
  function toPropertyKey(t) {
1356
751
  var i = toPrimitive(t, "string");
1357
752
  return "symbol" == _typeof(i) ? i : i + "";
1358
753
  }
1359
754
  //#endregion
1360
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
755
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
1361
756
  function _defineProperty(e, r, t) {
1362
757
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1363
758
  value: t,
@@ -1852,7 +1247,8 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1852
1247
  return false;
1853
1248
  };
1854
1249
  const resolvesMemberExpressionToIgnore = (path, seen) => {
1855
- if (propertyMatches(path.get("property"))) return true;
1250
+ const propertyPath = path.get("property");
1251
+ if (propertyMatches(propertyPath)) return true;
1856
1252
  const objectPath = path.get("object");
1857
1253
  if (objectPath.isIdentifier()) {
1858
1254
  const binding = (objectPath?.scope)?.getBinding?.(objectPath.node.name);
@@ -1919,7 +1315,10 @@ function createTaggedTemplateIgnore({ matcher, names }) {
1919
1315
  return current;
1920
1316
  };
1921
1317
  const evaluateTagPath = (tagPath, seen) => {
1922
- if (tagPath.isCallExpression?.() || tagPath.node.type === "CallExpression") return evaluateTagPath(tagPath.get("callee"), seen);
1318
+ if (tagPath.isCallExpression?.() || tagPath.node.type === "CallExpression") {
1319
+ const calleePath = tagPath.get("callee");
1320
+ return evaluateTagPath(calleePath, seen);
1321
+ }
1923
1322
  if (tagPath.isIdentifier()) {
1924
1323
  if (matchesIgnoreName(tagPath.node.name)) return true;
1925
1324
  const binding = tagPath?.scope?.getBinding?.(tagPath.node.name);
@@ -2101,351 +1500,6 @@ function jsHandler(rawSource, options) {
2101
1500
  }
2102
1501
  defaultEvalHandler = jsHandler;
2103
1502
  //#endregion
2104
- //#region src/js/literal-transform.ts
2105
- function transformLiteralText(literal, options) {
2106
- const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
2107
- if (!options.alwaysEscape && !fallbackEnabled && (!options.classNameSet || options.classNameSet.size === 0)) return;
2108
- const source = options.unescapeUnicode && literal.includes("\\u") ? decodeUnicode2(literal) : literal;
2109
- const candidates = splitCandidateTokens(source);
2110
- if (candidates.length === 0) return;
2111
- const transformOptions = {
2112
- ...options,
2113
- classContext: true
2114
- };
2115
- const replacementCache = getReplacementCacheStore(options.escapeMap);
2116
- let transformed = source;
2117
- let mutated = false;
2118
- for (const candidate of candidates) {
2119
- const result = resolveClassNameTransformWithResult(candidate, transformOptions);
2120
- if (result.decision === "skip" || !transformed.includes(candidate)) continue;
2121
- const replacement = result.decision === "escaped" && result.escapedValue ? result.escapedValue : getReplacement(candidate, options.escapeMap, replacementCache);
2122
- const replaced = transformed.replace(candidate, replacement);
2123
- if (replaced !== transformed) {
2124
- transformed = replaced;
2125
- mutated = true;
2126
- }
2127
- }
2128
- return mutated ? transformed : void 0;
2129
- }
2130
- //#endregion
2131
- //#region src/js/fast-path/oxc.ts
2132
- const require = createRequire(import.meta.url);
2133
- let oxcParser;
2134
- let oxcWalker;
2135
- function isOxcParserRuntimeSupported(version = process.versions.node) {
2136
- const match = /^(\d+)\.(\d+)(?:\.|$)/.exec(version);
2137
- if (!match) return false;
2138
- const major = Number(match[1]);
2139
- const minor = Number(match[2]);
2140
- if (major === 20) return minor >= 19;
2141
- if (major === 21) return false;
2142
- if (major === 22) return minor >= 12;
2143
- return major > 22;
2144
- }
2145
- function loadOxcParser() {
2146
- if (!isOxcParserRuntimeSupported()) return;
2147
- if (oxcParser === false) return;
2148
- if (oxcParser) return oxcParser;
2149
- try {
2150
- oxcParser = require("oxc-parser");
2151
- } catch {
2152
- oxcParser = false;
2153
- return;
2154
- }
2155
- return oxcParser;
2156
- }
2157
- function loadOxcWalker() {
2158
- if (!isOxcParserRuntimeSupported()) return;
2159
- if (oxcWalker === false) return;
2160
- if (oxcWalker) return oxcWalker;
2161
- try {
2162
- oxcWalker = require("oxc-walker");
2163
- } catch {
2164
- oxcWalker = false;
2165
- return;
2166
- }
2167
- return oxcWalker;
2168
- }
2169
- function hasValues(values) {
2170
- return Array.isArray(values) && values.length > 0;
2171
- }
2172
- function hasUnsupportedSourceMarker(rawSource) {
2173
- return rawSource.includes("eval(") || rawSource.includes("weapp-tw") && rawSource.includes("ignore");
2174
- }
2175
- function hasSupportedClassMatchSource(options) {
2176
- return options.alwaysEscape === true || Boolean(options.classNameSet && options.classNameSet.size > 0);
2177
- }
2178
- function canUseOxcJsFastPath(options) {
2179
- if (options.experimentalJsFastPath !== true && options.experimentalJsFastPath !== "oxc") return false;
2180
- return !options.generateMap && !options.wrapExpression && !options.moduleGraph && !options.moduleSpecifierReplacements && hasSupportedClassMatchSource(options) && !shouldEnableArbitraryValueFallback(options) && !hasValues(options.ignoreCallExpressionIdentifiers) && !hasValues(options.ignoreTaggedTemplateExpressionIdentifiers);
2181
- }
2182
- function getParserLang(filename) {
2183
- if (filename?.endsWith(".ts") || filename?.endsWith(".mts") || filename?.endsWith(".cts")) return "ts";
2184
- if (filename?.endsWith(".tsx")) return "tsx";
2185
- if (filename?.endsWith(".jsx")) return "jsx";
2186
- return "js";
2187
- }
2188
- function getParserSourceType(sourceType) {
2189
- return sourceType === "script" || sourceType === "module" ? sourceType : "module";
2190
- }
2191
- function isRangeValid(start, end) {
2192
- return typeof start === "number" && typeof end === "number" && start < end;
2193
- }
2194
- function getMagicString(rawSource, context) {
2195
- if (!context.ms) context.ms = new MagicString(rawSource);
2196
- return context.ms;
2197
- }
2198
- function addStringLiteralReplacement(rawSource, node, transformOptions, context) {
2199
- if (typeof node.value !== "string" || typeof node.raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2200
- const transformed = transformLiteralText(node.value, transformOptions);
2201
- if (!transformed) return false;
2202
- const start = node.start + 1;
2203
- const end = node.end - 1;
2204
- if (start >= end || transformed === rawSource.slice(start, end)) return false;
2205
- getMagicString(rawSource, context).update(start, end, jsStringEscape(transformed));
2206
- return true;
2207
- }
2208
- function addTemplateElementReplacement(rawSource, node, transformOptions, context) {
2209
- const raw = node.value?.raw;
2210
- if (typeof raw !== "string" || !isRangeValid(node.start, node.end)) return false;
2211
- const transformed = transformLiteralText(raw, transformOptions);
2212
- if (!transformed || transformed === raw) return false;
2213
- const first = rawSource[node.start];
2214
- const last = rawSource[node.end - 1];
2215
- const start = node.start + (first === "`" || first === "}" ? 1 : 0);
2216
- const end = node.end - (last === "`" ? 1 : last === "{" ? 2 : 0);
2217
- if (start >= end) return false;
2218
- getMagicString(rawSource, context).update(start, end, transformed);
2219
- return true;
2220
- }
2221
- function applyReplacements(rawSource, program, walker, stringLiteralOptions, templateLiteralOptions, context) {
2222
- let changed = false;
2223
- walker.walk(program, { enter(node) {
2224
- if (node.type === "Literal") {
2225
- changed = addStringLiteralReplacement(rawSource, node, stringLiteralOptions, context) || changed;
2226
- return;
2227
- }
2228
- if (node.type === "TemplateElement") {
2229
- changed = addTemplateElementReplacement(rawSource, node, templateLiteralOptions, context) || changed;
2230
- this.skip();
2231
- }
2232
- } });
2233
- return changed;
2234
- }
2235
- function oxcJsHandler(rawSource, options) {
2236
- if (!canUseOxcJsFastPath(options)) return;
2237
- if (hasUnsupportedSourceMarker(rawSource)) return;
2238
- const parser = loadOxcParser();
2239
- const walker = loadOxcWalker();
2240
- if (!parser || !walker) return;
2241
- let result;
2242
- try {
2243
- result = parser.parseSync(options.filename ?? "weapp-tailwindcss.js", rawSource, {
2244
- sourceType: getParserSourceType(options.babelParserOptions?.sourceType),
2245
- lang: getParserLang(options.filename)
2246
- });
2247
- } catch {
2248
- return;
2249
- }
2250
- if (!result.program || Array.isArray(result.errors) && result.errors.length > 0) return;
2251
- const stringLiteralOptions = options.needEscaped === true ? options : {
2252
- ...options,
2253
- needEscaped: true
2254
- };
2255
- const templateLiteralOptions = options.needEscaped === false ? options : {
2256
- ...options,
2257
- needEscaped: false
2258
- };
2259
- const replacementContext = {};
2260
- if (!applyReplacements(rawSource, result.program, walker, stringLiteralOptions, templateLiteralOptions, replacementContext)) return { code: rawSource };
2261
- return { code: replacementContext.ms.toString() };
2262
- }
2263
- //#endregion
2264
- //#region src/js/precheck.ts
2265
- /** 用于检测源码中是否包含类名相关模式的正则表达式 */
2266
- 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)-/;
2267
- /** 用于检测源码中是否包含 import/export/require 语句的正则表达式 */
2268
- const DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
2269
- /**
2270
- * 判断源码是否可能声明跨模块依赖。
2271
- *
2272
- * 该检查只作为性能预筛:返回 `true` 时必须保守走 AST 模块图分析;
2273
- * 返回 `false` 时源码中没有可被当前模块图消费的静态 import/export/require 形态。
2274
- */
2275
- function hasDependencyHint(rawSource) {
2276
- return DEPENDENCY_HINT_RE.test(rawSource);
2277
- }
2278
- /**
2279
- * 判断是否可以跳过 JS 转换。
2280
- * 通过正则快速检测源码内容,避免不必要的 Babel AST 解析。
2281
- *
2282
- * @param rawSource - 原始 JS 源码字符串
2283
- * @param options - 可选的 JS 处理器配置选项
2284
- * @returns 如果可以跳过转换返回 `true`,否则返回 `false`
2285
- */
2286
- function shouldSkipJsTransform(rawSource, options) {
2287
- if (process.env["WEAPP_TW_DISABLE_JS_PRECHECK"] === "1") return false;
2288
- if (!rawSource) return true;
2289
- if (options?.alwaysEscape) return false;
2290
- if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return false;
2291
- if (options?.wrapExpression) return false;
2292
- if (hasDependencyHint(rawSource)) return false;
2293
- return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
2294
- }
2295
- //#endregion
2296
- //#region src/js/index.ts
2297
- /** 默认 LRU 缓存最大条目数 */
2298
- const RESULT_CACHE_MAX = 512;
2299
- /** 仅对短片段做内层结果缓存,避免 bundler 热路径重复 hash 大块 JS。 */
2300
- const CACHEABLE_SOURCE_MAX_LENGTH = 512;
2301
- /** 为每个 ClassNameSet 实例分配递增 ID */
2302
- const classNameSetIds = /* @__PURE__ */ new WeakMap();
2303
- let nextClassNameSetId = 0;
2304
- /**
2305
- * 获取 ClassNameSet 的唯一身份 ID。
2306
- * 每个 Set 引用分配一个递增整数,用于指纹计算。
2307
- */
2308
- function getClassNameSetId(set) {
2309
- if (!set) return "none";
2310
- const existing = classNameSetIds.get(set);
2311
- if (existing !== void 0) return String(existing);
2312
- const id = nextClassNameSetId++;
2313
- classNameSetIds.set(set, id);
2314
- return String(id);
2315
- }
2316
- /** 缓存 IJsHandlerOptions -> fingerprint 的映射 */
2317
- const fingerprintCache = /* @__PURE__ */ new WeakMap();
2318
- /**
2319
- * 计算选项指纹,包含所有影响转译结果的字段。
2320
- * 不包含 filename、moduleGraph、jsPreserveClass。
2321
- */
2322
- function getOptionsFingerprint(options) {
2323
- const cached = fingerprintCache.get(options);
2324
- if (cached) return cached;
2325
- const fingerprint = [
2326
- getClassNameSetId(options.classNameSet),
2327
- JSON.stringify(options.escapeMap ?? null),
2328
- options.needEscaped ? "1" : "0",
2329
- options.alwaysEscape ? "1" : "0",
2330
- options.unescapeUnicode ? "1" : "0",
2331
- options.generateMap ? "1" : "0",
2332
- options.uniAppX ? "1" : "0",
2333
- options.wrapExpression ? "1" : "0",
2334
- String(options.tailwindcssMajorVersion ?? ""),
2335
- String(options.jsArbitraryValueFallback ?? ""),
2336
- JSON.stringify(options.arbitraryValues ?? null),
2337
- JSON.stringify(options.ignoreCallExpressionIdentifiers ?? null),
2338
- JSON.stringify(options.ignoreTaggedTemplateExpressionIdentifiers?.map((v) => v instanceof RegExp ? v.source : v) ?? null),
2339
- JSON.stringify(options.moduleSpecifierReplacements ?? null),
2340
- String(options.experimentalJsFastPath ?? ""),
2341
- JSON.stringify(options.babelParserOptions ?? null)
2342
- ].join("|");
2343
- fingerprintCache.set(options, fingerprint);
2344
- return fingerprint;
2345
- }
2346
- function hasDefinedOverrides(options) {
2347
- if (!options) return false;
2348
- for (const key in options) if (options[key] !== void 0) return true;
2349
- return false;
2350
- }
2351
- function shouldCacheJsResult(rawSource, options) {
2352
- if (rawSource.length === 0 || rawSource.length > CACHEABLE_SOURCE_MAX_LENGTH) return false;
2353
- if (options.moduleGraph || options.filename) return false;
2354
- return true;
2355
- }
2356
- function resolveFastPathOptions(rawSource, options) {
2357
- if (!options.moduleGraph) return options;
2358
- if (options.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) return options;
2359
- if (hasDependencyHint(rawSource)) return options;
2360
- const { moduleGraph: _moduleGraph, ...fastPathOptions } = options;
2361
- return fastPathOptions;
2362
- }
2363
- function createJsHandler(options) {
2364
- const defaults = {
2365
- escapeMap: options.escapeMap,
2366
- jsArbitraryValueFallback: options.jsArbitraryValueFallback,
2367
- tailwindcssMajorVersion: options.tailwindcssMajorVersion,
2368
- arbitraryValues: options.arbitraryValues,
2369
- jsPreserveClass: options.jsPreserveClass,
2370
- generateMap: options.generateMap,
2371
- needEscaped: options.needEscaped,
2372
- alwaysEscape: options.alwaysEscape,
2373
- unescapeUnicode: options.unescapeUnicode,
2374
- babelParserOptions: options.babelParserOptions,
2375
- experimentalJsFastPath: options.experimentalJsFastPath,
2376
- ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
2377
- ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
2378
- uniAppX: options.uniAppX,
2379
- moduleSpecifierReplacements: options.moduleSpecifierReplacements
2380
- };
2381
- /** 层1: 无 override 时,classNameSet -> resolvedOptions */
2382
- const defaultOptionsCache = /* @__PURE__ */ new WeakMap();
2383
- let resolvedOptionsWithoutClassNameSet;
2384
- /** 层2: 有 override 时,overrideOptions -> { bySet, noSet } */
2385
- const overrideOptionsCache = /* @__PURE__ */ new WeakMap();
2386
- const resultCache = new LRUCache({ max: RESULT_CACHE_MAX });
2387
- function resolveDefaultOptions(classNameSet) {
2388
- if (!classNameSet) {
2389
- if (!resolvedOptionsWithoutClassNameSet) resolvedOptionsWithoutClassNameSet = {
2390
- ...defaults,
2391
- classNameSet
2392
- };
2393
- return resolvedOptionsWithoutClassNameSet;
2394
- }
2395
- const cached = defaultOptionsCache.get(classNameSet);
2396
- if (cached) return cached;
2397
- const created = {
2398
- ...defaults,
2399
- classNameSet
2400
- };
2401
- defaultOptionsCache.set(classNameSet, created);
2402
- return created;
2403
- }
2404
- function getCachedJsResult(rawSource, resolvedOptions) {
2405
- if (!shouldCacheJsResult(rawSource, resolvedOptions)) return;
2406
- const key = `${getOptionsFingerprint(resolvedOptions)}:${md5Hash(rawSource)}`;
2407
- return resultCache.get(key);
2408
- }
2409
- function setCachedJsResult(rawSource, resolvedOptions, result) {
2410
- if (!shouldCacheJsResult(rawSource, resolvedOptions) || result.error || result.linked) return result;
2411
- const key = `${getOptionsFingerprint(resolvedOptions)}:${md5Hash(rawSource)}`;
2412
- resultCache.set(key, result);
2413
- return result;
2414
- }
2415
- function resolveOptions(classNameSet, overrideOptions) {
2416
- if (!hasDefinedOverrides(overrideOptions)) return resolveDefaultOptions(classNameSet);
2417
- let entry = overrideOptionsCache.get(overrideOptions);
2418
- if (!entry) {
2419
- entry = { bySet: /* @__PURE__ */ new WeakMap() };
2420
- overrideOptionsCache.set(overrideOptions, entry);
2421
- }
2422
- if (!classNameSet) {
2423
- if (entry.noSet) return entry.noSet;
2424
- const created = defuOverrideArray({
2425
- ...overrideOptions,
2426
- classNameSet
2427
- }, defaults);
2428
- entry.noSet = created;
2429
- return created;
2430
- }
2431
- const cached = entry.bySet.get(classNameSet);
2432
- if (cached) return cached;
2433
- const created = defuOverrideArray({
2434
- ...overrideOptions,
2435
- classNameSet
2436
- }, defaults);
2437
- entry.bySet.set(classNameSet, created);
2438
- return created;
2439
- }
2440
- function handler(rawSource, classNameSet, options) {
2441
- const resolvedOptions = resolveOptions(classNameSet, options);
2442
- const cached = getCachedJsResult(rawSource, resolvedOptions);
2443
- if (cached) return cached;
2444
- return setCachedJsResult(rawSource, resolvedOptions, oxcJsHandler(rawSource, resolveFastPathOptions(rawSource, resolvedOptions)) ?? jsHandler(rawSource, resolvedOptions));
2445
- }
2446
- return handler;
2447
- }
2448
- //#endregion
2449
1503
  //#region src/wxml/custom-attributes.ts
2450
1504
  function regTest(reg, str) {
2451
1505
  reg.lastIndex = 0;
@@ -4804,280 +3858,4 @@ function createTemplateHandler(options = {}) {
4804
3858
  };
4805
3859
  }
4806
3860
  //#endregion
4807
- //#region src/constants.ts
4808
- const pluginName = "weapp-tailwindcss";
4809
- const vitePluginName = "weapp-tailwindcss:adaptor";
4810
- const DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
4811
- "tailwind-merge": "@weapp-tailwindcss/merge",
4812
- "class-variance-authority": "@weapp-tailwindcss/cva",
4813
- "tailwind-variants": "@weapp-tailwindcss/variants"
4814
- };
4815
- //#endregion
4816
- //#region src/context/runtime-package-replacements.ts
4817
- function resolveRuntimePackageReplacements(option) {
4818
- const mapping = resolveBooleanObjectOption(option, DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS);
4819
- if (!mapping) return;
4820
- const normalized = {};
4821
- for (const [from, to] of Object.entries(mapping)) {
4822
- if (!from || typeof to !== "string" || to.length === 0) continue;
4823
- normalized[from] = to;
4824
- }
4825
- return Object.keys(normalized).length > 0 ? normalized : void 0;
4826
- }
4827
- //#endregion
4828
- //#region src/context/style-options.ts
4829
- function normalizeStyleHandlerMajorVersion(majorVersion) {
4830
- return majorVersion === 4 ? 4 : void 0;
4831
- }
4832
- function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
4833
- const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
4834
- const branch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
4835
- appType: ctx.appType,
4836
- platform: ctx.cssOptions?.platform ?? ctx.platform,
4837
- tailwindcssMajorVersion,
4838
- uniAppX: resolvedUniAppXOptions
4839
- }), {
4840
- appType: ctx.appType,
4841
- platform: ctx.cssOptions?.platform ?? ctx.platform,
4842
- tailwindcssMajorVersion,
4843
- uniAppX: resolvedUniAppXOptions
4844
- });
4845
- const hasCssOptions = ctx.cssOptions !== void 0;
4846
- const cssOptions = {
4847
- cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
4848
- cssPreflightRange: ctx.cssOptions?.cssPreflightRange ?? ctx.cssPreflightRange,
4849
- cssChildCombinatorReplaceValue: ctx.cssOptions?.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue,
4850
- cssSelectorReplacement: ctx.cssOptions?.cssSelectorReplacement ?? ctx.cssSelectorReplacement,
4851
- rem2rpx: ctx.cssOptions?.rem2rpx ?? ctx.rem2rpx,
4852
- cssRemoveProperty: ctx.cssOptions?.cssRemoveProperty ?? ctx.cssRemoveProperty,
4853
- cssRemoveHoverPseudoClass: ctx.cssOptions?.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass,
4854
- tailwindcssV4GradientFallback: ctx.cssOptions?.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback,
4855
- cssPresetEnv: ctx.cssOptions?.cssPresetEnv ?? ctx.cssPresetEnv,
4856
- atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
4857
- autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
4858
- cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
4859
- platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
4860
- px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
4861
- unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
4862
- unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
4863
- injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
4864
- };
4865
- return {
4866
- appType: ctx.appType,
4867
- postcssOptions: ctx.postcssOptions,
4868
- cssPreflight: cssOptions.cssPreflight,
4869
- cssPreflightRange: cssOptions.cssPreflightRange,
4870
- cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
4871
- cssSelectorReplacement: cssOptions.cssSelectorReplacement,
4872
- rem2rpx: cssOptions.rem2rpx,
4873
- ...hasCssOptions ? { cssOptions } : {},
4874
- cssRemoveProperty: cssOptions.cssRemoveProperty,
4875
- cssRemoveHoverPseudoClass: cssOptions.cssRemoveHoverPseudoClass,
4876
- tailwindcssV4GradientFallback: cssOptions.tailwindcssV4GradientFallback,
4877
- cssPresetEnv: cssOptions.cssPresetEnv,
4878
- atRules: cssOptions.atRules,
4879
- autoprefixer: cssOptions.autoprefixer,
4880
- cssCalc: cssOptions.cssCalc,
4881
- uniAppX: branch.isNativeApp,
4882
- platform: cssOptions.platform,
4883
- px2rpx: cssOptions.px2rpx,
4884
- unitsToPx: cssOptions.unitsToPx,
4885
- unitConversion: cssOptions.unitConversion
4886
- };
4887
- }
4888
- //#endregion
4889
- //#region src/context/handlers.ts
4890
- function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
4891
- const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, jsArbitraryValueFallback, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
4892
- const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
4893
- const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
4894
- const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
4895
- const uniAppXEnabled = styleOptions.uniAppX === true;
4896
- const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
4897
- const styleHandler = createStyleHandler({
4898
- ...styleOptions,
4899
- escapeMap,
4900
- injectAdditionalCssVarScope: resolvedInjectAdditionalCssVarScope,
4901
- postcssOptions,
4902
- uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
4903
- cssCalc: cssCalcOptions,
4904
- majorVersion: normalizeStyleHandlerMajorVersion(tailwindcssMajorVersion)
4905
- });
4906
- const jsHandler = createJsHandler({
4907
- escapeMap,
4908
- arbitraryValues,
4909
- jsPreserveClass,
4910
- jsArbitraryValueFallback: jsArbitraryValueFallback ?? "auto",
4911
- tailwindcssMajorVersion,
4912
- generateMap: true,
4913
- babelParserOptions,
4914
- experimentalJsFastPath,
4915
- ignoreCallExpressionIdentifiers,
4916
- ignoreTaggedTemplateExpressionIdentifiers,
4917
- uniAppX: uniAppXEnabled,
4918
- moduleSpecifierReplacements
4919
- });
4920
- return {
4921
- styleHandler,
4922
- jsHandler,
4923
- templateHandler: createTemplateHandler({
4924
- customAttributesEntities,
4925
- escapeMap,
4926
- inlineWxs,
4927
- jsHandler,
4928
- disabledDefaultTemplateHandler
4929
- })
4930
- };
4931
- }
4932
- //#endregion
4933
- //#region src/context/logger.ts
4934
- const loggerLevelMap = {
4935
- error: 0,
4936
- warn: 1,
4937
- info: 3,
4938
- silent: -999
4939
- };
4940
- function applyLoggerLevel(logLevel) {
4941
- logger.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
4942
- }
4943
- //#endregion
4944
- //#region src/context/index.ts
4945
- function resolveContextCssPreflight(opts, ctx, majorVersion) {
4946
- const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
4947
- const cssPreflight = resolveDefaultCssPreflight(userCssPreflight, majorVersion);
4948
- const shouldUseUniAppXPreflight = ctx.appType === "uni-app-x" || resolveUniAppXOptions(ctx.uniAppX).enabled;
4949
- if (cssPreflight === false || !shouldUseUniAppXPreflight) return cssPreflight;
4950
- const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
4951
- return {
4952
- ...cssPreflight,
4953
- "border-width": userCssPreflightObject && "border-width" in userCssPreflightObject ? cssPreflight["border-width"] ?? false : "0",
4954
- "border-style": userCssPreflightObject && "border-style" in userCssPreflightObject ? cssPreflight["border-style"] ?? false : false,
4955
- "border": userCssPreflightObject && "border" in userCssPreflightObject ? cssPreflight["border"] ?? false : false
4956
- };
4957
- }
4958
- function syncCssOptionsToLegacyFields(ctx) {
4959
- if (!ctx.cssOptions) return;
4960
- const cssOptions = ctx.cssOptions;
4961
- ctx.cssPreflight = cssOptions.cssPreflight ?? ctx.cssPreflight;
4962
- ctx.cssPreflightRange = cssOptions.cssPreflightRange ?? ctx.cssPreflightRange;
4963
- ctx.cssChildCombinatorReplaceValue = cssOptions.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue;
4964
- ctx.cssSelectorReplacement = cssOptions.cssSelectorReplacement ?? ctx.cssSelectorReplacement;
4965
- ctx.rem2rpx = cssOptions.rem2rpx ?? ctx.rem2rpx;
4966
- ctx.cssRemoveProperty = cssOptions.cssRemoveProperty ?? ctx.cssRemoveProperty;
4967
- ctx.cssRemoveHoverPseudoClass = cssOptions.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass;
4968
- ctx.tailwindcssV4GradientFallback = cssOptions.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback;
4969
- ctx.cssPresetEnv = cssOptions.cssPresetEnv ?? ctx.cssPresetEnv;
4970
- ctx.atRules = cssOptions.atRules ?? ctx.atRules;
4971
- ctx.autoprefixer = cssOptions.autoprefixer ?? ctx.autoprefixer;
4972
- ctx.cssCalc = cssOptions.cssCalc ?? ctx.cssCalc;
4973
- ctx.platform = cssOptions.platform ?? ctx.platform;
4974
- ctx.px2rpx = cssOptions.px2rpx ?? ctx.px2rpx;
4975
- ctx.unitsToPx = cssOptions.unitsToPx ?? ctx.unitsToPx;
4976
- ctx.unitConversion = cssOptions.unitConversion ?? ctx.unitConversion;
4977
- ctx.injectAdditionalCssVarScope = cssOptions.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope;
4978
- }
4979
- function syncLegacyFieldsToCssOptions(ctx) {
4980
- if (!ctx.cssOptions) return;
4981
- ctx.cssOptions = {
4982
- ...ctx.cssOptions ?? {},
4983
- cssPreflight: ctx.cssPreflight,
4984
- cssPreflightRange: ctx.cssPreflightRange,
4985
- cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
4986
- cssSelectorReplacement: ctx.cssSelectorReplacement,
4987
- rem2rpx: ctx.rem2rpx,
4988
- cssRemoveProperty: ctx.cssRemoveProperty,
4989
- cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
4990
- tailwindcssV4GradientFallback: ctx.tailwindcssV4GradientFallback,
4991
- cssPresetEnv: ctx.cssPresetEnv,
4992
- atRules: ctx.atRules,
4993
- autoprefixer: ctx.autoprefixer,
4994
- cssCalc: ctx.cssCalc,
4995
- platform: ctx.platform,
4996
- px2rpx: ctx.px2rpx,
4997
- unitsToPx: ctx.unitsToPx,
4998
- unitConversion: ctx.unitConversion,
4999
- injectAdditionalCssVarScope: ctx.injectAdditionalCssVarScope
5000
- };
5001
- }
5002
- function applyFrameworkPlatformDefaults(ctx) {
5003
- if (ctx.cssOptions?.platform || ctx.platform) {
5004
- ctx.platform = normalizeFrameworkStylePlatform(ctx.cssOptions?.platform ?? ctx.platform, ctx.appType);
5005
- return;
5006
- }
5007
- if (ctx.appType === "mpx") ctx.platform = normalizeFrameworkStylePlatform(resolveMpxPlatform().normalized, ctx.appType);
5008
- }
5009
- async function clearTailwindcssRuntimeCache(tailwindRuntime, options) {
5010
- if (!tailwindRuntime) return;
5011
- const cacheOptions = tailwindRuntime.options?.cache;
5012
- if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) return;
5013
- if (typeof tailwindRuntime.clearCache === "function") try {
5014
- await tailwindRuntime.clearCache({ scope: "all" });
5015
- } catch (error) {
5016
- logger.debug("failed to clear tailwindcss runtime cache via clearCache(): %O", error);
5017
- }
5018
- if (!options?.removeDirectory) return;
5019
- const cachePaths = /* @__PURE__ */ new Map();
5020
- const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
5021
- const privateCachePath = tailwindRuntime?.cacheStore?.options?.path;
5022
- if (privateCachePath) cachePaths.set(privateCachePath, false);
5023
- if (normalizedCacheOptions?.path) cachePaths.set(normalizedCacheOptions.path, false);
5024
- if (options?.removeDirectory && normalizedCacheOptions?.dir) cachePaths.set(normalizedCacheOptions.dir, true);
5025
- if (!cachePaths.size) return;
5026
- for (const [cachePath, recursive] of cachePaths.entries()) try {
5027
- await rm(cachePath, {
5028
- force: true,
5029
- recursive
5030
- });
5031
- } catch (error) {
5032
- const err = error;
5033
- if (err?.code === "ENOENT") continue;
5034
- logger.debug("failed to clear tailwindcss runtime cache: %s %O", cachePath, err);
5035
- }
5036
- }
5037
- function createInternalCompilerContext(opts) {
5038
- const ctx = defuOverrideArray(opts, getDefaultOptions(), {});
5039
- ctx.arbitraryValues = resolveUnocssBareArbitraryValues(ctx.arbitraryValues, ctx.unocss);
5040
- ctx.escapeMap = ctx.customReplaceDictionary;
5041
- syncCssOptionsToLegacyFields(ctx);
5042
- applyFrameworkPlatformDefaults(ctx);
5043
- applyLoggerLevel(ctx.logLevel);
5044
- const tailwindRuntime = createTailwindcssRuntimeFromContext(ctx);
5045
- logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
5046
- logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
5047
- if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, tailwindRuntime);
5048
- ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
5049
- const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
5050
- ctx.cssCalc = cssCalcOptions;
5051
- syncLegacyFieldsToCssOptions(ctx);
5052
- const { styleHandler, jsHandler, templateHandler } = createHandlersFromContext(ctx, toCustomAttributesEntities(ctx.customAttributes), cssCalcOptions, tailwindRuntime.majorVersion);
5053
- ctx.styleHandler = styleHandler;
5054
- ctx.jsHandler = jsHandler;
5055
- ctx.templateHandler = templateHandler;
5056
- ctx.cache = initializeCache(ctx.cache);
5057
- ctx.tailwindRuntime = tailwindRuntime;
5058
- const refreshTailwindcssRuntime = async (options) => {
5059
- const previousRuntime = ctx.tailwindRuntime;
5060
- if (options?.clearCache !== false) await clearTailwindcssRuntimeCache(previousRuntime);
5061
- invalidateRuntimeClassSet(previousRuntime);
5062
- const nextRuntime = createTailwindcssRuntimeFromContext(ctx);
5063
- Object.assign(previousRuntime, nextRuntime);
5064
- ctx.tailwindRuntime = previousRuntime;
5065
- return previousRuntime;
5066
- };
5067
- ctx.refreshTailwindcssRuntime = refreshTailwindcssRuntime;
5068
- Object.defineProperty(ctx.tailwindRuntime, refreshTailwindcssRuntimeSymbol, {
5069
- value: refreshTailwindcssRuntime,
5070
- configurable: true
5071
- });
5072
- return ctx;
5073
- }
5074
- /**
5075
- * 获取用户定义选项的内部表示,并初始化相关的处理程序和 Tailwind 运行时。
5076
- * @param opts - 用户定义的选项,可选。
5077
- * @returns 返回一个包含内部用户定义选项的对象,包括样式、JS 和模板处理程序,以及 Tailwind CSS 运行时。
5078
- */
5079
- function getCompilerContext(opts) {
5080
- return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
5081
- }
5082
- //#endregion
5083
- export { normalizeFrameworkStylePlatform 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, md5Hash as w, refreshTailwindRuntimeState as x, createTailwindRuntimeReadyPromise as y };
3861
+ export { babelParse as _, analyzeSource as a, md5Hash as b, _defineProperty as c, jsStringEscape as d, isClassContextLiteralPath as f, replaceWxml as g, shouldEnableArbitraryValueFallback as h, createAttributeMatcher as i, getReplacement as l, resolveClassNameTransformWithResult as m, Parser as n, jsHandler as o, decodeUnicode2 as p, generateCode as r, JsTokenUpdater as s, createTemplateHandler as t, getReplacementCacheStore as u, traverse as v, createDebug as y };