@deepseek-ai/libreoffice-kit 0.1.3 → 0.1.5
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 +7 -1
- package/README.zh.md +7 -1
- package/lib/cli.js +216 -30
- package/lib/index.js +216 -30
- package/lib/types/engine.d.ts +1 -1
- package/lib/types/native-process.d.ts +20 -0
- package/lib/types/native.d.ts +1 -0
- package/lib/types/rendering.d.ts +2 -0
- package/lib/types/sheet-geometry.d.ts +1 -1
- package/lib/worker.js +13 -1
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Converters created through the compatibility `createConverter(options)` API tran
|
|
|
41
41
|
|
|
42
42
|
For a long-lived service that wants one explicit lifecycle owner for concurrent conversion slots, create one `createConverterFactory(options)` and obtain converters through `factory.create()`. Those converters use a factory-private cache while retaining separate Workers, native helpers, profiles, and output ownership. Dispose the factory to stop and join every converter it created.
|
|
43
43
|
|
|
44
|
-
`convert()` exports the format named by the output suffix, `recalculate()` refreshes spreadsheet formula results before saving, and `renderImages()` writes a fresh directory containing PNG tiles plus `manifest.json`. Office images are painted directly from one loaded model; PDF images use PDFium. The CLI exposes the same operations through `dsoffice capabilities|convert|recalculate|render`.
|
|
44
|
+
`convert()` exports the format named by the output suffix, `recalculate()` refreshes spreadsheet formula results before saving, and `renderImages()` writes a fresh directory containing PNG tiles plus `manifest.json`. Office images are painted directly from one loaded model; PDF images use PDFium. The CLI exposes the same operations through `dsoffice capabilities|convert|recalculate|render`. Worksheet names are exact: a missing image-render selection rejects with `invalid-document`, and a missing CSV selection rejects with `failed`; neither leaves output behind. Recalculation applies to the entire workbook and rejects `--sheet`. A rejected selection leaves the converter available for subsequent operations.
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
47
|
npm exec -- dsoffice render --input report.docx --output-dir report-pages --pages 1
|
|
@@ -50,8 +50,14 @@ npm exec -- dsoffice convert --input report.docx --output report.pdf
|
|
|
50
50
|
npm exec -- dsoffice recalculate --input budget.xlsx --output recalculated.xlsx
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Right-to-left worksheets produce readable PNG text with column A on the right. A1 ranges and manifest rectangles retain logical column coordinates; each split tile is independently oriented for display.
|
|
54
|
+
|
|
53
55
|
Conversion workers run the package's shipped JavaScript with an empty `execArgv`; consumer launch flags such as `--input-type=module` are not inherited.
|
|
54
56
|
|
|
57
|
+
Windows native helpers use anonymous stdio pipes and inherit the caller's token and Job restrictions. Pipe polling does not occupy libuv worker threads while a helper waits for commands. Cancellation and rejected worksheet selections wait for process exit and pipe closure, including when the protocol reader has paused stdout; this transport does not grant additional filesystem or network access.
|
|
58
|
+
|
|
59
|
+
Native conversion and image-rendering helpers disable printer enumeration and default-printer lookup with `SAL_DISABLE_PRINTERLIST=1` and `SAL_DISABLE_DEFAULTPRINTER=1`. Document previews and exports do not need a physical printer; these child-process settings prevent printer-driver dialogs and network-printer connection waits without changing the system's printer settings.
|
|
60
|
+
|
|
55
61
|
On Windows, an engine executable or program path of 260 or more characters uses a temporary helper copy and a junction to the installed resources inside the private operation directory. Resources stay in their installation, and the junction remains until the helper closes. A renderer that exits before returning a protocol response rejects with its exit status and captured diagnostics.
|
|
56
62
|
|
|
57
63
|
On Linux, the native child searches the selected engine's program directory before system paths for shared libraries. Caller-provided `LD_LIBRARY_PATH` and `LD_PRELOAD` are not inherited.
|
package/README.zh.md
CHANGED
|
@@ -43,7 +43,7 @@ try {
|
|
|
43
43
|
|
|
44
44
|
长驻服务如果需要为多个并发转换槽提供一个显式生命周期所有者,可创建 `createConverterFactory(options)`,再通过 `factory.create()` 建立转换器。这些转换器使用 factory 私有缓存,同时仍分别拥有 Worker、原生 helper、配置目录和输出。释放 factory 会停止并等待它创建的全部转换器。
|
|
45
45
|
|
|
46
|
-
`convert()` 按输出后缀导出格式,`recalculate()` 在保存前刷新电子表格公式结果,`renderImages()` 在全新目录中写入 PNG tile 和 `manifest.json`。Office 图像直接从一次加载的模型绘制,PDF 使用 PDFium。CLI 通过 `dsoffice capabilities|convert|recalculate|render`
|
|
46
|
+
`convert()` 按输出后缀导出格式,`recalculate()` 在保存前刷新电子表格公式结果,`renderImages()` 在全新目录中写入 PNG tile 和 `manifest.json`。Office 图像直接从一次加载的模型绘制,PDF 使用 PDFium。CLI 通过 `dsoffice capabilities|convert|recalculate|render` 提供相同行为。工作表名称按精确名称匹配:图像渲染指定不存在的工作表时返回 `invalid-document`,CSV 导出返回 `failed`,两者均不保留输出。重算作用于整个工作簿并拒绝 `--sheet`。选择失败后仍可复用转换器。
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
npm exec -- dsoffice render --input report.docx --output-dir report-pages --pages 1
|
|
@@ -52,8 +52,14 @@ npm exec -- dsoffice convert --input report.docx --output report.pdf
|
|
|
52
52
|
npm exec -- dsoffice recalculate --input budget.xlsx --output recalculated.xlsx
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
从右向左排列的工作表会生成文字可正常阅读、A 列位于右侧的 PNG。A1 范围和 manifest 中的矩形仍使用逻辑列坐标;拆分后的每张 tile 均独立调整像素方向。
|
|
56
|
+
|
|
55
57
|
转换 worker 以空的 `execArgv` 运行包内发布的 JavaScript;`--input-type=module` 之类的调用方启动参数不会被继承。
|
|
56
58
|
|
|
59
|
+
Windows 原生 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。helper 等待命令时,管道轮询不会占用 libuv 工作线程。取消及工作表选择失败均会等待进程退出和管道关闭,包括协议读取器已暂停 stdout 的情况;此传输方式不授予额外的文件系统或网络权限。
|
|
60
|
+
|
|
61
|
+
原生转换和图片渲染 helper 设置 `SAL_DISABLE_PRINTERLIST=1` 与 `SAL_DISABLE_DEFAULTPRINTER=1`,禁用打印机枚举和默认打印机查询。文档预览和导出不需要实体打印机;这些子进程设置可避免打印机驱动弹窗及网络打印机连接等待,不会修改系统打印机设置。
|
|
62
|
+
|
|
57
63
|
在 Linux 上,原生子进程会先在所选引擎的 program 目录中查找共享库,然后才查找系统路径。调用方提供的 `LD_LIBRARY_PATH` 和 `LD_PRELOAD` 不会被继承。
|
|
58
64
|
|
|
59
65
|
调用方负责授权输入访问并拥有私有输入/输出目录;路径必须是绝对路径,并在转换期间保持不变。输入文件必须是常规 Office 文件,且在配置的字节限制之内。ZIP 条目数和解压大小限制适用于 OOXML;二进制 DOC/XLS/PPT 使用 OLE 复合容器,内部结构由 LibreOffice 导入器验证。二进制格式仍遵守相同的转换超时和输入/输出限制。输出创建使用独占模式和 `0600` 权限;已存在的输出绝不会被覆盖。失败或取消的渲染会删除新建的输出。`maxOutputBytes` 限制返回的 PDF 及其读取缓冲区;原生临时磁盘文件在导出完成前可能继续增长,随后过大的 PDF 会在 Node 读取之前被拒绝并删除。成功的 PDF 归调用方所有,调用方可以将其字节发送给浏览器 PDF 阅读器。
|
package/lib/cli.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
5
|
-
import { constants, lstatSync, readdirSync } from "node:fs";
|
|
5
|
+
import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync } from "node:fs";
|
|
6
6
|
import { copyFile, lstat, mkdir, mkdtemp, open, readFile, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
7
7
|
import { homedir, tmpdir } from "node:os";
|
|
8
8
|
import { Worker } from "node:worker_threads";
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
|
+
import { EventEmitter } from "node:events";
|
|
11
|
+
import { Readable } from "node:stream";
|
|
12
|
+
import { finished } from "node:stream/promises";
|
|
10
13
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
14
|
import { createInterface } from "node:readline";
|
|
12
15
|
import { zlibSync } from "fflate";
|
|
@@ -137,7 +140,7 @@ function dimension(data, first, last, maximum, scale) {
|
|
|
137
140
|
}
|
|
138
141
|
return [start / scale, (position - start) / scale];
|
|
139
142
|
}
|
|
140
|
-
/** Logical columns advance from A;
|
|
143
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
141
144
|
function sheetRangeRectangle(geometry, range, scale) {
|
|
142
145
|
if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
|
|
143
146
|
const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
|
|
@@ -158,6 +161,17 @@ function sheetRangeRectangle(geometry, range, scale) {
|
|
|
158
161
|
height
|
|
159
162
|
};
|
|
160
163
|
}
|
|
164
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
165
|
+
function unmirrorRtlTile({ width, height, rgba }) {
|
|
166
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < Math.floor(width / 2); x++) {
|
|
167
|
+
const left = (y * width + x) * 4, right = (y * width + width - 1 - x) * 4;
|
|
168
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
169
|
+
const value = rgba[left + channel];
|
|
170
|
+
rgba[left + channel] = rgba[right + channel];
|
|
171
|
+
rgba[right + channel] = value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
161
175
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
162
176
|
function splitRasterRectangle(rectangle, scale, limits) {
|
|
163
177
|
const { x, y, width, height } = rectangle;
|
|
@@ -317,6 +331,184 @@ function selectedPages(pages, count, limit) {
|
|
|
317
331
|
return result;
|
|
318
332
|
}
|
|
319
333
|
//#endregion
|
|
334
|
+
//#region lib/types/native-process.js
|
|
335
|
+
/** Native helper stdio; Windows pipe handles permit read/write access under restricted tokens. */
|
|
336
|
+
let pipeAttributes;
|
|
337
|
+
function windowsPipes() {
|
|
338
|
+
const koffi = createRequire(import.meta.url)("koffi");
|
|
339
|
+
const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
|
|
340
|
+
const attributes = pipeAttributes ??= koffi.struct("KIT_SECURITY_ATTRIBUTES", {
|
|
341
|
+
nLength: "uint32",
|
|
342
|
+
lpSecurityDescriptor: "void *",
|
|
343
|
+
bInheritHandle: "int"
|
|
344
|
+
});
|
|
345
|
+
const createPipe = kernel.func("int __stdcall CreatePipe(_Out_ void **read, _Out_ void **write, KIT_SECURITY_ATTRIBUTES *attributes, uint32 size)");
|
|
346
|
+
const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
347
|
+
const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
|
|
348
|
+
const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
|
|
349
|
+
const lastError = kernel.func("uint32 __stdcall GetLastError()");
|
|
350
|
+
const convertSecurityDescriptor = advapi.func("int __stdcall ConvertStringSecurityDescriptorToSecurityDescriptorW(void *sddl, uint32 revision, _Out_ void **descriptor, void *size)");
|
|
351
|
+
const openFd = node.func("int uv_open_osfhandle(void *handle)");
|
|
352
|
+
function pipe() {
|
|
353
|
+
const reads = [null], writes = [null];
|
|
354
|
+
const descriptor = [null];
|
|
355
|
+
if (!convertSecurityDescriptor(Buffer.from("D:(A;;GRGW;;;WD)\0", "utf16le"), 1, descriptor, null)) throw new Error(`Pipe security descriptor failed: ${lastError()}`);
|
|
356
|
+
try {
|
|
357
|
+
if (!createPipe(reads, writes, {
|
|
358
|
+
nLength: attributes.size,
|
|
359
|
+
lpSecurityDescriptor: descriptor[0],
|
|
360
|
+
bInheritHandle: 0
|
|
361
|
+
}, 0)) throw new Error(`CreatePipe failed: ${lastError()}`);
|
|
362
|
+
} finally {
|
|
363
|
+
localFree(descriptor[0]);
|
|
364
|
+
}
|
|
365
|
+
const read = openFd(reads[0]);
|
|
366
|
+
if (read < 0) {
|
|
367
|
+
closeHandle(reads[0]);
|
|
368
|
+
closeHandle(writes[0]);
|
|
369
|
+
throw new Error("Cannot open anonymous input descriptor");
|
|
370
|
+
}
|
|
371
|
+
const write = openFd(writes[0]);
|
|
372
|
+
if (write < 0) {
|
|
373
|
+
closeSync(read);
|
|
374
|
+
closeHandle(writes[0]);
|
|
375
|
+
throw new Error("Cannot open anonymous output descriptor");
|
|
376
|
+
}
|
|
377
|
+
let timer;
|
|
378
|
+
let ended = false;
|
|
379
|
+
const readable = new Readable({
|
|
380
|
+
read() {
|
|
381
|
+
if (timer === void 0 && !ended) poll();
|
|
382
|
+
},
|
|
383
|
+
destroy(error, callback) {
|
|
384
|
+
ended = true;
|
|
385
|
+
clearTimeout(timer);
|
|
386
|
+
try {
|
|
387
|
+
closeSync(read);
|
|
388
|
+
callback(error);
|
|
389
|
+
} catch (cause) {
|
|
390
|
+
callback(error ?? cause);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
function poll() {
|
|
395
|
+
timer = void 0;
|
|
396
|
+
try {
|
|
397
|
+
const available = [0];
|
|
398
|
+
if (!peek(reads[0], null, 0, null, available, null)) {
|
|
399
|
+
const code = lastError();
|
|
400
|
+
if (code !== 109) throw new Error(`PeekNamedPipe failed: ${code}`);
|
|
401
|
+
ended = true;
|
|
402
|
+
readable.push(null);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (available[0] > 0) {
|
|
406
|
+
const buffer = Buffer.allocUnsafe(Math.min(available[0], 65536));
|
|
407
|
+
const count = readSync(read, buffer, 0, buffer.length, null);
|
|
408
|
+
if (!readable.push(buffer.subarray(0, count))) return;
|
|
409
|
+
}
|
|
410
|
+
timer = setTimeout(poll, 5);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
readable.destroy(error);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
read,
|
|
417
|
+
write,
|
|
418
|
+
readable
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return { pipe };
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Spawn with inherited token and Job restrictions; pipe creation never requests a new sandbox policy.
|
|
425
|
+
* @param executable - Verified native helper executable.
|
|
426
|
+
* @param args - Helper protocol arguments.
|
|
427
|
+
* @param env - Filtered operation environment.
|
|
428
|
+
* @returns Helper streams and process lifetime, with output drained before close.
|
|
429
|
+
*/
|
|
430
|
+
function spawnNative(executable, args, env) {
|
|
431
|
+
if (process.platform !== "win32") return spawn(executable, args, {
|
|
432
|
+
stdio: "pipe",
|
|
433
|
+
windowsHide: true,
|
|
434
|
+
env
|
|
435
|
+
});
|
|
436
|
+
const { pipe } = windowsPipes();
|
|
437
|
+
const owned = [];
|
|
438
|
+
let child;
|
|
439
|
+
try {
|
|
440
|
+
const input = pipe();
|
|
441
|
+
owned.push(input);
|
|
442
|
+
const output = pipe();
|
|
443
|
+
owned.push(output);
|
|
444
|
+
const error = pipe();
|
|
445
|
+
owned.push(error);
|
|
446
|
+
child = spawn(executable, args, {
|
|
447
|
+
stdio: [
|
|
448
|
+
input.read,
|
|
449
|
+
output.write,
|
|
450
|
+
error.write
|
|
451
|
+
],
|
|
452
|
+
windowsHide: true,
|
|
453
|
+
env
|
|
454
|
+
});
|
|
455
|
+
} catch (error) {
|
|
456
|
+
for (const entry of owned) {
|
|
457
|
+
entry.readable.destroy();
|
|
458
|
+
closeSync(entry.write);
|
|
459
|
+
}
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
const [input, output, error] = owned;
|
|
463
|
+
input.readable.destroy();
|
|
464
|
+
closeSync(output.write);
|
|
465
|
+
closeSync(error.write);
|
|
466
|
+
const stdin = createWriteStream("", {
|
|
467
|
+
fd: input.write,
|
|
468
|
+
autoClose: true
|
|
469
|
+
});
|
|
470
|
+
const helper = new class extends EventEmitter {
|
|
471
|
+
stdin = stdin;
|
|
472
|
+
stdout = output.readable;
|
|
473
|
+
stderr = error.readable;
|
|
474
|
+
get exitCode() {
|
|
475
|
+
return child.exitCode;
|
|
476
|
+
}
|
|
477
|
+
get signalCode() {
|
|
478
|
+
return child.signalCode;
|
|
479
|
+
}
|
|
480
|
+
kill(signal) {
|
|
481
|
+
return child.kill(signal);
|
|
482
|
+
}
|
|
483
|
+
}();
|
|
484
|
+
let failure;
|
|
485
|
+
const fail = (cause) => {
|
|
486
|
+
failure ??= cause;
|
|
487
|
+
child.kill("SIGKILL");
|
|
488
|
+
};
|
|
489
|
+
stdin.on("error", fail);
|
|
490
|
+
output.readable.on("error", fail);
|
|
491
|
+
error.readable.on("error", fail);
|
|
492
|
+
const drained = Promise.allSettled([
|
|
493
|
+
finished(stdin),
|
|
494
|
+
finished(output.readable),
|
|
495
|
+
finished(error.readable)
|
|
496
|
+
]);
|
|
497
|
+
child.once("error", (cause) => {
|
|
498
|
+
failure ??= cause;
|
|
499
|
+
});
|
|
500
|
+
child.once("close", (code, signal) => {
|
|
501
|
+
stdin.destroy();
|
|
502
|
+
output.readable.resume();
|
|
503
|
+
error.readable.resume();
|
|
504
|
+
drained.then(() => {
|
|
505
|
+
if (failure !== void 0) helper.emit("error", failure);
|
|
506
|
+
helper.emit("close", code, signal);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
return helper;
|
|
510
|
+
}
|
|
511
|
+
//#endregion
|
|
320
512
|
//#region lib/types/profile.js
|
|
321
513
|
/** Private headless profile used by both native and WASM conversions. */
|
|
322
514
|
/**
|
|
@@ -538,6 +730,7 @@ async function prepareNativeFontProfile(profile, substitutions) {
|
|
|
538
730
|
});
|
|
539
731
|
}
|
|
540
732
|
/**
|
|
733
|
+
* Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
|
|
541
734
|
* Linux searches the verified program directory; ambient loader overrides and credentials are excluded.
|
|
542
735
|
* @param profile - Conversion-owned profile directory the helper treats as home.
|
|
543
736
|
* @param programDirectory - Verified engine program directory.
|
|
@@ -557,7 +750,9 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
|
|
|
557
750
|
USERPROFILE: profile,
|
|
558
751
|
TMPDIR: profile,
|
|
559
752
|
TMP: profile,
|
|
560
|
-
TEMP: profile
|
|
753
|
+
TEMP: profile,
|
|
754
|
+
SAL_DISABLE_PRINTERLIST: "1",
|
|
755
|
+
SAL_DISABLE_DEFAULTPRINTER: "1"
|
|
561
756
|
});
|
|
562
757
|
}
|
|
563
758
|
/**
|
|
@@ -607,7 +802,7 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
607
802
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
608
803
|
signal.throwIfAborted();
|
|
609
804
|
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
610
|
-
const child =
|
|
805
|
+
const child = spawnNative(engine.executable, [
|
|
611
806
|
"--program-directory",
|
|
612
807
|
engine.programDirectory,
|
|
613
808
|
"--input-path",
|
|
@@ -626,15 +821,8 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
626
821
|
String(operation.recalculate),
|
|
627
822
|
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
628
823
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
629
|
-
],
|
|
630
|
-
|
|
631
|
-
"ignore",
|
|
632
|
-
"pipe",
|
|
633
|
-
"pipe"
|
|
634
|
-
],
|
|
635
|
-
windowsHide: true,
|
|
636
|
-
env
|
|
637
|
-
});
|
|
824
|
+
], env);
|
|
825
|
+
child.stdin.end();
|
|
638
826
|
let stdout = "";
|
|
639
827
|
let stderr = "";
|
|
640
828
|
let failure;
|
|
@@ -816,7 +1004,7 @@ async function renderImagesWithNative(request) {
|
|
|
816
1004
|
await prepareNativeFontProfile(profile, substitutions);
|
|
817
1005
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
818
1006
|
signal.throwIfAborted();
|
|
819
|
-
const child =
|
|
1007
|
+
const child = spawnNative(engine.executable, [
|
|
820
1008
|
"--operation",
|
|
821
1009
|
"render-images",
|
|
822
1010
|
"--program-directory",
|
|
@@ -832,15 +1020,7 @@ async function renderImagesWithNative(request) {
|
|
|
832
1020
|
"--max-image-resolution",
|
|
833
1021
|
String(options.maxImageResolution),
|
|
834
1022
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
835
|
-
],
|
|
836
|
-
stdio: [
|
|
837
|
-
"pipe",
|
|
838
|
-
"pipe",
|
|
839
|
-
"pipe"
|
|
840
|
-
],
|
|
841
|
-
windowsHide: true,
|
|
842
|
-
env: nativeEnvironment(profile, engine.programDirectory)
|
|
843
|
-
});
|
|
1023
|
+
], nativeEnvironment(profile, engine.programDirectory));
|
|
844
1024
|
const lines = [];
|
|
845
1025
|
const waiters = [];
|
|
846
1026
|
const output = createInterface({ input: child.stdout });
|
|
@@ -956,7 +1136,13 @@ async function renderImagesWithNative(request) {
|
|
|
956
1136
|
if (resolve(painted.path) !== resolve(scratch, `tile-${index}.rgba`)) throw new Error("LibreOffice native renderer returned a tile outside its scratch directory.");
|
|
957
1137
|
const raw = await readFile(painted.path);
|
|
958
1138
|
if (raw.byteLength !== width * height * 4) throw new Error("LibreOffice native renderer returned incomplete pixels.");
|
|
959
|
-
const
|
|
1139
|
+
const rgba = ready.documentType === "pdf" ? new Uint8ClampedArray(raw) : rgbaPixels(raw, ready.tileMode);
|
|
1140
|
+
if (region.rtl) unmirrorRtlTile({
|
|
1141
|
+
width,
|
|
1142
|
+
height,
|
|
1143
|
+
rgba
|
|
1144
|
+
});
|
|
1145
|
+
const png = encodePng(width, height, rgba);
|
|
960
1146
|
total += png.byteLength;
|
|
961
1147
|
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
962
1148
|
const path = join(operation.outputDir, `page-${String(index).padStart(4, "0")}.png`);
|
|
@@ -1278,16 +1464,16 @@ function resolveOptions(input = {}) {
|
|
|
1278
1464
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1279
1465
|
const require = createRequire(import.meta.url);
|
|
1280
1466
|
/** Node API release version returned by runtime discovery. */
|
|
1281
|
-
const ENGINE_VERSION = "0.1.
|
|
1467
|
+
const ENGINE_VERSION = "0.1.5";
|
|
1282
1468
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1283
1469
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1284
|
-
"darwin-arm64": "0.1.
|
|
1285
|
-
"darwin-x64": "0.1.
|
|
1470
|
+
"darwin-arm64": "0.1.5",
|
|
1471
|
+
"darwin-x64": "0.1.5",
|
|
1286
1472
|
"linux-arm64-glibc": "0.1.1",
|
|
1287
1473
|
"linux-x64-glibc": "0.1.1",
|
|
1288
|
-
"win32-arm64": "0.1.
|
|
1289
|
-
"win32-x64": "0.1.
|
|
1290
|
-
wasm: "0.1.
|
|
1474
|
+
"win32-arm64": "0.1.5",
|
|
1475
|
+
"win32-x64": "0.1.5",
|
|
1476
|
+
wasm: "0.1.5"
|
|
1291
1477
|
});
|
|
1292
1478
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1293
1479
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { constants, lstatSync, readdirSync } from "node:fs";
|
|
2
|
+
import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync } from "node:fs";
|
|
3
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,7 +748,9 @@ 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
|
/**
|
|
@@ -605,7 +800,7 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
605
800
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
606
801
|
signal.throwIfAborted();
|
|
607
802
|
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
608
|
-
const child =
|
|
803
|
+
const child = spawnNative(engine.executable, [
|
|
609
804
|
"--program-directory",
|
|
610
805
|
engine.programDirectory,
|
|
611
806
|
"--input-path",
|
|
@@ -624,15 +819,8 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
624
819
|
String(operation.recalculate),
|
|
625
820
|
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
626
821
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
627
|
-
],
|
|
628
|
-
|
|
629
|
-
"ignore",
|
|
630
|
-
"pipe",
|
|
631
|
-
"pipe"
|
|
632
|
-
],
|
|
633
|
-
windowsHide: true,
|
|
634
|
-
env
|
|
635
|
-
});
|
|
822
|
+
], env);
|
|
823
|
+
child.stdin.end();
|
|
636
824
|
let stdout = "";
|
|
637
825
|
let stderr = "";
|
|
638
826
|
let failure;
|
|
@@ -814,7 +1002,7 @@ async function renderImagesWithNative(request) {
|
|
|
814
1002
|
await prepareNativeFontProfile(profile, substitutions);
|
|
815
1003
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
816
1004
|
signal.throwIfAborted();
|
|
817
|
-
const child =
|
|
1005
|
+
const child = spawnNative(engine.executable, [
|
|
818
1006
|
"--operation",
|
|
819
1007
|
"render-images",
|
|
820
1008
|
"--program-directory",
|
|
@@ -830,15 +1018,7 @@ async function renderImagesWithNative(request) {
|
|
|
830
1018
|
"--max-image-resolution",
|
|
831
1019
|
String(options.maxImageResolution),
|
|
832
1020
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
833
|
-
],
|
|
834
|
-
stdio: [
|
|
835
|
-
"pipe",
|
|
836
|
-
"pipe",
|
|
837
|
-
"pipe"
|
|
838
|
-
],
|
|
839
|
-
windowsHide: true,
|
|
840
|
-
env: nativeEnvironment(profile, engine.programDirectory)
|
|
841
|
-
});
|
|
1021
|
+
], nativeEnvironment(profile, engine.programDirectory));
|
|
842
1022
|
const lines = [];
|
|
843
1023
|
const waiters = [];
|
|
844
1024
|
const output = createInterface({ input: child.stdout });
|
|
@@ -954,7 +1134,13 @@ async function renderImagesWithNative(request) {
|
|
|
954
1134
|
if (resolve(painted.path) !== resolve(scratch, `tile-${index}.rgba`)) throw new Error("LibreOffice native renderer returned a tile outside its scratch directory.");
|
|
955
1135
|
const raw = await readFile(painted.path);
|
|
956
1136
|
if (raw.byteLength !== width * height * 4) throw new Error("LibreOffice native renderer returned incomplete pixels.");
|
|
957
|
-
const
|
|
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);
|
|
958
1144
|
total += png.byteLength;
|
|
959
1145
|
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
|
960
1146
|
const path = join(operation.outputDir, `page-${String(index).padStart(4, "0")}.png`);
|
|
@@ -1276,16 +1462,16 @@ function resolveOptions(input = {}) {
|
|
|
1276
1462
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1277
1463
|
const require = createRequire(import.meta.url);
|
|
1278
1464
|
/** Node API release version returned by runtime discovery. */
|
|
1279
|
-
const ENGINE_VERSION = "0.1.
|
|
1465
|
+
const ENGINE_VERSION = "0.1.5";
|
|
1280
1466
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1281
1467
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1282
|
-
"darwin-arm64": "0.1.
|
|
1283
|
-
"darwin-x64": "0.1.
|
|
1468
|
+
"darwin-arm64": "0.1.5",
|
|
1469
|
+
"darwin-x64": "0.1.5",
|
|
1284
1470
|
"linux-arm64-glibc": "0.1.1",
|
|
1285
1471
|
"linux-x64-glibc": "0.1.1",
|
|
1286
|
-
"win32-arm64": "0.1.
|
|
1287
|
-
"win32-x64": "0.1.
|
|
1288
|
-
wasm: "0.1.
|
|
1472
|
+
"win32-arm64": "0.1.5",
|
|
1473
|
+
"win32-x64": "0.1.5",
|
|
1474
|
+
wasm: "0.1.5"
|
|
1289
1475
|
});
|
|
1290
1476
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1291
1477
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
package/lib/types/engine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Node API release version returned by runtime discovery. */
|
|
2
|
-
export declare const ENGINE_VERSION = "0.1.
|
|
2
|
+
export declare const ENGINE_VERSION = "0.1.5";
|
|
3
3
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
4
4
|
export declare const ENGINE_VERSIONS: Readonly<Record<string, string>>;
|
|
5
5
|
/** Host diagnostic fields used to identify the runtime glibc version. */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Readable, Writable } from 'node:stream';
|
|
3
|
+
/** The helper owner observes closure only after both output pipes finish. */
|
|
4
|
+
export interface NativeChild extends EventEmitter {
|
|
5
|
+
stdin: Writable;
|
|
6
|
+
stdout: Readable;
|
|
7
|
+
stderr: Readable;
|
|
8
|
+
readonly exitCode: number | null;
|
|
9
|
+
readonly signalCode: NodeJS.Signals | null;
|
|
10
|
+
kill(signal: NodeJS.Signals): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Spawn with inherited token and Job restrictions; pipe creation never requests a new sandbox policy.
|
|
14
|
+
* @param executable - Verified native helper executable.
|
|
15
|
+
* @param args - Helper protocol arguments.
|
|
16
|
+
* @param env - Filtered operation environment.
|
|
17
|
+
* @returns Helper streams and process lifetime, with output drained before close.
|
|
18
|
+
*/
|
|
19
|
+
export declare function spawnNative(executable: string, args: string[], env: NodeJS.ProcessEnv): NativeChild;
|
|
20
|
+
//# sourceMappingURL=native-process.d.ts.map
|
package/lib/types/native.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { ResolvedOptions } from './options.ts';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function prepareNativeFontProfile(profile: string, substitutions: readonly FontSubstitution[]): Promise<void>;
|
|
13
13
|
/**
|
|
14
|
+
* Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
|
|
14
15
|
* Linux searches the verified program directory; ambient loader overrides and credentials are excluded.
|
|
15
16
|
* @param profile - Conversion-owned profile directory the helper treats as home.
|
|
16
17
|
* @param programDirectory - Verified engine program directory.
|
package/lib/types/rendering.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface RasterTile {
|
|
|
22
22
|
readonly height: number;
|
|
23
23
|
readonly rgba: Uint8ClampedArray;
|
|
24
24
|
}
|
|
25
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
26
|
+
export declare function unmirrorRtlTile({ width, height, rgba }: RasterTile): void;
|
|
25
27
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
26
28
|
export declare function splitRasterRectangle(rectangle: Rectangle, scale: number, limits: {
|
|
27
29
|
readonly maxPixels: number;
|
|
@@ -32,7 +32,7 @@ export declare function parseCellRange(value: string): CellRange;
|
|
|
32
32
|
export declare function sheetPartInfo(value: string): SheetPartInfo;
|
|
33
33
|
/** Formatting-only cells and standalone drawings do not enlarge LibreOffice's data area. */
|
|
34
34
|
export declare function dataArea(info: SheetPartInfo): CellRange;
|
|
35
|
-
/** Logical columns advance from A;
|
|
35
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
36
36
|
export declare function sheetRangeRectangle(geometry: SheetGeometry, range: CellRange, scale: number): Rectangle;
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=sheet-geometry.d.ts.map
|
package/lib/worker.js
CHANGED
|
@@ -860,6 +860,17 @@ async function convertWithWasm(request) {
|
|
|
860
860
|
};
|
|
861
861
|
});
|
|
862
862
|
}
|
|
863
|
+
/** Undo Calc's RTL transport mirroring so saved pixels contain readable text and right-to-left columns. */
|
|
864
|
+
function unmirrorRtlTile({ width, height, rgba }) {
|
|
865
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < Math.floor(width / 2); x++) {
|
|
866
|
+
const left = (y * width + x) * 4, right = (y * width + width - 1 - x) * 4;
|
|
867
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
868
|
+
const value = rgba[left + channel];
|
|
869
|
+
rgba[left + channel] = rgba[right + channel];
|
|
870
|
+
rgba[right + channel] = value;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
863
874
|
/** Split a region on its output-pixel grid, bounding the plan before allocating it. */
|
|
864
875
|
function splitRasterRectangle(rectangle, scale, limits) {
|
|
865
876
|
const { x, y, width, height } = rectangle;
|
|
@@ -1121,7 +1132,7 @@ function dimension(data, first, last, maximum, scale) {
|
|
|
1121
1132
|
}
|
|
1122
1133
|
return [start / scale, (position - start) / scale];
|
|
1123
1134
|
}
|
|
1124
|
-
/** Logical columns advance from A;
|
|
1135
|
+
/** Logical columns advance from A; RTL uses the same coordinates and mirrored transport pixels. */
|
|
1125
1136
|
function sheetRangeRectangle(geometry, range, scale) {
|
|
1126
1137
|
if (!Number.isFinite(scale) || scale <= 0 || scale > 16) throw new TypeError("Invalid worksheet raster scale.");
|
|
1127
1138
|
const [x, width] = dimension(geometry.columns, range.firstColumn, range.lastColumn, MAX_COLUMN, scale);
|
|
@@ -1357,6 +1368,7 @@ async function renderImagesWithWasm(request) {
|
|
|
1357
1368
|
...region.rectangle,
|
|
1358
1369
|
scale
|
|
1359
1370
|
}, [region.page], () => engineError(session.module, session.office), session.pdf);
|
|
1371
|
+
if (region.rtl) unmirrorRtlTile(tile);
|
|
1360
1372
|
const png = encodePng(tile.width, tile.height, tile.rgba);
|
|
1361
1373
|
total += png.length;
|
|
1362
1374
|
if (total > options.maxOutputBytes) throw new ConversionError("output-too-large", "PNG batch exceeds maxOutputBytes.");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/libreoffice-kit",
|
|
3
3
|
"description": "Convert, recalculate, and render Office documents with prebuilt LibreOffice",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"license": "MPL-2.0",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "
|
|
17
|
+
"url": "https://github.com/deepseek-ai/dsh-libreoffice-kit",
|
|
18
18
|
"directory": "packages/entry"
|
|
19
19
|
},
|
|
20
|
+
"homepage": "https://github.com/deepseek-ai/dsh-libreoffice-kit",
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|
|
22
23
|
"types": "./lib/types/index.d.ts",
|
|
@@ -37,14 +38,15 @@
|
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"fflate": "0.8.2",
|
|
39
40
|
"fontkit": "2.0.4",
|
|
41
|
+
"koffi": "3.1.1",
|
|
40
42
|
"saxes": "6.0.0"
|
|
41
43
|
},
|
|
42
44
|
"optionalDependencies": {
|
|
43
|
-
"@deepseek-ai/libreoffice-kit-darwin-arm64": "0.1.
|
|
44
|
-
"@deepseek-ai/libreoffice-kit-win32-x64": "0.1.
|
|
45
|
-
"@deepseek-ai/libreoffice-kit-
|
|
46
|
-
"@deepseek-ai/libreoffice-kit-
|
|
47
|
-
"@deepseek-ai/libreoffice-kit-win32-arm64": "0.1.
|
|
45
|
+
"@deepseek-ai/libreoffice-kit-darwin-arm64": "0.1.5",
|
|
46
|
+
"@deepseek-ai/libreoffice-kit-win32-x64": "0.1.5",
|
|
47
|
+
"@deepseek-ai/libreoffice-kit-darwin-x64": "0.1.5",
|
|
48
|
+
"@deepseek-ai/libreoffice-kit-wasm": "0.1.5",
|
|
49
|
+
"@deepseek-ai/libreoffice-kit-win32-arm64": "0.1.5"
|
|
48
50
|
},
|
|
49
51
|
"bin": {
|
|
50
52
|
"dsoffice": "./lib/cli.js"
|