@deepseek-ai/libreoffice-kit 0.0.1 → 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.
Files changed (94) hide show
  1. package/NOTICE +240 -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 +442 -0
  8. package/lib/browser/types/connection.d.ts +20 -0
  9. package/lib/browser/types/engine-rendering.d.ts +3 -0
  10. package/lib/browser/types/engine-types.d.ts +17 -0
  11. package/lib/browser/types/font-channel.d.ts +20 -0
  12. package/lib/browser/types/index.d.ts +13 -0
  13. package/lib/browser/types/office-engine.d.ts +46 -0
  14. package/lib/browser/types/office-types.d.ts +107 -0
  15. package/lib/browser/types/office.d.ts +4 -0
  16. package/lib/browser/types/protocol.d.ts +109 -0
  17. package/lib/browser/types/rendering.d.ts +4 -0
  18. package/lib/browser/types/types.d.ts +92 -0
  19. package/lib/browser/types/worker.d.ts +2 -0
  20. package/lib/browser/worker.js +3498 -0
  21. package/lib/browser-assets.js +119 -0
  22. package/lib/cli.js +1336 -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 +377 -0
  27. package/lib/font-worker.js +1383 -0
  28. package/lib/index.js +408 -165
  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/default-fonts.d.ts +3 -0
  34. package/lib/types/document.d.ts +1 -1
  35. package/lib/types/engine-rendering.d.ts +15 -0
  36. package/lib/types/engine.d.ts +5 -5
  37. package/lib/types/font-config.d.ts +24 -0
  38. package/lib/types/font-full.d.ts +13 -0
  39. package/lib/types/font-loader.d.ts +1 -7
  40. package/lib/types/font-preferences-data.d.ts +16 -0
  41. package/lib/types/font-preferences.d.ts +29 -0
  42. package/lib/types/font-request.d.ts +12 -0
  43. package/lib/types/font-source-types.d.ts +84 -0
  44. package/lib/types/font-source.d.ts +10 -0
  45. package/lib/types/font-subsets.d.ts +35 -0
  46. package/lib/types/font-worker.d.ts +2 -0
  47. package/lib/types/fonts.d.ts +20 -37
  48. package/lib/types/harfbuzz-subset.d.ts +11 -0
  49. package/lib/types/image-operations.d.ts +58 -0
  50. package/lib/types/image-renderer.d.ts +6 -0
  51. package/lib/types/index.d.ts +25 -2
  52. package/lib/types/native.d.ts +4 -2
  53. package/lib/types/operations.d.ts +41 -0
  54. package/lib/types/options.d.ts +1 -1
  55. package/lib/types/png.d.ts +2 -0
  56. package/lib/types/profile.d.ts +8 -0
  57. package/lib/types/rendering.d.ts +41 -0
  58. package/lib/types/runtime.d.ts +14 -0
  59. package/lib/types/sheet-geometry.d.ts +38 -0
  60. package/lib/types/unicode-scripts.d.ts +18 -0
  61. package/lib/types/wasm.d.ts +76 -1
  62. package/lib/types/worker.d.ts +3 -0
  63. package/lib/worker.js +1716 -271
  64. package/licenses/font-subset/harfbuzz-COPYING +42 -0
  65. package/licenses/font-subset/harfbuzzjs-LICENSE +19 -0
  66. package/licenses/javascript/fflate-LICENSE +21 -0
  67. package/licenses/javascript/saxes-LICENSE +64 -0
  68. package/licenses/javascript/xmlchars-LICENSE +18 -0
  69. package/package.json +59 -12
  70. package/sources/browser/packages/browser/package.json +22 -0
  71. package/sources/browser/packages/browser/src/connection.ts +166 -0
  72. package/sources/browser/packages/browser/src/engine-rendering.ts +2 -0
  73. package/sources/browser/packages/browser/src/engine-types.ts +14 -0
  74. package/sources/browser/packages/browser/src/font-channel.ts +99 -0
  75. package/sources/browser/packages/browser/src/index.ts +39 -0
  76. package/sources/browser/packages/browser/src/office-engine.ts +299 -0
  77. package/sources/browser/packages/browser/src/office-types.ts +77 -0
  78. package/sources/browser/packages/browser/src/office.ts +62 -0
  79. package/sources/browser/packages/browser/src/protocol.ts +39 -0
  80. package/sources/browser/packages/browser/src/rendering.ts +3 -0
  81. package/sources/browser/packages/browser/src/types.ts +94 -0
  82. package/sources/browser/packages/browser/src/worker.ts +166 -0
  83. package/sources/browser/packages/browser/tsconfig.json +5 -0
  84. package/sources/browser/packages/browser/tsdown.config.ts +7 -0
  85. package/sources/browser/scripts/build-browser.mjs +82 -0
  86. package/sources/font-subset/engine/font-subset/README.md +23 -0
  87. package/sources/font-subset/engine/font-subset/README.zh.md +23 -0
  88. package/sources/font-subset/engine/font-subset/source.json +16 -0
  89. package/sources/font-subset/harfbuzzjs/config-override-subset.h +7 -0
  90. package/sources/font-subset/harfbuzzjs/harfbuzz-subset.symbols +34 -0
  91. package/sources/font-subset/scripts/build-font-subset.mjs +64 -0
  92. package/sources/font-subset/scripts/pack-utils.mjs +69 -0
  93. package/sources/font-subset/scripts/platform-matrix.mjs +100 -0
  94. package/sources/font-subset/scripts/verify-artifacts.mjs +260 -0
@@ -0,0 +1,442 @@
1
+ //#region lib/types/protocol.js
2
+ const FONT_CHUNK_BYTES = 1048576;
3
+ //#endregion
4
+ //#region lib/types/types.js
5
+ /** Browser-facing document rendering and host font interfaces. */
6
+ /** A rendering failure with a stable machine-readable category. */
7
+ var BrowserRenderError = class extends Error {
8
+ code;
9
+ constructor(code, message) {
10
+ super(message);
11
+ this.code = code;
12
+ this.name = "BrowserRenderError";
13
+ }
14
+ };
15
+ //#endregion
16
+ //#region lib/types/font-channel.js
17
+ /** Views shared by the owner and engine; only the engine uses Atomics.wait. */
18
+ function fontViews(channel) {
19
+ return {
20
+ control: new Int32Array(channel, 0, 2),
21
+ bytes: new Uint8Array(channel, 8)
22
+ };
23
+ }
24
+ /** Frames are produced lazily so the transfer channel never duplicates a whole font set. */
25
+ function* fontFrames(result) {
26
+ const header = {
27
+ fonts: result.fonts.map((font) => ({
28
+ id: font.id,
29
+ bytes: font.data.byteLength,
30
+ family: font.family,
31
+ alias: font.alias,
32
+ ...font.format ? { format: font.format } : {}
33
+ })),
34
+ ...result.missingFamily === void 0 ? {} : { missingFamily: result.missingFamily }
35
+ };
36
+ const encoded = new TextEncoder().encode(JSON.stringify(header));
37
+ if (encoded.length > 1048576) throw new BrowserRenderError("font-limit", "Font response metadata exceeds the transfer limit.");
38
+ yield {
39
+ state: 1,
40
+ bytes: encoded
41
+ };
42
+ for (const font of result.fonts) for (let offset = 0; offset < font.data.byteLength; offset += FONT_CHUNK_BYTES) yield {
43
+ state: 2,
44
+ bytes: font.data.subarray(offset, offset + FONT_CHUNK_BYTES)
45
+ };
46
+ yield {
47
+ state: 3,
48
+ bytes: /* @__PURE__ */ new Uint8Array()
49
+ };
50
+ }
51
+ //#endregion
52
+ //#region lib/types/connection.js
53
+ /** Browser document ownership, cancellation and asynchronous Host font delivery. */
54
+ /**
55
+ * Load original Office bytes in a dedicated Worker with no intermediate PDF.
56
+ * @param options - Resources, limits, source bytes and asynchronous Host font provider.
57
+ * @param signal - Document lifetime; abort closes its Worker and all pending work.
58
+ * @returns Initial geometry, ordered Worker requests and joined disposal.
59
+ */
60
+ async function openBrowserConnection(options, signal, office = false, onEvent) {
61
+ signal?.throwIfAborted();
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
+ if (![
64
+ options.timeoutMs,
65
+ options.maxLoadedFontBytes,
66
+ options.maxArchiveEntries,
67
+ options.maxUncompressedBytes
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 (!(office ? [
70
+ "doc",
71
+ "docx",
72
+ "xls",
73
+ "xlsx",
74
+ "ppt",
75
+ "pptx"
76
+ ] : ["pdf"]).includes(options.extension) || options.data.byteLength === 0) throw new BrowserRenderError("invalid-document", "The document is empty or has an unsupported extension.");
77
+ const worker = new Worker(options.assets.workerUrl, { name: "libreoffice-document" });
78
+ const channel = new SharedArrayBuffer(1048584);
79
+ const { control, bytes } = fontViews(channel);
80
+ const lifetime = new AbortController();
81
+ const pending = /* @__PURE__ */ new Map();
82
+ let sequence = 0;
83
+ let closed = false;
84
+ let disposal;
85
+ let frames;
86
+ let opened;
87
+ function failPending(error) {
88
+ for (const entry of pending.values()) entry.reject(error);
89
+ pending.clear();
90
+ }
91
+ function sendFontError(error) {
92
+ if (closed) return;
93
+ frames = void 0;
94
+ const encoded = new TextEncoder().encode(error instanceof Error ? error.message : String(error)).subarray(0, FONT_CHUNK_BYTES);
95
+ bytes.set(encoded);
96
+ Atomics.store(control, 1, encoded.length);
97
+ Atomics.store(control, 0, 4);
98
+ Atomics.notify(control, 0);
99
+ }
100
+ function pumpFonts() {
101
+ if (closed || !frames) return;
102
+ try {
103
+ const frame = frames.next();
104
+ if (frame.done) {
105
+ frames = void 0;
106
+ return;
107
+ }
108
+ bytes.set(frame.value.bytes);
109
+ Atomics.store(control, 1, frame.value.bytes.length);
110
+ Atomics.store(control, 0, frame.value.state);
111
+ Atomics.notify(control, 0);
112
+ } catch (error) {
113
+ sendFontError(error);
114
+ }
115
+ }
116
+ worker.onmessage = (event) => {
117
+ const message = event.data;
118
+ switch (message.type) {
119
+ case "office-event":
120
+ if (!closed) {
121
+ onEvent?.(message.event);
122
+ if (message.event.type === "error") dispose();
123
+ }
124
+ return;
125
+ case "font":
126
+ if (closed) return;
127
+ Promise.resolve().then(() => options.resolveFonts(message.request, lifetime.signal)).then((result) => {
128
+ if (closed) return;
129
+ frames = fontFrames(result);
130
+ pumpFonts();
131
+ }, sendFontError);
132
+ return;
133
+ case "font-next":
134
+ pumpFonts();
135
+ return;
136
+ case "missing-fonts":
137
+ if (!closed) options.onMissingFonts?.(message.families);
138
+ return;
139
+ default: {
140
+ const entry = pending.get(message.id);
141
+ if (!entry) return;
142
+ pending.delete(message.id);
143
+ if (message.type === "error") {
144
+ entry.reject(new BrowserRenderError(message.code, message.message));
145
+ if (message.fatal || message.code === "font-limit" || message.code === "font-unavailable" || message.code === "timeout") {
146
+ onEvent?.({
147
+ type: "error",
148
+ code: message.code,
149
+ message: message.message
150
+ });
151
+ dispose();
152
+ }
153
+ } else entry.resolve(message);
154
+ }
155
+ }
156
+ };
157
+ worker.onerror = (event) => {
158
+ const error = new BrowserRenderError("render-failed", event.message || "LibreOffice Worker failed.");
159
+ onEvent?.({
160
+ type: "error",
161
+ code: error.code,
162
+ message: error.message
163
+ });
164
+ failPending(error);
165
+ dispose();
166
+ };
167
+ worker.onmessageerror = () => {
168
+ const error = new BrowserRenderError("render-failed", "LibreOffice Worker returned an unreadable response.");
169
+ onEvent?.({
170
+ type: "error",
171
+ code: error.code,
172
+ message: error.message
173
+ });
174
+ failPending(error);
175
+ dispose();
176
+ };
177
+ function post(message, transfer = []) {
178
+ return new Promise((resolve, reject) => {
179
+ const timer = setTimeout(() => {
180
+ pending.delete(message.id);
181
+ const error = new BrowserRenderError("timeout", "LibreOffice operation timed out.");
182
+ reject(error);
183
+ if (!closed) onEvent?.({
184
+ type: "error",
185
+ code: error.code,
186
+ message: error.message
187
+ });
188
+ dispose();
189
+ }, options.timeoutMs);
190
+ pending.set(message.id, {
191
+ resolve(value) {
192
+ clearTimeout(timer);
193
+ resolve(value);
194
+ },
195
+ reject(error) {
196
+ clearTimeout(timer);
197
+ reject(error);
198
+ }
199
+ });
200
+ try {
201
+ worker.postMessage(message, transfer);
202
+ } catch (error) {
203
+ pending.get(message.id)?.reject(error);
204
+ pending.delete(message.id);
205
+ }
206
+ });
207
+ }
208
+ function dispose() {
209
+ if (disposal) return disposal;
210
+ closed = true;
211
+ signal?.removeEventListener("abort", aborted);
212
+ lifetime.abort();
213
+ frames = void 0;
214
+ Atomics.store(control, 0, 5);
215
+ Atomics.notify(control, 0);
216
+ failPending(new BrowserRenderError("disposed", "The document is closed."));
217
+ disposal = new Promise((resolve) => {
218
+ const deadline = setTimeout(resolve, 1e3);
219
+ post({
220
+ type: "dispose",
221
+ id: ++sequence
222
+ }).then(() => resolve(), () => resolve()).finally(() => clearTimeout(deadline));
223
+ }).finally(() => {
224
+ worker.terminate();
225
+ failPending(new BrowserRenderError("disposed", "The document is closed."));
226
+ worker.onmessage = null;
227
+ worker.onerror = null;
228
+ worker.onmessageerror = null;
229
+ });
230
+ return disposal;
231
+ }
232
+ function aborted() {
233
+ dispose();
234
+ }
235
+ signal?.addEventListener("abort", aborted, { once: true });
236
+ try {
237
+ const data = new Uint8Array(options.data);
238
+ const engineOptions = {
239
+ data,
240
+ extension: options.extension,
241
+ assets: options.assets,
242
+ timeoutMs: options.timeoutMs,
243
+ maxLoadedFontBytes: options.maxLoadedFontBytes,
244
+ fontFallbacks: options.fontFallbacks,
245
+ maxArchiveEntries: options.maxArchiveEntries,
246
+ maxUncompressedBytes: options.maxUncompressedBytes
247
+ };
248
+ const result = await post({
249
+ type: "open",
250
+ id: ++sequence,
251
+ options: engineOptions,
252
+ channel,
253
+ ...office ? { office: true } : {}
254
+ }, [data.buffer]);
255
+ if (result.type !== "opened") throw new BrowserRenderError("invalid-document", "LibreOffice returned an unexpected load response.");
256
+ opened = result;
257
+ if (opened.type !== "opened" || opened.pages.length === 0) throw new BrowserRenderError("invalid-document", "LibreOffice returned no document pages.");
258
+ signal?.throwIfAborted();
259
+ } catch (error) {
260
+ await dispose();
261
+ signal?.throwIfAborted();
262
+ throw error;
263
+ }
264
+ return {
265
+ opened,
266
+ request(message, operation) {
267
+ if (closed) return Promise.reject(new BrowserRenderError("disposed", "The document is closed."));
268
+ if (operation?.aborted) return Promise.reject(operation.reason);
269
+ const task = post({
270
+ ...message,
271
+ id: ++sequence
272
+ });
273
+ if (!operation) return task;
274
+ return new Promise((resolve, reject) => {
275
+ const abort = () => {
276
+ reject(operation.reason);
277
+ };
278
+ operation.addEventListener("abort", abort, { once: true });
279
+ task.then(resolve, reject).finally(() => operation.removeEventListener("abort", abort));
280
+ });
281
+ },
282
+ dispose
283
+ };
284
+ }
285
+ //#endregion
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) {
290
+ const listeners = /* @__PURE__ */ new Set();
291
+ let state;
292
+ const connection = await openBrowserConnection(options, signal, true, (event) => {
293
+ if (event.type === "state") state = event.state;
294
+ for (const listener of listeners) try {
295
+ listener(event);
296
+ } catch (error) {
297
+ console.error("Office document observer failed", error);
298
+ }
299
+ });
300
+ state = connection.opened.office;
301
+ if (!state) {
302
+ await connection.dispose();
303
+ throw new BrowserRenderError("invalid-document", "LibreOffice returned no reading state.");
304
+ }
305
+ async function operate(operation) {
306
+ const response = await connection.request({
307
+ type: "office-operation",
308
+ operation
309
+ });
310
+ if (response.type !== "office-result") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected reading response.");
311
+ return response;
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
+ }
333
+ return {
334
+ get state() {
335
+ return state;
336
+ },
337
+ subscribe(listener) {
338
+ listeners.add(listener);
339
+ return () => {
340
+ listeners.delete(listener);
341
+ };
342
+ },
343
+ async pointer(event) {
344
+ await operate({
345
+ type: "pointer",
346
+ event
347
+ });
348
+ },
349
+ async navigate(event) {
350
+ await operate({
351
+ type: "navigate",
352
+ event
353
+ });
354
+ },
355
+ async selectAll() {
356
+ await operate({ type: "select-all" });
357
+ },
358
+ async copy() {
359
+ return (await operate({ type: "copy" })).text ?? "";
360
+ },
361
+ async goToCell(address) {
362
+ await operate({
363
+ type: "cell",
364
+ address
365
+ });
366
+ },
367
+ async setPart(part) {
368
+ await operate({
369
+ type: "part",
370
+ part
371
+ });
372
+ },
373
+ async setViewport(rectangle, scale) {
374
+ await operate({
375
+ type: "viewport",
376
+ rectangle,
377
+ scale
378
+ });
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
+ },
389
+ async renderTile(request, tileSignal) {
390
+ const response = await connection.request({
391
+ type: "office-tile",
392
+ request
393
+ }, tileSignal);
394
+ if (response.type !== "tile") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected tile response.");
395
+ return response.tile;
396
+ },
397
+ dispose() {
398
+ listeners.clear();
399
+ return connection.dispose();
400
+ }
401
+ };
402
+ }
403
+ //#endregion
404
+ //#region lib/types/index.js
405
+ /** Browser Office preview and retained reading entry points. */
406
+ /**
407
+ * Open a read-only document; each call owns an independent Worker.
408
+ * @param options - Source bytes, version-matched resources and Host fonts.
409
+ * @param signal - Document lifetime; abort awaits engine teardown.
410
+ * @returns Immutable geometry, serialized tile rendering and disposal.
411
+ */
412
+ async function openDocument(options, signal) {
413
+ const connection = await openBrowserConnection(options, signal);
414
+ let queue = Promise.resolve();
415
+ return {
416
+ pages: Object.freeze(connection.opened.pages.map((page) => Object.freeze(page))),
417
+ renderTile(request, tileSignal) {
418
+ if (tileSignal?.aborted) return Promise.reject(tileSignal.reason);
419
+ const task = queue.catch(() => void 0).then(async () => {
420
+ tileSignal?.throwIfAborted();
421
+ const response = await connection.request({
422
+ type: "tile",
423
+ request
424
+ }, tileSignal);
425
+ if (response.type !== "tile") throw new BrowserRenderError("render-failed", "LibreOffice returned an unexpected tile response.");
426
+ return response.tile;
427
+ });
428
+ queue = task;
429
+ if (!tileSignal) return task;
430
+ return new Promise((resolve, reject) => {
431
+ const abort = () => {
432
+ reject(tileSignal.reason);
433
+ };
434
+ tileSignal.addEventListener("abort", abort, { once: true });
435
+ task.then(resolve, reject).finally(() => tileSignal.removeEventListener("abort", abort));
436
+ });
437
+ },
438
+ dispose: connection.dispose
439
+ };
440
+ }
441
+ //#endregion
442
+ export { BrowserRenderError, openDocument, openOfficeDocument };
@@ -0,0 +1,20 @@
1
+ import type { OwnerRequest, WorkerMessage } from './protocol.ts';
2
+ import type { BrowserDocumentOptions } from './types.ts';
3
+ import type { OfficeDocumentEvent, OfficeDocumentOptions } from './office-types.ts';
4
+ /**
5
+ * Load original Office bytes in a dedicated Worker with no intermediate PDF.
6
+ * @param options - Resources, limits, source bytes and asynchronous Host font provider.
7
+ * @param signal - Document lifetime; abort closes its Worker and all pending work.
8
+ * @returns Initial geometry, ordered Worker requests and joined disposal.
9
+ */
10
+ export declare function openBrowserConnection(options: BrowserDocumentOptions | OfficeDocumentOptions, signal?: AbortSignal, office?: boolean, onEvent?: (event: OfficeDocumentEvent) => void): Promise<{
11
+ opened: {
12
+ readonly type: "opened";
13
+ readonly id: number;
14
+ readonly pages: readonly import("./types.ts").BrowserPage[];
15
+ readonly office?: import("./office-types.ts").OfficeDocumentState;
16
+ };
17
+ request(message: OwnerRequest, operation?: AbortSignal): Promise<WorkerMessage>;
18
+ dispose: () => Promise<void>;
19
+ }>;
20
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Raster allocation shared by Node and browser WASM consumers. */
2
+ export { renderRegion, pdfPages } from '@deepseek-ai/libreoffice-kit/internal/engine-rendering';
3
+ //# sourceMappingURL=engine-rendering.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** Emscripten operations used by the single owning engine Worker. */
2
+ export interface EmscriptenModule {
3
+ readonly FS: {
4
+ mkdirTree(path: string): void;
5
+ writeFile(path: string, data: Uint8Array): void;
6
+ readFile(path: string): Uint8Array<ArrayBuffer>;
7
+ unlink(path: string): void;
8
+ };
9
+ readonly ENV: Record<string, string>;
10
+ readonly HEAPU32: Uint32Array;
11
+ readonly PThread: {
12
+ terminateAllThreads(): void;
13
+ };
14
+ ccall(name: string, returnType: string | null, argTypes: string[], args: unknown[]): number;
15
+ UTF8ToString(pointer: number): string;
16
+ }
17
+ //# sourceMappingURL=engine-types.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { FontState } from './protocol.ts';
2
+ import type { BrowserFontRequest, BrowserFontResult } from './types.ts';
3
+ /** Views shared by the owner and engine; only the engine uses Atomics.wait. */
4
+ export declare function fontViews(channel: SharedArrayBuffer): {
5
+ control: Int32Array;
6
+ bytes: Uint8Array;
7
+ };
8
+ /** Frames are produced lazily so the transfer channel never duplicates a whole font set. */
9
+ export declare function fontFrames(result: BrowserFontResult): Generator<{
10
+ state: FontState;
11
+ bytes: Uint8Array;
12
+ }>;
13
+ /** One MEMFS font face registered under a document-local family alias. */
14
+ export interface EngineFontFace {
15
+ readonly path: string;
16
+ readonly family: string;
17
+ }
18
+ /** The synchronous reader installs immutable subsets before returning their MEMFS paths and aliases. */
19
+ export declare function createFontReader(channel: SharedArrayBuffer, timeoutMs: number, maxLoadedFontBytes: number, declaredFamilies: ReadonlyMap<string, string>, request: (request: BrowserFontRequest) => void, next: () => void, install: (path: string, bytes: Uint8Array) => void, missing: (families: readonly string[]) => void): (request: BrowserFontRequest) => EngineFontFace[];
20
+ //# sourceMappingURL=font-channel.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { BrowserDocument, BrowserDocumentOptions } from './types.ts';
2
+ export { BrowserRenderError } from './types.ts';
3
+ export { openOfficeDocument } from './office.ts';
4
+ export type * from './office-types.ts';
5
+ export type { BrowserDocument, BrowserDocumentOptions, BrowserEngineAssets, BrowserFontRequest, BrowserFontResult, BrowserPage, BrowserRenderErrorCode, BrowserTile, BrowserTileRequest } from './types.ts';
6
+ /**
7
+ * Open a read-only document; each call owns an independent Worker.
8
+ * @param options - Source bytes, version-matched resources and Host fonts.
9
+ * @param signal - Document lifetime; abort awaits engine teardown.
10
+ * @returns Immutable geometry, serialized tile rendering and disposal.
11
+ */
12
+ export declare function openDocument(options: BrowserDocumentOptions, signal?: AbortSignal): Promise<BrowserDocument>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -0,0 +1,107 @@
1
+ /** Retained Office reading sessions; this API never exposes document mutation. */
2
+ import type { BrowserDocumentOptions, BrowserPage, BrowserRenderErrorCode, BrowserTile } from './types.ts';
3
+ /** Office containers supported by the reading engine. */
4
+ export type OfficeDocumentFormat = 'doc' | 'docx' | 'xls' | 'xlsx' | 'ppt' | 'pptx';
5
+ /** Source bytes, engine resources and Host fonts; all sessions are read-only. */
6
+ export type OfficeDocumentOptions = Omit<BrowserDocumentOptions, 'extension'> & {
7
+ readonly extension: OfficeDocumentFormat;
8
+ };
9
+ /** Document coordinates in CSS pixels at 96 DPI, independent of zoom. */
10
+ export interface OfficeDocumentRectangle extends BrowserPage {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ }
14
+ /** One Writer document, Calc worksheet or Impress slide. */
15
+ export interface OfficeDocumentPart extends BrowserPage {
16
+ readonly name: string;
17
+ }
18
+ /** Writer layout; other document types always remain paginated. */
19
+ export type OfficeDocumentLayout = 'paginated' | 'continuous';
20
+ /** A point in the previous layout, normally the upper visible line of body text. */
21
+ export interface OfficeDocumentAnchor {
22
+ readonly x: number;
23
+ readonly y: number;
24
+ }
25
+ /** Continuous width is the available content width in document CSS pixels. */
26
+ export type OfficeDocumentLayoutRequest = {
27
+ readonly mode: 'paginated';
28
+ readonly anchor?: OfficeDocumentAnchor;
29
+ } | {
30
+ readonly mode: 'continuous';
31
+ readonly width: number;
32
+ readonly anchor?: OfficeDocumentAnchor;
33
+ };
34
+ /** An optional body-text rectangle in the new layout for restoring reading position. */
35
+ export interface OfficeDocumentLayoutResult {
36
+ readonly changed: boolean;
37
+ readonly anchor?: OfficeDocumentRectangle;
38
+ }
39
+ /** Geometry and selection; cursor is a navigation/cell rectangle, never an editing caret. */
40
+ export interface OfficeDocumentState {
41
+ readonly documentType: 'text' | 'spreadsheet' | 'presentation';
42
+ readonly renderGeneration: number;
43
+ readonly layoutGeneration: number;
44
+ readonly layout: OfficeDocumentLayout;
45
+ readonly part: number;
46
+ readonly parts: readonly OfficeDocumentPart[];
47
+ /** Writer page rectangles in paginated mode; one continuous rectangle otherwise. */
48
+ readonly pages: readonly OfficeDocumentRectangle[];
49
+ readonly cursor: OfficeDocumentRectangle | null;
50
+ readonly selection: readonly OfficeDocumentRectangle[];
51
+ readonly graphicSelection: OfficeDocumentRectangle | null;
52
+ readonly cellAddress: string;
53
+ readonly cellFormula: string;
54
+ }
55
+ /** Primary-button selection; modifiers use LOK Shift (0x1000) / Control (0x2000). */
56
+ export interface OfficeDocumentPointer {
57
+ readonly action: 'down' | 'up' | 'move';
58
+ readonly x: number;
59
+ readonly y: number;
60
+ readonly buttons: number;
61
+ readonly modifiers: number;
62
+ readonly clicks: number;
63
+ }
64
+ /** Only navigation keys are accepted; no arbitrary character or key injection. */
65
+ export interface OfficeDocumentNavigation {
66
+ readonly key: 'left' | 'right' | 'up' | 'down' | 'home' | 'end' | 'pageUp' | 'pageDown';
67
+ readonly extend?: boolean;
68
+ readonly word?: boolean;
69
+ }
70
+ /** One region of the current part. Pixel density does not change document layout. */
71
+ export interface OfficeDocumentTileRequest extends OfficeDocumentRectangle {
72
+ readonly part: number;
73
+ readonly scale: number;
74
+ }
75
+ /** A null rectangle invalidates an entire part; negative part means every part. */
76
+ export type OfficeDocumentEvent = {
77
+ readonly type: 'state';
78
+ readonly state: OfficeDocumentState;
79
+ } | {
80
+ readonly type: 'invalidate';
81
+ readonly part: number;
82
+ readonly rectangle: OfficeDocumentRectangle | null;
83
+ readonly generation: number;
84
+ } | {
85
+ readonly type: 'error';
86
+ readonly code: BrowserRenderErrorCode;
87
+ readonly message: string;
88
+ };
89
+ /** Retain this session while hidden; dispose only when the document is closed. */
90
+ export interface OfficeDocument {
91
+ readonly state: OfficeDocumentState;
92
+ subscribe(listener: (event: OfficeDocumentEvent) => void): () => void;
93
+ pointer(event: OfficeDocumentPointer): Promise<void>;
94
+ navigate(event: OfficeDocumentNavigation): Promise<void>;
95
+ selectAll(): Promise<void>;
96
+ copy(): Promise<string>;
97
+ /** Select a bounded A1 cell or range on the current worksheet. */
98
+ goToCell(address: string): Promise<void>;
99
+ setPart(part: number): Promise<void>;
100
+ setViewport(rectangle: OfficeDocumentRectangle, scale: number): Promise<void>;
101
+ /** Coalesces pending widths; superseded callers observe the newest applied layout. */
102
+ setLayout(request: OfficeDocumentLayoutRequest): Promise<OfficeDocumentLayoutResult>;
103
+ /** Only the current part can be painted; queued requests for a former part reject with stale-part without changing selection. */
104
+ renderTile(request: OfficeDocumentTileRequest, signal?: AbortSignal): Promise<BrowserTile>;
105
+ dispose(): Promise<void>;
106
+ }
107
+ //# sourceMappingURL=office-types.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { OfficeDocument, OfficeDocumentOptions } from './office-types.ts';
2
+ /** Open one read-only Office model; source bytes remain owned by the caller. */
3
+ export declare function openOfficeDocument(options: OfficeDocumentOptions, signal?: AbortSignal): Promise<OfficeDocument>;
4
+ //# sourceMappingURL=office.d.ts.map