@deepseek-ai/libreoffice-kit 0.0.1 → 0.0.2-rc4

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 (90) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +43 -47
  3. package/README.zh.md +35 -50
  4. package/assets/font-subset.json +70 -0
  5. package/assets/font-subset.wasm +0 -0
  6. package/lib/browser/assets.json +10 -0
  7. package/lib/browser/index.js +435 -0
  8. package/lib/browser/types/connection.d.ts +20 -0
  9. package/lib/browser/types/editor-engine.d.ts +50 -0
  10. package/lib/browser/types/editor-types.d.ts +141 -0
  11. package/lib/browser/types/editor.d.ts +9 -0
  12. package/lib/browser/types/engine-rendering.d.ts +3 -0
  13. package/lib/browser/types/engine-types.d.ts +17 -0
  14. package/lib/browser/types/font-channel.d.ts +20 -0
  15. package/lib/browser/types/index.d.ts +13 -0
  16. package/lib/browser/types/protocol.d.ts +117 -0
  17. package/lib/browser/types/rendering.d.ts +4 -0
  18. package/lib/browser/types/types.d.ts +90 -0
  19. package/lib/browser/types/worker.d.ts +2 -0
  20. package/lib/browser/worker.js +3711 -0
  21. package/lib/browser-assets.js +119 -0
  22. package/lib/cli.js +1303 -0
  23. package/lib/document.js +178 -0
  24. package/lib/engine-rendering.js +120 -0
  25. package/lib/font-config.js +46 -0
  26. package/lib/font-source.js +344 -0
  27. package/lib/font-worker.js +712 -0
  28. package/lib/index.js +319 -109
  29. package/lib/rendering.js +99 -0
  30. package/lib/sheet-geometry.js +111 -0
  31. package/lib/types/browser-assets.d.ts +15 -0
  32. package/lib/types/cli.d.ts +3 -0
  33. package/lib/types/document.d.ts +1 -1
  34. package/lib/types/engine-rendering.d.ts +15 -0
  35. package/lib/types/engine.d.ts +5 -5
  36. package/lib/types/font-config.d.ts +24 -0
  37. package/lib/types/font-full.d.ts +13 -0
  38. package/lib/types/font-loader.d.ts +1 -7
  39. package/lib/types/font-request.d.ts +12 -0
  40. package/lib/types/font-source-types.d.ts +82 -0
  41. package/lib/types/font-source.d.ts +10 -0
  42. package/lib/types/font-subsets.d.ts +35 -0
  43. package/lib/types/font-worker.d.ts +2 -0
  44. package/lib/types/fonts.d.ts +9 -29
  45. package/lib/types/harfbuzz-subset.d.ts +11 -0
  46. package/lib/types/image-operations.d.ts +58 -0
  47. package/lib/types/image-renderer.d.ts +6 -0
  48. package/lib/types/index.d.ts +25 -2
  49. package/lib/types/native.d.ts +4 -2
  50. package/lib/types/operations.d.ts +41 -0
  51. package/lib/types/png.d.ts +2 -0
  52. package/lib/types/profile.d.ts +8 -0
  53. package/lib/types/rendering.d.ts +41 -0
  54. package/lib/types/runtime.d.ts +14 -0
  55. package/lib/types/sheet-geometry.d.ts +38 -0
  56. package/lib/types/unicode-scripts.d.ts +18 -0
  57. package/lib/types/wasm.d.ts +76 -1
  58. package/lib/types/worker.d.ts +3 -0
  59. package/lib/worker.js +1012 -237
  60. package/licenses/font-subset/harfbuzz-COPYING +42 -0
  61. package/licenses/font-subset/harfbuzzjs-LICENSE +19 -0
  62. package/licenses/javascript/fflate-LICENSE +21 -0
  63. package/licenses/javascript/saxes-LICENSE +64 -0
  64. package/licenses/javascript/xmlchars-LICENSE +18 -0
  65. package/package.json +59 -12
  66. package/sources/browser/packages/browser/package.json +22 -0
  67. package/sources/browser/packages/browser/src/connection.ts +168 -0
  68. package/sources/browser/packages/browser/src/editor-engine.ts +382 -0
  69. package/sources/browser/packages/browser/src/editor-types.ts +106 -0
  70. package/sources/browser/packages/browser/src/editor.ts +55 -0
  71. package/sources/browser/packages/browser/src/engine-rendering.ts +2 -0
  72. package/sources/browser/packages/browser/src/engine-types.ts +14 -0
  73. package/sources/browser/packages/browser/src/font-channel.ts +99 -0
  74. package/sources/browser/packages/browser/src/index.ts +39 -0
  75. package/sources/browser/packages/browser/src/protocol.ts +40 -0
  76. package/sources/browser/packages/browser/src/rendering.ts +3 -0
  77. package/sources/browser/packages/browser/src/types.ts +92 -0
  78. package/sources/browser/packages/browser/src/worker.ts +171 -0
  79. package/sources/browser/packages/browser/tsconfig.json +5 -0
  80. package/sources/browser/packages/browser/tsdown.config.ts +7 -0
  81. package/sources/browser/scripts/build-browser.mjs +74 -0
  82. package/sources/font-subset/engine/font-subset/README.md +23 -0
  83. package/sources/font-subset/engine/font-subset/README.zh.md +23 -0
  84. package/sources/font-subset/engine/font-subset/source.json +16 -0
  85. package/sources/font-subset/harfbuzzjs/config-override-subset.h +7 -0
  86. package/sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols +34 -0
  87. package/sources/font-subset/scripts/build-font-subset.mjs +64 -0
  88. package/sources/font-subset/scripts/pack-utils.mjs +69 -0
  89. package/sources/font-subset/scripts/platform-matrix.mjs +100 -0
  90. package/sources/font-subset/scripts/verify-artifacts.mjs +260 -0
package/NOTICE CHANGED
@@ -24,3 +24,5 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
24
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
+
28
+ The Host font subset runtime uses HarfBuzz and the harfbuzzjs subset configuration. Exact commits and compiler settings are recorded in assets/font-subset.json and sources/font-subset/. Their MIT and Old MIT notices are retained in licenses/font-subset/.
package/README.md CHANGED
@@ -1,73 +1,69 @@
1
1
  # @deepseek-ai/libreoffice-kit
2
2
 
3
- English | [中文](README.zh.md)
3
+ The Node API, CLI, browser adapters and font service share this package. Its exact-version dependency, `@deepseek-ai/libreoffice-kit-wasm`, carries the prebuilt engine for all supported hosts. Installation and document operations never compile, download, or discover a system LibreOffice. Node.js 22.19 or newer is required.
4
4
 
5
- Convert local DOC, DOCX, XLS, XLSX, PPT, and PPTX files to PDF in Node.js with prebuilt LibreOffice engines. Use the same API in a server, desktop application, or document-processing job, with configurable fonts, cancellation, and resource limits.
5
+ ```ts
6
+ import { createConverter, discoverRuntime } from '@deepseek-ai/libreoffice-kit'
6
7
 
7
- 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
-
9
- ## Installation and usage
10
-
11
- Install with Node.js 22.19.0 or newer:
12
-
13
- ```sh
14
- npm install @deepseek-ai/libreoffice-kit@0.0.1
15
- ```
16
-
17
- 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.
18
-
19
- ```js
20
- import { createConverter } from '@deepseek-ai/libreoffice-kit';
21
-
22
- const converter = await createConverter({ timeoutMs: 120_000 });
8
+ const converter = await createConverter({ timeoutMs: 120_000 })
23
9
  try {
24
- const result = await converter.render({
25
- inputPath: '/private/work/document.docx',
26
- outputPath: '/private/work/document.pdf',
27
- });
28
- console.log(result.backend, result.missingFonts);
10
+ // Office paints directly from its model; PDF inputs use PDFium.
11
+ const images = await converter.renderImages({
12
+ inputPath: '/private/report.docx', outputDir: '/private/new-images', pages: [1, 3], dpi: 144,
13
+ })
14
+ await converter.convert({ inputPath: '/private/report.doc', outputPath: '/private/new-report.docx' })
15
+ await converter.recalculate({ inputPath: '/private/book.xlsx', outputPath: '/private/recalculated.xlsx' })
29
16
  } finally {
30
- await converter.dispose();
17
+ await converter.dispose()
31
18
  }
19
+ const runtime = await discoverRuntime() // installed CLI and API paths; no engine start
32
20
  ```
33
21
 
34
- Native and WASM engines are platform-filtered optional dependencies. Application builders must verify the required engine is installed: native on macOS/Windows, WASM on Linux. A missing required engine rejects `createConverter()` with `unavailable`.
22
+ ## Direct image rendering
35
23
 
36
- Each converter serializes renders. A render creates a separate native process or Node worker and private profile, so fonts, document state, and failures do not leak into later renders. The deadline begins after acquiring its conversion slot. An `AbortSignal` cancels queued or active work; cancellation and `dispose()` await process or worker exit and scratch cleanup. Disposed converters reject further work.
24
+ `renderImages(request, signal?)` loads one saved input snapshot and produces `page-0001.png`, subsequent images, and `manifest.json` in a **new** directory. It supports DOC/DOCX/ODT, XLS/XLSX/ODS, PPT/PPTX/ODP, and PDF. Office rasterization never exports an intermediate PDF. The existing `render({inputPath,outputPath})` method still exports PDF for compatibility.
37
25
 
38
- Conversion workers run the package's shipped JavaScript with an empty `execArgv`; consumer launch flags such as `--input-type=module` are not inherited.
26
+ - Writer, Impress and PDF use distinct, one-based `pages`, preserving the requested order. Omit it or specify `'all'` for all physical pages/slides.
27
+ - Calc uses an exact `sheet` name and optional `range: 'A1:D20'`; a range requires a sheet. Without selectors, every visible sheet's data area is captured. `pages` is rejected for worksheets. Hidden/filtered rows and columns retain their display behavior. The default data area excludes formatting-only cells and standalone drawings; select an explicit range to include additional content. An empty sheet renders A1.
28
+ - `dpi` defaults to 144 and accepts 24–600. Each image is bounded by `maxPixels` (default and maximum 16,777,216) and `maxDimension` (default 8192 pixels per side). Large worksheet regions split on the output-pixel grid in row order. Each fragment retains the requested `sheet`/`range`; its `rectangle` identifies the exact source portion. Writer, Impress and PDF keep whole pages and reject an oversized page.
29
+ - `maxPages` defaults to 100 and limits the total output image count, including worksheet fragments across all selected sheets. The complete batch is checked before painting; limits reject the request instead of truncating it.
30
+ - `maxInputBytes`, aggregate PNG `maxOutputBytes`, font limits, and `timeoutMs` come from `ConverterOptions`. Defaults and all options are in the shipped TypeScript declarations.
31
+ - The manifest identifies `source: 'saved'`, the original `inputPath`, `sourceSha256`, `backend: 'wasm'`, `rasterEngine: 'libreoffice' | 'pdfium'`, total `pageCount`, selected images, dimensions, source rectangles at 96 DPI, and OOXML missing-font diagnostics. For Calc, `pageCount` is the visible sheet count and each image has `sheet`/`range` instead of `page`.
39
32
 
40
- 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.
33
+ Absolute paths must be caller-authorized, private, and protected against concurrent path replacement. Input must be a nonempty regular file. The output directory must not exist. Cancellation, timeout, disposal or any failure waits for Worker exit and removes the whole newly owned output batch; it never removes a pre-existing output directory. Calls on one converter are serialized. Every operation starts a fresh Worker/model; retained browser editor sessions use the browser adapter.
41
34
 
42
- The caller authorizes input access and owns private input/output directories; paths must be absolute and remain unchanged during conversion. Input files must be regular Office files within the configured byte limits. ZIP entry and uncompressed-size limits apply to OOXML; binary DOC/XLS/PPT files use OLE compound containers validated by the LibreOffice importer. Binary formats retain the same conversion deadline and input/output limits. Output creation uses exclusive mode and permissions `0600`; an existing output is never overwritten. Failed or cancelled renders remove newly created outputs. `maxOutputBytes` limits the returned PDF and its read buffer; native temporary disk files can grow until export completes, then oversized PDFs are rejected and deleted before Node reads them. The caller owns successful PDFs and may send their bytes to a browser PDF viewer.
35
+ ## CLI and conversions
43
36
 
44
- `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.
37
+ ```sh
38
+ libreoffice-kit capabilities --json
39
+ libreoffice-kit render --input report.docx --output-dir new-images --pages 1,3 --dpi 144
40
+ libreoffice-kit render --input book.xlsx --output-dir new-sheet --sheet 'Summary' --range A1:D20
41
+ libreoffice-kit render --input document.pdf --output-dir new-pdf-images
42
+ libreoffice-kit convert --input report.docx --output report.pdf
43
+ libreoffice-kit convert --input book.xlsx --output table.csv --sheet 'Summary'
44
+ libreoffice-kit recalculate --input book.xlsx --output checked.xlsx
45
+ ```
45
46
 
46
- ## Engines, fonts, and runtime behavior
47
+ CLI paths resolve against its working directory. Success writes one JSON object to stdout; failure writes `{code,error}` to stderr and exits with status 1. SIGINT/SIGTERM cancel and await cleanup. `render` accepts `--max-pages`, `--max-pixels`, `--max-dimension`, and the common `--timeout-ms`, `--max-input-bytes`, `--max-output-bytes`, archive/font limits, repeated `--font-directory`/`--initial-font-family`, and JSON `--font-fallbacks`.
47
48
 
48
- The Node API and engine packages share the kit release version. `ENGINE_VERSION` pins both WASM and native optional dependencies to the exact engine version. 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/`.
49
+ `convert` supports Writer → PDF/DOCX/ODT/TXT, Calc → PDF/XLSX/ODS/CSV, Impress → PDF/PPTX/ODP. CSV requires an exact sheet for multi-sheet inputs and emits UTF-8 with a comma delimiter. `recalculate` synchronously recalculates XLS/XLSX/ODS and saves XLSX/ODS with formulas and refreshed cached results; it does not validate business logic. Conversion outputs must be fresh exclusive files. Macros and external-link updates remain disabled.
49
50
 
50
- 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. The converter reuses its first font metadata snapshot; recreate the converter after changing installed fonts. 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.
51
+ ## Fonts and PDF scope
51
52
 
52
- Exact installed families take priority in font matching, including explicitly requested handwriting or decorative fonts. Default `fontFallbacks` prefer common serif, sans-serif, and monospaced text families and corresponding Simplified Chinese faces, with Carlito for Calibri and Calibri Light, and Caladea for Cambria. Catalog matching retains the weight and italic style supplied by WASM font requests when matching faces are installed. The complete indexed catalog remains available for glyphs absent from the preferred families. Caller-provided groups replace the defaults; `[]` removes these preferences without disabling catalog discovery. WASM uses the same ordered aliases for imported fonts. The shipped option types describe `fontFallbacks`.
53
+ Node operations use bounded system-font discovery. Exact installed families precede configured fallbacks; full original font files retain shaping and encoding. Recreate the converter after changing installed fonts. `missingFonts` covers named families in readable OOXML metadata, not all missing glyphs or PDF font diagnostics.
53
54
 
54
- Native conversion writes missing-family choices into its private LibreOffice profile. LibreOffice resolves installed originals and its metric-compatible fonts before consulting these choices, so custom groups can produce different substitutions across engines. Native weight and italic selection depend on the engine and the fonts it can discover; native font preloading requests regular faces.
55
+ `createFontSource` from `@deepseek-ai/libreoffice-kit/fonts` provides an independent lazy Worker service. `resolve(attributes)` retains the Unicode-script subset behavior for interactive Office. `resolve({...attributes, mode:'full'})` returns opaque `full_…` identities, original family names and `format` (`ttf`, `otf`, `ttc`); `read(id)` returns complete original font bytes. Apple dfont resources are extracted as complete sfnt faces. Reads reject unknown or changed sources and do not expose host paths.
55
56
 
56
- `maxFontFiles` and `maxFontFileBytes` bound font indexing; `maxLoadedFontBytes` bounds original files explicitly imported by this kit per conversion. WASM uses only imported originals and rejects with `unavailable` when no usable fonts are found; install fonts or configure `fontDirectories` before converting in a minimal container. Native macOS and Windows engines can also use OS-managed fonts, so the import limit is not a cap on native total font memory. Font matching and XML work run inside the cancellable worker; no browser font RPC or DOM is involved.
57
+ PDFium is an experimental direct raster path, separate from PDF.js and editable Office models. Embedded PDF fonts remain PDFium-owned. A fixed, bounded set of regular faces selected from `initialFontFamilies` and fallback groups is mounted before PDFium's first font enumeration. This does not infer every arbitrary PDF font or repair custom encodings. Password-protected PDFs are rejected; forms are rasterized by the upstream PDFium wrapper, while ordinary annotations and advanced PDF features require further qualification.
57
58
 
58
- Node WASM image downscaling uses LibreOffice's CPU image filter. Text layout, font matching, and PDF serialization are CPU work as well.
59
+ ## Browser and font entries
59
60
 
60
- For reproducible comparisons, use identical documents, fonts, DPI, and limits; WASM installations run on Linux. Report engine startup together with conversion time; every render starts a fresh engine. The WASM assets and platform payloads carry their source, license, and integrity manifests.
61
+ `@deepseek-ai/libreoffice-kit/browser` provides persistent Office editing, read-only legacy Office models, PDFium viewing and consistent image capture. `@deepseek-ai/libreoffice-kit/browser-assets` resolves the local browser Worker and validates the assets in the exact-version WASM dependency. Host asset servers expose these resources as opaque URLs; the main package does not duplicate the LibreOffice payload.
61
62
 
62
- ## Source and license
63
+ `./fonts` provides the Host font service described above. Browser-safe `./font-config` and `./document-inspection` share font configuration and input validation with the Node API. `./internal/*` exports are implementation details used by the bundled browser Worker.
63
64
 
64
- This package is licensed under [MPL-2.0](LICENSE). The engine packages include `prebuilds.json` integrity inventories, corresponding source recipes and patches in `sources/`, and third-party redistribution notices in `licenses/`.
65
+ Subsets use Unicode 17 script data and HarfBuzz layout/composite closure. Their bounded in-memory cache can regenerate evicted entries from unchanged originals. [The subset build recipe](../../engine/font-subset/README.md) pins source and redistribution notices.
65
66
 
66
- ## Limitations
67
+ ## Source and license
67
68
 
68
- - Fidelity depends on source formatting, installed fonts, and the selected engine. Missing-font names do not report every missing glyph.
69
- - Only DOCX, XLSX, and PPTX input is supported. Conversion does not discover system LibreOffice or download engines and fonts.
70
- - Font import and output limits do not bound all native memory or temporary disk use. Native platform engines may resolve fonts differently from WASM.
71
- - Installations from npm use platform-specific optional packages. Applications that bundle engines must retain the complete selected package, including its resources and notices.
72
- - 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.
73
- - Version `0.0.1` ships macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine. Other native platforms are development recipes.
69
+ This package is licensed under [MPL-2.0](LICENSE). Engine `prebuilds.json` inventories, corresponding pinned source recipes and patches in `sources/`, and third-party notices in `licenses/` accompany the engine payload. The font subsetter carries its own pinned recipe and redistribution notices. Applications bundling the engine must retain these resources and notices. Declared targets and source-level tests do not substitute for testing the installed engine on representative files.
package/README.zh.md CHANGED
@@ -1,73 +1,58 @@
1
1
  # @deepseek-ai/libreoffice-kit
2
2
 
3
- [English](README.md) | 中文
3
+ Node API、CLI、浏览器适配器和字体服务复用本包;精确版本依赖 `@deepseek-ai/libreoffice-kit-wasm` 提供跨平台预编译引擎。不在安装或文档操作期间编译、下载引擎或发现系统 LibreOffice。需要 Node.js 22.19 以上。
4
4
 
5
- 使用预编译 LibreOffice 引擎,在 Node.js 中将本地 DOC、DOCX、XLS、XLSX、PPT 和 PPTX 文件转换为 PDF。通过同一套 API,为服务端、桌面应用和文档处理任务提供可配置字体、取消和资源限制。
5
+ ## 直接输出图片
6
6
 
7
- 二进制 `.doc`、`.xls`、`.ppt` 输入必须是 OLE 复合文档,例如 Office 97–2003 文件。不支持改后缀的 RTF/HTML 和 `.wps`。二进制输入的 `missingFonts` 为空,因为其字体表由 LibreOffice 读取,而不是由 OOXML 检查器读取。
8
-
9
- ## 安装与使用
10
-
11
- 使用 Node.js 22.19.0 或更新版本安装:
12
-
13
- ```sh
14
- npm install @deepseek-ai/libreoffice-kit@0.0.1
15
- ```
16
-
17
- npm 在 macOS/Windows ARM64 或 x64 上安装匹配的原生引擎,在 Linux 上安装共享 WASM 引擎。macOS 和 Windows 必须具有对应原生包;包缺失或无效时,`createConverter` 以 `unavailable` 拒绝,不会切换到 WASM。Linux 使用 WASM,除非显式安装了兼容的原生开发包。转换失败不会切换引擎。
18
-
19
- ```js
20
- import { createConverter } from '@deepseek-ai/libreoffice-kit';
21
-
22
- const converter = await createConverter({ timeoutMs: 120_000 });
7
+ ```ts
8
+ import { createConverter } from '@deepseek-ai/libreoffice-kit'
9
+ const converter = await createConverter({ timeoutMs: 120_000 })
23
10
  try {
24
- const result = await converter.render({
25
- inputPath: '/private/work/document.docx',
26
- outputPath: '/private/work/document.pdf',
27
- });
28
- console.log(result.backend, result.missingFonts);
29
- } finally {
30
- await converter.dispose();
31
- }
11
+ await converter.renderImages({ inputPath: '/private/report.docx', outputDir: '/private/new-images', pages: [1, 3], dpi: 144 })
12
+ await converter.renderImages({ inputPath: '/private/book.xlsx', outputDir: '/private/new-sheet', sheet: '汇总', range: 'A1:D20' })
13
+ } finally { await converter.dispose() }
32
14
  ```
33
15
 
34
- 原生与 WASM 引擎是按平台筛选的可选依赖。应用构建方必须验证所需引擎已安装:macOS/Windows 使用原生引擎,Linux 使用 WASM。必需引擎缺失时,`createConverter()` 以 `unavailable` 拒绝。
16
+ `renderImages` 从一次已保存文件快照加载模型,在新目录中输出 `page-0001.png` 等图片和 `manifest.json`。支持 DOC/DOCX/ODT、XLS/XLSX/ODS、PPT/PPTX/ODP 以及 PDF。Office 从内存模型直接绘图,不经过 PDF;PDF 使用独立 PDFium 路径。原 `render({inputPath,outputPath})` 仍保持导出 PDF 的兼容语义。
35
17
 
36
- 每个转换器串行执行渲染。一次渲染会创建独立的原生进程或 Node worker 以及私有配置目录,因此字体、文档状态和失败不会泄漏到后续渲染。截止时间在获得转换槽位之后开始计算。`AbortSignal` 可以取消排队中或进行中的工作;取消和 `dispose()` 都会等待进程或 worker 退出并完成临时文件清理。已释放的转换器会拒绝后续工作。
18
+ - Word、PPT 和 PDF 的 `pages` 是从 1 开始的实体页/幻灯片序号;默认全部,数组保留请求顺序。
19
+ - Excel 使用精确 `sheet` 名称与可选 A1 `range`,范围必须指定工作表。不传选择器时渲染全部可见表的数据区,拒绝打印页码。隐藏/筛选行列保留显示行为。默认数据区不包含仅有格式的单元格或独立绘图对象,可显式指定更大范围;空表渲染 A1。
20
+ - `dpi` 默认 144,范围 24–600;每图 `maxPixels` 默认且最多 16,777,216,`maxDimension` 默认每边 8192 像素。大表区域按输出像素网格、从上到下逐行拆图;每片保留原请求 `sheet`/`range`,`rectangle` 标明该片的准确源区域。Word、PPT、PDF 保持完整页面,单页超限时报错。
21
+ - `maxPages` 默认 100,限制全部工作表拆片后的输出图片总数。绘图前检查完整批次,超限明确报错,不截断批次。
22
+ - 输入、全部 PNG 字节总量、字体和超时受 `ConverterOptions` 限制。完整选项与默认值见随包 TypeScript 声明。
23
+ - 清单包含 `source:'saved'`、原输入路径与 SHA256、`backend:'wasm'`、实际 `rasterEngine`、总页数、已选图片及尺寸、96 DPI 下源矩形。Excel 总页数表示可见工作表数,图片使用 `sheet`/`range` 而非 `page`。
37
24
 
38
- 转换 worker 以空的 `execArgv` 运行包内发布的 JavaScript;`--input-type=module` 之类的调用方启动参数不会被继承。
25
+ 调用方负责授权绝对路径并保护私有目录免受并发路径替换。输入必须是非空普通文件,输出目录必须不存在。失败、取消、超时或 dispose 会等待 Worker 退出并清理整个新批次,不删除已有目录。转换器串行执行调用;每次操作使用新 Worker,浏览器编辑复用另行保留的会话。
39
26
 
40
- 在 Linux 上,原生子进程会先在所选引擎的 program 目录中查找共享库,然后才查找系统路径。调用方提供的 `LD_LIBRARY_PATH` 和 `LD_PRELOAD` 不会被继承。
27
+ ## CLI 与转换
41
28
 
42
- 调用方负责授权输入访问并拥有私有输入/输出目录;路径必须是绝对路径,并在转换期间保持不变。输入文件必须是常规 Office 文件,且在配置的字节限制之内。ZIP 条目数和解压大小限制适用于 OOXML;二进制 DOC/XLS/PPT 使用 OLE 复合容器,内部结构由 LibreOffice 导入器验证。二进制格式仍遵守相同的转换超时和输入/输出限制。输出创建使用独占模式和 `0600` 权限;已存在的输出绝不会被覆盖。失败或取消的渲染会删除新建的输出。`maxOutputBytes` 限制返回的 PDF 及其读取缓冲区;原生临时磁盘文件在导出完成前可能继续增长,随后过大的 PDF 会在 Node 读取之前被拒绝并删除。成功的 PDF 归调用方所有,调用方可以将其字节发送给浏览器 PDF 阅读器。
29
+ ```sh
30
+ libreoffice-kit capabilities --json
31
+ libreoffice-kit render --input report.docx --output-dir new-images --pages 1,3 --dpi 144
32
+ libreoffice-kit render --input book.xlsx --output-dir new-sheet --sheet '汇总' --range A1:D20
33
+ libreoffice-kit render --input document.pdf --output-dir new-pdf-images
34
+ libreoffice-kit convert --input book.xlsx --output table.csv --sheet '汇总'
35
+ libreoffice-kit recalculate --input book.xlsx --output checked.xlsx
36
+ ```
43
37
 
44
- `ConversionError.code` 区分 `invalid-document`、`unsupported-format`、`input-too-large`、`output-too-large`、`invalid-output`、`timeout`、`unavailable` 和 `failed`。这些 code 会原样穿过 worker 和原生传输层。无效的安装资源会让创建以 `unavailable` 拒绝;它们绝不会启用回退。`EEXIST` 等文件系统错误、无效配置错误和调用方取消原因保持原样。
38
+ CLI 相对路径按工作目录解析,成功在 stdout 输出一个 JSON,失败在 stderr 输出 `{code,error}` 并退出 1。SIGINT/SIGTERM 取消后等待清理。`render` 支持 `--max-pages`、`--max-pixels`、`--max-dimension`,以及通用输入/输出/归档/字体限制、`--timeout-ms`、可重复字体目录和初始 family,以及 JSON `--font-fallbacks`。
45
39
 
46
- ## 引擎、字体与运行行为
40
+ `convert` 保留 Writer → PDF/DOCX/ODT/TXT、Calc → PDF/XLSX/ODS/CSV、Impress → PDF/PPTX/ODP。多表 CSV 必须指定精确表名,输出 UTF-8 逗号分隔文件。`recalculate` 对 XLS/XLSX/ODS 同步重算并保存 XLSX/ODS 的公式和缓存结果,不验证业务逻辑。输出必须是新文件,宏和外部链接更新保持禁用。
47
41
 
48
- Node API 与引擎包使用相同的 kit 发布版本。`ENGINE_VERSION` 将 WASM 和原生可选依赖固定到精确的引擎版本。npm 安装预编译引擎;安装和转换阶段均不会编译 LibreOffice 或额外下载引擎资源。每个引擎包的 `sources/` 和 `licenses/` 保留匹配的源码配方、补丁、构建信息和第三方许可声明。
42
+ ## 字体与 PDF 范围
49
43
 
50
- 默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。转换器复用其第一次字体元数据快照;更改已安装字体后需重新创建转换器。原始字体字节和解码后的字形覆盖都只在本次转换内有效。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
44
+ Node 端在限制范围内发现系统字体,精确 family 优先于回退配置,导入完整原始字体。安装字体改变后重新创建转换器。`missingFonts` 只报告可读 OOXML 的声明 family,不代表全部缺字或 PDF 字体诊断。
51
45
 
52
- 精确匹配的已安装 family 优先,包括调用方显式要求的书法或装饰字体。默认 `fontFallbacks` 优先选择常见的衬线、无衬线、等宽文本字体族以及对应的简体中文字面,为 Calibri 和 Calibri Light 使用 Carlito,为 Cambria 使用 Caladea。当匹配的字面已安装时,目录匹配保留 WASM 字体请求给出的字重和斜体。完整索引目录对首选字体族缺失的字形仍然可用。调用方提供的分组会替换默认值;`[]` 会移除这些偏好但不关闭目录发现。WASM 对导入的字体使用相同的顺序别名。随包发布的选项类型包含 `fontFallbacks` 的定义。
46
+ `@deepseek-ai/libreoffice-kit/fonts` 的 `createFontSource` 是独立懒加载字体 Worker。默认 `resolve(attributes)` 保留 Office 的 Unicode-script 子集;新增 `resolve({...attributes,mode:'full'})` 返回不暴露主机路径的 `full_…` ID、原 family 和 ttf/otf/ttc 格式。`read(id)` 返回完整原字节,dfont 提取完整单字体 sfnt。来源变化或未知 ID 会拒绝读取。
53
47
 
54
- 原生转换会把缺失 family 的选择写入其私有 LibreOffice 配置。LibreOffice 会先解析已安装的原始字体及其度量兼容字体,然后才参考这些选择,因此自定义分组在不同引擎上可能产生不同的替换结果。原生的字重和斜体选择取决于引擎及其能发现的字体;原生字体预加载只请求常规字面。
48
+ PDFium 直接图片渲染仍为实验能力,与 PDF.js 和 Office 编辑模型分开。嵌入字体由 PDFium 管理;在首次字体枚举前,按初始 family 和回退组预载有字节上限的完整常规字体。该方案不自动推断所有 PDF 字体,也不修复任意自定义编码。加密 PDF 暂拒绝;上游包装层绘制表单,普通注释和高级 PDF 特性仍需专项验收。
55
49
 
56
- `maxFontFiles` 和 `maxFontFileBytes` 限制字体索引;`maxLoadedFontBytes` 限制本次转换中由本 kit 显式导入的原始文件。WASM 只使用导入的原始文件,找不到可用字体时以 `unavailable` 拒绝;在最小化容器中转换前请安装字体或配置 `fontDirectories`。原生 macOS 和 Windows 引擎还可以使用操作系统管理的字体,因此该导入限制不是原生字体总内存的上限。字体匹配和 XML 处理在可取消的 worker 内运行;不涉及浏览器字体 RPC 或 DOM。
50
+ ## 浏览器与字体入口
57
51
 
58
- Node WASM 的图像降采样使用 LibreOffice 的 CPU 图像过滤器。文本排版、字体匹配和 PDF 序列化同样由 CPU 完成。
52
+ `@deepseek-ai/libreoffice-kit/browser` 提供常驻 Office 编辑、旧格式只读模型、PDFium 查看和一致性截图。Node 端 `./browser-assets` 校验并解析主包中的 Worker,以及精确版本 WASM 依赖中的资源。Host 将其映射成资源 URL;主包不复制 LibreOffice 大文件。
59
53
 
60
- 为获得可复现的比较结果,请使用相同的文档、字体、DPI 和限制;WASM 安装在 Linux 上运行。报告时应把引擎启动时间和转换时间一起给出;每次渲染都会启动一个全新的引擎。WASM 资源和平台载荷都带有各自的源码、许可证和完整性清单。
54
+ `./fonts` 提供上文的字体服务。`./font-config` 与 `./document-inspection` 为浏览器和 Node 共用的纯逻辑;`./internal/*` 仅用于内部实现。字体子集采用 Unicode 17 数据和 HarfBuzz 布局闭包,内存缓存淘汰后从未变化的原字体重新生成。
61
55
 
62
56
  ## 源码与许可
63
57
 
64
- 本包使用 [MPL-2.0](LICENSE) 许可。引擎包包含 `prebuilds.json` 完整性清单、`sources/` 对应源码配方和补丁,以及 `licenses/` 第三方再分发声明。
65
-
66
- ## 使用限制
67
-
68
- - 保真度取决于源格式、已安装字体和所选引擎。缺失字体名称不能报告所有缺字。
69
- - 只支持 DOCX、XLSX 和 PPTX 输入。转换不发现系统 LibreOffice,也不下载引擎和字体。
70
- - 字体导入和输出限制不能约束全部原生内存或临时磁盘使用。原生平台引擎的字体解析可能与 WASM 不同。
71
- - npm 安装使用按平台选择的可选包。自行打包引擎的应用需要保留所选包的完整内容,包括资源和许可声明。
72
- - Windows 需要系统安装与 Node.js 架构一致的 Microsoft Visual C++ v14 Redistributable(x64 或 ARM64);包中不捆绑该运行库。Windows ARM64 引擎需要使用 ARM64 Node.js。
73
- - `0.0.1` 提供 macOS 和 Windows 的 ARM64、x64 原生引擎和共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
58
+ 使用 [MPL-2.0](LICENSE)。引擎包含 `prebuilds.json` 完整性清单、`sources/` 中的固定源码与补丁配方、`licenses/` 第三方声明;字体子集器也包含自己的配方和声明。打包应用需保留这些资源。声明目标和源码测试不能代替可安装产物的真实文档验收。
@@ -0,0 +1,70 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "source": {
4
+ "schemaVersion": 1,
5
+ "algorithm": "harfbuzzjs-1.6.1-hb-36cb489-growth-v1",
6
+ "harfbuzzjs": {
7
+ "repository": "https://github.com/harfbuzz/harfbuzzjs.git",
8
+ "commit": "8aa047b90387790b255b118cf45ad11691a38910"
9
+ },
10
+ "harfbuzz": {
11
+ "repository": "https://github.com/harfbuzz/harfbuzz.git",
12
+ "commit": "36cb489cb02ce4b92099669ba9f9bea348eff93f"
13
+ },
14
+ "emsdk": {
15
+ "commit": "5eb0bde7585670252e8ba05e9d361627bffd08b5",
16
+ "version": "4.0.10"
17
+ }
18
+ },
19
+ "recipe": "3dbe51aba06e309bc9a8573462af1a8c93628cf325e88db7d32320fc2a9d54e8",
20
+ "files": {
21
+ "assets/font-subset.wasm": {
22
+ "bytes": 623142,
23
+ "sha256": "9714355321714323b3b15b4a8fa186269cd52a3852282251e985daf76cfe0869"
24
+ },
25
+ "sources/font-subset/engine/font-subset/source.json": {
26
+ "bytes": 465,
27
+ "sha256": "b4fb57078136a796a950c6fcf654ca1b20e3d3ee0cc342b452324b3049e69fdc"
28
+ },
29
+ "sources/font-subset/scripts/build-font-subset.mjs": {
30
+ "bytes": 5401,
31
+ "sha256": "3dbe51aba06e309bc9a8573462af1a8c93628cf325e88db7d32320fc2a9d54e8"
32
+ },
33
+ "sources/font-subset/scripts/platform-matrix.mjs": {
34
+ "bytes": 4810,
35
+ "sha256": "fb5656feafafa89e02d1217bea5e36e3fea7583f113dbda8ff50ba5c966c411b"
36
+ },
37
+ "sources/font-subset/scripts/pack-utils.mjs": {
38
+ "bytes": 3327,
39
+ "sha256": "aa5368e0dd38d90459f0ef14e1d4b27740aef2f4e46617aca6d6fafed0577a44"
40
+ },
41
+ "sources/font-subset/scripts/verify-artifacts.mjs": {
42
+ "bytes": 15997,
43
+ "sha256": "6e89c766a49aa5cb3859e25ae16cdf48e0355df53a5210061b475357709f0cec"
44
+ },
45
+ "sources/font-subset/engine/font-subset/README.md": {
46
+ "bytes": 2130,
47
+ "sha256": "9d0291dec056a36ada10fb38579b0b4bd661e44e941e0fa6bf50e35266435a46"
48
+ },
49
+ "sources/font-subset/engine/font-subset/README.zh.md": {
50
+ "bytes": 1972,
51
+ "sha256": "de8a1f7508e6f9da99162de35ba285bbb75525f522f816a074261d9e004a73eb"
52
+ },
53
+ "sources/font-subset/harfbuzzjs/config-override-subset.h": {
54
+ "bytes": 150,
55
+ "sha256": "05175e798a0f3950814af7b7915be4a6dc8a99d00f59005c702813d8d3a187e6"
56
+ },
57
+ "sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols": {
58
+ "bytes": 755,
59
+ "sha256": "a17abb59f87725011902150347be9ba48f9ae6bfc5df29a906dfdef50d68387a"
60
+ },
61
+ "licenses/font-subset/harfbuzzjs-LICENSE": {
62
+ "bytes": 1079,
63
+ "sha256": "5d09767b2cc476f08028b56d9384dc45061c5a3e90f9ad966e44addc8d26c8b1"
64
+ },
65
+ "licenses/font-subset/harfbuzz-COPYING": {
66
+ "bytes": 1971,
67
+ "sha256": "ba8f810f2455c2f08e2d56bb49b72f37fcf68f1f4fade38977cfd7372050ad64"
68
+ }
69
+ }
70
+ }
Binary file
@@ -0,0 +1,10 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "files": {
4
+ "worker": {
5
+ "path": "lib/browser/worker.js",
6
+ "bytes": 123349,
7
+ "sha256": "be092996bd730eee69f736eaa2144042b0b67add32f54ffc9d4b061a65fe3c14"
8
+ }
9
+ }
10
+ }