@deepseek-ai/libreoffice-kit 0.0.2-rc4 → 0.0.2-rc6
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 +5 -3
- package/README.zh.md +3 -3
- package/assets/font-subset.json +4 -4
- package/lib/browser/assets.json +2 -2
- package/lib/browser/index.js +92 -72
- package/lib/browser/types/connection.d.ts +3 -3
- package/lib/browser/types/font-channel.d.ts +5 -4
- package/lib/browser/types/index.d.ts +2 -2
- package/lib/browser/types/office-engine.d.ts +48 -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 +34 -37
- package/lib/browser/types/types.d.ts +3 -1
- package/lib/browser/worker.js +338 -507
- 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 +717 -45
- 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 +8 -10
- package/sources/browser/packages/browser/src/font-channel.ts +22 -12
- package/sources/browser/packages/browser/src/index.ts +3 -3
- package/sources/browser/packages/browser/src/office-engine.ts +323 -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 +19 -18
- package/sources/browser/packages/browser/src/types.ts +3 -1
- package/sources/browser/packages/browser/src/worker.ts +37 -33
- package/sources/browser/scripts/build-browser.mjs +9 -1
- package/sources/font-subset/scripts/platform-matrix.mjs +1 -1
- package/sources/font-subset/scripts/verify-artifacts.mjs +2 -2
- 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,17 @@ 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
|
-
|
|
57
|
+
Full-mode selections from the same unchanged TTC share one file read and retained byte entry while keeping each selected family's name and alias. The existing cache budget counts unique full assets once; eviction may require a later read to regenerate them. Subsets and dfont resources remain specific to each physical face.
|
|
58
|
+
|
|
59
|
+
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
60
|
|
|
59
61
|
## Browser and font entries
|
|
60
62
|
|
|
61
|
-
`@deepseek-ai/libreoffice-kit/browser` provides
|
|
63
|
+
`@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
64
|
|
|
63
65
|
`./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
66
|
|
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/assets/font-subset.json
CHANGED
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"sha256": "3dbe51aba06e309bc9a8573462af1a8c93628cf325e88db7d32320fc2a9d54e8"
|
|
32
32
|
},
|
|
33
33
|
"sources/font-subset/scripts/platform-matrix.mjs": {
|
|
34
|
-
"bytes":
|
|
35
|
-
"sha256": "
|
|
34
|
+
"bytes": 4819,
|
|
35
|
+
"sha256": "870716743136c2a79283910ed58b73aa88766a94f491ca171a59c7fb7512890d"
|
|
36
36
|
},
|
|
37
37
|
"sources/font-subset/scripts/pack-utils.mjs": {
|
|
38
38
|
"bytes": 3327,
|
|
39
39
|
"sha256": "aa5368e0dd38d90459f0ef14e1d4b27740aef2f4e46617aca6d6fafed0577a44"
|
|
40
40
|
},
|
|
41
41
|
"sources/font-subset/scripts/verify-artifacts.mjs": {
|
|
42
|
-
"bytes":
|
|
43
|
-
"sha256": "
|
|
42
|
+
"bytes": 16017,
|
|
43
|
+
"sha256": "b69af5760f7ebfedece94f198dba765def2fd840a4d46bdb8c8b7729fb4884ea"
|
|
44
44
|
},
|
|
45
45
|
"sources/font-subset/engine/font-subset/README.md": {
|
|
46
46
|
"bytes": 2130,
|
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": 116577,
|
|
7
|
+
"sha256": "81237217e64c708763b3e8c2128ed29c1d589ddd4753008c761396d69449eb43"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
package/lib/browser/index.js
CHANGED
|
@@ -21,16 +21,26 @@ function fontViews(channel) {
|
|
|
21
21
|
bytes: new Uint8Array(channel, 8)
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
function* fontFrames(result) {
|
|
24
|
+
/** Only uninstalled content crosses the channel; each family retains its own alias. */
|
|
25
|
+
function* fontFrames(result, known = []) {
|
|
26
|
+
const identities = new Map(known.map((font) => [font.id, font]));
|
|
26
27
|
const header = {
|
|
27
|
-
fonts: result.fonts.map((font) =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
fonts: result.fonts.map((font) => {
|
|
29
|
+
const identity = {
|
|
30
|
+
id: font.id,
|
|
31
|
+
bytes: font.data.byteLength,
|
|
32
|
+
...font.format ? { format: font.format } : {}
|
|
33
|
+
};
|
|
34
|
+
const prior = identities.get(font.id);
|
|
35
|
+
if (prior && (prior.bytes !== identity.bytes || prior.format !== identity.format)) throw new BrowserRenderError("font-unavailable", "Font identity has conflicting bytes or formats.");
|
|
36
|
+
identities.set(font.id, identity);
|
|
37
|
+
return {
|
|
38
|
+
...identity,
|
|
39
|
+
family: font.family,
|
|
40
|
+
alias: font.alias,
|
|
41
|
+
...prior ? { reference: true } : {}
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
34
44
|
...result.missingFamily === void 0 ? {} : { missingFamily: result.missingFamily }
|
|
35
45
|
};
|
|
36
46
|
const encoded = new TextEncoder().encode(JSON.stringify(header));
|
|
@@ -39,10 +49,13 @@ function* fontFrames(result) {
|
|
|
39
49
|
state: 1,
|
|
40
50
|
bytes: encoded
|
|
41
51
|
};
|
|
42
|
-
for (const font of result.fonts
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
for (const [index, font] of result.fonts.entries()) {
|
|
53
|
+
if (header.fonts[index].reference) continue;
|
|
54
|
+
for (let offset = 0; offset < font.data.byteLength; offset += FONT_CHUNK_BYTES) yield {
|
|
55
|
+
state: 2,
|
|
56
|
+
bytes: font.data.subarray(offset, offset + FONT_CHUNK_BYTES)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
46
59
|
yield {
|
|
47
60
|
state: 3,
|
|
48
61
|
bytes: /* @__PURE__ */ new Uint8Array()
|
|
@@ -57,7 +70,7 @@ function* fontFrames(result) {
|
|
|
57
70
|
* @param signal - Document lifetime; abort closes its Worker and all pending work.
|
|
58
71
|
* @returns Initial geometry, ordered Worker requests and joined disposal.
|
|
59
72
|
*/
|
|
60
|
-
async function openBrowserConnection(options, signal,
|
|
73
|
+
async function openBrowserConnection(options, signal, office = false, onEvent) {
|
|
61
74
|
signal?.throwIfAborted();
|
|
62
75
|
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
76
|
if (![
|
|
@@ -66,7 +79,7 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
66
79
|
options.maxArchiveEntries,
|
|
67
80
|
options.maxUncompressedBytes
|
|
68
81
|
].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 (!(
|
|
82
|
+
if (!(office ? [
|
|
70
83
|
"doc",
|
|
71
84
|
"docx",
|
|
72
85
|
"xls",
|
|
@@ -74,11 +87,6 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
74
87
|
"ppt",
|
|
75
88
|
"pptx"
|
|
76
89
|
] : ["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
90
|
const worker = new Worker(options.assets.workerUrl, { name: "libreoffice-document" });
|
|
83
91
|
const channel = new SharedArrayBuffer(1048584);
|
|
84
92
|
const { control, bytes } = fontViews(channel);
|
|
@@ -121,7 +129,7 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
121
129
|
worker.onmessage = (event) => {
|
|
122
130
|
const message = event.data;
|
|
123
131
|
switch (message.type) {
|
|
124
|
-
case "
|
|
132
|
+
case "office-event":
|
|
125
133
|
if (!closed) {
|
|
126
134
|
onEvent?.(message.event);
|
|
127
135
|
if (message.event.type === "error") dispose();
|
|
@@ -131,7 +139,7 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
131
139
|
if (closed) return;
|
|
132
140
|
Promise.resolve().then(() => options.resolveFonts(message.request, lifetime.signal)).then((result) => {
|
|
133
141
|
if (closed) return;
|
|
134
|
-
frames = fontFrames(result);
|
|
142
|
+
frames = fontFrames(result, message.known);
|
|
135
143
|
pumpFonts();
|
|
136
144
|
}, sendFontError);
|
|
137
145
|
return;
|
|
@@ -248,15 +256,14 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
248
256
|
maxLoadedFontBytes: options.maxLoadedFontBytes,
|
|
249
257
|
fontFallbacks: options.fontFallbacks,
|
|
250
258
|
maxArchiveEntries: options.maxArchiveEntries,
|
|
251
|
-
maxUncompressedBytes: options.maxUncompressedBytes
|
|
252
|
-
..."readOnly" in options && options.readOnly !== void 0 ? { readOnly: options.readOnly } : {}
|
|
259
|
+
maxUncompressedBytes: options.maxUncompressedBytes
|
|
253
260
|
};
|
|
254
261
|
const result = await post({
|
|
255
262
|
type: "open",
|
|
256
263
|
id: ++sequence,
|
|
257
264
|
options: engineOptions,
|
|
258
265
|
channel,
|
|
259
|
-
...
|
|
266
|
+
...office ? { office: true } : {}
|
|
260
267
|
}, [data.buffer]);
|
|
261
268
|
if (result.type !== "opened") throw new BrowserRenderError("invalid-document", "LibreOffice returned an unexpected load response.");
|
|
262
269
|
opened = result;
|
|
@@ -289,15 +296,10 @@ async function openBrowserConnection(options, signal, editing = false, onEvent)
|
|
|
289
296
|
};
|
|
290
297
|
}
|
|
291
298
|
//#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) {
|
|
299
|
+
//#region lib/types/office.js
|
|
300
|
+
/** Browser owner for a retained read-only Office model. */
|
|
301
|
+
/** Open one read-only Office model; source bytes remain owned by the caller. */
|
|
302
|
+
async function openOfficeDocument(options, signal) {
|
|
301
303
|
const listeners = /* @__PURE__ */ new Set();
|
|
302
304
|
let state;
|
|
303
305
|
const connection = await openBrowserConnection(options, signal, true, (event) => {
|
|
@@ -305,22 +307,42 @@ async function openEditor(options, signal) {
|
|
|
305
307
|
for (const listener of listeners) try {
|
|
306
308
|
listener(event);
|
|
307
309
|
} catch (error) {
|
|
308
|
-
console.error("Office
|
|
310
|
+
console.error("Office document observer failed", error);
|
|
309
311
|
}
|
|
310
312
|
});
|
|
311
|
-
state = connection.opened.
|
|
313
|
+
state = connection.opened.office;
|
|
312
314
|
if (!state) {
|
|
313
315
|
await connection.dispose();
|
|
314
|
-
throw new BrowserRenderError("invalid-document", "LibreOffice returned no
|
|
316
|
+
throw new BrowserRenderError("invalid-document", "LibreOffice returned no reading state.");
|
|
315
317
|
}
|
|
316
|
-
async function
|
|
318
|
+
async function operate(operation) {
|
|
317
319
|
const response = await connection.request({
|
|
318
|
-
type: "
|
|
320
|
+
type: "office-operation",
|
|
319
321
|
operation
|
|
320
322
|
});
|
|
321
|
-
if (response.type !== "
|
|
323
|
+
if (response.type !== "office-result") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected reading response.");
|
|
322
324
|
return response;
|
|
323
325
|
}
|
|
326
|
+
let layoutRunning = false;
|
|
327
|
+
let pendingLayout;
|
|
328
|
+
async function applyLayouts() {
|
|
329
|
+
layoutRunning = true;
|
|
330
|
+
while (pendingLayout) {
|
|
331
|
+
const next = pendingLayout;
|
|
332
|
+
pendingLayout = void 0;
|
|
333
|
+
try {
|
|
334
|
+
const response = await operate({
|
|
335
|
+
type: "layout",
|
|
336
|
+
request: next.request
|
|
337
|
+
});
|
|
338
|
+
if (!response.layout) throw new BrowserRenderError("render-failed", "LibreOffice returned no layout result.");
|
|
339
|
+
for (const waiter of next.waiters) waiter.resolve(response.layout);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
for (const waiter of next.waiters) waiter.reject(error);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
layoutRunning = false;
|
|
345
|
+
}
|
|
324
346
|
return {
|
|
325
347
|
get state() {
|
|
326
348
|
return state;
|
|
@@ -331,62 +353,60 @@ async function openEditor(options, signal) {
|
|
|
331
353
|
listeners.delete(listener);
|
|
332
354
|
};
|
|
333
355
|
},
|
|
334
|
-
async
|
|
335
|
-
await
|
|
336
|
-
type: "
|
|
356
|
+
async pointer(event) {
|
|
357
|
+
await operate({
|
|
358
|
+
type: "pointer",
|
|
337
359
|
event
|
|
338
360
|
});
|
|
339
361
|
},
|
|
340
|
-
async
|
|
341
|
-
await
|
|
342
|
-
type: "
|
|
343
|
-
|
|
344
|
-
...args ? { arguments: args } : {}
|
|
362
|
+
async navigate(event) {
|
|
363
|
+
await operate({
|
|
364
|
+
type: "navigate",
|
|
365
|
+
event
|
|
345
366
|
});
|
|
346
367
|
},
|
|
347
|
-
async
|
|
348
|
-
await
|
|
349
|
-
type: "paste",
|
|
350
|
-
text
|
|
351
|
-
});
|
|
368
|
+
async selectAll() {
|
|
369
|
+
await operate({ type: "select-all" });
|
|
352
370
|
},
|
|
353
371
|
async copy() {
|
|
354
|
-
return (await
|
|
372
|
+
return (await operate({ type: "copy" })).text ?? "";
|
|
373
|
+
},
|
|
374
|
+
async goToCell(address) {
|
|
375
|
+
await operate({
|
|
376
|
+
type: "cell",
|
|
377
|
+
address
|
|
378
|
+
});
|
|
355
379
|
},
|
|
356
380
|
async setPart(part) {
|
|
357
|
-
await
|
|
381
|
+
await operate({
|
|
358
382
|
type: "part",
|
|
359
383
|
part
|
|
360
384
|
});
|
|
361
385
|
},
|
|
362
386
|
async setViewport(rectangle, scale) {
|
|
363
|
-
await
|
|
387
|
+
await operate({
|
|
364
388
|
type: "viewport",
|
|
365
389
|
rectangle,
|
|
366
390
|
scale
|
|
367
391
|
});
|
|
368
392
|
},
|
|
393
|
+
setLayout(request) {
|
|
394
|
+
const waiter = Promise.withResolvers();
|
|
395
|
+
pendingLayout = {
|
|
396
|
+
request,
|
|
397
|
+
waiters: [...pendingLayout?.waiters ?? [], waiter]
|
|
398
|
+
};
|
|
399
|
+
if (!layoutRunning) applyLayouts();
|
|
400
|
+
return waiter.promise;
|
|
401
|
+
},
|
|
369
402
|
async renderTile(request, tileSignal) {
|
|
370
403
|
const response = await connection.request({
|
|
371
|
-
type: "
|
|
404
|
+
type: "office-tile",
|
|
372
405
|
request
|
|
373
406
|
}, tileSignal);
|
|
374
407
|
if (response.type !== "tile") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected tile response.");
|
|
375
408
|
return response.tile;
|
|
376
409
|
},
|
|
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
410
|
dispose() {
|
|
391
411
|
listeners.clear();
|
|
392
412
|
return connection.dispose();
|
|
@@ -395,7 +415,7 @@ async function openEditor(options, signal) {
|
|
|
395
415
|
}
|
|
396
416
|
//#endregion
|
|
397
417
|
//#region lib/types/index.js
|
|
398
|
-
/** Browser Office preview and
|
|
418
|
+
/** Browser Office preview and retained reading entry points. */
|
|
399
419
|
/**
|
|
400
420
|
* Open a read-only document; each call owns an independent Worker.
|
|
401
421
|
* @param options - Source bytes, version-matched resources and Host fonts.
|
|
@@ -432,4 +452,4 @@ async function openDocument(options, signal) {
|
|
|
432
452
|
};
|
|
433
453
|
}
|
|
434
454
|
//#endregion
|
|
435
|
-
export { BrowserRenderError, openDocument,
|
|
455
|
+
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>;
|