weapp-tailwindcss 5.3.6 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/README.zh-CN.md +4 -4
- package/dist/bundlers/shared/framework-postcss.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/result-helpers.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +3 -1
- package/dist/bundlers/shared/source-candidates/snapshot.d.ts +19 -0
- package/dist/bundlers/shared/source-candidates/source-priority.d.ts +1 -0
- package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +1 -0
- package/dist/bundlers/shared/source-candidates/views.d.ts +12 -0
- package/dist/bundlers/shared/style-requests.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +9 -1
- package/dist/bundlers/vite/capability-profile.d.ts +18 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +12 -0
- package/dist/bundlers/vite/hot-css-modules.d.ts +2 -2
- package/dist/bundlers/vite/shared/configured-css-entry-observer.d.ts +29 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +8 -0
- package/dist/bundlers/vite/shared/framework-css-generation-queue.d.ts +1 -0
- package/dist/bundlers/vite/shared/framework-hmr-module-version.d.ts +9 -0
- package/dist/bundlers/vite/shared/framework-runtime-utils.d.ts +5 -0
- package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +12 -2
- package/dist/compiler/compilation-session-pool.d.ts +1 -0
- package/dist/compiler/framework-compiler-session.d.ts +21 -0
- package/dist/compiler/index.d.ts +1 -0
- package/dist/{context-DTLRADfE.cjs → compiler-CDAz4SwJ.cjs} +907 -11
- package/dist/{context-4ittVpgt.js → compiler-DWcUgi3A.js} +813 -6
- package/dist/context/handlers.d.ts +1 -1
- package/dist/core/compiler/compiler.d.ts +2 -0
- package/dist/core/compiler/generation-cache.d.ts +30 -0
- package/dist/core/compiler/generation-state.d.ts +17 -0
- package/dist/core/compiler/index.d.ts +2 -0
- package/dist/core/compiler/root-store.d.ts +41 -0
- package/dist/core/compiler/snapshot.d.ts +35 -0
- package/dist/core/compiler/source-fingerprint.d.ts +3 -0
- package/dist/core/compiler/transforms.d.ts +15 -0
- package/dist/core/compiler/types.d.ts +75 -0
- package/dist/core.cjs +34 -8
- package/dist/core.d.ts +4 -1
- package/dist/core.js +3 -2
- package/dist/framework/index.d.ts +3 -1
- package/dist/framework.cjs +6 -1
- package/dist/framework.js +6 -1
- package/dist/{generator-EnTXLBlK.js → generator-BjK5PRR-.js} +28 -10
- package/dist/{generator-DKiYbTFR.cjs → generator-WlhrtNa3.cjs} +26 -8
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/dist/{gulp-DwtrU4V1.js → gulp-BbMMp7vY.js} +7 -7
- package/dist/{gulp-CUysZjW3.cjs → gulp-CBu_waef.cjs} +14 -16
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-utmOgn6p.js → hmr-timing-B_4sAvsk.js} +369 -291
- package/dist/{hmr-timing-Cvh5UgnM.cjs → hmr-timing-CYhNto2U.cjs} +4 -4
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/{pipeline-helpers-CyVXL3h6.cjs → pipeline-helpers-Du8eAtMG.cjs} +6 -6
- package/dist/postcss.cjs +1 -1
- package/dist/postcss.js +1 -1
- package/dist/presets.cjs +2 -3
- package/dist/presets.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +2 -2
- package/dist/{source-candidate-scan-signature-BNt7NrrI.cjs → source-candidate-scan-signature-ZOm0O17V.cjs} +5 -5
- package/dist/{source-candidate-scan-signature-CDrLxVKu.js → source-candidate-scan-signature-wieibgE7.js} +3 -3
- package/dist/{tailwindcss-ChnpCv25.js → tailwindcss-9xmoCkaR.js} +1 -1
- package/dist/{tailwindcss-CexDJBhx.cjs → tailwindcss-D3jltF7M.cjs} +763 -5
- package/dist/{transform-CL-UZW1U.cjs → transform-C6k9zTQR.cjs} +12 -4
- package/dist/{transform-Bfi1_VgN.js → transform-DQhgAarN.js} +12 -4
- package/dist/typedoc.export.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/uni-app-x/component-local-style.d.ts +2 -0
- package/dist/uni-app-x/transform.d.ts +1 -0
- package/dist/uni-app-x/vite/asset-task.d.ts +21 -0
- package/dist/uni-app-x/vite/plugin-options.d.ts +8 -0
- package/dist/uni-app-x/vite/web-local-style.d.ts +2 -1
- package/dist/uni-app-x/vite.d.ts +1 -21
- package/dist/{v4-generation-core-Dhsu9Deu.cjs → v4-generation-core-BhYkeoZ4.cjs} +378 -300
- package/dist/{vite-DMX5zoID.cjs → vite-B0cvyfSY.cjs} +807 -200
- package/dist/{vite-DJkhb8n1.js → vite-Fu6GTjIY.js} +774 -165
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-generation-loader.cjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +7 -7
- package/dist/{webpack-Cpy_yggg.cjs → webpack-Amn5lmnx.cjs} +33 -35
- package/dist/{webpack-CzhrD9p3.js → webpack-BKHO-WSM.js} +10 -10
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/dist/wxml/utils.d.ts +1 -1
- package/dist/{wxml-B7OAVpXJ.js → wxml-CvKyV69S.js} +10 -2
- package/dist/{wxml-PrK-8ARX.cjs → wxml-o-CUulAM.cjs} +40 -32
- package/package.json +12 -11
- package/dist/options-BJrtIQbH.cjs +0 -768
- package/dist/style-options-DW30H5PV.cjs +0 -82
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
2
|
const require_framework = require("./framework.cjs");
|
|
3
|
-
const require_generator = require("./generator-
|
|
3
|
+
const require_generator = require("./generator-WlhrtNa3.cjs");
|
|
4
4
|
const require_object = require("./object-DbHtAXRk.cjs");
|
|
5
|
-
const
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-D3jltF7M.cjs");
|
|
6
6
|
require("./utils-CuKLf1Zv.cjs");
|
|
7
|
-
const require_wxml = require("./wxml-
|
|
7
|
+
const require_wxml = require("./wxml-o-CUulAM.cjs");
|
|
8
8
|
const require_defaults = require("./defaults.cjs");
|
|
9
|
-
const require_tailwindcss = require("./tailwindcss-CexDJBhx.cjs");
|
|
10
|
-
const require_style_options = require("./style-options-DW30H5PV.cjs");
|
|
11
9
|
let node_path = require("node:path");
|
|
12
10
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
13
11
|
let node_process = require("node:process");
|
|
@@ -17,10 +15,544 @@ let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
|
17
15
|
let lru_cache = require("lru-cache");
|
|
18
16
|
let node_module = require("node:module");
|
|
19
17
|
let node_fs_promises = require("node:fs/promises");
|
|
20
|
-
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
21
18
|
let node_buffer = require("node:buffer");
|
|
19
|
+
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
22
20
|
let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
|
|
23
21
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
22
|
+
//#region src/compiler/candidate-index.ts
|
|
23
|
+
var CandidateIndex = class {
|
|
24
|
+
constructor() {
|
|
25
|
+
require_object._defineProperty(this, "candidatesBySource", /* @__PURE__ */ new Map());
|
|
26
|
+
}
|
|
27
|
+
sync(sourceId, candidates) {
|
|
28
|
+
const previous = this.candidatesBySource.get(sourceId) ?? /* @__PURE__ */ new Set();
|
|
29
|
+
const next = new Set(candidates);
|
|
30
|
+
const addedCandidates = new Set([...next].filter((candidate) => !previous.has(candidate)));
|
|
31
|
+
const removedCandidates = new Set([...previous].filter((candidate) => !next.has(candidate)));
|
|
32
|
+
this.candidatesBySource.set(sourceId, next);
|
|
33
|
+
return {
|
|
34
|
+
sourceId,
|
|
35
|
+
addedCandidates,
|
|
36
|
+
removedCandidates
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
remove(sourceId) {
|
|
40
|
+
const previous = this.candidatesBySource.get(sourceId) ?? /* @__PURE__ */ new Set();
|
|
41
|
+
this.candidatesBySource.delete(sourceId);
|
|
42
|
+
return {
|
|
43
|
+
sourceId,
|
|
44
|
+
addedCandidates: /* @__PURE__ */ new Set(),
|
|
45
|
+
removedCandidates: new Set(previous)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
values() {
|
|
49
|
+
const values = /* @__PURE__ */ new Set();
|
|
50
|
+
for (const candidates of this.candidatesBySource.values()) for (const candidate of candidates) values.add(candidate);
|
|
51
|
+
return values;
|
|
52
|
+
}
|
|
53
|
+
get(sourceId) {
|
|
54
|
+
return new Set(this.candidatesBySource.get(sourceId) ?? []);
|
|
55
|
+
}
|
|
56
|
+
entries() {
|
|
57
|
+
return new Map([...this.candidatesBySource].map(([sourceId, candidates]) => [sourceId, new Set(candidates)]));
|
|
58
|
+
}
|
|
59
|
+
clear() {
|
|
60
|
+
this.candidatesBySource.clear();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/compiler/invalidation.ts
|
|
65
|
+
function resolveInvalidatedScopes(graph, changes) {
|
|
66
|
+
const invalidatedScopes = /* @__PURE__ */ new Set();
|
|
67
|
+
const visit = (sourceId, visited) => {
|
|
68
|
+
if (visited.has(sourceId)) return;
|
|
69
|
+
visited.add(sourceId);
|
|
70
|
+
const node = graph.getNode(sourceId);
|
|
71
|
+
if (node) invalidatedScopes.add(node.scope.id);
|
|
72
|
+
for (const dependent of graph.getDependents(sourceId)) visit(dependent, visited);
|
|
73
|
+
};
|
|
74
|
+
for (const change of changes) visit(change.sourceId, /* @__PURE__ */ new Set());
|
|
75
|
+
return invalidatedScopes;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/compiler/source-graph.ts
|
|
79
|
+
var SourceGraph = class {
|
|
80
|
+
constructor() {
|
|
81
|
+
require_object._defineProperty(this, "edges", /* @__PURE__ */ new Map());
|
|
82
|
+
require_object._defineProperty(this, "nodes", /* @__PURE__ */ new Map());
|
|
83
|
+
}
|
|
84
|
+
replace(nodes, edges) {
|
|
85
|
+
this.clear();
|
|
86
|
+
for (const node of nodes) this.nodes.set(node.id, {
|
|
87
|
+
...node,
|
|
88
|
+
scope: { ...node.scope }
|
|
89
|
+
});
|
|
90
|
+
for (const edge of edges) {
|
|
91
|
+
if (!this.nodes.has(edge.from) || !this.nodes.has(edge.to)) throw new Error(`编译图边引用了不存在的节点:${edge.from} -> ${edge.to}`);
|
|
92
|
+
this.edges.set(this.edgeKey(edge), { ...edge });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
getNode(id) {
|
|
96
|
+
const node = this.nodes.get(id);
|
|
97
|
+
return node ? {
|
|
98
|
+
...node,
|
|
99
|
+
scope: { ...node.scope }
|
|
100
|
+
} : void 0;
|
|
101
|
+
}
|
|
102
|
+
getNodes() {
|
|
103
|
+
return [...this.nodes.values()].map((node) => ({
|
|
104
|
+
...node,
|
|
105
|
+
scope: { ...node.scope }
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
getEdges() {
|
|
109
|
+
return [...this.edges.values()].map((edge) => ({ ...edge }));
|
|
110
|
+
}
|
|
111
|
+
getDependents(id) {
|
|
112
|
+
return this.getEdges().filter((edge) => edge.to === id).map((edge) => edge.from);
|
|
113
|
+
}
|
|
114
|
+
clear() {
|
|
115
|
+
this.edges.clear();
|
|
116
|
+
this.nodes.clear();
|
|
117
|
+
}
|
|
118
|
+
edgeKey(edge) {
|
|
119
|
+
return `${edge.kind}\0${edge.from}\0${edge.to}`;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/compiler/session.ts
|
|
124
|
+
var DefaultCompilationSession = class {
|
|
125
|
+
constructor() {
|
|
126
|
+
require_object._defineProperty(this, "candidateIndex", new CandidateIndex());
|
|
127
|
+
require_object._defineProperty(this, "graph", new SourceGraph());
|
|
128
|
+
require_object._defineProperty(this, "retainedCandidates", /* @__PURE__ */ new Set());
|
|
129
|
+
require_object._defineProperty(this, "validatedClassSet", /* @__PURE__ */ new Set());
|
|
130
|
+
require_object._defineProperty(this, "invalidatedScopes", /* @__PURE__ */ new Set());
|
|
131
|
+
require_object._defineProperty(this, "revision", 0);
|
|
132
|
+
}
|
|
133
|
+
update(snapshot) {
|
|
134
|
+
const changes = [...snapshot.changes ?? []];
|
|
135
|
+
const invalidatedScopes = resolveInvalidatedScopes(this.graph, changes);
|
|
136
|
+
this.graph.replace(snapshot.nodes, snapshot.edges);
|
|
137
|
+
for (const [sourceId, candidates] of snapshot.candidatesBySource ?? []) {
|
|
138
|
+
const change = this.candidateIndex.sync(sourceId, candidates);
|
|
139
|
+
if (change.addedCandidates.size > 0 || change.removedCandidates.size > 0) changes.push(change);
|
|
140
|
+
}
|
|
141
|
+
for (const change of changes) if ("type" in change && change.type === "source-removed") this.candidateIndex.remove(change.sourceId);
|
|
142
|
+
const currentCandidates = this.candidateIndex.values();
|
|
143
|
+
if (snapshot.preserveDeletedCss) for (const candidate of currentCandidates) this.retainedCandidates.add(candidate);
|
|
144
|
+
else {
|
|
145
|
+
this.retainedCandidates.clear();
|
|
146
|
+
for (const candidate of currentCandidates) this.retainedCandidates.add(candidate);
|
|
147
|
+
}
|
|
148
|
+
if (snapshot.validatedClassSet !== void 0) this.validatedClassSet = new Set(snapshot.validatedClassSet);
|
|
149
|
+
else if (!snapshot.preserveDeletedCss) this.validatedClassSet = new Set([...this.validatedClassSet].filter((candidate) => this.retainedCandidates.has(candidate)));
|
|
150
|
+
this.revision += 1;
|
|
151
|
+
for (const scopeId of resolveInvalidatedScopes(this.graph, changes)) invalidatedScopes.add(scopeId);
|
|
152
|
+
this.invalidatedScopes = invalidatedScopes;
|
|
153
|
+
return this.createResult();
|
|
154
|
+
}
|
|
155
|
+
commitValidation(revision, validatedClassSet, graph) {
|
|
156
|
+
if (revision !== this.revision) throw new Error(`不能向编译 revision ${this.revision} 提交 revision ${revision} 的 classSet。`);
|
|
157
|
+
if (graph) this.graph.replace(graph.nodes, graph.edges);
|
|
158
|
+
this.validatedClassSet = new Set(validatedClassSet);
|
|
159
|
+
return this.createResult();
|
|
160
|
+
}
|
|
161
|
+
createResult() {
|
|
162
|
+
return {
|
|
163
|
+
revision: this.revision,
|
|
164
|
+
candidates: new Set(this.retainedCandidates),
|
|
165
|
+
candidatesBySource: this.candidateIndex.entries(),
|
|
166
|
+
validatedClassSet: new Set(this.validatedClassSet),
|
|
167
|
+
invalidatedScopes: new Set(this.invalidatedScopes),
|
|
168
|
+
graphEdges: this.graph.getEdges(),
|
|
169
|
+
graphNodes: this.graph.getNodes()
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
dispose() {
|
|
173
|
+
this.candidateIndex.clear();
|
|
174
|
+
this.graph.clear();
|
|
175
|
+
this.retainedCandidates.clear();
|
|
176
|
+
this.validatedClassSet.clear();
|
|
177
|
+
this.invalidatedScopes.clear();
|
|
178
|
+
this.revision = 0;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/core/compiler/source-fingerprint.ts
|
|
183
|
+
function stableSerialize(value, stack = /* @__PURE__ */ new WeakSet()) {
|
|
184
|
+
if (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
185
|
+
if (typeof value === "function") return `[Function:${value.name}]`;
|
|
186
|
+
if (typeof value !== "object") return String(value);
|
|
187
|
+
if (stack.has(value)) return "[Circular]";
|
|
188
|
+
stack.add(value);
|
|
189
|
+
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(",")}}`;
|
|
190
|
+
stack.delete(value);
|
|
191
|
+
return serialized;
|
|
192
|
+
}
|
|
193
|
+
function createSourceFingerprint(source) {
|
|
194
|
+
return createCompilerValueFingerprint(source);
|
|
195
|
+
}
|
|
196
|
+
function createCompilerValueFingerprint(value) {
|
|
197
|
+
return (0, _weapp_tailwindcss_shared_node.md5)(stableSerialize(value));
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/core/compiler/generation-cache.ts
|
|
201
|
+
function createCompilerGenerationCacheKey(request, candidates, target) {
|
|
202
|
+
return {
|
|
203
|
+
bareArbitraryValues: request.bareArbitraryValues,
|
|
204
|
+
candidateSignature: [...candidates].sort().join("\0"),
|
|
205
|
+
incrementalCache: request.incrementalCache,
|
|
206
|
+
scanSources: request.scanSources,
|
|
207
|
+
sourcesFingerprint: request.sources === void 0 ? void 0 : createCompilerValueFingerprint(request.sources),
|
|
208
|
+
styleOptionsFingerprint: request.styleOptions === void 0 ? void 0 : createCompilerValueFingerprint(request.styleOptions),
|
|
209
|
+
target
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function isSameCompilerGenerationCacheKey(left, right) {
|
|
213
|
+
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;
|
|
214
|
+
}
|
|
215
|
+
function reuseCompilerGenerationResult(result) {
|
|
216
|
+
return {
|
|
217
|
+
...result,
|
|
218
|
+
incrementalCss: "",
|
|
219
|
+
incrementalRawCss: ""
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/core/compiler/generation-state.ts
|
|
224
|
+
function createGenerationGraph(rootId, source, dependencies) {
|
|
225
|
+
const scope = {
|
|
226
|
+
id: rootId,
|
|
227
|
+
kind: "global"
|
|
228
|
+
};
|
|
229
|
+
const dependencyIds = [...new Set(dependencies)].filter((id) => id !== rootId).sort();
|
|
230
|
+
const nodes = [{
|
|
231
|
+
content: source.css,
|
|
232
|
+
id: rootId,
|
|
233
|
+
kind: "css",
|
|
234
|
+
scope
|
|
235
|
+
}, ...dependencyIds.map((id) => ({
|
|
236
|
+
id,
|
|
237
|
+
kind: "config",
|
|
238
|
+
scope
|
|
239
|
+
}))];
|
|
240
|
+
return {
|
|
241
|
+
edges: dependencyIds.map((id) => ({
|
|
242
|
+
from: rootId,
|
|
243
|
+
kind: "depends-on",
|
|
244
|
+
to: id
|
|
245
|
+
})),
|
|
246
|
+
nodes
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function prepareCompilerGeneration(entry, request, source, sourceChanged) {
|
|
250
|
+
const explicitCandidates = request.candidates !== void 0;
|
|
251
|
+
const candidates = explicitCandidates ? [...request.candidates] : [];
|
|
252
|
+
const candidateSignature = [...candidates].sort().join("\0");
|
|
253
|
+
if (!sourceChanged && entry.compilationCache?.candidateSignature === candidateSignature && entry.compilationCache.compilation.revision === entry.compilationRevision) return {
|
|
254
|
+
...entry.compilationCache,
|
|
255
|
+
explicitCandidates
|
|
256
|
+
};
|
|
257
|
+
const graph = createGenerationGraph(entry.id, source, source.dependencies);
|
|
258
|
+
const compilation = entry.compilation.update({
|
|
259
|
+
...graph,
|
|
260
|
+
candidatesBySource: [[entry.id, candidates]],
|
|
261
|
+
changes: sourceChanged ? [{
|
|
262
|
+
sourceId: entry.id,
|
|
263
|
+
type: "dependency-changed"
|
|
264
|
+
}] : void 0
|
|
265
|
+
});
|
|
266
|
+
entry.compilationRevision = compilation.revision;
|
|
267
|
+
return {
|
|
268
|
+
candidateSignature,
|
|
269
|
+
compilation,
|
|
270
|
+
explicitCandidates,
|
|
271
|
+
graph
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function commitCompilerGeneration(entry, prepared, source, dependencies, classSet) {
|
|
275
|
+
const graph = createGenerationGraph(entry.id, source, dependencies);
|
|
276
|
+
const compilation = entry.compilation.commitValidation(prepared.compilation.revision, classSet, graph);
|
|
277
|
+
entry.compilationCache = {
|
|
278
|
+
candidateSignature: prepared.candidateSignature,
|
|
279
|
+
compilation,
|
|
280
|
+
graph
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/core/compiler/root-store.ts
|
|
285
|
+
function disposeGenerator(generator) {
|
|
286
|
+
generator?.dispose?.();
|
|
287
|
+
}
|
|
288
|
+
var CompilerRootStore = class {
|
|
289
|
+
constructor(maxRoots, onRootEvicted) {
|
|
290
|
+
this.maxRoots = maxRoots;
|
|
291
|
+
this.onRootEvicted = onRootEvicted;
|
|
292
|
+
require_object._defineProperty(this, "dependencyRoots", /* @__PURE__ */ new Map());
|
|
293
|
+
require_object._defineProperty(this, "releasing", /* @__PURE__ */ new Map());
|
|
294
|
+
require_object._defineProperty(this, "roots", /* @__PURE__ */ new Map());
|
|
295
|
+
}
|
|
296
|
+
get(id) {
|
|
297
|
+
if (!id) throw new Error("Compiler root id 不能为空。");
|
|
298
|
+
if (this.releasing.has(id)) throw new Error(`Compiler root 正在移除:${id}`);
|
|
299
|
+
const cached = this.roots.get(id);
|
|
300
|
+
if (cached) {
|
|
301
|
+
if (!cached.accepting) throw new Error(`Compiler root 正在移除:${id}`);
|
|
302
|
+
this.roots.delete(id);
|
|
303
|
+
this.roots.set(id, cached);
|
|
304
|
+
return cached;
|
|
305
|
+
}
|
|
306
|
+
if (this.roots.size >= this.maxRoots) {
|
|
307
|
+
const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
|
|
308
|
+
if (oldest) this.remove(oldest.id, true);
|
|
309
|
+
}
|
|
310
|
+
const entry = {
|
|
311
|
+
accepting: true,
|
|
312
|
+
active: true,
|
|
313
|
+
appliedInvalidation: 0,
|
|
314
|
+
compilation: new DefaultCompilationSession(),
|
|
315
|
+
compilationRevision: 0,
|
|
316
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
317
|
+
id,
|
|
318
|
+
invalidation: 0,
|
|
319
|
+
pending: Promise.resolve(),
|
|
320
|
+
pendingCount: 0,
|
|
321
|
+
sources: []
|
|
322
|
+
};
|
|
323
|
+
this.roots.set(id, entry);
|
|
324
|
+
return entry;
|
|
325
|
+
}
|
|
326
|
+
attachDependencies(entry, dependencies) {
|
|
327
|
+
this.detachDependencies(entry);
|
|
328
|
+
if (!entry.accepting) return;
|
|
329
|
+
for (const dependency of dependencies) {
|
|
330
|
+
entry.dependencies.add(dependency);
|
|
331
|
+
let owners = this.dependencyRoots.get(dependency);
|
|
332
|
+
if (!owners) {
|
|
333
|
+
owners = /* @__PURE__ */ new Set();
|
|
334
|
+
this.dependencyRoots.set(dependency, owners);
|
|
335
|
+
}
|
|
336
|
+
owners.add(entry.id);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
attachSources(entry, sources) {
|
|
340
|
+
entry.sources = [...sources];
|
|
341
|
+
}
|
|
342
|
+
invalidate(ids) {
|
|
343
|
+
const affected = /* @__PURE__ */ new Set();
|
|
344
|
+
for (const id of ids) {
|
|
345
|
+
const root = this.roots.get(id);
|
|
346
|
+
if (root?.accepting) affected.add(root.id);
|
|
347
|
+
for (const rootId of this.dependencyRoots.get(id) ?? []) affected.add(rootId);
|
|
348
|
+
const sourcePath = stripSourceQuery(id);
|
|
349
|
+
for (const sourceRoot of this.roots.values()) if (sourceRoot.accepting && sourceRoot.sources.length > 0 && require_generator.isFileMatchedByTailwindSourceEntries(sourcePath, sourceRoot.sources)) affected.add(sourceRoot.id);
|
|
350
|
+
}
|
|
351
|
+
for (const rootId of affected) {
|
|
352
|
+
const entry = this.roots.get(rootId);
|
|
353
|
+
if (entry?.accepting) entry.invalidation += 1;
|
|
354
|
+
}
|
|
355
|
+
return Object.freeze([...affected].sort());
|
|
356
|
+
}
|
|
357
|
+
trim() {
|
|
358
|
+
while (this.roots.size > this.maxRoots) {
|
|
359
|
+
const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
|
|
360
|
+
if (!oldest) return;
|
|
361
|
+
this.remove(oldest.id, true);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
remove(id, notifyEvicted = false) {
|
|
365
|
+
const pendingRelease = this.releasing.get(id);
|
|
366
|
+
if (pendingRelease) return pendingRelease;
|
|
367
|
+
const entry = this.roots.get(id);
|
|
368
|
+
if (!entry) return Promise.resolve();
|
|
369
|
+
entry.accepting = false;
|
|
370
|
+
this.roots.delete(id);
|
|
371
|
+
this.detachDependencies(entry);
|
|
372
|
+
const release = entry.pending.then(() => {
|
|
373
|
+
entry.active = false;
|
|
374
|
+
entry.compilation.dispose();
|
|
375
|
+
entry.compilationCache = void 0;
|
|
376
|
+
disposeGenerator(entry.generator);
|
|
377
|
+
entry.generator = void 0;
|
|
378
|
+
entry.generationCache = void 0;
|
|
379
|
+
entry.latestSnapshot = void 0;
|
|
380
|
+
entry.source = void 0;
|
|
381
|
+
entry.sourceInput = void 0;
|
|
382
|
+
entry.sourceFingerprint = void 0;
|
|
383
|
+
entry.sources = [];
|
|
384
|
+
if (notifyEvicted) this.onRootEvicted?.(id);
|
|
385
|
+
}).finally(() => {
|
|
386
|
+
this.releasing.delete(id);
|
|
387
|
+
});
|
|
388
|
+
this.releasing.set(id, release);
|
|
389
|
+
return release;
|
|
390
|
+
}
|
|
391
|
+
async dispose() {
|
|
392
|
+
await Promise.all([...[...this.roots.keys()].map((id) => this.remove(id)), ...this.releasing.values()]);
|
|
393
|
+
this.dependencyRoots.clear();
|
|
394
|
+
}
|
|
395
|
+
detachDependencies(entry) {
|
|
396
|
+
for (const dependency of entry.dependencies) {
|
|
397
|
+
const owners = this.dependencyRoots.get(dependency);
|
|
398
|
+
owners?.delete(entry.id);
|
|
399
|
+
if (owners?.size === 0) this.dependencyRoots.delete(dependency);
|
|
400
|
+
}
|
|
401
|
+
entry.dependencies.clear();
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
function stripSourceQuery(id) {
|
|
405
|
+
return id.replace(/[?#].*$/, "");
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/core/compiler/snapshot.ts
|
|
409
|
+
const readonlySetValues = /* @__PURE__ */ new WeakMap();
|
|
410
|
+
const snapshotRegistry = /* @__PURE__ */ new WeakMap();
|
|
411
|
+
var ImmutableSetView = class {
|
|
412
|
+
constructor(values) {
|
|
413
|
+
readonlySetValues.set(this, new Set(values));
|
|
414
|
+
Object.freeze(this);
|
|
415
|
+
}
|
|
416
|
+
get size() {
|
|
417
|
+
return this.valuesSet.size;
|
|
418
|
+
}
|
|
419
|
+
get [Symbol.toStringTag]() {
|
|
420
|
+
return "Set";
|
|
421
|
+
}
|
|
422
|
+
has(value) {
|
|
423
|
+
return this.valuesSet.has(value);
|
|
424
|
+
}
|
|
425
|
+
entries() {
|
|
426
|
+
return this.valuesSet.entries();
|
|
427
|
+
}
|
|
428
|
+
keys() {
|
|
429
|
+
return this.valuesSet.keys();
|
|
430
|
+
}
|
|
431
|
+
values() {
|
|
432
|
+
return this.valuesSet.values();
|
|
433
|
+
}
|
|
434
|
+
forEach(callbackfn, thisArg) {
|
|
435
|
+
for (const value of this.valuesSet) callbackfn.call(thisArg, value, value, this);
|
|
436
|
+
}
|
|
437
|
+
[Symbol.iterator]() {
|
|
438
|
+
return this.values();
|
|
439
|
+
}
|
|
440
|
+
get valuesSet() {
|
|
441
|
+
return readonlySetValues.get(this);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
function uniqueSorted(values) {
|
|
445
|
+
return Object.freeze([...new Set(values)].sort());
|
|
446
|
+
}
|
|
447
|
+
function sourceKey(source) {
|
|
448
|
+
return `${source.base}\0${source.pattern}\0${source.negated ? "1" : "0"}`;
|
|
449
|
+
}
|
|
450
|
+
function uniqueSortedSources(sources) {
|
|
451
|
+
const values = /* @__PURE__ */ new Map();
|
|
452
|
+
for (const source of sources) {
|
|
453
|
+
const cloned = Object.freeze({ ...source });
|
|
454
|
+
values.set(sourceKey(cloned), cloned);
|
|
455
|
+
}
|
|
456
|
+
return Object.freeze([...values.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, value]) => value));
|
|
457
|
+
}
|
|
458
|
+
function createRootFingerprint(root, target, classSet, dependencies, sources) {
|
|
459
|
+
return [
|
|
460
|
+
root.id,
|
|
461
|
+
String(root.revision),
|
|
462
|
+
target,
|
|
463
|
+
...[...classSet].sort(),
|
|
464
|
+
...dependencies,
|
|
465
|
+
...[...sources].map(sourceKey)
|
|
466
|
+
].join("\0");
|
|
467
|
+
}
|
|
468
|
+
function createSnapshotFromState(state, reusableClassSet, reusableClassSetView) {
|
|
469
|
+
const roots = Object.freeze([...state.roots.values()].sort((left, right) => left.id.localeCompare(right.id)).map(({ id, revision }) => Object.freeze({
|
|
470
|
+
id,
|
|
471
|
+
revision
|
|
472
|
+
})));
|
|
473
|
+
const classSet = reusableClassSet ?? new Set(state.classSet);
|
|
474
|
+
const fingerprint = [
|
|
475
|
+
state.target,
|
|
476
|
+
...[...state.roots.values()].map((root) => `${root.id}\0${root.revision}\0${root.fingerprint}`).sort(),
|
|
477
|
+
...[...classSet].sort(),
|
|
478
|
+
...state.dependencies,
|
|
479
|
+
...state.sources.map(sourceKey)
|
|
480
|
+
].join("\0");
|
|
481
|
+
const snapshot = Object.freeze({
|
|
482
|
+
classSet: reusableClassSetView ?? new ImmutableSetView(classSet),
|
|
483
|
+
dependencies: state.dependencies,
|
|
484
|
+
roots,
|
|
485
|
+
sources: state.sources,
|
|
486
|
+
target: state.target
|
|
487
|
+
});
|
|
488
|
+
snapshotRegistry.set(snapshot, {
|
|
489
|
+
...state,
|
|
490
|
+
classSet,
|
|
491
|
+
fingerprint
|
|
492
|
+
});
|
|
493
|
+
return snapshot;
|
|
494
|
+
}
|
|
495
|
+
function createRegisteredCompilerSnapshot(request, reusableClassSet, reusableClassSetView) {
|
|
496
|
+
if (!request.id) throw new Error("Compiler snapshot 的 root id 不能为空。");
|
|
497
|
+
const revision = request.revision ?? 0;
|
|
498
|
+
if (!Number.isSafeInteger(revision) || revision < 0) throw new Error(`Compiler snapshot revision 必须是非负安全整数:${revision}`);
|
|
499
|
+
const target = request.target ?? "weapp";
|
|
500
|
+
const classSet = new Set(request.classSet);
|
|
501
|
+
const dependencies = uniqueSorted(request.dependencies ?? []);
|
|
502
|
+
const sources = uniqueSortedSources(request.sources ?? []);
|
|
503
|
+
const root = {
|
|
504
|
+
id: request.id,
|
|
505
|
+
revision
|
|
506
|
+
};
|
|
507
|
+
const internalRoot = {
|
|
508
|
+
...root,
|
|
509
|
+
fingerprint: createRootFingerprint(root, target, classSet, dependencies, sources)
|
|
510
|
+
};
|
|
511
|
+
return createSnapshotFromState({
|
|
512
|
+
classSet,
|
|
513
|
+
dependencies,
|
|
514
|
+
roots: /* @__PURE__ */ new Map([[root.id, internalRoot]]),
|
|
515
|
+
sources,
|
|
516
|
+
target
|
|
517
|
+
}, reusableClassSet, reusableClassSetView);
|
|
518
|
+
}
|
|
519
|
+
function getInternalCompilerSnapshot(snapshot) {
|
|
520
|
+
const state = snapshotRegistry.get(snapshot);
|
|
521
|
+
if (!state) throw new Error("Compiler snapshot 必须由 createSnapshot()、generate() 或 mergeSnapshots() 创建。");
|
|
522
|
+
return state;
|
|
523
|
+
}
|
|
524
|
+
function mergeRegisteredCompilerSnapshots(snapshots) {
|
|
525
|
+
const states = [...snapshots].map(getInternalCompilerSnapshot);
|
|
526
|
+
if (states.length === 0) throw new Error("mergeSnapshots() 至少需要一个 snapshot。");
|
|
527
|
+
const target = states[0].target;
|
|
528
|
+
const roots = /* @__PURE__ */ new Map();
|
|
529
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
530
|
+
const dependencies = [];
|
|
531
|
+
const sources = [];
|
|
532
|
+
for (const state of states) {
|
|
533
|
+
if (state.target !== target) throw new Error(`不能合并不同 target 的 snapshot:${target} 与 ${state.target}`);
|
|
534
|
+
for (const root of state.roots.values()) {
|
|
535
|
+
const current = roots.get(root.id);
|
|
536
|
+
if (current && current.revision !== root.revision) throw new Error(`同一 root 不能合并不同 revision:${root.id} (${current.revision} / ${root.revision})`);
|
|
537
|
+
if (current && current.fingerprint !== root.fingerprint) throw new Error(`同一 root revision 的 snapshot 内容冲突:${root.id}@${root.revision}`);
|
|
538
|
+
roots.set(root.id, root);
|
|
539
|
+
}
|
|
540
|
+
for (const candidate of state.classSet) classSet.add(candidate);
|
|
541
|
+
dependencies.push(...state.dependencies);
|
|
542
|
+
sources.push(...state.sources);
|
|
543
|
+
}
|
|
544
|
+
return createSnapshotFromState({
|
|
545
|
+
classSet: new Set([...classSet].sort()),
|
|
546
|
+
dependencies: uniqueSorted(dependencies),
|
|
547
|
+
roots,
|
|
548
|
+
sources: uniqueSortedSources(sources),
|
|
549
|
+
target
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
function createImmutableSet(values) {
|
|
553
|
+
return new ImmutableSetView(values);
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
24
556
|
//#region src/cache/index.ts
|
|
25
557
|
function isProcessResult(value) {
|
|
26
558
|
return typeof value === "object" && value !== null && "result" in value;
|
|
@@ -619,7 +1151,7 @@ function toCustomAttributesEntities(customAttributes) {
|
|
|
619
1151
|
return Object.entries(customAttributes);
|
|
620
1152
|
}
|
|
621
1153
|
//#endregion
|
|
622
|
-
//#region ../../node_modules/.pnpm/oxc-walker@1.1.1_@oxc-project+types@0.
|
|
1154
|
+
//#region ../../node_modules/.pnpm/oxc-walker@1.1.1_@oxc-project+types@0.147.0_oxc-parser@0.147.0_rolldown@1.2.3/node_modules/oxc-walker/dist/index.mjs
|
|
623
1155
|
function isNode(v) {
|
|
624
1156
|
return v !== null && typeof v === "object" && typeof v.type === "string";
|
|
625
1157
|
}
|
|
@@ -1146,11 +1678,79 @@ function resolveRuntimePackageReplacements(option) {
|
|
|
1146
1678
|
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
1147
1679
|
}
|
|
1148
1680
|
//#endregion
|
|
1681
|
+
//#region src/context/style-options.ts
|
|
1682
|
+
function normalizeStyleHandlerMajorVersion(majorVersion) {
|
|
1683
|
+
return majorVersion === 4 ? 4 : void 0;
|
|
1684
|
+
}
|
|
1685
|
+
function resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion) {
|
|
1686
|
+
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX);
|
|
1687
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(ctx.generator, {
|
|
1688
|
+
appType: ctx.appType,
|
|
1689
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
1690
|
+
tailwindcssMajorVersion,
|
|
1691
|
+
uniAppX: resolvedUniAppXOptions
|
|
1692
|
+
});
|
|
1693
|
+
const branch = require_generator.resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
1694
|
+
appType: ctx.appType,
|
|
1695
|
+
platform: ctx.cssOptions?.platform ?? ctx.platform,
|
|
1696
|
+
tailwindcssMajorVersion,
|
|
1697
|
+
uniAppX: resolvedUniAppXOptions
|
|
1698
|
+
});
|
|
1699
|
+
const hasCssOptions = ctx.cssOptions !== void 0;
|
|
1700
|
+
const configuredRem2rpx = ctx.cssOptions?.rem2rpx ?? ctx.rem2rpx;
|
|
1701
|
+
const rem2rpx = branch.isWeb && require_generator.shouldUseUniAppWebRpxCompatibility(ctx.appType) ? false : configuredRem2rpx;
|
|
1702
|
+
const cssOptions = {
|
|
1703
|
+
cssPreflight: ctx.cssOptions?.cssPreflight ?? ctx.cssPreflight,
|
|
1704
|
+
cssPreflightRange: ctx.cssOptions?.cssPreflightRange ?? ctx.cssPreflightRange,
|
|
1705
|
+
cssChildCombinatorReplaceValue: ctx.cssOptions?.cssChildCombinatorReplaceValue ?? ctx.cssChildCombinatorReplaceValue,
|
|
1706
|
+
cssSelectorReplacement: ctx.cssOptions?.cssSelectorReplacement ?? ctx.cssSelectorReplacement,
|
|
1707
|
+
rem2rpx,
|
|
1708
|
+
cssRemoveProperty: ctx.cssOptions?.cssRemoveProperty ?? ctx.cssRemoveProperty,
|
|
1709
|
+
cssRemoveActivePseudoClass: ctx.cssOptions?.cssRemoveActivePseudoClass ?? ctx.cssRemoveActivePseudoClass,
|
|
1710
|
+
cssRemoveHoverPseudoClass: ctx.cssOptions?.cssRemoveHoverPseudoClass ?? ctx.cssRemoveHoverPseudoClass,
|
|
1711
|
+
cssRemoveFocusPseudoClass: ctx.cssOptions?.cssRemoveFocusPseudoClass ?? ctx.cssRemoveFocusPseudoClass,
|
|
1712
|
+
tailwindcssV4GradientFallback: ctx.cssOptions?.tailwindcssV4GradientFallback ?? ctx.tailwindcssV4GradientFallback,
|
|
1713
|
+
cssPresetEnv: ctx.cssOptions?.cssPresetEnv ?? ctx.cssPresetEnv,
|
|
1714
|
+
atRules: ctx.cssOptions?.atRules ?? ctx.atRules,
|
|
1715
|
+
autoprefixer: ctx.cssOptions?.autoprefixer ?? ctx.autoprefixer,
|
|
1716
|
+
cssCalc: ctx.cssOptions?.cssCalc ?? ctx.cssCalc,
|
|
1717
|
+
platform: branch.platform ?? ctx.cssOptions?.platform ?? ctx.platform,
|
|
1718
|
+
px2rpx: ctx.cssOptions?.px2rpx ?? ctx.px2rpx,
|
|
1719
|
+
unitsToPx: ctx.cssOptions?.unitsToPx ?? ctx.unitsToPx,
|
|
1720
|
+
unitConversion: ctx.cssOptions?.unitConversion ?? ctx.unitConversion,
|
|
1721
|
+
injectAdditionalCssVarScope: ctx.cssOptions?.injectAdditionalCssVarScope ?? ctx.injectAdditionalCssVarScope
|
|
1722
|
+
};
|
|
1723
|
+
return {
|
|
1724
|
+
appType: ctx.appType,
|
|
1725
|
+
postcssOptions: ctx.postcssOptions,
|
|
1726
|
+
cssPreflight: cssOptions.cssPreflight,
|
|
1727
|
+
cssPreflightRange: cssOptions.cssPreflightRange,
|
|
1728
|
+
cssChildCombinatorReplaceValue: cssOptions.cssChildCombinatorReplaceValue,
|
|
1729
|
+
cssSelectorReplacement: cssOptions.cssSelectorReplacement,
|
|
1730
|
+
rem2rpx: cssOptions.rem2rpx,
|
|
1731
|
+
...hasCssOptions ? { cssOptions } : {},
|
|
1732
|
+
cssRemoveProperty: cssOptions.cssRemoveProperty,
|
|
1733
|
+
cssRemoveActivePseudoClass: cssOptions.cssRemoveActivePseudoClass,
|
|
1734
|
+
cssRemoveHoverPseudoClass: cssOptions.cssRemoveHoverPseudoClass,
|
|
1735
|
+
cssRemoveFocusPseudoClass: cssOptions.cssRemoveFocusPseudoClass,
|
|
1736
|
+
tailwindcssV4GradientFallback: cssOptions.tailwindcssV4GradientFallback,
|
|
1737
|
+
cssPresetEnv: cssOptions.cssPresetEnv,
|
|
1738
|
+
atRules: cssOptions.atRules,
|
|
1739
|
+
autoprefixer: cssOptions.autoprefixer,
|
|
1740
|
+
cssCalc: cssOptions.cssCalc,
|
|
1741
|
+
uniAppX: branch.isNativeApp,
|
|
1742
|
+
platform: cssOptions.platform,
|
|
1743
|
+
px2rpx: cssOptions.px2rpx,
|
|
1744
|
+
unitsToPx: cssOptions.unitsToPx,
|
|
1745
|
+
unitConversion: cssOptions.unitConversion
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
//#endregion
|
|
1149
1749
|
//#region src/context/handlers.ts
|
|
1150
1750
|
function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
|
|
1151
1751
|
const { escapeMap, injectAdditionalCssVarScope, postcssOptions, uniAppX, arbitraryValues, jsPreserveClass, babelParserOptions, experimentalJsFastPath, ignoreCallExpressionIdentifiers, ignoreTaggedTemplateExpressionIdentifiers, inlineWxs, disabledDefaultTemplateHandler, replaceRuntimePackages } = ctx;
|
|
1152
|
-
const resolvedUniAppXOptions =
|
|
1153
|
-
const styleOptions =
|
|
1752
|
+
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
|
|
1753
|
+
const styleOptions = resolveStyleOptionsFromContext(ctx, tailwindcssMajorVersion);
|
|
1154
1754
|
const resolvedInjectAdditionalCssVarScope = styleOptions.cssOptions?.injectAdditionalCssVarScope ?? injectAdditionalCssVarScope;
|
|
1155
1755
|
const uniAppXEnabled = styleOptions.uniAppX === true;
|
|
1156
1756
|
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
@@ -1161,7 +1761,7 @@ function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions
|
|
|
1161
1761
|
postcssOptions,
|
|
1162
1762
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
1163
1763
|
cssCalc: cssCalcOptions,
|
|
1164
|
-
majorVersion:
|
|
1764
|
+
majorVersion: normalizeStyleHandlerMajorVersion(tailwindcssMajorVersion)
|
|
1165
1765
|
});
|
|
1166
1766
|
const jsHandler = createJsHandler({
|
|
1167
1767
|
escapeMap,
|
|
@@ -1203,7 +1803,7 @@ function applyLoggerLevel(logLevel) {
|
|
|
1203
1803
|
function resolveContextCssPreflight(opts, ctx, majorVersion) {
|
|
1204
1804
|
const userCssPreflight = opts?.cssOptions?.cssPreflight ?? opts?.cssPreflight;
|
|
1205
1805
|
const cssPreflight = require_defaults.resolveDefaultCssPreflight(userCssPreflight, majorVersion);
|
|
1206
|
-
const shouldUseUniAppXPreflight = ctx.appType === "uni-app-x" ||
|
|
1806
|
+
const shouldUseUniAppXPreflight = ctx.appType === "uni-app-x" || require_tailwindcss.resolveUniAppXOptions(ctx.uniAppX).enabled;
|
|
1207
1807
|
if (cssPreflight === false || !shouldUseUniAppXPreflight) return cssPreflight;
|
|
1208
1808
|
const userCssPreflightObject = userCssPreflight && typeof userCssPreflight === "object" ? userCssPreflight : void 0;
|
|
1209
1809
|
return {
|
|
@@ -1344,12 +1944,296 @@ function getCompilerContext(opts) {
|
|
|
1344
1944
|
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
1345
1945
|
}
|
|
1346
1946
|
//#endregion
|
|
1947
|
+
//#region src/core/compiler/transforms.ts
|
|
1948
|
+
const DEFAULT_JS_OPTIONS = Object.freeze({ tailwindcssMajorVersion: 4 });
|
|
1949
|
+
const DEFAULT_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|
|
1950
|
+
function clonePostcssResult(result) {
|
|
1951
|
+
return Object.assign(Object.create(Object.getPrototypeOf(result)), result, {
|
|
1952
|
+
messages: [...result.messages],
|
|
1953
|
+
root: result.root.clone()
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
function resolveStyleOptions(options) {
|
|
1957
|
+
if (!options) return DEFAULT_STYLE_OPTIONS;
|
|
1958
|
+
return options?.isMainChunk === void 0 ? {
|
|
1959
|
+
...options,
|
|
1960
|
+
isMainChunk: true
|
|
1961
|
+
} : options;
|
|
1962
|
+
}
|
|
1963
|
+
function resolveCssTransformOptions(options) {
|
|
1964
|
+
const { finalize: _finalize, ...styleOptions } = options ?? {};
|
|
1965
|
+
return {
|
|
1966
|
+
finalize: _finalize,
|
|
1967
|
+
styleOptions: resolveStyleOptions(styleOptions)
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
function finalizeResultRoot(result, snapshot, shouldFinalize) {
|
|
1971
|
+
if (!shouldFinalize || result.root.type !== "root") return;
|
|
1972
|
+
(0, _weapp_tailwindcss_postcss.finalizeMiniProgramCssRoot)(result.root, { isTailwindcssV4: snapshot.target === "weapp" });
|
|
1973
|
+
result.css = result.root.toString();
|
|
1974
|
+
}
|
|
1975
|
+
function createCompilerTransforms({ ensureActive, track, userOptions }) {
|
|
1976
|
+
const context = getCompilerContext({
|
|
1977
|
+
...userOptions,
|
|
1978
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
1979
|
+
});
|
|
1980
|
+
const styleHandler = context.styleHandler;
|
|
1981
|
+
let cachedTemplateClassSet;
|
|
1982
|
+
let cachedTemplateOptions;
|
|
1983
|
+
function clearCache() {
|
|
1984
|
+
cachedTemplateClassSet = void 0;
|
|
1985
|
+
cachedTemplateOptions = void 0;
|
|
1986
|
+
}
|
|
1987
|
+
function createTemplateOptions(classSet, options) {
|
|
1988
|
+
const isDefault = !options || Object.keys(options).length === 0;
|
|
1989
|
+
if (isDefault && cachedTemplateClassSet === classSet && cachedTemplateOptions) return cachedTemplateOptions;
|
|
1990
|
+
const resolved = {
|
|
1991
|
+
...options,
|
|
1992
|
+
classSetMode: "exact",
|
|
1993
|
+
jsHandler: (jsSource, _runtimeSet, jsOptions) => context.jsHandler(jsSource, classSet, {
|
|
1994
|
+
...jsOptions,
|
|
1995
|
+
tailwindcssMajorVersion: jsOptions?.tailwindcssMajorVersion ?? 4
|
|
1996
|
+
}),
|
|
1997
|
+
runtimeSet: classSet
|
|
1998
|
+
};
|
|
1999
|
+
if (isDefault) {
|
|
2000
|
+
cachedTemplateClassSet = classSet;
|
|
2001
|
+
cachedTemplateOptions = resolved;
|
|
2002
|
+
}
|
|
2003
|
+
return resolved;
|
|
2004
|
+
}
|
|
2005
|
+
function transformCss(css, snapshot, options) {
|
|
2006
|
+
ensureActive();
|
|
2007
|
+
getInternalCompilerSnapshot(snapshot);
|
|
2008
|
+
const resolved = resolveCssTransformOptions(options);
|
|
2009
|
+
const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
|
|
2010
|
+
return track(styleHandler(css, resolved.styleOptions).then((result) => {
|
|
2011
|
+
const cloned = clonePostcssResult(result);
|
|
2012
|
+
finalizeResultRoot(cloned, snapshot, shouldFinalize);
|
|
2013
|
+
return cloned;
|
|
2014
|
+
}));
|
|
2015
|
+
}
|
|
2016
|
+
function transformCssRoot(root, snapshot, options) {
|
|
2017
|
+
ensureActive();
|
|
2018
|
+
getInternalCompilerSnapshot(snapshot);
|
|
2019
|
+
const resolved = resolveCssTransformOptions(options);
|
|
2020
|
+
const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
|
|
2021
|
+
return track(styleHandler.transformRoot(root, resolved.styleOptions).then((result) => {
|
|
2022
|
+
finalizeResultRoot(result, snapshot, shouldFinalize);
|
|
2023
|
+
return result;
|
|
2024
|
+
}));
|
|
2025
|
+
}
|
|
2026
|
+
function transformJavaScript(source, snapshot, options) {
|
|
2027
|
+
ensureActive();
|
|
2028
|
+
const classSet = getInternalCompilerSnapshot(snapshot).classSet;
|
|
2029
|
+
const resolvedOptions = options?.tailwindcssMajorVersion === void 0 ? options ? {
|
|
2030
|
+
...options,
|
|
2031
|
+
tailwindcssMajorVersion: 4
|
|
2032
|
+
} : DEFAULT_JS_OPTIONS : options;
|
|
2033
|
+
return track(Promise.resolve(shouldSkipJsTransform(source, resolvedOptions) ? { code: source } : context.jsHandler(source, classSet, resolvedOptions)));
|
|
2034
|
+
}
|
|
2035
|
+
function transformTemplate(source, snapshot, options) {
|
|
2036
|
+
ensureActive();
|
|
2037
|
+
const classSet = getInternalCompilerSnapshot(snapshot).classSet;
|
|
2038
|
+
return track(context.templateHandler(source, createTemplateOptions(classSet, options)));
|
|
2039
|
+
}
|
|
2040
|
+
return {
|
|
2041
|
+
clearCache,
|
|
2042
|
+
transformCss,
|
|
2043
|
+
transformCssRoot,
|
|
2044
|
+
transformJavaScript,
|
|
2045
|
+
transformTemplate
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
//#endregion
|
|
2049
|
+
//#region src/core/compiler/compiler.ts
|
|
2050
|
+
const DEFAULT_MAX_ROOTS = 128;
|
|
2051
|
+
function createCompiler(options = {}) {
|
|
2052
|
+
const { compiler: compilerOptions, ...userOptions } = options;
|
|
2053
|
+
const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)), compilerOptions?.onRootEvicted);
|
|
2054
|
+
const activeTasks = /* @__PURE__ */ new Set();
|
|
2055
|
+
let lifecycle = "active";
|
|
2056
|
+
let disposePromise;
|
|
2057
|
+
function ensureActive() {
|
|
2058
|
+
if (lifecycle !== "active") throw new Error(lifecycle === "disposing" ? "Compiler 正在释放,不能接受新任务。" : "Compiler 已释放。");
|
|
2059
|
+
}
|
|
2060
|
+
function track(task) {
|
|
2061
|
+
activeTasks.add(task);
|
|
2062
|
+
task.then(() => activeTasks.delete(task), () => activeTasks.delete(task));
|
|
2063
|
+
return task;
|
|
2064
|
+
}
|
|
2065
|
+
const { clearCache: clearTransformCache, ...transforms } = createCompilerTransforms({
|
|
2066
|
+
ensureActive,
|
|
2067
|
+
track,
|
|
2068
|
+
userOptions
|
|
2069
|
+
});
|
|
2070
|
+
async function resolveRequestSource(entry, request) {
|
|
2071
|
+
if (request.source && request.sourceOptions) throw new Error("generate() 的 source 与 sourceOptions 互斥。");
|
|
2072
|
+
if (!request.source && !request.sourceOptions) throw new Error("generate() 必须提供 source 或 sourceOptions。");
|
|
2073
|
+
const sourceInput = request.source ?? request.sourceOptions;
|
|
2074
|
+
return {
|
|
2075
|
+
source: entry.source !== void 0 && entry.sourceInput === sourceInput && entry.appliedInvalidation === entry.invalidation ? entry.source : request.source ?? await require_generator.resolveTailwindV4Source(request.sourceOptions),
|
|
2076
|
+
sourceInput
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
async function runGenerate(entry, request) {
|
|
2080
|
+
if (!entry.active) throw new Error(`Compiler root 已被移除:${entry.id}`);
|
|
2081
|
+
const invalidation = entry.invalidation;
|
|
2082
|
+
const { source, sourceInput } = await resolveRequestSource(entry, request);
|
|
2083
|
+
const sourceFingerprint = entry.sourceInput === sourceInput && entry.sourceFingerprint !== void 0 && entry.appliedInvalidation === invalidation ? entry.sourceFingerprint : createSourceFingerprint(source);
|
|
2084
|
+
const sourceReused = entry.sourceFingerprint === sourceFingerprint;
|
|
2085
|
+
const engineReused = sourceReused && entry.generator !== void 0 && entry.appliedInvalidation === invalidation;
|
|
2086
|
+
const generator = engineReused ? entry.generator : require_generator.createWeappTailwindcssGenerator(source);
|
|
2087
|
+
const target = request.target ?? "weapp";
|
|
2088
|
+
const { id: _id, source: _source, sourceOptions: _sourceOptions, target: _target, ...generateOptions } = request;
|
|
2089
|
+
const prepared = prepareCompilerGeneration(entry, request, source, !sourceReused || entry.appliedInvalidation !== invalidation);
|
|
2090
|
+
const generationCacheKey = createCompilerGenerationCacheKey(request, prepared.compilation.candidates, target);
|
|
2091
|
+
const reusableGeneration = engineReused && entry.generationCache && isSameCompilerGenerationCacheKey(entry.generationCache.key, generationCacheKey) ? entry.generationCache.result : void 0;
|
|
2092
|
+
try {
|
|
2093
|
+
const generated = reusableGeneration ? reuseCompilerGenerationResult(reusableGeneration) : await generator.generate({
|
|
2094
|
+
...generateOptions,
|
|
2095
|
+
candidates: prepared.explicitCandidates ? prepared.compilation.candidates : void 0,
|
|
2096
|
+
incrementalCache: generateOptions.incrementalCache ?? true,
|
|
2097
|
+
target: target === "tailwind" ? "web" : target
|
|
2098
|
+
});
|
|
2099
|
+
if (!entry.active) throw new Error(`Compiler root 已被移除:${entry.id}`);
|
|
2100
|
+
const revision = (getLatestRevision(entry) ?? 0) + 1;
|
|
2101
|
+
const dependencies = [.../* @__PURE__ */ new Set([...source.dependencies, ...generated.dependencies])].sort();
|
|
2102
|
+
const sources = generated.sources ?? source.sources ?? [];
|
|
2103
|
+
const previousSnapshotState = entry.latestSnapshot ? getInternalCompilerSnapshot(entry.latestSnapshot) : void 0;
|
|
2104
|
+
const reusableClassSet = engineReused && generated.incrementalCss === "" && previousSnapshotState && previousSnapshotState.classSet.size === generated.classSet.size && [...generated.classSet].every((candidate) => previousSnapshotState.classSet.has(candidate)) ? previousSnapshotState.classSet : void 0;
|
|
2105
|
+
const reusableClassSetView = reusableClassSet ? entry.latestSnapshot?.classSet : void 0;
|
|
2106
|
+
const snapshot = createRegisteredCompilerSnapshot({
|
|
2107
|
+
classSet: generated.classSet,
|
|
2108
|
+
dependencies,
|
|
2109
|
+
id: entry.id,
|
|
2110
|
+
revision,
|
|
2111
|
+
sources,
|
|
2112
|
+
target
|
|
2113
|
+
}, reusableClassSet, reusableClassSetView);
|
|
2114
|
+
const internalSnapshot = getInternalCompilerSnapshot(snapshot);
|
|
2115
|
+
const previousGenerator = entry.generator;
|
|
2116
|
+
commitCompilerGeneration(entry, prepared, source, dependencies, generated.classSet);
|
|
2117
|
+
entry.generator = generator;
|
|
2118
|
+
entry.generationCache = {
|
|
2119
|
+
key: generationCacheKey,
|
|
2120
|
+
result: generated
|
|
2121
|
+
};
|
|
2122
|
+
entry.source = source;
|
|
2123
|
+
entry.sourceFingerprint = sourceFingerprint;
|
|
2124
|
+
entry.sourceInput = sourceInput;
|
|
2125
|
+
entry.appliedInvalidation = invalidation;
|
|
2126
|
+
entry.latestSnapshot = snapshot;
|
|
2127
|
+
rootStore.attachDependencies(entry, dependencies);
|
|
2128
|
+
rootStore.attachSources(entry, sources);
|
|
2129
|
+
if (!engineReused && previousGenerator !== generator) previousGenerator?.dispose?.();
|
|
2130
|
+
const css = target === "tailwind" ? generated.rawCss : generated.css;
|
|
2131
|
+
const incrementalCss = target === "tailwind" ? generated.incrementalRawCss : generated.incrementalCss;
|
|
2132
|
+
return {
|
|
2133
|
+
...generated,
|
|
2134
|
+
cache: Object.freeze({
|
|
2135
|
+
engine: engineReused,
|
|
2136
|
+
output: reusableGeneration !== void 0 || engineReused && incrementalCss === "",
|
|
2137
|
+
source: sourceReused
|
|
2138
|
+
}),
|
|
2139
|
+
classSet: snapshot.classSet,
|
|
2140
|
+
css,
|
|
2141
|
+
dependencies: snapshot.dependencies,
|
|
2142
|
+
incrementalCss,
|
|
2143
|
+
rawCandidates: createImmutableSet(generated.rawCandidates),
|
|
2144
|
+
revision,
|
|
2145
|
+
snapshot,
|
|
2146
|
+
sources: internalSnapshot.sources,
|
|
2147
|
+
target
|
|
2148
|
+
};
|
|
2149
|
+
} catch (error) {
|
|
2150
|
+
if (!engineReused) generator.dispose?.();
|
|
2151
|
+
throw error;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
function getLatestRevision(entry) {
|
|
2155
|
+
return entry.latestSnapshot?.roots[0]?.revision;
|
|
2156
|
+
}
|
|
2157
|
+
function generate(request) {
|
|
2158
|
+
ensureActive();
|
|
2159
|
+
const entry = rootStore.get(request.id);
|
|
2160
|
+
entry.pendingCount += 1;
|
|
2161
|
+
const execution = entry.pending.then(() => runGenerate(entry, request));
|
|
2162
|
+
entry.pending = execution.finally(() => {
|
|
2163
|
+
entry.pendingCount -= 1;
|
|
2164
|
+
rootStore.trim();
|
|
2165
|
+
}).then(() => void 0, () => void 0);
|
|
2166
|
+
return track(execution);
|
|
2167
|
+
}
|
|
2168
|
+
function createSnapshot(request) {
|
|
2169
|
+
ensureActive();
|
|
2170
|
+
return createRegisteredCompilerSnapshot(request);
|
|
2171
|
+
}
|
|
2172
|
+
function finalizeCss(css, options) {
|
|
2173
|
+
ensureActive();
|
|
2174
|
+
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, options);
|
|
2175
|
+
}
|
|
2176
|
+
function finalizeCssRoot(root, options) {
|
|
2177
|
+
ensureActive();
|
|
2178
|
+
const cloned = root.clone();
|
|
2179
|
+
(0, _weapp_tailwindcss_postcss.finalizeMiniProgramCssRoot)(cloned, options);
|
|
2180
|
+
return cloned;
|
|
2181
|
+
}
|
|
2182
|
+
function mergeSnapshots(snapshots) {
|
|
2183
|
+
ensureActive();
|
|
2184
|
+
return mergeRegisteredCompilerSnapshots(snapshots);
|
|
2185
|
+
}
|
|
2186
|
+
function invalidate(ids) {
|
|
2187
|
+
ensureActive();
|
|
2188
|
+
return rootStore.invalidate(ids);
|
|
2189
|
+
}
|
|
2190
|
+
async function remove(id) {
|
|
2191
|
+
if (lifecycle === "disposed") return;
|
|
2192
|
+
clearTransformCache();
|
|
2193
|
+
await rootStore.remove(id);
|
|
2194
|
+
}
|
|
2195
|
+
function dispose() {
|
|
2196
|
+
if (disposePromise) return disposePromise;
|
|
2197
|
+
lifecycle = "disposing";
|
|
2198
|
+
disposePromise = (async () => {
|
|
2199
|
+
await Promise.allSettled([...activeTasks]);
|
|
2200
|
+
clearTransformCache();
|
|
2201
|
+
await rootStore.dispose();
|
|
2202
|
+
lifecycle = "disposed";
|
|
2203
|
+
})();
|
|
2204
|
+
return disposePromise;
|
|
2205
|
+
}
|
|
2206
|
+
return {
|
|
2207
|
+
createSnapshot,
|
|
2208
|
+
dispose,
|
|
2209
|
+
finalizeCss,
|
|
2210
|
+
finalizeCssRoot,
|
|
2211
|
+
generate,
|
|
2212
|
+
invalidate,
|
|
2213
|
+
mergeSnapshots,
|
|
2214
|
+
remove,
|
|
2215
|
+
...transforms
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
//#endregion
|
|
2219
|
+
Object.defineProperty(exports, "DefaultCompilationSession", {
|
|
2220
|
+
enumerable: true,
|
|
2221
|
+
get: function() {
|
|
2222
|
+
return DefaultCompilationSession;
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
1347
2225
|
Object.defineProperty(exports, "collectRuntimeClassSet", {
|
|
1348
2226
|
enumerable: true,
|
|
1349
2227
|
get: function() {
|
|
1350
2228
|
return collectRuntimeClassSet;
|
|
1351
2229
|
}
|
|
1352
2230
|
});
|
|
2231
|
+
Object.defineProperty(exports, "createCompiler", {
|
|
2232
|
+
enumerable: true,
|
|
2233
|
+
get: function() {
|
|
2234
|
+
return createCompiler;
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
1353
2237
|
Object.defineProperty(exports, "createTailwindRuntimeReadyPromise", {
|
|
1354
2238
|
enumerable: true,
|
|
1355
2239
|
get: function() {
|
|
@@ -1374,6 +2258,12 @@ Object.defineProperty(exports, "normalizeFrameworkStylePlatform", {
|
|
|
1374
2258
|
return normalizeFrameworkStylePlatform;
|
|
1375
2259
|
}
|
|
1376
2260
|
});
|
|
2261
|
+
Object.defineProperty(exports, "normalizeStyleHandlerMajorVersion", {
|
|
2262
|
+
enumerable: true,
|
|
2263
|
+
get: function() {
|
|
2264
|
+
return normalizeStyleHandlerMajorVersion;
|
|
2265
|
+
}
|
|
2266
|
+
});
|
|
1377
2267
|
Object.defineProperty(exports, "pluginName", {
|
|
1378
2268
|
enumerable: true,
|
|
1379
2269
|
get: function() {
|
|
@@ -1386,6 +2276,12 @@ Object.defineProperty(exports, "refreshTailwindRuntimeState", {
|
|
|
1386
2276
|
return refreshTailwindRuntimeState;
|
|
1387
2277
|
}
|
|
1388
2278
|
});
|
|
2279
|
+
Object.defineProperty(exports, "resolveStyleOptionsFromContext", {
|
|
2280
|
+
enumerable: true,
|
|
2281
|
+
get: function() {
|
|
2282
|
+
return resolveStyleOptionsFromContext;
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
1389
2285
|
Object.defineProperty(exports, "shouldSkipJsTransform", {
|
|
1390
2286
|
enumerable: true,
|
|
1391
2287
|
get: function() {
|