weapp-tailwindcss 5.3.6 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +4 -4
  3. package/dist/bundlers/shared/framework-postcss.d.ts +3 -0
  4. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +1 -1
  5. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/types.d.ts +3 -1
  7. package/dist/bundlers/shared/source-candidates/snapshot.d.ts +19 -0
  8. package/dist/bundlers/shared/source-candidates/source-priority.d.ts +1 -0
  9. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +1 -0
  10. package/dist/bundlers/shared/source-candidates/views.d.ts +12 -0
  11. package/dist/bundlers/shared/style-requests.d.ts +1 -0
  12. package/dist/bundlers/vite/bundle-state.d.ts +9 -1
  13. package/dist/bundlers/vite/capability-profile.d.ts +18 -0
  14. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +12 -0
  15. package/dist/bundlers/vite/hot-css-modules.d.ts +2 -2
  16. package/dist/bundlers/vite/shared/configured-css-entry-observer.d.ts +29 -0
  17. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +8 -0
  18. package/dist/bundlers/vite/shared/framework-css-generation-queue.d.ts +1 -0
  19. package/dist/bundlers/vite/shared/framework-hmr-module-version.d.ts +9 -0
  20. package/dist/bundlers/vite/shared/framework-runtime-utils.d.ts +5 -0
  21. package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +12 -2
  22. package/dist/compiler/compilation-session-pool.d.ts +1 -0
  23. package/dist/compiler/framework-compiler-session.d.ts +21 -0
  24. package/dist/compiler/index.d.ts +1 -0
  25. package/dist/{context-DTLRADfE.cjs → compiler-C93NfxSe.cjs} +859 -11
  26. package/dist/{context-4ittVpgt.js → compiler-qDa3phIv.js} +764 -5
  27. package/dist/context/handlers.d.ts +1 -1
  28. package/dist/core/compiler/compiler.d.ts +2 -0
  29. package/dist/core/compiler/generation-cache.d.ts +30 -0
  30. package/dist/core/compiler/generation-state.d.ts +17 -0
  31. package/dist/core/compiler/index.d.ts +2 -0
  32. package/dist/core/compiler/root-store.d.ts +38 -0
  33. package/dist/core/compiler/snapshot.d.ts +35 -0
  34. package/dist/core/compiler/source-fingerprint.d.ts +3 -0
  35. package/dist/core/compiler/transforms.d.ts +15 -0
  36. package/dist/core/compiler/types.d.ts +69 -0
  37. package/dist/core.cjs +9 -8
  38. package/dist/core.d.ts +2 -1
  39. package/dist/core.js +2 -2
  40. package/dist/framework/index.d.ts +3 -1
  41. package/dist/framework.cjs +6 -1
  42. package/dist/framework.js +6 -1
  43. package/dist/{generator-EnTXLBlK.js → generator-C0m2S4WI.js} +3 -2
  44. package/dist/{generator-DKiYbTFR.cjs → generator-CKJ6sj1f.cjs} +3 -2
  45. package/dist/generator.cjs +1 -1
  46. package/dist/generator.js +1 -1
  47. package/dist/{gulp-CUysZjW3.cjs → gulp-CW6JGqVn.cjs} +14 -16
  48. package/dist/{gulp-DwtrU4V1.js → gulp-e2iWsmEK.js} +7 -7
  49. package/dist/gulp.cjs +1 -1
  50. package/dist/gulp.js +1 -1
  51. package/dist/{hmr-timing-utmOgn6p.js → hmr-timing-DgMgwSce.js} +367 -289
  52. package/dist/{hmr-timing-Cvh5UgnM.cjs → hmr-timing-n7QQKFp7.cjs} +4 -4
  53. package/dist/index.cjs +4 -4
  54. package/dist/index.js +4 -4
  55. package/dist/{pipeline-helpers-CyVXL3h6.cjs → pipeline-helpers-DoLQy44Q.cjs} +6 -6
  56. package/dist/postcss.cjs +1 -1
  57. package/dist/postcss.js +1 -1
  58. package/dist/presets.cjs +2 -3
  59. package/dist/presets.js +1 -1
  60. package/dist/rspack.cjs +2 -2
  61. package/dist/rspack.js +2 -2
  62. package/dist/{source-candidate-scan-signature-CDrLxVKu.js → source-candidate-scan-signature-B0lOMiwB.js} +3 -3
  63. package/dist/{source-candidate-scan-signature-BNt7NrrI.cjs → source-candidate-scan-signature-Chb-Zrwt.cjs} +5 -5
  64. package/dist/{tailwindcss-CexDJBhx.cjs → tailwindcss-BGlJ1m1l.cjs} +763 -5
  65. package/dist/{tailwindcss-ChnpCv25.js → tailwindcss-BSKl0FTD.js} +1 -1
  66. package/dist/{transform-CL-UZW1U.cjs → transform-C6k9zTQR.cjs} +12 -4
  67. package/dist/{transform-Bfi1_VgN.js → transform-DQhgAarN.js} +12 -4
  68. package/dist/typedoc.export.d.ts +1 -0
  69. package/dist/types/index.d.ts +1 -0
  70. package/dist/uni-app-x/component-local-style.d.ts +2 -0
  71. package/dist/uni-app-x/transform.d.ts +1 -0
  72. package/dist/uni-app-x/vite/asset-task.d.ts +21 -0
  73. package/dist/uni-app-x/vite/plugin-options.d.ts +8 -0
  74. package/dist/uni-app-x/vite/web-local-style.d.ts +2 -1
  75. package/dist/uni-app-x/vite.d.ts +1 -21
  76. package/dist/{v4-generation-core-Dhsu9Deu.cjs → v4-generation-core-B2sUkkgq.cjs} +378 -300
  77. package/dist/{vite-DMX5zoID.cjs → vite-B0IPgrvM.cjs} +807 -200
  78. package/dist/{vite-DJkhb8n1.js → vite-CcEb2SOl.js} +774 -165
  79. package/dist/vite.cjs +1 -1
  80. package/dist/vite.js +1 -1
  81. package/dist/weapp-tw-css-generation-loader.cjs +1 -1
  82. package/dist/weapp-tw-css-import-rewrite-loader.cjs +7 -7
  83. package/dist/{webpack-Cpy_yggg.cjs → webpack-B5vc13U_.cjs} +33 -35
  84. package/dist/{webpack-CzhrD9p3.js → webpack-BPA5I79o.js} +7 -7
  85. package/dist/webpack.cjs +1 -1
  86. package/dist/webpack.js +1 -1
  87. package/dist/wxml/utils.d.ts +1 -1
  88. package/dist/{wxml-B7OAVpXJ.js → wxml-CvKyV69S.js} +10 -2
  89. package/dist/{wxml-PrK-8ARX.cjs → wxml-o-CUulAM.cjs} +40 -32
  90. package/package.json +12 -11
  91. package/dist/options-BJrtIQbH.cjs +0 -768
  92. package/dist/style-options-DW30H5PV.cjs +0 -82
@@ -1,8 +1,9 @@
1
1
  import { resolveMpxPlatform } from "./framework.js";
2
- import { It as shouldUseUniAppWebRpxCompatibility, Lt as loadTailwindV4DesignSystem, Nt as resolveCssMacroTailwindV4Source, Rt as resolveValidTailwindV4Candidates$1, a as resolveGeneratorRuntimeBranch, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveBooleanObjectOption, yt as createTailwindV4Engine$1 } from "./generator-EnTXLBlK.js";
3
- import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-ChnpCv25.js";
2
+ import { It as shouldUseUniAppWebRpxCompatibility, Lt as loadTailwindV4DesignSystem, Nt as resolveCssMacroTailwindV4Source, Rt as resolveValidTailwindV4Candidates$1, a as resolveGeneratorRuntimeBranch, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveBooleanObjectOption, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source$1, yt as createTailwindV4Engine$1 } from "./generator-C0m2S4WI.js";
3
+ import { n as _defineProperty } from "./object-B-8IHefx.js";
4
+ import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-BSKl0FTD.js";
4
5
  import { i as isMap, n as defuOverrideArray } from "./utils-MVwpU07P.js";
5
- import { _ as md5Hash, a as jsHandler, c as getReplacementCacheStore, d as decodeUnicode2, f as resolveClassNameTransformWithResult, l as jsStringEscape, m as createDebug, s as getReplacement, t as createTemplateHandler } from "./wxml-B7OAVpXJ.js";
6
+ import { _ as md5Hash, a as jsHandler, c as getReplacementCacheStore, d as decodeUnicode2, f as resolveClassNameTransformWithResult, l as jsStringEscape, m as createDebug, s as getReplacement, t as createTemplateHandler } from "./wxml-CvKyV69S.js";
6
7
  import { getDefaultOptions, resolveDefaultCssPreflight } from "./defaults.js";
7
8
  import { createRequire } from "node:module";
8
9
  import path from "node:path";
@@ -12,9 +13,531 @@ import { createStyleHandler } from "@weapp-tailwindcss/postcss";
12
13
  import { LRUCache } from "lru-cache";
13
14
  import { rm } from "node:fs/promises";
14
15
  import MagicString from "magic-string";
15
- import { logger, pc } from "@weapp-tailwindcss/logger";
16
16
  import { Buffer } from "node:buffer";
17
+ import { logger, pc } from "@weapp-tailwindcss/logger";
17
18
  import { walk } from "oxc-walker";
19
+ //#region src/compiler/candidate-index.ts
20
+ var CandidateIndex = class {
21
+ constructor() {
22
+ _defineProperty(this, "candidatesBySource", /* @__PURE__ */ new Map());
23
+ }
24
+ sync(sourceId, candidates) {
25
+ const previous = this.candidatesBySource.get(sourceId) ?? /* @__PURE__ */ new Set();
26
+ const next = new Set(candidates);
27
+ const addedCandidates = new Set([...next].filter((candidate) => !previous.has(candidate)));
28
+ const removedCandidates = new Set([...previous].filter((candidate) => !next.has(candidate)));
29
+ this.candidatesBySource.set(sourceId, next);
30
+ return {
31
+ sourceId,
32
+ addedCandidates,
33
+ removedCandidates
34
+ };
35
+ }
36
+ remove(sourceId) {
37
+ const previous = this.candidatesBySource.get(sourceId) ?? /* @__PURE__ */ new Set();
38
+ this.candidatesBySource.delete(sourceId);
39
+ return {
40
+ sourceId,
41
+ addedCandidates: /* @__PURE__ */ new Set(),
42
+ removedCandidates: new Set(previous)
43
+ };
44
+ }
45
+ values() {
46
+ const values = /* @__PURE__ */ new Set();
47
+ for (const candidates of this.candidatesBySource.values()) for (const candidate of candidates) values.add(candidate);
48
+ return values;
49
+ }
50
+ get(sourceId) {
51
+ return new Set(this.candidatesBySource.get(sourceId) ?? []);
52
+ }
53
+ entries() {
54
+ return new Map([...this.candidatesBySource].map(([sourceId, candidates]) => [sourceId, new Set(candidates)]));
55
+ }
56
+ clear() {
57
+ this.candidatesBySource.clear();
58
+ }
59
+ };
60
+ //#endregion
61
+ //#region src/compiler/invalidation.ts
62
+ function resolveInvalidatedScopes(graph, changes) {
63
+ const invalidatedScopes = /* @__PURE__ */ new Set();
64
+ const visit = (sourceId, visited) => {
65
+ if (visited.has(sourceId)) return;
66
+ visited.add(sourceId);
67
+ const node = graph.getNode(sourceId);
68
+ if (node) invalidatedScopes.add(node.scope.id);
69
+ for (const dependent of graph.getDependents(sourceId)) visit(dependent, visited);
70
+ };
71
+ for (const change of changes) visit(change.sourceId, /* @__PURE__ */ new Set());
72
+ return invalidatedScopes;
73
+ }
74
+ //#endregion
75
+ //#region src/compiler/source-graph.ts
76
+ var SourceGraph = class {
77
+ constructor() {
78
+ _defineProperty(this, "edges", /* @__PURE__ */ new Map());
79
+ _defineProperty(this, "nodes", /* @__PURE__ */ new Map());
80
+ }
81
+ replace(nodes, edges) {
82
+ this.clear();
83
+ for (const node of nodes) this.nodes.set(node.id, {
84
+ ...node,
85
+ scope: { ...node.scope }
86
+ });
87
+ for (const edge of edges) {
88
+ if (!this.nodes.has(edge.from) || !this.nodes.has(edge.to)) throw new Error(`编译图边引用了不存在的节点:${edge.from} -> ${edge.to}`);
89
+ this.edges.set(this.edgeKey(edge), { ...edge });
90
+ }
91
+ }
92
+ getNode(id) {
93
+ const node = this.nodes.get(id);
94
+ return node ? {
95
+ ...node,
96
+ scope: { ...node.scope }
97
+ } : void 0;
98
+ }
99
+ getNodes() {
100
+ return [...this.nodes.values()].map((node) => ({
101
+ ...node,
102
+ scope: { ...node.scope }
103
+ }));
104
+ }
105
+ getEdges() {
106
+ return [...this.edges.values()].map((edge) => ({ ...edge }));
107
+ }
108
+ getDependents(id) {
109
+ return this.getEdges().filter((edge) => edge.to === id).map((edge) => edge.from);
110
+ }
111
+ clear() {
112
+ this.edges.clear();
113
+ this.nodes.clear();
114
+ }
115
+ edgeKey(edge) {
116
+ return `${edge.kind}\0${edge.from}\0${edge.to}`;
117
+ }
118
+ };
119
+ //#endregion
120
+ //#region src/compiler/session.ts
121
+ var DefaultCompilationSession = class {
122
+ constructor() {
123
+ _defineProperty(this, "candidateIndex", new CandidateIndex());
124
+ _defineProperty(this, "graph", new SourceGraph());
125
+ _defineProperty(this, "retainedCandidates", /* @__PURE__ */ new Set());
126
+ _defineProperty(this, "validatedClassSet", /* @__PURE__ */ new Set());
127
+ _defineProperty(this, "invalidatedScopes", /* @__PURE__ */ new Set());
128
+ _defineProperty(this, "revision", 0);
129
+ }
130
+ update(snapshot) {
131
+ const changes = [...snapshot.changes ?? []];
132
+ const invalidatedScopes = resolveInvalidatedScopes(this.graph, changes);
133
+ this.graph.replace(snapshot.nodes, snapshot.edges);
134
+ for (const [sourceId, candidates] of snapshot.candidatesBySource ?? []) {
135
+ const change = this.candidateIndex.sync(sourceId, candidates);
136
+ if (change.addedCandidates.size > 0 || change.removedCandidates.size > 0) changes.push(change);
137
+ }
138
+ for (const change of changes) if ("type" in change && change.type === "source-removed") this.candidateIndex.remove(change.sourceId);
139
+ const currentCandidates = this.candidateIndex.values();
140
+ if (snapshot.preserveDeletedCss) for (const candidate of currentCandidates) this.retainedCandidates.add(candidate);
141
+ else {
142
+ this.retainedCandidates.clear();
143
+ for (const candidate of currentCandidates) this.retainedCandidates.add(candidate);
144
+ }
145
+ if (snapshot.validatedClassSet !== void 0) this.validatedClassSet = new Set(snapshot.validatedClassSet);
146
+ else if (!snapshot.preserveDeletedCss) this.validatedClassSet = new Set([...this.validatedClassSet].filter((candidate) => this.retainedCandidates.has(candidate)));
147
+ this.revision += 1;
148
+ for (const scopeId of resolveInvalidatedScopes(this.graph, changes)) invalidatedScopes.add(scopeId);
149
+ this.invalidatedScopes = invalidatedScopes;
150
+ return this.createResult();
151
+ }
152
+ commitValidation(revision, validatedClassSet, graph) {
153
+ if (revision !== this.revision) throw new Error(`不能向编译 revision ${this.revision} 提交 revision ${revision} 的 classSet。`);
154
+ if (graph) this.graph.replace(graph.nodes, graph.edges);
155
+ this.validatedClassSet = new Set(validatedClassSet);
156
+ return this.createResult();
157
+ }
158
+ createResult() {
159
+ return {
160
+ revision: this.revision,
161
+ candidates: new Set(this.retainedCandidates),
162
+ candidatesBySource: this.candidateIndex.entries(),
163
+ validatedClassSet: new Set(this.validatedClassSet),
164
+ invalidatedScopes: new Set(this.invalidatedScopes),
165
+ graphEdges: this.graph.getEdges(),
166
+ graphNodes: this.graph.getNodes()
167
+ };
168
+ }
169
+ dispose() {
170
+ this.candidateIndex.clear();
171
+ this.graph.clear();
172
+ this.retainedCandidates.clear();
173
+ this.validatedClassSet.clear();
174
+ this.invalidatedScopes.clear();
175
+ this.revision = 0;
176
+ }
177
+ };
178
+ //#endregion
179
+ //#region src/core/compiler/source-fingerprint.ts
180
+ function stableSerialize(value, stack = /* @__PURE__ */ new WeakSet()) {
181
+ if (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
182
+ if (typeof value === "function") return `[Function:${value.name}]`;
183
+ if (typeof value !== "object") return String(value);
184
+ if (stack.has(value)) return "[Circular]";
185
+ stack.add(value);
186
+ const serialized = Array.isArray(value) ? `[${value.map((item) => stableSerialize(item, stack)).join(",")}]` : `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableSerialize(value[key], stack)}`).join(",")}}`;
187
+ stack.delete(value);
188
+ return serialized;
189
+ }
190
+ function createSourceFingerprint(source) {
191
+ return createCompilerValueFingerprint(source);
192
+ }
193
+ function createCompilerValueFingerprint(value) {
194
+ return md5Hash(stableSerialize(value));
195
+ }
196
+ //#endregion
197
+ //#region src/core/compiler/generation-cache.ts
198
+ function createCompilerGenerationCacheKey(request, candidates, target) {
199
+ return {
200
+ bareArbitraryValues: request.bareArbitraryValues,
201
+ candidateSignature: [...candidates].sort().join("\0"),
202
+ incrementalCache: request.incrementalCache,
203
+ scanSources: request.scanSources,
204
+ sourcesFingerprint: request.sources === void 0 ? void 0 : createCompilerValueFingerprint(request.sources),
205
+ styleOptionsFingerprint: request.styleOptions === void 0 ? void 0 : createCompilerValueFingerprint(request.styleOptions),
206
+ target
207
+ };
208
+ }
209
+ function isSameCompilerGenerationCacheKey(left, right) {
210
+ return left.bareArbitraryValues === right.bareArbitraryValues && left.candidateSignature === right.candidateSignature && left.incrementalCache === right.incrementalCache && left.scanSources === right.scanSources && left.sourcesFingerprint === right.sourcesFingerprint && left.styleOptionsFingerprint === right.styleOptionsFingerprint && left.target === right.target;
211
+ }
212
+ function reuseCompilerGenerationResult(result) {
213
+ return {
214
+ ...result,
215
+ incrementalCss: "",
216
+ incrementalRawCss: ""
217
+ };
218
+ }
219
+ //#endregion
220
+ //#region src/core/compiler/generation-state.ts
221
+ function createGenerationGraph(rootId, source, dependencies) {
222
+ const scope = {
223
+ id: rootId,
224
+ kind: "global"
225
+ };
226
+ const dependencyIds = [...new Set(dependencies)].filter((id) => id !== rootId).sort();
227
+ const nodes = [{
228
+ content: source.css,
229
+ id: rootId,
230
+ kind: "css",
231
+ scope
232
+ }, ...dependencyIds.map((id) => ({
233
+ id,
234
+ kind: "config",
235
+ scope
236
+ }))];
237
+ return {
238
+ edges: dependencyIds.map((id) => ({
239
+ from: rootId,
240
+ kind: "depends-on",
241
+ to: id
242
+ })),
243
+ nodes
244
+ };
245
+ }
246
+ function prepareCompilerGeneration(entry, request, source, sourceChanged) {
247
+ const explicitCandidates = request.candidates !== void 0;
248
+ const candidates = explicitCandidates ? [...request.candidates] : [];
249
+ const candidateSignature = [...candidates].sort().join("\0");
250
+ if (!sourceChanged && entry.compilationCache?.candidateSignature === candidateSignature && entry.compilationCache.compilation.revision === entry.compilationRevision) return {
251
+ ...entry.compilationCache,
252
+ explicitCandidates
253
+ };
254
+ const graph = createGenerationGraph(entry.id, source, source.dependencies);
255
+ const compilation = entry.compilation.update({
256
+ ...graph,
257
+ candidatesBySource: [[entry.id, candidates]],
258
+ changes: sourceChanged ? [{
259
+ sourceId: entry.id,
260
+ type: "dependency-changed"
261
+ }] : void 0
262
+ });
263
+ entry.compilationRevision = compilation.revision;
264
+ return {
265
+ candidateSignature,
266
+ compilation,
267
+ explicitCandidates,
268
+ graph
269
+ };
270
+ }
271
+ function commitCompilerGeneration(entry, prepared, source, dependencies, classSet) {
272
+ const graph = createGenerationGraph(entry.id, source, dependencies);
273
+ const compilation = entry.compilation.commitValidation(prepared.compilation.revision, classSet, graph);
274
+ entry.compilationCache = {
275
+ candidateSignature: prepared.candidateSignature,
276
+ compilation,
277
+ graph
278
+ };
279
+ }
280
+ //#endregion
281
+ //#region src/core/compiler/root-store.ts
282
+ function disposeGenerator(generator) {
283
+ generator?.dispose?.();
284
+ }
285
+ var CompilerRootStore = class {
286
+ constructor(maxRoots) {
287
+ this.maxRoots = maxRoots;
288
+ _defineProperty(this, "dependencyRoots", /* @__PURE__ */ new Map());
289
+ _defineProperty(this, "releasing", /* @__PURE__ */ new Map());
290
+ _defineProperty(this, "roots", /* @__PURE__ */ new Map());
291
+ }
292
+ get(id) {
293
+ if (!id) throw new Error("Compiler root id 不能为空。");
294
+ if (this.releasing.has(id)) throw new Error(`Compiler root 正在移除:${id}`);
295
+ const cached = this.roots.get(id);
296
+ if (cached) {
297
+ if (!cached.accepting) throw new Error(`Compiler root 正在移除:${id}`);
298
+ this.roots.delete(id);
299
+ this.roots.set(id, cached);
300
+ return cached;
301
+ }
302
+ if (this.roots.size >= this.maxRoots) {
303
+ const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
304
+ if (oldest) this.remove(oldest.id);
305
+ }
306
+ const entry = {
307
+ accepting: true,
308
+ active: true,
309
+ appliedInvalidation: 0,
310
+ compilation: new DefaultCompilationSession(),
311
+ compilationRevision: 0,
312
+ dependencies: /* @__PURE__ */ new Set(),
313
+ id,
314
+ invalidation: 0,
315
+ pending: Promise.resolve(),
316
+ pendingCount: 0
317
+ };
318
+ this.roots.set(id, entry);
319
+ return entry;
320
+ }
321
+ attachDependencies(entry, dependencies) {
322
+ this.detachDependencies(entry);
323
+ if (!entry.accepting) return;
324
+ for (const dependency of dependencies) {
325
+ entry.dependencies.add(dependency);
326
+ let owners = this.dependencyRoots.get(dependency);
327
+ if (!owners) {
328
+ owners = /* @__PURE__ */ new Set();
329
+ this.dependencyRoots.set(dependency, owners);
330
+ }
331
+ owners.add(entry.id);
332
+ }
333
+ }
334
+ invalidate(ids) {
335
+ const affected = /* @__PURE__ */ new Set();
336
+ for (const id of ids) {
337
+ const root = this.roots.get(id);
338
+ if (root?.accepting) affected.add(root.id);
339
+ for (const rootId of this.dependencyRoots.get(id) ?? []) affected.add(rootId);
340
+ }
341
+ for (const rootId of affected) {
342
+ const entry = this.roots.get(rootId);
343
+ if (entry?.accepting) entry.invalidation += 1;
344
+ }
345
+ return Object.freeze([...affected].sort());
346
+ }
347
+ trim() {
348
+ while (this.roots.size > this.maxRoots) {
349
+ const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
350
+ if (!oldest) return;
351
+ this.remove(oldest.id);
352
+ }
353
+ }
354
+ remove(id) {
355
+ const pendingRelease = this.releasing.get(id);
356
+ if (pendingRelease) return pendingRelease;
357
+ const entry = this.roots.get(id);
358
+ if (!entry) return Promise.resolve();
359
+ entry.accepting = false;
360
+ this.roots.delete(id);
361
+ this.detachDependencies(entry);
362
+ const release = entry.pending.then(() => {
363
+ entry.active = false;
364
+ entry.compilation.dispose();
365
+ entry.compilationCache = void 0;
366
+ disposeGenerator(entry.generator);
367
+ entry.generator = void 0;
368
+ entry.generationCache = void 0;
369
+ entry.latestSnapshot = void 0;
370
+ entry.source = void 0;
371
+ entry.sourceInput = void 0;
372
+ entry.sourceFingerprint = void 0;
373
+ }).finally(() => {
374
+ this.releasing.delete(id);
375
+ });
376
+ this.releasing.set(id, release);
377
+ return release;
378
+ }
379
+ async dispose() {
380
+ await Promise.all([...[...this.roots.keys()].map((id) => this.remove(id)), ...this.releasing.values()]);
381
+ this.dependencyRoots.clear();
382
+ }
383
+ detachDependencies(entry) {
384
+ for (const dependency of entry.dependencies) {
385
+ const owners = this.dependencyRoots.get(dependency);
386
+ owners?.delete(entry.id);
387
+ if (owners?.size === 0) this.dependencyRoots.delete(dependency);
388
+ }
389
+ entry.dependencies.clear();
390
+ }
391
+ };
392
+ //#endregion
393
+ //#region src/core/compiler/snapshot.ts
394
+ const readonlySetValues = /* @__PURE__ */ new WeakMap();
395
+ const snapshotRegistry = /* @__PURE__ */ new WeakMap();
396
+ var ImmutableSetView = class {
397
+ constructor(values) {
398
+ readonlySetValues.set(this, new Set(values));
399
+ Object.freeze(this);
400
+ }
401
+ get size() {
402
+ return this.valuesSet.size;
403
+ }
404
+ get [Symbol.toStringTag]() {
405
+ return "Set";
406
+ }
407
+ has(value) {
408
+ return this.valuesSet.has(value);
409
+ }
410
+ entries() {
411
+ return this.valuesSet.entries();
412
+ }
413
+ keys() {
414
+ return this.valuesSet.keys();
415
+ }
416
+ values() {
417
+ return this.valuesSet.values();
418
+ }
419
+ forEach(callbackfn, thisArg) {
420
+ for (const value of this.valuesSet) callbackfn.call(thisArg, value, value, this);
421
+ }
422
+ [Symbol.iterator]() {
423
+ return this.values();
424
+ }
425
+ get valuesSet() {
426
+ return readonlySetValues.get(this);
427
+ }
428
+ };
429
+ function uniqueSorted(values) {
430
+ return Object.freeze([...new Set(values)].sort());
431
+ }
432
+ function sourceKey(source) {
433
+ return `${source.base}\0${source.pattern}\0${source.negated ? "1" : "0"}`;
434
+ }
435
+ function uniqueSortedSources(sources) {
436
+ const values = /* @__PURE__ */ new Map();
437
+ for (const source of sources) {
438
+ const cloned = Object.freeze({ ...source });
439
+ values.set(sourceKey(cloned), cloned);
440
+ }
441
+ return Object.freeze([...values.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, value]) => value));
442
+ }
443
+ function createRootFingerprint(root, target, classSet, dependencies, sources) {
444
+ return [
445
+ root.id,
446
+ String(root.revision),
447
+ target,
448
+ ...[...classSet].sort(),
449
+ ...dependencies,
450
+ ...[...sources].map(sourceKey)
451
+ ].join("\0");
452
+ }
453
+ function createSnapshotFromState(state, reusableClassSet, reusableClassSetView) {
454
+ const roots = Object.freeze([...state.roots.values()].sort((left, right) => left.id.localeCompare(right.id)).map(({ id, revision }) => Object.freeze({
455
+ id,
456
+ revision
457
+ })));
458
+ const classSet = reusableClassSet ?? new Set(state.classSet);
459
+ const fingerprint = [
460
+ state.target,
461
+ ...[...state.roots.values()].map((root) => `${root.id}\0${root.revision}\0${root.fingerprint}`).sort(),
462
+ ...[...classSet].sort(),
463
+ ...state.dependencies,
464
+ ...state.sources.map(sourceKey)
465
+ ].join("\0");
466
+ const snapshot = Object.freeze({
467
+ classSet: reusableClassSetView ?? new ImmutableSetView(classSet),
468
+ dependencies: state.dependencies,
469
+ roots,
470
+ sources: state.sources,
471
+ target: state.target
472
+ });
473
+ snapshotRegistry.set(snapshot, {
474
+ ...state,
475
+ classSet,
476
+ fingerprint
477
+ });
478
+ return snapshot;
479
+ }
480
+ function createRegisteredCompilerSnapshot(request, reusableClassSet, reusableClassSetView) {
481
+ if (!request.id) throw new Error("Compiler snapshot 的 root id 不能为空。");
482
+ const revision = request.revision ?? 0;
483
+ if (!Number.isSafeInteger(revision) || revision < 0) throw new Error(`Compiler snapshot revision 必须是非负安全整数:${revision}`);
484
+ const target = request.target ?? "weapp";
485
+ const classSet = new Set(request.classSet);
486
+ const dependencies = uniqueSorted(request.dependencies ?? []);
487
+ const sources = uniqueSortedSources(request.sources ?? []);
488
+ const root = {
489
+ id: request.id,
490
+ revision
491
+ };
492
+ const internalRoot = {
493
+ ...root,
494
+ fingerprint: createRootFingerprint(root, target, classSet, dependencies, sources)
495
+ };
496
+ return createSnapshotFromState({
497
+ classSet,
498
+ dependencies,
499
+ roots: /* @__PURE__ */ new Map([[root.id, internalRoot]]),
500
+ sources,
501
+ target
502
+ }, reusableClassSet, reusableClassSetView);
503
+ }
504
+ function getInternalCompilerSnapshot(snapshot) {
505
+ const state = snapshotRegistry.get(snapshot);
506
+ if (!state) throw new Error("Compiler snapshot 必须由 createSnapshot()、generate() 或 mergeSnapshots() 创建。");
507
+ return state;
508
+ }
509
+ function mergeRegisteredCompilerSnapshots(snapshots) {
510
+ const states = [...snapshots].map(getInternalCompilerSnapshot);
511
+ if (states.length === 0) throw new Error("mergeSnapshots() 至少需要一个 snapshot。");
512
+ const target = states[0].target;
513
+ const roots = /* @__PURE__ */ new Map();
514
+ const classSet = /* @__PURE__ */ new Set();
515
+ const dependencies = [];
516
+ const sources = [];
517
+ for (const state of states) {
518
+ if (state.target !== target) throw new Error(`不能合并不同 target 的 snapshot:${target} 与 ${state.target}`);
519
+ for (const root of state.roots.values()) {
520
+ const current = roots.get(root.id);
521
+ if (current && current.revision !== root.revision) throw new Error(`同一 root 不能合并不同 revision:${root.id} (${current.revision} / ${root.revision})`);
522
+ if (current && current.fingerprint !== root.fingerprint) throw new Error(`同一 root revision 的 snapshot 内容冲突:${root.id}@${root.revision}`);
523
+ roots.set(root.id, root);
524
+ }
525
+ for (const candidate of state.classSet) classSet.add(candidate);
526
+ dependencies.push(...state.dependencies);
527
+ sources.push(...state.sources);
528
+ }
529
+ return createSnapshotFromState({
530
+ classSet: new Set([...classSet].sort()),
531
+ dependencies: uniqueSorted(dependencies),
532
+ roots,
533
+ sources: uniqueSortedSources(sources),
534
+ target
535
+ });
536
+ }
537
+ function createImmutableSet(values) {
538
+ return new ImmutableSetView(values);
539
+ }
540
+ //#endregion
18
541
  //#region src/cache/index.ts
19
542
  function isProcessResult(value) {
20
543
  return typeof value === "object" && value !== null && "result" in value;
@@ -1239,4 +1762,240 @@ function getCompilerContext(opts) {
1239
1762
  return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
1240
1763
  }
1241
1764
  //#endregion
1242
- export { vitePluginName as a, collectRuntimeClassSet as c, refreshTailwindRuntimeState as d, normalizeFrameworkStylePlatform as f, pluginName as i, createTailwindRuntimeReadyPromise as l, normalizeStyleHandlerMajorVersion as n, shouldSkipJsTransform as o, resolveStyleOptionsFromContext as r, toCustomAttributesEntities as s, getCompilerContext as t, ensureRuntimeClassSet as u };
1765
+ //#region src/core/compiler/transforms.ts
1766
+ const DEFAULT_JS_OPTIONS = Object.freeze({ tailwindcssMajorVersion: 4 });
1767
+ const DEFAULT_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
1768
+ function clonePostcssResult(result) {
1769
+ return Object.assign(Object.create(Object.getPrototypeOf(result)), result, {
1770
+ messages: [...result.messages],
1771
+ root: result.root.clone()
1772
+ });
1773
+ }
1774
+ function resolveStyleOptions(options) {
1775
+ if (!options) return DEFAULT_STYLE_OPTIONS;
1776
+ return options?.isMainChunk === void 0 ? {
1777
+ ...options,
1778
+ isMainChunk: true
1779
+ } : options;
1780
+ }
1781
+ function createCompilerTransforms({ ensureActive, track, userOptions }) {
1782
+ const context = getCompilerContext({
1783
+ ...userOptions,
1784
+ __internalDeferMissingCssEntriesWarning: true
1785
+ });
1786
+ const styleHandler = context.styleHandler;
1787
+ let cachedTemplateClassSet;
1788
+ let cachedTemplateOptions;
1789
+ function clearCache() {
1790
+ cachedTemplateClassSet = void 0;
1791
+ cachedTemplateOptions = void 0;
1792
+ }
1793
+ function createTemplateOptions(classSet, options) {
1794
+ const isDefault = !options || Object.keys(options).length === 0;
1795
+ if (isDefault && cachedTemplateClassSet === classSet && cachedTemplateOptions) return cachedTemplateOptions;
1796
+ const resolved = {
1797
+ ...options,
1798
+ classSetMode: "exact",
1799
+ jsHandler: (jsSource, _runtimeSet, jsOptions) => context.jsHandler(jsSource, classSet, {
1800
+ ...jsOptions,
1801
+ tailwindcssMajorVersion: jsOptions?.tailwindcssMajorVersion ?? 4
1802
+ }),
1803
+ runtimeSet: classSet
1804
+ };
1805
+ if (isDefault) {
1806
+ cachedTemplateClassSet = classSet;
1807
+ cachedTemplateOptions = resolved;
1808
+ }
1809
+ return resolved;
1810
+ }
1811
+ function transformCss(css, snapshot, options) {
1812
+ ensureActive();
1813
+ getInternalCompilerSnapshot(snapshot);
1814
+ return track(styleHandler(css, resolveStyleOptions(options)).then(clonePostcssResult));
1815
+ }
1816
+ function transformCssRoot(root, snapshot, options) {
1817
+ ensureActive();
1818
+ getInternalCompilerSnapshot(snapshot);
1819
+ return track(styleHandler.transformRoot(root, resolveStyleOptions(options)));
1820
+ }
1821
+ function transformJavaScript(source, snapshot, options) {
1822
+ ensureActive();
1823
+ const classSet = getInternalCompilerSnapshot(snapshot).classSet;
1824
+ const resolvedOptions = options?.tailwindcssMajorVersion === void 0 ? options ? {
1825
+ ...options,
1826
+ tailwindcssMajorVersion: 4
1827
+ } : DEFAULT_JS_OPTIONS : options;
1828
+ return track(Promise.resolve(shouldSkipJsTransform(source, resolvedOptions) ? { code: source } : context.jsHandler(source, classSet, resolvedOptions)));
1829
+ }
1830
+ function transformTemplate(source, snapshot, options) {
1831
+ ensureActive();
1832
+ const classSet = getInternalCompilerSnapshot(snapshot).classSet;
1833
+ return track(context.templateHandler(source, createTemplateOptions(classSet, options)));
1834
+ }
1835
+ return {
1836
+ clearCache,
1837
+ transformCss,
1838
+ transformCssRoot,
1839
+ transformJavaScript,
1840
+ transformTemplate
1841
+ };
1842
+ }
1843
+ //#endregion
1844
+ //#region src/core/compiler/compiler.ts
1845
+ const DEFAULT_MAX_ROOTS = 128;
1846
+ function createCompiler(options = {}) {
1847
+ const { compiler: compilerOptions, ...userOptions } = options;
1848
+ const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)));
1849
+ const activeTasks = /* @__PURE__ */ new Set();
1850
+ let lifecycle = "active";
1851
+ let disposePromise;
1852
+ function ensureActive() {
1853
+ if (lifecycle !== "active") throw new Error(lifecycle === "disposing" ? "Compiler 正在释放,不能接受新任务。" : "Compiler 已释放。");
1854
+ }
1855
+ function track(task) {
1856
+ activeTasks.add(task);
1857
+ task.then(() => activeTasks.delete(task), () => activeTasks.delete(task));
1858
+ return task;
1859
+ }
1860
+ const { clearCache: clearTransformCache, ...transforms } = createCompilerTransforms({
1861
+ ensureActive,
1862
+ track,
1863
+ userOptions
1864
+ });
1865
+ async function resolveRequestSource(entry, request) {
1866
+ if (request.source && request.sourceOptions) throw new Error("generate() 的 source 与 sourceOptions 互斥。");
1867
+ if (!request.source && !request.sourceOptions) throw new Error("generate() 必须提供 source 或 sourceOptions。");
1868
+ const sourceInput = request.source ?? request.sourceOptions;
1869
+ return {
1870
+ source: entry.source !== void 0 && entry.sourceInput === sourceInput && entry.appliedInvalidation === entry.invalidation ? entry.source : request.source ?? await resolveTailwindV4Source$1(request.sourceOptions),
1871
+ sourceInput
1872
+ };
1873
+ }
1874
+ async function runGenerate(entry, request) {
1875
+ if (!entry.active) throw new Error(`Compiler root 已被移除:${entry.id}`);
1876
+ const invalidation = entry.invalidation;
1877
+ const { source, sourceInput } = await resolveRequestSource(entry, request);
1878
+ const sourceFingerprint = entry.sourceInput === sourceInput && entry.sourceFingerprint !== void 0 && entry.appliedInvalidation === invalidation ? entry.sourceFingerprint : createSourceFingerprint(source);
1879
+ const sourceReused = entry.sourceFingerprint === sourceFingerprint;
1880
+ const engineReused = sourceReused && entry.generator !== void 0 && entry.appliedInvalidation === invalidation;
1881
+ const generator = engineReused ? entry.generator : createWeappTailwindcssGenerator(source);
1882
+ const target = request.target ?? "weapp";
1883
+ const { id: _id, source: _source, sourceOptions: _sourceOptions, target: _target, ...generateOptions } = request;
1884
+ const prepared = prepareCompilerGeneration(entry, request, source, !sourceReused || entry.appliedInvalidation !== invalidation);
1885
+ const generationCacheKey = createCompilerGenerationCacheKey(request, prepared.compilation.candidates, target);
1886
+ const reusableGeneration = engineReused && entry.generationCache && isSameCompilerGenerationCacheKey(entry.generationCache.key, generationCacheKey) ? entry.generationCache.result : void 0;
1887
+ try {
1888
+ const generated = reusableGeneration ? reuseCompilerGenerationResult(reusableGeneration) : await generator.generate({
1889
+ ...generateOptions,
1890
+ candidates: prepared.explicitCandidates ? prepared.compilation.candidates : void 0,
1891
+ incrementalCache: generateOptions.incrementalCache ?? true,
1892
+ target: target === "tailwind" ? "web" : target
1893
+ });
1894
+ if (!entry.active) throw new Error(`Compiler root 已被移除:${entry.id}`);
1895
+ const revision = (getLatestRevision(entry) ?? 0) + 1;
1896
+ const dependencies = [.../* @__PURE__ */ new Set([...source.dependencies, ...generated.dependencies])].sort();
1897
+ const sources = generated.sources ?? source.sources ?? [];
1898
+ const previousSnapshotState = entry.latestSnapshot ? getInternalCompilerSnapshot(entry.latestSnapshot) : void 0;
1899
+ const reusableClassSet = engineReused && generated.incrementalCss === "" && previousSnapshotState && previousSnapshotState.classSet.size === generated.classSet.size && [...generated.classSet].every((candidate) => previousSnapshotState.classSet.has(candidate)) ? previousSnapshotState.classSet : void 0;
1900
+ const reusableClassSetView = reusableClassSet ? entry.latestSnapshot?.classSet : void 0;
1901
+ const snapshot = createRegisteredCompilerSnapshot({
1902
+ classSet: generated.classSet,
1903
+ dependencies,
1904
+ id: entry.id,
1905
+ revision,
1906
+ sources,
1907
+ target
1908
+ }, reusableClassSet, reusableClassSetView);
1909
+ const internalSnapshot = getInternalCompilerSnapshot(snapshot);
1910
+ const previousGenerator = entry.generator;
1911
+ commitCompilerGeneration(entry, prepared, source, dependencies, generated.classSet);
1912
+ entry.generator = generator;
1913
+ entry.generationCache = {
1914
+ key: generationCacheKey,
1915
+ result: generated
1916
+ };
1917
+ entry.source = source;
1918
+ entry.sourceFingerprint = sourceFingerprint;
1919
+ entry.sourceInput = sourceInput;
1920
+ entry.appliedInvalidation = invalidation;
1921
+ entry.latestSnapshot = snapshot;
1922
+ rootStore.attachDependencies(entry, dependencies);
1923
+ if (!engineReused && previousGenerator !== generator) previousGenerator?.dispose?.();
1924
+ const css = target === "tailwind" ? generated.rawCss : generated.css;
1925
+ const incrementalCss = target === "tailwind" ? generated.incrementalRawCss : generated.incrementalCss;
1926
+ return {
1927
+ ...generated,
1928
+ cache: Object.freeze({
1929
+ engine: engineReused,
1930
+ output: reusableGeneration !== void 0 || engineReused && incrementalCss === "",
1931
+ source: sourceReused
1932
+ }),
1933
+ classSet: snapshot.classSet,
1934
+ css,
1935
+ dependencies: snapshot.dependencies,
1936
+ incrementalCss,
1937
+ rawCandidates: createImmutableSet(generated.rawCandidates),
1938
+ revision,
1939
+ snapshot,
1940
+ sources: internalSnapshot.sources,
1941
+ target
1942
+ };
1943
+ } catch (error) {
1944
+ if (!engineReused) generator.dispose?.();
1945
+ throw error;
1946
+ }
1947
+ }
1948
+ function getLatestRevision(entry) {
1949
+ return entry.latestSnapshot?.roots[0]?.revision;
1950
+ }
1951
+ function generate(request) {
1952
+ ensureActive();
1953
+ const entry = rootStore.get(request.id);
1954
+ entry.pendingCount += 1;
1955
+ const execution = entry.pending.then(() => runGenerate(entry, request));
1956
+ entry.pending = execution.finally(() => {
1957
+ entry.pendingCount -= 1;
1958
+ rootStore.trim();
1959
+ }).then(() => void 0, () => void 0);
1960
+ return track(execution);
1961
+ }
1962
+ function createSnapshot(request) {
1963
+ ensureActive();
1964
+ return createRegisteredCompilerSnapshot(request);
1965
+ }
1966
+ function mergeSnapshots(snapshots) {
1967
+ ensureActive();
1968
+ return mergeRegisteredCompilerSnapshots(snapshots);
1969
+ }
1970
+ function invalidate(ids) {
1971
+ ensureActive();
1972
+ return rootStore.invalidate(ids);
1973
+ }
1974
+ async function remove(id) {
1975
+ if (lifecycle === "disposed") return;
1976
+ clearTransformCache();
1977
+ await rootStore.remove(id);
1978
+ }
1979
+ function dispose() {
1980
+ if (disposePromise) return disposePromise;
1981
+ lifecycle = "disposing";
1982
+ disposePromise = (async () => {
1983
+ await Promise.allSettled([...activeTasks]);
1984
+ clearTransformCache();
1985
+ await rootStore.dispose();
1986
+ lifecycle = "disposed";
1987
+ })();
1988
+ return disposePromise;
1989
+ }
1990
+ return {
1991
+ createSnapshot,
1992
+ dispose,
1993
+ generate,
1994
+ invalidate,
1995
+ mergeSnapshots,
1996
+ remove,
1997
+ ...transforms
1998
+ };
1999
+ }
2000
+ //#endregion
2001
+ export { pluginName as a, toCustomAttributesEntities as c, ensureRuntimeClassSet as d, refreshTailwindRuntimeState as f, resolveStyleOptionsFromContext as i, collectRuntimeClassSet as l, DefaultCompilationSession as m, getCompilerContext as n, vitePluginName as o, normalizeFrameworkStylePlatform as p, normalizeStyleHandlerMajorVersion as r, shouldSkipJsTransform as s, createCompiler as t, createTailwindRuntimeReadyPromise as u };