@deepseek-ai/libreoffice-kit 0.0.2-rc7 → 0.0.2-rc9
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/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/browser/assets.json +2 -2
- package/lib/browser/index.js +297 -162
- package/lib/browser/types/connection.d.ts +28 -6
- package/lib/browser/types/font-channel.d.ts +16 -1
- package/lib/browser/types/index.d.ts +2 -2
- package/lib/browser/types/office-engine.d.ts +10 -2
- package/lib/browser/types/office-types.d.ts +60 -1
- package/lib/browser/types/office.d.ts +18 -3
- package/lib/browser/types/protocol.d.ts +32 -5
- package/lib/browser/types/types.d.ts +2 -0
- package/lib/browser/worker.js +286 -105
- package/lib/browser-assets.js +1 -1
- package/lib/cli.js +2 -2
- package/lib/index.js +2 -2
- package/lib/types/engine.d.ts +1 -1
- package/package.json +2 -2
- package/sources/browser/packages/browser/package.json +1 -1
- package/sources/browser/packages/browser/src/connection.ts +103 -37
- package/sources/browser/packages/browser/src/font-channel.ts +15 -6
- package/sources/browser/packages/browser/src/index.ts +2 -2
- package/sources/browser/packages/browser/src/office-engine.ts +80 -6
- package/sources/browser/packages/browser/src/office-types.ts +52 -1
- package/sources/browser/packages/browser/src/office.ts +118 -52
- package/sources/browser/packages/browser/src/protocol.ts +18 -4
- package/sources/browser/packages/browser/src/types.ts +3 -0
- package/sources/browser/packages/browser/src/worker.ts +132 -53
- package/sources/browser/scripts/build-browser.mjs +6 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BrowserTile } from './types.ts';
|
|
2
2
|
import type { EmscriptenModule } from './engine-types.ts';
|
|
3
3
|
import type { OfficeOperation } from './protocol.ts';
|
|
4
|
-
import type { OfficeDocumentEvent, OfficeDocumentFormat, OfficeDocumentState, OfficeDocumentTileRequest, OfficeDocumentLayoutResult } from './office-types.ts';
|
|
4
|
+
import type { OfficeDocumentEvent, OfficeDocumentFormat, OfficeDocumentState, OfficeDocumentTileRequest, OfficeDocumentLayoutResult, OfficeReadingState } from './office-types.ts';
|
|
5
5
|
/** One read-only document, driven exclusively by its Worker's messages and timer. */
|
|
6
6
|
export declare class OfficeEngine {
|
|
7
7
|
private readonly module;
|
|
@@ -14,7 +14,8 @@ export declare class OfficeEngine {
|
|
|
14
14
|
private geometryDirty;
|
|
15
15
|
private stopped;
|
|
16
16
|
private layoutWidth;
|
|
17
|
-
private
|
|
17
|
+
private viewportKey;
|
|
18
|
+
private viewportState;
|
|
18
19
|
private captureView;
|
|
19
20
|
private readingView;
|
|
20
21
|
private commandResult;
|
|
@@ -42,6 +43,13 @@ export declare class OfficeEngine {
|
|
|
42
43
|
private configure;
|
|
43
44
|
/** Internal whitelist commands only; no arbitrary command crosses the public API. */
|
|
44
45
|
private command;
|
|
46
|
+
/** Read the part and selection the next open of these bytes must restore. */
|
|
47
|
+
capture(): OfficeReadingState;
|
|
48
|
+
/**
|
|
49
|
+
* Apply a reading position captured from the same bytes.
|
|
50
|
+
* @param state - Part and selection captured before this document closed.
|
|
51
|
+
*/
|
|
52
|
+
restore(state: OfficeReadingState): Promise<void>;
|
|
45
53
|
/** Direct tiles preserve the active view, navigation state and selection. */
|
|
46
54
|
render(request: OfficeDocumentTileRequest): BrowserTile;
|
|
47
55
|
}
|
|
@@ -72,6 +72,53 @@ export interface OfficeDocumentTileRequest extends OfficeDocumentRectangle {
|
|
|
72
72
|
readonly part: number;
|
|
73
73
|
readonly scale: number;
|
|
74
74
|
}
|
|
75
|
+
/** Writer selection as document-model positions; one file always resolves to the same nodes. */
|
|
76
|
+
export interface OfficeTextSelection {
|
|
77
|
+
/** Document node holding the selection point. */
|
|
78
|
+
readonly pointNode: number;
|
|
79
|
+
/** Character offset inside the point node's text. */
|
|
80
|
+
readonly pointOffset: number;
|
|
81
|
+
/** Document node holding the selection mark. */
|
|
82
|
+
readonly markNode: number;
|
|
83
|
+
/** Character offset inside the mark node's text. */
|
|
84
|
+
readonly markOffset: number;
|
|
85
|
+
}
|
|
86
|
+
/** Reading position of one document; capturable before it closes and restorable when its bytes reopen. */
|
|
87
|
+
export interface OfficeReadingState {
|
|
88
|
+
readonly version: 1;
|
|
89
|
+
readonly documentType: OfficeDocumentState['documentType'];
|
|
90
|
+
/** Writer page, Calc worksheet, or Impress slide. */
|
|
91
|
+
readonly part: number;
|
|
92
|
+
/** Writer layout parameters; non-Writer documents remain paginated. */
|
|
93
|
+
readonly layout: {
|
|
94
|
+
readonly mode: 'paginated';
|
|
95
|
+
} | {
|
|
96
|
+
readonly mode: 'continuous';
|
|
97
|
+
readonly width: number;
|
|
98
|
+
};
|
|
99
|
+
/** Last document-coordinate viewport and raster scale, when one was configured. */
|
|
100
|
+
readonly viewport: {
|
|
101
|
+
readonly rectangle: OfficeDocumentRectangle;
|
|
102
|
+
readonly scale: number;
|
|
103
|
+
} | null;
|
|
104
|
+
/** Writer text selection; null when the reader holds no text selection. */
|
|
105
|
+
readonly text: OfficeTextSelection | null;
|
|
106
|
+
/** Calc selected range in A1 notation; null when the reader holds no cell range. */
|
|
107
|
+
readonly cell: string | null;
|
|
108
|
+
/** Selected drawing objects as ordinal paths inside the current slide. */
|
|
109
|
+
readonly object: readonly (readonly number[])[] | null;
|
|
110
|
+
}
|
|
111
|
+
/** Source bytes and reading position for one document of a shared runtime. */
|
|
112
|
+
export interface OfficeDocumentOpenOptions {
|
|
113
|
+
readonly data: Uint8Array;
|
|
114
|
+
readonly extension: OfficeDocumentFormat;
|
|
115
|
+
/** Match fonts for this document without blocking the browser's main thread. */
|
|
116
|
+
readonly resolveFonts: BrowserDocumentOptions['resolveFonts'];
|
|
117
|
+
/** Called with unavailable declared families for this document. */
|
|
118
|
+
readonly onMissingFonts?: BrowserDocumentOptions['onMissingFonts'];
|
|
119
|
+
/** Reading position captured from an earlier open of the same bytes. */
|
|
120
|
+
readonly restore?: OfficeReadingState;
|
|
121
|
+
}
|
|
75
122
|
/** A null rectangle invalidates an entire part; negative part means every part. */
|
|
76
123
|
export type OfficeDocumentEvent = {
|
|
77
124
|
readonly type: 'state';
|
|
@@ -86,7 +133,7 @@ export type OfficeDocumentEvent = {
|
|
|
86
133
|
readonly code: BrowserRenderErrorCode;
|
|
87
134
|
readonly message: string;
|
|
88
135
|
};
|
|
89
|
-
/**
|
|
136
|
+
/** One open document of a runtime; closing it frees the parsed model without destroying the engine. */
|
|
90
137
|
export interface OfficeDocument {
|
|
91
138
|
readonly state: OfficeDocumentState;
|
|
92
139
|
subscribe(listener: (event: OfficeDocumentEvent) => void): () => void;
|
|
@@ -102,6 +149,18 @@ export interface OfficeDocument {
|
|
|
102
149
|
setLayout(request: OfficeDocumentLayoutRequest): Promise<OfficeDocumentLayoutResult>;
|
|
103
150
|
/** Only the current part can be painted; queued requests for a former part reject with stale-part without changing selection. */
|
|
104
151
|
renderTile(request: OfficeDocumentTileRequest, signal?: AbortSignal): Promise<BrowserTile>;
|
|
152
|
+
/** Read the position the next open of the same bytes must restore. */
|
|
153
|
+
captureReadingState(): Promise<OfficeReadingState>;
|
|
154
|
+
/** Close this document and release its model; the owning runtime keeps its engine. */
|
|
155
|
+
close(): Promise<void>;
|
|
156
|
+
/** Close this document and destroy the owning runtime. */
|
|
157
|
+
dispose(): Promise<void>;
|
|
158
|
+
}
|
|
159
|
+
/** One engine Worker that opens documents one at a time without reinitializing LibreOffice. */
|
|
160
|
+
export interface OfficeRuntime {
|
|
161
|
+
/** Open a document, closing the document this runtime currently holds. */
|
|
162
|
+
open(options: OfficeDocumentOpenOptions, signal?: AbortSignal): Promise<OfficeDocument>;
|
|
163
|
+
/** Close the open document and release the Worker, its WASM instance and its pthreads. */
|
|
105
164
|
dispose(): Promise<void>;
|
|
106
165
|
}
|
|
107
166
|
//# sourceMappingURL=office-types.d.ts.map
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { BrowserRuntimeOptions } from './types.ts';
|
|
2
|
+
import type { OfficeDocument, OfficeDocumentOpenOptions, OfficeRuntime } from './office-types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Start one read-only Office engine that opens documents one at a time.
|
|
5
|
+
* @param options - Engine resources and limits shared by every document.
|
|
6
|
+
* @param signal - Runtime lifetime; abort closes the Worker and its pthreads.
|
|
7
|
+
* @returns Sequential document loading and joined disposal.
|
|
8
|
+
*/
|
|
9
|
+
export declare function openOfficeRuntime(options: BrowserRuntimeOptions, signal?: AbortSignal): Promise<OfficeRuntime>;
|
|
10
|
+
/**
|
|
11
|
+
* Open one read-only Office document in its own engine; the runtime ends with the document.
|
|
12
|
+
* @param options - Source bytes, engine resources and Host fonts.
|
|
13
|
+
* @param signal - Document lifetime; abort closes its Worker and pthreads.
|
|
14
|
+
* @returns Immutable reading state and disposal.
|
|
15
|
+
*/
|
|
16
|
+
export declare function openOfficeDocument(options: BrowserRuntimeOptions & {
|
|
17
|
+
readonly data: Uint8Array;
|
|
18
|
+
} & Pick<OfficeDocumentOpenOptions, 'extension' | 'resolveFonts' | 'onMissingFonts'>, signal?: AbortSignal): Promise<OfficeDocument>;
|
|
4
19
|
//# sourceMappingURL=office.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Private messages exchanged by the document owner and its single engine Worker. */
|
|
2
|
-
import type { BrowserDocumentOptions, BrowserFontIdentity, BrowserFontRequest, BrowserPage, BrowserRenderErrorCode, BrowserTile, BrowserTileRequest } from './types.ts';
|
|
3
|
-
import type { OfficeDocumentEvent, OfficeDocumentNavigation, OfficeDocumentOptions, OfficeDocumentState, OfficeDocumentPointer, OfficeDocumentLayoutRequest, OfficeDocumentLayoutResult, OfficeDocumentTileRequest, OfficeDocumentRectangle } from './office-types.ts';
|
|
2
|
+
import type { BrowserDocumentOptions, BrowserFontIdentity, BrowserFontRequest, BrowserPage, BrowserRenderErrorCode, BrowserRuntimeOptions, BrowserTile, BrowserTileRequest } from './types.ts';
|
|
3
|
+
import type { OfficeDocumentEvent, OfficeDocumentNavigation, OfficeDocumentOptions, OfficeDocumentState, OfficeDocumentPointer, OfficeDocumentLayoutRequest, OfficeDocumentLayoutResult, OfficeDocumentTileRequest, OfficeDocumentRectangle, OfficeReadingState } from './office-types.ts';
|
|
4
4
|
export declare const FONT_CHUNK_BYTES: number;
|
|
5
5
|
export declare const FONT_HEADER_BYTES = 8;
|
|
6
6
|
export declare const enum FontState {
|
|
@@ -11,7 +11,15 @@ export declare const enum FontState {
|
|
|
11
11
|
Error = 4,
|
|
12
12
|
Cancelled = 5
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
/** Engine resources a Worker holds for the lifetime of every document it opens. */
|
|
15
|
+
export type WorkerOptions = Omit<BrowserRuntimeOptions, 'resolveFonts' | 'onMissingFonts'>;
|
|
16
|
+
/** Source bytes and reading position of one document opened inside a started Worker. */
|
|
17
|
+
export interface WorkerDocumentOptions {
|
|
18
|
+
readonly data: Uint8Array;
|
|
19
|
+
readonly extension: BrowserDocumentOptions['extension'] | OfficeDocumentOptions['extension'];
|
|
20
|
+
/** Reading position captured from an earlier open of the same bytes. */
|
|
21
|
+
readonly restore?: OfficeReadingState;
|
|
22
|
+
}
|
|
15
23
|
export type OfficeOperation = {
|
|
16
24
|
readonly type: 'pointer';
|
|
17
25
|
readonly event: OfficeDocumentPointer;
|
|
@@ -37,11 +45,20 @@ export type OfficeOperation = {
|
|
|
37
45
|
readonly request: OfficeDocumentLayoutRequest;
|
|
38
46
|
};
|
|
39
47
|
export type OwnerMessage = {
|
|
40
|
-
readonly type: '
|
|
48
|
+
readonly type: 'start';
|
|
41
49
|
readonly id: number;
|
|
42
50
|
readonly options: WorkerOptions;
|
|
43
51
|
readonly channel: SharedArrayBuffer;
|
|
44
|
-
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: 'open';
|
|
54
|
+
readonly id: number;
|
|
55
|
+
readonly options: WorkerDocumentOptions;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: 'close-document';
|
|
58
|
+
readonly id: number;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: 'reading-state';
|
|
61
|
+
readonly id: number;
|
|
45
62
|
} | {
|
|
46
63
|
readonly type: 'tile';
|
|
47
64
|
readonly id: number;
|
|
@@ -61,10 +78,20 @@ export type OwnerMessage = {
|
|
|
61
78
|
type WithoutId<T> = T extends unknown ? Omit<T, 'id'> : never;
|
|
62
79
|
export type OwnerRequest = WithoutId<OwnerMessage>;
|
|
63
80
|
export type WorkerMessage = {
|
|
81
|
+
readonly type: 'started';
|
|
82
|
+
readonly id: number;
|
|
83
|
+
} | {
|
|
64
84
|
readonly type: 'opened';
|
|
65
85
|
readonly id: number;
|
|
66
86
|
readonly pages: readonly BrowserPage[];
|
|
67
87
|
readonly office?: OfficeDocumentState;
|
|
88
|
+
} | {
|
|
89
|
+
readonly type: 'closed-document';
|
|
90
|
+
readonly id: number;
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: 'reading-state';
|
|
93
|
+
readonly id: number;
|
|
94
|
+
readonly state: OfficeReadingState;
|
|
68
95
|
} | {
|
|
69
96
|
readonly type: 'tile';
|
|
70
97
|
readonly id: number;
|
|
@@ -93,6 +93,8 @@ export interface BrowserDocumentOptions {
|
|
|
93
93
|
/** Called with unavailable declared OOXML families; binary DOC/PPT have no font diagnostics. */
|
|
94
94
|
readonly onMissingFonts?: (families: readonly string[]) => void;
|
|
95
95
|
}
|
|
96
|
+
/** Engine resources and limits one Worker holds for every document it opens. */
|
|
97
|
+
export type BrowserRuntimeOptions = Omit<BrowserDocumentOptions, 'data' | 'extension' | 'resolveFonts' | 'onMissingFonts'>;
|
|
96
98
|
/** One Worker-owned, read-only Office document. */
|
|
97
99
|
export interface BrowserDocument {
|
|
98
100
|
/** Visible pages; Writer omits zero-area automatic section parity placeholders. */
|