@deepseek-ai/libreoffice-kit 0.1.5 → 0.2.0-alpha5
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/NOTICE +4 -0
- package/README.md +44 -8
- package/README.zh.md +45 -9
- package/lib/cli.js +109 -46
- package/lib/editor.js +2061 -0
- package/lib/index.js +109 -46
- package/lib/types/editor-protocol.d.ts +29 -0
- package/lib/types/editor-transport.d.ts +36 -0
- package/lib/types/editor-types.d.ts +119 -0
- package/lib/types/editor.d.ts +105 -0
- package/lib/types/engine.d.ts +4 -2
- package/lib/types/fonts.d.ts +4 -8
- package/lib/types/native-image-renderer.d.ts +0 -1
- package/lib/types/native-process.d.ts +1 -0
- package/lib/types/native.d.ts +30 -2
- package/lib/types/runtime.d.ts +2 -0
- package/lib/types/worker.d.ts +2 -2
- package/lib/worker.js +38 -31
- package/native-render/CMakeLists.txt +40 -0
- package/native-render/LICENSE +21 -0
- package/native-render/README.md +83 -0
- package/native-render/README.zh.md +83 -0
- package/native-render/include/dsh_render.h +101 -0
- package/native-render/include/dsh_render_engine.h +66 -0
- package/native-render/include/dsh_render_node.h +27 -0
- package/native-render/include/dsh_webgpu.h +52 -0
- package/native-render/index.d.ts +145 -0
- package/native-render/index.mjs +71 -0
- package/native-render/lib/browser/display.d.ts +46 -0
- package/native-render/lib/browser/display.js +128 -0
- package/native-render/lib/browser/index.d.ts +4 -0
- package/native-render/lib/browser/index.js +3 -0
- package/native-render/lib/browser/painters.d.ts +9 -0
- package/native-render/lib/browser/painters.js +180 -0
- package/native-render/lib/browser/types.d.ts +51 -0
- package/native-render/lib/browser/types.js +1 -0
- package/native-render/lib/electron/adapter.d.ts +9 -0
- package/native-render/lib/electron/adapter.js +118 -0
- package/native-render/lib/electron/index.d.ts +3 -0
- package/native-render/lib/electron/index.js +3 -0
- package/native-render/lib/electron/preload.d.ts +13 -0
- package/native-render/lib/electron/preload.js +47 -0
- package/native-render/lib/electron/transfer.d.ts +15 -0
- package/native-render/lib/electron/transfer.js +36 -0
- package/native-render/prebuilds/darwin-arm64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-arm64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-arm64/render.node +0 -0
- package/native-render/prebuilds/darwin-x64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-x64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-x64/render.node +0 -0
- package/native-render/prebuilds/win32-arm64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-arm64/manifest.json +34 -0
- package/native-render/prebuilds/win32-arm64/render.node +0 -0
- package/native-render/prebuilds/win32-x64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-x64/manifest.json +34 -0
- package/native-render/prebuilds/win32-x64/render.node +0 -0
- package/native-render/receipt.json +23 -0
- package/native-render/scripts/build-webgpu.mjs +197 -0
- package/native-render/scripts/build.mjs +43 -0
- package/native-render/scripts/metadata.mjs +47 -0
- package/native-render/scripts/source-identity.mjs +15 -0
- package/native-render/scripts/verify-prebuilds.mjs +14 -0
- package/native-render/sdk.json +45 -0
- package/native-render/src/node-producer.cc +595 -0
- package/native-render/src/producer-internal.h +8 -0
- package/native-render/src/producer.cc +306 -0
- package/native-render/src/receiver.cc +1050 -0
- package/native-render/src/relay-transport.inc +293 -0
- package/native-render/src/transport.cc +405 -0
- package/native-render/src/transport.h +80 -0
- package/native-render/src/webgpu.cc +214 -0
- package/native-render/src/win-delay-load.LICENSE +24 -0
- package/native-render/src/win-delay-load.cc +43 -0
- package/native-render/verify.d.mts +4 -0
- package/native-render/verify.mjs +101 -0
- package/native-render/webgpu-dependencies.json +51 -0
- package/package.json +95 -10
package/NOTICE
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
Browser presentation, Electron texture transfer and adapter detection, and GPU diagnostic examples originate from MIT-licensed DeepSeek Harness commit 21261bee8b9a820c62c9e42cade3ff644b747a29. They retain the native-render/LICENSE notice.
|
|
2
|
+
|
|
3
|
+
The native-render subpaths contain MIT-licensed SDK sources from DeepSeek Harness at commit 4438b67c13d529c9882d89893ed5cd610ace11cc, integrated with the LibreOffice Kit WebGPU adapter from commit 2ae2de8c7e88df00e74ee538ebd5662f47c7a1df. The SDK retains its MIT license in native-render/LICENSE. The Windows Node delay-load implementation retains its separate notice in native-render/src/win-delay-load.LICENSE. Native-render does not require the LibreOffice engine.
|
|
4
|
+
|
|
1
5
|
LibreOffice Kit incorporates font handling and conversion integration derived from DeepSeek Harness. These portions retain the following notice. LibreOffice engine sources and their separate third-party notices are distributed in the engine packages.
|
|
2
6
|
|
|
3
7
|
The adapter's src/native-font-names.ts contains font-name data derived from LibreOffice Core's unotools/source/misc/fontdefs.cxx at commit bce0998afefdbc355585ca324285661a2170ba77. That file retains the upstream Mozilla Public License 2.0 notice and the Apache Software Foundation notice for incorporated work licensed under the Apache License 2.0.
|
package/README.md
CHANGED
|
@@ -4,19 +4,21 @@ English | [中文](README.zh.md)
|
|
|
4
4
|
|
|
5
5
|
Convert, recalculate, and directly render local Office documents with prebuilt LibreOffice engines. Use the same API in a server, desktop application, or document-processing job, with configurable fonts, cancellation, and resource limits.
|
|
6
6
|
|
|
7
|
+
The conversion and native preview entry points can run together in one process, in either initialization order.
|
|
8
|
+
|
|
7
9
|
Binary `.doc`, `.xls`, and `.ppt` inputs must be OLE compound documents, such as Office 97–2003 files. Renamed RTF/HTML and `.wps` inputs are unsupported. `missingFonts` is empty for binary inputs because their font tables are interpreted by LibreOffice rather than the OOXML inspector.
|
|
8
10
|
|
|
9
|
-
The Node API version is independent of its platform engine versions.
|
|
11
|
+
The Node API version is independent of its platform engine versions. The 0.2.0-alpha5 adapter uses alpha5 macOS and Windows x64 engines, retains the Windows ARM64 0.1.5 engine, and uses a portable alpha5 WASM package containing the 0.1.5 engine files. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible engine versions. `discoverRuntime().nativePreview` distinguishes native preview support from PDF conversion. Missing native packages select WASM; malformed installed packages reject.
|
|
10
12
|
|
|
11
13
|
## Installation and usage
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Use Node.js 22.19.0 or newer. This command applies after alpha5 is published; unpublished candidates must be built and qualified from source first:
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
|
-
npm install @deepseek-ai/libreoffice-kit@0.
|
|
18
|
+
npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha5
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
npm installs the
|
|
21
|
+
npm installs the shared WASM engine and any matching native engine. The adapter prefers a compatible installed native engine, then selects WASM when no native package supports the host or the optional native package is absent. A corrupt installed package rejects with `unavailable`. Conversion failures never switch engines.
|
|
20
22
|
|
|
21
23
|
```js
|
|
22
24
|
import { createConverter } from '@deepseek-ai/libreoffice-kit';
|
|
@@ -54,11 +56,11 @@ Right-to-left worksheets produce readable PNG text with column A on the right. A
|
|
|
54
56
|
|
|
55
57
|
Conversion workers run the package's shipped JavaScript with an empty `execArgv`; consumer launch flags such as `--input-type=module` are not inherited.
|
|
56
58
|
|
|
57
|
-
Windows
|
|
59
|
+
Windows conversion, image-rendering, and persistent-editing helpers use anonymous stdio pipes and inherit the caller's token and Job restrictions. The pipes preserve binary pixel frames, and polling does not occupy libuv worker threads while a helper waits for commands. Closure waits for process exit and output drainage after cancellation and rejected worksheet selections, including when the protocol reader has paused stdout; this transport does not grant additional filesystem or network access.
|
|
58
60
|
|
|
59
61
|
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
62
|
|
|
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
|
|
63
|
+
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. Conversion, image rendering, and editing retain the helper paths until the child closes, including during startup failure; cleanup then unlinks the junction. A renderer that exits before returning a protocol response rejects with its exit status and captured diagnostics.
|
|
62
64
|
|
|
63
65
|
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.
|
|
64
66
|
|
|
@@ -66,11 +68,41 @@ The caller authorizes input access and owns private input/output directories; pa
|
|
|
66
68
|
|
|
67
69
|
`ConversionError.code` distinguishes `invalid-document`, `unsupported-format`, `input-too-large`, `output-too-large`, `invalid-output`, `timeout`, `unavailable`, and `failed`. These codes survive the worker/native transports. Invalid installation assets reject creation as `unavailable`; they never enable fallback. Filesystem errors such as `EEXIST`, invalid configuration errors, and caller cancellation reasons remain unchanged.
|
|
68
70
|
|
|
71
|
+
## Native editor
|
|
72
|
+
|
|
73
|
+
`@deepseek-ai/libreoffice-kit/editor` opens a persistent DOCX, XLSX, or PPTX document with `openDocument()`. The caller owns authorization, input bytes, rendering, and saved snapshots; `close()` joins the native process. Editing requires `writable: true`. The editor does not expose a browser document model or LibreOffice desktop windows.
|
|
74
|
+
|
|
75
|
+
`openDocument({ onProgress })` reports `fonts`, `engine`, and `document` when each loading stage begins. Observer failures become warnings. Rendering can start only after the returned promise resolves; the callback does not make LibreOffice import incremental.
|
|
76
|
+
|
|
77
|
+
Native document loading sends owned bytes over the helper's stdin into a seekable UNO `InputStream` with `private:stream`; it does not create an input document file. Conversion and image rendering read the caller's input path once and pass bytes to both the inspection worker and the native loader. The standard LibreOfficeKit URL-only loader cannot supply this stream: the bundled Core adds a private memory-loading entry. Missing that entry fails instead of writing a fallback file. Profile/font files, save/export outputs, and LibreOffice's internal repair or storage temporaries are separate; this is not a guarantee of zero filesystem activity. WASM uses its in-memory filesystem.
|
|
78
|
+
|
|
79
|
+
`renderBackend` selects the native drawing backend. The default `"auto"` enables LibreOffice's Skia Ganesh GPU path, which uses Vulkan on Windows and Metal on macOS, and keeps CPU drawing when the driver is denylisted, the GPU context cannot start, or shared-image import fails its initialization probe; `getInfo().renderBackend` reports the backend actually in use, so callers can surface that fallback. `"ganesh"` requires the GPU backend and rejects the open when it is unavailable, `"graphite"` initializes a native Dawn device before loading the document and binds each final output device directly to a borrowed SDK texture, and `"raster"` forces CPU rendering. `graphiteCacheBytes` defaults to 128 MiB, divided between the Graphite context and recorder caches; live/inflight allocations and SDK display textures are outside this cache budget. Forced-backend creation failures reject opening; shared rendering failures do not select another backend or close the document. The owner may export the current in-memory document and explicitly open a raster replacement.
|
|
80
|
+
|
|
81
|
+
When migrating from 0.1.3 to the 0.2.0 preview, update the Node adapter and its exact platform engines together; engines from 0.1.3 cannot serve the new editor startup options. Existing conversion calls keep their behavior, while editor calls that need the previous CPU path must set `renderBackend: "raster"`; omission now selects `"auto"`. Opt into `graphite` when opening a desktop document and retain the same shared receiver attachment, input ordering and release responsibilities. Changing backends requires a new process: export the current in-memory snapshot, open its replacement with `renderBackend: "raster"` before closing the old editor, and restore the view in the owner. The snapshot preserves document content, not the old undo/redo stack or running slideshow state. If export or replacement initialization fails, retain the old editor and its unsaved document.
|
|
82
|
+
|
|
83
|
+
Devices without a usable Graphite backend reject initialization; Linux development native engines support raster only. Borrowed WebGPU objects remain in the native document process; no device is passed through Node or a browser. Dawn manages GPU submission and completion, while the native SDK manages shared access across processes, frame credits, and consumer release. Submitting a WebGPU queue alone does not mean a display consumer has finished using an image.
|
|
84
|
+
|
|
85
|
+
Opening requires editor protocol 4 and native-render protocol 1 from the installed engine. A missing or incompatible protocol rejects initialization without selecting another engine.
|
|
86
|
+
|
|
87
|
+
`getSelection()` returns plain text or HTML for the active selection. Native JSON replies use `maxOutputBytes` with a 1 MiB minimum; a reply exceeding that budget rejects the operation while keeping the document open. Escape cancels selection even with modifiers and does not open native command popups.
|
|
88
|
+
|
|
89
|
+
`setViewport()` sets the actual visible rectangle in twips and the client pixel/twip scale. Writer opens in print layout; zooming and resizing the viewport preserve its page geometry and line breaks. Impress text selection uses the active cell's line-height settings for rendering and hit testing, including merged cells and vertical alignment.
|
|
90
|
+
|
|
91
|
+
`render()` and `renderSurface()` accept an optional zero-based `part` in the paint rectangle for background presentation slides. These requests use a lazily created, read-only view of the existing document, preserve the active part and selection, and restore the active view before accepting further input. Word pages use their document rectangles. Both operations require slideshow playback to be stopped. Opening still completes native import and pagination before rendering can begin.
|
|
92
|
+
|
|
93
|
+
`render()` and `presentationFrame()` return tightly packed straight RGBA in a dedicated buffer that later renders never reuse. The native worker normalizes document tiles in place; opaque slideshow frames already use this format. The adapter validates dimensions and the explicit pixel format without copying or converting the returned pixels.
|
|
94
|
+
|
|
95
|
+
`input()` and `dispatch()` submit ordered input and whitelisted editing commands. `exportSnapshot()` returns original-format bytes with their format and revision; the caller saves them. Opening copies the input bytes, and editing or exporting never overwrites the caller's source. Read-only documents reject mutations and snapshot export. An abort signal ends the document lifetime; call `close()` to await cleanup even after an operation fails.
|
|
96
|
+
|
|
97
|
+
Desktop applications that need shared images can bind a trusted native receiver to `processId`, then use `attachSurfaceTransport()`, `renderSurface()`, or `presentationSurface()`. Replies carry correlation fields while the separate SDK transports the image; the receiver releases each frame after its display consumer finishes. `waitForInput()` orders commands or exports after the requested input sequence. `detachSurfaceTransport()` retains the document. A healthy device can still serve RGBA requests, but detaching does not change the backend and Graphite pixel requests require readback. Raster reads tiles into a CPU buffer and uploads them into the SDK texture. Ganesh reuses LibreOffice's existing GPU context and copies its final image into the SDK texture with Metal blits or Vulkan external-memory copies; Windows allocates that texture on the Vulkan device's matching D3D11 adapter. Ganesh and Graphite shared output skip final-target CPU readback; document features may still need internal bitmap reads or asset uploads.
|
|
98
|
+
|
|
99
|
+
Continuous presentation streams acquire and publish only when the slideshow requests a canvas update. Static or paused slides retain their last image without consuming additional frame credits. A pending change survives unavailable credits; the next successful frame includes the latest state, including an animation's final frame. Starting a stream or changing its viewport forces a frame. Explicit `presentationFrame()` and `presentationSurface()` calls still return a frame on every request; document views paint only on explicit requests.
|
|
100
|
+
|
|
69
101
|
## Engines, fonts, and runtime behavior
|
|
70
102
|
|
|
71
103
|
The Node API reports its release version through `ENGINE_VERSION`; `ENGINE_VERSIONS` pins each platform engine independently. npm installs prepared engines; installation and conversion never compile LibreOffice or download additional engine payloads. Each engine includes its matching source recipes, patches, build information, and third-party license notices under `sources/` and `licenses/`.
|
|
72
104
|
|
|
73
|
-
Defaults and all options are documented in the shipped TypeScript declarations in `lib/types/index.d.ts`. Font directories use conventional system/user paths for the selected OS. Indexing skips missing or protected sources and propagates other filesystem errors. `fontkit` indexes original font files and selects installed faces and glyph coverage; it does not rewrite fonts. Each operation discovers font candidates again and revalidates cached file identities. It uses one ordered metadata snapshot; matching entries are invalidated when that snapshot changes. A detected font change during conversion rejects the operation and removes its output.
|
|
105
|
+
Defaults and all options are documented in the shipped TypeScript declarations in `lib/types/index.d.ts`. Font directories use conventional system/user paths for the selected OS. Indexing skips missing or protected sources and propagates other filesystem errors. `fontkit` indexes original font files and selects installed faces and glyph coverage; it does not rewrite fonts. Each operation discovers font candidates again and revalidates cached file identities. It uses one ordered metadata snapshot; matching entries are invalidated when that snapshot changes. A detected font change during conversion rejects the operation and removes its output. Glyph matching queries only requested Unicode scalars and shares decoding across faces in one physical font collection. It retains scalar answers within the operation and releases each parsed file before examining another; it does not enumerate every glyph or cache font bytes across documents. `missingFonts` contains absent families declared in readable document XML, excluding unrelated engine defaults. Missing glyphs without a named missing family are not a complete document accessibility report.
|
|
74
106
|
|
|
75
107
|
### Font metadata cache
|
|
76
108
|
|
|
@@ -112,4 +144,8 @@ This package is licensed under [MPL-2.0](LICENSE). The engine packages include `
|
|
|
112
144
|
- Font import and output limits do not bound all native memory or temporary disk use. Native platform engines may resolve fonts differently from WASM.
|
|
113
145
|
- Installations from npm use platform-specific optional packages. Applications that bundle engines must retain the complete selected package, including its resources and notices.
|
|
114
146
|
- Windows requires the Microsoft Visual C++ v14 Redistributable matching the Node.js architecture (x64 or ARM64); it is not bundled. Use ARM64 Node.js for the Windows ARM64 engine.
|
|
115
|
-
-
|
|
147
|
+
- The preview declares macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine for Linux. Other native platforms are development recipes.
|
|
148
|
+
|
|
149
|
+
## Native rendering SDK
|
|
150
|
+
|
|
151
|
+
`@deepseek-ai/libreoffice-kit/native-render` provides the standalone Node producer/receiver and C/C++ SDK for macOS and Windows x64/ARM64. Install with `--omit=optional` when LibreOffice engines are not needed. All four addons and static libraries ship in the main Kit package. `./native-render/sdk` describes source and library paths, and `./native-render/verify` checks complete SDK payloads. Installation and normal runtime do not compile or download native code. See the [SDK documentation](../native-render/README.md) for ownership and explicit diagnostic builds.
|
package/README.zh.md
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
使用预编译 LibreOffice 引擎,在 Node.js 中转换、重算并直接渲染本地 Office 文档。通过同一套 API,为服务端、桌面应用和文档处理任务提供可配置字体、取消和资源限制。
|
|
6
6
|
|
|
7
|
+
转换与原生预览入口可在同一进程中同时使用,不受初始化顺序影响。
|
|
8
|
+
|
|
7
9
|
二进制 `.doc`、`.xls`、`.ppt` 输入必须是 OLE 复合文档,例如 Office 97–2003 文件。不支持改后缀的 RTF/HTML 和 `.wps`。二进制输入的 `missingFonts` 为空,因为其字体表由 LibreOffice 读取,而不是由 OOXML 检查器读取。
|
|
8
10
|
|
|
9
|
-
Node API 与各平台引擎独立指定版本。0.
|
|
11
|
+
Node API 与各平台引擎独立指定版本。0.2.0-alpha5 转换器使用 alpha5 的 macOS 与 Windows x64 引擎,保留 Windows ARM64 的 0.1.5 引擎,并使用包含 0.1.5 引擎文件的通用 alpha5 WASM 包。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。`discoverRuntime().nativePreview` 区分原生预览与 PDF 转换能力。缺少原生包时选择 WASM;已安装的包损坏时拒绝。
|
|
10
12
|
|
|
11
13
|
## 安装与使用
|
|
12
14
|
|
|
13
|
-
使用 Node.js 22.19.0
|
|
15
|
+
使用 Node.js 22.19.0 或更新版本。以下命令适用于已发布的 alpha5 包;未发布的候选包需先从源码构建并验证:
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
|
-
npm install @deepseek-ai/libreoffice-kit@0.
|
|
18
|
+
npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha5
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
npm
|
|
20
|
-
|
|
21
|
-
在 Linux 上安装共享 WASM 引擎。macOS 和 Windows 必须具有对应原生包;包缺失或无效时,`createConverter` 以 `unavailable` 拒绝,不会切换到 WASM。Linux 使用 WASM,除非显式安装了兼容的原生开发包。转换失败不会切换引擎。
|
|
21
|
+
npm 安装共享 WASM 引擎和匹配平台的原生引擎。转换器优先使用已安装且兼容的原生引擎;平台没有原生包或可选原生包未安装时选择 WASM。已安装的包损坏时以 `unavailable` 拒绝。转换失败不会切换引擎。
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
24
|
import { createConverter } from '@deepseek-ai/libreoffice-kit';
|
|
@@ -56,21 +56,53 @@ npm exec -- dsoffice recalculate --input budget.xlsx --output recalculated.xlsx
|
|
|
56
56
|
|
|
57
57
|
转换 worker 以空的 `execArgv` 运行包内发布的 JavaScript;`--input-type=module` 之类的调用方启动参数不会被继承。
|
|
58
58
|
|
|
59
|
-
Windows
|
|
59
|
+
Windows 的转换、图像渲染和持久编辑 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。管道保持二进制像素帧完整,helper 等待命令时的管道轮询不会占用 libuv 工作线程。取消及工作表选择失败后,关闭会等待进程退出并读完输出,包括协议读取器已暂停 stdout 的情况;此传输方式不授予额外的文件系统或网络权限。
|
|
60
60
|
|
|
61
61
|
原生转换和图片渲染 helper 设置 `SAL_DISABLE_PRINTERLIST=1` 与 `SAL_DISABLE_DEFAULTPRINTER=1`,禁用打印机枚举和默认打印机查询。文档预览和导出不需要实体打印机;这些子进程设置可避免打印机驱动弹窗及网络打印机连接等待,不会修改系统打印机设置。
|
|
62
62
|
|
|
63
|
+
Windows 上,引擎可执行文件或程序目录路径达到 260 个字符时,在私有操作目录中使用 helper 临时副本和指向已安装资源的 junction。转换、图像渲染和编辑均保留这些路径直到子进程退出,包括启动失败时;随后清理 junction。渲染器若在返回协议响应前退出,会携带退出状态和捕获的诊断信息拒绝操作。
|
|
64
|
+
|
|
63
65
|
在 Linux 上,原生子进程会先在所选引擎的 program 目录中查找共享库,然后才查找系统路径。调用方提供的 `LD_LIBRARY_PATH` 和 `LD_PRELOAD` 不会被继承。
|
|
64
66
|
|
|
65
67
|
调用方负责授权输入访问并拥有私有输入/输出目录;路径必须是绝对路径,并在转换期间保持不变。输入文件必须是常规 Office 文件,且在配置的字节限制之内。ZIP 条目数和解压大小限制适用于 OOXML;二进制 DOC/XLS/PPT 使用 OLE 复合容器,内部结构由 LibreOffice 导入器验证。二进制格式仍遵守相同的转换超时和输入/输出限制。输出创建使用独占模式和 `0600` 权限;已存在的输出绝不会被覆盖。失败或取消的渲染会删除新建的输出。`maxOutputBytes` 限制返回的 PDF 及其读取缓冲区;原生临时磁盘文件在导出完成前可能继续增长,随后过大的 PDF 会在 Node 读取之前被拒绝并删除。成功的 PDF 归调用方所有,调用方可以将其字节发送给浏览器 PDF 阅读器。
|
|
66
68
|
|
|
67
69
|
`ConversionError.code` 区分 `invalid-document`、`unsupported-format`、`input-too-large`、`output-too-large`、`invalid-output`、`timeout`、`unavailable` 和 `failed`。这些 code 会原样穿过 worker 和原生传输层。无效的安装资源会让创建以 `unavailable` 拒绝;它们绝不会启用回退。`EEXIST` 等文件系统错误、无效配置错误和调用方取消原因保持原样。
|
|
68
70
|
|
|
71
|
+
## 原生编辑器
|
|
72
|
+
|
|
73
|
+
`@deepseek-ai/libreoffice-kit/editor` 通过 `openDocument()` 打开常驻的 DOCX、XLSX 或 PPTX 文档。调用方负责访问授权、输入字节、绘制和保存快照;`close()` 会等待原生进程退出。编辑需要设置 `writable: true`。编辑器不提供浏览器文档模型或 LibreOffice 桌面窗口。
|
|
74
|
+
|
|
75
|
+
`openDocument({ onProgress })` 在各加载阶段开始时报告 `fonts`、`engine` 和 `document`。观察函数抛错会转为警告。只有返回的 Promise 完成后才能开始绘制;该回调不会让 LibreOffice 导入变为渐进式。
|
|
76
|
+
|
|
77
|
+
原生文档加载将自有 bytes 通过 helper 的 stdin 传入可寻址的 UNO `InputStream`,以 `private:stream` 打开,不创建输入文档文件。转换和图像渲染读取一次调用方输入路径,将 bytes 传给检查 worker 和原生加载器。标准 LibreOfficeKit 加载接口只接受 URL,无法传入流;内置 Core 增加私有内存加载入口,缺少该入口会明确失败,不回退到写文件。配置与字体文件、保存与导出输出,以及 LibreOffice 内部修复或存储临时文件另行管理;这不代表完全没有文件系统活动。WASM 使用内存文件系统。
|
|
78
|
+
|
|
79
|
+
`renderBackend` 选择原生绘制后端。默认 `"auto"` 启用 LibreOffice 的 Skia Ganesh GPU 路径(Windows 用 Vulkan,macOS 用 Metal);当驱动进入黑名单或 GPU 上下文无法启动时保持 CPU 绘制,`getInfo().renderBackend` 返回实际使用的后端,便于调用方显式告警。`"ganesh"` 强制要求 GPU 后端,不可用时直接拒绝打开;`"graphite"` 在加载文档前初始化原生 Dawn device,并把最终输出设备直接绑定到 SDK 借用的纹理;`"raster"` 强制 CPU 绘制。`graphiteCacheBytes` 默认 128 MiB,分别分配给 Graphite context 和 recorder 缓存;正在使用或执行中的 GPU 分配以及 SDK 显示纹理不计入该缓存预算。强制指定的后端创建失败会拒绝打开文档;共享绘制失败不会切换后端或关闭文档。调用方可以导出当前内存文档,再显式打开 raster 替代进程。
|
|
80
|
+
|
|
81
|
+
从 0.1.3 迁移到 0.2.0 预览版时,需要同时更新 Node adapter 和其精确匹配的平台引擎;0.1.3 引擎不能处理新增的编辑器启动选项。现有转换调用保持原有行为;需要此前 CPU 路径的编辑器调用必须设置 `renderBackend: "raster"`,因为省略它现在会选择 `"auto"`。打开桌面文档时可显式选择 `graphite`,共享 receiver 连接、输入顺序和释放责任保持一致。切换后端需要新进程:先导出当前内存快照,在旧编辑器关闭前用 `renderBackend: "raster"` 打开替代进程,并由调用方恢复视图。快照保留文档内容,但不保留旧的撤销/重做历史或正在运行的放映。导出或替代进程初始化失败时,应保留旧编辑器及其未保存文档。
|
|
82
|
+
|
|
83
|
+
Graphite 后端不可用的设备会拒绝初始化;Linux 原生开发引擎仅支持 raster。共享绘制借用的 WebGPU 对象留在原生文档进程内,不通过 Node 或浏览器传递 device。GPU 提交和完成由 Dawn 管理,跨进程共享访问、帧配额和消费者释放仍由原生 SDK 管理。单独提交 WebGPU queue 不表示显示消费者已使用完该图像。
|
|
84
|
+
|
|
85
|
+
打开文档要求已安装的引擎提供编辑器协议 4 和 native-render 协议 1。缺失或不兼容的协议会使初始化失败,不会选择其他引擎。
|
|
86
|
+
|
|
87
|
+
`getSelection()` 返回当前选区的纯文本或 HTML。原生 JSON 回复以 `maxOutputBytes` 为预算,最低为 1 MiB;超出预算时只拒绝当前操作,文档保持打开。Escape 即使带有修饰键也只取消选择,不打开原生命令弹窗。
|
|
88
|
+
|
|
89
|
+
`setViewport()` 接收以 twip 为单位的实际可见区域和客户端像素/twip 比例。Writer 以打印布局打开;缩放和调整视口大小会保持纸张尺寸与换行。Impress 在文字选择的绘制和点击命中计算中使用当前单元格的行高设置,支持合并单元格与垂直对齐。
|
|
90
|
+
|
|
91
|
+
`render()` 和 `renderSurface()` 的绘制矩形可携带从零开始的 `part`,用于后台渲染幻灯片。此请求按需创建同一文档的只读视图,保留活动页和选区,并在接收后续输入前恢复活动视图。Word 页面使用其文档矩形坐标。两种绘制都要求先停止演示播放;打开文档仍需完成原生导入和分页后才能开始渲染。
|
|
92
|
+
|
|
93
|
+
`render()` 和 `presentationFrame()` 返回紧密排列、非预乘的 RGBA,使用后续渲染不会复用的独立缓冲区。原生 worker 原地转换文档图块;不透明的幻灯片播放帧本身已使用此格式。适配器校验尺寸和显式像素格式,不复制或转换返回的像素。
|
|
94
|
+
|
|
95
|
+
`input()` 和 `dispatch()` 按顺序提交输入与允许的编辑命令;`exportSnapshot()` 返回包含格式和修订号的原格式字节,调用方负责保存。打开时会复制输入字节,编辑和导出不会覆盖调用方源文件。只读文档拒绝修改和快照导出。取消信号结束文档生命周期;即使操作失败,也应调用 `close()` 等待清理。
|
|
96
|
+
|
|
97
|
+
需要共享图像的桌面应用可通过 `processId` 绑定可信原生接收端,再调用 `attachSurfaceTransport()`、`renderSurface()` 或 `presentationSurface()`。回复只包含关联信息,图像由独立 SDK 传输;接收端在显示消费者完成使用后释放帧。`waitForInput()` 可让命令或导出等待对应输入序号;`detachSurfaceTransport()` 保留文档;设备健康时可继续请求 RGBA 输出,但它不会更换后端,Graphite 的像素请求仍需要回读。Raster 将 tile 回读到 CPU 缓冲区,再上传到 SDK 纹理。Ganesh 复用 LibreOffice 的 GPU 上下文,通过 Metal blit 或 Vulkan 外部内存复制将最终图像送入 SDK 纹理;Windows 在与 Vulkan 设备匹配的 D3D11 适配器上分配纹理。Ganesh 和 Graphite 的共享输出均跳过最终目标的 CPU 回读。文档功能仍可能要求内部位图回读或素材上传。
|
|
98
|
+
|
|
99
|
+
连续放映流仅在幻灯片请求 canvas 更新时申请并提交帧。静止或暂停时保留最后一张图像,不消耗额外帧额度。等待可用额度期间会保留变化,下一次成功提交包含最新状态及动画末帧。启动流或更改视口会强制输出一帧。显式调用 `presentationFrame()` 和 `presentationSurface()` 仍每次返回一帧;文档视图仅在显式请求时绘制。
|
|
100
|
+
|
|
69
101
|
## 引擎、字体与运行行为
|
|
70
102
|
|
|
71
103
|
Node API 通过 `ENGINE_VERSION` 报告其发布版本;`ENGINE_VERSIONS` 独立固定各平台的引擎版本。npm 安装预编译引擎;安装和转换阶段均不会编译 LibreOffice 或额外下载引擎资源。每个引擎包的 `sources/` 和 `licenses/` 保留匹配的源码配方、补丁、构建信息和第三方许可声明。
|
|
72
104
|
|
|
73
|
-
默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit`
|
|
105
|
+
默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。字形匹配仅查询请求中的 Unicode 码点,同一物理字体集合中的各字面共享一次解码。码点查询结果只在本次操作内保留,开始检查下一文件前释放当前解析对象;不会遍历所有字形,也不会跨文档缓存字体字节。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
|
|
74
106
|
|
|
75
107
|
### 字体元数据缓存
|
|
76
108
|
|
|
@@ -112,4 +144,8 @@ Node WASM 的图像降采样使用 LibreOffice 的 CPU 图像过滤器。文本
|
|
|
112
144
|
- 字体导入和输出限制不能约束全部原生内存或临时磁盘使用。原生平台引擎的字体解析可能与 WASM 不同。
|
|
113
145
|
- npm 安装使用按平台选择的可选包。自行打包引擎的应用需要保留所选包的完整内容,包括资源和许可声明。
|
|
114
146
|
- Windows 需要系统安装与 Node.js 架构一致的 Microsoft Visual C++ v14 Redistributable(x64 或 ARM64);包中不捆绑该运行库。Windows ARM64 引擎需要使用 ARM64 Node.js。
|
|
115
|
-
-
|
|
147
|
+
- 预览版声明 macOS 和 Windows 的 ARM64、x64 原生引擎,以及供 Linux 使用的共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
|
|
148
|
+
|
|
149
|
+
## 原生渲染 SDK
|
|
150
|
+
|
|
151
|
+
`@deepseek-ai/libreoffice-kit/native-render` 提供独立的 Node 生产者、接收者和 C/C++ SDK,支持 macOS、Windows 的 x64/ARM64。不需要 LibreOffice 引擎时可使用 `--omit=optional` 安装。四套插件及静态库均随 Kit 主包分发。`./native-render/sdk` 描述源码与库路径,`./native-render/verify` 校验完整 SDK。正常安装和运行不编译或下载原生二进制。资源所有权与显式诊断构建见 [SDK 文档](../native-render/README.zh.md)。
|
package/lib/cli.js
CHANGED
|
@@ -337,12 +337,17 @@ let pipeAttributes;
|
|
|
337
337
|
function windowsPipes() {
|
|
338
338
|
const koffi = createRequire(import.meta.url)("koffi");
|
|
339
339
|
const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
|
|
340
|
-
const attributes = pipeAttributes ??= koffi.struct(
|
|
340
|
+
const attributes = pipeAttributes ??= koffi.struct({
|
|
341
341
|
nLength: "uint32",
|
|
342
342
|
lpSecurityDescriptor: "void *",
|
|
343
343
|
bInheritHandle: "int"
|
|
344
344
|
});
|
|
345
|
-
const createPipe = kernel.func("
|
|
345
|
+
const createPipe = kernel.func("__stdcall", "CreatePipe", "int", [
|
|
346
|
+
koffi.out(koffi.pointer("void *")),
|
|
347
|
+
koffi.out(koffi.pointer("void *")),
|
|
348
|
+
koffi.pointer(attributes),
|
|
349
|
+
"uint32"
|
|
350
|
+
]);
|
|
346
351
|
const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
347
352
|
const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
|
|
348
353
|
const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
|
|
@@ -471,6 +476,9 @@ function spawnNative(executable, args, env) {
|
|
|
471
476
|
stdin = stdin;
|
|
472
477
|
stdout = output.readable;
|
|
473
478
|
stderr = error.readable;
|
|
479
|
+
get pid() {
|
|
480
|
+
return child.pid;
|
|
481
|
+
}
|
|
474
482
|
get exitCode() {
|
|
475
483
|
return child.exitCode;
|
|
476
484
|
}
|
|
@@ -704,7 +712,9 @@ const NATIVE_ENVIRONMENT_KEYS = [
|
|
|
704
712
|
"PATHEXT",
|
|
705
713
|
"LANG",
|
|
706
714
|
"LC_ALL",
|
|
707
|
-
"TZ"
|
|
715
|
+
"TZ",
|
|
716
|
+
"OFFICE_GRAPHITE_DIAGNOSTICS",
|
|
717
|
+
"OFFICE_LOAD_DIAGNOSTICS"
|
|
708
718
|
];
|
|
709
719
|
function fontSearchName(value) {
|
|
710
720
|
const name = value.replaceAll(/[\uff00-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 65248)).replaceAll(/[A-Z]/g, (character) => character.toLowerCase()).replaceAll(/[^a-z0-9;()\u0080-\uffff]/g, "");
|
|
@@ -756,34 +766,84 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
|
|
|
756
766
|
});
|
|
757
767
|
}
|
|
758
768
|
/**
|
|
759
|
-
*
|
|
769
|
+
* Prepare short Windows engine paths owned by the caller's private profile.
|
|
760
770
|
* @param engine - Verified engine installation; its resources remain in place.
|
|
761
771
|
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
762
|
-
* @
|
|
763
|
-
* @returns The operation result after removing the resource junction.
|
|
772
|
+
* @returns Engine paths and a release function to call once, after the helper closes and before removing the profile.
|
|
764
773
|
*/
|
|
765
|
-
async function
|
|
766
|
-
if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return
|
|
774
|
+
async function prepareNativeEngine(engine, profile) {
|
|
775
|
+
if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return {
|
|
776
|
+
engine,
|
|
777
|
+
release: async () => {}
|
|
778
|
+
};
|
|
767
779
|
const root = join(profile, "engine");
|
|
768
780
|
await symlink(engine.root, root, "junction");
|
|
769
781
|
try {
|
|
770
782
|
const executable = join(profile, "libreoffice-kit.exe");
|
|
771
783
|
await copyFile(engine.executable, executable, constants.COPYFILE_EXCL);
|
|
772
|
-
return
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
784
|
+
return {
|
|
785
|
+
engine: {
|
|
786
|
+
...engine,
|
|
787
|
+
root,
|
|
788
|
+
executable,
|
|
789
|
+
programDirectory: join(root, relative(engine.root, engine.programDirectory))
|
|
790
|
+
},
|
|
791
|
+
release: () => unlink(root)
|
|
792
|
+
};
|
|
793
|
+
} catch (error) {
|
|
779
794
|
await unlink(root);
|
|
795
|
+
throw error;
|
|
780
796
|
}
|
|
781
797
|
}
|
|
782
798
|
/**
|
|
799
|
+
* Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
|
|
800
|
+
* @param engine - Verified engine installation; its resources remain in place.
|
|
801
|
+
* @param profile - Private operation directory that owns the temporary executable and junction.
|
|
802
|
+
* @param run - Operation that settles only after its helper closes.
|
|
803
|
+
* @returns The operation result after removing the resource junction.
|
|
804
|
+
*/
|
|
805
|
+
async function withNativeEngine(engine, profile, run) {
|
|
806
|
+
const prepared = await prepareNativeEngine(engine, profile);
|
|
807
|
+
try {
|
|
808
|
+
return await run(prepared.engine);
|
|
809
|
+
} finally {
|
|
810
|
+
await prepared.release();
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Prepare the document transport accepted by the pinned helper.
|
|
815
|
+
* @param engine - Resolved helper and input protocol.
|
|
816
|
+
* @param input - Owned document bytes and validated format.
|
|
817
|
+
* @param profile - Private directory retained until the helper exits and removed by the operation owner.
|
|
818
|
+
* @param signal - Cancellation of input preparation.
|
|
819
|
+
* @returns Helper arguments and an optional binary stdin prefix.
|
|
820
|
+
*/
|
|
821
|
+
async function prepareNativeInput(engine, input, profile, signal) {
|
|
822
|
+
signal.throwIfAborted();
|
|
823
|
+
if (engine.legacyInputPath) {
|
|
824
|
+
const path = join(profile, `source.${input.format}`);
|
|
825
|
+
await writeFile(path, input.bytes, {
|
|
826
|
+
flag: "wx",
|
|
827
|
+
mode: 384,
|
|
828
|
+
signal
|
|
829
|
+
});
|
|
830
|
+
return { args: ["--input-path", path] };
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
args: [
|
|
834
|
+
"--input-bytes",
|
|
835
|
+
String(input.bytes.byteLength),
|
|
836
|
+
"--input-format",
|
|
837
|
+
input.format
|
|
838
|
+
],
|
|
839
|
+
bytes: input.bytes
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
783
843
|
* Run one native conversion and await bounded result transport.
|
|
784
844
|
* @param engine - Resolved native engine installation.
|
|
785
845
|
* @param options - Validated conversion limits.
|
|
786
|
-
* @param input -
|
|
846
|
+
* @param input - Owned source bytes and format; older pinned helpers receive a private input file.
|
|
787
847
|
* @param output - Private PDF path inside the conversion scratch directory.
|
|
788
848
|
* @param profile - Conversion-owned profile directory.
|
|
789
849
|
* @param fonts - Installed font files the helper may load.
|
|
@@ -802,11 +862,12 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
802
862
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
803
863
|
signal.throwIfAborted();
|
|
804
864
|
const env = nativeEnvironment(profile, engine.programDirectory);
|
|
865
|
+
const transport = await prepareNativeInput(engine, input, profile, signal);
|
|
866
|
+
signal.throwIfAborted();
|
|
805
867
|
const child = spawnNative(engine.executable, [
|
|
806
868
|
"--program-directory",
|
|
807
869
|
engine.programDirectory,
|
|
808
|
-
|
|
809
|
-
input,
|
|
870
|
+
...transport.args,
|
|
810
871
|
"--output-path",
|
|
811
872
|
output,
|
|
812
873
|
"--profile-directory",
|
|
@@ -822,7 +883,6 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
822
883
|
...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
|
|
823
884
|
...fonts.flatMap((path) => ["--font-file", path])
|
|
824
885
|
], env);
|
|
825
|
-
child.stdin.end();
|
|
826
886
|
let stdout = "";
|
|
827
887
|
let stderr = "";
|
|
828
888
|
let failure;
|
|
@@ -843,6 +903,11 @@ async function runNative(engine, options, input, output, profile, fonts, substit
|
|
|
843
903
|
child.stderr.on("data", (chunk) => {
|
|
844
904
|
stderr = (stderr + chunk).slice(-65536);
|
|
845
905
|
});
|
|
906
|
+
child.stdin.on("error", (error) => {
|
|
907
|
+
failure ??= error;
|
|
908
|
+
child.kill("SIGKILL");
|
|
909
|
+
});
|
|
910
|
+
child.stdin.end(transport.bytes);
|
|
846
911
|
try {
|
|
847
912
|
const code = await new Promise((resolve, reject) => {
|
|
848
913
|
child.once("error", (error) => {
|
|
@@ -998,19 +1063,22 @@ function plan(ready, request) {
|
|
|
998
1063
|
}
|
|
999
1064
|
/** Run one native image batch and write final PNGs only after each bounded paint succeeds. */
|
|
1000
1065
|
async function renderImagesWithNative(request) {
|
|
1001
|
-
const { engine, options,
|
|
1066
|
+
const { engine, options, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
|
|
1002
1067
|
signal.throwIfAborted();
|
|
1003
1068
|
await mkdir(profile, { mode: 448 });
|
|
1004
1069
|
await prepareNativeFontProfile(profile, substitutions);
|
|
1005
1070
|
return withNativeEngine(engine, profile, async (engine) => {
|
|
1071
|
+
const transport = await prepareNativeInput(engine, {
|
|
1072
|
+
bytes: source,
|
|
1073
|
+
format: operation.extension
|
|
1074
|
+
}, profile, signal);
|
|
1006
1075
|
signal.throwIfAborted();
|
|
1007
1076
|
const child = spawnNative(engine.executable, [
|
|
1008
1077
|
"--operation",
|
|
1009
1078
|
"render-images",
|
|
1010
1079
|
"--program-directory",
|
|
1011
1080
|
engine.programDirectory,
|
|
1012
|
-
|
|
1013
|
-
inputPath,
|
|
1081
|
+
...transport.args,
|
|
1014
1082
|
"--scratch-directory",
|
|
1015
1083
|
scratch,
|
|
1016
1084
|
"--profile-directory",
|
|
@@ -1050,6 +1118,11 @@ async function renderImagesWithNative(request) {
|
|
|
1050
1118
|
child.kill("SIGKILL");
|
|
1051
1119
|
};
|
|
1052
1120
|
signal.addEventListener("abort", abort, { once: true });
|
|
1121
|
+
child.stdin.on("error", (error) => {
|
|
1122
|
+
stopped ??= error;
|
|
1123
|
+
child.kill("SIGKILL");
|
|
1124
|
+
});
|
|
1125
|
+
if (transport.bytes) child.stdin.write(transport.bytes);
|
|
1053
1126
|
const next = async () => {
|
|
1054
1127
|
signal.throwIfAborted();
|
|
1055
1128
|
if (lines.length > 0) return lines.shift();
|
|
@@ -1464,16 +1537,16 @@ function resolveOptions(input = {}) {
|
|
|
1464
1537
|
/** Resolve installed, version-matched engine packages without downloads or compilation. */
|
|
1465
1538
|
const require = createRequire(import.meta.url);
|
|
1466
1539
|
/** Node API release version returned by runtime discovery. */
|
|
1467
|
-
const ENGINE_VERSION = "0.
|
|
1540
|
+
const ENGINE_VERSION = "0.2.0-alpha5";
|
|
1468
1541
|
/** Exact compatible engine versions; unchanged platforms retain their published packages. */
|
|
1469
1542
|
const ENGINE_VERSIONS = Object.freeze({
|
|
1470
|
-
"darwin-arm64": "0.
|
|
1471
|
-
"darwin-x64": "0.
|
|
1543
|
+
"darwin-arm64": "0.2.0-alpha5",
|
|
1544
|
+
"darwin-x64": "0.2.0-alpha5",
|
|
1472
1545
|
"linux-arm64-glibc": "0.1.1",
|
|
1473
1546
|
"linux-x64-glibc": "0.1.1",
|
|
1474
1547
|
"win32-arm64": "0.1.5",
|
|
1475
|
-
"win32-x64": "0.
|
|
1476
|
-
wasm: "0.
|
|
1548
|
+
"win32-x64": "0.2.0-alpha5",
|
|
1549
|
+
wasm: "0.2.0-alpha5"
|
|
1477
1550
|
});
|
|
1478
1551
|
/** npm scope and name prefix shared by the engine packages this adapter installs. */
|
|
1479
1552
|
const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
|
|
@@ -1512,7 +1585,7 @@ function glibcVersion(value) {
|
|
|
1512
1585
|
return typeof value === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part))) ? value.split(".").map(Number) : void 0;
|
|
1513
1586
|
}
|
|
1514
1587
|
/**
|
|
1515
|
-
*
|
|
1588
|
+
* Prefer the installed compatible native engine; hosts without one use the shared WASM package.
|
|
1516
1589
|
* @param resolvePackage - Package manifest resolver; injectable for selection tests.
|
|
1517
1590
|
* @param packageExists - Installed-package probe; injectable for selection tests.
|
|
1518
1591
|
* @param host - Process identification and diagnostic report.
|
|
@@ -1530,7 +1603,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1530
1603
|
const failure = error;
|
|
1531
1604
|
if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
|
|
1532
1605
|
if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
|
|
1533
|
-
if (platform !== "linux") throw new Error(`Required LibreOfficeKit native package is missing: ${name}`, { cause: error });
|
|
1534
1606
|
}
|
|
1535
1607
|
if (packageFile !== void 0) {
|
|
1536
1608
|
const engine = await readEngine(packageFile, "native", target);
|
|
@@ -1539,7 +1611,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
|
|
|
1539
1611
|
if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
|
|
1540
1612
|
}
|
|
1541
1613
|
}
|
|
1542
|
-
if (platform !== "linux") throw new Error(`Unsupported LibreOfficeKit host: ${platform}-${arch}`);
|
|
1543
1614
|
return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
|
|
1544
1615
|
}
|
|
1545
1616
|
async function engineAsset(root, value, name, kind) {
|
|
@@ -1564,6 +1635,7 @@ async function readEngine(packageFile, backend, target) {
|
|
|
1564
1635
|
root,
|
|
1565
1636
|
programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
|
|
1566
1637
|
executable,
|
|
1638
|
+
...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
|
|
1567
1639
|
...glibcFloor
|
|
1568
1640
|
};
|
|
1569
1641
|
}
|
|
@@ -1680,6 +1752,7 @@ async function discoverRuntime() {
|
|
|
1680
1752
|
return {
|
|
1681
1753
|
version: ENGINE_VERSION,
|
|
1682
1754
|
backend: engine.backend,
|
|
1755
|
+
nativePreview: engine.backend === "native" && !engine.legacyInputPath,
|
|
1683
1756
|
cliPath: fileURLToPath(new URL("./cli.js", import.meta.url)),
|
|
1684
1757
|
nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
|
|
1685
1758
|
};
|
|
@@ -1968,16 +2041,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1968
2041
|
output = await open(request.outputPath, "wx", 384);
|
|
1969
2042
|
const sourceBytes = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
1970
2043
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-"));
|
|
1971
|
-
const inputPath = join(scratch, `document.${extension}`);
|
|
1972
|
-
const input = await open(inputPath, "wx", 384);
|
|
1973
|
-
try {
|
|
1974
|
-
await input.writeFile(sourceBytes);
|
|
1975
|
-
} finally {
|
|
1976
|
-
await input.close();
|
|
1977
|
-
}
|
|
1978
2044
|
const fonts = await snapshot(stopped);
|
|
1979
2045
|
const result = await runWorker({
|
|
1980
|
-
|
|
2046
|
+
bytes: sourceBytes,
|
|
1981
2047
|
extension,
|
|
1982
2048
|
operation: request,
|
|
1983
2049
|
options: resolvedOptions,
|
|
@@ -1994,7 +2060,10 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
1994
2060
|
const profile = join(scratch, "profile");
|
|
1995
2061
|
await mkdir(profile, { mode: 448 });
|
|
1996
2062
|
const path = join(scratch, `output.${format}`);
|
|
1997
|
-
await runNative(native, resolvedOptions,
|
|
2063
|
+
await runNative(native, resolvedOptions, {
|
|
2064
|
+
bytes: sourceBytes,
|
|
2065
|
+
format: extension
|
|
2066
|
+
}, path, profile, result.fonts, result.substitutions, stopped, request);
|
|
1998
2067
|
bytes = await readBounded(path, resolvedOptions.maxOutputBytes, stopped, "output");
|
|
1999
2068
|
}
|
|
2000
2069
|
validateOutput(bytes, format);
|
|
@@ -2045,14 +2114,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2045
2114
|
owned = true;
|
|
2046
2115
|
const source = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
|
|
2047
2116
|
scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-images-"));
|
|
2048
|
-
const inputPath = join(scratch, `document.${request.extension}`);
|
|
2049
|
-
await writeFile(inputPath, source, {
|
|
2050
|
-
flag: "wx",
|
|
2051
|
-
mode: 384
|
|
2052
|
-
});
|
|
2053
2117
|
const fonts = await snapshot(stopped);
|
|
2054
2118
|
const result = await runWorker({
|
|
2055
|
-
|
|
2119
|
+
bytes: source,
|
|
2056
2120
|
extension: request.extension,
|
|
2057
2121
|
operation: request,
|
|
2058
2122
|
options: resolvedOptions,
|
|
@@ -2068,7 +2132,6 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
|
|
|
2068
2132
|
images = await renderImagesWithNative({
|
|
2069
2133
|
engine,
|
|
2070
2134
|
options: resolvedOptions,
|
|
2071
|
-
inputPath,
|
|
2072
2135
|
source,
|
|
2073
2136
|
scratch,
|
|
2074
2137
|
profile,
|