@ycodium-ai/plugin-office 0.0.0-stage → 0.2.2800
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 +95 -2
- package/assets/check_office.py +279 -0
- package/dist/index.js +1575 -0
- package/locales/en.json +109 -0
- package/locales/zh-CN.json +109 -0
- package/package.json +89 -3
- package/skills/office-docx/SKILL.md +57 -0
- package/skills/office-pptx/SKILL.md +81 -0
- package/skills/office-xlsx/SKILL.md +74 -0
- package/ui/ui.js +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1575 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import * as NodePath7 from "node:path";
|
|
3
|
+
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
4
|
+
|
|
5
|
+
// src/download.ts
|
|
6
|
+
import * as NodeCrypto from "node:crypto";
|
|
7
|
+
import * as NodeFS from "node:fs";
|
|
8
|
+
import * as NodeFSP from "node:fs/promises";
|
|
9
|
+
import * as NodePath from "node:path";
|
|
10
|
+
import * as NodeStream from "node:stream";
|
|
11
|
+
import * as NodeStreamPromises from "node:stream/promises";
|
|
12
|
+
var DEFAULT_SOURCES = {
|
|
13
|
+
npmRegistry: "https://registry.npmjs.org",
|
|
14
|
+
githubMirror: "",
|
|
15
|
+
pypiMirror: "https://files.pythonhosted.org/packages",
|
|
16
|
+
localDir: ""
|
|
17
|
+
};
|
|
18
|
+
var PYPI_PACKAGES = "https://files.pythonhosted.org/packages";
|
|
19
|
+
var GITHUB_HOSTS = ["https://github.com/", "https://raw.githubusercontent.com/"];
|
|
20
|
+
var trimSlash = (value) => value.replace(/\/+$/, "");
|
|
21
|
+
var resolveDownloadUrl = (url, sources) => {
|
|
22
|
+
if (url.startsWith(PYPI_PACKAGES)) {
|
|
23
|
+
return `${trimSlash(sources.pypiMirror)}${url.slice(PYPI_PACKAGES.length)}`;
|
|
24
|
+
}
|
|
25
|
+
if (sources.githubMirror !== "" && GITHUB_HOSTS.some((host) => url.startsWith(host))) {
|
|
26
|
+
return `${trimSlash(sources.githubMirror)}/${url}`;
|
|
27
|
+
}
|
|
28
|
+
return url;
|
|
29
|
+
};
|
|
30
|
+
var npmTarballUrl = (registry, name, version) => {
|
|
31
|
+
const bare = name.includes("/") ? name.slice(name.indexOf("/") + 1) : name;
|
|
32
|
+
return `${trimSlash(registry)}/${name}/-/${bare}-${version}.tgz`;
|
|
33
|
+
};
|
|
34
|
+
var parseSri = (sri) => {
|
|
35
|
+
if (!sri.startsWith("sha512-")) throw new Error(`Unsupported integrity value: ${sri}`);
|
|
36
|
+
return { algorithm: "sha512", base64: sri.slice("sha512-".length) };
|
|
37
|
+
};
|
|
38
|
+
var digestMatches = (hash, integrity) => integrity.algorithm === "sha256" ? hash.digest("hex") === integrity.hex.toLowerCase() : hash.digest("base64") === integrity.base64;
|
|
39
|
+
var fileMatches = async (filePath, integrity) => {
|
|
40
|
+
const hash = NodeCrypto.createHash(integrity.algorithm);
|
|
41
|
+
try {
|
|
42
|
+
await NodeStreamPromises.pipeline(NodeFS.createReadStream(filePath), hash);
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return digestMatches(hash, integrity);
|
|
47
|
+
};
|
|
48
|
+
var DownloadError = class extends Error {
|
|
49
|
+
reason;
|
|
50
|
+
constructor(reason, message) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.reason = reason;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var hostOf = (url) => {
|
|
56
|
+
try {
|
|
57
|
+
return new URL(url).host;
|
|
58
|
+
} catch {
|
|
59
|
+
return url;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var describeNetworkError = (error) => {
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
const cause = error?.cause;
|
|
65
|
+
if (cause === void 0) return message;
|
|
66
|
+
const code = typeof cause.code === "string" ? `${cause.code} ` : "";
|
|
67
|
+
return `${message}: ${code}${typeof cause.message === "string" ? cause.message : ""}`.trim();
|
|
68
|
+
};
|
|
69
|
+
var downloadVerified = async (input) => {
|
|
70
|
+
const { item, dir, sources } = input;
|
|
71
|
+
const target = NodePath.join(dir, item.fileName);
|
|
72
|
+
await NodeFSP.mkdir(dir, { recursive: true });
|
|
73
|
+
if (await fileMatches(target, item.integrity)) return target;
|
|
74
|
+
if (sources.localDir !== "") {
|
|
75
|
+
const local = NodePath.join(sources.localDir, item.fileName);
|
|
76
|
+
if (await fileMatches(local, item.integrity)) {
|
|
77
|
+
await NodeFSP.copyFile(local, target);
|
|
78
|
+
return target;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const url = resolveDownloadUrl(item.url, sources);
|
|
82
|
+
let response;
|
|
83
|
+
try {
|
|
84
|
+
response = await input.http(url, { signal: input.signal });
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (input.signal.aborted) throw error;
|
|
87
|
+
throw new DownloadError(
|
|
88
|
+
"network",
|
|
89
|
+
`Could not reach ${hostOf(url)} to download ${item.fileName} (${describeNetworkError(error)}). Check this machine's internet access and proxy settings.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (!response.ok || response.body === null) {
|
|
93
|
+
throw new DownloadError(
|
|
94
|
+
"http",
|
|
95
|
+
`${hostOf(url)} answered HTTP ${String(response.status)} for ${item.fileName}.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const rawLength = Number(response.headers.get("content-length") ?? Number.NaN);
|
|
99
|
+
const totalBytes = Number.isFinite(rawLength) && rawLength > 0 ? rawLength : null;
|
|
100
|
+
const hash = NodeCrypto.createHash(input.item.integrity.algorithm);
|
|
101
|
+
const partPath = `${target}.part`;
|
|
102
|
+
let transferredBytes = 0;
|
|
103
|
+
let lastReport = 0;
|
|
104
|
+
const readable = NodeStream.Readable.fromWeb(
|
|
105
|
+
response.body
|
|
106
|
+
);
|
|
107
|
+
readable.on("data", (chunk) => {
|
|
108
|
+
transferredBytes += chunk.length;
|
|
109
|
+
hash.update(chunk);
|
|
110
|
+
const now = Date.now();
|
|
111
|
+
if (now - lastReport >= 250) {
|
|
112
|
+
lastReport = now;
|
|
113
|
+
input.onProgress({ fileName: item.fileName, transferredBytes, totalBytes });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
await NodeStreamPromises.pipeline(readable, NodeFS.createWriteStream(partPath));
|
|
118
|
+
} catch (error) {
|
|
119
|
+
await NodeFSP.rm(partPath, { force: true });
|
|
120
|
+
if (input.signal.aborted) throw error;
|
|
121
|
+
const code = error.code;
|
|
122
|
+
if (code === "ENOSPC") {
|
|
123
|
+
throw new DownloadError(
|
|
124
|
+
"disk",
|
|
125
|
+
`This machine ran out of disk space while downloading ${item.fileName}.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
throw new DownloadError(
|
|
129
|
+
"network",
|
|
130
|
+
`The download of ${item.fileName} stopped after ${String(transferredBytes)} bytes (${describeNetworkError(error)}).`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
input.onProgress({ fileName: item.fileName, transferredBytes, totalBytes });
|
|
134
|
+
if (!digestMatches(hash, item.integrity)) {
|
|
135
|
+
await NodeFSP.rm(partPath, { force: true });
|
|
136
|
+
throw new DownloadError(
|
|
137
|
+
"integrity",
|
|
138
|
+
`${item.fileName} from ${hostOf(url)} did not match its pinned ${item.integrity.algorithm} hash and was discarded. If this machine uses a proxy or mirror, make sure it serves the original file.`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
await NodeFSP.rename(partPath, target);
|
|
142
|
+
return target;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/engine.ts
|
|
146
|
+
import * as NodeFSP4 from "node:fs/promises";
|
|
147
|
+
import * as NodeProcess3 from "node:process";
|
|
148
|
+
|
|
149
|
+
// src/install.ts
|
|
150
|
+
import * as NodeFSP3 from "node:fs/promises";
|
|
151
|
+
import * as NodePath4 from "node:path";
|
|
152
|
+
import * as NodeProcess2 from "node:process";
|
|
153
|
+
|
|
154
|
+
// src/lock.ts
|
|
155
|
+
var OFFICE_LOCK = {
|
|
156
|
+
engine: {
|
|
157
|
+
version: "0.1.5",
|
|
158
|
+
shared: [
|
|
159
|
+
{
|
|
160
|
+
name: "@deepseek-ai/libreoffice-kit",
|
|
161
|
+
version: "0.1.5",
|
|
162
|
+
integrity: "sha512-H12xtUsAyl70zFeQ5pk5GGRc3N1+6zn+DVAcqwlguI6EvqopBGP3xkUmePU7g5f6ydYlDZLWedHT9lTSL7zLxA=="
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "@swc/helpers",
|
|
166
|
+
version: "0.5.23",
|
|
167
|
+
integrity: "sha512-5lSsMOTXURePglDfvuAQUqkGek9Hg2kksOYay2m0+XR++b2NWYL/4sWyuvVBIs8oKnJaxkdi9whaL/sqN13afw=="
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "base64-js",
|
|
171
|
+
version: "1.5.1",
|
|
172
|
+
integrity: "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "brotli",
|
|
176
|
+
version: "1.3.3",
|
|
177
|
+
integrity: "sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg=="
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "clone",
|
|
181
|
+
version: "2.1.2",
|
|
182
|
+
integrity: "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "dfa",
|
|
186
|
+
version: "1.2.0",
|
|
187
|
+
integrity: "sha512-ED3jP8saaweFTjeGX8HQPjeC1YYyZs98jGNZx6IiBvxW7JG5v492kamAQB3m2wop07CvU/RQmzcKr6bgcC5D/Q=="
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "fast-deep-equal",
|
|
191
|
+
version: "3.1.3",
|
|
192
|
+
integrity: "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "fflate",
|
|
196
|
+
version: "0.8.2",
|
|
197
|
+
integrity: "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "fontkit",
|
|
201
|
+
version: "2.0.4",
|
|
202
|
+
integrity: "sha512-syetQadaUEDNdxdugga9CpEYVaQIxOwk7GlwZWWZ19//qW4zE5bknOKeMBDYAASwnpaSHKJITRLMF9m1fp3s6g=="
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "koffi",
|
|
206
|
+
version: "3.1.1",
|
|
207
|
+
integrity: "sha512-mRX6AMeeKCxSOeOopqAcLAl5jcNvge7NAG8l7rF/8gGJATI0tdHFYjteIdE0mGOtWdsrJOij+PjnP8Q9c1gwgA=="
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "pako",
|
|
211
|
+
version: "0.2.9",
|
|
212
|
+
integrity: "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA=="
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "restructure",
|
|
216
|
+
version: "3.0.2",
|
|
217
|
+
integrity: "sha512-gSfoiOEA0VPE6Tukkrr7I0RBdE0s7H1eFCDBk05l1KIQT1UIKNc5JZy6jdyW6eYH3aR3g5b3PuL77rq0hvwtAw=="
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "saxes",
|
|
221
|
+
version: "6.0.0",
|
|
222
|
+
integrity: "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA=="
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "tiny-inflate",
|
|
226
|
+
version: "1.0.3",
|
|
227
|
+
integrity: "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw=="
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "tslib",
|
|
231
|
+
version: "2.8.1",
|
|
232
|
+
integrity: "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "unicode-properties",
|
|
236
|
+
version: "1.4.1",
|
|
237
|
+
integrity: "sha512-CLjCCLQ6UuMxWnbIylkisbRj31qxHPAurvena/0iwSVbQ2G1VY5/HjV0IRabOEbDHlzZlRdCrD4NhB0JtU40Pg=="
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "unicode-trie",
|
|
241
|
+
version: "2.0.0",
|
|
242
|
+
integrity: "sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ=="
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "xmlchars",
|
|
246
|
+
version: "2.2.0",
|
|
247
|
+
integrity: "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
targets: {
|
|
251
|
+
"win32-x64": [
|
|
252
|
+
{
|
|
253
|
+
name: "@deepseek-ai/libreoffice-kit-win32-x64",
|
|
254
|
+
version: "0.1.5",
|
|
255
|
+
integrity: "sha512-uKuDGZdofxuW4iRmUh8b3+XWU28JeOCYMTAONzo7tEHIq00DV2cARcgUYiTP7gUH49tH4A/RyPMOVEBzK7qjjw=="
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "@koromix/koffi-win32-x64",
|
|
259
|
+
version: "3.1.1",
|
|
260
|
+
integrity: "sha512-KqHPmvj6QILhNyI/To8QSihHsijeVGIYYPBOUnXEpcnH2LuLbargY4Hd6dDeTN3Z90uUUxN+1FWz1UnhVzFOiA=="
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
"win32-arm64": [
|
|
264
|
+
{
|
|
265
|
+
name: "@deepseek-ai/libreoffice-kit-win32-arm64",
|
|
266
|
+
version: "0.1.5",
|
|
267
|
+
integrity: "sha512-Av3aFfNLaVxfffu0JXP5mqfmsCU3gQtlUH9UD+zdXl8ON06ukVAmu7LqNyuKAz/68WoOMTQ+YBlVQukgDRKd/A=="
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "@koromix/koffi-win32-arm64",
|
|
271
|
+
version: "3.1.1",
|
|
272
|
+
integrity: "sha512-JhqHauEwQvdcWUERxrV5HH/DT9W7hY1A1eU6/o8tB+yck+D3kt5elpRDBt9KjpW6h+vHPy3V0sjDvO0CXyabTA=="
|
|
273
|
+
}
|
|
274
|
+
],
|
|
275
|
+
"darwin-arm64": [
|
|
276
|
+
{
|
|
277
|
+
name: "@deepseek-ai/libreoffice-kit-darwin-arm64",
|
|
278
|
+
version: "0.1.5",
|
|
279
|
+
integrity: "sha512-SjeXmyaTevEq2TxK7reb1rhCrQZ4QOXmXt/qEwfQD5Fx3odU0ILx2uiXN+nphSCQ95LFCzrElHGgv2c7a824yg=="
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
name: "@koromix/koffi-darwin-arm64",
|
|
283
|
+
version: "3.1.1",
|
|
284
|
+
integrity: "sha512-+Dl0zQDh1Wb55AWOn9hp7K30qgkODvrvN+ZNkFOh81Q0oFX/rpJQtocgjAuYk2zFAcajSeVDumkcHMPwnKSXzA=="
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
"darwin-x64": [
|
|
288
|
+
{
|
|
289
|
+
name: "@deepseek-ai/libreoffice-kit-darwin-x64",
|
|
290
|
+
version: "0.1.5",
|
|
291
|
+
integrity: "sha512-vuz2tTpH1Edk75+DISwg/TXdQ3BNSNSHoVnWVqxqbGMgrrK9trLOw2+0X7mjT1naGO00Zc1qkyQ4if3kx5XjqQ=="
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
name: "@koromix/koffi-darwin-x64",
|
|
295
|
+
version: "3.1.1",
|
|
296
|
+
integrity: "sha512-cDFAKn1qdZBFLrp7dAc9QUDw3l4xAhTJbOdPWWb0LxssVicUdHcRCLZGrDsmPW2tpH6LGNNeLgqRpAoD2Mo8iA=="
|
|
297
|
+
}
|
|
298
|
+
],
|
|
299
|
+
"linux-x64": [
|
|
300
|
+
{
|
|
301
|
+
name: "@deepseek-ai/libreoffice-kit-wasm",
|
|
302
|
+
version: "0.1.5",
|
|
303
|
+
integrity: "sha512-V+pu5xJsKhVD4AU1xbFlMWY91svK9ZIC2JsNOph9kWp/arF/KQcuytt76bcbozJqPbE8o0n04lyh0m3QW5RYSA=="
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "@koromix/koffi-linux-x64",
|
|
307
|
+
version: "3.1.1",
|
|
308
|
+
integrity: "sha512-pyTcX5fePeYbt7TZAwRby69wdlRx3PT+g15ra5IYdat/Pgh3qAKEYeZ+uu7WpPGOy43p/oSRqqZoa2kORzozlA=="
|
|
309
|
+
}
|
|
310
|
+
],
|
|
311
|
+
"linux-arm64": [
|
|
312
|
+
{
|
|
313
|
+
name: "@deepseek-ai/libreoffice-kit-wasm",
|
|
314
|
+
version: "0.1.5",
|
|
315
|
+
integrity: "sha512-V+pu5xJsKhVD4AU1xbFlMWY91svK9ZIC2JsNOph9kWp/arF/KQcuytt76bcbozJqPbE8o0n04lyh0m3QW5RYSA=="
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
name: "@koromix/koffi-linux-arm64",
|
|
319
|
+
version: "3.1.1",
|
|
320
|
+
integrity: "sha512-HA9xINK7G4dRAkpfnBWD9VfuyIBgW1SuK+KPHjksUwRMOnhgqP8J/JqgrAzdzcDiefGBkqEacIP776OUwz7knQ=="
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
python: {
|
|
326
|
+
version: "3.12.14",
|
|
327
|
+
release: "20260901",
|
|
328
|
+
packages: {
|
|
329
|
+
numpy: "2.3.5",
|
|
330
|
+
pandas: "3.0.1",
|
|
331
|
+
"python-dateutil": "2.9.0.post0",
|
|
332
|
+
six: "1.17.0",
|
|
333
|
+
tzdata: "2025.2",
|
|
334
|
+
"python-docx": "1.2.0",
|
|
335
|
+
"python-pptx": "1.0.2",
|
|
336
|
+
openpyxl: "3.1.5",
|
|
337
|
+
Pillow: "12.3.0",
|
|
338
|
+
lxml: "6.1.3",
|
|
339
|
+
XlsxWriter: "3.2.9",
|
|
340
|
+
typing_extensions: "4.16.0",
|
|
341
|
+
et_xmlfile: "2.0.0"
|
|
342
|
+
},
|
|
343
|
+
wheels: [
|
|
344
|
+
{
|
|
345
|
+
url: "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
|
|
346
|
+
sha256: "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
url: "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl",
|
|
350
|
+
sha256: "4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
url: "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl",
|
|
354
|
+
sha256: "1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
url: "https://files.pythonhosted.org/packages/d0/00/1e03a4989fa5795da308cd774f05b704ace555a70f9bf9d3be057b680bcf/python_docx-1.2.0-py3-none-any.whl",
|
|
358
|
+
sha256: "3fd478f3250fbbbfd3b94fe1e985955737c145627498896a8a6bf81f4baf66c7"
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
url: "https://files.pythonhosted.org/packages/d9/4f/00be2196329ebbff56ce564aa94efb0fbc828d00de250b1980de1a34ab49/python_pptx-1.0.2-py3-none-any.whl",
|
|
362
|
+
sha256: "160838e0b8565a8b1f67947675886e9fea18aa5e795db7ae531606d68e785cba"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
url: "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl",
|
|
366
|
+
sha256: "5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2"
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
url: "https://files.pythonhosted.org/packages/3a/0c/3662f4a66880196a590b202f0db82d919dd2f89e99a27fadef91c4a33d41/xlsxwriter-3.2.9-py3-none-any.whl",
|
|
370
|
+
sha256: "9a5db42bc5dff014806c58a20b9eae7322a134abb6fce3c92c181bfb275ec5b3"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
url: "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl",
|
|
374
|
+
sha256: "481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
url: "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl",
|
|
378
|
+
sha256: "7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa"
|
|
379
|
+
}
|
|
380
|
+
],
|
|
381
|
+
targets: {
|
|
382
|
+
"win32-x64": {
|
|
383
|
+
pythonTarget: "x86_64-pc-windows-msvc",
|
|
384
|
+
sha256: "7c45c9622400d578709a9b2cddbe8124cc21d382409d9f13406d706d28e31b14",
|
|
385
|
+
wheels: [
|
|
386
|
+
{
|
|
387
|
+
url: "https://files.pythonhosted.org/packages/2d/57/8aeaf160312f7f489dea47ab61e430b5cb051f59a98ae68b7133ce8fa06a/numpy-2.3.5-cp312-cp312-win_amd64.whl",
|
|
388
|
+
sha256: "86945f2ee6d10cdfd67bcb4069c1662dd711f7e2a4343db5cecec06b87cf31aa"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
url: "https://files.pythonhosted.org/packages/75/08/67cc404b3a966b6df27b38370ddd96b3b023030b572283d035181854aac5/pandas-3.0.1-cp312-cp312-win_amd64.whl",
|
|
392
|
+
sha256: "536232a5fe26dd989bd633e7a0c450705fdc86a207fec7254a55e9a22950fe43"
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
url: "https://files.pythonhosted.org/packages/45/89/da2f7971a317f83d807fdd4065c0af40208e59e692cc43d315a71a0e96d1/pillow-12.3.0-cp312-cp312-win_amd64.whl",
|
|
396
|
+
sha256: "a2b55dd6b2a4c4b7d87ffa56bdb33fdc5fdb9a462173861a7bc097f17d91cb09"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
url: "https://files.pythonhosted.org/packages/3a/5b/6ed903e4e6278a020c8a6f0dbbe78030d041840a6b4a64ea441a1e414077/lxml-6.1.3-cp312-cp312-win_amd64.whl",
|
|
400
|
+
sha256: "3e9a00d1c2c30936f7add097c41afc5da6556c580909104aafd382cac92a855c"
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
"darwin-arm64": {
|
|
405
|
+
pythonTarget: "aarch64-apple-darwin",
|
|
406
|
+
sha256: "81a359f1cfadd4da11766534c5913791cea55f26e1bb902cacd2a531bb1e4b2b",
|
|
407
|
+
wheels: [
|
|
408
|
+
{
|
|
409
|
+
url: "https://files.pythonhosted.org/packages/c5/65/df0db6c097892c9380851ab9e44b52d4f7ba576b833996e0080181c0c439/numpy-2.3.5-cp312-cp312-macosx_11_0_arm64.whl",
|
|
410
|
+
sha256: "ee3888d9ff7c14604052b2ca5535a30216aa0a58e948cdd3eeb8d3415f638769"
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
url: "https://files.pythonhosted.org/packages/7c/f1/e2567ffc8951ab371db2e40b2fe068e36b81d8cf3260f06ae508700e5504/pandas-3.0.1-cp312-cp312-macosx_11_0_arm64.whl",
|
|
414
|
+
sha256: "0ab749dfba921edf641d4036c4c21c0b3ea70fea478165cb98a998fb2a261955"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
url: "https://files.pythonhosted.org/packages/d8/66/9a386a92561f402389a4fc70c18838bf6d35eb5eb5c6850b4b2dc64f5048/pillow-12.3.0-cp312-cp312-macosx_11_0_arm64.whl",
|
|
418
|
+
sha256: "ffd0c5368496f41b0944be820fcb7a838aa6e623d250b01acf2643939c3f99d7"
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
url: "https://files.pythonhosted.org/packages/dd/1f/a180b57d9eeabaab77f9d5aa30356898ea749c4795596a8f66d1eb6bef2e/lxml-6.1.3-cp312-cp312-macosx_10_13_universal2.whl",
|
|
422
|
+
sha256: "0c0710ac085a157b593c38fbcacd950f15c4afa8e2057527185875ab302752bc"
|
|
423
|
+
}
|
|
424
|
+
]
|
|
425
|
+
},
|
|
426
|
+
"darwin-x64": {
|
|
427
|
+
pythonTarget: "x86_64-apple-darwin",
|
|
428
|
+
sha256: "65b195c9cedc1fef6767f044f9822069adbd1bd9204d424ece4628776fdc04bb",
|
|
429
|
+
wheels: [
|
|
430
|
+
{
|
|
431
|
+
url: "https://files.pythonhosted.org/packages/44/37/e669fe6cbb2b96c62f6bbedc6a81c0f3b7362f6a59230b23caa673a85721/numpy-2.3.5-cp312-cp312-macosx_10_13_x86_64.whl",
|
|
432
|
+
sha256: "74ae7b798248fe62021dbf3c914245ad45d1a6b0cb4a29ecb4b31d0bfbc4cc3e"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
url: "https://files.pythonhosted.org/packages/37/51/b467209c08dae2c624873d7491ea47d2b47336e5403309d433ea79c38571/pandas-3.0.1-cp312-cp312-macosx_10_13_x86_64.whl",
|
|
436
|
+
sha256: "476f84f8c20c9f5bc47252b66b4bb25e1a9fc2fa98cead96744d8116cb85771d"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
url: "https://files.pythonhosted.org/packages/37/bf/fb3ebff8ddcb76aac5a01389251bbbb9519922a9b520d8247c1ca864a25d/pillow-12.3.0-cp312-cp312-macosx_10_13_x86_64.whl",
|
|
440
|
+
sha256: "ba09209fbe443b4acccebe845d8a138b89a8f4fbaeedd44953490b5315d5e965"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
url: "https://files.pythonhosted.org/packages/a8/25/070c92013a1c029a602b03560d68772313d918268667fa993da7961759c9/lxml-6.1.3-cp312-cp312-macosx_10_13_x86_64.whl",
|
|
444
|
+
sha256: "623c8799c17128753c65699f1c3aa32402657393a9ad6db09ed8b98ddf76611d"
|
|
445
|
+
}
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
"linux-x64": {
|
|
449
|
+
pythonTarget: "x86_64-unknown-linux-gnu",
|
|
450
|
+
sha256: "72748da13197c1fb161e3afeef20a6a385ff24f2165e6e2758e47008e7faba4c",
|
|
451
|
+
wheels: [
|
|
452
|
+
{
|
|
453
|
+
url: "https://files.pythonhosted.org/packages/b6/23/2a1b231b8ff672b4c450dac27164a8b2ca7d9b7144f9c02d2396518352eb/numpy-2.3.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
|
|
454
|
+
sha256: "0d8163f43acde9a73c2a33605353a4f1bc4798745a8b1d73183b28e5b435ae28"
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
url: "https://files.pythonhosted.org/packages/3d/fe/89d77e424365280b79d99b3e1e7d606f5165af2f2ecfaf0c6d24c799d607/pandas-3.0.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl",
|
|
458
|
+
sha256: "532527a701281b9dd371e2f582ed9094f4c12dd9ffb82c0c54ee28d8ac9520c4"
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
url: "https://files.pythonhosted.org/packages/84/21/a35af28dcc61f37ed850a2d64c65c701321dfbf25085e469d5559360cbbf/pillow-12.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
|
|
462
|
+
sha256: "78cb2c6865a35ab8ff8b75fd122f6033b92a62c82801110e48ddd6c936a45d91"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
url: "https://files.pythonhosted.org/packages/db/36/aa413bc214dc4f785ad2b2ddd8cc99aae7062d49ab155e91e6011af00daf/lxml-6.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
|
|
466
|
+
sha256: "379f8a75cf6eb7eef0af074b55f49ab73b868388a98de14646abcdfa4564bb11"
|
|
467
|
+
}
|
|
468
|
+
]
|
|
469
|
+
},
|
|
470
|
+
"linux-arm64": {
|
|
471
|
+
pythonTarget: "aarch64-unknown-linux-gnu",
|
|
472
|
+
sha256: "577b4bec0793ad1ff0cbff9adbd0df078eddde38a4c41bf5d83ad381a85ee39d",
|
|
473
|
+
wheels: [
|
|
474
|
+
{
|
|
475
|
+
url: "https://files.pythonhosted.org/packages/74/78/fcd41e5a0ce4f3f7b003da85825acddae6d7ecb60cf25194741b036ca7d6/numpy-2.3.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl",
|
|
476
|
+
sha256: "8b973c57ff8e184109db042c842423ff4f60446239bd585a5131cc47f06f789d"
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
url: "https://files.pythonhosted.org/packages/d7/39/327802e0b6d693182403c144edacbc27eb82907b57062f23ef5a4c4a5ea7/pandas-3.0.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl",
|
|
480
|
+
sha256: "b8e36891080b87823aff3640c78649b91b8ff6eea3c0d70aeabd72ea43ab069b"
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
url: "https://files.pythonhosted.org/packages/25/27/ac8f99618ffd3dde21db0f4d4b1d2ab00c0880595bfd17df103f7f39fd0c/pillow-12.3.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl",
|
|
484
|
+
sha256: "d9c7f76c0673154f044e9d78c8655fb4213f6ca31a836df48b40fe5d187717b9"
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
url: "https://files.pythonhosted.org/packages/1e/1c/722e88883173097a1a375153e3c2447eba3060d0231522cf6596e99f4195/lxml-6.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl",
|
|
488
|
+
sha256: "f683dc6300317700025e41d89a43e0276692ded16113a3c43eab704d605c58e5"
|
|
489
|
+
}
|
|
490
|
+
]
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
fonts: {
|
|
495
|
+
files: [
|
|
496
|
+
{
|
|
497
|
+
path: "Sans2.004/Sans/SubsetOTF/SC/NotoSansSC-Regular.otf",
|
|
498
|
+
size: 8331336,
|
|
499
|
+
sha256: "faa6c9df652116dde789d351359f3d7e5d2285a2b2a1f04a2d7244df706d5ea9"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
path: "Sans2.004/Sans/SubsetOTF/SC/NotoSansSC-Bold.otf",
|
|
503
|
+
size: 8543168,
|
|
504
|
+
sha256: "c6cb5a93abaa9edc8ee7463b7ebb7f42d618d40e6ed2f7a5371c97b0b64767c0"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
path: "Serif2.003/Serif/SubsetOTF/SC/NotoSerifSC-Regular.otf",
|
|
508
|
+
size: 11625800,
|
|
509
|
+
sha256: "e8f396decc1f0963a016a989c3d8852e863d1350996f573860a80767c83a1cd3"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
path: "Serif2.003/Serif/SubsetOTF/SC/NotoSerifSC-Bold.otf",
|
|
513
|
+
size: 12094336,
|
|
514
|
+
sha256: "24693d48bdb9152f0a06b02af625638a1097abd6de4010ebba027f6e82710527"
|
|
515
|
+
}
|
|
516
|
+
]
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/paths.ts
|
|
521
|
+
import * as NodeCrypto2 from "node:crypto";
|
|
522
|
+
import * as NodeFSP2 from "node:fs/promises";
|
|
523
|
+
import * as NodePath2 from "node:path";
|
|
524
|
+
var PYTHON_PROGRAM = {
|
|
525
|
+
win32: "data:runtime/python/python.exe",
|
|
526
|
+
other: "data:runtime/python/bin/python3"
|
|
527
|
+
};
|
|
528
|
+
var officePaths = (dataDir) => {
|
|
529
|
+
const runtimeDir = NodePath2.join(dataDir, "runtime");
|
|
530
|
+
const dirOf = (component) => NodePath2.join(runtimeDir, component);
|
|
531
|
+
return {
|
|
532
|
+
dataDir,
|
|
533
|
+
runtimeDir,
|
|
534
|
+
downloadsDir: NodePath2.join(dataDir, "downloads"),
|
|
535
|
+
dirOf,
|
|
536
|
+
recordOf: (component) => NodePath2.join(runtimeDir, `${component}.json`),
|
|
537
|
+
engineCli: NodePath2.join(
|
|
538
|
+
dirOf("engine"),
|
|
539
|
+
"node_modules",
|
|
540
|
+
"@deepseek-ai",
|
|
541
|
+
"libreoffice-kit",
|
|
542
|
+
"lib",
|
|
543
|
+
"cli.js"
|
|
544
|
+
),
|
|
545
|
+
pythonExecutable: (platform5) => platform5 === "win32" ? NodePath2.join(dirOf("python"), "python.exe") : NodePath2.join(dirOf("python"), "bin", "python3")
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
var readInstallRecord = async (paths, component) => {
|
|
549
|
+
try {
|
|
550
|
+
const value = JSON.parse(await NodeFSP2.readFile(paths.recordOf(component), "utf8"));
|
|
551
|
+
if (typeof value !== "object" || value === null) return null;
|
|
552
|
+
const record = value;
|
|
553
|
+
return typeof record["version"] === "string" && typeof record["target"] === "string" ? { version: record["version"], target: record["target"] } : null;
|
|
554
|
+
} catch {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var writeInstallRecord = (paths, component, record) => writeAtomic(paths.recordOf(component), `${JSON.stringify(record)}
|
|
559
|
+
`);
|
|
560
|
+
var removePath = (target) => NodeFSP2.rm(target, { recursive: true, force: true });
|
|
561
|
+
var writeAtomic = async (filePath, contents) => {
|
|
562
|
+
await NodeFSP2.mkdir(NodePath2.dirname(filePath), { recursive: true });
|
|
563
|
+
const tmp = `${filePath}.${NodeCrypto2.randomBytes(6).toString("hex")}.tmp`;
|
|
564
|
+
try {
|
|
565
|
+
await NodeFSP2.writeFile(tmp, contents);
|
|
566
|
+
await NodeFSP2.rename(tmp, filePath);
|
|
567
|
+
} catch (error) {
|
|
568
|
+
await NodeFSP2.rm(tmp, { force: true });
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var swapIntoPlace = async (staging, target) => {
|
|
573
|
+
const retired = `${target}.old-${NodeCrypto2.randomBytes(4).toString("hex")}`;
|
|
574
|
+
const hadPrevious = await NodeFSP2.rename(target, retired).then(
|
|
575
|
+
() => true,
|
|
576
|
+
() => false
|
|
577
|
+
);
|
|
578
|
+
try {
|
|
579
|
+
await NodeFSP2.rename(staging, target);
|
|
580
|
+
} catch (error) {
|
|
581
|
+
if (hadPrevious) await NodeFSP2.rename(retired, target).catch(() => void 0);
|
|
582
|
+
throw error;
|
|
583
|
+
}
|
|
584
|
+
if (hadPrevious) await removePath(retired);
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
// src/platform.ts
|
|
588
|
+
import * as NodeFS2 from "node:fs";
|
|
589
|
+
import * as NodeOS from "node:os";
|
|
590
|
+
import * as NodePath3 from "node:path";
|
|
591
|
+
import * as NodeProcess from "node:process";
|
|
592
|
+
var detectOfficeTarget = (platform5 = NodeProcess.platform, arch2 = NodeProcess.arch) => {
|
|
593
|
+
const key = `${platform5}-${arch2}`;
|
|
594
|
+
return Object.hasOwn(OFFICE_LOCK.engine.targets, key) ? key : null;
|
|
595
|
+
};
|
|
596
|
+
var pythonTargetOf = (target) => OFFICE_LOCK.python.targets[target] ?? null;
|
|
597
|
+
var systemFontDirectories = (platform5 = NodeProcess.platform, home = NodeOS.homedir(), env2 = NodeProcess.env) => {
|
|
598
|
+
if (platform5 === "win32") {
|
|
599
|
+
return [
|
|
600
|
+
NodePath3.win32.join(env2["SystemRoot"] ?? "C:\\Windows", "Fonts"),
|
|
601
|
+
NodePath3.win32.join(
|
|
602
|
+
env2["LOCALAPPDATA"] ?? NodePath3.win32.join(home, "AppData", "Local"),
|
|
603
|
+
"Microsoft",
|
|
604
|
+
"Windows",
|
|
605
|
+
"Fonts"
|
|
606
|
+
)
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
if (platform5 === "darwin") {
|
|
610
|
+
return [
|
|
611
|
+
"/System/Library/Fonts",
|
|
612
|
+
"/Library/Fonts",
|
|
613
|
+
NodePath3.posix.join(home, "Library/Fonts"),
|
|
614
|
+
...mobileAssetFontDirectories("/System/Library/AssetsV2")
|
|
615
|
+
];
|
|
616
|
+
}
|
|
617
|
+
const shared = (env2["XDG_DATA_DIRS"] ?? "/usr/local/share:/usr/share").split(":").filter(Boolean);
|
|
618
|
+
return [
|
|
619
|
+
.../* @__PURE__ */ new Set([
|
|
620
|
+
...shared.map((dir) => NodePath3.posix.join(dir, "fonts")),
|
|
621
|
+
NodePath3.posix.join(home, ".fonts"),
|
|
622
|
+
NodePath3.posix.join(
|
|
623
|
+
env2["XDG_DATA_HOME"] ?? NodePath3.posix.join(home, ".local/share"),
|
|
624
|
+
"fonts"
|
|
625
|
+
)
|
|
626
|
+
])
|
|
627
|
+
];
|
|
628
|
+
};
|
|
629
|
+
var mobileAssetFontDirectories = (assets) => {
|
|
630
|
+
let entries = [];
|
|
631
|
+
try {
|
|
632
|
+
entries = NodeFS2.readdirSync(assets);
|
|
633
|
+
} catch {
|
|
634
|
+
return [];
|
|
635
|
+
}
|
|
636
|
+
return entries.filter((name) => /^com_apple_MobileAsset_Font\d*$/.test(name)).sort().map((name) => NodePath3.posix.join(assets, name));
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// src/install.ts
|
|
640
|
+
var InstallError = class extends Error {
|
|
641
|
+
/** 插件 locales 里 `failure.<reason>` 的那一段。 */
|
|
642
|
+
reason;
|
|
643
|
+
constructor(reason, message) {
|
|
644
|
+
super(message);
|
|
645
|
+
this.reason = reason;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var ENGINE_VERSION = OFFICE_LOCK.engine.version;
|
|
649
|
+
var PYTHON_VERSION = `${OFFICE_LOCK.python.version}+${OFFICE_LOCK.python.release}`;
|
|
650
|
+
var FONTS_VERSION = "Sans2.004+Serif2.003";
|
|
651
|
+
var npmFileName = (name, version) => `${name.replace(/^@/, "").replace("/", "__")}-${version}.tgz`;
|
|
652
|
+
var engineItems = (target, registry) => [...OFFICE_LOCK.engine.shared, ...OFFICE_LOCK.engine.targets[target]].map((pkg) => ({
|
|
653
|
+
name: pkg.name,
|
|
654
|
+
item: {
|
|
655
|
+
url: npmTarballUrl(registry, pkg.name, pkg.version),
|
|
656
|
+
fileName: npmFileName(pkg.name, pkg.version),
|
|
657
|
+
integrity: parseSri(pkg.integrity)
|
|
658
|
+
}
|
|
659
|
+
}));
|
|
660
|
+
var basenameOfUrl = (url) => decodeURIComponent(url.slice(url.lastIndexOf("/") + 1));
|
|
661
|
+
var pythonItems = (target) => {
|
|
662
|
+
const artifact = pythonTargetOf(target);
|
|
663
|
+
if (artifact === null) return null;
|
|
664
|
+
const fileName = `cpython-${OFFICE_LOCK.python.version}+${OFFICE_LOCK.python.release}-${artifact.pythonTarget}-install_only_stripped.tar.gz`;
|
|
665
|
+
const archive = {
|
|
666
|
+
url: `https://github.com/astral-sh/python-build-standalone/releases/download/${OFFICE_LOCK.python.release}/${encodeURIComponent(fileName)}`,
|
|
667
|
+
fileName,
|
|
668
|
+
integrity: { algorithm: "sha256", hex: artifact.sha256 }
|
|
669
|
+
};
|
|
670
|
+
const wheels = [...artifact.wheels, ...OFFICE_LOCK.python.wheels].map(
|
|
671
|
+
(wheel) => ({
|
|
672
|
+
url: wheel.url,
|
|
673
|
+
fileName: basenameOfUrl(wheel.url),
|
|
674
|
+
integrity: { algorithm: "sha256", hex: wheel.sha256 }
|
|
675
|
+
})
|
|
676
|
+
);
|
|
677
|
+
return { archive, wheels };
|
|
678
|
+
};
|
|
679
|
+
var fontItems = () => OFFICE_LOCK.fonts.files.map((file) => ({
|
|
680
|
+
url: `https://raw.githubusercontent.com/notofonts/noto-cjk/${file.path}`,
|
|
681
|
+
fileName: basenameOfUrl(file.path),
|
|
682
|
+
integrity: { algorithm: "sha256", hex: file.sha256 }
|
|
683
|
+
}));
|
|
684
|
+
var megabytes = (bytes) => (bytes / (1024 * 1024)).toFixed(1);
|
|
685
|
+
var downloadAll = async (ctx, component, items) => {
|
|
686
|
+
const dir = NodePath4.join(ctx.paths.downloadsDir, component);
|
|
687
|
+
const files = [];
|
|
688
|
+
for (const [index, item] of items.entries()) {
|
|
689
|
+
const report = (progress) => ctx.emit({
|
|
690
|
+
kind: "status",
|
|
691
|
+
statusKey: progress.totalBytes === null ? "progress.downloadingUnknown" : "progress.downloading",
|
|
692
|
+
params: {
|
|
693
|
+
file: progress.fileName,
|
|
694
|
+
index: String(index + 1),
|
|
695
|
+
count: String(items.length),
|
|
696
|
+
done: megabytes(progress.transferredBytes),
|
|
697
|
+
total: progress.totalBytes === null ? "" : megabytes(progress.totalBytes)
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
files.push(
|
|
701
|
+
await downloadVerified({
|
|
702
|
+
http: ctx.http,
|
|
703
|
+
item,
|
|
704
|
+
dir,
|
|
705
|
+
sources: ctx.sources,
|
|
706
|
+
signal: ctx.signal,
|
|
707
|
+
onProgress: report
|
|
708
|
+
})
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
return files;
|
|
712
|
+
};
|
|
713
|
+
var relativeToData = (ctx, target) => NodePath4.relative(ctx.paths.dataDir, target).split(NodePath4.sep).join("/");
|
|
714
|
+
var untar = async (ctx, archive, destination) => {
|
|
715
|
+
await NodeFSP3.mkdir(destination, { recursive: true });
|
|
716
|
+
const result = await ctx.process.run({
|
|
717
|
+
program: "tar",
|
|
718
|
+
args: [
|
|
719
|
+
"-xzf",
|
|
720
|
+
relativeToData(ctx, archive),
|
|
721
|
+
"-C",
|
|
722
|
+
relativeToData(ctx, destination),
|
|
723
|
+
"--strip-components=1"
|
|
724
|
+
],
|
|
725
|
+
cwd: ctx.paths.dataDir,
|
|
726
|
+
timeoutMs: 6e5
|
|
727
|
+
});
|
|
728
|
+
if (result.exitCode !== 0) {
|
|
729
|
+
throw new InstallError(
|
|
730
|
+
"unpack-failed",
|
|
731
|
+
`tar could not unpack ${NodePath4.basename(archive)}: ${(result.stderr || result.stdout).trim().slice(0, 400)}`
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
var steps = (ctx, states) => ctx.emit({
|
|
736
|
+
kind: "steps",
|
|
737
|
+
steps: ["download", "unpack", "check"].map((id) => ({
|
|
738
|
+
id,
|
|
739
|
+
labelKey: `progress.step.${id}`,
|
|
740
|
+
state: states[id]
|
|
741
|
+
}))
|
|
742
|
+
});
|
|
743
|
+
var stagingOf = (ctx, component) => `${ctx.paths.dirOf(component)}.staging`;
|
|
744
|
+
var finish = async (ctx, component, version) => {
|
|
745
|
+
await swapIntoPlace(stagingOf(ctx, component), ctx.paths.dirOf(component));
|
|
746
|
+
await writeInstallRecord(ctx.paths, component, { version, target: ctx.target });
|
|
747
|
+
await removePath(NodePath4.join(ctx.paths.downloadsDir, component));
|
|
748
|
+
};
|
|
749
|
+
var installEngine = async (ctx) => {
|
|
750
|
+
const packages = engineItems(ctx.target, ctx.sources.npmRegistry);
|
|
751
|
+
steps(ctx, { download: "running", unpack: "pending", check: "pending" });
|
|
752
|
+
const files = await downloadAll(
|
|
753
|
+
ctx,
|
|
754
|
+
"engine",
|
|
755
|
+
packages.map((pkg) => pkg.item)
|
|
756
|
+
);
|
|
757
|
+
steps(ctx, { download: "done", unpack: "running", check: "pending" });
|
|
758
|
+
const staging = stagingOf(ctx, "engine");
|
|
759
|
+
await removePath(staging);
|
|
760
|
+
for (const [index, pkg] of packages.entries()) {
|
|
761
|
+
await untar(ctx, files[index], NodePath4.join(staging, "node_modules", ...pkg.name.split("/")));
|
|
762
|
+
}
|
|
763
|
+
steps(ctx, { download: "done", unpack: "done", check: "running" });
|
|
764
|
+
const cli = NodePath4.join(
|
|
765
|
+
staging,
|
|
766
|
+
"node_modules",
|
|
767
|
+
"@deepseek-ai",
|
|
768
|
+
"libreoffice-kit",
|
|
769
|
+
"lib",
|
|
770
|
+
"cli.js"
|
|
771
|
+
);
|
|
772
|
+
const backend = await engineBackend(ctx.process, cli, ctx.paths.dataDir);
|
|
773
|
+
await finish(ctx, "engine", ENGINE_VERSION);
|
|
774
|
+
steps(ctx, { download: "done", unpack: "done", check: "done" });
|
|
775
|
+
return backend;
|
|
776
|
+
};
|
|
777
|
+
var engineBackend = async (processApi, cli, cwd) => {
|
|
778
|
+
const result = await processApi.run({
|
|
779
|
+
program: "host:node",
|
|
780
|
+
args: [cli, "capabilities", "--json"],
|
|
781
|
+
cwd,
|
|
782
|
+
timeoutMs: 6e4
|
|
783
|
+
});
|
|
784
|
+
let backend;
|
|
785
|
+
try {
|
|
786
|
+
backend = JSON.parse(result.stdout).runtime?.backend;
|
|
787
|
+
} catch {
|
|
788
|
+
backend = void 0;
|
|
789
|
+
}
|
|
790
|
+
if (result.exitCode !== 0 || typeof backend !== "string") {
|
|
791
|
+
throw new InstallError(
|
|
792
|
+
NodeProcess2.platform === "win32" ? "engine-unavailable-windows" : "engine-unavailable",
|
|
793
|
+
`The Office engine did not start: ${(result.stderr || result.stdout).trim().slice(0, 400)}`
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
return backend;
|
|
797
|
+
};
|
|
798
|
+
var pythonProgram = (platform5 = NodeProcess2.platform) => platform5 === "win32" ? PYTHON_PROGRAM.win32 : PYTHON_PROGRAM.other;
|
|
799
|
+
var runPython = async (ctx, args, what) => {
|
|
800
|
+
const result = await ctx.process.run({
|
|
801
|
+
program: pythonProgram(),
|
|
802
|
+
args,
|
|
803
|
+
cwd: ctx.paths.dataDir,
|
|
804
|
+
timeoutMs: 6e5
|
|
805
|
+
});
|
|
806
|
+
if (result.exitCode !== 0) {
|
|
807
|
+
throw new InstallError(
|
|
808
|
+
"python-failed",
|
|
809
|
+
`${what} failed: ${(result.stderr || result.stdout).trim().slice(-600)}`
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
var installPython = async (ctx) => {
|
|
814
|
+
const items = pythonItems(ctx.target);
|
|
815
|
+
if (items === null) {
|
|
816
|
+
throw new InstallError("python-unsupported", `No Python build is pinned for ${ctx.target}.`);
|
|
817
|
+
}
|
|
818
|
+
steps(ctx, { download: "running", unpack: "pending", check: "pending" });
|
|
819
|
+
const [archive, ...wheels] = await downloadAll(ctx, "python", [items.archive, ...items.wheels]);
|
|
820
|
+
steps(ctx, { download: "done", unpack: "running", check: "pending" });
|
|
821
|
+
const staging = stagingOf(ctx, "python");
|
|
822
|
+
await removePath(staging);
|
|
823
|
+
await untar(ctx, archive, staging);
|
|
824
|
+
await removePath(ctx.paths.recordOf("python"));
|
|
825
|
+
await swapIntoPlace(staging, ctx.paths.dirOf("python"));
|
|
826
|
+
try {
|
|
827
|
+
await runPython(
|
|
828
|
+
ctx,
|
|
829
|
+
[
|
|
830
|
+
"-I",
|
|
831
|
+
"-m",
|
|
832
|
+
"pip",
|
|
833
|
+
"install",
|
|
834
|
+
"--no-index",
|
|
835
|
+
"--no-deps",
|
|
836
|
+
"--no-compile",
|
|
837
|
+
"--disable-pip-version-check",
|
|
838
|
+
...wheels
|
|
839
|
+
],
|
|
840
|
+
"Installing the document libraries"
|
|
841
|
+
);
|
|
842
|
+
steps(ctx, { download: "done", unpack: "done", check: "running" });
|
|
843
|
+
await runPython(ctx, ["-I", "-m", "pip", "check"], "Checking the document libraries");
|
|
844
|
+
await runPython(
|
|
845
|
+
ctx,
|
|
846
|
+
["-I", "-c", "import docx, pptx, openpyxl, pandas, PIL, lxml"],
|
|
847
|
+
"Importing the document libraries"
|
|
848
|
+
);
|
|
849
|
+
} catch (error) {
|
|
850
|
+
await removePath(ctx.paths.dirOf("python"));
|
|
851
|
+
throw error;
|
|
852
|
+
}
|
|
853
|
+
await writeInstallRecord(ctx.paths, "python", { version: PYTHON_VERSION, target: ctx.target });
|
|
854
|
+
await removePath(NodePath4.join(ctx.paths.downloadsDir, "python"));
|
|
855
|
+
steps(ctx, { download: "done", unpack: "done", check: "done" });
|
|
856
|
+
};
|
|
857
|
+
var installFonts = async (ctx) => {
|
|
858
|
+
steps(ctx, { download: "running", unpack: "pending", check: "pending" });
|
|
859
|
+
const files = await downloadAll(ctx, "fonts", fontItems());
|
|
860
|
+
steps(ctx, { download: "done", unpack: "running", check: "pending" });
|
|
861
|
+
const staging = stagingOf(ctx, "fonts");
|
|
862
|
+
await removePath(staging);
|
|
863
|
+
await NodeFSP3.mkdir(staging, { recursive: true });
|
|
864
|
+
for (const file of files) {
|
|
865
|
+
await NodeFSP3.copyFile(file, NodePath4.join(staging, NodePath4.basename(file)));
|
|
866
|
+
}
|
|
867
|
+
await finish(ctx, "fonts", FONTS_VERSION);
|
|
868
|
+
steps(ctx, { download: "done", unpack: "done", check: "done" });
|
|
869
|
+
};
|
|
870
|
+
var removeRuntime = async (paths) => {
|
|
871
|
+
await removePath(paths.runtimeDir);
|
|
872
|
+
await removePath(paths.downloadsDir);
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/engine.ts
|
|
876
|
+
var EXPECTED_VERSION = {
|
|
877
|
+
engine: ENGINE_VERSION,
|
|
878
|
+
python: PYTHON_VERSION,
|
|
879
|
+
fonts: FONTS_VERSION
|
|
880
|
+
};
|
|
881
|
+
var componentReady = async (paths, component, target) => {
|
|
882
|
+
if (target === null) return false;
|
|
883
|
+
const record = await readInstallRecord(paths, component);
|
|
884
|
+
if (record?.version !== EXPECTED_VERSION[component] || record.target !== target) return false;
|
|
885
|
+
return NodeFSP4.stat(paths.dirOf(component)).then(
|
|
886
|
+
(info) => info.isDirectory(),
|
|
887
|
+
() => false
|
|
888
|
+
);
|
|
889
|
+
};
|
|
890
|
+
var fontDirectoryArgs = async (paths, target) => await componentReady(paths, "fonts", target) ? [...systemFontDirectories(), paths.dirOf("fonts")].flatMap((dir) => ["--font-directory", dir]) : [];
|
|
891
|
+
var EngineError = class extends Error {
|
|
892
|
+
};
|
|
893
|
+
var parseEngineOutput = (stdout, stderr, exitCode) => {
|
|
894
|
+
if (exitCode === 0) {
|
|
895
|
+
try {
|
|
896
|
+
return JSON.parse(stdout);
|
|
897
|
+
} catch {
|
|
898
|
+
throw new EngineError(
|
|
899
|
+
`The Office engine printed something that is not JSON: ${stdout.slice(0, 300)}`
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const detail = (stderr || stdout).trim().split("\n").slice(-6).join("\n");
|
|
904
|
+
throw new EngineError(
|
|
905
|
+
detail === "" ? `The Office engine exited with ${String(exitCode)}.` : detail
|
|
906
|
+
);
|
|
907
|
+
};
|
|
908
|
+
var runEngine = async (input) => {
|
|
909
|
+
const result = await input.process.run({
|
|
910
|
+
program: "host:node",
|
|
911
|
+
args: [
|
|
912
|
+
input.paths.engineCli,
|
|
913
|
+
...input.args,
|
|
914
|
+
...await fontDirectoryArgs(input.paths, input.target)
|
|
915
|
+
],
|
|
916
|
+
cwd: input.cwd,
|
|
917
|
+
timeoutMs: input.timeoutMs ?? 3e5,
|
|
918
|
+
maxOutputBytes: 4 * 1024 * 1024
|
|
919
|
+
});
|
|
920
|
+
if (result.timedOut) throw new EngineError("The Office engine did not finish in time.");
|
|
921
|
+
return parseEngineOutput(result.stdout, result.stderr, result.exitCode);
|
|
922
|
+
};
|
|
923
|
+
var collect = async (stream) => {
|
|
924
|
+
const chunks = [];
|
|
925
|
+
for await (const chunk of stream) chunks.push(chunk);
|
|
926
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
927
|
+
};
|
|
928
|
+
var runEngineCancellable = async (input) => {
|
|
929
|
+
const handle = await input.process.spawn({
|
|
930
|
+
program: "host:node",
|
|
931
|
+
args: [
|
|
932
|
+
input.paths.engineCli,
|
|
933
|
+
...input.args,
|
|
934
|
+
...await fontDirectoryArgs(input.paths, input.target)
|
|
935
|
+
],
|
|
936
|
+
cwd: input.cwd
|
|
937
|
+
});
|
|
938
|
+
const onAbort = () => void handle.kill("SIGTERM");
|
|
939
|
+
input.signal.addEventListener("abort", onAbort, { once: true });
|
|
940
|
+
try {
|
|
941
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
942
|
+
collect(handle.stdout),
|
|
943
|
+
collect(handle.stderr),
|
|
944
|
+
handle.exited
|
|
945
|
+
]);
|
|
946
|
+
if (input.signal.aborted) throw new EngineError("The conversion was cancelled.");
|
|
947
|
+
return parseEngineOutput(stdout, stderr, exitCode);
|
|
948
|
+
} finally {
|
|
949
|
+
input.signal.removeEventListener("abort", onAbort);
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var machineHasCjkFont = async (processApi, paths, target, platform5 = NodeProcess3.platform) => {
|
|
953
|
+
if (await componentReady(paths, "fonts", target)) return true;
|
|
954
|
+
if (platform5 !== "linux") return true;
|
|
955
|
+
try {
|
|
956
|
+
const result = await processApi.run({
|
|
957
|
+
program: "fc-list",
|
|
958
|
+
args: [":lang=zh", "family"],
|
|
959
|
+
timeoutMs: 15e3
|
|
960
|
+
});
|
|
961
|
+
return result.exitCode === 0 && result.stdout.trim().length > 0;
|
|
962
|
+
} catch {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/health.ts
|
|
968
|
+
var firstLine = (error) => (error instanceof Error ? error.message : String(error)).split("\n")[0].slice(0, 300);
|
|
969
|
+
var runHealthCheck = async (input) => {
|
|
970
|
+
const { process: processApi, paths, target } = input;
|
|
971
|
+
if (target === null) return [{ key: "health.unsupportedPlatform", ok: false }];
|
|
972
|
+
const entries = [];
|
|
973
|
+
if (!await componentReady(paths, "engine", target)) {
|
|
974
|
+
entries.push({ key: "health.engine.missing", ok: false });
|
|
975
|
+
} else {
|
|
976
|
+
try {
|
|
977
|
+
const backend = await engineBackend(processApi, paths.engineCli, paths.dataDir);
|
|
978
|
+
entries.push({ key: "health.engine.ok", params: { backend }, ok: true });
|
|
979
|
+
} catch (error) {
|
|
980
|
+
entries.push({
|
|
981
|
+
key: "health.engine.broken",
|
|
982
|
+
params: { detail: firstLine(error) },
|
|
983
|
+
ok: false
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
if (pythonTargetOf(target) === null) {
|
|
988
|
+
entries.push({ key: "health.python.unsupported", ok: false });
|
|
989
|
+
} else if (!await componentReady(paths, "python", target)) {
|
|
990
|
+
entries.push({ key: "health.python.missing", ok: false });
|
|
991
|
+
} else {
|
|
992
|
+
const result = await processApi.run({
|
|
993
|
+
program: pythonProgram(),
|
|
994
|
+
args: ["-I", "-c", "import docx, pptx, openpyxl, pandas, PIL, lxml"],
|
|
995
|
+
cwd: paths.dataDir,
|
|
996
|
+
timeoutMs: 6e4
|
|
997
|
+
});
|
|
998
|
+
entries.push(
|
|
999
|
+
result.exitCode === 0 ? { key: "health.python.ok", ok: true } : {
|
|
1000
|
+
key: "health.python.broken",
|
|
1001
|
+
params: { detail: (result.stderr || result.stdout).trim().slice(-300) },
|
|
1002
|
+
ok: false
|
|
1003
|
+
}
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
entries.push(
|
|
1007
|
+
await machineHasCjkFont(processApi, paths, target) ? { key: "health.fonts.ok", ok: true } : { key: "health.fonts.missing", ok: false }
|
|
1008
|
+
);
|
|
1009
|
+
return entries;
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
// src/preview.ts
|
|
1013
|
+
import * as NodeFSP5 from "node:fs/promises";
|
|
1014
|
+
import * as NodePath5 from "node:path";
|
|
1015
|
+
var PREVIEW_COMMAND = "convert-preview";
|
|
1016
|
+
var isWithin = (root, candidate) => {
|
|
1017
|
+
const relative4 = NodePath5.relative(root, candidate);
|
|
1018
|
+
return relative4 !== "" && !relative4.startsWith("..") && !NodePath5.isAbsolute(relative4);
|
|
1019
|
+
};
|
|
1020
|
+
var isAllowedPreviewOutput = async (cacheDir, outputPath) => {
|
|
1021
|
+
if (!NodePath5.isAbsolute(outputPath) || NodePath5.extname(outputPath).toLowerCase() !== ".pdf") {
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
try {
|
|
1025
|
+
const [root, parent] = await Promise.all([
|
|
1026
|
+
NodeFSP5.realpath(cacheDir),
|
|
1027
|
+
NodeFSP5.realpath(NodePath5.dirname(outputPath))
|
|
1028
|
+
]);
|
|
1029
|
+
return isWithin(root, NodePath5.join(parent, NodePath5.basename(outputPath)));
|
|
1030
|
+
} catch {
|
|
1031
|
+
return false;
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
var readPayload = (payload) => {
|
|
1035
|
+
const sourcePath = payload["sourcePath"];
|
|
1036
|
+
const outputPath = payload["outputPath"];
|
|
1037
|
+
return typeof sourcePath === "string" && typeof outputPath === "string" ? { sourcePath, outputPath } : null;
|
|
1038
|
+
};
|
|
1039
|
+
var registerPreviewCommand = (ctx, deps) => ctx.stream({
|
|
1040
|
+
name: PREVIEW_COMMAND,
|
|
1041
|
+
description: "Convert a document to PDF for the file preview (called by Ycodium).",
|
|
1042
|
+
scope: "operate",
|
|
1043
|
+
payloadSchema: {
|
|
1044
|
+
type: "object",
|
|
1045
|
+
properties: { sourcePath: { type: "string" }, outputPath: { type: "string" } },
|
|
1046
|
+
required: ["sourcePath", "outputPath"]
|
|
1047
|
+
},
|
|
1048
|
+
handle: async (raw, emit, signal) => {
|
|
1049
|
+
const payload = readPayload(raw);
|
|
1050
|
+
if (payload === null) throw new Error("sourcePath and outputPath are required.");
|
|
1051
|
+
if (!await componentReady(deps.paths, "engine", deps.target)) {
|
|
1052
|
+
emit({ status: "unavailable" });
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
if (!await isAllowedPreviewOutput(ctx.paths.cacheDir, payload.outputPath)) {
|
|
1056
|
+
throw new Error("The preview output must be a new .pdf file inside this plugin's cache.");
|
|
1057
|
+
}
|
|
1058
|
+
await runEngineCancellable({
|
|
1059
|
+
process: ctx.process,
|
|
1060
|
+
paths: deps.paths,
|
|
1061
|
+
target: deps.target,
|
|
1062
|
+
args: ["convert", "--input", payload.sourcePath, "--output", payload.outputPath],
|
|
1063
|
+
cwd: ctx.paths.dataDir,
|
|
1064
|
+
signal
|
|
1065
|
+
});
|
|
1066
|
+
emit({ status: "done" });
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
// src/tools.ts
|
|
1071
|
+
import * as NodePath6 from "node:path";
|
|
1072
|
+
import * as NodeProcess4 from "node:process";
|
|
1073
|
+
|
|
1074
|
+
// src/ooxml.ts
|
|
1075
|
+
import * as NodeZlib from "node:zlib";
|
|
1076
|
+
var CJK = /[-ヿ㐀-䶿一-鿿가-豈-]/u;
|
|
1077
|
+
var TEXT_PART = /^(word\/(document|header\d*|footer\d*|footnotes|endnotes)\.xml|ppt\/slides\/slide\d+\.xml|ppt\/notesSlides\/notesSlide\d+\.xml|xl\/sharedStrings\.xml|xl\/worksheets\/sheet\d+\.xml)$/u;
|
|
1078
|
+
var EOCD_SIGNATURE = 101010256;
|
|
1079
|
+
var CENTRAL_SIGNATURE = 33639248;
|
|
1080
|
+
var LOCAL_SIGNATURE = 67324752;
|
|
1081
|
+
var MAX_PART_BYTES = 64 * 1024 * 1024;
|
|
1082
|
+
var findEndOfCentralDirectory = (bytes) => {
|
|
1083
|
+
const earliest = Math.max(0, bytes.length - 22 - 65535);
|
|
1084
|
+
for (let offset = bytes.length - 22; offset >= earliest; offset -= 1) {
|
|
1085
|
+
if (bytes.readUInt32LE(offset) === EOCD_SIGNATURE) return offset;
|
|
1086
|
+
}
|
|
1087
|
+
return -1;
|
|
1088
|
+
};
|
|
1089
|
+
var centralEntries = (bytes) => {
|
|
1090
|
+
const eocd = findEndOfCentralDirectory(bytes);
|
|
1091
|
+
if (eocd < 0) return null;
|
|
1092
|
+
const count = bytes.readUInt16LE(eocd + 10);
|
|
1093
|
+
let offset = bytes.readUInt32LE(eocd + 16);
|
|
1094
|
+
const entries = [];
|
|
1095
|
+
for (let index = 0; index < count; index += 1) {
|
|
1096
|
+
if (offset + 46 > bytes.length || bytes.readUInt32LE(offset) !== CENTRAL_SIGNATURE) return null;
|
|
1097
|
+
const nameLength = bytes.readUInt16LE(offset + 28);
|
|
1098
|
+
const extraLength = bytes.readUInt16LE(offset + 30);
|
|
1099
|
+
const commentLength = bytes.readUInt16LE(offset + 32);
|
|
1100
|
+
entries.push({
|
|
1101
|
+
name: bytes.toString("utf8", offset + 46, offset + 46 + nameLength),
|
|
1102
|
+
method: bytes.readUInt16LE(offset + 10),
|
|
1103
|
+
compressedSize: bytes.readUInt32LE(offset + 20),
|
|
1104
|
+
localOffset: bytes.readUInt32LE(offset + 42)
|
|
1105
|
+
});
|
|
1106
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
1107
|
+
}
|
|
1108
|
+
return entries;
|
|
1109
|
+
};
|
|
1110
|
+
var readPart = (bytes, entry) => {
|
|
1111
|
+
const local = entry.localOffset;
|
|
1112
|
+
if (local + 30 > bytes.length || bytes.readUInt32LE(local) !== LOCAL_SIGNATURE) return null;
|
|
1113
|
+
const start = local + 30 + bytes.readUInt16LE(local + 26) + bytes.readUInt16LE(local + 28);
|
|
1114
|
+
const data = bytes.subarray(start, start + entry.compressedSize);
|
|
1115
|
+
if (entry.method === 0) return data.toString("utf8");
|
|
1116
|
+
if (entry.method !== 8) return null;
|
|
1117
|
+
try {
|
|
1118
|
+
return NodeZlib.inflateRawSync(data, { maxOutputLength: MAX_PART_BYTES }).toString("utf8");
|
|
1119
|
+
} catch {
|
|
1120
|
+
return null;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
var ooxmlHasCjk = (input) => {
|
|
1124
|
+
const bytes = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
1125
|
+
const entries = centralEntries(bytes);
|
|
1126
|
+
if (entries === null) return null;
|
|
1127
|
+
const parts = entries.filter((entry) => TEXT_PART.test(entry.name));
|
|
1128
|
+
if (parts.length === 0) return null;
|
|
1129
|
+
for (const part of parts) {
|
|
1130
|
+
const text2 = readPart(bytes, part);
|
|
1131
|
+
if (text2 !== null && CJK.test(text2)) return true;
|
|
1132
|
+
}
|
|
1133
|
+
return false;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
// src/tools.ts
|
|
1137
|
+
var MAX_IMAGES = 4;
|
|
1138
|
+
var MAX_IMAGE_BYTES = 3 * 1024 * 1024;
|
|
1139
|
+
var SETUP_HINT = "Ask the user to set it up in Settings \u2192 Plugins \u2192 Office. Do not install LibreOffice, Python packages, or another renderer yourself.";
|
|
1140
|
+
var text = (value, isError = false) => isError ? { text: value, isError: true } : { text: value };
|
|
1141
|
+
var stringArg = (input, key) => {
|
|
1142
|
+
const value = input[key];
|
|
1143
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
1144
|
+
};
|
|
1145
|
+
var workingDirOf = (invocation) => invocation.workspace?.roots[0] ?? invocation.projectRoot;
|
|
1146
|
+
var relativeTo = (cwd, target) => {
|
|
1147
|
+
const relative4 = NodePath6.relative(cwd, target);
|
|
1148
|
+
return relative4.startsWith("..") || NodePath6.isAbsolute(relative4) ? target : relative4;
|
|
1149
|
+
};
|
|
1150
|
+
var requireEngine = async (deps) => await componentReady(deps.paths, "engine", deps.target) ? null : text(`The Office engine is not installed on this machine. ${SETUP_HINT}`, true);
|
|
1151
|
+
var noWorkspace = text(
|
|
1152
|
+
"This tool needs a conversation with a project folder; call it from a thread.",
|
|
1153
|
+
true
|
|
1154
|
+
);
|
|
1155
|
+
var engineFailure = (error) => text(
|
|
1156
|
+
`The Office engine failed: ${error instanceof Error ? error.message : String(error)}
|
|
1157
|
+
Do not retry with another renderer; report the failure.`,
|
|
1158
|
+
true
|
|
1159
|
+
);
|
|
1160
|
+
var CJK_WARNING = "Warning: this machine has no Chinese/Japanese/Korean font, so CJK text in these images is drawn as boxes. Do not judge the layout from them. Fixes: install Chinese fonts in Settings \u2192 Plugins \u2192 Office, or install a system package such as fonts-noto-cjk.";
|
|
1161
|
+
var missingFontsLine = (fonts) => fonts === void 0 || fonts.length === 0 ? "Missing fonts: none." : `Missing fonts (substituted): ${fonts.join(", ")}.`;
|
|
1162
|
+
var readImages = async (invocation, images) => {
|
|
1163
|
+
const workspace = invocation.workspace;
|
|
1164
|
+
if (workspace === void 0) return [];
|
|
1165
|
+
const attached = [];
|
|
1166
|
+
for (const image of images.slice(0, MAX_IMAGES)) {
|
|
1167
|
+
if ((image.byteLength ?? 0) > MAX_IMAGE_BYTES) continue;
|
|
1168
|
+
try {
|
|
1169
|
+
const file = await workspace.readFile(image.path, { maxBytes: MAX_IMAGE_BYTES });
|
|
1170
|
+
attached.push({ data: file.bytes, mimeType: "image/png" });
|
|
1171
|
+
} catch {
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
return attached;
|
|
1175
|
+
};
|
|
1176
|
+
var documentHasCjk = async (invocation, source) => {
|
|
1177
|
+
try {
|
|
1178
|
+
const file = await invocation.workspace?.readFile(source);
|
|
1179
|
+
return file === void 0 ? null : ooxmlHasCjk(file.bytes);
|
|
1180
|
+
} catch {
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
var render = (deps) => ({
|
|
1185
|
+
name: "render",
|
|
1186
|
+
description: "Render pages, slides, or a worksheet range of an Office document (docx, pptx, xlsx, doc, ppt, xls, odt, odp, ods) or a PDF to PNG images with the bundled LibreOffice engine, for visual checks. Returns the page count, image paths, and missing fonts; up to four images are attached for models that read images. `outputDir` must be a new directory.",
|
|
1187
|
+
inputSchema: {
|
|
1188
|
+
type: "object",
|
|
1189
|
+
properties: {
|
|
1190
|
+
path: { type: "string", description: "Document to render, relative to the project folder." },
|
|
1191
|
+
outputDir: {
|
|
1192
|
+
type: "string",
|
|
1193
|
+
description: "New directory for the PNG files and manifest.json."
|
|
1194
|
+
},
|
|
1195
|
+
pages: {
|
|
1196
|
+
type: "string",
|
|
1197
|
+
description: "`all`, or one-based page/slide numbers such as `1,3`."
|
|
1198
|
+
},
|
|
1199
|
+
sheet: { type: "string", description: "Exact worksheet name (spreadsheets)." },
|
|
1200
|
+
range: { type: "string", description: "A1 range on that worksheet, such as `A1:D20`." },
|
|
1201
|
+
dpi: { type: "number", description: "Resolution; 144 by default." }
|
|
1202
|
+
},
|
|
1203
|
+
required: ["path", "outputDir"]
|
|
1204
|
+
},
|
|
1205
|
+
handle: async (input, invocation) => {
|
|
1206
|
+
const blocked = await requireEngine(deps);
|
|
1207
|
+
if (blocked !== null) return blocked;
|
|
1208
|
+
const cwd = workingDirOf(invocation);
|
|
1209
|
+
if (cwd === null) return noWorkspace;
|
|
1210
|
+
const source = stringArg(input, "path");
|
|
1211
|
+
const outputDir = stringArg(input, "outputDir");
|
|
1212
|
+
if (source === null || outputDir === null)
|
|
1213
|
+
return text("`path` and `outputDir` are required.", true);
|
|
1214
|
+
const optional = (flag, key) => {
|
|
1215
|
+
const value = stringArg(input, key);
|
|
1216
|
+
return value === null ? [] : [flag, value];
|
|
1217
|
+
};
|
|
1218
|
+
const dpi = typeof input["dpi"] === "number" ? ["--dpi", String(input["dpi"])] : [];
|
|
1219
|
+
let result;
|
|
1220
|
+
try {
|
|
1221
|
+
result = await runEngine({
|
|
1222
|
+
process: deps.process,
|
|
1223
|
+
paths: deps.paths,
|
|
1224
|
+
target: deps.target,
|
|
1225
|
+
cwd,
|
|
1226
|
+
args: [
|
|
1227
|
+
"render",
|
|
1228
|
+
"--input",
|
|
1229
|
+
source,
|
|
1230
|
+
"--output-dir",
|
|
1231
|
+
outputDir,
|
|
1232
|
+
...optional("--pages", "pages"),
|
|
1233
|
+
...optional("--sheet", "sheet"),
|
|
1234
|
+
...optional("--range", "range"),
|
|
1235
|
+
...dpi
|
|
1236
|
+
]
|
|
1237
|
+
});
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
return engineFailure(error);
|
|
1240
|
+
}
|
|
1241
|
+
const images = result.images ?? [];
|
|
1242
|
+
const absoluteSource = NodePath6.resolve(cwd, source);
|
|
1243
|
+
const warn = !await machineHasCjkFont(deps.process, deps.paths, deps.target) && await documentHasCjk(invocation, absoluteSource) === true;
|
|
1244
|
+
const lines = [
|
|
1245
|
+
...warn ? [CJK_WARNING] : [],
|
|
1246
|
+
`Rendered ${source} with the ${result.backend ?? "bundled"} engine: ${String(result.pageCount ?? images.length)} page(s) in the document, ${String(images.length)} image(s) written.`,
|
|
1247
|
+
"Images:",
|
|
1248
|
+
...images.map(
|
|
1249
|
+
(image) => `- page ${String(image.page ?? "?")}: ${relativeTo(cwd, image.path)}${image.width === void 0 ? "" : ` (${String(image.width)}x${String(image.height)})`}`
|
|
1250
|
+
),
|
|
1251
|
+
...images.length > MAX_IMAGES ? [
|
|
1252
|
+
`Only the first ${String(MAX_IMAGES)} images are attached; the rest are at the paths above.`
|
|
1253
|
+
] : [],
|
|
1254
|
+
missingFontsLine(result.missingFonts)
|
|
1255
|
+
];
|
|
1256
|
+
return { text: lines.join("\n"), images: await readImages(invocation, images) };
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
var convertLike = (deps, spec) => ({
|
|
1260
|
+
name: spec.name,
|
|
1261
|
+
description: spec.name === "convert" ? "Convert an Office document with the bundled LibreOffice engine; the output suffix selects the format (pdf, docx, xlsx, pptx, csv, odt, ods, odp). The output file must be new." : "Recalculate every formula in a workbook (xls, xlsx, ods) with the bundled LibreOffice engine and save the results to a new xlsx or ods file.",
|
|
1262
|
+
inputSchema: {
|
|
1263
|
+
type: "object",
|
|
1264
|
+
properties: {
|
|
1265
|
+
path: { type: "string", description: "Source document, relative to the project folder." },
|
|
1266
|
+
output: { type: "string", description: "New output file; its suffix selects the format." },
|
|
1267
|
+
...spec.name === "convert" ? { sheet: { type: "string", description: "Worksheet to export when the output is CSV." } } : {}
|
|
1268
|
+
},
|
|
1269
|
+
required: ["path", "output"]
|
|
1270
|
+
},
|
|
1271
|
+
handle: async (input, invocation) => {
|
|
1272
|
+
const blocked = await requireEngine(deps);
|
|
1273
|
+
if (blocked !== null) return blocked;
|
|
1274
|
+
const cwd = workingDirOf(invocation);
|
|
1275
|
+
if (cwd === null) return noWorkspace;
|
|
1276
|
+
const source = stringArg(input, "path");
|
|
1277
|
+
const output = stringArg(input, "output");
|
|
1278
|
+
if (source === null || output === null) return text("`path` and `output` are required.", true);
|
|
1279
|
+
const sheet = spec.name === "convert" ? stringArg(input, "sheet") : null;
|
|
1280
|
+
let result;
|
|
1281
|
+
try {
|
|
1282
|
+
result = await runEngine({
|
|
1283
|
+
process: deps.process,
|
|
1284
|
+
paths: deps.paths,
|
|
1285
|
+
target: deps.target,
|
|
1286
|
+
cwd,
|
|
1287
|
+
args: [
|
|
1288
|
+
spec.name,
|
|
1289
|
+
"--input",
|
|
1290
|
+
source,
|
|
1291
|
+
"--output",
|
|
1292
|
+
output,
|
|
1293
|
+
...sheet === null ? [] : ["--sheet", sheet]
|
|
1294
|
+
]
|
|
1295
|
+
});
|
|
1296
|
+
} catch (error) {
|
|
1297
|
+
return engineFailure(error);
|
|
1298
|
+
}
|
|
1299
|
+
const verb = spec.name === "convert" ? "Converted" : "Recalculated";
|
|
1300
|
+
return text(`${verb} ${source} into ${output}.
|
|
1301
|
+
${missingFontsLine(result.missingFonts)}`);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
var check = (deps) => ({
|
|
1305
|
+
name: "check",
|
|
1306
|
+
description: "Run the read-only OOXML checker on a docx, pptx, or xlsx: ZIP/XML integrity, internal relationships, paragraph/table/section, slide and sheet summaries, and optional text assertions. Returns JSON. It does not check pagination, fonts, or appearance; use office_render for that.",
|
|
1307
|
+
inputSchema: {
|
|
1308
|
+
type: "object",
|
|
1309
|
+
properties: {
|
|
1310
|
+
path: { type: "string", description: "Document to check, relative to the project folder." },
|
|
1311
|
+
contains: {
|
|
1312
|
+
type: "array",
|
|
1313
|
+
items: { type: "string" },
|
|
1314
|
+
description: "Text the document must contain (each checked separately)."
|
|
1315
|
+
},
|
|
1316
|
+
count: { type: "number", description: "Expected slide or sheet count." }
|
|
1317
|
+
},
|
|
1318
|
+
required: ["path"]
|
|
1319
|
+
},
|
|
1320
|
+
handle: async (input, invocation) => {
|
|
1321
|
+
if (!await componentReady(deps.paths, "python", deps.target)) {
|
|
1322
|
+
return text(`Python for Office is not installed on this machine. ${SETUP_HINT}`, true);
|
|
1323
|
+
}
|
|
1324
|
+
const cwd = workingDirOf(invocation);
|
|
1325
|
+
if (cwd === null) return noWorkspace;
|
|
1326
|
+
const source = stringArg(input, "path");
|
|
1327
|
+
if (source === null) return text("`path` is required.", true);
|
|
1328
|
+
const contains = Array.isArray(input["contains"]) ? input["contains"].filter((entry) => typeof entry === "string") : [];
|
|
1329
|
+
const count = typeof input["count"] === "number" ? ["--count", String(input["count"])] : [];
|
|
1330
|
+
const result = await deps.process.run({
|
|
1331
|
+
program: pythonProgram(),
|
|
1332
|
+
args: [
|
|
1333
|
+
"-I",
|
|
1334
|
+
deps.checkerScript,
|
|
1335
|
+
source,
|
|
1336
|
+
...contains.flatMap((value) => ["--contains", value]),
|
|
1337
|
+
...count
|
|
1338
|
+
],
|
|
1339
|
+
cwd,
|
|
1340
|
+
env: { PYTHONIOENCODING: "utf-8" },
|
|
1341
|
+
timeoutMs: 12e4
|
|
1342
|
+
});
|
|
1343
|
+
const report = result.stdout.trim();
|
|
1344
|
+
if (result.exitCode === 0) return text(`Checks passed.
|
|
1345
|
+
${report}`);
|
|
1346
|
+
if (result.exitCode === 1)
|
|
1347
|
+
return text(`Checks failed.
|
|
1348
|
+
${report}
|
|
1349
|
+
${result.stderr.trim()}`.trim());
|
|
1350
|
+
return text(`The checker could not run: ${(result.stderr || report).trim()}`, true);
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
var python = (deps) => ({
|
|
1354
|
+
name: "python",
|
|
1355
|
+
description: "Return the bundled Python interpreter for writing Office files, with python-docx, python-pptx, openpyxl, pandas, Pillow, lxml, and XlsxWriter preinstalled. Run your scripts with this executable instead of installing packages or looking for a system Python.",
|
|
1356
|
+
inputSchema: { type: "object", properties: {} },
|
|
1357
|
+
handle: async () => {
|
|
1358
|
+
if (!await componentReady(deps.paths, "python", deps.target)) {
|
|
1359
|
+
return text(`Python for Office is not installed on this machine. ${SETUP_HINT}`, true);
|
|
1360
|
+
}
|
|
1361
|
+
return text(
|
|
1362
|
+
[
|
|
1363
|
+
JSON.stringify(
|
|
1364
|
+
{
|
|
1365
|
+
python: deps.paths.pythonExecutable(NodeProcess4.platform),
|
|
1366
|
+
version: OFFICE_LOCK.python.version,
|
|
1367
|
+
packages: OFFICE_LOCK.python.packages
|
|
1368
|
+
},
|
|
1369
|
+
null,
|
|
1370
|
+
2
|
|
1371
|
+
),
|
|
1372
|
+
"Quote the path when you run it; PowerShell also needs the `&` call operator. Keep scripts and outputs in the project folder."
|
|
1373
|
+
].join("\n")
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
var officeTools = (deps) => [
|
|
1378
|
+
check(deps),
|
|
1379
|
+
render(deps),
|
|
1380
|
+
convertLike(deps, { name: "convert" }),
|
|
1381
|
+
convertLike(deps, { name: "recalculate" }),
|
|
1382
|
+
python(deps)
|
|
1383
|
+
];
|
|
1384
|
+
|
|
1385
|
+
// src/index.ts
|
|
1386
|
+
var sourcesOf = (config) => {
|
|
1387
|
+
const pick = (value, fallback) => typeof value === "string" && value.trim() !== "" ? value.trim() : fallback;
|
|
1388
|
+
return {
|
|
1389
|
+
npmRegistry: pick(config.npmRegistry, DEFAULT_SOURCES.npmRegistry),
|
|
1390
|
+
githubMirror: pick(config.githubMirror, DEFAULT_SOURCES.githubMirror),
|
|
1391
|
+
pypiMirror: pick(config.pypiMirror, DEFAULT_SOURCES.pypiMirror),
|
|
1392
|
+
localDir: pick(config.localDir, DEFAULT_SOURCES.localDir)
|
|
1393
|
+
};
|
|
1394
|
+
};
|
|
1395
|
+
var failureOf = (error) => {
|
|
1396
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1397
|
+
if (error instanceof InstallError)
|
|
1398
|
+
return { kind: "failed", reasonKey: `failure.${error.reason}`, detail };
|
|
1399
|
+
if (error instanceof DownloadError) {
|
|
1400
|
+
return { kind: "failed", reasonKey: `failure.download-${error.reason}`, detail };
|
|
1401
|
+
}
|
|
1402
|
+
return { kind: "failed", reasonKey: "failure.unknown", detail };
|
|
1403
|
+
};
|
|
1404
|
+
var EMPTY_PAYLOAD = { type: "object", properties: {} };
|
|
1405
|
+
var index_default = definePlugin({
|
|
1406
|
+
id: "office",
|
|
1407
|
+
apiVersion: 3,
|
|
1408
|
+
activate: (ctx) => {
|
|
1409
|
+
const paths = officePaths(ctx.paths.dataDir);
|
|
1410
|
+
const target = detectOfficeTarget();
|
|
1411
|
+
ctx.toolkit({
|
|
1412
|
+
name: "office",
|
|
1413
|
+
tools: officeTools({
|
|
1414
|
+
process: ctx.process,
|
|
1415
|
+
paths,
|
|
1416
|
+
target,
|
|
1417
|
+
checkerScript: NodePath7.join(ctx.paths.pluginDir, "assets", "check_office.py")
|
|
1418
|
+
})
|
|
1419
|
+
});
|
|
1420
|
+
registerPreviewCommand(ctx, { paths, target });
|
|
1421
|
+
let busy = false;
|
|
1422
|
+
const action = (name, description, run) => ctx.stream({
|
|
1423
|
+
name,
|
|
1424
|
+
description,
|
|
1425
|
+
scope: "operate",
|
|
1426
|
+
payloadSchema: EMPTY_PAYLOAD,
|
|
1427
|
+
handle: async (_payload, emit, signal) => {
|
|
1428
|
+
if (busy) {
|
|
1429
|
+
emit({ kind: "failed", reasonKey: "failure.busy" });
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
busy = true;
|
|
1433
|
+
try {
|
|
1434
|
+
emit(await run(emit, signal));
|
|
1435
|
+
} catch (error) {
|
|
1436
|
+
if (!signal.aborted) emit(failureOf(error));
|
|
1437
|
+
} finally {
|
|
1438
|
+
busy = false;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
const installContext = (emit, signal) => {
|
|
1443
|
+
if (target === null) {
|
|
1444
|
+
throw new InstallError(
|
|
1445
|
+
"unsupported-platform",
|
|
1446
|
+
"This machine's platform has no Office engine build."
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
return {
|
|
1450
|
+
http: ctx.http,
|
|
1451
|
+
process: ctx.process,
|
|
1452
|
+
paths,
|
|
1453
|
+
target,
|
|
1454
|
+
sources: sourcesOf(ctx.config),
|
|
1455
|
+
signal,
|
|
1456
|
+
emit
|
|
1457
|
+
};
|
|
1458
|
+
};
|
|
1459
|
+
action("install-engine", "Download and install the Office engine.", async (emit, signal) => {
|
|
1460
|
+
const backend = await installEngine(installContext(emit, signal));
|
|
1461
|
+
return {
|
|
1462
|
+
kind: "done",
|
|
1463
|
+
fills: {},
|
|
1464
|
+
messageKey: `progress.done.engine.${backend === "wasm" ? "wasm" : "native"}`
|
|
1465
|
+
};
|
|
1466
|
+
});
|
|
1467
|
+
action(
|
|
1468
|
+
"install-python",
|
|
1469
|
+
"Download and install Python with the document libraries.",
|
|
1470
|
+
async (emit, signal) => {
|
|
1471
|
+
await installPython(installContext(emit, signal));
|
|
1472
|
+
return { kind: "done", fills: {}, messageKey: "progress.done.python" };
|
|
1473
|
+
}
|
|
1474
|
+
);
|
|
1475
|
+
action(
|
|
1476
|
+
"install-fonts",
|
|
1477
|
+
"Download Chinese fonts for the Office engine.",
|
|
1478
|
+
async (emit, signal) => {
|
|
1479
|
+
await installFonts(installContext(emit, signal));
|
|
1480
|
+
return { kind: "done", fills: {}, messageKey: "progress.done.fonts" };
|
|
1481
|
+
}
|
|
1482
|
+
);
|
|
1483
|
+
action(
|
|
1484
|
+
"health",
|
|
1485
|
+
"Check the Office engine, Python, and fonts on this machine.",
|
|
1486
|
+
async (emit) => {
|
|
1487
|
+
emit({ kind: "status", statusKey: "progress.checking" });
|
|
1488
|
+
const entries = await runHealthCheck({ process: ctx.process, paths, target });
|
|
1489
|
+
return {
|
|
1490
|
+
kind: "done",
|
|
1491
|
+
fills: {},
|
|
1492
|
+
messageKey: entries.every((entry) => entry.ok) ? "health.summary.ok" : "health.summary.issues",
|
|
1493
|
+
warnings: entries.map((entry) => ({
|
|
1494
|
+
key: entry.key,
|
|
1495
|
+
...entry.params === void 0 ? {} : { params: entry.params }
|
|
1496
|
+
}))
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
);
|
|
1500
|
+
action(
|
|
1501
|
+
"remove-runtime",
|
|
1502
|
+
"Delete the Office engine, Python, and fonts from this machine.",
|
|
1503
|
+
async (emit) => {
|
|
1504
|
+
emit({ kind: "status", statusKey: "progress.removing" });
|
|
1505
|
+
await removeRuntime(paths);
|
|
1506
|
+
return { kind: "done", fills: {}, messageKey: "progress.done.removed" };
|
|
1507
|
+
}
|
|
1508
|
+
);
|
|
1509
|
+
ctx.settingsCard({
|
|
1510
|
+
titleKey: "settings.card.title",
|
|
1511
|
+
descriptionKey: "settings.card.description",
|
|
1512
|
+
fields: [
|
|
1513
|
+
{
|
|
1514
|
+
key: "npmRegistry",
|
|
1515
|
+
kind: "text",
|
|
1516
|
+
labelKey: "settings.npmRegistry.label",
|
|
1517
|
+
descriptionKey: "settings.npmRegistry.description"
|
|
1518
|
+
},
|
|
1519
|
+
{
|
|
1520
|
+
key: "githubMirror",
|
|
1521
|
+
kind: "text",
|
|
1522
|
+
labelKey: "settings.githubMirror.label",
|
|
1523
|
+
descriptionKey: "settings.githubMirror.description"
|
|
1524
|
+
},
|
|
1525
|
+
{
|
|
1526
|
+
key: "pypiMirror",
|
|
1527
|
+
kind: "text",
|
|
1528
|
+
labelKey: "settings.pypiMirror.label",
|
|
1529
|
+
descriptionKey: "settings.pypiMirror.description"
|
|
1530
|
+
},
|
|
1531
|
+
{
|
|
1532
|
+
key: "localDir",
|
|
1533
|
+
kind: "text",
|
|
1534
|
+
labelKey: "settings.localDir.label",
|
|
1535
|
+
descriptionKey: "settings.localDir.description"
|
|
1536
|
+
}
|
|
1537
|
+
],
|
|
1538
|
+
actions: [
|
|
1539
|
+
{
|
|
1540
|
+
id: "install-engine",
|
|
1541
|
+
labelKey: "actions.installEngine.label",
|
|
1542
|
+
descriptionKey: "actions.installEngine.description",
|
|
1543
|
+
command: "install-engine"
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
id: "install-python",
|
|
1547
|
+
labelKey: "actions.installPython.label",
|
|
1548
|
+
descriptionKey: "actions.installPython.description",
|
|
1549
|
+
command: "install-python"
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
id: "install-fonts",
|
|
1553
|
+
labelKey: "actions.installFonts.label",
|
|
1554
|
+
descriptionKey: "actions.installFonts.description",
|
|
1555
|
+
command: "install-fonts"
|
|
1556
|
+
},
|
|
1557
|
+
{
|
|
1558
|
+
id: "health",
|
|
1559
|
+
labelKey: "actions.health.label",
|
|
1560
|
+
descriptionKey: "actions.health.description",
|
|
1561
|
+
command: "health"
|
|
1562
|
+
},
|
|
1563
|
+
{
|
|
1564
|
+
id: "remove-runtime",
|
|
1565
|
+
labelKey: "actions.remove.label",
|
|
1566
|
+
descriptionKey: "actions.remove.description",
|
|
1567
|
+
command: "remove-runtime"
|
|
1568
|
+
}
|
|
1569
|
+
]
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
export {
|
|
1574
|
+
index_default as default
|
|
1575
|
+
};
|