@songtonyli/dsh-cli 0.1.57 → 0.1.59
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 +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +1 -0
- package/node_modules/@deepseek-ai/dsh-api-session-controller/lib/client.js +1 -0
- package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +59 -4
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +73 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +166 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +166 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +227 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +704 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/package.json +62 -0
- package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-sandbox-policy/lib/index.js +23 -0
- package/node_modules/@deepseek-ai/dsh-session/lib/index.js +1 -0
- package/node_modules/@deepseek-ai/dsh-session/lib/types/known-event-types.js +1 -0
- package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/worker.cjs +1 -0
- package/node_modules/@deepseek-ai/dsh-system-prompt/lib/index.js +1 -0
- package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +22 -0
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +24 -0
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.i18n.yaml +4 -4
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.md +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.zh.md +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/lib/index.js +28 -3
- package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +7 -2
- package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/lib/index.js +14 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +6 -5
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +6 -5
- package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +20 -0
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +42 -31
- package/node_modules/@deepseek-ai/dsh-tui-app/package.json +1 -0
- package/node_modules/@deepseek-ai/libreoffice-kit/README.md +20 -5
- package/node_modules/@deepseek-ai/libreoffice-kit/README.zh.md +21 -6
- package/node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js +499 -253
- package/node_modules/@deepseek-ai/libreoffice-kit/lib/font-snapshot-worker.js +37 -26
- package/node_modules/@deepseek-ai/libreoffice-kit/lib/index.js +498 -252
- package/node_modules/@deepseek-ai/libreoffice-kit/lib/worker.js +39 -13
- package/node_modules/@deepseek-ai/libreoffice-kit/package.json +5 -3
- package/node_modules/@earendil-works/pi-ai/README.md +4 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +117 -18
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +19 -8
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +24 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +3 -2
- package/node_modules/@earendil-works/pi-ai/package.json +6 -2
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@shikijs/core/dist/index.mjs +15 -12
- package/node_modules/@shikijs/core/package.json +4 -4
- package/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs +2 -4
- package/node_modules/@shikijs/engine-javascript/dist/engine-raw.mjs +2 -4
- package/node_modules/@shikijs/engine-javascript/dist/index.mjs +1 -1
- package/node_modules/@shikijs/engine-javascript/dist/string-TLTPtCPs.mjs +115 -0
- package/node_modules/@shikijs/engine-javascript/package.json +3 -3
- package/node_modules/@shikijs/engine-oniguruma/package.json +3 -3
- package/node_modules/@shikijs/langs/dist/ada.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/ahk.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/beancount.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/coq.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/csharp.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/css.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/dart.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/dotenv.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/emacs-lisp.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/gn.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/handlebars.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/julia.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/latex.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/luau.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/marko.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/moonbit.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/nextflow-groovy.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/nextflow.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/nushell.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/php.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/powershell.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/ruby.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/rust.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/sql.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/svelte.mjs +1 -1
- package/node_modules/@shikijs/langs/dist/twig.mjs +3 -3
- package/node_modules/@shikijs/langs/dist/typespec.mjs +1 -1
- package/node_modules/@shikijs/langs/package.json +3 -3
- package/node_modules/@shikijs/primitive/dist/index.mjs +2 -1
- package/node_modules/@shikijs/primitive/package.json +3 -3
- package/node_modules/@shikijs/themes/dist/monokai.mjs +1 -1
- package/node_modules/@shikijs/themes/dist/one-dark-pro.mjs +1 -1
- package/node_modules/@shikijs/themes/dist/red.mjs +1 -1
- package/node_modules/@shikijs/themes/dist/solarized-dark.mjs +1 -1
- package/node_modules/@shikijs/themes/dist/solarized-light.mjs +1 -1
- package/node_modules/@shikijs/themes/package.json +3 -3
- package/node_modules/@shikijs/types/package.json +1 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +33 -11
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/exceptions.js +33 -11
- package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +3 -0
- package/node_modules/@smithy/core/package.json +1 -1
- package/node_modules/node-addon-native-custom-loader/lib/index.js +23 -10
- package/node_modules/node-addon-native-custom-loader/package.json +6 -1
- package/node_modules/node-addon-require-builtin/package.json +7 -2
- package/node_modules/powershell-utils/index.js +40 -19
- package/node_modules/powershell-utils/package.json +1 -1
- package/node_modules/powershell-utils/readme.md +69 -13
- package/node_modules/shiki/package.json +10 -10
- package/node_modules/wsl-utils/index.js +18 -37
- package/node_modules/wsl-utils/package.json +2 -2
- package/package.json +33 -29
- package/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs +0 -77
- package/node_modules/open/node_modules/powershell-utils/index.js +0 -79
- package/node_modules/open/node_modules/powershell-utils/license +0 -9
- package/node_modules/open/node_modules/powershell-utils/package.json +0 -47
- package/node_modules/open/node_modules/powershell-utils/readme.md +0 -209
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { constants, lstatSync, readdirSync } from "node:fs";
|
|
3
|
-
import { lstat, mkdir, mkdtemp, open, readFile, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync } from "node:fs";
|
|
3
|
+
import { copyFile, lstat, mkdir, mkdtemp, open, readFile, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
6
6
|
import { Worker } from "node:worker_threads";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
+
import { EventEmitter } from "node:events";
|
|
9
|
+
import { Readable } from "node:stream";
|
|
10
|
+
import { finished } from "node:stream/promises";
|
|
8
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
12
|
import { createInterface } from "node:readline";
|
|
10
13
|
import { zlibSync } from "fflate";
|
|
@@ -135,7 +138,7 @@ function dimension(data, first, last, maximum, scale) {
|
|
|
135
138
|
}
|
|
136
139
|
return [start / scale, (position - start) / scale];
|
|
137
140
|
}
|
|
138
|
-
/** Logical columns advance from A;
|
|
141
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
139
142
|
function sheetRangeRectangle(geometry, range, scale) {
|
|
140
143
|
if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
|
|
141
144
|
const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
|
|
@@ -156,6 +159,17 @@ function sheetRangeRectangle(geometry, range, scale) {
|
|
|
156
159
|
height
|
|
157
160
|
};
|
|
158
161
|
}
|
|
162
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
163
|
+
function unmirrorRtlTile({ width, height, rgba }) {
|
|
164
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < Math.floor(width / 2); x++) {
|
|
165
|
+
const left = (y * width + x) * 4, right = (y * width + width - 1 - x) * 4;
|
|
166
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
167
|
+
const value = rgba[left + channel];
|
|
168
|
+
rgba[left + channel] = rgba[right + channel];
|
|
169
|
+
rgba[right + channel] = value;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
159
173
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
160
174
|
function splitRasterRectangle(rectangle, scale, limits) {
|
|
161
175
|
const { x, y, width, height } = rectangle;
|
|
@@ -315,6 +329,184 @@ function selectedPages(pages, count, limit) {
|
|
|
315
329
|
return result;
|
|
316
330
|
}
|
|
317
331
|
//#endregion
|
|
332
|
+
//#region lib/types/native-process.js
|
|
333
|
+
/** Native helper stdio; Windows pipe handles permit read/write access under restricted tokens. */
|
|
334
|
+
let pipeAttributes;
|
|
335
|
+
function windowsPipes() {
|
|
336
|
+
const koffi = createRequire(import.meta.url)("koffi");
|
|
337
|
+
const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
|
|
338
|
+
const attributes = pipeAttributes ??= koffi.struct("KIT_SECURITY_ATTRIBUTES", {
|
|
339
|
+
nLength: "uint32",
|
|
340
|
+
lpSecurityDescriptor: "void *",
|
|
341
|
+
bInheritHandle: "int"
|
|
342
|
+
});
|
|
343
|
+
const createPipe = kernel.func("int __stdcall CreatePipe(_Out_ void **read, _Out_ void **write, KIT_SECURITY_ATTRIBUTES *attributes, uint32 size)");
|
|
344
|
+
const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
345
|
+
const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
|
|
346
|
+
const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
|
|
347
|
+
const lastError = kernel.func("uint32 __stdcall GetLastError()");
|
|
348
|
+
const convertSecurityDescriptor = advapi.func("int __stdcall ConvertStringSecurityDescriptorToSecurityDescriptorW(void *sddl, uint32 revision, _Out_ void **descriptor, void *size)");
|
|
349
|
+
const openFd = node.func("int uv_open_osfhandle(void *handle)");
|
|
350
|
+
function pipe() {
|
|
351
|
+
const reads = [null], writes = [null];
|
|
352
|
+
const descriptor = [null];
|
|
353
|
+
if (!convertSecurityDescriptor(Buffer.from("D:(A;;GRGW;;;WD)\0", "utf16le"), 1, descriptor, null)) throw new Error(`Pipe security descriptor failed: ${lastError()}`);
|
|
354
|
+
try {
|
|
355
|
+
if (!createPipe(reads, writes, {
|
|
356
|
+
nLength: attributes.size,
|
|
357
|
+
lpSecurityDescriptor: descriptor[0],
|
|
358
|
+
bInheritHandle: 0
|
|
359
|
+
}, 0)) throw new Error(`CreatePipe failed: ${lastError()}`);
|
|
360
|
+
} finally {
|
|
361
|
+
localFree(descriptor[0]);
|
|
362
|
+
}
|
|
363
|
+
const read = openFd(reads[0]);
|
|
364
|
+
if (read < 0) {
|
|
365
|
+
closeHandle(reads[0]);
|
|
366
|
+
closeHandle(writes[0]);
|
|
367
|
+
throw new Error("Cannot open anonymous input descriptor");
|
|
368
|
+
}
|
|
369
|
+
const write = openFd(writes[0]);
|
|
370
|
+
if (write < 0) {
|
|
371
|
+
closeSync(read);
|
|
372
|
+
closeHandle(writes[0]);
|
|
373
|
+
throw new Error("Cannot open anonymous output descriptor");
|
|
374
|
+
}
|
|
375
|
+
let timer;
|
|
376
|
+
let ended = false;
|
|
377
|
+
const readable = new Readable({
|
|
378
|
+
read() {
|
|
379
|
+
if (timer === void 0 && !ended) poll();
|
|
380
|
+
},
|
|
381
|
+
destroy(error, callback) {
|
|
382
|
+
ended = true;
|
|
383
|
+
clearTimeout(timer);
|
|
384
|
+
try {
|
|
385
|
+
closeSync(read);
|
|
386
|
+
callback(error);
|
|
387
|
+
} catch (cause) {
|
|
388
|
+
callback(error ?? cause);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
function poll() {
|
|
393
|
+
timer = void 0;
|
|
394
|
+
try {
|
|
395
|
+
const available = [0];
|
|
396
|
+
if (!peek(reads[0], null, 0, null, available, null)) {
|
|
397
|
+
const code = lastError();
|
|
398
|
+
if (code !== 109) throw new Error(`PeekNamedPipe failed: ${code}`);
|
|
399
|
+
ended = true;
|
|
400
|
+
readable.push(null);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (available[0] > 0) {
|
|
404
|
+
const buffer = Buffer.allocUnsafe(Math.min(available[0], 65536));
|
|
405
|
+
const count = readSync(read, buffer, 0, buffer.length, null);
|
|
406
|
+
if (!readable.push(buffer.subarray(0, count))) return;
|
|
407
|
+
}
|
|
408
|
+
timer = setTimeout(poll, 5);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
readable.destroy(error);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
read,
|
|
415
|
+
write,
|
|
416
|
+
readable
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return { pipe };
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Spawn with inherited token and Job restrictions; pipe creation never requests a new sandbox policy.
|
|
423
|
+
* @param executable - Verified native helper executable.
|
|
424
|
+
* @param args - Helper protocol arguments.
|
|
425
|
+
* @param env - Filtered operation environment.
|
|
426
|
+
* @returns Helper streams and process lifetime, with output drained before close.
|
|
427
|
+
*/
|
|
428
|
+
function spawnNative(executable, args, env) {
|
|
429
|
+
if (process.platform !== "win32") return spawn(executable, args, {
|
|
430
|
+
stdio: "pipe",
|
|
431
|
+
windowsHide: true,
|
|
432
|
+
env
|
|
433
|
+
});
|
|
434
|
+
const { pipe } = windowsPipes();
|
|
435
|
+
const owned = [];
|
|
436
|
+
let child;
|
|
437
|
+
try {
|
|
438
|
+
const input = pipe();
|
|
439
|
+
owned.push(input);
|
|
440
|
+
const output = pipe();
|
|
441
|
+
owned.push(output);
|
|
442
|
+
const error = pipe();
|
|
443
|
+
owned.push(error);
|
|
444
|
+
child = spawn(executable, args, {
|
|
445
|
+
stdio: [
|
|
446
|
+
input.read,
|
|
447
|
+
output.write,
|
|
448
|
+
error.write
|
|
449
|
+
],
|
|
450
|
+
windowsHide: true,
|
|
451
|
+
env
|
|
452
|
+
});
|
|
453
|
+
} catch (error) {
|
|
454
|
+
for (const entry of owned) {
|
|
455
|
+
entry.readable.destroy();
|
|
456
|
+
closeSync(entry.write);
|
|
457
|
+
}
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
const [input, output, error] = owned;
|
|
461
|
+
input.readable.destroy();
|
|
462
|
+
closeSync(output.write);
|
|
463
|
+
closeSync(error.write);
|
|
464
|
+
const stdin = createWriteStream("", {
|
|
465
|
+
fd: input.write,
|
|
466
|
+
autoClose: true
|
|
467
|
+
});
|
|
468
|
+
const helper = new class extends EventEmitter {
|
|
469
|
+
stdin = stdin;
|
|
470
|
+
stdout = output.readable;
|
|
471
|
+
stderr = error.readable;
|
|
472
|
+
get exitCode() {
|
|
473
|
+
return child.exitCode;
|
|
474
|
+
}
|
|
475
|
+
get signalCode() {
|
|
476
|
+
return child.signalCode;
|
|
477
|
+
}
|
|
478
|
+
kill(signal) {
|
|
479
|
+
return child.kill(signal);
|
|
480
|
+
}
|
|
481
|
+
}();
|
|
482
|
+
let failure;
|
|
483
|
+
const fail = (cause) => {
|
|
484
|
+
failure ??= cause;
|
|
485
|
+
child.kill("SIGKILL");
|
|
486
|
+
};
|
|
487
|
+
stdin.on("error", fail);
|
|
488
|
+
output.readable.on("error", fail);
|
|
489
|
+
error.readable.on("error", fail);
|
|
490
|
+
const drained = Promise.allSettled([
|
|
491
|
+
finished(stdin),
|
|
492
|
+
finished(output.readable),
|
|
493
|
+
finished(error.readable)
|
|
494
|
+
]);
|
|
495
|
+
child.once("error", (cause) => {
|
|
496
|
+
failure ??= cause;
|
|
497
|
+
});
|
|
498
|
+
child.once("close", (code, signal) => {
|
|
499
|
+
stdin.destroy();
|
|
500
|
+
output.readable.resume();
|
|
501
|
+
error.readable.resume();
|
|
502
|
+
drained.then(() => {
|
|
503
|
+
if (failure !== void 0) helper.emit("error", failure);
|
|
504
|
+
helper.emit("close", code, signal);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
return helper;
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
318
510
|
//#region lib/types/profile.js
|
|
319
511
|
/** Private headless profile used by both native and WASM conversions. */
|
|
320
512
|
/**
|
|
@@ -536,6 +728,7 @@ async function prepareNativeFontProfile(profile, substitutions) {
|
|
|
536
728
|
});
|
|
537
729
|
}
|
|
538
730
|
/**
|
|
731
|
+
* Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
|
|
539
732
|
* Linux searches the verified program directory; ambient loader overrides and credentials are excluded.
|
|
540
733
|
* @param profile - Conversion-owned profile directory the helper treats as home.
|
|
541
734
|
* @param programDirectory - Verified engine program directory.
|
|
@@ -555,10 +748,36 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
|
|
|
555
748
|
USERPROFILE: profile,
|
|
556
749
|
TMPDIR: profile,
|
|
557
750
|
TMP: profile,
|
|
558
|
-
TEMP: profile
|
|
751
|
+
TEMP: profile,
|
|
752
|
+
SAL_DISABLE_PRINTERLIST: "1",
|
|
753
|
+
SAL_DISABLE_DEFAULTPRINTER: "1"
|
|
559
754
|
});
|
|
560
755
|
}
|
|
561
756
|
/**
|
|
757
|
+
* Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
|
|
758
|
+
* @param engine - Verified engine installation; its resources remain in place.
|
|
759
|
+
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
760
|
+
* @param run - Operation that settles only after its helper closes.
|
|
761
|
+
* @returns The operation result after removing the resource junction.
|
|
762
|
+
*/
|
|
763
|
+
async function withNativeEngine(engine, profile, run) {
|
|
764
|
+
if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return run(engine);
|
|
765
|
+
const root = join(profile, "engine");
|
|
766
|
+
await symlink(engine.root, root, "junction");
|
|
767
|
+
try {
|
|
768
|
+
const executable = join(profile, "libreoffice-kit.exe");
|
|
769
|
+
await copyFile(engine.executable, executable, constants.COPYFILE_EXCL);
|
|
770
|
+
return await run({
|
|
771
|
+
...engine,
|
|
772
|
+
root,
|
|
773
|
+
executable,
|
|
774
|
+
programDirectory: join(root, relative(engine.root, engine.programDirectory))
|
|
775
|
+
});
|
|
776
|
+
} finally {
|
|
777
|
+
await unlink(root);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
562
781
|
* Run one native conversion and await bounded result transport.
|
|
563
782
|
* @param engine - Resolved native engine installation.
|
|
564
783
|
* @param options - Validated conversion limits.
|
|
@@ -578,77 +797,73 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
578
797
|
signal.throwIfAborted();
|
|
579
798
|
await prepareNativeFontProfile(profile, substitutions);
|
|
580
799
|
signal.throwIfAborted();
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
engine.
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
let stdout = "";
|
|
611
|
-
let stderr = "";
|
|
612
|
-
let failure;
|
|
613
|
-
const abort = () => {
|
|
614
|
-
failure ??= signal.reason;
|
|
615
|
-
child.kill("SIGKILL");
|
|
616
|
-
};
|
|
617
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
618
|
-
child.stdout.setEncoding("utf8");
|
|
619
|
-
child.stderr.setEncoding("utf8");
|
|
620
|
-
child.stdout.on("data", (chunk) => {
|
|
621
|
-
stdout += chunk;
|
|
622
|
-
if (stdout.length > 65536) {
|
|
623
|
-
failure ??= /* @__PURE__ */ new Error("LibreOffice helper exceeded its response limit.");
|
|
800
|
+
return withNativeEngine(engine, profile, async (engine) => {
|
|
801
|
+
signal.throwIfAborted();
|
|
802
|
+
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
803
|
+
const child = spawnNative(engine.executable, [
|
|
804
|
+
"--program-directory",
|
|
805
|
+
engine.programDirectory,
|
|
806
|
+
"--input-path",
|
|
807
|
+
input,
|
|
808
|
+
"--output-path",
|
|
809
|
+
output,
|
|
810
|
+
"--profile-directory",
|
|
811
|
+
profile,
|
|
812
|
+
"--max-output-bytes",
|
|
813
|
+
String(options.maxOutputBytes),
|
|
814
|
+
"--max-image-resolution",
|
|
815
|
+
String(options.maxImageResolution),
|
|
816
|
+
"--format",
|
|
817
|
+
operation.format,
|
|
818
|
+
"--recalculate",
|
|
819
|
+
String(operation.recalculate),
|
|
820
|
+
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
821
|
+
...fonts.flatMap((path) => ["--font-file", path])
|
|
822
|
+
], env);
|
|
823
|
+
child.stdin.end();
|
|
824
|
+
let stdout = "";
|
|
825
|
+
let stderr = "";
|
|
826
|
+
let failure;
|
|
827
|
+
const abort = () => {
|
|
828
|
+
failure ??= signal.reason;
|
|
624
829
|
child.kill("SIGKILL");
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
stderr
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
else resolve(code);
|
|
639
|
-
});
|
|
830
|
+
};
|
|
831
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
832
|
+
child.stdout.setEncoding("utf8");
|
|
833
|
+
child.stderr.setEncoding("utf8");
|
|
834
|
+
child.stdout.on("data", (chunk) => {
|
|
835
|
+
stdout += chunk;
|
|
836
|
+
if (stdout.length > 65536) {
|
|
837
|
+
failure ??= /* @__PURE__ */ new Error("LibreOffice helper exceeded its response limit.");
|
|
838
|
+
child.kill("SIGKILL");
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
child.stderr.on("data", (chunk) => {
|
|
842
|
+
stderr = (stderr + chunk).slice(-65536);
|
|
640
843
|
});
|
|
641
|
-
signal.throwIfAborted();
|
|
642
|
-
let result;
|
|
643
844
|
try {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
845
|
+
const code = await new Promise((resolve, reject) => {
|
|
846
|
+
child.once("error", (error) => {
|
|
847
|
+
failure ??= error;
|
|
848
|
+
});
|
|
849
|
+
child.once("close", (code, signal) => {
|
|
850
|
+
if (signal === "SIGXFSZ") failure ??= new ConversionError("output-too-large", "LibreOffice exceeded its output file-size limit.");
|
|
851
|
+
if (failure) reject(failure);
|
|
852
|
+
else resolve(code);
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
signal.throwIfAborted();
|
|
856
|
+
let result;
|
|
857
|
+
try {
|
|
858
|
+
result = JSON.parse(stdout);
|
|
859
|
+
} catch (cause) {
|
|
860
|
+
throw new Error(`LibreOffice helper returned an invalid response (exit ${code}). ${stderr}`, { cause });
|
|
861
|
+
}
|
|
862
|
+
if (code !== 0 || result.ok !== true) throw new ConversionError(failureCode(result), `LibreOffice native conversion failed: ${result.error ?? stderr}`);
|
|
863
|
+
} finally {
|
|
864
|
+
signal.removeEventListener("abort", abort);
|
|
647
865
|
}
|
|
648
|
-
|
|
649
|
-
} finally {
|
|
650
|
-
signal.removeEventListener("abort", abort);
|
|
651
|
-
}
|
|
866
|
+
});
|
|
652
867
|
}
|
|
653
868
|
//#endregion
|
|
654
869
|
//#region lib/types/png.js
|
|
@@ -785,179 +1000,216 @@ async function renderImagesWithNative(request) {
|
|
|
785
1000
|
signal.throwIfAborted();
|
|
786
1001
|
await mkdir(profile, { mode: 448 });
|
|
787
1002
|
await prepareNativeFontProfile(profile, substitutions);
|
|
788
|
-
|
|
789
|
-
"--operation",
|
|
790
|
-
"render-images",
|
|
791
|
-
"--program-directory",
|
|
792
|
-
engine.programDirectory,
|
|
793
|
-
"--input-path",
|
|
794
|
-
inputPath,
|
|
795
|
-
"--scratch-directory",
|
|
796
|
-
scratch,
|
|
797
|
-
"--profile-directory",
|
|
798
|
-
profile,
|
|
799
|
-
"--max-output-bytes",
|
|
800
|
-
String(options.maxOutputBytes),
|
|
801
|
-
"--max-image-resolution",
|
|
802
|
-
String(options.maxImageResolution),
|
|
803
|
-
...fonts.flatMap((path) => ["--font-file", path])
|
|
804
|
-
], {
|
|
805
|
-
stdio: [
|
|
806
|
-
"pipe",
|
|
807
|
-
"pipe",
|
|
808
|
-
"pipe"
|
|
809
|
-
],
|
|
810
|
-
windowsHide: true,
|
|
811
|
-
env: nativeEnvironment(profile, engine.programDirectory)
|
|
812
|
-
});
|
|
813
|
-
const lines = [];
|
|
814
|
-
const waiters = [];
|
|
815
|
-
const output = createInterface({ input: child.stdout });
|
|
816
|
-
output.on("line", (line) => {
|
|
817
|
-
const waiter = waiters.shift();
|
|
818
|
-
if (waiter) waiter(line);
|
|
819
|
-
else lines.push(line);
|
|
820
|
-
});
|
|
821
|
-
let stderr = "";
|
|
822
|
-
let stopped;
|
|
823
|
-
child.stderr.setEncoding("utf8");
|
|
824
|
-
child.stderr.on("data", (chunk) => {
|
|
825
|
-
stderr = (stderr + chunk).slice(-65536);
|
|
826
|
-
});
|
|
827
|
-
const closed = new Promise((resolve, reject) => {
|
|
828
|
-
child.once("error", reject);
|
|
829
|
-
child.once("close", resolve);
|
|
830
|
-
});
|
|
831
|
-
const abort = () => {
|
|
832
|
-
stopped ??= signal.reason;
|
|
833
|
-
child.kill("SIGKILL");
|
|
834
|
-
};
|
|
835
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
836
|
-
const next = async () => {
|
|
1003
|
+
return withNativeEngine(engine, profile, async (engine) => {
|
|
837
1004
|
signal.throwIfAborted();
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1005
|
+
const child = spawnNative(engine.executable, [
|
|
1006
|
+
"--operation",
|
|
1007
|
+
"render-images",
|
|
1008
|
+
"--program-directory",
|
|
1009
|
+
engine.programDirectory,
|
|
1010
|
+
"--input-path",
|
|
1011
|
+
inputPath,
|
|
1012
|
+
"--scratch-directory",
|
|
1013
|
+
scratch,
|
|
1014
|
+
"--profile-directory",
|
|
1015
|
+
profile,
|
|
1016
|
+
"--max-output-bytes",
|
|
1017
|
+
String(options.maxOutputBytes),
|
|
1018
|
+
"--max-image-resolution",
|
|
1019
|
+
String(options.maxImageResolution),
|
|
1020
|
+
...fonts.flatMap((path) => ["--font-file", path])
|
|
1021
|
+
], nativeEnvironment(profile, engine.programDirectory));
|
|
1022
|
+
const lines = [];
|
|
1023
|
+
const waiters = [];
|
|
1024
|
+
const output = createInterface({ input: child.stdout });
|
|
1025
|
+
output.on("line", (line) => {
|
|
1026
|
+
const waiter = waiters.shift();
|
|
1027
|
+
if (waiter) waiter(line);
|
|
1028
|
+
else lines.push(line);
|
|
851
1029
|
});
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1030
|
+
let stderr = "";
|
|
1031
|
+
let stopped;
|
|
1032
|
+
child.stderr.setEncoding("utf8");
|
|
1033
|
+
child.stderr.on("data", (chunk) => {
|
|
1034
|
+
stderr = (stderr + chunk).slice(-65536);
|
|
1035
|
+
});
|
|
1036
|
+
const closed = new Promise((resolve, reject) => {
|
|
1037
|
+
let failure;
|
|
1038
|
+
child.once("error", (error) => {
|
|
1039
|
+
failure = error;
|
|
1040
|
+
});
|
|
1041
|
+
child.once("close", (code) => {
|
|
1042
|
+
if (failure) reject(failure);
|
|
1043
|
+
else resolve(code);
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
const abort = () => {
|
|
1047
|
+
stopped ??= signal.reason;
|
|
1048
|
+
child.kill("SIGKILL");
|
|
1049
|
+
};
|
|
1050
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1051
|
+
const next = async () => {
|
|
1052
|
+
signal.throwIfAborted();
|
|
1053
|
+
if (lines.length > 0) return lines.shift();
|
|
1054
|
+
return new Promise((resolve, reject) => {
|
|
1055
|
+
const done = (line) => {
|
|
1056
|
+
signal.removeEventListener("abort", cancel);
|
|
1057
|
+
resolve(line);
|
|
1058
|
+
};
|
|
1059
|
+
const fail = (error) => {
|
|
1060
|
+
const index = waiters.indexOf(done);
|
|
1061
|
+
if (index >= 0) waiters.splice(index, 1);
|
|
1062
|
+
signal.removeEventListener("abort", cancel);
|
|
1063
|
+
reject(error);
|
|
1064
|
+
};
|
|
1065
|
+
const cancel = () => {
|
|
1066
|
+
fail(signal.reason);
|
|
1067
|
+
};
|
|
1068
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
1069
|
+
waiters.push(done);
|
|
1070
|
+
closed.then((code) => {
|
|
1071
|
+
fail(/* @__PURE__ */ new Error(`LibreOffice native renderer exited ${code ?? child.signalCode} before responding. ${stderr}`));
|
|
1072
|
+
}, fail);
|
|
1073
|
+
});
|
|
1074
|
+
};
|
|
1075
|
+
const response = async () => {
|
|
1076
|
+
const line = await next();
|
|
1077
|
+
let value;
|
|
873
1078
|
try {
|
|
874
|
-
|
|
875
|
-
maxPixels: operation.maxPixels,
|
|
876
|
-
maxDimension: operation.maxDimension,
|
|
877
|
-
maxTiles: operation.maxPages - selected.length
|
|
878
|
-
});
|
|
1079
|
+
value = JSON.parse(line);
|
|
879
1080
|
} catch (cause) {
|
|
880
|
-
throw new
|
|
1081
|
+
throw new Error(`LibreOffice native renderer returned invalid JSON. ${stderr}`, { cause });
|
|
881
1082
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
rectangle
|
|
885
|
-
})));
|
|
886
|
-
}
|
|
887
|
-
for (const { page, rectangle } of selected) {
|
|
888
|
-
const { width, height } = tileDimensions({
|
|
889
|
-
pageIndex: 0,
|
|
890
|
-
...rectangle,
|
|
891
|
-
scale
|
|
892
|
-
}, [page]);
|
|
893
|
-
if (width > operation.maxDimension || height > operation.maxDimension || width * height > operation.maxPixels) throw new ConversionError("output-too-large", "Selected page exceeds maxPixels or maxDimension; reduce DPI or raise the image limits.");
|
|
894
|
-
}
|
|
895
|
-
const images = [];
|
|
896
|
-
let total = 0;
|
|
897
|
-
for (const region of selected) {
|
|
898
|
-
signal.throwIfAborted();
|
|
899
|
-
const { width, height } = tileDimensions({
|
|
900
|
-
pageIndex: 0,
|
|
901
|
-
...region.rectangle,
|
|
902
|
-
scale
|
|
903
|
-
}, [region.page]);
|
|
904
|
-
const x = region.page.x + Math.round(region.rectangle.x * 15);
|
|
905
|
-
const y = region.page.y + Math.round(region.rectangle.y * 15);
|
|
906
|
-
const twipsWidth = Math.max(1, Math.round(region.rectangle.width * 15));
|
|
907
|
-
const twipsHeight = Math.max(1, Math.round(region.rectangle.height * 15));
|
|
908
|
-
const index = images.length + 1;
|
|
909
|
-
child.stdin.write(`P ${index} ${region.page.part} ${width} ${height} ${x} ${y} ${twipsWidth} ${twipsHeight}\n`);
|
|
910
|
-
const painted = await response();
|
|
911
|
-
if (painted.kind !== "paint" || painted.index !== index || painted.width !== width || painted.height !== height) throw new Error("LibreOffice native renderer returned inconsistent tile metadata.");
|
|
912
|
-
if (resolve(painted.path) !== resolve(scratch, `tile-${index}.rgba`)) throw new Error("LibreOffice native renderer returned a tile outside its scratch directory.");
|
|
913
|
-
const raw = await readFile(painted.path);
|
|
914
|
-
if (raw.byteLength !== width * height * 4) throw new Error("LibreOffice native renderer returned incomplete pixels.");
|
|
915
|
-
const png = encodePng(width, height, ready.documentType === "pdf" ? new Uint8ClampedArray(raw) : rgbaPixels(raw, ready.tileMode));
|
|
916
|
-
total += png.byteLength;
|
|
917
|
-
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
918
|
-
const path = join(operation.outputDir, `page-${String(index).padStart(4, "0")}.png`);
|
|
919
|
-
await writeFile(path, png, {
|
|
920
|
-
flag: "wx",
|
|
921
|
-
mode: 384
|
|
922
|
-
});
|
|
923
|
-
images.push({
|
|
924
|
-
index,
|
|
925
|
-
...region.number === void 0 ? {} : { page: region.number },
|
|
926
|
-
...region.sheet === void 0 ? {} : {
|
|
927
|
-
sheet: region.sheet,
|
|
928
|
-
range: region.range,
|
|
929
|
-
rtl: region.rtl
|
|
930
|
-
},
|
|
931
|
-
path,
|
|
932
|
-
width,
|
|
933
|
-
height,
|
|
934
|
-
rectangle: region.rectangle,
|
|
935
|
-
byteLength: png.byteLength
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
child.stdin.end("DONE\n");
|
|
939
|
-
if ((await response()).kind !== "done") throw new Error("LibreOffice native renderer did not finish.");
|
|
940
|
-
const code = await closed;
|
|
941
|
-
if (code !== 0) throw new Error(`LibreOffice native renderer exited ${code}. ${stderr}`);
|
|
942
|
-
return {
|
|
943
|
-
schemaVersion: 1,
|
|
944
|
-
backend: "native",
|
|
945
|
-
rasterEngine: ready.documentType === "pdf" ? "pdfium" : "libreoffice",
|
|
946
|
-
source: "saved",
|
|
947
|
-
inputPath: operation.inputPath,
|
|
948
|
-
sourceSha256: createHash("sha256").update(source).digest("hex"),
|
|
949
|
-
dpi: operation.dpi,
|
|
950
|
-
pageCount: planned.count,
|
|
951
|
-
images,
|
|
952
|
-
missingFonts: [...missingFonts]
|
|
1083
|
+
if (!value.ok) throw failure(value, stderr);
|
|
1084
|
+
return value;
|
|
953
1085
|
};
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1086
|
+
try {
|
|
1087
|
+
const ready = await response();
|
|
1088
|
+
if (ready.kind !== "ready") throw new Error("LibreOffice native renderer did not initialize.");
|
|
1089
|
+
const planned = plan(ready, operation);
|
|
1090
|
+
const scale = operation.dpi / 96;
|
|
1091
|
+
const selected = [];
|
|
1092
|
+
for (const region of planned.regions) if (region.sheet === void 0) selected.push(region);
|
|
1093
|
+
else {
|
|
1094
|
+
let rectangles;
|
|
1095
|
+
try {
|
|
1096
|
+
rectangles = splitRasterRectangle(region.rectangle, scale, {
|
|
1097
|
+
maxPixels: operation.maxPixels,
|
|
1098
|
+
maxDimension: operation.maxDimension,
|
|
1099
|
+
maxTiles: operation.maxPages - selected.length
|
|
1100
|
+
});
|
|
1101
|
+
} catch (cause) {
|
|
1102
|
+
throw new ConversionError("output-too-large", String(cause), { cause });
|
|
1103
|
+
}
|
|
1104
|
+
selected.push(...rectangles.map((rectangle) => ({
|
|
1105
|
+
...region,
|
|
1106
|
+
rectangle
|
|
1107
|
+
})));
|
|
1108
|
+
}
|
|
1109
|
+
for (const { page, rectangle } of selected) {
|
|
1110
|
+
const { width, height } = tileDimensions({
|
|
1111
|
+
pageIndex: 0,
|
|
1112
|
+
...rectangle,
|
|
1113
|
+
scale
|
|
1114
|
+
}, [page]);
|
|
1115
|
+
if (width > operation.maxDimension || height > operation.maxDimension || width * height > operation.maxPixels) throw new ConversionError("output-too-large", "Selected page exceeds maxPixels or maxDimension; reduce DPI or raise the image limits.");
|
|
1116
|
+
}
|
|
1117
|
+
const images = [];
|
|
1118
|
+
let total = 0;
|
|
1119
|
+
for (const region of selected) {
|
|
1120
|
+
signal.throwIfAborted();
|
|
1121
|
+
const { width, height } = tileDimensions({
|
|
1122
|
+
pageIndex: 0,
|
|
1123
|
+
...region.rectangle,
|
|
1124
|
+
scale
|
|
1125
|
+
}, [region.page]);
|
|
1126
|
+
const x = region.page.x + Math.round(region.rectangle.x * 15);
|
|
1127
|
+
const y = region.page.y + Math.round(region.rectangle.y * 15);
|
|
1128
|
+
const twipsWidth = Math.max(1, Math.round(region.rectangle.width * 15));
|
|
1129
|
+
const twipsHeight = Math.max(1, Math.round(region.rectangle.height * 15));
|
|
1130
|
+
const index = images.length + 1;
|
|
1131
|
+
child.stdin.write(`P ${index} ${region.page.part} ${width} ${height} ${x} ${y} ${twipsWidth} ${twipsHeight}\n`);
|
|
1132
|
+
const painted = await response();
|
|
1133
|
+
if (painted.kind !== "paint" || painted.index !== index || painted.width !== width || painted.height !== height) throw new Error("LibreOffice native renderer returned inconsistent tile metadata.");
|
|
1134
|
+
if (resolve(painted.path) !== resolve(scratch, `tile-${index}.rgba`)) throw new Error("LibreOffice native renderer returned a tile outside its scratch directory.");
|
|
1135
|
+
const raw = await readFile(painted.path);
|
|
1136
|
+
if (raw.byteLength !== width * height * 4) throw new Error("LibreOffice native renderer returned incomplete pixels.");
|
|
1137
|
+
const rgba = ready.documentType === "pdf" ? new Uint8ClampedArray(raw) : rgbaPixels(raw, ready.tileMode);
|
|
1138
|
+
if (region.rtl) unmirrorRtlTile({
|
|
1139
|
+
width,
|
|
1140
|
+
height,
|
|
1141
|
+
rgba
|
|
1142
|
+
});
|
|
1143
|
+
const png = encodePng(width, height, rgba);
|
|
1144
|
+
total += png.byteLength;
|
|
1145
|
+
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
1146
|
+
const path = join(operation.outputDir, `page-${String(index).padStart(4, "0")}.png`);
|
|
1147
|
+
await writeFile(path, png, {
|
|
1148
|
+
flag: "wx",
|
|
1149
|
+
mode: 384
|
|
1150
|
+
});
|
|
1151
|
+
images.push({
|
|
1152
|
+
index,
|
|
1153
|
+
...region.number === void 0 ? {} : { page: region.number },
|
|
1154
|
+
...region.sheet === void 0 ? {} : {
|
|
1155
|
+
sheet: region.sheet,
|
|
1156
|
+
range: region.range,
|
|
1157
|
+
rtl: region.rtl
|
|
1158
|
+
},
|
|
1159
|
+
path,
|
|
1160
|
+
width,
|
|
1161
|
+
height,
|
|
1162
|
+
rectangle: region.rectangle,
|
|
1163
|
+
byteLength: png.byteLength
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
child.stdin.end("DONE\n");
|
|
1167
|
+
if ((await response()).kind !== "done") throw new Error("LibreOffice native renderer did not finish.");
|
|
1168
|
+
const code = await closed;
|
|
1169
|
+
if (code !== 0) throw new Error(`LibreOffice native renderer exited ${code}. ${stderr}`);
|
|
1170
|
+
return {
|
|
1171
|
+
schemaVersion: 1,
|
|
1172
|
+
backend: "native",
|
|
1173
|
+
rasterEngine: ready.documentType === "pdf" ? "pdfium" : "libreoffice",
|
|
1174
|
+
source: "saved",
|
|
1175
|
+
inputPath: operation.inputPath,
|
|
1176
|
+
sourceSha256: createHash("sha256").update(source).digest("hex"),
|
|
1177
|
+
dpi: operation.dpi,
|
|
1178
|
+
pageCount: planned.count,
|
|
1179
|
+
images,
|
|
1180
|
+
missingFonts: [...missingFonts]
|
|
1181
|
+
};
|
|
1182
|
+
} finally {
|
|
1183
|
+
signal.removeEventListener("abort", abort);
|
|
1184
|
+
output.close();
|
|
1185
|
+
if (child.exitCode === null) child.kill("SIGKILL");
|
|
1186
|
+
await closed.catch(() => {});
|
|
1187
|
+
if (stopped !== void 0) throw stopped;
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region lib/types/font-file-identity.js
|
|
1193
|
+
/** Preserve 64-bit device and inode values without JavaScript integer rounding. */
|
|
1194
|
+
function fontFileIdentity(status) {
|
|
1195
|
+
return {
|
|
1196
|
+
dev: status.dev.toString(),
|
|
1197
|
+
ino: status.ino.toString(),
|
|
1198
|
+
size: Number(status.size),
|
|
1199
|
+
mtimeMs: Number(status.mtimeNs) / 1e6,
|
|
1200
|
+
ctimeMs: Number(status.ctimeNs) / 1e6
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
/** Compare a source descriptor's exact identity with its indexed font metadata. */
|
|
1204
|
+
function matchesFontFile(status, expected) {
|
|
1205
|
+
const current = fontFileIdentity(status);
|
|
1206
|
+
return [
|
|
1207
|
+
"dev",
|
|
1208
|
+
"ino",
|
|
1209
|
+
"size",
|
|
1210
|
+
"mtimeMs",
|
|
1211
|
+
"ctimeMs"
|
|
1212
|
+
].every((key) => current[key] === expected[key]);
|
|
961
1213
|
}
|
|
962
1214
|
//#endregion
|
|
963
1215
|
//#region lib/types/fonts.js
|
|
@@ -1210,16 +1462,16 @@ function resolveOptions(input = {}) {
|
|
|
1210
1462
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1211
1463
|
const require = createRequire(import.meta.url);
|
|
1212
1464
|
/** Node API release version returned by runtime discovery. */
|
|
1213
|
-
const ENGINE_VERSION = "0.1.
|
|
1465
|
+
const ENGINE_VERSION = "0.1.5";
|
|
1214
1466
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1215
1467
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1216
|
-
"darwin-arm64": "0.1.
|
|
1217
|
-
"darwin-x64": "0.1.
|
|
1468
|
+
"darwin-arm64": "0.1.5",
|
|
1469
|
+
"darwin-x64": "0.1.5",
|
|
1218
1470
|
"linux-arm64-glibc": "0.1.1",
|
|
1219
1471
|
"linux-x64-glibc": "0.1.1",
|
|
1220
|
-
"win32-arm64": "0.1.
|
|
1221
|
-
"win32-x64": "0.1.
|
|
1222
|
-
wasm: "0.1.
|
|
1472
|
+
"win32-arm64": "0.1.5",
|
|
1473
|
+
"win32-x64": "0.1.5",
|
|
1474
|
+
wasm: "0.1.5"
|
|
1223
1475
|
});
|
|
1224
1476
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1225
1477
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
|
@@ -1526,14 +1778,8 @@ var FontSnapshotState = class {
|
|
|
1526
1778
|
async function validateFontSnapshot(snapshot) {
|
|
1527
1779
|
await Promise.all(snapshot.records.map(async (record) => {
|
|
1528
1780
|
try {
|
|
1529
|
-
const current = await lstat(record.path);
|
|
1530
|
-
if (current.isFile() &&
|
|
1531
|
-
"dev",
|
|
1532
|
-
"ino",
|
|
1533
|
-
"size",
|
|
1534
|
-
"mtimeMs",
|
|
1535
|
-
"ctimeMs"
|
|
1536
|
-
].every((key) => current[key] === record[key])) return;
|
|
1781
|
+
const current = await lstat(record.path, { bigint: true });
|
|
1782
|
+
if (current.isFile() && matchesFontFile(current, record)) return;
|
|
1537
1783
|
} catch {}
|
|
1538
1784
|
throw new ConversionError("failed", "A system font changed during conversion; retry the operation.");
|
|
1539
1785
|
}));
|