@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.
Files changed (43) hide show
  1. package/NOTICE +238 -0
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -3
  4. package/lib/browser/assets.json +2 -2
  5. package/lib/browser/index.js +65 -58
  6. package/lib/browser/types/connection.d.ts +3 -3
  7. package/lib/browser/types/index.d.ts +2 -2
  8. package/lib/browser/types/office-engine.d.ts +46 -0
  9. package/lib/browser/types/office-types.d.ts +107 -0
  10. package/lib/browser/types/office.d.ts +4 -0
  11. package/lib/browser/types/protocol.d.ts +24 -32
  12. package/lib/browser/types/types.d.ts +3 -1
  13. package/lib/browser/worker.js +276 -489
  14. package/lib/browser-assets.js +1 -1
  15. package/lib/cli.js +91 -58
  16. package/lib/font-source.js +89 -56
  17. package/lib/font-worker.js +710 -39
  18. package/lib/index.js +91 -58
  19. package/lib/types/default-fonts.d.ts +3 -0
  20. package/lib/types/engine.d.ts +1 -1
  21. package/lib/types/font-preferences-data.d.ts +16 -0
  22. package/lib/types/font-preferences.d.ts +29 -0
  23. package/lib/types/font-source-types.d.ts +2 -0
  24. package/lib/types/fonts.d.ts +11 -8
  25. package/lib/types/options.d.ts +1 -1
  26. package/lib/worker.js +707 -37
  27. package/package.json +3 -3
  28. package/sources/browser/packages/browser/package.json +2 -2
  29. package/sources/browser/packages/browser/src/connection.ts +7 -9
  30. package/sources/browser/packages/browser/src/index.ts +3 -3
  31. package/sources/browser/packages/browser/src/office-engine.ts +299 -0
  32. package/sources/browser/packages/browser/src/office-types.ts +77 -0
  33. package/sources/browser/packages/browser/src/office.ts +62 -0
  34. package/sources/browser/packages/browser/src/protocol.ts +15 -16
  35. package/sources/browser/packages/browser/src/types.ts +3 -1
  36. package/sources/browser/packages/browser/src/worker.ts +25 -30
  37. package/sources/browser/scripts/build-browser.mjs +9 -1
  38. package/lib/browser/types/editor-engine.d.ts +0 -50
  39. package/lib/browser/types/editor-types.d.ts +0 -141
  40. package/lib/browser/types/editor.d.ts +0 -9
  41. package/sources/browser/packages/browser/src/editor-engine.ts +0 -382
  42. package/sources/browser/packages/browser/src/editor-types.ts +0 -106
  43. package/sources/browser/packages/browser/src/editor.ts +0 -55
@@ -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
@@ -1,6 +1,6 @@
1
1
  /** Private messages exchanged by the document owner and its single engine Worker. */
2
2
  import type { BrowserDocumentOptions, BrowserFontRequest, BrowserPage, BrowserRenderErrorCode, BrowserTile, BrowserTileRequest } from './types.ts';
3
- import type { BrowserCommandArguments, BrowserEditorCapture, BrowserEditorCaptureRequest, BrowserEditorEvent, BrowserEditorInput, BrowserEditorOptions, BrowserEditorSnapshot, BrowserEditorState, BrowserEditorTileRequest, BrowserRectangle } from './editor-types.ts';
3
+ import type { OfficeDocumentEvent, OfficeDocumentNavigation, OfficeDocumentOptions, OfficeDocumentState, OfficeDocumentPointer, OfficeDocumentLayoutRequest, OfficeDocumentLayoutResult, OfficeDocumentTileRequest, OfficeDocumentRectangle } 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,19 +11,18 @@ export declare const enum FontState {
11
11
  Error = 4,
12
12
  Cancelled = 5
13
13
  }
14
- export type WorkerOptions = Omit<BrowserDocumentOptions | BrowserEditorOptions, 'resolveFonts' | 'onMissingFonts'> & {
15
- readonly readOnly?: boolean;
16
- };
17
- export type EditorOperation = {
18
- readonly type: 'input';
19
- readonly event: BrowserEditorInput;
14
+ export type WorkerOptions = Omit<BrowserDocumentOptions | OfficeDocumentOptions, 'resolveFonts' | 'onMissingFonts'>;
15
+ export type OfficeOperation = {
16
+ readonly type: 'pointer';
17
+ readonly event: OfficeDocumentPointer;
18
+ } | {
19
+ readonly type: 'navigate';
20
+ readonly event: OfficeDocumentNavigation;
20
21
  } | {
21
- readonly type: 'command';
22
- readonly command: string;
23
- readonly arguments?: BrowserCommandArguments;
22
+ readonly type: 'select-all';
24
23
  } | {
25
- readonly type: 'paste';
26
- readonly text: string;
24
+ readonly type: 'cell';
25
+ readonly address: string;
27
26
  } | {
28
27
  readonly type: 'copy';
29
28
  } | {
@@ -31,33 +30,30 @@ export type EditorOperation = {
31
30
  readonly part: number;
32
31
  } | {
33
32
  readonly type: 'viewport';
34
- readonly rectangle: BrowserRectangle;
33
+ readonly rectangle: OfficeDocumentRectangle;
35
34
  readonly scale: number;
36
35
  } | {
37
- readonly type: 'save';
36
+ readonly type: 'layout';
37
+ readonly request: OfficeDocumentLayoutRequest;
38
38
  };
39
39
  export type OwnerMessage = {
40
40
  readonly type: 'open';
41
41
  readonly id: number;
42
42
  readonly options: WorkerOptions;
43
43
  readonly channel: SharedArrayBuffer;
44
- readonly editing?: boolean;
44
+ readonly office?: boolean;
45
45
  } | {
46
46
  readonly type: 'tile';
47
47
  readonly id: number;
48
48
  readonly request: BrowserTileRequest;
49
49
  } | {
50
- readonly type: 'editor-tile';
51
- readonly id: number;
52
- readonly request: BrowserEditorTileRequest;
53
- } | {
54
- readonly type: 'capture';
50
+ readonly type: 'office-tile';
55
51
  readonly id: number;
56
- readonly request: BrowserEditorCaptureRequest;
52
+ readonly request: OfficeDocumentTileRequest;
57
53
  } | {
58
- readonly type: 'edit';
54
+ readonly type: 'office-operation';
59
55
  readonly id: number;
60
- readonly operation: EditorOperation;
56
+ readonly operation: OfficeOperation;
61
57
  } | {
62
58
  readonly type: 'dispose';
63
59
  readonly id: number;
@@ -68,23 +64,19 @@ export type WorkerMessage = {
68
64
  readonly type: 'opened';
69
65
  readonly id: number;
70
66
  readonly pages: readonly BrowserPage[];
71
- readonly editor?: BrowserEditorState;
67
+ readonly office?: OfficeDocumentState;
72
68
  } | {
73
69
  readonly type: 'tile';
74
70
  readonly id: number;
75
71
  readonly tile: BrowserTile;
76
72
  } | {
77
- readonly type: 'captured';
78
- readonly id: number;
79
- readonly capture: BrowserEditorCapture;
80
- } | {
81
- readonly type: 'edited';
73
+ readonly type: 'office-result';
82
74
  readonly id: number;
83
75
  readonly text?: string;
84
- readonly snapshot?: BrowserEditorSnapshot;
76
+ readonly layout?: OfficeDocumentLayoutResult;
85
77
  } | {
86
- readonly type: 'editor-event';
87
- readonly event: BrowserEditorEvent;
78
+ readonly type: 'office-event';
79
+ readonly event: OfficeDocumentEvent;
88
80
  } | {
89
81
  readonly type: 'disposed';
90
82
  readonly id: number;
@@ -30,6 +30,8 @@ export interface BrowserFontResult {
30
30
  readonly format?: 'ttf' | 'otf' | 'ttc';
31
31
  }[];
32
32
  readonly missingFamily?: string;
33
+ /** Missing scalars reported by the Host, independently of a substituted family. */
34
+ readonly unresolvedCodePoints?: readonly number[];
33
35
  }
34
36
  /** All sizes are CSS pixels at 96 pixels per inch. */
35
37
  export interface BrowserPage {
@@ -81,7 +83,7 @@ export interface BrowserDocument {
81
83
  dispose(): Promise<void>;
82
84
  }
83
85
  /** Stable failures callers may map to their own localized product copy. */
84
- export type BrowserRenderErrorCode = 'unavailable' | 'invalid-document' | 'timeout' | 'font-limit' | 'font-unavailable' | 'disposed' | 'render-failed' | 'snapshot-changed';
86
+ export type BrowserRenderErrorCode = 'unavailable' | 'invalid-document' | 'timeout' | 'font-limit' | 'font-unavailable' | 'disposed' | 'render-failed' | 'stale-part';
85
87
  /** A rendering failure with a stable machine-readable category. */
86
88
  export declare class BrowserRenderError extends Error {
87
89
  readonly code: BrowserRenderErrorCode;