@deepseek-ai/libreoffice-kit 0.0.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/LICENSE +373 -0
- package/NOTICE +26 -0
- package/README.md +73 -0
- package/README.zh.md +73 -0
- package/lib/index.js +924 -0
- package/lib/types/document.d.ts +15 -0
- package/lib/types/engine.d.ts +67 -0
- package/lib/types/errors.d.ts +21 -0
- package/lib/types/font-loader.d.ts +42 -0
- package/lib/types/fonts.d.ts +141 -0
- package/lib/types/index.d.ts +65 -0
- package/lib/types/native-font-names.d.ts +3 -0
- package/lib/types/native.d.ts +34 -0
- package/lib/types/ooxml.d.ts +17 -0
- package/lib/types/options.d.ts +28 -0
- package/lib/types/wasm.d.ts +25 -0
- package/lib/types/worker.d.ts +14 -0
- package/lib/worker.js +800 -0
- package/package.json +46 -0
package/lib/worker.js
ADDED
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
5
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
6
|
+
import { SaxesParser } from "saxes";
|
|
7
|
+
import { create } from "fontkit";
|
|
8
|
+
//#region lib/types/errors.js
|
|
9
|
+
/** Stable render failure categories shared across the Node worker and native helper transports. */
|
|
10
|
+
const CODES = /* @__PURE__ */ new Set([
|
|
11
|
+
"input-too-large",
|
|
12
|
+
"output-too-large",
|
|
13
|
+
"invalid-document",
|
|
14
|
+
"unsupported-format",
|
|
15
|
+
"invalid-output",
|
|
16
|
+
"timeout",
|
|
17
|
+
"unavailable",
|
|
18
|
+
"failed"
|
|
19
|
+
]);
|
|
20
|
+
/** An actionable converter failure; operating-system errors and caller abort reasons remain unchanged. */
|
|
21
|
+
var ConversionError = class extends Error {
|
|
22
|
+
/** Published failure category carried across worker and helper transports. */
|
|
23
|
+
code;
|
|
24
|
+
/**
|
|
25
|
+
* @param code - Published failure category.
|
|
26
|
+
* @param message - Consumer-facing failure description.
|
|
27
|
+
* @param options - Standard error options; a cause is preserved for diagnostics.
|
|
28
|
+
*/
|
|
29
|
+
constructor(code, message, options) {
|
|
30
|
+
super(message, options);
|
|
31
|
+
this.name = "ConversionError";
|
|
32
|
+
this.code = code;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Only published categories cross worker/helper messages; unknown errors use the generic failure category.
|
|
37
|
+
* @param error - The thrown value, which may be any type and may carry an unpublished `code`.
|
|
38
|
+
* @returns The published category, or `failed` when no published category is present.
|
|
39
|
+
*/
|
|
40
|
+
function failureCode(error) {
|
|
41
|
+
const code = error?.code;
|
|
42
|
+
return typeof code === "string" && CODES.has(code) ? code : "failed";
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region lib/types/fonts.js
|
|
46
|
+
/** Host font metadata snapshots and conversion-local glyph matching over original files. */
|
|
47
|
+
const FONT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
48
|
+
".ttf",
|
|
49
|
+
".otf",
|
|
50
|
+
".ttc",
|
|
51
|
+
".otc",
|
|
52
|
+
".dfont"
|
|
53
|
+
]);
|
|
54
|
+
const VCL_WEIGHTS = [
|
|
55
|
+
400,
|
|
56
|
+
100,
|
|
57
|
+
200,
|
|
58
|
+
300,
|
|
59
|
+
350,
|
|
60
|
+
400,
|
|
61
|
+
500,
|
|
62
|
+
600,
|
|
63
|
+
700,
|
|
64
|
+
800,
|
|
65
|
+
900
|
|
66
|
+
];
|
|
67
|
+
const GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
68
|
+
"serif",
|
|
69
|
+
"sansserif",
|
|
70
|
+
"monospace",
|
|
71
|
+
"cursive",
|
|
72
|
+
"fantasy",
|
|
73
|
+
"systemui",
|
|
74
|
+
"symbol"
|
|
75
|
+
]);
|
|
76
|
+
/** File identity read from the descriptor, before and after, to detect concurrent replacement. */
|
|
77
|
+
const STAT_KEYS = [
|
|
78
|
+
"dev",
|
|
79
|
+
"ino",
|
|
80
|
+
"size",
|
|
81
|
+
"mtimeMs",
|
|
82
|
+
"ctimeMs"
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* @param error - Thrown filesystem value.
|
|
86
|
+
* @returns whether it means the path is not a usable font source.
|
|
87
|
+
*/
|
|
88
|
+
function absent(error) {
|
|
89
|
+
return error instanceof Error && "code" in error && [
|
|
90
|
+
"ENOENT",
|
|
91
|
+
"EACCES",
|
|
92
|
+
"EPERM",
|
|
93
|
+
"ENOTDIR"
|
|
94
|
+
].includes(String(error.code));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Case- and separator-insensitive family key used to compare names across sources.
|
|
98
|
+
* @param value - Family, style, or postscript name as recorded by a document or font.
|
|
99
|
+
* @returns The normalized key.
|
|
100
|
+
*/
|
|
101
|
+
function normalize(value) {
|
|
102
|
+
return value.normalize("NFKC").toLowerCase().replaceAll(/[\s_-]/g, "");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Order named substitutions and their generic text family without excluding unlisted fonts.
|
|
106
|
+
* @param requested - Original family names, in document order.
|
|
107
|
+
* @param groups - Ordered family groups shared with Fontconfig aliases.
|
|
108
|
+
* @param pitch - VCL pitch; one requests a monospaced fallback.
|
|
109
|
+
* @param symbols - Whether symbol alternatives precede the generic fallback.
|
|
110
|
+
* @returns distinct family names, with original requests first.
|
|
111
|
+
*/
|
|
112
|
+
function fontFamilyPriority(requested, groups, pitch = 0, symbols = false) {
|
|
113
|
+
const original = requested.map(normalize);
|
|
114
|
+
const matched = groups.filter((group) => group.some((family) => original.includes(normalize(family))));
|
|
115
|
+
const generic = original.includes("monospace") || pitch === 1 ? "monospace" : original.includes("serif") ? "serif" : matched.flat().map(normalize).find((family) => family === "serif" || family === "sansserif" || family === "monospace") ?? "sansserif";
|
|
116
|
+
const families = [...requested, ...matched.flat()];
|
|
117
|
+
for (const kind of symbols ? ["symbol", generic] : [generic]) for (const group of groups) if (group.some((family) => normalize(family) === kind)) families.push(...group);
|
|
118
|
+
const priority = /* @__PURE__ */ new Map();
|
|
119
|
+
for (const family of families) {
|
|
120
|
+
const name = normalize(family);
|
|
121
|
+
if (!priority.has(name)) priority.set(name, family);
|
|
122
|
+
}
|
|
123
|
+
return [...priority.values()];
|
|
124
|
+
}
|
|
125
|
+
function fontPaths(directories, maxFiles) {
|
|
126
|
+
const pending = [...directories].reverse();
|
|
127
|
+
const visited = /* @__PURE__ */ new Set();
|
|
128
|
+
const paths = [];
|
|
129
|
+
for (let path = pending.pop(); path !== void 0; path = pending.pop()) {
|
|
130
|
+
let canonical;
|
|
131
|
+
let status;
|
|
132
|
+
try {
|
|
133
|
+
canonical = realpathSync(path);
|
|
134
|
+
status = statSync(canonical);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (absent(error)) continue;
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
if (visited.has(canonical)) continue;
|
|
140
|
+
visited.add(canonical);
|
|
141
|
+
if (status.isDirectory()) {
|
|
142
|
+
let names;
|
|
143
|
+
try {
|
|
144
|
+
names = readdirSync(canonical);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (absent(error)) continue;
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
pending.push(...names.sort().reverse().map((name) => join(canonical, name)));
|
|
150
|
+
} else if (status.isFile() && FONT_EXTENSIONS.has(extname(canonical).toLowerCase())) {
|
|
151
|
+
if (paths.length >= maxFiles) throw new Error("The system font catalog exceeds maxFontFiles.");
|
|
152
|
+
paths.push(canonical);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return paths;
|
|
156
|
+
}
|
|
157
|
+
function ranges(font) {
|
|
158
|
+
const points = font.characterSet.filter((point) => font.hasGlyphForCodePoint(point)).sort((left, right) => left - right);
|
|
159
|
+
const result = [];
|
|
160
|
+
for (const point of points) {
|
|
161
|
+
const last = result.at(-1);
|
|
162
|
+
if (last !== void 0 && point <= last[1] + 1) last[1] = Math.max(last[1], point);
|
|
163
|
+
else result.push([point, point]);
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Decode glyph coverage for one parsed face.
|
|
169
|
+
* @param font - The parsed physical face.
|
|
170
|
+
* @returns the inclusive ranges the face renders, or none when its glyph tables reject decoding.
|
|
171
|
+
*/
|
|
172
|
+
function faceCoverage(font) {
|
|
173
|
+
try {
|
|
174
|
+
return ranges(font);
|
|
175
|
+
} catch {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* @param parsed - Parsed font file: one face, or a collection of faces.
|
|
181
|
+
* @param face - Indexed metadata naming the face inside that file.
|
|
182
|
+
* @returns the physical face the index names.
|
|
183
|
+
* @throws when the file no longer provides the indexed face.
|
|
184
|
+
*/
|
|
185
|
+
function indexedFace(parsed, face) {
|
|
186
|
+
const font = "fonts" in parsed ? parsed.fonts[face.faceIndex] : parsed;
|
|
187
|
+
if (font === void 0 || font.postscriptName !== face.postscriptName) throw new Error("The indexed font face is no longer available; recreate the converter.");
|
|
188
|
+
return font;
|
|
189
|
+
}
|
|
190
|
+
function covers(face, points) {
|
|
191
|
+
if (points.length === 0) return [];
|
|
192
|
+
if (face.coverage === void 0) face.coverage = faceCoverage(indexedFace(create(readFont(face)), face));
|
|
193
|
+
const coverage = face.coverage;
|
|
194
|
+
return points.filter((point) => coverage.some(([first, last]) => point >= first && point <= last));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* VCL weight, width, and fixed-pitch values for one parsed face.
|
|
198
|
+
* @param font - The parsed physical face, whose `OS/2` and `post` tables may be absent.
|
|
199
|
+
* @returns the recorded classes, or the regular defaults for an absent table.
|
|
200
|
+
*/
|
|
201
|
+
function faceMetrics(font) {
|
|
202
|
+
const os2 = font["OS/2"];
|
|
203
|
+
return {
|
|
204
|
+
weight: os2 === void 0 ? 400 : os2.usWeightClass,
|
|
205
|
+
width: os2 === void 0 ? 5 : os2.usWidthClass,
|
|
206
|
+
fixed: Boolean(font.post?.isFixedPitch)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function inspect(path, maxBytes) {
|
|
210
|
+
let status;
|
|
211
|
+
let bytes;
|
|
212
|
+
try {
|
|
213
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW);
|
|
214
|
+
try {
|
|
215
|
+
status = fstatSync(fd);
|
|
216
|
+
if (!status.isFile() || status.size > maxBytes) return [];
|
|
217
|
+
bytes = Buffer.alloc(status.size);
|
|
218
|
+
let offset = 0;
|
|
219
|
+
while (offset < bytes.length) {
|
|
220
|
+
const count = readSync(fd, bytes, offset, bytes.length - offset, offset);
|
|
221
|
+
if (count === 0) throw new Error("A system font was truncated while indexing; reload the font service.");
|
|
222
|
+
offset += count;
|
|
223
|
+
}
|
|
224
|
+
const after = fstatSync(fd);
|
|
225
|
+
if (after.size !== status.size || after.mtimeMs !== status.mtimeMs || after.ctimeMs !== status.ctimeMs) throw new Error("A system font changed while indexing; reload the font service.");
|
|
226
|
+
} finally {
|
|
227
|
+
closeSync(fd);
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (absent(error)) return [];
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
let faces;
|
|
234
|
+
try {
|
|
235
|
+
const parsed = create(bytes);
|
|
236
|
+
faces = ("fonts" in parsed ? parsed.fonts : [parsed]).map((font, faceIndex) => {
|
|
237
|
+
const names = [
|
|
238
|
+
"fontFamily",
|
|
239
|
+
"preferredFamily",
|
|
240
|
+
"fullName",
|
|
241
|
+
"postscriptName"
|
|
242
|
+
].flatMap((key) => Object.values(font.name?.records[key] ?? {})).filter((name) => typeof name === "string");
|
|
243
|
+
const aliases = [...new Set([
|
|
244
|
+
...names,
|
|
245
|
+
font.familyName,
|
|
246
|
+
font.fullName,
|
|
247
|
+
font.postscriptName
|
|
248
|
+
].filter((name) => Boolean(name)).map(normalize))];
|
|
249
|
+
return {
|
|
250
|
+
path,
|
|
251
|
+
size: status.size,
|
|
252
|
+
mtimeMs: status.mtimeMs,
|
|
253
|
+
ctimeMs: status.ctimeMs,
|
|
254
|
+
dev: status.dev,
|
|
255
|
+
ino: status.ino,
|
|
256
|
+
faceIndex,
|
|
257
|
+
family: font.familyName,
|
|
258
|
+
style: font.subfamilyName,
|
|
259
|
+
aliases,
|
|
260
|
+
...faceMetrics(font),
|
|
261
|
+
italic: font.italicAngle !== 0,
|
|
262
|
+
postscriptName: font.postscriptName
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
} catch {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
return faces;
|
|
269
|
+
}
|
|
270
|
+
function regionalPriority(face, language) {
|
|
271
|
+
const locale = language.toLowerCase();
|
|
272
|
+
const preferred = locale.startsWith("ja") ? ["jp"] : locale.startsWith("ko") ? ["kr"] : locale.startsWith("zh") ? /hant|tw|hk|mo/.test(locale) ? ["tc", "hk"] : ["sc"] : [];
|
|
273
|
+
if (preferred.length === 0) return 0;
|
|
274
|
+
const region = `${face.family} ${face.postscriptName} ${basename(face.path)}`.toLowerCase().match(/(?:cjk|[\s_-])(sc|tc|jp|kr|hk)(?=[\s_.-]|$)/)?.[1];
|
|
275
|
+
return region === void 0 ? 1 : preferred.includes(region) ? 0 : 2;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Snapshot eligible local font metadata without retaining font bytes or decoding glyph coverage.
|
|
279
|
+
* @param options - Host font roots and physical file limits.
|
|
280
|
+
* @returns metadata reused for the converter lifetime; recreate it after changing installed fonts.
|
|
281
|
+
*/
|
|
282
|
+
function indexSystemFonts(options) {
|
|
283
|
+
return fontPaths(options.directories, options.maxFiles).flatMap((path) => inspect(path, options.maxFileBytes));
|
|
284
|
+
}
|
|
285
|
+
/** Conversion-local glyph coverage over the converter's first metadata snapshot. */
|
|
286
|
+
var SystemFontCatalog = class {
|
|
287
|
+
options;
|
|
288
|
+
faces;
|
|
289
|
+
/**
|
|
290
|
+
* @param options - Host metadata snapshot and fallback families.
|
|
291
|
+
*/
|
|
292
|
+
constructor(options) {
|
|
293
|
+
this.options = options;
|
|
294
|
+
this.faces = options.faces.map((face) => ({ ...face }));
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Find installed faces covering the requested family or missing characters.
|
|
298
|
+
* Exact families precede configured alternatives, symbol families for missing symbols,
|
|
299
|
+
* generic families, then other glyph-covering faces.
|
|
300
|
+
* @param request - VCL family/style attributes and Unicode scalars missing from its current font.
|
|
301
|
+
* @param signal - cancellation checked between synchronous font reads.
|
|
302
|
+
* @returns selected physical files, deduplicated across collection faces; absent glyphs remain unresolved.
|
|
303
|
+
* @throws if an indexed font changes or cannot be read during glyph matching.
|
|
304
|
+
*/
|
|
305
|
+
match(request, signal) {
|
|
306
|
+
signal.throwIfAborted();
|
|
307
|
+
const requested = request.family.split(";").map((family) => family.trim()).filter(Boolean);
|
|
308
|
+
const primary = requested[0];
|
|
309
|
+
let missingFamily;
|
|
310
|
+
if (primary !== void 0 && !GENERIC_FAMILIES.has(normalize(primary)) && !this.faces.some((face) => face.aliases.includes(normalize(primary)))) missingFamily = primary;
|
|
311
|
+
const priority = fontFamilyPriority(requested, this.options.fallbackFamilies, request.pitch, request.codePoints.some((point) => /\p{Symbol}/u.test(String.fromCodePoint(point)))).map(normalize);
|
|
312
|
+
const missing = new Set(request.codePoints);
|
|
313
|
+
const ranked = this.faces.map((face) => {
|
|
314
|
+
const rank = priority.findIndex((family) => face.aliases.includes(family));
|
|
315
|
+
const region = regionalPriority(face, request.language);
|
|
316
|
+
const style = (request.style && normalize(request.style) === normalize(face.style) ? -1 : 0) + (request.italic === 3 || request.italic !== 0 === face.italic ? 0 : 100) + (request.pitch === 0 || request.pitch === 1 === face.fixed ? 0 : 50) + Math.abs((VCL_WEIGHTS[request.weight] ?? 400) - face.weight) / 100 + (request.width === 0 ? 0 : Math.abs(request.width - face.width));
|
|
317
|
+
return {
|
|
318
|
+
face,
|
|
319
|
+
rank: rank < 0 ? priority.length : rank,
|
|
320
|
+
region,
|
|
321
|
+
style
|
|
322
|
+
};
|
|
323
|
+
}).sort((left, right) => left.rank - right.rank || left.region - right.region || left.style - right.style || left.face.path.localeCompare(right.face.path, "en") || left.face.faceIndex - right.face.faceIndex);
|
|
324
|
+
const selected = [];
|
|
325
|
+
const files = /* @__PURE__ */ new Set();
|
|
326
|
+
for (const { face } of ranked) {
|
|
327
|
+
signal.throwIfAborted();
|
|
328
|
+
const covered = covers(face, [...missing]);
|
|
329
|
+
if (missing.size > 0 && covered.length === 0) continue;
|
|
330
|
+
if (!files.has(face.path)) {
|
|
331
|
+
selected.push(face);
|
|
332
|
+
files.add(face.path);
|
|
333
|
+
}
|
|
334
|
+
for (const point of covered) missing.delete(point);
|
|
335
|
+
if (missing.size === 0) break;
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
fonts: selected,
|
|
339
|
+
...missingFamily === void 0 ? {} : { missingFamily }
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Read the unchanged indexed regular file; reject concurrent replacement or truncation.
|
|
345
|
+
* @param face - Indexed face metadata whose identity and timestamps must still match the file.
|
|
346
|
+
* @returns the complete original font bytes.
|
|
347
|
+
* @throws when the file changed, was replaced, or was truncated since indexing.
|
|
348
|
+
*/
|
|
349
|
+
function readFont(face) {
|
|
350
|
+
const fd = openSync(face.path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW);
|
|
351
|
+
try {
|
|
352
|
+
const before = fstatSync(fd);
|
|
353
|
+
if (!before.isFile() || STAT_KEYS.some((key) => before[key] !== face[key])) throw new Error("An indexed font changed; recreate the converter.");
|
|
354
|
+
const bytes = Buffer.alloc(face.size);
|
|
355
|
+
for (let offset = 0; offset < bytes.length;) {
|
|
356
|
+
const count = readSync(fd, bytes, offset, bytes.length - offset, offset);
|
|
357
|
+
if (!count) throw new Error("An indexed font was truncated.");
|
|
358
|
+
offset += count;
|
|
359
|
+
}
|
|
360
|
+
const after = fstatSync(fd);
|
|
361
|
+
if (STAT_KEYS.some((key) => after[key] !== face[key])) throw new Error("An indexed font changed while reading.");
|
|
362
|
+
return bytes;
|
|
363
|
+
} finally {
|
|
364
|
+
closeSync(fd);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region lib/types/ooxml.js
|
|
369
|
+
/** Bounded OOXML inspection and declared font diagnostics, using maintained ZIP/XML parsers. */
|
|
370
|
+
const MAIN_PARTS = {
|
|
371
|
+
docx: ["word/document.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"],
|
|
372
|
+
xlsx: ["xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"],
|
|
373
|
+
pptx: ["ppt/presentation.xml", "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"]
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* @param character - One code point as yielded by iteration over a string.
|
|
377
|
+
* @returns the Unicode scalar the character encodes; iteration never yields an empty string.
|
|
378
|
+
*/
|
|
379
|
+
function codePointOf(character) {
|
|
380
|
+
return character.codePointAt(0);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Validate ZIP size and membership before decoding selected document XML.
|
|
384
|
+
* @param bytes - Complete source document bytes.
|
|
385
|
+
* @param extension - Input extension, which selects the main document part.
|
|
386
|
+
* @param limits - Archive entry and declared uncompressed byte limits.
|
|
387
|
+
* @returns declared font families and the scalar values readable document XML declares.
|
|
388
|
+
* @throws ConversionError when the extension is unsupported or the archive violates its limits.
|
|
389
|
+
*/
|
|
390
|
+
function inspectDocument$1(bytes, extension, limits) {
|
|
391
|
+
const main = MAIN_PARTS[extension];
|
|
392
|
+
if (!main) throw new ConversionError("unsupported-format", "Input extension must be docx, xlsx, or pptx.");
|
|
393
|
+
const names = /* @__PURE__ */ new Set();
|
|
394
|
+
let total = 0;
|
|
395
|
+
let files;
|
|
396
|
+
try {
|
|
397
|
+
files = unzipSync(bytes, { filter(entry) {
|
|
398
|
+
total += entry.originalSize;
|
|
399
|
+
if (names.has(entry.name) || names.size >= limits.maxArchiveEntries || !Number.isSafeInteger(total) || total > limits.maxUncompressedBytes) throw new Error("OOXML archive exceeds its limits or repeats an entry.");
|
|
400
|
+
names.add(entry.name);
|
|
401
|
+
return entry.name === "[Content_Types].xml" || /^(word|xl|ppt)\/.*\.xml$/.test(entry.name) && !entry.name.endsWith("/fontTable.xml") && !entry.name.includes("/theme/");
|
|
402
|
+
} });
|
|
403
|
+
} catch (cause) {
|
|
404
|
+
throw new ConversionError("invalid-document", "Input is not a supported, bounded OOXML archive.", { cause });
|
|
405
|
+
}
|
|
406
|
+
const contentTypes = files["[Content_Types].xml"];
|
|
407
|
+
if (!names.has("_rels/.rels") || !names.has(main[0]) || contentTypes === void 0 || !strFromU8(contentTypes).includes(main[1])) throw new ConversionError("invalid-document", `Input does not contain a ${extension} document.`);
|
|
408
|
+
const families = /* @__PURE__ */ new Map();
|
|
409
|
+
const codePoints = /* @__PURE__ */ new Set();
|
|
410
|
+
for (const [name, data] of Object.entries(files)) {
|
|
411
|
+
if (name === "[Content_Types].xml") continue;
|
|
412
|
+
const partFamilies = [];
|
|
413
|
+
const partPoints = /* @__PURE__ */ new Set();
|
|
414
|
+
const parser = new SaxesParser({ xmlns: true });
|
|
415
|
+
parser.on("opentag", (tag) => {
|
|
416
|
+
const word = /wordprocessingml\/(?:2006\/)?main$/.test(tag.uri) && tag.local === "rFonts";
|
|
417
|
+
const drawing = /drawingml\/(?:2006\/)?main$/.test(tag.uri);
|
|
418
|
+
const sheet = /spreadsheetml\/(?:2006\/)?main$/.test(tag.uri) && tag.local === "name";
|
|
419
|
+
for (const attribute of Object.values(tag.attributes)) if (word && [
|
|
420
|
+
"ascii",
|
|
421
|
+
"hAnsi",
|
|
422
|
+
"eastAsia",
|
|
423
|
+
"cs"
|
|
424
|
+
].includes(attribute.local) || drawing && attribute.local === "typeface" || sheet && attribute.local === "val") partFamilies.push(attribute.value);
|
|
425
|
+
});
|
|
426
|
+
parser.on("text", (text) => {
|
|
427
|
+
for (const char of text) if (!/\s/u.test(char)) partPoints.add(codePointOf(char));
|
|
428
|
+
});
|
|
429
|
+
const encoding = data[0] === 255 && data[1] === 254 ? "utf-16le" : data[0] === 254 && data[1] === 255 ? "utf-16be" : "utf-8";
|
|
430
|
+
try {
|
|
431
|
+
parser.write(new TextDecoder(encoding).decode(data)).close();
|
|
432
|
+
} catch {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
for (const declared of partFamilies) for (const family of declared.split(";").map((value) => value.trim()).filter((value) => value && !/^\+(?:mj|mn)-(?:lt|ea|cs)$/.test(value))) families.set(normalize(family), family);
|
|
436
|
+
for (const point of partPoints) codePoints.add(point);
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
families,
|
|
440
|
+
codePoints: [...codePoints]
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region lib/types/document.js
|
|
445
|
+
/** Select bounded OOXML inspection or a legacy Office compound-file import. */
|
|
446
|
+
/** Input suffixes accepted by the public converter. */
|
|
447
|
+
const DOCUMENT_EXTENSIONS = [
|
|
448
|
+
"doc",
|
|
449
|
+
"docx",
|
|
450
|
+
"xls",
|
|
451
|
+
"xlsx",
|
|
452
|
+
"ppt",
|
|
453
|
+
"pptx"
|
|
454
|
+
];
|
|
455
|
+
const COMPOUND_SIGNATURE = [
|
|
456
|
+
208,
|
|
457
|
+
207,
|
|
458
|
+
17,
|
|
459
|
+
224,
|
|
460
|
+
161,
|
|
461
|
+
177,
|
|
462
|
+
26,
|
|
463
|
+
225
|
|
464
|
+
];
|
|
465
|
+
/**
|
|
466
|
+
* Inspect the input container before invoking LibreOffice's document importer.
|
|
467
|
+
* Compound-file streams and legacy font tables are interpreted by LibreOffice;
|
|
468
|
+
* they do not supply the API's OOXML font diagnostics.
|
|
469
|
+
* @param bytes - Source bytes already bounded by maxInputBytes.
|
|
470
|
+
* @param extension - Lowercase source suffix.
|
|
471
|
+
* @param limits - Limits applied to ZIP-based document contents.
|
|
472
|
+
* @returns OOXML font metadata, or empty diagnostics for a binary document.
|
|
473
|
+
*/
|
|
474
|
+
function inspectDocument(bytes, extension, limits) {
|
|
475
|
+
if (!DOCUMENT_EXTENSIONS.includes(extension)) throw new ConversionError("unsupported-format", `Input extension must be ${DOCUMENT_EXTENSIONS.join(", ")}.`);
|
|
476
|
+
if ([
|
|
477
|
+
"docx",
|
|
478
|
+
"xlsx",
|
|
479
|
+
"pptx"
|
|
480
|
+
].includes(extension)) return inspectDocument$1(bytes, extension, limits);
|
|
481
|
+
if (bytes.length < 512 || !COMPOUND_SIGNATURE.every((value, index) => bytes[index] === value)) throw new ConversionError("invalid-document", "Legacy Office input must contain an OLE compound document.");
|
|
482
|
+
const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
483
|
+
const version = header.getUint16(26, true);
|
|
484
|
+
const sectorShift = header.getUint16(30, true);
|
|
485
|
+
if (header.getUint16(28, true) !== 65534 || header.getUint16(32, true) !== 6 || !(version === 3 && sectorShift === 9 || version === 4 && sectorShift === 12) || bytes.length < 2 ** sectorShift * 2 || bytes.length % 2 ** sectorShift !== 0) throw new ConversionError("invalid-document", "Legacy Office input has an invalid or truncated compound-file header.");
|
|
486
|
+
return {
|
|
487
|
+
families: /* @__PURE__ */ new Map(),
|
|
488
|
+
codePoints: []
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region lib/types/font-loader.js
|
|
493
|
+
/** Conversion-local font imports and exact-family diagnostics. */
|
|
494
|
+
/** Build the metadata catalog inside a cancellable conversion worker. */
|
|
495
|
+
function createFontLoader(options, document, install, faces) {
|
|
496
|
+
const catalog = new SystemFontCatalog({
|
|
497
|
+
faces,
|
|
498
|
+
fallbackFamilies: options.fontFallbacks
|
|
499
|
+
});
|
|
500
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
501
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
502
|
+
const missing = /* @__PURE__ */ new Map();
|
|
503
|
+
const substitutions = /* @__PURE__ */ new Map();
|
|
504
|
+
const signal = new AbortController().signal;
|
|
505
|
+
let bytes = 0;
|
|
506
|
+
return {
|
|
507
|
+
get missingFonts() {
|
|
508
|
+
return [...missing.values()];
|
|
509
|
+
},
|
|
510
|
+
get substitutions() {
|
|
511
|
+
return [...substitutions.values()];
|
|
512
|
+
},
|
|
513
|
+
get files() {
|
|
514
|
+
return [...loaded.values()];
|
|
515
|
+
},
|
|
516
|
+
resolve(request) {
|
|
517
|
+
const key = JSON.stringify(request);
|
|
518
|
+
const cached = resolved.get(key);
|
|
519
|
+
if (cached) return cached;
|
|
520
|
+
const match = catalog.match(request, signal);
|
|
521
|
+
if (match.missingFamily && document.families.has(normalize(match.missingFamily))) {
|
|
522
|
+
const family = normalize(match.missingFamily);
|
|
523
|
+
missing.set(family, match.missingFamily);
|
|
524
|
+
if (match.fonts[0]) substitutions.set(family, {
|
|
525
|
+
family: match.missingFamily,
|
|
526
|
+
substitute: match.fonts[0].family
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
const paths = match.fonts.map((face) => {
|
|
530
|
+
const installed = loaded.get(face.path);
|
|
531
|
+
if (installed !== void 0) return installed;
|
|
532
|
+
if (bytes + face.size > options.maxLoadedFontBytes) throw new Error("Imported fonts exceed maxLoadedFontBytes.");
|
|
533
|
+
const path = install(`${loaded.size}${extname(face.path)}`, readFont(face));
|
|
534
|
+
bytes += face.size;
|
|
535
|
+
loaded.set(face.path, path);
|
|
536
|
+
return path;
|
|
537
|
+
});
|
|
538
|
+
resolved.set(key, paths);
|
|
539
|
+
return paths;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/** Supply native imports and seed WASM's first usable default font. */
|
|
544
|
+
function preloadFonts(loader, options, document, native = false) {
|
|
545
|
+
const families = [
|
|
546
|
+
...options.initialFontFamilies,
|
|
547
|
+
...native ? [...document.families.values()] : [],
|
|
548
|
+
"sans-serif"
|
|
549
|
+
];
|
|
550
|
+
for (const family of families) loader.resolve({
|
|
551
|
+
family,
|
|
552
|
+
style: "",
|
|
553
|
+
weight: 5,
|
|
554
|
+
italic: 0,
|
|
555
|
+
width: 5,
|
|
556
|
+
pitch: 0,
|
|
557
|
+
language: "",
|
|
558
|
+
codePoints: native ? document.codePoints : []
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Fontconfig XML restricts WASM discovery to imported originals in MEMFS.
|
|
563
|
+
* @param families - Ordered family groups; the first name of each group is its canonical spelling.
|
|
564
|
+
* @param requested - Additional family names the document declared.
|
|
565
|
+
* @returns the fontconfig document written into the module's memory filesystem.
|
|
566
|
+
*/
|
|
567
|
+
function memoryFontConfig(families, requested = []) {
|
|
568
|
+
const escape = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
569
|
+
return `<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"><fontconfig><dir>/dsh-fonts</dir><cachedir>/dsh/font-cache</cachedir>${[...new Map([...families.flatMap((group) => group.slice(0, 1)), ...requested].map((name) => [normalize(name), name])).values()].map((name) => {
|
|
570
|
+
const alternatives = fontFamilyPriority([name], families).filter((family) => normalize(family) !== normalize(name));
|
|
571
|
+
return `<alias><family>${escape(name)}</family><accept>${alternatives.map((family) => `<family>${escape(family)}</family>`).join("")}</accept></alias>`;
|
|
572
|
+
}).join("")}</fontconfig>`;
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region lib/types/wasm.js
|
|
576
|
+
/** Node-only LibreOffice module execution; the owner terminates this worker on cancellation. */
|
|
577
|
+
const require = createRequire(import.meta.url);
|
|
578
|
+
function engineError(module, office) {
|
|
579
|
+
const pointer = module.ccall("dsh_lok_error", "number", ["number"], [office]);
|
|
580
|
+
if (!pointer) return /* @__PURE__ */ new Error("LibreOffice WASM could not convert the document.");
|
|
581
|
+
try {
|
|
582
|
+
return new Error(module.UTF8ToString(pointer));
|
|
583
|
+
} finally {
|
|
584
|
+
module.ccall("free", null, ["number"], [pointer]);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* @param loader - Loader the module's pre-run hook installs.
|
|
589
|
+
* @returns the initialized font loader.
|
|
590
|
+
* @throws when the module resolved without running its pre-run hook.
|
|
591
|
+
*/
|
|
592
|
+
function requiredFontLoader(loader) {
|
|
593
|
+
if (loader === void 0) throw new Error("LibreOffice initialized without its font loader.");
|
|
594
|
+
return loader;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Convert bounded source bytes; return owned PDF bytes only after engine teardown.
|
|
598
|
+
* @param request - Engine installation, source bytes, limits, and font metadata.
|
|
599
|
+
* @returns the generated PDF bytes and the declared families the catalog could not provide.
|
|
600
|
+
*/
|
|
601
|
+
async function convertWithWasm(request) {
|
|
602
|
+
const { engine, bytes, extension, options, document: metadata, faces } = request;
|
|
603
|
+
const factory = require(engine.loader);
|
|
604
|
+
const raw = readFileSync(engine.data);
|
|
605
|
+
const data = raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength);
|
|
606
|
+
let module;
|
|
607
|
+
let office = 0;
|
|
608
|
+
let document = 0;
|
|
609
|
+
let fontLoader;
|
|
610
|
+
let fatal = false;
|
|
611
|
+
let failure;
|
|
612
|
+
try {
|
|
613
|
+
module = await factory({
|
|
614
|
+
noInitialRun: true,
|
|
615
|
+
mainScriptUrlOrBlob: engine.loader,
|
|
616
|
+
locateFile(name) {
|
|
617
|
+
const file = basename(name);
|
|
618
|
+
if (![
|
|
619
|
+
engine.loader,
|
|
620
|
+
engine.data,
|
|
621
|
+
engine.wasm,
|
|
622
|
+
engine.metadata
|
|
623
|
+
].some((path) => basename(path) === file)) throw new Error(`LibreOffice requested an unlisted asset: ${file}`);
|
|
624
|
+
return join(dirname(engine.loader), file);
|
|
625
|
+
},
|
|
626
|
+
getPreloadedPackage: () => data,
|
|
627
|
+
dshResolveSystemFonts(request) {
|
|
628
|
+
if (!fontLoader) throw new Error("LibreOffice requested fonts before initializing MEMFS.");
|
|
629
|
+
return fontLoader.resolve(request);
|
|
630
|
+
},
|
|
631
|
+
preRun: [(loadedModule) => {
|
|
632
|
+
for (const path of [
|
|
633
|
+
"/dsh/profile",
|
|
634
|
+
"/dsh/font-cache",
|
|
635
|
+
"/dsh-fonts"
|
|
636
|
+
]) loadedModule.FS.mkdirTree(path);
|
|
637
|
+
loadedModule.FS.writeFile("/dsh/fonts.conf", new TextEncoder().encode(memoryFontConfig(options.fontFallbacks, metadata.families.values())));
|
|
638
|
+
Object.assign(loadedModule.ENV, {
|
|
639
|
+
HOME: "/dsh/profile",
|
|
640
|
+
TMPDIR: "/tmp",
|
|
641
|
+
FONTCONFIG_FILE: "/dsh/fonts.conf",
|
|
642
|
+
LOK_HOST_ALLOWLIST: "^$"
|
|
643
|
+
});
|
|
644
|
+
fontLoader = createFontLoader(options, metadata, (name, bytes) => {
|
|
645
|
+
const path = `/dsh-fonts/${name}`;
|
|
646
|
+
loadedModule.FS.writeFile(path, bytes);
|
|
647
|
+
return path;
|
|
648
|
+
}, faces);
|
|
649
|
+
preloadFonts(fontLoader, options, metadata);
|
|
650
|
+
}],
|
|
651
|
+
onAbort() {
|
|
652
|
+
fatal = true;
|
|
653
|
+
},
|
|
654
|
+
print() {},
|
|
655
|
+
printErr() {}
|
|
656
|
+
});
|
|
657
|
+
const instance = module;
|
|
658
|
+
const input = `/dsh/document.${extension}`;
|
|
659
|
+
const output = "/dsh/document.pdf";
|
|
660
|
+
instance.FS.writeFile(input, bytes);
|
|
661
|
+
office = instance.ccall("dsh_lok_initialize", "number", ["string", "string"], [engine.programDirectory, "file:///dsh/profile"]);
|
|
662
|
+
if (!office) throw engineError(instance, 0);
|
|
663
|
+
document = instance.ccall("dsh_lok_document_load", "number", [
|
|
664
|
+
"number",
|
|
665
|
+
"string",
|
|
666
|
+
"string"
|
|
667
|
+
], [
|
|
668
|
+
office,
|
|
669
|
+
`file://${input}`,
|
|
670
|
+
"Batch=true,EnableMacrosExecution=false"
|
|
671
|
+
]);
|
|
672
|
+
if (!document) throw engineError(instance, office);
|
|
673
|
+
if (!instance.ccall("dsh_lok_document_save_pdf", "number", [
|
|
674
|
+
"number",
|
|
675
|
+
"string",
|
|
676
|
+
"string"
|
|
677
|
+
], [
|
|
678
|
+
document,
|
|
679
|
+
`file://${output}`,
|
|
680
|
+
JSON.stringify({
|
|
681
|
+
ExportBookmarks: {
|
|
682
|
+
type: "boolean",
|
|
683
|
+
value: "true"
|
|
684
|
+
},
|
|
685
|
+
ReduceImageResolution: {
|
|
686
|
+
type: "boolean",
|
|
687
|
+
value: "true"
|
|
688
|
+
},
|
|
689
|
+
MaxImageResolution: {
|
|
690
|
+
type: "long",
|
|
691
|
+
value: String(options.maxImageResolution)
|
|
692
|
+
}
|
|
693
|
+
})
|
|
694
|
+
])) throw engineError(instance, office);
|
|
695
|
+
if (!instance.FS.analyzePath(output).exists) throw new ConversionError("invalid-output", "LibreOffice did not create its PDF output.");
|
|
696
|
+
const status = instance.FS.stat(output);
|
|
697
|
+
if (!instance.FS.isFile(status.mode)) throw new ConversionError("invalid-output", "Generated PDF is not a regular file.");
|
|
698
|
+
if (status.size > options.maxOutputBytes) throw new ConversionError("output-too-large", "Generated PDF exceeds its output byte limit.");
|
|
699
|
+
const pdf = instance.FS.readFile(output);
|
|
700
|
+
if (new TextDecoder().decode(pdf.subarray(0, 5)) !== "%PDF-") throw new ConversionError("invalid-output", "LibreOffice did not produce a PDF.");
|
|
701
|
+
return {
|
|
702
|
+
pdf,
|
|
703
|
+
missingFonts: requiredFontLoader(fontLoader).missingFonts
|
|
704
|
+
};
|
|
705
|
+
} catch (error) {
|
|
706
|
+
fatal ||= error instanceof WebAssembly.RuntimeError;
|
|
707
|
+
failure = error;
|
|
708
|
+
throw error;
|
|
709
|
+
} finally {
|
|
710
|
+
const errors = [];
|
|
711
|
+
if (module && !fatal) {
|
|
712
|
+
if (document) try {
|
|
713
|
+
if (!module.ccall("dsh_lok_document_destroy", "number", ["number"], [document])) throw engineError(module, office);
|
|
714
|
+
} catch (error) {
|
|
715
|
+
errors.push(error);
|
|
716
|
+
fatal ||= error instanceof WebAssembly.RuntimeError;
|
|
717
|
+
}
|
|
718
|
+
if (office && !fatal) try {
|
|
719
|
+
if (!module.ccall("dsh_lok_destroy", "number", ["number"], [office])) throw engineError(module, 0);
|
|
720
|
+
} catch (error) {
|
|
721
|
+
errors.push(error);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (module) try {
|
|
725
|
+
module.PThread.terminateAllThreads();
|
|
726
|
+
} catch (error) {
|
|
727
|
+
errors.push(error);
|
|
728
|
+
}
|
|
729
|
+
if (errors.length) throw new AggregateError(failure ? [failure, ...errors] : errors, "LibreOffice WASM cleanup failed.");
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
//#endregion
|
|
733
|
+
//#region lib/types/worker.js
|
|
734
|
+
/** Cancellable CPU work and WASM conversion run outside the Node event loop. */
|
|
735
|
+
/**
|
|
736
|
+
* @param port - The parent port, present inside a Worker thread.
|
|
737
|
+
* @returns the connected parent port.
|
|
738
|
+
* @throws when this entry is loaded outside a Worker.
|
|
739
|
+
*/
|
|
740
|
+
function requireParentPort(port) {
|
|
741
|
+
if (port === null) throw new Error("The LibreOffice conversion worker requires a parent port.");
|
|
742
|
+
return port;
|
|
743
|
+
}
|
|
744
|
+
const port = requireParentPort(parentPort);
|
|
745
|
+
try {
|
|
746
|
+
const { inputPath, extension, options, engine, scratch, fontFaces } = workerData;
|
|
747
|
+
const bytes = readFileSync(inputPath);
|
|
748
|
+
const document = inspectDocument(bytes, extension, options);
|
|
749
|
+
const faces = fontFaces ?? indexSystemFonts({
|
|
750
|
+
directories: options.fontDirectories,
|
|
751
|
+
maxFiles: options.maxFontFiles,
|
|
752
|
+
maxFileBytes: options.maxFontFileBytes
|
|
753
|
+
});
|
|
754
|
+
if (!fontFaces) port.postMessage({
|
|
755
|
+
kind: "fonts",
|
|
756
|
+
faces
|
|
757
|
+
});
|
|
758
|
+
if (engine.backend === "wasm") {
|
|
759
|
+
if (faces.length === 0) throw new ConversionError("unavailable", "No usable fonts were found. Install fonts or configure fontDirectories before converting documents.");
|
|
760
|
+
const result = await convertWithWasm({
|
|
761
|
+
engine,
|
|
762
|
+
bytes,
|
|
763
|
+
extension,
|
|
764
|
+
options,
|
|
765
|
+
document,
|
|
766
|
+
faces
|
|
767
|
+
});
|
|
768
|
+
port.postMessage({
|
|
769
|
+
ok: true,
|
|
770
|
+
...result
|
|
771
|
+
}, [result.pdf.buffer]);
|
|
772
|
+
} else {
|
|
773
|
+
const directory = join(scratch, "fonts");
|
|
774
|
+
mkdirSync(directory, { mode: 448 });
|
|
775
|
+
const fonts = createFontLoader(options, document, (name, data) => {
|
|
776
|
+
const path = join(directory, name);
|
|
777
|
+
writeFileSync(path, data, {
|
|
778
|
+
flag: "wx",
|
|
779
|
+
mode: 384
|
|
780
|
+
});
|
|
781
|
+
return path;
|
|
782
|
+
}, faces);
|
|
783
|
+
preloadFonts(fonts, options, document, true);
|
|
784
|
+
port.postMessage({
|
|
785
|
+
ok: true,
|
|
786
|
+
fonts: fonts.files,
|
|
787
|
+
substitutions: fonts.substitutions,
|
|
788
|
+
missingFonts: fonts.missingFonts
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
} catch (error) {
|
|
792
|
+
port.postMessage({
|
|
793
|
+
ok: false,
|
|
794
|
+
code: failureCode(error),
|
|
795
|
+
error: error instanceof Error ? error.message : String(error),
|
|
796
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
export {};
|