@p10node/office-engine 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +65 -1
- package/dist/DocViewer-kfAVEXOO.js +10533 -0
- package/dist/DocViewer-kfAVEXOO.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.txt +79 -0
- package/dist/assets/worker-DbLPJnSo.js.map +1 -0
- package/dist/collab-BzN1ZI-z.js +1984 -0
- package/dist/collab-BzN1ZI-z.js.map +1 -0
- package/dist/collab.js +2 -0
- package/dist/core.js +2 -0
- package/dist/default-worker-f546VALp.js +9196 -0
- package/dist/default-worker-f546VALp.js.map +1 -0
- package/dist/embed.js +91 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/office-engine.embed.js +81 -0
- package/dist/office-engine.worker.js +9092 -0
- package/dist/types/collab/codec.d.ts +3 -0
- package/dist/types/collab/docx.d.ts +166 -0
- package/dist/types/collab/hosts.d.ts +24 -0
- package/dist/types/collab/hub.d.ts +41 -0
- package/dist/types/collab/index.d.ts +43 -0
- package/dist/types/collab/pptx-ops.d.ts +60 -0
- package/dist/types/collab/pptx-worker.d.ts +35 -0
- package/dist/types/collab/pptx.d.ts +47 -0
- package/dist/types/collab/protocol.d.ts +76 -0
- package/dist/types/collab/react.d.ts +23 -0
- package/dist/types/collab/session.d.ts +115 -0
- package/dist/types/collab/transport.d.ts +47 -0
- package/dist/types/collab/xlsx-ops.d.ts +72 -0
- package/dist/types/collab/xlsx-worker.d.ts +29 -0
- package/dist/types/collab/xlsx.d.ts +51 -0
- package/dist/types/core/color.d.ts +25 -0
- package/dist/types/core/convert.d.ts +29 -0
- package/dist/types/core/default-worker.d.ts +1 -0
- package/dist/types/core/docx/numbering.d.ts +33 -0
- package/dist/types/core/docx/parser.d.ts +126 -0
- package/dist/types/core/docx/spec.d.ts +4 -0
- package/dist/types/core/docx/styles.d.ts +63 -0
- package/dist/types/core/docx/types.d.ts +325 -0
- package/dist/types/core/docx/writer.d.ts +35 -0
- package/dist/types/core/fonts.d.ts +1 -0
- package/dist/types/core/index.d.ts +15 -0
- package/dist/types/core/opc.d.ts +56 -0
- package/dist/types/core/pptx/edit.d.ts +10 -0
- package/dist/types/core/pptx/parser.d.ts +52 -0
- package/dist/types/core/pptx/types.d.ts +238 -0
- package/dist/types/core/raw.d.ts +40 -0
- package/dist/types/core/source.d.ts +65 -0
- package/dist/types/core/theme.d.ts +11 -0
- package/dist/types/core/units.d.ts +7 -0
- package/dist/types/core/worker/client.d.ts +48 -0
- package/dist/types/core/worker/engine.d.ts +27 -0
- package/dist/types/core/worker/protocol.d.ts +112 -0
- package/dist/types/core/worker/worker.d.ts +1 -0
- package/dist/types/core/xlsx/calc.d.ts +31 -0
- package/dist/types/core/xlsx/editor.d.ts +95 -0
- package/dist/types/core/xlsx/formula/assist.d.ts +35 -0
- package/dist/types/core/xlsx/formula/catalog.d.ts +14 -0
- package/dist/types/core/xlsx/formula/dates.d.ts +23 -0
- package/dist/types/core/xlsx/formula/evaluate.d.ts +33 -0
- package/dist/types/core/xlsx/formula/fn-date.d.ts +2 -0
- package/dist/types/core/xlsx/formula/fn-logic.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-lookup.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-math.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-stats.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-text.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn.d.ts +64 -0
- package/dist/types/core/xlsx/formula/format.d.ts +5 -0
- package/dist/types/core/xlsx/formula/functions.d.ts +4 -0
- package/dist/types/core/xlsx/formula/index.d.ts +17 -0
- package/dist/types/core/xlsx/formula/lexer.d.ts +54 -0
- package/dist/types/core/xlsx/formula/parser.d.ts +53 -0
- package/dist/types/core/xlsx/formula/refs.d.ts +23 -0
- package/dist/types/core/xlsx/formula/transform.d.ts +21 -0
- package/dist/types/core/xlsx/formula/types.d.ts +59 -0
- package/dist/types/core/xlsx/formula/values.d.ts +49 -0
- package/dist/types/core/xlsx/numfmt.d.ts +11 -0
- package/dist/types/core/xlsx/structure.d.ts +31 -0
- package/dist/types/core/xlsx/styles.d.ts +17 -0
- package/dist/types/core/xlsx/types.d.ts +193 -0
- package/dist/types/core/xlsx/workbook.d.ts +94 -0
- package/dist/types/core/xml.d.ts +80 -0
- package/dist/types/core/zip.d.ts +35 -0
- package/dist/types/core/zipwrite.d.ts +11 -0
- package/dist/types/embed.d.ts +30 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/react/DocViewer.d.ts +61 -0
- package/dist/types/react/common/ContextMenu.d.ts +21 -0
- package/dist/types/react/common/Dialog.d.ts +35 -0
- package/dist/types/react/common/Slots.d.ts +38 -0
- package/dist/types/react/common/Status.d.ts +6 -0
- package/dist/types/react/common/ZoomControl.d.ts +6 -0
- package/dist/types/react/common/hooks.d.ts +20 -0
- package/dist/types/react/docx/DocxEditor.d.ts +172 -0
- package/dist/types/react/docx/DocxToolbar.d.ts +19 -0
- package/dist/types/react/docx/DocxView.d.ts +8 -0
- package/dist/types/react/docx/FindBar.d.ts +22 -0
- package/dist/types/react/docx/html.d.ts +8 -0
- package/dist/types/react/docx/render.d.ts +24 -0
- package/dist/types/react/docx/tables.d.ts +20 -0
- package/dist/types/react/edit/Toolbar.d.ts +134 -0
- package/dist/types/react/edit/input.d.ts +81 -0
- package/dist/types/react/edit/rich.d.ts +40 -0
- package/dist/types/react/file/DetailsDialog.d.ts +7 -0
- package/dist/types/react/file/FileMenu.d.ts +48 -0
- package/dist/types/react/file/importFile.d.ts +10 -0
- package/dist/types/react/file/print.d.ts +16 -0
- package/dist/types/react/file/text.d.ts +10 -0
- package/dist/types/react/injectStyles.d.ts +4 -0
- package/dist/types/react/pptx/PptxEditor.d.ts +95 -0
- package/dist/types/react/pptx/PptxToolbar.d.ts +36 -0
- package/dist/types/react/pptx/PptxView.d.ts +24 -0
- package/dist/types/react/pptx/Presenter.d.ts +9 -0
- package/dist/types/react/pptx/Slide.d.ts +28 -0
- package/dist/types/react/pptx/geometry.d.ts +5 -0
- package/dist/types/react/useDocument.d.ts +11 -0
- package/dist/types/react/xlsx/XlsxToolbar.d.ts +27 -0
- package/dist/types/react/xlsx/XlsxView.d.ts +18 -0
- package/dist/types/react/xlsx/axis.d.ts +19 -0
- package/dist/types/react/xlsx/print.d.ts +17 -0
- package/dist/xlsx-ops-CsjNpMI0.js +244 -0
- package/dist/xlsx-ops-CsjNpMI0.js.map +1 -0
- package/package.json +75 -2
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/** Geometry in px (96 dpi, EMU/9525); font sizes in pt. */
|
|
2
|
+
export type Fill = {
|
|
3
|
+
t: 'solid';
|
|
4
|
+
c: string;
|
|
5
|
+
} | {
|
|
6
|
+
t: 'grad';
|
|
7
|
+
css: string;
|
|
8
|
+
} | {
|
|
9
|
+
t: 'img';
|
|
10
|
+
target: string;
|
|
11
|
+
tile?: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
t: 'none';
|
|
14
|
+
};
|
|
15
|
+
export interface Stroke {
|
|
16
|
+
c: string;
|
|
17
|
+
w: number;
|
|
18
|
+
dash?: string;
|
|
19
|
+
head?: string;
|
|
20
|
+
tail?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Box {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
w: number;
|
|
26
|
+
h: number;
|
|
27
|
+
rot?: number;
|
|
28
|
+
flipH?: boolean;
|
|
29
|
+
flipV?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface TRun {
|
|
32
|
+
text: string;
|
|
33
|
+
sz: number;
|
|
34
|
+
b?: boolean;
|
|
35
|
+
i?: boolean;
|
|
36
|
+
u?: boolean;
|
|
37
|
+
strike?: boolean;
|
|
38
|
+
color?: string;
|
|
39
|
+
font?: string;
|
|
40
|
+
baseline?: number;
|
|
41
|
+
caps?: boolean;
|
|
42
|
+
href?: string;
|
|
43
|
+
hl?: string;
|
|
44
|
+
br?: boolean;
|
|
45
|
+
/** slide field (number/date): kept as an object when editing */
|
|
46
|
+
fld?: boolean;
|
|
47
|
+
/** [paragraph, run] index in the original shape XML */
|
|
48
|
+
src?: [number, number];
|
|
49
|
+
}
|
|
50
|
+
export interface TPara {
|
|
51
|
+
algn: 'left' | 'center' | 'right' | 'justify';
|
|
52
|
+
marL: number;
|
|
53
|
+
indent: number;
|
|
54
|
+
/** line height multiplier or px */
|
|
55
|
+
lnPct?: number;
|
|
56
|
+
lnPx?: number;
|
|
57
|
+
spcBef: number;
|
|
58
|
+
spcAft: number;
|
|
59
|
+
bullet?: {
|
|
60
|
+
text: string;
|
|
61
|
+
color?: string;
|
|
62
|
+
font?: string;
|
|
63
|
+
sz: number;
|
|
64
|
+
};
|
|
65
|
+
/** outline level and bullet kind (editor state) */
|
|
66
|
+
lvl?: number;
|
|
67
|
+
buKind?: 'none' | 'bullet' | 'number';
|
|
68
|
+
runs: TRun[];
|
|
69
|
+
endSz: number;
|
|
70
|
+
/** template paragraph index in the original shape XML */
|
|
71
|
+
k?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface TextBody {
|
|
74
|
+
anchor: 't' | 'ctr' | 'b';
|
|
75
|
+
ins: [number, number, number, number];
|
|
76
|
+
wrap: boolean;
|
|
77
|
+
vert?: string;
|
|
78
|
+
paras: TPara[];
|
|
79
|
+
/** placeholder without text (editable, invisible when viewing) */
|
|
80
|
+
empty?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** `top`: id of the slide-level element (selection / move); `sid`: own id of a text shape (text editing) */
|
|
83
|
+
export type SlideEl = ({
|
|
84
|
+
t: 'shape';
|
|
85
|
+
box: Box;
|
|
86
|
+
geom: string;
|
|
87
|
+
adj?: Record<string, number>;
|
|
88
|
+
fill?: Fill;
|
|
89
|
+
stroke?: Stroke;
|
|
90
|
+
text?: TextBody;
|
|
91
|
+
path?: string;
|
|
92
|
+
sid?: number;
|
|
93
|
+
} | {
|
|
94
|
+
t: 'pic';
|
|
95
|
+
box: Box;
|
|
96
|
+
target?: string;
|
|
97
|
+
crop?: [number, number, number, number];
|
|
98
|
+
stroke?: Stroke;
|
|
99
|
+
geom?: string;
|
|
100
|
+
video?: boolean;
|
|
101
|
+
} | {
|
|
102
|
+
t: 'table';
|
|
103
|
+
box: Box;
|
|
104
|
+
cols: number[];
|
|
105
|
+
rows: {
|
|
106
|
+
h: number;
|
|
107
|
+
cells: TCell[];
|
|
108
|
+
}[];
|
|
109
|
+
} | {
|
|
110
|
+
t: 'placeholder';
|
|
111
|
+
box: Box;
|
|
112
|
+
label: string;
|
|
113
|
+
}) & {
|
|
114
|
+
top?: number;
|
|
115
|
+
};
|
|
116
|
+
/** 'text', 'line', 'image' or any DrawingML preset geometry name (rect, ellipse, star5, chevron…) */
|
|
117
|
+
export type ShapeKind = 'text' | 'line' | 'image' | (string & {});
|
|
118
|
+
export type ShapeOp = {
|
|
119
|
+
op: 'xfrm';
|
|
120
|
+
top: number;
|
|
121
|
+
box: Box;
|
|
122
|
+
} | {
|
|
123
|
+
op: 'delete';
|
|
124
|
+
top: number;
|
|
125
|
+
} | {
|
|
126
|
+
op: 'fill';
|
|
127
|
+
top: number;
|
|
128
|
+
color: string | null;
|
|
129
|
+
} | {
|
|
130
|
+
op: 'line';
|
|
131
|
+
top: number;
|
|
132
|
+
color?: string | null;
|
|
133
|
+
w?: number;
|
|
134
|
+
dash?: string;
|
|
135
|
+
} | {
|
|
136
|
+
op: 'order';
|
|
137
|
+
top: number;
|
|
138
|
+
to: 'front' | 'back' | 'forward' | 'backward';
|
|
139
|
+
} | {
|
|
140
|
+
op: 'duplicate';
|
|
141
|
+
top: number;
|
|
142
|
+
dx?: number;
|
|
143
|
+
dy?: number;
|
|
144
|
+
}
|
|
145
|
+
/** vertical text anchor of a text shape (by shape id) */
|
|
146
|
+
| {
|
|
147
|
+
op: 'anchor';
|
|
148
|
+
sid: number;
|
|
149
|
+
anchor: 't' | 'ctr' | 'b';
|
|
150
|
+
}
|
|
151
|
+
/** slide background color (null = follow layout) */
|
|
152
|
+
| {
|
|
153
|
+
op: 'bg';
|
|
154
|
+
color: string | null;
|
|
155
|
+
} | {
|
|
156
|
+
op: 'insert';
|
|
157
|
+
kind: ShapeKind;
|
|
158
|
+
box: Box;
|
|
159
|
+
text?: string;
|
|
160
|
+
rid?: string;
|
|
161
|
+
};
|
|
162
|
+
export type SlideOp = {
|
|
163
|
+
op: 'add';
|
|
164
|
+
after: number;
|
|
165
|
+
layout?: 'title' | 'content' | 'blank';
|
|
166
|
+
} | {
|
|
167
|
+
op: 'duplicate';
|
|
168
|
+
index: number;
|
|
169
|
+
} | {
|
|
170
|
+
op: 'delete';
|
|
171
|
+
index: number;
|
|
172
|
+
} | {
|
|
173
|
+
op: 'move';
|
|
174
|
+
from: number;
|
|
175
|
+
to: number;
|
|
176
|
+
} | {
|
|
177
|
+
op: 'hide';
|
|
178
|
+
index: number;
|
|
179
|
+
hidden: boolean;
|
|
180
|
+
};
|
|
181
|
+
export interface TCell {
|
|
182
|
+
text?: TextBody;
|
|
183
|
+
fill?: Fill;
|
|
184
|
+
bl?: Stroke;
|
|
185
|
+
br?: Stroke;
|
|
186
|
+
bt?: Stroke;
|
|
187
|
+
bb?: Stroke;
|
|
188
|
+
colSpan: number;
|
|
189
|
+
rowSpan: number;
|
|
190
|
+
hidden: boolean;
|
|
191
|
+
}
|
|
192
|
+
export interface SlideModel {
|
|
193
|
+
index: number;
|
|
194
|
+
w: number;
|
|
195
|
+
h: number;
|
|
196
|
+
bg?: Fill;
|
|
197
|
+
els: SlideEl[];
|
|
198
|
+
notes?: string;
|
|
199
|
+
hidden?: boolean;
|
|
200
|
+
}
|
|
201
|
+
export interface PresentationMeta {
|
|
202
|
+
w: number;
|
|
203
|
+
h: number;
|
|
204
|
+
count: number;
|
|
205
|
+
slides: {
|
|
206
|
+
index: number;
|
|
207
|
+
path: string;
|
|
208
|
+
hidden: boolean;
|
|
209
|
+
}[];
|
|
210
|
+
}
|
|
211
|
+
export interface PRunSet {
|
|
212
|
+
b?: boolean;
|
|
213
|
+
i?: boolean;
|
|
214
|
+
u?: boolean;
|
|
215
|
+
strike?: boolean;
|
|
216
|
+
sz?: number;
|
|
217
|
+
color?: string | null;
|
|
218
|
+
font?: string;
|
|
219
|
+
hl?: string | null;
|
|
220
|
+
/** percent of the font size (+30 superscript, -25 subscript), null = normal */
|
|
221
|
+
baseline?: number | null;
|
|
222
|
+
}
|
|
223
|
+
export interface PRunSpec {
|
|
224
|
+
text: string;
|
|
225
|
+
src?: [number, number];
|
|
226
|
+
set?: PRunSet;
|
|
227
|
+
fld?: boolean;
|
|
228
|
+
}
|
|
229
|
+
export interface PParaSpec {
|
|
230
|
+
k?: number;
|
|
231
|
+
algn?: 'left' | 'center' | 'right' | 'justify';
|
|
232
|
+
/** outline level 0-8 */
|
|
233
|
+
lvl?: number;
|
|
234
|
+
bullet?: 'none' | 'bullet' | 'number';
|
|
235
|
+
/** line spacing multiplier */
|
|
236
|
+
lnPct?: number;
|
|
237
|
+
runs: PRunSpec[];
|
|
238
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte-faithful XML tree: keeps qualified names, raw attribute text and raw
|
|
3
|
+
* (still-escaped) text, so untouched parts serialize back exactly as read.
|
|
4
|
+
*/
|
|
5
|
+
export interface RNode {
|
|
6
|
+
q: string;
|
|
7
|
+
a: string;
|
|
8
|
+
c: RChild[];
|
|
9
|
+
self: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type RChild = RNode | string;
|
|
12
|
+
export declare const isNode: (x: RChild | undefined) => x is RNode;
|
|
13
|
+
export declare function parseRaw(xml: string): RChild[];
|
|
14
|
+
export declare function serialize(x: RChild | RChild[]): string;
|
|
15
|
+
export declare const local: (q: string) => string;
|
|
16
|
+
export declare const prefixOf: (q: string) => string;
|
|
17
|
+
export declare function rootEl(nodes: RChild[]): RNode | undefined;
|
|
18
|
+
export declare function kidsOf(n: RNode | undefined, loc?: string): RNode[];
|
|
19
|
+
export declare function kidOf(n: RNode | undefined, loc: string): RNode | undefined;
|
|
20
|
+
/** Attribute value by exact qualified name, or by local name when `loose`. */
|
|
21
|
+
export declare function getAttr(n: RNode, name: string, loose?: boolean): string | undefined;
|
|
22
|
+
export declare function setAttr(n: RNode, name: string, value: string | undefined): void;
|
|
23
|
+
export declare function el(q: string, attrs?: Record<string, string | undefined>, children?: RChild[]): RNode;
|
|
24
|
+
export declare function clone<T extends RChild>(x: T): T;
|
|
25
|
+
export declare function removeKids(n: RNode, loc: string | ((l: string) => boolean)): void;
|
|
26
|
+
/**
|
|
27
|
+
* Replaces (or inserts) the child with local name `loc`, keeping schema order:
|
|
28
|
+
* the new child goes before the first existing sibling that comes later in `order`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function setOrdered(parent: RNode, child: RNode | undefined, loc: string, order: string[]): void;
|
|
31
|
+
export declare function escText(s: string): string;
|
|
32
|
+
export declare function escAttr(s: string): string;
|
|
33
|
+
export declare function textContent(n: RChild): string;
|
|
34
|
+
/**
|
|
35
|
+
* Preorder walk mirroring TreeBuilder semantics: mc:Fallback skipped, only the first
|
|
36
|
+
* mc:Choice of an mc:AlternateContent is visited. `visit` returns true to stop descending.
|
|
37
|
+
*/
|
|
38
|
+
export declare function walkOoxml(n: RNode, visit: (node: RNode, parent: RNode, index: number) => boolean | void): void;
|
|
39
|
+
/** attributes for an `r:id`-style reference that are valid whatever prefixes the root declared */
|
|
40
|
+
export declare function relIdAttrs(root: RNode, local: string | undefined, value: string): Record<string, string>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Random-access byte sources. The ZIP reader only touches the bytes it needs
|
|
3
|
+
* (central directory + requested entries), so a 500 MB file is never read in full.
|
|
4
|
+
*/
|
|
5
|
+
export interface ByteSource {
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
read(offset: number, length: number): Promise<Uint8Array>;
|
|
9
|
+
stream(offset: number, length: number): ReadableStream<Uint8Array>;
|
|
10
|
+
/** Zero-copy sub-Blob when available (used when re-zipping unchanged entries). */
|
|
11
|
+
slice?(offset: number, length: number): Blob;
|
|
12
|
+
}
|
|
13
|
+
export type ProgressFn = (loaded: number, total: number) => void;
|
|
14
|
+
export declare class BlobSource implements ByteSource {
|
|
15
|
+
private blob;
|
|
16
|
+
readonly name?: string | undefined;
|
|
17
|
+
readonly size: number;
|
|
18
|
+
constructor(blob: Blob, name?: string | undefined);
|
|
19
|
+
read(offset: number, length: number): Promise<Uint8Array>;
|
|
20
|
+
stream(offset: number, length: number): ReadableStream<Uint8Array>;
|
|
21
|
+
slice(offset: number, length: number): Blob;
|
|
22
|
+
}
|
|
23
|
+
export declare class BufferSource implements ByteSource {
|
|
24
|
+
readonly name?: string | undefined;
|
|
25
|
+
readonly size: number;
|
|
26
|
+
private bytes;
|
|
27
|
+
constructor(data: ArrayBuffer | Uint8Array, name?: string | undefined);
|
|
28
|
+
read(offset: number, length: number): Promise<Uint8Array>;
|
|
29
|
+
stream(offset: number, length: number): ReadableStream<Uint8Array>;
|
|
30
|
+
}
|
|
31
|
+
export interface HttpSourceOptions {
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
credentials?: RequestCredentials;
|
|
34
|
+
/** Block size used for cached range reads (default 256 KB). */
|
|
35
|
+
blockSize?: number;
|
|
36
|
+
/** Max cached blocks (default 128 → 32 MB). */
|
|
37
|
+
maxBlocks?: number;
|
|
38
|
+
onProgress?: ProgressFn;
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* HTTP source using Range requests. Falls back to a full download when the
|
|
43
|
+
* server does not honour ranges (or CORS hides the needed headers).
|
|
44
|
+
*/
|
|
45
|
+
export declare class HttpRangeSource implements ByteSource {
|
|
46
|
+
readonly url: string;
|
|
47
|
+
readonly size: number;
|
|
48
|
+
private opts;
|
|
49
|
+
readonly name?: string | undefined;
|
|
50
|
+
private cache;
|
|
51
|
+
private inflight;
|
|
52
|
+
private blockSize;
|
|
53
|
+
private maxBlocks;
|
|
54
|
+
private constructor();
|
|
55
|
+
static open(url: string, opts?: HttpSourceOptions): Promise<ByteSource>;
|
|
56
|
+
private fetchRange;
|
|
57
|
+
private ensureBlocks;
|
|
58
|
+
private evict;
|
|
59
|
+
read(offset: number, length: number): Promise<Uint8Array>;
|
|
60
|
+
stream(offset: number, length: number): ReadableStream<Uint8Array>;
|
|
61
|
+
}
|
|
62
|
+
export type DocSource = Blob | File | ArrayBuffer | Uint8Array | string | URL;
|
|
63
|
+
export declare function openSource(src: DocSource, opts?: HttpSourceOptions & {
|
|
64
|
+
name?: string;
|
|
65
|
+
}): Promise<ByteSource>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type XEl } from './xml';
|
|
2
|
+
export interface Theme {
|
|
3
|
+
colors: Record<string, string>;
|
|
4
|
+
major: string;
|
|
5
|
+
minor: string;
|
|
6
|
+
fillStyles: XEl[];
|
|
7
|
+
bgFillStyles: XEl[];
|
|
8
|
+
lineStyles: XEl[];
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_THEME: Theme;
|
|
11
|
+
export declare function parseTheme(root: XEl | undefined): Theme;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const EMU_PER_PX = 9525;
|
|
2
|
+
export declare const EMU_PER_PT = 12700;
|
|
3
|
+
export declare const emuToPx: (v: number | undefined) => number;
|
|
4
|
+
export declare const emuToPt: (v: number | undefined) => number;
|
|
5
|
+
export declare const twipToPt: (v: number | undefined) => number;
|
|
6
|
+
export declare const ptToPx: (pt: number) => number;
|
|
7
|
+
export declare const round2: (v: number) => number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DocKind } from '../opc';
|
|
2
|
+
import type { DocSource } from '../source';
|
|
3
|
+
import type { Events, Methods, OpenParams, OpenResult } from './protocol';
|
|
4
|
+
export interface OpenOptions extends OpenParams {
|
|
5
|
+
/** Custom worker factory (e.g. for strict CSP setups). Pass `false` to run on the main thread. */
|
|
6
|
+
worker?: (() => Worker) | false;
|
|
7
|
+
/** Download / parse progress, including progress emitted while opening. */
|
|
8
|
+
onProgress?: (p: Events['progress']) => void;
|
|
9
|
+
}
|
|
10
|
+
type Listener<K extends keyof Events> = (data: Events[K]) => void;
|
|
11
|
+
/** Registers the worker factory used when none is passed to `DocumentClient.open`. */
|
|
12
|
+
export declare function setDefaultWorker(factory: () => Worker): void;
|
|
13
|
+
/**
|
|
14
|
+
* Main-thread handle to a document living in a Web Worker.
|
|
15
|
+
* Parsing, unzipping and formatting never block the UI thread.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DocumentClient {
|
|
18
|
+
kind: DocKind;
|
|
19
|
+
name?: string;
|
|
20
|
+
size: number;
|
|
21
|
+
info: OpenResult;
|
|
22
|
+
private worker?;
|
|
23
|
+
private engine?;
|
|
24
|
+
private seq;
|
|
25
|
+
private pending;
|
|
26
|
+
private listeners;
|
|
27
|
+
private urls;
|
|
28
|
+
private destroyed;
|
|
29
|
+
private constructor();
|
|
30
|
+
static open(src: DocSource, opts?: OpenOptions): Promise<DocumentClient>;
|
|
31
|
+
private onMessage;
|
|
32
|
+
/**
|
|
33
|
+
* Set by a collaboration session: sees every call first and handles the ones that change the
|
|
34
|
+
* document (returns a promise), or returns undefined to let the call through unchanged.
|
|
35
|
+
*/
|
|
36
|
+
interceptor?: (method: keyof Methods, args: unknown[]) => Promise<unknown> | undefined;
|
|
37
|
+
call<M extends keyof Methods>(method: M, ...args: Parameters<Methods[M]>): Promise<ReturnType<Methods[M]>>;
|
|
38
|
+
/** calls the engine directly, bypassing `interceptor` */
|
|
39
|
+
direct<M extends keyof Methods>(method: M, ...args: Parameters<Methods[M]>): Promise<ReturnType<Methods[M]>>;
|
|
40
|
+
/** dispatches an event to listeners on this thread (e.g. remote changes applied by a collaboration session) */
|
|
41
|
+
notify<K extends keyof Events>(event: K, data: Events[K]): void;
|
|
42
|
+
on<K extends keyof Events>(event: K, fn: Listener<K>): () => void;
|
|
43
|
+
/** Object URL for a package part (images, media). Cached per client; revoked on destroy. */
|
|
44
|
+
mediaUrl(path: string): Promise<string>;
|
|
45
|
+
static canRender(path: string): boolean;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type DocSource } from '../source';
|
|
2
|
+
import type { Events, Methods, OpenParams, OpenResult } from './protocol';
|
|
3
|
+
type Emit = <K extends keyof Events>(event: K, data: Events[K]) => void;
|
|
4
|
+
/** Format-agnostic engine; runs inside the worker (or directly, e.g. in tests). */
|
|
5
|
+
export declare class Engine {
|
|
6
|
+
private emit;
|
|
7
|
+
private pkg?;
|
|
8
|
+
private kind?;
|
|
9
|
+
private docx?;
|
|
10
|
+
private xlsx?;
|
|
11
|
+
private xlsxEd?;
|
|
12
|
+
private pptx?;
|
|
13
|
+
private abort;
|
|
14
|
+
constructor(emit: Emit);
|
|
15
|
+
open(src: DocSource, params?: OpenParams): Promise<OpenResult>;
|
|
16
|
+
private writes;
|
|
17
|
+
call<M extends keyof Methods>(method: M, args: unknown[]): Promise<unknown>;
|
|
18
|
+
private dispatch;
|
|
19
|
+
private xcollab?;
|
|
20
|
+
private pcollab?;
|
|
21
|
+
private xc;
|
|
22
|
+
private xed;
|
|
23
|
+
private save;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
private need;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DocKind } from '../opc';
|
|
2
|
+
import type { XOp } from '../../collab/xlsx-ops';
|
|
3
|
+
import type { POp } from '../../collab/pptx-ops';
|
|
4
|
+
import type { PptxCollabResult } from '../../collab/pptx-worker';
|
|
5
|
+
import type { CanonStyle, DocxMeta, Block, EditOp, EditResult, StyleInfo, TableOp } from '../docx/types';
|
|
6
|
+
import type { BlockOut, BookOp, CellDetail, CellInput, FindMatch, FindOptions, FmtPatch, Range, SheetOp, SheetProgress, WorkbookMeta, XlsxEditResult } from '../xlsx/types';
|
|
7
|
+
import type { PParaSpec, PresentationMeta, ShapeOp, SlideModel, SlideOp } from '../pptx/types';
|
|
8
|
+
export interface OpenParams {
|
|
9
|
+
name?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
credentials?: RequestCredentials;
|
|
12
|
+
}
|
|
13
|
+
export interface OpenResult {
|
|
14
|
+
kind: DocKind;
|
|
15
|
+
name?: string;
|
|
16
|
+
size: number;
|
|
17
|
+
xlsx?: WorkbookMeta;
|
|
18
|
+
pptx?: PresentationMeta;
|
|
19
|
+
}
|
|
20
|
+
export interface Methods {
|
|
21
|
+
open(src: Blob | ArrayBuffer | string, params: OpenParams): OpenResult;
|
|
22
|
+
part(path: string): Blob;
|
|
23
|
+
'docx.start'(): void;
|
|
24
|
+
'docx.edit'(op: EditOp): EditResult;
|
|
25
|
+
'docx.table'(op: TableOp): void;
|
|
26
|
+
'docx.image'(bytes: ArrayBuffer, ext: string): {
|
|
27
|
+
rid: string;
|
|
28
|
+
path: string;
|
|
29
|
+
};
|
|
30
|
+
'docx.link'(url: string): string;
|
|
31
|
+
/** id of a built-in paragraph style, created in styles.xml when missing */
|
|
32
|
+
'docx.style'(kind: CanonStyle): {
|
|
33
|
+
id: string;
|
|
34
|
+
styles: StyleInfo[];
|
|
35
|
+
};
|
|
36
|
+
/** builds the edited file */
|
|
37
|
+
save(): Blob;
|
|
38
|
+
dirty(): boolean;
|
|
39
|
+
'xlsx.load'(sheet: number): void;
|
|
40
|
+
'xlsx.block'(sheet: number, r0: number, r1: number): BlockOut;
|
|
41
|
+
'xlsx.cell'(sheet: number, r: number, c: number): CellDetail | undefined;
|
|
42
|
+
/** cells whose shown value (or formula) contains the text */
|
|
43
|
+
'xlsx.find'(sheet: number, query: string, opts?: FindOptions): FindMatch[];
|
|
44
|
+
/** replaces text in matching cells (or only `at`); null when nothing changed */
|
|
45
|
+
'xlsx.replace'(sheet: number, query: string, by: string, opts?: FindOptions, at?: {
|
|
46
|
+
r: number;
|
|
47
|
+
c: number;
|
|
48
|
+
}): XlsxEditResult | null;
|
|
49
|
+
'xlsx.set'(sheet: number, cells: CellInput[]): XlsxEditResult;
|
|
50
|
+
'xlsx.format'(sheet: number, range: Range, patch: FmtPatch): XlsxEditResult;
|
|
51
|
+
'xlsx.sheetOp'(sheet: number, op: SheetOp): XlsxEditResult;
|
|
52
|
+
'xlsx.bookOp'(op: BookOp): XlsxEditResult;
|
|
53
|
+
'xlsx.undo'(): XlsxEditResult | null;
|
|
54
|
+
'xlsx.redo'(): XlsxEditResult | null;
|
|
55
|
+
'pptx.slide'(index: number): SlideModel;
|
|
56
|
+
'pptx.setText'(index: number, sid: number, paras: PParaSpec[]): SlideModel;
|
|
57
|
+
'pptx.shapes'(index: number, ops: ShapeOp[]): SlideModel;
|
|
58
|
+
'pptx.slides'(op: SlideOp): PresentationMeta;
|
|
59
|
+
'pptx.image'(index: number, bytes: ArrayBuffer, ext: string): string;
|
|
60
|
+
/** undo (or redo) the last shape edit */
|
|
61
|
+
'pptx.undo'(redo?: boolean): {
|
|
62
|
+
index: number;
|
|
63
|
+
model: SlideModel;
|
|
64
|
+
} | null;
|
|
65
|
+
/** collaboration (src/collab): a shared XLSX operation, outside the undo history; `rec` reverts it */
|
|
66
|
+
'collab.xlsx.apply'(op: XOp): {
|
|
67
|
+
res: XlsxEditResult | null;
|
|
68
|
+
rec: number | null;
|
|
69
|
+
};
|
|
70
|
+
'collab.xlsx.revert'(rec: number): XlsxEditResult | null;
|
|
71
|
+
/** collaboration: a shared PPTX operation (recorded as slide snapshots) */
|
|
72
|
+
'collab.pptx.apply'(op: POp): {
|
|
73
|
+
res: PptxCollabResult;
|
|
74
|
+
rec: number | null;
|
|
75
|
+
};
|
|
76
|
+
'collab.pptx.revert'(rec: number): PptxCollabResult;
|
|
77
|
+
}
|
|
78
|
+
export interface Events {
|
|
79
|
+
progress: {
|
|
80
|
+
phase: string;
|
|
81
|
+
loaded: number;
|
|
82
|
+
total: number;
|
|
83
|
+
};
|
|
84
|
+
'docx:blocks': Block[];
|
|
85
|
+
'docx:meta': DocxMeta;
|
|
86
|
+
'docx:done': {
|
|
87
|
+
error?: string;
|
|
88
|
+
};
|
|
89
|
+
'xlsx:progress': SheetProgress;
|
|
90
|
+
/** collaboration: remote (or rebased) XLSX changes applied on this client */
|
|
91
|
+
'collab:xlsx': XlsxEditResult;
|
|
92
|
+
/** collaboration: a slide (or the slide list) changed remotely */
|
|
93
|
+
'collab:pptx': PptxCollabResult;
|
|
94
|
+
}
|
|
95
|
+
export type Req = {
|
|
96
|
+
id: number;
|
|
97
|
+
method: keyof Methods;
|
|
98
|
+
args: unknown[];
|
|
99
|
+
};
|
|
100
|
+
export type Res = {
|
|
101
|
+
id: number;
|
|
102
|
+
ok: true;
|
|
103
|
+
result: unknown;
|
|
104
|
+
} | {
|
|
105
|
+
id: number;
|
|
106
|
+
ok: false;
|
|
107
|
+
error: string;
|
|
108
|
+
};
|
|
109
|
+
export type Evt = {
|
|
110
|
+
event: keyof Events;
|
|
111
|
+
data: unknown;
|
|
112
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type XlsxWorkbook } from './workbook';
|
|
2
|
+
export declare class Calc {
|
|
3
|
+
private wb;
|
|
4
|
+
private asts;
|
|
5
|
+
private cellDeps;
|
|
6
|
+
private rangeDeps;
|
|
7
|
+
private indexed;
|
|
8
|
+
constructor(wb: XlsxWorkbook);
|
|
9
|
+
invalidate(): void;
|
|
10
|
+
private sheetIndex;
|
|
11
|
+
private ast;
|
|
12
|
+
private index;
|
|
13
|
+
private addDeps;
|
|
14
|
+
/** a formula was added / changed / removed at (sheet, key) */
|
|
15
|
+
formulaChanged(sheet: number, key: number): void;
|
|
16
|
+
/** current value of a cell as the formula engine sees it */
|
|
17
|
+
private value;
|
|
18
|
+
private provider;
|
|
19
|
+
private cur;
|
|
20
|
+
private compute;
|
|
21
|
+
/** Evaluates the given formula cells and everything that depends on the changed cells. */
|
|
22
|
+
recalc(changed: {
|
|
23
|
+
sheet: number;
|
|
24
|
+
key: number;
|
|
25
|
+
}[], formulas?: {
|
|
26
|
+
sheet: number;
|
|
27
|
+
key: number;
|
|
28
|
+
}[]): Set<number>;
|
|
29
|
+
/** formulas whose value is missing (files written without cached values) */
|
|
30
|
+
computeMissing(sheet: number, keys: number[]): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { BookOp, CellInput, ColInfo, FindOptions, FmtPatch, Merge, Range, SheetOp, SheetProgress, XlsxEditResult } from './types';
|
|
2
|
+
import { type Snapshot } from './structure';
|
|
3
|
+
import { SheetData, XlsxWorkbook } from './workbook';
|
|
4
|
+
export declare const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
5
|
+
type Entry = [number, unknown, number];
|
|
6
|
+
interface CellChange {
|
|
7
|
+
key: number;
|
|
8
|
+
prev: Entry | null;
|
|
9
|
+
prevF?: string;
|
|
10
|
+
next: Entry | null;
|
|
11
|
+
nextF?: string;
|
|
12
|
+
}
|
|
13
|
+
interface LayoutState {
|
|
14
|
+
merges?: Merge[];
|
|
15
|
+
colInfo?: ColInfo[];
|
|
16
|
+
rowAttrs?: [number, {
|
|
17
|
+
ht?: number;
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
}][];
|
|
20
|
+
frozen?: {
|
|
21
|
+
rows: number;
|
|
22
|
+
cols: number;
|
|
23
|
+
};
|
|
24
|
+
gridLines?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface Change {
|
|
27
|
+
sheet: number;
|
|
28
|
+
cells: CellChange[];
|
|
29
|
+
range: Range;
|
|
30
|
+
/** cheap layout state (merges, sizes, panes) before/after */
|
|
31
|
+
lay?: {
|
|
32
|
+
before: LayoutState;
|
|
33
|
+
after: LayoutState;
|
|
34
|
+
};
|
|
35
|
+
/** whole-sheet snapshots (row/column insert/delete) */
|
|
36
|
+
full?: {
|
|
37
|
+
before: Snapshot;
|
|
38
|
+
after: Snapshot;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare function getEntry(d: SheetData, r: number, c: number): Entry | null;
|
|
42
|
+
export declare class XlsxEditor {
|
|
43
|
+
private wb;
|
|
44
|
+
private undoStack;
|
|
45
|
+
private redoStack;
|
|
46
|
+
private styleEd?;
|
|
47
|
+
private stylesPath?;
|
|
48
|
+
private formulaTouched;
|
|
49
|
+
constructor(wb: XlsxWorkbook);
|
|
50
|
+
get dirty(): boolean;
|
|
51
|
+
private sheet;
|
|
52
|
+
private lastRecalc;
|
|
53
|
+
private apply;
|
|
54
|
+
private applyRaw;
|
|
55
|
+
private record;
|
|
56
|
+
/** after rows/columns moved: rebuild the dependency graph and recompute every formula */
|
|
57
|
+
private recalcAll;
|
|
58
|
+
setCells(sheet: number, inputs: CellInput[]): XlsxEditResult;
|
|
59
|
+
private styles;
|
|
60
|
+
format(sheet: number, range: Range, patch: FmtPatch): Promise<XlsxEditResult>;
|
|
61
|
+
private step;
|
|
62
|
+
undo(): XlsxEditResult | null;
|
|
63
|
+
redo(): XlsxEditResult | null;
|
|
64
|
+
/** takes the change recorded by the last operation out of the (unused) undo history */
|
|
65
|
+
takeRecord(): Change | undefined;
|
|
66
|
+
/** exactly undoes a recorded change (rolling back an unconfirmed operation) */
|
|
67
|
+
revertRecord(ch: Change): XlsxEditResult;
|
|
68
|
+
/** sets the cells / layout touched by `ch` to its `which` state, recorded as a new change */
|
|
69
|
+
restoreRecord(ch: Change, which: 'prev' | 'next'): XlsxEditResult;
|
|
70
|
+
/** style table sizes before an operation */
|
|
71
|
+
styleMark(): Promise<Record<string, number>>;
|
|
72
|
+
/** drops styles derived after `m` (the operations that used them were rolled back) */
|
|
73
|
+
styleTruncate(m: Record<string, number>): Promise<void>;
|
|
74
|
+
/** style index of a cell (0 when empty) */
|
|
75
|
+
styleAt(sheet: number, r: number, c: number): number;
|
|
76
|
+
/** current layout of a sheet (after structural edits) */
|
|
77
|
+
layout(sheet: number): SheetProgress;
|
|
78
|
+
private allSheets;
|
|
79
|
+
sheetOp(sheet: number, op: SheetOp): Promise<XlsxEditResult>;
|
|
80
|
+
/** replaces `query` in matching cells (one undo step); `at` limits it to one cell */
|
|
81
|
+
replace(sheet: number, query: string, by: string, opts?: FindOptions, at?: {
|
|
82
|
+
r: number;
|
|
83
|
+
c: number;
|
|
84
|
+
}): XlsxEditResult | null;
|
|
85
|
+
private fill;
|
|
86
|
+
private sort;
|
|
87
|
+
bookOp(op: BookOp): Promise<XlsxEditResult>;
|
|
88
|
+
private bookChanged;
|
|
89
|
+
/** XML of sheets created in this session (no original to stream from) */
|
|
90
|
+
private newSheets;
|
|
91
|
+
save(): Promise<Blob>;
|
|
92
|
+
/** Streams the original sheet XML, patching only rows that contain edits. */
|
|
93
|
+
private rewrite;
|
|
94
|
+
}
|
|
95
|
+
export {};
|