@deepseek-ai/libreoffice-kit 0.0.2-rc4 → 0.0.2-rc5
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 +238 -0
- package/README.md +3 -3
- package/README.zh.md +3 -3
- package/lib/browser/assets.json +2 -2
- package/lib/browser/index.js +65 -58
- package/lib/browser/types/connection.d.ts +3 -3
- package/lib/browser/types/index.d.ts +2 -2
- package/lib/browser/types/office-engine.d.ts +46 -0
- package/lib/browser/types/office-types.d.ts +107 -0
- package/lib/browser/types/office.d.ts +4 -0
- package/lib/browser/types/protocol.d.ts +24 -32
- package/lib/browser/types/types.d.ts +3 -1
- package/lib/browser/worker.js +276 -489
- package/lib/browser-assets.js +1 -1
- package/lib/cli.js +91 -58
- package/lib/font-source.js +89 -56
- package/lib/font-worker.js +710 -39
- package/lib/index.js +91 -58
- package/lib/types/default-fonts.d.ts +3 -0
- package/lib/types/engine.d.ts +1 -1
- package/lib/types/font-preferences-data.d.ts +16 -0
- package/lib/types/font-preferences.d.ts +29 -0
- package/lib/types/font-source-types.d.ts +2 -0
- package/lib/types/fonts.d.ts +11 -8
- package/lib/types/options.d.ts +1 -1
- package/lib/worker.js +707 -37
- package/package.json +3 -3
- package/sources/browser/packages/browser/package.json +2 -2
- package/sources/browser/packages/browser/src/connection.ts +7 -9
- package/sources/browser/packages/browser/src/index.ts +3 -3
- package/sources/browser/packages/browser/src/office-engine.ts +299 -0
- package/sources/browser/packages/browser/src/office-types.ts +77 -0
- package/sources/browser/packages/browser/src/office.ts +62 -0
- package/sources/browser/packages/browser/src/protocol.ts +15 -16
- package/sources/browser/packages/browser/src/types.ts +3 -1
- package/sources/browser/packages/browser/src/worker.ts +25 -30
- package/sources/browser/scripts/build-browser.mjs +9 -1
- package/lib/browser/types/editor-engine.d.ts +0 -50
- package/lib/browser/types/editor-types.d.ts +0 -141
- package/lib/browser/types/editor.d.ts +0 -9
- package/sources/browser/packages/browser/src/editor-engine.ts +0 -382
- package/sources/browser/packages/browser/src/editor-types.ts +0 -106
- package/sources/browser/packages/browser/src/editor.ts +0 -55
package/NOTICE
CHANGED
|
@@ -26,3 +26,241 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
26
26
|
SOFTWARE.
|
|
27
27
|
|
|
28
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/.
|
|
29
|
+
|
|
30
|
+
Font preference data
|
|
31
|
+
|
|
32
|
+
https://raw.githubusercontent.com/chromium/chromium/ffaf825e8c2e27fccc089b425f9f114d275804ae/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
|
|
33
|
+
/*
|
|
34
|
+
* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights
|
|
35
|
+
* reserved.
|
|
36
|
+
*
|
|
37
|
+
* Redistribution and use in source and binary forms, with or without
|
|
38
|
+
* modification, are permitted provided that the following conditions are
|
|
39
|
+
* met:
|
|
40
|
+
*
|
|
41
|
+
* * Redistributions of source code must retain the above copyright
|
|
42
|
+
* notice, this list of conditions and the following disclaimer.
|
|
43
|
+
* * Redistributions in binary form must reproduce the above
|
|
44
|
+
* copyright notice, this list of conditions and the following disclaimer
|
|
45
|
+
* in the documentation and/or other materials provided with the
|
|
46
|
+
* distribution.
|
|
47
|
+
* * Neither the name of Google Inc. nor the names of its
|
|
48
|
+
* contributors may be used to endorse or promote products derived from
|
|
49
|
+
* this software without specific prior written permission.
|
|
50
|
+
*
|
|
51
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
52
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
53
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
54
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
55
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
56
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
57
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
58
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
59
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
60
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
61
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
https://raw.githubusercontent.com/fontconfig/fontconfig/84ae86bc21c94d4aedbc02e32c9dc18b8750193c/COPYING
|
|
65
|
+
fontconfig/COPYING
|
|
66
|
+
|
|
67
|
+
Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
|
|
68
|
+
Copyright © 2005 Patrick Lam
|
|
69
|
+
Copyright © 2007 Dwayne Bailey and Translate.org.za
|
|
70
|
+
Copyright © 2009 Roozbeh Pournader
|
|
71
|
+
Copyright © 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Red Hat, Inc.
|
|
72
|
+
Copyright © 2008 Danilo Šegan
|
|
73
|
+
Copyright © 2012 Google, Inc.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
Permission to use, copy, modify, distribute, and sell this software and its
|
|
77
|
+
documentation for any purpose is hereby granted without fee, provided that
|
|
78
|
+
the above copyright notice appear in all copies and that both that
|
|
79
|
+
copyright notice and this permission notice appear in supporting
|
|
80
|
+
documentation, and that the name of the author(s) not be used in
|
|
81
|
+
advertising or publicity pertaining to distribution of the software without
|
|
82
|
+
specific, written prior permission. The authors make no
|
|
83
|
+
representations about the suitability of this software for any purpose. It
|
|
84
|
+
is provided "as is" without express or implied warranty.
|
|
85
|
+
|
|
86
|
+
THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
87
|
+
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
88
|
+
EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
89
|
+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
90
|
+
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
91
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
92
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
--------------------------------------------------------------------------------
|
|
96
|
+
fontconfig/fc-case/CaseFolding.txt
|
|
97
|
+
|
|
98
|
+
© 2019 Unicode®, Inc.
|
|
99
|
+
Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.
|
|
100
|
+
For terms of use, see http://www.unicode.org/terms_of_use.html
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
--------------------------------------------------------------------------------
|
|
104
|
+
fontconfig/src/fcatomic.h
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Mutex operations. Originally copied from HarfBuzz.
|
|
108
|
+
*
|
|
109
|
+
* Copyright © 2007 Chris Wilson
|
|
110
|
+
* Copyright © 2009,2010 Red Hat, Inc.
|
|
111
|
+
* Copyright © 2011,2012,2013 Google, Inc.
|
|
112
|
+
*
|
|
113
|
+
* Permission is hereby granted, without written agreement and without
|
|
114
|
+
* license or royalty fees, to use, copy, modify, and distribute this
|
|
115
|
+
* software and its documentation for any purpose, provided that the
|
|
116
|
+
* above copyright notice and the following two paragraphs appear in
|
|
117
|
+
* all copies of this software.
|
|
118
|
+
*
|
|
119
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
120
|
+
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
121
|
+
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
122
|
+
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
123
|
+
* DAMAGE.
|
|
124
|
+
*
|
|
125
|
+
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
126
|
+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
127
|
+
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
128
|
+
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
129
|
+
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
130
|
+
*
|
|
131
|
+
* Contributor(s):
|
|
132
|
+
* Chris Wilson <chris@chris-wilson.co.uk>
|
|
133
|
+
* Red Hat Author(s): Behdad Esfahbod
|
|
134
|
+
* Google Author(s): Behdad Esfahbod
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
--------------------------------------------------------------------------------
|
|
139
|
+
fontconfig/src/fcfoundry.h
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
Copyright © 2002-2003 by Juliusz Chroboczek
|
|
143
|
+
|
|
144
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
145
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
146
|
+
in the Software without restriction, including without limitation the rights
|
|
147
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
148
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
149
|
+
furnished to do so, subject to the following conditions:
|
|
150
|
+
|
|
151
|
+
The above copyright notice and this permission notice shall be included in
|
|
152
|
+
all copies or substantial portions of the Software.
|
|
153
|
+
|
|
154
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
155
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
156
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
157
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
158
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
159
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
160
|
+
THE SOFTWARE.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
--------------------------------------------------------------------------------
|
|
165
|
+
fontconfig/src/fcmd5.h
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
* This code implements the MD5 message-digest algorithm.
|
|
169
|
+
* The algorithm is due to Ron Rivest. This code was
|
|
170
|
+
* written by Colin Plumb in 1993, no copyright is claimed.
|
|
171
|
+
* This code is in the public domain; do with it what you wish.
|
|
172
|
+
*
|
|
173
|
+
* Equivalent code is available from RSA Data Security, Inc.
|
|
174
|
+
* This code has been tested against that, and is equivalent,
|
|
175
|
+
* except that you don't need to include two pages of legalese
|
|
176
|
+
* with every copy.
|
|
177
|
+
*
|
|
178
|
+
* To compute the message digest of a chunk of bytes, declare an
|
|
179
|
+
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
|
180
|
+
* needed on buffers full of bytes, and then call MD5Final, which
|
|
181
|
+
* will fill a supplied 16-byte array with the digest.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
--------------------------------------------------------------------------------
|
|
186
|
+
fontconfig/src/fcmutex.h
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
* Atomic int and pointer operations. Originally copied from HarfBuzz.
|
|
190
|
+
*
|
|
191
|
+
* Copyright © 2007 Chris Wilson
|
|
192
|
+
* Copyright © 2009,2010 Red Hat, Inc.
|
|
193
|
+
* Copyright © 2011,2012,2013 Google, Inc.
|
|
194
|
+
*
|
|
195
|
+
* Permission is hereby granted, without written agreement and without
|
|
196
|
+
* license or royalty fees, to use, copy, modify, and distribute this
|
|
197
|
+
* software and its documentation for any purpose, provided that the
|
|
198
|
+
* above copyright notice and the following two paragraphs appear in
|
|
199
|
+
* all copies of this software.
|
|
200
|
+
*
|
|
201
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
202
|
+
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
203
|
+
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
204
|
+
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
205
|
+
* DAMAGE.
|
|
206
|
+
*
|
|
207
|
+
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
208
|
+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
209
|
+
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
210
|
+
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
211
|
+
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
212
|
+
*
|
|
213
|
+
* Contributor(s):
|
|
214
|
+
* Chris Wilson <chris@chris-wilson.co.uk>
|
|
215
|
+
* Red Hat Author(s): Behdad Esfahbod
|
|
216
|
+
* Google Author(s): Behdad Esfahbod
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
--------------------------------------------------------------------------------
|
|
221
|
+
fontconfig/src/ftglue.[ch]
|
|
222
|
+
|
|
223
|
+
/* ftglue.c: Glue code for compiling the OpenType code from
|
|
224
|
+
* FreeType 1 using only the public API of FreeType 2
|
|
225
|
+
*
|
|
226
|
+
* By David Turner, The FreeType Project (www.freetype.org)
|
|
227
|
+
*
|
|
228
|
+
* This code is explicitely put in the public domain
|
|
229
|
+
*
|
|
230
|
+
* ==========================================================================
|
|
231
|
+
*
|
|
232
|
+
* the OpenType parser codes was originally written as an extension to
|
|
233
|
+
* FreeType 1.x. As such, its source code was embedded within the library,
|
|
234
|
+
* and used many internal FreeType functions to deal with memory and
|
|
235
|
+
* stream i/o.
|
|
236
|
+
*
|
|
237
|
+
* When it was 'salvaged' for Pango and Qt, the code was "ported" to FreeType 2,
|
|
238
|
+
* which basically means that some macro tricks were performed in order to
|
|
239
|
+
* directly access FT2 _internal_ functions.
|
|
240
|
+
*
|
|
241
|
+
* these functions were never part of FT2 public API, and _did_ change between
|
|
242
|
+
* various releases. This created chaos for many users: when they upgraded the
|
|
243
|
+
* FreeType library on their system, they couldn't run Gnome anymore since
|
|
244
|
+
* Pango refused to link.
|
|
245
|
+
*
|
|
246
|
+
* Very fortunately, it's possible to completely avoid this problem because
|
|
247
|
+
* the FT_StreamRec and FT_MemoryRec structure types, which describe how
|
|
248
|
+
* memory and stream implementations interface with the rest of the font
|
|
249
|
+
* library, have always been part of the public API, and never changed.
|
|
250
|
+
*
|
|
251
|
+
* What we do thus is re-implement, within the OpenType parser, the few
|
|
252
|
+
* functions that depend on them. This only adds one or two kilobytes of
|
|
253
|
+
* code, and ensures that the parser can work with _any_ version
|
|
254
|
+
* of FreeType installed on your system. How sweet... !
|
|
255
|
+
*
|
|
256
|
+
* Note that we assume that Pango doesn't use any other internal functions
|
|
257
|
+
* from FreeType. It used to in old versions, but this should no longer
|
|
258
|
+
* be the case. (crossing my fingers).
|
|
259
|
+
*
|
|
260
|
+
* - David Turner
|
|
261
|
+
* - The FreeType Project (www.freetype.org)
|
|
262
|
+
*
|
|
263
|
+
* PS: This "glue" code is explicitely put in the public domain
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
Unicode data is supplied by @unicode/unicode-17.0.0 under its included MIT license.
|
package/README.md
CHANGED
|
@@ -50,15 +50,15 @@ CLI paths resolve against its working directory. Success writes one JSON object
|
|
|
50
50
|
|
|
51
51
|
## Fonts and PDF scope
|
|
52
52
|
|
|
53
|
-
Node operations use bounded system-font discovery. Exact installed families precede
|
|
53
|
+
Node operations and the Host font service use bounded system-font discovery. Exact installed families and explicit aliases precede Unicode-script and regional body-text preferences, then other glyph-covering fonts. Windows preferences derive from pinned Chromium data; macOS/Linux use Fontconfig categories, with the other source supplying additional candidates. Unicode 17 Script/Script_Extensions data keeps mixed text independent of incorrectly declared document languages. Only unlisted Latin/CJK decorative faces are demoted; cursive writing traditions such as Urdu Nastaliq remain normal body fonts. No fonts are downloaded or bundled by these rules. Full original files retain shaping and encoding. Recreate the converter after changing installed fonts. `missingFonts` reports unavailable declared OOXML families; font-service `unresolvedCodePoints` separately reports scalars no installed face covers. The rule data and licenses are regenerated with `node scripts/generate-font-preferences.mjs` and retained in `NOTICE`.
|
|
54
54
|
|
|
55
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.
|
|
56
56
|
|
|
57
|
-
PDFium is an experimental direct raster path, separate from PDF.js and
|
|
57
|
+
PDFium is an experimental direct raster path, separate from PDF.js and Office reading sessions. 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.
|
|
58
58
|
|
|
59
59
|
## Browser and font entries
|
|
60
60
|
|
|
61
|
-
`@deepseek-ai/libreoffice-kit/browser` provides
|
|
61
|
+
`@deepseek-ai/libreoffice-kit/browser` provides retained read-only Office sessions through `openOfficeDocument`, Writer paginated/continuous layouts, selection/copy, and standalone PDFium viewing. The rc5 browser API has no editing, snapshot-save or capture operations; Node/CLI conversion and recalculation retain their explicit output APIs. `@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.
|
|
62
62
|
|
|
63
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.
|
|
64
64
|
|
package/README.zh.md
CHANGED
|
@@ -41,15 +41,15 @@ CLI 相对路径按工作目录解析,成功在 stdout 输出一个 JSON,失
|
|
|
41
41
|
|
|
42
42
|
## 字体与 PDF 范围
|
|
43
43
|
|
|
44
|
-
Node
|
|
44
|
+
Node 和 Host 字体服务共用有界系统字体发现与匹配:原字体和显式配置的替代字体优先,其次是对应 Unicode 文字系统、地区及正文类别的候选,最后选择其他覆盖所需字符的字体。Windows 顺序来自固定版本 Chromium,macOS/Linux 使用 Fontconfig 类别顺序,并补充另一来源的候选。Unicode 17 Script/Script_Extensions 数据识别混合文字,不让错误文档语言影响韩文等文字的选择。仅对未明确指定的 Latin/CJK 装饰字体降权,乌尔都文 Nastaliq 等正文传统不受影响。规则不下载或打包字体,仍导入原始字体以保留塑形和编码;安装字体改变后需重新创建转换器。`missingFonts` 报告缺失的声明字体,字体服务的 `unresolvedCodePoints` 单独报告没有任何已安装字体覆盖的字符。使用 `node scripts/generate-font-preferences.mjs` 更新固定来源数据,许可证保留在 `NOTICE`。
|
|
45
45
|
|
|
46
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 会拒绝读取。
|
|
47
47
|
|
|
48
|
-
PDFium 直接图片渲染仍为实验能力,与 PDF.js 和 Office
|
|
48
|
+
PDFium 直接图片渲染仍为实验能力,与 PDF.js 和 Office 阅读会话分开。嵌入字体由 PDFium 管理;在首次字体枚举前,按初始 family 和回退组预载有字节上限的完整常规字体。该方案不自动推断所有 PDF 字体,也不修复任意自定义编码。加密 PDF 暂拒绝;上游包装层绘制表单,普通注释和高级 PDF 特性仍需专项验收。
|
|
49
49
|
|
|
50
50
|
## 浏览器与字体入口
|
|
51
51
|
|
|
52
|
-
`@deepseek-ai/libreoffice-kit/browser` 提供常驻 Office
|
|
52
|
+
`@deepseek-ai/libreoffice-kit/browser` 通过 `openOfficeDocument` 提供常驻 Office 阅读会话、Writer 分页/连续重排、选择复制和独立 PDFium 查看。rc5 浏览器 API 不提供编辑、OOXML 保存快照或 capture;Node/CLI 的转换和重算仍保留显式输出能力。Node 端 `./browser-assets` 校验并解析主包中的 Worker,以及精确版本 WASM 依赖中的资源。Host 将其映射成资源 URL;主包不复制 LibreOffice 大文件。
|
|
53
53
|
|
|
54
54
|
`./fonts` 提供上文的字体服务。`./font-config` 与 `./document-inspection` 为浏览器和 Node 共用的纯逻辑;`./internal/*` 仅用于内部实现。字体子集采用 Unicode 17 数据和 HarfBuzz 布局闭包,内存缓存淘汰后从未变化的原字体重新生成。
|
|
55
55
|
|
package/lib/browser/assets.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"files": {
|
|
4
4
|
"worker": {
|
|
5
5
|
"path": "lib/browser/worker.js",
|
|
6
|
-
"bytes":
|
|
7
|
-
"sha256": "
|
|
6
|
+
"bytes": 114732,
|
|
7
|
+
"sha256": "9e4d6b2a7d9598fbfcf14d1a359ba0c962f4c94772849224ac4ba68dd6c725e5"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
package/lib/browser/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function* fontFrames(result) {
|
|
|
57
57
|
* @param signal - Document lifetime; abort closes its Worker and all pending work.
|
|
58
58
|
* @returns Initial geometry, ordered Worker requests and joined disposal.
|
|
59
59
|
*/
|
|
60
|
-
async function openBrowserConnection(options, signal,
|
|
60
|
+
async function openBrowserConnection(options, signal, office = false, onEvent) {
|
|
61
61
|
signal?.throwIfAborted();
|
|
62
62
|
if (!globalThis.crossOriginIsolated || typeof SharedArrayBuffer === "undefined" || typeof Worker === "undefined") throw new BrowserRenderError("unavailable", "LibreOffice requires an isolated secure browser context with Worker and SharedArrayBuffer support.");
|
|
63
63
|
if (![
|
|
@@ -66,7 +66,7 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
66
66
|
options.maxArchiveEntries,
|
|
67
67
|
options.maxUncompressedBytes
|
|
68
68
|
].every((value) => Number.isSafeInteger(value) && value > 0) || options.timeoutMs > 2147483647) throw new TypeError("Document limits must be positive integers and timeoutMs must fit a browser timer.");
|
|
69
|
-
if (!(
|
|
69
|
+
if (!(office ? [
|
|
70
70
|
"doc",
|
|
71
71
|
"docx",
|
|
72
72
|
"xls",
|
|
@@ -74,11 +74,6 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
74
74
|
"ppt",
|
|
75
75
|
"pptx"
|
|
76
76
|
] : ["pdf"]).includes(options.extension) || options.data.byteLength === 0) throw new BrowserRenderError("invalid-document", "The document is empty or has an unsupported extension.");
|
|
77
|
-
if ([
|
|
78
|
-
"doc",
|
|
79
|
-
"xls",
|
|
80
|
-
"ppt"
|
|
81
|
-
].includes(options.extension) && !("readOnly" in options && options.readOnly === true)) throw new BrowserRenderError("invalid-document", "Legacy Office documents require readOnly mode.");
|
|
82
77
|
const worker = new Worker(options.assets.workerUrl, { name: "libreoffice-document" });
|
|
83
78
|
const channel = new SharedArrayBuffer(1048584);
|
|
84
79
|
const { control, bytes } = fontViews(channel);
|
|
@@ -121,7 +116,7 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
121
116
|
worker.onmessage = (event) => {
|
|
122
117
|
const message = event.data;
|
|
123
118
|
switch (message.type) {
|
|
124
|
-
case "
|
|
119
|
+
case "office-event":
|
|
125
120
|
if (!closed) {
|
|
126
121
|
onEvent?.(message.event);
|
|
127
122
|
if (message.event.type === "error") dispose();
|
|
@@ -248,15 +243,14 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
248
243
|
maxLoadedFontBytes: options.maxLoadedFontBytes,
|
|
249
244
|
fontFallbacks: options.fontFallbacks,
|
|
250
245
|
maxArchiveEntries: options.maxArchiveEntries,
|
|
251
|
-
maxUncompressedBytes: options.maxUncompressedBytes
|
|
252
|
-
..."readOnly" in options && options.readOnly !== void 0 ? { readOnly: options.readOnly } : {}
|
|
246
|
+
maxUncompressedBytes: options.maxUncompressedBytes
|
|
253
247
|
};
|
|
254
248
|
const result = await post({
|
|
255
249
|
type: "open",
|
|
256
250
|
id: ++sequence,
|
|
257
251
|
options: engineOptions,
|
|
258
252
|
channel,
|
|
259
|
-
...
|
|
253
|
+
...office ? { office: true } : {}
|
|
260
254
|
}, [data.buffer]);
|
|
261
255
|
if (result.type !== "opened") throw new BrowserRenderError("invalid-document", "LibreOffice returned an unexpected load response.");
|
|
262
256
|
opened = result;
|
|
@@ -289,15 +283,10 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
289
283
|
};
|
|
290
284
|
}
|
|
291
285
|
//#endregion
|
|
292
|
-
//#region lib/types/
|
|
293
|
-
/** Browser owner for
|
|
294
|
-
/**
|
|
295
|
-
|
|
296
|
-
* @param options - OOXML bytes, version-matched engine resources and Host fonts.
|
|
297
|
-
* @param signal - Document lifetime; visibility changes must not abort it.
|
|
298
|
-
* @returns An editor whose exports remain unsaved until the caller writes them.
|
|
299
|
-
*/
|
|
300
|
-
async function openEditor(options, signal) {
|
|
286
|
+
//#region lib/types/office.js
|
|
287
|
+
/** Browser owner for a retained read-only Office model. */
|
|
288
|
+
/** Open one read-only Office model; source bytes remain owned by the caller. */
|
|
289
|
+
async function openOfficeDocument(options, signal) {
|
|
301
290
|
const listeners = /* @__PURE__ */ new Set();
|
|
302
291
|
let state;
|
|
303
292
|
const connection = await openBrowserConnection(options, signal, true, (event) => {
|
|
@@ -305,22 +294,42 @@ async function openEditor(options, signal) {
|
|
|
305
294
|
for (const listener of listeners) try {
|
|
306
295
|
listener(event);
|
|
307
296
|
} catch (error) {
|
|
308
|
-
console.error("Office
|
|
297
|
+
console.error("Office document observer failed", error);
|
|
309
298
|
}
|
|
310
299
|
});
|
|
311
|
-
state = connection.opened.
|
|
300
|
+
state = connection.opened.office;
|
|
312
301
|
if (!state) {
|
|
313
302
|
await connection.dispose();
|
|
314
|
-
throw new BrowserRenderError("invalid-document", "LibreOffice returned no
|
|
303
|
+
throw new BrowserRenderError("invalid-document", "LibreOffice returned no reading state.");
|
|
315
304
|
}
|
|
316
|
-
async function
|
|
305
|
+
async function operate(operation) {
|
|
317
306
|
const response = await connection.request({
|
|
318
|
-
type: "
|
|
307
|
+
type: "office-operation",
|
|
319
308
|
operation
|
|
320
309
|
});
|
|
321
|
-
if (response.type !== "
|
|
310
|
+
if (response.type !== "office-result") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected reading response.");
|
|
322
311
|
return response;
|
|
323
312
|
}
|
|
313
|
+
let layoutRunning = false;
|
|
314
|
+
let pendingLayout;
|
|
315
|
+
async function applyLayouts() {
|
|
316
|
+
layoutRunning = true;
|
|
317
|
+
while (pendingLayout) {
|
|
318
|
+
const next = pendingLayout;
|
|
319
|
+
pendingLayout = void 0;
|
|
320
|
+
try {
|
|
321
|
+
const response = await operate({
|
|
322
|
+
type: "layout",
|
|
323
|
+
request: next.request
|
|
324
|
+
});
|
|
325
|
+
if (!response.layout) throw new BrowserRenderError("render-failed", "LibreOffice returned no layout result.");
|
|
326
|
+
for (const waiter of next.waiters) waiter.resolve(response.layout);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
for (const waiter of next.waiters) waiter.reject(error);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
layoutRunning = false;
|
|
332
|
+
}
|
|
324
333
|
return {
|
|
325
334
|
get state() {
|
|
326
335
|
return state;
|
|
@@ -331,62 +340,60 @@ async function openEditor(options, signal) {
|
|
|
331
340
|
listeners.delete(listener);
|
|
332
341
|
};
|
|
333
342
|
},
|
|
334
|
-
async
|
|
335
|
-
await
|
|
336
|
-
type: "
|
|
343
|
+
async pointer(event) {
|
|
344
|
+
await operate({
|
|
345
|
+
type: "pointer",
|
|
337
346
|
event
|
|
338
347
|
});
|
|
339
348
|
},
|
|
340
|
-
async
|
|
341
|
-
await
|
|
342
|
-
type: "
|
|
343
|
-
|
|
344
|
-
...args ? { arguments: args } : {}
|
|
349
|
+
async navigate(event) {
|
|
350
|
+
await operate({
|
|
351
|
+
type: "navigate",
|
|
352
|
+
event
|
|
345
353
|
});
|
|
346
354
|
},
|
|
347
|
-
async
|
|
348
|
-
await
|
|
349
|
-
type: "paste",
|
|
350
|
-
text
|
|
351
|
-
});
|
|
355
|
+
async selectAll() {
|
|
356
|
+
await operate({ type: "select-all" });
|
|
352
357
|
},
|
|
353
358
|
async copy() {
|
|
354
|
-
return (await
|
|
359
|
+
return (await operate({ type: "copy" })).text ?? "";
|
|
360
|
+
},
|
|
361
|
+
async goToCell(address) {
|
|
362
|
+
await operate({
|
|
363
|
+
type: "cell",
|
|
364
|
+
address
|
|
365
|
+
});
|
|
355
366
|
},
|
|
356
367
|
async setPart(part) {
|
|
357
|
-
await
|
|
368
|
+
await operate({
|
|
358
369
|
type: "part",
|
|
359
370
|
part
|
|
360
371
|
});
|
|
361
372
|
},
|
|
362
373
|
async setViewport(rectangle, scale) {
|
|
363
|
-
await
|
|
374
|
+
await operate({
|
|
364
375
|
type: "viewport",
|
|
365
376
|
rectangle,
|
|
366
377
|
scale
|
|
367
378
|
});
|
|
368
379
|
},
|
|
380
|
+
setLayout(request) {
|
|
381
|
+
const waiter = Promise.withResolvers();
|
|
382
|
+
pendingLayout = {
|
|
383
|
+
request,
|
|
384
|
+
waiters: [...pendingLayout?.waiters ?? [], waiter]
|
|
385
|
+
};
|
|
386
|
+
if (!layoutRunning) applyLayouts();
|
|
387
|
+
return waiter.promise;
|
|
388
|
+
},
|
|
369
389
|
async renderTile(request, tileSignal) {
|
|
370
390
|
const response = await connection.request({
|
|
371
|
-
type: "
|
|
391
|
+
type: "office-tile",
|
|
372
392
|
request
|
|
373
393
|
}, tileSignal);
|
|
374
394
|
if (response.type !== "tile") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected tile response.");
|
|
375
395
|
return response.tile;
|
|
376
396
|
},
|
|
377
|
-
async capture(request, captureSignal) {
|
|
378
|
-
const response = await connection.request({
|
|
379
|
-
type: "capture",
|
|
380
|
-
request
|
|
381
|
-
}, captureSignal);
|
|
382
|
-
if (response.type !== "captured") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected capture response.");
|
|
383
|
-
return response.capture;
|
|
384
|
-
},
|
|
385
|
-
async save() {
|
|
386
|
-
const response = await edit({ type: "save" });
|
|
387
|
-
if (!response.snapshot) throw new BrowserRenderError("render-failed", "LibreOffice returned no saved document bytes.");
|
|
388
|
-
return response.snapshot;
|
|
389
|
-
},
|
|
390
397
|
dispose() {
|
|
391
398
|
listeners.clear();
|
|
392
399
|
return connection.dispose();
|
|
@@ -395,7 +402,7 @@ async function openEditor(options, signal) {
|
|
|
395
402
|
}
|
|
396
403
|
//#endregion
|
|
397
404
|
//#region lib/types/index.js
|
|
398
|
-
/** Browser Office preview and
|
|
405
|
+
/** Browser Office preview and retained reading entry points. */
|
|
399
406
|
/**
|
|
400
407
|
* Open a read-only document; each call owns an independent Worker.
|
|
401
408
|
* @param options - Source bytes, version-matched resources and Host fonts.
|
|
@@ -432,4 +439,4 @@ async function openDocument(options, signal) {
|
|
|
432
439
|
};
|
|
433
440
|
}
|
|
434
441
|
//#endregion
|
|
435
|
-
export { BrowserRenderError, openDocument,
|
|
442
|
+
export { BrowserRenderError, openDocument, openOfficeDocument };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { OwnerRequest, WorkerMessage } from './protocol.ts';
|
|
2
2
|
import type { BrowserDocumentOptions } from './types.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OfficeDocumentEvent, OfficeDocumentOptions } from './office-types.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Load original Office bytes in a dedicated Worker with no intermediate PDF.
|
|
6
6
|
* @param options - Resources, limits, source bytes and asynchronous Host font provider.
|
|
7
7
|
* @param signal - Document lifetime; abort closes its Worker and all pending work.
|
|
8
8
|
* @returns Initial geometry, ordered Worker requests and joined disposal.
|
|
9
9
|
*/
|
|
10
|
-
export declare function openBrowserConnection(options: BrowserDocumentOptions |
|
|
10
|
+
export declare function openBrowserConnection(options: BrowserDocumentOptions | OfficeDocumentOptions, signal?: AbortSignal, office?: boolean, onEvent?: (event: OfficeDocumentEvent) => void): Promise<{
|
|
11
11
|
opened: {
|
|
12
12
|
readonly type: "opened";
|
|
13
13
|
readonly id: number;
|
|
14
14
|
readonly pages: readonly import("./types.ts").BrowserPage[];
|
|
15
|
-
readonly
|
|
15
|
+
readonly office?: import("./office-types.ts").OfficeDocumentState;
|
|
16
16
|
};
|
|
17
17
|
request(message: OwnerRequest, operation?: AbortSignal): Promise<WorkerMessage>;
|
|
18
18
|
dispose: () => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BrowserDocument, BrowserDocumentOptions } from './types.ts';
|
|
2
2
|
export { BrowserRenderError } from './types.ts';
|
|
3
|
-
export {
|
|
4
|
-
export type * from './
|
|
3
|
+
export { openOfficeDocument } from './office.ts';
|
|
4
|
+
export type * from './office-types.ts';
|
|
5
5
|
export type { BrowserDocument, BrowserDocumentOptions, BrowserEngineAssets, BrowserFontRequest, BrowserFontResult, BrowserPage, BrowserRenderErrorCode, BrowserTile, BrowserTileRequest } from './types.ts';
|
|
6
6
|
/**
|
|
7
7
|
* Open a read-only document; each call owns an independent Worker.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BrowserTile } from './types.ts';
|
|
2
|
+
import type { EmscriptenModule } from './engine-types.ts';
|
|
3
|
+
import type { OfficeOperation } from './protocol.ts';
|
|
4
|
+
import type { OfficeDocumentEvent, OfficeDocumentFormat, OfficeDocumentState, OfficeDocumentTileRequest, OfficeDocumentLayoutResult } from './office-types.ts';
|
|
5
|
+
/** One read-only document, driven exclusively by its Worker's messages and timer. */
|
|
6
|
+
export declare class OfficeEngine {
|
|
7
|
+
private readonly module;
|
|
8
|
+
private readonly document;
|
|
9
|
+
private readonly emit;
|
|
10
|
+
private readonly failure;
|
|
11
|
+
state: OfficeDocumentState;
|
|
12
|
+
private timer;
|
|
13
|
+
private readonly callbacks;
|
|
14
|
+
private geometryDirty;
|
|
15
|
+
private stopped;
|
|
16
|
+
private layoutWidth;
|
|
17
|
+
private viewport;
|
|
18
|
+
private commandResult;
|
|
19
|
+
constructor(module: EmscriptenModule, document: number, format: OfficeDocumentFormat, emit: (event: OfficeDocumentEvent) => void, failure: (error: unknown) => void);
|
|
20
|
+
private call;
|
|
21
|
+
private text;
|
|
22
|
+
private invoke;
|
|
23
|
+
private requireOpen;
|
|
24
|
+
/** Collect callbacks without reentering LibreOffice inside its callback. */
|
|
25
|
+
callback(type: number, payload: string): void;
|
|
26
|
+
/** Enforce the native read-only view before accepting any input. */
|
|
27
|
+
start(): Promise<void>;
|
|
28
|
+
private schedule;
|
|
29
|
+
/** Stop event processing before destroying the document. */
|
|
30
|
+
stop(): void;
|
|
31
|
+
/** Return the part whose cached coordinates changed, or -1 when part identities changed. */
|
|
32
|
+
private refreshGeometry;
|
|
33
|
+
private pump;
|
|
34
|
+
private flush;
|
|
35
|
+
/** The Worker permits only these typed reading operations, including at runtime. */
|
|
36
|
+
operation(operation: OfficeOperation): Promise<{
|
|
37
|
+
text?: string;
|
|
38
|
+
layout?: OfficeDocumentLayoutResult;
|
|
39
|
+
}>;
|
|
40
|
+
private configure;
|
|
41
|
+
/** Internal whitelist commands only; no arbitrary command crosses the public API. */
|
|
42
|
+
private command;
|
|
43
|
+
/** Direct tiles preserve the active view, navigation state and selection. */
|
|
44
|
+
render(request: OfficeDocumentTileRequest): BrowserTile;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=office-engine.d.ts.map
|