@deepseek-ai/libreoffice-kit 0.1.4 → 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.
Files changed (79) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +49 -9
  3. package/README.zh.md +50 -10
  4. package/lib/cli.js +155 -52
  5. package/lib/editor.js +2061 -0
  6. package/lib/index.js +155 -52
  7. package/lib/types/editor-protocol.d.ts +29 -0
  8. package/lib/types/editor-transport.d.ts +36 -0
  9. package/lib/types/editor-types.d.ts +119 -0
  10. package/lib/types/editor.d.ts +105 -0
  11. package/lib/types/engine.d.ts +4 -2
  12. package/lib/types/fonts.d.ts +4 -8
  13. package/lib/types/native-image-renderer.d.ts +0 -1
  14. package/lib/types/native-process.d.ts +1 -0
  15. package/lib/types/native.d.ts +31 -2
  16. package/lib/types/rendering.d.ts +2 -0
  17. package/lib/types/runtime.d.ts +2 -0
  18. package/lib/types/sheet-geometry.d.ts +1 -1
  19. package/lib/types/worker.d.ts +2 -2
  20. package/lib/worker.js +51 -32
  21. package/native-render/CMakeLists.txt +40 -0
  22. package/native-render/LICENSE +21 -0
  23. package/native-render/README.md +83 -0
  24. package/native-render/README.zh.md +83 -0
  25. package/native-render/include/dsh_render.h +101 -0
  26. package/native-render/include/dsh_render_engine.h +66 -0
  27. package/native-render/include/dsh_render_node.h +27 -0
  28. package/native-render/include/dsh_webgpu.h +52 -0
  29. package/native-render/index.d.ts +145 -0
  30. package/native-render/index.mjs +71 -0
  31. package/native-render/lib/browser/display.d.ts +46 -0
  32. package/native-render/lib/browser/display.js +128 -0
  33. package/native-render/lib/browser/index.d.ts +4 -0
  34. package/native-render/lib/browser/index.js +3 -0
  35. package/native-render/lib/browser/painters.d.ts +9 -0
  36. package/native-render/lib/browser/painters.js +180 -0
  37. package/native-render/lib/browser/types.d.ts +51 -0
  38. package/native-render/lib/browser/types.js +1 -0
  39. package/native-render/lib/electron/adapter.d.ts +9 -0
  40. package/native-render/lib/electron/adapter.js +118 -0
  41. package/native-render/lib/electron/index.d.ts +3 -0
  42. package/native-render/lib/electron/index.js +3 -0
  43. package/native-render/lib/electron/preload.d.ts +13 -0
  44. package/native-render/lib/electron/preload.js +47 -0
  45. package/native-render/lib/electron/transfer.d.ts +15 -0
  46. package/native-render/lib/electron/transfer.js +36 -0
  47. package/native-render/prebuilds/darwin-arm64/libdsh_render_sdk.a +0 -0
  48. package/native-render/prebuilds/darwin-arm64/manifest.json +34 -0
  49. package/native-render/prebuilds/darwin-arm64/render.node +0 -0
  50. package/native-render/prebuilds/darwin-x64/libdsh_render_sdk.a +0 -0
  51. package/native-render/prebuilds/darwin-x64/manifest.json +34 -0
  52. package/native-render/prebuilds/darwin-x64/render.node +0 -0
  53. package/native-render/prebuilds/win32-arm64/dsh_render_sdk.lib +0 -0
  54. package/native-render/prebuilds/win32-arm64/manifest.json +34 -0
  55. package/native-render/prebuilds/win32-arm64/render.node +0 -0
  56. package/native-render/prebuilds/win32-x64/dsh_render_sdk.lib +0 -0
  57. package/native-render/prebuilds/win32-x64/manifest.json +34 -0
  58. package/native-render/prebuilds/win32-x64/render.node +0 -0
  59. package/native-render/receipt.json +23 -0
  60. package/native-render/scripts/build-webgpu.mjs +197 -0
  61. package/native-render/scripts/build.mjs +43 -0
  62. package/native-render/scripts/metadata.mjs +47 -0
  63. package/native-render/scripts/source-identity.mjs +15 -0
  64. package/native-render/scripts/verify-prebuilds.mjs +14 -0
  65. package/native-render/sdk.json +45 -0
  66. package/native-render/src/node-producer.cc +595 -0
  67. package/native-render/src/producer-internal.h +8 -0
  68. package/native-render/src/producer.cc +306 -0
  69. package/native-render/src/receiver.cc +1050 -0
  70. package/native-render/src/relay-transport.inc +293 -0
  71. package/native-render/src/transport.cc +405 -0
  72. package/native-render/src/transport.h +80 -0
  73. package/native-render/src/webgpu.cc +214 -0
  74. package/native-render/src/win-delay-load.LICENSE +24 -0
  75. package/native-render/src/win-delay-load.cc +43 -0
  76. package/native-render/verify.d.mts +4 -0
  77. package/native-render/verify.mjs +101 -0
  78. package/native-render/webgpu-dependencies.json +51 -0
  79. package/package.json +97 -11
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. Version 0.1.3 uses macOS, Windows and WASM engines 0.1.3. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible 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
- Install with Node.js 22.19.0 or newer:
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.1.3
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha5
17
19
  ```
18
20
 
19
- npm installs the matching native engine on macOS/Windows ARM64 or x64, and the shared WASM engine on Linux. macOS and Windows require their native package; a missing or invalid package rejects `createConverter` with `unavailable`, without switching to WASM. Linux uses WASM unless a compatible development native package was installed explicitly. Conversion failures never switch engines.
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';
@@ -41,7 +43,7 @@ Converters created through the compatibility `createConverter(options)` API tran
41
43
 
42
44
  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
45
 
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`.
46
+ `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
47
 
46
48
  ```sh
47
49
  npm exec -- dsoffice render --input report.docx --output-dir report-pages --pages 1
@@ -50,11 +52,15 @@ npm exec -- dsoffice convert --input report.docx --output report.pdf
50
52
  npm exec -- dsoffice recalculate --input budget.xlsx --output recalculated.xlsx
51
53
  ```
52
54
 
55
+ 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.
56
+
53
57
  Conversion workers run the package's shipped JavaScript with an empty `execArgv`; consumer launch flags such as `--input-type=module` are not inherited.
54
58
 
55
- 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 waits for process exit and pipe closure; this transport does not grant additional filesystem or network access.
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.
60
+
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.
56
62
 
57
- 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.
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.
58
64
 
59
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.
60
66
 
@@ -62,11 +68,41 @@ The caller authorizes input access and owns private input/output directories; pa
62
68
 
63
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.
64
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
+
65
101
  ## Engines, fonts, and runtime behavior
66
102
 
67
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/`.
68
104
 
69
- 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. Original font bytes and decoded glyph coverage remain conversion-local. `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.
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.
70
106
 
71
107
  ### Font metadata cache
72
108
 
@@ -108,4 +144,8 @@ This package is licensed under [MPL-2.0](LICENSE). The engine packages include `
108
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.
109
145
  - Installations from npm use platform-specific optional packages. Applications that bundle engines must retain the complete selected package, including its resources and notices.
110
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.
111
- - Version `0.1.0` ships macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine for Linux. Other native platforms are development recipes.
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.1.3 使用 macOS、Windows 和 WASM 引擎 0.1.3。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。
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.1.3
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha5
17
19
  ```
18
20
 
19
- npm 在 macOS/Windows ARM64 或 x64 上安装匹配的原生引擎,Windows 上,引擎可执行文件或程序目录路径达到 260 个字符时,在私有操作目录中使用 helper 临时副本和指向已安装资源的 junction。资源保留在安装目录,junction 在 helper 关闭后清理。渲染器若在返回协议响应前退出,会携带退出状态和捕获的诊断信息拒绝操作。
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';
@@ -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,9 +52,15 @@ 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
 
57
- Windows 原生 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。helper 等待命令时,管道轮询不会占用 libuv 工作线程。取消会等待进程退出和管道关闭;此传输方式不授予额外的文件系统或网络权限。
59
+ Windows 的转换、图像渲染和持久编辑 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。管道保持二进制像素帧完整,helper 等待命令时的管道轮询不会占用 libuv 工作线程。取消及工作表选择失败后,关闭会等待进程退出并读完输出,包括协议读取器已暂停 stdout 的情况;此传输方式不授予额外的文件系统或网络权限。
60
+
61
+ 原生转换和图片渲染 helper 设置 `SAL_DISABLE_PRINTERLIST=1` 与 `SAL_DISABLE_DEFAULTPRINTER=1`,禁用打印机枚举和默认打印机查询。文档预览和导出不需要实体打印机;这些子进程设置可避免打印机驱动弹窗及网络打印机连接等待,不会修改系统打印机设置。
62
+
63
+ Windows 上,引擎可执行文件或程序目录路径达到 260 个字符时,在私有操作目录中使用 helper 临时副本和指向已安装资源的 junction。转换、图像渲染和编辑均保留这些路径直到子进程退出,包括启动失败时;随后清理 junction。渲染器若在返回协议响应前退出,会携带退出状态和捕获的诊断信息拒绝操作。
58
64
 
59
65
  在 Linux 上,原生子进程会先在所选引擎的 program 目录中查找共享库,然后才查找系统路径。调用方提供的 `LD_LIBRARY_PATH` 和 `LD_PRELOAD` 不会被继承。
60
66
 
@@ -62,11 +68,41 @@ Windows 原生 helper 使用匿名标准输入输出管道,继承调用方的
62
68
 
63
69
  `ConversionError.code` 区分 `invalid-document`、`unsupported-format`、`input-too-large`、`output-too-large`、`invalid-output`、`timeout`、`unavailable` 和 `failed`。这些 code 会原样穿过 worker 和原生传输层。无效的安装资源会让创建以 `unavailable` 拒绝;它们绝不会启用回退。`EEXIST` 等文件系统错误、无效配置错误和调用方取消原因保持原样。
64
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
+
65
101
  ## 引擎、字体与运行行为
66
102
 
67
103
  Node API 通过 `ENGINE_VERSION` 报告其发布版本;`ENGINE_VERSIONS` 独立固定各平台的引擎版本。npm 安装预编译引擎;安装和转换阶段均不会编译 LibreOffice 或额外下载引擎资源。每个引擎包的 `sources/` 和 `licenses/` 保留匹配的源码配方、补丁、构建信息和第三方许可声明。
68
104
 
69
- 默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。原始字体字节和解码后的字形覆盖都只在本次转换内有效。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
105
+ 默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。字形匹配仅查询请求中的 Unicode 码点,同一物理字体集合中的各字面共享一次解码。码点查询结果只在本次操作内保留,开始检查下一文件前释放当前解析对象;不会遍历所有字形,也不会跨文档缓存字体字节。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
70
106
 
71
107
  ### 字体元数据缓存
72
108
 
@@ -108,4 +144,8 @@ Node WASM 的图像降采样使用 LibreOffice 的 CPU 图像过滤器。文本
108
144
  - 字体导入和输出限制不能约束全部原生内存或临时磁盘使用。原生平台引擎的字体解析可能与 WASM 不同。
109
145
  - npm 安装使用按平台选择的可选包。自行打包引擎的应用需要保留所选包的完整内容,包括资源和许可声明。
110
146
  - Windows 需要系统安装与 Node.js 架构一致的 Microsoft Visual C++ v14 Redistributable(x64 或 ARM64);包中不捆绑该运行库。Windows ARM64 引擎需要使用 ARM64 Node.js。
111
- - `0.1.0` 提供 macOS 和 Windows 的 ARM64、x64 原生引擎,以及供 Linux 使用的共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
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)。